]> git.saurik.com Git - wxWidgets.git/commitdiff
get rid of the wxListString class in wxStatusBar code; introduce a wxStatusBarPane...
authorFrancesco Montorsi <f18m_cpp217828@yahoo.it>
Wed, 31 Dec 2008 12:28:05 +0000 (12:28 +0000)
committerFrancesco Montorsi <f18m_cpp217828@yahoo.it>
Wed, 31 Dec 2008 12:28:05 +0000 (12:28 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@57686 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/generic/statusbr.h
include/wx/palmos/statusbr.h
include/wx/statusbr.h
include/wx/univ/statusbr.h
src/common/statbar.cpp
src/generic/statusbr.cpp
src/msw/statusbar.cpp
src/osx/carbon/statbrma.cpp
src/univ/statusbr.cpp

index 2f58f2b93e11a394b251589832a42cde88c5509e..785011cbeb24a5c6af19f526d683dd50b30a617d 100644 (file)
 #include "wx/pen.h"
 #include "wx/arrstr.h"
 
+
+// ----------------------------------------------------------------------------
+// wxStatusBarGeneric
+// ----------------------------------------------------------------------------
+
 class WXDLLIMPEXP_CORE wxStatusBarGeneric : public wxStatusBarBase
 {
 public:
@@ -87,11 +92,13 @@ protected:
     // common part of all ctors
     void Init();
 
+    // the array of the currently displayed strings
     wxArrayString     m_statusStrings;
 
     // the last known width of the client rect (used to rebuild cache)
     int               m_lastClientWidth;
-    // the widths of the status bar panes in pixels
+
+    // the absolute widths of the status bar panes in pixels
     wxArrayInt        m_widthsAbs;
 
     int               m_borderX;
index af51252d21943d6c78301b2256e892d61724e116..977723ce854c0b67aab747261eb80a23d3e65fb9 100644 (file)
@@ -63,7 +63,7 @@ public:
 protected:
     void CopyFieldsWidth(const int widths[]);
     void SetFieldsWidth();
-
+/*
     // store the text in the status bar
     wxListString **StatusTextBuffer;
     void SetStatusBufferText(const wxString& text, int number);
@@ -72,6 +72,9 @@ protected:
     wxListString *GetStatusBufferStack(int i) const;
     void DeleteStatusBuffer();
 
+    TODO: reuse wxStatusBarBase's stack routines instead of reimplementing them here
+*/
+
     // override base class virtual
     void DoMoveWindow(int x, int y, int width, int height);
 
index 70f24e2734627223e3633dbc6d1e56594e675d72..a5593c27cf92a79a7a26d0df3c2b322a7a3dc0f0 100644 (file)
@@ -22,8 +22,6 @@
 
 extern WXDLLIMPEXP_DATA_CORE(const char) wxStatusBarNameStr[];
 
-WX_DECLARE_LIST(wxString, wxListString);
-
 // ----------------------------------------------------------------------------
 // wxStatusBar constants
 // ----------------------------------------------------------------------------
@@ -33,6 +31,27 @@ WX_DECLARE_LIST(wxString, wxListString);
 #define wxSB_FLAT      0x0001
 #define wxSB_RAISED    0x0002
 
+// ----------------------------------------------------------------------------
+// wxStatusBarPane: an helper for wxStatusBar
+// ----------------------------------------------------------------------------
+
+class wxStatusBarPane
+{
+public:
+    wxStatusBarPane(int style = wxSB_NORMAL, size_t width = 0)
+        : nStyle(style), nWidth(width) {}
+
+    int nStyle;
+    int 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 not include the string currently displayed in this pane
+    // as it's stored in the native status bar control
+    wxArrayString arrStack;
+};
+
+WX_DECLARE_OBJARRAY(wxStatusBarPane, wxStatusBarPaneArray);
+
 // ----------------------------------------------------------------------------
 // wxStatusBar: a window near the bottom of the frame used for status info
 // ----------------------------------------------------------------------------
@@ -50,7 +69,7 @@ public:
     // set the number of fields and call SetStatusWidths(widths) if widths are
     // given
     virtual void SetFieldsCount(int number = 1, const int *widths = NULL);
-    int GetFieldsCount() const { return m_nFields; }
+    int GetFieldsCount() const { return m_panes.GetCount(); }
 
     // field text
     // ----------
@@ -102,45 +121,14 @@ public:
 protected:
     virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; }
 
-    // set the widths array to NULL
-    void InitWidths();
-
-    // free the status widths arrays
-    void FreeWidths();
-
-    // reset the widths
-    void ReinitWidths() { FreeWidths(); InitWidths(); }
-
-    // same, for field styles
-    void InitStyles();
-    void FreeStyles();
-    void ReinitStyles() { FreeStyles(); InitStyles(); }
-
-    // same, for text stacks
-    void InitStacks();
-    void FreeStacks();
-    void ReinitStacks() { FreeStacks(); InitStacks(); }
-
     // calculate the real field widths for the given total available size
     wxArrayInt CalculateAbsWidths(wxCoord widthTotal) const;
 
-    // use these functions to access the stacks of field strings
-    wxListString *GetStatusStack(int i) const;
-    wxListString *GetOrCreateStatusStack(int i);
-
-    // the current number of fields
-    int        m_nFields;
-
-    // the widths of the fields in pixels if !NULL, all fields have the same
-    // width otherwise
-    int       *m_statusWidths;
+    // the array with the pane infos:
+    wxStatusBarPaneArray m_panes;
 
-    // the styles of the fields
-    int       *m_statusStyles;
-
-    // stacks of previous values for PushStatusText/PopStatusText
-    // this is created on demand, use GetStatusStack/GetOrCreateStatusStack
-    wxListString **m_statusTextStacks;
+    // if true overrides the width info of the wxStatusBarPanes
+    bool m_bSameWidthForAllPanes;
 
     DECLARE_NO_COPY_CLASS(wxStatusBarBase)
 };
@@ -151,22 +139,18 @@ protected:
 
 #if defined(__WXUNIVERSAL__)
     #define wxStatusBarUniv wxStatusBar
-
     #include "wx/univ/statusbr.h"
 #elif defined(__WXPALMOS__)
     #define wxStatusBarPalm wxStatusBar
-
     #include "wx/palmos/statusbr.h"
 #elif defined(__WIN32__) && wxUSE_NATIVE_STATUSBAR
     #include "wx/msw/statusbar.h"
 #elif defined(__WXMAC__)
     #define wxStatusBarMac wxStatusBar
-
     #include "wx/generic/statusbr.h"
     #include "wx/osx/statusbr.h"
 #else
     #define wxStatusBarGeneric wxStatusBar
-
     #include "wx/generic/statusbr.h"
 #endif
 
index 992b0ec99b06db04268cfac48ae5917058127c19..dca76ee74bf8b703346520ee6b4aefb7156f7961 100644 (file)
@@ -16,7 +16,7 @@
 #include "wx/arrstr.h"
 
 // ----------------------------------------------------------------------------
-// wxStatusBar: a window near the bottom of the frame used for status info
+// wxStatusBarUniv: a window near the bottom of the frame used for status info
 // ----------------------------------------------------------------------------
 
 class WXDLLIMPEXP_CORE wxStatusBarUniv : public wxStatusBarBase,
@@ -95,7 +95,7 @@ protected:
     void Init();
 
 private:
-    // the status fields strings
+    // the current status fields strings
     wxArrayString m_statusText;
 
     // the absolute status fields widths
index 36f0ac976e0dad7dcaa2345538a5c008ba4ee280..a8ad8868c82f5330d92172269a3c8865ad3cc3b9 100644 (file)
@@ -2,7 +2,7 @@
 // Name:        src/common/statbar.cpp
 // Purpose:     wxStatusBarBase implementation
 // Author:      Vadim Zeitlin
-// Modified by:
+// Modified by: Francesco Montorsi
 // Created:     14.10.01
 // RCS-ID:      $Id$
 // Copyright:   (c) 2001 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
     #include "wx/frame.h"
 #endif //WX_PRECOMP
 
-#include "wx/listimpl.cpp"
-WX_DEFINE_LIST(wxListString)
-
 const char wxStatusBarNameStr[] = "statusBar";
 
+
 // ============================================================================
 // wxStatusBarBase implementation
 // ============================================================================
 
 IMPLEMENT_DYNAMIC_CLASS(wxStatusBar, wxWindow)
 
+#include <wx/arrimpl.cpp> // This is a magic incantation which must be done!
+WX_DEFINE_OBJARRAY(wxStatusBarPaneArray);
+
+
 // ----------------------------------------------------------------------------
 // ctor/dtor
 // ----------------------------------------------------------------------------
 
 wxStatusBarBase::wxStatusBarBase()
 {
-    m_nFields = 0;
-
-    InitWidths();
-    InitStacks();
-    InitStyles();
+    m_bSameWidthForAllPanes = true;
 }
 
 wxStatusBarBase::~wxStatusBarBase()
 {
-    FreeWidths();
-    FreeStacks();
-    FreeStyles();
-
     // notify the frame that it doesn't have a status bar any longer to avoid
     // dangling pointers
-    wxFrame *frame = wxDynamicCast(GetParent(), wxFrame);
+    wxFrame *frame = dynamic_cast<wxFrame*>(GetParent());
     if ( frame && frame->GetStatusBar() == this )
-    {
         frame->SetStatusBar(NULL);
-    }
-}
-
-// ----------------------------------------------------------------------------
-// widths array handling
-// ----------------------------------------------------------------------------
-
-void wxStatusBarBase::InitWidths()
-{
-    m_statusWidths = NULL;
-}
-
-void wxStatusBarBase::FreeWidths()
-{
-    delete [] m_statusWidths;
-}
-
-// ----------------------------------------------------------------------------
-// styles array handling
-// ----------------------------------------------------------------------------
-
-void wxStatusBarBase::InitStyles()
-{
-    m_statusStyles = NULL;
-}
-
-void wxStatusBarBase::FreeStyles()
-{
-    delete [] m_statusStyles;
 }
 
 // ----------------------------------------------------------------------------
@@ -109,60 +73,22 @@ void wxStatusBarBase::SetFieldsCount(int number, const int *widths)
 
     bool refresh = false;
 
-    if ( number != m_nFields )
+    if ( (size_t)number > m_panes.GetCount() )
     {
-        // copy stacks if present
-        if(m_statusTextStacks)
-        {
-            wxListString **newStacks = new wxListString*[number];
-            size_t i, j, max = wxMin(number, m_nFields);
-
-            // copy old stacks
-            for(i = 0; i < max; ++i)
-                newStacks[i] = m_statusTextStacks[i];
-            // free old stacks in excess
-            for(j = i; j < (size_t)m_nFields; ++j)
-            {
-                if(m_statusTextStacks[j])
-                {
-                    m_statusTextStacks[j]->Clear();
-                    delete m_statusTextStacks[j];
-                }
-            }
-            // initialize new stacks to NULL
-            for(j = i; j < (size_t)number; ++j)
-                newStacks[j] = 0;
-
-            m_statusTextStacks = newStacks;
-        }
-
-        // Resize styles array
-        if (m_statusStyles)
-        {
-            int *oldStyles = m_statusStyles;
-            m_statusStyles = new int[number];
-            int i, max = wxMin(number, m_nFields);
-
-            // copy old styles
-            for (i = 0; i < max; ++i)
-                m_statusStyles[i] = oldStyles[i];
-
-            // initialize new styles to wxSB_NORMAL
-            for (i = max; i < number; ++i)
-                m_statusStyles[i] = wxSB_NORMAL;
+        wxStatusBarPane newPane;
 
-            // free old styles
-            delete [] oldStyles;
-        }
-
-
-        m_nFields = number;
-
-        ReinitWidths();
-
-        refresh = true;
+        // add more entries with the default style and zero width
+        // (this will be set later)
+        for (size_t i = m_panes.GetCount(); i < (size_t)number; ++i)
+            m_panes.Add(newPane);
     }
-    //else: keep the old m_statusWidths if we had them
+    else if ( (size_t)number < m_panes.GetCount() )
+    {
+        // remove entries in excess
+        m_panes.RemoveAt(number, m_panes.GetCount()-number);
+    }
+
+    refresh = true;
 
     if ( widths )
     {
@@ -181,15 +107,12 @@ void wxStatusBarBase::SetStatusWidths(int WXUNUSED_UNLESS_DEBUG(n),
 {
     wxCHECK_RET( widths, _T("NULL pointer in SetStatusWidths") );
 
-    wxASSERT_MSG( n == m_nFields, _T("field number mismatch") );
+    wxASSERT_MSG( (size_t)n == m_panes.GetCount(), _T("field number mismatch") );
 
-    if ( !m_statusWidths )
-        m_statusWidths = new int[m_nFields];
+    for ( size_t i = 0; i < m_panes.GetCount(); i++ )
+        m_panes[i].nWidth = widths[i];
 
-    for ( int i = 0; i < m_nFields; i++ )
-    {
-        m_statusWidths[i] = widths[i];
-    }
+    m_bSameWidthForAllPanes = false;
 
     // update the display after the widths changed
     Refresh();
@@ -200,15 +123,10 @@ void wxStatusBarBase::SetStatusStyles(int WXUNUSED_UNLESS_DEBUG(n),
 {
     wxCHECK_RET( styles, _T("NULL pointer in SetStatusStyles") );
 
-    wxASSERT_MSG( n == m_nFields, _T("field number mismatch") );
+    wxASSERT_MSG( (size_t)n == m_panes.GetCount(), _T("field number mismatch") );
 
-    if ( !m_statusStyles )
-        m_statusStyles = new int[m_nFields];
-
-    for ( int i = 0; i < m_nFields; i++ )
-    {
-        m_statusStyles[i] = styles[i];
-    }
+    for ( size_t i = 0; i < m_panes.GetCount(); i++ )
+        m_panes[i].nStyle = styles[i];
 
     // update the display after the widths changed
     Refresh();
@@ -218,61 +136,51 @@ wxArrayInt wxStatusBarBase::CalculateAbsWidths(wxCoord widthTotal) const
 {
     wxArrayInt widths;
 
-    if ( m_statusWidths == NULL )
+    if ( m_bSameWidthForAllPanes )
     {
-        if ( m_nFields )
-        {
-            // Default: all fields have the same width. This is not always
-            // possible to do exactly (if widthTotal is not divisible by
-            // m_nFields) - if that happens, we distribute the extra pixels
-            // among all fields:
-            int widthToUse = widthTotal;
-
-            for ( int i = m_nFields; i > 0; i-- )
-            {
-                // divide the unassigned width evently between the
-                // not yet processed fields:
-                int w = widthToUse / i;
-                widths.Add(w);
-                widthToUse -= w;
-            }
+        // Default: all fields have the same width. This is not always
+        // possible to do exactly (if widthTotal is not divisible by
+        // m_panes.GetCount()) - if that happens, we distribute the extra
+        // pixels among all fields:
+        int widthToUse = widthTotal;
 
+        for ( size_t i = m_panes.GetCount(); i > 0; i-- )
+        {
+            // divide the unassigned width evently between the
+            // not yet processed fields:
+            int w = widthToUse / i;
+            widths.Add(w);
+            widthToUse -= w;
         }
-        //else: we're empty anyhow
     }
-    else // have explicit status widths
+    else // do not override explicit pane widths
     {
         // calculate the total width of all the fixed width fields and the
         // total number of var field widths counting with multiplicity
-        int nTotalWidth = 0,
-            nVarCount = 0,
-            i;
-        for ( i = 0; i < m_nFields; i++ )
+        size_t nTotalWidth = 0,
+               nVarCount = 0,
+               i;
+
+        for ( i = 0; i < m_panes.GetCount(); i++ )
         {
-            if ( m_statusWidths[i] >= 0 )
-            {
-                nTotalWidth += m_statusWidths[i];
-            }
+            if ( m_panes[i].nWidth >= 0 )
+                nTotalWidth += m_panes[i].nWidth;
             else
-            {
-                nVarCount += -m_statusWidths[i];
-            }
+                nVarCount += -m_panes[i].nWidth;
         }
 
         // the amount of extra width we have per each var width field
         int widthExtra = widthTotal - nTotalWidth;
 
         // do fill the array
-        for ( i = 0; i < m_nFields; i++ )
+        for ( i = 0; i < m_panes.GetCount(); i++ )
         {
-            if ( m_statusWidths[i] >= 0 )
-            {
-                widths.Add(m_statusWidths[i]);
-            }
+            if ( m_panes[i].nWidth >= 0 )
+                widths.Add(m_panes[i].nWidth);
             else
             {
-                int nVarWidth = widthExtra > 0 ? (widthExtra * -m_statusWidths[i]) / nVarCount : 0;
-                nVarCount += m_statusWidths[i];
+                int nVarWidth = widthExtra > 0 ? (widthExtra * (-m_panes[i].nWidth)) / nVarCount : 0;
+                nVarCount += m_panes[i].nWidth;
                 widthExtra -= nVarWidth;
                 widths.Add(nVarWidth);
             }
@@ -283,86 +191,25 @@ wxArrayInt wxStatusBarBase::CalculateAbsWidths(wxCoord widthTotal) const
 }
 
 // ----------------------------------------------------------------------------
-// text stacks handling
-// ----------------------------------------------------------------------------
-
-void wxStatusBarBase::InitStacks()
-{
-    m_statusTextStacks = NULL;
-}
-
-void wxStatusBarBase::FreeStacks()
-{
-    if ( !m_statusTextStacks )
-        return;
-
-    for ( size_t i = 0; i < (size_t)m_nFields; ++i )
-    {
-        if ( m_statusTextStacks[i] )
-        {
-            wxListString& t = *m_statusTextStacks[i];
-            WX_CLEAR_LIST(wxListString, t);
-            delete m_statusTextStacks[i];
-        }
-    }
-
-    delete[] m_statusTextStacks;
-}
-
-// ----------------------------------------------------------------------------
-// text stacks
+// status text stacks
 // ----------------------------------------------------------------------------
 
 void wxStatusBarBase::PushStatusText(const wxString& text, int number)
 {
-    wxListString* st = GetOrCreateStatusStack(number);
-    // This long-winded way around avoids an internal compiler error
-    // in VC++ 6 with RTTI enabled
-    wxString tmp1(GetStatusText(number));
-    wxString* tmp = new wxString(tmp1);
-    st->Insert(tmp);
+    // save current status text in the stack
+    m_panes[number].arrStack.push_back(GetStatusText(number));
+
+    // update current status text
     SetStatusText(text, number);
 }
 
 void wxStatusBarBase::PopStatusText(int number)
 {
-    wxListString *st = GetStatusStack(number);
-    wxCHECK_RET( st, _T("Unbalanced PushStatusText/PopStatusText") );
-    wxListString::compatibility_iterator top = st->GetFirst();
-
-    SetStatusText(*top->GetData(), number);
-    delete top->GetData();
-    st->Erase(top);
-    if(st->GetCount() == 0)
-    {
-        delete st;
-        m_statusTextStacks[number] = 0;
-    }
-}
-
-wxListString *wxStatusBarBase::GetStatusStack(int i) const
-{
-    if(!m_statusTextStacks)
-        return 0;
-    return m_statusTextStacks[i];
-}
-
-wxListString *wxStatusBarBase::GetOrCreateStatusStack(int i)
-{
-    if(!m_statusTextStacks)
-    {
-        m_statusTextStacks = new wxListString*[m_nFields];
+    wxString text = m_panes[number].arrStack.back();
+    m_panes[number].arrStack.pop_back();  // also remove it from the stack
 
-        size_t j;
-        for(j = 0; j < (size_t)m_nFields; ++j) m_statusTextStacks[j] = 0;
-    }
-
-    if(!m_statusTextStacks[i])
-    {
-        m_statusTextStacks[i] = new wxListString();
-    }
-
-    return m_statusTextStacks[i];
+    // restore the popped status text in the pane
+    SetStatusText(text, number);
 }
 
 #endif // wxUSE_STATUSBAR
index 7e9e7791ff67582fd845ec2b14eeb388e01bd5b6..72ac77fdcc386da943a1ce83a481878aaef3bf1e 100644 (file)
     IMPLEMENT_DYNAMIC_CLASS(wxStatusBarGeneric, wxWindow)
 #endif // wxUSE_NATIVE_STATUSBAR
 
+// Default status border dimensions
+#define wxTHICK_LINE_BORDER 2
+
+
+// ----------------------------------------------------------------------------
+// wxStatusBarGeneric
+// ----------------------------------------------------------------------------
+
 BEGIN_EVENT_TABLE(wxStatusBarGeneric, wxWindow)
     EVT_PAINT(wxStatusBarGeneric::OnPaint)
     EVT_LEFT_DOWN(wxStatusBarGeneric::OnLeftDown)
@@ -48,9 +56,6 @@ BEGIN_EVENT_TABLE(wxStatusBarGeneric, wxWindow)
     EVT_SYS_COLOUR_CHANGED(wxStatusBarGeneric::OnSysColourChanged)
 END_EVENT_TABLE()
 
-// Default status border dimensions
-#define         wxTHICK_LINE_BORDER 2
-
 void wxStatusBarGeneric::Init()
 {
     m_borderX = wxTHICK_LINE_BORDER;
@@ -98,7 +103,6 @@ bool wxStatusBarGeneric::Create(wxWindow *parent,
     return true;
 }
 
-
 wxSize wxStatusBarGeneric::DoGetBestSize() const
 {
     int width, height;
@@ -120,25 +124,26 @@ void wxStatusBarGeneric::SetFieldsCount(int number, const int *widths)
 {
     wxASSERT_MSG( number >= 0, _T("negative number of fields in wxStatusBar?") );
 
-    int i;
-    for(i = m_nFields; i < number; ++i)
+    // enlarge the m_statusStrings array if needed:
+    for (size_t i = m_panes.GetCount(); i < (size_t)number; ++i)
         m_statusStrings.Add( wxEmptyString );
 
-    for (i = m_nFields - 1; i >= number; --i)
-        m_statusStrings.RemoveAt(i);
+    // shrink the m_statusStrings array if needed:
+    for (int j = (int)m_panes.GetCount() - 1; j >= number; --j)
+        m_statusStrings.RemoveAt(j);
 
     // forget the old cached pixel widths
     m_widthsAbs.Empty();
 
     wxStatusBarBase::SetFieldsCount(number, widths);
 
-    wxASSERT_MSG( m_nFields == (int)m_statusStrings.GetCount(),
-                  _T("This really should never happen, can we do away with m_nFields here?") );
+    wxASSERT_MSG( m_panes.GetCount() == m_statusStrings.GetCount(),
+                  _T("This really should never happen, can we do away with m_panes.GetCount() here?") );
 }
 
 void wxStatusBarGeneric::SetStatusText(const wxString& text, int number)
 {
-    wxCHECK_RET( (number >= 0) && (number < m_nFields),
+    wxCHECK_RET( (number >= 0) && ((size_t)number < m_panes.GetCount()),
                  _T("invalid status bar field index") );
 
     wxString oldText = m_statusStrings[number];
@@ -160,7 +165,7 @@ void wxStatusBarGeneric::SetStatusText(const wxString& text, int number)
 
 wxString wxStatusBarGeneric::GetStatusText(int n) const
 {
-    wxCHECK_MSG( (n >= 0) && (n < m_nFields), wxEmptyString,
+    wxCHECK_MSG( (n >= 0) && ((size_t)n < m_panes.GetCount()), wxEmptyString,
                  _T("invalid status bar field index") );
 
     return m_statusStrings[n];
@@ -168,14 +173,16 @@ wxString wxStatusBarGeneric::GetStatusText(int n) const
 
 void wxStatusBarGeneric::SetStatusWidths(int n, const int widths_field[])
 {
-    // only set status widths, when n == number of statuswindows
-    wxCHECK_RET( n == m_nFields, _T("status bar field count mismatch") );
+    // only set status widths when n == number of statuswindows
+    wxCHECK_RET( (size_t)n == m_panes.GetCount(), _T("status bar field count mismatch") );
 
     // delete the old widths in any case - this function may be used to reset
     // the widths to the default (all equal)
     // MBN: this is incompatible with at least wxMSW and wxMAC and not
     //      documented, but let's keep it for now
-    ReinitWidths();
+    m_bSameWidthForAllPanes = true;
+    // FM: what MBN's comment is saying is that allowing widths_field = NULL
+    //     only for wxStatusBarGeneric is not documented...
 
     // forget the old cached pixel widths
     m_widthsAbs.Empty();
@@ -241,7 +248,7 @@ void wxStatusBarGeneric::OnPaint(wxPaintEvent& WXUNUSED(event) )
 
     dc.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT);
 
-    for (int i = 0; i < m_nFields; i ++)
+    for (size_t i = 0; i < m_panes.GetCount(); i ++)
         DrawField(dc, i);
 }
 
@@ -278,10 +285,7 @@ void wxStatusBarGeneric::DrawField(wxDC& dc, int i)
     wxRect rect;
     GetFieldRect(i, rect);
 
-    int style = wxSB_NORMAL;
-    if (m_statusStyles)
-        style = m_statusStyles[i];
-
+    int style = m_panes[i].nStyle;
     if (style != wxSB_FLAT)
     {
         // Draw border
@@ -331,7 +335,7 @@ void wxStatusBarGeneric::DrawField(wxDC& dc, int i)
   // Get the position and size of the field's internal bounding rectangle
 bool wxStatusBarGeneric::GetFieldRect(int n, wxRect& rect) const
 {
-    wxCHECK_MSG( (n >= 0) && (n < m_nFields), false,
+    wxCHECK_MSG( (n >= 0) && ((size_t)n < m_panes.GetCount()), false,
                  _T("invalid status bar field index") );
 
     // FIXME: workarounds for OS/2 bugs have nothing to do here (VZ)
index 4baebc470bd894a3cde7004c93d51a0ee303d343..a913d193089804d59a88c1a426867ec21591334c 100644 (file)
@@ -161,7 +161,7 @@ void wxStatusBar::SetStatusWidths(int n, const int widths[])
 
 void wxStatusBar::SetFieldsWidth()
 {
-    if ( !m_nFields )
+    if ( m_panes.IsEmpty() )
         return;
 
     int aBorders[3];
@@ -170,17 +170,17 @@ void wxStatusBar::SetFieldsWidth()
     int extraWidth = aBorders[2]; // space between fields
 
     wxArrayInt widthsAbs =
-        CalculateAbsWidths(GetClientSize().x - extraWidth*(m_nFields - 1));
+        CalculateAbsWidths(GetClientSize().x - extraWidth*(m_panes.GetCount() - 1));
 
-    int *pWidths = new int[m_nFields];
+    int *pWidths = new int[m_panes.GetCount()];
 
     int nCurPos = 0;
-    for ( int i = 0; i < m_nFields; i++ ) {
+    for ( int i = 0; i < m_panes.GetCount(); i++ ) {
         nCurPos += widthsAbs[i] + extraWidth;
         pWidths[i] = nCurPos;
     }
 
-    if ( !StatusBar_SetParts(GetHwnd(), m_nFields, pWidths) ) {
+    if ( !StatusBar_SetParts(GetHwnd(), m_panes.GetCount(), pWidths) ) {
         wxLogLastError(wxT("StatusBar_SetParts"));
     }
 
@@ -200,24 +200,20 @@ void wxStatusBar::SetStatusText(const wxString& strText, int nField)
 
     // Get field style, if any
     int style;
-    if (m_statusStyles)
+    switch(m_panes[nField].nStyle)
     {
-        switch(m_statusStyles[nField])
-        {
-        case wxSB_RAISED:
-            style = SBT_POPOUT;
-            break;
-        case wxSB_FLAT:
-            style = SBT_NOBORDERS;
-            break;
-        case wxSB_NORMAL:
-        default:
-            style = 0;
-            break;
-        }
-    }
-    else
+    case wxSB_RAISED:
+        style = SBT_POPOUT;
+        break;
+    case wxSB_FLAT:
+        style = SBT_NOBORDERS;
+        break;
+
+    case wxSB_NORMAL:
+    default:
         style = 0;
+        break;
+    }
 
     // Pass both field number and style. MSDN library doesn't mention
     // that nField and style have to be 'ORed'
@@ -229,7 +225,7 @@ void wxStatusBar::SetStatusText(const wxString& strText, int nField)
 
 wxString wxStatusBar::GetStatusText(int nField) const
 {
-    wxCHECK_MSG( (nField >= 0) && (nField < m_nFields), wxEmptyString,
+    wxCHECK_MSG( (nField >= 0) && (nField < m_panes.GetCount()), wxEmptyString,
                  _T("invalid statusbar field index") );
 
     wxString str;
@@ -268,7 +264,7 @@ void wxStatusBar::SetMinHeight(int height)
 
 bool wxStatusBar::GetFieldRect(int i, wxRect& rect) const
 {
-    wxCHECK_MSG( (i >= 0) && (i < m_nFields), false,
+    wxCHECK_MSG( (i >= 0) && (i < m_panes.GetCount()), false,
                  _T("invalid statusbar field index") );
 
     RECT r;
@@ -309,10 +305,10 @@ wxSize wxStatusBar::DoGetBestSize() const
 
     // calculate width
     int width = 0;
-    for ( int i = 0; i < m_nFields; ++i )
+    for ( int i = 0; i < m_panes.GetCount(); ++i )
     {
-        int widthField = m_statusWidths ? m_statusWidths[i]
-                                        : DEFAULT_FIELD_WIDTH;
+        int widthField =
+            m_bSameWidthForAllPanes ? DEFAULT_FIELD_WIDTH : m_panes[i].nWidth;
         if ( widthField >= 0 )
         {
             width += widthField;
@@ -384,7 +380,7 @@ void wxStatusBar::SetStatusStyles(int n, const int styles[])
 {
     wxStatusBarBase::SetStatusStyles(n, styles);
 
-    if (n != m_nFields)
+    if (n != m_panes.GetCount())
         return;
 
     for (int i = 0; i < n; i++)
index dff7641652bb674c98a1d5926e30f4e459154532..d16703f43f477299a5f6ed6f845c4f5a4ac3a618 100644 (file)
@@ -103,7 +103,7 @@ void wxStatusBarMac::DrawField(wxDC& dc, int i)
 
 void wxStatusBarMac::SetStatusText(const wxString& text, int number)
 {
-    wxCHECK_RET( (number >= 0) && (number < m_nFields),
+    wxCHECK_RET( (number >= 0) && ((size_t)number < m_panes.GetCount()),
         wxT("invalid status bar field index") );
 
     if ( m_statusStrings[number] == text )
@@ -162,12 +162,11 @@ void wxStatusBarMac::OnPaint(wxPaintEvent& WXUNUSED(event))
         dc.DrawLine(0, 0, w, 0);
     }
 
-    int i;
     if ( GetFont().Ok() )
         dc.SetFont(GetFont());
     dc.SetBackgroundMode(wxTRANSPARENT);
 
-    for ( i = 0; i < m_nFields; i ++ )
+    for ( size_t i = 0; i < m_panes.GetCount(); i ++ )
         DrawField(dc, i);
 }
 
index 8c817a5ab3cd381d28a787872807a72a393671ab..071237016be9e960520980fd5a444cac97c33ee4 100644 (file)
@@ -96,7 +96,7 @@ wxRect wxStatusBarUniv::GetTotalFieldRect(wxCoord *borderBetweenFields)
         // the total width for the fields doesn't include the borders between
         // them
         m_widthsAbs = CalculateAbsWidths(rect.width -
-                                         *borderBetweenFields*(m_nFields - 1));
+                                         *borderBetweenFields*(m_panes.GetCount() - 1));
     }
 
     return rect;
@@ -115,7 +115,7 @@ void wxStatusBarUniv::DoDraw(wxControlRenderer *renderer)
 
     // do draw the fields
     int flags = IsEnabled() ? 0 : (int)wxCONTROL_DISABLED;
-    for ( int n = 0; n < m_nFields; n++ )
+    for ( int n = 0; n < (int)m_panes.GetCount(); n++ )
     {
         rect.width = m_widthsAbs[n];
 
@@ -126,7 +126,7 @@ void wxStatusBarUniv::DoDraw(wxControlRenderer *renderer)
             // the size grip may be drawn only on the last field and only if we
             // have the corresponding style and even then only if we really can
             // resize this frame
-            if ( n == m_nFields - 1 &&
+            if ( n == (int)m_panes.GetCount() - 1 &&
                  HasFlag(wxST_SIZEGRIP) &&
                  GetParent()->HasFlag(wxRESIZE_BORDER) &&
                  parentTLW && !parentTLW->IsMaximized() )
@@ -134,12 +134,7 @@ void wxStatusBarUniv::DoDraw(wxControlRenderer *renderer)
                 flags |= wxCONTROL_SIZEGRIP;
             }
 
-            int style;
-            if (m_statusStyles)
-                style = m_statusStyles[n];
-            else
-                style = wxSB_NORMAL;
-            m_renderer->DrawStatusField(dc, rect, m_statusText[n], flags, style);
+            m_renderer->DrawStatusField(dc, rect, m_statusText[n], flags, m_panes[n].nStyle);
         }
 
         rect.x += rect.width + borderBetweenFields;
@@ -161,7 +156,7 @@ void wxStatusBarUniv::RefreshField(int i)
 
 void wxStatusBarUniv::SetStatusText(const wxString& text, int number)
 {
-    wxCHECK_RET( number >= 0 && number < m_nFields,
+    wxCHECK_RET( number >= 0 && (size_t)number < m_panes.GetCount(),
                  _T("invalid status bar field index in SetStatusText()") );
 
     if ( text == m_statusText[number] )
@@ -177,7 +172,7 @@ void wxStatusBarUniv::SetStatusText(const wxString& text, int number)
 
 wxString wxStatusBarUniv::GetStatusText(int number) const
 {
-    wxCHECK_MSG( number >= 0 && number < m_nFields, wxEmptyString,
+    wxCHECK_MSG( number >= 0 && (size_t)number < m_panes.GetCount(), wxEmptyString,
                  _T("invalid status bar field index") );
 
     return m_statusText[number];
@@ -191,6 +186,7 @@ void wxStatusBarUniv::SetFieldsCount(int number, const int *widths)
 {
     m_statusText.SetCount(number);
     wxStatusBarBase::SetFieldsCount(number, widths);
+
     m_widthsAbs.Empty();
 }
 
@@ -209,25 +205,25 @@ void wxStatusBarUniv::OnSize(wxSizeEvent& event)
 {
     // we don't need to refresh the fields whose width didn't change, so find
     // the first field whose width did change and refresh starting from it
-    int field;
-    if ( m_statusWidths )
+    size_t field;
+    if ( m_bSameWidthForAllPanes )
+    {
+        // hence all fields widths have changed
+        field = 0;
+    }
+    else
     {
-        for ( field = 0; field < m_nFields; field++ )
+        for ( field = 0; field < m_panes.GetCount(); field++ )
         {
-            if ( m_statusWidths[field] < 0 )
+            if ( m_panes[field].nWidth < 0 )
             {
                 // var width field
                 break;
             }
         }
     }
-    else // all fields have the same width
-    {
-        // hence all fields widths have changed
-        field = 0;
-    }
 
-    if ( field < m_nFields )
+    if ( field < m_panes.GetCount() )
     {
         // call this before invalidating the old widths as we want to use them,
         // not the new ones
@@ -248,7 +244,7 @@ void wxStatusBarUniv::OnSize(wxSizeEvent& event)
 
 bool wxStatusBarUniv::GetFieldRect(int n, wxRect& rect) const
 {
-    wxCHECK_MSG( n >= 0 && n < m_nFields, false,
+    wxCHECK_MSG( n >= 0 && (size_t)n < m_panes.GetCount(), false,
                  _T("invalid field index in GetFieldRect()") );
 
     // this is a fix for a bug exhibited by the statbar sample: if