git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@30652
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
- wxBU_... button align flags support
- vertical notebook orientation support
- 3rd state support for checkboxes
- wxBU_... button align flags support
- vertical notebook orientation support
- 3rd state support for checkboxes
+- wxLB_SORT and wxCB_SORT now cause case-insensitive sorting
virtual void Clear();
virtual void Delete(int n);
virtual void Clear();
virtual void Delete(int n);
- virtual int GetCount() const { return (int)m_strings->GetCount(); }
- virtual wxString GetString(int n) const { return (*m_strings)[n]; }
+ virtual int GetCount() const
+ { return (int)m_strings->GetCount(); }
+ virtual wxString GetString(int n) const
+ { return m_strings->Item(n); }
virtual void SetString(int n, const wxString& s);
virtual int FindString(const wxString& s) const
virtual void SetString(int n, const wxString& s);
virtual int FindString(const wxString& s) const
- { return IsSorted() ? m_stringsSorted->Index(s) : m_strings->Index(s); }
+ { return m_strings->Index(s); }
virtual bool IsSelected(int n) const
{ return m_selections.Index(n) != wxNOT_FOUND; }
virtual bool IsSelected(int n) const
{ return m_selections.Index(n) != wxNOT_FOUND; }
virtual int GetSelections(wxArrayInt& aSelections) const;
protected:
virtual int GetSelections(wxArrayInt& aSelections) const;
protected:
+ virtual int DoAppendOnly(const wxString& item);
virtual int DoAppend(const wxString& item);
virtual void DoInsertItems(const wxArrayString& items, int pos);
virtual void DoSetItems(const wxArrayString& items, void **clientData);
virtual int DoAppend(const wxString& item);
virtual void DoInsertItems(const wxArrayString& items, int pos);
virtual void DoSetItems(const wxArrayString& items, void **clientData);
void UpdateItems();
// the array containing all items (it is sorted if the listbox has
void UpdateItems();
// the array containing all items (it is sorted if the listbox has
- // wxLB_SORT style). Note the evil trick: the pointers share the
- // same location, hence we use m_strings when we don't care if the
- // array is sorted or not, m_stringsSorted when we do
- union
- {
- wxArrayString* m_strings;
- wxSortedArrayString* m_stringsSorted;
- };
+ // wxLB_SORT style)
+ wxArrayString* 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
// this array contains the indices of the selected items (for the single
// selection listboxes only the first element of it is used and contains
- if ( style & wxLB_SORT )
- m_stringsSorted = new wxSortedArrayString;
- else
- m_strings = new wxArrayString;
+ m_strings = new wxArrayString;
// call this just to free the client data -- and avoid leaking memory
DoClear();
// call this just to free the client data -- and avoid leaking memory
DoClear();
- if ( IsSorted() )
- delete m_stringsSorted;
- else
- delete m_strings;
// adding/inserting strings
// ----------------------------------------------------------------------------
// adding/inserting strings
// ----------------------------------------------------------------------------
-int wxListBox::DoAppend(const wxString& item)
+int wxCMPFUNC_CONV wxListBoxSortNoCase(wxString* s1, wxString* s2)
+{
+ return s1->CmpNoCase(*s2);
+}
+
+int wxListBox::DoAppendOnly(const wxString& item)
{
size_t index;
if ( IsSorted() )
{
{
size_t index;
if ( IsSorted() )
{
- index = m_stringsSorted->Add(item);
+ m_strings->Add(item);
+ m_strings->Sort(wxListBoxSortNoCase);
+ index = m_strings->Index(item);
+ return index;
+}
+
+int wxListBox::DoAppend(const wxString& item)
+{
+ size_t index = DoAppendOnly( item );
+
m_itemsClientData.Insert(NULL, index);
m_updateScrollbarY = true;
m_itemsClientData.Insert(NULL, index);
m_updateScrollbarY = true;
return;
m_strings->Alloc(count);
return;
m_strings->Alloc(count);
m_itemsClientData.Alloc(count);
for ( size_t n = 0; n < count; n++ )
{
m_itemsClientData.Alloc(count);
for ( size_t n = 0; n < count; n++ )
{
- size_t index;
-
- if ( IsSorted() )
- {
- index = m_stringsSorted->Add(items[n]);
- }
- else
- {
- index = m_strings->GetCount();
- m_strings->Add(items[n]);
- }
+ size_t index = DoAppendOnly(items[n]);
m_itemsClientData.Insert(clientData ? clientData[n] : NULL, index);
}
m_itemsClientData.Insert(clientData ? clientData[n] : NULL, index);
}
void wxListBox::SetString(int n, const wxString& s)
{
void wxListBox::SetString(int n, const wxString& s)
{
+ wxCHECK_RET( !IsSorted(), _T("can't set string in sorted listbox") );
+
+ (*m_strings)[n] = s;
+
if ( HasHorzScrollbar() )
{
// we need to update m_maxWidth as changing the string may cause the
// horz scrollbar [dis]appear
wxCoord width;
if ( HasHorzScrollbar() )
{
// we need to update m_maxWidth as changing the string may cause the
// horz scrollbar [dis]appear
wxCoord width;
GetTextExtent(s, &width, NULL);
// it might have increased if the new string is long
GetTextExtent(s, &width, NULL);
// it might have increased if the new string is long
RefreshHorzScrollbar();
}
}
RefreshHorzScrollbar();
}
}
- else // no horz scrollbar
- {
- (*m_strings)[n] = s;
- }
size_t count = m_strings->GetCount();
for ( size_t n = 0; n < count; n++ )
{
size_t count = m_strings->GetCount();
for ( size_t n = 0; n < count; n++ )
{
- GetTextExtent((*m_strings)[n], &width, NULL);
+ GetTextExtent(this->GetString(n), &width, NULL);
if ( width > m_maxWidth )
{
self->m_maxWidth = width;
if ( width > m_maxWidth )
{
self->m_maxWidth = width;
for ( size_t n = 0; n < count; n++ )
{
wxCoord w,h;
for ( size_t n = 0; n < count; n++ )
{
wxCoord w,h;
- GetTextExtent((*m_strings)[n], &w, &h);
+ GetTextExtent(this->GetString(n), &w, &h);
if ( w > width )
width = w;
if ( w > width )
width = w;
// loop over all items in the listbox
for ( int item = first; item != last; item < count - 1 ? item++ : item = 0 )
{
// loop over all items in the listbox
for ( int item = first; item != last; item < count - 1 ? item++ : item = 0 )
{
- if ( wxStrnicmp((*m_strings)[item], prefix, len) == 0 )
+ if ( wxStrnicmp(this->GetString(item).c_str(), prefix, len) == 0 )