From 9d522606d0a1dfd22bcdc1a386b3dca01fa985e3 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Thu, 6 May 2004 17:26:25 +0000 Subject: [PATCH] Get(Class)DefaultAttributes() for wxGTK controls git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@27115 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/gtk/button.h | 3 + include/wx/gtk/checkbox.h | 3 + include/wx/gtk/choice.h | 4 ++ include/wx/gtk/combobox.h | 7 +++ include/wx/gtk/control.h | 25 ++++++++ include/wx/gtk/gauge.h | 5 ++ include/wx/gtk/listbox.h | 7 +++ include/wx/gtk/notebook.h | 4 ++ include/wx/gtk/radiobox.h | 3 + include/wx/gtk/radiobut.h | 3 + include/wx/gtk/scrolbar.h | 3 + include/wx/gtk/slider.h | 3 + include/wx/gtk/spinbutt.h | 3 + include/wx/gtk/spinctrl.h | 7 +++ include/wx/gtk/statbmp.h | 3 + include/wx/gtk/statbox.h | 3 + include/wx/gtk/statline.h | 4 ++ include/wx/gtk/stattext.h | 3 + include/wx/gtk/tbargtk.h | 3 + include/wx/gtk/textctrl.h | 7 +++ include/wx/gtk/tglbtn.h | 7 ++- include/wx/gtk1/button.h | 3 + include/wx/gtk1/checkbox.h | 3 + include/wx/gtk1/choice.h | 4 ++ include/wx/gtk1/combobox.h | 7 +++ include/wx/gtk1/control.h | 25 ++++++++ include/wx/gtk1/gauge.h | 5 ++ include/wx/gtk1/listbox.h | 7 +++ include/wx/gtk1/notebook.h | 4 ++ include/wx/gtk1/radiobox.h | 3 + include/wx/gtk1/radiobut.h | 3 + include/wx/gtk1/scrolbar.h | 3 + include/wx/gtk1/slider.h | 3 + include/wx/gtk1/spinbutt.h | 3 + include/wx/gtk1/spinctrl.h | 7 +++ include/wx/gtk1/statbmp.h | 3 + include/wx/gtk1/statbox.h | 3 + include/wx/gtk1/statline.h | 4 ++ include/wx/gtk1/stattext.h | 3 + include/wx/gtk1/tbargtk.h | 3 + include/wx/gtk1/textctrl.h | 7 +++ include/wx/gtk1/tglbtn.h | 7 ++- src/gtk/button.cpp | 7 +++ src/gtk/checkbox.cpp | 7 +++ src/gtk/choice.cpp | 7 +++ src/gtk/combobox.cpp | 7 +++ src/gtk/control.cpp | 120 +++++++++++++++++++++++++++++++++++++ src/gtk/gauge.cpp | 17 ++++++ src/gtk/listbox.cpp | 8 +++ src/gtk/notebook.cpp | 7 +++ src/gtk/radiobox.cpp | 11 ++++ src/gtk/radiobut.cpp | 12 ++++ src/gtk/scrolbar.cpp | 7 +++ src/gtk/slider.cpp | 7 +++ src/gtk/spinbutt.cpp | 9 +++ src/gtk/spinctrl.cpp | 9 +++ src/gtk/statbmp.cpp | 8 +++ src/gtk/statbox.cpp | 7 +++ src/gtk/statline.cpp | 7 +++ src/gtk/stattext.cpp | 7 +++ src/gtk/tbargtk.cpp | 18 ++++++ src/gtk/textctrl.cpp | 34 ++++++----- src/gtk/tglbtn.cpp | 17 ++++++ src/gtk1/button.cpp | 7 +++ src/gtk1/checkbox.cpp | 7 +++ src/gtk1/choice.cpp | 7 +++ src/gtk1/combobox.cpp | 7 +++ src/gtk1/control.cpp | 120 +++++++++++++++++++++++++++++++++++++ src/gtk1/gauge.cpp | 17 ++++++ src/gtk1/listbox.cpp | 8 +++ src/gtk1/notebook.cpp | 7 +++ src/gtk1/radiobox.cpp | 11 ++++ src/gtk1/radiobut.cpp | 12 ++++ src/gtk1/scrolbar.cpp | 7 +++ src/gtk1/slider.cpp | 7 +++ src/gtk1/spinbutt.cpp | 9 +++ src/gtk1/spinctrl.cpp | 9 +++ src/gtk1/statbmp.cpp | 8 +++ src/gtk1/statbox.cpp | 7 +++ src/gtk1/statline.cpp | 7 +++ src/gtk1/stattext.cpp | 7 +++ src/gtk1/tbargtk.cpp | 18 ++++++ src/gtk1/textctrl.cpp | 34 ++++++----- src/gtk1/tglbtn.cpp | 17 ++++++ 84 files changed, 852 insertions(+), 34 deletions(-) diff --git a/include/wx/gtk/button.h b/include/wx/gtk/button.h index 5c90c03e24..3a55ddec52 100644 --- a/include/wx/gtk/button.h +++ b/include/wx/gtk/button.h @@ -71,6 +71,9 @@ public: // to override this here too... virtual bool ShouldInheritColours() const { return false; } + static wxVisualAttributes + GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); + protected: virtual wxSize DoGetBestSize() const; diff --git a/include/wx/gtk/checkbox.h b/include/wx/gtk/checkbox.h index 11f89e0a47..0fefb3c67c 100644 --- a/include/wx/gtk/checkbox.h +++ b/include/wx/gtk/checkbox.h @@ -45,6 +45,9 @@ public: virtual void SetLabel( const wxString& label ); virtual bool Enable( bool enable = TRUE ); + static wxVisualAttributes + GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); + // implementation // -------------- diff --git a/include/wx/gtk/choice.h b/include/wx/gtk/choice.h index d738e3e253..17ae9edeb2 100644 --- a/include/wx/gtk/choice.h +++ b/include/wx/gtk/choice.h @@ -77,6 +77,9 @@ public: wxString GetString( int n ) const; void SetString( int n, const wxString& string ); + static wxVisualAttributes + GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); + protected: wxList m_clientList; // contains the client data for the items @@ -92,6 +95,7 @@ protected: virtual wxSize DoGetBestSize() const; virtual bool IsOwnGtkWindow( GdkWindow *window ); + private: // common part of Create() and DoAppend() int GtkAddHelper(GtkWidget *menu, int pos, const wxString& item); diff --git a/include/wx/gtk/combobox.h b/include/wx/gtk/combobox.h index b3756066cc..39bbb7ed54 100644 --- a/include/wx/gtk/combobox.h +++ b/include/wx/gtk/combobox.h @@ -134,6 +134,9 @@ public: wxCONTROL_ITEMCONTAINER_CLIENTDATAOBJECT_RECAST + static wxVisualAttributes + GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); + protected: virtual int DoAppend(const wxString& item); virtual int DoInsert(const wxString& item, int pos); @@ -145,6 +148,10 @@ protected: virtual wxSize DoGetBestSize() const; + // Widgets that use the style->base colour for the BG colour should + // override this and return true. + virtual bool UseGTKStyleBase() const { return true; } + private: DECLARE_DYNAMIC_CLASS_NO_COPY(wxComboBox) DECLARE_EVENT_TABLE() diff --git a/include/wx/gtk/control.h b/include/wx/gtk/control.h index 38b277a858..be6f36bc1c 100644 --- a/include/wx/gtk/control.h +++ b/include/wx/gtk/control.h @@ -53,6 +53,8 @@ public: virtual void SetLabel( const wxString &label ); virtual wxString GetLabel() const; + virtual wxVisualAttributes GetDefaultAttributes() const; + protected: virtual wxSize DoGetBestSize() const; void PostCreation(const wxSize& size); @@ -61,6 +63,29 @@ protected: wxString PrepareLabelMnemonics( const wxString &label ) const; #endif + // These are used by GetDefaultAttributes + static wxVisualAttributes + GetDefaultAttributesFromGTKWidget(GtkWidget* widget, + bool useBase = false, + int state = -1); + static wxVisualAttributes + GetDefaultAttributesFromGTKWidget(GtkWidget* (*widget_new)(void), + bool useBase = false, + int state = -1); + static wxVisualAttributes + GetDefaultAttributesFromGTKWidget(GtkWidget* (*widget_new)(const gchar*), + bool useBase = false, + int state = -1); + + static wxVisualAttributes + GetDefaultAttributesFromGTKWidget(GtkWidget* (*widget_new)(GtkAdjustment*), + bool useBase = false, + int state = -1); + + // Widgets that use the style->base colour for the BG colour should + // override this and return true. + virtual bool UseGTKStyleBase() const { return false; } + wxString m_label; char m_chAccel; // enabled to avoid breaking binary compatibility later on diff --git a/include/wx/gtk/gauge.h b/include/wx/gtk/gauge.h index 5ca47abcf6..5652b6b5cb 100644 --- a/include/wx/gtk/gauge.h +++ b/include/wx/gtk/gauge.h @@ -77,6 +77,9 @@ public: bool IsVertical() const { return HasFlag(wxGA_VERTICAL); } + static wxVisualAttributes + GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); + // implementation // ------------- @@ -100,6 +103,8 @@ protected: virtual wxSize DoGetBestSize() const; + virtual wxVisualAttributes GetDefaultAttributes() const; + private: DECLARE_DYNAMIC_CLASS(wxGauge) }; diff --git a/include/wx/gtk/listbox.h b/include/wx/gtk/listbox.h index 7974011566..ff8d595c6c 100644 --- a/include/wx/gtk/listbox.h +++ b/include/wx/gtk/listbox.h @@ -96,6 +96,9 @@ public: virtual void DoSetItemClientObject(int n, wxClientData* clientData); virtual wxClientData* DoGetItemClientObject(int n) const; + static wxVisualAttributes + GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); + // implementation from now on void GtkAddItem( const wxString &item, int pos=-1 ); @@ -127,6 +130,10 @@ protected: // return the string label for the given item wxString GetRealLabel(struct _GList *item) const; + // Widgets that use the style->base colour for the BG colour should + // override this and return true. + virtual bool UseGTKStyleBase() const { return true; } + private: // this array is only used for controls with wxCB_SORT style, so only // allocate it if it's needed (hence using pointer) diff --git a/include/wx/gtk/notebook.h b/include/wx/gtk/notebook.h index 9dfef193c1..664eb5f199 100644 --- a/include/wx/gtk/notebook.h +++ b/include/wx/gtk/notebook.h @@ -98,6 +98,10 @@ public: // -------------------------- void OnNavigationKey(wxNavigationKeyEvent& event); + + static wxVisualAttributes + GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); + // implementation // -------------- diff --git a/include/wx/gtk/radiobox.h b/include/wx/gtk/radiobox.h index cfdcef9c94..882bda0357 100644 --- a/include/wx/gtk/radiobox.h +++ b/include/wx/gtk/radiobox.h @@ -111,6 +111,9 @@ public: virtual bool Show( bool show = TRUE ); virtual bool Enable( bool enable = TRUE ); + static wxVisualAttributes + GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); + // implementation // -------------- diff --git a/include/wx/gtk/radiobut.h b/include/wx/gtk/radiobut.h index af716335ea..39c442216f 100644 --- a/include/wx/gtk/radiobut.h +++ b/include/wx/gtk/radiobut.h @@ -49,6 +49,9 @@ public: virtual bool GetValue() const; virtual bool Enable( bool enable = TRUE ); + static wxVisualAttributes + GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); + // implementation virtual bool IsRadioButton() const { return TRUE; } diff --git a/include/wx/gtk/scrolbar.h b/include/wx/gtk/scrolbar.h index 4f43d99e7e..8ce5e82897 100644 --- a/include/wx/gtk/scrolbar.h +++ b/include/wx/gtk/scrolbar.h @@ -68,6 +68,9 @@ public: void SetObjectLength( int objectLength ); void SetViewLength( int viewLength ); + static wxVisualAttributes + GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); + // implementation // -------------- diff --git a/include/wx/gtk/slider.h b/include/wx/gtk/slider.h index 945c726ede..bd4af3fcad 100644 --- a/include/wx/gtk/slider.h +++ b/include/wx/gtk/slider.h @@ -60,6 +60,9 @@ public: virtual void SetThumbLength(int lenPixels); virtual int GetThumbLength() const; + static wxVisualAttributes + GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); + // implementation bool IsOwnGtkWindow( GdkWindow *window ); void ApplyWidgetStyle(); diff --git a/include/wx/gtk/spinbutt.h b/include/wx/gtk/spinbutt.h index ce80a907e5..dfe3c40c05 100644 --- a/include/wx/gtk/spinbutt.h +++ b/include/wx/gtk/spinbutt.h @@ -46,6 +46,9 @@ public: virtual int GetMin() const; virtual int GetMax() const; + static wxVisualAttributes + GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); + // implementation void OnSize( wxSizeEvent &event ); diff --git a/include/wx/gtk/spinctrl.h b/include/wx/gtk/spinctrl.h index f39e5184e6..425f31f335 100644 --- a/include/wx/gtk/spinctrl.h +++ b/include/wx/gtk/spinctrl.h @@ -59,6 +59,9 @@ public: virtual int GetMin() const; virtual int GetMax() const; + static wxVisualAttributes + GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); + // implementation void OnChar( wxKeyEvent &event ); @@ -73,6 +76,10 @@ public: protected: virtual wxSize DoGetBestSize() const; + // Widgets that use the style->base colour for the BG colour should + // override this and return true. + virtual bool UseGTKStyleBase() const { return true; } + private: DECLARE_DYNAMIC_CLASS(wxSpinCtrl) DECLARE_EVENT_TABLE() diff --git a/include/wx/gtk/statbmp.h b/include/wx/gtk/statbmp.h index 642e708448..00677618de 100644 --- a/include/wx/gtk/statbmp.h +++ b/include/wx/gtk/statbmp.h @@ -52,6 +52,9 @@ public: return (const wxIcon &)m_bitmap; } + static wxVisualAttributes + GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); + private: // creates the new pixmap widget void CreatePixmapWidget(); diff --git a/include/wx/gtk/statbox.h b/include/wx/gtk/statbox.h index fa4d65228a..f0f1b2ff0e 100644 --- a/include/wx/gtk/statbox.h +++ b/include/wx/gtk/statbox.h @@ -40,6 +40,9 @@ public: virtual void SetLabel( const wxString &label ); + static wxVisualAttributes + GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); + // implementation virtual void ApplyWidgetStyle(); diff --git a/include/wx/gtk/statline.h b/include/wx/gtk/statline.h index 2324b01204..803ae2018a 100644 --- a/include/wx/gtk/statline.h +++ b/include/wx/gtk/statline.h @@ -45,6 +45,10 @@ public: bool Create( wxWindow *parent, wxWindowID id, const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize, long style = wxLI_HORIZONTAL, const wxString &name = wxStaticTextNameStr ); + + static wxVisualAttributes + GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); + }; #endif diff --git a/include/wx/gtk/stattext.h b/include/wx/gtk/stattext.h index ca98ba9015..eb9ee2a86e 100644 --- a/include/wx/gtk/stattext.h +++ b/include/wx/gtk/stattext.h @@ -59,6 +59,9 @@ public: bool SetFont( const wxFont &font ); bool SetForegroundColour( const wxColour& colour ); + + static wxVisualAttributes + GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); // implementation // -------------- diff --git a/include/wx/gtk/tbargtk.h b/include/wx/gtk/tbargtk.h index c3c585be05..340d70d665 100644 --- a/include/wx/gtk/tbargtk.h +++ b/include/wx/gtk/tbargtk.h @@ -56,6 +56,9 @@ public: virtual void SetWindowStyleFlag( long style ); + static wxVisualAttributes + GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); + // implementation from now on // -------------------------- diff --git a/include/wx/gtk/textctrl.h b/include/wx/gtk/textctrl.h index 88ebbb41af..7ca89491e6 100644 --- a/include/wx/gtk/textctrl.h +++ b/include/wx/gtk/textctrl.h @@ -162,6 +162,9 @@ public: // should we ignore the changed signal? always resets the flag bool IgnoreTextUpdate(); + static wxVisualAttributes + GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); + protected: virtual wxSize DoGetBestSize() const; @@ -175,6 +178,10 @@ protected: // scroll position changed bool DoScroll(GtkAdjustment *adj, int diff); + // Widgets that use the style->base colour for the BG colour should + // override this and return true. + virtual bool UseGTKStyleBase() const { return true; } + private: // change the font for everything in this control void ChangeFontGlobally(); diff --git a/include/wx/gtk/tglbtn.h b/include/wx/gtk/tglbtn.h index 9d66c44797..7da1777c18 100644 --- a/include/wx/gtk/tglbtn.h +++ b/include/wx/gtk/tglbtn.h @@ -66,7 +66,9 @@ public: void SetLabel(const wxBitmap& label); bool Enable(bool enable = TRUE); - + static wxVisualAttributes + GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); + // implementation bool m_blockEvent; wxBitmap m_bitmap; @@ -81,6 +83,7 @@ public: private: DECLARE_DYNAMIC_CLASS(wxToggleBitmapButton) }; + //----------------------------------------------------------------------------- // wxToggleButton //----------------------------------------------------------------------------- @@ -119,6 +122,8 @@ public: void SetLabel(const wxString& label); bool Enable(bool enable = TRUE); + static wxVisualAttributes + GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); // implementation bool m_blockEvent; diff --git a/include/wx/gtk1/button.h b/include/wx/gtk1/button.h index 5c90c03e24..3a55ddec52 100644 --- a/include/wx/gtk1/button.h +++ b/include/wx/gtk1/button.h @@ -71,6 +71,9 @@ public: // to override this here too... virtual bool ShouldInheritColours() const { return false; } + static wxVisualAttributes + GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); + protected: virtual wxSize DoGetBestSize() const; diff --git a/include/wx/gtk1/checkbox.h b/include/wx/gtk1/checkbox.h index 11f89e0a47..0fefb3c67c 100644 --- a/include/wx/gtk1/checkbox.h +++ b/include/wx/gtk1/checkbox.h @@ -45,6 +45,9 @@ public: virtual void SetLabel( const wxString& label ); virtual bool Enable( bool enable = TRUE ); + static wxVisualAttributes + GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); + // implementation // -------------- diff --git a/include/wx/gtk1/choice.h b/include/wx/gtk1/choice.h index d738e3e253..17ae9edeb2 100644 --- a/include/wx/gtk1/choice.h +++ b/include/wx/gtk1/choice.h @@ -77,6 +77,9 @@ public: wxString GetString( int n ) const; void SetString( int n, const wxString& string ); + static wxVisualAttributes + GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); + protected: wxList m_clientList; // contains the client data for the items @@ -92,6 +95,7 @@ protected: virtual wxSize DoGetBestSize() const; virtual bool IsOwnGtkWindow( GdkWindow *window ); + private: // common part of Create() and DoAppend() int GtkAddHelper(GtkWidget *menu, int pos, const wxString& item); diff --git a/include/wx/gtk1/combobox.h b/include/wx/gtk1/combobox.h index b3756066cc..39bbb7ed54 100644 --- a/include/wx/gtk1/combobox.h +++ b/include/wx/gtk1/combobox.h @@ -134,6 +134,9 @@ public: wxCONTROL_ITEMCONTAINER_CLIENTDATAOBJECT_RECAST + static wxVisualAttributes + GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); + protected: virtual int DoAppend(const wxString& item); virtual int DoInsert(const wxString& item, int pos); @@ -145,6 +148,10 @@ protected: virtual wxSize DoGetBestSize() const; + // Widgets that use the style->base colour for the BG colour should + // override this and return true. + virtual bool UseGTKStyleBase() const { return true; } + private: DECLARE_DYNAMIC_CLASS_NO_COPY(wxComboBox) DECLARE_EVENT_TABLE() diff --git a/include/wx/gtk1/control.h b/include/wx/gtk1/control.h index 38b277a858..be6f36bc1c 100644 --- a/include/wx/gtk1/control.h +++ b/include/wx/gtk1/control.h @@ -53,6 +53,8 @@ public: virtual void SetLabel( const wxString &label ); virtual wxString GetLabel() const; + virtual wxVisualAttributes GetDefaultAttributes() const; + protected: virtual wxSize DoGetBestSize() const; void PostCreation(const wxSize& size); @@ -61,6 +63,29 @@ protected: wxString PrepareLabelMnemonics( const wxString &label ) const; #endif + // These are used by GetDefaultAttributes + static wxVisualAttributes + GetDefaultAttributesFromGTKWidget(GtkWidget* widget, + bool useBase = false, + int state = -1); + static wxVisualAttributes + GetDefaultAttributesFromGTKWidget(GtkWidget* (*widget_new)(void), + bool useBase = false, + int state = -1); + static wxVisualAttributes + GetDefaultAttributesFromGTKWidget(GtkWidget* (*widget_new)(const gchar*), + bool useBase = false, + int state = -1); + + static wxVisualAttributes + GetDefaultAttributesFromGTKWidget(GtkWidget* (*widget_new)(GtkAdjustment*), + bool useBase = false, + int state = -1); + + // Widgets that use the style->base colour for the BG colour should + // override this and return true. + virtual bool UseGTKStyleBase() const { return false; } + wxString m_label; char m_chAccel; // enabled to avoid breaking binary compatibility later on diff --git a/include/wx/gtk1/gauge.h b/include/wx/gtk1/gauge.h index 5ca47abcf6..5652b6b5cb 100644 --- a/include/wx/gtk1/gauge.h +++ b/include/wx/gtk1/gauge.h @@ -77,6 +77,9 @@ public: bool IsVertical() const { return HasFlag(wxGA_VERTICAL); } + static wxVisualAttributes + GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); + // implementation // ------------- @@ -100,6 +103,8 @@ protected: virtual wxSize DoGetBestSize() const; + virtual wxVisualAttributes GetDefaultAttributes() const; + private: DECLARE_DYNAMIC_CLASS(wxGauge) }; diff --git a/include/wx/gtk1/listbox.h b/include/wx/gtk1/listbox.h index 7974011566..ff8d595c6c 100644 --- a/include/wx/gtk1/listbox.h +++ b/include/wx/gtk1/listbox.h @@ -96,6 +96,9 @@ public: virtual void DoSetItemClientObject(int n, wxClientData* clientData); virtual wxClientData* DoGetItemClientObject(int n) const; + static wxVisualAttributes + GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); + // implementation from now on void GtkAddItem( const wxString &item, int pos=-1 ); @@ -127,6 +130,10 @@ protected: // return the string label for the given item wxString GetRealLabel(struct _GList *item) const; + // Widgets that use the style->base colour for the BG colour should + // override this and return true. + virtual bool UseGTKStyleBase() const { return true; } + private: // this array is only used for controls with wxCB_SORT style, so only // allocate it if it's needed (hence using pointer) diff --git a/include/wx/gtk1/notebook.h b/include/wx/gtk1/notebook.h index 9dfef193c1..664eb5f199 100644 --- a/include/wx/gtk1/notebook.h +++ b/include/wx/gtk1/notebook.h @@ -98,6 +98,10 @@ public: // -------------------------- void OnNavigationKey(wxNavigationKeyEvent& event); + + static wxVisualAttributes + GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); + // implementation // -------------- diff --git a/include/wx/gtk1/radiobox.h b/include/wx/gtk1/radiobox.h index cfdcef9c94..882bda0357 100644 --- a/include/wx/gtk1/radiobox.h +++ b/include/wx/gtk1/radiobox.h @@ -111,6 +111,9 @@ public: virtual bool Show( bool show = TRUE ); virtual bool Enable( bool enable = TRUE ); + static wxVisualAttributes + GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); + // implementation // -------------- diff --git a/include/wx/gtk1/radiobut.h b/include/wx/gtk1/radiobut.h index af716335ea..39c442216f 100644 --- a/include/wx/gtk1/radiobut.h +++ b/include/wx/gtk1/radiobut.h @@ -49,6 +49,9 @@ public: virtual bool GetValue() const; virtual bool Enable( bool enable = TRUE ); + static wxVisualAttributes + GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); + // implementation virtual bool IsRadioButton() const { return TRUE; } diff --git a/include/wx/gtk1/scrolbar.h b/include/wx/gtk1/scrolbar.h index 4f43d99e7e..8ce5e82897 100644 --- a/include/wx/gtk1/scrolbar.h +++ b/include/wx/gtk1/scrolbar.h @@ -68,6 +68,9 @@ public: void SetObjectLength( int objectLength ); void SetViewLength( int viewLength ); + static wxVisualAttributes + GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); + // implementation // -------------- diff --git a/include/wx/gtk1/slider.h b/include/wx/gtk1/slider.h index 945c726ede..bd4af3fcad 100644 --- a/include/wx/gtk1/slider.h +++ b/include/wx/gtk1/slider.h @@ -60,6 +60,9 @@ public: virtual void SetThumbLength(int lenPixels); virtual int GetThumbLength() const; + static wxVisualAttributes + GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); + // implementation bool IsOwnGtkWindow( GdkWindow *window ); void ApplyWidgetStyle(); diff --git a/include/wx/gtk1/spinbutt.h b/include/wx/gtk1/spinbutt.h index ce80a907e5..dfe3c40c05 100644 --- a/include/wx/gtk1/spinbutt.h +++ b/include/wx/gtk1/spinbutt.h @@ -46,6 +46,9 @@ public: virtual int GetMin() const; virtual int GetMax() const; + static wxVisualAttributes + GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); + // implementation void OnSize( wxSizeEvent &event ); diff --git a/include/wx/gtk1/spinctrl.h b/include/wx/gtk1/spinctrl.h index f39e5184e6..425f31f335 100644 --- a/include/wx/gtk1/spinctrl.h +++ b/include/wx/gtk1/spinctrl.h @@ -59,6 +59,9 @@ public: virtual int GetMin() const; virtual int GetMax() const; + static wxVisualAttributes + GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); + // implementation void OnChar( wxKeyEvent &event ); @@ -73,6 +76,10 @@ public: protected: virtual wxSize DoGetBestSize() const; + // Widgets that use the style->base colour for the BG colour should + // override this and return true. + virtual bool UseGTKStyleBase() const { return true; } + private: DECLARE_DYNAMIC_CLASS(wxSpinCtrl) DECLARE_EVENT_TABLE() diff --git a/include/wx/gtk1/statbmp.h b/include/wx/gtk1/statbmp.h index 642e708448..00677618de 100644 --- a/include/wx/gtk1/statbmp.h +++ b/include/wx/gtk1/statbmp.h @@ -52,6 +52,9 @@ public: return (const wxIcon &)m_bitmap; } + static wxVisualAttributes + GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); + private: // creates the new pixmap widget void CreatePixmapWidget(); diff --git a/include/wx/gtk1/statbox.h b/include/wx/gtk1/statbox.h index fa4d65228a..f0f1b2ff0e 100644 --- a/include/wx/gtk1/statbox.h +++ b/include/wx/gtk1/statbox.h @@ -40,6 +40,9 @@ public: virtual void SetLabel( const wxString &label ); + static wxVisualAttributes + GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); + // implementation virtual void ApplyWidgetStyle(); diff --git a/include/wx/gtk1/statline.h b/include/wx/gtk1/statline.h index 2324b01204..803ae2018a 100644 --- a/include/wx/gtk1/statline.h +++ b/include/wx/gtk1/statline.h @@ -45,6 +45,10 @@ public: bool Create( wxWindow *parent, wxWindowID id, const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize, long style = wxLI_HORIZONTAL, const wxString &name = wxStaticTextNameStr ); + + static wxVisualAttributes + GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); + }; #endif diff --git a/include/wx/gtk1/stattext.h b/include/wx/gtk1/stattext.h index ca98ba9015..eb9ee2a86e 100644 --- a/include/wx/gtk1/stattext.h +++ b/include/wx/gtk1/stattext.h @@ -59,6 +59,9 @@ public: bool SetFont( const wxFont &font ); bool SetForegroundColour( const wxColour& colour ); + + static wxVisualAttributes + GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); // implementation // -------------- diff --git a/include/wx/gtk1/tbargtk.h b/include/wx/gtk1/tbargtk.h index c3c585be05..340d70d665 100644 --- a/include/wx/gtk1/tbargtk.h +++ b/include/wx/gtk1/tbargtk.h @@ -56,6 +56,9 @@ public: virtual void SetWindowStyleFlag( long style ); + static wxVisualAttributes + GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); + // implementation from now on // -------------------------- diff --git a/include/wx/gtk1/textctrl.h b/include/wx/gtk1/textctrl.h index 88ebbb41af..7ca89491e6 100644 --- a/include/wx/gtk1/textctrl.h +++ b/include/wx/gtk1/textctrl.h @@ -162,6 +162,9 @@ public: // should we ignore the changed signal? always resets the flag bool IgnoreTextUpdate(); + static wxVisualAttributes + GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); + protected: virtual wxSize DoGetBestSize() const; @@ -175,6 +178,10 @@ protected: // scroll position changed bool DoScroll(GtkAdjustment *adj, int diff); + // Widgets that use the style->base colour for the BG colour should + // override this and return true. + virtual bool UseGTKStyleBase() const { return true; } + private: // change the font for everything in this control void ChangeFontGlobally(); diff --git a/include/wx/gtk1/tglbtn.h b/include/wx/gtk1/tglbtn.h index 9d66c44797..7da1777c18 100644 --- a/include/wx/gtk1/tglbtn.h +++ b/include/wx/gtk1/tglbtn.h @@ -66,7 +66,9 @@ public: void SetLabel(const wxBitmap& label); bool Enable(bool enable = TRUE); - + static wxVisualAttributes + GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); + // implementation bool m_blockEvent; wxBitmap m_bitmap; @@ -81,6 +83,7 @@ public: private: DECLARE_DYNAMIC_CLASS(wxToggleBitmapButton) }; + //----------------------------------------------------------------------------- // wxToggleButton //----------------------------------------------------------------------------- @@ -119,6 +122,8 @@ public: void SetLabel(const wxString& label); bool Enable(bool enable = TRUE); + static wxVisualAttributes + GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); // implementation bool m_blockEvent; diff --git a/src/gtk/button.cpp b/src/gtk/button.cpp index 1fc794b763..4638f0a6b1 100644 --- a/src/gtk/button.cpp +++ b/src/gtk/button.cpp @@ -232,5 +232,12 @@ wxSize wxButton::DoGetBestSize() const return ret; } +// static +wxVisualAttributes +wxButton::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) +{ + return GetDefaultAttributesFromGTKWidget(gtk_button_new); +} + #endif // wxUSE_BUTTON diff --git a/src/gtk/checkbox.cpp b/src/gtk/checkbox.cpp index 33437d0b08..e7fe520d4d 100644 --- a/src/gtk/checkbox.cpp +++ b/src/gtk/checkbox.cpp @@ -216,4 +216,11 @@ wxSize wxCheckBox::DoGetBestSize() const return wxControl::DoGetBestSize(); } +// static +wxVisualAttributes +wxCheckBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) +{ + return GetDefaultAttributesFromGTKWidget(gtk_check_button_new); +} + #endif diff --git a/src/gtk/choice.cpp b/src/gtk/choice.cpp index 9c63f8502f..384f8b5d00 100644 --- a/src/gtk/choice.cpp +++ b/src/gtk/choice.cpp @@ -574,6 +574,13 @@ bool wxChoice::IsOwnGtkWindow( GdkWindow *window ) #endif } +// static +wxVisualAttributes +wxChoice::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) +{ + return GetDefaultAttributesFromGTKWidget(gtk_option_menu_new); +} + #endif // wxUSE_CHOICE diff --git a/src/gtk/combobox.cpp b/src/gtk/combobox.cpp index 2972a0a998..f7950f67bf 100644 --- a/src/gtk/combobox.cpp +++ b/src/gtk/combobox.cpp @@ -779,4 +779,11 @@ wxSize wxComboBox::DoGetBestSize() const return ret; } +// static +wxVisualAttributes +wxComboBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) +{ + return GetDefaultAttributesFromGTKWidget(gtk_combo_new, true); +} + #endif diff --git a/src/gtk/control.cpp b/src/gtk/control.cpp index 8e3e23ee57..dfbfe4b9c0 100644 --- a/src/gtk/control.cpp +++ b/src/gtk/control.cpp @@ -19,6 +19,8 @@ #if wxUSE_CONTROLS #include "wx/control.h" +#include "wx/fontutil.h" +#include "wx/settings.h" #include @@ -140,5 +142,123 @@ wxString wxControl::PrepareLabelMnemonics( const wxString &label ) const } #endif + +wxVisualAttributes wxControl::GetDefaultAttributes() const +{ + return GetDefaultAttributesFromGTKWidget(m_widget, + UseGTKStyleBase()); +} + + +#define SHIFT (8*(sizeof(short int)-sizeof(char))) + +// static +wxVisualAttributes +wxControl::GetDefaultAttributesFromGTKWidget(GtkWidget* widget, + bool useBase, + int state) +{ + GtkStyle* style; + wxVisualAttributes attr; + + style = gtk_rc_get_style(widget); + if (!style) + style = gtk_widget_get_default_style(); + + if (!style) + { + return wxWindow::GetClassDefaultAttributes(wxWINDOW_VARIANT_NORMAL); + } + + if (state == -1) + state = GTK_STATE_NORMAL; + + // get the style's colours + attr.colFg = wxColour(style->fg[state].red >> SHIFT, + style->fg[state].green >> SHIFT, + style->fg[state].blue >> SHIFT); + if (useBase) + attr.colBg = wxColour(style->base[state].red >> SHIFT, + style->base[state].green >> SHIFT, + style->base[state].blue >> SHIFT); + else + attr.colBg = wxColour(style->bg[state].red >> SHIFT, + style->bg[state].green >> SHIFT, + style->bg[state].blue >> SHIFT); + + // get the style's font +#ifdef __WXGTK20__ + if ( !style->font_desc ) + style = gtk_widget_get_default_style(); + if ( style && style->font_desc ) + { + wxNativeFontInfo info; + info.description = style->font_desc; + attr.font = wxFont(info); + } + else + { + GtkSettings *settings = gtk_settings_get_default(); + gchar *font_name = NULL; + g_object_get ( settings, + "gtk-font-name", + &font_name, + NULL); + if (!font_name) + attr.font = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT ); + else + attr.font = wxFont(wxString::FromAscii(font_name)); + g_free (font_name); + } +#else + // TODO: isn't there a way to get a standard gtk 1.2 font? + attr.font = wxFont( 12, wxSWISS, wxNORMAL, wxNORMAL ); +#endif + + return attr; +} + + +//static +wxVisualAttributes +wxControl::GetDefaultAttributesFromGTKWidget(GtkWidget* (*widget_new)(void), + bool useBase, + int state) +{ + wxVisualAttributes attr; + GtkWidget* widget = widget_new(); + attr = GetDefaultAttributesFromGTKWidget(widget, useBase, state); + gtk_widget_destroy(widget); + return attr; +} + +//static +wxVisualAttributes +wxControl::GetDefaultAttributesFromGTKWidget(GtkWidget* (*widget_new)(const gchar*), + bool useBase, + int state) +{ + wxVisualAttributes attr; + GtkWidget* widget = widget_new(""); + attr = GetDefaultAttributesFromGTKWidget(widget, useBase, state); + gtk_widget_destroy(widget); + return attr; +} + + +//static +wxVisualAttributes +wxControl::GetDefaultAttributesFromGTKWidget(GtkWidget* (*widget_new)(GtkAdjustment*), + bool useBase, + int state) +{ + wxVisualAttributes attr; + GtkWidget* widget = widget_new(NULL); + attr = GetDefaultAttributesFromGTKWidget(widget, useBase, state); + gtk_widget_destroy(widget); + return attr; +} + + #endif // wxUSE_CONTROLS diff --git a/src/gtk/gauge.cpp b/src/gtk/gauge.cpp index 54360ce314..b6cd78c4c5 100644 --- a/src/gtk/gauge.cpp +++ b/src/gtk/gauge.cpp @@ -112,5 +112,22 @@ void wxGauge::ApplyWidgetStyle() gtk_widget_set_style( m_widget, m_widgetStyle ); } +wxVisualAttributes wxGauge::GetDefaultAttributes() const +{ + // Visible gauge colours use a different colour state + return GetDefaultAttributesFromGTKWidget(m_widget, + UseGTKStyleBase(), + GTK_STATE_ACTIVE); + +} + +// static +wxVisualAttributes +wxGauge::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) +{ + return GetDefaultAttributesFromGTKWidget(gtk_progress_bar_new, + false, GTK_STATE_ACTIVE); +} + #endif // wxUSE_GAUGE diff --git a/src/gtk/listbox.cpp b/src/gtk/listbox.cpp index 3436dae156..9f06846793 100644 --- a/src/gtk/listbox.cpp +++ b/src/gtk/listbox.cpp @@ -1087,5 +1087,13 @@ void wxListBox::FixUpMouseEvent(GtkWidget *widget, wxCoord& x, wxCoord& y) y += widget->allocation.y; } + +// static +wxVisualAttributes +wxListBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) +{ + return GetDefaultAttributesFromGTKWidget(gtk_list_new, true); +} + #endif // wxUSE_LISTBOX diff --git a/src/gtk/notebook.cpp b/src/gtk/notebook.cpp index 25edf2c110..ded15fb845 100644 --- a/src/gtk/notebook.cpp +++ b/src/gtk/notebook.cpp @@ -866,6 +866,13 @@ bool wxNotebook::SetFont(const wxFont& font) return rc; } +// static +wxVisualAttributes +wxNotebook::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) +{ + return GetDefaultAttributesFromGTKWidget(gtk_notebook_new); +} + //----------------------------------------------------------------------------- // wxNotebookEvent //----------------------------------------------------------------------------- diff --git a/src/gtk/radiobox.cpp b/src/gtk/radiobox.cpp index 37c9f529f2..3538f3c037 100644 --- a/src/gtk/radiobox.cpp +++ b/src/gtk/radiobox.cpp @@ -752,5 +752,16 @@ void wxRadioBox::OnInternalIdle() } } +// static +wxVisualAttributes +wxRadioBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) +{ + wxVisualAttributes attr; + GtkWidget* widget = gtk_radio_button_new_with_label(NULL, ""); + attr = GetDefaultAttributesFromGTKWidget(widget); + gtk_widget_destroy(widget); + return attr; +} + #endif // wxUSE_RADIOBOX diff --git a/src/gtk/radiobut.cpp b/src/gtk/radiobut.cpp index 1fd39b77fb..c03a82e438 100644 --- a/src/gtk/radiobut.cpp +++ b/src/gtk/radiobut.cpp @@ -233,4 +233,16 @@ wxSize wxRadioButton::DoGetBestSize() const return wxControl::DoGetBestSize(); } +// static +wxVisualAttributes +wxRadioButton::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) +{ + wxVisualAttributes attr; + GtkWidget* widget = gtk_radio_button_new_with_label(NULL, ""); + attr = GetDefaultAttributesFromGTKWidget(widget); + gtk_widget_destroy(widget); + return attr; +} + + #endif diff --git a/src/gtk/scrolbar.cpp b/src/gtk/scrolbar.cpp index 4aa408af1f..6dcd71ec52 100644 --- a/src/gtk/scrolbar.cpp +++ b/src/gtk/scrolbar.cpp @@ -336,4 +336,11 @@ wxSize wxScrollBar::DoGetBestSize() const return wxControl::DoGetBestSize(); } +// static +wxVisualAttributes +wxScrollBar::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) +{ + return GetDefaultAttributesFromGTKWidget(gtk_vscrollbar_new); +} + #endif diff --git a/src/gtk/slider.cpp b/src/gtk/slider.cpp index 2dcc57d58e..e7079c5c10 100644 --- a/src/gtk/slider.cpp +++ b/src/gtk/slider.cpp @@ -286,4 +286,11 @@ void wxSlider::GtkEnableEvents() (gpointer) this ); } +// static +wxVisualAttributes +wxSlider::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) +{ + return GetDefaultAttributesFromGTKWidget(gtk_vscale_new); +} + #endif diff --git a/src/gtk/spinbutt.cpp b/src/gtk/spinbutt.cpp index f0db6cb58b..423947a1d3 100644 --- a/src/gtk/spinbutt.cpp +++ b/src/gtk/spinbutt.cpp @@ -236,4 +236,13 @@ wxSize wxSpinButton::DoGetBestSize() const return wxSize(15, 26); } +// static +wxVisualAttributes +wxSpinButton::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) +{ + // TODO: overload to accept functions like gtk_spin_button_new? + // Until then use a similar type + return GetDefaultAttributesFromGTKWidget(gtk_button_new); +} + #endif diff --git a/src/gtk/spinctrl.cpp b/src/gtk/spinctrl.cpp index e5d32a1f85..45cc31f6b8 100644 --- a/src/gtk/spinctrl.cpp +++ b/src/gtk/spinctrl.cpp @@ -310,5 +310,14 @@ wxSize wxSpinCtrl::DoGetBestSize() const return wxSize(95, ret.y); } +// static +wxVisualAttributes +wxSpinCtrl::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) +{ + // TODO: overload to accept functions like gtk_spin_button_new? + // Until then use a similar type + return GetDefaultAttributesFromGTKWidget(gtk_entry_new, true); +} + #endif // wxUSE_SPINCTRL diff --git a/src/gtk/statbmp.cpp b/src/gtk/statbmp.cpp index 9d206950ea..48a8dafe73 100644 --- a/src/gtk/statbmp.cpp +++ b/src/gtk/statbmp.cpp @@ -117,5 +117,13 @@ void wxStaticBitmap::SetBitmap( const wxBitmap &bitmap ) } } +// static +wxVisualAttributes +wxStaticBitmap::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) +{ + // TODO: overload to allow using gtk_pixmap_new? + return GetDefaultAttributesFromGTKWidget(gtk_label_new); +} + #endif // wxUSE_STATBMP diff --git a/src/gtk/statbox.cpp b/src/gtk/statbox.cpp index 3bf811a25b..879e2bc579 100644 --- a/src/gtk/statbox.cpp +++ b/src/gtk/statbox.cpp @@ -97,4 +97,11 @@ void wxStaticBox::ApplyWidgetStyle() gtk_widget_set_style( m_widget, m_widgetStyle ); } +// static +wxVisualAttributes +wxStaticBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) +{ + return GetDefaultAttributesFromGTKWidget(gtk_frame_new); +} + #endif // wxUSE_STATBOX diff --git a/src/gtk/statline.cpp b/src/gtk/statline.cpp index d10067f6ac..3f95edd803 100644 --- a/src/gtk/statline.cpp +++ b/src/gtk/statline.cpp @@ -79,4 +79,11 @@ bool wxStaticLine::Create( wxWindow *parent, wxWindowID id, return TRUE; } +// static +wxVisualAttributes +wxStaticLine::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) +{ + return GetDefaultAttributesFromGTKWidget(gtk_vseparator_new); +} + #endif diff --git a/src/gtk/stattext.cpp b/src/gtk/stattext.cpp index 7073bcd6cc..89594853ae 100644 --- a/src/gtk/stattext.cpp +++ b/src/gtk/stattext.cpp @@ -199,4 +199,11 @@ bool wxStaticText::SetForegroundColour(const wxColour& colour) return true; } +// static +wxVisualAttributes +wxStaticText::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) +{ + return GetDefaultAttributesFromGTKWidget(gtk_label_new); +} + #endif // wxUSE_STATTEXT diff --git a/src/gtk/tbargtk.cpp b/src/gtk/tbargtk.cpp index 61804aa048..3360929f68 100644 --- a/src/gtk/tbargtk.cpp +++ b/src/gtk/tbargtk.cpp @@ -703,4 +703,22 @@ void wxToolBar::OnInternalIdle() UpdateWindowUI(wxUPDATE_UI_FROMIDLE); } + +// ---------------------------------------------------------------------------- + +// static +wxVisualAttributes +wxToolBar::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) +{ +#ifdef __WXGTK20__ + return GetDefaultAttributesFromGTKWidget(gtk_toolbar_new); +#else + wxVisualAttributes attr; + GtkWidget* widget = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL, GTK_TOOLBAR_BOTH); + attr = GetDefaultAttributesFromGTKWidget(widget); + gtk_widget_destroy(widget); + return attr; +#endif +} + #endif // wxUSE_TOOLBAR_NATIVE diff --git a/src/gtk/textctrl.cpp b/src/gtk/textctrl.cpp index 815c0c66ac..f37ca3d41e 100644 --- a/src/gtk/textctrl.cpp +++ b/src/gtk/textctrl.cpp @@ -303,7 +303,7 @@ bool wxTextCtrl::Create( wxWindow *parent, gtk_container_add( GTK_CONTAINER(m_widget), m_text ); // Global settings which can be overridden by tags, I guess. - if (HasFlag( wxHSCROLL )) + if (HasFlag( wxHSCROLL ) || HasFlag( wxTE_DONTWRAP )) gtk_text_view_set_wrap_mode( GTK_TEXT_VIEW( m_text ), GTK_WRAP_NONE ); else gtk_text_view_set_wrap_mode( GTK_TEXT_VIEW( m_text ), GTK_WRAP_WORD ); @@ -415,16 +415,16 @@ bool wxTextCtrl::Create( wxWindow *parent, #ifdef __WXGTK20__ else gtk_text_view_set_editable( GTK_TEXT_VIEW( m_text), FALSE); - } #else } else { if (multi_line) gtk_text_set_editable( GTK_TEXT(m_text), 1 ); - } #endif + } + // We want to be notified about text changes. #ifdef __WXGTK20__ if (multi_line) @@ -434,26 +434,21 @@ bool wxTextCtrl::Create( wxWindow *parent, } else #endif + { gtk_signal_connect( GTK_OBJECT(m_text), "changed", GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this); } - // we don't set a valid background colour, because the window - // manager should use a default one - m_backgroundColour = wxColour(); - - wxColour colFg = parent->GetForegroundColour(); - SetForegroundColour( colFg ); - m_cursor = wxCursor( wxCURSOR_IBEAM ); - wxTextAttr attrDef( colFg, m_backgroundColour, parent->GetFont() ); + wxTextAttr attrDef(GetForegroundColour(), GetBackgroundColour(), GetFont()); SetDefaultStyle( attrDef ); return TRUE; } + void wxTextCtrl::CalculateScrollbar() { #ifndef __WXGTK20__ @@ -1522,11 +1517,11 @@ bool wxTextCtrl::SetStyle( long start, long end, const wxTextAttr& style ) void wxTextCtrl::ApplyWidgetStyle() { - if (m_windowStyle & wxTE_MULTILINE) - { - // how ? - } - else +// if (m_windowStyle & wxTE_MULTILINE) +// { +// // how ? +// } +// else { SetWidgetStyle(); gtk_widget_set_style( m_text, m_widgetStyle ); @@ -1724,3 +1719,10 @@ bool wxTextCtrl::ScrollPages(int pages) #endif } + +// static +wxVisualAttributes +wxTextCtrl::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) +{ + return GetDefaultAttributesFromGTKWidget(gtk_entry_new, true); +} diff --git a/src/gtk/tglbtn.cpp b/src/gtk/tglbtn.cpp index 4d57e220cf..d8aac966f6 100644 --- a/src/gtk/tglbtn.cpp +++ b/src/gtk/tglbtn.cpp @@ -207,6 +207,16 @@ wxSize wxToggleBitmapButton::DoGetBestSize() const } return best; } + + +// static +wxVisualAttributes +wxToggleBitmapButton::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) +{ + return GetDefaultAttributesFromGTKWidget(gtk_toggle_button_new); +} + + // ------------------------------------------------------------------------ // wxToggleButton // ------------------------------------------------------------------------ @@ -339,5 +349,12 @@ wxSize wxToggleButton::DoGetBestSize() const return ret; } +// static +wxVisualAttributes +wxToggleButton::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) +{ + return GetDefaultAttributesFromGTKWidget(gtk_toggle_button_new); +} + #endif // wxUSE_TOGGLEBTN diff --git a/src/gtk1/button.cpp b/src/gtk1/button.cpp index 1fc794b763..4638f0a6b1 100644 --- a/src/gtk1/button.cpp +++ b/src/gtk1/button.cpp @@ -232,5 +232,12 @@ wxSize wxButton::DoGetBestSize() const return ret; } +// static +wxVisualAttributes +wxButton::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) +{ + return GetDefaultAttributesFromGTKWidget(gtk_button_new); +} + #endif // wxUSE_BUTTON diff --git a/src/gtk1/checkbox.cpp b/src/gtk1/checkbox.cpp index 33437d0b08..e7fe520d4d 100644 --- a/src/gtk1/checkbox.cpp +++ b/src/gtk1/checkbox.cpp @@ -216,4 +216,11 @@ wxSize wxCheckBox::DoGetBestSize() const return wxControl::DoGetBestSize(); } +// static +wxVisualAttributes +wxCheckBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) +{ + return GetDefaultAttributesFromGTKWidget(gtk_check_button_new); +} + #endif diff --git a/src/gtk1/choice.cpp b/src/gtk1/choice.cpp index 9c63f8502f..384f8b5d00 100644 --- a/src/gtk1/choice.cpp +++ b/src/gtk1/choice.cpp @@ -574,6 +574,13 @@ bool wxChoice::IsOwnGtkWindow( GdkWindow *window ) #endif } +// static +wxVisualAttributes +wxChoice::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) +{ + return GetDefaultAttributesFromGTKWidget(gtk_option_menu_new); +} + #endif // wxUSE_CHOICE diff --git a/src/gtk1/combobox.cpp b/src/gtk1/combobox.cpp index 2972a0a998..f7950f67bf 100644 --- a/src/gtk1/combobox.cpp +++ b/src/gtk1/combobox.cpp @@ -779,4 +779,11 @@ wxSize wxComboBox::DoGetBestSize() const return ret; } +// static +wxVisualAttributes +wxComboBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) +{ + return GetDefaultAttributesFromGTKWidget(gtk_combo_new, true); +} + #endif diff --git a/src/gtk1/control.cpp b/src/gtk1/control.cpp index 8e3e23ee57..dfbfe4b9c0 100644 --- a/src/gtk1/control.cpp +++ b/src/gtk1/control.cpp @@ -19,6 +19,8 @@ #if wxUSE_CONTROLS #include "wx/control.h" +#include "wx/fontutil.h" +#include "wx/settings.h" #include @@ -140,5 +142,123 @@ wxString wxControl::PrepareLabelMnemonics( const wxString &label ) const } #endif + +wxVisualAttributes wxControl::GetDefaultAttributes() const +{ + return GetDefaultAttributesFromGTKWidget(m_widget, + UseGTKStyleBase()); +} + + +#define SHIFT (8*(sizeof(short int)-sizeof(char))) + +// static +wxVisualAttributes +wxControl::GetDefaultAttributesFromGTKWidget(GtkWidget* widget, + bool useBase, + int state) +{ + GtkStyle* style; + wxVisualAttributes attr; + + style = gtk_rc_get_style(widget); + if (!style) + style = gtk_widget_get_default_style(); + + if (!style) + { + return wxWindow::GetClassDefaultAttributes(wxWINDOW_VARIANT_NORMAL); + } + + if (state == -1) + state = GTK_STATE_NORMAL; + + // get the style's colours + attr.colFg = wxColour(style->fg[state].red >> SHIFT, + style->fg[state].green >> SHIFT, + style->fg[state].blue >> SHIFT); + if (useBase) + attr.colBg = wxColour(style->base[state].red >> SHIFT, + style->base[state].green >> SHIFT, + style->base[state].blue >> SHIFT); + else + attr.colBg = wxColour(style->bg[state].red >> SHIFT, + style->bg[state].green >> SHIFT, + style->bg[state].blue >> SHIFT); + + // get the style's font +#ifdef __WXGTK20__ + if ( !style->font_desc ) + style = gtk_widget_get_default_style(); + if ( style && style->font_desc ) + { + wxNativeFontInfo info; + info.description = style->font_desc; + attr.font = wxFont(info); + } + else + { + GtkSettings *settings = gtk_settings_get_default(); + gchar *font_name = NULL; + g_object_get ( settings, + "gtk-font-name", + &font_name, + NULL); + if (!font_name) + attr.font = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT ); + else + attr.font = wxFont(wxString::FromAscii(font_name)); + g_free (font_name); + } +#else + // TODO: isn't there a way to get a standard gtk 1.2 font? + attr.font = wxFont( 12, wxSWISS, wxNORMAL, wxNORMAL ); +#endif + + return attr; +} + + +//static +wxVisualAttributes +wxControl::GetDefaultAttributesFromGTKWidget(GtkWidget* (*widget_new)(void), + bool useBase, + int state) +{ + wxVisualAttributes attr; + GtkWidget* widget = widget_new(); + attr = GetDefaultAttributesFromGTKWidget(widget, useBase, state); + gtk_widget_destroy(widget); + return attr; +} + +//static +wxVisualAttributes +wxControl::GetDefaultAttributesFromGTKWidget(GtkWidget* (*widget_new)(const gchar*), + bool useBase, + int state) +{ + wxVisualAttributes attr; + GtkWidget* widget = widget_new(""); + attr = GetDefaultAttributesFromGTKWidget(widget, useBase, state); + gtk_widget_destroy(widget); + return attr; +} + + +//static +wxVisualAttributes +wxControl::GetDefaultAttributesFromGTKWidget(GtkWidget* (*widget_new)(GtkAdjustment*), + bool useBase, + int state) +{ + wxVisualAttributes attr; + GtkWidget* widget = widget_new(NULL); + attr = GetDefaultAttributesFromGTKWidget(widget, useBase, state); + gtk_widget_destroy(widget); + return attr; +} + + #endif // wxUSE_CONTROLS diff --git a/src/gtk1/gauge.cpp b/src/gtk1/gauge.cpp index 54360ce314..b6cd78c4c5 100644 --- a/src/gtk1/gauge.cpp +++ b/src/gtk1/gauge.cpp @@ -112,5 +112,22 @@ void wxGauge::ApplyWidgetStyle() gtk_widget_set_style( m_widget, m_widgetStyle ); } +wxVisualAttributes wxGauge::GetDefaultAttributes() const +{ + // Visible gauge colours use a different colour state + return GetDefaultAttributesFromGTKWidget(m_widget, + UseGTKStyleBase(), + GTK_STATE_ACTIVE); + +} + +// static +wxVisualAttributes +wxGauge::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) +{ + return GetDefaultAttributesFromGTKWidget(gtk_progress_bar_new, + false, GTK_STATE_ACTIVE); +} + #endif // wxUSE_GAUGE diff --git a/src/gtk1/listbox.cpp b/src/gtk1/listbox.cpp index 3436dae156..9f06846793 100644 --- a/src/gtk1/listbox.cpp +++ b/src/gtk1/listbox.cpp @@ -1087,5 +1087,13 @@ void wxListBox::FixUpMouseEvent(GtkWidget *widget, wxCoord& x, wxCoord& y) y += widget->allocation.y; } + +// static +wxVisualAttributes +wxListBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) +{ + return GetDefaultAttributesFromGTKWidget(gtk_list_new, true); +} + #endif // wxUSE_LISTBOX diff --git a/src/gtk1/notebook.cpp b/src/gtk1/notebook.cpp index 25edf2c110..ded15fb845 100644 --- a/src/gtk1/notebook.cpp +++ b/src/gtk1/notebook.cpp @@ -866,6 +866,13 @@ bool wxNotebook::SetFont(const wxFont& font) return rc; } +// static +wxVisualAttributes +wxNotebook::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) +{ + return GetDefaultAttributesFromGTKWidget(gtk_notebook_new); +} + //----------------------------------------------------------------------------- // wxNotebookEvent //----------------------------------------------------------------------------- diff --git a/src/gtk1/radiobox.cpp b/src/gtk1/radiobox.cpp index 37c9f529f2..3538f3c037 100644 --- a/src/gtk1/radiobox.cpp +++ b/src/gtk1/radiobox.cpp @@ -752,5 +752,16 @@ void wxRadioBox::OnInternalIdle() } } +// static +wxVisualAttributes +wxRadioBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) +{ + wxVisualAttributes attr; + GtkWidget* widget = gtk_radio_button_new_with_label(NULL, ""); + attr = GetDefaultAttributesFromGTKWidget(widget); + gtk_widget_destroy(widget); + return attr; +} + #endif // wxUSE_RADIOBOX diff --git a/src/gtk1/radiobut.cpp b/src/gtk1/radiobut.cpp index 1fd39b77fb..c03a82e438 100644 --- a/src/gtk1/radiobut.cpp +++ b/src/gtk1/radiobut.cpp @@ -233,4 +233,16 @@ wxSize wxRadioButton::DoGetBestSize() const return wxControl::DoGetBestSize(); } +// static +wxVisualAttributes +wxRadioButton::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) +{ + wxVisualAttributes attr; + GtkWidget* widget = gtk_radio_button_new_with_label(NULL, ""); + attr = GetDefaultAttributesFromGTKWidget(widget); + gtk_widget_destroy(widget); + return attr; +} + + #endif diff --git a/src/gtk1/scrolbar.cpp b/src/gtk1/scrolbar.cpp index 4aa408af1f..6dcd71ec52 100644 --- a/src/gtk1/scrolbar.cpp +++ b/src/gtk1/scrolbar.cpp @@ -336,4 +336,11 @@ wxSize wxScrollBar::DoGetBestSize() const return wxControl::DoGetBestSize(); } +// static +wxVisualAttributes +wxScrollBar::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) +{ + return GetDefaultAttributesFromGTKWidget(gtk_vscrollbar_new); +} + #endif diff --git a/src/gtk1/slider.cpp b/src/gtk1/slider.cpp index 2dcc57d58e..e7079c5c10 100644 --- a/src/gtk1/slider.cpp +++ b/src/gtk1/slider.cpp @@ -286,4 +286,11 @@ void wxSlider::GtkEnableEvents() (gpointer) this ); } +// static +wxVisualAttributes +wxSlider::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) +{ + return GetDefaultAttributesFromGTKWidget(gtk_vscale_new); +} + #endif diff --git a/src/gtk1/spinbutt.cpp b/src/gtk1/spinbutt.cpp index f0db6cb58b..423947a1d3 100644 --- a/src/gtk1/spinbutt.cpp +++ b/src/gtk1/spinbutt.cpp @@ -236,4 +236,13 @@ wxSize wxSpinButton::DoGetBestSize() const return wxSize(15, 26); } +// static +wxVisualAttributes +wxSpinButton::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) +{ + // TODO: overload to accept functions like gtk_spin_button_new? + // Until then use a similar type + return GetDefaultAttributesFromGTKWidget(gtk_button_new); +} + #endif diff --git a/src/gtk1/spinctrl.cpp b/src/gtk1/spinctrl.cpp index e5d32a1f85..45cc31f6b8 100644 --- a/src/gtk1/spinctrl.cpp +++ b/src/gtk1/spinctrl.cpp @@ -310,5 +310,14 @@ wxSize wxSpinCtrl::DoGetBestSize() const return wxSize(95, ret.y); } +// static +wxVisualAttributes +wxSpinCtrl::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) +{ + // TODO: overload to accept functions like gtk_spin_button_new? + // Until then use a similar type + return GetDefaultAttributesFromGTKWidget(gtk_entry_new, true); +} + #endif // wxUSE_SPINCTRL diff --git a/src/gtk1/statbmp.cpp b/src/gtk1/statbmp.cpp index 9d206950ea..48a8dafe73 100644 --- a/src/gtk1/statbmp.cpp +++ b/src/gtk1/statbmp.cpp @@ -117,5 +117,13 @@ void wxStaticBitmap::SetBitmap( const wxBitmap &bitmap ) } } +// static +wxVisualAttributes +wxStaticBitmap::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) +{ + // TODO: overload to allow using gtk_pixmap_new? + return GetDefaultAttributesFromGTKWidget(gtk_label_new); +} + #endif // wxUSE_STATBMP diff --git a/src/gtk1/statbox.cpp b/src/gtk1/statbox.cpp index 3bf811a25b..879e2bc579 100644 --- a/src/gtk1/statbox.cpp +++ b/src/gtk1/statbox.cpp @@ -97,4 +97,11 @@ void wxStaticBox::ApplyWidgetStyle() gtk_widget_set_style( m_widget, m_widgetStyle ); } +// static +wxVisualAttributes +wxStaticBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) +{ + return GetDefaultAttributesFromGTKWidget(gtk_frame_new); +} + #endif // wxUSE_STATBOX diff --git a/src/gtk1/statline.cpp b/src/gtk1/statline.cpp index d10067f6ac..3f95edd803 100644 --- a/src/gtk1/statline.cpp +++ b/src/gtk1/statline.cpp @@ -79,4 +79,11 @@ bool wxStaticLine::Create( wxWindow *parent, wxWindowID id, return TRUE; } +// static +wxVisualAttributes +wxStaticLine::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) +{ + return GetDefaultAttributesFromGTKWidget(gtk_vseparator_new); +} + #endif diff --git a/src/gtk1/stattext.cpp b/src/gtk1/stattext.cpp index 7073bcd6cc..89594853ae 100644 --- a/src/gtk1/stattext.cpp +++ b/src/gtk1/stattext.cpp @@ -199,4 +199,11 @@ bool wxStaticText::SetForegroundColour(const wxColour& colour) return true; } +// static +wxVisualAttributes +wxStaticText::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) +{ + return GetDefaultAttributesFromGTKWidget(gtk_label_new); +} + #endif // wxUSE_STATTEXT diff --git a/src/gtk1/tbargtk.cpp b/src/gtk1/tbargtk.cpp index 61804aa048..3360929f68 100644 --- a/src/gtk1/tbargtk.cpp +++ b/src/gtk1/tbargtk.cpp @@ -703,4 +703,22 @@ void wxToolBar::OnInternalIdle() UpdateWindowUI(wxUPDATE_UI_FROMIDLE); } + +// ---------------------------------------------------------------------------- + +// static +wxVisualAttributes +wxToolBar::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) +{ +#ifdef __WXGTK20__ + return GetDefaultAttributesFromGTKWidget(gtk_toolbar_new); +#else + wxVisualAttributes attr; + GtkWidget* widget = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL, GTK_TOOLBAR_BOTH); + attr = GetDefaultAttributesFromGTKWidget(widget); + gtk_widget_destroy(widget); + return attr; +#endif +} + #endif // wxUSE_TOOLBAR_NATIVE diff --git a/src/gtk1/textctrl.cpp b/src/gtk1/textctrl.cpp index 815c0c66ac..f37ca3d41e 100644 --- a/src/gtk1/textctrl.cpp +++ b/src/gtk1/textctrl.cpp @@ -303,7 +303,7 @@ bool wxTextCtrl::Create( wxWindow *parent, gtk_container_add( GTK_CONTAINER(m_widget), m_text ); // Global settings which can be overridden by tags, I guess. - if (HasFlag( wxHSCROLL )) + if (HasFlag( wxHSCROLL ) || HasFlag( wxTE_DONTWRAP )) gtk_text_view_set_wrap_mode( GTK_TEXT_VIEW( m_text ), GTK_WRAP_NONE ); else gtk_text_view_set_wrap_mode( GTK_TEXT_VIEW( m_text ), GTK_WRAP_WORD ); @@ -415,16 +415,16 @@ bool wxTextCtrl::Create( wxWindow *parent, #ifdef __WXGTK20__ else gtk_text_view_set_editable( GTK_TEXT_VIEW( m_text), FALSE); - } #else } else { if (multi_line) gtk_text_set_editable( GTK_TEXT(m_text), 1 ); - } #endif + } + // We want to be notified about text changes. #ifdef __WXGTK20__ if (multi_line) @@ -434,26 +434,21 @@ bool wxTextCtrl::Create( wxWindow *parent, } else #endif + { gtk_signal_connect( GTK_OBJECT(m_text), "changed", GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this); } - // we don't set a valid background colour, because the window - // manager should use a default one - m_backgroundColour = wxColour(); - - wxColour colFg = parent->GetForegroundColour(); - SetForegroundColour( colFg ); - m_cursor = wxCursor( wxCURSOR_IBEAM ); - wxTextAttr attrDef( colFg, m_backgroundColour, parent->GetFont() ); + wxTextAttr attrDef(GetForegroundColour(), GetBackgroundColour(), GetFont()); SetDefaultStyle( attrDef ); return TRUE; } + void wxTextCtrl::CalculateScrollbar() { #ifndef __WXGTK20__ @@ -1522,11 +1517,11 @@ bool wxTextCtrl::SetStyle( long start, long end, const wxTextAttr& style ) void wxTextCtrl::ApplyWidgetStyle() { - if (m_windowStyle & wxTE_MULTILINE) - { - // how ? - } - else +// if (m_windowStyle & wxTE_MULTILINE) +// { +// // how ? +// } +// else { SetWidgetStyle(); gtk_widget_set_style( m_text, m_widgetStyle ); @@ -1724,3 +1719,10 @@ bool wxTextCtrl::ScrollPages(int pages) #endif } + +// static +wxVisualAttributes +wxTextCtrl::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) +{ + return GetDefaultAttributesFromGTKWidget(gtk_entry_new, true); +} diff --git a/src/gtk1/tglbtn.cpp b/src/gtk1/tglbtn.cpp index 4d57e220cf..d8aac966f6 100644 --- a/src/gtk1/tglbtn.cpp +++ b/src/gtk1/tglbtn.cpp @@ -207,6 +207,16 @@ wxSize wxToggleBitmapButton::DoGetBestSize() const } return best; } + + +// static +wxVisualAttributes +wxToggleBitmapButton::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) +{ + return GetDefaultAttributesFromGTKWidget(gtk_toggle_button_new); +} + + // ------------------------------------------------------------------------ // wxToggleButton // ------------------------------------------------------------------------ @@ -339,5 +349,12 @@ wxSize wxToggleButton::DoGetBestSize() const return ret; } +// static +wxVisualAttributes +wxToggleButton::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) +{ + return GetDefaultAttributesFromGTKWidget(gtk_toggle_button_new); +} + #endif // wxUSE_TOGGLEBTN -- 2.45.2