From 5dd070c25bd91c12380f9aeada27a2b7b64ed1d7 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 7 Mar 2005 23:37:15 +0000 Subject: [PATCH] extracted platform-specific code to determine static box borders to wxStaticBox::GetBordersForSizer() git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@32654 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/cocoa/statbox.h | 2 +- include/wx/mac/carbon/statbox.h | 3 +-- include/wx/statbox.h | 13 ++++++++++ src/common/sizer.cpp | 42 +-------------------------------- src/mac/carbon/statbox.cpp | 41 ++++++++++++++++++++++++++------ 5 files changed, 50 insertions(+), 51 deletions(-) diff --git a/include/wx/cocoa/statbox.h b/include/wx/cocoa/statbox.h index 92e2985d42..8764385c1e 100644 --- a/include/wx/cocoa/statbox.h +++ b/include/wx/cocoa/statbox.h @@ -51,7 +51,7 @@ protected: // Implementation // ------------------------------------------------------------------------ public: - void GetBordersForSizer(int *borderTop, int *borderOther) const; + virtual void GetBordersForSizer(int *borderTop, int *borderOther) const; protected: }; diff --git a/include/wx/mac/carbon/statbox.h b/include/wx/mac/carbon/statbox.h index 6dd85bf43d..2cd136e650 100644 --- a/include/wx/mac/carbon/statbox.h +++ b/include/wx/mac/carbon/statbox.h @@ -47,8 +47,7 @@ class WXDLLEXPORT wxStaticBox: public wxControl virtual void Command(wxCommandEvent& WXUNUSED(event)) {}; virtual void ProcessCommand(wxCommandEvent& WXUNUSED(event)) {}; - -protected: + virtual void GetBordersForSizer(int *borderTop, int *borderOther) const; }; #endif diff --git a/include/wx/statbox.h b/include/wx/statbox.h index 78690c41a0..41d29b05b9 100644 --- a/include/wx/statbox.h +++ b/include/wx/statbox.h @@ -20,6 +20,19 @@ public: virtual bool AcceptsFocus() const { return false; } virtual bool HasTransparentBackground() { return true; } + // implementation only: this is used by wxStaticBoxSizer to account for the + // need for extra space taken by the static box + // + // the top border is the margin at the top (where the title is), + // borderOther is the margin on all other sides + virtual void GetBordersForSizer(int *borderTop, int *borderOther) const + { + static const int BORDER = 5; // FIXME: hardcoded value + + *borderTop = GetLabel().empty() ? BORDER : GetCharHeight(); + *borderOther = BORDER; + } + private: DECLARE_NO_COPY_CLASS(wxStaticBoxBase) }; diff --git a/src/common/sizer.cpp b/src/common/sizer.cpp index f787a74ffc..703882151e 100644 --- a/src/common/sizer.cpp +++ b/src/common/sizer.cpp @@ -36,10 +36,6 @@ #include "wx/notebook.h" #endif -#ifdef __WXMAC__ -# include "wx/mac/uma.h" -#endif - //--------------------------------------------------------------------------- IMPLEMENT_CLASS(wxSizerItem, wxObject) @@ -1582,43 +1578,7 @@ static void GetStaticBoxBorders( wxStaticBox *box, { // this has to be done platform by platform as there is no way to // guess the thickness of a wxStaticBox border -#ifdef __WXCOCOA__ - box->GetBordersForSizer(borderTop,borderOther); -#elif defined(__WXMAC__) - - static int extraTop = -1; // Uninitted - static int other = 5; - - if ( extraTop == -1 ) - { - // The minimal border used for the top. Later on the staticbox' - // font height is added to this. - extraTop = 0; - - if ( UMAGetSystemVersion() >= 0x1030 /*Panther*/ ) - { - // As indicated by the HIG, Panther needs an extra border of 11 - // pixels (otherwise overlapping occurs at the top). The "other" - // border has to be 11. - extraTop = 11; - other = 11; - } - - } - - *borderTop = extraTop + box->GetCharHeight(); - *borderOther = other; - -#else -#ifdef __WXGTK__ - if ( box->GetLabel().empty() ) - *borderTop = 5; - else -#endif // __WXGTK__ - *borderTop = box->GetCharHeight(); - - *borderOther = 5; -#endif // __WXCOCOA__ + box->GetBordersForSizer(borderTop, borderOther); } void wxStaticBoxSizer::RecalcSizes() diff --git a/src/mac/carbon/statbox.cpp b/src/mac/carbon/statbox.cpp index cc29e9b267..50e62f2b92 100644 --- a/src/mac/carbon/statbox.cpp +++ b/src/mac/carbon/statbox.cpp @@ -27,7 +27,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxStaticBox, wxControl) /* * Static box */ - + bool wxStaticBox::Create(wxWindow *parent, wxWindowID id, const wxString& label, const wxPoint& pos, @@ -36,7 +36,7 @@ bool wxStaticBox::Create(wxWindow *parent, wxWindowID id, const wxString& name) { m_macIsUserPane = FALSE ; - + if ( !wxControl::Create(parent, id, pos, size, style, wxDefaultValidator, name) ) return false; @@ -44,14 +44,41 @@ bool wxStaticBox::Create(wxWindow *parent, wxWindowID id, m_label = label ; Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; - + m_peer = new wxMacControl(this) ; - verify_noerr(CreateGroupBoxControl(MAC_WXHWND(parent->MacGetTopLevelWindowRef()),&bounds, CFSTR("") , - true /*primary*/ , m_peer->GetControlRefAddr() ) ) ; + verify_noerr(CreateGroupBoxControl(MAC_WXHWND(parent->MacGetTopLevelWindowRef()),&bounds, CFSTR("") , + true /*primary*/ , m_peer->GetControlRefAddr() ) ) ; MacPostControlCreate(pos,size) ; - + return TRUE; } -#endif \ No newline at end of file +void wxStaticBox::GetBordersForSizer(int *borderTop, int *borderOther) const +{ + static int extraTop = -1; // Uninitted + static int other = 5; + + if ( extraTop == -1 ) + { + // The minimal border used for the top. Later on the staticbox' + // font height is added to this. + extraTop = 0; + + if ( UMAGetSystemVersion() >= 0x1030 /*Panther*/ ) + { + // As indicated by the HIG, Panther needs an extra border of 11 + // pixels (otherwise overlapping occurs at the top). The "other" + // border has to be 11. + extraTop = 11; + other = 11; + } + + } + + *borderTop = extraTop + box->GetCharHeight(); + *borderOther = other; +} + +#endif // wxUSE_STATBOX + -- 2.49.0