]> git.saurik.com Git - wxWidgets.git/blob - src/generic/statusbr.cpp
Fix cvs conflict.
[wxWidgets.git] / src / generic / statusbr.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: generic/statusbr.cpp
3 // Purpose: wxStatusBarGeneric class implementation
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 01/02/97
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
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
23 //#if !defined(__WIN32__) || !wxUSE_NATIVE_STATUSBAR
24
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
32 #include "wx/statusbr.h"
33
34 // with wxUSE_NATIVE_STATUSBAR it is not included from wx/statusbr.h
35 #include "wx/generic/statusbr.h"
36
37 IMPLEMENT_DYNAMIC_CLASS(wxStatusBarGeneric, wxWindow)
38
39 #if !defined(__WIN32__) || !wxUSE_NATIVE_STATUSBAR
40 IMPLEMENT_DYNAMIC_CLASS(wxStatusBar, wxStatusBarGeneric)
41 #endif // Win32 && wxUSE_NATIVE_STATUSBAR
42
43 BEGIN_EVENT_TABLE(wxStatusBarGeneric, wxWindow)
44 EVT_PAINT(wxStatusBarGeneric::OnPaint)
45 EVT_SYS_COLOUR_CHANGED(wxStatusBarGeneric::OnSysColourChanged)
46 END_EVENT_TABLE()
47
48 // Default status border dimensions
49 #define wxTHICK_LINE_BORDER 2
50 #define wxTHICK_LINE_WIDTH 1
51
52 wxStatusBarGeneric::wxStatusBarGeneric()
53 {
54 m_statusWidths = (int *) NULL;
55 m_statusStrings = (wxString *) NULL;
56 m_nFields = 0;
57 m_borderX = wxTHICK_LINE_BORDER;
58 m_borderY = wxTHICK_LINE_BORDER;
59 }
60
61 wxStatusBarGeneric::~wxStatusBarGeneric()
62 {
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;
71 }
72
73 bool wxStatusBarGeneric::Create(wxWindow *parent,
74 wxWindowID id,
75 long style,
76 const wxString& name)
77 {
78 m_statusWidths = (int *) NULL;
79 m_statusStrings = (wxString *) NULL;
80 m_nFields = 0;
81 m_borderX = wxTHICK_LINE_BORDER;
82 m_borderY = wxTHICK_LINE_BORDER;
83
84 bool success = wxWindow::Create(parent, id,
85 wxDefaultPosition, wxDefaultSize,
86 style | wxTAB_TRAVERSAL, name);
87
88 // Don't wish this to be found as a child
89 #ifndef __WXMAC__
90 parent->GetChildren().DeleteObject(this);
91 #endif
92 InitColours();
93
94 SetFont(m_defaultStatusBarFont);
95
96 return success;
97 }
98
99 void wxStatusBarGeneric::SetFieldsCount(int number, const int *widths)
100 {
101 if ( number != m_nFields )
102 {
103 m_nFields = number;
104
105 delete[] m_statusStrings;
106 m_statusStrings = new wxString[number];
107
108 #if 0 // VZ: what is this for?
109 int i;
110 for (i = 0; i < number; i++)
111 m_statusStrings[i] = "";
112 #endif
113 }
114
115 SetStatusWidths(number, widths);
116 }
117
118 void wxStatusBarGeneric::SetStatusText(const wxString& text, int number)
119 {
120 wxCHECK_RET( (number >= 0) && (number < m_nFields),
121 _T("invalid status bar field index") );
122
123 m_statusStrings[number] = text;
124
125 Refresh();
126 }
127
128 wxString wxStatusBarGeneric::GetStatusText(int n) const
129 {
130 wxCHECK_MSG( (n >= 0) && (n < m_nFields), wxEmptyString,
131 _T("invalid status bar field index") );
132
133 return m_statusStrings[n];
134 }
135
136 void wxStatusBarGeneric::SetStatusWidths(int n, const int widths_field[])
137 {
138 // only set status widths, when n == number of statuswindows
139 wxCHECK_RET( n == m_nFields, _T("status bar field count mismatch") );
140
141 // delete the old widths in any case - this function may be used to reset
142 // the widths to the default (all equal)
143 delete [] m_statusWidths;
144
145 if ( !widths_field )
146 {
147 // not an error, see the comment above
148 m_statusWidths = (int *)NULL;
149
150 return;
151 }
152
153 int i;
154
155 // VZ: this doesn't do anything as is_variable is unused later
156 #if 0
157 // when one window (minimum) is variable (width <= 0)
158 bool is_variable = FALSE;
159 for (i = 0; i < m_nFields; i++)
160 {
161 if (widths_field[i] <= 0)
162 is_variable = TRUE;
163 }
164 #endif // 0
165
166 // set widths
167 m_statusWidths = new int[n];
168 for (i = 0; i < m_nFields; i++)
169 {
170 m_statusWidths[i] = widths_field[i];
171 }
172 }
173
174 void wxStatusBarGeneric::OnPaint(wxPaintEvent& WXUNUSED(event) )
175 {
176 wxPaintDC dc(this);
177
178
179 int i;
180 if ( GetFont().Ok() )
181 dc.SetFont(GetFont());
182 dc.SetBackgroundMode(wxTRANSPARENT);
183
184 #ifdef __WXPM__
185 wxColour vColor;
186
187 vColor.InitFromName("GREY");
188 ::WinFillRect(dc.m_hPS, &dc.m_vRclPaint, vColor.GetPixel());
189 #endif
190
191 for ( i = 0; i < m_nFields; i ++ )
192 DrawField(dc, i);
193
194 #ifdef __WXMSW__
195 dc.SetFont(wxNullFont);
196 #endif // MSW
197 }
198
199 void wxStatusBarGeneric::DrawFieldText(wxDC& dc, int i)
200 {
201 int leftMargin = 2;
202
203 wxRect rect;
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) ;
214
215 #if defined( __WXGTK__ ) || defined(__WXMAC__)
216 xpos++;
217 ypos++;
218 #endif
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
227 void wxStatusBarGeneric::DrawField(wxDC& dc, int i)
228 {
229 wxRect rect;
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
238 dc.SetPen(m_hilightPen);
239
240 #ifndef __WXPM__
241
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,
246 rect.x, rect.y + rect.height);
247
248 dc.SetPen(m_mediumShadowPen);
249
250 // Left and top grey lines
251 dc.DrawLine(rect.x, rect.y + rect.height,
252 rect.x, rect.y);
253 dc.DrawLine(rect.x, rect.y,
254 rect.x + rect.width, rect.y);
255 #else
256 // Right
257 dc.DrawLine(rect.x + rect.width, rect.y,
258 rect.x + rect.width, rect.y + rect.height + 2);
259 dc.SetPen(m_mediumShadowPen);
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);
264 // Top
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);
269 dc.SetPen(m_hilightPen);
270 dc.DrawLine(rect.x + rect.width, rect.y - 2,
271 rect.x - 2, rect.y - 2);
272
273 #endif
274
275 DrawFieldText(dc, i);
276 }
277
278 // Get the position and size of the field's internal bounding rectangle
279 bool wxStatusBarGeneric::GetFieldRect(int n, wxRect& rect) const
280 {
281 wxCHECK_MSG( (n >= 0) && (n < m_nFields), FALSE,
282 _T("invalid status bar field index") );
283
284 int width, height;
285 #ifdef __WXPM__
286 GetSize(&width, &height);
287 #else
288 GetClientSize(&width, &height);
289 #endif
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);
316 fieldPosition = i*fieldWidth;
317 if ( i == n )
318 break;
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 {
332 fieldWidth = tempwidth[i];
333 fieldPosition = temppos;
334
335 temppos += tempwidth[i];
336
337 if ( i == n )
338 break;
339 }
340 delete [] tempwidth;
341 }
342
343 rect.x = fieldPosition + wxTHICK_LINE_BORDER;
344 rect.y = wxTHICK_LINE_BORDER;
345
346 rect.width = fieldWidth - 2 * wxTHICK_LINE_BORDER ;
347 rect.height = height - 2 * wxTHICK_LINE_BORDER ;
348
349 return TRUE;
350 }
351
352 // Initialize colours
353 void wxStatusBarGeneric::InitColours()
354 {
355 // Shadow colours
356 #if defined(__WIN95__)
357 wxColour mediumShadowColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DSHADOW));
358 m_mediumShadowPen = wxPen(mediumShadowColour, 1, wxSOLID);
359
360 wxColour hilightColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DHILIGHT));
361 m_hilightPen = wxPen(hilightColour, 1, wxSOLID);
362 #elif defined(__WXPM__)
363 m_mediumShadowPen = wxPen("LIGHT GREY", 1, wxSOLID);
364 m_hilightPen = wxPen("WHITE", 1, wxSOLID);
365 #else
366 m_mediumShadowPen = wxPen("GREY", 1, wxSOLID);
367 m_hilightPen = wxPen("WHITE", 1, wxSOLID);
368 #endif
369
370 m_defaultStatusBarFont = wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT);
371 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
372 }
373
374 // Responds to colour changes, and passes event on to children.
375 void wxStatusBarGeneric::OnSysColourChanged(wxSysColourChangedEvent& event)
376 {
377 InitColours();
378 Refresh();
379
380 // Propagate the event to the non-top-level children
381 wxWindow::OnSysColourChanged(event);
382 }
383
384 void wxStatusBarGeneric::SetMinHeight(int height)
385 {
386 // check that this min height is not less than minimal height for the
387 // current font
388 wxClientDC dc(this);
389 wxCoord y;
390 dc.GetTextExtent( _T("X"), NULL, &y );
391
392 if ( height > (11*y)/10 )
393 {
394 SetSize(-1, -1, -1, height + 2*m_borderY);
395 }
396 }
397
398 //#endif // Win32 && wxUSE_NATIVE_STATUSBAR