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