From 5e513780edd2dfb86c2c32a13d02c789b7de04ae Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Wed, 15 Nov 2006 08:59:50 +0000 Subject: [PATCH] Check if DnD is started from a mouse event. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@43429 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/gtk/dnd.cpp | 49 ++++++++++++++++++++++++++-------------------- src/gtk/window.cpp | 15 ++++++++++---- 2 files changed, 39 insertions(+), 25 deletions(-) diff --git a/src/gtk/dnd.cpp b/src/gtk/dnd.cpp index 6424b24ee5..2a147ae682 100644 --- a/src/gtk/dnd.cpp +++ b/src/gtk/dnd.cpp @@ -39,14 +39,17 @@ extern bool g_blockEventsOnDrag; // the flags used for the last DoDragDrop() static long gs_flagsForDrag = 0; +#ifdef __WXDEBUG__ // the trace mask we use with wxLogTrace() - call // wxLog::AddTraceMask(TRACE_DND) to enable the trace messages from here // (there are quite a few of them, so don't enable this by default) static const wxChar *TRACE_DND = _T("dnd"); +#endif +// global variables because GTK+ DnD want to have the +// mouse event that caused it extern GdkEvent *g_lastMouseEvent; - -extern int g_lastButtonNumber; +extern int g_lastButtonNumber; //---------------------------------------------------------------------------- // standard icons @@ -835,6 +838,14 @@ wxDragResult wxDropSource::DoDragDrop(int flags) if (g_blockEventsOnDrag) return wxDragNone; + // don't start dragging if no button is down + if (g_lastButtonNumber == 0) + return wxDragNone; + + // we can only start a drag after a mouse event + if (g_lastMouseEvent == NULL) + return wxDragNone; + // disabled for now g_blockEventsOnDrag = true; @@ -855,35 +866,31 @@ wxDragResult wxDropSource::DoDragDrop(int flags) } delete[] array; - /* don't start dragging if no button is down */ - if (g_lastButtonNumber) - { - int action = GDK_ACTION_COPY; - if ( flags & wxDrag_AllowMove ) - action |= GDK_ACTION_MOVE; + int action = GDK_ACTION_COPY; + if ( flags & wxDrag_AllowMove ) + action |= GDK_ACTION_MOVE; - // VZ: as we already use g_blockEventsOnDrag it shouldn't be that bad - // to use a global to pass the flags to the drop target but I'd - // surely prefer a better way to do it - gs_flagsForDrag = flags; + // VZ: as we already use g_blockEventsOnDrag it shouldn't be that bad + // to use a global to pass the flags to the drop target but I'd + // surely prefer a better way to do it + gs_flagsForDrag = flags; - GdkDragContext *context = gtk_drag_begin( m_widget, + GdkDragContext *context = gtk_drag_begin( m_widget, target_list, (GdkDragAction)action, g_lastButtonNumber, // number of mouse button which started drag (GdkEvent*) g_lastMouseEvent ); - m_dragContext = context; + m_dragContext = context; - PrepareIcon( action, context ); + PrepareIcon( action, context ); - while (m_waiting) - gtk_main_iteration(); + while (m_waiting) + gtk_main_iteration(); - m_retValue = ConvertFromGTK(context->action); - if ( m_retValue == wxDragNone ) - m_retValue = wxDragCancel; - } + m_retValue = ConvertFromGTK(context->action); + if ( m_retValue == wxDragNone ) + m_retValue = wxDragCancel; g_blockEventsOnDrag = false; diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index a772737691..e8851e90a4 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -210,9 +210,10 @@ wxWindowGTK *g_focusWindowLast = (wxWindowGTK*) NULL; // yet, defer setting the focus to idle time. wxWindowGTK *g_delayedFocus = (wxWindowGTK*) NULL; -// Save the last mouse event for drag start -GdkEvent *g_lastMouseEvent = (GdkEvent*) NULL; -int g_lastButtonNumber = 0; +// global variables because GTK+ DnD want to have the +// mouse event that caused it +GdkEvent *g_lastMouseEvent = (GdkEvent*) NULL; +int g_lastButtonNumber = 0; extern bool g_mainThreadLocked; @@ -1607,8 +1608,10 @@ gtk_window_button_press_callback( GtkWidget *widget, if (win->GTKProcessEvent( event )) { + g_lastMouseEvent = NULL; return TRUE; } + g_lastMouseEvent = NULL; if (event_type == wxEVT_RIGHT_DOWN) { @@ -1749,7 +1752,11 @@ gtk_window_motion_notify_callback( GtkWidget *widget, } } - return win->GTKProcessEvent(event); + bool ret = win->GTKProcessEvent(event); + + g_lastMouseEvent = NULL; + + return ret; } //----------------------------------------------------------------------------- -- 2.45.2