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
This commit is contained in:
Robert Roebling
2006-11-15 08:59:50 +00:00
parent aac75444c6
commit 5e513780ed
2 changed files with 39 additions and 25 deletions

View File

@@ -39,14 +39,17 @@ extern bool g_blockEventsOnDrag;
// the flags used for the last DoDragDrop() // the flags used for the last DoDragDrop()
static long gs_flagsForDrag = 0; static long gs_flagsForDrag = 0;
#ifdef __WXDEBUG__
// the trace mask we use with wxLogTrace() - call // the trace mask we use with wxLogTrace() - call
// wxLog::AddTraceMask(TRACE_DND) to enable the trace messages from here // 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) // (there are quite a few of them, so don't enable this by default)
static const wxChar *TRACE_DND = _T("dnd"); 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 GdkEvent *g_lastMouseEvent;
extern int g_lastButtonNumber;
extern int g_lastButtonNumber;
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// standard icons // standard icons
@@ -835,6 +838,14 @@ wxDragResult wxDropSource::DoDragDrop(int flags)
if (g_blockEventsOnDrag) if (g_blockEventsOnDrag)
return wxDragNone; 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 // disabled for now
g_blockEventsOnDrag = true; g_blockEventsOnDrag = true;
@@ -855,35 +866,31 @@ wxDragResult wxDropSource::DoDragDrop(int flags)
} }
delete[] array; delete[] array;
/* don't start dragging if no button is down */ int action = GDK_ACTION_COPY;
if (g_lastButtonNumber) 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 // 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 // to use a global to pass the flags to the drop target but I'd
// surely prefer a better way to do it // surely prefer a better way to do it
gs_flagsForDrag = flags; gs_flagsForDrag = flags;
GdkDragContext *context = gtk_drag_begin( m_widget, GdkDragContext *context = gtk_drag_begin( m_widget,
target_list, target_list,
(GdkDragAction)action, (GdkDragAction)action,
g_lastButtonNumber, // number of mouse button which started drag g_lastButtonNumber, // number of mouse button which started drag
(GdkEvent*) g_lastMouseEvent ); (GdkEvent*) g_lastMouseEvent );
m_dragContext = context; m_dragContext = context;
PrepareIcon( action, context ); PrepareIcon( action, context );
while (m_waiting) while (m_waiting)
gtk_main_iteration(); gtk_main_iteration();
m_retValue = ConvertFromGTK(context->action); m_retValue = ConvertFromGTK(context->action);
if ( m_retValue == wxDragNone ) if ( m_retValue == wxDragNone )
m_retValue = wxDragCancel; m_retValue = wxDragCancel;
}
g_blockEventsOnDrag = false; g_blockEventsOnDrag = false;

View File

@@ -210,9 +210,10 @@ wxWindowGTK *g_focusWindowLast = (wxWindowGTK*) NULL;
// yet, defer setting the focus to idle time. // yet, defer setting the focus to idle time.
wxWindowGTK *g_delayedFocus = (wxWindowGTK*) NULL; wxWindowGTK *g_delayedFocus = (wxWindowGTK*) NULL;
// Save the last mouse event for drag start // global variables because GTK+ DnD want to have the
GdkEvent *g_lastMouseEvent = (GdkEvent*) NULL; // mouse event that caused it
int g_lastButtonNumber = 0; GdkEvent *g_lastMouseEvent = (GdkEvent*) NULL;
int g_lastButtonNumber = 0;
extern bool g_mainThreadLocked; extern bool g_mainThreadLocked;
@@ -1607,8 +1608,10 @@ gtk_window_button_press_callback( GtkWidget *widget,
if (win->GTKProcessEvent( event )) if (win->GTKProcessEvent( event ))
{ {
g_lastMouseEvent = NULL;
return TRUE; return TRUE;
} }
g_lastMouseEvent = NULL;
if (event_type == wxEVT_RIGHT_DOWN) 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;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------