]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: src/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 | #include "wx/wxprec.h" | |
21 | ||
22 | #ifdef __BORLANDC__ | |
23 | #pragma hdrstop | |
24 | #endif | |
25 | ||
26 | #if wxUSE_STATUSBAR | |
27 | ||
28 | #include "wx/statusbr.h" | |
29 | ||
30 | #ifndef WX_PRECOMP | |
31 | #include "wx/settings.h" | |
32 | #include "wx/dcclient.h" | |
33 | #include "wx/toplevel.h" | |
34 | #endif | |
35 | ||
36 | #include "wx/univ/renderer.h" | |
37 | ||
38 | // ============================================================================ | |
39 | // implementation | |
40 | // ============================================================================ | |
41 | ||
42 | BEGIN_EVENT_TABLE(wxStatusBarUniv, wxStatusBarBase) | |
43 | EVT_SIZE(wxStatusBarUniv::OnSize) | |
44 | ||
45 | WX_EVENT_TABLE_INPUT_CONSUMER(wxStatusBarUniv) | |
46 | END_EVENT_TABLE() | |
47 | ||
48 | WX_FORWARD_TO_INPUT_CONSUMER(wxStatusBarUniv) | |
49 | ||
50 | // ---------------------------------------------------------------------------- | |
51 | // creation | |
52 | // ---------------------------------------------------------------------------- | |
53 | ||
54 | void wxStatusBarUniv::Init() | |
55 | { | |
56 | } | |
57 | ||
58 | bool 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 | { | |
67 | return false; | |
68 | } | |
69 | ||
70 | SetFieldsCount(1); | |
71 | ||
72 | CreateInputHandler(wxINP_HANDLER_STATUSBAR); | |
73 | ||
74 | SetSize(DoGetBestSize()); | |
75 | ||
76 | return true; | |
77 | } | |
78 | ||
79 | // ---------------------------------------------------------------------------- | |
80 | // drawing | |
81 | // ---------------------------------------------------------------------------- | |
82 | ||
83 | wxRect wxStatusBarUniv::GetTotalFieldRect(wxCoord *borderBetweenFields) | |
84 | { | |
85 | wxRect rect = GetClientRect(); | |
86 | ||
87 | // no, don't do this - the borders are meant to be inside this rect | |
88 | // wxSize sizeBorders = | |
89 | if ( borderBetweenFields ) | |
90 | *borderBetweenFields = m_renderer->GetStatusBarBorderBetweenFields(); | |
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_panes.GetCount() - 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(GetFont()); | |
114 | dc.SetTextForeground(GetForegroundColour()); | |
115 | ||
116 | // do draw the fields | |
117 | int flags = IsEnabled() ? 0 : (int)wxCONTROL_DISABLED; | |
118 | for ( int n = 0; n < (int)m_panes.GetCount(); n++ ) | |
119 | { | |
120 | rect.width = m_widthsAbs[n]; | |
121 | ||
122 | if ( IsExposed(rect) ) | |
123 | { | |
124 | wxTopLevelWindow *parentTLW = wxDynamicCast(GetParent(), wxTopLevelWindow); | |
125 | ||
126 | // the size grip may be drawn only on the last field and only if we | |
127 | // have the corresponding style and even then only if we really can | |
128 | // resize this frame | |
129 | if ( n == (int)m_panes.GetCount() - 1 && | |
130 | HasFlag(wxST_SIZEGRIP) && | |
131 | GetParent()->HasFlag(wxRESIZE_BORDER) && | |
132 | parentTLW && !parentTLW->IsMaximized() ) | |
133 | { | |
134 | flags |= wxCONTROL_SIZEGRIP; | |
135 | } | |
136 | ||
137 | m_renderer->DrawStatusField(dc, rect, m_statusText[n], flags, m_panes[n].nStyle); | |
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 && (size_t)number < m_panes.GetCount(), | |
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 && (size_t)number < m_panes.GetCount(), wxEmptyString, | |
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 | m_statusText.SetCount(number); | |
188 | wxStatusBarBase::SetFieldsCount(number, widths); | |
189 | ||
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 | // we don't need to refresh the fields whose width didn't change, so find | |
207 | // the first field whose width did change and refresh starting from it | |
208 | size_t field; | |
209 | if ( m_bSameWidthForAllPanes ) | |
210 | { | |
211 | // hence all fields widths have changed | |
212 | field = 0; | |
213 | } | |
214 | else | |
215 | { | |
216 | for ( field = 0; field < m_panes.GetCount(); field++ ) | |
217 | { | |
218 | if ( m_panes[field].nWidth < 0 ) | |
219 | { | |
220 | // var width field | |
221 | break; | |
222 | } | |
223 | } | |
224 | } | |
225 | ||
226 | if ( field < m_panes.GetCount() ) | |
227 | { | |
228 | // call this before invalidating the old widths as we want to use them, | |
229 | // not the new ones | |
230 | wxRect rect = DoGetFieldRect(field); | |
231 | ||
232 | // invalidate the widths, we'll have to recalc them | |
233 | m_widthsAbs.Empty(); | |
234 | ||
235 | // refresh everything after the first invalid field | |
236 | rect.y = 0; | |
237 | rect.SetRight(event.GetSize().x); | |
238 | rect.height = event.GetSize().y; | |
239 | RefreshRect(rect); | |
240 | } | |
241 | ||
242 | event.Skip(); | |
243 | } | |
244 | ||
245 | bool wxStatusBarUniv::GetFieldRect(int n, wxRect& rect) const | |
246 | { | |
247 | wxCHECK_MSG( n >= 0 && (size_t)n < m_panes.GetCount(), false, | |
248 | _T("invalid field index in GetFieldRect()") ); | |
249 | ||
250 | // this is a fix for a bug exhibited by the statbar sample: if | |
251 | // GetFieldRect() is called from the derived class OnSize() handler, then | |
252 | // our geometry info is wrong as our OnSize() didn't invalidate m_widthsAbs | |
253 | // yet - so recalc it just in case | |
254 | wxConstCast(this, wxStatusBarUniv)->m_widthsAbs.Empty(); | |
255 | ||
256 | rect = DoGetFieldRect(n); | |
257 | ||
258 | return true; | |
259 | } | |
260 | ||
261 | wxRect wxStatusBarUniv::DoGetFieldRect(int n) const | |
262 | { | |
263 | wxStatusBarUniv *self = wxConstCast(this, wxStatusBarUniv); | |
264 | ||
265 | wxCoord borderBetweenFields; | |
266 | wxRect rect = self->GetTotalFieldRect(&borderBetweenFields); | |
267 | ||
268 | // it's the caller responsability to check this, if unsure - call | |
269 | // GetFieldRect() instead | |
270 | wxCHECK_MSG( !m_widthsAbs.IsEmpty(), rect, | |
271 | _T("can't be called if we don't have the widths") ); | |
272 | ||
273 | for ( int i = 0; i <= n; i++ ) | |
274 | { | |
275 | rect.width = m_widthsAbs[i]; | |
276 | ||
277 | if ( i < n ) | |
278 | rect.x += rect.width + borderBetweenFields; | |
279 | } | |
280 | ||
281 | return rect; | |
282 | } | |
283 | ||
284 | wxCoord wxStatusBarUniv::GetHeight() const | |
285 | { | |
286 | return GetCharHeight() + 2*GetBorderY(); | |
287 | } | |
288 | ||
289 | wxSize wxStatusBarUniv::DoGetBestSize() const | |
290 | { | |
291 | return wxSize(100, GetHeight()); | |
292 | } | |
293 | ||
294 | void wxStatusBarUniv::DoSetSize(int x, int y, | |
295 | int width, int WXUNUSED(height), | |
296 | int sizeFlags) | |
297 | { | |
298 | wxStatusBarBase::DoSetSize(x, y, width, GetHeight(), sizeFlags); | |
299 | } | |
300 | ||
301 | // ---------------------------------------------------------------------------- | |
302 | // misc | |
303 | // ---------------------------------------------------------------------------- | |
304 | ||
305 | void wxStatusBarUniv::SetMinHeight(int WXUNUSED(height)) | |
306 | { | |
307 | // nothing to do here, we don't support it - and why would we? | |
308 | } | |
309 | ||
310 | int wxStatusBarUniv::GetBorderX() const | |
311 | { | |
312 | return m_renderer->GetStatusBarBorders().x + | |
313 | m_renderer->GetStatusBarFieldMargins().x; | |
314 | } | |
315 | ||
316 | int wxStatusBarUniv::GetBorderY() const | |
317 | { | |
318 | return m_renderer->GetStatusBarBorders().y + | |
319 | m_renderer->GetStatusBarFieldMargins().y; | |
320 | } | |
321 | ||
322 | #endif // wxUSE_STATUSBAR |