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