]> git.saurik.com Git - wxWidgets.git/commitdiff
make wxStatusBarPane a 'full class' with getters and protected data; document it...
authorFrancesco Montorsi <f18m_cpp217828@yahoo.it>
Sun, 15 Mar 2009 17:54:05 +0000 (17:54 +0000)
committerFrancesco Montorsi <f18m_cpp217828@yahoo.it>
Sun, 15 Mar 2009 17:54:05 +0000 (17:54 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@59566 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/statusbr.h
interface/wx/statusbr.h
src/common/statbar.cpp
src/generic/statusbr.cpp
src/msw/statusbar.cpp
src/univ/statusbr.cpp

index 66ec068c96ea6063a5253725fd5de85bbd37db79..3d1ca63a4b4fa8b794b921ea795c1f9645c22bba 100644 (file)
@@ -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:
index 1f95231b015ca87aae330c7652f956abb0e5c822..d078e37b6114398c1b013d5b892418654a54a3e6 100644 (file)
@@ -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.
index 323ce920e048558ed816a5ab515e6519cbe9e0b3..a05afa4b1b83b8d995817612898965b0110726f5 100644 (file)
@@ -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);
index f4dfe9c0d402922da56c1f500604031da30fbd8b..12648439464304f456297d1d0263c79c514b22c1 100644 (file)
@@ -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
index 667b9d13b645c11a335fc8383501e2673e81d4a5..e2fd86ab70b53b4a48f4b206b777b51be9a5d372 100644 (file)
@@ -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;
index 6b70e2e7f6f7917786161c8edab27f32c1e52c85..cc7a00096e405bd11b5994d38e0a8f429acd05d5 100644 (file)
@@ -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;