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