From b31eaa5c34b384f0d210d9e06c9159f9fd59ea16 Mon Sep 17 00:00:00 2001 From: Francesco Montorsi Date: Sun, 15 Mar 2009 17:54:05 +0000 Subject: [PATCH] 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 --- include/wx/statusbr.h | 43 ++++++++++++++++++++---- interface/wx/statusbr.h | 70 +++++++++++++++++++++++++++++++++++++--- src/common/statbar.cpp | 26 +++++++-------- src/generic/statusbr.cpp | 2 +- src/msw/statusbar.cpp | 4 +-- src/univ/statusbr.cpp | 4 +-- 6 files changed, 121 insertions(+), 28 deletions(-) diff --git a/include/wx/statusbr.h b/include/wx/statusbr.h index 66ec068c96..3d1ca63a4b 100644 --- a/include/wx/statusbr.h +++ b/include/wx/statusbr.h @@ -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; } + + // use wxStatusBar setter functions to modify a wxStatusBarPane - int nStyle; - int nWidth; // the width maybe negative, indicating a variable-width field +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: diff --git a/interface/wx/statusbr.h b/interface/wx/statusbr.h index 1f95231b01..d078e37b61 100644 --- a/interface/wx/statusbr.h +++ b/interface/wx/statusbr.h @@ -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. diff --git a/src/common/statbar.cpp b/src/common/statbar.cpp index 323ce920e0..a05afa4b1b 100644 --- a/src/common/statbar.cpp +++ b/src/common/statbar.cpp @@ -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); diff --git a/src/generic/statusbr.cpp b/src/generic/statusbr.cpp index f4dfe9c0d4..1264843946 100644 --- a/src/generic/statusbr.cpp +++ b/src/generic/statusbr.cpp @@ -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 diff --git a/src/msw/statusbar.cpp b/src/msw/statusbar.cpp index 667b9d13b6..e2fd86ab70 100644 --- a/src/msw/statusbar.cpp +++ b/src/msw/statusbar.cpp @@ -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; diff --git a/src/univ/statusbr.cpp b/src/univ/statusbr.cpp index 6b70e2e7f6..cc7a00096e 100644 --- a/src/univ/statusbr.cpp +++ b/src/univ/statusbr.cpp @@ -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; -- 2.45.2