From 105fbe1ffa8968cb85fd2cac7192957e522d17ba Mon Sep 17 00:00:00 2001 From: Mattia Barbon Date: Sat, 7 Apr 2007 21:18:33 +0000 Subject: [PATCH] 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 --- include/wx/motif/font.h | 14 +-- include/wx/motif/private.h | 3 + include/wx/motif/stattext.h | 1 + include/wx/motif/window.h | 6 ++ src/generic/notebook.cpp | 2 - src/generic/tabg.cpp | 10 +- src/motif/app.cpp | 23 +++-- src/motif/bmpbuttn.cpp | 10 +- src/motif/button.cpp | 4 +- src/motif/checkbox.cpp | 7 +- src/motif/checklst.cpp | 2 +- src/motif/choice.cpp | 7 +- src/motif/combobox.cpp | 6 +- src/motif/combobox_native.cpp | 8 +- src/motif/control.cpp | 7 -- src/motif/dcclient.cpp | 12 ++- src/motif/dialog.cpp | 9 +- src/motif/evtloop.cpp | 6 +- src/motif/filedlg.cpp | 13 ++- src/motif/font.cpp | 10 +- src/motif/frame.cpp | 16 ++- src/motif/gauge.cpp | 6 +- src/motif/listbox.cpp | 17 ++-- src/motif/mdi.cpp | 13 +-- src/motif/menu.cpp | 50 ++++++---- src/motif/msgdlg.cpp | 13 ++- src/motif/popupwin.cpp | 14 ++- src/motif/radiobox.cpp | 7 +- src/motif/radiobut.cpp | 4 +- src/motif/scrolbar.cpp | 3 +- src/motif/slider.cpp | 5 +- src/motif/spinbutt.cpp | 4 +- src/motif/statbmp.cpp | 10 +- src/motif/statbox.cpp | 6 +- src/motif/stattext.cpp | 21 +++- src/motif/textctrl.cpp | 25 +++-- src/motif/toolbar.cpp | 8 +- src/motif/toplevel.cpp | 5 + src/motif/utils.cpp | 6 ++ src/motif/window.cpp | 179 ++++++++++++++++++++++++++++------ 40 files changed, 367 insertions(+), 205 deletions(-) diff --git a/include/wx/motif/font.h b/include/wx/motif/font.h index 4fb5e08a3d..69f0a5cea8 100644 --- a/include/wx/motif/font.h +++ b/include/wx/motif/font.h @@ -13,12 +13,11 @@ #define _WX_FONT_H_ #if __WXMOTIF20__ && !__WXLESSTIF__ - #define wxMOTIF_NEW_FONT_HANDLING 1 #define wxMOTIF_USE_RENDER_TABLE 1 #else - #define wxMOTIF_NEW_FONT_HANDLING 0 #define wxMOTIF_USE_RENDER_TABLE 0 #endif +#define wxMOTIF_NEW_FONT_HANDLING wxMOTIF_USE_RENDER_TABLE class wxXFont; @@ -93,18 +92,15 @@ public: WXDisplay* display = NULL) const; // 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 + WXFontSet GetFontSet(double scale, WXDisplay* display = NULL) const; WXRenderTable GetRenderTable(WXDisplay* display) const; #else // if !wxMOTIF_USE_RENDER_TABLE + WXFontStructPtr GetFontStruct(double scale = 1.0, + WXDisplay* display = NULL) const; WXFontList GetFontList(double scale = 1.0, WXDisplay* display = NULL) const; -#endif // wxMOTIF_USE_RENDER_TABLE +#endif // !wxMOTIF_USE_RENDER_TABLE // returns either a XmFontList or XmRenderTable, depending // on Motif version WXFontType GetFontType(WXDisplay* display) const; diff --git a/include/wx/motif/private.h b/include/wx/motif/private.h index c19974fbe4..8bee9f9bf7 100644 --- a/include/wx/motif/private.h +++ b/include/wx/motif/private.h @@ -106,6 +106,9 @@ extern void wxGetTextExtent(WXDisplay* display, const wxFont& font, double scale, const wxString& string, int* width, int* height, 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 wxBACK_COLORS 0x01 diff --git a/include/wx/motif/stattext.h b/include/wx/motif/stattext.h index 6b53e185d4..d330e78ca3 100644 --- a/include/wx/motif/stattext.h +++ b/include/wx/motif/stattext.h @@ -55,6 +55,7 @@ public: virtual void DoSetLabel(const wxString& str); virtual wxString DoGetLabel() const; + virtual wxSize DoGetBestSize() const; protected: WXWidget m_labelWidget; }; diff --git a/include/wx/motif/window.h b/include/wx/motif/window.h index 819fe17f3e..7a8e21899f 100644 --- a/include/wx/motif/window.h +++ b/include/wx/motif/window.h @@ -147,6 +147,12 @@ public: // Process idle (send update events) void OnInternalIdle(); + // post-creation activities + void PostCreation(); + + // pre-creation activities + void PreCreation(); + protected: // Responds to colour changes: passes event on to children. void OnSysColourChanged(wxSysColourChangedEvent& event); diff --git a/src/generic/notebook.cpp b/src/generic/notebook.cpp index a77f340b2e..fd5c9f05ea 100644 --- a/src/generic/notebook.cpp +++ b/src/generic/notebook.cpp @@ -158,8 +158,6 @@ bool wxNotebook::Create(wxWindow *parent, if (!wxControl::Create(parent, id, pos, size, style|wxNO_BORDER, wxDefaultValidator, name)) return false; - SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)); - SetTabView(new wxNotebookTabView(this)); return true; diff --git a/src/generic/tabg.cpp b/src/generic/tabg.cpp index cec7c1d37a..cf1722b52c 100644 --- a/src/generic/tabg.cpp +++ b/src/generic/tabg.cpp @@ -85,7 +85,8 @@ void wxTabControl::OnDraw(wxDC& dc, bool lastInRow) // Draw grey background 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. #ifdef __WXMOTIF__ @@ -523,11 +524,11 @@ wxTabView::wxTabView(long style) m_tabViewRect.x = 300; m_highlightColour = *wxWHITE; m_shadowColour = wxColour(128, 128, 128); - m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE); + // m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE); m_textColour = *wxBLACK; m_highlightPen = wxWHITE_PEN; m_shadowPen = wxGREY_PEN; - SetBackgroundColour(m_backgroundColour); + // SetBackgroundColour(m_backgroundColour); m_tabFont = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); m_tabSelectedFont = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); m_window = (wxWindow *) NULL; @@ -797,7 +798,8 @@ void wxTabView::Draw(wxDC& dc) if (GetTabStyle() & wxTAB_STYLE_COLOUR_INTERIOR) { dc.SetPen(*wxTRANSPARENT_PEN); - dc.SetBrush(*GetBackgroundBrush()); + if(GetBackgroundBrush()) + dc.SetBrush(*GetBackgroundBrush()); // Add 1 because the pen is transparent. Under Motif, may be different. dc.DrawRectangle( diff --git a/src/motif/app.cpp b/src/motif/app.cpp index eacfa20a29..e36d19b6e6 100644 --- a/src/motif/app.cpp +++ b/src/motif/app.cpp @@ -99,15 +99,15 @@ static int wxXErrorHandler(Display *dpy, XErrorEvent *xevent) bool wxApp::Initialize(int& argcOrig, wxChar **argvOrig) { +#if wxUSE_INTL + wxFont::SetDefaultEncoding(wxLocale::GetSystemEncoding()); +#endif + if ( !wxAppBase::Initialize(argcOrig, argvOrig) ) return false; wxWidgetHashTable = new wxHashTable(wxKEY_INTEGER); -#if wxUSE_INTL - wxFont::SetDefaultEncoding(wxLocale::GetSystemEncoding()); -#endif - return true; } @@ -197,10 +197,17 @@ static char *fallbackResources[] = { wxMOTIF_STR("*sgiMode: True"), wxMOTIF_STR("*useSchemes: all"), #else // !__SGI__ - wxMOTIF_STR("*menuBar.marginHeight: 0"), - wxMOTIF_STR("*menuBar.shadowThickness: 1"), - wxMOTIF_STR("*background: #c0c0c0"), - wxMOTIF_STR("*foreground: black"), +#if !wxMOTIF_USE_RENDER_TABLE + wxMOTIF_STR("*.fontList: -*-helvetica-medium-r-normal-*-*-120-*-*-*-*-*-*"), +#else + 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__ NULL }; diff --git a/src/motif/bmpbuttn.cpp b/src/motif/bmpbuttn.cpp index 7a2c68e90e..5e94188ba4 100644 --- a/src/motif/bmpbuttn.cpp +++ b/src/motif/bmpbuttn.cpp @@ -51,6 +51,7 @@ bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id, { if( !CreateControl( parent, id, pos, size, style, validator, name ) ) return false; + PreCreation(); m_bmpNormal = m_bmpNormalOriginal = bitmap; m_bmpSelected = m_bmpSelectedOriginal = bitmap; @@ -81,12 +82,6 @@ bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id, m_mainWidget = (WXWidget) buttonWidget; - ChangeFont(false); - - ChangeBackgroundColour (); - - DoSetBitmap(); - XtAddCallback (buttonWidget, XmNactivateCallback, (XtCallbackProc) wxButtonCallback, (XtPointer) this); @@ -95,6 +90,9 @@ bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id, if( size.x != -1 ) best.x = size.x; if( size.y != -1 ) best.y = size.y; + PostCreation(); + DoSetBitmap(); + AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, best.x, best.y); diff --git a/src/motif/button.cpp b/src/motif/button.cpp index 77ce5c0242..5befa4d2f1 100644 --- a/src/motif/button.cpp +++ b/src/motif/button.cpp @@ -57,6 +57,7 @@ bool wxButton::Create(wxWindow *parent, wxWindowID id, const wxString& lbl, if( !CreateControl( parent, id, pos, size, style, validator, name ) ) return false; + PreCreation(); 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.y != -1 ) best.y = size.y; + PostCreation(); AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, best.x, best.y); - ChangeBackgroundColour(); - return true; } diff --git a/src/motif/checkbox.cpp b/src/motif/checkbox.cpp index 84dfd520a8..566e52abd7 100644 --- a/src/motif/checkbox.cpp +++ b/src/motif/checkbox.cpp @@ -44,7 +44,6 @@ #define wxHAS_3STATE 0 #endif - #include "wx/motif/private.h" 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, name ) ) return false; + PreCreation(); wxXmString text( GetLabelText(label) ); @@ -85,10 +85,10 @@ bool wxCheckBox::Create(wxWindow *parent, wxWindowID id, const wxString& label, XmToggleButtonSetState ((Widget) m_mainWidget, False, True); + PostCreation(); AttachWidget( parent, m_mainWidget, (WXWidget)NULL, pos.x, pos.y, size.x, size.y ); - ChangeBackgroundColour(); return true; } @@ -144,6 +144,9 @@ void wxCheckBoxCallback (Widget WXUNUSED(w), XtPointer clientData, void wxCheckBox::ChangeBackgroundColour() { + if (!m_backgroundColour.Ok()) + return; + wxComputeColours (XtDisplay((Widget) m_mainWidget), & m_backgroundColour, (wxColour*) NULL); diff --git a/src/motif/checklst.cpp b/src/motif/checklst.cpp index ea21e7e192..0205216a2b 100644 --- a/src/motif/checklst.cpp +++ b/src/motif/checklst.cpp @@ -134,7 +134,7 @@ void wxCheckListBox::Check(unsigned int uiIndex, bool bCheck) void wxCheckListBox::DoToggleItem( int n, int x ) { - if( x < 23 ) + if( x > 0 && x < 23 ) { wxString label = wxListBox::GetString(n); label[1u] = (!::IsChecked(label)) ? checkChar : uncheckChar; diff --git a/src/motif/choice.cpp b/src/motif/choice.cpp index 585c467600..6c7edaa117 100644 --- a/src/motif/choice.cpp +++ b/src/motif/choice.cpp @@ -71,6 +71,7 @@ bool wxChoice::Create(wxWindow *parent, wxWindowID id, { if ( !CreateControl(parent, id, pos, size, style, validator, name) ) return false; + PreCreation(); Widget parentWidget = (Widget) parent->GetClientWidget(); @@ -138,9 +139,7 @@ bool wxChoice::Create(wxWindow *parent, wxWindowID id, XtVaSetValues((Widget) m_formWidget, XmNresizePolicy, XmRESIZE_NONE, NULL); - ChangeFont(false); - ChangeBackgroundColour(); - + PostCreation(); AttachWidget (parent, m_buttonWidget, m_formWidget, 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 // to its original size! We therefore have to set the size // back again. TODO: a better way in Motif? - if (m_font.Ok()) + if (m_mainWidget && m_font.Ok()) { Display* dpy = XtDisplay((Widget) m_mainWidget); int width, height, width1, height1; diff --git a/src/motif/combobox.cpp b/src/motif/combobox.cpp index de2b16e9b1..201a8aa4ad 100644 --- a/src/motif/combobox.cpp +++ b/src/motif/combobox.cpp @@ -51,6 +51,7 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id, { if( !CreateControl( parent, id, pos, size, style, validator, name ) ) return false; + PreCreation(); m_noStrings = n; @@ -80,17 +81,14 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id, SetValue(value); - ChangeFont(false); - XtAddCallback (buttonWidget, XmNselectionCallback, (XtCallbackProc) wxComboBoxCallback, (XtPointer) this); XtAddCallback (buttonWidget, XmNvalueChangedCallback, (XtCallbackProc) wxComboBoxCallback, (XtPointer) this); + PostCreation(); AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y); - ChangeBackgroundColour(); - return true; } diff --git a/src/motif/combobox_native.cpp b/src/motif/combobox_native.cpp index 3138681bd6..242a507bd9 100644 --- a/src/motif/combobox_native.cpp +++ b/src/motif/combobox_native.cpp @@ -80,6 +80,7 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id, { if( !CreateControl( parent, id, pos, size, style, validator, name ) ) return false; + PreCreation(); Widget parentWidget = (Widget) parent->GetClientWidget(); @@ -106,8 +107,6 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id, SetValue(value); - ChangeFont(false); - XtAddCallback (buttonWidget, XmNselectionCallback, (XtCallbackProc) wxComboBoxCallback, (XtPointer) this); @@ -119,11 +118,10 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id, if( size.x != wxDefaultCoord ) best.x = size.x; if( size.y != wxDefaultCoord ) best.y = size.y; + PostCreation(); AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, best.x, best.y); - ChangeBackgroundColour(); - return true; } @@ -407,7 +405,7 @@ void wxComboBoxCallback (Widget WXUNUSED(w), XtPointer clientData, void wxComboBox::ChangeFont(bool keepOriginalSize) { - if( m_font.Ok() ) + if( m_font.Ok() && m_mainWidget != NULL ) { wxDoChangeFont( GetXmText(this), m_font ); wxDoChangeFont( GetXmList(this), m_font ); diff --git a/src/motif/control.cpp b/src/motif/control.cpp index 4026913541..3d6cdf909c 100644 --- a/src/motif/control.cpp +++ b/src/motif/control.cpp @@ -37,9 +37,6 @@ END_EVENT_TABLE() // Item members wxControl::wxControl() { - m_backgroundColour = *wxWHITE; - m_foregroundColour = *wxBLACK; - m_inSetValue = false; } @@ -72,10 +69,6 @@ bool wxControl::CreateControl(wxWindow *parent, validator, name ) ) return false; - m_backgroundColour = parent->GetBackgroundColour(); - m_foregroundColour = parent->GetForegroundColour(); - m_font = parent->GetFont(); - return true; } diff --git a/src/motif/dcclient.cpp b/src/motif/dcclient.cpp index 1a3ec55e8d..56ad7af018 100644 --- a/src/motif/dcclient.cpp +++ b/src/motif/dcclient.cpp @@ -179,8 +179,16 @@ wxWindowDC::wxWindowDC( wxWindow *window ) gcvalues.graphics_exposures = False; gcvalues.subwindow_mode = IncludeInferiors; 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)), - GCForeground | GCBackground | GCGraphicsExposures | GCLineWidth | GCSubwindowMode, + GCForeground | GCBackground | GCGraphicsExposures | GCLineWidth | GCSubwindowMode +#if !wxMOTIF_NEW_FONT_HANDLING + | GCFont +#endif + , &gcvalues); if (m_window->GetBackingPixmap()) @@ -1685,7 +1693,7 @@ void wxWindowDC::SetPen( const wxPen &pen ) if (m_window && m_window->GetBackingPixmap()) 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)) { XSetStipple ((Display*) m_display, (GC) m_gc, (Pixmap) m_currentStipple.GetDrawable()); diff --git a/src/motif/dialog.cpp b/src/motif/dialog.cpp index 9eceb43581..b34a7ae801 100644 --- a/src/motif/dialog.cpp +++ b/src/motif/dialog.cpp @@ -75,7 +75,6 @@ wxDialog::wxDialog() { m_modalShowing = false; m_eventLoop = NULL; - m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE); } bool wxDialog::Create(wxWindow *parent, wxWindowID id, @@ -94,16 +93,10 @@ bool wxDialog::Create(wxWindow *parent, wxWindowID id, m_modalShowing = false; m_eventLoop = NULL; - m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE); - m_foregroundColour = *wxBLACK; - Widget dialogShell = (Widget) m_mainWidget; 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. #if wxUSE_INVISIBLE_RESIZE if (pos.x > -1) @@ -135,7 +128,7 @@ bool wxDialog::Create(wxWindow *parent, wxWindowID id, XtAddEventHandler(dialogShell,ExposureMask,False, wxUniversalRepaintProc, (XtPointer) this); - ChangeBackgroundColour(); + PostCreation(); return true; } diff --git a/src/motif/evtloop.cpp b/src/motif/evtloop.cpp index 84999bb11e..9ed21e2ada 100644 --- a/src/motif/evtloop.cpp +++ b/src/motif/evtloop.cpp @@ -17,14 +17,14 @@ // headers // ---------------------------------------------------------------------------- +// For compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + #ifdef __VMS #define XtParent XTPARENT #define XtDisplay XTDISPLAY #endif -// For compilers that support precompilation, includes "wx.h". -#include "wx/wxprec.h" - #ifndef WX_PRECOMP #include "wx/event.h" #include "wx/app.h" diff --git a/src/motif/filedlg.cpp b/src/motif/filedlg.cpp index 1684607914..6ab59b0205 100644 --- a/src/motif/filedlg.cpp +++ b/src/motif/filedlg.cpp @@ -172,12 +172,15 @@ int wxFileDialog::ShowModal() Arg args[10]; 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], XmNtopShadowColor, g_itemColors[wxTOPS_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], XmNbackground, g_itemColors[wxBACK_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], XmNforeground, g_itemColors[wxFORE_INDEX].pixel); ac++; + } wxFont font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); diff --git a/src/motif/font.cpp b/src/motif/font.cpp index db64aa47da..42e6e1e70f 100644 --- a/src/motif/font.cpp +++ b/src/motif/font.cpp @@ -59,7 +59,7 @@ public: #if !wxMOTIF_NEW_FONT_HANDLING WXFontStructPtr m_fontStruct; // XFontStruct #endif -#if !wxMOTIF_USE_RENDER_TABLE && !wxMOTIF_NEW_FONT_HANDLING +#if !wxMOTIF_USE_RENDER_TABLE WXFontList m_fontList; // Motif XmFontList #else // if wxUSE_RENDER_TABLE WXRenderTable m_renderTable; // Motif XmRenderTable @@ -131,7 +131,7 @@ wxXFont::wxXFont() #if !wxMOTIF_NEW_FONT_HANDLING m_fontStruct = (WXFontStructPtr) 0; #endif -#if !wxMOTIF_USE_RENDER_TABLE && !wxMOTIF_NEW_FONT_HANDLING +#if !wxMOTIF_USE_RENDER_TABLE m_fontList = (WXFontList) 0; #else // if wxMOTIF_USE_RENDER_TABLE m_renderTable = (WXRenderTable) 0; @@ -635,7 +635,7 @@ WXFontType wxFont::GetFontTypeC(WXDisplay* display) const #endif } -#if wxMOTIF_NEW_FONT_HANDLING +#if wxMOTIF_USE_RENDER_TABLE 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; } -#else // if !wxMOTIF_NEW_FONT_HANDLING +#else // if !wxMOTIF_USE_RENDER_TABLE void wxGetTextExtent(WXDisplay* display, const wxFont& font, double scale, const wxString& str, @@ -692,4 +692,4 @@ void wxGetTextExtent(WXDisplay* display, const wxFont& font, *ascent = ascent2; } -#endif // !wxMOTIF_NEW_FONT_HANDLING +#endif // !wxMOTIF_USE_RENDER_TABLE diff --git a/src/motif/frame.cpp b/src/motif/frame.cpp index 8de4757af2..6870ed2bc2 100644 --- a/src/motif/frame.cpp +++ b/src/motif/frame.cpp @@ -130,11 +130,6 @@ bool wxFrame::Create(wxWindow *parent, name ) ) 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 width = size.x, height = size.y; @@ -180,10 +175,7 @@ bool wxFrame::Create(wxWindow *parent, if (height > -1) XtVaSetValues((Widget) m_frameShell, XmNheight, height, NULL); - ChangeFont(false); - - ChangeBackgroundColour(); - + PostCreation(); PreResize(); wxSize newSize(width, height); @@ -398,6 +390,12 @@ void wxFrame::DoSetClientSize(int width, int height) void wxFrame::DoGetSize(int *width, int *height) const { + if (!m_frameShell) + { + *width = -1; *height = -1; + return; + } + Dimension xx, yy; XtVaGetValues((Widget) m_frameShell, XmNwidth, &xx, XmNheight, &yy, NULL); *width = xx; *height = yy; diff --git a/src/motif/gauge.cpp b/src/motif/gauge.cpp index c809994fbc..4ccdf87265 100644 --- a/src/motif/gauge.cpp +++ b/src/motif/gauge.cpp @@ -109,6 +109,7 @@ bool wxGauge::Create(wxWindow *parent, wxWindowID id, { if( !CreateControl( parent, id, pos, size, style, validator, name ) ) return false; + PreCreation(); 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.y != wxDefaultCoord ) best.y = size.y; - ChangeFont(false); - + PostCreation(); AttachWidget (parent, m_mainWidget, (WXWidget) NULL, x, y, best.x, best.y); - ChangeBackgroundColour(); - return true; } diff --git a/src/motif/listbox.cpp b/src/motif/listbox.cpp index 817b9b1c99..74b891b293 100644 --- a/src/motif/listbox.cpp +++ b/src/motif/listbox.cpp @@ -52,21 +52,23 @@ static void wxListBoxCallback(Widget w, class wxSizeKeeper { int m_x, m_y; - wxWindow* m_w; + int m_w, m_h; + wxWindow* m_wnd; public: 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() { int x, y; - m_w->GetSize( &x, &y ); + m_wnd->GetSize( &x, &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, validator, name ) ) return false; + PreCreation(); m_noItems = (unsigned int)n; - m_backgroundColour = * wxWHITE; Widget parentWidget = (Widget) parent->GetClientWidget(); Display* dpy = XtDisplay(parentWidget); @@ -149,11 +151,10 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id, (XtCallbackProc) wxListBoxCallback, (XtPointer) this); + PostCreation(); AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, best.x, best.y); - ChangeBackgroundColour(); - return true; } diff --git a/src/motif/mdi.cpp b/src/motif/mdi.cpp index 1373b0b925..fe31aa958a 100644 --- a/src/motif/mdi.cpp +++ b/src/motif/mdi.cpp @@ -338,10 +338,6 @@ bool wxMDIChildFrame::Create(wxMDIParentFrame *parent, SetName(name); SetWindowStyleFlag(style); - m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE); - m_foregroundColour = *wxBLACK; - m_font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); - if ( id > -1 ) m_windowId = id; else @@ -354,6 +350,7 @@ bool wxMDIChildFrame::Create(wxMDIParentFrame *parent, clientWindow->AddChild(this); SetMDIParentFrame(parent); + PreCreation(); int width = size.x; int height = size.y; @@ -393,10 +390,9 @@ bool wxMDIChildFrame::Create(wxMDIParentFrame *parent, XtAddEventHandler((Widget) m_mainWidget, ExposureMask,False, wxUniversalRepaintProc, (XtPointer) this); + PostCreation(); AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y); - ChangeBackgroundColour(); - XtManageChild((Widget) m_mainWidget); SetTitle(title); @@ -640,14 +636,9 @@ bool wxMDIClientWindow::CreateClient(wxMDIParentFrame *parent, long 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); if (success) { - wxFont font(10, wxSWISS, wxNORMAL, wxNORMAL); - SetFont(font); return true; } else diff --git a/src/motif/menu.cpp b/src/motif/menu.cpp index abbe28a365..00637cc3b8 100644 --- a/src/motif/menu.cpp +++ b/src/motif/menu.cpp @@ -82,10 +82,6 @@ void wxMenu::Init() Append(-3, m_title) ; 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. @@ -190,9 +186,6 @@ void wxMenuBar::Init() m_eventHandler = this; m_menuBarFrame = 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)) @@ -349,6 +342,10 @@ wxMenuItem *wxMenuBar::FindItem(int id, wxMenu ** itemMenu) const // Create menubar bool wxMenuBar::CreateMenuBar(wxFrame* parent) { + m_parent = parent; // bleach... override it! + PreCreation(); + m_parent = NULL; + if (m_mainWidget) { XtVaSetValues((Widget) parent->GetMainWidget(), XmNmenuBar, (Widget) m_mainWidget, NULL); @@ -388,9 +385,7 @@ bool wxMenuBar::CreateMenuBar(wxFrame* parent) } } - SetBackgroundColour(m_backgroundColour); - SetForegroundColour(m_foregroundColour); - SetFont(m_font); + PostCreation(); XtVaSetValues((Widget) parent->GetMainWidget(), XmNmenuBar, (Widget) m_mainWidget, NULL); XtRealizeWidget ((Widget) menuBarW); @@ -474,13 +469,24 @@ WXWidget wxMenu::CreateMenu (wxMenuBar * menuBar, { Widget menu = (Widget) 0; Widget buttonWidget = (Widget) 0; + Display* dpy = XtDisplay((Widget)parent); Arg args[5]; XtSetArg (args[0], XmNnumColumns, m_numColumns); 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) { - menu = XmCreatePopupMenu ((Widget) parent, wxMOTIF_STR("popup"), args, 2); + menu = XmCreatePopupMenu ((Widget) parent, wxMOTIF_STR("popup"), args, 3); #if 0 XtAddCallback(menu, XmNunmapCallback, @@ -491,7 +497,7 @@ WXWidget wxMenu::CreateMenu (wxMenuBar * menuBar, else { 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)); wxXmString label_str(title2); @@ -503,6 +509,8 @@ WXWidget wxMenu::CreateMenu (wxMenuBar * menuBar, #endif XmNlabelString, label_str(), XmNsubMenuId, menu, + (String)wxFont::GetFontTag(), m_font.GetFontTypeC(dpy), + XmNpositionIndex, index, NULL); if (mnem != 0) @@ -523,9 +531,7 @@ WXWidget wxMenu::CreateMenu (wxMenuBar * menuBar, item->CreateItem(menu, menuBar, topMenu, i); } - SetBackgroundColour(m_backgroundColour); - SetForegroundColour(m_foregroundColour); - SetFont(m_font); + ChangeFont(); return buttonWidget; } @@ -600,6 +606,8 @@ WXWidget wxMenu::FindMenuItem (int id, wxMenuItem ** it) const void wxMenu::SetBackgroundColour(const wxColour& col) { m_backgroundColour = col; + if (!col.Ok()) + return; if (m_menuWidget) wxDoChangeBackgroundColour(m_menuWidget, (wxColour&) col); if (m_buttonWidget) @@ -623,6 +631,8 @@ void wxMenu::SetBackgroundColour(const wxColour& col) void wxMenu::SetForegroundColour(const wxColour& col) { m_foregroundColour = col; + if (!col.Ok()) + return; if (m_menuWidget) wxDoChangeForegroundColour(m_menuWidget, (wxColour&) col); if (m_buttonWidget) @@ -689,7 +699,10 @@ void wxMenu::SetFont(const wxFont& font) bool wxMenuBar::SetBackgroundColour(const wxColour& col) { - m_backgroundColour = col; + if (!wxWindowBase::SetBackgroundColour(col)) + return false; + if (!col.Ok()) + return false; if (m_mainWidget) wxDoChangeBackgroundColour(m_mainWidget, (wxColour&) col); @@ -702,7 +715,10 @@ bool wxMenuBar::SetBackgroundColour(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) wxDoChangeForegroundColour(m_mainWidget, (wxColour&) col); diff --git a/src/motif/msgdlg.cpp b/src/motif/msgdlg.cpp index fe8e598e30..f103cfc0d1 100644 --- a/src/motif/msgdlg.cpp +++ b/src/motif/msgdlg.cpp @@ -167,12 +167,15 @@ int wxMessageDialog::ShowModal() 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], XmNtopShadowColor, g_itemColors[wxTOPS_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], XmNbackground, g_itemColors[wxBACK_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], XmNforeground, g_itemColors[wxFORE_INDEX].pixel); ac++; + } wxFont font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); diff --git a/src/motif/popupwin.cpp b/src/motif/popupwin.cpp index 30aab7ea17..ffa6837734 100644 --- a/src/motif/popupwin.cpp +++ b/src/motif/popupwin.cpp @@ -44,11 +44,19 @@ bool wxPopupWindow::Create( wxWindow *parent, int flags ) 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 ); XtRealizeWidget( popup ); - + XtManageChild ( popup ); +/* + XtTranslations ptr; + XtOverrideTranslations (popup, + ptr = XtParseTranslationTable (": resize()")); + XtFree ((char *) ptr); +*/ return true; } @@ -59,7 +67,7 @@ bool wxPopupWindow::Show( bool show ) if( show ) { - XtPopup( (Widget)GetMainWidget(), XtGrabNone ); + XtPopup( (Widget)GetMainWidget(), XtGrabNonexclusive ); } else { diff --git a/src/motif/radiobox.cpp b/src/motif/radiobox.cpp index fa0f0dbfca..e6a71ba4fb 100644 --- a/src/motif/radiobox.cpp +++ b/src/motif/radiobox.cpp @@ -51,6 +51,7 @@ void wxRadioBox::Init() m_selectedButton = -1; m_noItems = 0; m_noRowsOrCols = 0; + m_labelWidget = (WXWidget) 0; } 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 ) ) return false; + PreCreation(); m_noItems = (unsigned int)n; m_noRowsOrCols = majorDim; @@ -137,18 +139,15 @@ bool wxRadioBox::Create(wxWindow *parent, wxWindowID id, const wxString& title, (XtPointer) this); } - ChangeFont(false); - SetSelection (0); XtRealizeWidget((Widget)m_mainWidget); XtManageChild (radioBoxWidget); XtManageChild ((Widget)m_mainWidget); + PostCreation(); AttachWidget (parent, m_mainWidget, NULL, pos.x, pos.y, size.x, size.y); - ChangeBackgroundColour(); - return true; } diff --git a/src/motif/radiobut.cpp b/src/motif/radiobut.cpp index 00ec024178..4ac378762e 100644 --- a/src/motif/radiobut.cpp +++ b/src/motif/radiobut.cpp @@ -51,6 +51,7 @@ bool wxRadioButton::Create(wxWindow *parent, wxWindowID id, { if( !CreateControl( parent, id, pos, size, style, validator, name ) ) return false; + PreCreation(); Widget parentWidget = (Widget) parent->GetClientWidget(); Display* dpy = XtDisplay(parentWidget); @@ -80,11 +81,10 @@ bool wxRadioButton::Create(wxWindow *parent, wxWindowID id, XtManageChild (radioButtonWidget); + PostCreation(); AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y); - ChangeBackgroundColour(); - //copied from mac/radiobut.cpp (from here till "return true;") m_cycle = this ; diff --git a/src/motif/scrolbar.cpp b/src/motif/scrolbar.cpp index 6cbdf29c23..9c35d48ea3 100644 --- a/src/motif/scrolbar.cpp +++ b/src/motif/scrolbar.cpp @@ -40,6 +40,7 @@ bool wxScrollBar::Create(wxWindow *parent, wxWindowID id, { if( !CreateControl( parent, id, pos, size, style, validator, name ) ) return false; + PreCreation(); wxSize newSize = ( style & wxHORIZONTAL ) ? wxSize( 140, 16 ) : wxSize( 16, 140 ); @@ -53,9 +54,9 @@ bool wxScrollBar::Create(wxWindow *parent, wxWindowID id, (wxOrientation)(style & (wxHORIZONTAL|wxVERTICAL)), (void (*)())wxScrollBarCallback ); + PostCreation(); AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, newSize.x, newSize.y); - ChangeBackgroundColour(); return true; } diff --git a/src/motif/slider.cpp b/src/motif/slider.cpp index 8e52931335..6b012f2964 100644 --- a/src/motif/slider.cpp +++ b/src/motif/slider.cpp @@ -64,6 +64,7 @@ bool wxSlider::Create(wxWindow *parent, wxWindowID id, if( !CreateControl( parent, id, pos, size, style, validator, name ) ) return false; + PreCreation(); m_lineSize = 1; m_windowStyle = style; @@ -93,11 +94,9 @@ bool wxSlider::Create(wxWindow *parent, wxWindowID id, XtAddCallback (sliderWidget, XmNvalueChangedCallback, (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); - ChangeBackgroundColour(); - return true; } diff --git a/src/motif/spinbutt.cpp b/src/motif/spinbutt.cpp index a84d1f38dd..abee5b0bb6 100644 --- a/src/motif/spinbutt.cpp +++ b/src/motif/spinbutt.cpp @@ -210,6 +210,7 @@ bool wxArrowButton::Create( wxSpinButton* parent, } parent->AddChild( this ); + PreCreation(); Widget parentWidget = (Widget) parent->GetClientWidget(); m_mainWidget = (WXWidget) XtVaCreateManagedWidget( "XmArrowButton", @@ -230,11 +231,10 @@ bool wxArrowButton::Create( wxSpinButton* parent, XmNactivateCallback, (XtCallbackProc) StopTimerCallback, (XtPointer) this ); + PostCreation(); AttachWidget( parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y ); - SetForegroundColour( parent->GetBackgroundColour() ); - return true; } diff --git a/src/motif/statbmp.cpp b/src/motif/statbmp.cpp index 13dd72ae88..89a74c3792 100644 --- a/src/motif/statbmp.cpp +++ b/src/motif/statbmp.cpp @@ -42,6 +42,7 @@ bool wxStaticBitmap::Create(wxWindow *parent, wxWindowID id, if( !CreateControl( parent, id, pos, size, style, wxDefaultValidator, name ) ) return false; + PreCreation(); m_messageBitmap = bitmap; m_messageBitmapOriginal = bitmap; @@ -57,18 +58,15 @@ bool wxStaticBitmap::Create(wxWindow *parent, wxWindowID id, XmNalignment, XmALIGNMENT_BEGINNING, NULL); - ChangeBackgroundColour (); - - DoSetBitmap(); - - ChangeFont(false); - wxSize actualSize(size); // work around the cases where the bitmap is a wxNull(Icon/Bitmap) if (actualSize.x == -1) actualSize.x = bitmap.Ok() ? bitmap.GetWidth() : 1; if (actualSize.y == -1) actualSize.y = bitmap.Ok() ? bitmap.GetHeight() : 1; + + PostCreation(); + DoSetBitmap(); AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, actualSize.x, actualSize.y); diff --git a/src/motif/statbox.cpp b/src/motif/statbox.cpp index ae4838acdc..22deeec8c9 100644 --- a/src/motif/statbox.cpp +++ b/src/motif/statbox.cpp @@ -93,6 +93,8 @@ bool wxStaticBox::Create(wxWindow *parent, wxWindowID id, if( !CreateControl( parent, id, pos, size, style, wxDefaultValidator, name ) ) return false; + m_labelWidget = (WXWidget) 0; + PreCreation(); Widget parentWidget = (Widget) parent->GetClientWidget(); @@ -119,9 +121,9 @@ bool wxStaticBox::Create(wxWindow *parent, wxWindowID id, #endif NULL); } - + + PostCreation(); AttachWidget (parent, m_mainWidget, NULL, pos.x, pos.y, size.x, size.y); - ChangeBackgroundColour(); return true; } diff --git a/src/motif/stattext.cpp b/src/motif/stattext.cpp index fce5aaf4f0..f233a51080 100644 --- a/src/motif/stattext.cpp +++ b/src/motif/stattext.cpp @@ -42,6 +42,8 @@ bool wxStaticText::Create(wxWindow *parent, wxWindowID id, if( !CreateControl( parent, id, pos, size, style, wxDefaultValidator, name ) ) return false; + m_labelWidget = (WXWidget) 0; + PreCreation(); Widget parentWidget = (Widget) parent->GetClientWidget(); @@ -61,12 +63,15 @@ bool wxStaticText::Create(wxWindow *parent, wxWindowID id, m_mainWidget = borderWidget ? borderWidget : m_labelWidget; - AttachWidget (parent, m_mainWidget, (WXWidget) NULL, - pos.x, pos.y, size.x, size.y); + SetLabel(label); - ChangeBackgroundColour (); + wxSize best = GetBestSize(); + if( size.x != -1 ) best.x = size.x; + if( size.y != -1 ) best.y = size.y; - SetLabel(label); + PostCreation(); + AttachWidget (parent, m_mainWidget, (WXWidget) NULL, + pos.x, pos.y, best.x, best.y); return true; } @@ -108,4 +113,12 @@ void wxStaticText::DoSetLabel(const wxString& str) 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 diff --git a/src/motif/textctrl.cpp b/src/motif/textctrl.cpp index 20d462eabe..1fd22c3af5 100644 --- a/src/motif/textctrl.cpp +++ b/src/motif/textctrl.cpp @@ -110,13 +110,12 @@ bool wxTextCtrl::Create(wxWindow *parent, { if( !CreateControl( parent, id, pos, size, style, validator, name ) ) return false; + PreCreation(); m_tempCallbackStruct = (void*) NULL; m_modified = false; m_processedDefault = false; - m_backgroundColour = *wxWHITE; - Widget parentWidget = (Widget) parent->GetClientWidget(); Bool wantHorizScroll = (m_windowStyle & wxHSCROLL) != 0 ? True : False; @@ -135,8 +134,9 @@ bool wxTextCtrl::Create(wxWindow *parent, Arg args[8]; int count = 0; XtSetArg (args[count], XmNscrollHorizontal, wantHorizScroll); ++count; - XtSetArg (args[count], (String) wxFont::GetFontTag(), - m_font.GetFontType( XtDisplay(parentWidget) ) ); ++count; + if( m_font.IsOk() ) + XtSetArg (args[count], (String) wxFont::GetFontTag(), + m_font.GetFontType( XtDisplay(parentWidget) ) ); ++count; XtSetArg (args[count], XmNwordWrap, wantWordWrap); ++count; XtSetArg (args[count], XmNvalue, value.mb_str()); ++count; XtSetArg (args[count], XmNeditable, @@ -194,11 +194,10 @@ bool wxTextCtrl::Create(wxWindow *parent, XtAddCallback((Widget) m_mainWidget, XmNlosingFocusCallback, (XtCallbackProc)wxTextWindowLoseFocusProc, (XtPointer)this); + PostCreation(); AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y); - ChangeBackgroundColour(); - return true; } @@ -667,8 +666,8 @@ wxSize wxDoGetSingleTextCtrlBestSize( Widget textWidget, int x, y; window->GetTextExtent( value, &x, &y ); - if( x < 100 ) - x = 100; + if( x < 90 ) + x = 90; return wxSize( x + 2 * xmargin + 2 * highlight + 2 * shadow, // MBN: +2 necessary: Lesstif bug or mine? @@ -680,10 +679,16 @@ wxSize wxTextCtrl::DoGetBestSize() const if( IsSingleLine() ) { wxSize best = wxControl::DoGetBestSize(); - - if( best.x < 110 ) best.x = 110; +#if wxCHECK_MOTIF_VERSION( 2, 3 ) + // 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; +#endif } else return wxWindow::DoGetBestSize(); diff --git a/src/motif/toolbar.cpp b/src/motif/toolbar.cpp index 98619468b5..cbb8223d82 100644 --- a/src/motif/toolbar.cpp +++ b/src/motif/toolbar.cpp @@ -204,11 +204,10 @@ bool wxToolBar::Create(wxWindow *parent, if( !wxControl::CreateControl( parent, id, pos, size, style, wxDefaultValidator, name ) ) return false; + PreCreation(); FixupStyle(); - m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE); - Widget parentWidget = (Widget) parent->GetClientWidget(); Widget toolbar = XtVaCreateManagedWidget("toolbar", @@ -232,8 +231,6 @@ bool wxToolBar::Create(wxWindow *parent, m_mainWidget = (WXWidget) toolbar; - ChangeFont(false); - wxPoint rPos = pos; wxSize rSize = size; @@ -242,11 +239,10 @@ bool wxToolBar::Create(wxWindow *parent, if( rSize.x == -1 && GetParent() ) rSize.x = GetParent()->GetSize().x; + PostCreation(); AttachWidget (parent, m_mainWidget, (WXWidget) NULL, rPos.x, rPos.y, rSize.x, rSize.y); - ChangeBackgroundColour(); - return true; } diff --git a/src/motif/toplevel.cpp b/src/motif/toplevel.cpp index 5ce626267a..aaa53556da 100644 --- a/src/motif/toplevel.cpp +++ b/src/motif/toplevel.cpp @@ -21,6 +21,8 @@ #include "wx/wxprec.h" #include "wx/toplevel.h" +#include "wx/settings.h" +#include "wx/app.h" #ifndef WX_PRECOMP #include "wx/app.h" @@ -112,6 +114,9 @@ bool wxTopLevelWindowMotif::Create( wxWindow *parent, wxWindowID id, wxTopLevelWindows.Append(this); 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 ); diff --git a/src/motif/utils.cpp b/src/motif/utils.cpp index 1f5d60838a..d60e87705e 100644 --- a/src/motif/utils.cpp +++ b/src/motif/utils.cpp @@ -524,6 +524,9 @@ XmString wxFindAcceleratorText (const char *s) // Change a widget's foreground and background colours. void wxDoChangeForegroundColour(WXWidget widget, wxColour& foregroundColour) { + if (!foregroundColour.Ok()) + return; + // When should we specify the foreground, if it's calculated // by wxComputeColours? // 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) { + if (!backgroundColour.Ok()) + return; + wxComputeColours (XtDisplay((Widget) widget), & backgroundColour, (wxColour*) NULL); diff --git a/src/motif/window.cpp b/src/motif/window.cpp index a99a8bb706..9a7d7eb156 100644 --- a/src/motif/window.cpp +++ b/src/motif/window.cpp @@ -235,9 +235,7 @@ bool wxWindow::Create(wxWindow *parent, wxWindowID id, CreateBase(parent, id, pos, size, style, wxDefaultValidator, name); parent->AddChild(this); - - m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE); - m_foregroundColour = *wxBLACK; + PreCreation(); //// TODO: we should probably optimize by only creating a //// 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 ); - // 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( (Widget)m_scrolledWindow, (Widget) 0, (Widget) 0, (Widget) m_drawingArea); + PostCreation(); + // Without this, the cursor may not be restored properly (e.g. in splitter // sample). SetCursor(*wxSTANDARD_CURSOR); - SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); DoSetSizeIntr(pos.x, pos.y, size.x,size.y, wxSIZE_AUTO, true); return true; } @@ -1173,12 +1166,13 @@ void wxWindow::DoGetSize(int *x, int *y) const m_drawingArea ) ); Dimension xx, yy; - XtVaGetValues( widget, - XmNwidth, &xx, - XmNheight, &yy, - NULL ); - if(x) *x = xx; - if(y) *y = yy; + if (widget) + XtVaGetValues( widget, + XmNwidth, &xx, + XmNheight, &yy, + NULL ); + if(x) *x = widget ? xx : -1; + if(y) *y = widget ? yy : -1; } 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); } + if (x == -1) + x = oldX; + if (x == -1) + x = oldY; + if ( !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) ) { if ( width == -1 ) @@ -1457,24 +1456,26 @@ void wxWindow::DoMoveWindow(int x, int y, int width, int height) int wxWindow::GetCharHeight() const { - wxCHECK_MSG( m_font.Ok(), 0, "valid window font needed" ); - int height; - wxGetTextExtent (GetXDisplay(), m_font, 1.0, - "x", NULL, &height, NULL, NULL); + if (m_font.Ok()) + wxGetTextExtent (GetXDisplay(), m_font, 1.0, + "x", NULL, &height, NULL, NULL); + else + wxGetTextExtent (this, "x", NULL, &height, NULL, NULL); return height; } int wxWindow::GetCharWidth() const { - wxCHECK_MSG( m_font.Ok(), 0, "valid window font needed" ); - int width; - wxGetTextExtent (GetXDisplay(), m_font, 1.0, - "x", &width, NULL, NULL, NULL); + if (m_font.Ok()) + wxGetTextExtent (GetXDisplay(), m_font, 1.0, + "x", &width, NULL, NULL, NULL); + else + wxGetTextExtent (this, "x", &width, NULL, NULL, NULL); return width; } @@ -1486,12 +1487,13 @@ void wxWindow::GetTextExtent(const wxString& string, { const wxFont *fontToUse = theFont ? theFont : &m_font; - wxCHECK_RET( fontToUse->Ok(), "valid window font needed" ); - if (externalLeading) *externalLeading = 0; - wxGetTextExtent (GetXDisplay(), *fontToUse, 1.0, - string, x, y, NULL, descent); + if (fontToUse->Ok()) + 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) { + Widget widget = (Widget) GetMainWidget(); + if (!widget) + return; m_needsRefresh = true; - Display *display = XtDisplay((Widget) GetMainWidget()); - Window thisWindow = XtWindow((Widget) GetMainWidget()); + Display *display = XtDisplay(widget); + Window thisWindow = XtWindow(widget); XExposeEvent dummyEvent; int width, height; @@ -2494,7 +2499,7 @@ void wxWindow::ChangeFont(bool keepOriginalSize) int width, height, width1, height1; GetSize(& width, & height); - wxDoChangeFont( GetLabelWidget(), m_font ); + wxDoChangeFont( w, m_font ); GetSize(& width1, & 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 // ---------------------------------------------------------------------------- @@ -2578,6 +2597,104 @@ wxMouseState wxGetMouseState() } +#if wxMOTIF_NEW_FONT_HANDLING + +#include + +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 // ---------------------------------------------------------------------------- -- 2.45.2