Make sure all users of GtkCMCList do not blindly assume that a button-press-event...
authorAndrej Kacian <ticho@claws-mail.org>
Mon, 5 Nov 2018 23:05:17 +0000 (00:05 +0100)
committerAndrej Kacian <ticho@claws-mail.org>
Mon, 5 Nov 2018 23:05:17 +0000 (00:05 +0100)
If clicking on the header row, the event's x,y coordinates
were pointing to a different spot than what the event handler
code expected, since those coordinates are relative to the
relevant GDK window, and header row has its own. Calls to
gtk_cmclist_get_selection_info() or gtk_sctree_is_hot_spot()
in such cases therefore returned bogus info.

This fixes things like folderview expanding/collapsing
selected folder when double-clicking its header column, or
selecting first row when single-clicking it.

src/addressbook.c
src/editgroup.c
src/folderview.c
src/grouplistdialog.c
src/gtk/gtkcmctree.h
src/gtk/gtksctree.h
src/summaryview.c

index 6592385..3c95609 100644 (file)
@@ -2482,6 +2482,7 @@ static gboolean addressbook_list_button_pressed(GtkWidget *widget,
                                                gpointer data)
 {
        if( ! event ) return FALSE;
+       if( event->window != GTK_CMCLIST(widget)->clist_window ) return FALSE;
 
        addressbook_list_menu_setup();
 
@@ -2539,6 +2540,9 @@ static gboolean addressbook_tree_button_pressed(GtkWidget *ctree,
        if( ! event ) return FALSE;
 /*     if( ! event || event->type != GDK_BUTTON_PRESS) return FALSE;*/
 
+       if( event->window != clist->clist_window )
+               return FALSE;
+
        if (event->button == 1) {
                if (event->type == GDK_2BUTTON_PRESS) {
                        if( gtk_cmclist_get_selection_info( clist, event->x, event->y, &row, &column ) ) {
index 21e77f2..22f16a8 100644 (file)
@@ -215,6 +215,7 @@ static void edit_group_to_avail( GtkWidget *widget, gpointer data ) {
 
 static gboolean edit_group_list_group_button( GtkCMCList *clist, GdkEventButton *event, gpointer data ) {
        if( ! event ) return FALSE;
+       if( event->window != clist->clist_window ) return FALSE;
 
        if( event->button == 1 ) {
                if( event->type == GDK_2BUTTON_PRESS ) {
@@ -226,6 +227,7 @@ static gboolean edit_group_list_group_button( GtkCMCList *clist, GdkEventButton
 
 static gboolean edit_group_list_avail_button( GtkCMCList *clist, GdkEventButton *event, gpointer data ) {
        if( ! event ) return FALSE;
+       if( event->window != clist->clist_window ) return FALSE;
 
        if( event->button == 1 ) {
                if( event->type == GDK_2BUTTON_PRESS ) {
index 63cabc2..2679320 100644 (file)
@@ -2023,6 +2023,7 @@ static gboolean folderview_button_pressed(GtkWidget *ctree, GdkEventButton *even
        gint prev_row = -1, row = -1, column = -1;
 
        if (!event) return FALSE;
+       if (event->window != clist->clist_window) return FALSE;
 
        if (event->button == 1 || event->button == 2) {
                if (!gtk_sctree_is_hot_spot (GTK_SCTREE(clist), event->x, event->y))
index 9ff8b25..429e57e 100644 (file)
@@ -565,6 +565,7 @@ static gboolean button_press_cb(GtkCMCTree *ctree, GdkEventButton *button,
 
        if (button->type != GDK_BUTTON_PRESS) return TRUE;
        if (button->button != 1) return TRUE;
+       if (button->window != GTK_CMCLIST(ctree)->clist_window) return TRUE;
 
        if (!gtk_cmclist_get_selection_info(GTK_CMCLIST(ctree), 
                                     button->x, button->y, &row, &col))
index 54a0235..07b8ea1 100644 (file)
@@ -253,6 +253,10 @@ GList * gtk_cmctree_find_all_by_row_data_custom    (GtkCMCTree     *ctree,
                                                  GtkCMCTreeNode *node,
                                                  gpointer      data,
                                                  GCompareFunc  func);
+
+/* This assumes that x and y coordinates are inside the clist_window.
+ * Returns true if the coordinates are inside a tree expander on
+ * one of the rows. */
 gboolean gtk_cmctree_is_hot_spot                   (GtkCMCTree     *ctree,
                                                  gint          x,
                                                  gint          y);
index b310f96..79b4f2f 100644 (file)
@@ -119,6 +119,10 @@ void gtk_sctree_set_column_tooltip     (GtkSCTree          *sctree,
 void gtk_sctree_set_use_markup             (GtkSCTree          *sctree,
                                             int                 column,
                                             gboolean            markup);
+
+/* This assumes that x and y coordinates are inside the clist_window.
+ * Returns true if the coordinates are inside a tree expander on
+ * one of the rows. */
 gboolean
 gtk_sctree_is_hot_spot (GtkSCTree *ctree, 
                       gint      x, 
index 2bc9e05..e4976bf 100644 (file)
@@ -6846,6 +6846,7 @@ static gboolean summary_button_pressed(GtkWidget *ctree, GdkEventButton *event,
                                       SummaryView *summaryview)
 {
        if (!event) return FALSE;
+       if (event->window != GTK_CMCLIST(ctree)->clist_window) return FALSE;
 
        if (event->button == 3) {
                /* right clicked */