]> git.saurik.com Git - wxWidgets.git/blame - src/common/statbar.cpp
no need to check for wxID_HELP buttons in SetLabel() now that it's overridden in...
[wxWidgets.git] / src / common / statbar.cpp
CommitLineData
71e03035 1///////////////////////////////////////////////////////////////////////////////
3304646d 2// Name: src/common/statbar.cpp
71e03035
VZ
3// Purpose: wxStatusBarBase implementation
4// Author: Vadim Zeitlin
7b6fefbe 5// Modified by: Francesco Montorsi
71e03035
VZ
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
71e03035
VZ
20// For compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
24 #pragma hdrstop
25#endif
26
53b6d7a2
PC
27#if wxUSE_STATUSBAR
28
3304646d
WS
29#include "wx/statusbr.h"
30
71e03035 31#ifndef WX_PRECOMP
e9a05074 32 #include "wx/frame.h"
71e03035
VZ
33#endif //WX_PRECOMP
34
23318a53 35const char wxStatusBarNameStr[] = "statusBar";
53b6d7a2 36
7b6fefbe 37
71e03035
VZ
38// ============================================================================
39// wxStatusBarBase implementation
40// ============================================================================
41
a93e536b 42IMPLEMENT_DYNAMIC_CLASS(wxStatusBar, wxWindow)
71e03035 43
0dc8fac2 44#include "wx/arrimpl.cpp" // This is a magic incantation which must be done!
b2d76621 45WX_DEFINE_EXPORTED_OBJARRAY(wxStatusBarPaneArray)
7b6fefbe
FM
46
47
71e03035
VZ
48// ----------------------------------------------------------------------------
49// ctor/dtor
50// ----------------------------------------------------------------------------
51
52wxStatusBarBase::wxStatusBarBase()
53{
7b6fefbe 54 m_bSameWidthForAllPanes = true;
71e03035
VZ
55}
56
57wxStatusBarBase::~wxStatusBarBase()
58{
2ab82214
VZ
59 // notify the frame that it doesn't have a status bar any longer to avoid
60 // dangling pointers
67f30682 61 wxFrame *frame = wxDynamicCast(GetParent(), wxFrame);
2ab82214 62 if ( frame && frame->GetStatusBar() == this )
2ab82214 63 frame->SetStatusBar(NULL);
c2919ab3
VZ
64}
65
71e03035
VZ
66// ----------------------------------------------------------------------------
67// field widths
68// ----------------------------------------------------------------------------
69
70void wxStatusBarBase::SetFieldsCount(int number, const int *widths)
71{
72 wxCHECK_RET( number > 0, _T("invalid field number in SetFieldsCount") );
73
7b6fefbe 74 if ( (size_t)number > m_panes.GetCount() )
71e03035 75 {
7b6fefbe 76 wxStatusBarPane newPane;
c2919ab3 77
7b6fefbe
FM
78 // add more entries with the default style and zero width
79 // (this will be set later)
80 for (size_t i = m_panes.GetCount(); i < (size_t)number; ++i)
81 m_panes.Add(newPane);
71e03035 82 }
7b6fefbe
FM
83 else if ( (size_t)number < m_panes.GetCount() )
84 {
85 // remove entries in excess
86 m_panes.RemoveAt(number, m_panes.GetCount()-number);
87 }
88
fd3ece57
FM
89 // SetStatusWidths will automatically refresh
90 SetStatusWidths(number, widths);
71e03035
VZ
91}
92
93void wxStatusBarBase::SetStatusWidths(int WXUNUSED_UNLESS_DEBUG(n),
fd3ece57 94 const int widths[])
71e03035 95{
7b6fefbe 96 wxASSERT_MSG( (size_t)n == m_panes.GetCount(), _T("field number mismatch") );
71e03035 97
54e18afc 98 if (widths == NULL)
fd3ece57
FM
99 {
100 // special value meaning: override explicit pane widths and make them all
101 // of the same size
102 m_bSameWidthForAllPanes = true;
103 }
104 else
105 {
106 for ( size_t i = 0; i < m_panes.GetCount(); i++ )
b31eaa5c 107 m_panes[i].m_nWidth = widths[i];
fd3ece57
FM
108
109 m_bSameWidthForAllPanes = false;
110 }
71e03035
VZ
111
112 // update the display after the widths changed
113 Refresh();
114}
115
c2919ab3 116void wxStatusBarBase::SetStatusStyles(int WXUNUSED_UNLESS_DEBUG(n),
fd3ece57 117 const int styles[])
c2919ab3
VZ
118{
119 wxCHECK_RET( styles, _T("NULL pointer in SetStatusStyles") );
120
7b6fefbe 121 wxASSERT_MSG( (size_t)n == m_panes.GetCount(), _T("field number mismatch") );
c2919ab3 122
7b6fefbe 123 for ( size_t i = 0; i < m_panes.GetCount(); i++ )
b31eaa5c 124 m_panes[i].m_nStyle = styles[i];
c2919ab3
VZ
125
126 // update the display after the widths changed
127 Refresh();
128}
129
71e03035
VZ
130wxArrayInt wxStatusBarBase::CalculateAbsWidths(wxCoord widthTotal) const
131{
132 wxArrayInt widths;
133
7b6fefbe 134 if ( m_bSameWidthForAllPanes )
71e03035 135 {
7b6fefbe
FM
136 // Default: all fields have the same width. This is not always
137 // possible to do exactly (if widthTotal is not divisible by
138 // m_panes.GetCount()) - if that happens, we distribute the extra
139 // pixels among all fields:
140 int widthToUse = widthTotal;
68ab959c 141
7b6fefbe
FM
142 for ( size_t i = m_panes.GetCount(); i > 0; i-- )
143 {
144 // divide the unassigned width evently between the
145 // not yet processed fields:
146 int w = widthToUse / i;
147 widths.Add(w);
148 widthToUse -= w;
71e03035
VZ
149 }
150 }
7b6fefbe 151 else // do not override explicit pane widths
71e03035
VZ
152 {
153 // calculate the total width of all the fixed width fields and the
154 // total number of var field widths counting with multiplicity
7b6fefbe 155 size_t nTotalWidth = 0,
fd3ece57
FM
156 nVarCount = 0,
157 i;
7b6fefbe
FM
158
159 for ( i = 0; i < m_panes.GetCount(); i++ )
71e03035 160 {
b31eaa5c
FM
161 if ( m_panes[i].GetWidth() >= 0 )
162 nTotalWidth += m_panes[i].GetWidth();
71e03035 163 else
b31eaa5c 164 nVarCount += -m_panes[i].GetWidth();
71e03035
VZ
165 }
166
167 // the amount of extra width we have per each var width field
1a83b9bd 168 int widthExtra = widthTotal - nTotalWidth;
71e03035
VZ
169
170 // do fill the array
7b6fefbe 171 for ( i = 0; i < m_panes.GetCount(); i++ )
71e03035 172 {
b31eaa5c
FM
173 if ( m_panes[i].GetWidth() >= 0 )
174 widths.Add(m_panes[i].GetWidth());
71e03035
VZ
175 else
176 {
b31eaa5c
FM
177 int nVarWidth = widthExtra > 0 ? (widthExtra * (-m_panes[i].GetWidth())) / nVarCount : 0;
178 nVarCount += m_panes[i].GetWidth();
1a83b9bd
VZ
179 widthExtra -= nVarWidth;
180 widths.Add(nVarWidth);
71e03035
VZ
181 }
182 }
183 }
184
185 return widths;
186}
187
1f361cdd 188// ----------------------------------------------------------------------------
7b6fefbe 189// status text stacks
1f361cdd
MB
190// ----------------------------------------------------------------------------
191
192void wxStatusBarBase::PushStatusText(const wxString& text, int number)
193{
30800ba5
FM
194 // save the new text (in non-ellipsized form) in the stack
195 m_panes[number].m_arrStack.push_back(text);
7b6fefbe 196
1f361cdd 197 SetStatusText(text, number);
30800ba5
FM
198 // update current status text (which will possibly be ellipsized)
199 // also in the native control
86c188e7
FM
200
201 // SetStatusText() typically has an optimization built-in to avoid flickering
202 // which won't refresh the status bar pane if the current top of the stack
203 // is identic to the text passed to that function.
204 // Since this optimization however cannot detect push/pop operations on the stack
205 // we need to explicitely refresh the status bar pane ourselves:
206 wxRect rect;
207 GetFieldRect(number, rect);
208 Refresh(true, &rect);
209 Update();
1f361cdd
MB
210}
211
212void wxStatusBarBase::PopStatusText(int number)
213{
86c188e7 214 wxASSERT_MSG(m_panes[number].m_arrStack.GetCount() > 1,
0cd15959
FM
215 "can't pop any further string");
216
30800ba5
FM
217 // the top of the stack is the status text currently shown in the native control;
218 // remove it
219 m_panes[number].m_arrStack.pop_back();
1f361cdd 220
30800ba5
FM
221 // restore the previous status text in the native control
222 const wxString& text = m_panes[number].m_arrStack.back();
7b6fefbe 223 SetStatusText(text, number);
86c188e7
FM
224
225 // see comment in wxStatusBarBase::PushStatusText about why we need to explicitely
226 // refresh the status bar pane
227 wxRect rect;
228 GetFieldRect(number, rect);
229 Refresh(true, &rect);
230 Update();
1f361cdd
MB
231}
232
71e03035 233#endif // wxUSE_STATUSBAR