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 // ----------------------------------------------------------------------------
143 static void target_drag_leave( GtkWidget
*WXUNUSED(widget
),
144 GdkDragContext
*context
,
145 guint
WXUNUSED(time
),
146 wxDropTarget
*drop_target
)
148 if (g_isIdle
) wxapp_install_idle_handler();
150 /* inform the wxDropTarget about the current GdkDragContext.
151 this is only valid for the duration of this call */
152 drop_target
->SetDragContext( context
);
154 /* we don't need return values. this event is just for
156 drop_target
->OnLeave();
158 /* this has to be done because GDK has no "drag_enter" event */
159 drop_target
->m_firstMotion
= TRUE
;
161 /* after this, invalidate the drop_target's GdkDragContext */
162 drop_target
->SetDragContext( (GdkDragContext
*) NULL
);
166 // ----------------------------------------------------------------------------
168 // ----------------------------------------------------------------------------
171 static gboolean
target_drag_motion( GtkWidget
*WXUNUSED(widget
),
172 GdkDragContext
*context
,
176 wxDropTarget
*drop_target
)
178 if (g_isIdle
) wxapp_install_idle_handler();
180 /* Owen Taylor: "if the coordinates not in a drop zone,
181 return FALSE, otherwise call gtk_drag_status() and
184 /* inform the wxDropTarget about the current GdkDragContext.
185 this is only valid for the duration of this call */
186 drop_target
->SetDragContext( context
);
188 // GTK+ always supposes that we want to copy the data by default while we
189 // might want to move it, so examine not only suggested_action - which is
190 // only good if we don't have our own preferences - but also the actions
193 if (drop_target
->GetDefaultAction() == wxDragNone
)
195 // use default action set by wxDropSource::DoDragDrop()
196 if ( (gs_flagsForDrag
& wxDrag_DefaultMove
) == wxDrag_DefaultMove
&&
197 (context
->actions
& GDK_ACTION_MOVE
) )
199 // move is requested by the program and allowed by GTK+ - do it, even
200 // though suggested_action may be currently wxDragCopy
203 else // use whatever GTK+ says we should
205 result
= ConvertFromGTK(context
->suggested_action
);
207 if ( (result
== wxDragMove
) && !(gs_flagsForDrag
& wxDrag_AllowMove
) )
209 // we're requested to move but we can't
214 else if (drop_target
->GetDefaultAction() == wxDragMove
&&
215 (context
->actions
& GDK_ACTION_MOVE
))
221 if (context
->actions
& GDK_ACTION_COPY
)
223 else if (context
->actions
& GDK_ACTION_MOVE
)
229 if (drop_target
->m_firstMotion
)
231 /* the first "drag_motion" event substitutes a "drag_enter" event */
232 result
= drop_target
->OnEnter( x
, y
, result
);
236 /* give program a chance to react (i.e. to say no by returning FALSE) */
237 result
= drop_target
->OnDragOver( x
, y
, result
);
240 bool ret
= wxIsDragResultOk( result
);
243 GdkDragAction action
;
244 if (result
== wxDragCopy
)
245 action
= GDK_ACTION_COPY
;
246 else if (result
== wxDragLink
)
247 action
= GDK_ACTION_LINK
;
249 action
= GDK_ACTION_MOVE
;
251 gdk_drag_status( context
, action
, time
);
254 /* after this, invalidate the drop_target's GdkDragContext */
255 drop_target
->SetDragContext( (GdkDragContext
*) NULL
);
257 /* this has to be done because GDK has no "drag_enter" event */
258 drop_target
->m_firstMotion
= FALSE
;
264 // ----------------------------------------------------------------------------
266 // ----------------------------------------------------------------------------
269 static gboolean
target_drag_drop( GtkWidget
*widget
,
270 GdkDragContext
*context
,
274 wxDropTarget
*drop_target
)
276 if (g_isIdle
) wxapp_install_idle_handler();
278 /* Owen Taylor: "if the drop is not in a drop zone,
279 return FALSE, otherwise, if you aren't accepting
280 the drop, call gtk_drag_finish() with success == FALSE
281 otherwise call gtk_drag_data_get()" */
283 // printf( "drop.\n" );
285 /* this seems to make a difference between not accepting
286 due to wrong target area and due to wrong format. let
287 us hope that this is not required.. */
289 /* inform the wxDropTarget about the current GdkDragContext.
290 this is only valid for the duration of this call */
291 drop_target
->SetDragContext( context
);
293 /* inform the wxDropTarget about the current drag widget.
294 this is only valid for the duration of this call */
295 drop_target
->SetDragWidget( widget
);
297 /* inform the wxDropTarget about the current drag time.
298 this is only valid for the duration of this call */
299 drop_target
->SetDragTime( time
);
302 wxDragResult result = wxDragMove;
303 if (context->suggested_action == GDK_ACTION_COPY) result = wxDragCopy;
306 /* reset the block here as someone might very well
307 show a dialog as a reaction to a drop and this
308 wouldn't work without events */
309 g_blockEventsOnDrag
= FALSE
;
311 bool ret
= drop_target
->OnDrop( x
, y
);
315 wxLogTrace(TRACE_DND
, wxT( "Drop target: OnDrop returned FALSE") );
317 /* cancel the whole thing */
318 gtk_drag_finish( context
,
319 FALSE
, /* no success */
320 FALSE
, /* don't delete data on dropping side */
325 wxLogTrace(TRACE_DND
, wxT( "Drop target: OnDrop returned TRUE") );
328 /* disable GUI threads */
331 GdkAtom format
= drop_target
->GetMatchingPair();
333 // this does happen somehow, see bug 555111
334 wxCHECK_MSG( format
, FALSE
, _T("no matching GdkAtom for format?") )
337 GdkDragAction action = GDK_ACTION_MOVE;
338 if (result == wxDragCopy) action == GDK_ACTION_COPY;
339 context->action = action;
341 /* this should trigger an "drag_data_received" event */
342 gtk_drag_get_data( widget
,
348 /* re-enable GUI threads */
352 /* after this, invalidate the drop_target's GdkDragContext */
353 drop_target
->SetDragContext( (GdkDragContext
*) NULL
);
355 /* after this, invalidate the drop_target's drag widget */
356 drop_target
->SetDragWidget( (GtkWidget
*) NULL
);
358 /* this has to be done because GDK has no "drag_enter" event */
359 drop_target
->m_firstMotion
= TRUE
;
365 // ----------------------------------------------------------------------------
366 // "drag_data_received"
367 // ----------------------------------------------------------------------------
370 static void target_drag_data_received( GtkWidget
*WXUNUSED(widget
),
371 GdkDragContext
*context
,
374 GtkSelectionData
*data
,
375 guint
WXUNUSED(info
),
377 wxDropTarget
*drop_target
)
379 if (g_isIdle
) wxapp_install_idle_handler();
381 /* Owen Taylor: "call gtk_drag_finish() with
384 if ((data
->length
<= 0) || (data
->format
!= 8))
386 /* negative data length and non 8-bit data format
387 qualifies for junk */
388 gtk_drag_finish (context
, FALSE
, FALSE
, time
);
393 wxLogTrace(TRACE_DND
, wxT( "Drop target: data received event") );
395 /* inform the wxDropTarget about the current GtkSelectionData.
396 this is only valid for the duration of this call */
397 drop_target
->SetDragData( data
);
399 wxDragResult result
= ConvertFromGTK(context
->action
);
401 if ( wxIsDragResultOk( drop_target
->OnData( x
, y
, result
) ) )
403 wxLogTrace(TRACE_DND
, wxT( "Drop target: OnData returned TRUE") );
405 /* tell GTK that data transfer was successfull */
406 gtk_drag_finish( context
, TRUE
, FALSE
, time
);
410 wxLogTrace(TRACE_DND
, wxT( "Drop target: OnData returned FALSE") );
412 /* tell GTK that data transfer was not successfull */
413 gtk_drag_finish( context
, FALSE
, FALSE
, time
);
416 /* after this, invalidate the drop_target's drag data */
417 drop_target
->SetDragData( (GtkSelectionData
*) NULL
);
421 //----------------------------------------------------------------------------
423 //----------------------------------------------------------------------------
425 wxDropTarget::wxDropTarget( wxDataObject
*data
)
426 : wxDropTargetBase( data
)
428 m_firstMotion
= TRUE
;
429 m_dragContext
= (GdkDragContext
*) NULL
;
430 m_dragWidget
= (GtkWidget
*) NULL
;
431 m_dragData
= (GtkSelectionData
*) NULL
;
435 wxDragResult
wxDropTarget::OnDragOver( wxCoord
WXUNUSED(x
),
439 // GetMatchingPair() checks for m_dataObject too, no need to do it here
441 // disable the debug message from GetMatchingPair() - there are too many
447 return (GetMatchingPair() != (GdkAtom
) 0) ? def
: wxDragNone
;
450 bool wxDropTarget::OnDrop( wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
) )
455 return (GetMatchingPair() != (GdkAtom
) 0);
458 wxDragResult
wxDropTarget::OnData( wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
),
464 if (GetMatchingPair() == (GdkAtom
) 0)
467 return GetData() ? def
: wxDragNone
;
470 GdkAtom
wxDropTarget::GetMatchingPair()
478 GList
*child
= m_dragContext
->targets
;
481 GdkAtom formatAtom
= (GdkAtom
) GPOINTER_TO_INT(child
->data
);
482 wxDataFormat
format( formatAtom
);
485 wxLogTrace(TRACE_DND
, wxT("Drop target: drag has format: %s"),
486 format
.GetId().c_str());
489 if (m_dataObject
->IsSupportedFormat( format
))
498 bool wxDropTarget::GetData()
506 wxDataFormat
dragFormat( m_dragData
->target
);
508 if (!m_dataObject
->IsSupportedFormat( dragFormat
))
511 m_dataObject
->SetData( dragFormat
, (size_t)m_dragData
->length
, (const void*)m_dragData
->data
);
516 void wxDropTarget::UnregisterWidget( GtkWidget
*widget
)
518 wxCHECK_RET( widget
!= NULL
, wxT("unregister widget is NULL") );
520 gtk_drag_dest_unset( widget
);
522 gtk_signal_disconnect_by_func( GTK_OBJECT(widget
),
523 GTK_SIGNAL_FUNC(target_drag_leave
), (gpointer
) this );
525 gtk_signal_disconnect_by_func( GTK_OBJECT(widget
),
526 GTK_SIGNAL_FUNC(target_drag_motion
), (gpointer
) this );
528 gtk_signal_disconnect_by_func( GTK_OBJECT(widget
),
529 GTK_SIGNAL_FUNC(target_drag_drop
), (gpointer
) this );
531 gtk_signal_disconnect_by_func( GTK_OBJECT(widget
),
532 GTK_SIGNAL_FUNC(target_drag_data_received
), (gpointer
) this );
535 void wxDropTarget::RegisterWidget( GtkWidget
*widget
)
537 wxCHECK_RET( widget
!= NULL
, wxT("register widget is NULL") );
539 /* gtk_drag_dest_set() determines what default behaviour we'd like
540 GTK to supply. we don't want to specify out targets (=formats)
541 or actions in advance (i.e. not GTK_DEST_DEFAULT_MOTION and
542 not GTK_DEST_DEFAULT_DROP). instead we react individually to
543 "drag_motion" and "drag_drop" events. this makes it possible
544 to allow dropping on only a small area. we should set
545 GTK_DEST_DEFAULT_HIGHLIGHT as this will switch on the nice
546 highlighting if dragging over standard controls, but this
547 seems to be broken without the other two. */
549 gtk_drag_dest_set( widget
,
550 (GtkDestDefaults
) 0, /* no default behaviour */
551 (GtkTargetEntry
*) NULL
, /* we don't supply any formats here */
552 0, /* number of targets = 0 */
553 (GdkDragAction
) 0 ); /* we don't supply any actions here */
555 gtk_signal_connect( GTK_OBJECT(widget
), "drag_leave",
556 GTK_SIGNAL_FUNC(target_drag_leave
), (gpointer
) this );
558 gtk_signal_connect( GTK_OBJECT(widget
), "drag_motion",
559 GTK_SIGNAL_FUNC(target_drag_motion
), (gpointer
) this );
561 gtk_signal_connect( GTK_OBJECT(widget
), "drag_drop",
562 GTK_SIGNAL_FUNC(target_drag_drop
), (gpointer
) this );
564 gtk_signal_connect( GTK_OBJECT(widget
), "drag_data_received",
565 GTK_SIGNAL_FUNC(target_drag_data_received
), (gpointer
) this );
568 //----------------------------------------------------------------------------
570 //----------------------------------------------------------------------------
574 source_drag_data_get (GtkWidget
*WXUNUSED(widget
),
575 GdkDragContext
*WXUNUSED(context
),
576 GtkSelectionData
*selection_data
,
577 guint
WXUNUSED(info
),
578 guint
WXUNUSED(time
),
579 wxDropSource
*drop_source
)
581 if (g_isIdle
) wxapp_install_idle_handler();
583 wxDataFormat
format( selection_data
->target
);
585 wxLogTrace(TRACE_DND
, wxT("Drop source: format requested: %s"),
586 format
.GetId().c_str());
588 drop_source
->m_retValue
= wxDragCancel
;
590 wxDataObject
*data
= drop_source
->GetDataObject();
594 wxLogTrace(TRACE_DND
, wxT("Drop source: no data object") );
598 if (!data
->IsSupportedFormat(format
))
600 wxLogTrace(TRACE_DND
, wxT("Drop source: unsupported format") );
604 if (data
->GetDataSize(format
) == 0)
606 wxLogTrace(TRACE_DND
, wxT("Drop source: empty data") );
610 size_t size
= data
->GetDataSize(format
);
612 // printf( "data size: %d.\n", (int)data_size );
614 guchar
*d
= new guchar
[size
];
616 if (!data
->GetDataHere( format
, (void*)d
))
623 /* disable GUI threads */
626 gtk_selection_data_set( selection_data
,
627 selection_data
->target
,
633 /* enable GUI threads */
640 //----------------------------------------------------------------------------
641 // "drag_data_delete"
642 //----------------------------------------------------------------------------
645 static void source_drag_data_delete( GtkWidget
*WXUNUSED(widget
),
646 GdkDragContext
*context
,
647 wxDropSource
*WXUNUSED(drop_source
) )
650 wxapp_install_idle_handler();
652 // printf( "Drag source: drag_data_delete\n" );
656 //----------------------------------------------------------------------------
658 //----------------------------------------------------------------------------
661 static void source_drag_begin( GtkWidget
*WXUNUSED(widget
),
662 GdkDragContext
*WXUNUSED(context
),
663 wxDropSource
*WXUNUSED(drop_source
) )
666 wxapp_install_idle_handler();
668 // printf( "Drag source: drag_begin.\n" );
672 //----------------------------------------------------------------------------
674 //----------------------------------------------------------------------------
677 static void source_drag_end( GtkWidget
*WXUNUSED(widget
),
678 GdkDragContext
*WXUNUSED(context
),
679 wxDropSource
*drop_source
)
681 if (g_isIdle
) wxapp_install_idle_handler();
683 // printf( "Drag source: drag_end.\n" );
685 drop_source
->m_waiting
= FALSE
;
689 //-----------------------------------------------------------------------------
690 // "configure_event" from m_iconWindow
691 //-----------------------------------------------------------------------------
695 gtk_dnd_window_configure_callback( GtkWidget
*WXUNUSED(widget
), GdkEventConfigure
*WXUNUSED(event
), wxDropSource
*source
)
698 wxapp_install_idle_handler();
700 source
->GiveFeedback( ConvertFromGTK(source
->m_dragContext
->action
) );
706 //---------------------------------------------------------------------------
708 //---------------------------------------------------------------------------
710 wxDropSource::wxDropSource(wxWindow
*win
,
711 const wxIcon
&iconCopy
,
712 const wxIcon
&iconMove
,
713 const wxIcon
&iconNone
)
717 m_iconWindow
= (GtkWidget
*) NULL
;
720 m_widget
= win
->m_widget
;
721 if (win
->m_wxwindow
) m_widget
= win
->m_wxwindow
;
723 m_retValue
= wxDragCancel
;
725 SetIcons(iconCopy
, iconMove
, iconNone
);
728 wxDropSource::wxDropSource(wxDataObject
& data
,
730 const wxIcon
&iconCopy
,
731 const wxIcon
&iconMove
,
732 const wxIcon
&iconNone
)
738 m_iconWindow
= (GtkWidget
*) NULL
;
741 m_widget
= win
->m_widget
;
742 if (win
->m_wxwindow
) m_widget
= win
->m_wxwindow
;
744 m_retValue
= wxDragCancel
;
746 SetIcons(iconCopy
, iconMove
, iconNone
);
749 void wxDropSource::SetIcons(const wxIcon
&iconCopy
,
750 const wxIcon
&iconMove
,
751 const wxIcon
&iconNone
)
753 m_iconCopy
= iconCopy
;
754 m_iconMove
= iconMove
;
755 m_iconNone
= iconNone
;
757 if ( !m_iconCopy
.Ok() )
758 m_iconCopy
= wxIcon(page_xpm
);
759 if ( !m_iconMove
.Ok() )
760 m_iconMove
= m_iconCopy
;
761 if ( !m_iconNone
.Ok() )
762 m_iconNone
= m_iconCopy
;
765 wxDropSource::~wxDropSource()
769 void wxDropSource::PrepareIcon( int action
, GdkDragContext
*context
)
771 // get the right icon to display
773 if ( action
& GDK_ACTION_MOVE
)
775 else if ( action
& GDK_ACTION_COPY
)
781 if ( icon
->GetMask() )
782 mask
= icon
->GetMask()->GetBitmap();
784 mask
= (GdkBitmap
*)NULL
;
786 GdkPixmap
*pixmap
= icon
->GetPixmap();
789 gdk_window_get_size (pixmap
, &width
, &height
);
791 GdkColormap
*colormap
= gtk_widget_get_colormap( m_widget
);
793 gtk_widget_push_visual (gdk_colormap_get_visual (colormap
));
795 gtk_widget_push_colormap (colormap
);
797 m_iconWindow
= gtk_window_new (GTK_WINDOW_POPUP
);
798 gtk_widget_set_events (m_iconWindow
, GDK_BUTTON_PRESS_MASK
| GDK_BUTTON_RELEASE_MASK
);
799 gtk_widget_set_app_paintable (GTK_WIDGET (m_iconWindow
), TRUE
);
802 gtk_widget_pop_visual ();
804 gtk_widget_pop_colormap ();
806 gtk_widget_set_usize (m_iconWindow
, width
, height
);
807 gtk_widget_realize (m_iconWindow
);
809 gtk_signal_connect( GTK_OBJECT(m_iconWindow
), "configure_event",
810 GTK_SIGNAL_FUNC(gtk_dnd_window_configure_callback
), (gpointer
)this );
812 gdk_window_set_back_pixmap (m_iconWindow
->window
, pixmap
, FALSE
);
815 gtk_widget_shape_combine_mask (m_iconWindow
, mask
, 0, 0);
817 gtk_drag_set_icon_widget( context
, m_iconWindow
, 0, 0 );
820 wxDragResult
wxDropSource::DoDragDrop(int flags
)
822 wxCHECK_MSG( m_data
&& m_data
->GetFormatCount(), wxDragNone
,
823 wxT("Drop source: no data") );
826 if (g_blockEventsOnDrag
)
830 g_blockEventsOnDrag
= TRUE
;
836 GtkTargetList
*target_list
= gtk_target_list_new( (GtkTargetEntry
*) NULL
, 0 );
838 wxDataFormat
*array
= new wxDataFormat
[ m_data
->GetFormatCount() ];
839 m_data
->GetAllFormats( array
);
840 size_t count
= m_data
->GetFormatCount();
841 for (size_t i
= 0; i
< count
; i
++)
843 GdkAtom atom
= array
[i
];
844 wxLogTrace(TRACE_DND
, wxT("Drop source: Supported atom %s"), gdk_atom_name( atom
));
845 gtk_target_list_add( target_list
, atom
, 0, 0 );
849 GdkEventMotion event
;
850 event
.window
= m_widget
->window
;
853 GdkModifierType state
;
854 gdk_window_get_pointer( event
.window
, &x
, &y
, &state
);
858 event
.time
= (guint32
)GDK_CURRENT_TIME
;
860 /* GTK wants to know which button was pressed which caused the dragging */
861 int button_number
= 0;
862 if (event
.state
& GDK_BUTTON1_MASK
) button_number
= 1;
863 else if (event
.state
& GDK_BUTTON2_MASK
) button_number
= 2;
864 else if (event
.state
& GDK_BUTTON3_MASK
) button_number
= 3;
867 /* disable GUI threads */
870 /* don't start dragging if no button is down */
873 int action
= GDK_ACTION_COPY
;
874 if ( flags
& wxDrag_AllowMove
)
875 action
|= GDK_ACTION_MOVE
;
877 // VZ: as we already use g_blockEventsOnDrag it shouldn't be that bad
878 // to use a global to pass the flags to the drop target but I'd
879 // surely prefer a better way to do it
880 gs_flagsForDrag
= flags
;
882 GdkDragContext
*context
= gtk_drag_begin( m_widget
,
884 (GdkDragAction
)action
,
885 button_number
, /* number of mouse button which started drag */
886 (GdkEvent
*) &event
);
888 m_dragContext
= context
;
890 PrepareIcon( action
, context
);
893 gtk_main_iteration();
895 m_retValue
= ConvertFromGTK(context
->action
);
896 if ( m_retValue
== wxDragNone
)
897 m_retValue
= wxDragCancel
;
901 /* re-enable GUI threads */
904 g_blockEventsOnDrag
= FALSE
;
911 void wxDropSource::RegisterWindow()
913 if (!m_widget
) return;
915 gtk_signal_connect( GTK_OBJECT(m_widget
), "drag_data_get",
916 GTK_SIGNAL_FUNC (source_drag_data_get
), (gpointer
) this);
917 gtk_signal_connect (GTK_OBJECT(m_widget
), "drag_data_delete",
918 GTK_SIGNAL_FUNC (source_drag_data_delete
), (gpointer
) this );
919 gtk_signal_connect (GTK_OBJECT(m_widget
), "drag_begin",
920 GTK_SIGNAL_FUNC (source_drag_begin
), (gpointer
) this );
921 gtk_signal_connect (GTK_OBJECT(m_widget
), "drag_end",
922 GTK_SIGNAL_FUNC (source_drag_end
), (gpointer
) this );
926 void wxDropSource::UnregisterWindow()
928 if (!m_widget
) return;
930 gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget
),
931 GTK_SIGNAL_FUNC(source_drag_data_get
), (gpointer
) this );
932 gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget
),
933 GTK_SIGNAL_FUNC(source_drag_data_delete
), (gpointer
) this );
934 gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget
),
935 GTK_SIGNAL_FUNC(source_drag_begin
), (gpointer
) this );
936 gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget
),
937 GTK_SIGNAL_FUNC(source_drag_end
), (gpointer
) this );
941 // wxUSE_DRAG_AND_DROP