Merge branch 'macos-native-statusbar' of https://github.com/vslavik/wxWidgets

Improve macOS status bar appearance and simplify code.

See https://github.com/wxWidgets/wxWidgets/pull/2160
This commit is contained in:
Vadim Zeitlin
2021-01-16 18:57:23 +01:00
9 changed files with 52 additions and 104 deletions

View File

@@ -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);

View File

@@ -329,6 +329,8 @@ public :
virtual void SetRepresentedFilename(const wxString& filename) wxOVERRIDE;
virtual void SetBottomBorderThickness(int thickness) wxOVERRIDE;
wxNonOwnedWindow* GetWXPeer() { return m_wxPeer; }
CGWindowLevel GetWindowLevel() const wxOVERRIDE { return m_macWindowLevel; }

View File

@@ -984,6 +984,8 @@ public :
virtual void SetRepresentedFilename(const wxString& WXUNUSED(filename)) { }
virtual void SetBottomBorderThickness(int WXUNUSED(thickness)) { }
#if wxOSX_USE_IPHONE
virtual CGFloat GetWindowLevel() const { return 0.0; }
#else

View File

@@ -71,6 +71,8 @@ public:
long style = wxSTB_DEFAULT_STYLE,
wxWindowID id = 0,
const wxString& name = wxASCII_STR(wxStatusLineNameStr)) wxOVERRIDE;
virtual void SetStatusBar(wxStatusBar *statbar) wxOVERRIDE;
#endif // wxUSE_STATUSBAR
void PositionBars();

View File

@@ -31,16 +31,12 @@ 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;
private:
wxColour m_textActive, m_textInactive,
m_bgActiveFrom, m_bgActiveTo,
m_borderActive, m_borderInactive;
wxColour m_textActive, m_textInactive;
wxDECLARE_DYNAMIC_CLASS(wxStatusBarMac);
wxDECLARE_EVENT_TABLE();

View File

@@ -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

View File

@@ -24,14 +24,28 @@
#endif // WX_PRECOMP
#include "wx/osx/private.h"
#include "wx/osx/private/available.h"
namespace
{
int GetMacStatusbarHeight()
{
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_16
if ( WX_IS_MACOS_AVAILABLE(10, 16) )
return 28;
else
#endif
return 24;
}
} // anonymous namespace
wxBEGIN_EVENT_TABLE(wxFrame, wxFrameBase)
EVT_ACTIVATE(wxFrame::OnActivate)
EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged)
wxEND_EVENT_TABLE()
#define WX_MAC_STATUSBAR_HEIGHT 24
// ----------------------------------------------------------------------------
// creation/destruction
// ----------------------------------------------------------------------------
@@ -106,12 +120,18 @@ wxStatusBar *wxFrame::OnCreateStatusBar(int number, long style, wxWindowID id,
wxStatusBar *statusBar;
statusBar = new wxStatusBar(this, id, style, name);
statusBar->SetSize(100, WX_MAC_STATUSBAR_HEIGHT);
statusBar->SetSize(100, GetMacStatusbarHeight());
statusBar->SetFieldsCount(number);
return statusBar;
}
void wxFrame::SetStatusBar(wxStatusBar *statbar)
{
wxFrameBase::SetStatusBar(statbar);
m_nowpeer->SetBottomBorderThickness(statbar ? GetMacStatusbarHeight() : 0);
}
void wxFrame::PositionStatusBar()
{
if (m_frameStatusBar && m_frameStatusBar->IsShown() )
@@ -121,7 +141,7 @@ void wxFrame::PositionStatusBar()
// Since we wish the status bar to be directly under the client area,
// we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
m_frameStatusBar->SetSize(0, h, w, WX_MAC_STATUSBAR_HEIGHT);
m_frameStatusBar->SetSize(0, h, w, GetMacStatusbarHeight());
}
}
#endif // wxUSE_STATUSBAR
@@ -217,7 +237,7 @@ void wxFrame::DoGetClientSize(int *x, int *y) const
#if wxUSE_STATUSBAR
if ( GetStatusBar() && GetStatusBar()->IsShown() && y )
*y -= WX_MAC_STATUSBAR_HEIGHT;
*y -= GetMacStatusbarHeight();
#endif
#if wxUSE_TOOLBAR

View File

@@ -78,97 +78,28 @@ void wxStatusBarMac::InitColours()
{
if ( WX_IS_MACOS_AVAILABLE(10, 14) )
{
// FIXME: None of this is correct and is only very loose
// approximation. 10.14's dark mode uses dynamic colors that
// use desktop tinting. The only correct way to render the
// statusbar is to use windowBackgroundColor in a NSBox.
wxColour bg = wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE);
m_textActive = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT);
m_textInactive = wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT);
if ( wxSystemSettings::GetAppearance().IsDark() )
{
// dark mode appearance
m_textActive = wxColour(0xB0, 0xB0, 0xB0);
m_bgActiveFrom = wxColour(0x32, 0x32, 0x34);
m_bgActiveTo = wxColour(0x29, 0x29, 0x2A);
m_borderActive = wxColour(0x00, 0x00, 0x00);
m_borderInactive = wxColour(0x00, 0x00, 0x00);
m_textActive = wxColour(0xA9, 0xA9, 0xA9);
m_textInactive = wxColour(0x67, 0x67, 0x67);
}
else
{
m_bgActiveFrom = wxColour(0xE9, 0xE7, 0xEA);
m_bgActiveTo = wxColour(0xCD, 0xCB, 0xCE);
m_borderActive = wxColour(0xBA, 0xB8, 0xBB);
m_borderInactive = wxColour(0xC3, 0xC3, 0xC3);
m_textActive = wxColour(0x4B, 0x4B, 0x4B);
m_textInactive = wxColour(0xB1, 0xB1, 0xB1);
}
SetBackgroundColour(bg); // inactive bg
}
else
else // 10.10 Yosemite to 10.13:
{
// 10.10 Yosemite to 10.13 :
m_textActive = wxColour(0x40, 0x40, 0x40);
m_textInactive = wxColour(0x4B, 0x4B, 0x4B);
m_bgActiveFrom = wxColour(0xE9, 0xE7, 0xEA);
m_bgActiveTo = wxColour(0xCD, 0xCB, 0xCE);
m_borderActive = wxColour(0xBA, 0xB8, 0xBB);
m_borderInactive = wxColour(0xC3, 0xC3, 0xC3);
SetBackgroundColour(wxColour(0xF4, 0xF4, 0xF4)); // inactive bg
}
}
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);
dc.Clear();
int w, h;
GetSize( &w, &h );
// Notice that wxOSXGetKeyWindow (aka [NSApp keyWindow] used below is
// subtly different from IsActive() (aka [NSWindow iskeyWindow]): the
@@ -188,22 +119,9 @@ void wxStatusBarMac::OnPaint(wxPaintEvent& WXUNUSED(event))
break;
}
if ( tlw == keyWindow )
{
dc.GradientFillLinear(dc.GetSize(), m_bgActiveFrom, m_bgActiveTo, wxBOTTOM);
// Don't paint any background, that's handled by the OS. Only draw text:
// Finder statusbar border color
dc.SetPen(wxPen(m_borderActive, 2, wxPENSTYLE_SOLID));
dc.SetTextForeground(m_textActive);
}
else
{
// Finder statusbar border color
dc.SetPen(wxPen(m_borderInactive, 2, wxPENSTYLE_SOLID));
dc.SetTextForeground(m_textInactive);
}
dc.DrawLine(0, 0, w, 0);
dc.SetTextForeground(tlw == keyWindow ? m_textActive : m_textInactive);
if ( GetFont().IsOk() )
dc.SetFont(GetFont());

View File

@@ -1288,6 +1288,12 @@ void wxNonOwnedWindowCocoaImpl::SetRepresentedFilename(const wxString& filename)
[m_macWindow setRepresentedFilename:wxCFStringRef(filename).AsNSString()];
}
void wxNonOwnedWindowCocoaImpl::SetBottomBorderThickness(int thickness)
{
[m_macWindow setAutorecalculatesContentBorderThickness:(thickness ? NO : YES) forEdge:NSMinYEdge];
[m_macWindow setContentBorderThickness:thickness forEdge:NSMinYEdge];
}
void wxNonOwnedWindowCocoaImpl::RestoreWindowLevel()
{
if ( [m_macWindow level] != m_macWindowLevel )