]> git.saurik.com Git - wxWidgets.git/blame - src/univ/statusbr.cpp
further encapsulation of graphics context, wxdc becoming 'generic'
[wxWidgets.git] / src / univ / statusbr.cpp
CommitLineData
71e03035 1/////////////////////////////////////////////////////////////////////////////
3304646d 2// Name: src/univ/statusbr.cpp
71e03035
VZ
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
3304646d
WS
28#include "wx/statusbr.h"
29
71e03035 30#ifndef WX_PRECOMP
fe9fea7e
VS
31 #include "wx/settings.h"
32 #include "wx/dcclient.h"
1832043f 33 #include "wx/toplevel.h"
71e03035
VZ
34#endif
35
71e03035
VZ
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 131 {
fb61f58a 132 flags |= wxCONTROL_SIZEGRIP;
71e03035
VZ
133 }
134
c2919ab3
VZ
135 int style;
136 if (m_statusStyles)
137 style = m_statusStyles[n];
138 else
139 style = wxSB_NORMAL;
140 m_renderer->DrawStatusField(dc, rect, m_statusText[n], flags, style);
71e03035
VZ
141 }
142
143 rect.x += rect.width + borderBetweenFields;
144 }
145}
146
147void wxStatusBarUniv::RefreshField(int i)
148{
149 wxRect rect;
150 if ( GetFieldRect(i, rect) )
151 {
152 RefreshRect(rect);
153 }
154}
155
156// ----------------------------------------------------------------------------
157// fields text
158// ----------------------------------------------------------------------------
159
160void wxStatusBarUniv::SetStatusText(const wxString& text, int number)
161{
162 wxCHECK_RET( number >= 0 && number < m_nFields,
163 _T("invalid status bar field index in SetStatusText()") );
164
165 if ( text == m_statusText[number] )
166 {
167 // nothing changed
168 return;
169 }
170
171 m_statusText[number] = text;
172
173 RefreshField(number);
174}
175
176wxString wxStatusBarUniv::GetStatusText(int number) const
177{
0966aee3 178 wxCHECK_MSG( number >= 0 && number < m_nFields, wxEmptyString,
71e03035
VZ
179 _T("invalid status bar field index") );
180
181 return m_statusText[number];
182}
183
184// ----------------------------------------------------------------------------
185// fields count/widths
186// ----------------------------------------------------------------------------
187
188void wxStatusBarUniv::SetFieldsCount(int number, const int *widths)
189{
71e03035 190 m_statusText.SetCount(number);
ca7497c2 191 wxStatusBarBase::SetFieldsCount(number, widths);
71e03035
VZ
192 m_widthsAbs.Empty();
193}
194
195void wxStatusBarUniv::SetStatusWidths(int n, const int widths[])
196{
197 wxStatusBarBase::SetStatusWidths(n, widths);
198
199 m_widthsAbs.Empty();
200}
201
202// ----------------------------------------------------------------------------
203// geometry
204// ----------------------------------------------------------------------------
205
206void wxStatusBarUniv::OnSize(wxSizeEvent& event)
207{
5057e659
VZ
208 // we don't need to refresh the fields whose width didn't change, so find
209 // the first field whose width did change and refresh starting from it
210 int field;
211 if ( m_statusWidths )
212 {
213 for ( field = 0; field < m_nFields; field++ )
214 {
215 if ( m_statusWidths[field] < 0 )
216 {
217 // var width field
218 break;
219 }
220 }
221 }
222 else // all fields have the same width
223 {
224 // hence all fields widths have changed
225 field = 0;
226 }
71e03035 227
5057e659
VZ
228 if ( field < m_nFields )
229 {
230 // call this before invalidating the old widths as we want to use them,
231 // not the new ones
232 wxRect rect = DoGetFieldRect(field);
233
234 // invalidate the widths, we'll have to recalc them
235 m_widthsAbs.Empty();
236
237 // refresh everything after the first invalid field
238 rect.y = 0;
239 rect.SetRight(event.GetSize().x);
240 rect.height = event.GetSize().y;
241 RefreshRect(rect);
242 }
71e03035
VZ
243
244 event.Skip();
245}
246
247bool wxStatusBarUniv::GetFieldRect(int n, wxRect& rect) const
248{
a290fa5a 249 wxCHECK_MSG( n >= 0 && n < m_nFields, false,
71e03035
VZ
250 _T("invalid field index in GetFieldRect()") );
251
252 // this is a fix for a bug exhibited by the statbar sample: if
253 // GetFieldRect() is called from the derived class OnSize() handler, then
254 // our geometry info is wrong as our OnSize() didn't invalidate m_widthsAbs
255 // yet - so recalc it just in case
5057e659
VZ
256 wxConstCast(this, wxStatusBarUniv)->m_widthsAbs.Empty();
257
258 rect = DoGetFieldRect(n);
259
a290fa5a 260 return true;
5057e659
VZ
261}
262
263wxRect wxStatusBarUniv::DoGetFieldRect(int n) const
264{
71e03035 265 wxStatusBarUniv *self = wxConstCast(this, wxStatusBarUniv);
71e03035
VZ
266
267 wxCoord borderBetweenFields;
5057e659
VZ
268 wxRect rect = self->GetTotalFieldRect(&borderBetweenFields);
269
270 // it's the caller responsability to check this, if unsure - call
271 // GetFieldRect() instead
272 wxCHECK_MSG( !m_widthsAbs.IsEmpty(), rect,
273 _T("can't be called if we don't have the widths") );
274
71e03035
VZ
275 for ( int i = 0; i <= n; i++ )
276 {
277 rect.width = m_widthsAbs[i];
278
279 if ( i < n )
280 rect.x += rect.width + borderBetweenFields;
281 }
282
5057e659 283 return rect;
71e03035
VZ
284}
285
286wxCoord wxStatusBarUniv::GetHeight() const
287{
3083f142 288 return GetCharHeight() + 2*GetBorderY();
71e03035
VZ
289}
290
291wxSize wxStatusBarUniv::DoGetBestSize() const
292{
293 return wxSize(100, GetHeight());
294}
295
296void wxStatusBarUniv::DoSetSize(int x, int y,
297 int width, int WXUNUSED(height),
298 int sizeFlags)
299{
300 wxStatusBarBase::DoSetSize(x, y, width, GetHeight(), sizeFlags);
301}
302
303// ----------------------------------------------------------------------------
304// misc
305// ----------------------------------------------------------------------------
306
307void wxStatusBarUniv::SetMinHeight(int WXUNUSED(height))
308{
309 // nothing to do here, we don't support it - and why would we?
310}
311
312int wxStatusBarUniv::GetBorderX() const
313{
314 return m_renderer->GetStatusBarBorders(NULL).x;
315}
316
317int wxStatusBarUniv::GetBorderY() const
318{
319 return m_renderer->GetStatusBarBorders(NULL).y;
320}
321
322#endif // wxUSE_STATUSBAR