X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a756f210019dd5b51331b7181c816d3882146a30..5aab763c09c663ab5e5b92e533ca025e811f1bcf:/src/msw/choice.cpp diff --git a/src/msw/choice.cpp b/src/msw/choice.cpp index 8ef52dbcff..58a2f6a17d 100644 --- a/src/msw/choice.cpp +++ b/src/msw/choice.cpp @@ -191,25 +191,53 @@ int wxChoice::FindString(const wxString& s) const #endif // Watcom/!Watcom } -void wxChoice::SetString(int WXUNUSED(n), const wxString& WXUNUSED(s)) +void wxChoice::SetString(int n, const wxString& s) { - wxFAIL_MSG(wxT("not implemented")); + wxCHECK_RET( n >= 0 && n < GetCount(), + wxT("invalid item index in wxChoice::SetString") ); -#if 0 // should do this, but no Insert() so far - Delete(n); - Insert(n + 1, s); -#endif + // we have to delete and add back the string as there is no way to change a + // string in place + + // we need to preserve the client data + void *data; + if ( m_clientDataItemsType != wxClientData_None ) + { + data = DoGetItemClientData(n); + } + else // no client data + { + data = NULL; + } + + ::SendMessage(GetHwnd(), CB_DELETESTRING, n, 0); + ::SendMessage(GetHwnd(), CB_INSERTSTRING, n, (LPARAM)s.c_str() ); + + if ( data ) + { + DoSetItemClientData(n, data); + } + //else: it's already NULL by default } wxString wxChoice::GetString(int n) const { - size_t len = (size_t)::SendMessage(GetHwnd(), CB_GETLBTEXTLEN, n, 0); + int len = (int)::SendMessage(GetHwnd(), CB_GETLBTEXTLEN, n, 0); + wxString str; - if (len) { - if ( ::SendMessage(GetHwnd(), CB_GETLBTEXT, n, - (LPARAM)str.GetWriteBuf(len)) == CB_ERR ) { + if ( len != CB_ERR && len > 0 ) + { + if ( ::SendMessage + ( + GetHwnd(), + CB_GETLBTEXT, + n, + (LPARAM)(wxChar *)wxStringBuffer(str, len) + ) == CB_ERR ) + { wxLogLastError(wxT("SendMessage(CB_GETLBTEXT)")); } + str.UngetWriteBuf(); } @@ -222,7 +250,8 @@ wxString wxChoice::GetString(int n) const void wxChoice::DoSetItemClientData( int n, void* clientData ) { - if ( SendMessage(GetHwnd(), CB_SETITEMDATA, n, (LPARAM)clientData) == CB_ERR ) + if ( ::SendMessage(GetHwnd(), CB_SETITEMDATA, + n, (LPARAM)clientData) == CB_ERR ) { wxLogLastError(wxT("CB_SETITEMDATA")); } @@ -283,6 +312,7 @@ void wxChoice::DoSetSize(int x, int y, // wxWindows interpretation is different; also, getting the size returns // the _displayed_ size (NOT the drop down menu size) so // setting-getting-setting size would not work. + wxControl::DoSetSize(x, y, width, -1, sizeFlags); }