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