Added new __WXMOTIF20__ macro, which is true if the Motif version

is 2.0 or higher.
  Now Motif 2.0 or better (but not Lesstif) uses XmRenderTable instead
of the deprecated XmFontList. This allows underlined text in controls.
  Miscellaneous cleanup; used wxXmString in some more places.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@19495 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Mattia Barbon 2003-03-05 20:15:35 +00:00
parent bdb9ccbfd6
commit da494b405d
20 changed files with 1018 additions and 860 deletions

1614
configure vendored

File diff suppressed because it is too large Load Diff

View File

@ -2543,6 +2543,27 @@ equivalent variable and GTK+ is version 1.2.3 or above.
AC_MSG_ERROR([can't link a simple motif program])
fi
save_CFLAGS=$CFLAGS
CFLAGS="$CFLAGS $TOOLKIT_INCLUDE"
AC_MSG_CHECKING([for Motif 2])
AC_TRY_COMPILE([
#include <Xm/Xm.h>
],
[
#if XmVersion < 2000
#error "Not Motif 2"
#endif
],
[
AC_DEFINE(__WXMOTIF20__,1)
AC_MSG_RESULT([found])
],
[
AC_DEFINE(__WXMOTIF20__,0)
AC_MSG_RESULT([not found])
])
CFLAGS=$save_CFLAGS
GUI_TK_LIBRARY="$GUI_TK_LIBRARY -lXm$xpm_link${libp_link} -lXmu -lXext -lXt${libsm_ice_link} -lX11"
TOOLKIT_VPATH="\${top_srcdir}/src/motif${PATH_IFS}\${top_srcdir}/src/motif/xmcombo${PATH_IFS}\${top_srcdir}/src/x11"
TOOLKIT=MOTIF

View File

@ -155,7 +155,7 @@ overview}{wxfontencodingoverview} for the meaning of the last parameter).
\docparam{weight}{One of {\bf wxNORMAL}, {\bf wxLIGHT} and {\bf wxBOLD}.}
\docparam{underline}{The value can be true or false. At present this has an effect on Windows only.}
\docparam{underline}{The value can be true or false. At present this has an effect on Windows and Motif 2.x only.}
\docparam{faceName}{An optional string specifying the actual typeface to be used. If the empty string,
a default typeface will chosen based on the family.}

View File

@ -2024,6 +2024,10 @@ typedef void* WXRegion;
typedef void* WXFont;
typedef void* WXImage;
typedef void* WXFontList;
typedef void* WXRendition;
typedef void* WXRenderTable;
typedef void* WXFontType; /* either a XmFontList or XmRenderTable */
typedef void* WXString;
typedef unsigned long Atom; /* this might fail on a few architectures */

View File

@ -99,7 +99,13 @@ public:
WXDisplay* display = NULL) const;
WXFontList GetFontList(double scale = 1.0,
WXDisplay* display = NULL) const;
#if __WXMOTIF20__
WXRenderTable GetRenderTable(WXDisplay* display) const;
#endif
// returns either a XmFontList or XmRendition, depending
// on Motif version
WXFontType GetFontType(WXDisplay* display) const;
static WXString GetFontTag();
protected:
virtual void DoSetNativeFontInfo( const wxNativeFontInfo& info );

View File

@ -109,7 +109,10 @@ public:
m_string = XmStringCreateLtoR((char *)str.c_str(),
XmSTRING_DEFAULT_CHARSET);
}
// just to avoid calling XmStringFree()
wxXmString(const XmString& string) { m_string = string; }
~wxXmString() { XmStringFree(m_string); }
// semi-implicit conversion to XmString (shouldn't rely on implicit

View File

@ -61,6 +61,9 @@
/* Define this if your version of GTK+ is greater than 1.3 */
#undef __WXGTK20__
/* Define this if your version of Motif is greater than 2.0 */
#undef __WXMOTIF20__
/*
* Define to 1 for Unix[-like] system
*/

View File

@ -54,9 +54,6 @@ bool wxButton::Create(wxWindow *parent, wxWindowID id, const wxString& label,
Widget parentWidget = (Widget) parent->GetClientWidget();
XmFontList fontList =
(XmFontList)m_font.GetFontList(1.0, XtDisplay(parentWidget));
/*
* Patch Note (important)
* There is no major reason to put a defaultButtonThickness here.
@ -69,7 +66,7 @@ bool wxButton::Create(wxWindow *parent, wxWindowID id, const wxString& label,
m_mainWidget = (WXWidget) XtVaCreateManagedWidget ("button",
xmPushButtonWidgetClass,
parentWidget,
XmNfontList, fontList,
wxFont::GetFontTag(), m_font.GetFontType(XtDisplay(parentWidget)),
XmNlabelString, text(),
// See comment for wxButton::SetDefault
// XmNdefaultButtonShadowThickness, 1,

View File

@ -56,12 +56,10 @@ bool wxCheckBox::Create(wxWindow *parent, wxWindowID id, const wxString& label,
wxXmString text( label1 );
Widget parentWidget = (Widget) parent->GetClientWidget();
XmFontList fontList =
(XmFontList) m_font.GetFontList(1.0, XtDisplay(parentWidget));
m_mainWidget = (WXWidget) XtVaCreateManagedWidget ("toggle",
xmToggleButtonWidgetClass, parentWidget,
XmNfontList, fontList,
wxFont::GetFontTag(), m_font.GetFontType(XtDisplay(parentWidget)),
XmNlabelString, text(),
NULL);

View File

@ -244,33 +244,29 @@ void wxChoice::Clear()
int wxChoice::GetSelection() const
{
XmString text;
char *s;
Widget label = XmOptionButtonGadget ((Widget) m_buttonWidget);
XtVaGetValues (label,
XmNlabelString, &text,
NULL);
wxXmString freeMe(text);
wxString s = wxXmStringToString( text );
if (XmStringGetLtoR (text, XmSTRING_DEFAULT_CHARSET, &s))
if (!s.IsEmpty())
{
int i = 0;
for (wxStringListNode* node = m_stringList.GetFirst ();
node; node = node->GetNext ())
{
if (strcmp(node->GetData(), s) == 0)
if (wxStrcmp(node->GetData(), s.c_str()) == 0)
{
XmStringFree(text) ;
XtFree (s);
return i;
}
else
i++;
} // for()
XmStringFree(text) ;
XtFree (s);
return -1;
}
XmStringFree(text) ;
return -1;
}
@ -433,13 +429,16 @@ void wxChoice::ChangeFont(bool keepOriginalSize)
int width, height, width1, height1;
GetSize(& width, & height);
XmFontList fontList = (XmFontList) m_font.GetFontList(1.0, XtDisplay((Widget) m_mainWidget));
XtVaSetValues ((Widget) m_formWidget, XmNfontList, fontList, NULL);
XtVaSetValues ((Widget) m_buttonWidget, XmNfontList, fontList, NULL);
WXFontType fontType =
m_font.GetFontType(XtDisplay((Widget) m_mainWidget));
WXString fontTag = wxFont::GetFontTag();
XtVaSetValues ((Widget) m_formWidget, fontTag, fontType, NULL);
XtVaSetValues ((Widget) m_buttonWidget, fontTag, fontType, NULL);
for( size_t i = 0; i < m_noStrings; ++i )
XtVaSetValues( (Widget)m_widgetArray[i],
XmNfontList, fontList,
fontTag, fontType,
NULL );
GetSize(& width1, & height1);

View File

@ -105,23 +105,11 @@ wxString wxControl::GetLabel() const
return wxEmptyString;
XmString text;
char *s;
XtVaGetValues (widget,
XmNlabelString, &text,
NULL);
if (XmStringGetLtoR (text, XmSTRING_DEFAULT_CHARSET, &s))
{
wxString str(s);
XtFree (s);
XmStringFree(text);
return str;
}
else
{
// XmStringFree(text);
return wxEmptyString;
}
return wxXmStringToString( text );
}
bool wxControl::ProcessCommand(wxCommandEvent & event)

View File

@ -39,6 +39,7 @@
#include "wx/fontutil.h" // for wxNativeFontInfo
#include "wx/tokenzr.h"
#include "wx/settings.h"
#include "wx/motif/private.h"
IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject)
@ -56,6 +57,9 @@ public:
WXFontStructPtr m_fontStruct; // XFontStruct
WXFontList m_fontList; // Motif XmFontList
#if wxCHECK_MOTIF_VERSION( 2, 0 )
WXRenderTable m_renderTable; // Motif XmRenderTable
#endif
WXDisplay* m_display; // XDisplay
int m_scale; // Scale * 100
};
@ -121,6 +125,9 @@ wxXFont::wxXFont()
{
m_fontStruct = (WXFontStructPtr) 0;
m_fontList = (WXFontList) 0;
#if wxCHECK_MOTIF_VERSION( 2, 0 )
m_renderTable = (WXRenderTable) 0;
#endif
m_display = (WXDisplay*) 0;
m_scale = 100;
}
@ -128,9 +135,13 @@ wxXFont::wxXFont()
wxXFont::~wxXFont()
{
XmFontList fontList = (XmFontList) m_fontList;
XmFontListFree (fontList);
#if wxCHECK_MOTIF_VERSION( 2, 0 )
XmRenderTable renderTable = (XmRenderTable) m_renderTable;
XmRenderTableFree (renderTable);
#endif
// TODO: why does freeing the font produce a segv???
// Note that XFreeFont wasn't called in wxWin 1.68 either.
// XFontStruct* fontStruct = (XFontStruct*) m_fontStruct;
@ -533,6 +544,24 @@ wxXFont* wxFont::GetInternalFont(double scale, WXDisplay* display) const
f->m_fontList = XmFontListCreate ((XFontStruct*) font, XmSTRING_DEFAULT_CHARSET);
M_FONTDATA->m_fonts.Append(f);
#if wxCHECK_MOTIF_VERSION( 2, 0 ) && !wxCHECK_LESSTIF()
XmRendition rendition;
XmRenderTable renderTable;
Arg args[5];
int count = 0;
XtSetArg( args[count], XmNfont, font ); ++count;
XtSetArg( args[count], XmNunderlineType,
GetUnderlined() ? XmSINGLE_LINE : XmNO_LINE ); ++count;
rendition = XmRenditionCreate( XmGetXmDisplay( (Display*)f->m_display ),
(XmStringTag)"",
args, count );
renderTable = XmRenderTableAddRenditions( NULL, &rendition, 1,
XmMERGE_REPLACE );
f->m_renderTable = (WXRenderTable)renderTable;
#endif
return f;
}
@ -550,3 +579,31 @@ WXFontList wxFont::GetFontList(double scale, WXDisplay* display) const
return (f ? f->m_fontList : (WXFontList) 0);
}
#if wxCHECK_MOTIF_VERSION( 2, 0 )
WXRenderTable wxFont::GetRenderTable(WXDisplay* display) const
{
wxXFont* f = GetInternalFont(1.0, display);
return (f ? f->m_renderTable : (WXFontList) 0);
}
#endif
WXFontType wxFont::GetFontType(WXDisplay* display) const
{
#if wxCHECK_MOTIF_VERSION( 2, 0 ) && !wxCHECK_LESSTIF()
return Ok() ? GetRenderTable(display) : NULL;
#else
return Ok() ? GetFontList(1.0, display) : NULL;
#endif
}
/*static*/ WXString wxFont::GetFontTag()
{
#if wxCHECK_MOTIF_VERSION( 2, 0 ) && !wxCHECK_LESSTIF()
return (WXString)XmNrenderTable;
#else
return (WXString)XmNfontList;
#endif
}

View File

@ -92,12 +92,11 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id,
Widget parentWidget = (Widget) parent->GetClientWidget();
XmFontList fontList = (XmFontList)NULL;
WXFontType fontType = (WXFontType)NULL;
if( m_font.Ok() )
{
fontList = (XmFontList)m_font.GetFontList(1.0,
XtDisplay(parentWidget));
fontType = m_font.GetFontType(XtDisplay(parentWidget));
}
Arg args[4];
@ -108,9 +107,9 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id,
( m_windowStyle & wxLB_EXTENDED ) ? XmEXTENDED_SELECT :
XmBROWSE_SELECT );
++count;
if( fontList )
if( fontType )
{
XtSetArg( args[count], XmNfontList, fontList );
XtSetArg( args[count], (String)wxFont::GetFontTag(), fontType );
++count;
}
if( m_windowStyle & wxLB_ALWAYS_SB )

View File

@ -247,8 +247,6 @@ void wxMenuBar::SetLabelTop(size_t pos, const wxString& label)
wxString wxMenuBar::GetLabelTop(size_t pos) const
{
wxString str;
wxMenu *menu = GetMenu(pos);
if ( menu )
{
@ -260,17 +258,11 @@ wxString wxMenuBar::GetLabelTop(size_t pos) const
XmNlabelString, &text,
NULL);
char *s;
if ( XmStringGetLtoR(text, XmSTRING_DEFAULT_CHARSET, &s) )
{
str = s;
XtFree(s);
}
return wxXmStringToString( text );
}
}
return str;
return wxEmptyString;
}
bool wxMenuBar::Append(wxMenu * menu, const wxString& title)
@ -652,21 +644,21 @@ void wxMenu::SetForegroundColour(const wxColour& col)
void wxMenu::ChangeFont(bool keepOriginalSize)
{
// lesstif 0.87 hangs when setting XmNfontList
#ifndef LESSTIF_VERSION
// Lesstif 0.87 hangs here, but 0.93 does not
#if !wxCHECK_LESSTIF() || wxCHECK_LESSTIF_VERSION( 0, 93 )
if (!m_font.Ok() || !m_menuWidget)
return;
XmFontList fontList = (XmFontList) m_font.GetFontList(1.0, XtDisplay((Widget) m_menuWidget));
WXFontType fontType = m_font.GetFontType(XtDisplay((Widget) m_menuWidget));
XtVaSetValues ((Widget) m_menuWidget,
XmNfontList, fontList,
NULL);
wxFont::GetFontTag(), fontType,
NULL);
if (m_buttonWidget)
{
XtVaSetValues ((Widget) m_buttonWidget,
XmNfontList, fontList,
NULL);
wxFont::GetFontTag(), fontType,
NULL);
}
for ( wxMenuItemList::Node *node = GetMenuItems().GetFirst();
@ -677,8 +669,8 @@ void wxMenu::ChangeFont(bool keepOriginalSize)
if (m_menuWidget && item->GetButtonWidget() && m_font.Ok())
{
XtVaSetValues ((Widget) item->GetButtonWidget(),
XmNfontList, fontList,
NULL);
wxFont::GetFontTag(), fontType,
NULL);
}
if (item->GetSubMenu())
item->GetSubMenu()->ChangeFont(keepOriginalSize);

View File

@ -97,31 +97,33 @@ bool wxRadioBox::Create(wxWindow *parent, wxWindowID id, const wxString& title,
wxString label1(wxStripMenuCodes(title));
XmFontList fontList = (XmFontList) m_font.GetFontList(1.0, XtDisplay(parentWidget));
WXFontType fontType = m_font.GetFontType(XtDisplay(parentWidget));
if (label1 != "")
{
wxXmString text(label1);
(void)XtVaCreateManagedWidget(label1.c_str(),
(void)XtVaCreateManagedWidget( label1.c_str(),
#if wxUSE_GADGETS
style & wxCOLOURED ? xmLabelWidgetClass
: xmLabelGadgetClass,
(Widget)m_mainWidget,
style & wxCOLOURED ? xmLabelWidgetClass
: xmLabelGadgetClass,
(Widget)m_mainWidget,
#else
xmLabelWidgetClass, (Widget)m_mainWidget,
xmLabelWidgetClass,
(Widget)m_mainWidget,
#endif
XmNfontList, fontList,
XmNlabelString, text(),
wxFont::GetFontTag(), fontType,
XmNlabelString, text(),
// XmNframeChildType is not in Motif 1.2, nor in Lesstif,
// if it was compiled with 1.2 compatibility
// TODO: check this still looks OK for Motif 1.2.
#if (XmVersion > 1200)
XmNframeChildType, XmFRAME_TITLE_CHILD,
XmNframeChildType, XmFRAME_TITLE_CHILD,
#else
XmNchildType, XmFRAME_TITLE_CHILD,
XmNchildType, XmFRAME_TITLE_CHILD,
#endif
XmNchildVerticalAlignment, XmALIGNMENT_CENTER,
NULL);
XmNchildVerticalAlignment,
XmALIGNMENT_CENTER,
NULL);
}
Arg args[3];
@ -148,9 +150,9 @@ bool wxRadioBox::Create(wxWindow *parent, wxWindowID id, const wxString& title,
#if wxUSE_GADGETS
xmToggleButtonGadgetClass, radioBoxWidget,
#else
xmToggleButtonWidgetClass, radioBoxWidget,
xmToggleButtonWidgetClass, radioBoxWidget,
#endif
XmNfontList, fontList,
wxFont::GetFontTag(), fontType,
NULL);
XtAddCallback ((Widget) m_radioButtons[i], XmNvalueChangedCallback, (XtCallbackProc) wxRadioBoxCallback,
(XtPointer) this);
@ -194,12 +196,11 @@ void wxRadioBox::SetString(int item, const wxString& label)
if (label != "")
{
wxString label1(wxStripMenuCodes(label));
XmString text = XmStringCreateSimple ((char*) (const char*) label1);
wxXmString text( label1 );
XtVaSetValues (widget,
XmNlabelString, text,
XmNlabelString, text(),
XmNlabelType, XmSTRING,
NULL);
XmStringFree (text);
}
}
@ -358,7 +359,8 @@ void wxRadioBox::ChangeFont(bool keepOriginalSize)
{
wxWindow::ChangeFont(keepOriginalSize);
XmFontList fontList = (XmFontList) m_font.GetFontList(1.0, XtDisplay((Widget) GetTopWidget()));
WXFontType fontType =
m_font.GetFontType(XtDisplay((Widget) GetTopWidget()));
int i;
for (i = 0; i < m_noItems; i++)
@ -366,7 +368,7 @@ void wxRadioBox::ChangeFont(bool keepOriginalSize)
WXWidget radioButton = m_radioButtons[i];
XtVaSetValues ((Widget) radioButton,
XmNfontList, fontList,
wxFont::GetFontTag(), fontType,
NULL);
}
}

View File

@ -72,9 +72,9 @@ bool wxRadioButton::Create(wxWindow *parent, wxWindowID id,
wxString label1(wxStripMenuCodes(label));
XmString text = XmStringCreateSimple ((char*) (const char*) label1);
wxXmString text( label1 );
XmFontList fontList = (XmFontList) m_font.GetFontList(1.0, XtDisplay(parentWidget));
WXFontType fontType = m_font.GetFontType(XtDisplay(parentWidget));
Widget radioButtonWidget = XtVaCreateManagedWidget ("toggle",
#if wxUSE_GADGETS
@ -82,12 +82,11 @@ bool wxRadioButton::Create(wxWindow *parent, wxWindowID id,
#else
xmToggleButtonWidgetClass, parentWidget,
#endif
XmNfontList, fontList,
XmNlabelString, text,
wxFont::GetFontTag(), fontType,
XmNlabelString, text(),
XmNfillOnSelect, True,
XmNindicatorType, XmONE_OF_MANY, // diamond-shape
NULL);
XmStringFree (text);
XtAddCallback (radioButtonWidget, XmNvalueChangedCallback, (XtCallbackProc) wxRadioButtonCallback,
(XtPointer) this);

View File

@ -105,13 +105,13 @@ bool wxStaticBox::Create(wxWindow *parent, wxWindowID id,
bool hasLabel = (!label.IsNull() && !label.IsEmpty()) ;
if (hasLabel)
{
XmFontList fontList = (XmFontList) m_font.GetFontList(1.0, XtDisplay( parentWidget ) );
WXFontType fontType = m_font.GetFontType( XtDisplay( parentWidget ) );
wxString label1(wxStripMenuCodes(label));
wxXmString text(label1);
m_labelWidget = (WXWidget) XtVaCreateManagedWidget ("staticboxlabel",
xmLabelWidgetClass, (Widget)m_mainWidget,
XmNfontList, fontList,
wxFont::GetFontTag(), fontType,
XmNlabelString, text(),
#if wxCHECK_MOTIF_VERSION( 2, 0 )
XmNframeChildType, XmFRAME_TITLE_CHILD,

View File

@ -101,26 +101,24 @@ bool wxStaticText::Create(wxWindow *parent, wxWindowID id,
// Use XmStringCreateLtoR(), since XmStringCreateSimple
// doesn't obey separators.
// XmString text = XmStringCreateSimple (label1);
XmString text = XmStringCreateLtoR (label1, XmSTRING_DEFAULT_CHARSET);
wxXmString text( label1 );
#endif // 0
XmString text = XmStringCreateLtoR ((char *)(const char*)label, XmSTRING_DEFAULT_CHARSET);
wxXmString text( label );
XmFontList fontList = (XmFontList) m_font.GetFontList(1.0, XtDisplay(parentWidget));
WXFontType fontType = m_font.GetFontType(XtDisplay(parentWidget));
m_labelWidget = XtVaCreateManagedWidget ((char*) (const char*) name,
xmLabelWidgetClass,
borderWidget ? borderWidget : parentWidget,
XmNfontList, fontList,
XmNlabelString, text,
wxFont::GetFontTag(), fontType,
XmNlabelString, text(),
XmNalignment,
((style & wxALIGN_RIGHT) ? XmALIGNMENT_END :
((style & wxALIGN_CENTRE) ? XmALIGNMENT_CENTER :
XmALIGNMENT_BEGINNING)),
NULL);
XmStringFree (text);
m_mainWidget = borderWidget ? borderWidget : m_labelWidget;
SetCanAddEventHandler(TRUE);

View File

@ -1249,14 +1249,11 @@ void wxDoChangeBackgroundColour(WXWidget widget, wxColour& backgroundColour, boo
extern void wxDoChangeFont(WXWidget widget, wxFont& font)
{
// lesstif 0.87 hangs here, but 0.93 does not
#if !defined(LESSTIF_VERSION) \
|| (defined(LesstifVersion) && LesstifVersion >= 93)
// Lesstif 0.87 hangs here, but 0.93 does not
#if !wxCHECK_LESSTIF() || wxCHECK_LESSTIF_VERSION( 0, 93 )
Widget w = (Widget)widget;
XmFontList fontList = (XmFontList)font.GetFontList(1.0, XtDisplay(w));
XtVaSetValues( w,
XmNfontList, fontList,
wxFont::GetFontTag(), font.GetFontType( XtDisplay(w) ),
NULL );
#endif

View File

@ -1997,7 +1997,8 @@ static void wxCanvasEnterLeave(Widget drawingArea,
}
// Fix to make it work under Motif 1.0 (!)
static void wxCanvasMotionEvent (Widget WXUNUSED(drawingArea), XButtonEvent * WXUNUSED(event))
static void wxCanvasMotionEvent (Widget WXUNUSED(drawingArea),
XButtonEvent *WXUNUSED(event))
{
#if XmVersion <= 1000
XmDrawingAreaCallbackStruct cbs;