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