Fix crash on exit with Lesstif (and possibly Motif 1.x).

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@34704 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Mattia Barbon
2005-06-19 19:11:21 +00:00
parent 3550706df7
commit 7360894949
12 changed files with 100 additions and 77 deletions

View File

@@ -105,6 +105,8 @@ public:
// returns either a XmFontList or XmRendition, depending // returns either a XmFontList or XmRendition, depending
// on Motif version // on Motif version
WXFontType GetFontType(WXDisplay* display) const; WXFontType GetFontType(WXDisplay* display) const;
// like the function above but does a copy for XmFontList
WXFontType GetFontTypeC(WXDisplay* display) const;
static WXString GetFontTag(); static WXString GetFontTag();
protected: protected:
virtual void DoSetNativeFontInfo( const wxNativeFontInfo& info ); virtual void DoSetNativeFontInfo( const wxNativeFontInfo& info );

View File

@@ -76,7 +76,7 @@ bool wxButton::Create(wxWindow *parent, wxWindowID id, const wxString& lbl,
m_mainWidget = (WXWidget) XtVaCreateManagedWidget ("button", m_mainWidget = (WXWidget) XtVaCreateManagedWidget ("button",
xmPushButtonWidgetClass, xmPushButtonWidgetClass,
parentWidget, parentWidget,
wxFont::GetFontTag(), m_font.GetFontType(XtDisplay(parentWidget)), wxFont::GetFontTag(), m_font.GetFontTypeC(XtDisplay(parentWidget)),
XmNlabelString, text(), XmNlabelString, text(),
XmNrecomputeSize, False, XmNrecomputeSize, False,
// See comment for wxButton::SetDefault // See comment for wxButton::SetDefault

View File

@@ -73,7 +73,7 @@ bool wxCheckBox::Create(wxWindow *parent, wxWindowID id, const wxString& label,
m_mainWidget = (WXWidget) XtVaCreateManagedWidget ("toggle", m_mainWidget = (WXWidget) XtVaCreateManagedWidget ("toggle",
xmToggleButtonWidgetClass, parentWidget, xmToggleButtonWidgetClass, parentWidget,
wxFont::GetFontTag(), m_font.GetFontType(XtDisplay(parentWidget)), wxFont::GetFontTag(), m_font.GetFontTypeC(XtDisplay(parentWidget)),
XmNlabelString, text(), XmNlabelString, text(),
XmNrecomputeSize, False, XmNrecomputeSize, False,
// XmNindicatorOn, XmINDICATOR_CHECK_BOX, // XmNindicatorOn, XmINDICATOR_CHECK_BOX,

View File

@@ -459,19 +459,22 @@ void wxChoice::ChangeFont(bool keepOriginalSize)
// back again. TODO: a better way in Motif? // back again. TODO: a better way in Motif?
if (m_font.Ok()) if (m_font.Ok())
{ {
Display* dpy = XtDisplay((Widget) m_mainWidget);
int width, height, width1, height1; int width, height, width1, height1;
GetSize(& width, & height); GetSize(& width, & height);
WXFontType fontType =
m_font.GetFontType(XtDisplay((Widget) m_mainWidget));
WXString fontTag = wxFont::GetFontTag(); WXString fontTag = wxFont::GetFontTag();
XtVaSetValues ((Widget) m_formWidget, fontTag, fontType, NULL); XtVaSetValues ((Widget) m_formWidget,
XtVaSetValues ((Widget) m_buttonWidget, fontTag, fontType, NULL); fontTag, m_font.GetFontTypeC(dpy),
NULL);
XtVaSetValues ((Widget) m_buttonWidget,
fontTag, m_font.GetFontTypeC(dpy),
NULL);
for( size_t i = 0; i < m_noStrings; ++i ) for( size_t i = 0; i < m_noStrings; ++i )
XtVaSetValues( (Widget)m_widgetArray[i], XtVaSetValues( (Widget)m_widgetArray[i],
fontTag, fontType, fontTag, m_font.GetFontTypeC(dpy),
NULL ); NULL );
GetSize(& width1, & height1); GetSize(& width1, & height1);

View File

@@ -46,6 +46,12 @@
IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject) IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject)
#if wxCHECK_MOTIF_VERSION( 2, 0 ) && !wxCHECK_LESSTIF()
#define wxUSE_RENDER_TABLE 1
#else
#define wxUSE_RENDER_TABLE 0
#endif
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// private classes // private classes
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -59,8 +65,9 @@ public:
~wxXFont(); ~wxXFont();
WXFontStructPtr m_fontStruct; // XFontStruct WXFontStructPtr m_fontStruct; // XFontStruct
#if !wxUSE_RENDER_TABLE
WXFontList m_fontList; // Motif XmFontList WXFontList m_fontList; // Motif XmFontList
#if wxCHECK_MOTIF_VERSION( 2, 0 ) #else // if wxUSE_RENDER_TABLE
WXRenderTable m_renderTable; // Motif XmRenderTable WXRenderTable m_renderTable; // Motif XmRenderTable
#endif #endif
WXDisplay* m_display; // XDisplay WXDisplay* m_display; // XDisplay
@@ -127,8 +134,9 @@ protected:
wxXFont::wxXFont() wxXFont::wxXFont()
{ {
m_fontStruct = (WXFontStructPtr) 0; m_fontStruct = (WXFontStructPtr) 0;
#if !wxUSE_RENDER_TABLE
m_fontList = (WXFontList) 0; m_fontList = (WXFontList) 0;
#if wxCHECK_MOTIF_VERSION( 2, 0 ) #else // if wxUSE_RENDER_TABLE
m_renderTable = (WXRenderTable) 0; m_renderTable = (WXRenderTable) 0;
#endif #endif
m_display = (WXDisplay*) 0; m_display = (WXDisplay*) 0;
@@ -137,16 +145,20 @@ wxXFont::wxXFont()
wxXFont::~wxXFont() wxXFont::~wxXFont()
{ {
XmFontList fontList = (XmFontList) m_fontList; #if !wxUSE_RENDER_TABLE
XmFontListFree (fontList); if (m_fontList)
XmFontListFree ((XmFontList) m_fontList);
#if wxCHECK_MOTIF_VERSION( 2, 0 ) && !wxCHECK_LESSTIF() m_fontList = NULL;
XmRenderTable renderTable = (XmRenderTable) m_renderTable; #else // if wxUSE_RENDER_TABLE
XmRenderTableFree (renderTable); if (m_renderTable)
XmRenderTableFree ((XmRenderTable) m_renderTable);
m_renderTable = NULL;
#endif #endif
// TODO: why does freeing the font produce a segv??? // TODO: why does freeing the font produce a segv???
// Note that XFreeFont wasn't called in wxWin 1.68 either. // Note that XFreeFont wasn't called in wxWin 1.68 either.
// MBN: probably some interaction with fonts being still
// in use in some widgets...
// XFontStruct* fontStruct = (XFontStruct*) m_fontStruct; // XFontStruct* fontStruct = (XFontStruct*) m_fontStruct;
// XFreeFont((Display*) m_display, fontStruct); // XFreeFont((Display*) m_display, fontStruct);
} }
@@ -544,10 +556,10 @@ wxXFont* wxFont::GetInternalFont(double scale, WXDisplay* display) const
f->m_fontStruct = (WXFontStructPtr)font; f->m_fontStruct = (WXFontStructPtr)font;
f->m_display = ( display ? display : wxGetDisplay() ); f->m_display = ( display ? display : wxGetDisplay() );
f->m_scale = intScale; f->m_scale = intScale;
#if !wxUSE_RENDER_TABLE
f->m_fontList = XmFontListCreate ((XFontStruct*) font, XmSTRING_DEFAULT_CHARSET); f->m_fontList = XmFontListCreate ((XFontStruct*) font, XmSTRING_DEFAULT_CHARSET);
M_FONTDATA->m_fonts.Append(f); M_FONTDATA->m_fonts.Append(f);
#else // if wxUSE_RENDER_TABLE
#if wxCHECK_MOTIF_VERSION( 2, 0 ) && !wxCHECK_LESSTIF()
XmRendition rendition; XmRendition rendition;
XmRenderTable renderTable; XmRenderTable renderTable;
Arg args[5]; Arg args[5];
@@ -577,34 +589,52 @@ WXFontStructPtr wxFont::GetFontStruct(double scale, WXDisplay* display) const
WXFontList wxFont::GetFontList(double scale, WXDisplay* display) const WXFontList wxFont::GetFontList(double scale, WXDisplay* display) const
{ {
#if !wxUSE_RENDER_TABLE
wxXFont* f = GetInternalFont(scale, display); wxXFont* f = GetInternalFont(scale, display);
return (f ? f->m_fontList : (WXFontList) 0); return (f ? f->m_fontList : (WXFontList) 0);
#else
return NULL;
#endif
} }
// declared in the header, can't use wxUSE_RENDER_TABLE
#if wxCHECK_MOTIF_VERSION( 2, 0 ) #if wxCHECK_MOTIF_VERSION( 2, 0 )
WXRenderTable wxFont::GetRenderTable(WXDisplay* display) const WXRenderTable wxFont::GetRenderTable(WXDisplay* display) const
{ {
#if wxUSE_RENDER_TABLE
wxXFont* f = GetInternalFont(1.0, display); wxXFont* f = GetInternalFont(1.0, display);
return (f ? f->m_renderTable : (WXFontList) 0); return (f ? f->m_renderTable : (WXFontList) 0);
#else
return NULL;
#endif
} }
#endif #endif
WXFontType wxFont::GetFontType(WXDisplay* display) const WXFontType wxFont::GetFontType(WXDisplay* display) const
{ {
#if wxCHECK_MOTIF_VERSION( 2, 0 ) && !wxCHECK_LESSTIF() #if wxUSE_RENDER_TABLE
return Ok() ? GetRenderTable(display) : NULL; return Ok() ? GetRenderTable(display) : NULL;
#else #else
return Ok() ? GetFontList(1.0, display) : NULL; return Ok() ? GetFontList(1.0, display) : NULL;
#endif #endif
} }
WXFontType wxFont::GetFontTypeC(WXDisplay* display) const
{
#if wxUSE_RENDER_TABLE
return Ok() ? GetRenderTable(display) : NULL;
#else
return Ok() ? XmFontListCopy( (XmFontList)GetFontList(1.0, display) ) : NULL;
#endif
}
/*static*/ WXString wxFont::GetFontTag() /*static*/ WXString wxFont::GetFontTag()
{ {
#if wxCHECK_MOTIF_VERSION( 2, 0 ) && !wxCHECK_LESSTIF() #if wxUSE_RENDER_TABLE
return (WXString)XmNrenderTable; return (WXString)XmNrenderTable;
#else #else
return (WXString)XmNfontList; return (WXString)XmNfontList;

View File

@@ -95,13 +95,7 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id,
m_backgroundColour = * wxWHITE; m_backgroundColour = * wxWHITE;
Widget parentWidget = (Widget) parent->GetClientWidget(); Widget parentWidget = (Widget) parent->GetClientWidget();
Display* dpy = XtDisplay(parentWidget);
WXFontType fontType = (WXFontType)NULL;
if( m_font.Ok() )
{
fontType = m_font.GetFontType(XtDisplay(parentWidget));
}
Arg args[4]; Arg args[4];
int count = 0; int count = 0;
@@ -111,9 +105,10 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id,
( m_windowStyle & wxLB_EXTENDED ) ? XmEXTENDED_SELECT : ( m_windowStyle & wxLB_EXTENDED ) ? XmEXTENDED_SELECT :
XmBROWSE_SELECT ); XmBROWSE_SELECT );
++count; ++count;
if( fontType ) if( m_font.Ok() )
{ {
XtSetArg( args[count], (String)wxFont::GetFontTag(), fontType ); XtSetArg( args[count],
(String)wxFont::GetFontTag(), m_font.GetFontTypeC(dpy) );
++count; ++count;
} }
if( m_windowStyle & wxLB_ALWAYS_SB ) if( m_windowStyle & wxLB_ALWAYS_SB )

View File

@@ -661,15 +661,15 @@ void wxMenu::ChangeFont(bool keepOriginalSize)
if (!m_font.Ok() || !m_menuWidget) if (!m_font.Ok() || !m_menuWidget)
return; return;
WXFontType fontType = m_font.GetFontType(XtDisplay((Widget) m_menuWidget)); Display* dpy = XtDisplay((Widget) m_menuWidget);
XtVaSetValues ((Widget) m_menuWidget, XtVaSetValues ((Widget) m_menuWidget,
wxFont::GetFontTag(), fontType, wxFont::GetFontTag(), m_font.GetFontTypeC(dpy),
NULL); NULL);
if (m_buttonWidget) if (m_buttonWidget)
{ {
XtVaSetValues ((Widget) m_buttonWidget, XtVaSetValues ((Widget) m_buttonWidget,
wxFont::GetFontTag(), fontType, wxFont::GetFontTag(), m_font.GetFontTypeC(dpy),
NULL); NULL);
} }
@@ -681,7 +681,7 @@ void wxMenu::ChangeFont(bool keepOriginalSize)
if (m_menuWidget && item->GetButtonWidget() && m_font.Ok()) if (m_menuWidget && item->GetButtonWidget() && m_font.Ok())
{ {
XtVaSetValues ((Widget) item->GetButtonWidget(), XtVaSetValues ((Widget) item->GetButtonWidget(),
wxFont::GetFontTag(), fontType, wxFont::GetFontTag(), m_font.GetFontTypeC(dpy),
NULL); NULL);
} }
if (item->GetSubMenu()) if (item->GetSubMenu())

View File

@@ -73,6 +73,7 @@ bool wxRadioBox::Create(wxWindow *parent, wxWindowID id, const wxString& title,
m_majorDim = majorDim ; m_majorDim = majorDim ;
Widget parentWidget = (Widget) parent->GetClientWidget(); Widget parentWidget = (Widget) parent->GetClientWidget();
Display* dpy = XtDisplay(parentWidget);
m_mainWidget = XtVaCreateWidget ("radioboxframe", m_mainWidget = XtVaCreateWidget ("radioboxframe",
xmFrameWidgetClass, parentWidget, xmFrameWidgetClass, parentWidget,
@@ -82,8 +83,6 @@ bool wxRadioBox::Create(wxWindow *parent, wxWindowID id, const wxString& title,
wxString label1(wxStripMenuCodes(title)); wxString label1(wxStripMenuCodes(title));
WXFontType fontType = m_font.GetFontType(XtDisplay(parentWidget));
if (!label1.empty()) if (!label1.empty())
{ {
wxXmString text(label1); wxXmString text(label1);
@@ -94,10 +93,9 @@ bool wxRadioBox::Create(wxWindow *parent, wxWindowID id, const wxString& title,
: xmLabelGadgetClass, : xmLabelGadgetClass,
(Widget)m_mainWidget, (Widget)m_mainWidget,
#else #else
xmLabelWidgetClass, xmLabelWidgetClass, (Widget)m_mainWidget,
(Widget)m_mainWidget,
#endif #endif
wxFont::GetFontTag(), fontType, wxFont::GetFontTag(), m_font.GetFontTypeC(dpy),
XmNlabelString, text(), XmNlabelString, text(),
// XmNframeChildType is not in Motif 1.2, nor in Lesstif, // XmNframeChildType is not in Motif 1.2, nor in Lesstif,
// if it was compiled with 1.2 compatibility // if it was compiled with 1.2 compatibility
@@ -107,8 +105,7 @@ bool wxRadioBox::Create(wxWindow *parent, wxWindowID id, const wxString& title,
#else #else
XmNchildType, XmFRAME_TITLE_CHILD, XmNchildType, XmFRAME_TITLE_CHILD,
#endif #endif
XmNchildVerticalAlignment, XmNchildVerticalAlignment, XmALIGNMENT_CENTER,
XmALIGNMENT_CENTER,
NULL); NULL);
} }
@@ -132,13 +129,14 @@ bool wxRadioBox::Create(wxWindow *parent, wxWindowID id, const wxString& title,
{ {
wxString str(wxStripMenuCodes(choices[i])); wxString str(wxStripMenuCodes(choices[i]));
m_radioButtonLabels.push_back(str); m_radioButtonLabels.push_back(str);
Widget radioItem = XtVaCreateManagedWidget (wxConstCast(str.c_str(), char), Widget radioItem = XtVaCreateManagedWidget (
wxConstCast(str.c_str(), char),
#if wxUSE_GADGETS #if wxUSE_GADGETS
xmToggleButtonGadgetClass, radioBoxWidget, xmToggleButtonGadgetClass, radioBoxWidget,
#else #else
xmToggleButtonWidgetClass, radioBoxWidget, xmToggleButtonWidgetClass, radioBoxWidget,
#endif #endif
wxFont::GetFontTag(), fontType, wxFont::GetFontTag(), m_font.GetFontTypeC(dpy),
NULL); NULL);
m_radioButtons.push_back((WXWidget)radioItem); m_radioButtons.push_back((WXWidget)radioItem);
XtAddCallback (radioItem, XmNvalueChangedCallback, XtAddCallback (radioItem, XmNvalueChangedCallback,
@@ -356,16 +354,13 @@ void wxRadioBox::ChangeFont(bool keepOriginalSize)
{ {
wxWindow::ChangeFont(keepOriginalSize); wxWindow::ChangeFont(keepOriginalSize);
WXFontType fontType =
m_font.GetFontType(XtDisplay((Widget) GetTopWidget()));
int i; int i;
for (i = 0; i < m_noItems; i++) for (i = 0; i < m_noItems; i++)
{ {
WXWidget radioButton = m_radioButtons[i]; WXWidget radioButton = m_radioButtons[i];
XtVaSetValues ((Widget) radioButton, XtVaSetValues ((Widget) radioButton,
wxFont::GetFontTag(), fontType, wxFont::GetFontTag(), m_font.GetFontTypeC(XtDisplay((Widget) GetTopWidget())),
NULL); NULL);
} }
} }

View File

@@ -56,20 +56,19 @@ bool wxRadioButton::Create(wxWindow *parent, wxWindowID id,
return false; return false;
Widget parentWidget = (Widget) parent->GetClientWidget(); Widget parentWidget = (Widget) parent->GetClientWidget();
Display* dpy = XtDisplay(parentWidget);
wxString label1(wxStripMenuCodes(label)); wxString label1(wxStripMenuCodes(label));
wxXmString text( label1 ); wxXmString text( label1 );
WXFontType fontType = m_font.GetFontType(XtDisplay(parentWidget));
Widget radioButtonWidget = XtVaCreateManagedWidget ("toggle", Widget radioButtonWidget = XtVaCreateManagedWidget ("toggle",
#if wxUSE_GADGETS #if wxUSE_GADGETS
xmToggleButtonGadgetClass, parentWidget, xmToggleButtonGadgetClass, parentWidget,
#else #else
xmToggleButtonWidgetClass, parentWidget, xmToggleButtonWidgetClass, parentWidget,
#endif #endif
wxFont::GetFontTag(), fontType, wxFont::GetFontTag(), m_font.GetFontTypeC(dpy),
XmNlabelString, text(), XmNlabelString, text(),
XmNfillOnSelect, True, XmNfillOnSelect, True,
XmNindicatorType, XmONE_OF_MANY, // diamond-shape XmNindicatorType, XmONE_OF_MANY, // diamond-shape

View File

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

View File

@@ -51,15 +51,14 @@ bool wxStaticText::Create(wxWindow *parent, wxWindowID id,
Widget borderWidget = Widget borderWidget =
(Widget) wxCreateBorderWidget( (WXWidget)parentWidget, style ); (Widget) wxCreateBorderWidget( (WXWidget)parentWidget, style );
wxXmString text( wxStripMenuCodes( label ) ); wxXmString text( wxStripMenuCodes( label ) );
WXFontType fontType = m_font.GetFontType(XtDisplay(parentWidget));
m_labelWidget = XtVaCreateManagedWidget (wxConstCast(name.c_str(), char), m_labelWidget =
XtVaCreateManagedWidget (wxConstCast(name.c_str(), char),
xmLabelWidgetClass, xmLabelWidgetClass,
borderWidget ? borderWidget : parentWidget, borderWidget ? borderWidget : parentWidget,
wxFont::GetFontTag(), fontType, wxFont::GetFontTag(), m_font.GetFontTypeC(XtDisplay(parentWidget)),
XmNlabelString, text(), XmNlabelString, text(),
XmNalignment, XmNalignment, ((style & wxALIGN_RIGHT) ? XmALIGNMENT_END :
((style & wxALIGN_RIGHT) ? XmALIGNMENT_END :
((style & wxALIGN_CENTRE) ? XmALIGNMENT_CENTER : ((style & wxALIGN_CENTRE) ? XmALIGNMENT_CENTER :
XmALIGNMENT_BEGINNING)), XmALIGNMENT_BEGINNING)),
NULL); NULL);

View File

@@ -929,7 +929,7 @@ extern void wxDoChangeFont(WXWidget widget, wxFont& font)
#if !wxCHECK_LESSTIF() || wxCHECK_LESSTIF_VERSION( 0, 93 ) #if !wxCHECK_LESSTIF() || wxCHECK_LESSTIF_VERSION( 0, 93 )
Widget w = (Widget)widget; Widget w = (Widget)widget;
XtVaSetValues( w, XtVaSetValues( w,
wxFont::GetFontTag(), font.GetFontType( XtDisplay(w) ), wxFont::GetFontTag(), font.GetFontTypeC( XtDisplay(w) ),
NULL ); NULL );
#endif #endif