X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a236aa2058ccf3d36e9cafc20fa7375080c4be50..8064223b7b1b3657363b7a635c381b9269d95e55:/src/gtk/choice.cpp diff --git a/src/gtk/choice.cpp b/src/gtk/choice.cpp index 7dfecca77a..8f25aa9632 100644 --- a/src/gtk/choice.cpp +++ b/src/gtk/choice.cpp @@ -62,7 +62,7 @@ static void gtk_choice_clicked_callback( GtkWidget *WXUNUSED(widget), wxChoice * else if ( choice->HasClientUntypedData() ) event.SetClientData( choice->GetClientData(n) ); - choice->GetEventHandler()->ProcessEvent(event); + choice->HandleWindowEvent(event); } } @@ -70,7 +70,7 @@ static void gtk_choice_clicked_callback( GtkWidget *WXUNUSED(widget), wxChoice * // wxChoice //----------------------------------------------------------------------------- -IMPLEMENT_DYNAMIC_CLASS(wxChoice,wxControl) +IMPLEMENT_DYNAMIC_CLASS(wxChoice, wxControlWithItems) wxChoice::wxChoice() { @@ -110,8 +110,8 @@ bool wxChoice::Create( wxWindow *parent, wxWindowID id, m_strings = new wxSortedArrayString; } - // begin with no selection - m_selection_hack = wxNOT_FOUND; + // If we have items, GTK will choose the first item by default + m_selection_hack = n > 0 ? 0 : wxNOT_FOUND; GtkWidget *menu = gtk_menu_new(); @@ -127,6 +127,13 @@ bool wxChoice::Create( wxWindow *parent, wxWindowID id, PostCreation(size); SetInitialSize(size); // need this too because this is a wxControlWithItems + // workaround for bug in gtk_option_menu_set_history(), it causes + // gtk_widget_size_allocate() to be called with the current + // widget->allocation values, which will be zero if a proper + // size_allocate has not occured yet + m_widget->allocation.width = m_width; + m_widget->allocation.height = m_height; + return true; } @@ -163,6 +170,12 @@ int wxChoice::DoInsertItems(const wxArrayStringsAdapter & items, m_selection_hack += count; } + // We must set the selection so that it can be read back even if + // the user has not modified it since GTK+ will then select the + // first item so well return 0. + if ((count > 0) && (m_selection_hack==wxNOT_FOUND)) + m_selection_hack = 0; + return pos - 1; } @@ -216,8 +229,8 @@ void wxChoice::DoDeleteOneItem(unsigned int n) wxArrayString items; wxArrayPtrVoid itemsData; - items.Alloc(count); - itemsData.Alloc(count); + items.Alloc(count - 1); + itemsData.Alloc(count - 1); for ( unsigned i = 0; i < count; i++ ) { if ( i != n ) @@ -229,11 +242,15 @@ void wxChoice::DoDeleteOneItem(unsigned int n) wxChoice::DoClear(); - void ** const data = &itemsData[0]; - if ( HasClientObjectData() ) - Append(items, wx_reinterpret_cast(wxClientData **, data)); - else - Append(items, data); + if ( count > 1 ) + { + void ** const data = &itemsData[0]; + if ( HasClientObjectData() ) + Append(items, wx_reinterpret_cast(wxClientData **, data)); + else + Append(items, data); + } + //else: the control is now empty, nothing to append } int wxChoice::FindString( const wxString &string, bool bCase ) const