]>
git.saurik.com Git - wxWidgets.git/blob - src/common/statbar.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: common/statbar.cpp
3 // Purpose: wxStatusBarBase implementation
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 2001 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // License: wxWindows license
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "statbar.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
32 #include "wx/statusbr.h"
37 #include "wx/listimpl.cpp"
38 WX_DEFINE_LIST(wxListString
);
40 // ============================================================================
41 // wxStatusBarBase implementation
42 // ============================================================================
44 IMPLEMENT_DYNAMIC_CLASS(wxStatusBar
, wxWindow
)
46 // ----------------------------------------------------------------------------
48 // ----------------------------------------------------------------------------
50 wxStatusBarBase::wxStatusBarBase()
58 wxStatusBarBase::~wxStatusBarBase()
64 // ----------------------------------------------------------------------------
65 // widths array handling
66 // ----------------------------------------------------------------------------
68 void wxStatusBarBase::InitWidths()
70 m_statusWidths
= NULL
;
73 void wxStatusBarBase::FreeWidths()
75 delete [] m_statusWidths
;
78 // ----------------------------------------------------------------------------
80 // ----------------------------------------------------------------------------
82 void wxStatusBarBase::SetFieldsCount(int number
, const int *widths
)
84 wxCHECK_RET( number
> 0, _T("invalid field number in SetFieldsCount") );
88 if ( number
!= m_nFields
)
90 // copy stacks if present
91 if(m_statusTextStacks
)
93 wxListString
**newStacks
= new wxListString
*[number
];
94 size_t i
, j
, max
= wxMin(number
, m_nFields
);
97 for(i
= 0; i
< max
; ++i
)
98 newStacks
[i
] = m_statusTextStacks
[i
];
99 // free old stacks in excess
100 for(j
= i
; j
< (size_t)m_nFields
; ++j
)
102 if(m_statusTextStacks
[j
])
104 m_statusTextStacks
[j
]->Clear();
105 delete m_statusTextStacks
[j
];
108 // initialize new stacks to NULL
109 for(j
= i
; j
< (size_t)number
; ++j
)
112 m_statusTextStacks
= newStacks
;
121 //else: keep the old m_statusWidths if we had them
125 SetStatusWidths(number
, widths
);
127 // already done from SetStatusWidths()
135 void wxStatusBarBase::SetStatusWidths(int WXUNUSED_UNLESS_DEBUG(n
),
138 wxCHECK_RET( widths
, _T("NULL pointer in SetStatusWidths") );
140 wxASSERT_MSG( n
== m_nFields
, _T("field number mismatch") );
142 if ( !m_statusWidths
)
143 m_statusWidths
= new int[m_nFields
];
145 for ( int i
= 0; i
< m_nFields
; i
++ )
147 m_statusWidths
[i
] = widths
[i
];
150 // update the display after the widths changed
154 wxArrayInt
wxStatusBarBase::CalculateAbsWidths(wxCoord widthTotal
) const
158 if ( m_statusWidths
== NULL
)
162 // default: all fields have the same width
163 int nWidth
= widthTotal
/ m_nFields
;
164 for ( int i
= 0; i
< m_nFields
; i
++ )
169 //else: we're empty anyhow
171 else // have explicit status widths
173 // calculate the total width of all the fixed width fields and the
174 // total number of var field widths counting with multiplicity
178 for ( i
= 0; i
< m_nFields
; i
++ )
180 if ( m_statusWidths
[i
] >= 0 )
182 nTotalWidth
+= m_statusWidths
[i
];
186 nVarCount
+= -m_statusWidths
[i
];
190 // the amount of extra width we have per each var width field
194 int widthExtra
= widthTotal
- nTotalWidth
;
195 nVarWidth
= widthExtra
> 0 ? widthExtra
/ nVarCount
: 0;
197 else // no var width fields at all
203 for ( i
= 0; i
< m_nFields
; i
++ )
205 if ( m_statusWidths
[i
] >= 0 )
207 widths
.Add(m_statusWidths
[i
]);
211 widths
.Add(-m_statusWidths
[i
]*nVarWidth
);
219 // ----------------------------------------------------------------------------
220 // text stacks handling
221 // ----------------------------------------------------------------------------
223 void wxStatusBarBase::InitStacks()
225 m_statusTextStacks
= NULL
;
228 void wxStatusBarBase::FreeStacks()
230 if(!m_statusTextStacks
) return;
233 for(i
= 0; i
< (size_t)m_nFields
; ++i
)
235 if(m_statusTextStacks
[i
])
237 m_statusTextStacks
[i
]->Clear();
238 delete m_statusTextStacks
[i
];
242 delete[] m_statusTextStacks
;
245 // ----------------------------------------------------------------------------
247 // ----------------------------------------------------------------------------
249 void wxStatusBarBase::PushStatusText(const wxString
& text
, int number
)
251 wxListString
* st
= GetOrCreateStatusStack(number
);
252 st
->Insert(new wxString(GetStatusText(number
)));
253 SetStatusText(text
, number
);
256 void wxStatusBarBase::PopStatusText(int number
)
258 wxListString
*st
= GetStatusStack(number
);
259 wxCHECK_RET( st
, _T("Unbalanced PushStatusText/PopStatusText") );
260 wxListString::Node
*top
= st
->GetFirst();
262 SetStatusText(*top
->GetData(), number
);
264 if(st
->GetCount() == 0)
267 m_statusTextStacks
[number
] = 0;
271 wxListString
*wxStatusBarBase::GetStatusStack(int i
) const
273 if(!m_statusTextStacks
)
275 return m_statusTextStacks
[i
];
278 wxListString
*wxStatusBarBase::GetOrCreateStatusStack(int i
)
280 if(!m_statusTextStacks
)
282 m_statusTextStacks
= new wxListString
*[m_nFields
];
285 for(j
= 0; j
< (size_t)m_nFields
; ++j
) m_statusTextStacks
[j
] = 0;
288 if(!m_statusTextStacks
[i
])
290 m_statusTextStacks
[i
] = new wxListString();
291 m_statusTextStacks
[i
]->DeleteContents(TRUE
);
294 return m_statusTextStacks
[i
];
297 #endif // wxUSE_STATUSBAR