]>
Commit | Line | Data |
---|---|---|
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$ | |
8 | // Copyright: (c) Julian Smart and Markus Holzem | |
ed791986 | 9 | // Licence: wxWindows license |
c801d85f KB |
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 | ||
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 | ||
412e4edf | 32 | #include "wx/statusbr.h" |
c801d85f | 33 | |
84f68c21 VZ |
34 | // we only have to do it here when we use wxStatusBarGeneric in addition to the |
35 | // standard wxStatusBar class, if wxStatusBarGeneric is the same as | |
36 | // wxStatusBar, then the corresponding IMPLEMENT_DYNAMIC_CLASS is already in | |
37 | // common/statbar.cpp | |
38 | #if defined(__WXMAC__) || \ | |
39 | (defined(wxUSE_NATIVE_STATUSBAR) && wxUSE_NATIVE_STATUSBAR) | |
b64a8473 | 40 | #include "wx/generic/statusbr.h" |
c801d85f | 41 | |
b64a8473 VZ |
42 | IMPLEMENT_DYNAMIC_CLASS(wxStatusBarGeneric, wxWindow) |
43 | #endif // wxUSE_NATIVE_STATUSBAR | |
ed791986 | 44 | |
ed791986 VZ |
45 | BEGIN_EVENT_TABLE(wxStatusBarGeneric, wxWindow) |
46 | EVT_PAINT(wxStatusBarGeneric::OnPaint) | |
47 | EVT_SYS_COLOUR_CHANGED(wxStatusBarGeneric::OnSysColourChanged) | |
c801d85f | 48 | END_EVENT_TABLE() |
c801d85f KB |
49 | |
50 | // Default status border dimensions | |
51 | #define wxTHICK_LINE_BORDER 2 | |
52 | #define wxTHICK_LINE_WIDTH 1 | |
53 | ||
ed791986 | 54 | wxStatusBarGeneric::wxStatusBarGeneric() |
c801d85f | 55 | { |
c67daf87 UR |
56 | m_statusWidths = (int *) NULL; |
57 | m_statusStrings = (wxString *) NULL; | |
c801d85f KB |
58 | m_nFields = 0; |
59 | m_borderX = wxTHICK_LINE_BORDER; | |
60 | m_borderY = wxTHICK_LINE_BORDER; | |
61 | } | |
62 | ||
ed791986 | 63 | wxStatusBarGeneric::~wxStatusBarGeneric() |
c801d85f | 64 | { |
f51f94ea VZ |
65 | # ifdef __WXMSW__ |
66 | SetFont(wxNullFont); | |
67 | # endif // MSW | |
68 | ||
f51f94ea VZ |
69 | if ( m_statusStrings ) |
70 | delete[] m_statusStrings; | |
c801d85f KB |
71 | } |
72 | ||
ed791986 VZ |
73 | bool wxStatusBarGeneric::Create(wxWindow *parent, |
74 | wxWindowID id, | |
75 | long style, | |
76 | const wxString& name) | |
c801d85f | 77 | { |
c67daf87 UR |
78 | m_statusWidths = (int *) NULL; |
79 | m_statusStrings = (wxString *) NULL; | |
c801d85f KB |
80 | m_nFields = 0; |
81 | m_borderX = wxTHICK_LINE_BORDER; | |
82 | m_borderY = wxTHICK_LINE_BORDER; | |
83 | ||
ed791986 VZ |
84 | bool success = wxWindow::Create(parent, id, |
85 | wxDefaultPosition, wxDefaultSize, | |
86 | style | wxTAB_TRAVERSAL, name); | |
c801d85f | 87 | |
f90566f5 RR |
88 | // The status bar should have a themed background |
89 | SetThemeEnabled( TRUE ); | |
90 | ||
c801d85f | 91 | // Don't wish this to be found as a child |
7c74e7fe | 92 | #ifndef __WXMAC__ |
c0ed460c | 93 | parent->GetChildren().DeleteObject(this); |
7c74e7fe | 94 | #endif |
c801d85f KB |
95 | InitColours(); |
96 | ||
97 | SetFont(m_defaultStatusBarFont); | |
98 | ||
71e03035 VZ |
99 | // Set the height according to the font and the border size |
100 | wxClientDC dc(this); | |
101 | dc.SetFont(GetFont()); | |
102 | ||
103 | wxCoord y; | |
104 | dc.GetTextExtent(_T("X"), NULL, &y ); | |
105 | ||
106 | int height = (int)( (11*y)/10 + 2*GetBorderY()); | |
107 | ||
108 | SetSize(-1, -1, -1, height); | |
109 | ||
c801d85f KB |
110 | return success; |
111 | } | |
112 | ||
cc56206f | 113 | void wxStatusBarGeneric::SetFieldsCount(int number, const int *widths) |
c801d85f | 114 | { |
633d67bb VZ |
115 | if ( number != m_nFields ) |
116 | { | |
117 | m_nFields = number; | |
c801d85f | 118 | |
f51f94ea | 119 | delete[] m_statusStrings; |
633d67bb | 120 | m_statusStrings = new wxString[number]; |
633d67bb | 121 | } |
c801d85f | 122 | |
633d67bb | 123 | SetStatusWidths(number, widths); |
c801d85f KB |
124 | } |
125 | ||
ed791986 | 126 | void wxStatusBarGeneric::SetStatusText(const wxString& text, int number) |
c801d85f | 127 | { |
633d67bb VZ |
128 | wxCHECK_RET( (number >= 0) && (number < m_nFields), |
129 | _T("invalid status bar field index") ); | |
c801d85f | 130 | |
633d67bb | 131 | m_statusStrings[number] = text; |
c801d85f | 132 | |
f8a4fa4c VZ |
133 | wxRect rect; |
134 | GetFieldRect(number, rect); | |
f90566f5 RR |
135 | |
136 | Refresh( TRUE, &rect ); | |
c801d85f KB |
137 | } |
138 | ||
ed791986 | 139 | wxString wxStatusBarGeneric::GetStatusText(int n) const |
c801d85f | 140 | { |
ed791986 VZ |
141 | wxCHECK_MSG( (n >= 0) && (n < m_nFields), wxEmptyString, |
142 | _T("invalid status bar field index") ); | |
143 | ||
c801d85f KB |
144 | return m_statusStrings[n]; |
145 | } | |
146 | ||
ed791986 | 147 | void wxStatusBarGeneric::SetStatusWidths(int n, const int widths_field[]) |
c801d85f | 148 | { |
633d67bb VZ |
149 | // only set status widths, when n == number of statuswindows |
150 | wxCHECK_RET( n == m_nFields, _T("status bar field count mismatch") ); | |
151 | ||
152 | // delete the old widths in any case - this function may be used to reset | |
153 | // the widths to the default (all equal) | |
154 | delete [] m_statusWidths; | |
155 | ||
156 | if ( !widths_field ) | |
157 | { | |
158 | // not an error, see the comment above | |
159 | m_statusWidths = (int *)NULL; | |
f8a4fa4c | 160 | Refresh(); |
633d67bb VZ |
161 | return; |
162 | } | |
163 | ||
164 | int i; | |
165 | ||
166 | // VZ: this doesn't do anything as is_variable is unused later | |
167 | #if 0 | |
c801d85f KB |
168 | // when one window (minimum) is variable (width <= 0) |
169 | bool is_variable = FALSE; | |
c801d85f KB |
170 | for (i = 0; i < m_nFields; i++) |
171 | { | |
633d67bb VZ |
172 | if (widths_field[i] <= 0) |
173 | is_variable = TRUE; | |
c801d85f | 174 | } |
633d67bb | 175 | #endif // 0 |
c801d85f KB |
176 | |
177 | // set widths | |
178 | m_statusWidths = new int[n]; | |
179 | for (i = 0; i < m_nFields; i++) | |
180 | { | |
633d67bb | 181 | m_statusWidths[i] = widths_field[i]; |
c801d85f | 182 | } |
f8a4fa4c | 183 | Refresh(); |
c801d85f KB |
184 | } |
185 | ||
ed791986 | 186 | void wxStatusBarGeneric::OnPaint(wxPaintEvent& WXUNUSED(event) ) |
c801d85f KB |
187 | { |
188 | wxPaintDC dc(this); | |
189 | ||
5b3ed311 | 190 | |
c801d85f | 191 | int i; |
c0ed460c JS |
192 | if ( GetFont().Ok() ) |
193 | dc.SetFont(GetFont()); | |
c801d85f KB |
194 | dc.SetBackgroundMode(wxTRANSPARENT); |
195 | ||
28be2e8a | 196 | #ifdef __WXPM__ |
b34590eb DW |
197 | wxColour vColor; |
198 | ||
dd7d1435 | 199 | vColor.InitFromName("LIGHT GREY"); |
b34590eb | 200 | ::WinFillRect(dc.m_hPS, &dc.m_vRclPaint, vColor.GetPixel()); |
28be2e8a DW |
201 | #endif |
202 | ||
c801d85f | 203 | for ( i = 0; i < m_nFields; i ++ ) |
f51f94ea | 204 | DrawField(dc, i); |
e97f20a0 | 205 | |
28be2e8a DW |
206 | #ifdef __WXMSW__ |
207 | dc.SetFont(wxNullFont); | |
208 | #endif // MSW | |
c801d85f KB |
209 | } |
210 | ||
ed791986 | 211 | void wxStatusBarGeneric::DrawFieldText(wxDC& dc, int i) |
c801d85f KB |
212 | { |
213 | int leftMargin = 2; | |
214 | ||
16e93305 | 215 | wxRect rect; |
c801d85f KB |
216 | GetFieldRect(i, rect); |
217 | ||
218 | wxString text(GetStatusText(i)); | |
219 | ||
220 | long x, y; | |
221 | ||
222 | dc.GetTextExtent(text, &x, &y); | |
223 | ||
224 | int xpos = rect.x + leftMargin; | |
225 | int ypos = (int) (((rect.height - y) / 2 ) + rect.y + 0.5) ; | |
ed791986 | 226 | |
7c74e7fe | 227 | #if defined( __WXGTK__ ) || defined(__WXMAC__) |
92976ab6 RR |
228 | xpos++; |
229 | ypos++; | |
230 | #endif | |
c801d85f KB |
231 | |
232 | dc.SetClippingRegion(rect.x, rect.y, rect.width, rect.height); | |
233 | ||
234 | dc.DrawText(text, xpos, ypos); | |
235 | ||
236 | dc.DestroyClippingRegion(); | |
237 | } | |
238 | ||
ed791986 | 239 | void wxStatusBarGeneric::DrawField(wxDC& dc, int i) |
c801d85f | 240 | { |
16e93305 | 241 | wxRect rect; |
c801d85f KB |
242 | GetFieldRect(i, rect); |
243 | ||
244 | // Draw border | |
245 | // Have grey background, plus 3-d border - | |
246 | // One black rectangle. | |
247 | // Inside this, left and top sides - dark grey. Bottom and right - | |
248 | // white. | |
249 | ||
f51f94ea | 250 | dc.SetPen(m_hilightPen); |
c801d85f | 251 | |
b34590eb DW |
252 | #ifndef __WXPM__ |
253 | ||
c801d85f KB |
254 | // Right and bottom white lines |
255 | dc.DrawLine(rect.x + rect.width, rect.y, | |
256 | rect.x + rect.width, rect.y + rect.height); | |
257 | dc.DrawLine(rect.x + rect.width, rect.y + rect.height, | |
f51f94ea | 258 | rect.x, rect.y + rect.height); |
c801d85f | 259 | |
f51f94ea | 260 | dc.SetPen(m_mediumShadowPen); |
c801d85f KB |
261 | |
262 | // Left and top grey lines | |
263 | dc.DrawLine(rect.x, rect.y + rect.height, | |
f51f94ea | 264 | rect.x, rect.y); |
c801d85f | 265 | dc.DrawLine(rect.x, rect.y, |
f51f94ea | 266 | rect.x + rect.width, rect.y); |
b34590eb DW |
267 | #else |
268 | // Right | |
702c190d DW |
269 | dc.DrawLine(rect.x + rect.width, rect.y, |
270 | rect.x + rect.width, rect.y + rect.height + 2); | |
b34590eb | 271 | dc.SetPen(m_mediumShadowPen); |
702c190d DW |
272 | dc.DrawLine(rect.x + rect.width + 1, rect.y, |
273 | rect.x + rect.width + 1, rect.y + rect.height + 2); | |
274 | dc.DrawLine(rect.x + rect.width + 2, rect.y, | |
275 | rect.x + rect.width + 2, rect.y + rect.height + 2); | |
b34590eb | 276 | // Top |
702c190d DW |
277 | dc.DrawLine(rect.x + rect.width + 2, rect.y, |
278 | rect.x - 2, rect.y); | |
279 | dc.DrawLine(rect.x + rect.width + 1, rect.y - 1, | |
280 | rect.x - 2, rect.y - 1); | |
b34590eb | 281 | dc.SetPen(m_hilightPen); |
702c190d DW |
282 | dc.DrawLine(rect.x + rect.width, rect.y - 2, |
283 | rect.x - 2, rect.y - 2); | |
b34590eb DW |
284 | |
285 | #endif | |
c801d85f | 286 | |
f51f94ea | 287 | DrawFieldText(dc, i); |
c801d85f KB |
288 | } |
289 | ||
290 | // Get the position and size of the field's internal bounding rectangle | |
ed791986 | 291 | bool wxStatusBarGeneric::GetFieldRect(int n, wxRect& rect) const |
c801d85f | 292 | { |
ed791986 VZ |
293 | wxCHECK_MSG( (n >= 0) && (n < m_nFields), FALSE, |
294 | _T("invalid status bar field index") ); | |
c801d85f KB |
295 | |
296 | int width, height; | |
28be2e8a DW |
297 | #ifdef __WXPM__ |
298 | GetSize(&width, &height); | |
299 | #else | |
c801d85f | 300 | GetClientSize(&width, &height); |
28be2e8a | 301 | #endif |
c801d85f KB |
302 | |
303 | int i; | |
304 | int sum_of_nonvar = 0; | |
305 | int num_of_var = 0; | |
306 | bool do_same_width = FALSE; | |
307 | ||
308 | int fieldWidth = 0; | |
309 | int fieldPosition = 0; | |
310 | ||
311 | if (m_statusWidths) | |
312 | { | |
313 | // if sum(not variable Windows) > c_width - (20 points per variable_window) | |
314 | // then do_same_width = TRUE; | |
315 | for (i = 0; i < m_nFields; i++) | |
316 | { | |
317 | if (m_statusWidths[i] > 0) sum_of_nonvar += m_statusWidths[i]; | |
318 | else num_of_var++; | |
319 | } | |
320 | if (sum_of_nonvar > (width - 20*num_of_var)) do_same_width = TRUE; | |
321 | } | |
322 | else do_same_width = TRUE; | |
323 | if (do_same_width) | |
324 | { | |
325 | for (i = 0; i < m_nFields; i++) | |
326 | { | |
327 | fieldWidth = (int)(width/m_nFields); | |
f51f94ea VZ |
328 | fieldPosition = i*fieldWidth; |
329 | if ( i == n ) | |
330 | break; | |
c801d85f KB |
331 | } |
332 | } | |
333 | else // no_same_width | |
334 | { | |
335 | int *tempwidth = new int[m_nFields]; | |
336 | int temppos = 0; | |
337 | for (i = 0; i < m_nFields; i++) | |
338 | { | |
339 | if (m_statusWidths[i] > 0) tempwidth[i] = m_statusWidths[i]; | |
340 | else tempwidth[i] = (width - sum_of_nonvar) / num_of_var; | |
341 | } | |
342 | for (i = 0; i < m_nFields; i++) | |
343 | { | |
f51f94ea VZ |
344 | fieldWidth = tempwidth[i]; |
345 | fieldPosition = temppos; | |
c801d85f | 346 | |
f51f94ea | 347 | temppos += tempwidth[i]; |
c801d85f | 348 | |
f51f94ea VZ |
349 | if ( i == n ) |
350 | break; | |
c801d85f KB |
351 | } |
352 | delete [] tempwidth; | |
353 | } | |
354 | ||
355 | rect.x = fieldPosition + wxTHICK_LINE_BORDER; | |
f51f94ea | 356 | rect.y = wxTHICK_LINE_BORDER; |
c801d85f | 357 | |
f51f94ea VZ |
358 | rect.width = fieldWidth - 2 * wxTHICK_LINE_BORDER ; |
359 | rect.height = height - 2 * wxTHICK_LINE_BORDER ; | |
c801d85f | 360 | |
f51f94ea | 361 | return TRUE; |
c801d85f KB |
362 | } |
363 | ||
364 | // Initialize colours | |
ed791986 | 365 | void wxStatusBarGeneric::InitColours() |
c801d85f KB |
366 | { |
367 | // Shadow colours | |
5b3ed311 | 368 | #if defined(__WIN95__) |
a756f210 | 369 | wxColour mediumShadowColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW)); |
c801d85f KB |
370 | m_mediumShadowPen = wxPen(mediumShadowColour, 1, wxSOLID); |
371 | ||
a756f210 | 372 | wxColour hilightColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DHILIGHT)); |
c801d85f | 373 | m_hilightPen = wxPen(hilightColour, 1, wxSOLID); |
b34590eb | 374 | #elif defined(__WXPM__) |
dd7d1435 | 375 | m_mediumShadowPen = wxPen("DARK GREY", 1, wxSOLID); |
b34590eb | 376 | m_hilightPen = wxPen("WHITE", 1, wxSOLID); |
dd7d1435 DW |
377 | |
378 | wxColour vColour; | |
379 | ||
5e5390dd | 380 | vColour.Set(wxString("LIGHT GREY")); |
dd7d1435 | 381 | SetBackgroundColour(vColour); |
5e5390dd | 382 | vColour.Set(wxString("BLACK")); |
dd7d1435 DW |
383 | SetForegroundColour(vColour); |
384 | m_defaultStatusBarFont = *wxSMALL_FONT; | |
c801d85f KB |
385 | #else |
386 | m_mediumShadowPen = wxPen("GREY", 1, wxSOLID); | |
387 | m_hilightPen = wxPen("WHITE", 1, wxSOLID); | |
388 | #endif | |
389 | ||
dd7d1435 | 390 | #ifndef __WXPM__ |
a756f210 VS |
391 | m_defaultStatusBarFont = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); |
392 | SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)); | |
dd7d1435 | 393 | #endif |
c801d85f KB |
394 | } |
395 | ||
396 | // Responds to colour changes, and passes event on to children. | |
ed791986 | 397 | void wxStatusBarGeneric::OnSysColourChanged(wxSysColourChangedEvent& event) |
c801d85f KB |
398 | { |
399 | InitColours(); | |
400 | Refresh(); | |
401 | ||
402 | // Propagate the event to the non-top-level children | |
403 | wxWindow::OnSysColourChanged(event); | |
404 | } | |
405 | ||
ed791986 VZ |
406 | void wxStatusBarGeneric::SetMinHeight(int height) |
407 | { | |
408 | // check that this min height is not less than minimal height for the | |
409 | // current font | |
410 | wxClientDC dc(this); | |
411 | wxCoord y; | |
412 | dc.GetTextExtent( _T("X"), NULL, &y ); | |
413 | ||
414 | if ( height > (11*y)/10 ) | |
415 | { | |
416 | SetSize(-1, -1, -1, height + 2*m_borderY); | |
417 | } | |
418 | } | |
419 | ||
1e6feb95 | 420 | #endif // wxUSE_STATUSBAR |