1 ///////////////////////////////////////////////////////////////////////////////
2 // Name:        src/osx/carbon/statbarma.cpp
3 // Purpose:     native implementation of wxStatusBar (optional)
4 // Author:      Stefan Csomor
5 // Modified by:
6 // Created:     1998-01-01
7 // Copyright:   (c) 1998 Stefan Csomor
8 // Licence:     wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
10 
11 #include "wx/wxprec.h"
12 
13 #if wxUSE_STATUSBAR
14 
15 #include "wx/statusbr.h"
16 #include "wx/platinfo.h"
17 #include "wx/settings.h"
18 
19 #ifndef WX_PRECOMP
20     #include "wx/dc.h"
21     #include "wx/dcclient.h"
22     #include "wx/dialog.h"
23     #include "wx/toplevel.h"
24 #endif
25 
26 #include "wx/osx/private.h"
27 #include "wx/osx/private/available.h"
28 
29 // Margin between the field text and the field rect
30 #define wxFIELD_TEXT_MARGIN 2
31 
32 
wxBEGIN_EVENT_TABLE(wxStatusBarMac,wxStatusBarGeneric)33 wxBEGIN_EVENT_TABLE(wxStatusBarMac, wxStatusBarGeneric)
34     EVT_PAINT(wxStatusBarMac::OnPaint)
35 wxEND_EVENT_TABLE()
36 
37 
38 wxStatusBarMac::wxStatusBarMac(wxWindow *parent,
39         wxWindowID id,
40         long style,
41         const wxString& name)
42         :
43         wxStatusBarGeneric()
44 {
45     SetParent( NULL );
46     Create( parent, id, style, name );
47 }
48 
wxStatusBarMac()49 wxStatusBarMac::wxStatusBarMac()
50         :
51         wxStatusBarGeneric()
52 {
53     SetParent( NULL );
54 }
55 
~wxStatusBarMac()56 wxStatusBarMac::~wxStatusBarMac()
57 {
58 }
59 
Create(wxWindow * parent,wxWindowID id,long style,const wxString & name)60 bool wxStatusBarMac::Create(wxWindow *parent, wxWindowID id,
61                             long style ,
62                             const wxString& name)
63 {
64     SetBackgroundStyle( wxBG_STYLE_TRANSPARENT );
65 
66     if ( !wxStatusBarGeneric::Create( parent, id, style, name ) )
67         return false;
68 
69     // normal system font is too tall for fitting into the standard height
70     SetWindowVariant( wxWINDOW_VARIANT_SMALL );
71 
72     InitColours();
73 
74     return true;
75 }
76 
InitColours()77 void wxStatusBarMac::InitColours()
78 {
79     if ( WX_IS_MACOS_AVAILABLE(10, 14) )
80     {
81         if ( wxSystemSettings::GetAppearance().IsDark() )
82         {
83             m_textActive = wxColour(0xA9, 0xA9, 0xA9);
84             m_textInactive = wxColour(0x67, 0x67, 0x67);
85         }
86         else
87         {
88             m_textActive = wxColour(0x4B, 0x4B, 0x4B);
89             m_textInactive = wxColour(0xB1, 0xB1, 0xB1);
90         }
91     }
92     else // 10.10 Yosemite to 10.13:
93     {
94 
95         m_textActive = wxColour(0x40, 0x40, 0x40);
96         m_textInactive = wxColour(0x4B, 0x4B, 0x4B);
97     }
98 }
99 
OnPaint(wxPaintEvent & WXUNUSED (event))100 void wxStatusBarMac::OnPaint(wxPaintEvent& WXUNUSED(event))
101 {
102     wxPaintDC dc(this);
103 
104     // Notice that wxOSXGetKeyWindow (aka [NSApp keyWindow] used below is
105     // subtly different from IsActive() (aka [NSWindow iskeyWindow]): the
106     // former remains non-NULL if another application shows a temporary
107     // floating window or a status icon's menu is used. That's what we want: in
108     // that case, statusbar appearance shouldn't change. It also shouldn't
109     // change if a window-modal sheet attached to this window is key.
110     wxTopLevelWindow *tlw = wxDynamicCast(MacGetTopLevelWindow(), wxTopLevelWindow);
111     wxNonOwnedWindow* directKeyWindow = wxNonOwnedWindow::GetFromWXWindow(wxOSXGetKeyWindow());
112     wxWindow *keyWindow = directKeyWindow ? directKeyWindow->MacGetTopLevelWindow() : NULL;
113     while ( keyWindow && keyWindow != tlw )
114     {
115         wxDialog *dlg = wxDynamicCast(keyWindow, wxDialog);
116         if ( dlg && dlg->GetModality() == wxDIALOG_MODALITY_WINDOW_MODAL )
117             keyWindow = dlg->GetParent();
118         else
119             break;
120     }
121 
122     // Don't paint any background, that's handled by the OS. Only draw text:
123 
124     dc.SetTextForeground(tlw == keyWindow ? m_textActive : m_textInactive);
125 
126     if ( GetFont().IsOk() )
127         dc.SetFont(GetFont());
128     dc.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT);
129 
130     // compute char height only once for all panes:
131     int textHeight = dc.GetCharHeight();
132 
133     for ( size_t i = 0; i < m_panes.GetCount(); i ++ )
134         DrawField(dc, i, textHeight);
135 }
136 
MacHiliteChanged()137 void wxStatusBarMac::MacHiliteChanged()
138 {
139     Refresh();
140     Update();
141 }
142 
143 #endif // wxUSE_STATUSBAR
144 
145