Rework wxMotif font/color inheritance so it works

like in the other ports.  Avoid setting foreground/background
color for windows and let the toolkit use the natural color.
As an intermediate step font is still explicitly set.

  Handle the cases where m_foregroundColour, m_backgroundColour ir m_font
are not initialized.

  Set default (overridable) X resources to emulate the old look.

  Unify wxMOTIF_NEW_FONT_HANDLING with wxMOTIF_USE_RENDER_TABLE.

  Minor unrelated (sizing) fixes to wxCheckListBox, wxStaticText, wxTextCtrl.

  Tagged with MOTIF_BEFORE_COLOUR_FONT_INHERITANCE before the changes.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@45312 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Mattia Barbon
2007-04-07 21:18:33 +00:00
parent d5c87edd82
commit 105fbe1ffa
40 changed files with 368 additions and 206 deletions

View File

@@ -13,12 +13,11 @@
#define _WX_FONT_H_ #define _WX_FONT_H_
#if __WXMOTIF20__ && !__WXLESSTIF__ #if __WXMOTIF20__ && !__WXLESSTIF__
#define wxMOTIF_NEW_FONT_HANDLING 1
#define wxMOTIF_USE_RENDER_TABLE 1 #define wxMOTIF_USE_RENDER_TABLE 1
#else #else
#define wxMOTIF_NEW_FONT_HANDLING 0
#define wxMOTIF_USE_RENDER_TABLE 0 #define wxMOTIF_USE_RENDER_TABLE 0
#endif #endif
#define wxMOTIF_NEW_FONT_HANDLING wxMOTIF_USE_RENDER_TABLE
class wxXFont; class wxXFont;
@@ -93,18 +92,15 @@ public:
WXDisplay* display = NULL) const; WXDisplay* display = NULL) const;
// These two are helper functions for convenient access of the above. // These two are helper functions for convenient access of the above.
#if wxMOTIF_NEW_FONT_HANDLING
WXFontSet GetFontSet(double scale, WXDisplay* display = NULL) const;
#else // if !wxMOTIF_NEW_FONT_HANDLING
WXFontStructPtr GetFontStruct(double scale = 1.0,
WXDisplay* display = NULL) const;
#endif // wxMOTIF_NEW_FONT_HANDLING
#if wxMOTIF_USE_RENDER_TABLE #if wxMOTIF_USE_RENDER_TABLE
WXFontSet GetFontSet(double scale, WXDisplay* display = NULL) const;
WXRenderTable GetRenderTable(WXDisplay* display) const; WXRenderTable GetRenderTable(WXDisplay* display) const;
#else // if !wxMOTIF_USE_RENDER_TABLE #else // if !wxMOTIF_USE_RENDER_TABLE
WXFontStructPtr GetFontStruct(double scale = 1.0,
WXDisplay* display = NULL) const;
WXFontList GetFontList(double scale = 1.0, WXFontList GetFontList(double scale = 1.0,
WXDisplay* display = NULL) const; WXDisplay* display = NULL) const;
#endif // wxMOTIF_USE_RENDER_TABLE #endif // !wxMOTIF_USE_RENDER_TABLE
// returns either a XmFontList or XmRenderTable, depending // returns either a XmFontList or XmRenderTable, depending
// on Motif version // on Motif version
WXFontType GetFontType(WXDisplay* display) const; WXFontType GetFontType(WXDisplay* display) const;

View File

@@ -106,6 +106,9 @@ extern void wxGetTextExtent(WXDisplay* display, const wxFont& font,
double scale, double scale,
const wxString& string, int* width, int* height, const wxString& string, int* width, int* height,
int* ascent, int* descent); int* ascent, int* descent);
extern void wxGetTextExtent(const wxWindow* window, const wxString& str,
int* width, int* height,
int* ascent, int* descent);
#define wxNO_COLORS 0x00 #define wxNO_COLORS 0x00
#define wxBACK_COLORS 0x01 #define wxBACK_COLORS 0x01

View File

@@ -55,6 +55,7 @@ public:
virtual void DoSetLabel(const wxString& str); virtual void DoSetLabel(const wxString& str);
virtual wxString DoGetLabel() const; virtual wxString DoGetLabel() const;
virtual wxSize DoGetBestSize() const;
protected: protected:
WXWidget m_labelWidget; WXWidget m_labelWidget;
}; };

View File

@@ -147,6 +147,12 @@ public:
// Process idle (send update events) // Process idle (send update events)
void OnInternalIdle(); void OnInternalIdle();
// post-creation activities
void PostCreation();
// pre-creation activities
void PreCreation();
protected: protected:
// Responds to colour changes: passes event on to children. // Responds to colour changes: passes event on to children.
void OnSysColourChanged(wxSysColourChangedEvent& event); void OnSysColourChanged(wxSysColourChangedEvent& event);

View File

@@ -158,8 +158,6 @@ bool wxNotebook::Create(wxWindow *parent,
if (!wxControl::Create(parent, id, pos, size, style|wxNO_BORDER, wxDefaultValidator, name)) if (!wxControl::Create(parent, id, pos, size, style|wxNO_BORDER, wxDefaultValidator, name))
return false; return false;
SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));
SetTabView(new wxNotebookTabView(this)); SetTabView(new wxNotebookTabView(this));
return true; return true;

View File

@@ -85,7 +85,8 @@ void wxTabControl::OnDraw(wxDC& dc, bool lastInRow)
// Draw grey background // Draw grey background
if (m_view->GetTabStyle() & wxTAB_STYLE_COLOUR_INTERIOR) if (m_view->GetTabStyle() & wxTAB_STYLE_COLOUR_INTERIOR)
{ {
dc.SetBrush(*m_view->GetBackgroundBrush()); if(m_view->GetBackgroundBrush())
dc.SetBrush(*m_view->GetBackgroundBrush());
// Add 1 because the pen is transparent. Under Motif, may be different. // Add 1 because the pen is transparent. Under Motif, may be different.
#ifdef __WXMOTIF__ #ifdef __WXMOTIF__
@@ -523,11 +524,11 @@ wxTabView::wxTabView(long style)
m_tabViewRect.x = 300; m_tabViewRect.x = 300;
m_highlightColour = *wxWHITE; m_highlightColour = *wxWHITE;
m_shadowColour = wxColour(128, 128, 128); m_shadowColour = wxColour(128, 128, 128);
m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE); // m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
m_textColour = *wxBLACK; m_textColour = *wxBLACK;
m_highlightPen = wxWHITE_PEN; m_highlightPen = wxWHITE_PEN;
m_shadowPen = wxGREY_PEN; m_shadowPen = wxGREY_PEN;
SetBackgroundColour(m_backgroundColour); // SetBackgroundColour(m_backgroundColour);
m_tabFont = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); m_tabFont = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
m_tabSelectedFont = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); m_tabSelectedFont = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
m_window = (wxWindow *) NULL; m_window = (wxWindow *) NULL;
@@ -797,7 +798,8 @@ void wxTabView::Draw(wxDC& dc)
if (GetTabStyle() & wxTAB_STYLE_COLOUR_INTERIOR) if (GetTabStyle() & wxTAB_STYLE_COLOUR_INTERIOR)
{ {
dc.SetPen(*wxTRANSPARENT_PEN); dc.SetPen(*wxTRANSPARENT_PEN);
dc.SetBrush(*GetBackgroundBrush()); if(GetBackgroundBrush())
dc.SetBrush(*GetBackgroundBrush());
// Add 1 because the pen is transparent. Under Motif, may be different. // Add 1 because the pen is transparent. Under Motif, may be different.
dc.DrawRectangle( dc.DrawRectangle(

View File

@@ -99,15 +99,15 @@ static int wxXErrorHandler(Display *dpy, XErrorEvent *xevent)
bool wxApp::Initialize(int& argcOrig, wxChar **argvOrig) bool wxApp::Initialize(int& argcOrig, wxChar **argvOrig)
{ {
#if wxUSE_INTL
wxFont::SetDefaultEncoding(wxLocale::GetSystemEncoding());
#endif
if ( !wxAppBase::Initialize(argcOrig, argvOrig) ) if ( !wxAppBase::Initialize(argcOrig, argvOrig) )
return false; return false;
wxWidgetHashTable = new wxHashTable(wxKEY_INTEGER); wxWidgetHashTable = new wxHashTable(wxKEY_INTEGER);
#if wxUSE_INTL
wxFont::SetDefaultEncoding(wxLocale::GetSystemEncoding());
#endif
return true; return true;
} }
@@ -197,10 +197,17 @@ static char *fallbackResources[] = {
wxMOTIF_STR("*sgiMode: True"), wxMOTIF_STR("*sgiMode: True"),
wxMOTIF_STR("*useSchemes: all"), wxMOTIF_STR("*useSchemes: all"),
#else // !__SGI__ #else // !__SGI__
wxMOTIF_STR("*menuBar.marginHeight: 0"), #if !wxMOTIF_USE_RENDER_TABLE
wxMOTIF_STR("*menuBar.shadowThickness: 1"), wxMOTIF_STR("*.fontList: -*-helvetica-medium-r-normal-*-*-120-*-*-*-*-*-*"),
wxMOTIF_STR("*background: #c0c0c0"), #else
wxMOTIF_STR("*foreground: black"), wxMOTIF_STR("*wxDefaultRendition.fontName: -*-helvetica-medium-r-normal-*-*-120-*-*-*-*-*-*"),
wxMOTIF_STR("*wxDefaultRendition.fontType: FONT_IS_FONTSET"),
wxMOTIF_STR("*.renderTable: wxDefaultRendition"),
#endif
wxMOTIF_STR("*listBox.background: white"),
wxMOTIF_STR("*text.background: white"),
wxMOTIF_STR("*comboBox.Text.background: white"),
wxMOTIF_STR("*comboBox.List.background: white"),
#endif // __SGI__/!__SGI__ #endif // __SGI__/!__SGI__
NULL NULL
}; };

View File

@@ -51,6 +51,7 @@ bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id,
{ {
if( !CreateControl( parent, id, pos, size, style, validator, name ) ) if( !CreateControl( parent, id, pos, size, style, validator, name ) )
return false; return false;
PreCreation();
m_bmpNormal = m_bmpNormalOriginal = bitmap; m_bmpNormal = m_bmpNormalOriginal = bitmap;
m_bmpSelected = m_bmpSelectedOriginal = bitmap; m_bmpSelected = m_bmpSelectedOriginal = bitmap;
@@ -81,12 +82,6 @@ bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id,
m_mainWidget = (WXWidget) buttonWidget; m_mainWidget = (WXWidget) buttonWidget;
ChangeFont(false);
ChangeBackgroundColour ();
DoSetBitmap();
XtAddCallback (buttonWidget, XtAddCallback (buttonWidget,
XmNactivateCallback, (XtCallbackProc) wxButtonCallback, XmNactivateCallback, (XtCallbackProc) wxButtonCallback,
(XtPointer) this); (XtPointer) this);
@@ -95,6 +90,9 @@ bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id,
if( size.x != -1 ) best.x = size.x; if( size.x != -1 ) best.x = size.x;
if( size.y != -1 ) best.y = size.y; if( size.y != -1 ) best.y = size.y;
PostCreation();
DoSetBitmap();
AttachWidget (parent, m_mainWidget, (WXWidget) NULL, AttachWidget (parent, m_mainWidget, (WXWidget) NULL,
pos.x, pos.y, best.x, best.y); pos.x, pos.y, best.x, best.y);

View File

@@ -57,6 +57,7 @@ bool wxButton::Create(wxWindow *parent, wxWindowID id, const wxString& lbl,
if( !CreateControl( parent, id, pos, size, style, validator, name ) ) if( !CreateControl( parent, id, pos, size, style, validator, name ) )
return false; return false;
PreCreation();
wxXmString text( GetLabelText(label) ); wxXmString text( GetLabelText(label) );
@@ -89,11 +90,10 @@ bool wxButton::Create(wxWindow *parent, wxWindowID id, const wxString& lbl,
if( size.x != -1 ) best.x = size.x; if( size.x != -1 ) best.x = size.x;
if( size.y != -1 ) best.y = size.y; if( size.y != -1 ) best.y = size.y;
PostCreation();
AttachWidget (parent, m_mainWidget, (WXWidget) NULL, AttachWidget (parent, m_mainWidget, (WXWidget) NULL,
pos.x, pos.y, best.x, best.y); pos.x, pos.y, best.x, best.y);
ChangeBackgroundColour();
return true; return true;
} }

View File

@@ -44,7 +44,6 @@
#define wxHAS_3STATE 0 #define wxHAS_3STATE 0
#endif #endif
#include "wx/motif/private.h" #include "wx/motif/private.h"
void wxCheckBoxCallback (Widget w, XtPointer clientData, void wxCheckBoxCallback (Widget w, XtPointer clientData,
@@ -62,6 +61,7 @@ bool wxCheckBox::Create(wxWindow *parent, wxWindowID id, const wxString& label,
if( !wxControl::CreateControl( parent, id, pos, size, style, validator, if( !wxControl::CreateControl( parent, id, pos, size, style, validator,
name ) ) name ) )
return false; return false;
PreCreation();
wxXmString text( GetLabelText(label) ); wxXmString text( GetLabelText(label) );
@@ -85,10 +85,10 @@ bool wxCheckBox::Create(wxWindow *parent, wxWindowID id, const wxString& label,
XmToggleButtonSetState ((Widget) m_mainWidget, False, True); XmToggleButtonSetState ((Widget) m_mainWidget, False, True);
PostCreation();
AttachWidget( parent, m_mainWidget, (WXWidget)NULL, AttachWidget( parent, m_mainWidget, (WXWidget)NULL,
pos.x, pos.y, size.x, size.y ); pos.x, pos.y, size.x, size.y );
ChangeBackgroundColour();
return true; return true;
} }
@@ -144,6 +144,9 @@ void wxCheckBoxCallback (Widget WXUNUSED(w), XtPointer clientData,
void wxCheckBox::ChangeBackgroundColour() void wxCheckBox::ChangeBackgroundColour()
{ {
if (!m_backgroundColour.Ok())
return;
wxComputeColours (XtDisplay((Widget) m_mainWidget), & m_backgroundColour, wxComputeColours (XtDisplay((Widget) m_mainWidget), & m_backgroundColour,
(wxColour*) NULL); (wxColour*) NULL);

View File

@@ -134,7 +134,7 @@ void wxCheckListBox::Check(unsigned int uiIndex, bool bCheck)
void wxCheckListBox::DoToggleItem( int n, int x ) void wxCheckListBox::DoToggleItem( int n, int x )
{ {
if( x < 23 ) if( x > 0 && x < 23 )
{ {
wxString label = wxListBox::GetString(n); wxString label = wxListBox::GetString(n);
label[1u] = (!::IsChecked(label)) ? checkChar : uncheckChar; label[1u] = (!::IsChecked(label)) ? checkChar : uncheckChar;

View File

@@ -71,6 +71,7 @@ bool wxChoice::Create(wxWindow *parent, wxWindowID id,
{ {
if ( !CreateControl(parent, id, pos, size, style, validator, name) ) if ( !CreateControl(parent, id, pos, size, style, validator, name) )
return false; return false;
PreCreation();
Widget parentWidget = (Widget) parent->GetClientWidget(); Widget parentWidget = (Widget) parent->GetClientWidget();
@@ -138,9 +139,7 @@ bool wxChoice::Create(wxWindow *parent, wxWindowID id,
XtVaSetValues((Widget) m_formWidget, XmNresizePolicy, XmRESIZE_NONE, NULL); XtVaSetValues((Widget) m_formWidget, XmNresizePolicy, XmRESIZE_NONE, NULL);
ChangeFont(false); PostCreation();
ChangeBackgroundColour();
AttachWidget (parent, m_buttonWidget, m_formWidget, AttachWidget (parent, m_buttonWidget, m_formWidget,
pos.x, pos.y, bestSize.x, bestSize.y); pos.x, pos.y, bestSize.x, bestSize.y);
@@ -450,7 +449,7 @@ void wxChoice::ChangeFont(bool keepOriginalSize)
// Note that this causes the widget to be resized back // Note that this causes the widget to be resized back
// to its original size! We therefore have to set the size // to its original size! We therefore have to set the size
// back again. TODO: a better way in Motif? // back again. TODO: a better way in Motif?
if (m_font.Ok()) if (m_mainWidget && m_font.Ok())
{ {
Display* dpy = XtDisplay((Widget) m_mainWidget); Display* dpy = XtDisplay((Widget) m_mainWidget);
int width, height, width1, height1; int width, height, width1, height1;

View File

@@ -51,6 +51,7 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id,
{ {
if( !CreateControl( parent, id, pos, size, style, validator, name ) ) if( !CreateControl( parent, id, pos, size, style, validator, name ) )
return false; return false;
PreCreation();
m_noStrings = n; m_noStrings = n;
@@ -80,17 +81,14 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id,
SetValue(value); SetValue(value);
ChangeFont(false);
XtAddCallback (buttonWidget, XmNselectionCallback, (XtCallbackProc) wxComboBoxCallback, XtAddCallback (buttonWidget, XmNselectionCallback, (XtCallbackProc) wxComboBoxCallback,
(XtPointer) this); (XtPointer) this);
XtAddCallback (buttonWidget, XmNvalueChangedCallback, (XtCallbackProc) wxComboBoxCallback, XtAddCallback (buttonWidget, XmNvalueChangedCallback, (XtCallbackProc) wxComboBoxCallback,
(XtPointer) this); (XtPointer) this);
PostCreation();
AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y); AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y);
ChangeBackgroundColour();
return true; return true;
} }

View File

@@ -80,6 +80,7 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id,
{ {
if( !CreateControl( parent, id, pos, size, style, validator, name ) ) if( !CreateControl( parent, id, pos, size, style, validator, name ) )
return false; return false;
PreCreation();
Widget parentWidget = (Widget) parent->GetClientWidget(); Widget parentWidget = (Widget) parent->GetClientWidget();
@@ -106,8 +107,6 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id,
SetValue(value); SetValue(value);
ChangeFont(false);
XtAddCallback (buttonWidget, XmNselectionCallback, XtAddCallback (buttonWidget, XmNselectionCallback,
(XtCallbackProc) wxComboBoxCallback, (XtCallbackProc) wxComboBoxCallback,
(XtPointer) this); (XtPointer) this);
@@ -119,11 +118,10 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id,
if( size.x != wxDefaultCoord ) best.x = size.x; if( size.x != wxDefaultCoord ) best.x = size.x;
if( size.y != wxDefaultCoord ) best.y = size.y; if( size.y != wxDefaultCoord ) best.y = size.y;
PostCreation();
AttachWidget (parent, m_mainWidget, (WXWidget) NULL, AttachWidget (parent, m_mainWidget, (WXWidget) NULL,
pos.x, pos.y, best.x, best.y); pos.x, pos.y, best.x, best.y);
ChangeBackgroundColour();
return true; return true;
} }
@@ -407,7 +405,7 @@ void wxComboBoxCallback (Widget WXUNUSED(w), XtPointer clientData,
void wxComboBox::ChangeFont(bool keepOriginalSize) void wxComboBox::ChangeFont(bool keepOriginalSize)
{ {
if( m_font.Ok() ) if( m_font.Ok() && m_mainWidget != NULL )
{ {
wxDoChangeFont( GetXmText(this), m_font ); wxDoChangeFont( GetXmText(this), m_font );
wxDoChangeFont( GetXmList(this), m_font ); wxDoChangeFont( GetXmList(this), m_font );

View File

@@ -37,9 +37,6 @@ END_EVENT_TABLE()
// Item members // Item members
wxControl::wxControl() wxControl::wxControl()
{ {
m_backgroundColour = *wxWHITE;
m_foregroundColour = *wxBLACK;
m_inSetValue = false; m_inSetValue = false;
} }
@@ -72,10 +69,6 @@ bool wxControl::CreateControl(wxWindow *parent,
validator, name ) ) validator, name ) )
return false; return false;
m_backgroundColour = parent->GetBackgroundColour();
m_foregroundColour = parent->GetForegroundColour();
m_font = parent->GetFont();
return true; return true;
} }

View File

@@ -179,8 +179,16 @@ wxWindowDC::wxWindowDC( wxWindow *window )
gcvalues.graphics_exposures = False; gcvalues.graphics_exposures = False;
gcvalues.subwindow_mode = IncludeInferiors; gcvalues.subwindow_mode = IncludeInferiors;
gcvalues.line_width = 1; gcvalues.line_width = 1;
#if !wxMOTIF_NEW_FONT_HANDLING
WXFontStructPtr pFontStruct = m_font.GetFontStruct(m_userScaleY*m_logicalScaleY, m_display);
gcvalues.font = ((XFontStruct*)pFontStruct)->fid;
#endif
m_gc = (WXGC) XCreateGC (display, RootWindow (display, DefaultScreen (display)), m_gc = (WXGC) XCreateGC (display, RootWindow (display, DefaultScreen (display)),
GCForeground | GCBackground | GCGraphicsExposures | GCLineWidth | GCSubwindowMode, GCForeground | GCBackground | GCGraphicsExposures | GCLineWidth | GCSubwindowMode
#if !wxMOTIF_NEW_FONT_HANDLING
| GCFont
#endif
,
&gcvalues); &gcvalues);
if (m_window->GetBackingPixmap()) if (m_window->GetBackingPixmap())
@@ -1685,7 +1693,7 @@ void wxWindowDC::SetPen( const wxPen &pen )
if (m_window && m_window->GetBackingPixmap()) if (m_window && m_window->GetBackingPixmap())
XSetStipple ((Display*) m_display,(GC) m_gcBacking, myStipple); XSetStipple ((Display*) m_display,(GC) m_gcBacking, myStipple);
} }
else if (m_currentStipple.Ok() else if (m_currentStyle == wxSTIPPLE && m_currentStipple.Ok()
&& ((!m_currentStipple.IsSameAs(oldStipple)) || !GET_OPTIMIZATION)) && ((!m_currentStipple.IsSameAs(oldStipple)) || !GET_OPTIMIZATION))
{ {
XSetStipple ((Display*) m_display, (GC) m_gc, (Pixmap) m_currentStipple.GetDrawable()); XSetStipple ((Display*) m_display, (GC) m_gc, (Pixmap) m_currentStipple.GetDrawable());

View File

@@ -75,7 +75,6 @@ wxDialog::wxDialog()
{ {
m_modalShowing = false; m_modalShowing = false;
m_eventLoop = NULL; m_eventLoop = NULL;
m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE);
} }
bool wxDialog::Create(wxWindow *parent, wxWindowID id, bool wxDialog::Create(wxWindow *parent, wxWindowID id,
@@ -94,16 +93,10 @@ bool wxDialog::Create(wxWindow *parent, wxWindowID id,
m_modalShowing = false; m_modalShowing = false;
m_eventLoop = NULL; m_eventLoop = NULL;
m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE);
m_foregroundColour = *wxBLACK;
Widget dialogShell = (Widget) m_mainWidget; Widget dialogShell = (Widget) m_mainWidget;
SetTitle( title ); SetTitle( title );
m_font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
ChangeFont(false);
// Can't remember what this was about... but I think it's necessary. // Can't remember what this was about... but I think it's necessary.
#if wxUSE_INVISIBLE_RESIZE #if wxUSE_INVISIBLE_RESIZE
if (pos.x > -1) if (pos.x > -1)
@@ -135,7 +128,7 @@ bool wxDialog::Create(wxWindow *parent, wxWindowID id,
XtAddEventHandler(dialogShell,ExposureMask,False, XtAddEventHandler(dialogShell,ExposureMask,False,
wxUniversalRepaintProc, (XtPointer) this); wxUniversalRepaintProc, (XtPointer) this);
ChangeBackgroundColour(); PostCreation();
return true; return true;
} }

View File

@@ -17,14 +17,14 @@
// headers // headers
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __VMS #ifdef __VMS
#define XtParent XTPARENT #define XtParent XTPARENT
#define XtDisplay XTDISPLAY #define XtDisplay XTDISPLAY
#endif #endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifndef WX_PRECOMP #ifndef WX_PRECOMP
#include "wx/event.h" #include "wx/event.h"
#include "wx/app.h" #include "wx/app.h"

View File

@@ -172,12 +172,15 @@ int wxFileDialog::ShowModal()
Arg args[10]; Arg args[10];
int ac = 0; int ac = 0;
wxComputeColours (dpy, & m_backgroundColour, (wxColour*) NULL); if (m_backgroundColour.Ok())
{
wxComputeColours (dpy, & m_backgroundColour, (wxColour*) NULL);
XtSetArg(args[ac], XmNbackground, g_itemColors[wxBACK_INDEX].pixel); ac++; XtSetArg(args[ac], XmNbackground, g_itemColors[wxBACK_INDEX].pixel); ac++;
XtSetArg(args[ac], XmNtopShadowColor, g_itemColors[wxTOPS_INDEX].pixel); ac++; XtSetArg(args[ac], XmNtopShadowColor, g_itemColors[wxTOPS_INDEX].pixel); ac++;
XtSetArg(args[ac], XmNbottomShadowColor, g_itemColors[wxBOTS_INDEX].pixel); ac++; XtSetArg(args[ac], XmNbottomShadowColor, g_itemColors[wxBOTS_INDEX].pixel); ac++;
XtSetArg(args[ac], XmNforeground, g_itemColors[wxFORE_INDEX].pixel); ac++; XtSetArg(args[ac], XmNforeground, g_itemColors[wxFORE_INDEX].pixel); ac++;
}
wxFont font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); wxFont font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);

View File

@@ -59,7 +59,7 @@ public:
#if !wxMOTIF_NEW_FONT_HANDLING #if !wxMOTIF_NEW_FONT_HANDLING
WXFontStructPtr m_fontStruct; // XFontStruct WXFontStructPtr m_fontStruct; // XFontStruct
#endif #endif
#if !wxMOTIF_USE_RENDER_TABLE && !wxMOTIF_NEW_FONT_HANDLING #if !wxMOTIF_USE_RENDER_TABLE
WXFontList m_fontList; // Motif XmFontList WXFontList m_fontList; // Motif XmFontList
#else // if wxUSE_RENDER_TABLE #else // if wxUSE_RENDER_TABLE
WXRenderTable m_renderTable; // Motif XmRenderTable WXRenderTable m_renderTable; // Motif XmRenderTable
@@ -131,7 +131,7 @@ wxXFont::wxXFont()
#if !wxMOTIF_NEW_FONT_HANDLING #if !wxMOTIF_NEW_FONT_HANDLING
m_fontStruct = (WXFontStructPtr) 0; m_fontStruct = (WXFontStructPtr) 0;
#endif #endif
#if !wxMOTIF_USE_RENDER_TABLE && !wxMOTIF_NEW_FONT_HANDLING #if !wxMOTIF_USE_RENDER_TABLE
m_fontList = (WXFontList) 0; m_fontList = (WXFontList) 0;
#else // if wxMOTIF_USE_RENDER_TABLE #else // if wxMOTIF_USE_RENDER_TABLE
m_renderTable = (WXRenderTable) 0; m_renderTable = (WXRenderTable) 0;
@@ -635,7 +635,7 @@ WXFontType wxFont::GetFontTypeC(WXDisplay* display) const
#endif #endif
} }
#if wxMOTIF_NEW_FONT_HANDLING #if wxMOTIF_USE_RENDER_TABLE
WXFontSet wxFont::GetFontSet(double scale, WXDisplay* display) const WXFontSet wxFont::GetFontSet(double scale, WXDisplay* display) const
{ {
@@ -667,7 +667,7 @@ void wxGetTextExtent(WXDisplay* display, const wxFont& font, double scale,
if( descent ) *descent = logical.height + logical.y; if( descent ) *descent = logical.height + logical.y;
} }
#else // if !wxMOTIF_NEW_FONT_HANDLING #else // if !wxMOTIF_USE_RENDER_TABLE
void wxGetTextExtent(WXDisplay* display, const wxFont& font, void wxGetTextExtent(WXDisplay* display, const wxFont& font,
double scale, const wxString& str, double scale, const wxString& str,
@@ -692,4 +692,4 @@ void wxGetTextExtent(WXDisplay* display, const wxFont& font,
*ascent = ascent2; *ascent = ascent2;
} }
#endif // !wxMOTIF_NEW_FONT_HANDLING #endif // !wxMOTIF_USE_RENDER_TABLE

View File

@@ -130,11 +130,6 @@ bool wxFrame::Create(wxWindow *parent,
name ) ) name ) )
return false; return false;
m_backgroundColour =
wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE);
m_foregroundColour = *wxBLACK;
m_font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
int x = pos.x, y = pos.y; int x = pos.x, y = pos.y;
int width = size.x, height = size.y; int width = size.x, height = size.y;
@@ -180,10 +175,7 @@ bool wxFrame::Create(wxWindow *parent,
if (height > -1) if (height > -1)
XtVaSetValues((Widget) m_frameShell, XmNheight, height, NULL); XtVaSetValues((Widget) m_frameShell, XmNheight, height, NULL);
ChangeFont(false); PostCreation();
ChangeBackgroundColour();
PreResize(); PreResize();
wxSize newSize(width, height); wxSize newSize(width, height);
@@ -398,6 +390,12 @@ void wxFrame::DoSetClientSize(int width, int height)
void wxFrame::DoGetSize(int *width, int *height) const void wxFrame::DoGetSize(int *width, int *height) const
{ {
if (!m_frameShell)
{
*width = -1; *height = -1;
return;
}
Dimension xx, yy; Dimension xx, yy;
XtVaGetValues((Widget) m_frameShell, XmNwidth, &xx, XmNheight, &yy, NULL); XtVaGetValues((Widget) m_frameShell, XmNwidth, &xx, XmNheight, &yy, NULL);
*width = xx; *height = yy; *width = xx; *height = yy;

View File

@@ -109,6 +109,7 @@ bool wxGauge::Create(wxWindow *parent, wxWindowID id,
{ {
if( !CreateControl( parent, id, pos, size, style, validator, name ) ) if( !CreateControl( parent, id, pos, size, style, validator, name ) )
return false; return false;
PreCreation();
Widget parentWidget = (Widget) parent->GetClientWidget(); Widget parentWidget = (Widget) parent->GetClientWidget();
@@ -147,13 +148,10 @@ bool wxGauge::Create(wxWindow *parent, wxWindowID id,
if( size.x != wxDefaultCoord ) best.x = size.x; if( size.x != wxDefaultCoord ) best.x = size.x;
if( size.y != wxDefaultCoord ) best.y = size.y; if( size.y != wxDefaultCoord ) best.y = size.y;
ChangeFont(false); PostCreation();
AttachWidget (parent, m_mainWidget, (WXWidget) NULL, x, y, AttachWidget (parent, m_mainWidget, (WXWidget) NULL, x, y,
best.x, best.y); best.x, best.y);
ChangeBackgroundColour();
return true; return true;
} }

View File

@@ -52,21 +52,23 @@ static void wxListBoxCallback(Widget w,
class wxSizeKeeper class wxSizeKeeper
{ {
int m_x, m_y; int m_x, m_y;
wxWindow* m_w; int m_w, m_h;
wxWindow* m_wnd;
public: public:
wxSizeKeeper( wxWindow* w ) wxSizeKeeper( wxWindow* w )
: m_w( w ) : m_wnd( w )
{ {
m_w->GetSize( &m_x, &m_y ); m_wnd->GetSize( &m_w, &m_h );
m_wnd->GetPosition( &m_x, &m_y );
} }
void Restore() void Restore()
{ {
int x, y; int x, y;
m_w->GetSize( &x, &y ); m_wnd->GetSize( &x, &y );
if( x != m_x || y != m_y ) if( x != m_x || y != m_y )
m_w->SetSize( -1, -1, m_x, m_y ); m_wnd->SetSize( m_x, m_y, m_w, m_h );
} }
}; };
@@ -91,9 +93,9 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id,
if( !wxControl::CreateControl( parent, id, pos, size, style, if( !wxControl::CreateControl( parent, id, pos, size, style,
validator, name ) ) validator, name ) )
return false; return false;
PreCreation();
m_noItems = (unsigned int)n; m_noItems = (unsigned int)n;
m_backgroundColour = * wxWHITE;
Widget parentWidget = (Widget) parent->GetClientWidget(); Widget parentWidget = (Widget) parent->GetClientWidget();
Display* dpy = XtDisplay(parentWidget); Display* dpy = XtDisplay(parentWidget);
@@ -149,11 +151,10 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id,
(XtCallbackProc) wxListBoxCallback, (XtCallbackProc) wxListBoxCallback,
(XtPointer) this); (XtPointer) this);
PostCreation();
AttachWidget (parent, m_mainWidget, (WXWidget) NULL, AttachWidget (parent, m_mainWidget, (WXWidget) NULL,
pos.x, pos.y, best.x, best.y); pos.x, pos.y, best.x, best.y);
ChangeBackgroundColour();
return true; return true;
} }

View File

@@ -338,10 +338,6 @@ bool wxMDIChildFrame::Create(wxMDIParentFrame *parent,
SetName(name); SetName(name);
SetWindowStyleFlag(style); SetWindowStyleFlag(style);
m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE);
m_foregroundColour = *wxBLACK;
m_font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
if ( id > -1 ) if ( id > -1 )
m_windowId = id; m_windowId = id;
else else
@@ -354,6 +350,7 @@ bool wxMDIChildFrame::Create(wxMDIParentFrame *parent,
clientWindow->AddChild(this); clientWindow->AddChild(this);
SetMDIParentFrame(parent); SetMDIParentFrame(parent);
PreCreation();
int width = size.x; int width = size.x;
int height = size.y; int height = size.y;
@@ -393,10 +390,9 @@ bool wxMDIChildFrame::Create(wxMDIParentFrame *parent,
XtAddEventHandler((Widget) m_mainWidget, ExposureMask,False, XtAddEventHandler((Widget) m_mainWidget, ExposureMask,False,
wxUniversalRepaintProc, (XtPointer) this); wxUniversalRepaintProc, (XtPointer) this);
PostCreation();
AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y); AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y);
ChangeBackgroundColour();
XtManageChild((Widget) m_mainWidget); XtManageChild((Widget) m_mainWidget);
SetTitle(title); SetTitle(title);
@@ -640,14 +636,9 @@ bool wxMDIClientWindow::CreateClient(wxMDIParentFrame *parent, long style)
{ {
SetWindowStyleFlag(style); SetWindowStyleFlag(style);
// m_windowParent = parent;
// m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE);
bool success = wxNotebook::Create(parent, wxID_NOTEBOOK_CLIENT_AREA, wxPoint(0, 0), wxSize(100, 100), 0); bool success = wxNotebook::Create(parent, wxID_NOTEBOOK_CLIENT_AREA, wxPoint(0, 0), wxSize(100, 100), 0);
if (success) if (success)
{ {
wxFont font(10, wxSWISS, wxNORMAL, wxNORMAL);
SetFont(font);
return true; return true;
} }
else else

View File

@@ -82,10 +82,6 @@ void wxMenu::Init()
Append(-3, m_title) ; Append(-3, m_title) ;
AppendSeparator() ; AppendSeparator() ;
} }
m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_MENU);
m_foregroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_MENUTEXT);
m_font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
} }
// The wxWindow destructor will take care of deleting the submenus. // The wxWindow destructor will take care of deleting the submenus.
@@ -190,9 +186,6 @@ void wxMenuBar::Init()
m_eventHandler = this; m_eventHandler = this;
m_menuBarFrame = NULL; m_menuBarFrame = NULL;
m_mainWidget = (WXWidget) NULL; m_mainWidget = (WXWidget) NULL;
m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_MENU);
m_foregroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_MENUTEXT);
m_font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
} }
wxMenuBar::wxMenuBar(size_t n, wxMenu *menus[], const wxArrayString& titles, long WXUNUSED(style)) wxMenuBar::wxMenuBar(size_t n, wxMenu *menus[], const wxArrayString& titles, long WXUNUSED(style))
@@ -349,6 +342,10 @@ wxMenuItem *wxMenuBar::FindItem(int id, wxMenu ** itemMenu) const
// Create menubar // Create menubar
bool wxMenuBar::CreateMenuBar(wxFrame* parent) bool wxMenuBar::CreateMenuBar(wxFrame* parent)
{ {
m_parent = parent; // bleach... override it!
PreCreation();
m_parent = NULL;
if (m_mainWidget) if (m_mainWidget)
{ {
XtVaSetValues((Widget) parent->GetMainWidget(), XmNmenuBar, (Widget) m_mainWidget, NULL); XtVaSetValues((Widget) parent->GetMainWidget(), XmNmenuBar, (Widget) m_mainWidget, NULL);
@@ -388,9 +385,7 @@ bool wxMenuBar::CreateMenuBar(wxFrame* parent)
} }
} }
SetBackgroundColour(m_backgroundColour); PostCreation();
SetForegroundColour(m_foregroundColour);
SetFont(m_font);
XtVaSetValues((Widget) parent->GetMainWidget(), XmNmenuBar, (Widget) m_mainWidget, NULL); XtVaSetValues((Widget) parent->GetMainWidget(), XmNmenuBar, (Widget) m_mainWidget, NULL);
XtRealizeWidget ((Widget) menuBarW); XtRealizeWidget ((Widget) menuBarW);
@@ -474,13 +469,24 @@ WXWidget wxMenu::CreateMenu (wxMenuBar * menuBar,
{ {
Widget menu = (Widget) 0; Widget menu = (Widget) 0;
Widget buttonWidget = (Widget) 0; Widget buttonWidget = (Widget) 0;
Display* dpy = XtDisplay((Widget)parent);
Arg args[5]; Arg args[5];
XtSetArg (args[0], XmNnumColumns, m_numColumns); XtSetArg (args[0], XmNnumColumns, m_numColumns);
XtSetArg (args[1], XmNpacking, (m_numColumns > 1) ? XmPACK_COLUMN : XmPACK_TIGHT); XtSetArg (args[1], XmNpacking, (m_numColumns > 1) ? XmPACK_COLUMN : XmPACK_TIGHT);
if ( !m_font.Ok() )
{
if ( menuBar )
m_font = menuBar->GetFont();
else if ( GetInvokingWindow() )
m_font = GetInvokingWindow()->GetFont();
}
XtSetArg (args[2], (String)wxFont::GetFontTag(), m_font.GetFontTypeC(dpy) );
if (!pullDown) if (!pullDown)
{ {
menu = XmCreatePopupMenu ((Widget) parent, wxMOTIF_STR("popup"), args, 2); menu = XmCreatePopupMenu ((Widget) parent, wxMOTIF_STR("popup"), args, 3);
#if 0 #if 0
XtAddCallback(menu, XtAddCallback(menu,
XmNunmapCallback, XmNunmapCallback,
@@ -491,7 +497,7 @@ WXWidget wxMenu::CreateMenu (wxMenuBar * menuBar,
else else
{ {
char mnem = wxFindMnemonic (title); char mnem = wxFindMnemonic (title);
menu = XmCreatePulldownMenu ((Widget) parent, wxMOTIF_STR("pulldown"), args, 2); menu = XmCreatePulldownMenu ((Widget) parent, wxMOTIF_STR("pulldown"), args, 3);
wxString title2(wxStripMenuCodes(title)); wxString title2(wxStripMenuCodes(title));
wxXmString label_str(title2); wxXmString label_str(title2);
@@ -503,6 +509,8 @@ WXWidget wxMenu::CreateMenu (wxMenuBar * menuBar,
#endif #endif
XmNlabelString, label_str(), XmNlabelString, label_str(),
XmNsubMenuId, menu, XmNsubMenuId, menu,
(String)wxFont::GetFontTag(), m_font.GetFontTypeC(dpy),
XmNpositionIndex, index,
NULL); NULL);
if (mnem != 0) if (mnem != 0)
@@ -523,9 +531,7 @@ WXWidget wxMenu::CreateMenu (wxMenuBar * menuBar,
item->CreateItem(menu, menuBar, topMenu, i); item->CreateItem(menu, menuBar, topMenu, i);
} }
SetBackgroundColour(m_backgroundColour); ChangeFont();
SetForegroundColour(m_foregroundColour);
SetFont(m_font);
return buttonWidget; return buttonWidget;
} }
@@ -600,6 +606,8 @@ WXWidget wxMenu::FindMenuItem (int id, wxMenuItem ** it) const
void wxMenu::SetBackgroundColour(const wxColour& col) void wxMenu::SetBackgroundColour(const wxColour& col)
{ {
m_backgroundColour = col; m_backgroundColour = col;
if (!col.Ok())
return;
if (m_menuWidget) if (m_menuWidget)
wxDoChangeBackgroundColour(m_menuWidget, (wxColour&) col); wxDoChangeBackgroundColour(m_menuWidget, (wxColour&) col);
if (m_buttonWidget) if (m_buttonWidget)
@@ -623,6 +631,8 @@ void wxMenu::SetBackgroundColour(const wxColour& col)
void wxMenu::SetForegroundColour(const wxColour& col) void wxMenu::SetForegroundColour(const wxColour& col)
{ {
m_foregroundColour = col; m_foregroundColour = col;
if (!col.Ok())
return;
if (m_menuWidget) if (m_menuWidget)
wxDoChangeForegroundColour(m_menuWidget, (wxColour&) col); wxDoChangeForegroundColour(m_menuWidget, (wxColour&) col);
if (m_buttonWidget) if (m_buttonWidget)
@@ -689,7 +699,10 @@ void wxMenu::SetFont(const wxFont& font)
bool wxMenuBar::SetBackgroundColour(const wxColour& col) bool wxMenuBar::SetBackgroundColour(const wxColour& col)
{ {
m_backgroundColour = col; if (!wxWindowBase::SetBackgroundColour(col))
return false;
if (!col.Ok())
return false;
if (m_mainWidget) if (m_mainWidget)
wxDoChangeBackgroundColour(m_mainWidget, (wxColour&) col); wxDoChangeBackgroundColour(m_mainWidget, (wxColour&) col);
@@ -702,7 +715,10 @@ bool wxMenuBar::SetBackgroundColour(const wxColour& col)
bool wxMenuBar::SetForegroundColour(const wxColour& col) bool wxMenuBar::SetForegroundColour(const wxColour& col)
{ {
m_foregroundColour = col; if (!wxWindowBase::SetForegroundColour(col))
return false;
if (!col.Ok())
return false;
if (m_mainWidget) if (m_mainWidget)
wxDoChangeForegroundColour(m_mainWidget, (wxColour&) col); wxDoChangeForegroundColour(m_mainWidget, (wxColour&) col);

View File

@@ -167,12 +167,15 @@ int wxMessageDialog::ShowModal()
Display* dpy = XtDisplay(wParent); Display* dpy = XtDisplay(wParent);
wxComputeColours (dpy, & m_backgroundColour, (wxColour*) NULL); if (m_backgroundColour.Ok())
{
wxComputeColours (dpy, & m_backgroundColour, (wxColour*) NULL);
XtSetArg(args[ac], XmNbackground, g_itemColors[wxBACK_INDEX].pixel); ac++; XtSetArg(args[ac], XmNbackground, g_itemColors[wxBACK_INDEX].pixel); ac++;
XtSetArg(args[ac], XmNtopShadowColor, g_itemColors[wxTOPS_INDEX].pixel); ac++; XtSetArg(args[ac], XmNtopShadowColor, g_itemColors[wxTOPS_INDEX].pixel); ac++;
XtSetArg(args[ac], XmNbottomShadowColor, g_itemColors[wxBOTS_INDEX].pixel); ac++; XtSetArg(args[ac], XmNbottomShadowColor, g_itemColors[wxBOTS_INDEX].pixel); ac++;
XtSetArg(args[ac], XmNforeground, g_itemColors[wxFORE_INDEX].pixel); ac++; XtSetArg(args[ac], XmNforeground, g_itemColors[wxFORE_INDEX].pixel); ac++;
}
wxFont font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); wxFont font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);

View File

@@ -44,11 +44,19 @@ bool wxPopupWindow::Create( wxWindow *parent, int flags )
m_mainWidget = (WXWidget)popup; m_mainWidget = (WXWidget)popup;
SetSize( 100, 100 ); // for child creation to work wxAddWindowToTable( (Widget) m_mainWidget, this );
DoSetSizeIntr( -1, -1, 100, 100, 0, true );
XtSetMappedWhenManaged( popup, False ); XtSetMappedWhenManaged( popup, False );
XtRealizeWidget( popup ); XtRealizeWidget( popup );
XtManageChild ( popup );
/*
XtTranslations ptr;
XtOverrideTranslations (popup,
ptr = XtParseTranslationTable ("<Configure>: resize()"));
XtFree ((char *) ptr);
*/
return true; return true;
} }
@@ -59,7 +67,7 @@ bool wxPopupWindow::Show( bool show )
if( show ) if( show )
{ {
XtPopup( (Widget)GetMainWidget(), XtGrabNone ); XtPopup( (Widget)GetMainWidget(), XtGrabNonexclusive );
} }
else else
{ {

View File

@@ -51,6 +51,7 @@ void wxRadioBox::Init()
m_selectedButton = -1; m_selectedButton = -1;
m_noItems = 0; m_noItems = 0;
m_noRowsOrCols = 0; m_noRowsOrCols = 0;
m_labelWidget = (WXWidget) 0;
} }
bool wxRadioBox::Create(wxWindow *parent, wxWindowID id, const wxString& title, bool wxRadioBox::Create(wxWindow *parent, wxWindowID id, const wxString& title,
@@ -61,6 +62,7 @@ bool wxRadioBox::Create(wxWindow *parent, wxWindowID id, const wxString& title,
{ {
if( !CreateControl( parent, id, pos, size, style, val, name ) ) if( !CreateControl( parent, id, pos, size, style, val, name ) )
return false; return false;
PreCreation();
m_noItems = (unsigned int)n; m_noItems = (unsigned int)n;
m_noRowsOrCols = majorDim; m_noRowsOrCols = majorDim;
@@ -137,18 +139,15 @@ bool wxRadioBox::Create(wxWindow *parent, wxWindowID id, const wxString& title,
(XtPointer) this); (XtPointer) this);
} }
ChangeFont(false);
SetSelection (0); SetSelection (0);
XtRealizeWidget((Widget)m_mainWidget); XtRealizeWidget((Widget)m_mainWidget);
XtManageChild (radioBoxWidget); XtManageChild (radioBoxWidget);
XtManageChild ((Widget)m_mainWidget); XtManageChild ((Widget)m_mainWidget);
PostCreation();
AttachWidget (parent, m_mainWidget, NULL, pos.x, pos.y, size.x, size.y); AttachWidget (parent, m_mainWidget, NULL, pos.x, pos.y, size.x, size.y);
ChangeBackgroundColour();
return true; return true;
} }

View File

@@ -51,6 +51,7 @@ bool wxRadioButton::Create(wxWindow *parent, wxWindowID id,
{ {
if( !CreateControl( parent, id, pos, size, style, validator, name ) ) if( !CreateControl( parent, id, pos, size, style, validator, name ) )
return false; return false;
PreCreation();
Widget parentWidget = (Widget) parent->GetClientWidget(); Widget parentWidget = (Widget) parent->GetClientWidget();
Display* dpy = XtDisplay(parentWidget); Display* dpy = XtDisplay(parentWidget);
@@ -80,11 +81,10 @@ bool wxRadioButton::Create(wxWindow *parent, wxWindowID id,
XtManageChild (radioButtonWidget); XtManageChild (radioButtonWidget);
PostCreation();
AttachWidget (parent, m_mainWidget, (WXWidget) NULL, AttachWidget (parent, m_mainWidget, (WXWidget) NULL,
pos.x, pos.y, size.x, size.y); pos.x, pos.y, size.x, size.y);
ChangeBackgroundColour();
//copied from mac/radiobut.cpp (from here till "return true;") //copied from mac/radiobut.cpp (from here till "return true;")
m_cycle = this ; m_cycle = this ;

View File

@@ -40,6 +40,7 @@ bool wxScrollBar::Create(wxWindow *parent, wxWindowID id,
{ {
if( !CreateControl( parent, id, pos, size, style, validator, name ) ) if( !CreateControl( parent, id, pos, size, style, validator, name ) )
return false; return false;
PreCreation();
wxSize newSize = wxSize newSize =
( style & wxHORIZONTAL ) ? wxSize( 140, 16 ) : wxSize( 16, 140 ); ( style & wxHORIZONTAL ) ? wxSize( 140, 16 ) : wxSize( 16, 140 );
@@ -53,9 +54,9 @@ bool wxScrollBar::Create(wxWindow *parent, wxWindowID id,
(wxOrientation)(style & (wxHORIZONTAL|wxVERTICAL)), (wxOrientation)(style & (wxHORIZONTAL|wxVERTICAL)),
(void (*)())wxScrollBarCallback ); (void (*)())wxScrollBarCallback );
PostCreation();
AttachWidget (parent, m_mainWidget, (WXWidget) NULL, AttachWidget (parent, m_mainWidget, (WXWidget) NULL,
pos.x, pos.y, newSize.x, newSize.y); pos.x, pos.y, newSize.x, newSize.y);
ChangeBackgroundColour();
return true; return true;
} }

View File

@@ -64,6 +64,7 @@ bool wxSlider::Create(wxWindow *parent, wxWindowID id,
if( !CreateControl( parent, id, pos, size, style, validator, name ) ) if( !CreateControl( parent, id, pos, size, style, validator, name ) )
return false; return false;
PreCreation();
m_lineSize = 1; m_lineSize = 1;
m_windowStyle = style; m_windowStyle = style;
@@ -93,11 +94,9 @@ bool wxSlider::Create(wxWindow *parent, wxWindowID id,
XtAddCallback (sliderWidget, XmNvalueChangedCallback, (XtCallbackProc) wxSliderCallback, (XtPointer) this); XtAddCallback (sliderWidget, XmNvalueChangedCallback, (XtCallbackProc) wxSliderCallback, (XtPointer) this);
XtAddCallback (sliderWidget, XmNdragCallback, (XtCallbackProc) wxSliderCallback, (XtPointer) this); XtAddCallback (sliderWidget, XmNdragCallback, (XtCallbackProc) wxSliderCallback, (XtPointer) this);
ChangeFont(false); PostCreation();
AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y); AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y);
ChangeBackgroundColour();
return true; return true;
} }

View File

@@ -210,6 +210,7 @@ bool wxArrowButton::Create( wxSpinButton* parent,
} }
parent->AddChild( this ); parent->AddChild( this );
PreCreation();
Widget parentWidget = (Widget) parent->GetClientWidget(); Widget parentWidget = (Widget) parent->GetClientWidget();
m_mainWidget = (WXWidget) XtVaCreateManagedWidget( "XmArrowButton", m_mainWidget = (WXWidget) XtVaCreateManagedWidget( "XmArrowButton",
@@ -230,11 +231,10 @@ bool wxArrowButton::Create( wxSpinButton* parent,
XmNactivateCallback, (XtCallbackProc) StopTimerCallback, XmNactivateCallback, (XtCallbackProc) StopTimerCallback,
(XtPointer) this ); (XtPointer) this );
PostCreation();
AttachWidget( parent, m_mainWidget, (WXWidget) NULL, AttachWidget( parent, m_mainWidget, (WXWidget) NULL,
pos.x, pos.y, size.x, size.y ); pos.x, pos.y, size.x, size.y );
SetForegroundColour( parent->GetBackgroundColour() );
return true; return true;
} }

View File

@@ -42,6 +42,7 @@ bool wxStaticBitmap::Create(wxWindow *parent, wxWindowID id,
if( !CreateControl( parent, id, pos, size, style, wxDefaultValidator, if( !CreateControl( parent, id, pos, size, style, wxDefaultValidator,
name ) ) name ) )
return false; return false;
PreCreation();
m_messageBitmap = bitmap; m_messageBitmap = bitmap;
m_messageBitmapOriginal = bitmap; m_messageBitmapOriginal = bitmap;
@@ -57,18 +58,15 @@ bool wxStaticBitmap::Create(wxWindow *parent, wxWindowID id,
XmNalignment, XmALIGNMENT_BEGINNING, XmNalignment, XmALIGNMENT_BEGINNING,
NULL); NULL);
ChangeBackgroundColour ();
DoSetBitmap();
ChangeFont(false);
wxSize actualSize(size); wxSize actualSize(size);
// work around the cases where the bitmap is a wxNull(Icon/Bitmap) // work around the cases where the bitmap is a wxNull(Icon/Bitmap)
if (actualSize.x == -1) if (actualSize.x == -1)
actualSize.x = bitmap.Ok() ? bitmap.GetWidth() : 1; actualSize.x = bitmap.Ok() ? bitmap.GetWidth() : 1;
if (actualSize.y == -1) if (actualSize.y == -1)
actualSize.y = bitmap.Ok() ? bitmap.GetHeight() : 1; actualSize.y = bitmap.Ok() ? bitmap.GetHeight() : 1;
PostCreation();
DoSetBitmap();
AttachWidget (parent, m_mainWidget, (WXWidget) NULL, AttachWidget (parent, m_mainWidget, (WXWidget) NULL,
pos.x, pos.y, actualSize.x, actualSize.y); pos.x, pos.y, actualSize.x, actualSize.y);

View File

@@ -93,6 +93,8 @@ bool wxStaticBox::Create(wxWindow *parent, wxWindowID id,
if( !CreateControl( parent, id, pos, size, style, if( !CreateControl( parent, id, pos, size, style,
wxDefaultValidator, name ) ) wxDefaultValidator, name ) )
return false; return false;
m_labelWidget = (WXWidget) 0;
PreCreation();
Widget parentWidget = (Widget) parent->GetClientWidget(); Widget parentWidget = (Widget) parent->GetClientWidget();
@@ -119,9 +121,9 @@ bool wxStaticBox::Create(wxWindow *parent, wxWindowID id,
#endif #endif
NULL); NULL);
} }
PostCreation();
AttachWidget (parent, m_mainWidget, NULL, pos.x, pos.y, size.x, size.y); AttachWidget (parent, m_mainWidget, NULL, pos.x, pos.y, size.x, size.y);
ChangeBackgroundColour();
return true; return true;
} }

View File

@@ -42,6 +42,8 @@ bool wxStaticText::Create(wxWindow *parent, wxWindowID id,
if( !CreateControl( parent, id, pos, size, style, if( !CreateControl( parent, id, pos, size, style,
wxDefaultValidator, name ) ) wxDefaultValidator, name ) )
return false; return false;
m_labelWidget = (WXWidget) 0;
PreCreation();
Widget parentWidget = (Widget) parent->GetClientWidget(); Widget parentWidget = (Widget) parent->GetClientWidget();
@@ -61,13 +63,16 @@ bool wxStaticText::Create(wxWindow *parent, wxWindowID id,
m_mainWidget = borderWidget ? borderWidget : m_labelWidget; m_mainWidget = borderWidget ? borderWidget : m_labelWidget;
AttachWidget (parent, m_mainWidget, (WXWidget) NULL,
pos.x, pos.y, size.x, size.y);
ChangeBackgroundColour ();
SetLabel(label); SetLabel(label);
wxSize best = GetBestSize();
if( size.x != -1 ) best.x = size.x;
if( size.y != -1 ) best.y = size.y;
PostCreation();
AttachWidget (parent, m_mainWidget, (WXWidget) NULL,
pos.x, pos.y, best.x, best.y);
return true; return true;
} }
@@ -108,4 +113,12 @@ void wxStaticText::DoSetLabel(const wxString& str)
dynamic ellipsizing of the label dynamic ellipsizing of the label
*/ */
wxSize wxStaticText::DoGetBestSize() const
{
int w, h;
GetTextExtent(GetLabelText(), &w, &h, NULL, NULL, NULL);
return wxSize(w, h);
}
#endif // wxUSE_STATTEXT #endif // wxUSE_STATTEXT

View File

@@ -110,13 +110,12 @@ bool wxTextCtrl::Create(wxWindow *parent,
{ {
if( !CreateControl( parent, id, pos, size, style, validator, name ) ) if( !CreateControl( parent, id, pos, size, style, validator, name ) )
return false; return false;
PreCreation();
m_tempCallbackStruct = (void*) NULL; m_tempCallbackStruct = (void*) NULL;
m_modified = false; m_modified = false;
m_processedDefault = false; m_processedDefault = false;
m_backgroundColour = *wxWHITE;
Widget parentWidget = (Widget) parent->GetClientWidget(); Widget parentWidget = (Widget) parent->GetClientWidget();
Bool wantHorizScroll = (m_windowStyle & wxHSCROLL) != 0 ? True : False; Bool wantHorizScroll = (m_windowStyle & wxHSCROLL) != 0 ? True : False;
@@ -135,8 +134,9 @@ bool wxTextCtrl::Create(wxWindow *parent,
Arg args[8]; Arg args[8];
int count = 0; int count = 0;
XtSetArg (args[count], XmNscrollHorizontal, wantHorizScroll); ++count; XtSetArg (args[count], XmNscrollHorizontal, wantHorizScroll); ++count;
XtSetArg (args[count], (String) wxFont::GetFontTag(), if( m_font.IsOk() )
m_font.GetFontType( XtDisplay(parentWidget) ) ); ++count; XtSetArg (args[count], (String) wxFont::GetFontTag(),
m_font.GetFontType( XtDisplay(parentWidget) ) ); ++count;
XtSetArg (args[count], XmNwordWrap, wantWordWrap); ++count; XtSetArg (args[count], XmNwordWrap, wantWordWrap); ++count;
XtSetArg (args[count], XmNvalue, value.mb_str()); ++count; XtSetArg (args[count], XmNvalue, value.mb_str()); ++count;
XtSetArg (args[count], XmNeditable, XtSetArg (args[count], XmNeditable,
@@ -194,11 +194,10 @@ bool wxTextCtrl::Create(wxWindow *parent,
XtAddCallback((Widget) m_mainWidget, XmNlosingFocusCallback, (XtCallbackProc)wxTextWindowLoseFocusProc, (XtPointer)this); XtAddCallback((Widget) m_mainWidget, XmNlosingFocusCallback, (XtCallbackProc)wxTextWindowLoseFocusProc, (XtPointer)this);
PostCreation();
AttachWidget (parent, m_mainWidget, (WXWidget) NULL, AttachWidget (parent, m_mainWidget, (WXWidget) NULL,
pos.x, pos.y, size.x, size.y); pos.x, pos.y, size.x, size.y);
ChangeBackgroundColour();
return true; return true;
} }
@@ -667,8 +666,8 @@ wxSize wxDoGetSingleTextCtrlBestSize( Widget textWidget,
int x, y; int x, y;
window->GetTextExtent( value, &x, &y ); window->GetTextExtent( value, &x, &y );
if( x < 100 ) if( x < 90 )
x = 100; x = 90;
return wxSize( x + 2 * xmargin + 2 * highlight + 2 * shadow, return wxSize( x + 2 * xmargin + 2 * highlight + 2 * shadow,
// MBN: +2 necessary: Lesstif bug or mine? // MBN: +2 necessary: Lesstif bug or mine?
@@ -680,10 +679,16 @@ wxSize wxTextCtrl::DoGetBestSize() const
if( IsSingleLine() ) if( IsSingleLine() )
{ {
wxSize best = wxControl::DoGetBestSize(); wxSize best = wxControl::DoGetBestSize();
#if wxCHECK_MOTIF_VERSION( 2, 3 )
if( best.x < 110 ) best.x = 110; // OpenMotif 2.3 gives way too big X sizes
wxSize other_best = wxDoGetSingleTextCtrlBestSize
( (Widget) GetTopWidget(), this );
return wxSize( other_best.x, best.y );
#else
if( best.x < 90 ) best.x = 90;
return best; return best;
#endif
} }
else else
return wxWindow::DoGetBestSize(); return wxWindow::DoGetBestSize();

View File

@@ -204,11 +204,10 @@ bool wxToolBar::Create(wxWindow *parent,
if( !wxControl::CreateControl( parent, id, pos, size, style, if( !wxControl::CreateControl( parent, id, pos, size, style,
wxDefaultValidator, name ) ) wxDefaultValidator, name ) )
return false; return false;
PreCreation();
FixupStyle(); FixupStyle();
m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE);
Widget parentWidget = (Widget) parent->GetClientWidget(); Widget parentWidget = (Widget) parent->GetClientWidget();
Widget toolbar = XtVaCreateManagedWidget("toolbar", Widget toolbar = XtVaCreateManagedWidget("toolbar",
@@ -232,8 +231,6 @@ bool wxToolBar::Create(wxWindow *parent,
m_mainWidget = (WXWidget) toolbar; m_mainWidget = (WXWidget) toolbar;
ChangeFont(false);
wxPoint rPos = pos; wxPoint rPos = pos;
wxSize rSize = size; wxSize rSize = size;
@@ -242,11 +239,10 @@ bool wxToolBar::Create(wxWindow *parent,
if( rSize.x == -1 && GetParent() ) if( rSize.x == -1 && GetParent() )
rSize.x = GetParent()->GetSize().x; rSize.x = GetParent()->GetSize().x;
PostCreation();
AttachWidget (parent, m_mainWidget, (WXWidget) NULL, AttachWidget (parent, m_mainWidget, (WXWidget) NULL,
rPos.x, rPos.y, rSize.x, rSize.y); rPos.x, rPos.y, rSize.x, rSize.y);
ChangeBackgroundColour();
return true; return true;
} }

View File

@@ -21,6 +21,8 @@
#include "wx/wxprec.h" #include "wx/wxprec.h"
#include "wx/toplevel.h" #include "wx/toplevel.h"
#include "wx/settings.h"
#include "wx/app.h"
#ifndef WX_PRECOMP #ifndef WX_PRECOMP
#include "wx/app.h" #include "wx/app.h"
@@ -112,6 +114,9 @@ bool wxTopLevelWindowMotif::Create( wxWindow *parent, wxWindowID id,
wxTopLevelWindows.Append(this); wxTopLevelWindows.Append(this);
m_windowId = ( id > -1 ) ? id : NewControlId(); m_windowId = ( id > -1 ) ? id : NewControlId();
// MBN: More backward compatible, but uglier
m_font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
m_inheritFont = true;
bool retval = XmDoCreateTLW( parent, id, title, pos, size, style, name ); bool retval = XmDoCreateTLW( parent, id, title, pos, size, style, name );

View File

@@ -524,6 +524,9 @@ XmString wxFindAcceleratorText (const char *s)
// Change a widget's foreground and background colours. // Change a widget's foreground and background colours.
void wxDoChangeForegroundColour(WXWidget widget, wxColour& foregroundColour) void wxDoChangeForegroundColour(WXWidget widget, wxColour& foregroundColour)
{ {
if (!foregroundColour.Ok())
return;
// When should we specify the foreground, if it's calculated // When should we specify the foreground, if it's calculated
// by wxComputeColours? // by wxComputeColours?
// Solution: say we start with the default (computed) foreground colour. // Solution: say we start with the default (computed) foreground colour.
@@ -540,6 +543,9 @@ void wxDoChangeForegroundColour(WXWidget widget, wxColour& foregroundColour)
void wxDoChangeBackgroundColour(WXWidget widget, const wxColour& backgroundColour, bool changeArmColour) void wxDoChangeBackgroundColour(WXWidget widget, const wxColour& backgroundColour, bool changeArmColour)
{ {
if (!backgroundColour.Ok())
return;
wxComputeColours (XtDisplay((Widget) widget), & backgroundColour, wxComputeColours (XtDisplay((Widget) widget), & backgroundColour,
(wxColour*) NULL); (wxColour*) NULL);

View File

@@ -235,9 +235,7 @@ bool wxWindow::Create(wxWindow *parent, wxWindowID id,
CreateBase(parent, id, pos, size, style, wxDefaultValidator, name); CreateBase(parent, id, pos, size, style, wxDefaultValidator, name);
parent->AddChild(this); parent->AddChild(this);
PreCreation();
m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE);
m_foregroundColour = *wxBLACK;
//// TODO: we should probably optimize by only creating a //// TODO: we should probably optimize by only creating a
//// a drawing area if we have one or more scrollbars (wxVSCROLL/wxHSCROLL). //// a drawing area if we have one or more scrollbars (wxVSCROLL/wxHSCROLL).
@@ -330,21 +328,16 @@ bool wxWindow::Create(wxWindow *parent, wxWindowID id,
(XtPointer) this (XtPointer) this
); );
// Scrolled widget needs to have its colour changed or we get a little blue
// square where the scrollbars abutt
wxColour backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE);
wxDoChangeBackgroundColour(m_scrolledWindow, backgroundColour, true);
wxDoChangeBackgroundColour(m_drawingArea, backgroundColour, true);
XmScrolledWindowSetAreas( XmScrolledWindowSetAreas(
(Widget)m_scrolledWindow, (Widget)m_scrolledWindow,
(Widget) 0, (Widget) 0, (Widget) 0, (Widget) 0,
(Widget) m_drawingArea); (Widget) m_drawingArea);
PostCreation();
// Without this, the cursor may not be restored properly (e.g. in splitter // Without this, the cursor may not be restored properly (e.g. in splitter
// sample). // sample).
SetCursor(*wxSTANDARD_CURSOR); SetCursor(*wxSTANDARD_CURSOR);
SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
DoSetSizeIntr(pos.x, pos.y, size.x,size.y, wxSIZE_AUTO, true); DoSetSizeIntr(pos.x, pos.y, size.x,size.y, wxSIZE_AUTO, true);
return true; return true;
} }
@@ -1173,12 +1166,13 @@ void wxWindow::DoGetSize(int *x, int *y) const
m_drawingArea ) ); m_drawingArea ) );
Dimension xx, yy; Dimension xx, yy;
XtVaGetValues( widget, if (widget)
XmNwidth, &xx, XtVaGetValues( widget,
XmNheight, &yy, XmNwidth, &xx,
NULL ); XmNheight, &yy,
if(x) *x = xx; NULL );
if(y) *y = yy; if(x) *x = widget ? xx : -1;
if(y) *y = widget ? yy : -1;
} }
void wxWindow::DoGetPosition(int *x, int *y) const void wxWindow::DoGetPosition(int *x, int *y) const
@@ -1261,6 +1255,11 @@ void wxWindow::DoSetSizeIntr(int x, int y, int width, int height,
GetPosition(& oldX, & oldY); GetPosition(& oldX, & oldY);
} }
if (x == -1)
x = oldX;
if (x == -1)
x = oldY;
if ( !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) ) if ( !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
{ {
if ( width == -1 ) if ( width == -1 )
@@ -1457,24 +1456,26 @@ void wxWindow::DoMoveWindow(int x, int y, int width, int height)
int wxWindow::GetCharHeight() const int wxWindow::GetCharHeight() const
{ {
wxCHECK_MSG( m_font.Ok(), 0, "valid window font needed" );
int height; int height;
wxGetTextExtent (GetXDisplay(), m_font, 1.0, if (m_font.Ok())
"x", NULL, &height, NULL, NULL); wxGetTextExtent (GetXDisplay(), m_font, 1.0,
"x", NULL, &height, NULL, NULL);
else
wxGetTextExtent (this, "x", NULL, &height, NULL, NULL);
return height; return height;
} }
int wxWindow::GetCharWidth() const int wxWindow::GetCharWidth() const
{ {
wxCHECK_MSG( m_font.Ok(), 0, "valid window font needed" );
int width; int width;
wxGetTextExtent (GetXDisplay(), m_font, 1.0, if (m_font.Ok())
"x", &width, NULL, NULL, NULL); wxGetTextExtent (GetXDisplay(), m_font, 1.0,
"x", &width, NULL, NULL, NULL);
else
wxGetTextExtent (this, "x", &width, NULL, NULL, NULL);
return width; return width;
} }
@@ -1486,12 +1487,13 @@ void wxWindow::GetTextExtent(const wxString& string,
{ {
const wxFont *fontToUse = theFont ? theFont : &m_font; const wxFont *fontToUse = theFont ? theFont : &m_font;
wxCHECK_RET( fontToUse->Ok(), "valid window font needed" );
if (externalLeading) if (externalLeading)
*externalLeading = 0; *externalLeading = 0;
wxGetTextExtent (GetXDisplay(), *fontToUse, 1.0, if (fontToUse->Ok())
string, x, y, NULL, descent); wxGetTextExtent (GetXDisplay(), *fontToUse, 1.0,
string, x, y, NULL, descent);
else
wxGetTextExtent (this, string, x, y, NULL, descent);
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -1505,9 +1507,12 @@ void wxWindow::AddUpdateRect(int x, int y, int w, int h)
void wxWindow::Refresh(bool eraseBack, const wxRect *rect) void wxWindow::Refresh(bool eraseBack, const wxRect *rect)
{ {
Widget widget = (Widget) GetMainWidget();
if (!widget)
return;
m_needsRefresh = true; m_needsRefresh = true;
Display *display = XtDisplay((Widget) GetMainWidget()); Display *display = XtDisplay(widget);
Window thisWindow = XtWindow((Widget) GetMainWidget()); Window thisWindow = XtWindow(widget);
XExposeEvent dummyEvent; XExposeEvent dummyEvent;
int width, height; int width, height;
@@ -2494,7 +2499,7 @@ void wxWindow::ChangeFont(bool keepOriginalSize)
int width, height, width1, height1; int width, height, width1, height1;
GetSize(& width, & height); GetSize(& width, & height);
wxDoChangeFont( GetLabelWidget(), m_font ); wxDoChangeFont( w, m_font );
GetSize(& width1, & height1); GetSize(& width1, & height1);
if (keepOriginalSize && (width != width1 || height != height1)) if (keepOriginalSize && (width != width1 || height != height1))
@@ -2504,6 +2509,20 @@ void wxWindow::ChangeFont(bool keepOriginalSize)
} }
} }
// Post-creation
void wxWindow::PostCreation()
{
ChangeFont();
ChangeForegroundColour();
ChangeBackgroundColour();
}
// Pre-creation
void wxWindow::PreCreation()
{
InheritAttributes();
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// global functions // global functions
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -2578,6 +2597,104 @@ wxMouseState wxGetMouseState()
} }
#if wxMOTIF_NEW_FONT_HANDLING
#include <Xm/XmP.h>
void wxGetTextExtent(const wxWindow* window, const wxString& str,
int* width, int* height, int* ascent, int* descent)
{
Arg args[2];
int count = 0;
XmRendition rendition = NULL;
XmRenderTable table = NULL;
Widget w = (Widget) window->GetLabelWidget();
XtVaGetValues( w, XmNrenderTable, &table, NULL );
if (table == NULL)
table = XmeGetDefaultRenderTable(w, XmTEXT_RENDER_TABLE);
rendition = XmRenderTableGetRendition( table, "" );
XtSetArg( args[count], XmNfont, 0 ); ++count;
XtSetArg( args[count], XmNfontType, 0 ); ++count;
XmRenditionRetrieve( rendition, args, count );
if (args[1].value == XmFONT_IS_FONTSET)
{
XRectangle ink, logical;
WXFontSet fset = (WXFontSet) args[0].value;
XmbTextExtents( (XFontSet)fset, str.c_str(), str.length(),
&ink, &logical);
if( width ) *width = logical.width;
if( height ) *height = logical.height;
if( ascent ) *ascent = -logical.y;
if( descent ) *descent = logical.height + logical.y;
}
else
{
int direction, ascent2, descent2;
XCharStruct overall;
XFontStruct* fontStruct;
XmeRenderTableGetDefaultFont( table, &fontStruct );
XTextExtents(fontStruct, (const char*)str.c_str(), str.length(),
&direction, &ascent2, &descent2, &overall);
if ( width ) *width = overall.width;
if ( height ) *height = ascent2 + descent2;
if ( descent ) *descent = descent2;
if ( ascent ) *ascent = ascent2;
}
}
#else // if !wxMOTIF_NEW_FONT_HANDLING
void wxGetTextExtent(const wxWindow* window, const wxString& str,
int* width, int* height, int* ascent, int* descent)
{
XmFontList list = NULL;
XmFontContext cxt;
XmFontType type;
Widget w = (Widget) window->GetLabelWidget();
XtVaGetValues( w, XmNfontList, &list, NULL );
XmFontListInitFontContext( &cxt, list );
XmFontListEntry entry = XmFontListNextEntry( cxt );
XmFontListFreeFontContext( cxt );
XtPointer thing = XmFontListEntryGetFont( entry, &type );
if (type == XmFONT_IS_FONTSET)
{
XRectangle ink, logical;
XmbTextExtents( (XFontSet)thing, str.c_str(), str.length(),
&ink, &logical);
if( width ) *width = logical.width;
if( height ) *height = logical.height;
if( ascent ) *ascent = -logical.y;
if( descent ) *descent = logical.height + logical.y;
}
else
{
int direction, ascent2, descent2;
XCharStruct overall;
XTextExtents( (XFontStruct*)thing, (char*)(const char*)str.c_str(), str.length(),
&direction, &ascent2, &descent2, &overall);
if ( width ) *width = overall.width;
if ( height ) *height = ascent2 + descent2;
if ( descent ) *descent = descent2;
if ( ascent ) *ascent = ascent2;
}
}
#endif // !wxMOTIF_NEW_FONT_HANDLING
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxNoOptimize: switch off size optimization // wxNoOptimize: switch off size optimization
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------