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