]> git.saurik.com Git - wxWidgets.git/blame - src/generic/statusbr.cpp
A few compile things.
[wxWidgets.git] / src / generic / statusbr.cpp
CommitLineData
c801d85f
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: statusbr.cpp
3// Purpose: wxStatusBar 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
f51f94ea 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
23#ifndef WX_PRECOMP
24#include "wx/setup.h"
25#include "wx/frame.h"
26#include "wx/settings.h"
27#include "wx/dcclient.h"
28#endif
29
30#include "wx/generic/statusbr.h"
31
2049ba38 32#ifdef __WXMSW__
c801d85f 33#include <windows.h>
25889d3c 34#include "wx/msw/winundef.h"
c801d85f
KB
35#endif
36
37#if !USE_SHARED_LIBRARY
38IMPLEMENT_DYNAMIC_CLASS(wxStatusBar, wxWindow)
39
40BEGIN_EVENT_TABLE(wxStatusBar, wxWindow)
f51f94ea 41 EVT_PAINT(wxStatusBar::OnPaint)
c801d85f
KB
42 EVT_SYS_COLOUR_CHANGED(wxStatusBar::OnSysColourChanged)
43END_EVENT_TABLE()
44#endif
45
46// Default status border dimensions
47#define wxTHICK_LINE_BORDER 2
48#define wxTHICK_LINE_WIDTH 1
49
50wxStatusBar::wxStatusBar(void)
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
59wxStatusBar::~wxStatusBar(void)
60{
f51f94ea
VZ
61# ifdef __WXMSW__
62 SetFont(wxNullFont);
63# endif // MSW
64
65 if ( m_statusWidths )
66 delete[] m_statusWidths;
67 if ( m_statusStrings )
68 delete[] m_statusStrings;
c801d85f
KB
69}
70
debe6624 71bool wxStatusBar::Create(wxWindow *parent, wxWindowID id,
c801d85f
KB
72 const wxPoint& pos,
73 const wxSize& size,
debe6624 74 long style,
c801d85f
KB
75 const wxString& name)
76{
c67daf87
UR
77 m_statusWidths = (int *) NULL;
78 m_statusStrings = (wxString *) NULL;
c801d85f
KB
79 m_nFields = 0;
80 m_borderX = wxTHICK_LINE_BORDER;
81 m_borderY = wxTHICK_LINE_BORDER;
82
b292e2f5 83 bool success = wxWindow::Create(parent, id, pos, size, style | wxTAB_TRAVERSAL, name);
c801d85f
KB
84
85 // Don't wish this to be found as a child
c0ed460c 86 parent->GetChildren().DeleteObject(this);
c801d85f
KB
87
88 InitColours();
89
90 SetFont(m_defaultStatusBarFont);
91
92 return success;
93}
94
8b9518ee 95void wxStatusBar::SetFieldsCount(int number, const int widths[])
c801d85f
KB
96{
97 m_nFields = number;
98
99 if ( m_statusWidths )
f51f94ea 100 delete[] m_statusWidths;
c801d85f
KB
101
102 if ( m_statusStrings )
f51f94ea 103 delete[] m_statusStrings;
c801d85f
KB
104
105 m_statusStrings = new wxString[number];
106
107 int i;
108 for (i = 0; i < number; i++)
f51f94ea 109 m_statusStrings[i] = "";
c801d85f 110
f51f94ea
VZ
111 if ( widths )
112 SetStatusWidths(number, widths);
c801d85f
KB
113}
114
debe6624 115void wxStatusBar::SetStatusText(const wxString& text, int number)
c801d85f
KB
116{
117 if ((number < 0) || (number >= m_nFields))
118 return;
119
120 m_statusStrings[number] = text;
121
122 Refresh();
123
2049ba38 124#ifdef __WXMSW__
c801d85f
KB
125 // For some reason, this can cause major GDI problems - graphics
126 // all over the place. E.g. in print previewing.
127// ::UpdateWindow((HWND) GetHWND());
128#endif
129}
130
debe6624 131wxString wxStatusBar::GetStatusText(int n) const
c801d85f
KB
132{
133 if ((n < 0) || (n >= m_nFields))
134 return wxString("");
135 else
136 return m_statusStrings[n];
137}
138
8b9518ee 139void wxStatusBar::SetStatusWidths(int n, const int widths_field[])
c801d85f
KB
140{
141 // only set status widths, when n == number of statuswindows
142 if (n == m_nFields)
143 {
144 // only set status widths,
145 // when one window (minimum) is variable (width <= 0)
146 bool is_variable = FALSE;
147 int i;
148 for (i = 0; i < m_nFields; i++)
149 {
150 if (widths_field[i] <= 0) is_variable = TRUE;
151 }
152
153 // if there are old widths, delete them
154 if (m_statusWidths)
155 delete [] m_statusWidths;
156
157 // set widths
158 m_statusWidths = new int[n];
159 for (i = 0; i < m_nFields; i++)
160 {
161 m_statusWidths[i] = widths_field[i];
162 }
163 }
164}
165
166void wxStatusBar::OnPaint(wxPaintEvent& WXUNUSED(event) )
167{
168 wxPaintDC dc(this);
169
170 int i;
c0ed460c
JS
171 if ( GetFont().Ok() )
172 dc.SetFont(GetFont());
c801d85f
KB
173 dc.SetBackgroundMode(wxTRANSPARENT);
174
175 for ( i = 0; i < m_nFields; i ++ )
f51f94ea 176 DrawField(dc, i);
e97f20a0 177
f51f94ea
VZ
178# ifdef __WXMSW__
179 dc.SetFont(wxNullFont);
180# endif // MSW
c801d85f
KB
181}
182
debe6624 183void wxStatusBar::DrawFieldText(wxDC& dc, int i)
c801d85f
KB
184{
185 int leftMargin = 2;
186
16e93305 187 wxRect rect;
c801d85f
KB
188 GetFieldRect(i, rect);
189
190 wxString text(GetStatusText(i));
191
192 long x, y;
193
194 dc.GetTextExtent(text, &x, &y);
195
196 int xpos = rect.x + leftMargin;
197 int ypos = (int) (((rect.height - y) / 2 ) + rect.y + 0.5) ;
92976ab6
RR
198
199#ifdef __WXGTK__
200 xpos++;
201 ypos++;
202#endif
c801d85f
KB
203
204 dc.SetClippingRegion(rect.x, rect.y, rect.width, rect.height);
205
206 dc.DrawText(text, xpos, ypos);
207
208 dc.DestroyClippingRegion();
209}
210
debe6624 211void wxStatusBar::DrawField(wxDC& dc, int i)
c801d85f 212{
16e93305 213 wxRect rect;
c801d85f
KB
214 GetFieldRect(i, rect);
215
216 // Draw border
217 // Have grey background, plus 3-d border -
218 // One black rectangle.
219 // Inside this, left and top sides - dark grey. Bottom and right -
220 // white.
221
f51f94ea 222 dc.SetPen(m_hilightPen);
c801d85f
KB
223
224 // Right and bottom white lines
225 dc.DrawLine(rect.x + rect.width, rect.y,
226 rect.x + rect.width, rect.y + rect.height);
227 dc.DrawLine(rect.x + rect.width, rect.y + rect.height,
f51f94ea 228 rect.x, rect.y + rect.height);
c801d85f 229
f51f94ea 230 dc.SetPen(m_mediumShadowPen);
c801d85f
KB
231
232 // Left and top grey lines
233 dc.DrawLine(rect.x, rect.y + rect.height,
f51f94ea 234 rect.x, rect.y);
c801d85f 235 dc.DrawLine(rect.x, rect.y,
f51f94ea 236 rect.x + rect.width, rect.y);
c801d85f 237
f51f94ea 238 DrawFieldText(dc, i);
c801d85f
KB
239}
240
241 // Get the position and size of the field's internal bounding rectangle
16e93305 242bool wxStatusBar::GetFieldRect(int n, wxRect& rect) const
c801d85f
KB
243{
244 if ((n < 0) || (n >= m_nFields))
245 return FALSE;
246
247 int width, height;
248 GetClientSize(&width, &height);
249
250 int i;
251 int sum_of_nonvar = 0;
252 int num_of_var = 0;
253 bool do_same_width = FALSE;
254
255 int fieldWidth = 0;
256 int fieldPosition = 0;
257
258 if (m_statusWidths)
259 {
260 // if sum(not variable Windows) > c_width - (20 points per variable_window)
261 // then do_same_width = TRUE;
262 for (i = 0; i < m_nFields; i++)
263 {
264 if (m_statusWidths[i] > 0) sum_of_nonvar += m_statusWidths[i];
265 else num_of_var++;
266 }
267 if (sum_of_nonvar > (width - 20*num_of_var)) do_same_width = TRUE;
268 }
269 else do_same_width = TRUE;
270 if (do_same_width)
271 {
272 for (i = 0; i < m_nFields; i++)
273 {
274 fieldWidth = (int)(width/m_nFields);
f51f94ea
VZ
275 fieldPosition = i*fieldWidth;
276 if ( i == n )
277 break;
c801d85f
KB
278 }
279 }
280 else // no_same_width
281 {
282 int *tempwidth = new int[m_nFields];
283 int temppos = 0;
284 for (i = 0; i < m_nFields; i++)
285 {
286 if (m_statusWidths[i] > 0) tempwidth[i] = m_statusWidths[i];
287 else tempwidth[i] = (width - sum_of_nonvar) / num_of_var;
288 }
289 for (i = 0; i < m_nFields; i++)
290 {
f51f94ea
VZ
291 fieldWidth = tempwidth[i];
292 fieldPosition = temppos;
c801d85f 293
f51f94ea 294 temppos += tempwidth[i];
c801d85f 295
f51f94ea
VZ
296 if ( i == n )
297 break;
c801d85f
KB
298 }
299 delete [] tempwidth;
300 }
301
302 rect.x = fieldPosition + wxTHICK_LINE_BORDER;
f51f94ea 303 rect.y = wxTHICK_LINE_BORDER;
c801d85f 304
f51f94ea
VZ
305 rect.width = fieldWidth - 2 * wxTHICK_LINE_BORDER ;
306 rect.height = height - 2 * wxTHICK_LINE_BORDER ;
c801d85f 307
f51f94ea 308 return TRUE;
c801d85f
KB
309}
310
311// Initialize colours
312void wxStatusBar::InitColours(void)
313{
314 // Shadow colours
315#if defined(__WIN95__)
316 wxColour mediumShadowColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DSHADOW));
317 m_mediumShadowPen = wxPen(mediumShadowColour, 1, wxSOLID);
318
319 wxColour hilightColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DHILIGHT));
320 m_hilightPen = wxPen(hilightColour, 1, wxSOLID);
321#else
322 m_mediumShadowPen = wxPen("GREY", 1, wxSOLID);
323 m_hilightPen = wxPen("WHITE", 1, wxSOLID);
324#endif
325
16c1f7f3 326 m_defaultStatusBarFont = wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT);
c801d85f
KB
327 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
328}
329
330// Responds to colour changes, and passes event on to children.
331void wxStatusBar::OnSysColourChanged(wxSysColourChangedEvent& event)
332{
333 InitColours();
334 Refresh();
335
336 // Propagate the event to the non-top-level children
337 wxWindow::OnSysColourChanged(event);
338}
339