make Delete() work in presence of client data
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@24026 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -227,18 +227,49 @@ void wxChoice::Delete( int n )
|
|||||||
wxCHECK_RET( m_widget != NULL, wxT("invalid choice") );
|
wxCHECK_RET( m_widget != NULL, wxT("invalid choice") );
|
||||||
|
|
||||||
// VZ: apparently GTK+ doesn't have a built-in function to do it (not even
|
// VZ: apparently GTK+ doesn't have a built-in function to do it (not even
|
||||||
// in 2.0), hence this dump implementation - still better than nothing
|
// in 2.0), hence this dumb implementation -- still better than nothing
|
||||||
int i,
|
int i,
|
||||||
count = GetCount();
|
count = GetCount();
|
||||||
|
|
||||||
wxCHECK_RET( n >= 0 && n < count, _T("invalid index in wxChoice::Delete") );
|
wxCHECK_RET( n >= 0 && n < count, _T("invalid index in wxChoice::Delete") );
|
||||||
|
|
||||||
|
const bool hasClientData = m_clientDataItemsType != wxClientData_None;
|
||||||
|
const bool hasObjectData = m_clientDataItemsType == wxClientData_Object;
|
||||||
|
|
||||||
|
wxList::compatibility_iterator node = m_clientList.GetFirst();
|
||||||
|
|
||||||
wxArrayString items;
|
wxArrayString items;
|
||||||
|
wxArrayPtrVoid itemsData;
|
||||||
items.Alloc(count);
|
items.Alloc(count);
|
||||||
for ( i = 0; i < count; i++ )
|
for ( i = 0; i < count; i++ )
|
||||||
{
|
{
|
||||||
if ( i != n )
|
if ( i != n )
|
||||||
|
{
|
||||||
items.Add(GetString(i));
|
items.Add(GetString(i));
|
||||||
|
if ( hasClientData )
|
||||||
|
{
|
||||||
|
// also save the client data
|
||||||
|
itemsData.Add(node->GetData());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else // need to delete the client object too
|
||||||
|
{
|
||||||
|
if ( hasObjectData )
|
||||||
|
{
|
||||||
|
delete (wxClientData *)node->GetData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( hasClientData )
|
||||||
|
{
|
||||||
|
node = node->GetNext();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( hasObjectData )
|
||||||
|
{
|
||||||
|
// prevent Clear() from destroying all client data
|
||||||
|
m_clientDataItemsType = wxClientData_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
Clear();
|
Clear();
|
||||||
@@ -246,6 +277,11 @@ void wxChoice::Delete( int n )
|
|||||||
for ( i = 0; i < count - 1; i++ )
|
for ( i = 0; i < count - 1; i++ )
|
||||||
{
|
{
|
||||||
Append(items[i]);
|
Append(items[i]);
|
||||||
|
|
||||||
|
if ( hasObjectData )
|
||||||
|
SetClientObject(i, (wxClientData *)itemsData[i]);
|
||||||
|
else if ( hasClientData )
|
||||||
|
SetClientDate(i, itemsData[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -227,18 +227,49 @@ void wxChoice::Delete( int n )
|
|||||||
wxCHECK_RET( m_widget != NULL, wxT("invalid choice") );
|
wxCHECK_RET( m_widget != NULL, wxT("invalid choice") );
|
||||||
|
|
||||||
// VZ: apparently GTK+ doesn't have a built-in function to do it (not even
|
// VZ: apparently GTK+ doesn't have a built-in function to do it (not even
|
||||||
// in 2.0), hence this dump implementation - still better than nothing
|
// in 2.0), hence this dumb implementation -- still better than nothing
|
||||||
int i,
|
int i,
|
||||||
count = GetCount();
|
count = GetCount();
|
||||||
|
|
||||||
wxCHECK_RET( n >= 0 && n < count, _T("invalid index in wxChoice::Delete") );
|
wxCHECK_RET( n >= 0 && n < count, _T("invalid index in wxChoice::Delete") );
|
||||||
|
|
||||||
|
const bool hasClientData = m_clientDataItemsType != wxClientData_None;
|
||||||
|
const bool hasObjectData = m_clientDataItemsType == wxClientData_Object;
|
||||||
|
|
||||||
|
wxList::compatibility_iterator node = m_clientList.GetFirst();
|
||||||
|
|
||||||
wxArrayString items;
|
wxArrayString items;
|
||||||
|
wxArrayPtrVoid itemsData;
|
||||||
items.Alloc(count);
|
items.Alloc(count);
|
||||||
for ( i = 0; i < count; i++ )
|
for ( i = 0; i < count; i++ )
|
||||||
{
|
{
|
||||||
if ( i != n )
|
if ( i != n )
|
||||||
|
{
|
||||||
items.Add(GetString(i));
|
items.Add(GetString(i));
|
||||||
|
if ( hasClientData )
|
||||||
|
{
|
||||||
|
// also save the client data
|
||||||
|
itemsData.Add(node->GetData());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else // need to delete the client object too
|
||||||
|
{
|
||||||
|
if ( hasObjectData )
|
||||||
|
{
|
||||||
|
delete (wxClientData *)node->GetData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( hasClientData )
|
||||||
|
{
|
||||||
|
node = node->GetNext();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( hasObjectData )
|
||||||
|
{
|
||||||
|
// prevent Clear() from destroying all client data
|
||||||
|
m_clientDataItemsType = wxClientData_None;
|
||||||
}
|
}
|
||||||
|
|
||||||
Clear();
|
Clear();
|
||||||
@@ -246,6 +277,11 @@ void wxChoice::Delete( int n )
|
|||||||
for ( i = 0; i < count - 1; i++ )
|
for ( i = 0; i < count - 1; i++ )
|
||||||
{
|
{
|
||||||
Append(items[i]);
|
Append(items[i]);
|
||||||
|
|
||||||
|
if ( hasObjectData )
|
||||||
|
SetClientObject(i, (wxClientData *)itemsData[i]);
|
||||||
|
else if ( hasClientData )
|
||||||
|
SetClientDate(i, itemsData[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user