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