]>
git.saurik.com Git - wxWidgets.git/blob - src/common/statbar.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/statbar.cpp
3 // Purpose: wxStatusBarBase implementation
4 // Author: Vadim Zeitlin
5 // Modified by: Francesco Montorsi
8 // Copyright: (c) 2001 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // License: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
29 #include "wx/statusbr.h"
35 const char wxStatusBarNameStr
[] = "statusBar";
38 // ============================================================================
39 // wxStatusBarBase implementation
40 // ============================================================================
42 IMPLEMENT_DYNAMIC_CLASS(wxStatusBar
, wxWindow
)
44 #include "wx/arrimpl.cpp" // This is a magic incantation which must be done!
45 WX_DEFINE_OBJARRAY(wxStatusBarPaneArray
)
48 // ----------------------------------------------------------------------------
50 // ----------------------------------------------------------------------------
52 wxStatusBarBase::wxStatusBarBase()
54 m_bSameWidthForAllPanes
= true;
57 wxStatusBarBase::~wxStatusBarBase()
59 // notify the frame that it doesn't have a status bar any longer to avoid
61 wxFrame
*frame
= wxDynamicCast(GetParent(), wxFrame
);
62 if ( frame
&& frame
->GetStatusBar() == this )
63 frame
->SetStatusBar(NULL
);
66 // ----------------------------------------------------------------------------
68 // ----------------------------------------------------------------------------
70 void wxStatusBarBase::SetFieldsCount(int number
, const int *widths
)
72 wxCHECK_RET( number
> 0, _T("invalid field number in SetFieldsCount") );
74 if ( (size_t)number
> m_panes
.GetCount() )
76 wxStatusBarPane newPane
;
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
)
83 else if ( (size_t)number
< m_panes
.GetCount() )
85 // remove entries in excess
86 m_panes
.RemoveAt(number
, m_panes
.GetCount()-number
);
89 // SetStatusWidths will automatically refresh
90 SetStatusWidths(number
, widths
);
93 void wxStatusBarBase::SetStatusWidths(int WXUNUSED_UNLESS_DEBUG(n
),
96 wxASSERT_MSG( (size_t)n
== m_panes
.GetCount(), _T("field number mismatch") );
100 // special value meaning: override explicit pane widths and make them all
102 m_bSameWidthForAllPanes
= true;
106 for ( size_t i
= 0; i
< m_panes
.GetCount(); i
++ )
107 m_panes
[i
].m_nWidth
= widths
[i
];
109 m_bSameWidthForAllPanes
= false;
112 // update the display after the widths changed
116 void wxStatusBarBase::SetStatusStyles(int WXUNUSED_UNLESS_DEBUG(n
),
119 wxCHECK_RET( styles
, _T("NULL pointer in SetStatusStyles") );
121 wxASSERT_MSG( (size_t)n
== m_panes
.GetCount(), _T("field number mismatch") );
123 for ( size_t i
= 0; i
< m_panes
.GetCount(); i
++ )
124 m_panes
[i
].m_nStyle
= styles
[i
];
126 // update the display after the widths changed
130 wxArrayInt
wxStatusBarBase::CalculateAbsWidths(wxCoord widthTotal
) const
134 if ( m_bSameWidthForAllPanes
)
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
;
142 for ( size_t i
= m_panes
.GetCount(); i
> 0; i
-- )
144 // divide the unassigned width evently between the
145 // not yet processed fields:
146 int w
= widthToUse
/ i
;
151 else // do not override explicit pane widths
153 // calculate the total width of all the fixed width fields and the
154 // total number of var field widths counting with multiplicity
155 size_t nTotalWidth
= 0,
159 for ( i
= 0; i
< m_panes
.GetCount(); i
++ )
161 if ( m_panes
[i
].GetWidth() >= 0 )
162 nTotalWidth
+= m_panes
[i
].GetWidth();
164 nVarCount
+= -m_panes
[i
].GetWidth();
167 // the amount of extra width we have per each var width field
168 int widthExtra
= widthTotal
- nTotalWidth
;
171 for ( i
= 0; i
< m_panes
.GetCount(); i
++ )
173 if ( m_panes
[i
].GetWidth() >= 0 )
174 widths
.Add(m_panes
[i
].GetWidth());
177 int nVarWidth
= widthExtra
> 0 ? (widthExtra
* (-m_panes
[i
].GetWidth())) / nVarCount
: 0;
178 nVarCount
+= m_panes
[i
].GetWidth();
179 widthExtra
-= nVarWidth
;
180 widths
.Add(nVarWidth
);
188 // ----------------------------------------------------------------------------
189 // status text stacks
190 // ----------------------------------------------------------------------------
192 void wxStatusBarBase::PushStatusText(const wxString
& text
, int number
)
194 // save the new text (in non-ellipsized form) in the stack
195 m_panes
[number
].m_arrStack
.push_back(text
);
197 SetStatusText(text
, number
);
198 // update current status text (which will possibly be ellipsized)
199 // also in the native control
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:
207 GetFieldRect(number
, rect
);
208 Refresh(true, &rect
);
212 void wxStatusBarBase::PopStatusText(int number
)
214 wxASSERT_MSG(m_panes
[number
].m_arrStack
.GetCount() > 1,
215 "can't pop any further string");
217 // the top of the stack is the status text currently shown in the native control;
219 m_panes
[number
].m_arrStack
.pop_back();
221 // restore the previous status text in the native control
222 const wxString
& text
= m_panes
[number
].m_arrStack
.back();
223 SetStatusText(text
, number
);
225 // see comment in wxStatusBarBase::PushStatusText about why we need to explicitely
226 // refresh the status bar pane
228 GetFieldRect(number
, rect
);
229 Refresh(true, &rect
);
233 #endif // wxUSE_STATUSBAR