]>
Commit | Line | Data |
---|---|---|
489468fe | 1 | /////////////////////////////////////////////////////////////////////////////// |
524c47aa | 2 | // Name: src/osx/carbon/statbarma.cpp |
489468fe SC |
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 | #if wxUSE_STATUSBAR | |
15 | ||
16 | #include "wx/statusbr.h" | |
17 | ||
18 | #ifndef WX_PRECOMP | |
19 | #include "wx/dc.h" | |
20 | #include "wx/dcclient.h" | |
21 | #include "wx/toplevel.h" | |
22 | #endif | |
23 | ||
1f0c8f31 | 24 | #include "wx/osx/private.h" |
489468fe | 25 | |
0cd15959 FM |
26 | // Margin between the field text and the field rect |
27 | #define wxFIELD_TEXT_MARGIN 2 | |
28 | ||
489468fe SC |
29 | |
30 | BEGIN_EVENT_TABLE(wxStatusBarMac, wxStatusBarGeneric) | |
31 | EVT_PAINT(wxStatusBarMac::OnPaint) | |
32 | END_EVENT_TABLE() | |
33 | ||
34 | ||
35 | wxStatusBarMac::wxStatusBarMac(wxWindow *parent, | |
36 | wxWindowID id, | |
37 | long style, | |
38 | const wxString& name) | |
39 | : | |
40 | wxStatusBarGeneric() | |
41 | { | |
42 | SetParent( NULL ); | |
43 | Create( parent, id, style, name ); | |
44 | } | |
45 | ||
46 | wxStatusBarMac::wxStatusBarMac() | |
47 | : | |
48 | wxStatusBarGeneric() | |
49 | { | |
50 | SetParent( NULL ); | |
51 | } | |
52 | ||
53 | wxStatusBarMac::~wxStatusBarMac() | |
54 | { | |
55 | } | |
56 | ||
57 | bool wxStatusBarMac::Create(wxWindow *parent, wxWindowID id, | |
58 | long style , | |
59 | const wxString& name) | |
60 | { | |
61 | if ( !wxStatusBarGeneric::Create( parent, id, style, name ) ) | |
62 | return false; | |
63 | ||
b2680ced | 64 | if ( parent->MacGetTopLevelWindow()->GetExtraStyle() & wxFRAME_EX_METAL ) |
489468fe SC |
65 | SetBackgroundStyle( wxBG_STYLE_TRANSPARENT ); |
66 | ||
67 | // normal system font is too tall for fitting into the standard height | |
68 | SetWindowVariant( wxWINDOW_VARIANT_SMALL ); | |
69 | ||
70 | return true; | |
71 | } | |
72 | ||
0cd15959 | 73 | void wxStatusBarMac::DrawFieldText(wxDC& dc, const wxRect& rect, int i, int textHeight) |
489468fe SC |
74 | { |
75 | int w, h; | |
76 | GetSize( &w , &h ); | |
489468fe SC |
77 | |
78 | if ( !MacIsReallyHilited() ) | |
79 | dc.SetTextForeground( wxColour( 0x80, 0x80, 0x80 ) ); | |
80 | ||
81 | wxString text(GetStatusText( i )); | |
82 | ||
0cd15959 FM |
83 | /*wxCoord x, y; |
84 | dc.GetTextExtent(text, &x, &y); -- seems unused (FM)*/ | |
489468fe | 85 | |
0cd15959 | 86 | int xpos = rect.x + wxFIELD_TEXT_MARGIN + 1; |
489468fe SC |
87 | int ypos = 1; |
88 | ||
b2680ced | 89 | if ( MacGetTopLevelWindow()->GetExtraStyle() & wxFRAME_EX_METAL ) |
489468fe SC |
90 | ypos++; |
91 | ||
92 | dc.SetClippingRegion(rect.x, 0, rect.width, h); | |
489468fe | 93 | dc.DrawText(text, xpos, ypos); |
489468fe SC |
94 | dc.DestroyClippingRegion(); |
95 | } | |
96 | ||
0cd15959 | 97 | void wxStatusBarMac::DrawField(wxDC& dc, int i, int textHeight) |
489468fe | 98 | { |
0cd15959 FM |
99 | wxRect rect; |
100 | GetFieldRect(i, rect); | |
101 | ||
102 | DrawFieldText(dc, rect, i, textHeight); | |
489468fe SC |
103 | } |
104 | ||
105 | void wxStatusBarMac::SetStatusText(const wxString& text, int number) | |
106 | { | |
0cd15959 FM |
107 | // NOTE: seems this function is identic to wxStatusBarGeneric::SetStatusText; |
108 | // probably can be removed without problems (FM) | |
109 | ||
7b6fefbe | 110 | wxCHECK_RET( (number >= 0) && ((size_t)number < m_panes.GetCount()), |
489468fe SC |
111 | wxT("invalid status bar field index") ); |
112 | ||
0cd15959 FM |
113 | if ( GetStatusText(number) == text ) |
114 | return; | |
115 | ||
116 | wxStatusBarGeneric::SetStatusText(text, number); | |
489468fe | 117 | |
489468fe SC |
118 | wxRect rect; |
119 | GetFieldRect(number, rect); | |
0cd15959 | 120 | |
489468fe SC |
121 | int w, h; |
122 | GetSize( &w, &h ); | |
0cd15959 | 123 | |
489468fe SC |
124 | rect.y = 0; |
125 | rect.height = h ; | |
0cd15959 | 126 | |
489468fe SC |
127 | Refresh( true, &rect ); |
128 | Update(); | |
129 | } | |
130 | ||
131 | void wxStatusBarMac::OnPaint(wxPaintEvent& WXUNUSED(event)) | |
132 | { | |
133 | wxPaintDC dc(this); | |
134 | dc.Clear(); | |
135 | ||
136 | int major, minor; | |
137 | wxGetOsVersion( &major, &minor ); | |
138 | int w, h; | |
139 | GetSize( &w, &h ); | |
140 | ||
141 | if ( MacIsReallyHilited() ) | |
142 | { | |
143 | wxPen white( *wxWHITE , 1 , wxSOLID ); | |
144 | if (major >= 10) | |
145 | { | |
146 | // Finder statusbar border color: (Project Builder similar is 9B9B9B) | |
b2680ced | 147 | if ( MacGetTopLevelWindow()->GetExtraStyle() & wxFRAME_EX_METAL ) |
489468fe SC |
148 | dc.SetPen(wxPen(wxColour(0x40, 0x40, 0x40), 1, wxSOLID)); |
149 | else | |
150 | dc.SetPen(wxPen(wxColour(0xB1, 0xB1, 0xB1), 1, wxSOLID)); | |
151 | } | |
152 | else | |
153 | { | |
154 | wxPen black( *wxBLACK , 1 , wxSOLID ); | |
155 | dc.SetPen(black); | |
156 | } | |
157 | ||
158 | dc.DrawLine(0, 0, w, 0); | |
159 | dc.SetPen(white); | |
160 | dc.DrawLine(0, 1, w, 1); | |
161 | } | |
162 | else | |
163 | { | |
164 | if (major >= 10) | |
165 | // Finder statusbar border color: (Project Builder similar is 9B9B9B) | |
166 | dc.SetPen(wxPen(wxColour(0xB1, 0xB1, 0xB1), 1, wxSOLID)); | |
167 | else | |
168 | dc.SetPen(wxPen(wxColour(0x80, 0x80, 0x80), 1, wxSOLID)); | |
169 | ||
170 | dc.DrawLine(0, 0, w, 0); | |
171 | } | |
172 | ||
0cd15959 | 173 | if ( GetFont().IsOk() ) |
489468fe SC |
174 | dc.SetFont(GetFont()); |
175 | dc.SetBackgroundMode(wxTRANSPARENT); | |
176 | ||
0cd15959 FM |
177 | // compute char height only once for all panes: |
178 | int textHeight = dc.GetCharHeight(); | |
179 | ||
7b6fefbe | 180 | for ( size_t i = 0; i < m_panes.GetCount(); i ++ ) |
0cd15959 | 181 | DrawField(dc, i, textHeight); |
489468fe SC |
182 | } |
183 | ||
184 | void wxStatusBarMac::MacHiliteChanged() | |
185 | { | |
186 | Refresh(); | |
187 | Update(); | |
188 | } | |
189 | ||
190 | #endif // wxUSE_STATUSBAR | |
191 |