many wxItemContainer-related changes:
1. the main function for item insertion is now DoInsertItems() which allows for much more efficient addition of many new items at once 2. the items client data management is done entirely in wxItemContainer itself, the derived classes don't have to distinguish between void and object client data 3. many fixes for sorted controls, in particular implemented wxCB_SORT support in wxGTK combobox git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@47730 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -211,63 +211,56 @@ WXDWORD wxChoice::MSWGetStyle(long style, WXDWORD *exstyle) const
|
||||
|
||||
wxChoice::~wxChoice()
|
||||
{
|
||||
Free();
|
||||
Clear();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// adding/deleting items to/from the list
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
int wxChoice::DoAppend(const wxString& item)
|
||||
int wxChoice::DoInsertItems(const wxArrayStringsAdapter& items,
|
||||
unsigned int pos,
|
||||
void **clientData, wxClientDataType type)
|
||||
{
|
||||
int n = (int)SendMessage(GetHwnd(), CB_ADDSTRING, 0,
|
||||
(LPARAM)item.wx_str());
|
||||
if ( n == CB_ERR )
|
||||
MSWAllocStorage(items, CB_INITSTORAGE);
|
||||
|
||||
const bool append = pos == GetCount();
|
||||
|
||||
// use CB_ADDSTRING when appending at the end to make sure the control is
|
||||
// resorted if it has wxCB_SORT style
|
||||
const unsigned msg = append ? CB_ADDSTRING : CB_INSERTSTRING;
|
||||
|
||||
if ( append )
|
||||
pos = 0;
|
||||
|
||||
int n = wxNOT_FOUND;
|
||||
const unsigned numItems = items.GetCount();
|
||||
for ( unsigned i = 0; i < numItems; ++i )
|
||||
{
|
||||
wxLogLastError(wxT("SendMessage(CB_ADDSTRING)"));
|
||||
}
|
||||
else // ok
|
||||
{
|
||||
// we need to refresh our size in order to have enough space for the
|
||||
// newly added items
|
||||
if ( !IsFrozen() )
|
||||
UpdateVisibleHeight();
|
||||
n = MSWInsertOrAppendItem(pos, items[i], msg);
|
||||
if ( n == wxNOT_FOUND )
|
||||
return n;
|
||||
|
||||
if ( !append )
|
||||
pos++;
|
||||
|
||||
AssignNewItemClientData(n, clientData, i, type);
|
||||
}
|
||||
|
||||
// we need to refresh our size in order to have enough space for the
|
||||
// newly added items
|
||||
if ( !IsFrozen() )
|
||||
UpdateVisibleHeight();
|
||||
|
||||
InvalidateBestSize();
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
int wxChoice::DoInsert(const wxString& item, unsigned int pos)
|
||||
{
|
||||
wxCHECK_MSG(!(GetWindowStyle() & wxCB_SORT), -1, wxT("can't insert into sorted list"));
|
||||
wxCHECK_MSG(IsValidInsert(pos), -1, wxT("invalid index"));
|
||||
|
||||
int n = (int)SendMessage(GetHwnd(), CB_INSERTSTRING, pos,
|
||||
(LPARAM)item.wx_str());
|
||||
if ( n == CB_ERR )
|
||||
{
|
||||
wxLogLastError(wxT("SendMessage(CB_INSERTSTRING)"));
|
||||
}
|
||||
else // ok
|
||||
{
|
||||
if ( !IsFrozen() )
|
||||
UpdateVisibleHeight();
|
||||
}
|
||||
|
||||
InvalidateBestSize();
|
||||
return n;
|
||||
}
|
||||
|
||||
void wxChoice::Delete(unsigned int n)
|
||||
void wxChoice::DoDeleteOneItem(unsigned int n)
|
||||
{
|
||||
wxCHECK_RET( IsValid(n), wxT("invalid item index in wxChoice::Delete") );
|
||||
|
||||
if ( HasClientObjectData() )
|
||||
{
|
||||
delete GetClientObject(n);
|
||||
}
|
||||
|
||||
SendMessage(GetHwnd(), CB_DELETESTRING, n, 0);
|
||||
|
||||
if ( !IsFrozen() )
|
||||
@@ -276,10 +269,8 @@ void wxChoice::Delete(unsigned int n)
|
||||
InvalidateBestSize();
|
||||
}
|
||||
|
||||
void wxChoice::Clear()
|
||||
void wxChoice::DoClear()
|
||||
{
|
||||
Free();
|
||||
|
||||
SendMessage(GetHwnd(), CB_RESETCONTENT, 0, 0);
|
||||
|
||||
if ( !IsFrozen() )
|
||||
@@ -288,18 +279,6 @@ void wxChoice::Clear()
|
||||
InvalidateBestSize();
|
||||
}
|
||||
|
||||
void wxChoice::Free()
|
||||
{
|
||||
if ( HasClientObjectData() )
|
||||
{
|
||||
unsigned int count = GetCount();
|
||||
for ( unsigned int n = 0; n < count; n++ )
|
||||
{
|
||||
delete GetClientObject(n);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// selection
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -456,16 +435,6 @@ void* wxChoice::DoGetItemClientData(unsigned int n) const
|
||||
return (void *)rc;
|
||||
}
|
||||
|
||||
void wxChoice::DoSetItemClientObject(unsigned int n, wxClientData* clientData)
|
||||
{
|
||||
DoSetItemClientData(n, clientData);
|
||||
}
|
||||
|
||||
wxClientData* wxChoice::DoGetItemClientObject(unsigned int n) const
|
||||
{
|
||||
return (wxClientData *)DoGetItemClientData(n);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxMSW specific helpers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
Reference in New Issue
Block a user