From d9ec9ab1f14585abae4bd4bfb31edd8a6b61ff4e Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Sat, 23 Apr 2022 19:31:22 +0200 Subject: [PATCH] Use Cocoa native layout inset method Don't hardcode inset sizes any longer. This improves various issues under macOS 12, see #22134 and #22135 (but doesn't fully fix the former problem yet). Closes #22351. --- include/wx/osx/cocoa/private.h | 3 +-- src/osx/cocoa/button.mm | 44 ---------------------------------- src/osx/cocoa/choice.mm | 37 ---------------------------- src/osx/cocoa/gauge.mm | 23 ------------------ src/osx/cocoa/window.mm | 9 +++++++ 5 files changed, 10 insertions(+), 106 deletions(-) diff --git a/include/wx/osx/cocoa/private.h b/include/wx/osx/cocoa/private.h index bbef297d1f..355dea4d3e 100644 --- a/include/wx/osx/cocoa/private.h +++ b/include/wx/osx/cocoa/private.h @@ -111,7 +111,7 @@ public : virtual void GetPosition( int &x, int &y ) const wxOVERRIDE; virtual void GetSize( int &width, int &height ) const wxOVERRIDE; virtual void SetControlSize( wxWindowVariant variant ) wxOVERRIDE; - + virtual void GetLayoutInset(int &left , int &top , int &right, int &bottom) const wxOVERRIDE; virtual void SetNeedsDisplay( const wxRect* where = NULL ) wxOVERRIDE; virtual bool GetNeedsDisplay() const wxOVERRIDE; @@ -368,7 +368,6 @@ public: #endif // wxUSE_MARKUP void SetPressedBitmap( const wxBitmapBundle& bitmap ) wxOVERRIDE; - void GetLayoutInset(int &left, int &top, int &right, int &bottom) const wxOVERRIDE; void SetAcceleratorFromLabel(const wxString& label); NSButton *GetNSButton() const; diff --git a/src/osx/cocoa/button.mm b/src/osx/cocoa/button.mm index f0e9030307..4187e0db06 100644 --- a/src/osx/cocoa/button.mm +++ b/src/osx/cocoa/button.mm @@ -140,50 +140,6 @@ void wxButtonCocoaImpl::SetPressedBitmap( const wxBitmapBundle& bitmap ) } } -void wxButtonCocoaImpl::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 = [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 ) - { -#if __MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_16 - case NSControlSizeLarge: -#endif - case NSRegularControlSize: - left = right = 6; - top = 4; - bottom = 7; - break; - case NSSmallControlSize: - left = right = 5; - top = 4; - bottom = 6; - break; - case NSMiniControlSize: - left = right = 1; - top = 0; - bottom = 1; - break; - } - } - else if ( [GetNSButton() bezelStyle] == NSSmallSquareBezelStyle ) - { - left = right = 0; - top = bottom = 1; - } -} - void wxButtonCocoaImpl::SetAcceleratorFromLabel(const wxString& label) { const int accelPos = wxControl::FindAccelIndex(label); diff --git a/src/osx/cocoa/choice.mm b/src/osx/cocoa/choice.mm index c7ea9dbad7..2f0eb4ba51 100644 --- a/src/osx/cocoa/choice.mm +++ b/src/osx/cocoa/choice.mm @@ -73,43 +73,6 @@ public: delete m_popUpMenu; } - void GetLayoutInset(int &left , int &top , int &right, int &bottom) const wxOVERRIDE - { - left = top = right = bottom = 0; - NSControlSize size = NSRegularControlSize; - if ( [m_osxView respondsToSelector:@selector(controlSize)] ) - size = [m_osxView controlSize]; - else if ([m_osxView respondsToSelector:@selector(cell)]) - { - id cell = [(id)m_osxView cell]; - if ([cell respondsToSelector:@selector(controlSize)]) - size = [cell controlSize]; - } - - switch( size ) - { -#if __MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_16 - case NSControlSizeLarge: -#endif - case NSRegularControlSize: - left = right = 3; - top = 2; - bottom = 3; - break; - case NSSmallControlSize: - left = right = 3; - top = 1; - bottom = 3; - break; - case NSMiniControlSize: - left = 1; - right = 2; - top = 0; - bottom = 0; - break; - } - } - void InsertItem( size_t pos, int itemid, const wxString& text) wxOVERRIDE { m_popUpMenu->Insert( pos, itemid, text ); diff --git a/src/osx/cocoa/gauge.mm b/src/osx/cocoa/gauge.mm index 244a316c1f..3fc3f57939 100644 --- a/src/osx/cocoa/gauge.mm +++ b/src/osx/cocoa/gauge.mm @@ -71,29 +71,6 @@ public : } } - void GetLayoutInset(int &left , int &top , int &right, int &bottom) const wxOVERRIDE - { - left = top = right = bottom = 0; - NSControlSize size = [(wxNSProgressIndicator*)m_osxView controlSize]; - - switch( size ) - { -#if __MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_16 - case NSControlSizeLarge: -#endif - case NSRegularControlSize: - left = right = 2; - top = 0; - bottom = 3; - break; - case NSMiniControlSize: - case NSSmallControlSize: - left = right = 1; - top = 0; - bottom = 1; - break; - } - } protected: void SetDeterminateMode() { diff --git a/src/osx/cocoa/window.mm b/src/osx/cocoa/window.mm index 3546b34dcc..635ea286d4 100644 --- a/src/osx/cocoa/window.mm +++ b/src/osx/cocoa/window.mm @@ -3112,6 +3112,15 @@ void wxWidgetCocoaImpl::GetContentArea( int&left, int &top, int &width, int &hei } } +void wxWidgetCocoaImpl::GetLayoutInset(int &left , int &top , int &right, int &bottom) const +{ + NSEdgeInsets insets = [m_osxView alignmentRectInsets]; + left = insets.left; + top = insets.top; + right = insets.right; + bottom = insets.bottom; +} + namespace {