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; }
// 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
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;
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);
// 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);
}
// ----------------------------------------------------------------------------
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);
{
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() )
{
void wxListBox::DoClear()
{
- m_strings->Clear();
+ if ( IsSorted() )
+ m_strings.sorted->Clear();
+ else
+ m_strings.unsorted->Clear();
m_itemsClientData.Clear();
m_selections.Clear();
// 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);
wxCoord lineHeight = GetLineHeight();
unsigned int itemFirst = yTop / lineHeight,
itemLast = (yBottom + lineHeight - 1) / lineHeight,
- itemMax = m_strings->GetCount();
+ itemMax = GetCount();
if ( itemFirst >= itemMax )
return;
{
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);
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;