From 54ea28348cd5123e42e2029139d9772a736ed57c Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Tue, 7 Dec 2010 15:46:12 +0000 Subject: [PATCH] adding support for layout coordinates via insets from framecoordinates git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@66360 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/osx/core/private.h | 7 +++++ include/wx/osx/window.h | 1 + src/osx/cocoa/button.mm | 45 +++++++++++++++++++++++++-- src/osx/window_osx.cpp | 57 ++++++++++++++++++++++++++++++----- 4 files changed, 101 insertions(+), 9 deletions(-) diff --git a/include/wx/osx/core/private.h b/include/wx/osx/core/private.h index d56484f7c5..5eec53c0c6 100644 --- a/include/wx/osx/core/private.h +++ b/include/wx/osx/core/private.h @@ -234,6 +234,13 @@ public : virtual void GetPosition( int &x, int &y ) const = 0; virtual void GetSize( int &width, int &height ) const = 0; virtual void SetControlSize( wxWindowVariant variant ) = 0; + + // the native coordinates may have an 'aura' for shadows etc, if this is the case the layout + // inset indicates on which insets the real control is drawn + virtual void GetLayoutInset(int &left , int &top , int &right, int &bottom) const + { + left = top = right = bottom = 0; + } // native view coordinates are topleft to bottom right (flipped regarding CoreGraphics origin) virtual bool IsFlipped() const { return true; } diff --git a/include/wx/osx/window.h b/include/wx/osx/window.h index 5758b5a8c3..875a5ef093 100644 --- a/include/wx/osx/window.h +++ b/include/wx/osx/window.h @@ -182,6 +182,7 @@ public: WXWindow MacGetTopLevelWindowRef() const ; wxNonOwnedWindow* MacGetTopLevelWindow() const ; + virtual long MacGetWXBorderSize() const; virtual long MacGetLeftBorderSize() const ; virtual long MacGetRightBorderSize() const ; virtual long MacGetTopBorderSize() const ; diff --git a/src/osx/cocoa/button.mm b/src/osx/cocoa/button.mm index 77e2d20676..13ae019fef 100644 --- a/src/osx/cocoa/button.mm +++ b/src/osx/cocoa/button.mm @@ -30,7 +30,11 @@ wxSize wxButton::DoGetBestSize() const m_peer->GetBestRect(&r); wxSize sz = r.GetSize(); - + sz.x = sz.x + MacGetLeftBorderSize() + + MacGetRightBorderSize(); + sz.y = sz.y + MacGetTopBorderSize() + + MacGetBottomBorderSize(); + const int wBtnStd = GetDefaultSize().x; if ( (sz.x < wBtnStd) && !HasFlag(wxBU_EXACTFIT) ) @@ -41,7 +45,7 @@ wxSize wxButton::DoGetBestSize() const wxSize wxButton::GetDefaultSize() { - return wxSize(84, 23); + return wxSize(84, 20); } @implementation wxNSButton @@ -124,6 +128,43 @@ public: [button setButtonType:NSMomentaryChangeButton]; } + void GetLayoutInset(int &left , int &top , int &right, int &bottom) const + { + left = top = right = bottom = 0; + NSControlSize size = NSRegularControlSize; + if ( [m_osxView respondsToSelector:@selector(controlSize)] ) + size = (NSControlSize) [m_osxView controlSize]; + else if ([m_osxView respondsToSelector:@selector(cell)]) + { + id cell = [(id)m_osxView cell]; + if ([cell respondsToSelector:@selector(controlSize)]) + size = [cell controlSize]; + } + + if ( [GetNSButton() bezelStyle] == NSRoundedBezelStyle ) + { + switch( size ) + { + case NSRegularControlSize: + left = right = 6; + top = 4; + bottom = 8; + break; + case NSSmallControlSize: + left = right = 5; + top = 4; + bottom = 7; + break; + case NSMiniControlSize: + left = right = 1; + top = 0; + bottom = 2; + break; + } + } + } + + private: NSButton *GetNSButton() const { diff --git a/src/osx/window_osx.cpp b/src/osx/window_osx.cpp index 25b9abea3a..ec1375142e 100644 --- a/src/osx/window_osx.cpp +++ b/src/osx/window_osx.cpp @@ -2263,7 +2263,7 @@ void wxWindowMac::MacTopLevelWindowChangedPosition() } } -long wxWindowMac::MacGetLeftBorderSize() const +long wxWindowMac::MacGetWXBorderSize() const { if ( IsTopLevel() ) return 0 ; @@ -2297,22 +2297,65 @@ long wxWindowMac::MacGetLeftBorderSize() const return border ; } +long wxWindowMac::MacGetLeftBorderSize() const +{ + // the wx borders are all symmetric in mac themes + long border = MacGetWXBorderSize() ; + + if ( m_peer ) + { + int left, top, right, bottom; + m_peer->GetLayoutInset( left, top, right, bottom ); + border -= left; + } + + return border; +} + + long wxWindowMac::MacGetRightBorderSize() const { - // they are all symmetric in mac themes - return MacGetLeftBorderSize() ; + // the wx borders are all symmetric in mac themes + long border = MacGetWXBorderSize() ; + + if ( m_peer ) + { + int left, top, right, bottom; + m_peer->GetLayoutInset( left, top, right, bottom ); + border -= right; + } + + return border; } long wxWindowMac::MacGetTopBorderSize() const { - // they are all symmetric in mac themes - return MacGetLeftBorderSize() ; + // the wx borders are all symmetric in mac themes + long border = MacGetWXBorderSize() ; + + if ( m_peer ) + { + int left, top, right, bottom; + m_peer->GetLayoutInset( left, top, right, bottom ); + border -= top; + } + + return border; } long wxWindowMac::MacGetBottomBorderSize() const { - // they are all symmetric in mac themes - return MacGetLeftBorderSize() ; + // the wx borders are all symmetric in mac themes + long border = MacGetWXBorderSize() ; + + if ( m_peer ) + { + int left, top, right, bottom; + m_peer->GetLayoutInset( left, top, right, bottom ); + border -= bottom; + } + + return border; } long wxWindowMac::MacRemoveBordersFromStyle( long style ) -- 2.45.2