+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[],
+ long style, const wxValidator& validator,
+ const wxString &name )
+{
+ if (!PreCreation( parent, pos, size ) ||
+ !CreateBase( parent, id, pos, size, style, validator, name ))
+ {
+ wxFAIL_MSG( wxT("wxChoice creation failed") );
+ return false;
+ }
+
+ if ( IsSorted() )
+ {
+ // if our m_strings != NULL, Append() will check for it and insert
+ // items in the correct order
+ m_strings = new wxSortedArrayString;
+ }
+
+ m_widget = gtk_combo_box_new_text();
+ g_object_ref(m_widget);
+
+ Append(n, choices);
+
+ m_parent->DoAddChild( this );
+
+ PostCreation(size);
+
+ g_signal_connect_after (m_widget, "changed",
+ G_CALLBACK (gtk_choice_changed_callback), this);
+
+ return true;
+}
+
+wxChoice::~wxChoice()
+{
+ delete m_strings;
+}
+
+void wxChoice::SendSelectionChangedEvent(wxEventType evt_type)
+{
+ if (!m_hasVMT)
+ return;
+
+ if (GetSelection() == -1)
+ return;
+
+ wxCommandEvent event( evt_type, GetId() );
+
+ int n = GetSelection();
+ event.SetInt( n );
+ event.SetString( GetStringSelection() );
+ event.SetEventObject( this );
+ InitCommandEventWithItems( event, n );
+
+ HandleWindowEvent( event );
+}
+
+void wxChoice::GTKInsertComboBoxTextItem( unsigned int n, const wxString& text )
+{
+ gtk_combo_box_insert_text( GTK_COMBO_BOX( m_widget ), n, wxGTK_CONV( text ) );
+}
+
+int wxChoice::DoInsertItems(const wxArrayStringsAdapter & items,
+ unsigned int pos,
+ void **clientData, wxClientDataType type)
+{
+ wxCHECK_MSG( m_widget != NULL, -1, wxT("invalid control") );
+
+ wxASSERT_MSG( !IsSorted() || (pos == GetCount()),
+ wxT("In a sorted choice data could only be appended"));
+
+ const int count = items.GetCount();
+
+ int n = wxNOT_FOUND;
+
+ for ( int i = 0; i < count; ++i )
+ {
+ n = pos + i;
+ // If sorted, use this wxSortedArrayStrings to determine
+ // the right insertion point
+ if(m_strings)
+ n = m_strings->Add(items[i]);
+
+ GTKInsertComboBoxTextItem( n, items[i] );
+
+ m_clientData.Insert( NULL, n );
+ AssignNewItemClientData(n, clientData, i, type);
+ }
+
+ InvalidateBestSize();
+
+ return n;
+}
+
+void wxChoice::DoSetItemClientData(unsigned int n, void* clientData)
+{
+ m_clientData[n] = clientData;
+}
+
+void* wxChoice::DoGetItemClientData(unsigned int n) const
+{
+ return m_clientData[n];
+}
+
+void wxChoice::DoClear()
+{
+ wxCHECK_RET( m_widget != NULL, wxT("invalid control") );