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:
Francesco Montorsi
2009-03-15 17:54:05 +00:00
parent bff248644e
commit b31eaa5c34
6 changed files with 121 additions and 28 deletions

View File

@@ -37,19 +37,33 @@ extern WXDLLIMPEXP_DATA_CORE(const char) wxStatusBarNameStr[];
class wxStatusBarPane class wxStatusBarPane
{ {
// only wxStatusBarBase can access our internal members and modify them:
friend class WXDLLIMPEXP_FWD_CORE wxStatusBarBase;
public: public:
wxStatusBarPane(int style = wxSB_NORMAL, size_t width = 0) 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 nStyle; int GetWidth() const
int nWidth; // the width maybe negative, indicating a variable-width field { return m_nWidth; }
int GetStyle() const
{ return m_nStyle; }
const wxArrayString& GetStack() const
{ return m_arrStack; }
// 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 // 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 // stack does include also the string currently displayed in this pane
// as the version stored in the native status bar control is possibly // as the version stored in the native status bar control is possibly
// ellipsized; note that arrStack.Last() is the top of the stack // ellipsized; note that arrStack.Last() is the top of the stack
// (i.e. the string shown in the status bar) // (i.e. the string shown in the status bar)
wxArrayString arrStack; wxArrayString m_arrStack;
}; };
WX_DECLARE_OBJARRAY(wxStatusBarPane, wxStatusBarPaneArray); WX_DECLARE_OBJARRAY(wxStatusBarPane, wxStatusBarPaneArray);
@@ -77,9 +91,11 @@ public:
// ---------- // ----------
virtual void SetStatusText(const wxString& text, int number = 0) 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 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 PushStatusText(const wxString& text, int number = 0);
void PopStatusText(int number = 0); void PopStatusText(int number = 0);
@@ -95,6 +111,9 @@ public:
// -2 grows twice as much as one with width -1 &c) // -2 grows twice as much as one with width -1 &c)
virtual void SetStatusWidths(int n, const int widths[]); virtual void SetStatusWidths(int n, const int widths[]);
int GetStatusWidth(int n) const
{ return m_panes[n].GetWidth(); }
// field styles // field styles
// ------------ // ------------
@@ -104,6 +123,9 @@ public:
// Setting field styles only works on wxMSW // Setting field styles only works on wxMSW
virtual void SetStatusStyles(int n, const int styles[]); virtual void SetStatusStyles(int n, const int styles[]);
int GetStatusStyle(int n) const
{ return m_panes[n].GetStyle(); }
// geometry // geometry
// -------- // --------
@@ -117,9 +139,18 @@ public:
virtual int GetBorderX() const = 0; virtual int GetBorderX() const = 0;
virtual int GetBorderY() 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 // don't want status bars to accept the focus at all
virtual bool AcceptsFocus() const { return false; } 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; } virtual bool CanBeOutsideClientArea() const { return true; }
protected: protected:

View File

@@ -6,6 +6,42 @@
// Licence: wxWindows license // 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 @class wxStatusBar
@@ -25,7 +61,7 @@
@library{wxcore} @library{wxcore}
@category{miscwnd} @category{miscwnd}
@see wxFrame, @ref page_samples_statbar @see wxStatusBarPane, wxFrame, @ref page_samples_statbar
*/ */
class wxStatusBar : public wxWindow class wxStatusBar : public wxWindow
{ {
@@ -84,9 +120,10 @@ public:
virtual bool GetFieldRect(int i, wxRect& rect) const; 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. Returns the string associated with a status bar field.
@@ -101,6 +138,31 @@ public:
*/ */
virtual wxString GetStatusText(int i = 0) const; 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 Sets the field text to the top of the stack, and pops the stack of saved
strings. strings.

View File

@@ -104,7 +104,7 @@ void wxStatusBarBase::SetStatusWidths(int WXUNUSED_UNLESS_DEBUG(n),
else else
{ {
for ( size_t i = 0; i < m_panes.GetCount(); i++ ) 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; 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") ); wxASSERT_MSG( (size_t)n == m_panes.GetCount(), _T("field number mismatch") );
for ( size_t i = 0; i < m_panes.GetCount(); i++ ) 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 // update the display after the widths changed
Refresh(); Refresh();
@@ -158,10 +158,10 @@ wxArrayInt wxStatusBarBase::CalculateAbsWidths(wxCoord widthTotal) const
for ( i = 0; i < m_panes.GetCount(); i++ ) for ( i = 0; i < m_panes.GetCount(); i++ )
{ {
if ( m_panes[i].nWidth >= 0 ) if ( m_panes[i].GetWidth() >= 0 )
nTotalWidth += m_panes[i].nWidth; nTotalWidth += m_panes[i].GetWidth();
else else
nVarCount += -m_panes[i].nWidth; nVarCount += -m_panes[i].GetWidth();
} }
// the amount of extra width we have per each var width field // 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 // do fill the array
for ( i = 0; i < m_panes.GetCount(); i++ ) for ( i = 0; i < m_panes.GetCount(); i++ )
{ {
if ( m_panes[i].nWidth >= 0 ) if ( m_panes[i].GetWidth() >= 0 )
widths.Add(m_panes[i].nWidth); widths.Add(m_panes[i].GetWidth());
else else
{ {
int nVarWidth = widthExtra > 0 ? (widthExtra * (-m_panes[i].nWidth)) / nVarCount : 0; int nVarWidth = widthExtra > 0 ? (widthExtra * (-m_panes[i].GetWidth())) / nVarCount : 0;
nVarCount += m_panes[i].nWidth; nVarCount += m_panes[i].GetWidth();
widthExtra -= nVarWidth; widthExtra -= nVarWidth;
widths.Add(nVarWidth); widths.Add(nVarWidth);
} }
@@ -192,7 +192,7 @@ wxArrayInt wxStatusBarBase::CalculateAbsWidths(wxCoord widthTotal) const
void wxStatusBarBase::PushStatusText(const wxString& text, int number) void wxStatusBarBase::PushStatusText(const wxString& text, int number)
{ {
// save current status text in the stack // 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); SetStatusText(text, number);
// update current status text (eventually also in the native control) // 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) 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"); "can't pop any further string");
wxString text = m_panes[number].arrStack.back(); wxString text = m_panes[number].m_arrStack.back();
m_panes[number].arrStack.pop_back(); // also remove it from the stack m_panes[number].m_arrStack.pop_back(); // also remove it from the stack
// restore the popped status text in the pane // restore the popped status text in the pane
SetStatusText(text, number); SetStatusText(text, number);

View File

@@ -225,7 +225,7 @@ void wxStatusBarGeneric::DrawField(wxDC& dc, int i, int textHeight)
if (rect.GetWidth() <= 0) if (rect.GetWidth() <= 0)
return; // happens when the status bar is shrinked in a very small area! 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) if (style != wxSB_FLAT)
{ {
// Draw border // Draw border

View File

@@ -232,7 +232,7 @@ void wxStatusBar::UpdateFieldText(int nField)
// Get field style, if any // Get field style, if any
int style; int style;
switch(m_panes[nField].nStyle) switch(m_panes[nField].GetStyle())
{ {
case wxSB_RAISED: case wxSB_RAISED:
style = SBT_POPOUT; style = SBT_POPOUT;
@@ -338,7 +338,7 @@ wxSize wxStatusBar::DoGetBestSize() const
for ( size_t i = 0; i < m_panes.GetCount(); ++i ) for ( size_t i = 0; i < m_panes.GetCount(); ++i )
{ {
int widthField = int widthField =
m_bSameWidthForAllPanes ? DEFAULT_FIELD_WIDTH : m_panes[i].nWidth; m_bSameWidthForAllPanes ? DEFAULT_FIELD_WIDTH : m_panes[i].GetWidth();
if ( widthField >= 0 ) if ( widthField >= 0 )
{ {
width += widthField; width += widthField;

View File

@@ -134,7 +134,7 @@ void wxStatusBarUniv::DoDraw(wxControlRenderer *renderer)
flags |= wxCONTROL_SIZEGRIP; 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; rect.x += rect.width + borderBetweenFields;
@@ -207,7 +207,7 @@ void wxStatusBarUniv::OnSize(wxSizeEvent& event)
{ {
for ( field = 0; field < m_panes.GetCount(); field++ ) for ( field = 0; field < m_panes.GetCount(); field++ )
{ {
if ( m_panes[field].nWidth < 0 ) if ( m_panes[field].GetWidth() < 0 )
{ {
// var width field // var width field
break; break;