Implementing GtkComboBox using GtkTreeMenu !

First iteration at implementing combo box using a delegate
treemenu, almost everything is working. Still need to finalize
sensitivity issues in GtkTreeMenu (and should go ahead and pass
through GtkComboBox code with a fine comb...).
This commit is contained in:
Tristan Van Berkom 2010-11-24 18:14:36 +09:00
parent e1ecd34ce1
commit 83c69f4cf3
3 changed files with 2447 additions and 3762 deletions

View File

@ -829,9 +829,14 @@ row_changed_cb (GtkTreeModel *model,
row_path =
gtk_tree_row_reference_get_path (view->priv->displayed_row);
/* Resize everything in our context if our row changed */
if (gtk_tree_path_compare (row_path, path) == 0)
gtk_cell_area_context_flush (view->priv->context);
if (row_path)
{
/* Resize everything in our context if our row changed */
if (gtk_tree_path_compare (row_path, path) == 0)
gtk_cell_area_context_flush (view->priv->context);
gtk_tree_path_free (row_path);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -115,6 +115,8 @@ static void item_activated_cb (GtkMenuItem
static void submenu_activated_cb (GtkTreeMenu *submenu,
const gchar *path,
GtkTreeMenu *menu);
static void gtk_tree_menu_set_model_internal (GtkTreeMenu *menu,
GtkTreeModel *model);
@ -828,7 +830,7 @@ row_changed_cb (GtkTreeModel *model,
GtkTreePath *root_path =
gtk_tree_row_reference_get_path (priv->root);
if (gtk_tree_path_compare (root_path, path) == 0)
if (root_path && gtk_tree_path_compare (root_path, path) == 0)
{
if (priv->header_func)
has_header =
@ -853,9 +855,9 @@ row_changed_cb (GtkTreeModel *model,
priv->menu_with_header = FALSE;
}
gtk_tree_path_free (root_path);
}
gtk_tree_path_free (root_path);
}
if (item)
@ -940,7 +942,7 @@ area_apply_attributes_cb (GtkCellArea *area,
/* If there is no submenu, go ahead and update item sensitivity,
* items with submenus are always sensitive */
if (!gtk_menu_item_get_submenu (GTK_MENU_ITEM (item)))
if (item && !gtk_menu_item_get_submenu (GTK_MENU_ITEM (item)))
{
sensitive = area_is_sensitive (priv->area);
@ -1100,6 +1102,7 @@ gtk_tree_menu_create_item (GtkTreeMenu *menu,
if (is_separator)
{
item = gtk_separator_menu_item_new ();
gtk_widget_show (item);
g_object_set_qdata_full (G_OBJECT (item),
tree_menu_path_quark,
@ -1138,9 +1141,8 @@ gtk_tree_menu_create_item (GtkTreeMenu *menu,
priv->header_data,
priv->header_destroy);
gtk_tree_menu_set_model (GTK_TREE_MENU (submenu), priv->model);
gtk_tree_menu_set_model_internal (GTK_TREE_MENU (submenu), priv->model);
gtk_tree_menu_set_root (GTK_TREE_MENU (submenu), path);
gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), submenu);
g_signal_connect (submenu, "menu-activate",
@ -1274,44 +1276,15 @@ submenu_activated_cb (GtkTreeMenu *submenu,
g_signal_emit (menu, tree_menu_signals[SIGNAL_MENU_ACTIVATE], 0, path);
}
/****************************************************************
* API *
****************************************************************/
GtkWidget *
gtk_tree_menu_new (void)
{
return (GtkWidget *)g_object_new (GTK_TYPE_TREE_MENU, NULL);
}
GtkWidget *
gtk_tree_menu_new_with_area (GtkCellArea *area)
{
return (GtkWidget *)g_object_new (GTK_TYPE_TREE_MENU,
"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);
}
void
gtk_tree_menu_set_model (GtkTreeMenu *menu,
GtkTreeModel *model)
/* Sets the model without rebuilding the menu, prevents
* infinite recursion while building submenus (we wait
* until the root is set and then build the menu) */
static void
gtk_tree_menu_set_model_internal (GtkTreeMenu *menu,
GtkTreeModel *model)
{
GtkTreeMenuPrivate *priv;
g_return_if_fail (GTK_IS_TREE_MENU (menu));
g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
priv = menu->priv;
if (priv->model != model)
@ -1354,6 +1327,47 @@ gtk_tree_menu_set_model (GtkTreeMenu *menu,
}
}
/****************************************************************
* API *
****************************************************************/
GtkWidget *
gtk_tree_menu_new (void)
{
return (GtkWidget *)g_object_new (GTK_TYPE_TREE_MENU, NULL);
}
GtkWidget *
gtk_tree_menu_new_with_area (GtkCellArea *area)
{
return (GtkWidget *)g_object_new (GTK_TYPE_TREE_MENU,
"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);
}
void
gtk_tree_menu_set_model (GtkTreeMenu *menu,
GtkTreeModel *model)
{
g_return_if_fail (GTK_IS_TREE_MENU (menu));
g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
gtk_tree_menu_set_model_internal (menu, model);
rebuild_menu (menu);
}
GtkTreeModel *
gtk_tree_menu_get_model (GtkTreeMenu *menu)
{