From 2d18aaf58a1b5c6d6fe9960f282d478e392a5c31 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 6 Dec 2018 20:48:32 +0100 Subject: [PATCH 1/3] Move check for mouse button down events in wxDataViewMainWindow No real changes, just prepare for the next commit. --- src/generic/datavgen.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index 448a58bf5b..f5c60b3953 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -4525,14 +4525,6 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event ) return; } - if(event.ButtonDown()) - { - // Not skipping button down events would prevent the system from - // setting focus to this window as most (all?) of them do by default, - // so skip it to enable default handling. - event.Skip(); - } - int x = event.GetX(); int y = event.GetY(); m_owner->CalcUnscrolledPosition( x, y, &x, &y ); @@ -4560,6 +4552,14 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event ) const unsigned int current = GetLineAt( y ); const wxDataViewItem item = GetItemByRow(current); + if(event.ButtonDown()) + { + // Not skipping button down events would prevent the system from + // setting focus to this window as most (all?) of them do by default, + // so skip it to enable default handling. + event.Skip(); + } + // Handle right clicking here, before everything else as context menu // events should be sent even when we click outside of any item, unlike all // the other ones. From da612f02b5a8f2a8a8f8832dd12edd5a199cb066 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 6 Dec 2018 22:53:28 +0100 Subject: [PATCH 2/3] Stop editing in generic wxDataViewCtrl when any button is pressed Previously, the editor was hidden if the left mouse button was pressed, but not for the right (or any other) button, which could result in a confusing situation when a user could select a command from a context menu shown from the corresponding event handler and start editing another item while the current one was still being edited too. --- src/generic/datavgen.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index f5c60b3953..f94700b072 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -4558,6 +4558,12 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event ) // setting focus to this window as most (all?) of them do by default, // so skip it to enable default handling. event.Skip(); + + // Also stop editing if any mouse button is pressed: this is not really + // necessary for the left button, as it would result in a focus loss + // that would make the editor close anyhow, but we do need to do it for + // the other ones and it does no harm to do it for the left one too. + FinishEditing(); } // Handle right clicking here, before everything else as context menu From dc1aa3097c15868d124b947fae7b5dc91f350edc Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 6 Dec 2018 22:55:42 +0100 Subject: [PATCH 3/3] Avoid warnings on right click in GTK wxDataViewCtrl while editing The code handling right button click used the path of the item under mouse without checking if there was any item, resulting in GTK+ warnings due to the use of an invalid item. Simply add a check for the item validity: we definitely don't want to select it if it's invalid anyhow. --- src/gtk/dataview.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/gtk/dataview.cpp b/src/gtk/dataview.cpp index d2c1abf352..6a7811cf1d 100644 --- a/src/gtk/dataview.cpp +++ b/src/gtk/dataview.cpp @@ -4591,11 +4591,14 @@ gtk_dataview_button_press_callback( GtkWidget *WXUNUSED(widget), // If the right click is on an item that isn't selected, select it, as is // commonly done. Do not do it if the item under mouse is already selected, // because it could be a part of multi-item selection. - GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dv->GtkGetTreeView())); - if ( !gtk_tree_selection_path_is_selected(selection, path) ) + if ( path ) { - gtk_tree_selection_unselect_all(selection); - gtk_tree_selection_select_path(selection, path); + GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dv->GtkGetTreeView())); + if ( !gtk_tree_selection_path_is_selected(selection, path) ) + { + gtk_tree_selection_unselect_all(selection); + gtk_tree_selection_select_path(selection, path); + } } wxDataViewEvent