style |= wxBORDER_SUNKEN;
#endif
- if ( !wxControl::Create(parent, id, pos, size, style,
+ if ( !wxControl::Create(parent, id, pos, size, style,
validator, name) )
return false;
SetWindow(this);
- if ( style & wxLB_SORT )
- m_stringsSorted = new wxSortedArrayString;
- else
- m_strings = new wxArrayString;
+ m_strings = new wxArrayString;
Set(n, choices);
// call this just to free the client data -- and avoid leaking memory
DoClear();
- if ( IsSorted() )
- delete m_stringsSorted;
- else
- delete m_strings;
+ delete m_strings;
m_strings = NULL;
}
// 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() )
{
- index = m_stringsSorted->Add(item);
+ m_strings->Add(item);
+ m_strings->Sort(wxListBoxSortNoCase);
+ index = m_strings->Index(item);
}
else
{
m_strings->Add(item);
}
+ return index;
+}
+
+int wxListBox::DoAppend(const wxString& item)
+{
+ size_t index = DoAppendOnly( item );
+
m_itemsClientData.Insert(NULL, index);
m_updateScrollbarY = true;
return;
m_strings->Alloc(count);
+
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);
}
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;
- (*m_strings)[n] = s;
+
GetTextExtent(s, &width, NULL);
// it might have increased if the new string is long
RefreshHorzScrollbar();
}
}
- else // no horz scrollbar
- {
- (*m_strings)[n] = s;
- }
RefreshItem(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;
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;
event.SetString(GetString(item));
}
- event.m_commandInt = item;
+ event.SetInt(item);
return GetEventHandler()->ProcessEvent(event);
}
// 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 )
{
SetCurrentItem(item);
break;
default:
- if ( (keycode < 255) && wxIsalnum(keycode) )
+ if ( (keycode < 255) && wxIsalnum((wxChar)keycode) )
{
action = wxACTION_LISTBOX_FIND;
strArg = (wxChar)keycode;