[gtk+/combo-refactor: 8/42] Fixed GtkTreeMenu to not infinitely recurse when building submenus.
- From: Tristan Van Berkom <tvb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/combo-refactor: 8/42] Fixed GtkTreeMenu to not infinitely recurse when building submenus.
- Date: Thu, 2 Dec 2010 04:33:36 +0000 (UTC)
commit 9147bb5d5045abfacff08ccd19f138d2dea2cf33
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date: Fri Nov 19 13:30:30 2010 +0900
Fixed GtkTreeMenu to not infinitely recurse when building submenus.
GtkTreeMenu needs to only populate it's submenus when set_root()
is called, we were populating it when the model is set which cause
the tree to be infinitely populated as the root is NULL by default.
Also call gtk_menu_set_reserve_toggle_thingy (FALSE) to not reserve
space for the toggle size.
gtk/gtktreemenu.c | 36 ++++++++++++++++++++++--------------
gtk/gtktreemenu.h | 3 +++
2 files changed, 25 insertions(+), 14 deletions(-)
---
diff --git a/gtk/gtktreemenu.c b/gtk/gtktreemenu.c
index cff4541..e80ed45 100644
--- a/gtk/gtktreemenu.c
+++ b/gtk/gtktreemenu.c
@@ -138,6 +138,8 @@ gtk_tree_menu_init (GtkTreeMenu *menu)
GTK_TYPE_TREE_MENU,
GtkTreeMenuPrivate);
priv = menu->priv;
+
+ gtk_menu_set_reserve_toggle_size (GTK_MENU (menu), FALSE);
}
static void
@@ -170,7 +172,7 @@ gtk_tree_menu_class_init (GtkTreeMenuClass *class)
P_("TreeMenu root row"),
P_("The TreeMenu will display children of the "
"specified root"),
- GTK_TYPE_TREE_ROW_REFERENCE,
+ GTK_TYPE_TREE_PATH,
GTK_PARAM_READWRITE));
g_object_class_install_property (object_class,
@@ -751,10 +753,7 @@ gtk_tree_menu_populate (GtkTreeMenu *menu)
GtkWidget *submenu;
row_path = gtk_tree_model_get_path (priv->model, &iter);
- submenu = gtk_tree_menu_new_with_area (priv->area);
-
- gtk_tree_menu_set_model (GTK_TREE_MENU (submenu), priv->model);
- gtk_tree_menu_set_root (GTK_TREE_MENU (submenu), row_path);
+ submenu = gtk_tree_menu_new_full (priv->area, priv->model, row_path);
gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_item), submenu);
@@ -781,7 +780,19 @@ GtkWidget *
gtk_tree_menu_new_with_area (GtkCellArea *area)
{
return (GtkWidget *)g_object_new (GTK_TYPE_TREE_MENU,
- "area", area,
+ "cell-area", area,
+ NULL);
+}
+
+GtkWidget *
+gtk_tree_menu_new_full (GtkCellArea *area,
+ GtkTreeModel *model,
+ GtkTreePath *root)
+{
+ return (GtkWidget *)g_object_new (GTK_TYPE_TREE_MENU,
+ "cell-area", area,
+ "model", model,
+ "root", root,
NULL);
}
@@ -813,12 +824,6 @@ gtk_tree_menu_set_model (GtkTreeMenu *menu,
g_object_ref (priv->model);
}
-
- /* Changing the model in any way invalidates the currently set root,
- * so we implicitly reset it to NULL here */
- gtk_tree_menu_set_root (menu, NULL);
-
- g_object_notify (G_OBJECT (menu), "model");
}
}
@@ -841,7 +846,7 @@ gtk_tree_menu_set_root (GtkTreeMenu *menu,
GtkTreeMenuPrivate *priv;
g_return_if_fail (GTK_IS_TREE_MENU (menu));
- g_return_if_fail (path == NULL || menu->priv->model != NULL);
+ g_return_if_fail (menu->priv->model != NULL || path == NULL);
priv = menu->priv;
@@ -858,7 +863,10 @@ gtk_tree_menu_set_root (GtkTreeMenu *menu,
(GtkCallback) gtk_widget_destroy, NULL);
/* Populate for the new root */
- gtk_tree_menu_populate (menu);
+ if (priv->model)
+ gtk_tree_menu_populate (menu);
+
+ gtk_widget_queue_resize (GTK_WIDGET (menu));
}
GtkTreePath *
diff --git a/gtk/gtktreemenu.h b/gtk/gtktreemenu.h
index 994e293..9a05678 100644
--- a/gtk/gtktreemenu.h
+++ b/gtk/gtktreemenu.h
@@ -73,6 +73,9 @@ GType gtk_tree_menu_get_type (void) G_GNUC
GtkWidget *gtk_tree_menu_new (void);
GtkWidget *gtk_tree_menu_new_with_area (GtkCellArea *area);
+GtkWidget *gtk_tree_menu_new_full (GtkCellArea *area,
+ GtkTreeModel *model,
+ GtkTreePath *root);
void gtk_tree_menu_set_model (GtkTreeMenu *menu,
GtkTreeModel *model);
GtkTreeModel *gtk_tree_menu_get_model (GtkTreeMenu *menu);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]