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