]> git.saurik.com Git - wxWidgets.git/blame - src/generic/statusbr.cpp
OS/2 Statusbar fixes
[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
ed791986
VZ
23//#if !defined(__WIN32__) || !wxUSE_NATIVE_STATUSBAR
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
412e4edf
VZ
34// with wxUSE_NATIVE_STATUSBAR it is not included from wx/statusbr.h
35#include "wx/generic/statusbr.h"
c801d85f 36
ed791986
VZ
37IMPLEMENT_DYNAMIC_CLASS(wxStatusBarGeneric, wxWindow)
38
39#if !defined(__WIN32__) || !wxUSE_NATIVE_STATUSBAR
40 IMPLEMENT_DYNAMIC_CLASS(wxStatusBar, wxStatusBarGeneric)
41#endif // Win32 && wxUSE_NATIVE_STATUSBAR
c801d85f 42
ed791986
VZ
43BEGIN_EVENT_TABLE(wxStatusBarGeneric, wxWindow)
44 EVT_PAINT(wxStatusBarGeneric::OnPaint)
45 EVT_SYS_COLOUR_CHANGED(wxStatusBarGeneric::OnSysColourChanged)
c801d85f 46END_EVENT_TABLE()
c801d85f
KB
47
48// Default status border dimensions
49#define wxTHICK_LINE_BORDER 2
50#define wxTHICK_LINE_WIDTH 1
51
ed791986 52wxStatusBarGeneric::wxStatusBarGeneric()
c801d85f 53{
c67daf87
UR
54 m_statusWidths = (int *) NULL;
55 m_statusStrings = (wxString *) NULL;
c801d85f
KB
56 m_nFields = 0;
57 m_borderX = wxTHICK_LINE_BORDER;
58 m_borderY = wxTHICK_LINE_BORDER;
59}
60
ed791986 61wxStatusBarGeneric::~wxStatusBarGeneric()
c801d85f 62{
f51f94ea
VZ
63# ifdef __WXMSW__
64 SetFont(wxNullFont);
65# endif // MSW
66
67 if ( m_statusWidths )
68 delete[] m_statusWidths;
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;
a2d93e73 83 m_themeEnabled = TRUE;
c801d85f 84
ed791986
VZ
85 bool success = wxWindow::Create(parent, id,
86 wxDefaultPosition, wxDefaultSize,
87 style | wxTAB_TRAVERSAL, name);
c801d85f
KB
88
89 // Don't wish this to be found as a child
7c74e7fe 90#ifndef __WXMAC__
c0ed460c 91 parent->GetChildren().DeleteObject(this);
7c74e7fe 92#endif
c801d85f
KB
93 InitColours();
94
95 SetFont(m_defaultStatusBarFont);
96
97 return success;
98}
99
cc56206f 100void wxStatusBarGeneric::SetFieldsCount(int number, const int *widths)
c801d85f 101{
633d67bb
VZ
102 if ( number != m_nFields )
103 {
104 m_nFields = number;
c801d85f 105
f51f94ea 106 delete[] m_statusStrings;
633d67bb 107 m_statusStrings = new wxString[number];
c801d85f 108
633d67bb
VZ
109#if 0 // VZ: what is this for?
110 int i;
111 for (i = 0; i < number; i++)
112 m_statusStrings[i] = "";
113#endif
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
179 int i;
c0ed460c
JS
180 if ( GetFont().Ok() )
181 dc.SetFont(GetFont());
c801d85f 182 dc.SetBackgroundMode(wxTRANSPARENT);
37d403aa 183 dc.SetTextForeground(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOWTEXT));
c801d85f
KB
184
185 for ( i = 0; i < m_nFields; i ++ )
f51f94ea 186 DrawField(dc, i);
e97f20a0 187
f51f94ea
VZ
188# ifdef __WXMSW__
189 dc.SetFont(wxNullFont);
190# endif // MSW
c801d85f
KB
191}
192
ed791986 193void wxStatusBarGeneric::DrawFieldText(wxDC& dc, int i)
c801d85f
KB
194{
195 int leftMargin = 2;
196
16e93305 197 wxRect rect;
c801d85f
KB
198 GetFieldRect(i, rect);
199
200 wxString text(GetStatusText(i));
201
202 long x, y;
203
204 dc.GetTextExtent(text, &x, &y);
205
206 int xpos = rect.x + leftMargin;
207 int ypos = (int) (((rect.height - y) / 2 ) + rect.y + 0.5) ;
ed791986 208
7c74e7fe 209#if defined( __WXGTK__ ) || defined(__WXMAC__)
92976ab6
RR
210 xpos++;
211 ypos++;
212#endif
c801d85f
KB
213
214 dc.SetClippingRegion(rect.x, rect.y, rect.width, rect.height);
215
216 dc.DrawText(text, xpos, ypos);
217
218 dc.DestroyClippingRegion();
219}
220
ed791986 221void wxStatusBarGeneric::DrawField(wxDC& dc, int i)
c801d85f 222{
16e93305 223 wxRect rect;
c801d85f
KB
224 GetFieldRect(i, rect);
225
226 // Draw border
227 // Have grey background, plus 3-d border -
228 // One black rectangle.
229 // Inside this, left and top sides - dark grey. Bottom and right -
230 // white.
231
f51f94ea 232 dc.SetPen(m_hilightPen);
c801d85f
KB
233
234 // Right and bottom white lines
235 dc.DrawLine(rect.x + rect.width, rect.y,
236 rect.x + rect.width, rect.y + rect.height);
237 dc.DrawLine(rect.x + rect.width, rect.y + rect.height,
f51f94ea 238 rect.x, rect.y + rect.height);
c801d85f 239
f51f94ea 240 dc.SetPen(m_mediumShadowPen);
c801d85f
KB
241
242 // Left and top grey lines
243 dc.DrawLine(rect.x, rect.y + rect.height,
f51f94ea 244 rect.x, rect.y);
c801d85f 245 dc.DrawLine(rect.x, rect.y,
f51f94ea 246 rect.x + rect.width, rect.y);
c801d85f 247
f51f94ea 248 DrawFieldText(dc, i);
c801d85f
KB
249}
250
251 // Get the position and size of the field's internal bounding rectangle
ed791986 252bool wxStatusBarGeneric::GetFieldRect(int n, wxRect& rect) const
c801d85f 253{
ed791986
VZ
254 wxCHECK_MSG( (n >= 0) && (n < m_nFields), FALSE,
255 _T("invalid status bar field index") );
c801d85f
KB
256
257 int width, height;
258 GetClientSize(&width, &height);
259
260 int i;
261 int sum_of_nonvar = 0;
262 int num_of_var = 0;
263 bool do_same_width = FALSE;
264
265 int fieldWidth = 0;
266 int fieldPosition = 0;
267
268 if (m_statusWidths)
269 {
270 // if sum(not variable Windows) > c_width - (20 points per variable_window)
271 // then do_same_width = TRUE;
272 for (i = 0; i < m_nFields; i++)
273 {
274 if (m_statusWidths[i] > 0) sum_of_nonvar += m_statusWidths[i];
275 else num_of_var++;
276 }
277 if (sum_of_nonvar > (width - 20*num_of_var)) do_same_width = TRUE;
278 }
279 else do_same_width = TRUE;
280 if (do_same_width)
281 {
282 for (i = 0; i < m_nFields; i++)
283 {
284 fieldWidth = (int)(width/m_nFields);
f51f94ea
VZ
285 fieldPosition = i*fieldWidth;
286 if ( i == n )
287 break;
c801d85f
KB
288 }
289 }
290 else // no_same_width
291 {
292 int *tempwidth = new int[m_nFields];
293 int temppos = 0;
294 for (i = 0; i < m_nFields; i++)
295 {
296 if (m_statusWidths[i] > 0) tempwidth[i] = m_statusWidths[i];
297 else tempwidth[i] = (width - sum_of_nonvar) / num_of_var;
298 }
299 for (i = 0; i < m_nFields; i++)
300 {
f51f94ea
VZ
301 fieldWidth = tempwidth[i];
302 fieldPosition = temppos;
c801d85f 303
f51f94ea 304 temppos += tempwidth[i];
c801d85f 305
f51f94ea
VZ
306 if ( i == n )
307 break;
c801d85f
KB
308 }
309 delete [] tempwidth;
310 }
311
312 rect.x = fieldPosition + wxTHICK_LINE_BORDER;
f51f94ea 313 rect.y = wxTHICK_LINE_BORDER;
c801d85f 314
f51f94ea
VZ
315 rect.width = fieldWidth - 2 * wxTHICK_LINE_BORDER ;
316 rect.height = height - 2 * wxTHICK_LINE_BORDER ;
c801d85f 317
f51f94ea 318 return TRUE;
c801d85f
KB
319}
320
321// Initialize colours
ed791986 322void wxStatusBarGeneric::InitColours()
c801d85f
KB
323{
324 // Shadow colours
37d403aa 325#ifndef __WIN16__
c801d85f
KB
326 wxColour mediumShadowColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DSHADOW));
327 m_mediumShadowPen = wxPen(mediumShadowColour, 1, wxSOLID);
328
329 wxColour hilightColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DHILIGHT));
330 m_hilightPen = wxPen(hilightColour, 1, wxSOLID);
331#else
332 m_mediumShadowPen = wxPen("GREY", 1, wxSOLID);
333 m_hilightPen = wxPen("WHITE", 1, wxSOLID);
334#endif
335
16c1f7f3 336 m_defaultStatusBarFont = wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT);
c801d85f
KB
337 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
338}
339
340// Responds to colour changes, and passes event on to children.
ed791986 341void wxStatusBarGeneric::OnSysColourChanged(wxSysColourChangedEvent& event)
c801d85f
KB
342{
343 InitColours();
344 Refresh();
345
346 // Propagate the event to the non-top-level children
347 wxWindow::OnSysColourChanged(event);
348}
349
ed791986
VZ
350void wxStatusBarGeneric::SetMinHeight(int height)
351{
352 // check that this min height is not less than minimal height for the
353 // current font
354 wxClientDC dc(this);
355 wxCoord y;
356 dc.GetTextExtent( _T("X"), NULL, &y );
357
358 if ( height > (11*y)/10 )
359 {
360 SetSize(-1, -1, -1, height + 2*m_borderY);
361 }
362}
363
364//#endif // Win32 && wxUSE_NATIVE_STATUSBAR