]> git.saurik.com Git - wxWidgets.git/blame - src/univ/statusbr.cpp
Updated MinGW build instructions
[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"
38
39#include "wx/univ/renderer.h"
40
41// ============================================================================
42// implementation
43// ============================================================================
44
45BEGIN_EVENT_TABLE(wxStatusBarUniv, wxStatusBarBase)
46 EVT_SIZE(wxStatusBarUniv::OnSize)
47
48 WX_EVENT_TABLE_INPUT_CONSUMER(wxStatusBarUniv)
49END_EVENT_TABLE()
50
51WX_FORWARD_TO_INPUT_CONSUMER(wxStatusBarUniv)
52
53// ----------------------------------------------------------------------------
54// creation
55// ----------------------------------------------------------------------------
56
57void wxStatusBarUniv::Init()
58{
59}
60
61bool wxStatusBarUniv::Create(wxWindow *parent,
62 wxWindowID id,
63 long style,
64 const wxString& name)
65{
66 if ( !wxWindow::Create(parent, id,
67 wxDefaultPosition, wxDefaultSize,
68 style, name) )
69 {
70 return FALSE;
71 }
72
73 SetFieldsCount(1);
74
75 CreateInputHandler(wxINP_HANDLER_STATUSBAR);
76
77 SetSize(DoGetBestSize());
78
79 return TRUE;
80}
81
82// ----------------------------------------------------------------------------
83// drawing
84// ----------------------------------------------------------------------------
85
86wxRect wxStatusBarUniv::GetTotalFieldRect(wxCoord *borderBetweenFields)
87{
71e03035
VZ
88 wxRect rect = GetClientRect();
89
90 // no, don't do this - the borders are meant to be inside this rect
cece1d88
VZ
91 // wxSize sizeBorders =
92 m_renderer->GetStatusBarBorders(borderBetweenFields);
71e03035
VZ
93 //rect.Deflate(sizeBorders.x, sizeBorders.y);
94
95 // recalc the field widths if needed
96 if ( m_widthsAbs.IsEmpty() )
97 {
98 // the total width for the fields doesn't include the borders between
99 // them
100 m_widthsAbs = CalculateAbsWidths(rect.width -
101 *borderBetweenFields*(m_nFields - 1));
102 }
103
104 return rect;
105}
106
107void wxStatusBarUniv::DoDraw(wxControlRenderer *renderer)
108{
109 // get the fields rect
110 wxCoord borderBetweenFields;
111 wxRect rect = GetTotalFieldRect(&borderBetweenFields);
112
113 // prepare the DC
114 wxDC& dc = renderer->GetDC();
a756f210 115 dc.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
71e03035
VZ
116
117 // do draw the fields
118 int flags = IsEnabled() ? 0 : wxCONTROL_DISABLED;
119 for ( int n = 0; n < m_nFields; n++ )
120 {
121 rect.width = m_widthsAbs[n];
122
123 if ( IsExposed(rect) )
124 {
125 // the size grip may be drawn only on the last field and only if we
126 // have the corresponding style and even then only if we really can
127 // resize this frame
128 if ( n == m_nFields - 1 &&
129 HasFlag(wxST_SIZEGRIP) &&
130 GetParent()->HasFlag(wxRESIZE_BORDER) )
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
139 m_renderer->DrawStatusField(dc, rect, m_statusText[n], flags);
140 }
141
142 rect.x += rect.width + borderBetweenFields;
143 }
144}
145
146void wxStatusBarUniv::RefreshField(int i)
147{
148 wxRect rect;
149 if ( GetFieldRect(i, rect) )
150 {
151 RefreshRect(rect);
152 }
153}
154
155// ----------------------------------------------------------------------------
156// fields text
157// ----------------------------------------------------------------------------
158
159void wxStatusBarUniv::SetStatusText(const wxString& text, int number)
160{
161 wxCHECK_RET( number >= 0 && number < m_nFields,
162 _T("invalid status bar field index in SetStatusText()") );
163
164 if ( text == m_statusText[number] )
165 {
166 // nothing changed
167 return;
168 }
169
170 m_statusText[number] = text;
171
172 RefreshField(number);
173}
174
175wxString wxStatusBarUniv::GetStatusText(int number) const
176{
177 wxCHECK_MSG( number >= 0 && number < m_nFields, _T(""),
178 _T("invalid status bar field index") );
179
180 return m_statusText[number];
181}
182
183// ----------------------------------------------------------------------------
184// fields count/widths
185// ----------------------------------------------------------------------------
186
187void wxStatusBarUniv::SetFieldsCount(int number, const int *widths)
188{
71e03035 189 m_statusText.SetCount(number);
ca7497c2 190 wxStatusBarBase::SetFieldsCount(number, widths);
71e03035
VZ
191 m_widthsAbs.Empty();
192}
193
194void wxStatusBarUniv::SetStatusWidths(int n, const int widths[])
195{
196 wxStatusBarBase::SetStatusWidths(n, widths);
197
198 m_widthsAbs.Empty();
199}
200
201// ----------------------------------------------------------------------------
202// geometry
203// ----------------------------------------------------------------------------
204
205void wxStatusBarUniv::OnSize(wxSizeEvent& event)
206{
207 // invalidate the widths, we'll have to recalc them
208 m_widthsAbs.Empty();
209
210 // refresh entirely, shouldn't matter much as the statusbar is quick to
211 // redraw and it would be difficult to avoid it as we'd need to find out
212 // which fields exactly were affected...
213 Refresh();
214
215 event.Skip();
216}
217
218bool wxStatusBarUniv::GetFieldRect(int n, wxRect& rect) const
219{
220 wxCHECK_MSG( n >= 0 && n < m_nFields, FALSE,
221 _T("invalid field index in GetFieldRect()") );
222
223 // this is a fix for a bug exhibited by the statbar sample: if
224 // GetFieldRect() is called from the derived class OnSize() handler, then
225 // our geometry info is wrong as our OnSize() didn't invalidate m_widthsAbs
226 // yet - so recalc it just in case
227 wxStatusBarUniv *self = wxConstCast(this, wxStatusBarUniv);
228 self->m_widthsAbs.Empty();
229
230 wxCoord borderBetweenFields;
231 rect = self->GetTotalFieldRect(&borderBetweenFields);
232 for ( int i = 0; i <= n; i++ )
233 {
234 rect.width = m_widthsAbs[i];
235
236 if ( i < n )
237 rect.x += rect.width + borderBetweenFields;
238 }
239
240 return TRUE;
241}
242
243wxCoord wxStatusBarUniv::GetHeight() const
244{
245 wxClientDC dc(wxConstCast(this, wxStatusBarUniv));
a756f210 246 dc.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
71e03035
VZ
247
248 return dc.GetCharHeight() + 2*GetBorderY();
249}
250
251wxSize wxStatusBarUniv::DoGetBestSize() const
252{
253 return wxSize(100, GetHeight());
254}
255
256void wxStatusBarUniv::DoSetSize(int x, int y,
257 int width, int WXUNUSED(height),
258 int sizeFlags)
259{
260 wxStatusBarBase::DoSetSize(x, y, width, GetHeight(), sizeFlags);
261}
262
263// ----------------------------------------------------------------------------
264// misc
265// ----------------------------------------------------------------------------
266
267void wxStatusBarUniv::SetMinHeight(int WXUNUSED(height))
268{
269 // nothing to do here, we don't support it - and why would we?
270}
271
272int wxStatusBarUniv::GetBorderX() const
273{
274 return m_renderer->GetStatusBarBorders(NULL).x;
275}
276
277int wxStatusBarUniv::GetBorderY() const
278{
279 return m_renderer->GetStatusBarBorders(NULL).y;
280}
281
282#endif // wxUSE_STATUSBAR
283