]> git.saurik.com Git - wxWidgets.git/blob - src/univ/statusbr.cpp
unimportant DOS fix
[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 // wxSize sizeBorders =
92 m_renderer->GetStatusBarBorders(borderBetweenFields);
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
107 void 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();
115 dc.SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
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
146 void 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
159 void 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
175 wxString 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
187 void wxStatusBarUniv::SetFieldsCount(int number, const int *widths)
188 {
189 wxStatusBarBase::SetFieldsCount(number, widths);
190
191 m_statusText.SetCount(number);
192 m_widthsAbs.Empty();
193 }
194
195 void 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
206 void wxStatusBarUniv::OnSize(wxSizeEvent& event)
207 {
208 // invalidate the widths, we'll have to recalc them
209 m_widthsAbs.Empty();
210
211 // refresh entirely, shouldn't matter much as the statusbar is quick to
212 // redraw and it would be difficult to avoid it as we'd need to find out
213 // which fields exactly were affected...
214 Refresh();
215
216 event.Skip();
217 }
218
219 bool wxStatusBarUniv::GetFieldRect(int n, wxRect& rect) const
220 {
221 wxCHECK_MSG( n >= 0 && n < m_nFields, FALSE,
222 _T("invalid field index in GetFieldRect()") );
223
224 // this is a fix for a bug exhibited by the statbar sample: if
225 // GetFieldRect() is called from the derived class OnSize() handler, then
226 // our geometry info is wrong as our OnSize() didn't invalidate m_widthsAbs
227 // yet - so recalc it just in case
228 wxStatusBarUniv *self = wxConstCast(this, wxStatusBarUniv);
229 self->m_widthsAbs.Empty();
230
231 wxCoord borderBetweenFields;
232 rect = self->GetTotalFieldRect(&borderBetweenFields);
233 for ( int i = 0; i <= n; i++ )
234 {
235 rect.width = m_widthsAbs[i];
236
237 if ( i < n )
238 rect.x += rect.width + borderBetweenFields;
239 }
240
241 return TRUE;
242 }
243
244 wxCoord wxStatusBarUniv::GetHeight() const
245 {
246 wxClientDC dc(wxConstCast(this, wxStatusBarUniv));
247 dc.SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
248
249 return dc.GetCharHeight() + 2*GetBorderY();
250 }
251
252 wxSize wxStatusBarUniv::DoGetBestSize() const
253 {
254 return wxSize(100, GetHeight());
255 }
256
257 void wxStatusBarUniv::DoSetSize(int x, int y,
258 int width, int WXUNUSED(height),
259 int sizeFlags)
260 {
261 wxStatusBarBase::DoSetSize(x, y, width, GetHeight(), sizeFlags);
262 }
263
264 // ----------------------------------------------------------------------------
265 // misc
266 // ----------------------------------------------------------------------------
267
268 void wxStatusBarUniv::SetMinHeight(int WXUNUSED(height))
269 {
270 // nothing to do here, we don't support it - and why would we?
271 }
272
273 int wxStatusBarUniv::GetBorderX() const
274 {
275 return m_renderer->GetStatusBarBorders(NULL).x;
276 }
277
278 int wxStatusBarUniv::GetBorderY() const
279 {
280 return m_renderer->GetStatusBarBorders(NULL).y;
281 }
282
283 #endif // wxUSE_STATUSBAR
284