]> git.saurik.com Git - wxWidgets.git/blob - src/generic/statusbr.cpp
Applied patch [ 774886 ] wxnotebook bug
[wxWidgets.git] / src / generic / statusbr.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: generic/statusbr.cpp
3 // Purpose: wxStatusBarGeneric class implementation
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 01/02/97
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
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
23 #if wxUSE_STATUSBAR
24
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
32 #ifdef __WXGTK20__
33 #include "wx/gtk/private.h"
34 #include "wx/gtk/win_gtk.h"
35 #endif
36
37 #include "wx/statusbr.h"
38
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)
45 #include "wx/generic/statusbr.h"
46
47 IMPLEMENT_DYNAMIC_CLASS(wxStatusBarGeneric, wxWindow)
48 #endif // wxUSE_NATIVE_STATUSBAR
49
50 BEGIN_EVENT_TABLE(wxStatusBarGeneric, wxWindow)
51 EVT_PAINT(wxStatusBarGeneric::OnPaint)
52 EVT_LEFT_DOWN(wxStatusBarGeneric::OnLeftDown)
53 EVT_RIGHT_DOWN(wxStatusBarGeneric::OnRightDown)
54 EVT_SYS_COLOUR_CHANGED(wxStatusBarGeneric::OnSysColourChanged)
55 END_EVENT_TABLE()
56
57 // Default status border dimensions
58 #define wxTHICK_LINE_BORDER 2
59 #define wxTHICK_LINE_WIDTH 1
60
61 void wxStatusBarGeneric::Init()
62 {
63 m_borderX = wxTHICK_LINE_BORDER;
64 m_borderY = wxTHICK_LINE_BORDER;
65 }
66
67 wxStatusBarGeneric::~wxStatusBarGeneric()
68 {
69 // VZ: what is this for? please comment...
70 #ifdef __WXMSW__
71 SetFont(wxNullFont);
72 #endif // MSW
73 }
74
75 bool wxStatusBarGeneric::Create(wxWindow *parent,
76 wxWindowID id,
77 long style,
78 const wxString& name)
79 {
80 if ( !wxWindow::Create(parent, id,
81 wxDefaultPosition, wxDefaultSize,
82 style | wxTAB_TRAVERSAL, name) )
83 return FALSE;
84
85 // The status bar should have a themed background
86 SetThemeEnabled( TRUE );
87
88 // Don't wish this to be found as a child
89 #ifndef __WXMAC__
90 parent->GetChildren().DeleteObject(this);
91 #endif
92 InitColours();
93
94 SetFont(m_defaultStatusBarFont);
95
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
107 SetFieldsCount(1);
108
109 return TRUE;
110 }
111
112 void wxStatusBarGeneric::SetFieldsCount(int number, const int *widths)
113 {
114 wxASSERT_MSG( number >= 0, _T("negative number of fields in wxStatusBar?") );
115
116 int i;
117 for(i = m_nFields; i < number; ++i)
118 m_statusStrings.Add( wxEmptyString );
119
120 for (i = m_nFields - 1; i >= number; --i)
121 m_statusStrings.RemoveAt(i);
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?") );
127
128 SetStatusWidths(number, widths);
129 }
130
131 void wxStatusBarGeneric::SetStatusText(const wxString& text, int number)
132 {
133 wxCHECK_RET( (number >= 0) && (number < m_nFields),
134 _T("invalid status bar field index") );
135
136 m_statusStrings[number] = text;
137
138 wxRect rect;
139 GetFieldRect(number, rect);
140
141 Refresh( TRUE, &rect );
142 }
143
144 wxString wxStatusBarGeneric::GetStatusText(int n) const
145 {
146 wxCHECK_MSG( (n >= 0) && (n < m_nFields), wxEmptyString,
147 _T("invalid status bar field index") );
148
149 return m_statusStrings[n];
150 }
151
152 void wxStatusBarGeneric::SetStatusWidths(int n, const int widths_field[])
153 {
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)
159 // MBN: this is incompatible with at least wxMSW and wxMAC and not
160 // documented, but let's keep it for now
161 ReinitWidths();
162
163 // forget the old cached pixel widths
164 m_widthsAbs.Empty();
165
166 if ( !widths_field )
167 {
168 // not an error, see the comment above
169 Refresh();
170 return;
171 }
172
173 wxStatusBarBase::SetStatusWidths(n, widths_field);
174 }
175
176 void wxStatusBarGeneric::OnPaint(wxPaintEvent& WXUNUSED(event) )
177 {
178 wxPaintDC dc(this);
179
180 #ifdef __WXGTK20__
181 // Draw grip first
182 if (HasFlag( wxST_SIZEGRIP ))
183 {
184 int width, height;
185 GetClientSize(&width, &height);
186
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 );
195
196 }
197 #endif
198
199 if (GetFont().Ok())
200 dc.SetFont(GetFont());
201
202 dc.SetBackgroundMode(wxTRANSPARENT);
203
204 #ifdef __WXPM__
205 wxColour vColor;
206
207 vColor = wxSystemSettings::GetColour(wxSYS_COLOUR_MENUBAR);
208 ::WinFillRect(dc.m_hPS, &dc.m_vRclPaint, vColor.GetPixel());
209 #endif
210
211 for (int i = 0; i < m_nFields; i ++)
212 DrawField(dc, i);
213 }
214
215 void wxStatusBarGeneric::DrawFieldText(wxDC& dc, int i)
216 {
217 int leftMargin = 2;
218
219 wxRect rect;
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) ;
230
231 #if defined( __WXGTK__ ) || defined(__WXMAC__)
232 xpos++;
233 ypos++;
234 #endif
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
243 void wxStatusBarGeneric::DrawField(wxDC& dc, int i)
244 {
245 wxRect rect;
246 GetFieldRect(i, rect);
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
254 dc.SetPen(m_hilightPen);
255
256 #ifndef __WXPM__
257
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,
262 rect.x, rect.y + rect.height);
263
264 dc.SetPen(m_mediumShadowPen);
265
266 // Left and top grey lines
267 dc.DrawLine(rect.x, rect.y + rect.height,
268 rect.x, rect.y);
269 dc.DrawLine(rect.x, rect.y,
270 rect.x + rect.width, rect.y);
271 #else
272
273 dc.DrawLine(rect.x + rect.width, rect.height + 2,
274 rect.x, rect.height + 2);
275 dc.DrawLine(rect.x + rect.width, rect.y,
276 rect.x + rect.width, rect.y + rect.height);
277
278 dc.SetPen(m_mediumShadowPen);
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);
283
284 #endif
285
286 DrawFieldText(dc, i);
287 }
288
289 // Get the position and size of the field's internal bounding rectangle
290 bool wxStatusBarGeneric::GetFieldRect(int n, wxRect& rect) const
291 {
292 wxCHECK_MSG( (n >= 0) && (n < m_nFields), FALSE,
293 _T("invalid status bar field index") );
294
295 // FIXME: workarounds for OS/2 bugs have nothing to do here (VZ)
296 int width, height;
297 #ifdef __WXPM__
298 GetSize(&width, &height);
299 #else
300 GetClientSize(&width, &height);
301 #endif
302
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) )
306 {
307 wxConstCast(this, wxStatusBarGeneric)->
308 m_widthsAbs = CalculateAbsWidths(width);
309 // remember last width for which we have recomputed the widths in pixels
310 wxConstCast(this, wxStatusBarGeneric)->
311 m_lastClientWidth = width;
312 }
313
314 rect.x = 0;
315 for ( int i = 0; i < n; i++ )
316 {
317 rect.x += m_widthsAbs[i];
318 }
319
320 rect.x += m_borderX;
321 rect.y = m_borderY;
322
323 rect.width = m_widthsAbs[n] - 2*m_borderX;
324 rect.height = height - 2*m_borderY;
325
326 return TRUE;
327 }
328
329 // Initialize colours
330 void wxStatusBarGeneric::InitColours()
331 {
332 // Shadow colours
333 #if defined(__WIN95__) || defined(__WXMAC__)
334 wxColour mediumShadowColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW));
335 m_mediumShadowPen = wxPen(mediumShadowColour, 1, wxSOLID);
336
337 wxColour hilightColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DHILIGHT));
338 m_hilightPen = wxPen(hilightColour, 1, wxSOLID);
339 #elif defined(__WXPM__)
340 m_mediumShadowPen = wxPen(wxColour(127, 127, 127), 1, wxSOLID);
341 m_hilightPen = wxPen("WHITE", 1, wxSOLID);
342
343 wxColour vColour;
344
345 vColour.Set(wxString("LIGHT GREY"));
346 SetBackgroundColour(vColour);
347 vColour.Set(wxString("BLACK"));
348 SetForegroundColour(vColour);
349 m_defaultStatusBarFont = *wxSMALL_FONT;
350 #else
351 m_mediumShadowPen = wxPen("GREY", 1, wxSOLID);
352 m_hilightPen = wxPen("WHITE", 1, wxSOLID);
353 #endif
354
355 #ifndef __WXPM__
356 m_defaultStatusBarFont = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
357 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));
358 #endif
359 }
360
361 // Responds to colour changes, and passes event on to children.
362 void wxStatusBarGeneric::OnSysColourChanged(wxSysColourChangedEvent& event)
363 {
364 InitColours();
365 Refresh();
366
367 // Propagate the event to the non-top-level children
368 wxWindow::OnSysColourChanged(event);
369 }
370
371 void 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;
377 dc.GetTextExtent( wxT("X"), NULL, &y );
378
379 if ( height > (11*y)/10 )
380 {
381 SetSize(-1, -1, -1, height + 2*m_borderY);
382 }
383 }
384
385 void wxStatusBarGeneric::OnLeftDown(wxMouseEvent& event)
386 {
387 #ifdef __WXGTK20__
388 int width, height;
389 GetClientSize(&width, &height);
390
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;
397
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,
407 org_x + event.GetX(),
408 org_y + event.GetY(),
409 0);
410 }
411 else
412 {
413 event.Skip( TRUE );
414 }
415 #else
416 event.Skip( TRUE );
417 #endif
418 }
419
420 void wxStatusBarGeneric::OnRightDown(wxMouseEvent& event)
421 {
422 #ifdef __WXGTK20__
423 int width, height;
424 GetClientSize(&width, &height);
425
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 );
438
439 gtk_window_begin_move_drag (GTK_WINDOW (ancestor),
440 2,
441 org_x + event.GetX(),
442 org_y + event.GetY(),
443 0);
444 }
445 else
446 {
447 event.Skip( TRUE );
448 }
449 #else
450 event.Skip( TRUE );
451 #endif
452 }
453
454 #endif // wxUSE_STATUSBAR
455