From f40fdaa339e19bbdf60c9c065c82daae4ca77b36 Mon Sep 17 00:00:00 2001 From: =?utf8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Mon, 14 Jun 2004 17:34:00 +0000 Subject: [PATCH] fixed GTK styles handling: 1. don't modify the style unless something changed 2. use gtk_widget_modify_style instead of gtk_widget_set_style, the latter is not recommended by GTK+ developers git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@27784 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 2 +- include/wx/defs.h | 2 +- include/wx/gtk/bmpbuttn.h | 2 +- include/wx/gtk/button.h | 2 +- include/wx/gtk/checkbox.h | 2 +- include/wx/gtk/choice.h | 2 +- include/wx/gtk/combobox.h | 2 +- include/wx/gtk/control.h | 5 ++ include/wx/gtk/gauge.h | 2 - include/wx/gtk/listbox.h | 2 +- include/wx/gtk/notebook.h | 2 +- include/wx/gtk/radiobox.h | 2 +- include/wx/gtk/radiobut.h | 2 +- include/wx/gtk/scrolbar.h | 1 - include/wx/gtk/slider.h | 1 - include/wx/gtk/spinbutt.h | 1 - include/wx/gtk/spinctrl.h | 1 - include/wx/gtk/statbox.h | 2 - include/wx/gtk/stattext.h | 2 - include/wx/gtk/textctrl.h | 2 +- include/wx/gtk/tglbtn.h | 4 +- include/wx/gtk/window.h | 24 ++---- include/wx/gtk1/bmpbuttn.h | 2 +- include/wx/gtk1/button.h | 2 +- include/wx/gtk1/checkbox.h | 2 +- include/wx/gtk1/choice.h | 2 +- include/wx/gtk1/combobox.h | 2 +- include/wx/gtk1/control.h | 5 ++ include/wx/gtk1/gauge.h | 2 - include/wx/gtk1/listbox.h | 2 +- include/wx/gtk1/notebook.h | 2 +- include/wx/gtk1/radiobox.h | 2 +- include/wx/gtk1/radiobut.h | 2 +- include/wx/gtk1/scrolbar.h | 1 - include/wx/gtk1/slider.h | 1 - include/wx/gtk1/spinbutt.h | 1 - include/wx/gtk1/spinctrl.h | 1 - include/wx/gtk1/statbox.h | 2 - include/wx/gtk1/stattext.h | 2 - include/wx/gtk1/textctrl.h | 2 +- include/wx/gtk1/tglbtn.h | 4 +- include/wx/gtk1/window.h | 24 ++---- src/gtk/bmpbuttn.cpp | 4 +- src/gtk/button.cpp | 7 +- src/gtk/checkbox.cpp | 7 +- src/gtk/choice.cpp | 14 ++-- src/gtk/combobox.cpp | 19 ++--- src/gtk/control.cpp | 23 ++++++ src/gtk/gauge.cpp | 6 -- src/gtk/listbox.cpp | 18 ++--- src/gtk/notebook.cpp | 53 +++--------- src/gtk/radiobox.cpp | 10 +-- src/gtk/radiobut.cpp | 7 +- src/gtk/scrolbar.cpp | 6 -- src/gtk/slider.cpp | 6 -- src/gtk/spinbutt.cpp | 8 +- src/gtk/spinctrl.cpp | 6 -- src/gtk/statbox.cpp | 6 -- src/gtk/stattext.cpp | 6 -- src/gtk/textctrl.cpp | 5 +- src/gtk/tglbtn.cpp | 14 ++-- src/gtk/window.cpp | 161 ++++++++++--------------------------- src/gtk1/bmpbuttn.cpp | 4 +- src/gtk1/button.cpp | 7 +- src/gtk1/checkbox.cpp | 7 +- src/gtk1/choice.cpp | 14 ++-- src/gtk1/combobox.cpp | 19 ++--- src/gtk1/control.cpp | 23 ++++++ src/gtk1/gauge.cpp | 6 -- src/gtk1/listbox.cpp | 18 ++--- src/gtk1/notebook.cpp | 53 +++--------- src/gtk1/radiobox.cpp | 10 +-- src/gtk1/radiobut.cpp | 7 +- src/gtk1/scrolbar.cpp | 6 -- src/gtk1/slider.cpp | 6 -- src/gtk1/spinbutt.cpp | 8 +- src/gtk1/spinctrl.cpp | 6 -- src/gtk1/statbox.cpp | 6 -- src/gtk1/stattext.cpp | 6 -- src/gtk1/textctrl.cpp | 5 +- src/gtk1/tglbtn.cpp | 14 ++-- src/gtk1/window.cpp | 161 ++++++++++--------------------------- 82 files changed, 294 insertions(+), 608 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index f8978bcd3d..6a0e2c0e39 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -119,7 +119,7 @@ Unix: wxGTK: -- fixed wrong colour of tooltips under some themes +- fixed many rendering artifacts and wrong colours with lots of GTK+ themes - implemented wxColourDialog as native dialog - wxTreeCtrl::GetCount() counts root as well now (compatible with MSW) diff --git a/include/wx/defs.h b/include/wx/defs.h index 74eb5b8e91..56044c1f81 100644 --- a/include/wx/defs.h +++ b/include/wx/defs.h @@ -2342,7 +2342,7 @@ typedef struct _GdkICAttr GdkICAttr; /* Stand-ins for GTK types */ typedef struct _GtkWidget GtkWidget; -typedef struct _GtkStyle GtkStyle; +typedef struct _GtkRcStyle GtkRcStyle; typedef struct _GtkAdjustment GtkAdjustment; typedef struct _GtkList GtkList; typedef struct _GtkToolbar GtkToolbar; diff --git a/include/wx/gtk/bmpbuttn.h b/include/wx/gtk/bmpbuttn.h index c71501e59a..f4d71460df 100644 --- a/include/wx/gtk/bmpbuttn.h +++ b/include/wx/gtk/bmpbuttn.h @@ -61,7 +61,7 @@ public: void NotFocus(); void StartSelect(); void EndSelect(); - void ApplyWidgetStyle(); + void DoApplyWidgetStyle(GtkRcStyle *style); bool m_hasFocus:1; bool m_isSelected:1; diff --git a/include/wx/gtk/button.h b/include/wx/gtk/button.h index 3a55ddec52..59d8bb74c3 100644 --- a/include/wx/gtk/button.h +++ b/include/wx/gtk/button.h @@ -64,7 +64,7 @@ public: // implementation // -------------- - void ApplyWidgetStyle(); + void DoApplyWidgetStyle(GtkRcStyle *style); bool IsOwnGtkWindow( GdkWindow *window ); // Since this wxButton doesn't derive from wxButtonBase (why?) we need diff --git a/include/wx/gtk/checkbox.h b/include/wx/gtk/checkbox.h index 0fefb3c67c..aa2c495d44 100644 --- a/include/wx/gtk/checkbox.h +++ b/include/wx/gtk/checkbox.h @@ -51,7 +51,7 @@ public: // implementation // -------------- - void ApplyWidgetStyle(); + void DoApplyWidgetStyle(GtkRcStyle *style); bool IsOwnGtkWindow( GdkWindow *window ); void OnInternalIdle(); diff --git a/include/wx/gtk/choice.h b/include/wx/gtk/choice.h index 17ae9edeb2..8732297d19 100644 --- a/include/wx/gtk/choice.h +++ b/include/wx/gtk/choice.h @@ -83,7 +83,7 @@ public: protected: wxList m_clientList; // contains the client data for the items - void ApplyWidgetStyle(); + void DoApplyWidgetStyle(GtkRcStyle *style); virtual int DoAppend(const wxString& item); virtual int DoInsert(const wxString& item, int pos); diff --git a/include/wx/gtk/combobox.h b/include/wx/gtk/combobox.h index 39bbb7ed54..c4c7bf3d89 100644 --- a/include/wx/gtk/combobox.h +++ b/include/wx/gtk/combobox.h @@ -130,7 +130,7 @@ public: void EnableEvents(); GtkWidget* GetConnectWidget(); bool IsOwnGtkWindow( GdkWindow *window ); - void ApplyWidgetStyle(); + void DoApplyWidgetStyle(GtkRcStyle *style); wxCONTROL_ITEMCONTAINER_CLIENTDATAOBJECT_RECAST diff --git a/include/wx/gtk/control.h b/include/wx/gtk/control.h index be6f36bc1c..417ad2083f 100644 --- a/include/wx/gtk/control.h +++ b/include/wx/gtk/control.h @@ -56,6 +56,11 @@ public: virtual wxVisualAttributes GetDefaultAttributes() const; protected: + virtual void ApplyWidgetStyle(); + // helper function to ease native widgets wrapping, called by + // ApplyWidgetStyle -- override this, not ApplyWidgetStyle + virtual void DoApplyWidgetStyle(GtkRcStyle *style); + virtual wxSize DoGetBestSize() const; void PostCreation(const wxSize& size); diff --git a/include/wx/gtk/gauge.h b/include/wx/gtk/gauge.h index 5652b6b5cb..e00e65d934 100644 --- a/include/wx/gtk/gauge.h +++ b/include/wx/gtk/gauge.h @@ -83,8 +83,6 @@ public: // implementation // ------------- - void ApplyWidgetStyle(); - // the max and current gauge values int m_rangeMax, m_gaugePos; diff --git a/include/wx/gtk/listbox.h b/include/wx/gtk/listbox.h index ff8d595c6c..b8c980241f 100644 --- a/include/wx/gtk/listbox.h +++ b/include/wx/gtk/listbox.h @@ -105,7 +105,7 @@ public: int GtkGetIndex( GtkWidget *item ) const; GtkWidget *GetConnectWidget(); bool IsOwnGtkWindow( GdkWindow *window ); - void ApplyWidgetStyle(); + void DoApplyWidgetStyle(GtkRcStyle *style); void OnInternalIdle(); #if wxUSE_TOOLTIPS diff --git a/include/wx/gtk/notebook.h b/include/wx/gtk/notebook.h index 664eb5f199..1830da0e9e 100644 --- a/include/wx/gtk/notebook.h +++ b/include/wx/gtk/notebook.h @@ -113,7 +113,7 @@ public: // set all page's font bool SetFont(const wxFont& font); - void ApplyWidgetStyle(); + void DoApplyWidgetStyle(GtkRcStyle *style); // report if window belongs to notebook bool IsOwnGtkWindow( GdkWindow *window ); diff --git a/include/wx/gtk/radiobox.h b/include/wx/gtk/radiobox.h index 882bda0357..e426de643f 100644 --- a/include/wx/gtk/radiobox.h +++ b/include/wx/gtk/radiobox.h @@ -121,7 +121,7 @@ public: void GtkDisableEvents(); void GtkEnableEvents(); bool IsOwnGtkWindow( GdkWindow *window ); - void ApplyWidgetStyle(); + void DoApplyWidgetStyle(GtkRcStyle *style); #if wxUSE_TOOLTIPS void ApplyToolTip( GtkTooltips *tips, const wxChar *tip ); #endif // wxUSE_TOOLTIPS diff --git a/include/wx/gtk/radiobut.h b/include/wx/gtk/radiobut.h index 39c442216f..552286e179 100644 --- a/include/wx/gtk/radiobut.h +++ b/include/wx/gtk/radiobut.h @@ -57,7 +57,7 @@ public: virtual bool IsRadioButton() const { return TRUE; } GSList *m_radioButtonGroup; - void ApplyWidgetStyle(); + void DoApplyWidgetStyle(GtkRcStyle *style); bool IsOwnGtkWindow( GdkWindow *window ); void OnInternalIdle(); diff --git a/include/wx/gtk/scrolbar.h b/include/wx/gtk/scrolbar.h index 8ce5e82897..5a8dd5cbc2 100644 --- a/include/wx/gtk/scrolbar.h +++ b/include/wx/gtk/scrolbar.h @@ -75,7 +75,6 @@ public: // -------------- bool IsOwnGtkWindow( GdkWindow *window ); - void ApplyWidgetStyle(); GtkAdjustment *m_adjust; float m_oldPos; diff --git a/include/wx/gtk/slider.h b/include/wx/gtk/slider.h index bd4af3fcad..3ff3ad6ea2 100644 --- a/include/wx/gtk/slider.h +++ b/include/wx/gtk/slider.h @@ -65,7 +65,6 @@ public: // implementation bool IsOwnGtkWindow( GdkWindow *window ); - void ApplyWidgetStyle(); void GtkDisableEvents(); void GtkEnableEvents(); diff --git a/include/wx/gtk/spinbutt.h b/include/wx/gtk/spinbutt.h index dfe3c40c05..bbf998067d 100644 --- a/include/wx/gtk/spinbutt.h +++ b/include/wx/gtk/spinbutt.h @@ -53,7 +53,6 @@ public: void OnSize( wxSizeEvent &event ); bool IsOwnGtkWindow( GdkWindow *window ); - void ApplyWidgetStyle(); GtkAdjustment *m_adjust; float m_oldPos; diff --git a/include/wx/gtk/spinctrl.h b/include/wx/gtk/spinctrl.h index 425f31f335..7ca72d8262 100644 --- a/include/wx/gtk/spinctrl.h +++ b/include/wx/gtk/spinctrl.h @@ -66,7 +66,6 @@ public: void OnChar( wxKeyEvent &event ); bool IsOwnGtkWindow( GdkWindow *window ); - void ApplyWidgetStyle(); void GtkDisableEvents(); void GtkEnableEvents(); diff --git a/include/wx/gtk/statbox.h b/include/wx/gtk/statbox.h index f0f1b2ff0e..2bedf27d46 100644 --- a/include/wx/gtk/statbox.h +++ b/include/wx/gtk/statbox.h @@ -45,8 +45,6 @@ public: // implementation - virtual void ApplyWidgetStyle(); - virtual bool IsTransparentForMouse() const { return TRUE; } private: diff --git a/include/wx/gtk/stattext.h b/include/wx/gtk/stattext.h index eb9ee2a86e..6686c96982 100644 --- a/include/wx/gtk/stattext.h +++ b/include/wx/gtk/stattext.h @@ -65,8 +65,6 @@ public: // implementation // -------------- - - void ApplyWidgetStyle(); protected: virtual wxSize DoGetBestSize() const; diff --git a/include/wx/gtk/textctrl.h b/include/wx/gtk/textctrl.h index 7ca89491e6..3832c956dc 100644 --- a/include/wx/gtk/textctrl.h +++ b/include/wx/gtk/textctrl.h @@ -133,7 +133,7 @@ public: GtkWidget* GetConnectWidget(); bool IsOwnGtkWindow( GdkWindow *window ); - void ApplyWidgetStyle(); + void DoApplyWidgetStyle(GtkRcStyle *style); void CalculateScrollbar(); void OnInternalIdle(); void UpdateFontIfNeeded(); diff --git a/include/wx/gtk/tglbtn.h b/include/wx/gtk/tglbtn.h index 7da1777c18..06f317f52b 100644 --- a/include/wx/gtk/tglbtn.h +++ b/include/wx/gtk/tglbtn.h @@ -74,7 +74,7 @@ public: wxBitmap m_bitmap; void OnSetBitmap(); - void ApplyWidgetStyle(); + void DoApplyWidgetStyle(GtkRcStyle *style); bool IsOwnGtkWindow(GdkWindow *window); virtual void OnInternalIdle(); @@ -128,7 +128,7 @@ public: // implementation bool m_blockEvent; - void ApplyWidgetStyle(); + void DoApplyWidgetStyle(GtkRcStyle *style); bool IsOwnGtkWindow(GdkWindow *window); virtual void OnInternalIdle(); diff --git a/include/wx/gtk/window.h b/include/wx/gtk/window.h index de52035835..a0496b7fb9 100644 --- a/include/wx/gtk/window.h +++ b/include/wx/gtk/window.h @@ -153,10 +153,6 @@ public: virtual bool IsOwnGtkWindow( GdkWindow *window ); void ConnectWidget( GtkWidget *widget ); - // Creates a new widget style if none is there - // and sets m_widgetStyle to this value. - GtkStyle *GetWidgetStyle(); - #ifdef __WXGTK20__ // Returns the default context which usually is anti-aliased PangoContext *GtkGetPangoDefaultContext(); @@ -168,12 +164,6 @@ public: PangoContext *m_x11Context; #endif - // Called by SetFont() and SetXXXColour etc - void SetWidgetStyle(); - - // Overridden in many GTK widgets who have to handle subwidgets - virtual void ApplyWidgetStyle(); - #if wxUSE_TOOLTIPS virtual void ApplyToolTip( GtkTooltips *tips, const wxChar *tip ); #endif // wxUSE_TOOLTIPS @@ -247,12 +237,6 @@ public: bool m_delayedForegroundColour:1; bool m_delayedBackgroundColour:1; - // Contains GTK's widgets internal information about non-default widget - // font and colours. we create one for each widget that gets any - // non-default attribute set via SetFont() or SetForegroundColour() / - // SetBackgroundColour(). - GtkStyle *m_widgetStyle; - // C++ has no virtual methods in the constrcutor of any class but we need // different methods of inserting a child window into a wxFrame, // wxMDIFrame, wxNotebook etc. this is the callback that will get used. @@ -280,6 +264,14 @@ public: protected: // common part of all ctors (not virtual because called from ctor) void Init(); + + // Called by ApplyWidgetStyle (which is called by SetFont() and + // SetXXXColour etc to apply style changed to native widgets) to create + // modified GTK style with non-standard attributes. + GtkRcStyle *CreateWidgetStyle(); + + // Overridden in many GTK widgets who have to handle subwidgets + virtual void ApplyWidgetStyle(); private: DECLARE_DYNAMIC_CLASS(wxWindowGTK) diff --git a/include/wx/gtk1/bmpbuttn.h b/include/wx/gtk1/bmpbuttn.h index c71501e59a..f4d71460df 100644 --- a/include/wx/gtk1/bmpbuttn.h +++ b/include/wx/gtk1/bmpbuttn.h @@ -61,7 +61,7 @@ public: void NotFocus(); void StartSelect(); void EndSelect(); - void ApplyWidgetStyle(); + void DoApplyWidgetStyle(GtkRcStyle *style); bool m_hasFocus:1; bool m_isSelected:1; diff --git a/include/wx/gtk1/button.h b/include/wx/gtk1/button.h index 3a55ddec52..59d8bb74c3 100644 --- a/include/wx/gtk1/button.h +++ b/include/wx/gtk1/button.h @@ -64,7 +64,7 @@ public: // implementation // -------------- - void ApplyWidgetStyle(); + void DoApplyWidgetStyle(GtkRcStyle *style); bool IsOwnGtkWindow( GdkWindow *window ); // Since this wxButton doesn't derive from wxButtonBase (why?) we need diff --git a/include/wx/gtk1/checkbox.h b/include/wx/gtk1/checkbox.h index 0fefb3c67c..aa2c495d44 100644 --- a/include/wx/gtk1/checkbox.h +++ b/include/wx/gtk1/checkbox.h @@ -51,7 +51,7 @@ public: // implementation // -------------- - void ApplyWidgetStyle(); + void DoApplyWidgetStyle(GtkRcStyle *style); bool IsOwnGtkWindow( GdkWindow *window ); void OnInternalIdle(); diff --git a/include/wx/gtk1/choice.h b/include/wx/gtk1/choice.h index 17ae9edeb2..8732297d19 100644 --- a/include/wx/gtk1/choice.h +++ b/include/wx/gtk1/choice.h @@ -83,7 +83,7 @@ public: protected: wxList m_clientList; // contains the client data for the items - void ApplyWidgetStyle(); + void DoApplyWidgetStyle(GtkRcStyle *style); virtual int DoAppend(const wxString& item); virtual int DoInsert(const wxString& item, int pos); diff --git a/include/wx/gtk1/combobox.h b/include/wx/gtk1/combobox.h index 39bbb7ed54..c4c7bf3d89 100644 --- a/include/wx/gtk1/combobox.h +++ b/include/wx/gtk1/combobox.h @@ -130,7 +130,7 @@ public: void EnableEvents(); GtkWidget* GetConnectWidget(); bool IsOwnGtkWindow( GdkWindow *window ); - void ApplyWidgetStyle(); + void DoApplyWidgetStyle(GtkRcStyle *style); wxCONTROL_ITEMCONTAINER_CLIENTDATAOBJECT_RECAST diff --git a/include/wx/gtk1/control.h b/include/wx/gtk1/control.h index be6f36bc1c..417ad2083f 100644 --- a/include/wx/gtk1/control.h +++ b/include/wx/gtk1/control.h @@ -56,6 +56,11 @@ public: virtual wxVisualAttributes GetDefaultAttributes() const; protected: + virtual void ApplyWidgetStyle(); + // helper function to ease native widgets wrapping, called by + // ApplyWidgetStyle -- override this, not ApplyWidgetStyle + virtual void DoApplyWidgetStyle(GtkRcStyle *style); + virtual wxSize DoGetBestSize() const; void PostCreation(const wxSize& size); diff --git a/include/wx/gtk1/gauge.h b/include/wx/gtk1/gauge.h index 5652b6b5cb..e00e65d934 100644 --- a/include/wx/gtk1/gauge.h +++ b/include/wx/gtk1/gauge.h @@ -83,8 +83,6 @@ public: // implementation // ------------- - void ApplyWidgetStyle(); - // the max and current gauge values int m_rangeMax, m_gaugePos; diff --git a/include/wx/gtk1/listbox.h b/include/wx/gtk1/listbox.h index ff8d595c6c..b8c980241f 100644 --- a/include/wx/gtk1/listbox.h +++ b/include/wx/gtk1/listbox.h @@ -105,7 +105,7 @@ public: int GtkGetIndex( GtkWidget *item ) const; GtkWidget *GetConnectWidget(); bool IsOwnGtkWindow( GdkWindow *window ); - void ApplyWidgetStyle(); + void DoApplyWidgetStyle(GtkRcStyle *style); void OnInternalIdle(); #if wxUSE_TOOLTIPS diff --git a/include/wx/gtk1/notebook.h b/include/wx/gtk1/notebook.h index 664eb5f199..1830da0e9e 100644 --- a/include/wx/gtk1/notebook.h +++ b/include/wx/gtk1/notebook.h @@ -113,7 +113,7 @@ public: // set all page's font bool SetFont(const wxFont& font); - void ApplyWidgetStyle(); + void DoApplyWidgetStyle(GtkRcStyle *style); // report if window belongs to notebook bool IsOwnGtkWindow( GdkWindow *window ); diff --git a/include/wx/gtk1/radiobox.h b/include/wx/gtk1/radiobox.h index 882bda0357..e426de643f 100644 --- a/include/wx/gtk1/radiobox.h +++ b/include/wx/gtk1/radiobox.h @@ -121,7 +121,7 @@ public: void GtkDisableEvents(); void GtkEnableEvents(); bool IsOwnGtkWindow( GdkWindow *window ); - void ApplyWidgetStyle(); + void DoApplyWidgetStyle(GtkRcStyle *style); #if wxUSE_TOOLTIPS void ApplyToolTip( GtkTooltips *tips, const wxChar *tip ); #endif // wxUSE_TOOLTIPS diff --git a/include/wx/gtk1/radiobut.h b/include/wx/gtk1/radiobut.h index 39c442216f..552286e179 100644 --- a/include/wx/gtk1/radiobut.h +++ b/include/wx/gtk1/radiobut.h @@ -57,7 +57,7 @@ public: virtual bool IsRadioButton() const { return TRUE; } GSList *m_radioButtonGroup; - void ApplyWidgetStyle(); + void DoApplyWidgetStyle(GtkRcStyle *style); bool IsOwnGtkWindow( GdkWindow *window ); void OnInternalIdle(); diff --git a/include/wx/gtk1/scrolbar.h b/include/wx/gtk1/scrolbar.h index 8ce5e82897..5a8dd5cbc2 100644 --- a/include/wx/gtk1/scrolbar.h +++ b/include/wx/gtk1/scrolbar.h @@ -75,7 +75,6 @@ public: // -------------- bool IsOwnGtkWindow( GdkWindow *window ); - void ApplyWidgetStyle(); GtkAdjustment *m_adjust; float m_oldPos; diff --git a/include/wx/gtk1/slider.h b/include/wx/gtk1/slider.h index bd4af3fcad..3ff3ad6ea2 100644 --- a/include/wx/gtk1/slider.h +++ b/include/wx/gtk1/slider.h @@ -65,7 +65,6 @@ public: // implementation bool IsOwnGtkWindow( GdkWindow *window ); - void ApplyWidgetStyle(); void GtkDisableEvents(); void GtkEnableEvents(); diff --git a/include/wx/gtk1/spinbutt.h b/include/wx/gtk1/spinbutt.h index dfe3c40c05..bbf998067d 100644 --- a/include/wx/gtk1/spinbutt.h +++ b/include/wx/gtk1/spinbutt.h @@ -53,7 +53,6 @@ public: void OnSize( wxSizeEvent &event ); bool IsOwnGtkWindow( GdkWindow *window ); - void ApplyWidgetStyle(); GtkAdjustment *m_adjust; float m_oldPos; diff --git a/include/wx/gtk1/spinctrl.h b/include/wx/gtk1/spinctrl.h index 425f31f335..7ca72d8262 100644 --- a/include/wx/gtk1/spinctrl.h +++ b/include/wx/gtk1/spinctrl.h @@ -66,7 +66,6 @@ public: void OnChar( wxKeyEvent &event ); bool IsOwnGtkWindow( GdkWindow *window ); - void ApplyWidgetStyle(); void GtkDisableEvents(); void GtkEnableEvents(); diff --git a/include/wx/gtk1/statbox.h b/include/wx/gtk1/statbox.h index f0f1b2ff0e..2bedf27d46 100644 --- a/include/wx/gtk1/statbox.h +++ b/include/wx/gtk1/statbox.h @@ -45,8 +45,6 @@ public: // implementation - virtual void ApplyWidgetStyle(); - virtual bool IsTransparentForMouse() const { return TRUE; } private: diff --git a/include/wx/gtk1/stattext.h b/include/wx/gtk1/stattext.h index eb9ee2a86e..6686c96982 100644 --- a/include/wx/gtk1/stattext.h +++ b/include/wx/gtk1/stattext.h @@ -65,8 +65,6 @@ public: // implementation // -------------- - - void ApplyWidgetStyle(); protected: virtual wxSize DoGetBestSize() const; diff --git a/include/wx/gtk1/textctrl.h b/include/wx/gtk1/textctrl.h index 7ca89491e6..3832c956dc 100644 --- a/include/wx/gtk1/textctrl.h +++ b/include/wx/gtk1/textctrl.h @@ -133,7 +133,7 @@ public: GtkWidget* GetConnectWidget(); bool IsOwnGtkWindow( GdkWindow *window ); - void ApplyWidgetStyle(); + void DoApplyWidgetStyle(GtkRcStyle *style); void CalculateScrollbar(); void OnInternalIdle(); void UpdateFontIfNeeded(); diff --git a/include/wx/gtk1/tglbtn.h b/include/wx/gtk1/tglbtn.h index 7da1777c18..06f317f52b 100644 --- a/include/wx/gtk1/tglbtn.h +++ b/include/wx/gtk1/tglbtn.h @@ -74,7 +74,7 @@ public: wxBitmap m_bitmap; void OnSetBitmap(); - void ApplyWidgetStyle(); + void DoApplyWidgetStyle(GtkRcStyle *style); bool IsOwnGtkWindow(GdkWindow *window); virtual void OnInternalIdle(); @@ -128,7 +128,7 @@ public: // implementation bool m_blockEvent; - void ApplyWidgetStyle(); + void DoApplyWidgetStyle(GtkRcStyle *style); bool IsOwnGtkWindow(GdkWindow *window); virtual void OnInternalIdle(); diff --git a/include/wx/gtk1/window.h b/include/wx/gtk1/window.h index de52035835..a0496b7fb9 100644 --- a/include/wx/gtk1/window.h +++ b/include/wx/gtk1/window.h @@ -153,10 +153,6 @@ public: virtual bool IsOwnGtkWindow( GdkWindow *window ); void ConnectWidget( GtkWidget *widget ); - // Creates a new widget style if none is there - // and sets m_widgetStyle to this value. - GtkStyle *GetWidgetStyle(); - #ifdef __WXGTK20__ // Returns the default context which usually is anti-aliased PangoContext *GtkGetPangoDefaultContext(); @@ -168,12 +164,6 @@ public: PangoContext *m_x11Context; #endif - // Called by SetFont() and SetXXXColour etc - void SetWidgetStyle(); - - // Overridden in many GTK widgets who have to handle subwidgets - virtual void ApplyWidgetStyle(); - #if wxUSE_TOOLTIPS virtual void ApplyToolTip( GtkTooltips *tips, const wxChar *tip ); #endif // wxUSE_TOOLTIPS @@ -247,12 +237,6 @@ public: bool m_delayedForegroundColour:1; bool m_delayedBackgroundColour:1; - // Contains GTK's widgets internal information about non-default widget - // font and colours. we create one for each widget that gets any - // non-default attribute set via SetFont() or SetForegroundColour() / - // SetBackgroundColour(). - GtkStyle *m_widgetStyle; - // C++ has no virtual methods in the constrcutor of any class but we need // different methods of inserting a child window into a wxFrame, // wxMDIFrame, wxNotebook etc. this is the callback that will get used. @@ -280,6 +264,14 @@ public: protected: // common part of all ctors (not virtual because called from ctor) void Init(); + + // Called by ApplyWidgetStyle (which is called by SetFont() and + // SetXXXColour etc to apply style changed to native widgets) to create + // modified GTK style with non-standard attributes. + GtkRcStyle *CreateWidgetStyle(); + + // Overridden in many GTK widgets who have to handle subwidgets + virtual void ApplyWidgetStyle(); private: DECLARE_DYNAMIC_CLASS(wxWindowGTK) diff --git a/src/gtk/bmpbuttn.cpp b/src/gtk/bmpbuttn.cpp index 17bc64454f..db11765013 100644 --- a/src/gtk/bmpbuttn.cpp +++ b/src/gtk/bmpbuttn.cpp @@ -193,12 +193,12 @@ wxString wxBitmapButton::GetLabel() const return wxControl::GetLabel(); } -void wxBitmapButton::ApplyWidgetStyle() +void wxBitmapButton::DoApplyWidgetStyle(GtkRcStyle *style) { if ( !BUTTON_CHILD(m_widget) ) return; - wxButton::ApplyWidgetStyle(); + wxButton::DoApplyWidgetStyle(style); } void wxBitmapButton::OnSetBitmap() diff --git a/src/gtk/button.cpp b/src/gtk/button.cpp index f71214c940..d64273b780 100644 --- a/src/gtk/button.cpp +++ b/src/gtk/button.cpp @@ -196,11 +196,10 @@ bool wxButton::IsOwnGtkWindow( GdkWindow *window ) #endif } -void wxButton::ApplyWidgetStyle() +void wxButton::DoApplyWidgetStyle(GtkRcStyle *style) { - SetWidgetStyle(); - gtk_widget_set_style( m_widget, m_widgetStyle ); - gtk_widget_set_style( BUTTON_CHILD(m_widget), m_widgetStyle ); + gtk_widget_modify_style(m_widget, style); + gtk_widget_modify_style(BUTTON_CHILD(m_widget), style); } wxSize wxButton::DoGetBestSize() const diff --git a/src/gtk/checkbox.cpp b/src/gtk/checkbox.cpp index e7fe520d4d..1c64e26ba1 100644 --- a/src/gtk/checkbox.cpp +++ b/src/gtk/checkbox.cpp @@ -170,11 +170,10 @@ bool wxCheckBox::Enable( bool enable ) return TRUE; } -void wxCheckBox::ApplyWidgetStyle() +void wxCheckBox::DoApplyWidgetStyle(GtkRcStyle *style) { - SetWidgetStyle(); - gtk_widget_set_style( m_widgetCheckbox, m_widgetStyle ); - gtk_widget_set_style( m_widgetLabel, m_widgetStyle ); + gtk_widget_modify_style(m_widgetCheckbox, style); + gtk_widget_modify_style(m_widgetLabel, style); } bool wxCheckBox::IsOwnGtkWindow( GdkWindow *window ) diff --git a/src/gtk/choice.cpp b/src/gtk/choice.cpp index 54f9b1de42..28d895dd2e 100644 --- a/src/gtk/choice.cpp +++ b/src/gtk/choice.cpp @@ -437,19 +437,17 @@ void wxChoice::SetSelection( int n ) gtk_option_menu_set_history( GTK_OPTION_MENU(m_widget), (gint)tmp ); } -void wxChoice::ApplyWidgetStyle() +void wxChoice::DoApplyWidgetStyle(GtkRcStyle *style) { - SetWidgetStyle(); - GtkMenuShell *menu_shell = GTK_MENU_SHELL( gtk_option_menu_get_menu( GTK_OPTION_MENU(m_widget) ) ); - gtk_widget_set_style( m_widget, m_widgetStyle ); - gtk_widget_set_style( GTK_WIDGET( menu_shell ), m_widgetStyle ); + gtk_widget_modify_style( m_widget, style ); + gtk_widget_modify_style( GTK_WIDGET( menu_shell ), style ); GList *child = menu_shell->children; while (child) { - gtk_widget_set_style( GTK_WIDGET( child->data ), m_widgetStyle ); + gtk_widget_modify_style( GTK_WIDGET( child->data ), style ); GtkBin *bin = GTK_BIN( child->data ); GtkWidget *label = (GtkWidget *) NULL; @@ -458,7 +456,7 @@ void wxChoice::ApplyWidgetStyle() if (!label) label = BUTTON_CHILD(m_widget); - gtk_widget_set_style( label, m_widgetStyle ); + gtk_widget_modify_style( label, style ); child = child->next; } @@ -513,7 +511,7 @@ int wxChoice::GtkAddHelper(GtkWidget *menu, int pos, const wxString& item) gtk_widget_realize( menu_item ); gtk_widget_realize( GTK_BIN(menu_item)->child ); - if (m_widgetStyle) ApplyWidgetStyle(); + ApplyWidgetStyle(); } gtk_signal_connect( GTK_OBJECT( menu_item ), "activate", diff --git a/src/gtk/combobox.cpp b/src/gtk/combobox.cpp index f7950f67bf..2ddf6fcf95 100644 --- a/src/gtk/combobox.cpp +++ b/src/gtk/combobox.cpp @@ -239,7 +239,7 @@ int wxComboBox::DoAppend( const wxString &item ) gtk_widget_realize( list_item ); gtk_widget_realize( GTK_BIN(list_item)->child ); - if (m_widgetStyle) ApplyWidgetStyle(); + ApplyWidgetStyle(); } gtk_widget_show( list_item ); @@ -284,8 +284,7 @@ int wxComboBox::DoInsert( const wxString &item, int pos ) gtk_widget_realize( list_item ); gtk_widget_realize( GTK_BIN(list_item)->child ); - if (m_widgetStyle) - ApplyWidgetStyle(); + ApplyWidgetStyle(); } gtk_widget_show( list_item ); @@ -722,22 +721,20 @@ void wxComboBox::OnSize( wxSizeEvent &event ) #endif // 0 } -void wxComboBox::ApplyWidgetStyle() +void wxComboBox::DoApplyWidgetStyle(GtkRcStyle *style) { - SetWidgetStyle(); - -// gtk_widget_set_style( GTK_COMBO(m_widget)->button, m_widgetStyle ); - gtk_widget_set_style( GTK_COMBO(m_widget)->entry, m_widgetStyle ); - gtk_widget_set_style( GTK_COMBO(m_widget)->list, m_widgetStyle ); +// gtk_widget_modify_style( GTK_COMBO(m_widget)->button, syle ); + gtk_widget_modify_style( GTK_COMBO(m_widget)->entry, style ); + gtk_widget_modify_style( GTK_COMBO(m_widget)->list, style ); GtkList *list = GTK_LIST( GTK_COMBO(m_widget)->list ); GList *child = list->children; while (child) { - gtk_widget_set_style( GTK_WIDGET(child->data), m_widgetStyle ); + gtk_widget_modify_style( GTK_WIDGET(child->data), style ); GtkBin *bin = GTK_BIN(child->data); - gtk_widget_set_style( bin->child, m_widgetStyle ); + gtk_widget_modify_style( bin->child, style ); child = child->next; } diff --git a/src/gtk/control.cpp b/src/gtk/control.cpp index dfbfe4b9c0..e638c35d8d 100644 --- a/src/gtk/control.cpp +++ b/src/gtk/control.cpp @@ -92,6 +92,14 @@ wxSize wxControl::DoGetBestSize() const void wxControl::PostCreation(const wxSize& size) { wxWindow::PostCreation(); + + // NB: GetBestSize needs to know the style, otherwise it will assume + // default font and if the user uses a different font, determined + // best size will be different (typically, smaller) than the desired + // size. This call ensure that a style is available at the time + // GetBestSize is called. + gtk_widget_ensure_style(m_widget); + InheritAttributes(); ApplyWidgetStyle(); SetInitialBestSize(size); @@ -259,6 +267,21 @@ wxControl::GetDefaultAttributesFromGTKWidget(GtkWidget* (*widget_new)(GtkAdjustm return attr; } +void wxControl::ApplyWidgetStyle() +{ + GtkRcStyle *style = CreateWidgetStyle(); + if ( style ) + { + DoApplyWidgetStyle(style); + gtk_rc_style_unref(style); + } +} + +void wxControl::DoApplyWidgetStyle(GtkRcStyle *style) +{ + gtk_widget_modify_style(m_widget, style); +} + #endif // wxUSE_CONTROLS diff --git a/src/gtk/gauge.cpp b/src/gtk/gauge.cpp index 7fe754a52e..90aad2ca5b 100644 --- a/src/gtk/gauge.cpp +++ b/src/gtk/gauge.cpp @@ -106,12 +106,6 @@ int wxGauge::GetValue() const return m_gaugePos; } -void wxGauge::ApplyWidgetStyle() -{ - SetWidgetStyle(); - gtk_widget_set_style( m_widget, m_widgetStyle ); -} - wxVisualAttributes wxGauge::GetDefaultAttributes() const { // Visible gauge colours use a different colour state diff --git a/src/gtk/listbox.cpp b/src/gtk/listbox.cpp index 9f06846793..15c355869d 100644 --- a/src/gtk/listbox.cpp +++ b/src/gtk/listbox.cpp @@ -575,12 +575,14 @@ void wxListBox::GtkAddItem( const wxString &item, int pos ) gtk_widget_realize( GTK_BIN(list_item)->child ); // Apply current widget style to the new list_item - if (m_widgetStyle) + GtkRcStyle *style = CreateWidgetStyle(); + if (style) { - gtk_widget_set_style( GTK_WIDGET( list_item ), m_widgetStyle ); + gtk_widget_modify_style( GTK_WIDGET( list_item ), style ); GtkBin *bin = GTK_BIN( list_item ); GtkWidget *label = GTK_WIDGET( bin->child ); - gtk_widget_set_style( label, m_widgetStyle ); + gtk_widget_modify_style( label, style ); + gtk_rc_style_unref( style ); } #if wxUSE_TOOLTIPS @@ -981,11 +983,9 @@ bool wxListBox::IsOwnGtkWindow( GdkWindow *window ) return FALSE; } -void wxListBox::ApplyWidgetStyle() +void wxListBox::DoApplyWidgetStyle(GtkRcStyle *style) { - SetWidgetStyle(); - - if (m_backgroundColour.Ok()) + if (m_hasBgCol && m_backgroundColour.Ok()) { GdkWindow *window = GTK_WIDGET(m_list)->window; if ( window ) @@ -999,11 +999,11 @@ void wxListBox::ApplyWidgetStyle() GList *child = m_list->children; while (child) { - gtk_widget_set_style( GTK_WIDGET(child->data), m_widgetStyle ); + gtk_widget_modify_style( GTK_WIDGET(child->data), style ); GtkBin *bin = GTK_BIN( child->data ); GtkWidget *label = GTK_WIDGET( bin->child ); - gtk_widget_set_style( label, m_widgetStyle ); + gtk_widget_modify_style( label, style ); child = child->next; } diff --git a/src/gtk/notebook.cpp b/src/gtk/notebook.cpp index ded15fb845..cb6e7b39d4 100644 --- a/src/gtk/notebook.cpp +++ b/src/gtk/notebook.cpp @@ -72,13 +72,6 @@ public: m_image = -1; m_page = (GtkNotebookPage *) NULL; m_box = (GtkWidget *) NULL; - m_labelStyle = (GtkStyle*) NULL; - } - - ~wxGtkNotebookPage() - { - if (m_labelStyle) - gtk_style_unref( m_labelStyle ); } bool SetFont(const wxFont& font); @@ -88,7 +81,6 @@ public: GtkNotebookPage *m_page; GtkLabel *m_label; GtkWidget *m_box; // in which the label and image are packed - GtkStyle *m_labelStyle; }; @@ -97,42 +89,17 @@ bool wxGtkNotebookPage::SetFont(const wxFont& font) if (!m_label) return false; - if (m_labelStyle) - { - GtkStyle *remake = gtk_style_copy( m_labelStyle ); - -#ifndef __WXGTK20__ - remake->klass = m_labelStyle->klass; -#endif - - gtk_style_unref( m_labelStyle ); - m_labelStyle = remake; - } - else - { - GtkStyle *def = gtk_rc_get_style( GTK_WIDGET(m_label) ); - - if (!def) - def = gtk_widget_get_default_style(); - - m_labelStyle = gtk_style_copy( def ); - - // FIXME: no more klass in 2.0 -#ifndef __WXGTK20__ - m_labelStyle->klass = def->klass; -#endif - } - #ifdef __WXGTK20__ - pango_font_description_free( m_labelStyle->font_desc ); - m_labelStyle->font_desc = pango_font_description_copy( font.GetNativeFontInfo()->description ); + gtk_widget_modify_font(GTK_WIDGET(m_label), + font.GetNativeFontInfo()->description); #else - gdk_font_unref( m_labelStyle->font ); - m_labelStyle->font = gdk_font_ref( font.GetInternalFont( 1.0 ) ); + GtkRcStyle *style = gtk_rc_style_new(); + style->fontset_name = + g_strdup(font.GetNativeFontInfo()->GetXFontName().c_str()); + gtk_widget_modify_style(GTK_WIDGET(m_label), style); + gtk_rc_style_unref(style); #endif - gtk_widget_set_style( GTK_WIDGET(m_label), m_labelStyle ); - return true; } @@ -839,12 +806,10 @@ bool wxNotebook::DoPhase( int WXUNUSED(nPhase) ) #endif -void wxNotebook::ApplyWidgetStyle() +void wxNotebook::DoApplyWidgetStyle(GtkRcStyle *style) { // TODO, font for labels etc - - SetWidgetStyle(); - gtk_widget_set_style( m_widget, m_widgetStyle ); + gtk_widget_modify_style( m_widget, style ); } bool wxNotebook::IsOwnGtkWindow( GdkWindow *window ) diff --git a/src/gtk/radiobox.cpp b/src/gtk/radiobox.cpp index 3538f3c037..ea1eee5230 100644 --- a/src/gtk/radiobox.cpp +++ b/src/gtk/radiobox.cpp @@ -681,19 +681,17 @@ void wxRadioBox::GtkEnableEvents() } } -void wxRadioBox::ApplyWidgetStyle() +void wxRadioBox::DoApplyWidgetStyle(GtkRcStyle *style) { - SetWidgetStyle(); - - gtk_widget_set_style( m_widget, m_widgetStyle ); + gtk_widget_modify_style( m_widget, style ); wxList::compatibility_iterator node = m_boxes.GetFirst(); while (node) { GtkWidget *widget = GTK_WIDGET( node->GetData() ); - gtk_widget_set_style( widget, m_widgetStyle ); - gtk_widget_set_style( BUTTON_CHILD(node->GetData()), m_widgetStyle ); + gtk_widget_modify_style( widget, style ); + gtk_widget_modify_style( BUTTON_CHILD(node->GetData()), style ); node = node->GetNext(); } diff --git a/src/gtk/radiobut.cpp b/src/gtk/radiobut.cpp index c03a82e438..2c3e1c0d10 100644 --- a/src/gtk/radiobut.cpp +++ b/src/gtk/radiobut.cpp @@ -187,11 +187,10 @@ bool wxRadioButton::Enable( bool enable ) return TRUE; } -void wxRadioButton::ApplyWidgetStyle() +void wxRadioButton::DoApplyWidgetStyle(GtkRcStyle *style) { - SetWidgetStyle(); - gtk_widget_set_style( m_widget, m_widgetStyle ); - gtk_widget_set_style( BUTTON_CHILD(m_widget), m_widgetStyle ); + gtk_widget_modify_style(m_widget, style); + gtk_widget_modify_style(BUTTON_CHILD(m_widget), style); } bool wxRadioButton::IsOwnGtkWindow( GdkWindow *window ) diff --git a/src/gtk/scrolbar.cpp b/src/gtk/scrolbar.cpp index 6dcd71ec52..f2d26ced1d 100644 --- a/src/gtk/scrolbar.cpp +++ b/src/gtk/scrolbar.cpp @@ -325,12 +325,6 @@ bool wxScrollBar::IsOwnGtkWindow( GdkWindow *window ) ); } -void wxScrollBar::ApplyWidgetStyle() -{ - SetWidgetStyle(); - gtk_widget_set_style( m_widget, m_widgetStyle ); -} - wxSize wxScrollBar::DoGetBestSize() const { return wxControl::DoGetBestSize(); diff --git a/src/gtk/slider.cpp b/src/gtk/slider.cpp index e7079c5c10..bcd260ad6e 100644 --- a/src/gtk/slider.cpp +++ b/src/gtk/slider.cpp @@ -265,12 +265,6 @@ bool wxSlider::IsOwnGtkWindow( GdkWindow *window ) #endif } -void wxSlider::ApplyWidgetStyle() -{ - SetWidgetStyle(); - gtk_widget_set_style( m_widget, m_widgetStyle ); -} - void wxSlider::GtkDisableEvents() { gtk_signal_disconnect_by_func( GTK_OBJECT(m_adjust), diff --git a/src/gtk/spinbutt.cpp b/src/gtk/spinbutt.cpp index 423947a1d3..a62d2c121e 100644 --- a/src/gtk/spinbutt.cpp +++ b/src/gtk/spinbutt.cpp @@ -225,15 +225,9 @@ bool wxSpinButton::IsOwnGtkWindow( GdkWindow *window ) return GTK_SPIN_BUTTON(m_widget)->panel == window; } -void wxSpinButton::ApplyWidgetStyle() -{ - SetWidgetStyle(); - gtk_widget_set_style( m_widget, m_widgetStyle ); -} - wxSize wxSpinButton::DoGetBestSize() const { - return wxSize(15, 26); + return wxSize(15, 26); // FIXME } // static diff --git a/src/gtk/spinctrl.cpp b/src/gtk/spinctrl.cpp index 80d5007a43..9390128cf0 100644 --- a/src/gtk/spinctrl.cpp +++ b/src/gtk/spinctrl.cpp @@ -298,12 +298,6 @@ bool wxSpinCtrl::IsOwnGtkWindow( GdkWindow *window ) return FALSE; } -void wxSpinCtrl::ApplyWidgetStyle() -{ - SetWidgetStyle(); - gtk_widget_set_style( m_widget, m_widgetStyle ); -} - wxSize wxSpinCtrl::DoGetBestSize() const { wxSize ret( wxControl::DoGetBestSize() ); diff --git a/src/gtk/statbox.cpp b/src/gtk/statbox.cpp index 879e2bc579..7c3eb9678e 100644 --- a/src/gtk/statbox.cpp +++ b/src/gtk/statbox.cpp @@ -91,12 +91,6 @@ void wxStaticBox::SetLabel( const wxString &label ) m_label.empty() ? (char *)NULL : (const char*) wxGTK_CONV( m_label ) ); } -void wxStaticBox::ApplyWidgetStyle() -{ - SetWidgetStyle(); - gtk_widget_set_style( m_widget, m_widgetStyle ); -} - // static wxVisualAttributes wxStaticBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) diff --git a/src/gtk/stattext.cpp b/src/gtk/stattext.cpp index 1849d21f5d..d659e8cc16 100644 --- a/src/gtk/stattext.cpp +++ b/src/gtk/stattext.cpp @@ -168,12 +168,6 @@ bool wxStaticText::SetFont( const wxFont &font ) return ret; } -void wxStaticText::ApplyWidgetStyle() -{ - SetWidgetStyle(); - gtk_widget_set_style( m_widget, m_widgetStyle ); -} - wxSize wxStaticText::DoGetBestSize() const { // Do not return any arbitrary default value... diff --git a/src/gtk/textctrl.cpp b/src/gtk/textctrl.cpp index a2ad1509bb..2d5b6460a5 100644 --- a/src/gtk/textctrl.cpp +++ b/src/gtk/textctrl.cpp @@ -1535,10 +1535,9 @@ bool wxTextCtrl::SetStyle( long start, long end, const wxTextAttr& style ) } } -void wxTextCtrl::ApplyWidgetStyle() +void wxTextCtrl::DoApplyWidgetStyle(GtkRcStyle *style) { - SetWidgetStyle(); - gtk_widget_set_style( m_text, m_widgetStyle ); + gtk_widget_modify_style(m_text, style); } void wxTextCtrl::OnCut(wxCommandEvent& WXUNUSED(event)) diff --git a/src/gtk/tglbtn.cpp b/src/gtk/tglbtn.cpp index d8aac966f6..8ac7ec5a3c 100644 --- a/src/gtk/tglbtn.cpp +++ b/src/gtk/tglbtn.cpp @@ -159,11 +159,10 @@ bool wxToggleBitmapButton::Enable(bool enable /*=TRUE*/) return TRUE; } -void wxToggleBitmapButton::ApplyWidgetStyle() +void wxToggleBitmapButton::DoApplyWidgetStyle(GtkRcStyle *style) { - SetWidgetStyle(); - gtk_widget_set_style(m_widget, m_widgetStyle); - gtk_widget_set_style(BUTTON_CHILD(m_widget), m_widgetStyle); + gtk_widget_modify_style(m_widget, style); + gtk_widget_modify_style(BUTTON_CHILD(m_widget), style); } bool wxToggleBitmapButton::IsOwnGtkWindow(GdkWindow *window) @@ -300,11 +299,10 @@ bool wxToggleButton::Enable(bool enable /*=TRUE*/) return TRUE; } -void wxToggleButton::ApplyWidgetStyle() +void wxToggleButton::DoApplyWidgetStyle(GtkRcStyle *style) { - SetWidgetStyle(); - gtk_widget_set_style(m_widget, m_widgetStyle); - gtk_widget_set_style(BUTTON_CHILD(m_widget), m_widgetStyle); + gtk_widget_modify_style(m_widget, style); + gtk_widget_modify_style(BUTTON_CHILD(m_widget), style); } bool wxToggleButton::IsOwnGtkWindow(GdkWindow *window) diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index 150aabdcfc..13d9f19cd6 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -267,10 +267,6 @@ extern bool g_mainThreadLocked; // debug //----------------------------------------------------------------------------- -#ifndef __WXGTK20__ -#define DISABLE_STYLE_IF_BROKEN_THEME 0 -#endif - #ifdef __WXDEBUG__ #if wxUSE_THREADS @@ -2566,7 +2562,6 @@ void wxWindowGTK::Init() m_oldClientHeight = 0; m_resizing = FALSE; - m_widgetStyle = (GtkStyle*) NULL; m_insertCallback = (wxInsertChildFunction) NULL; @@ -2760,16 +2755,6 @@ wxWindowGTK::~wxWindowGTK() gdk_ic_attr_destroy (m_icattr); #endif - if (m_widgetStyle) - { -#if DISABLE_STYLE_IF_BROKEN_THEME - // don't delete if it's a pixmap theme style - if (!m_widgetStyle->engine_data) - gtk_style_unref( m_widgetStyle ); -#endif - m_widgetStyle = (GtkStyle*) NULL; - } - if (m_wxwindow) { gtk_widget_destroy( m_wxwindow ); @@ -4097,131 +4082,69 @@ PangoContext *wxWindowGTK::GtkGetPangoX11Context() return m_x11Context; } #endif - -GtkStyle *wxWindowGTK::GetWidgetStyle() -{ - if (m_widgetStyle) - { - GtkStyle *remake = gtk_style_copy( m_widgetStyle ); - - // FIXME: no more klass in 2.0 -#ifndef __WXGTK20__ - remake->klass = m_widgetStyle->klass; -#endif - - gtk_style_unref( m_widgetStyle ); - m_widgetStyle = remake; - } - else - { - GtkStyle *def = gtk_rc_get_style( m_widget ); - - if (!def) - def = gtk_widget_get_default_style(); - - m_widgetStyle = gtk_style_copy( def ); - - // FIXME: no more klass in 2.0 -#ifndef __WXGTK20__ - m_widgetStyle->klass = def->klass; -#endif - } - - return m_widgetStyle; -} - -void wxWindowGTK::SetWidgetStyle() + +GtkRcStyle *wxWindowGTK::CreateWidgetStyle() { -#if DISABLE_STYLE_IF_BROKEN_THEME - if (m_widget->style->engine_data) + // do we need to apply any changes at all? + if ( !m_hasFont && !m_hasFgCol && + (!m_hasBgCol || !m_backgroundColour.Ok()) ) { - static bool s_warningPrinted = FALSE; - if (!s_warningPrinted) - { - printf( "wxWidgets warning: Widget styles disabled due to buggy GTK theme.\n" ); - s_warningPrinted = TRUE; - } - m_widgetStyle = m_widget->style; - return; + return NULL; } -#endif - GtkStyle *style = GetWidgetStyle(); + GtkRcStyle *style = gtk_rc_style_new(); if ( m_hasFont ) { #ifdef __WXGTK20__ - pango_font_description_free( style->font_desc ); - style->font_desc = pango_font_description_copy( m_font.GetNativeFontInfo()->description ); + style->font_desc = + pango_font_description_copy( m_font.GetNativeFontInfo()->description ); #else - gdk_font_unref( style->font ); - style->font = gdk_font_ref( m_font.GetInternalFont( 1.0 ) ); + wxString xfontname = m_font.GetNativeFontInfo()->GetXFontName(); + style->fontset_name = g_strdup(xfontname.c_str()); #endif } if ( m_hasFgCol ) { m_foregroundColour.CalcPixel( gtk_widget_get_colormap( m_widget ) ); - if (m_foregroundColour != wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT)) - { - style->fg[GTK_STATE_NORMAL] = *m_foregroundColour.GetColor(); - style->fg[GTK_STATE_PRELIGHT] = *m_foregroundColour.GetColor(); - style->fg[GTK_STATE_ACTIVE] = *m_foregroundColour.GetColor(); - } - else - { - // Try to restore the gtk default style. This is still a little - // oversimplified for what is probably really needed here for controls - // other than buttons, but is better than not being able to (re)set a - // control's foreground colour to *wxBLACK -- RL - GtkStyle *def = gtk_rc_get_style( m_widget ); - - if (!def) - def = gtk_widget_get_default_style(); - - style->fg[GTK_STATE_NORMAL] = def->fg[GTK_STATE_NORMAL]; - style->fg[GTK_STATE_PRELIGHT] = def->fg[GTK_STATE_PRELIGHT]; - style->fg[GTK_STATE_ACTIVE] = def->fg[GTK_STATE_ACTIVE]; - } + + style->fg[GTK_STATE_NORMAL] = *m_foregroundColour.GetColor(); + style->color_flags[GTK_STATE_NORMAL] = GTK_RC_FG; + + style->fg[GTK_STATE_PRELIGHT] = *m_foregroundColour.GetColor(); + style->color_flags[GTK_STATE_PRELIGHT] = GTK_RC_FG; + + style->fg[GTK_STATE_ACTIVE] = *m_foregroundColour.GetColor(); + style->color_flags[GTK_STATE_ACTIVE] = GTK_RC_FG; } if ( m_hasBgCol && m_backgroundColour.Ok() ) { m_backgroundColour.CalcPixel( gtk_widget_get_colormap( m_widget ) ); - if (m_backgroundColour != wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)) - { - style->bg[GTK_STATE_NORMAL] = *m_backgroundColour.GetColor(); - style->base[GTK_STATE_NORMAL] = *m_backgroundColour.GetColor(); - style->bg[GTK_STATE_PRELIGHT] = *m_backgroundColour.GetColor(); - style->base[GTK_STATE_PRELIGHT] = *m_backgroundColour.GetColor(); - style->bg[GTK_STATE_ACTIVE] = *m_backgroundColour.GetColor(); - style->base[GTK_STATE_ACTIVE] = *m_backgroundColour.GetColor(); - style->bg[GTK_STATE_INSENSITIVE] = *m_backgroundColour.GetColor(); - style->base[GTK_STATE_INSENSITIVE] = *m_backgroundColour.GetColor(); - } - else - { - // Try to restore the gtk default style. This is still a little - // oversimplified for what is probably really needed here for controls - // other than buttons, but is better than not being able to (re)set a - // control's background colour to default grey and means resetting a - // button to wxSYS_COLOUR_BTNFACE will restore its usual highlighting - // behavior -- RL - GtkStyle *def = gtk_rc_get_style( m_widget ); - - if (!def) - def = gtk_widget_get_default_style(); - - style->bg[GTK_STATE_NORMAL] = def->bg[GTK_STATE_NORMAL]; - style->base[GTK_STATE_NORMAL] = def->base[GTK_STATE_NORMAL]; - style->bg[GTK_STATE_PRELIGHT] = def->bg[GTK_STATE_PRELIGHT]; - style->base[GTK_STATE_PRELIGHT] = def->base[GTK_STATE_PRELIGHT]; - style->bg[GTK_STATE_ACTIVE] = def->bg[GTK_STATE_ACTIVE]; - style->base[GTK_STATE_ACTIVE] = def->base[GTK_STATE_ACTIVE]; - style->bg[GTK_STATE_INSENSITIVE] = def->bg[GTK_STATE_INSENSITIVE]; - style->base[GTK_STATE_INSENSITIVE] = def->base[GTK_STATE_INSENSITIVE]; - } + + style->bg[GTK_STATE_NORMAL] = *m_backgroundColour.GetColor(); + style->base[GTK_STATE_NORMAL] = *m_backgroundColour.GetColor(); + style->color_flags[GTK_STATE_NORMAL] = (GtkRcFlags) + (style->color_flags[GTK_STATE_NORMAL] | GTK_RC_BG | GTK_RC_BASE); + + style->bg[GTK_STATE_PRELIGHT] = *m_backgroundColour.GetColor(); + style->base[GTK_STATE_PRELIGHT] = *m_backgroundColour.GetColor(); + style->color_flags[GTK_STATE_PRELIGHT] = (GtkRcFlags) + (style->color_flags[GTK_STATE_PRELIGHT] | GTK_RC_BG | GTK_RC_BASE); + + style->bg[GTK_STATE_ACTIVE] = *m_backgroundColour.GetColor(); + style->base[GTK_STATE_ACTIVE] = *m_backgroundColour.GetColor(); + style->color_flags[GTK_STATE_ACTIVE] = (GtkRcFlags) + (style->color_flags[GTK_STATE_ACTIVE] | GTK_RC_BG | GTK_RC_BASE); + + style->bg[GTK_STATE_INSENSITIVE] = *m_backgroundColour.GetColor(); + style->base[GTK_STATE_INSENSITIVE] = *m_backgroundColour.GetColor(); + style->color_flags[GTK_STATE_INSENSITIVE] = (GtkRcFlags) + (style->color_flags[GTK_STATE_INSENSITIVE] | GTK_RC_BG | GTK_RC_BASE); } + + return style; } void wxWindowGTK::ApplyWidgetStyle() diff --git a/src/gtk1/bmpbuttn.cpp b/src/gtk1/bmpbuttn.cpp index 17bc64454f..db11765013 100644 --- a/src/gtk1/bmpbuttn.cpp +++ b/src/gtk1/bmpbuttn.cpp @@ -193,12 +193,12 @@ wxString wxBitmapButton::GetLabel() const return wxControl::GetLabel(); } -void wxBitmapButton::ApplyWidgetStyle() +void wxBitmapButton::DoApplyWidgetStyle(GtkRcStyle *style) { if ( !BUTTON_CHILD(m_widget) ) return; - wxButton::ApplyWidgetStyle(); + wxButton::DoApplyWidgetStyle(style); } void wxBitmapButton::OnSetBitmap() diff --git a/src/gtk1/button.cpp b/src/gtk1/button.cpp index f71214c940..d64273b780 100644 --- a/src/gtk1/button.cpp +++ b/src/gtk1/button.cpp @@ -196,11 +196,10 @@ bool wxButton::IsOwnGtkWindow( GdkWindow *window ) #endif } -void wxButton::ApplyWidgetStyle() +void wxButton::DoApplyWidgetStyle(GtkRcStyle *style) { - SetWidgetStyle(); - gtk_widget_set_style( m_widget, m_widgetStyle ); - gtk_widget_set_style( BUTTON_CHILD(m_widget), m_widgetStyle ); + gtk_widget_modify_style(m_widget, style); + gtk_widget_modify_style(BUTTON_CHILD(m_widget), style); } wxSize wxButton::DoGetBestSize() const diff --git a/src/gtk1/checkbox.cpp b/src/gtk1/checkbox.cpp index e7fe520d4d..1c64e26ba1 100644 --- a/src/gtk1/checkbox.cpp +++ b/src/gtk1/checkbox.cpp @@ -170,11 +170,10 @@ bool wxCheckBox::Enable( bool enable ) return TRUE; } -void wxCheckBox::ApplyWidgetStyle() +void wxCheckBox::DoApplyWidgetStyle(GtkRcStyle *style) { - SetWidgetStyle(); - gtk_widget_set_style( m_widgetCheckbox, m_widgetStyle ); - gtk_widget_set_style( m_widgetLabel, m_widgetStyle ); + gtk_widget_modify_style(m_widgetCheckbox, style); + gtk_widget_modify_style(m_widgetLabel, style); } bool wxCheckBox::IsOwnGtkWindow( GdkWindow *window ) diff --git a/src/gtk1/choice.cpp b/src/gtk1/choice.cpp index 54f9b1de42..28d895dd2e 100644 --- a/src/gtk1/choice.cpp +++ b/src/gtk1/choice.cpp @@ -437,19 +437,17 @@ void wxChoice::SetSelection( int n ) gtk_option_menu_set_history( GTK_OPTION_MENU(m_widget), (gint)tmp ); } -void wxChoice::ApplyWidgetStyle() +void wxChoice::DoApplyWidgetStyle(GtkRcStyle *style) { - SetWidgetStyle(); - GtkMenuShell *menu_shell = GTK_MENU_SHELL( gtk_option_menu_get_menu( GTK_OPTION_MENU(m_widget) ) ); - gtk_widget_set_style( m_widget, m_widgetStyle ); - gtk_widget_set_style( GTK_WIDGET( menu_shell ), m_widgetStyle ); + gtk_widget_modify_style( m_widget, style ); + gtk_widget_modify_style( GTK_WIDGET( menu_shell ), style ); GList *child = menu_shell->children; while (child) { - gtk_widget_set_style( GTK_WIDGET( child->data ), m_widgetStyle ); + gtk_widget_modify_style( GTK_WIDGET( child->data ), style ); GtkBin *bin = GTK_BIN( child->data ); GtkWidget *label = (GtkWidget *) NULL; @@ -458,7 +456,7 @@ void wxChoice::ApplyWidgetStyle() if (!label) label = BUTTON_CHILD(m_widget); - gtk_widget_set_style( label, m_widgetStyle ); + gtk_widget_modify_style( label, style ); child = child->next; } @@ -513,7 +511,7 @@ int wxChoice::GtkAddHelper(GtkWidget *menu, int pos, const wxString& item) gtk_widget_realize( menu_item ); gtk_widget_realize( GTK_BIN(menu_item)->child ); - if (m_widgetStyle) ApplyWidgetStyle(); + ApplyWidgetStyle(); } gtk_signal_connect( GTK_OBJECT( menu_item ), "activate", diff --git a/src/gtk1/combobox.cpp b/src/gtk1/combobox.cpp index f7950f67bf..2ddf6fcf95 100644 --- a/src/gtk1/combobox.cpp +++ b/src/gtk1/combobox.cpp @@ -239,7 +239,7 @@ int wxComboBox::DoAppend( const wxString &item ) gtk_widget_realize( list_item ); gtk_widget_realize( GTK_BIN(list_item)->child ); - if (m_widgetStyle) ApplyWidgetStyle(); + ApplyWidgetStyle(); } gtk_widget_show( list_item ); @@ -284,8 +284,7 @@ int wxComboBox::DoInsert( const wxString &item, int pos ) gtk_widget_realize( list_item ); gtk_widget_realize( GTK_BIN(list_item)->child ); - if (m_widgetStyle) - ApplyWidgetStyle(); + ApplyWidgetStyle(); } gtk_widget_show( list_item ); @@ -722,22 +721,20 @@ void wxComboBox::OnSize( wxSizeEvent &event ) #endif // 0 } -void wxComboBox::ApplyWidgetStyle() +void wxComboBox::DoApplyWidgetStyle(GtkRcStyle *style) { - SetWidgetStyle(); - -// gtk_widget_set_style( GTK_COMBO(m_widget)->button, m_widgetStyle ); - gtk_widget_set_style( GTK_COMBO(m_widget)->entry, m_widgetStyle ); - gtk_widget_set_style( GTK_COMBO(m_widget)->list, m_widgetStyle ); +// gtk_widget_modify_style( GTK_COMBO(m_widget)->button, syle ); + gtk_widget_modify_style( GTK_COMBO(m_widget)->entry, style ); + gtk_widget_modify_style( GTK_COMBO(m_widget)->list, style ); GtkList *list = GTK_LIST( GTK_COMBO(m_widget)->list ); GList *child = list->children; while (child) { - gtk_widget_set_style( GTK_WIDGET(child->data), m_widgetStyle ); + gtk_widget_modify_style( GTK_WIDGET(child->data), style ); GtkBin *bin = GTK_BIN(child->data); - gtk_widget_set_style( bin->child, m_widgetStyle ); + gtk_widget_modify_style( bin->child, style ); child = child->next; } diff --git a/src/gtk1/control.cpp b/src/gtk1/control.cpp index dfbfe4b9c0..e638c35d8d 100644 --- a/src/gtk1/control.cpp +++ b/src/gtk1/control.cpp @@ -92,6 +92,14 @@ wxSize wxControl::DoGetBestSize() const void wxControl::PostCreation(const wxSize& size) { wxWindow::PostCreation(); + + // NB: GetBestSize needs to know the style, otherwise it will assume + // default font and if the user uses a different font, determined + // best size will be different (typically, smaller) than the desired + // size. This call ensure that a style is available at the time + // GetBestSize is called. + gtk_widget_ensure_style(m_widget); + InheritAttributes(); ApplyWidgetStyle(); SetInitialBestSize(size); @@ -259,6 +267,21 @@ wxControl::GetDefaultAttributesFromGTKWidget(GtkWidget* (*widget_new)(GtkAdjustm return attr; } +void wxControl::ApplyWidgetStyle() +{ + GtkRcStyle *style = CreateWidgetStyle(); + if ( style ) + { + DoApplyWidgetStyle(style); + gtk_rc_style_unref(style); + } +} + +void wxControl::DoApplyWidgetStyle(GtkRcStyle *style) +{ + gtk_widget_modify_style(m_widget, style); +} + #endif // wxUSE_CONTROLS diff --git a/src/gtk1/gauge.cpp b/src/gtk1/gauge.cpp index 7fe754a52e..90aad2ca5b 100644 --- a/src/gtk1/gauge.cpp +++ b/src/gtk1/gauge.cpp @@ -106,12 +106,6 @@ int wxGauge::GetValue() const return m_gaugePos; } -void wxGauge::ApplyWidgetStyle() -{ - SetWidgetStyle(); - gtk_widget_set_style( m_widget, m_widgetStyle ); -} - wxVisualAttributes wxGauge::GetDefaultAttributes() const { // Visible gauge colours use a different colour state diff --git a/src/gtk1/listbox.cpp b/src/gtk1/listbox.cpp index 9f06846793..15c355869d 100644 --- a/src/gtk1/listbox.cpp +++ b/src/gtk1/listbox.cpp @@ -575,12 +575,14 @@ void wxListBox::GtkAddItem( const wxString &item, int pos ) gtk_widget_realize( GTK_BIN(list_item)->child ); // Apply current widget style to the new list_item - if (m_widgetStyle) + GtkRcStyle *style = CreateWidgetStyle(); + if (style) { - gtk_widget_set_style( GTK_WIDGET( list_item ), m_widgetStyle ); + gtk_widget_modify_style( GTK_WIDGET( list_item ), style ); GtkBin *bin = GTK_BIN( list_item ); GtkWidget *label = GTK_WIDGET( bin->child ); - gtk_widget_set_style( label, m_widgetStyle ); + gtk_widget_modify_style( label, style ); + gtk_rc_style_unref( style ); } #if wxUSE_TOOLTIPS @@ -981,11 +983,9 @@ bool wxListBox::IsOwnGtkWindow( GdkWindow *window ) return FALSE; } -void wxListBox::ApplyWidgetStyle() +void wxListBox::DoApplyWidgetStyle(GtkRcStyle *style) { - SetWidgetStyle(); - - if (m_backgroundColour.Ok()) + if (m_hasBgCol && m_backgroundColour.Ok()) { GdkWindow *window = GTK_WIDGET(m_list)->window; if ( window ) @@ -999,11 +999,11 @@ void wxListBox::ApplyWidgetStyle() GList *child = m_list->children; while (child) { - gtk_widget_set_style( GTK_WIDGET(child->data), m_widgetStyle ); + gtk_widget_modify_style( GTK_WIDGET(child->data), style ); GtkBin *bin = GTK_BIN( child->data ); GtkWidget *label = GTK_WIDGET( bin->child ); - gtk_widget_set_style( label, m_widgetStyle ); + gtk_widget_modify_style( label, style ); child = child->next; } diff --git a/src/gtk1/notebook.cpp b/src/gtk1/notebook.cpp index ded15fb845..cb6e7b39d4 100644 --- a/src/gtk1/notebook.cpp +++ b/src/gtk1/notebook.cpp @@ -72,13 +72,6 @@ public: m_image = -1; m_page = (GtkNotebookPage *) NULL; m_box = (GtkWidget *) NULL; - m_labelStyle = (GtkStyle*) NULL; - } - - ~wxGtkNotebookPage() - { - if (m_labelStyle) - gtk_style_unref( m_labelStyle ); } bool SetFont(const wxFont& font); @@ -88,7 +81,6 @@ public: GtkNotebookPage *m_page; GtkLabel *m_label; GtkWidget *m_box; // in which the label and image are packed - GtkStyle *m_labelStyle; }; @@ -97,42 +89,17 @@ bool wxGtkNotebookPage::SetFont(const wxFont& font) if (!m_label) return false; - if (m_labelStyle) - { - GtkStyle *remake = gtk_style_copy( m_labelStyle ); - -#ifndef __WXGTK20__ - remake->klass = m_labelStyle->klass; -#endif - - gtk_style_unref( m_labelStyle ); - m_labelStyle = remake; - } - else - { - GtkStyle *def = gtk_rc_get_style( GTK_WIDGET(m_label) ); - - if (!def) - def = gtk_widget_get_default_style(); - - m_labelStyle = gtk_style_copy( def ); - - // FIXME: no more klass in 2.0 -#ifndef __WXGTK20__ - m_labelStyle->klass = def->klass; -#endif - } - #ifdef __WXGTK20__ - pango_font_description_free( m_labelStyle->font_desc ); - m_labelStyle->font_desc = pango_font_description_copy( font.GetNativeFontInfo()->description ); + gtk_widget_modify_font(GTK_WIDGET(m_label), + font.GetNativeFontInfo()->description); #else - gdk_font_unref( m_labelStyle->font ); - m_labelStyle->font = gdk_font_ref( font.GetInternalFont( 1.0 ) ); + GtkRcStyle *style = gtk_rc_style_new(); + style->fontset_name = + g_strdup(font.GetNativeFontInfo()->GetXFontName().c_str()); + gtk_widget_modify_style(GTK_WIDGET(m_label), style); + gtk_rc_style_unref(style); #endif - gtk_widget_set_style( GTK_WIDGET(m_label), m_labelStyle ); - return true; } @@ -839,12 +806,10 @@ bool wxNotebook::DoPhase( int WXUNUSED(nPhase) ) #endif -void wxNotebook::ApplyWidgetStyle() +void wxNotebook::DoApplyWidgetStyle(GtkRcStyle *style) { // TODO, font for labels etc - - SetWidgetStyle(); - gtk_widget_set_style( m_widget, m_widgetStyle ); + gtk_widget_modify_style( m_widget, style ); } bool wxNotebook::IsOwnGtkWindow( GdkWindow *window ) diff --git a/src/gtk1/radiobox.cpp b/src/gtk1/radiobox.cpp index 3538f3c037..ea1eee5230 100644 --- a/src/gtk1/radiobox.cpp +++ b/src/gtk1/radiobox.cpp @@ -681,19 +681,17 @@ void wxRadioBox::GtkEnableEvents() } } -void wxRadioBox::ApplyWidgetStyle() +void wxRadioBox::DoApplyWidgetStyle(GtkRcStyle *style) { - SetWidgetStyle(); - - gtk_widget_set_style( m_widget, m_widgetStyle ); + gtk_widget_modify_style( m_widget, style ); wxList::compatibility_iterator node = m_boxes.GetFirst(); while (node) { GtkWidget *widget = GTK_WIDGET( node->GetData() ); - gtk_widget_set_style( widget, m_widgetStyle ); - gtk_widget_set_style( BUTTON_CHILD(node->GetData()), m_widgetStyle ); + gtk_widget_modify_style( widget, style ); + gtk_widget_modify_style( BUTTON_CHILD(node->GetData()), style ); node = node->GetNext(); } diff --git a/src/gtk1/radiobut.cpp b/src/gtk1/radiobut.cpp index c03a82e438..2c3e1c0d10 100644 --- a/src/gtk1/radiobut.cpp +++ b/src/gtk1/radiobut.cpp @@ -187,11 +187,10 @@ bool wxRadioButton::Enable( bool enable ) return TRUE; } -void wxRadioButton::ApplyWidgetStyle() +void wxRadioButton::DoApplyWidgetStyle(GtkRcStyle *style) { - SetWidgetStyle(); - gtk_widget_set_style( m_widget, m_widgetStyle ); - gtk_widget_set_style( BUTTON_CHILD(m_widget), m_widgetStyle ); + gtk_widget_modify_style(m_widget, style); + gtk_widget_modify_style(BUTTON_CHILD(m_widget), style); } bool wxRadioButton::IsOwnGtkWindow( GdkWindow *window ) diff --git a/src/gtk1/scrolbar.cpp b/src/gtk1/scrolbar.cpp index 6dcd71ec52..f2d26ced1d 100644 --- a/src/gtk1/scrolbar.cpp +++ b/src/gtk1/scrolbar.cpp @@ -325,12 +325,6 @@ bool wxScrollBar::IsOwnGtkWindow( GdkWindow *window ) ); } -void wxScrollBar::ApplyWidgetStyle() -{ - SetWidgetStyle(); - gtk_widget_set_style( m_widget, m_widgetStyle ); -} - wxSize wxScrollBar::DoGetBestSize() const { return wxControl::DoGetBestSize(); diff --git a/src/gtk1/slider.cpp b/src/gtk1/slider.cpp index e7079c5c10..bcd260ad6e 100644 --- a/src/gtk1/slider.cpp +++ b/src/gtk1/slider.cpp @@ -265,12 +265,6 @@ bool wxSlider::IsOwnGtkWindow( GdkWindow *window ) #endif } -void wxSlider::ApplyWidgetStyle() -{ - SetWidgetStyle(); - gtk_widget_set_style( m_widget, m_widgetStyle ); -} - void wxSlider::GtkDisableEvents() { gtk_signal_disconnect_by_func( GTK_OBJECT(m_adjust), diff --git a/src/gtk1/spinbutt.cpp b/src/gtk1/spinbutt.cpp index 423947a1d3..a62d2c121e 100644 --- a/src/gtk1/spinbutt.cpp +++ b/src/gtk1/spinbutt.cpp @@ -225,15 +225,9 @@ bool wxSpinButton::IsOwnGtkWindow( GdkWindow *window ) return GTK_SPIN_BUTTON(m_widget)->panel == window; } -void wxSpinButton::ApplyWidgetStyle() -{ - SetWidgetStyle(); - gtk_widget_set_style( m_widget, m_widgetStyle ); -} - wxSize wxSpinButton::DoGetBestSize() const { - return wxSize(15, 26); + return wxSize(15, 26); // FIXME } // static diff --git a/src/gtk1/spinctrl.cpp b/src/gtk1/spinctrl.cpp index 80d5007a43..9390128cf0 100644 --- a/src/gtk1/spinctrl.cpp +++ b/src/gtk1/spinctrl.cpp @@ -298,12 +298,6 @@ bool wxSpinCtrl::IsOwnGtkWindow( GdkWindow *window ) return FALSE; } -void wxSpinCtrl::ApplyWidgetStyle() -{ - SetWidgetStyle(); - gtk_widget_set_style( m_widget, m_widgetStyle ); -} - wxSize wxSpinCtrl::DoGetBestSize() const { wxSize ret( wxControl::DoGetBestSize() ); diff --git a/src/gtk1/statbox.cpp b/src/gtk1/statbox.cpp index 879e2bc579..7c3eb9678e 100644 --- a/src/gtk1/statbox.cpp +++ b/src/gtk1/statbox.cpp @@ -91,12 +91,6 @@ void wxStaticBox::SetLabel( const wxString &label ) m_label.empty() ? (char *)NULL : (const char*) wxGTK_CONV( m_label ) ); } -void wxStaticBox::ApplyWidgetStyle() -{ - SetWidgetStyle(); - gtk_widget_set_style( m_widget, m_widgetStyle ); -} - // static wxVisualAttributes wxStaticBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) diff --git a/src/gtk1/stattext.cpp b/src/gtk1/stattext.cpp index 1849d21f5d..d659e8cc16 100644 --- a/src/gtk1/stattext.cpp +++ b/src/gtk1/stattext.cpp @@ -168,12 +168,6 @@ bool wxStaticText::SetFont( const wxFont &font ) return ret; } -void wxStaticText::ApplyWidgetStyle() -{ - SetWidgetStyle(); - gtk_widget_set_style( m_widget, m_widgetStyle ); -} - wxSize wxStaticText::DoGetBestSize() const { // Do not return any arbitrary default value... diff --git a/src/gtk1/textctrl.cpp b/src/gtk1/textctrl.cpp index a2ad1509bb..2d5b6460a5 100644 --- a/src/gtk1/textctrl.cpp +++ b/src/gtk1/textctrl.cpp @@ -1535,10 +1535,9 @@ bool wxTextCtrl::SetStyle( long start, long end, const wxTextAttr& style ) } } -void wxTextCtrl::ApplyWidgetStyle() +void wxTextCtrl::DoApplyWidgetStyle(GtkRcStyle *style) { - SetWidgetStyle(); - gtk_widget_set_style( m_text, m_widgetStyle ); + gtk_widget_modify_style(m_text, style); } void wxTextCtrl::OnCut(wxCommandEvent& WXUNUSED(event)) diff --git a/src/gtk1/tglbtn.cpp b/src/gtk1/tglbtn.cpp index d8aac966f6..8ac7ec5a3c 100644 --- a/src/gtk1/tglbtn.cpp +++ b/src/gtk1/tglbtn.cpp @@ -159,11 +159,10 @@ bool wxToggleBitmapButton::Enable(bool enable /*=TRUE*/) return TRUE; } -void wxToggleBitmapButton::ApplyWidgetStyle() +void wxToggleBitmapButton::DoApplyWidgetStyle(GtkRcStyle *style) { - SetWidgetStyle(); - gtk_widget_set_style(m_widget, m_widgetStyle); - gtk_widget_set_style(BUTTON_CHILD(m_widget), m_widgetStyle); + gtk_widget_modify_style(m_widget, style); + gtk_widget_modify_style(BUTTON_CHILD(m_widget), style); } bool wxToggleBitmapButton::IsOwnGtkWindow(GdkWindow *window) @@ -300,11 +299,10 @@ bool wxToggleButton::Enable(bool enable /*=TRUE*/) return TRUE; } -void wxToggleButton::ApplyWidgetStyle() +void wxToggleButton::DoApplyWidgetStyle(GtkRcStyle *style) { - SetWidgetStyle(); - gtk_widget_set_style(m_widget, m_widgetStyle); - gtk_widget_set_style(BUTTON_CHILD(m_widget), m_widgetStyle); + gtk_widget_modify_style(m_widget, style); + gtk_widget_modify_style(BUTTON_CHILD(m_widget), style); } bool wxToggleButton::IsOwnGtkWindow(GdkWindow *window) diff --git a/src/gtk1/window.cpp b/src/gtk1/window.cpp index 150aabdcfc..13d9f19cd6 100644 --- a/src/gtk1/window.cpp +++ b/src/gtk1/window.cpp @@ -267,10 +267,6 @@ extern bool g_mainThreadLocked; // debug //----------------------------------------------------------------------------- -#ifndef __WXGTK20__ -#define DISABLE_STYLE_IF_BROKEN_THEME 0 -#endif - #ifdef __WXDEBUG__ #if wxUSE_THREADS @@ -2566,7 +2562,6 @@ void wxWindowGTK::Init() m_oldClientHeight = 0; m_resizing = FALSE; - m_widgetStyle = (GtkStyle*) NULL; m_insertCallback = (wxInsertChildFunction) NULL; @@ -2760,16 +2755,6 @@ wxWindowGTK::~wxWindowGTK() gdk_ic_attr_destroy (m_icattr); #endif - if (m_widgetStyle) - { -#if DISABLE_STYLE_IF_BROKEN_THEME - // don't delete if it's a pixmap theme style - if (!m_widgetStyle->engine_data) - gtk_style_unref( m_widgetStyle ); -#endif - m_widgetStyle = (GtkStyle*) NULL; - } - if (m_wxwindow) { gtk_widget_destroy( m_wxwindow ); @@ -4097,131 +4082,69 @@ PangoContext *wxWindowGTK::GtkGetPangoX11Context() return m_x11Context; } #endif - -GtkStyle *wxWindowGTK::GetWidgetStyle() -{ - if (m_widgetStyle) - { - GtkStyle *remake = gtk_style_copy( m_widgetStyle ); - - // FIXME: no more klass in 2.0 -#ifndef __WXGTK20__ - remake->klass = m_widgetStyle->klass; -#endif - - gtk_style_unref( m_widgetStyle ); - m_widgetStyle = remake; - } - else - { - GtkStyle *def = gtk_rc_get_style( m_widget ); - - if (!def) - def = gtk_widget_get_default_style(); - - m_widgetStyle = gtk_style_copy( def ); - - // FIXME: no more klass in 2.0 -#ifndef __WXGTK20__ - m_widgetStyle->klass = def->klass; -#endif - } - - return m_widgetStyle; -} - -void wxWindowGTK::SetWidgetStyle() + +GtkRcStyle *wxWindowGTK::CreateWidgetStyle() { -#if DISABLE_STYLE_IF_BROKEN_THEME - if (m_widget->style->engine_data) + // do we need to apply any changes at all? + if ( !m_hasFont && !m_hasFgCol && + (!m_hasBgCol || !m_backgroundColour.Ok()) ) { - static bool s_warningPrinted = FALSE; - if (!s_warningPrinted) - { - printf( "wxWidgets warning: Widget styles disabled due to buggy GTK theme.\n" ); - s_warningPrinted = TRUE; - } - m_widgetStyle = m_widget->style; - return; + return NULL; } -#endif - GtkStyle *style = GetWidgetStyle(); + GtkRcStyle *style = gtk_rc_style_new(); if ( m_hasFont ) { #ifdef __WXGTK20__ - pango_font_description_free( style->font_desc ); - style->font_desc = pango_font_description_copy( m_font.GetNativeFontInfo()->description ); + style->font_desc = + pango_font_description_copy( m_font.GetNativeFontInfo()->description ); #else - gdk_font_unref( style->font ); - style->font = gdk_font_ref( m_font.GetInternalFont( 1.0 ) ); + wxString xfontname = m_font.GetNativeFontInfo()->GetXFontName(); + style->fontset_name = g_strdup(xfontname.c_str()); #endif } if ( m_hasFgCol ) { m_foregroundColour.CalcPixel( gtk_widget_get_colormap( m_widget ) ); - if (m_foregroundColour != wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT)) - { - style->fg[GTK_STATE_NORMAL] = *m_foregroundColour.GetColor(); - style->fg[GTK_STATE_PRELIGHT] = *m_foregroundColour.GetColor(); - style->fg[GTK_STATE_ACTIVE] = *m_foregroundColour.GetColor(); - } - else - { - // Try to restore the gtk default style. This is still a little - // oversimplified for what is probably really needed here for controls - // other than buttons, but is better than not being able to (re)set a - // control's foreground colour to *wxBLACK -- RL - GtkStyle *def = gtk_rc_get_style( m_widget ); - - if (!def) - def = gtk_widget_get_default_style(); - - style->fg[GTK_STATE_NORMAL] = def->fg[GTK_STATE_NORMAL]; - style->fg[GTK_STATE_PRELIGHT] = def->fg[GTK_STATE_PRELIGHT]; - style->fg[GTK_STATE_ACTIVE] = def->fg[GTK_STATE_ACTIVE]; - } + + style->fg[GTK_STATE_NORMAL] = *m_foregroundColour.GetColor(); + style->color_flags[GTK_STATE_NORMAL] = GTK_RC_FG; + + style->fg[GTK_STATE_PRELIGHT] = *m_foregroundColour.GetColor(); + style->color_flags[GTK_STATE_PRELIGHT] = GTK_RC_FG; + + style->fg[GTK_STATE_ACTIVE] = *m_foregroundColour.GetColor(); + style->color_flags[GTK_STATE_ACTIVE] = GTK_RC_FG; } if ( m_hasBgCol && m_backgroundColour.Ok() ) { m_backgroundColour.CalcPixel( gtk_widget_get_colormap( m_widget ) ); - if (m_backgroundColour != wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)) - { - style->bg[GTK_STATE_NORMAL] = *m_backgroundColour.GetColor(); - style->base[GTK_STATE_NORMAL] = *m_backgroundColour.GetColor(); - style->bg[GTK_STATE_PRELIGHT] = *m_backgroundColour.GetColor(); - style->base[GTK_STATE_PRELIGHT] = *m_backgroundColour.GetColor(); - style->bg[GTK_STATE_ACTIVE] = *m_backgroundColour.GetColor(); - style->base[GTK_STATE_ACTIVE] = *m_backgroundColour.GetColor(); - style->bg[GTK_STATE_INSENSITIVE] = *m_backgroundColour.GetColor(); - style->base[GTK_STATE_INSENSITIVE] = *m_backgroundColour.GetColor(); - } - else - { - // Try to restore the gtk default style. This is still a little - // oversimplified for what is probably really needed here for controls - // other than buttons, but is better than not being able to (re)set a - // control's background colour to default grey and means resetting a - // button to wxSYS_COLOUR_BTNFACE will restore its usual highlighting - // behavior -- RL - GtkStyle *def = gtk_rc_get_style( m_widget ); - - if (!def) - def = gtk_widget_get_default_style(); - - style->bg[GTK_STATE_NORMAL] = def->bg[GTK_STATE_NORMAL]; - style->base[GTK_STATE_NORMAL] = def->base[GTK_STATE_NORMAL]; - style->bg[GTK_STATE_PRELIGHT] = def->bg[GTK_STATE_PRELIGHT]; - style->base[GTK_STATE_PRELIGHT] = def->base[GTK_STATE_PRELIGHT]; - style->bg[GTK_STATE_ACTIVE] = def->bg[GTK_STATE_ACTIVE]; - style->base[GTK_STATE_ACTIVE] = def->base[GTK_STATE_ACTIVE]; - style->bg[GTK_STATE_INSENSITIVE] = def->bg[GTK_STATE_INSENSITIVE]; - style->base[GTK_STATE_INSENSITIVE] = def->base[GTK_STATE_INSENSITIVE]; - } + + style->bg[GTK_STATE_NORMAL] = *m_backgroundColour.GetColor(); + style->base[GTK_STATE_NORMAL] = *m_backgroundColour.GetColor(); + style->color_flags[GTK_STATE_NORMAL] = (GtkRcFlags) + (style->color_flags[GTK_STATE_NORMAL] | GTK_RC_BG | GTK_RC_BASE); + + style->bg[GTK_STATE_PRELIGHT] = *m_backgroundColour.GetColor(); + style->base[GTK_STATE_PRELIGHT] = *m_backgroundColour.GetColor(); + style->color_flags[GTK_STATE_PRELIGHT] = (GtkRcFlags) + (style->color_flags[GTK_STATE_PRELIGHT] | GTK_RC_BG | GTK_RC_BASE); + + style->bg[GTK_STATE_ACTIVE] = *m_backgroundColour.GetColor(); + style->base[GTK_STATE_ACTIVE] = *m_backgroundColour.GetColor(); + style->color_flags[GTK_STATE_ACTIVE] = (GtkRcFlags) + (style->color_flags[GTK_STATE_ACTIVE] | GTK_RC_BG | GTK_RC_BASE); + + style->bg[GTK_STATE_INSENSITIVE] = *m_backgroundColour.GetColor(); + style->base[GTK_STATE_INSENSITIVE] = *m_backgroundColour.GetColor(); + style->color_flags[GTK_STATE_INSENSITIVE] = (GtkRcFlags) + (style->color_flags[GTK_STATE_INSENSITIVE] | GTK_RC_BG | GTK_RC_BASE); } + + return style; } void wxWindowGTK::ApplyWidgetStyle() -- 2.45.2