#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();
}
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"));
}
// 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);
}