[gtk/tabular-menus: 7/9] tree menu: Drop support for grids



commit a65f5c2e732dc19360569a6c6f9ac54c7b712de6
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Jan 23 23:20:22 2019 -0500

    tree menu: Drop support for grids
    
    This was only used in GtkComboBox, and it no longer
    supports grids,

 gtk/gtktreemenu.c | 407 ++++--------------------------------------------------
 1 file changed, 26 insertions(+), 381 deletions(-)
---
diff --git a/gtk/gtktreemenu.c b/gtk/gtktreemenu.c
index 80db15419f..f3f728f9ee 100644
--- a/gtk/gtktreemenu.c
+++ b/gtk/gtktreemenu.c
@@ -73,15 +73,6 @@ static GtkCellArea *gtk_tree_menu_cell_layout_get_area        (GtkCellLayout
 
 /* TreeModel/DrawingArea callbacks and building menus/submenus */
 static inline void rebuild_menu                               (GtkTreeMenu          *menu);
-static gboolean   menu_occupied                               (GtkTreeMenu          *menu,
-                                                               guint                 left_attach,
-                                                               guint                 right_attach,
-                                                               guint                 top_attach,
-                                                               guint                 bottom_attach);
-static void       relayout_item                               (GtkTreeMenu          *menu,
-                                                               GtkWidget            *item,
-                                                               GtkTreeIter          *iter,
-                                                               GtkWidget            *prev);
 static void       gtk_tree_menu_populate                      (GtkTreeMenu          *menu);
 static GtkWidget *gtk_tree_menu_create_item                   (GtkTreeMenu          *menu,
                                                                GtkTreeIter          *iter,
@@ -149,11 +140,6 @@ struct _GtkTreeMenuPrivate
   gulong               row_reordered_id;
   gulong               row_changed_id;
 
-  /* Grid menu mode */
-  gint                 wrap_width;
-  gint                 row_span_col;
-  gint                 col_span_col;
-
   /* Flags */
   guint32              menu_with_header : 1;
 
@@ -167,10 +153,7 @@ enum {
   PROP_0,
   PROP_MODEL,
   PROP_ROOT,
-  PROP_CELL_AREA,
-  PROP_WRAP_WIDTH,
-  PROP_ROW_SPAN_COL,
-  PROP_COL_SPAN_COL
+  PROP_CELL_AREA
 };
 
 enum {
@@ -190,8 +173,6 @@ static void
 _gtk_tree_menu_init (GtkTreeMenu *menu)
 {
   menu->priv = _gtk_tree_menu_get_instance_private (menu);
-  menu->priv->row_span_col = -1;
-  menu->priv->col_span_col = -1;
 
   gtk_menu_set_reserve_toggle_size (GTK_MENU (menu), FALSE);
 }
@@ -281,59 +262,6 @@ _gtk_tree_menu_class_init (GtkTreeMenuClass *class)
                                                         P_("The GtkCellArea used to layout cells"),
                                                         GTK_TYPE_CELL_AREA,
                                                         GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
-
-  /*
-   * GtkTreeMenu:wrap-width:
-   *
-   * If wrap-width is set to a positive value, items in the popup will be laid
-   * out along multiple columns, starting a new row on reaching the wrap width.
-   */
-  g_object_class_install_property (object_class,
-                                   PROP_WRAP_WIDTH,
-                                   g_param_spec_int ("wrap-width",
-                                                     P_("Wrap Width"),
-                                                     P_("Wrap width for laying out items in a grid"),
-                                                     0,
-                                                     G_MAXINT,
-                                                     0,
-                                                     GTK_PARAM_READWRITE));
-
-  /*
-   * GtkTreeMenu:row-span-column:
-   *
-   * If this is set to a non-negative value, it must be the index of a column
-   * of type %G_TYPE_INT in the model. The value in that column for each item
-   * will determine how many rows that item will span in the popup. Therefore,
-   * values in this column must be greater than zero.
-   */
-  g_object_class_install_property (object_class,
-                                   PROP_ROW_SPAN_COL,
-                                   g_param_spec_int ("row-span-column",
-                                                     P_("Row span column"),
-                                                     P_("TreeModel column containing the row span values"),
-                                                     -1,
-                                                     G_MAXINT,
-                                                     -1,
-                                                     GTK_PARAM_READWRITE));
-
-  /*
-   * GtkTreeMenu:column-span-column:
-   *
-   * If this is set to a non-negative value, it must be the index of a column
-   * of type %G_TYPE_INT in the model. The value in that column for each item
-   * will determine how many columns that item will span in the popup.
-   * Therefore, values in this column must be greater than zero, and the sum of
-   * an item’s column position + span should not exceed #GtkTreeMenu:wrap-width.
-   */
-  g_object_class_install_property (object_class,
-                                   PROP_COL_SPAN_COL,
-                                   g_param_spec_int ("column-span-column",
-                                                     P_("Column span column"),
-                                                     P_("TreeModel column containing the column span 
values"),
-                                                     -1,
-                                                     G_MAXINT,
-                                                     -1,
-                                                     GTK_PARAM_READWRITE));
 }
 
 /****************************************************************
@@ -426,18 +354,6 @@ gtk_tree_menu_set_property (GObject            *object,
       gtk_tree_menu_set_area (menu, (GtkCellArea *)g_value_get_object (value));
       break;
 
-    case PROP_WRAP_WIDTH:
-      _gtk_tree_menu_set_wrap_width (menu, g_value_get_int (value));
-      break;
-
-     case PROP_ROW_SPAN_COL:
-      _gtk_tree_menu_set_row_span_column (menu, g_value_get_int (value));
-      break;
-
-     case PROP_COL_SPAN_COL:
-      _gtk_tree_menu_set_column_span_column (menu, g_value_get_int (value));
-      break;
-
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -773,26 +689,21 @@ row_inserted_cb (GtkTreeModel     *model,
   /* If the iter should be in this menu then go ahead and insert it */
   if (gtk_tree_menu_path_in_menu (menu, path, NULL))
     {
-      if (priv->wrap_width > 0)
-        rebuild_menu (menu);
-      else
-        {
-          /* Get the index of the path for this depth */
-          indices = gtk_tree_path_get_indices (path);
-          depth   = gtk_tree_path_get_depth (path);
-          index   = indices[depth -1];
+      /* Get the index of the path for this depth */
+      indices = gtk_tree_path_get_indices (path);
+      depth   = gtk_tree_path_get_depth (path);
+      index   = indices[depth -1];
 
-          /* Menus with a header include a menuitem for its root node
-           * and a separator menu item */
-          if (priv->menu_with_header)
-            index += 2;
+      /* Menus with a header include a menuitem for its root node
+       * and a separator menu item */
+      if (priv->menu_with_header)
+        index += 2;
 
-          item = gtk_tree_menu_create_item (menu, iter, FALSE);
-          gtk_menu_shell_insert (GTK_MENU_SHELL (menu), item, index);
+      item = gtk_tree_menu_create_item (menu, iter, FALSE);
+      gtk_menu_shell_insert (GTK_MENU_SHELL (menu), item, index);
 
-          /* Resize everything */
-          gtk_cell_area_context_reset (menu->priv->context);
-        }
+      /* Resize everything */
+      gtk_cell_area_context_reset (menu->priv->context);
     }
   else
     {
@@ -814,7 +725,6 @@ row_deleted_cb (GtkTreeModel     *model,
                 GtkTreePath      *path,
                 GtkTreeMenu      *menu)
 {
-  GtkTreeMenuPrivate *priv = menu->priv;
   GtkWidget          *item;
 
   /* If it's the header item we leave it to the parent menu
@@ -824,16 +734,11 @@ row_deleted_cb (GtkTreeModel     *model,
 
   if (item)
     {
-      if (priv->wrap_width > 0)
-        rebuild_menu (menu);
-      else
-        {
-          /* Get rid of the deleted item */
-          gtk_widget_destroy (item);
+      /* Get rid of the deleted item */
+      gtk_widget_destroy (item);
 
-          /* Resize everything */
-          gtk_cell_area_context_reset (menu->priv->context);
-        }
+      /* Resize everything */
+      gtk_cell_area_context_reset (menu->priv->context);
     }
   else
     {
@@ -920,27 +825,16 @@ row_changed_cb (GtkTreeModel         *model,
 
   if (item)
     {
-      if (priv->wrap_width > 0)
-        /* Ugly, we need to rebuild the menu here if
-         * the row-span/row-column values change
-         */
-        rebuild_menu (menu);
-      else
-        {
-          if (priv->row_separator_func)
-            is_separator =
-              priv->row_separator_func (model, iter,
-                                        priv->row_separator_data);
+      if (priv->row_separator_func)
+        is_separator = priv->row_separator_func (model, iter, priv->row_separator_data);
 
+      if (is_separator != GTK_IS_SEPARATOR_MENU_ITEM (item))
+        {
+          gint position = menu_item_position (menu, item);
 
-          if (is_separator != GTK_IS_SEPARATOR_MENU_ITEM (item))
-            {
-              gint position = menu_item_position (menu, item);
-
-              gtk_widget_destroy (item);
-              item = gtk_tree_menu_create_item (menu, iter, FALSE);
-              gtk_menu_shell_insert (GTK_MENU_SHELL (menu), item, position);
-            }
+          gtk_widget_destroy (item);
+          item = gtk_tree_menu_create_item (menu, iter, FALSE);
+          gtk_menu_shell_insert (GTK_MENU_SHELL (menu), item, position);
         }
     }
 }
@@ -1053,93 +947,6 @@ gtk_tree_menu_set_area (GtkTreeMenu *menu,
     }
 }
 
-static gboolean
-menu_occupied (GtkTreeMenu *menu,
-               guint        left_attach,
-               guint        right_attach,
-               guint        top_attach,
-               guint        bottom_attach)
-{
-  GList *i;
-
-  for (i = GTK_MENU_SHELL (menu)->priv->children; i; i = i->next)
-    {
-      guint l, r, b, t;
-
-      gtk_container_child_get (GTK_CONTAINER (menu),
-                               i->data,
-                               "left-attach", &l,
-                               "right-attach", &r,
-                               "bottom-attach", &b,
-                               "top-attach", &t,
-                               NULL);
-
-      /* look if this item intersects with the given coordinates */
-      if (right_attach > l && left_attach < r && bottom_attach > t && top_attach < b)
-        return TRUE;
-    }
-
-  return FALSE;
-}
-
-static void
-relayout_item (GtkTreeMenu *menu,
-               GtkWidget   *item,
-               GtkTreeIter *iter,
-               GtkWidget   *prev)
-{
-  GtkTreeMenuPrivate *priv = menu->priv;
-  gint                current_col = 0, current_row = 0;
-  gint                rows = 1, cols = 1;
-
-  if (priv->col_span_col == -1 &&
-      priv->row_span_col == -1 &&
-      prev)
-    {
-      gtk_container_child_get (GTK_CONTAINER (menu), prev,
-                               "right-attach", &current_col,
-                               "top-attach", &current_row,
-                               NULL);
-      if (current_col + cols > priv->wrap_width)
-        {
-          current_col = 0;
-          current_row++;
-        }
-    }
-  else
-    {
-      if (priv->col_span_col != -1)
-        gtk_tree_model_get (priv->model, iter,
-                            priv->col_span_col, &cols,
-                            -1);
-      if (priv->row_span_col != -1)
-        gtk_tree_model_get (priv->model, iter,
-                            priv->row_span_col, &rows,
-                            -1);
-
-      while (1)
-        {
-          if (current_col + cols > priv->wrap_width)
-            {
-              current_col = 0;
-              current_row++;
-            }
-
-          if (!menu_occupied (menu,
-                              current_col, current_col + cols,
-                              current_row, current_row + rows))
-            break;
-
-          current_col++;
-        }
-    }
-
-  /* set attach props */
-  gtk_menu_attach (GTK_MENU (menu), item,
-                   current_col, current_col + cols,
-                   current_row, current_row + rows);
-}
-
 static void
 gtk_tree_menu_create_submenu (GtkTreeMenu *menu,
                               GtkWidget   *item,
@@ -1159,10 +966,6 @@ gtk_tree_menu_create_submenu (GtkTreeMenu *menu,
                                          priv->row_separator_data,
                                          priv->row_separator_destroy);
 
-  _gtk_tree_menu_set_wrap_width (GTK_TREE_MENU (submenu), priv->wrap_width);
-  _gtk_tree_menu_set_row_span_column (GTK_TREE_MENU (submenu), priv->row_span_col);
-  _gtk_tree_menu_set_column_span_column (GTK_TREE_MENU (submenu), priv->col_span_col);
-
   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);
@@ -1243,7 +1046,7 @@ gtk_tree_menu_populate (GtkTreeMenu *menu)
   GtkTreeIter         parent;
   GtkTreeIter         iter;
   gboolean            valid = FALSE;
-  GtkWidget          *menu_item, *prev = NULL;
+  GtkWidget          *menu_item;
 
   if (!priv->model)
     return;
@@ -1271,10 +1074,6 @@ gtk_tree_menu_populate (GtkTreeMenu *menu)
 
       gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
 
-      if (priv->wrap_width > 0)
-        relayout_item (menu, menu_item, &iter, prev);
-
-      prev  = menu_item;
       valid = gtk_tree_model_iter_next (priv->model, &iter);
     }
 }
@@ -1510,160 +1309,6 @@ _gtk_tree_menu_get_root (GtkTreeMenu *menu)
   return NULL;
 }
 
-/*
- * _gtk_tree_menu_get_wrap_width:
- * @menu: a #GtkTreeMenu
- *
- * Gets the wrap width which is used to determine the number of columns
- * for @menu. If the wrap width is larger than 1, @menu is in table mode.
- *
- * Returns: the wrap width.
- */
-gint
-_gtk_tree_menu_get_wrap_width (GtkTreeMenu *menu)
-{
-  GtkTreeMenuPrivate *priv;
-
-  g_return_val_if_fail (GTK_IS_TREE_MENU (menu), FALSE);
-
-  priv = menu->priv;
-
-  return priv->wrap_width;
-}
-
-/*
- * _gtk_tree_menu_set_wrap_width:
- * @menu: a #GtkTreeMenu
- * @width: the wrap width
- *
- * Sets the wrap width which is used to determine the number of columns
- * for @menu. If the wrap width is larger than 1, @menu is in table mode.
- */
-void
-_gtk_tree_menu_set_wrap_width (GtkTreeMenu *menu,
-                               gint         width)
-{
-  GtkTreeMenuPrivate *priv;
-
-  g_return_if_fail (GTK_IS_TREE_MENU (menu));
-  g_return_if_fail (width >= 0);
-
-  priv = menu->priv;
-
-  if (priv->wrap_width != width)
-    {
-      priv->wrap_width = width;
-
-      rebuild_menu (menu);
-
-      g_object_notify (G_OBJECT (menu), "wrap-width");
-    }
-}
-
-/*
- * _gtk_tree_menu_get_row_span_column:
- * @menu: a #GtkTreeMenu
- *
- * Gets the column with row span information for @menu.
- * The row span column contains integers which indicate how many rows
- * a menu item should span.
- *
- * Returns: the column in @menu’s model containing row span information, or -1.
- */
-gint
-_gtk_tree_menu_get_row_span_column (GtkTreeMenu *menu)
-{
-  GtkTreeMenuPrivate *priv;
-
-  g_return_val_if_fail (GTK_IS_TREE_MENU (menu), FALSE);
-
-  priv = menu->priv;
-
-  return priv->row_span_col;
-}
-
-/*
- * _gtk_tree_menu_set_row_span_column:
- * @menu: a #GtkTreeMenu
- * @row_span: the column in the model to fetch the row span for a given menu item.
- *
- * Sets the column with row span information for @menu to be @row_span.
- * The row span column contains integers which indicate how many rows
- * a menu item should span.
- */
-void
-_gtk_tree_menu_set_row_span_column (GtkTreeMenu *menu,
-                                    gint         row_span)
-{
-  GtkTreeMenuPrivate *priv;
-
-  g_return_if_fail (GTK_IS_TREE_MENU (menu));
-
-  priv = menu->priv;
-
-  if (priv->row_span_col != row_span)
-    {
-      priv->row_span_col = row_span;
-
-      if (priv->wrap_width > 0)
-        rebuild_menu (menu);
-
-      g_object_notify (G_OBJECT (menu), "row-span-column");
-    }
-}
-
-/*
- * _gtk_tree_menu_get_column_span_column:
- * @menu: a #GtkTreeMenu
- *
- * Gets the column with column span information for @menu.
- * The column span column contains integers which indicate how many columns
- * a menu item should span.
- *
- * Returns: the column in @menu’s model containing column span information, or -1.
- */
-gint
-_gtk_tree_menu_get_column_span_column (GtkTreeMenu *menu)
-{
-  GtkTreeMenuPrivate *priv;
-
-  g_return_val_if_fail (GTK_IS_TREE_MENU (menu), FALSE);
-
-  priv = menu->priv;
-
-  return priv->col_span_col;
-}
-
-/*
- * _gtk_tree_menu_set_column_span_column:
- * @menu: a #GtkTreeMenu
- * @column_span: the column in the model to fetch the column span for a given menu item.
- *
- * Sets the column with column span information for @menu to be @column_span.
- * The column span column contains integers which indicate how many columns
- * a menu item should span.
- */
-void
-_gtk_tree_menu_set_column_span_column (GtkTreeMenu *menu,
-                                       gint         column_span)
-{
-  GtkTreeMenuPrivate *priv;
-
-  g_return_if_fail (GTK_IS_TREE_MENU (menu));
-
-  priv = menu->priv;
-
-  if (priv->col_span_col != column_span)
-    {
-      priv->col_span_col = column_span;
-
-      if (priv->wrap_width > 0)
-        rebuild_menu (menu);
-
-      g_object_notify (G_OBJECT (menu), "column-span-column");
-    }
-}
-
 /*
  * _gtk_tree_menu_get_row_separator_func:
  * @menu: a #GtkTreeMenu


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]