From 01e61f6e7f2ec94dd0f9f336904d6b075edece73 Mon Sep 17 00:00:00 2001 From: Ian McInerney Date: Wed, 12 Apr 2023 16:39:08 +0100 Subject: [PATCH] Remove GTKInsertComboBoxTextItem completely Instead of having a special function for this, collapse it down into the DoInsertItems function to allow for only querying the model once from the combobox. This function is considered private because of the GTK prefix, so its removal isn't API-breaking. --- include/wx/gtk/choice.h | 4 ---- src/gtk/choice.cpp | 18 ++++++------------ 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/include/wx/gtk/choice.h b/include/wx/gtk/choice.h index f936745180..146fb775b2 100644 --- a/include/wx/gtk/choice.h +++ b/include/wx/gtk/choice.h @@ -105,10 +105,6 @@ protected: virtual GdkWindow *GTKGetWindow(wxArrayGdkWindows& windows) const override; virtual void DoApplyWidgetStyle(GtkRcStyle *style) override; - // in derived classes, implement this to insert list store entry - // with all items default except text - virtual void GTKInsertComboBoxTextItem( unsigned int n, const wxString& text ); - private: void Init(); diff --git a/src/gtk/choice.cpp b/src/gtk/choice.cpp index 1a784fc187..a473ca70b4 100644 --- a/src/gtk/choice.cpp +++ b/src/gtk/choice.cpp @@ -139,17 +139,6 @@ bool wxChoice::GTKHandleFocusOut() return wxChoiceBase::GTKHandleFocusOut(); } -void wxChoice::GTKInsertComboBoxTextItem( unsigned int n, const wxString& text ) -{ - GtkComboBox* combobox = GTK_COMBO_BOX( m_widget ); - GtkTreeModel *model = gtk_combo_box_get_model( combobox ); - GtkListStore *store = GTK_LIST_STORE( model ); - GtkTreeIter iter; - - gtk_list_store_insert_with_values(store, &iter, n, m_stringCellIndex, - text.utf8_str().data(), -1); -} - int wxChoice::DoInsertItems(const wxArrayStringsAdapter & items, unsigned int pos, void **clientData, wxClientDataType type) @@ -163,6 +152,10 @@ int wxChoice::DoInsertItems(const wxArrayStringsAdapter & items, int n = wxNOT_FOUND; + GtkTreeIter iter; + GtkTreeModel *model = gtk_combo_box_get_model( GTK_COMBO_BOX( m_widget ) ); + GtkListStore *store = GTK_LIST_STORE( model ); + gtk_widget_freeze_child_notify(m_widget); for ( int i = 0; i < count; ++i ) @@ -173,7 +166,8 @@ int wxChoice::DoInsertItems(const wxArrayStringsAdapter & items, if (m_strings) n = m_strings->Add(items[i]); - GTKInsertComboBoxTextItem( n, items[i] ); + gtk_list_store_insert_with_values(store, &iter, n, m_stringCellIndex, + items[i].utf8_str().data(), -1); m_clientData.Insert( nullptr, n ); AssignNewItemClientData(n, clientData, i, type);