Migrating from GtkOptionMenu and GtkCombo to GtkComboBox and GtkComboBoxEntry

Migrating from GtkOptionMenu to GtkComboBox
Migrating from GtkCombo to GtkComboBoxEntry
New features

Prior to 2.4, GTK+ offered two widgets for the task of selecting one item from a list of options. GtkOptionMenu presents the list of options as a menu while GtkCombo presents them in a Windows-style list popup. The only difference between the two is that a GtkCombo allows to manually edit the selected value, while the GtkOptionMenu does not.

In GTK+ 2.4, a unified API for list selection was introduced, with GtkComboBox for the non-editable case and GtkComboBoxEntry for the editable case. The selection of the display style — menu or list — is no longer done at the API level, but has been made themeable via the style property “appears-as-list”.

Migrating from GtkOptionMenu to GtkComboBox

Here is an example of a simple, but typical use of GtkOptionMenu:

1

In order to react to the user's selection, connect to the “changed” signal on the option menu and use gtk_option_menu_get_history() to retrieve the index of the selected item.

And here is how it would be done with a GtkComboBox:

1

In order to react to the user's selection, connect to the “changed” signal and use gtk_combo_box_get_active() to retrieve the index of the selected item.

A slightly more complex example involving images:

1

can be done using a GtkComboBox as follows:

1