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