// Author: Vadim Zeitlin
// Modified by:
// Created: 22.10.99
-// RCS-ID: $Id$
// Copyright: (c) wxWidgets team
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
ResetItemClientObject(i);
}
- m_clientDataItemsType = wxClientData_None;
+ SetClientDataType(wxClientData_None);
DoClear();
}
void wxItemContainer::Delete(unsigned int pos)
{
- wxCHECK_RET( pos < GetCount(), _T("invalid index") );
+ wxCHECK_RET( pos < GetCount(), wxT("invalid index") );
if ( HasClientObjectData() )
ResetItemClientObject(pos);
if ( IsEmpty() )
{
- m_clientDataItemsType = wxClientData_None;
+ SetClientDataType(wxClientData_None);
}
}
// ----------------------------------------------------------------------------
-//
+//
// ----------------------------------------------------------------------------
int wxItemContainer::DoInsertItemsInLoop(const wxArrayStringsAdapter& items,
wxItemContainer::DoInsertOneItem(const wxString& WXUNUSED(item),
unsigned int WXUNUSED(pos))
{
- wxFAIL_MSG( _T("Must be overridden if DoInsertItemsInLoop() is used") );
+ wxFAIL_MSG( wxT("Must be overridden if DoInsertItemsInLoop() is used") );
return wxNOT_FOUND;
}
void wxItemContainer::SetClientObject(unsigned int n, wxClientData *data)
{
- wxASSERT_MSG( m_clientDataItemsType == wxClientData_Object ||
- m_clientDataItemsType == wxClientData_None,
+ wxASSERT_MSG( !HasClientUntypedData(),
wxT("can't have both object and void client data") );
- if ( m_clientDataItemsType == wxClientData_Object )
+ wxCHECK_RET( IsValid(n), "Invalid index passed to SetClientObject()" );
+
+ if ( HasClientObjectData() )
{
wxClientData * clientDataOld
- = wx_static_cast(wxClientData *, DoGetItemClientData(n));
+ = static_cast<wxClientData *>(DoGetItemClientData(n));
if ( clientDataOld )
delete clientDataOld;
}
- else // m_clientDataItemsType == wxClientData_None
+ else // didn't have any client data so far
{
// now we have object client data
DoInitItemClientData();
- m_clientDataItemsType = wxClientData_Object;
+ SetClientDataType(wxClientData_Object);
}
DoSetItemClientData(n, data);
wxClientData *wxItemContainer::GetClientObject(unsigned int n) const
{
- wxCHECK_MSG( m_clientDataItemsType == wxClientData_Object, NULL,
+ wxCHECK_MSG( HasClientObjectData(), NULL,
wxT("this window doesn't have object client data") );
- return wx_static_cast(wxClientData *, DoGetItemClientData(n));
+ wxCHECK_MSG( IsValid(n), NULL,
+ "Invalid index passed to GetClientObject()" );
+
+ return static_cast<wxClientData *>(DoGetItemClientData(n));
+}
+
+wxClientData *wxItemContainer::DetachClientObject(unsigned int n)
+{
+ wxClientData * const data = GetClientObject(n);
+ if ( data )
+ {
+ // reset the pointer as we don't own it any more
+ DoSetItemClientData(n, NULL);
+ }
+
+ return data;
}
void wxItemContainer::SetClientData(unsigned int n, void *data)
{
- if ( m_clientDataItemsType == wxClientData_None )
+ if ( !HasClientData() )
{
DoInitItemClientData();
- m_clientDataItemsType = wxClientData_Void;
+ SetClientDataType(wxClientData_Void);
}
- wxASSERT_MSG( m_clientDataItemsType == wxClientData_Void,
+ wxASSERT_MSG( HasClientUntypedData(),
wxT("can't have both object and void client data") );
+ wxCHECK_RET( IsValid(n), "Invalid index passed to SetClientData()" );
+
DoSetItemClientData(n, data);
}
void *wxItemContainer::GetClientData(unsigned int n) const
{
- wxCHECK_MSG( m_clientDataItemsType == wxClientData_Void, NULL,
+ wxCHECK_MSG( HasClientUntypedData(), NULL,
wxT("this window doesn't have void client data") );
+ wxCHECK_MSG( IsValid(n), NULL,
+ "Invalid index passed to GetClientData()" );
+
return DoGetItemClientData(n);
}
SetClientObject
(
pos,
- (wx_reinterpret_cast(wxClientData **, clientData))[n]
+ (reinterpret_cast<wxClientData **>(clientData))[n]
);
break;
break;
default:
- wxFAIL_MSG( _T("unknown client data type") );
+ wxFAIL_MSG( wxT("unknown client data type") );
// fall through
case wxClientData_None:
}
}
+void wxControlWithItemsBase::SendSelectionChangedEvent(wxEventType eventType)
+{
+ const int n = GetSelection();
+ if ( n == wxNOT_FOUND )
+ return;
+
+ wxCommandEvent event(eventType, m_windowId);
+ event.SetInt(n);
+ event.SetEventObject(this);
+ event.SetString(GetStringSelection());
+ InitCommandEventWithItems(event, n);
+
+ HandleWindowEvent(event);
+}
+
#endif // wxUSE_CONTROLS