]> git.saurik.com Git - wxWidgets.git/blame - src/univ/statusbr.cpp
generate key events for Space/Enter in addition to the activate events, as wxMSW...
[wxWidgets.git] / src / univ / statusbr.cpp
CommitLineData
71e03035
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: univ/statusbr.cpp
3// Purpose: wxStatusBar implementation
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 14.10.01
7// RCS-ID: $Id$
8// Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com)
9// Licence: wxWindows license
10/////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
20#ifdef __GNUG__
21 #pragma implementation "univstatusbr.h"
22#endif
23
24#include "wx/wxprec.h"
25
26#ifdef __BORLANDC__
27 #pragma hdrstop
28#endif
29
30#if wxUSE_STATUSBAR
31
32#ifndef WX_PRECOMP
fe9fea7e
VS
33 #include "wx/settings.h"
34 #include "wx/dcclient.h"
71e03035
VZ
35#endif
36
37#include "wx/statusbr.h"
c60ba92d 38#include "wx/toplevel.h"
71e03035
VZ
39
40#include "wx/univ/renderer.h"
41
42// ============================================================================
43// implementation
44// ============================================================================
45
46BEGIN_EVENT_TABLE(wxStatusBarUniv, wxStatusBarBase)
47 EVT_SIZE(wxStatusBarUniv::OnSize)
48
49 WX_EVENT_TABLE_INPUT_CONSUMER(wxStatusBarUniv)
50END_EVENT_TABLE()
51
52WX_FORWARD_TO_INPUT_CONSUMER(wxStatusBarUniv)
53
54// ----------------------------------------------------------------------------
55// creation
56// ----------------------------------------------------------------------------
57
58void wxStatusBarUniv::Init()
59{
60}
61
62bool wxStatusBarUniv::Create(wxWindow *parent,
63 wxWindowID id,
64 long style,
65 const wxString& name)
66{
67 if ( !wxWindow::Create(parent, id,
68 wxDefaultPosition, wxDefaultSize,
69 style, name) )
70 {
71 return FALSE;
72 }
73
74 SetFieldsCount(1);
75
76 CreateInputHandler(wxINP_HANDLER_STATUSBAR);
77
78 SetSize(DoGetBestSize());
79
80 return TRUE;
81}
82
83// ----------------------------------------------------------------------------
84// drawing
85// ----------------------------------------------------------------------------
86
87wxRect wxStatusBarUniv::GetTotalFieldRect(wxCoord *borderBetweenFields)
88{
71e03035
VZ
89 wxRect rect = GetClientRect();
90
91 // no, don't do this - the borders are meant to be inside this rect
cece1d88
VZ
92 // wxSize sizeBorders =
93 m_renderer->GetStatusBarBorders(borderBetweenFields);
71e03035
VZ
94 //rect.Deflate(sizeBorders.x, sizeBorders.y);
95
96 // recalc the field widths if needed
97 if ( m_widthsAbs.IsEmpty() )
98 {
99 // the total width for the fields doesn't include the borders between
100 // them
101 m_widthsAbs = CalculateAbsWidths(rect.width -
102 *borderBetweenFields*(m_nFields - 1));
103 }
104
105 return rect;
106}
107
108void wxStatusBarUniv::DoDraw(wxControlRenderer *renderer)
109{
110 // get the fields rect
111 wxCoord borderBetweenFields;
112 wxRect rect = GetTotalFieldRect(&borderBetweenFields);
113
114 // prepare the DC
115 wxDC& dc = renderer->GetDC();
a756f210 116 dc.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
71e03035
VZ
117
118 // do draw the fields
119 int flags = IsEnabled() ? 0 : wxCONTROL_DISABLED;
120 for ( int n = 0; n < m_nFields; n++ )
121 {
122 rect.width = m_widthsAbs[n];
123
124 if ( IsExposed(rect) )
125 {
c60ba92d 126 wxTopLevelWindow *parentTLW = wxDynamicCast(GetParent(), wxTopLevelWindow);
5057e659 127
71e03035
VZ
128 // the size grip may be drawn only on the last field and only if we
129 // have the corresponding style and even then only if we really can
130 // resize this frame
131 if ( n == m_nFields - 1 &&
132 HasFlag(wxST_SIZEGRIP) &&
c60ba92d
VS
133 GetParent()->HasFlag(wxRESIZE_BORDER) &&
134 parentTLW && !parentTLW->IsMaximized() )
71e03035
VZ
135 {
136 // NB: we use wxCONTROL_ISDEFAULT for this because it doesn't
137 // have any meaning for the status bar otherwise anyhow
138 // (it's still ugly, of course, but there are too few flags
139 // to squander them for things like this)
140 flags |= wxCONTROL_ISDEFAULT;
141 }
142
143 m_renderer->DrawStatusField(dc, rect, m_statusText[n], flags);
144 }
145
146 rect.x += rect.width + borderBetweenFields;
147 }
148}
149
150void wxStatusBarUniv::RefreshField(int i)
151{
152 wxRect rect;
153 if ( GetFieldRect(i, rect) )
154 {
155 RefreshRect(rect);
156 }
157}
158
159// ----------------------------------------------------------------------------
160// fields text
161// ----------------------------------------------------------------------------
162
163void wxStatusBarUniv::SetStatusText(const wxString& text, int number)
164{
165 wxCHECK_RET( number >= 0 && number < m_nFields,
166 _T("invalid status bar field index in SetStatusText()") );
167
168 if ( text == m_statusText[number] )
169 {
170 // nothing changed
171 return;
172 }
173
174 m_statusText[number] = text;
175
176 RefreshField(number);
177}
178
179wxString wxStatusBarUniv::GetStatusText(int number) const
180{
181 wxCHECK_MSG( number >= 0 && number < m_nFields, _T(""),
182 _T("invalid status bar field index") );
183
184 return m_statusText[number];
185}
186
187// ----------------------------------------------------------------------------
188// fields count/widths
189// ----------------------------------------------------------------------------
190
191void wxStatusBarUniv::SetFieldsCount(int number, const int *widths)
192{
71e03035 193 m_statusText.SetCount(number);
ca7497c2 194 wxStatusBarBase::SetFieldsCount(number, widths);
71e03035
VZ
195 m_widthsAbs.Empty();
196}
197
198void wxStatusBarUniv::SetStatusWidths(int n, const int widths[])
199{
200 wxStatusBarBase::SetStatusWidths(n, widths);
201
202 m_widthsAbs.Empty();
203}
204
205// ----------------------------------------------------------------------------
206// geometry
207// ----------------------------------------------------------------------------
208
209void wxStatusBarUniv::OnSize(wxSizeEvent& event)
210{
5057e659
VZ
211 // we don't need to refresh the fields whose width didn't change, so find
212 // the first field whose width did change and refresh starting from it
213 int field;
214 if ( m_statusWidths )
215 {
216 for ( field = 0; field < m_nFields; field++ )
217 {
218 if ( m_statusWidths[field] < 0 )
219 {
220 // var width field
221 break;
222 }
223 }
224 }
225 else // all fields have the same width
226 {
227 // hence all fields widths have changed
228 field = 0;
229 }
71e03035 230
5057e659
VZ
231 if ( field < m_nFields )
232 {
233 // call this before invalidating the old widths as we want to use them,
234 // not the new ones
235 wxRect rect = DoGetFieldRect(field);
236
237 // invalidate the widths, we'll have to recalc them
238 m_widthsAbs.Empty();
239
240 // refresh everything after the first invalid field
241 rect.y = 0;
242 rect.SetRight(event.GetSize().x);
243 rect.height = event.GetSize().y;
244 RefreshRect(rect);
245 }
71e03035
VZ
246
247 event.Skip();
248}
249
250bool wxStatusBarUniv::GetFieldRect(int n, wxRect& rect) const
251{
252 wxCHECK_MSG( n >= 0 && n < m_nFields, FALSE,
253 _T("invalid field index in GetFieldRect()") );
254
255 // this is a fix for a bug exhibited by the statbar sample: if
256 // GetFieldRect() is called from the derived class OnSize() handler, then
257 // our geometry info is wrong as our OnSize() didn't invalidate m_widthsAbs
258 // yet - so recalc it just in case
5057e659
VZ
259 wxConstCast(this, wxStatusBarUniv)->m_widthsAbs.Empty();
260
261 rect = DoGetFieldRect(n);
262
263 return TRUE;
264}
265
266wxRect wxStatusBarUniv::DoGetFieldRect(int n) const
267{
71e03035 268 wxStatusBarUniv *self = wxConstCast(this, wxStatusBarUniv);
71e03035
VZ
269
270 wxCoord borderBetweenFields;
5057e659
VZ
271 wxRect rect = self->GetTotalFieldRect(&borderBetweenFields);
272
273 // it's the caller responsability to check this, if unsure - call
274 // GetFieldRect() instead
275 wxCHECK_MSG( !m_widthsAbs.IsEmpty(), rect,
276 _T("can't be called if we don't have the widths") );
277
71e03035
VZ
278 for ( int i = 0; i <= n; i++ )
279 {
280 rect.width = m_widthsAbs[i];
281
282 if ( i < n )
283 rect.x += rect.width + borderBetweenFields;
284 }
285
5057e659 286 return rect;
71e03035
VZ
287}
288
289wxCoord wxStatusBarUniv::GetHeight() const
290{
291 wxClientDC dc(wxConstCast(this, wxStatusBarUniv));
a756f210 292 dc.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
71e03035
VZ
293
294 return dc.GetCharHeight() + 2*GetBorderY();
295}
296
297wxSize wxStatusBarUniv::DoGetBestSize() const
298{
299 return wxSize(100, GetHeight());
300}
301
302void wxStatusBarUniv::DoSetSize(int x, int y,
303 int width, int WXUNUSED(height),
304 int sizeFlags)
305{
306 wxStatusBarBase::DoSetSize(x, y, width, GetHeight(), sizeFlags);
307}
308
309// ----------------------------------------------------------------------------
310// misc
311// ----------------------------------------------------------------------------
312
313void wxStatusBarUniv::SetMinHeight(int WXUNUSED(height))
314{
315 // nothing to do here, we don't support it - and why would we?
316}
317
318int wxStatusBarUniv::GetBorderX() const
319{
320 return m_renderer->GetStatusBarBorders(NULL).x;
321}
322
323int wxStatusBarUniv::GetBorderY() const
324{
325 return m_renderer->GetStatusBarBorders(NULL).y;
326}
327
328#endif // wxUSE_STATUSBAR
329