From dc797d8e1b4ef10be4f5c9cd73151406f459706d Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Tue, 13 Nov 2007 12:10:34 +0000 Subject: [PATCH] More border rationalisation. GetDefaultBorder is now mostly defined in base class files. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@49893 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/aui/auibook.h | 4 ++++ include/wx/bookctrl.h | 3 +++ include/wx/button.h | 3 +++ include/wx/checkbox.h | 3 +++ include/wx/control.h | 3 +++ include/wx/gauge.h | 2 ++ include/wx/hyperlink.h | 2 ++ include/wx/mac/carbon/tglbtn.h | 1 + include/wx/motif/tglbtn.h | 4 ++++ include/wx/msw/choice.h | 3 +++ include/wx/msw/datectrl.h | 1 + include/wx/msw/slider95.h | 3 --- include/wx/msw/statbmp.h | 1 - include/wx/msw/statbox.h | 3 --- include/wx/msw/stattext.h | 1 - include/wx/msw/tglbtn.h | 2 +- include/wx/msw/window.h | 4 ++++ include/wx/slider.h | 3 +++ include/wx/statbmp.h | 3 +++ include/wx/statbox.h | 3 +++ include/wx/statline.h | 3 +++ include/wx/stattext.h | 3 +++ include/wx/univ/tglbtn.h | 2 ++ include/wx/window.h | 5 ++-- src/common/ctrlcmn.cpp | 6 +++++ src/msw/control.cpp | 4 +++- src/msw/statbmp.cpp | 5 ---- src/msw/statbox.cpp | 5 ---- src/msw/stattext.cpp | 11 +++------ src/msw/tglbtn.cpp | 5 ---- src/msw/window.cpp | 42 ++++++++++++++++++++++++++++++---- 31 files changed, 104 insertions(+), 39 deletions(-) diff --git a/include/wx/aui/auibook.h b/include/wx/aui/auibook.h index 618e42af7c..51632fbd7e 100644 --- a/include/wx/aui/auibook.h +++ b/include/wx/aui/auibook.h @@ -455,6 +455,8 @@ public: bool IsDragging() const { return m_is_dragging; } protected: + // choose the default border for this window + virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; } void OnPaint(wxPaintEvent& evt); void OnEraseBackground(wxEraseEvent& evt); @@ -580,6 +582,8 @@ public: // virtual bool AcceptsFocus() const { return false; } protected: + // choose the default border for this window + virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; } // these can be overridden virtual void UpdateTabCtrlHeight(); diff --git a/include/wx/bookctrl.h b/include/wx/bookctrl.h index 15dd227715..60ceefc855 100644 --- a/include/wx/bookctrl.h +++ b/include/wx/bookctrl.h @@ -243,6 +243,9 @@ protected: SetSelection_SendEvent = 1 }; + // choose the default border for this window + virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; } + // set the selection to the given page, sending the events (which can // possibly prevent the page change from taking place) if SendEvent flag is // included diff --git a/include/wx/button.h b/include/wx/button.h index bf32419366..58f8ab55fe 100644 --- a/include/wx/button.h +++ b/include/wx/button.h @@ -78,6 +78,9 @@ public: static wxSize GetDefaultSize(); protected: + // choose the default border for this window + virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; } + DECLARE_NO_COPY_CLASS(wxButtonBase) }; diff --git a/include/wx/checkbox.h b/include/wx/checkbox.h index 47ba77a0e2..8b0348fe37 100644 --- a/include/wx/checkbox.h +++ b/include/wx/checkbox.h @@ -118,6 +118,9 @@ public: } protected: + // choose the default border for this window + virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; } + virtual void DoSet3StateValue(wxCheckBoxState WXUNUSED(state)) { wxFAIL; } virtual wxCheckBoxState DoGet3StateValue() const diff --git a/include/wx/control.h b/include/wx/control.h index fcc3b923f8..08e9aeceea 100644 --- a/include/wx/control.h +++ b/include/wx/control.h @@ -92,6 +92,9 @@ public: virtual void DoUpdateWindowUI(wxUpdateUIEvent& event); protected: + // choose the default border for this window + virtual wxBorder GetDefaultBorder() const; + // creates the control (calls wxWindowBase::CreateBase inside) and adds it // to the list of parents children bool CreateControl(wxWindowBase *parent, diff --git a/include/wx/gauge.h b/include/wx/gauge.h index 2156e05a87..11605c9d1a 100644 --- a/include/wx/gauge.h +++ b/include/wx/gauge.h @@ -88,6 +88,8 @@ public: virtual bool AcceptsFocus() const { return false; } protected: + virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; } + // the max position int m_rangeMax; diff --git a/include/wx/hyperlink.h b/include/wx/hyperlink.h index 9e0f90ddc1..264b771282 100644 --- a/include/wx/hyperlink.h +++ b/include/wx/hyperlink.h @@ -69,6 +69,8 @@ public: // wxWindow::Get/SetFont, wxWindow::Get/SetCursor are important ! protected: + virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; } + // checks for validity some of the ctor/Create() function parameters void CheckParams(const wxString& label, const wxString& url, long style); diff --git a/include/wx/mac/carbon/tglbtn.h b/include/wx/mac/carbon/tglbtn.h index 7031d4a6a9..b27bdeb59c 100644 --- a/include/wx/mac/carbon/tglbtn.h +++ b/include/wx/mac/carbon/tglbtn.h @@ -49,6 +49,7 @@ public: virtual void Command(wxCommandEvent& event); protected: + virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; } virtual wxSize DoGetBestSize() const; private: diff --git a/include/wx/motif/tglbtn.h b/include/wx/motif/tglbtn.h index d6cdadd009..0fd827b953 100644 --- a/include/wx/motif/tglbtn.h +++ b/include/wx/motif/tglbtn.h @@ -37,6 +37,10 @@ public: long style = 0, const wxValidator& val = wxDefaultValidator, const wxString &name = wxCheckBoxNameStr ); + +protected: + virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; } + private: DECLARE_DYNAMIC_CLASS(wxToggleButton) diff --git a/include/wx/msw/choice.h b/include/wx/msw/choice.h index 20d8edb5fd..402948e08a 100644 --- a/include/wx/msw/choice.h +++ b/include/wx/msw/choice.h @@ -86,6 +86,9 @@ public: virtual bool CanApplyThemeBorder() const { return false; } protected: + // choose the default border for this window + virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; } + // common part of all ctors void Init() { m_lastAcceptedSelection = wxID_NONE; } diff --git a/include/wx/msw/datectrl.h b/include/wx/msw/datectrl.h index c5d43d93a2..b92a88ea38 100644 --- a/include/wx/msw/datectrl.h +++ b/include/wx/msw/datectrl.h @@ -61,6 +61,7 @@ public: virtual bool CanApplyThemeBorder() const { return false; } protected: + virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; } virtual wxSize DoGetBestSize() const; // the date currently shown by the control, may be invalid diff --git a/include/wx/msw/slider95.h b/include/wx/msw/slider95.h index 5702f1824a..08cf96528a 100644 --- a/include/wx/msw/slider95.h +++ b/include/wx/msw/slider95.h @@ -116,9 +116,6 @@ protected: virtual void DoMoveWindow(int x, int y, int width, int height); virtual wxSize DoGetBestSize() const; - virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; } - - // the labels windows, if any wxSubwindows *m_labels; diff --git a/include/wx/msw/statbmp.h b/include/wx/msw/statbmp.h index ba494939a7..ba61d269ef 100644 --- a/include/wx/msw/statbmp.h +++ b/include/wx/msw/statbmp.h @@ -58,7 +58,6 @@ public: virtual bool CanApplyThemeBorder() const { return false; } protected: - virtual wxBorder GetDefaultBorder() const; virtual wxSize DoGetBestSize() const; // ctor/dtor helpers diff --git a/include/wx/msw/statbox.h b/include/wx/msw/statbox.h index 8d48ba933e..e51ede32cf 100644 --- a/include/wx/msw/statbox.h +++ b/include/wx/msw/statbox.h @@ -46,9 +46,6 @@ public: protected: virtual wxSize DoGetBestSize() const; - // choose the default border for this window - virtual wxBorder GetDefaultBorder() const; - #ifndef __WXWINCE__ public: virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam); diff --git a/include/wx/msw/stattext.h b/include/wx/msw/stattext.h index 1c05fbf758..b9c4b6ad21 100644 --- a/include/wx/msw/stattext.h +++ b/include/wx/msw/stattext.h @@ -44,7 +44,6 @@ public: protected: // implement/override some base class virtuals - virtual wxBorder GetDefaultBorder() const; virtual void DoSetSize(int x, int y, int w, int h, int sizeFlags = wxSIZE_AUTO); virtual wxSize DoGetBestSize() const; diff --git a/include/wx/msw/tglbtn.h b/include/wx/msw/tglbtn.h index 02650d58ed..8680717340 100644 --- a/include/wx/msw/tglbtn.h +++ b/include/wx/msw/tglbtn.h @@ -52,8 +52,8 @@ public: virtual bool CanApplyThemeBorder() const { return false; } protected: + virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; } virtual wxSize DoGetBestSize() const; - virtual wxBorder GetDefaultBorder() const; private: DECLARE_DYNAMIC_CLASS_NO_COPY(wxToggleButton) diff --git a/include/wx/msw/window.h b/include/wx/msw/window.h index c88d22e299..cfab751f41 100644 --- a/include/wx/msw/window.h +++ b/include/wx/msw/window.h @@ -448,6 +448,10 @@ protected: // choose the default border for this window virtual wxBorder GetDefaultBorder() const; + // Translate wxBORDER_THEME (and other border styles if necessary to the value + // that makes most sense for this Windows environment + virtual wxBorder TranslateBorder(wxBorder border) const; + #if wxUSE_MENUS_NATIVE virtual bool DoPopupMenu( wxMenu *menu, int x, int y ); #endif // wxUSE_MENUS_NATIVE diff --git a/include/wx/slider.h b/include/wx/slider.h index 99167e7474..14aca4445b 100644 --- a/include/wx/slider.h +++ b/include/wx/slider.h @@ -105,6 +105,9 @@ public: protected: + // choose the default border for this window + virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; } + // adjust value according to wxSL_INVERSE style virtual int ValueInvertOrNot(int value) const { diff --git a/include/wx/statbmp.h b/include/wx/statbmp.h index 24281700b4..b80459f3ff 100644 --- a/include/wx/statbmp.h +++ b/include/wx/statbmp.h @@ -45,6 +45,9 @@ public: virtual bool HasTransparentBackground() { return true; } protected: + // choose the default border for this window + virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; } + virtual wxSize DoGetBestSize() const; DECLARE_NO_COPY_CLASS(wxStaticBitmapBase) diff --git a/include/wx/statbox.h b/include/wx/statbox.h index 039df42af3..7eee31685e 100644 --- a/include/wx/statbox.h +++ b/include/wx/statbox.h @@ -47,6 +47,9 @@ public: } private: + // choose the default border for this window + virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; } + DECLARE_NO_COPY_CLASS(wxStaticBoxBase) }; diff --git a/include/wx/statline.h b/include/wx/statline.h index b1046d6d5e..87115f6f13 100644 --- a/include/wx/statline.h +++ b/include/wx/statline.h @@ -50,6 +50,9 @@ public: virtual bool AcceptsFocus() const { return false; } protected: + // choose the default border for this window + virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; } + // set the right size for the right dimension wxSize AdjustSize(const wxSize& size) const { diff --git a/include/wx/stattext.h b/include/wx/stattext.h index 05059831bb..395b19066a 100644 --- a/include/wx/stattext.h +++ b/include/wx/stattext.h @@ -72,6 +72,9 @@ public: protected: // functions required for wxST_ELLIPSIZE_* support + // choose the default border for this window + virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; } + // just calls RemoveMarkup & Ellipsize on the original label. virtual wxString GetEllipsizedLabelWithoutMarkup() const; diff --git a/include/wx/univ/tglbtn.h b/include/wx/univ/tglbtn.h index 35d3667e0e..8f78e3a7b8 100644 --- a/include/wx/univ/tglbtn.h +++ b/include/wx/univ/tglbtn.h @@ -57,6 +57,8 @@ public: bool GetValue() const { return m_value; } protected: + virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; } + // the current value bool m_value; diff --git a/include/wx/window.h b/include/wx/window.h index d09acb8c5b..972fb886b4 100644 --- a/include/wx/window.h +++ b/include/wx/window.h @@ -1244,7 +1244,8 @@ public: // area (normal windows can't, but e.g. menubar or statusbar can): virtual bool CanBeOutsideClientArea() const { return false; } - // returns true if the platform should explicitly apply a theme border + // returns true if the platform should explicitly apply a theme border. Currently + // used only by Windows virtual bool CanApplyThemeBorder() const { return true; } protected: @@ -1409,7 +1410,7 @@ protected: // this allows you to implement standard control borders without // repeating the code in different classes that are not derived from // wxControl - virtual wxBorder GetDefaultBorderForControl() const { return wxBORDER_SUNKEN; } + virtual wxBorder GetDefaultBorderForControl() const { return wxBORDER_THEME; } // Get the default size for the new window if no explicit size given. TLWs // have their own default size so this is just for non top-level windows. diff --git a/src/common/ctrlcmn.cpp b/src/common/ctrlcmn.cpp index 3e4fbb119f..83f789b824 100644 --- a/src/common/ctrlcmn.cpp +++ b/src/common/ctrlcmn.cpp @@ -158,6 +158,12 @@ wxString wxControlBase::RemoveMnemonics(const wxString& str) return wxStripMenuCodes(str, wxStrip_Mnemonics); } +wxBorder wxControlBase::GetDefaultBorder() const +{ + return wxBORDER_THEME; +} + + // ---------------------------------------------------------------------------- // wxStaticBitmap // ---------------------------------------------------------------------------- diff --git a/src/msw/control.cpp b/src/msw/control.cpp index 857cc3325b..f0d866b275 100644 --- a/src/msw/control.cpp +++ b/src/msw/control.cpp @@ -245,7 +245,9 @@ wxSize wxControl::DoGetBestSize() const wxBorder wxControl::GetDefaultBorder() const { - return GetDefaultBorderForControl(); + return wxControlBase::GetDefaultBorder(); + +// return GetDefaultBorderForControl(); } // This is a helper for all wxControls made with UPDOWN native control. diff --git a/src/msw/statbmp.cpp b/src/msw/statbmp.cpp index cd03008f89..537c193d84 100644 --- a/src/msw/statbmp.cpp +++ b/src/msw/statbmp.cpp @@ -171,11 +171,6 @@ bool wxStaticBitmap::Create(wxWindow *parent, return true; } -wxBorder wxStaticBitmap::GetDefaultBorder() const -{ - return wxBORDER_NONE; -} - WXDWORD wxStaticBitmap::MSWGetStyle(long style, WXDWORD *exstyle) const { WXDWORD msStyle = wxControl::MSWGetStyle(style, exstyle); diff --git a/src/msw/statbox.cpp b/src/msw/statbox.cpp index 0d4df55d13..e568f4475d 100644 --- a/src/msw/statbox.cpp +++ b/src/msw/statbox.cpp @@ -138,11 +138,6 @@ bool wxStaticBox::Create(wxWindow *parent, return true; } -wxBorder wxStaticBox::GetDefaultBorder() const -{ - return wxBORDER_NONE; -} - WXDWORD wxStaticBox::MSWGetStyle(long style, WXDWORD *exstyle) const { long styleWin = wxStaticBoxBase::MSWGetStyle(style, exstyle); diff --git a/src/msw/stattext.cpp b/src/msw/stattext.cpp index 2df67c28b8..a3b52cac70 100644 --- a/src/msw/stattext.cpp +++ b/src/msw/stattext.cpp @@ -100,11 +100,6 @@ bool wxStaticText::Create(wxWindow *parent, return true; } -wxBorder wxStaticText::GetDefaultBorder() const -{ - return wxBORDER_NONE; -} - WXDWORD wxStaticText::MSWGetStyle(long style, WXDWORD *exstyle) const { WXDWORD msStyle = wxControl::MSWGetStyle(style, exstyle); @@ -220,9 +215,9 @@ void wxStaticText::SetLabel(const wxString& label) if ( HasFlag(wxST_ELLIPSIZE_END) && wxGetOsVersion() == wxOS_WINDOWS_NT ) { - // adding SS_ENDELLIPSIS or SS_ENDELLIPSIS "disables" the correct - // newline handling in static texts: the newlines in the labels are - // shown as square. Thus we don't use it even on newer OS when + // adding SS_ENDELLIPSIS or SS_ENDELLIPSIS "disables" the correct + // newline handling in static texts: the newlines in the labels are + // shown as square. Thus we don't use it even on newer OS when // the static label contains a newline. if ( label.Contains(wxT('\n')) ) styleReal &= ~SS_ENDELLIPSIS; diff --git a/src/msw/tglbtn.cpp b/src/msw/tglbtn.cpp index 906c430116..7a0e49c862 100644 --- a/src/msw/tglbtn.cpp +++ b/src/msw/tglbtn.cpp @@ -83,11 +83,6 @@ bool wxToggleButton::Create(wxWindow *parent, wxWindowID id, return true; } -wxBorder wxToggleButton::GetDefaultBorder() const -{ - return wxBORDER_NONE; -} - WXDWORD wxToggleButton::MSWGetStyle(long style, WXDWORD *exstyle) const { WXDWORD msStyle = wxControl::MSWGetStyle(style, exstyle); diff --git a/src/msw/window.cpp b/src/msw/window.cpp index 87122d67bd..c3b83772f4 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -1309,9 +1309,38 @@ wxBorder wxWindowMSW::GetDefaultBorderForControl() const wxBorder wxWindowMSW::GetDefaultBorder() const { - return GetDefaultBorderForControl(); + // return GetDefaultBorderForControl(); + return wxWindowBase::GetDefaultBorder(); } +// Translate wxBORDER_THEME (and other border styles if necessary to the value +// that makes most sense for this Windows environment +wxBorder wxWindowMSW::TranslateBorder(wxBorder border) const +{ +#if defined(__POCKETPC__) || defined(__SMARTPHONE__) + if (border == wxBORDER_THEME || border == wxBORDER_SUNKEN || border == wxBORDER_SIMPLE) + return wxBORDER_SIMPLE; + else + return wxBORDER_NONE; +#else +#if wxUSE_UXTHEME + if (border == wxBORDER_THEME) + { + if (CanApplyThemeBorder()) + { + wxUxThemeEngine* theme = wxUxThemeEngine::GetIfActive(); + if (theme) + return wxBORDER_THEME; + } + } +#endif + return border; +#endif + + return border; +} + + WXDWORD wxWindowMSW::MSWGetStyle(long flags, WXDWORD *exstyle) const { // translate common wxWidgets styles to Windows ones @@ -1341,7 +1370,10 @@ WXDWORD wxWindowMSW::MSWGetStyle(long flags, WXDWORD *exstyle) const if ( flags & wxHSCROLL ) style |= WS_HSCROLL; - const wxBorder border = GetBorder(flags); + const wxBorder border = TranslateBorder(GetBorder(flags)); + + // After translation, border is now optimized for the specific version of Windows + // and theme engine presence. // WS_BORDER is only required for wxBORDER_SIMPLE if ( border == wxBORDER_SIMPLE ) @@ -3260,7 +3292,8 @@ WXLRESULT wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM l case WM_NCCALCSIZE: { wxUxThemeEngine* theme = wxUxThemeEngine::GetIfActive(); - if (theme && GetBorder() == wxBORDER_THEME) + const wxBorder border = TranslateBorder(GetBorder()); + if (theme && border == wxBORDER_THEME) { // first ask the widget to calculate the border size rc.result = MSWDefWindowProc(message, wParam, lParam); @@ -3300,7 +3333,8 @@ WXLRESULT wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM l case WM_NCPAINT: { wxUxThemeEngine* theme = wxUxThemeEngine::GetIfActive(); - if (theme && GetBorder() == wxBORDER_THEME) + const wxBorder border = TranslateBorder(GetBorder()); + if (theme && border == wxBORDER_THEME) { // first ask the widget to paint its non-client area, such as scrollbars, etc. rc.result = MSWDefWindowProc(message, wParam, lParam); -- 2.45.2