From 1ede92afa143c7f84cdb9f0b17a7e27118c727e6 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 9 May 2021 00:15:12 +0200 Subject: [PATCH 1/2] Use temporary variable in gtk_dataview_button_press_callback() No real changes, just simplify the code a bit by using a local variable instead of repeating the same expression a couple of times. --- src/gtk/dataview.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/gtk/dataview.cpp b/src/gtk/dataview.cpp index 81de210a39..276e9f4e36 100644 --- a/src/gtk/dataview.cpp +++ b/src/gtk/dataview.cpp @@ -4662,13 +4662,15 @@ gtk_dataview_button_press_callback( GtkWidget *WXUNUSED(widget), { if ((gdk_event->button == 3) && (gdk_event->type == GDK_BUTTON_PRESS)) { + GtkTreeView* const treeview = GTK_TREE_VIEW(dv->GtkGetTreeView()); + wxGtkTreePath path; GtkTreeViewColumn *column = NULL; gint cell_x = 0; gint cell_y = 0; gtk_tree_view_get_path_at_pos ( - GTK_TREE_VIEW(dv->GtkGetTreeView()), + treeview, (int) gdk_event->x, (int) gdk_event->y, path.ByRef(), &column, @@ -4681,7 +4683,7 @@ gtk_dataview_button_press_callback( GtkWidget *WXUNUSED(widget), // because it could be a part of multi-item selection. if ( path ) { - GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dv->GtkGetTreeView())); + GtkTreeSelection *selection = gtk_tree_view_get_selection(treeview); if ( !gtk_tree_selection_path_is_selected(selection, path) ) { gtk_tree_selection_unselect_all(selection); From 07459e8f2f468619513482685a0be7bc4396e0b9 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 9 May 2021 00:15:48 +0200 Subject: [PATCH 2/2] Avoid bogus context menu events in wxGTK wxDataViewCtrl Right clicking on the column header shouldn't generate context menu events, but it did because our gtk_dataview_button_press_callback() got these events for both the "bin" window, containing the items, and the "header" window. Fix this by filtering out the events not sent to the right window. It would be even better to not get these events in the first place, i.e. somehow not connect to them in the first place, but it's not clear how to do this, so settle for this solution for now. For testing this fix, just right click any column in the dataview sample: previously this generated both messages about the column header right click and the context menu in wxGTK, while now it only generates the former, as in the generic version. --- src/gtk/dataview.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/gtk/dataview.cpp b/src/gtk/dataview.cpp index 276e9f4e36..8ffa7b7b3b 100644 --- a/src/gtk/dataview.cpp +++ b/src/gtk/dataview.cpp @@ -4664,6 +4664,13 @@ gtk_dataview_button_press_callback( GtkWidget *WXUNUSED(widget), { GtkTreeView* const treeview = GTK_TREE_VIEW(dv->GtkGetTreeView()); + // Surprisingly, we can get the events not only from the "bin" window, + // containing the items, but also from the window containing the column + // headers, and we're not interested in them here, we already generate + // wxEVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK for them, so just ignore. + if (gdk_event->window != gtk_tree_view_get_bin_window(treeview)) + return FALSE; + wxGtkTreePath path; GtkTreeViewColumn *column = NULL; gint cell_x = 0;