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