]>
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 KB |
87 | |
88 | // Don't wish this to be found as a child | |
7c74e7fe | 89 | #ifndef __WXMAC__ |
c0ed460c | 90 | parent->GetChildren().DeleteObject(this); |
7c74e7fe | 91 | #endif |
c801d85f KB |
92 | InitColours(); |
93 | ||
94 | SetFont(m_defaultStatusBarFont); | |
95 | ||
71e03035 VZ |
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 | ||
c801d85f KB |
107 | return success; |
108 | } | |
109 | ||
cc56206f | 110 | void wxStatusBarGeneric::SetFieldsCount(int number, const int *widths) |
c801d85f | 111 | { |
633d67bb VZ |
112 | if ( number != m_nFields ) |
113 | { | |
114 | m_nFields = number; | |
c801d85f | 115 | |
f51f94ea | 116 | delete[] m_statusStrings; |
633d67bb | 117 | m_statusStrings = new wxString[number]; |
633d67bb | 118 | } |
c801d85f | 119 | |
633d67bb | 120 | SetStatusWidths(number, widths); |
c801d85f KB |
121 | } |
122 | ||
ed791986 | 123 | void wxStatusBarGeneric::SetStatusText(const wxString& text, int number) |
c801d85f | 124 | { |
633d67bb VZ |
125 | wxCHECK_RET( (number >= 0) && (number < m_nFields), |
126 | _T("invalid status bar field index") ); | |
c801d85f | 127 | |
633d67bb | 128 | m_statusStrings[number] = text; |
c801d85f | 129 | |
f8a4fa4c VZ |
130 | wxRect rect; |
131 | GetFieldRect(number, rect); | |
132 | wxClientDC dc(this); | |
133 | ||
134 | dc.SetBackground( wxBrush(GetBackgroundColour(), wxSOLID) ); | |
135 | dc.SetClippingRegion( rect.x+1, rect.y+1, rect.width-1, rect.height-1 ); | |
136 | dc.Clear(); | |
137 | dc.DestroyClippingRegion(); | |
138 | ||
139 | DrawFieldText( dc, number ); | |
c801d85f KB |
140 | } |
141 | ||
ed791986 | 142 | wxString wxStatusBarGeneric::GetStatusText(int n) const |
c801d85f | 143 | { |
ed791986 VZ |
144 | wxCHECK_MSG( (n >= 0) && (n < m_nFields), wxEmptyString, |
145 | _T("invalid status bar field index") ); | |
146 | ||
c801d85f KB |
147 | return m_statusStrings[n]; |
148 | } | |
149 | ||
ed791986 | 150 | void wxStatusBarGeneric::SetStatusWidths(int n, const int widths_field[]) |
c801d85f | 151 | { |
633d67bb VZ |
152 | // only set status widths, when n == number of statuswindows |
153 | wxCHECK_RET( n == m_nFields, _T("status bar field count mismatch") ); | |
154 | ||
155 | // delete the old widths in any case - this function may be used to reset | |
156 | // the widths to the default (all equal) | |
157 | delete [] m_statusWidths; | |
158 | ||
159 | if ( !widths_field ) | |
160 | { | |
161 | // not an error, see the comment above | |
162 | m_statusWidths = (int *)NULL; | |
f8a4fa4c | 163 | Refresh(); |
633d67bb VZ |
164 | return; |
165 | } | |
166 | ||
167 | int i; | |
168 | ||
169 | // VZ: this doesn't do anything as is_variable is unused later | |
170 | #if 0 | |
c801d85f KB |
171 | // when one window (minimum) is variable (width <= 0) |
172 | bool is_variable = FALSE; | |
c801d85f KB |
173 | for (i = 0; i < m_nFields; i++) |
174 | { | |
633d67bb VZ |
175 | if (widths_field[i] <= 0) |
176 | is_variable = TRUE; | |
c801d85f | 177 | } |
633d67bb | 178 | #endif // 0 |
c801d85f KB |
179 | |
180 | // set widths | |
181 | m_statusWidths = new int[n]; | |
182 | for (i = 0; i < m_nFields; i++) | |
183 | { | |
633d67bb | 184 | m_statusWidths[i] = widths_field[i]; |
c801d85f | 185 | } |
f8a4fa4c | 186 | Refresh(); |
c801d85f KB |
187 | } |
188 | ||
ed791986 | 189 | void wxStatusBarGeneric::OnPaint(wxPaintEvent& WXUNUSED(event) ) |
c801d85f KB |
190 | { |
191 | wxPaintDC dc(this); | |
192 | ||
5b3ed311 | 193 | |
c801d85f | 194 | int i; |
c0ed460c JS |
195 | if ( GetFont().Ok() ) |
196 | dc.SetFont(GetFont()); | |
c801d85f KB |
197 | dc.SetBackgroundMode(wxTRANSPARENT); |
198 | ||
28be2e8a | 199 | #ifdef __WXPM__ |
b34590eb DW |
200 | wxColour vColor; |
201 | ||
702c190d | 202 | vColor.InitFromName("GREY"); |
b34590eb | 203 | ::WinFillRect(dc.m_hPS, &dc.m_vRclPaint, vColor.GetPixel()); |
28be2e8a DW |
204 | #endif |
205 | ||
c801d85f | 206 | for ( i = 0; i < m_nFields; i ++ ) |
f51f94ea | 207 | DrawField(dc, i); |
e97f20a0 | 208 | |
28be2e8a DW |
209 | #ifdef __WXMSW__ |
210 | dc.SetFont(wxNullFont); | |
211 | #endif // MSW | |
c801d85f KB |
212 | } |
213 | ||
ed791986 | 214 | void wxStatusBarGeneric::DrawFieldText(wxDC& dc, int i) |
c801d85f KB |
215 | { |
216 | int leftMargin = 2; | |
217 | ||
16e93305 | 218 | wxRect rect; |
c801d85f KB |
219 | GetFieldRect(i, rect); |
220 | ||
221 | wxString text(GetStatusText(i)); | |
222 | ||
223 | long x, y; | |
224 | ||
225 | dc.GetTextExtent(text, &x, &y); | |
226 | ||
227 | int xpos = rect.x + leftMargin; | |
228 | int ypos = (int) (((rect.height - y) / 2 ) + rect.y + 0.5) ; | |
ed791986 | 229 | |
7c74e7fe | 230 | #if defined( __WXGTK__ ) || defined(__WXMAC__) |
92976ab6 RR |
231 | xpos++; |
232 | ypos++; | |
233 | #endif | |
c801d85f KB |
234 | |
235 | dc.SetClippingRegion(rect.x, rect.y, rect.width, rect.height); | |
236 | ||
237 | dc.DrawText(text, xpos, ypos); | |
238 | ||
239 | dc.DestroyClippingRegion(); | |
240 | } | |
241 | ||
ed791986 | 242 | void wxStatusBarGeneric::DrawField(wxDC& dc, int i) |
c801d85f | 243 | { |
16e93305 | 244 | wxRect rect; |
c801d85f KB |
245 | GetFieldRect(i, rect); |
246 | ||
247 | // Draw border | |
248 | // Have grey background, plus 3-d border - | |
249 | // One black rectangle. | |
250 | // Inside this, left and top sides - dark grey. Bottom and right - | |
251 | // white. | |
252 | ||
f51f94ea | 253 | dc.SetPen(m_hilightPen); |
c801d85f | 254 | |
b34590eb DW |
255 | #ifndef __WXPM__ |
256 | ||
c801d85f KB |
257 | // Right and bottom white lines |
258 | dc.DrawLine(rect.x + rect.width, rect.y, | |
259 | rect.x + rect.width, rect.y + rect.height); | |
260 | dc.DrawLine(rect.x + rect.width, rect.y + rect.height, | |
f51f94ea | 261 | rect.x, rect.y + rect.height); |
c801d85f | 262 | |
f51f94ea | 263 | dc.SetPen(m_mediumShadowPen); |
c801d85f KB |
264 | |
265 | // Left and top grey lines | |
266 | dc.DrawLine(rect.x, rect.y + rect.height, | |
f51f94ea | 267 | rect.x, rect.y); |
c801d85f | 268 | dc.DrawLine(rect.x, rect.y, |
f51f94ea | 269 | rect.x + rect.width, rect.y); |
b34590eb DW |
270 | #else |
271 | // Right | |
702c190d DW |
272 | dc.DrawLine(rect.x + rect.width, rect.y, |
273 | rect.x + rect.width, rect.y + rect.height + 2); | |
b34590eb | 274 | dc.SetPen(m_mediumShadowPen); |
702c190d DW |
275 | dc.DrawLine(rect.x + rect.width + 1, rect.y, |
276 | rect.x + rect.width + 1, rect.y + rect.height + 2); | |
277 | dc.DrawLine(rect.x + rect.width + 2, rect.y, | |
278 | rect.x + rect.width + 2, rect.y + rect.height + 2); | |
b34590eb | 279 | // Top |
702c190d DW |
280 | dc.DrawLine(rect.x + rect.width + 2, rect.y, |
281 | rect.x - 2, rect.y); | |
282 | dc.DrawLine(rect.x + rect.width + 1, rect.y - 1, | |
283 | rect.x - 2, rect.y - 1); | |
b34590eb | 284 | dc.SetPen(m_hilightPen); |
702c190d DW |
285 | dc.DrawLine(rect.x + rect.width, rect.y - 2, |
286 | rect.x - 2, rect.y - 2); | |
b34590eb DW |
287 | |
288 | #endif | |
c801d85f | 289 | |
f51f94ea | 290 | DrawFieldText(dc, i); |
c801d85f KB |
291 | } |
292 | ||
293 | // Get the position and size of the field's internal bounding rectangle | |
ed791986 | 294 | bool wxStatusBarGeneric::GetFieldRect(int n, wxRect& rect) const |
c801d85f | 295 | { |
ed791986 VZ |
296 | wxCHECK_MSG( (n >= 0) && (n < m_nFields), FALSE, |
297 | _T("invalid status bar field index") ); | |
c801d85f KB |
298 | |
299 | int width, height; | |
28be2e8a DW |
300 | #ifdef __WXPM__ |
301 | GetSize(&width, &height); | |
302 | #else | |
c801d85f | 303 | GetClientSize(&width, &height); |
28be2e8a | 304 | #endif |
c801d85f KB |
305 | |
306 | int i; | |
307 | int sum_of_nonvar = 0; | |
308 | int num_of_var = 0; | |
309 | bool do_same_width = FALSE; | |
310 | ||
311 | int fieldWidth = 0; | |
312 | int fieldPosition = 0; | |
313 | ||
314 | if (m_statusWidths) | |
315 | { | |
316 | // if sum(not variable Windows) > c_width - (20 points per variable_window) | |
317 | // then do_same_width = TRUE; | |
318 | for (i = 0; i < m_nFields; i++) | |
319 | { | |
320 | if (m_statusWidths[i] > 0) sum_of_nonvar += m_statusWidths[i]; | |
321 | else num_of_var++; | |
322 | } | |
323 | if (sum_of_nonvar > (width - 20*num_of_var)) do_same_width = TRUE; | |
324 | } | |
325 | else do_same_width = TRUE; | |
326 | if (do_same_width) | |
327 | { | |
328 | for (i = 0; i < m_nFields; i++) | |
329 | { | |
330 | fieldWidth = (int)(width/m_nFields); | |
f51f94ea VZ |
331 | fieldPosition = i*fieldWidth; |
332 | if ( i == n ) | |
333 | break; | |
c801d85f KB |
334 | } |
335 | } | |
336 | else // no_same_width | |
337 | { | |
338 | int *tempwidth = new int[m_nFields]; | |
339 | int temppos = 0; | |
340 | for (i = 0; i < m_nFields; i++) | |
341 | { | |
342 | if (m_statusWidths[i] > 0) tempwidth[i] = m_statusWidths[i]; | |
343 | else tempwidth[i] = (width - sum_of_nonvar) / num_of_var; | |
344 | } | |
345 | for (i = 0; i < m_nFields; i++) | |
346 | { | |
f51f94ea VZ |
347 | fieldWidth = tempwidth[i]; |
348 | fieldPosition = temppos; | |
c801d85f | 349 | |
f51f94ea | 350 | temppos += tempwidth[i]; |
c801d85f | 351 | |
f51f94ea VZ |
352 | if ( i == n ) |
353 | break; | |
c801d85f KB |
354 | } |
355 | delete [] tempwidth; | |
356 | } | |
357 | ||
358 | rect.x = fieldPosition + wxTHICK_LINE_BORDER; | |
f51f94ea | 359 | rect.y = wxTHICK_LINE_BORDER; |
c801d85f | 360 | |
f51f94ea VZ |
361 | rect.width = fieldWidth - 2 * wxTHICK_LINE_BORDER ; |
362 | rect.height = height - 2 * wxTHICK_LINE_BORDER ; | |
c801d85f | 363 | |
f51f94ea | 364 | return TRUE; |
c801d85f KB |
365 | } |
366 | ||
367 | // Initialize colours | |
ed791986 | 368 | void wxStatusBarGeneric::InitColours() |
c801d85f KB |
369 | { |
370 | // Shadow colours | |
5b3ed311 | 371 | #if defined(__WIN95__) |
c801d85f KB |
372 | wxColour mediumShadowColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DSHADOW)); |
373 | m_mediumShadowPen = wxPen(mediumShadowColour, 1, wxSOLID); | |
374 | ||
375 | wxColour hilightColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DHILIGHT)); | |
376 | m_hilightPen = wxPen(hilightColour, 1, wxSOLID); | |
b34590eb DW |
377 | #elif defined(__WXPM__) |
378 | m_mediumShadowPen = wxPen("LIGHT GREY", 1, wxSOLID); | |
379 | m_hilightPen = wxPen("WHITE", 1, wxSOLID); | |
c801d85f KB |
380 | #else |
381 | m_mediumShadowPen = wxPen("GREY", 1, wxSOLID); | |
382 | m_hilightPen = wxPen("WHITE", 1, wxSOLID); | |
383 | #endif | |
384 | ||
16c1f7f3 | 385 | m_defaultStatusBarFont = wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT); |
c801d85f KB |
386 | SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE)); |
387 | } | |
388 | ||
389 | // Responds to colour changes, and passes event on to children. | |
ed791986 | 390 | void wxStatusBarGeneric::OnSysColourChanged(wxSysColourChangedEvent& event) |
c801d85f KB |
391 | { |
392 | InitColours(); | |
393 | Refresh(); | |
394 | ||
395 | // Propagate the event to the non-top-level children | |
396 | wxWindow::OnSysColourChanged(event); | |
397 | } | |
398 | ||
ed791986 VZ |
399 | void wxStatusBarGeneric::SetMinHeight(int height) |
400 | { | |
401 | // check that this min height is not less than minimal height for the | |
402 | // current font | |
403 | wxClientDC dc(this); | |
404 | wxCoord y; | |
405 | dc.GetTextExtent( _T("X"), NULL, &y ); | |
406 | ||
407 | if ( height > (11*y)/10 ) | |
408 | { | |
409 | SetSize(-1, -1, -1, height + 2*m_borderY); | |
410 | } | |
411 | } | |
412 | ||
1e6feb95 | 413 | #endif // wxUSE_STATUSBAR |