X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a8e65eeeae46b9df8577903469c65bb218489372..05159a2750ed2cc5945a85bc5fc6849ad1a30e75:/src/msw/choice.cpp diff --git a/src/msw/choice.cpp b/src/msw/choice.cpp index 32b36c3603..58a2f6a17d 100644 --- a/src/msw/choice.cpp +++ b/src/msw/choice.cpp @@ -193,20 +193,51 @@ int wxChoice::FindString(const wxString& s) const void wxChoice::SetString(int n, const wxString& s) { - wxCHECK_RET( (n>=0)&&(n= 0 && n < GetCount(), + wxT("invalid item index in wxChoice::SetString") ); + + // 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(); } @@ -219,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")); } @@ -281,8 +313,7 @@ void wxChoice::DoSetSize(int x, int y, // the _displayed_ size (NOT the drop down menu size) so // setting-getting-setting size would not work. - wxSize sz = GetSize(); - wxControl::DoSetSize(x, y, width, sz.y, sizeFlags); + wxControl::DoSetSize(x, y, width, -1, sizeFlags); } wxSize wxChoice::DoGetBestSize() const