]> git.saurik.com Git - wxWidgets.git/blame - src/generic/statusbr.cpp
Added list style to text attributes, independent from paragraph style
[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);
fc2d4209
RR
202
203 if (GetLayoutDirection() == wxLayout_RightToLeft)
204 {
205 gtk_paint_resize_grip( m_widget->style,
206 GTK_PIZZA(m_wxwindow)->bin_window,
207 (GtkStateType) GTK_WIDGET_STATE (m_widget),
208 NULL,
209 m_widget,
210 "statusbar",
211 GDK_WINDOW_EDGE_SOUTH_WEST,
212 2, 2, height-2, height-4 );
213 }
214 else
215 {
216 gtk_paint_resize_grip( m_widget->style,
2b5f62a0
VZ
217 GTK_PIZZA(m_wxwindow)->bin_window,
218 (GtkStateType) GTK_WIDGET_STATE (m_widget),
219 NULL,
220 m_widget,
221 "statusbar",
222 GDK_WINDOW_EDGE_SOUTH_EAST,
fc2d4209
RR
223 width-height-2, 2, height-2, height-4 );
224 }
2b5f62a0
VZ
225 }
226#endif
5b3ed311 227
48f7ffbe 228 if (GetFont().Ok())
2b5f62a0 229 dc.SetFont(GetFont());
8aa2cea1 230
48f7ffbe 231 dc.SetBackgroundMode(wxTRANSPARENT);
c801d85f 232
28be2e8a 233#ifdef __WXPM__
48f7ffbe 234 wxColour vColor;
b34590eb 235
48f7ffbe
WS
236 vColor = wxSystemSettings::GetColour(wxSYS_COLOUR_MENUBAR);
237 ::WinFillRect(dc.m_hPS, &dc.m_vRclPaint, vColor.GetPixel());
28be2e8a
DW
238#endif
239
48f7ffbe 240 for (int i = 0; i < m_nFields; i ++)
2b5f62a0 241 DrawField(dc, i);
c801d85f
KB
242}
243
ed791986 244void wxStatusBarGeneric::DrawFieldText(wxDC& dc, int i)
c801d85f 245{
48f7ffbe 246 int leftMargin = 2;
c801d85f 247
48f7ffbe
WS
248 wxRect rect;
249 GetFieldRect(i, rect);
c801d85f 250
48f7ffbe 251 wxString text(GetStatusText(i));
c801d85f 252
8d7eaf91 253 long x = 0, y = 0;
c801d85f 254
48f7ffbe 255 dc.GetTextExtent(text, &x, &y);
c801d85f 256
48f7ffbe
WS
257 int xpos = rect.x + leftMargin;
258 int ypos = (int) (((rect.height - y) / 2 ) + rect.y + 0.5) ;
ed791986 259
7c74e7fe 260#if defined( __WXGTK__ ) || defined(__WXMAC__)
48f7ffbe
WS
261 xpos++;
262 ypos++;
92976ab6 263#endif
c801d85f 264
48f7ffbe 265 dc.SetClippingRegion(rect.x, rect.y, rect.width, rect.height);
c801d85f 266
48f7ffbe 267 dc.DrawText(text, xpos, ypos);
c801d85f 268
48f7ffbe 269 dc.DestroyClippingRegion();
c801d85f
KB
270}
271
ed791986 272void wxStatusBarGeneric::DrawField(wxDC& dc, int i)
c801d85f 273{
2b5f62a0
VZ
274 wxRect rect;
275 GetFieldRect(i, rect);
c801d85f 276
c2919ab3
VZ
277 int style = wxSB_NORMAL;
278 if (m_statusStyles)
279 style = m_statusStyles[i];
c801d85f 280
c2919ab3
VZ
281 if (style != wxSB_FLAT)
282 {
283 // Draw border
284 // For wxSB_NORMAL:
285 // Have grey background, plus 3-d border -
286 // One black rectangle.
287 // Inside this, left and top sides - dark grey. Bottom and right -
288 // white.
289 // Reverse it for wxSB_RAISED
290
291 dc.SetPen((style == wxSB_RAISED) ? m_mediumShadowPen : m_hilightPen);
292
293 #ifndef __WXPM__
294
295 // Right and bottom lines
296 dc.DrawLine(rect.x + rect.width, rect.y,
297 rect.x + rect.width, rect.y + rect.height);
298 dc.DrawLine(rect.x + rect.width, rect.y + rect.height,
299 rect.x, rect.y + rect.height);
300
301 dc.SetPen((style == wxSB_RAISED) ? m_hilightPen : m_mediumShadowPen);
302
303 // Left and top lines
304 dc.DrawLine(rect.x, rect.y + rect.height,
305 rect.x, rect.y);
306 dc.DrawLine(rect.x, rect.y,
307 rect.x + rect.width, rect.y);
308 #else
309
310 dc.DrawLine(rect.x + rect.width, rect.height + 2,
311 rect.x, rect.height + 2);
312 dc.DrawLine(rect.x + rect.width, rect.y,
313 rect.x + rect.width, rect.y + rect.height);
314
315 dc.SetPen((style == wxSB_RAISED) ? m_hilightPen : m_mediumShadowPen);
316 dc.DrawLine(rect.x, rect.y,
317 rect.x + rect.width, rect.y);
318 dc.DrawLine(rect.x, rect.y + rect.height,
319 rect.x, rect.y);
b34590eb
DW
320
321#endif
c2919ab3 322 }
c801d85f 323
f51f94ea 324 DrawFieldText(dc, i);
c801d85f
KB
325}
326
327 // Get the position and size of the field's internal bounding rectangle
ed791986 328bool wxStatusBarGeneric::GetFieldRect(int n, wxRect& rect) const
c801d85f 329{
ca65c044 330 wxCHECK_MSG( (n >= 0) && (n < m_nFields), false,
390015c0 331 _T("invalid status bar field index") );
c801d85f 332
390015c0
VZ
333 // FIXME: workarounds for OS/2 bugs have nothing to do here (VZ)
334 int width, height;
28be2e8a 335#ifdef __WXPM__
390015c0 336 GetSize(&width, &height);
28be2e8a 337#else
390015c0 338 GetClientSize(&width, &height);
28be2e8a 339#endif
c801d85f 340
2b5f62a0
VZ
341 // we cache m_widthsAbs between calls and recompute it if client
342 // width has changed (or when it is initially empty)
343 if ( m_widthsAbs.IsEmpty() || (m_lastClientWidth != width) )
c801d85f 344 {
390015c0
VZ
345 wxConstCast(this, wxStatusBarGeneric)->
346 m_widthsAbs = CalculateAbsWidths(width);
2b5f62a0
VZ
347 // remember last width for which we have recomputed the widths in pixels
348 wxConstCast(this, wxStatusBarGeneric)->
349 m_lastClientWidth = width;
c801d85f 350 }
c801d85f 351
390015c0
VZ
352 rect.x = 0;
353 for ( int i = 0; i < n; i++ )
354 {
355 rect.x += m_widthsAbs[i];
c801d85f 356 }
c801d85f 357
390015c0
VZ
358 rect.x += m_borderX;
359 rect.y = m_borderY;
c801d85f 360
390015c0
VZ
361 rect.width = m_widthsAbs[n] - 2*m_borderX;
362 rect.height = height - 2*m_borderY;
c801d85f 363
ca65c044 364 return true;
c801d85f
KB
365}
366
367// Initialize colours
ed791986 368void wxStatusBarGeneric::InitColours()
c801d85f
KB
369{
370 // Shadow colours
a71d815b 371#if defined(__WXMSW__) || defined(__WXMAC__)
a756f210 372 wxColour mediumShadowColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW));
c801d85f
KB
373 m_mediumShadowPen = wxPen(mediumShadowColour, 1, wxSOLID);
374
a756f210 375 wxColour hilightColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DHILIGHT));
c801d85f 376 m_hilightPen = wxPen(hilightColour, 1, wxSOLID);
b34590eb 377#elif defined(__WXPM__)
e715f4e7 378 m_mediumShadowPen = wxPen(wxColour(127, 127, 127), 1, wxSOLID);
b0fa2187 379 m_hilightPen = *wxWHITE_PEN;
dd7d1435 380
b0fa2187
PC
381 SetBackgroundColour(*wxLIGHT_GREY);
382 SetForegroundColour(*wxBLACK);
c801d85f 383#else
b0fa2187
PC
384 m_mediumShadowPen = *wxGREY_PEN;
385 m_hilightPen = *wxWHITE_PEN;
c801d85f 386#endif
c801d85f
KB
387}
388
389// Responds to colour changes, and passes event on to children.
ed791986 390void wxStatusBarGeneric::OnSysColourChanged(wxSysColourChangedEvent& event)
c801d85f
KB
391{
392 InitColours();
c801d85f
KB
393
394 // Propagate the event to the non-top-level children
395 wxWindow::OnSysColourChanged(event);
396}
397
ed791986
VZ
398void wxStatusBarGeneric::SetMinHeight(int height)
399{
400 // check that this min height is not less than minimal height for the
401 // current font
402 wxClientDC dc(this);
403 wxCoord y;
2b5f62a0 404 dc.GetTextExtent( wxT("X"), NULL, &y );
ed791986
VZ
405
406 if ( height > (11*y)/10 )
407 {
422d0ff0 408 SetSize(wxDefaultCoord, wxDefaultCoord, wxDefaultCoord, height + 2*m_borderY);
ed791986
VZ
409 }
410}
411
2b5f62a0 412void wxStatusBarGeneric::OnLeftDown(wxMouseEvent& event)
390015c0 413{
2b5f62a0
VZ
414#ifdef __WXGTK20__
415 int width, height;
416 GetClientSize(&width, &height);
8aa2cea1 417
2b5f62a0
VZ
418 if (HasFlag( wxST_SIZEGRIP ) && (event.GetX() > width-height))
419 {
420 GtkWidget *ancestor = gtk_widget_get_toplevel( m_widget );
421
422 if (!GTK_IS_WINDOW (ancestor))
423 return;
390015c0 424
2b5f62a0
VZ
425 GdkWindow *source = GTK_PIZZA(m_wxwindow)->bin_window;
426
427 int org_x = 0;
428 int org_y = 0;
429 gdk_window_get_origin( source, &org_x, &org_y );
430
fc2d4209
RR
431 if (GetLayoutDirection() == wxLayout_RightToLeft)
432 {
433 gtk_window_begin_resize_drag (GTK_WINDOW (ancestor),
434 GDK_WINDOW_EDGE_SOUTH_WEST,
435 1,
436 org_x - event.GetX() + GetSize().x ,
437 org_y + event.GetY(),
438 0);
439 }
440 else
441 {
442 gtk_window_begin_resize_drag (GTK_WINDOW (ancestor),
2b5f62a0
VZ
443 GDK_WINDOW_EDGE_SOUTH_EAST,
444 1,
8aa2cea1
RD
445 org_x + event.GetX(),
446 org_y + event.GetY(),
2b5f62a0 447 0);
fc2d4209 448 }
2b5f62a0
VZ
449 }
450 else
451 {
ca65c044 452 event.Skip( true );
2b5f62a0
VZ
453 }
454#else
ca65c044 455 event.Skip( true );
2b5f62a0
VZ
456#endif
457}
458
459void wxStatusBarGeneric::OnRightDown(wxMouseEvent& event)
460{
461#ifdef __WXGTK20__
462 int width, height;
463 GetClientSize(&width, &height);
8aa2cea1 464
2b5f62a0
VZ
465 if (HasFlag( wxST_SIZEGRIP ) && (event.GetX() > width-height))
466 {
467 GtkWidget *ancestor = gtk_widget_get_toplevel( m_widget );
468
469 if (!GTK_IS_WINDOW (ancestor))
470 return;
471
472 GdkWindow *source = GTK_PIZZA(m_wxwindow)->bin_window;
473
474 int org_x = 0;
475 int org_y = 0;
476 gdk_window_get_origin( source, &org_x, &org_y );
8aa2cea1 477
2b5f62a0
VZ
478 gtk_window_begin_move_drag (GTK_WINDOW (ancestor),
479 2,
8aa2cea1
RD
480 org_x + event.GetX(),
481 org_y + event.GetY(),
2b5f62a0
VZ
482 0);
483 }
484 else
485 {
ca65c044 486 event.Skip( true );
2b5f62a0
VZ
487 }
488#else
ca65c044 489 event.Skip( true );
2b5f62a0 490#endif
390015c0
VZ
491}
492
1e6feb95 493#endif // wxUSE_STATUSBAR