]> git.saurik.com Git - wxWidgets.git/blame - src/common/statbar.cpp
Blind fix for missing files
[wxWidgets.git] / src / common / statbar.cpp
CommitLineData
71e03035
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: common/statbar.cpp
3// Purpose: wxStatusBarBase implementation
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 14.10.01
7// RCS-ID: $Id$
8// Copyright: (c) 2001 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
65571936 9// License: wxWindows licence
71e03035
VZ
10///////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
14f355c2 20#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
71e03035
VZ
21 #pragma implementation "statbar.h"
22#endif
23
24// For compilers that support precompilation, includes "wx.h".
25#include "wx/wxprec.h"
26
27#ifdef __BORLANDC__
28 #pragma hdrstop
29#endif
30
31#ifndef WX_PRECOMP
32 #include "wx/statusbr.h"
33#endif //WX_PRECOMP
34
35#if wxUSE_STATUSBAR
36
1f361cdd
MB
37#include "wx/listimpl.cpp"
38WX_DEFINE_LIST(wxListString);
39
71e03035
VZ
40// ============================================================================
41// wxStatusBarBase implementation
42// ============================================================================
43
a93e536b 44IMPLEMENT_DYNAMIC_CLASS(wxStatusBar, wxWindow)
71e03035
VZ
45
46// ----------------------------------------------------------------------------
47// ctor/dtor
48// ----------------------------------------------------------------------------
49
50wxStatusBarBase::wxStatusBarBase()
51{
52 m_nFields = 0;
53
54 InitWidths();
1f361cdd 55 InitStacks();
c2919ab3 56 InitStyles();
71e03035
VZ
57}
58
59wxStatusBarBase::~wxStatusBarBase()
60{
61 FreeWidths();
1f361cdd 62 FreeStacks();
c2919ab3 63 InitStyles();
71e03035
VZ
64}
65
66// ----------------------------------------------------------------------------
67// widths array handling
68// ----------------------------------------------------------------------------
69
70void wxStatusBarBase::InitWidths()
71{
72 m_statusWidths = NULL;
73}
74
75void wxStatusBarBase::FreeWidths()
76{
77 delete [] m_statusWidths;
78}
79
c2919ab3
VZ
80// ----------------------------------------------------------------------------
81// styles array handling
82// ----------------------------------------------------------------------------
83
84void wxStatusBarBase::InitStyles()
85{
86 m_statusStyles = NULL;
87}
88
89void wxStatusBarBase::FreeStyles()
90{
91 delete [] m_statusStyles;
92}
93
71e03035
VZ
94// ----------------------------------------------------------------------------
95// field widths
96// ----------------------------------------------------------------------------
97
98void wxStatusBarBase::SetFieldsCount(int number, const int *widths)
99{
100 wxCHECK_RET( number > 0, _T("invalid field number in SetFieldsCount") );
101
d775fa82 102 bool refresh = false;
71e03035
VZ
103
104 if ( number != m_nFields )
105 {
1f361cdd
MB
106 // copy stacks if present
107 if(m_statusTextStacks)
108 {
109 wxListString **newStacks = new wxListString*[number];
110 size_t i, j, max = wxMin(number, m_nFields);
111
112 // copy old stacks
113 for(i = 0; i < max; ++i)
114 newStacks[i] = m_statusTextStacks[i];
115 // free old stacks in excess
116 for(j = i; j < (size_t)m_nFields; ++j)
117 {
118 if(m_statusTextStacks[j])
119 {
120 m_statusTextStacks[j]->Clear();
121 delete m_statusTextStacks[j];
122 }
123 }
124 // initialize new stacks to NULL
125 for(j = i; j < (size_t)number; ++j)
126 newStacks[j] = 0;
127
128 m_statusTextStacks = newStacks;
129 }
130
c2919ab3
VZ
131 // Resize styles array
132 if (m_statusStyles)
133 {
134 int *oldStyles = m_statusStyles;
135 m_statusStyles = new int[number];
136 int i, max = wxMin(number, m_nFields);
137
138 // copy old styles
139 for (i = 0; i < max; ++i)
140 m_statusStyles[i] = oldStyles[i];
141
142 // initialize new styles to wxSB_NORMAL
143 for (i = max; i < number; ++i)
144 m_statusStyles[i] = wxSB_NORMAL;
145
146 // free old styles
147 delete [] oldStyles;
148 }
149
150
71e03035
VZ
151 m_nFields = number;
152
153 ReinitWidths();
154
d775fa82 155 refresh = true;
71e03035
VZ
156 }
157 //else: keep the old m_statusWidths if we had them
158
159 if ( widths )
160 {
161 SetStatusWidths(number, widths);
162
163 // already done from SetStatusWidths()
d775fa82 164 refresh = false;
71e03035
VZ
165 }
166
167 if ( refresh )
168 Refresh();
169}
170
171void wxStatusBarBase::SetStatusWidths(int WXUNUSED_UNLESS_DEBUG(n),
172 const int widths[])
173{
174 wxCHECK_RET( widths, _T("NULL pointer in SetStatusWidths") );
175
176 wxASSERT_MSG( n == m_nFields, _T("field number mismatch") );
177
178 if ( !m_statusWidths )
179 m_statusWidths = new int[m_nFields];
180
181 for ( int i = 0; i < m_nFields; i++ )
182 {
183 m_statusWidths[i] = widths[i];
184 }
185
186 // update the display after the widths changed
187 Refresh();
188}
189
c2919ab3
VZ
190void wxStatusBarBase::SetStatusStyles(int WXUNUSED_UNLESS_DEBUG(n),
191 const int styles[])
192{
193 wxCHECK_RET( styles, _T("NULL pointer in SetStatusStyles") );
194
195 wxASSERT_MSG( n == m_nFields, _T("field number mismatch") );
196
197 if ( !m_statusStyles )
198 m_statusStyles = new int[m_nFields];
199
200 for ( int i = 0; i < m_nFields; i++ )
201 {
202 m_statusStyles[i] = styles[i];
203 }
204
205 // update the display after the widths changed
206 Refresh();
207}
208
71e03035
VZ
209wxArrayInt wxStatusBarBase::CalculateAbsWidths(wxCoord widthTotal) const
210{
211 wxArrayInt widths;
212
213 if ( m_statusWidths == NULL )
214 {
5057e659 215 if ( m_nFields )
71e03035 216 {
5057e659
VZ
217 // default: all fields have the same width
218 int nWidth = widthTotal / m_nFields;
219 for ( int i = 0; i < m_nFields; i++ )
220 {
221 widths.Add(nWidth);
222 }
71e03035 223 }
5057e659 224 //else: we're empty anyhow
71e03035
VZ
225 }
226 else // have explicit status widths
227 {
228 // calculate the total width of all the fixed width fields and the
229 // total number of var field widths counting with multiplicity
230 int nTotalWidth = 0,
231 nVarCount = 0,
232 i;
233 for ( i = 0; i < m_nFields; i++ )
234 {
235 if ( m_statusWidths[i] >= 0 )
236 {
237 nTotalWidth += m_statusWidths[i];
238 }
239 else
240 {
241 nVarCount += -m_statusWidths[i];
242 }
243 }
244
245 // the amount of extra width we have per each var width field
1a83b9bd 246 int widthExtra = widthTotal - nTotalWidth;
71e03035
VZ
247
248 // do fill the array
249 for ( i = 0; i < m_nFields; i++ )
250 {
251 if ( m_statusWidths[i] >= 0 )
252 {
253 widths.Add(m_statusWidths[i]);
254 }
255 else
256 {
1a83b9bd
VZ
257 int nVarWidth = widthExtra > 0 ? (widthExtra * -m_statusWidths[i]) / nVarCount : 0;
258 nVarCount += m_statusWidths[i];
259 widthExtra -= nVarWidth;
260 widths.Add(nVarWidth);
71e03035
VZ
261 }
262 }
263 }
264
265 return widths;
266}
267
1f361cdd
MB
268// ----------------------------------------------------------------------------
269// text stacks handling
270// ----------------------------------------------------------------------------
271
272void wxStatusBarBase::InitStacks()
273{
274 m_statusTextStacks = NULL;
275}
276
277void wxStatusBarBase::FreeStacks()
278{
279 if(!m_statusTextStacks) return;
280 size_t i;
281
282 for(i = 0; i < (size_t)m_nFields; ++i)
283 {
284 if(m_statusTextStacks[i])
285 {
222ed1d6
MB
286 wxListString& t = *m_statusTextStacks[i];
287 WX_CLEAR_LIST(wxListString, t);
1f361cdd
MB
288 delete m_statusTextStacks[i];
289 }
290 }
291
292 delete[] m_statusTextStacks;
293}
294
295// ----------------------------------------------------------------------------
296// text stacks
297// ----------------------------------------------------------------------------
298
299void wxStatusBarBase::PushStatusText(const wxString& text, int number)
300{
301 wxListString* st = GetOrCreateStatusStack(number);
7d2d5d81
JS
302 // This long-winded way around avoids an internal compiler error
303 // in VC++ 6 with RTTI enabled
304 wxString tmp1(GetStatusText(number));
305 wxString* tmp = new wxString(tmp1);
306 st->Insert(tmp);
1f361cdd
MB
307 SetStatusText(text, number);
308}
309
310void wxStatusBarBase::PopStatusText(int number)
311{
312 wxListString *st = GetStatusStack(number);
313 wxCHECK_RET( st, _T("Unbalanced PushStatusText/PopStatusText") );
222ed1d6 314 wxListString::compatibility_iterator top = st->GetFirst();
1f361cdd
MB
315
316 SetStatusText(*top->GetData(), number);
222ed1d6
MB
317 delete top->GetData();
318 st->Erase(top);
1f361cdd
MB
319 if(st->GetCount() == 0)
320 {
321 delete st;
322 m_statusTextStacks[number] = 0;
323 }
324}
325
326wxListString *wxStatusBarBase::GetStatusStack(int i) const
327{
328 if(!m_statusTextStacks)
329 return 0;
330 return m_statusTextStacks[i];
331}
332
333wxListString *wxStatusBarBase::GetOrCreateStatusStack(int i)
334{
335 if(!m_statusTextStacks)
336 {
337 m_statusTextStacks = new wxListString*[m_nFields];
338
339 size_t j;
340 for(j = 0; j < (size_t)m_nFields; ++j) m_statusTextStacks[j] = 0;
341 }
342
343 if(!m_statusTextStacks[i])
344 {
345 m_statusTextStacks[i] = new wxListString();
1f361cdd
MB
346 }
347
348 return m_statusTextStacks[i];
349}
350
71e03035
VZ
351#endif // wxUSE_STATUSBAR
352