[gtk+/gtk-3-22] ComboBox: list: Fix expanding/collapsing tree rows



commit a20ff44b09d62d0fd3e36a242a7a68a60553909b
Author: Daniel Boles <dboles src gnome org>
Date:   Wed Oct 4 18:54:43 2017 +0100

    ComboBox: list: Fix expanding/collapsing tree rows
    
    On clicking release, we call TreeView.get_path_at_pos() &, if we hit a
    row, select it (if sensitive) & close the popup. But this alone does
    not account for clicks on the expanders within the TreeView, so in
    addition to expanding/collapsing, clicking them would close the list.
    
    Check if the click is in the cell_area() & thus “excluding surrounding
    borders and the tree expander area” but still including the background
    (which TreeView.is_blank_at_pos() doesn’t); if TRUE, don’t select/close.
    
    The popup doesn’t always resize enough… so there’s still breakage here.
    The XXX comment on TreeView requests in list_position() may be relevant
    to this. But at least this drags such CBs one step closer to adequacy:
    expanding by mouse now works ~no worse~ than by keyboard already did.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=788505

 gtk/gtkcombobox.c |   15 ++++++++++++---
 1 files changed, 12 insertions(+), 3 deletions(-)
---
diff --git a/gtk/gtkcombobox.c b/gtk/gtkcombobox.c
index 1f79e6f..4c3682a 100644
--- a/gtk/gtkcombobox.c
+++ b/gtk/gtkcombobox.c
@@ -3129,6 +3129,9 @@ gtk_combo_box_list_button_released (GtkWidget      *widget,
   gboolean ret;
   GtkTreePath *path = NULL;
   GtkTreeIter iter;
+  GtkTreeViewColumn *column;
+  gint x;
+  GdkRectangle cell_area;
 
   GtkComboBox *combo_box = GTK_COMBO_BOX (data);
   GtkComboBoxPrivate *priv = combo_box->priv;
@@ -3177,15 +3180,21 @@ gtk_combo_box_list_button_released (GtkWidget      *widget,
       return FALSE;
     }
 
-  /* select something cool */
+  /* Determine which row was clicked and which column therein */
   ret = gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (priv->tree_view),
                                        event->x, event->y,
-                                       &path,
-                                       NULL, NULL, NULL);
+                                       &path, &column,
+                                       &x, NULL);
 
   if (!ret)
     return TRUE; /* clicked outside window? */
 
+  /* Don’t select/close after clicking row’s expander. cell_area excludes that */
+  gtk_tree_view_get_cell_area (GTK_TREE_VIEW (priv->tree_view),
+                               path, column, &cell_area);
+  if (x < cell_area.x || x >= cell_area.x + cell_area.width)
+    return TRUE;
+
   gtk_tree_model_get_iter (priv->model, &iter, path);
 
   /* Use iter before popdown, as mis-users like GtkFileChooserButton alter the


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