]>
Commit | Line | Data |
---|---|---|
c801d85f | 1 | ///////////////////////////////////////////////////////////////////////////// |
ed791986 VZ |
2 | // Name: generic/statusbr.cpp |
3 | // Purpose: wxStatusBarGeneric class implementation | |
c801d85f KB |
4 | // Author: Julian Smart |
5 | // Modified by: | |
6 | // Created: 01/02/97 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart and Markus Holzem | |
ed791986 | 9 | // Licence: wxWindows license |
c801d85f KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "statusbr.h" | |
14 | #endif | |
15 | ||
16 | // For compilers that support precompilation, includes "wx.h". | |
17 | #include "wx/wxprec.h" | |
18 | ||
19 | #ifdef __BORLANDC__ | |
20 | #pragma hdrstop | |
21 | #endif | |
22 | ||
1e6feb95 | 23 | #if wxUSE_STATUSBAR |
ed791986 | 24 | |
c801d85f KB |
25 | #ifndef WX_PRECOMP |
26 | #include "wx/setup.h" | |
27 | #include "wx/frame.h" | |
28 | #include "wx/settings.h" | |
29 | #include "wx/dcclient.h" | |
30 | #endif | |
31 | ||
412e4edf | 32 | #include "wx/statusbr.h" |
c801d85f | 33 | |
84f68c21 VZ |
34 | // we only have to do it here when we use wxStatusBarGeneric in addition to the |
35 | // standard wxStatusBar class, if wxStatusBarGeneric is the same as | |
36 | // wxStatusBar, then the corresponding IMPLEMENT_DYNAMIC_CLASS is already in | |
37 | // common/statbar.cpp | |
38 | #if defined(__WXMAC__) || \ | |
39 | (defined(wxUSE_NATIVE_STATUSBAR) && wxUSE_NATIVE_STATUSBAR) | |
b64a8473 | 40 | #include "wx/generic/statusbr.h" |
c801d85f | 41 | |
b64a8473 VZ |
42 | IMPLEMENT_DYNAMIC_CLASS(wxStatusBarGeneric, wxWindow) |
43 | #endif // wxUSE_NATIVE_STATUSBAR | |
ed791986 | 44 | |
ed791986 VZ |
45 | BEGIN_EVENT_TABLE(wxStatusBarGeneric, wxWindow) |
46 | EVT_PAINT(wxStatusBarGeneric::OnPaint) | |
47 | EVT_SYS_COLOUR_CHANGED(wxStatusBarGeneric::OnSysColourChanged) | |
c801d85f | 48 | END_EVENT_TABLE() |
c801d85f KB |
49 | |
50 | // Default status border dimensions | |
51 | #define wxTHICK_LINE_BORDER 2 | |
52 | #define wxTHICK_LINE_WIDTH 1 | |
53 | ||
ed791986 | 54 | wxStatusBarGeneric::wxStatusBarGeneric() |
c801d85f | 55 | { |
c67daf87 | 56 | m_statusStrings = (wxString *) NULL; |
c801d85f KB |
57 | m_borderX = wxTHICK_LINE_BORDER; |
58 | m_borderY = wxTHICK_LINE_BORDER; | |
59 | } | |
60 | ||
ed791986 | 61 | wxStatusBarGeneric::~wxStatusBarGeneric() |
c801d85f | 62 | { |
f51f94ea VZ |
63 | # ifdef __WXMSW__ |
64 | SetFont(wxNullFont); | |
65 | # endif // MSW | |
66 | ||
f51f94ea VZ |
67 | if ( m_statusStrings ) |
68 | delete[] m_statusStrings; | |
c801d85f KB |
69 | } |
70 | ||
ed791986 VZ |
71 | bool wxStatusBarGeneric::Create(wxWindow *parent, |
72 | wxWindowID id, | |
73 | long style, | |
74 | const wxString& name) | |
c801d85f | 75 | { |
c67daf87 | 76 | m_statusStrings = (wxString *) NULL; |
c801d85f KB |
77 | m_borderX = wxTHICK_LINE_BORDER; |
78 | m_borderY = wxTHICK_LINE_BORDER; | |
79 | ||
ed791986 VZ |
80 | bool success = wxWindow::Create(parent, id, |
81 | wxDefaultPosition, wxDefaultSize, | |
82 | style | wxTAB_TRAVERSAL, name); | |
c801d85f | 83 | |
f90566f5 RR |
84 | // The status bar should have a themed background |
85 | SetThemeEnabled( TRUE ); | |
86 | ||
c801d85f | 87 | // Don't wish this to be found as a child |
7c74e7fe | 88 | #ifndef __WXMAC__ |
c0ed460c | 89 | parent->GetChildren().DeleteObject(this); |
7c74e7fe | 90 | #endif |
c801d85f KB |
91 | InitColours(); |
92 | ||
93 | SetFont(m_defaultStatusBarFont); | |
94 | ||
71e03035 VZ |
95 | // Set the height according to the font and the border size |
96 | wxClientDC dc(this); | |
97 | dc.SetFont(GetFont()); | |
98 | ||
99 | wxCoord y; | |
100 | dc.GetTextExtent(_T("X"), NULL, &y ); | |
101 | ||
102 | int height = (int)( (11*y)/10 + 2*GetBorderY()); | |
103 | ||
104 | SetSize(-1, -1, -1, height); | |
105 | ||
c801d85f KB |
106 | return success; |
107 | } | |
108 | ||
cc56206f | 109 | void wxStatusBarGeneric::SetFieldsCount(int number, const int *widths) |
c801d85f | 110 | { |
633d67bb VZ |
111 | if ( number != m_nFields ) |
112 | { | |
113 | m_nFields = number; | |
c801d85f | 114 | |
f51f94ea | 115 | delete[] m_statusStrings; |
633d67bb | 116 | m_statusStrings = new wxString[number]; |
633d67bb | 117 | } |
c801d85f | 118 | |
633d67bb | 119 | SetStatusWidths(number, widths); |
c801d85f KB |
120 | } |
121 | ||
ed791986 | 122 | void wxStatusBarGeneric::SetStatusText(const wxString& text, int number) |
c801d85f | 123 | { |
633d67bb VZ |
124 | wxCHECK_RET( (number >= 0) && (number < m_nFields), |
125 | _T("invalid status bar field index") ); | |
c801d85f | 126 | |
633d67bb | 127 | m_statusStrings[number] = text; |
c801d85f | 128 | |
f8a4fa4c VZ |
129 | wxRect rect; |
130 | GetFieldRect(number, rect); | |
f90566f5 RR |
131 | |
132 | Refresh( TRUE, &rect ); | |
c801d85f KB |
133 | } |
134 | ||
ed791986 | 135 | wxString wxStatusBarGeneric::GetStatusText(int n) const |
c801d85f | 136 | { |
ed791986 VZ |
137 | wxCHECK_MSG( (n >= 0) && (n < m_nFields), wxEmptyString, |
138 | _T("invalid status bar field index") ); | |
139 | ||
c801d85f KB |
140 | return m_statusStrings[n]; |
141 | } | |
142 | ||
ed791986 | 143 | void wxStatusBarGeneric::SetStatusWidths(int n, const int widths_field[]) |
c801d85f | 144 | { |
633d67bb VZ |
145 | // only set status widths, when n == number of statuswindows |
146 | wxCHECK_RET( n == m_nFields, _T("status bar field count mismatch") ); | |
147 | ||
148 | // delete the old widths in any case - this function may be used to reset | |
149 | // the widths to the default (all equal) | |
1f361cdd MB |
150 | // MBN: this is incompatible with at least wxMSW and wxMAC and not |
151 | // documented, but let's keep it for now | |
152 | ReinitWidths(); | |
633d67bb VZ |
153 | |
154 | if ( !widths_field ) | |
155 | { | |
156 | // not an error, see the comment above | |
f8a4fa4c | 157 | Refresh(); |
633d67bb VZ |
158 | return; |
159 | } | |
160 | ||
1f361cdd | 161 | wxStatusBarBase::SetStatusWidths(n, widths_field); |
c801d85f KB |
162 | } |
163 | ||
ed791986 | 164 | void wxStatusBarGeneric::OnPaint(wxPaintEvent& WXUNUSED(event) ) |
c801d85f KB |
165 | { |
166 | wxPaintDC dc(this); | |
167 | ||
5b3ed311 | 168 | |
c801d85f | 169 | int i; |
c0ed460c JS |
170 | if ( GetFont().Ok() ) |
171 | dc.SetFont(GetFont()); | |
c801d85f KB |
172 | dc.SetBackgroundMode(wxTRANSPARENT); |
173 | ||
28be2e8a | 174 | #ifdef __WXPM__ |
b34590eb DW |
175 | wxColour vColor; |
176 | ||
dd7d1435 | 177 | vColor.InitFromName("LIGHT GREY"); |
b34590eb | 178 | ::WinFillRect(dc.m_hPS, &dc.m_vRclPaint, vColor.GetPixel()); |
28be2e8a DW |
179 | #endif |
180 | ||
c801d85f | 181 | for ( i = 0; i < m_nFields; i ++ ) |
f51f94ea | 182 | DrawField(dc, i); |
e97f20a0 | 183 | |
28be2e8a DW |
184 | #ifdef __WXMSW__ |
185 | dc.SetFont(wxNullFont); | |
186 | #endif // MSW | |
c801d85f KB |
187 | } |
188 | ||
ed791986 | 189 | void wxStatusBarGeneric::DrawFieldText(wxDC& dc, int i) |
c801d85f KB |
190 | { |
191 | int leftMargin = 2; | |
192 | ||
16e93305 | 193 | wxRect rect; |
c801d85f KB |
194 | GetFieldRect(i, rect); |
195 | ||
196 | wxString text(GetStatusText(i)); | |
197 | ||
198 | long x, y; | |
199 | ||
200 | dc.GetTextExtent(text, &x, &y); | |
201 | ||
202 | int xpos = rect.x + leftMargin; | |
203 | int ypos = (int) (((rect.height - y) / 2 ) + rect.y + 0.5) ; | |
ed791986 | 204 | |
7c74e7fe | 205 | #if defined( __WXGTK__ ) || defined(__WXMAC__) |
92976ab6 RR |
206 | xpos++; |
207 | ypos++; | |
208 | #endif | |
c801d85f KB |
209 | |
210 | dc.SetClippingRegion(rect.x, rect.y, rect.width, rect.height); | |
211 | ||
212 | dc.DrawText(text, xpos, ypos); | |
213 | ||
214 | dc.DestroyClippingRegion(); | |
215 | } | |
216 | ||
ed791986 | 217 | void wxStatusBarGeneric::DrawField(wxDC& dc, int i) |
c801d85f | 218 | { |
16e93305 | 219 | wxRect rect; |
c801d85f KB |
220 | GetFieldRect(i, rect); |
221 | ||
222 | // Draw border | |
223 | // Have grey background, plus 3-d border - | |
224 | // One black rectangle. | |
225 | // Inside this, left and top sides - dark grey. Bottom and right - | |
226 | // white. | |
227 | ||
f51f94ea | 228 | dc.SetPen(m_hilightPen); |
c801d85f | 229 | |
b34590eb DW |
230 | #ifndef __WXPM__ |
231 | ||
c801d85f KB |
232 | // Right and bottom white lines |
233 | dc.DrawLine(rect.x + rect.width, rect.y, | |
234 | rect.x + rect.width, rect.y + rect.height); | |
235 | dc.DrawLine(rect.x + rect.width, rect.y + rect.height, | |
f51f94ea | 236 | rect.x, rect.y + rect.height); |
c801d85f | 237 | |
f51f94ea | 238 | dc.SetPen(m_mediumShadowPen); |
c801d85f KB |
239 | |
240 | // Left and top grey lines | |
241 | dc.DrawLine(rect.x, rect.y + rect.height, | |
f51f94ea | 242 | rect.x, rect.y); |
c801d85f | 243 | dc.DrawLine(rect.x, rect.y, |
f51f94ea | 244 | rect.x + rect.width, rect.y); |
b34590eb DW |
245 | #else |
246 | // Right | |
702c190d DW |
247 | dc.DrawLine(rect.x + rect.width, rect.y, |
248 | rect.x + rect.width, rect.y + rect.height + 2); | |
b34590eb | 249 | dc.SetPen(m_mediumShadowPen); |
702c190d DW |
250 | dc.DrawLine(rect.x + rect.width + 1, rect.y, |
251 | rect.x + rect.width + 1, rect.y + rect.height + 2); | |
252 | dc.DrawLine(rect.x + rect.width + 2, rect.y, | |
253 | rect.x + rect.width + 2, rect.y + rect.height + 2); | |
b34590eb | 254 | // Top |
702c190d DW |
255 | dc.DrawLine(rect.x + rect.width + 2, rect.y, |
256 | rect.x - 2, rect.y); | |
257 | dc.DrawLine(rect.x + rect.width + 1, rect.y - 1, | |
258 | rect.x - 2, rect.y - 1); | |
b34590eb | 259 | dc.SetPen(m_hilightPen); |
702c190d DW |
260 | dc.DrawLine(rect.x + rect.width, rect.y - 2, |
261 | rect.x - 2, rect.y - 2); | |
b34590eb DW |
262 | |
263 | #endif | |
c801d85f | 264 | |
f51f94ea | 265 | DrawFieldText(dc, i); |
c801d85f KB |
266 | } |
267 | ||
268 | // Get the position and size of the field's internal bounding rectangle | |
ed791986 | 269 | bool wxStatusBarGeneric::GetFieldRect(int n, wxRect& rect) const |
c801d85f | 270 | { |
ed791986 VZ |
271 | wxCHECK_MSG( (n >= 0) && (n < m_nFields), FALSE, |
272 | _T("invalid status bar field index") ); | |
c801d85f KB |
273 | |
274 | int width, height; | |
28be2e8a DW |
275 | #ifdef __WXPM__ |
276 | GetSize(&width, &height); | |
277 | #else | |
c801d85f | 278 | GetClientSize(&width, &height); |
28be2e8a | 279 | #endif |
c801d85f KB |
280 | |
281 | int i; | |
282 | int sum_of_nonvar = 0; | |
283 | int num_of_var = 0; | |
284 | bool do_same_width = FALSE; | |
285 | ||
286 | int fieldWidth = 0; | |
287 | int fieldPosition = 0; | |
288 | ||
289 | if (m_statusWidths) | |
290 | { | |
291 | // if sum(not variable Windows) > c_width - (20 points per variable_window) | |
292 | // then do_same_width = TRUE; | |
293 | for (i = 0; i < m_nFields; i++) | |
294 | { | |
295 | if (m_statusWidths[i] > 0) sum_of_nonvar += m_statusWidths[i]; | |
296 | else num_of_var++; | |
297 | } | |
298 | if (sum_of_nonvar > (width - 20*num_of_var)) do_same_width = TRUE; | |
299 | } | |
300 | else do_same_width = TRUE; | |
301 | if (do_same_width) | |
302 | { | |
303 | for (i = 0; i < m_nFields; i++) | |
304 | { | |
305 | fieldWidth = (int)(width/m_nFields); | |
f51f94ea VZ |
306 | fieldPosition = i*fieldWidth; |
307 | if ( i == n ) | |
308 | break; | |
c801d85f KB |
309 | } |
310 | } | |
311 | else // no_same_width | |
312 | { | |
313 | int *tempwidth = new int[m_nFields]; | |
314 | int temppos = 0; | |
315 | for (i = 0; i < m_nFields; i++) | |
316 | { | |
317 | if (m_statusWidths[i] > 0) tempwidth[i] = m_statusWidths[i]; | |
318 | else tempwidth[i] = (width - sum_of_nonvar) / num_of_var; | |
319 | } | |
320 | for (i = 0; i < m_nFields; i++) | |
321 | { | |
f51f94ea VZ |
322 | fieldWidth = tempwidth[i]; |
323 | fieldPosition = temppos; | |
c801d85f | 324 | |
f51f94ea | 325 | temppos += tempwidth[i]; |
c801d85f | 326 | |
f51f94ea VZ |
327 | if ( i == n ) |
328 | break; | |
c801d85f KB |
329 | } |
330 | delete [] tempwidth; | |
331 | } | |
332 | ||
333 | rect.x = fieldPosition + wxTHICK_LINE_BORDER; | |
f51f94ea | 334 | rect.y = wxTHICK_LINE_BORDER; |
c801d85f | 335 | |
f51f94ea VZ |
336 | rect.width = fieldWidth - 2 * wxTHICK_LINE_BORDER ; |
337 | rect.height = height - 2 * wxTHICK_LINE_BORDER ; | |
c801d85f | 338 | |
f51f94ea | 339 | return TRUE; |
c801d85f KB |
340 | } |
341 | ||
342 | // Initialize colours | |
ed791986 | 343 | void wxStatusBarGeneric::InitColours() |
c801d85f KB |
344 | { |
345 | // Shadow colours | |
5b3ed311 | 346 | #if defined(__WIN95__) |
a756f210 | 347 | wxColour mediumShadowColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW)); |
c801d85f KB |
348 | m_mediumShadowPen = wxPen(mediumShadowColour, 1, wxSOLID); |
349 | ||
a756f210 | 350 | wxColour hilightColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DHILIGHT)); |
c801d85f | 351 | m_hilightPen = wxPen(hilightColour, 1, wxSOLID); |
b34590eb | 352 | #elif defined(__WXPM__) |
dd7d1435 | 353 | m_mediumShadowPen = wxPen("DARK GREY", 1, wxSOLID); |
b34590eb | 354 | m_hilightPen = wxPen("WHITE", 1, wxSOLID); |
dd7d1435 DW |
355 | |
356 | wxColour vColour; | |
357 | ||
5e5390dd | 358 | vColour.Set(wxString("LIGHT GREY")); |
dd7d1435 | 359 | SetBackgroundColour(vColour); |
5e5390dd | 360 | vColour.Set(wxString("BLACK")); |
dd7d1435 DW |
361 | SetForegroundColour(vColour); |
362 | m_defaultStatusBarFont = *wxSMALL_FONT; | |
c801d85f KB |
363 | #else |
364 | m_mediumShadowPen = wxPen("GREY", 1, wxSOLID); | |
365 | m_hilightPen = wxPen("WHITE", 1, wxSOLID); | |
366 | #endif | |
367 | ||
dd7d1435 | 368 | #ifndef __WXPM__ |
a756f210 VS |
369 | m_defaultStatusBarFont = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); |
370 | SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)); | |
dd7d1435 | 371 | #endif |
c801d85f KB |
372 | } |
373 | ||
374 | // Responds to colour changes, and passes event on to children. | |
ed791986 | 375 | void wxStatusBarGeneric::OnSysColourChanged(wxSysColourChangedEvent& event) |
c801d85f KB |
376 | { |
377 | InitColours(); | |
378 | Refresh(); | |
379 | ||
380 | // Propagate the event to the non-top-level children | |
381 | wxWindow::OnSysColourChanged(event); | |
382 | } | |
383 | ||
ed791986 VZ |
384 | void wxStatusBarGeneric::SetMinHeight(int height) |
385 | { | |
386 | // check that this min height is not less than minimal height for the | |
387 | // current font | |
388 | wxClientDC dc(this); | |
389 | wxCoord y; | |
390 | dc.GetTextExtent( _T("X"), NULL, &y ); | |
391 | ||
392 | if ( height > (11*y)/10 ) | |
393 | { | |
394 | SetSize(-1, -1, -1, height + 2*m_borderY); | |
395 | } | |
396 | } | |
397 | ||
1e6feb95 | 398 | #endif // wxUSE_STATUSBAR |