Mimic native focus handling in wxStatusBar on macOS
Improve the logic for determining whether the statusbar should be renderer as for active/key window or a background one. wxTopLevelWindow::IsActive() is not a sufficient test because it returns false in some situations when the statusbar need to appear as active (another floating window) and also didn't account for window-modal sheets (which don't change statusbar appearance either).
This commit is contained in:
committed by
Václav Slavík
parent
e6274c7dfc
commit
5d87c70eba
@@ -40,6 +40,7 @@ CGContextRef WXDLLIMPEXP_CORE wxOSXCreateBitmapContextFromNSImage( WX_NSImage ns
|
||||
|
||||
wxBitmap WXDLLIMPEXP_CORE wxOSXCreateSystemBitmap(const wxString& id, const wxString &client, const wxSize& size);
|
||||
WXWindow WXDLLIMPEXP_CORE wxOSXGetMainWindow();
|
||||
WXWindow WXDLLIMPEXP_CORE wxOSXGetKeyWindow();
|
||||
|
||||
class WXDLLIMPEXP_FWD_CORE wxDialog;
|
||||
|
||||
|
@@ -18,6 +18,7 @@
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/dc.h"
|
||||
#include "wx/dcclient.h"
|
||||
#include "wx/dialog.h"
|
||||
#include "wx/toplevel.h"
|
||||
#endif
|
||||
|
||||
@@ -147,8 +148,24 @@ void wxStatusBarMac::OnPaint(wxPaintEvent& WXUNUSED(event))
|
||||
int w, h;
|
||||
GetSize( &w, &h );
|
||||
|
||||
// Notice that wxOSXGetKeyWindow (aka [NSApp keyWindow] used below is
|
||||
// subtly different from IsActive() (aka [NSWindow iskeyWindow]): the
|
||||
// former remains non-NULL if another application shows a temporary
|
||||
// floating window or a status icon's menu is used. That's what we want: in
|
||||
// that case, statusbar appearance shouldn't change. It also shouldn't
|
||||
// change if a window-modal sheet attached to this window is key.
|
||||
wxTopLevelWindow *tlw = wxDynamicCast(MacGetTopLevelWindow(), wxTopLevelWindow);
|
||||
if ( tlw && tlw->IsActive() )
|
||||
wxWindow *keyWindow = wxNonOwnedWindow::GetFromWXWindow(wxOSXGetKeyWindow())->MacGetTopLevelWindow();
|
||||
while ( keyWindow && keyWindow != tlw )
|
||||
{
|
||||
wxDialog *dlg = wxDynamicCast(keyWindow, wxDialog);
|
||||
if ( dlg && dlg->GetModality() == wxDIALOG_MODALITY_WINDOW_MODAL )
|
||||
keyWindow = dlg->GetParent();
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
if ( tlw == keyWindow )
|
||||
{
|
||||
dc.GradientFillLinear(dc.GetSize(), m_bgActiveFrom, m_bgActiveTo, wxBOTTOM);
|
||||
|
||||
|
@@ -345,6 +345,11 @@ WXWindow wxOSXGetMainWindow()
|
||||
return [NSApp mainWindow];
|
||||
}
|
||||
|
||||
WXWindow wxOSXGetKeyWindow()
|
||||
{
|
||||
return [NSApp keyWindow];
|
||||
}
|
||||
|
||||
#endif
|
||||
// ----------------------------------------------------------------------------
|
||||
// NSImage Utils
|
||||
|
Reference in New Issue
Block a user