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