X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d50c81d3adb484655e394e4257cf76bcaf4038f2..d5bb85a0a4f28df1b966481de9a320806bbb1471:/src/msw/choice.cpp diff --git a/src/msw/choice.cpp b/src/msw/choice.cpp index 84d90c83b0..c6a9f7909f 100644 --- a/src/msw/choice.cpp +++ b/src/msw/choice.cpp @@ -69,10 +69,10 @@ bool wxChoice::Create(wxWindow *parent, wxASSERT_MSG( !(style & wxCB_DROPDOWN) && !(style & wxCB_READONLY) && !(style & wxCB_SIMPLE), - _T("this style flag is ignored by wxChoice, you " + wxT("this style flag is ignored by wxChoice, you " "probably want to use a wxComboBox") ); - if ( !MSWCreateControl(_T("COMBOBOX"), msStyle) ) + if ( !MSWCreateControl(wxT("COMBOBOX"), msStyle) ) return FALSE; for ( int i = 0; i < n; i++ ) @@ -85,27 +85,57 @@ bool wxChoice::Create(wxWindow *parent, return TRUE; } +wxChoice::~wxChoice() +{ + Free(); +} + // ---------------------------------------------------------------------------- // adding/deleting items to/from the list // ---------------------------------------------------------------------------- -void wxChoice::DoAppend(const wxString& item) +int wxChoice::DoAppend(const wxString& item) { - SendMessage(GetHwnd(), CB_ADDSTRING, 0, (LONG)item.c_str()); + int n = (int)SendMessage(GetHwnd(), CB_ADDSTRING, 0, (LONG)item.c_str()); + if ( n == CB_ERR ) + { + wxLogLastError("SendMessage(CB_ADDSTRING)"); + } + + return n; } void wxChoice::Delete(int n) { - wxCHECK_RET( n < GetCount(), _T("invalid item index in wxChoice::Delete") ); + wxCHECK_RET( n < GetCount(), wxT("invalid item index in wxChoice::Delete") ); + + if ( HasClientObjectData() ) + { + delete GetClientObject(n); + } SendMessage(GetHwnd(), CB_DELETESTRING, n, 0); } void wxChoice::Clear() { + Free(); + SendMessage(GetHwnd(), CB_RESETCONTENT, 0, 0); } +void wxChoice::Free() +{ + if ( HasClientObjectData() ) + { + size_t count = GetCount(); + for ( size_t n = 0; n < count; n++ ) + { + delete GetClientObject(n); + } + } +} + // ---------------------------------------------------------------------------- // selection // ---------------------------------------------------------------------------- @@ -151,10 +181,20 @@ int wxChoice::FindString(const wxString& s) const #endif // Watcom/!Watcom } +void wxChoice::SetString(int n, const wxString& s) +{ + wxFAIL_MSG(wxT("not implemented")); + +#if 0 // should do this, but no Insert() so far + Delete(n); + Insert(n + 1, s); +#endif +} + wxString wxChoice::GetString(int n) const { size_t len = (size_t)::SendMessage(GetHwnd(), CB_GETLBTEXTLEN, n, 0); - wxString str = ""; + wxString str; if (len) { if ( ::SendMessage(GetHwnd(), CB_GETLBTEXT, n, (LPARAM)str.GetWriteBuf(len)) == CB_ERR ) { @@ -170,36 +210,36 @@ wxString wxChoice::GetString(int n) const // client data // ---------------------------------------------------------------------------- -void wxChoice::DoSetClientData( int n, void* clientData ) +void wxChoice::DoSetItemClientData( int n, void* clientData ) { if ( SendMessage(GetHwnd(), CB_SETITEMDATA, n, (LPARAM)clientData) == CB_ERR ) { - wxLogLastError(_T("CB_SETITEMDATA")); + wxLogLastError(wxT("CB_SETITEMDATA")); } } -void* wxChoice::DoGetClientData( int n ) const +void* wxChoice::DoGetItemClientData( int n ) const { LPARAM rc = SendMessage(GetHwnd(), CB_GETITEMDATA, n, 0); if ( rc == CB_ERR ) { - wxLogLastError(_T("CB_GETITEMDATA")); + wxLogLastError(wxT("CB_GETITEMDATA")); // unfortunately, there is no way to return an error code to the user - rc = (LPARAM) NULL; + rc = (LPARAM) NULL; } return (void *)rc; } -void wxChoice::DoSetClientObject( int n, wxClientData* clientData ) +void wxChoice::DoSetItemClientObject( int n, wxClientData* clientData ) { - DoSetClientData(n, clientData); + DoSetItemClientData(n, clientData); } -wxClientData* wxChoice::DoGetClientObject( int n ) const +wxClientData* wxChoice::DoGetItemClientObject( int n ) const { - return (wxClientData *)DoGetClientData(n); + return (wxClientData *)DoGetItemClientData(n); } // ---------------------------------------------------------------------------- @@ -277,10 +317,15 @@ bool wxChoice::MSWCommand(WXUINT param, WXWORD WXUNUSED(id)) return FALSE; } + int n = GetSelection(); wxCommandEvent event(wxEVT_COMMAND_CHOICE_SELECTED, m_windowId); - event.SetInt(GetSelection()); + event.SetInt(n); event.SetEventObject(this); event.SetString(GetStringSelection()); + if ( HasClientObjectData() ) + event.SetClientObject( GetClientObject(n) ); + else if ( HasClientUntypedData() ) + event.SetClientData( GetClientData(n) ); ProcessCommand(event); return TRUE;