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