m_strings = (wxSortedArrayString *)NULL;
}
+bool wxChoice::Create( wxWindow *parent, wxWindowID id,
+ const wxPoint &pos, const wxSize &size,
+ const wxArrayString& choices,
+ long style, const wxValidator& validator,
+ const wxString &name )
+{
+ wxCArrayString chs(choices);
+
+ return Create( parent, id, pos, size, chs.GetCount(), chs.GetStrings(),
+ style, validator, name );
+}
+
bool wxChoice::Create( wxWindow *parent, wxWindowID id,
const wxPoint &pos, const wxSize &size,
int n, const wxString choices[],
m_parent->DoAddChild( this );
PostCreation();
-
- SetFont( parent->GetFont() );
+ InheritAttributes();
SetBestSize(size);
- SetBackgroundColour( parent->GetBackgroundColour() );
- SetForegroundColour( parent->GetForegroundColour() );
-
Show( TRUE );
return TRUE;
wxCHECK_RET( m_widget != NULL, wxT("invalid choice") );
// VZ: apparently GTK+ doesn't have a built-in function to do it (not even
- // in 2.0), hence this dump implementation - still better than nothing
+ // in 2.0), hence this dumb implementation -- still better than nothing
int i,
count = GetCount();
wxCHECK_RET( n >= 0 && n < count, _T("invalid index in wxChoice::Delete") );
+ const bool hasClientData = m_clientDataItemsType != wxClientData_None;
+ const bool hasObjectData = m_clientDataItemsType == wxClientData_Object;
+
+ wxList::compatibility_iterator node = m_clientList.GetFirst();
+
wxArrayString items;
+ wxArrayPtrVoid itemsData;
items.Alloc(count);
for ( i = 0; i < count; i++ )
{
if ( i != n )
+ {
items.Add(GetString(i));
+ if ( hasClientData )
+ {
+ // also save the client data
+ itemsData.Add(node->GetData());
+ }
+ }
+ else // need to delete the client object too
+ {
+ if ( hasObjectData )
+ {
+ delete (wxClientData *)node->GetData();
+ }
+ }
+
+ if ( hasClientData )
+ {
+ node = node->GetNext();
+ }
+ }
+
+ if ( hasObjectData )
+ {
+ // prevent Clear() from destroying all client data
+ m_clientDataItemsType = wxClientData_None;
}
Clear();
for ( i = 0; i < count - 1; i++ )
{
Append(items[i]);
+
+ if ( hasObjectData )
+ SetClientObject(i, (wxClientData *)itemsData[i]);
+ else if ( hasClientData )
+ SetClientData(i, itemsData[i]);
}
}
label = GTK_LABEL( BUTTON_CHILD(m_widget) );
wxASSERT_MSG( label != NULL , wxT("wxChoice: invalid label") );
-
+
#ifdef __WXGTK20__
wxString tmp( wxGTK_CONV_BACK( gtk_label_get_text( label) ) );
#else
int wxChoice::GetSelection() const
{
wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid choice") );
-
+
#ifdef __WXGTK20__
return gtk_option_menu_get_history( GTK_OPTION_MENU(m_widget) );
-
+
#else
GtkMenuShell *menu_shell = GTK_MENU_SHELL( gtk_option_menu_get_menu( GTK_OPTION_MENU(m_widget) ) );
int count = 0;
-
+
GList *child = menu_shell->children;
while (child)
{
#endif
}
-void wxChoice::SetString( int WXUNUSED(n), const wxString& WXUNUSED(string) )
+void wxChoice::SetString( int n, const wxString& str )
{
wxCHECK_RET( m_widget != NULL, wxT("invalid choice") );
- wxFAIL_MSG(wxT("not implemented"));
+ GtkMenuShell *menu_shell = GTK_MENU_SHELL( gtk_option_menu_get_menu( GTK_OPTION_MENU(m_widget) ) );
+ int count = 0;
+ GList *child = menu_shell->children;
+ while (child)
+ {
+ GtkBin *bin = GTK_BIN( child->data );
+ if (count == n)
+ {
+ GtkLabel *label = (GtkLabel *) NULL;
+ if (bin->child)
+ label = GTK_LABEL(bin->child);
+ if (!label)
+ label = GTK_LABEL( BUTTON_CHILD(m_widget) );
+
+ wxASSERT_MSG( label != NULL , wxT("wxChoice: invalid label") );
+
+ gtk_label_set_text( label, wxGTK_CONV( str ) );
+
+ return;
+ }
+ child = child->next;
+ count++;
+ }
}
wxString wxChoice::GetString( int n ) const
size_t count = GetCount();
for ( size_t n = 0; n < count; n++ )
{
- GetTextExtent( GetString(n), &width, NULL, NULL, NULL, &m_font );
+ GetTextExtent( GetString(n), &width, NULL, NULL, NULL );
if ( width > ret.x )
ret.x = width;
}