X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/8907154c1a8a6882c6797d1f16393ddfb23e7f3a..30d6c59b297f98ebda1d6c14e56f289bd3b02799:/src/gtk1/dnd.cpp diff --git a/src/gtk1/dnd.cpp b/src/gtk1/dnd.cpp index 75a0c0962e..d21b31386a 100644 --- a/src/gtk1/dnd.cpp +++ b/src/gtk1/dnd.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Name: dnd.cpp +// Name: src/gtk1/dnd.cpp // Purpose: wxDropTarget class // Author: Robert Roebling // Id: $Id$ @@ -10,19 +10,20 @@ // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" -#include "wx/dnd.h" -#include "wx/log.h" - - #if wxUSE_DRAG_AND_DROP -#include "wx/window.h" -#include "wx/app.h" -#include "wx/gdicmn.h" -#include "wx/intl.h" -#include "wx/utils.h" +#include "wx/dnd.h" + +#ifndef WX_PRECOMP + #include "wx/intl.h" + #include "wx/log.h" + #include "wx/app.h" + #include "wx/utils.h" + #include "wx/window.h" + #include "wx/gdicmn.h" +#endif -#include "wx/gtk/private.h" +#include "wx/gtk1/private.h" #include @@ -36,13 +37,6 @@ extern void wxapp_install_idle_handler(); extern bool g_isIdle; -//----------------------------------------------------------------------------- -// thread system -//----------------------------------------------------------------------------- - -#if wxUSE_THREADS -#endif - //---------------------------------------------------------------------------- // global data //---------------------------------------------------------------------------- @@ -55,7 +49,12 @@ static long gs_flagsForDrag = 0; // 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"); +#define TRACE_DND wxT("dnd") + +// global variables because GTK+ DnD want to have the +// mouse event that caused it +extern GdkEvent *g_lastMouseEvent; +extern int g_lastButtonNumber; //---------------------------------------------------------------------------- // standard icons @@ -187,7 +186,7 @@ static void target_drag_leave( GtkWidget *WXUNUSED(widget), drop_target->m_firstMotion = true; /* after this, invalidate the drop_target's GdkDragContext */ - drop_target->SetDragContext( (GdkDragContext*) NULL ); + drop_target->SetDragContext( NULL ); } } @@ -280,7 +279,7 @@ static gboolean target_drag_motion( GtkWidget *WXUNUSED(widget), } /* after this, invalidate the drop_target's GdkDragContext */ - drop_target->SetDragContext( (GdkDragContext*) NULL ); + drop_target->SetDragContext( NULL ); /* this has to be done because GDK has no "drag_enter" event */ drop_target->m_firstMotion = false; @@ -359,7 +358,7 @@ static gboolean target_drag_drop( GtkWidget *widget, GdkAtom format = drop_target->GetMatchingPair(); // this does happen somehow, see bug 555111 - wxCHECK_MSG( format, FALSE, _T("no matching GdkAtom for format?") ) + wxCHECK_MSG( format, FALSE, wxT("no matching GdkAtom for format?") ); /* GdkDragAction action = GDK_ACTION_MOVE; @@ -378,10 +377,10 @@ static gboolean target_drag_drop( GtkWidget *widget, } /* after this, invalidate the drop_target's GdkDragContext */ - drop_target->SetDragContext( (GdkDragContext*) NULL ); + drop_target->SetDragContext( NULL ); /* after this, invalidate the drop_target's drag widget */ - drop_target->SetDragWidget( (GtkWidget*) NULL ); + drop_target->SetDragWidget( NULL ); /* this has to be done because GDK has no "drag_enter" event */ drop_target->m_firstMotion = true; @@ -442,7 +441,7 @@ static void target_drag_data_received( GtkWidget *WXUNUSED(widget), } /* after this, invalidate the drop_target's drag data */ - drop_target->SetDragData( (GtkSelectionData*) NULL ); + drop_target->SetDragData( NULL ); } } @@ -454,9 +453,9 @@ wxDropTarget::wxDropTarget( wxDataObject *data ) : wxDropTargetBase( data ) { m_firstMotion = true; - m_dragContext = (GdkDragContext*) NULL; - m_dragWidget = (GtkWidget*) NULL; - m_dragData = (GtkSelectionData*) NULL; + m_dragContext = NULL; + m_dragWidget = NULL; + m_dragData = NULL; m_dragTime = 0; } @@ -466,13 +465,8 @@ wxDragResult wxDropTarget::OnDragOver( wxCoord WXUNUSED(x), { // GetMatchingPair() checks for m_dataObject too, no need to do it here - // disable the debug message from GetMatchingPair() - there are too many - // of them otherwise -#ifdef __WXDEBUG__ - wxLogNull noLog; -#endif // Debug - - return (GetMatchingPair() != (GdkAtom) 0) ? def : wxDragNone; + // disable the debug message from GetMatchingPair() by passing true to it + return (GetMatchingPair(true) != (GdkAtom) 0) ? def : wxDragNone; } bool wxDropTarget::OnDrop( wxCoord WXUNUSED(x), wxCoord WXUNUSED(y) ) @@ -495,7 +489,7 @@ wxDragResult wxDropTarget::OnData( wxCoord WXUNUSED(x), wxCoord WXUNUSED(y), return GetData() ? def : wxDragNone; } -GdkAtom wxDropTarget::GetMatchingPair() +GdkAtom wxDropTarget::GetMatchingPair(bool quiet) { if (!m_dataObject) return (GdkAtom) 0; @@ -506,13 +500,14 @@ GdkAtom wxDropTarget::GetMatchingPair() GList *child = m_dragContext->targets; while (child) { - GdkAtom formatAtom = (GdkAtom) GPOINTER_TO_INT(child->data); + GdkAtom formatAtom = GPOINTER_TO_INT(child->data); wxDataFormat format( formatAtom ); -#ifdef __WXDEBUG__ - wxLogTrace(TRACE_DND, wxT("Drop target: drag has format: %s"), - format.GetId().c_str()); -#endif // Debug + if ( !quiet ) + { + wxLogTrace(TRACE_DND, wxT("Drop target: drag has format: %s"), + format.GetId().c_str()); + } if (m_dataObject->IsSupportedFormat( format )) return formatAtom; @@ -576,7 +571,7 @@ void wxDropTarget::RegisterWidget( GtkWidget *widget ) gtk_drag_dest_set( widget, (GtkDestDefaults) 0, /* no default behaviour */ - (GtkTargetEntry*) NULL, /* we don't supply any formats here */ + NULL, /* we don't supply any formats here */ 0, /* number of targets = 0 */ (GdkDragAction) 0 ); /* we don't supply any actions here */ @@ -671,7 +666,7 @@ source_drag_data_get (GtkWidget *WXUNUSED(widget), extern "C" { static void source_drag_data_delete( GtkWidget *WXUNUSED(widget), - GdkDragContext *context, + GdkDragContext *WXUNUSED(context), wxDropSource *WXUNUSED(drop_source) ) { if (g_isIdle) @@ -742,7 +737,7 @@ wxDropSource::wxDropSource(wxWindow *win, { m_waiting = true; - m_iconWindow = (GtkWidget*) NULL; + m_iconWindow = NULL; m_window = win; m_widget = win->m_widget; @@ -763,7 +758,7 @@ wxDropSource::wxDropSource(wxDataObject& data, SetData( data ); - m_iconWindow = (GtkWidget*) NULL; + m_iconWindow = NULL; m_window = win; m_widget = win->m_widget; @@ -809,7 +804,7 @@ void wxDropSource::PrepareIcon( int action, GdkDragContext *context ) if ( icon->GetMask() ) mask = icon->GetMask()->GetBitmap(); else - mask = (GdkBitmap *)NULL; + mask = NULL; GdkPixmap *pixmap = icon->GetPixmap(); @@ -817,18 +812,14 @@ void wxDropSource::PrepareIcon( int action, GdkDragContext *context ) gdk_window_get_size (pixmap, &width, &height); GdkColormap *colormap = gtk_widget_get_colormap( m_widget ); -#ifndef __WXGTK20__ gtk_widget_push_visual (gdk_colormap_get_visual (colormap)); -#endif gtk_widget_push_colormap (colormap); m_iconWindow = gtk_window_new (GTK_WINDOW_POPUP); gtk_widget_set_events (m_iconWindow, GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK); gtk_widget_set_app_paintable (GTK_WIDGET (m_iconWindow), TRUE); -#ifndef __WXGTK20__ gtk_widget_pop_visual (); -#endif gtk_widget_pop_colormap (); gtk_widget_set_usize (m_iconWindow, width, height); @@ -854,6 +845,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; @@ -861,7 +860,7 @@ wxDragResult wxDropSource::DoDragDrop(int flags) m_waiting = true; - GtkTargetList *target_list = gtk_target_list_new( (GtkTargetEntry*) NULL, 0 ); + GtkTargetList *target_list = gtk_target_list_new( NULL, 0 ); wxDataFormat *array = new wxDataFormat[ m_data->GetFormatCount() ]; m_data->GetAllFormats( array ); @@ -874,30 +873,6 @@ wxDragResult wxDropSource::DoDragDrop(int flags) } delete[] array; - GdkEventMotion event; - event.window = m_widget->window; - int x = 0; - int y = 0; - GdkModifierType state; - gdk_window_get_pointer( event.window, &x, &y, &state ); - event.x = x; - event.y = y; - event.state = state; - event.time = (guint32)GDK_CURRENT_TIME; - - /* GTK wants to know which button was pressed which caused the dragging */ - int button_number = 0; - if (event.state & GDK_BUTTON1_MASK) button_number = 1; - else if (event.state & GDK_BUTTON2_MASK) button_number = 2; - else if (event.state & GDK_BUTTON3_MASK) button_number = 3; - -#if wxUSE_THREADS - /* disable GUI threads */ -#endif - - /* don't start dragging if no button is down */ - if (button_number) - { int action = GDK_ACTION_COPY; if ( flags & wxDrag_AllowMove ) action |= GDK_ACTION_MOVE; @@ -910,8 +885,8 @@ wxDragResult wxDropSource::DoDragDrop(int flags) GdkDragContext *context = gtk_drag_begin( m_widget, target_list, (GdkDragAction)action, - button_number, /* number of mouse button which started drag */ - (GdkEvent*) &event ); + g_lastButtonNumber, // number of mouse button which started drag + (GdkEvent*) g_lastMouseEvent ); m_dragContext = context; @@ -923,11 +898,6 @@ wxDragResult wxDropSource::DoDragDrop(int flags) m_retValue = ConvertFromGTK(context->action); if ( m_retValue == wxDragNone ) m_retValue = wxDragCancel; - } - -#if wxUSE_THREADS - /* re-enable GUI threads */ -#endif g_blockEventsOnDrag = false;