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