From 6f34862c6a06cf588afa8c0d095f38f3fb085a62 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 30 Nov 2007 14:16:11 +0000 Subject: [PATCH] build fixes for wxUSE_STL==1 git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@50349 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/univ/listbox.h | 15 +++++----- src/univ/listbox.cpp | 61 +++++++++++++++++++++++++++++++-------- 2 files changed, 57 insertions(+), 19 deletions(-) diff --git a/include/wx/univ/listbox.h b/include/wx/univ/listbox.h index 47fd5a69ac..41d2b7df56 100644 --- a/include/wx/univ/listbox.h +++ b/include/wx/univ/listbox.h @@ -99,13 +99,10 @@ public: virtual void DoClear(); virtual void DoDeleteOneItem(unsigned int n); - virtual unsigned int GetCount() const - { return (unsigned int)m_strings->GetCount(); } - virtual wxString GetString(unsigned int n) const - { return m_strings->Item(n); } + virtual unsigned int GetCount() const; + virtual wxString GetString(unsigned int n) const; virtual void SetString(unsigned int n, const wxString& s); - virtual int FindString(const wxString& s, bool bCase = false) const - { return m_strings->Index(s, bCase); } + virtual int FindString(const wxString& s, bool bCase = false) const; virtual bool IsSelected(int n) const { return m_selections.Index(n) != wxNOT_FOUND; } @@ -249,7 +246,11 @@ protected: // the array containing all items (it is sorted if the listbox has // wxLB_SORT style) - wxArrayString* m_strings; + union + { + wxArrayString *unsorted; + wxSortedArrayString *sorted; + } m_strings; // this array contains the indices of the selected items (for the single // selection listboxes only the first element of it is used and contains diff --git a/src/univ/listbox.cpp b/src/univ/listbox.cpp index 0255489bce..8297decc68 100644 --- a/src/univ/listbox.cpp +++ b/src/univ/listbox.cpp @@ -115,7 +115,7 @@ void wxListBox::Init() m_maxWidth = 0; m_scrollRangeY = 0; m_maxWidthItem = -1; - m_strings = NULL; + m_strings.unsorted = NULL; // no items hence no current item m_current = -1; @@ -192,7 +192,10 @@ bool wxListBox::Create(wxWindow *parent, validator, name) ) return false; - m_strings = IsSorted() ? new wxSortedArrayString : new wxArrayString; + if ( IsSorted() ) + m_strings.sorted = new wxSortedArrayString; + else + m_strings.unsorted = new wxArrayString; Set(n, choices); @@ -208,9 +211,34 @@ wxListBox::~wxListBox() // call this just to free the client data -- and avoid leaking memory DoClear(); - delete m_strings; + if ( IsSorted() ) + delete m_strings.sorted; + else + delete m_strings.unsorted; + + m_strings.sorted = NULL; +} + +// ---------------------------------------------------------------------------- +// accessing strings +// ---------------------------------------------------------------------------- + +unsigned int wxListBox::GetCount() const +{ + return IsSorted() ? m_strings.sorted->size() + : m_strings.unsorted->size(); +} + +wxString wxListBox::GetString(unsigned int n) const +{ + return IsSorted() ? m_strings.sorted->Item(n) + : m_strings.unsorted->Item(n); +} - m_strings = NULL; +int wxListBox::FindString(const wxString& s, bool bCase) const +{ + return IsSorted() ? m_strings.sorted->Index(s, bCase) + : m_strings.unsorted->Index(s, bCase); } // ---------------------------------------------------------------------------- @@ -228,8 +256,8 @@ int wxListBox::DoInsertItems(const wxArrayStringsAdapter& items, for ( unsigned int i = 0; i < numItems; ++i ) { const wxString& item = items[i]; - idx = IsSorted() ? m_strings->Add(item) - : (m_strings->Insert(item, pos), pos++); + idx = IsSorted() ? m_strings.sorted->Add(item) + : (m_strings.unsorted->Insert(item, pos), pos++); m_itemsClientData.Insert(NULL, idx); AssignNewItemClientData(idx, clientData, i, type); @@ -257,7 +285,10 @@ void wxListBox::SetString(unsigned int n, const wxString& s) { wxCHECK_RET( !IsSorted(), _T("can't set string in sorted listbox") ); - (*m_strings)[n] = s; + if ( IsSorted() ) + (*m_strings.sorted)[n] = s; + else + (*m_strings.unsorted)[n] = s; if ( HasHorzScrollbar() ) { @@ -290,7 +321,10 @@ void wxListBox::SetString(unsigned int n, const wxString& s) void wxListBox::DoClear() { - m_strings->Clear(); + if ( IsSorted() ) + m_strings.sorted->Clear(); + else + m_strings.unsorted->Clear(); m_itemsClientData.Clear(); m_selections.Clear(); @@ -313,7 +347,10 @@ void wxListBox::DoDeleteOneItem(unsigned int n) // refreshed (as GetCount() will be decremented) RefreshFromItemToEnd(n); - m_strings->RemoveAt(n); + if ( IsSorted() ) + m_strings.sorted->RemoveAt(n); + else + m_strings.unsorted->RemoveAt(n); m_itemsClientData.RemoveAt(n); @@ -680,7 +717,7 @@ void wxListBox::DoDraw(wxControlRenderer *renderer) wxCoord lineHeight = GetLineHeight(); unsigned int itemFirst = yTop / lineHeight, itemLast = (yBottom + lineHeight - 1) / lineHeight, - itemMax = m_strings->GetCount(); + itemMax = GetCount(); if ( itemFirst >= itemMax ) return; @@ -749,7 +786,7 @@ wxCoord wxListBox::GetMaxWidth() const { wxListBox *self = wxConstCast(this, wxListBox); wxCoord width; - unsigned int count = m_strings->GetCount(); + unsigned int count = GetCount(); for ( unsigned int n = 0; n < count; n++ ) { GetTextExtent(this->GetString(n), &width, NULL); @@ -806,7 +843,7 @@ wxSize wxListBox::DoGetBestClientSize() const wxCoord width = 0, height = 0; - unsigned int count = m_strings->GetCount(); + unsigned int count = GetCount(); for ( unsigned int n = 0; n < count; n++ ) { wxCoord w,h; -- 2.45.2