]>
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$ | |
6aa89a22 | 8 | // Copyright: (c) Julian Smart |
65571936 | 9 | // Licence: wxWindows licence |
c801d85f KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
14f355c2 | 12 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
c801d85f KB |
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 | ||
2b5f62a0 VZ |
32 | #ifdef __WXGTK20__ |
33 | #include "wx/gtk/private.h" | |
34 | #include "wx/gtk/win_gtk.h" | |
35 | #endif | |
36 | ||
412e4edf | 37 | #include "wx/statusbr.h" |
c801d85f | 38 | |
84f68c21 VZ |
39 | // we only have to do it here when we use wxStatusBarGeneric in addition to the |
40 | // standard wxStatusBar class, if wxStatusBarGeneric is the same as | |
41 | // wxStatusBar, then the corresponding IMPLEMENT_DYNAMIC_CLASS is already in | |
42 | // common/statbar.cpp | |
43 | #if defined(__WXMAC__) || \ | |
44 | (defined(wxUSE_NATIVE_STATUSBAR) && wxUSE_NATIVE_STATUSBAR) | |
b64a8473 | 45 | #include "wx/generic/statusbr.h" |
c801d85f | 46 | |
b64a8473 VZ |
47 | IMPLEMENT_DYNAMIC_CLASS(wxStatusBarGeneric, wxWindow) |
48 | #endif // wxUSE_NATIVE_STATUSBAR | |
ed791986 | 49 | |
ed791986 VZ |
50 | BEGIN_EVENT_TABLE(wxStatusBarGeneric, wxWindow) |
51 | EVT_PAINT(wxStatusBarGeneric::OnPaint) | |
2b5f62a0 VZ |
52 | EVT_LEFT_DOWN(wxStatusBarGeneric::OnLeftDown) |
53 | EVT_RIGHT_DOWN(wxStatusBarGeneric::OnRightDown) | |
ed791986 | 54 | EVT_SYS_COLOUR_CHANGED(wxStatusBarGeneric::OnSysColourChanged) |
c801d85f | 55 | END_EVENT_TABLE() |
c801d85f KB |
56 | |
57 | // Default status border dimensions | |
58 | #define wxTHICK_LINE_BORDER 2 | |
59 | #define wxTHICK_LINE_WIDTH 1 | |
60 | ||
390015c0 | 61 | void wxStatusBarGeneric::Init() |
c801d85f | 62 | { |
c801d85f KB |
63 | m_borderX = wxTHICK_LINE_BORDER; |
64 | m_borderY = wxTHICK_LINE_BORDER; | |
65 | } | |
66 | ||
ed791986 | 67 | wxStatusBarGeneric::~wxStatusBarGeneric() |
c801d85f | 68 | { |
390015c0 VZ |
69 | // VZ: what is this for? please comment... |
70 | #ifdef __WXMSW__ | |
387d96cc JS |
71 | // JACS: commenting out since it causes an assert |
72 | // and there seems no reason for it. | |
73 | // SetFont(wxNullFont); | |
390015c0 | 74 | #endif // MSW |
c801d85f KB |
75 | } |
76 | ||
ed791986 | 77 | bool wxStatusBarGeneric::Create(wxWindow *parent, |
76880b87 RL |
78 | wxWindowID id, |
79 | long style, | |
80 | const wxString& name) | |
c801d85f | 81 | { |
390015c0 VZ |
82 | if ( !wxWindow::Create(parent, id, |
83 | wxDefaultPosition, wxDefaultSize, | |
84 | style | wxTAB_TRAVERSAL, name) ) | |
ca65c044 | 85 | return false; |
c801d85f | 86 | |
f90566f5 | 87 | // The status bar should have a themed background |
ca65c044 | 88 | SetThemeEnabled( true ); |
f90566f5 | 89 | |
c801d85f | 90 | // Don't wish this to be found as a child |
7c74e7fe | 91 | #ifndef __WXMAC__ |
c0ed460c | 92 | parent->GetChildren().DeleteObject(this); |
7c74e7fe | 93 | #endif |
c801d85f | 94 | InitColours(); |
1ca21594 VS |
95 | |
96 | #ifdef __WXPM__ | |
97 | SetFont(*wxSMALL_FONT); | |
98 | #endif | |
c801d85f | 99 | |
71e03035 VZ |
100 | // Set the height according to the font and the border size |
101 | wxClientDC dc(this); | |
102 | dc.SetFont(GetFont()); | |
103 | ||
104 | wxCoord y; | |
105 | dc.GetTextExtent(_T("X"), NULL, &y ); | |
106 | ||
107 | int height = (int)( (11*y)/10 + 2*GetBorderY()); | |
108 | ||
422d0ff0 | 109 | SetSize(wxDefaultCoord, wxDefaultCoord, wxDefaultCoord, height); |
71e03035 | 110 | |
8aa2cea1 RD |
111 | SetFieldsCount(1); |
112 | ||
ca65c044 | 113 | return true; |
c801d85f KB |
114 | } |
115 | ||
595a9493 RD |
116 | |
117 | wxSize wxStatusBarGeneric::DoGetBestSize() const | |
118 | { | |
119 | int width, height; | |
120 | ||
121 | // best width is the width of the parent | |
122 | GetParent()->GetClientSize(&width, NULL); | |
123 | ||
124 | // best height is as calculated above in Create | |
125 | wxClientDC dc((wxWindow*)this); | |
126 | dc.SetFont(GetFont()); | |
127 | wxCoord y; | |
128 | dc.GetTextExtent(_T("X"), NULL, &y ); | |
129 | height = (int)( (11*y)/10 + 2*GetBorderY()); | |
130 | ||
131 | return wxSize(width, height); | |
ca65c044 | 132 | } |
595a9493 | 133 | |
cc56206f | 134 | void wxStatusBarGeneric::SetFieldsCount(int number, const int *widths) |
c801d85f | 135 | { |
390015c0 | 136 | wxASSERT_MSG( number >= 0, _T("negative number of fields in wxStatusBar?") ); |
76880b87 | 137 | |
893f25f2 JS |
138 | int i; |
139 | for(i = m_nFields; i < number; ++i) | |
76880b87 RL |
140 | m_statusStrings.Add( wxEmptyString ); |
141 | ||
893f25f2 | 142 | for (i = m_nFields - 1; i >= number; --i) |
390015c0 | 143 | m_statusStrings.RemoveAt(i); |
76880b87 | 144 | |
f9a961e1 DS |
145 | // forget the old cached pixel widths |
146 | m_widthsAbs.Empty(); | |
147 | ||
d64b1c76 DS |
148 | wxStatusBarBase::SetFieldsCount(number, widths); |
149 | ||
76880b87 RL |
150 | wxASSERT_MSG( m_nFields == (int)m_statusStrings.GetCount(), |
151 | _T("This really should never happen, can we do away with m_nFields here?") ); | |
c801d85f KB |
152 | } |
153 | ||
ed791986 | 154 | void wxStatusBarGeneric::SetStatusText(const wxString& text, int number) |
c801d85f | 155 | { |
633d67bb VZ |
156 | wxCHECK_RET( (number >= 0) && (number < m_nFields), |
157 | _T("invalid status bar field index") ); | |
c801d85f | 158 | |
87ff599d JS |
159 | wxString oldText = m_statusStrings[number]; |
160 | if (oldText != text) | |
161 | { | |
162 | m_statusStrings[number] = text; | |
c801d85f | 163 | |
87ff599d JS |
164 | wxRect rect; |
165 | GetFieldRect(number, rect); | |
e715f4e7 | 166 | |
ca65c044 | 167 | Refresh( true, &rect ); |
87ff599d | 168 | } |
c801d85f KB |
169 | } |
170 | ||
ed791986 | 171 | wxString wxStatusBarGeneric::GetStatusText(int n) const |
c801d85f | 172 | { |
ed791986 VZ |
173 | wxCHECK_MSG( (n >= 0) && (n < m_nFields), wxEmptyString, |
174 | _T("invalid status bar field index") ); | |
175 | ||
c801d85f KB |
176 | return m_statusStrings[n]; |
177 | } | |
178 | ||
ed791986 | 179 | void wxStatusBarGeneric::SetStatusWidths(int n, const int widths_field[]) |
c801d85f | 180 | { |
633d67bb VZ |
181 | // only set status widths, when n == number of statuswindows |
182 | wxCHECK_RET( n == m_nFields, _T("status bar field count mismatch") ); | |
183 | ||
184 | // delete the old widths in any case - this function may be used to reset | |
185 | // the widths to the default (all equal) | |
1f361cdd MB |
186 | // MBN: this is incompatible with at least wxMSW and wxMAC and not |
187 | // documented, but let's keep it for now | |
188 | ReinitWidths(); | |
633d67bb | 189 | |
390015c0 VZ |
190 | // forget the old cached pixel widths |
191 | m_widthsAbs.Empty(); | |
192 | ||
633d67bb VZ |
193 | if ( !widths_field ) |
194 | { | |
195 | // not an error, see the comment above | |
f8a4fa4c | 196 | Refresh(); |
633d67bb VZ |
197 | return; |
198 | } | |
199 | ||
1f361cdd | 200 | wxStatusBarBase::SetStatusWidths(n, widths_field); |
c801d85f KB |
201 | } |
202 | ||
ed791986 | 203 | void wxStatusBarGeneric::OnPaint(wxPaintEvent& WXUNUSED(event) ) |
c801d85f | 204 | { |
2b5f62a0 | 205 | wxPaintDC dc(this); |
c801d85f | 206 | |
2b5f62a0 VZ |
207 | #ifdef __WXGTK20__ |
208 | // Draw grip first | |
209 | if (HasFlag( wxST_SIZEGRIP )) | |
210 | { | |
211 | int width, height; | |
212 | GetClientSize(&width, &height); | |
8aa2cea1 | 213 | |
2b5f62a0 VZ |
214 | gtk_paint_resize_grip( m_widget->style, |
215 | GTK_PIZZA(m_wxwindow)->bin_window, | |
216 | (GtkStateType) GTK_WIDGET_STATE (m_widget), | |
217 | NULL, | |
218 | m_widget, | |
219 | "statusbar", | |
220 | GDK_WINDOW_EDGE_SOUTH_EAST, | |
221 | width-height-2, 1, height-2, height-3 ); | |
8aa2cea1 | 222 | |
2b5f62a0 VZ |
223 | } |
224 | #endif | |
5b3ed311 | 225 | |
2b5f62a0 VZ |
226 | if (GetFont().Ok()) |
227 | dc.SetFont(GetFont()); | |
8aa2cea1 | 228 | |
c801d85f KB |
229 | dc.SetBackgroundMode(wxTRANSPARENT); |
230 | ||
28be2e8a | 231 | #ifdef __WXPM__ |
2b5f62a0 | 232 | wxColour vColor; |
b34590eb | 233 | |
e715f4e7 | 234 | vColor = wxSystemSettings::GetColour(wxSYS_COLOUR_MENUBAR); |
b34590eb | 235 | ::WinFillRect(dc.m_hPS, &dc.m_vRclPaint, vColor.GetPixel()); |
28be2e8a DW |
236 | #endif |
237 | ||
2b5f62a0 VZ |
238 | for (int i = 0; i < m_nFields; i ++) |
239 | DrawField(dc, i); | |
c801d85f KB |
240 | } |
241 | ||
ed791986 | 242 | void wxStatusBarGeneric::DrawFieldText(wxDC& dc, int i) |
c801d85f KB |
243 | { |
244 | int leftMargin = 2; | |
245 | ||
16e93305 | 246 | wxRect rect; |
c801d85f KB |
247 | GetFieldRect(i, rect); |
248 | ||
249 | wxString text(GetStatusText(i)); | |
250 | ||
251 | long x, y; | |
252 | ||
253 | dc.GetTextExtent(text, &x, &y); | |
254 | ||
255 | int xpos = rect.x + leftMargin; | |
256 | int ypos = (int) (((rect.height - y) / 2 ) + rect.y + 0.5) ; | |
ed791986 | 257 | |
7c74e7fe | 258 | #if defined( __WXGTK__ ) || defined(__WXMAC__) |
92976ab6 RR |
259 | xpos++; |
260 | ypos++; | |
261 | #endif | |
c801d85f KB |
262 | |
263 | dc.SetClippingRegion(rect.x, rect.y, rect.width, rect.height); | |
264 | ||
265 | dc.DrawText(text, xpos, ypos); | |
266 | ||
267 | dc.DestroyClippingRegion(); | |
268 | } | |
269 | ||
ed791986 | 270 | void wxStatusBarGeneric::DrawField(wxDC& dc, int i) |
c801d85f | 271 | { |
2b5f62a0 VZ |
272 | wxRect rect; |
273 | GetFieldRect(i, rect); | |
c801d85f | 274 | |
c2919ab3 VZ |
275 | int style = wxSB_NORMAL; |
276 | if (m_statusStyles) | |
277 | style = m_statusStyles[i]; | |
c801d85f | 278 | |
c2919ab3 VZ |
279 | if (style != wxSB_FLAT) |
280 | { | |
281 | // Draw border | |
282 | // For wxSB_NORMAL: | |
283 | // Have grey background, plus 3-d border - | |
284 | // One black rectangle. | |
285 | // Inside this, left and top sides - dark grey. Bottom and right - | |
286 | // white. | |
287 | // Reverse it for wxSB_RAISED | |
288 | ||
289 | dc.SetPen((style == wxSB_RAISED) ? m_mediumShadowPen : m_hilightPen); | |
290 | ||
291 | #ifndef __WXPM__ | |
292 | ||
293 | // Right and bottom lines | |
294 | dc.DrawLine(rect.x + rect.width, rect.y, | |
295 | rect.x + rect.width, rect.y + rect.height); | |
296 | dc.DrawLine(rect.x + rect.width, rect.y + rect.height, | |
297 | rect.x, rect.y + rect.height); | |
298 | ||
299 | dc.SetPen((style == wxSB_RAISED) ? m_hilightPen : m_mediumShadowPen); | |
300 | ||
301 | // Left and top lines | |
302 | dc.DrawLine(rect.x, rect.y + rect.height, | |
303 | rect.x, rect.y); | |
304 | dc.DrawLine(rect.x, rect.y, | |
305 | rect.x + rect.width, rect.y); | |
306 | #else | |
307 | ||
308 | dc.DrawLine(rect.x + rect.width, rect.height + 2, | |
309 | rect.x, rect.height + 2); | |
310 | dc.DrawLine(rect.x + rect.width, rect.y, | |
311 | rect.x + rect.width, rect.y + rect.height); | |
312 | ||
313 | dc.SetPen((style == wxSB_RAISED) ? m_hilightPen : m_mediumShadowPen); | |
314 | dc.DrawLine(rect.x, rect.y, | |
315 | rect.x + rect.width, rect.y); | |
316 | dc.DrawLine(rect.x, rect.y + rect.height, | |
317 | rect.x, rect.y); | |
b34590eb DW |
318 | |
319 | #endif | |
c2919ab3 | 320 | } |
c801d85f | 321 | |
f51f94ea | 322 | DrawFieldText(dc, i); |
c801d85f KB |
323 | } |
324 | ||
325 | // Get the position and size of the field's internal bounding rectangle | |
ed791986 | 326 | bool wxStatusBarGeneric::GetFieldRect(int n, wxRect& rect) const |
c801d85f | 327 | { |
ca65c044 | 328 | wxCHECK_MSG( (n >= 0) && (n < m_nFields), false, |
390015c0 | 329 | _T("invalid status bar field index") ); |
c801d85f | 330 | |
390015c0 VZ |
331 | // FIXME: workarounds for OS/2 bugs have nothing to do here (VZ) |
332 | int width, height; | |
28be2e8a | 333 | #ifdef __WXPM__ |
390015c0 | 334 | GetSize(&width, &height); |
28be2e8a | 335 | #else |
390015c0 | 336 | GetClientSize(&width, &height); |
28be2e8a | 337 | #endif |
c801d85f | 338 | |
2b5f62a0 VZ |
339 | // we cache m_widthsAbs between calls and recompute it if client |
340 | // width has changed (or when it is initially empty) | |
341 | if ( m_widthsAbs.IsEmpty() || (m_lastClientWidth != width) ) | |
c801d85f | 342 | { |
390015c0 VZ |
343 | wxConstCast(this, wxStatusBarGeneric)-> |
344 | m_widthsAbs = CalculateAbsWidths(width); | |
2b5f62a0 VZ |
345 | // remember last width for which we have recomputed the widths in pixels |
346 | wxConstCast(this, wxStatusBarGeneric)-> | |
347 | m_lastClientWidth = width; | |
c801d85f | 348 | } |
c801d85f | 349 | |
390015c0 VZ |
350 | rect.x = 0; |
351 | for ( int i = 0; i < n; i++ ) | |
352 | { | |
353 | rect.x += m_widthsAbs[i]; | |
c801d85f | 354 | } |
c801d85f | 355 | |
390015c0 VZ |
356 | rect.x += m_borderX; |
357 | rect.y = m_borderY; | |
c801d85f | 358 | |
390015c0 VZ |
359 | rect.width = m_widthsAbs[n] - 2*m_borderX; |
360 | rect.height = height - 2*m_borderY; | |
c801d85f | 361 | |
ca65c044 | 362 | return true; |
c801d85f KB |
363 | } |
364 | ||
365 | // Initialize colours | |
ed791986 | 366 | void wxStatusBarGeneric::InitColours() |
c801d85f KB |
367 | { |
368 | // Shadow colours | |
44c44c82 | 369 | #if defined(__WIN95__) || defined(__WXMAC__) |
a756f210 | 370 | wxColour mediumShadowColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW)); |
c801d85f KB |
371 | m_mediumShadowPen = wxPen(mediumShadowColour, 1, wxSOLID); |
372 | ||
a756f210 | 373 | wxColour hilightColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DHILIGHT)); |
c801d85f | 374 | m_hilightPen = wxPen(hilightColour, 1, wxSOLID); |
b34590eb | 375 | #elif defined(__WXPM__) |
e715f4e7 | 376 | m_mediumShadowPen = wxPen(wxColour(127, 127, 127), 1, wxSOLID); |
b34590eb | 377 | m_hilightPen = wxPen("WHITE", 1, wxSOLID); |
dd7d1435 DW |
378 | |
379 | wxColour vColour; | |
380 | ||
5e5390dd | 381 | vColour.Set(wxString("LIGHT GREY")); |
dd7d1435 | 382 | SetBackgroundColour(vColour); |
5e5390dd | 383 | vColour.Set(wxString("BLACK")); |
dd7d1435 | 384 | SetForegroundColour(vColour); |
c801d85f KB |
385 | #else |
386 | m_mediumShadowPen = wxPen("GREY", 1, wxSOLID); | |
387 | m_hilightPen = wxPen("WHITE", 1, wxSOLID); | |
388 | #endif | |
c801d85f KB |
389 | } |
390 | ||
391 | // Responds to colour changes, and passes event on to children. | |
ed791986 | 392 | void wxStatusBarGeneric::OnSysColourChanged(wxSysColourChangedEvent& event) |
c801d85f KB |
393 | { |
394 | InitColours(); | |
c801d85f KB |
395 | |
396 | // Propagate the event to the non-top-level children | |
397 | wxWindow::OnSysColourChanged(event); | |
398 | } | |
399 | ||
ed791986 VZ |
400 | void wxStatusBarGeneric::SetMinHeight(int height) |
401 | { | |
402 | // check that this min height is not less than minimal height for the | |
403 | // current font | |
404 | wxClientDC dc(this); | |
405 | wxCoord y; | |
2b5f62a0 | 406 | dc.GetTextExtent( wxT("X"), NULL, &y ); |
ed791986 VZ |
407 | |
408 | if ( height > (11*y)/10 ) | |
409 | { | |
422d0ff0 | 410 | SetSize(wxDefaultCoord, wxDefaultCoord, wxDefaultCoord, height + 2*m_borderY); |
ed791986 VZ |
411 | } |
412 | } | |
413 | ||
2b5f62a0 | 414 | void wxStatusBarGeneric::OnLeftDown(wxMouseEvent& event) |
390015c0 | 415 | { |
2b5f62a0 VZ |
416 | #ifdef __WXGTK20__ |
417 | int width, height; | |
418 | GetClientSize(&width, &height); | |
8aa2cea1 | 419 | |
2b5f62a0 VZ |
420 | if (HasFlag( wxST_SIZEGRIP ) && (event.GetX() > width-height)) |
421 | { | |
422 | GtkWidget *ancestor = gtk_widget_get_toplevel( m_widget ); | |
423 | ||
424 | if (!GTK_IS_WINDOW (ancestor)) | |
425 | return; | |
390015c0 | 426 | |
2b5f62a0 VZ |
427 | GdkWindow *source = GTK_PIZZA(m_wxwindow)->bin_window; |
428 | ||
429 | int org_x = 0; | |
430 | int org_y = 0; | |
431 | gdk_window_get_origin( source, &org_x, &org_y ); | |
432 | ||
433 | gtk_window_begin_resize_drag (GTK_WINDOW (ancestor), | |
434 | GDK_WINDOW_EDGE_SOUTH_EAST, | |
435 | 1, | |
8aa2cea1 RD |
436 | org_x + event.GetX(), |
437 | org_y + event.GetY(), | |
2b5f62a0 VZ |
438 | 0); |
439 | } | |
440 | else | |
441 | { | |
ca65c044 | 442 | event.Skip( true ); |
2b5f62a0 VZ |
443 | } |
444 | #else | |
ca65c044 | 445 | event.Skip( true ); |
2b5f62a0 VZ |
446 | #endif |
447 | } | |
448 | ||
449 | void wxStatusBarGeneric::OnRightDown(wxMouseEvent& event) | |
450 | { | |
451 | #ifdef __WXGTK20__ | |
452 | int width, height; | |
453 | GetClientSize(&width, &height); | |
8aa2cea1 | 454 | |
2b5f62a0 VZ |
455 | if (HasFlag( wxST_SIZEGRIP ) && (event.GetX() > width-height)) |
456 | { | |
457 | GtkWidget *ancestor = gtk_widget_get_toplevel( m_widget ); | |
458 | ||
459 | if (!GTK_IS_WINDOW (ancestor)) | |
460 | return; | |
461 | ||
462 | GdkWindow *source = GTK_PIZZA(m_wxwindow)->bin_window; | |
463 | ||
464 | int org_x = 0; | |
465 | int org_y = 0; | |
466 | gdk_window_get_origin( source, &org_x, &org_y ); | |
8aa2cea1 | 467 | |
2b5f62a0 VZ |
468 | gtk_window_begin_move_drag (GTK_WINDOW (ancestor), |
469 | 2, | |
8aa2cea1 RD |
470 | org_x + event.GetX(), |
471 | org_y + event.GetY(), | |
2b5f62a0 VZ |
472 | 0); |
473 | } | |
474 | else | |
475 | { | |
ca65c044 | 476 | event.Skip( true ); |
2b5f62a0 VZ |
477 | } |
478 | #else | |
ca65c044 | 479 | event.Skip( true ); |
2b5f62a0 | 480 | #endif |
390015c0 VZ |
481 | } |
482 | ||
1e6feb95 | 483 | #endif // wxUSE_STATUSBAR |
76880b87 | 484 |