From 634f60ff2385ffc6465560b182672274420875a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Va=CC=81clav=20Slavi=CC=81k?= Date: Sat, 16 Jan 2021 18:30:45 +0100 Subject: [PATCH] Remove redundant code from wxStatusBarMac MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove a lot of Mac-specific code from wxStatusBarMac in favour of using shared wxStatusBarGeneric: - Now that wxFRAME_EX_METAL aka NSWindowStyleMaskTexturedBackground doesn’t affect text placement, there’s no reason for customized DrawFieldText(). As a side effect of this removal, ellipsizing fields is now supported. - Remove customized DoUpdateStatusText() code that is no longer needed. See https://github.com/wxWidgets/wxWidgets/pull/2160#pullrequestreview-563916013 --- include/wx/generic/statusbr.h | 2 +- include/wx/osx/statusbr.h | 4 +--- src/generic/statusbr.cpp | 6 +++-- src/osx/carbon/statbrma.cpp | 45 ----------------------------------- 4 files changed, 6 insertions(+), 51 deletions(-) diff --git a/include/wx/generic/statusbr.h b/include/wx/generic/statusbr.h index 8a3d73d4f7..a13ca9e133 100644 --- a/include/wx/generic/statusbr.h +++ b/include/wx/generic/statusbr.h @@ -70,7 +70,7 @@ protected: void OnSysColourChanged(wxSysColourChangedEvent& event); protected: - + virtual int GetEffectiveFieldStyle(int i) const { return m_panes[i].GetStyle(); } virtual void DrawFieldText(wxDC& dc, const wxRect& rc, int i, int textHeight); virtual void DrawField(wxDC& dc, int i, int textHeight); diff --git a/include/wx/osx/statusbr.h b/include/wx/osx/statusbr.h index ea931f998f..d80d5a9d78 100644 --- a/include/wx/osx/statusbr.h +++ b/include/wx/osx/statusbr.h @@ -31,9 +31,7 @@ public: void OnPaint(wxPaintEvent& event); protected: - virtual void DrawFieldText(wxDC& dc, const wxRect& rc, int i, int textHeight) wxOVERRIDE; - virtual void DrawField(wxDC& dc, int i, int textHeight) wxOVERRIDE; - virtual void DoUpdateStatusText(int number = 0) wxOVERRIDE; + virtual int GetEffectiveFieldStyle(int WXUNUSED(i)) const wxOVERRIDE { return wxSB_NORMAL; } virtual void InitColours() wxOVERRIDE; diff --git a/src/generic/statusbr.cpp b/src/generic/statusbr.cpp index b8494d4a9d..4993a3f23f 100644 --- a/src/generic/statusbr.cpp +++ b/src/generic/statusbr.cpp @@ -265,9 +265,11 @@ void wxStatusBarGeneric::DrawFieldText(wxDC& dc, const wxRect& rect, int i, int SetEllipsizedFlag(i, text != GetStatusText(i)); } -#if defined( __WXGTK__ ) || defined(__WXMAC__) +#if defined( __WXGTK__ ) xpos++; ypos++; +#elif defined(__WXMAC__) + xpos++; #endif // draw the text @@ -285,7 +287,7 @@ void wxStatusBarGeneric::DrawField(wxDC& dc, int i, int textHeight) if (rect.GetWidth() <= 0) return; // happens when the status bar is shrunk in a very small area! - int style = m_panes[i].GetStyle(); + int style = GetEffectiveFieldStyle(i); if (style == wxSB_RAISED || style == wxSB_SUNKEN) { // Draw border diff --git a/src/osx/carbon/statbrma.cpp b/src/osx/carbon/statbrma.cpp index 29e7b9fe76..91e78d80bc 100644 --- a/src/osx/carbon/statbrma.cpp +++ b/src/osx/carbon/statbrma.cpp @@ -97,51 +97,6 @@ void wxStatusBarMac::InitColours() } } -void wxStatusBarMac::DrawFieldText(wxDC& dc, const wxRect& rect, int i, int textHeight) -{ - int w, h; - GetSize( &w , &h ); - - wxString text(GetStatusText( i )); - - int xpos = rect.x + wxFIELD_TEXT_MARGIN + 1; - int ypos = 2 + (rect.height - textHeight) / 2; - - if ( MacGetTopLevelWindow()->GetExtraStyle() & wxFRAME_EX_METAL ) - ypos++; - - dc.SetClippingRegion(rect.x, 0, rect.width, h); - dc.DrawText(text, xpos, ypos); - dc.DestroyClippingRegion(); -} - -void wxStatusBarMac::DrawField(wxDC& dc, int i, int textHeight) -{ - wxRect rect; - GetFieldRect(i, rect); - - DrawFieldText(dc, rect, i, textHeight); -} - -void wxStatusBarMac::DoUpdateStatusText(int number) -{ - wxRect rect; - GetFieldRect(number, rect); - - int w, h; - GetSize( &w, &h ); - - rect.y = 0; - rect.height = h ; - - Refresh( true, &rect ); - // we should have to force the update here - // TODO Remove if no regressions occur -#if 0 - Update(); -#endif -} - void wxStatusBarMac::OnPaint(wxPaintEvent& WXUNUSED(event)) { wxPaintDC dc(this);