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