#include "wx/choice.h"
#include "wx/utils.h"
#include "wx/log.h"
+ #include "wx/settings.h"
#endif
#include "wx/msw/private.h"
-#if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxChoice, wxControl)
-#endif
// ============================================================================
// implementation
if ( !MSWCreateControl(wxT("COMBOBOX"), msStyle) )
return FALSE;
+ // A choice/combobox normally has a white background (or other, depending
+ // on global settings) rather than inheriting the parent's background colour.
+ SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW));
+
for ( int i = 0; i < n; i++ )
{
Append(choices[i]);
return TRUE;
}
+wxChoice::~wxChoice()
+{
+ Free();
+}
+
// ----------------------------------------------------------------------------
// adding/deleting items to/from the list
// ----------------------------------------------------------------------------
{
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
// ----------------------------------------------------------------------------
#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 ) {
// 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 )
{
}
}
-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(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);
}
// ----------------------------------------------------------------------------
return FALSE;
}
- wxCommandEvent event(wxEVT_COMMAND_CHOICE_SELECTED, m_windowId);
- event.SetInt(GetSelection());
- event.SetEventObject(this);
- event.SetString(GetStringSelection());
- ProcessCommand(event);
+ int n = GetSelection();
+ if (n > -1)
+ {
+ wxCommandEvent event(wxEVT_COMMAND_CHOICE_SELECTED, m_windowId);
+ 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;
}