make wxStatusBarPane a 'full class' with getters and protected data; document it; provide more accessors in wxStatusBar (closes #10574)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@59566 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -37,19 +37,33 @@ extern WXDLLIMPEXP_DATA_CORE(const char) wxStatusBarNameStr[];
|
||||
|
||||
class wxStatusBarPane
|
||||
{
|
||||
// only wxStatusBarBase can access our internal members and modify them:
|
||||
friend class WXDLLIMPEXP_FWD_CORE wxStatusBarBase;
|
||||
|
||||
public:
|
||||
wxStatusBarPane(int style = wxSB_NORMAL, size_t width = 0)
|
||||
: nStyle(style), nWidth(width) { arrStack.Add(wxEmptyString); }
|
||||
: m_nStyle(style), m_nWidth(width) { m_arrStack.Add(wxEmptyString); }
|
||||
|
||||
int GetWidth() const
|
||||
{ return m_nWidth; }
|
||||
int GetStyle() const
|
||||
{ return m_nStyle; }
|
||||
|
||||
const wxArrayString& GetStack() const
|
||||
{ return m_arrStack; }
|
||||
|
||||
int nStyle;
|
||||
int nWidth; // the width maybe negative, indicating a variable-width field
|
||||
// use wxStatusBar setter functions to modify a wxStatusBarPane
|
||||
|
||||
protected:
|
||||
int m_nStyle;
|
||||
int m_nWidth; // the width maybe negative, indicating a variable-width field
|
||||
|
||||
// this is the array of the stacked strings of this pane; note that this
|
||||
// stack does include also the string currently displayed in this pane
|
||||
// as the version stored in the native status bar control is possibly
|
||||
// ellipsized; note that arrStack.Last() is the top of the stack
|
||||
// (i.e. the string shown in the status bar)
|
||||
wxArrayString arrStack;
|
||||
wxArrayString m_arrStack;
|
||||
};
|
||||
|
||||
WX_DECLARE_OBJARRAY(wxStatusBarPane, wxStatusBarPaneArray);
|
||||
@@ -77,9 +91,11 @@ public:
|
||||
// ----------
|
||||
|
||||
virtual void SetStatusText(const wxString& text, int number = 0)
|
||||
{ m_panes[number].arrStack.Last() = text; }
|
||||
{ m_panes[number].GetStack().Last() = text; }
|
||||
virtual wxString GetStatusText(int number = 0) const
|
||||
{ return m_panes[number].arrStack.Last(); }
|
||||
{ return m_panes[number].GetStack().Last(); }
|
||||
const wxArrayString& GetStatusStack(int n) const
|
||||
{ return m_panes[n].GetStack(); }
|
||||
|
||||
void PushStatusText(const wxString& text, int number = 0);
|
||||
void PopStatusText(int number = 0);
|
||||
@@ -94,6 +110,9 @@ public:
|
||||
// negative width according to the abs value of the width (field with width
|
||||
// -2 grows twice as much as one with width -1 &c)
|
||||
virtual void SetStatusWidths(int n, const int widths[]);
|
||||
|
||||
int GetStatusWidth(int n) const
|
||||
{ return m_panes[n].GetWidth(); }
|
||||
|
||||
// field styles
|
||||
// ------------
|
||||
@@ -103,6 +122,9 @@ public:
|
||||
// appears flat or wxSB_POPOUT to make the field appear raised.
|
||||
// Setting field styles only works on wxMSW
|
||||
virtual void SetStatusStyles(int n, const int styles[]);
|
||||
|
||||
int GetStatusStyle(int n) const
|
||||
{ return m_panes[n].GetStyle(); }
|
||||
|
||||
// geometry
|
||||
// --------
|
||||
@@ -117,9 +139,18 @@ public:
|
||||
virtual int GetBorderX() const = 0;
|
||||
virtual int GetBorderY() const = 0;
|
||||
|
||||
// miscellaneous
|
||||
// -------------
|
||||
|
||||
const wxStatusBarPane& GetField(int n) const
|
||||
{ return m_panes[n]; }
|
||||
|
||||
// wxWindow overrides:
|
||||
|
||||
// don't want status bars to accept the focus at all
|
||||
virtual bool AcceptsFocus() const { return false; }
|
||||
|
||||
// the client size of a toplevel window doesn't include the status bar
|
||||
virtual bool CanBeOutsideClientArea() const { return true; }
|
||||
|
||||
protected:
|
||||
|
@@ -6,6 +6,42 @@
|
||||
// Licence: wxWindows license
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
@class wxStatusBarPane
|
||||
|
||||
A status bar pane data container used by wxStatusBar.
|
||||
*/
|
||||
class wxStatusBarPane
|
||||
{
|
||||
public:
|
||||
/**
|
||||
Constructs the pane with the given @a style and @a width.
|
||||
*/
|
||||
wxStatusBarPane(int style = wxSB_NORMAL, size_t width = 0);
|
||||
|
||||
/**
|
||||
Returns the pane width; it maybe negative, indicating a variable-width field.
|
||||
*/
|
||||
int GetWidth() const;
|
||||
|
||||
/**
|
||||
Returns the pane style.
|
||||
*/
|
||||
int GetStyle() const;
|
||||
|
||||
/**
|
||||
Returns the stack of strings pushed on this pane.
|
||||
|
||||
Note that this stack does include also the string currently displayed in this pane
|
||||
as the version stored in the native status bar control is possibly ellipsized.
|
||||
|
||||
Also note that GetStack().Last() is the top of the stack (i.e. the string shown
|
||||
in the status bar).
|
||||
*/
|
||||
const wxArrayString& GetStack() const
|
||||
{ return m_arrStack; }
|
||||
};
|
||||
|
||||
/**
|
||||
@class wxStatusBar
|
||||
|
||||
@@ -25,7 +61,7 @@
|
||||
@library{wxcore}
|
||||
@category{miscwnd}
|
||||
|
||||
@see wxFrame, @ref page_samples_statbar
|
||||
@see wxStatusBarPane, wxFrame, @ref page_samples_statbar
|
||||
*/
|
||||
class wxStatusBar : public wxWindow
|
||||
{
|
||||
@@ -84,10 +120,11 @@ public:
|
||||
virtual bool GetFieldRect(int i, wxRect& rect) const;
|
||||
|
||||
/**
|
||||
Returns the number of fields in the status bar.
|
||||
Returns the wxStatusBarPane representing the @a n-th field.
|
||||
*/
|
||||
int GetFieldsCount() const;
|
||||
|
||||
const wxStatusBarPane& GetField(int n) const
|
||||
{ return m_panes[n]; }
|
||||
|
||||
/**
|
||||
Returns the string associated with a status bar field.
|
||||
|
||||
@@ -101,6 +138,31 @@ public:
|
||||
*/
|
||||
virtual wxString GetStatusText(int i = 0) const;
|
||||
|
||||
/**
|
||||
Returns the stack of strings pushed (see PushStatusText()) on the
|
||||
@a n-th field.
|
||||
|
||||
See wxStatusBarPane::GetStack() for more info.
|
||||
*/
|
||||
const wxArrayString& GetStatusStack(int n) const
|
||||
{ return m_panes[n].GetStack(); }
|
||||
|
||||
/**
|
||||
Returns the width of the @a n-th field.
|
||||
|
||||
See wxStatusBarPane::GetWidth() for more info.
|
||||
*/
|
||||
int GetStatusWidth(int n) const
|
||||
{ return m_panes[n].GetWidth(); }
|
||||
|
||||
/**
|
||||
Returns the style of the @a n-th field.
|
||||
|
||||
See wxStatusBarPane::GetStyle() for more info.
|
||||
*/
|
||||
int GetStatusStyle(int n) const
|
||||
{ return m_panes[n].GetStyle(); }
|
||||
|
||||
/**
|
||||
Sets the field text to the top of the stack, and pops the stack of saved
|
||||
strings.
|
||||
|
@@ -104,7 +104,7 @@ void wxStatusBarBase::SetStatusWidths(int WXUNUSED_UNLESS_DEBUG(n),
|
||||
else
|
||||
{
|
||||
for ( size_t i = 0; i < m_panes.GetCount(); i++ )
|
||||
m_panes[i].nWidth = widths[i];
|
||||
m_panes[i].m_nWidth = widths[i];
|
||||
|
||||
m_bSameWidthForAllPanes = false;
|
||||
}
|
||||
@@ -121,7 +121,7 @@ void wxStatusBarBase::SetStatusStyles(int WXUNUSED_UNLESS_DEBUG(n),
|
||||
wxASSERT_MSG( (size_t)n == m_panes.GetCount(), _T("field number mismatch") );
|
||||
|
||||
for ( size_t i = 0; i < m_panes.GetCount(); i++ )
|
||||
m_panes[i].nStyle = styles[i];
|
||||
m_panes[i].m_nStyle = styles[i];
|
||||
|
||||
// update the display after the widths changed
|
||||
Refresh();
|
||||
@@ -158,10 +158,10 @@ wxArrayInt wxStatusBarBase::CalculateAbsWidths(wxCoord widthTotal) const
|
||||
|
||||
for ( i = 0; i < m_panes.GetCount(); i++ )
|
||||
{
|
||||
if ( m_panes[i].nWidth >= 0 )
|
||||
nTotalWidth += m_panes[i].nWidth;
|
||||
if ( m_panes[i].GetWidth() >= 0 )
|
||||
nTotalWidth += m_panes[i].GetWidth();
|
||||
else
|
||||
nVarCount += -m_panes[i].nWidth;
|
||||
nVarCount += -m_panes[i].GetWidth();
|
||||
}
|
||||
|
||||
// the amount of extra width we have per each var width field
|
||||
@@ -170,12 +170,12 @@ wxArrayInt wxStatusBarBase::CalculateAbsWidths(wxCoord widthTotal) const
|
||||
// do fill the array
|
||||
for ( i = 0; i < m_panes.GetCount(); i++ )
|
||||
{
|
||||
if ( m_panes[i].nWidth >= 0 )
|
||||
widths.Add(m_panes[i].nWidth);
|
||||
if ( m_panes[i].GetWidth() >= 0 )
|
||||
widths.Add(m_panes[i].GetWidth());
|
||||
else
|
||||
{
|
||||
int nVarWidth = widthExtra > 0 ? (widthExtra * (-m_panes[i].nWidth)) / nVarCount : 0;
|
||||
nVarCount += m_panes[i].nWidth;
|
||||
int nVarWidth = widthExtra > 0 ? (widthExtra * (-m_panes[i].GetWidth())) / nVarCount : 0;
|
||||
nVarCount += m_panes[i].GetWidth();
|
||||
widthExtra -= nVarWidth;
|
||||
widths.Add(nVarWidth);
|
||||
}
|
||||
@@ -192,7 +192,7 @@ wxArrayInt wxStatusBarBase::CalculateAbsWidths(wxCoord widthTotal) const
|
||||
void wxStatusBarBase::PushStatusText(const wxString& text, int number)
|
||||
{
|
||||
// save current status text in the stack
|
||||
m_panes[number].arrStack.push_back(GetStatusText(number));
|
||||
m_panes[number].m_arrStack.push_back(GetStatusText(number));
|
||||
|
||||
SetStatusText(text, number);
|
||||
// update current status text (eventually also in the native control)
|
||||
@@ -200,11 +200,11 @@ void wxStatusBarBase::PushStatusText(const wxString& text, int number)
|
||||
|
||||
void wxStatusBarBase::PopStatusText(int number)
|
||||
{
|
||||
wxASSERT_MSG(m_panes[number].arrStack.GetCount() == 1,
|
||||
wxASSERT_MSG(m_panes[number].m_arrStack.GetCount() == 1,
|
||||
"can't pop any further string");
|
||||
|
||||
wxString text = m_panes[number].arrStack.back();
|
||||
m_panes[number].arrStack.pop_back(); // also remove it from the stack
|
||||
wxString text = m_panes[number].m_arrStack.back();
|
||||
m_panes[number].m_arrStack.pop_back(); // also remove it from the stack
|
||||
|
||||
// restore the popped status text in the pane
|
||||
SetStatusText(text, number);
|
||||
|
@@ -225,7 +225,7 @@ void wxStatusBarGeneric::DrawField(wxDC& dc, int i, int textHeight)
|
||||
if (rect.GetWidth() <= 0)
|
||||
return; // happens when the status bar is shrinked in a very small area!
|
||||
|
||||
int style = m_panes[i].nStyle;
|
||||
int style = m_panes[i].GetStyle();
|
||||
if (style != wxSB_FLAT)
|
||||
{
|
||||
// Draw border
|
||||
|
@@ -232,7 +232,7 @@ void wxStatusBar::UpdateFieldText(int nField)
|
||||
|
||||
// Get field style, if any
|
||||
int style;
|
||||
switch(m_panes[nField].nStyle)
|
||||
switch(m_panes[nField].GetStyle())
|
||||
{
|
||||
case wxSB_RAISED:
|
||||
style = SBT_POPOUT;
|
||||
@@ -338,7 +338,7 @@ wxSize wxStatusBar::DoGetBestSize() const
|
||||
for ( size_t i = 0; i < m_panes.GetCount(); ++i )
|
||||
{
|
||||
int widthField =
|
||||
m_bSameWidthForAllPanes ? DEFAULT_FIELD_WIDTH : m_panes[i].nWidth;
|
||||
m_bSameWidthForAllPanes ? DEFAULT_FIELD_WIDTH : m_panes[i].GetWidth();
|
||||
if ( widthField >= 0 )
|
||||
{
|
||||
width += widthField;
|
||||
|
@@ -134,7 +134,7 @@ void wxStatusBarUniv::DoDraw(wxControlRenderer *renderer)
|
||||
flags |= wxCONTROL_SIZEGRIP;
|
||||
}
|
||||
|
||||
m_renderer->DrawStatusField(dc, rect, GetStatusText(n), flags, m_panes[n].nStyle);
|
||||
m_renderer->DrawStatusField(dc, rect, GetStatusText(n), flags, m_panes[n].GetStyle());
|
||||
}
|
||||
|
||||
rect.x += rect.width + borderBetweenFields;
|
||||
@@ -207,7 +207,7 @@ void wxStatusBarUniv::OnSize(wxSizeEvent& event)
|
||||
{
|
||||
for ( field = 0; field < m_panes.GetCount(); field++ )
|
||||
{
|
||||
if ( m_panes[field].nWidth < 0 )
|
||||
if ( m_panes[field].GetWidth() < 0 )
|
||||
{
|
||||
// var width field
|
||||
break;
|
||||
|
Reference in New Issue
Block a user