]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/statbrma.cpp
6a8bd124ac4c88ba6234b921af799c6351448491
[wxWidgets.git] / src / mac / carbon / statbrma.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/statbarma.cpp
3 // Purpose: native implementation of wxStatusBar (optional)
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 1998-01-01
7 // RCS-ID: $Id$
8 // Copyright: (c) 1998 Stefan Csomor
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #include "wx/wxprec.h"
13
14 #include "wx/statusbr.h"
15
16 #ifndef WX_PRECOMP
17 #include "wx/dc.h"
18 #endif
19
20 #include "wx/dcclient.h"
21
22 #include "wx/mac/private.h"
23 #include "wx/toplevel.h"
24
25
26 BEGIN_EVENT_TABLE(wxStatusBarMac, wxStatusBarGeneric)
27 EVT_PAINT(wxStatusBarMac::OnPaint)
28 END_EVENT_TABLE()
29
30
31 wxStatusBarMac::wxStatusBarMac(wxWindow *parent,
32 wxWindowID id,
33 long style,
34 const wxString& name)
35 :
36 wxStatusBarGeneric()
37 {
38 SetParent( NULL );
39 Create( parent, id, style, name );
40 }
41
42 wxStatusBarMac::wxStatusBarMac()
43 :
44 wxStatusBarGeneric()
45 {
46 SetParent( NULL );
47 }
48
49 wxStatusBarMac::~wxStatusBarMac()
50 {
51 }
52
53 bool wxStatusBarMac::Create(wxWindow *parent, wxWindowID id,
54 long style ,
55 const wxString& name)
56 {
57 if ( !wxStatusBarGeneric::Create( parent, id, style, name ) )
58 return false;
59
60 if ( parent->MacGetTopLevelWindow()->MacGetMetalAppearance() )
61 MacSetBackgroundBrush( wxNullBrush );
62
63 // normal system font is too tall for fitting into the standard height
64 SetWindowVariant( wxWINDOW_VARIANT_SMALL );
65
66 return true;
67 }
68
69 void wxStatusBarMac::DrawFieldText(wxDC& dc, int i)
70 {
71 int w, h;
72 GetSize( &w , &h );
73 wxRect rect;
74 GetFieldRect( i, rect );
75
76 if ( !MacIsReallyHilited() )
77 dc.SetTextForeground( wxColour( 0x80, 0x80, 0x80 ) );
78
79 wxString text(GetStatusText( i ));
80
81 long x, y;
82
83 dc.GetTextExtent(text, &x, &y);
84
85 int leftMargin = 2;
86 int xpos = rect.x + leftMargin + 1;
87 int ypos = 1;
88
89 if ( MacGetTopLevelWindow()->MacGetMetalAppearance() )
90 ypos++;
91
92 dc.SetClippingRegion(rect.x, 0, rect.width, h);
93
94 dc.DrawText(text, xpos, ypos);
95
96 dc.DestroyClippingRegion();
97 }
98
99 void wxStatusBarMac::DrawField(wxDC& dc, int i)
100 {
101 DrawFieldText(dc, i);
102 }
103
104 void wxStatusBarMac::SetStatusText(const wxString& text, int number)
105 {
106 wxCHECK_RET( (number >= 0) && (number < m_nFields),
107 wxT("invalid status bar field index") );
108
109 if ( m_statusStrings[number] == text )
110 return ;
111
112 m_statusStrings[number] = text;
113 wxRect rect;
114 GetFieldRect(number, rect);
115 int w, h;
116 GetSize( &w, &h );
117 rect.y = 0;
118 rect.height = h ;
119 Refresh( true, &rect );
120 Update();
121 }
122
123 void wxStatusBarMac::OnPaint(wxPaintEvent& WXUNUSED(event))
124 {
125 wxPaintDC dc(this);
126 dc.Clear();
127
128 int major, minor;
129 wxGetOsVersion( &major, &minor );
130 int w, h;
131 GetSize( &w, &h );
132
133 if ( MacIsReallyHilited() )
134 {
135 wxPen white( *wxWHITE , 1 , wxSOLID );
136 if (major >= 10)
137 {
138 // Finder statusbar border color: (Project Builder similar is 9B9B9B)
139 if ( MacGetTopLevelWindow()->MacGetMetalAppearance() )
140 dc.SetPen(wxPen(wxColour(0x40, 0x40, 0x40), 1, wxSOLID));
141 else
142 dc.SetPen(wxPen(wxColour(0xB1, 0xB1, 0xB1), 1, wxSOLID));
143 }
144 else
145 {
146 wxPen black( *wxBLACK , 1 , wxSOLID );
147 dc.SetPen(black);
148 }
149
150 dc.DrawLine(0, 0, w, 0);
151 dc.SetPen(white);
152 dc.DrawLine(0, 1, w, 1);
153 }
154 else
155 {
156 if (major >= 10)
157 // Finder statusbar border color: (Project Builder similar is 9B9B9B)
158 dc.SetPen(wxPen(wxColour(0xB1, 0xB1, 0xB1), 1, wxSOLID));
159 else
160 dc.SetPen(wxPen(wxColour(0x80, 0x80, 0x80), 1, wxSOLID));
161
162 dc.DrawLine(0, 0, w, 0);
163 }
164
165 int i;
166 if ( GetFont().Ok() )
167 dc.SetFont(GetFont());
168 dc.SetBackgroundMode(wxTRANSPARENT);
169
170 for ( i = 0; i < m_nFields; i ++ )
171 DrawField(dc, i);
172 }
173
174 void wxStatusBarMac::MacHiliteChanged()
175 {
176 Refresh();
177 Update();
178 }