From 76880b8757589f0bc07e4b042b5b4ec6c5524af7 Mon Sep 17 00:00:00 2001 From: Ron Lee Date: Sun, 30 Jun 2002 23:53:58 +0000 Subject: [PATCH] Preserve prior StatusBar contents when adding removing fields (consistant with MSW behaviour). Made m_statusSring a wxArrayString, furthur simplification may be possible if someone is interested and has the time. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@15988 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/generic/statusbr.h | 4 +++- src/generic/statusbr.cpp | 39 ++++++++++++++++++++++------------- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/include/wx/generic/statusbr.h b/include/wx/generic/statusbr.h index 47a834f1c1..b0d27f3ca9 100644 --- a/include/wx/generic/statusbr.h +++ b/include/wx/generic/statusbr.h @@ -96,7 +96,7 @@ public: void OnSysColourChanged(wxSysColourChangedEvent& event); protected: - wxString * m_statusStrings; + wxArrayString m_statusStrings; int m_borderX; int m_borderY; wxFont m_defaultStatusBarFont; @@ -110,3 +110,5 @@ private: #endif // _WX_GENERIC_STATUSBR_H_ + +// vi:sts=4:sw=4:et diff --git a/src/generic/statusbr.cpp b/src/generic/statusbr.cpp index a7c9f6387c..51603177f5 100644 --- a/src/generic/statusbr.cpp +++ b/src/generic/statusbr.cpp @@ -53,7 +53,6 @@ END_EVENT_TABLE() wxStatusBarGeneric::wxStatusBarGeneric() { - m_statusStrings = (wxString *) NULL; m_borderX = wxTHICK_LINE_BORDER; m_borderY = wxTHICK_LINE_BORDER; } @@ -63,17 +62,17 @@ wxStatusBarGeneric::~wxStatusBarGeneric() # ifdef __WXMSW__ SetFont(wxNullFont); # endif // MSW - - if ( m_statusStrings ) - delete[] m_statusStrings; } bool wxStatusBarGeneric::Create(wxWindow *parent, - wxWindowID id, - long style, - const wxString& name) + wxWindowID id, + long style, + const wxString& name) { - m_statusStrings = (wxString *) NULL; + // If create is ever meant to be re-entrant over the life of + // an object we should: + // m_statusStrings.Empty(); + m_borderX = wxTHICK_LINE_BORDER; m_borderY = wxTHICK_LINE_BORDER; @@ -108,13 +107,23 @@ bool wxStatusBarGeneric::Create(wxWindow *parent, void wxStatusBarGeneric::SetFieldsCount(int number, const int *widths) { - if ( number != m_nFields ) - { - m_nFields = number; + wxASSERT_MSG( number >= 0, + _T("Yes, number should be a size_t and less than no fields is silly.") ); - delete[] m_statusStrings; - m_statusStrings = new wxString[number]; - } + // if( number > m_nFields ) + + for( int i = m_nFields; i < number; ++i ) + m_statusStrings.Add( wxEmptyString ); + + // if( number < m_nFields ) + + for (int i = m_nFields - 1; i >= number; --i) + m_statusStrings.Remove(i); + + m_nFields = number; + + wxASSERT_MSG( m_nFields == (int)m_statusStrings.GetCount(), + _T("This really should never happen, can we do away with m_nFields here?") ); SetStatusWidths(number, widths); } @@ -396,3 +405,5 @@ void wxStatusBarGeneric::SetMinHeight(int height) } #endif // wxUSE_STATUSBAR + +// vi:sts=4:sw=4:et -- 2.45.2