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