diff options
author | Tristan Van Berkom <tristan.van.berkom@gmail.com> | 2010-11-20 16:32:24 +0900 |
---|---|---|
committer | Tristan Van Berkom <tristan.van.berkom@gmail.com> | 2011-01-04 23:37:06 +0900 |
commit | 9ffaae50220da45e0004b4682ec7d1d1031fe924 (patch) | |
tree | cc91d1b6b431ce35dc216481b70604e9301626eb /tests | |
parent | 6d8dfd5546578bd49835aa2dd44e12f0f427f38a (diff) | |
download | gtk+-9ffaae50220da45e0004b4682ec7d1d1031fe924.tar.gz |
Added GtkTreeMenuHeaderFunc to decide if a submenu gets a leaf header.
GtkComboBox needs treemenus to allow selection of all leafs including
rows which may have children, this allows the combobox or combobox user
to decide which row that has children can also be selectable as a header
leaf of the submenu. Test case testtreemenu updated to reflect this.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/testtreemenu.c | 72 |
1 files changed, 71 insertions, 1 deletions
diff --git a/tests/testtreemenu.c b/tests/testtreemenu.c index d099f0d3fc..e514f47522 100644 --- a/tests/testtreemenu.c +++ b/tests/testtreemenu.c @@ -16,7 +16,7 @@ static GtkCellRenderer *cell_1 = NULL, *cell_2 = NULL, *cell_3 = NULL; static GtkTreeModel * simple_tree_model (void) { - GtkTreeIter iter, parent; + GtkTreeIter iter, parent, child; GtkTreeStore *store = gtk_tree_store_new (N_SIMPLE_COLUMNS, G_TYPE_STRING, /* name text */ @@ -84,6 +84,27 @@ simple_tree_model (void) SIMPLE_COLUMN_DESCRIPTION, "Eager", -1); + gtk_tree_store_append (store, &child, &iter); + gtk_tree_store_set (store, &child, + SIMPLE_COLUMN_NAME, "Jump", + SIMPLE_COLUMN_ICON, "gtk-yes", + SIMPLE_COLUMN_DESCRIPTION, "Very High", + -1); + + gtk_tree_store_append (store, &child, &iter); + gtk_tree_store_set (store, &child, + SIMPLE_COLUMN_NAME, "Pounce", + SIMPLE_COLUMN_ICON, "gtk-no", + SIMPLE_COLUMN_DESCRIPTION, "On Pooh", + -1); + + gtk_tree_store_append (store, &child, &iter); + gtk_tree_store_set (store, &child, + SIMPLE_COLUMN_NAME, "Bounce", + SIMPLE_COLUMN_ICON, "gtk-cancel", + SIMPLE_COLUMN_DESCRIPTION, "Around", + -1); + gtk_tree_store_append (store, &iter, &parent); gtk_tree_store_set (store, &iter, SIMPLE_COLUMN_NAME, "Owl", @@ -213,6 +234,44 @@ expand_cell_3_toggled (GtkToggleButton *toggle, } static void +menu_activated_cb (GtkTreeMenu *menu, + const gchar *path, + gpointer unused) +{ + GtkTreeModel *model = gtk_tree_menu_get_model (menu); + GtkTreeIter iter; + gchar *row_name; + + if (!gtk_tree_model_get_iter_from_string (model, &iter, path)) + return; + + gtk_tree_model_get (model, &iter, SIMPLE_COLUMN_NAME, &row_name, -1); + + g_print ("Item activated: %s\n", row_name); + + g_free (row_name); +} + +gboolean +enable_submenu_headers (GtkTreeModel *model, + GtkTreeIter *iter, + gpointer data) +{ + return TRUE; +} + + +static void +submenu_headers_toggled (GtkToggleButton *toggle, + GtkTreeMenu *menu) +{ + if (gtk_toggle_button_get_active (toggle)) + gtk_tree_menu_set_header_func (menu, enable_submenu_headers, NULL, NULL); + else + gtk_tree_menu_set_header_func (menu, NULL, NULL, NULL); +} + +static void tree_menu (void) { GtkWidget *window, *widget; @@ -224,6 +283,8 @@ tree_menu (void) menu = simple_tree_menu (); + g_signal_connect (menu, "menu-activate", G_CALLBACK (menu_activated_cb), NULL); + vbox = gtk_vbox_new (FALSE, 4); gtk_widget_show (vbox); @@ -278,6 +339,15 @@ tree_menu (void) g_signal_connect (G_OBJECT (widget), "toggled", G_CALLBACK (expand_cell_3_toggled), menu); + widget = gtk_check_button_new_with_label ("Submenu Headers"); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), FALSE); + gtk_widget_show (widget); + gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE, FALSE, 0); + + g_signal_connect (G_OBJECT (widget), "toggled", + G_CALLBACK (submenu_headers_toggled), menu); + + gtk_container_add (GTK_CONTAINER (window), vbox); gtk_widget_show (window); |