Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace gtk_combo_box_text_insert_text with direct model insertion #23443

Merged
merged 3 commits into from
Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion include/wx/gtk/bmpcbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ class WXDLLIMPEXP_ADV wxBitmapComboBox : public wxComboBox,
virtual GdkWindow *GTKGetWindow(wxArrayGdkWindows& windows) const override;

virtual void GTKCreateComboBoxWidget() override;
virtual void GTKInsertComboBoxTextItem( unsigned int n, const wxString& text ) override;

virtual wxSize DoGetBestSize() const override;

Expand Down
4 changes: 0 additions & 4 deletions include/wx/gtk/choice.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,6 @@ class WXDLLIMPEXP_CORE wxChoice : public wxChoiceBase
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();

Expand Down
14 changes: 0 additions & 14 deletions src/gtk/bmpcbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,20 +285,6 @@ int wxBitmapComboBox::Insert(const wxString& item, const wxBitmapBundle& bitmap,
return n;
}

void wxBitmapComboBox::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( store, &iter, n );

wxGtkValue value( G_TYPE_STRING );
g_value_set_string( value, text.utf8_str() );
gtk_list_store_set_value( store, &iter, m_stringCellIndex, value );
}

// ----------------------------------------------------------------------------
// wxTextEntry interface override
// ----------------------------------------------------------------------------
Expand Down
21 changes: 11 additions & 10 deletions src/gtk/choice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,6 @@ bool wxChoice::GTKHandleFocusOut()
return wxChoiceBase::GTKHandleFocusOut();
}

void wxChoice::GTKInsertComboBoxTextItem( unsigned int n, const wxString& text )
{
#ifdef __WXGTK3__
gtk_combo_box_text_insert_text(GTK_COMBO_BOX_TEXT(m_widget), n, text.utf8_str());
#else
gtk_combo_box_insert_text( GTK_COMBO_BOX( m_widget ), n, text.utf8_str() );
#endif
}

int wxChoice::DoInsertItems(const wxArrayStringsAdapter & items,
unsigned int pos,
void **clientData, wxClientDataType type)
Expand All @@ -161,6 +152,12 @@ 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);
imciner2 marked this conversation as resolved.
Show resolved Hide resolved

for ( int i = 0; i < count; ++i )
{
n = pos + i;
Expand All @@ -169,12 +166,16 @@ 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);
}

gtk_widget_thaw_child_notify(m_widget);


InvalidateBestSize();

return n;
Expand Down