///////////////////////////////////////////////////////////////////////////////
-// Name: dnd.cpp
+// Name: src/gtk1/dnd.cpp
// Purpose: wxDropTarget class
// Author: Robert Roebling
// Id: $Id$
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
-#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
- #pragma implementation "dnd.h"
-#endif
-
// 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 <gdk/gdkprivate.h>
// 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 _T("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
drop_target->OnLeave();
/* this has to be done because GDK has no "drag_enter" event */
- drop_target->m_firstMotion = TRUE;
+ drop_target->m_firstMotion = true;
/* after this, invalidate the drop_target's GdkDragContext */
drop_target->SetDragContext( (GdkDragContext*) NULL );
drop_target->SetDragContext( (GdkDragContext*) NULL );
/* this has to be done because GDK has no "drag_enter" event */
- drop_target->m_firstMotion = FALSE;
+ drop_target->m_firstMotion = false;
return ret;
}
/* reset the block here as someone might very well
show a dialog as a reaction to a drop and this
wouldn't work without events */
- g_blockEventsOnDrag = FALSE;
+ g_blockEventsOnDrag = false;
bool ret = drop_target->OnDrop( x, y );
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, _T("no matching GdkAtom for format?") );
/*
GdkDragAction action = GDK_ACTION_MOVE;
drop_target->SetDragWidget( (GtkWidget*) NULL );
/* this has to be done because GDK has no "drag_enter" event */
- drop_target->m_firstMotion = TRUE;
+ drop_target->m_firstMotion = true;
return ret;
}
wxDropTarget::wxDropTarget( wxDataObject *data )
: wxDropTargetBase( data )
{
- m_firstMotion = TRUE;
+ m_firstMotion = true;
m_dragContext = (GdkDragContext*) NULL;
m_dragWidget = (GtkWidget*) NULL;
m_dragData = (GtkSelectionData*) NULL;
bool wxDropTarget::OnDrop( wxCoord WXUNUSED(x), wxCoord WXUNUSED(y) )
{
if (!m_dataObject)
- return FALSE;
+ return false;
return (GetMatchingPair() != (GdkAtom) 0);
}
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__
bool wxDropTarget::GetData()
{
if (!m_dragData)
- return FALSE;
+ return false;
if (!m_dataObject)
- return FALSE;
+ return false;
wxDataFormat dragFormat( m_dragData->target );
if (!m_dataObject->IsSupportedFormat( dragFormat ))
- return FALSE;
+ return false;
m_dataObject->SetData( dragFormat, (size_t)m_dragData->length, (const void*)m_dragData->data );
- return TRUE;
+ return true;
}
void wxDropTarget::UnregisterWidget( GtkWidget *widget )
/* disable GUI threads */
#endif
- gtk_selection_data_set( selection_data,
- selection_data->target,
- 8, // 8-bit
- d,
- size );
+ gtk_selection_data_set( selection_data,
+ selection_data->target,
+ 8, // 8-bit
+ d,
+ size );
#if wxUSE_THREADS
/* enable GUI threads */
extern "C" {
static void source_drag_data_delete( GtkWidget *WXUNUSED(widget),
- GdkDragContext *context,
+ GdkDragContext *WXUNUSED(context),
wxDropSource *WXUNUSED(drop_source) )
{
if (g_isIdle)
// printf( "Drag source: drag_end.\n" );
- drop_source->m_waiting = FALSE;
+ drop_source->m_waiting = false;
}
}
const wxIcon &iconMove,
const wxIcon &iconNone)
{
- m_waiting = TRUE;
+ m_waiting = true;
m_iconWindow = (GtkWidget*) NULL;
const wxIcon &iconMove,
const wxIcon &iconNone)
{
- m_waiting = TRUE;
+ m_waiting = true;
SetData( data );
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);
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;
+ g_blockEventsOnDrag = true;
RegisterWindow();
- m_waiting = TRUE;
+ m_waiting = true;
GtkTargetList *target_list = gtk_target_list_new( (GtkTargetEntry*) NULL, 0 );
}
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;
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;
m_retValue = ConvertFromGTK(context->action);
if ( m_retValue == wxDragNone )
m_retValue = wxDragCancel;
- }
-
-#if wxUSE_THREADS
- /* re-enable GUI threads */
-#endif
- g_blockEventsOnDrag = FALSE;
+ g_blockEventsOnDrag = false;
UnregisterWindow();