1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxDropTarget class
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
10 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
11 #pragma implementation "dnd.h"
14 // For compilers that support precompilation, includes "wx.h".
15 #include "wx/wxprec.h"
21 #if wxUSE_DRAG_AND_DROP
23 #include "wx/window.h"
25 #include "wx/gdicmn.h"
29 #include "wx/gtk/private.h"
31 #include <gdk/gdkprivate.h>
33 #include <gtk/gtkdnd.h>
34 #include <gtk/gtkselection.h>
36 //-----------------------------------------------------------------------------
38 //-----------------------------------------------------------------------------
40 extern void wxapp_install_idle_handler();
43 //-----------------------------------------------------------------------------
45 //-----------------------------------------------------------------------------
50 //----------------------------------------------------------------------------
52 //----------------------------------------------------------------------------
54 extern bool g_blockEventsOnDrag
;
56 // the flags used for the last DoDragDrop()
57 static long gs_flagsForDrag
= 0;
59 // the trace mask we use with wxLogTrace() - call
60 // wxLog::AddTraceMask(TRACE_DND) to enable the trace messages from here
61 // (there are quite a few of them, so don't enable this by default)
62 static const wxChar
*TRACE_DND
= _T("dnd");
64 //----------------------------------------------------------------------------
66 //----------------------------------------------------------------------------
69 static const char * page_xpm
[] = {
70 /* width height ncolors chars_per_pixel */
79 " ................... ",
80 " .XXXXXXXXXXXXXXXXX.. ",
81 " .XXXXXXXXXXXXXXXXX.o. ",
82 " .XXXXXXXXXXXXXXXXX.oo. ",
83 " .XXXXXXXXXXXXXXXXX.ooo. ",
84 " .XXXXXXXXXXXXXXXXX.oooo. ",
85 " .XXXXXXXXXXXXXXXXX....... ",
86 " .XXXXXOOOOOOOOOOXXXooooo. ",
87 " .XXXXXXXXXXXXXXXXXXooooo. ",
88 " .XXXXXOOOOOOOOOOXXXXXXXX. ",
89 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
90 " .XXXXXXXOOOOOOOOOXXXXXXX. ",
91 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
92 " .XXXXXXOOOOOOOOOOXXXXXXX. ",
93 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
94 " .XXXXXOOOOOOOOOOXXXXXXXX. ",
95 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
96 " .XXXXXXXOOOOOOOOOXXXXXXX. ",
97 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
98 " .XXXXXXOOOOOOOOOOXXXXXXX. ",
99 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
100 " .XXXXXOOOOOOOOOOXXXXXXXX. ",
101 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
102 " .XXXXXXOOOOOOOOOOXXXXXXX. ",
103 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
104 " .XXXXXOOOOOOOXXXXXXXXXXX. ",
105 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
106 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
107 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
108 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
109 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
110 " ......................... "};
113 // ============================================================================
115 // ============================================================================
117 // ----------------------------------------------------------------------------
118 // convert between GTK+ and wxWidgets DND constants
119 // ----------------------------------------------------------------------------
121 static wxDragResult
ConvertFromGTK(long action
)
125 case GDK_ACTION_COPY
:
128 case GDK_ACTION_LINK
:
131 case GDK_ACTION_MOVE
:
138 // ----------------------------------------------------------------------------
140 // ----------------------------------------------------------------------------
142 static void target_drag_leave( GtkWidget
*WXUNUSED(widget
),
143 GdkDragContext
*context
,
144 guint
WXUNUSED(time
),
145 wxDropTarget
*drop_target
)
147 if (g_isIdle
) wxapp_install_idle_handler();
149 /* inform the wxDropTarget about the current GdkDragContext.
150 this is only valid for the duration of this call */
151 drop_target
->SetDragContext( context
);
153 /* we don't need return values. this event is just for
155 drop_target
->OnLeave();
157 /* this has to be done because GDK has no "drag_enter" event */
158 drop_target
->m_firstMotion
= TRUE
;
160 /* after this, invalidate the drop_target's GdkDragContext */
161 drop_target
->SetDragContext( (GdkDragContext
*) NULL
);
164 // ----------------------------------------------------------------------------
166 // ----------------------------------------------------------------------------
168 static gboolean
target_drag_motion( GtkWidget
*WXUNUSED(widget
),
169 GdkDragContext
*context
,
173 wxDropTarget
*drop_target
)
175 if (g_isIdle
) wxapp_install_idle_handler();
177 /* Owen Taylor: "if the coordinates not in a drop zone,
178 return FALSE, otherwise call gtk_drag_status() and
181 /* inform the wxDropTarget about the current GdkDragContext.
182 this is only valid for the duration of this call */
183 drop_target
->SetDragContext( context
);
185 // GTK+ always supposes that we want to copy the data by default while we
186 // might want to move it, so examine not only suggested_action - which is
187 // only good if we don't have our own preferences - but also the actions
190 if ( (gs_flagsForDrag
& wxDrag_DefaultMove
) == wxDrag_DefaultMove
&&
191 (context
->actions
& GDK_ACTION_MOVE
) )
193 // move is requested by the program and allowed by GTK+ - do it, even
194 // though suggested_action may be currently wxDragCopy
197 else // use whatever GTK+ says we should
199 result
= ConvertFromGTK(context
->suggested_action
);
201 if ( (result
== wxDragMove
) && !(gs_flagsForDrag
& wxDrag_AllowMove
) )
203 // we're requested to move but we can't
208 if (drop_target
->m_firstMotion
)
210 /* the first "drag_motion" event substitutes a "drag_enter" event */
211 result
= drop_target
->OnEnter( x
, y
, result
);
215 /* give program a chance to react (i.e. to say no by returning FALSE) */
216 result
= drop_target
->OnDragOver( x
, y
, result
);
219 bool ret
= wxIsDragResultOk( result
);
222 GdkDragAction action
;
223 if ((result
== wxDragCopy
) && (context
->actions
& GDK_ACTION_COPY
) ||
224 (result
== wxDragMove
) && !(context
->actions
& GDK_ACTION_MOVE
) ||
225 (result
== wxDragLink
) && !(context
->actions
& GDK_ACTION_LINK
))
226 action
= GDK_ACTION_COPY
;
227 else if (result
== wxDragLink
)
228 action
= GDK_ACTION_LINK
;
230 action
= GDK_ACTION_MOVE
;
232 gdk_drag_status( context
, action
, time
);
235 /* after this, invalidate the drop_target's GdkDragContext */
236 drop_target
->SetDragContext( (GdkDragContext
*) NULL
);
238 /* this has to be done because GDK has no "drag_enter" event */
239 drop_target
->m_firstMotion
= FALSE
;
244 // ----------------------------------------------------------------------------
246 // ----------------------------------------------------------------------------
248 static gboolean
target_drag_drop( GtkWidget
*widget
,
249 GdkDragContext
*context
,
253 wxDropTarget
*drop_target
)
255 if (g_isIdle
) wxapp_install_idle_handler();
257 /* Owen Taylor: "if the drop is not in a drop zone,
258 return FALSE, otherwise, if you aren't accepting
259 the drop, call gtk_drag_finish() with success == FALSE
260 otherwise call gtk_drag_data_get()" */
262 // printf( "drop.\n" );
264 /* this seems to make a difference between not accepting
265 due to wrong target area and due to wrong format. let
266 us hope that this is not required.. */
268 /* inform the wxDropTarget about the current GdkDragContext.
269 this is only valid for the duration of this call */
270 drop_target
->SetDragContext( context
);
272 /* inform the wxDropTarget about the current drag widget.
273 this is only valid for the duration of this call */
274 drop_target
->SetDragWidget( widget
);
276 /* inform the wxDropTarget about the current drag time.
277 this is only valid for the duration of this call */
278 drop_target
->SetDragTime( time
);
281 wxDragResult result = wxDragMove;
282 if (context->suggested_action == GDK_ACTION_COPY) result = wxDragCopy;
285 /* reset the block here as someone might very well
286 show a dialog as a reaction to a drop and this
287 wouldn't work without events */
288 g_blockEventsOnDrag
= FALSE
;
290 bool ret
= drop_target
->OnDrop( x
, y
);
294 wxLogTrace(TRACE_DND
, wxT( "Drop target: OnDrop returned FALSE") );
296 /* cancel the whole thing */
297 gtk_drag_finish( context
,
298 FALSE
, /* no success */
299 FALSE
, /* don't delete data on dropping side */
304 wxLogTrace(TRACE_DND
, wxT( "Drop target: OnDrop returned TRUE") );
307 /* disable GUI threads */
310 GdkAtom format
= drop_target
->GetMatchingPair();
312 // this does happen somehow, see bug 555111
313 wxCHECK_MSG( format
, FALSE
, _T("no matching GdkAtom for format?") )
316 GdkDragAction action = GDK_ACTION_MOVE;
317 if (result == wxDragCopy) action == GDK_ACTION_COPY;
318 context->action = action;
320 /* this should trigger an "drag_data_received" event */
321 gtk_drag_get_data( widget
,
327 /* re-enable GUI threads */
331 /* after this, invalidate the drop_target's GdkDragContext */
332 drop_target
->SetDragContext( (GdkDragContext
*) NULL
);
334 /* after this, invalidate the drop_target's drag widget */
335 drop_target
->SetDragWidget( (GtkWidget
*) NULL
);
337 /* this has to be done because GDK has no "drag_enter" event */
338 drop_target
->m_firstMotion
= TRUE
;
343 // ----------------------------------------------------------------------------
344 // "drag_data_received"
345 // ----------------------------------------------------------------------------
347 static void target_drag_data_received( GtkWidget
*WXUNUSED(widget
),
348 GdkDragContext
*context
,
351 GtkSelectionData
*data
,
352 guint
WXUNUSED(info
),
354 wxDropTarget
*drop_target
)
356 if (g_isIdle
) wxapp_install_idle_handler();
358 /* Owen Taylor: "call gtk_drag_finish() with
361 if ((data
->length
<= 0) || (data
->format
!= 8))
363 /* negative data length and non 8-bit data format
364 qualifies for junk */
365 gtk_drag_finish (context
, FALSE
, FALSE
, time
);
370 wxLogTrace(TRACE_DND
, wxT( "Drop target: data received event") );
372 /* inform the wxDropTarget about the current GtkSelectionData.
373 this is only valid for the duration of this call */
374 drop_target
->SetDragData( data
);
376 wxDragResult result
= ConvertFromGTK(context
->action
);
378 if ( wxIsDragResultOk( drop_target
->OnData( x
, y
, result
) ) )
380 wxLogTrace(TRACE_DND
, wxT( "Drop target: OnData returned TRUE") );
382 /* tell GTK that data transfer was successfull */
383 gtk_drag_finish( context
, TRUE
, FALSE
, time
);
387 wxLogTrace(TRACE_DND
, wxT( "Drop target: OnData returned FALSE") );
389 /* tell GTK that data transfer was not successfull */
390 gtk_drag_finish( context
, FALSE
, FALSE
, time
);
393 /* after this, invalidate the drop_target's drag data */
394 drop_target
->SetDragData( (GtkSelectionData
*) NULL
);
397 //----------------------------------------------------------------------------
399 //----------------------------------------------------------------------------
401 wxDropTarget::wxDropTarget( wxDataObject
*data
)
402 : wxDropTargetBase( data
)
404 m_firstMotion
= TRUE
;
405 m_dragContext
= (GdkDragContext
*) NULL
;
406 m_dragWidget
= (GtkWidget
*) NULL
;
407 m_dragData
= (GtkSelectionData
*) NULL
;
411 wxDragResult
wxDropTarget::OnDragOver( wxCoord
WXUNUSED(x
),
415 // GetMatchingPair() checks for m_dataObject too, no need to do it here
417 // disable the debug message from GetMatchingPair() - there are too many
423 return (GetMatchingPair() != (GdkAtom
) 0) ? def
: wxDragNone
;
426 bool wxDropTarget::OnDrop( wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
) )
431 return (GetMatchingPair() != (GdkAtom
) 0);
434 wxDragResult
wxDropTarget::OnData( wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
),
440 if (GetMatchingPair() == (GdkAtom
) 0)
443 return GetData() ? def
: wxDragNone
;
446 GdkAtom
wxDropTarget::GetMatchingPair()
454 GList
*child
= m_dragContext
->targets
;
457 GdkAtom formatAtom
= (GdkAtom
) GPOINTER_TO_INT(child
->data
);
458 wxDataFormat
format( formatAtom
);
461 wxLogTrace(TRACE_DND
, wxT("Drop target: drag has format: %s"),
462 format
.GetId().c_str());
465 if (m_dataObject
->IsSupportedFormat( format
))
474 bool wxDropTarget::GetData()
482 wxDataFormat
dragFormat( m_dragData
->target
);
484 if (!m_dataObject
->IsSupportedFormat( dragFormat
))
487 m_dataObject
->SetData( dragFormat
, (size_t)m_dragData
->length
, (const void*)m_dragData
->data
);
492 void wxDropTarget::UnregisterWidget( GtkWidget
*widget
)
494 wxCHECK_RET( widget
!= NULL
, wxT("unregister widget is NULL") );
496 gtk_drag_dest_unset( widget
);
498 gtk_signal_disconnect_by_func( GTK_OBJECT(widget
),
499 GTK_SIGNAL_FUNC(target_drag_leave
), (gpointer
) this );
501 gtk_signal_disconnect_by_func( GTK_OBJECT(widget
),
502 GTK_SIGNAL_FUNC(target_drag_motion
), (gpointer
) this );
504 gtk_signal_disconnect_by_func( GTK_OBJECT(widget
),
505 GTK_SIGNAL_FUNC(target_drag_drop
), (gpointer
) this );
507 gtk_signal_disconnect_by_func( GTK_OBJECT(widget
),
508 GTK_SIGNAL_FUNC(target_drag_data_received
), (gpointer
) this );
511 void wxDropTarget::RegisterWidget( GtkWidget
*widget
)
513 wxCHECK_RET( widget
!= NULL
, wxT("register widget is NULL") );
515 /* gtk_drag_dest_set() determines what default behaviour we'd like
516 GTK to supply. we don't want to specify out targets (=formats)
517 or actions in advance (i.e. not GTK_DEST_DEFAULT_MOTION and
518 not GTK_DEST_DEFAULT_DROP). instead we react individually to
519 "drag_motion" and "drag_drop" events. this makes it possible
520 to allow dropping on only a small area. we should set
521 GTK_DEST_DEFAULT_HIGHLIGHT as this will switch on the nice
522 highlighting if dragging over standard controls, but this
523 seems to be broken without the other two. */
525 gtk_drag_dest_set( widget
,
526 (GtkDestDefaults
) 0, /* no default behaviour */
527 (GtkTargetEntry
*) NULL
, /* we don't supply any formats here */
528 0, /* number of targets = 0 */
529 (GdkDragAction
) 0 ); /* we don't supply any actions here */
531 gtk_signal_connect( GTK_OBJECT(widget
), "drag_leave",
532 GTK_SIGNAL_FUNC(target_drag_leave
), (gpointer
) this );
534 gtk_signal_connect( GTK_OBJECT(widget
), "drag_motion",
535 GTK_SIGNAL_FUNC(target_drag_motion
), (gpointer
) this );
537 gtk_signal_connect( GTK_OBJECT(widget
), "drag_drop",
538 GTK_SIGNAL_FUNC(target_drag_drop
), (gpointer
) this );
540 gtk_signal_connect( GTK_OBJECT(widget
), "drag_data_received",
541 GTK_SIGNAL_FUNC(target_drag_data_received
), (gpointer
) this );
544 //----------------------------------------------------------------------------
546 //----------------------------------------------------------------------------
549 source_drag_data_get (GtkWidget
*WXUNUSED(widget
),
550 GdkDragContext
*WXUNUSED(context
),
551 GtkSelectionData
*selection_data
,
552 guint
WXUNUSED(info
),
553 guint
WXUNUSED(time
),
554 wxDropSource
*drop_source
)
556 if (g_isIdle
) wxapp_install_idle_handler();
558 wxDataFormat
format( selection_data
->target
);
560 wxLogTrace(TRACE_DND
, wxT("Drop source: format requested: %s"),
561 format
.GetId().c_str());
563 drop_source
->m_retValue
= wxDragCancel
;
565 wxDataObject
*data
= drop_source
->GetDataObject();
569 wxLogTrace(TRACE_DND
, wxT("Drop source: no data object") );
573 if (!data
->IsSupportedFormat(format
))
575 wxLogTrace(TRACE_DND
, wxT("Drop source: unsupported format") );
579 if (data
->GetDataSize(format
) == 0)
581 wxLogTrace(TRACE_DND
, wxT("Drop source: empty data") );
585 size_t size
= data
->GetDataSize(format
);
587 // printf( "data size: %d.\n", (int)data_size );
589 guchar
*d
= new guchar
[size
];
591 if (!data
->GetDataHere( format
, (void*)d
))
598 /* disable GUI threads */
601 gtk_selection_data_set( selection_data
,
602 selection_data
->target
,
608 /* enable GUI threads */
614 //----------------------------------------------------------------------------
615 // "drag_data_delete"
616 //----------------------------------------------------------------------------
618 static void source_drag_data_delete( GtkWidget
*WXUNUSED(widget
),
619 GdkDragContext
*context
,
620 wxDropSource
*WXUNUSED(drop_source
) )
623 wxapp_install_idle_handler();
625 // printf( "Drag source: drag_data_delete\n" );
628 //----------------------------------------------------------------------------
630 //----------------------------------------------------------------------------
632 static void source_drag_begin( GtkWidget
*WXUNUSED(widget
),
633 GdkDragContext
*WXUNUSED(context
),
634 wxDropSource
*WXUNUSED(drop_source
) )
637 wxapp_install_idle_handler();
639 // printf( "Drag source: drag_begin.\n" );
642 //----------------------------------------------------------------------------
644 //----------------------------------------------------------------------------
646 static void source_drag_end( GtkWidget
*WXUNUSED(widget
),
647 GdkDragContext
*WXUNUSED(context
),
648 wxDropSource
*drop_source
)
650 if (g_isIdle
) wxapp_install_idle_handler();
652 // printf( "Drag source: drag_end.\n" );
654 drop_source
->m_waiting
= FALSE
;
657 //-----------------------------------------------------------------------------
658 // "configure_event" from m_iconWindow
659 //-----------------------------------------------------------------------------
662 gtk_dnd_window_configure_callback( GtkWidget
*WXUNUSED(widget
), GdkEventConfigure
*WXUNUSED(event
), wxDropSource
*source
)
665 wxapp_install_idle_handler();
667 source
->GiveFeedback( ConvertFromGTK(source
->m_dragContext
->action
) );
672 //---------------------------------------------------------------------------
674 //---------------------------------------------------------------------------
676 wxDropSource::wxDropSource(wxWindow
*win
,
677 const wxIcon
&iconCopy
,
678 const wxIcon
&iconMove
,
679 const wxIcon
&iconNone
)
683 m_iconWindow
= (GtkWidget
*) NULL
;
686 m_widget
= win
->m_widget
;
687 if (win
->m_wxwindow
) m_widget
= win
->m_wxwindow
;
689 m_retValue
= wxDragCancel
;
691 SetIcons(iconCopy
, iconMove
, iconNone
);
694 wxDropSource::wxDropSource(wxDataObject
& data
,
696 const wxIcon
&iconCopy
,
697 const wxIcon
&iconMove
,
698 const wxIcon
&iconNone
)
704 m_iconWindow
= (GtkWidget
*) NULL
;
707 m_widget
= win
->m_widget
;
708 if (win
->m_wxwindow
) m_widget
= win
->m_wxwindow
;
710 m_retValue
= wxDragCancel
;
712 SetIcons(iconCopy
, iconMove
, iconNone
);
715 void wxDropSource::SetIcons(const wxIcon
&iconCopy
,
716 const wxIcon
&iconMove
,
717 const wxIcon
&iconNone
)
719 m_iconCopy
= iconCopy
;
720 m_iconMove
= iconMove
;
721 m_iconNone
= iconNone
;
723 if ( !m_iconCopy
.Ok() )
724 m_iconCopy
= wxIcon(page_xpm
);
725 if ( !m_iconMove
.Ok() )
726 m_iconMove
= m_iconCopy
;
727 if ( !m_iconNone
.Ok() )
728 m_iconNone
= m_iconCopy
;
731 wxDropSource::~wxDropSource()
735 void wxDropSource::PrepareIcon( int action
, GdkDragContext
*context
)
737 // get the right icon to display
739 if ( action
& GDK_ACTION_MOVE
)
741 else if ( action
& GDK_ACTION_COPY
)
747 if ( icon
->GetMask() )
748 mask
= icon
->GetMask()->GetBitmap();
750 mask
= (GdkBitmap
*)NULL
;
752 GdkPixmap
*pixmap
= icon
->GetPixmap();
755 gdk_window_get_size (pixmap
, &width
, &height
);
757 GdkColormap
*colormap
= gtk_widget_get_colormap( m_widget
);
759 gtk_widget_push_visual (gdk_colormap_get_visual (colormap
));
761 gtk_widget_push_colormap (colormap
);
763 m_iconWindow
= gtk_window_new (GTK_WINDOW_POPUP
);
764 gtk_widget_set_events (m_iconWindow
, GDK_BUTTON_PRESS_MASK
| GDK_BUTTON_RELEASE_MASK
);
765 gtk_widget_set_app_paintable (GTK_WIDGET (m_iconWindow
), TRUE
);
768 gtk_widget_pop_visual ();
770 gtk_widget_pop_colormap ();
772 gtk_widget_set_usize (m_iconWindow
, width
, height
);
773 gtk_widget_realize (m_iconWindow
);
775 gtk_signal_connect( GTK_OBJECT(m_iconWindow
), "configure_event",
776 GTK_SIGNAL_FUNC(gtk_dnd_window_configure_callback
), (gpointer
)this );
778 gdk_window_set_back_pixmap (m_iconWindow
->window
, pixmap
, FALSE
);
781 gtk_widget_shape_combine_mask (m_iconWindow
, mask
, 0, 0);
783 gtk_drag_set_icon_widget( context
, m_iconWindow
, 0, 0 );
786 wxDragResult
wxDropSource::DoDragDrop(int flags
)
788 wxCHECK_MSG( m_data
&& m_data
->GetFormatCount(), wxDragNone
,
789 wxT("Drop source: no data") );
792 if (g_blockEventsOnDrag
)
796 g_blockEventsOnDrag
= TRUE
;
802 GtkTargetList
*target_list
= gtk_target_list_new( (GtkTargetEntry
*) NULL
, 0 );
804 wxDataFormat
*array
= new wxDataFormat
[ m_data
->GetFormatCount() ];
805 m_data
->GetAllFormats( array
);
806 size_t count
= m_data
->GetFormatCount();
807 for (size_t i
= 0; i
< count
; i
++)
809 GdkAtom atom
= array
[i
];
810 wxLogTrace(TRACE_DND
, wxT("Drop source: Supported atom %s"), gdk_atom_name( atom
));
811 gtk_target_list_add( target_list
, atom
, 0, 0 );
815 GdkEventMotion event
;
816 event
.window
= m_widget
->window
;
819 GdkModifierType state
;
820 gdk_window_get_pointer( event
.window
, &x
, &y
, &state
);
824 event
.time
= (guint32
)GDK_CURRENT_TIME
;
826 /* GTK wants to know which button was pressed which caused the dragging */
827 int button_number
= 0;
828 if (event
.state
& GDK_BUTTON1_MASK
) button_number
= 1;
829 else if (event
.state
& GDK_BUTTON2_MASK
) button_number
= 2;
830 else if (event
.state
& GDK_BUTTON3_MASK
) button_number
= 3;
833 /* disable GUI threads */
836 /* don't start dragging if no button is down */
839 int action
= GDK_ACTION_COPY
;
840 if ( flags
& wxDrag_AllowMove
)
841 action
|= GDK_ACTION_MOVE
;
843 // VZ: as we already use g_blockEventsOnDrag it shouldn't be that bad
844 // to use a global to pass the flags to the drop target but I'd
845 // surely prefer a better way to do it
846 gs_flagsForDrag
= flags
;
848 GdkDragContext
*context
= gtk_drag_begin( m_widget
,
850 (GdkDragAction
)action
,
851 button_number
, /* number of mouse button which started drag */
852 (GdkEvent
*) &event
);
854 m_dragContext
= context
;
856 PrepareIcon( action
, context
);
859 gtk_main_iteration();
861 m_retValue
= ConvertFromGTK(context
->action
);
862 if ( m_retValue
== wxDragNone
)
863 m_retValue
= wxDragCancel
;
867 /* re-enable GUI threads */
870 g_blockEventsOnDrag
= FALSE
;
877 void wxDropSource::RegisterWindow()
879 if (!m_widget
) return;
881 gtk_signal_connect( GTK_OBJECT(m_widget
), "drag_data_get",
882 GTK_SIGNAL_FUNC (source_drag_data_get
), (gpointer
) this);
883 gtk_signal_connect (GTK_OBJECT(m_widget
), "drag_data_delete",
884 GTK_SIGNAL_FUNC (source_drag_data_delete
), (gpointer
) this );
885 gtk_signal_connect (GTK_OBJECT(m_widget
), "drag_begin",
886 GTK_SIGNAL_FUNC (source_drag_begin
), (gpointer
) this );
887 gtk_signal_connect (GTK_OBJECT(m_widget
), "drag_end",
888 GTK_SIGNAL_FUNC (source_drag_end
), (gpointer
) this );
892 void wxDropSource::UnregisterWindow()
894 if (!m_widget
) return;
896 gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget
),
897 GTK_SIGNAL_FUNC(source_drag_data_get
), (gpointer
) this );
898 gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget
),
899 GTK_SIGNAL_FUNC(source_drag_data_delete
), (gpointer
) this );
900 gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget
),
901 GTK_SIGNAL_FUNC(source_drag_begin
), (gpointer
) this );
902 gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget
),
903 GTK_SIGNAL_FUNC(source_drag_end
), (gpointer
) this );
907 // wxUSE_DRAG_AND_DROP