don't access m_clientDataItemsType directly

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@48732 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2007-09-17 00:12:13 +00:00
parent efb35bebfa
commit b4a11fe85c
7 changed files with 30 additions and 45 deletions

View File

@@ -109,7 +109,7 @@ private:
// this is the first time client data is used with this control // this is the first time client data is used with this control
DoInitItemClientData(); DoInitItemClientData();
m_clientDataItemsType = type; SetClientDataType(type);
} }
//else: we already have client data //else: we already have client data

View File

@@ -483,9 +483,6 @@ int wxListBox::DoInsertItems(const wxArrayStringsAdapter& items,
g_object_unref (entry); g_object_unref (entry);
} }
if ( !HasClientData() )
m_clientDataItemsType = type;
return pos + numItems - 1; return pos + numItems - 1;
} }

View File

@@ -89,7 +89,6 @@ bool wxCheckListBox::Create(
// this will be increased by our Append command // this will be increased by our Append command
wxMacDataBrowserCheckListControl* control = new wxMacDataBrowserCheckListControl( this, pos, size, style ); wxMacDataBrowserCheckListControl* control = new wxMacDataBrowserCheckListControl( this, pos, size, style );
control->SetClientDataType( m_clientDataItemsType );
m_peer = control; m_peer = control;
MacPostControlCreate(pos,size); MacPostControlCreate(pos,size);

View File

@@ -507,44 +507,37 @@ int wxComboBox::DoInsertItems(const wxArrayStringsAdapter& items,
void **clientData, void **clientData,
wxClientDataType type) wxClientDataType type)
{ {
// wxItemContainer should probably be doing it itself but usually this is return m_choice->DoInsertItems(items, pos, clientData, type);
// not necessary as the derived class DoInsertItems() calls
// AssignNewItemClientData() which initializes m_clientDataItemsType
// correctly; however as we just forward everything to wxChoice, we need to
// do it ourselves
//
// also notice that we never use wxClientData_Object with wxChoice as we
// don't want it to delete the data -- we will
int rc = m_choice->DoInsertItems(items, pos, clientData,
clientData ? wxClientData_Void
: wxClientData_None) ;
if ( rc != wxNOT_FOUND )
{
if ( !HasClientData() && type != wxClientData_None )
m_clientDataItemsType = type;
}
return rc;
} }
void wxComboBox::DoSetItemClientData(unsigned int n, void* clientData) void wxComboBox::DoSetItemClientData(unsigned int n, void* clientData)
{ {
return m_choice->SetClientData( n , clientData ) ; return m_choice->DoSetItemClientData( n , clientData ) ;
} }
void* wxComboBox::DoGetItemClientData(unsigned int n) const void* wxComboBox::DoGetItemClientData(unsigned int n) const
{ {
return m_choice->GetClientData( n ) ; return m_choice->DoGetItemClientData( n ) ;
}
wxClientDataType wxComboBox::GetClientDataType() const
{
return m_choice->GetClientDataType();
}
void wxComboBox::SetClientDataType(wxClientDataType clientDataItemsType)
{
m_choice->SetClientDataType(clientDataItemsType);
} }
void wxComboBox::DoDeleteOneItem(unsigned int n) void wxComboBox::DoDeleteOneItem(unsigned int n)
{ {
m_choice->Delete( n ); m_choice->DoDeleteOneItem( n );
} }
void wxComboBox::DoClear() void wxComboBox::DoClear()
{ {
m_choice->Clear(); m_choice->DoClear();
} }
int wxComboBox::GetSelection() const int wxComboBox::GetSelection() const

View File

@@ -82,7 +82,6 @@ bool wxListBox::Create(
return false; return false;
wxMacDataBrowserListControl* control = new wxMacDataBrowserListControl( this, pos, size, style ); wxMacDataBrowserListControl* control = new wxMacDataBrowserListControl( this, pos, size, style );
control->SetClientDataType( m_clientDataItemsType );
m_peer = control; m_peer = control;
MacPostControlCreate( pos, size ); MacPostControlCreate( pos, size );

View File

@@ -363,25 +363,22 @@ void wxChoice::SetString(unsigned int n, const wxString& s)
// we have to delete and add back the string as there is no way to change a // we have to delete and add back the string as there is no way to change a
// string in place // string in place
// we need to preserve the client data // we need to preserve the client data manually
void *data; void *oldData = NULL;
if ( m_clientDataItemsType != wxClientData_None ) wxClientData *oldObjData = NULL;
{ if ( HasClientUntypedData() )
data = DoGetItemClientData(n); oldData = GetClientData(n);
} else if ( HasClientObjectData() )
else // no client data oldObjData = GetClientObject(n);
{
data = NULL;
}
::SendMessage(GetHwnd(), CB_DELETESTRING, n, 0); ::SendMessage(GetHwnd(), CB_DELETESTRING, n, 0);
::SendMessage(GetHwnd(), CB_INSERTSTRING, n, (LPARAM)s.wx_str() ); ::SendMessage(GetHwnd(), CB_INSERTSTRING, n, (LPARAM)s.wx_str() );
if ( data ) // restore the client data
{ if ( oldData )
DoSetItemClientData(n, data); SetClientData(n, oldData);
} else if ( oldObjData )
//else: it's already NULL by default SetClientObject(n, oldObjData);
InvalidateBestSize(); InvalidateBestSize();
} }

View File

@@ -486,9 +486,9 @@ void wxListBox::SetString(unsigned int n, const wxString& s)
void *oldData = NULL; void *oldData = NULL;
wxClientData *oldObjData = NULL; wxClientData *oldObjData = NULL;
if ( m_clientDataItemsType == wxClientData_Void ) if ( HasClientUntypedData() )
oldData = GetClientData(n); oldData = GetClientData(n);
else if ( m_clientDataItemsType == wxClientData_Object ) else if ( HasClientObjectData() )
oldObjData = GetClientObject(n); oldObjData = GetClientObject(n);
// delete and recreate it // delete and recreate it