1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxDropTarget class
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "dnd.h"
16 #if wxUSE_DRAG_AND_DROP
18 #include "wx/window.h"
20 #include "wx/gdicmn.h"
24 #include "wx/gtk/private.h"
26 #include <gdk/gdkprivate.h>
28 #include <gtk/gtkdnd.h>
29 #include <gtk/gtkselection.h>
31 //-----------------------------------------------------------------------------
33 //-----------------------------------------------------------------------------
35 extern void wxapp_install_idle_handler();
38 //-----------------------------------------------------------------------------
40 //-----------------------------------------------------------------------------
45 //----------------------------------------------------------------------------
47 //----------------------------------------------------------------------------
49 extern bool g_blockEventsOnDrag
;
51 // the flags used for the last DoDragDrop()
52 static long gs_flagsForDrag
= 0;
54 // the trace mask we use with wxLogTrace() - call
55 // wxLog::AddTraceMask(TRACE_DND) to enable the trace messages from here
56 // (there are quite a few of them, so don't enable this by default)
57 static const wxChar
*TRACE_DND
= _T("dnd");
59 //----------------------------------------------------------------------------
61 //----------------------------------------------------------------------------
64 static const char * page_xpm
[] = {
65 /* width height ncolors chars_per_pixel */
74 " ................... ",
75 " .XXXXXXXXXXXXXXXXX.. ",
76 " .XXXXXXXXXXXXXXXXX.o. ",
77 " .XXXXXXXXXXXXXXXXX.oo. ",
78 " .XXXXXXXXXXXXXXXXX.ooo. ",
79 " .XXXXXXXXXXXXXXXXX.oooo. ",
80 " .XXXXXXXXXXXXXXXXX....... ",
81 " .XXXXXOOOOOOOOOOXXXooooo. ",
82 " .XXXXXXXXXXXXXXXXXXooooo. ",
83 " .XXXXXOOOOOOOOOOXXXXXXXX. ",
84 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
85 " .XXXXXXXOOOOOOOOOXXXXXXX. ",
86 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
87 " .XXXXXXOOOOOOOOOOXXXXXXX. ",
88 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
89 " .XXXXXOOOOOOOOOOXXXXXXXX. ",
90 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
91 " .XXXXXXXOOOOOOOOOXXXXXXX. ",
92 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
93 " .XXXXXXOOOOOOOOOOXXXXXXX. ",
94 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
95 " .XXXXXOOOOOOOOOOXXXXXXXX. ",
96 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
97 " .XXXXXXOOOOOOOOOOXXXXXXX. ",
98 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
99 " .XXXXXOOOOOOOXXXXXXXXXXX. ",
100 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
101 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
102 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
103 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
104 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
105 " ......................... "};
108 // ============================================================================
110 // ============================================================================
112 // ----------------------------------------------------------------------------
113 // convert between GTK+ and wxWindows DND constants
114 // ----------------------------------------------------------------------------
116 static wxDragResult
ConvertFromGTK(long action
)
120 case GDK_ACTION_COPY
:
123 case GDK_ACTION_LINK
:
126 case GDK_ACTION_MOVE
:
133 // ----------------------------------------------------------------------------
135 // ----------------------------------------------------------------------------
137 static void target_drag_leave( GtkWidget
*WXUNUSED(widget
),
138 GdkDragContext
*context
,
139 guint
WXUNUSED(time
),
140 wxDropTarget
*drop_target
)
142 if (g_isIdle
) wxapp_install_idle_handler();
144 /* inform the wxDropTarget about the current GdkDragContext.
145 this is only valid for the duration of this call */
146 drop_target
->SetDragContext( context
);
148 /* we don't need return values. this event is just for
150 drop_target
->OnLeave();
152 /* this has to be done because GDK has no "drag_enter" event */
153 drop_target
->m_firstMotion
= TRUE
;
155 /* after this, invalidate the drop_target's GdkDragContext */
156 drop_target
->SetDragContext( (GdkDragContext
*) NULL
);
159 // ----------------------------------------------------------------------------
161 // ----------------------------------------------------------------------------
163 static gboolean
target_drag_motion( GtkWidget
*WXUNUSED(widget
),
164 GdkDragContext
*context
,
168 wxDropTarget
*drop_target
)
170 if (g_isIdle
) wxapp_install_idle_handler();
172 /* Owen Taylor: "if the coordinates not in a drop zone,
173 return FALSE, otherwise call gtk_drag_status() and
176 /* inform the wxDropTarget about the current GdkDragContext.
177 this is only valid for the duration of this call */
178 drop_target
->SetDragContext( context
);
180 // GTK+ always supposes that we want to copy the data by default while we
181 // might want to move it, so examine not only suggested_action - which is
182 // only good if we don't have our own preferences - but also the actions
185 if ( (gs_flagsForDrag
& wxDrag_DefaultMove
) == wxDrag_DefaultMove
&&
186 (context
->actions
& GDK_ACTION_MOVE
) )
188 // move is requested by the program and allowed by GTK+ - do it, even
189 // though suggested_action may be currently wxDragCopy
192 else // use whatever GTK+ says we should
194 result
= ConvertFromGTK(context
->suggested_action
);
196 if ( (result
== wxDragMove
) && !(gs_flagsForDrag
& wxDrag_AllowMove
) )
198 // we're requested to move but we can't
203 if (drop_target
->m_firstMotion
)
205 /* the first "drag_motion" event substitutes a "drag_enter" event */
206 result
= drop_target
->OnEnter( x
, y
, result
);
210 /* give program a chance to react (i.e. to say no by returning FALSE) */
211 result
= drop_target
->OnDragOver( x
, y
, result
);
214 bool ret
= wxIsDragResultOk( result
);
217 GdkDragAction action
;
218 if (result
== wxDragCopy
)
219 action
= GDK_ACTION_COPY
;
220 else if (result
== wxDragLink
)
221 action
= GDK_ACTION_LINK
;
223 action
= GDK_ACTION_MOVE
;
225 gdk_drag_status( context
, action
, time
);
228 /* after this, invalidate the drop_target's GdkDragContext */
229 drop_target
->SetDragContext( (GdkDragContext
*) NULL
);
231 /* this has to be done because GDK has no "drag_enter" event */
232 drop_target
->m_firstMotion
= FALSE
;
237 // ----------------------------------------------------------------------------
239 // ----------------------------------------------------------------------------
241 static gboolean
target_drag_drop( GtkWidget
*widget
,
242 GdkDragContext
*context
,
246 wxDropTarget
*drop_target
)
248 if (g_isIdle
) wxapp_install_idle_handler();
250 /* Owen Taylor: "if the drop is not in a drop zone,
251 return FALSE, otherwise, if you aren't accepting
252 the drop, call gtk_drag_finish() with success == FALSE
253 otherwise call gtk_drag_data_get()" */
255 // printf( "drop.\n" );
257 /* this seems to make a difference between not accepting
258 due to wrong target area and due to wrong format. let
259 us hope that this is not required.. */
261 /* inform the wxDropTarget about the current GdkDragContext.
262 this is only valid for the duration of this call */
263 drop_target
->SetDragContext( context
);
265 /* inform the wxDropTarget about the current drag widget.
266 this is only valid for the duration of this call */
267 drop_target
->SetDragWidget( widget
);
269 /* inform the wxDropTarget about the current drag time.
270 this is only valid for the duration of this call */
271 drop_target
->SetDragTime( time
);
274 wxDragResult result = wxDragMove;
275 if (context->suggested_action == GDK_ACTION_COPY) result = wxDragCopy;
278 /* reset the block here as someone might very well
279 show a dialog as a reaction to a drop and this
280 wouldn't work without events */
281 g_blockEventsOnDrag
= FALSE
;
283 bool ret
= drop_target
->OnDrop( x
, y
);
287 wxLogTrace(TRACE_DND
, wxT( "Drop target: OnDrop returned FALSE") );
289 /* cancel the whole thing */
290 gtk_drag_finish( context
,
291 FALSE
, /* no success */
292 FALSE
, /* don't delete data on dropping side */
297 wxLogTrace(TRACE_DND
, wxT( "Drop target: OnDrop returned TRUE") );
300 /* disable GUI threads */
303 GdkAtom format
= drop_target
->GetMatchingPair();
307 GdkDragAction action = GDK_ACTION_MOVE;
308 if (result == wxDragCopy) action == GDK_ACTION_COPY;
309 context->action = action;
311 /* this should trigger an "drag_data_received" event */
312 gtk_drag_get_data( widget
,
318 /* re-enable GUI threads */
322 /* after this, invalidate the drop_target's GdkDragContext */
323 drop_target
->SetDragContext( (GdkDragContext
*) NULL
);
325 /* after this, invalidate the drop_target's drag widget */
326 drop_target
->SetDragWidget( (GtkWidget
*) NULL
);
328 /* this has to be done because GDK has no "drag_enter" event */
329 drop_target
->m_firstMotion
= TRUE
;
334 // ----------------------------------------------------------------------------
335 // "drag_data_received"
336 // ----------------------------------------------------------------------------
338 static void target_drag_data_received( GtkWidget
*WXUNUSED(widget
),
339 GdkDragContext
*context
,
342 GtkSelectionData
*data
,
343 guint
WXUNUSED(info
),
345 wxDropTarget
*drop_target
)
347 if (g_isIdle
) wxapp_install_idle_handler();
349 /* Owen Taylor: "call gtk_drag_finish() with
352 if ((data
->length
<= 0) || (data
->format
!= 8))
354 /* negative data length and non 8-bit data format
355 qualifies for junk */
356 gtk_drag_finish (context
, FALSE
, FALSE
, time
);
361 wxLogTrace(TRACE_DND
, wxT( "Drop target: data received event") );
363 /* inform the wxDropTarget about the current GtkSelectionData.
364 this is only valid for the duration of this call */
365 drop_target
->SetDragData( data
);
367 wxDragResult result
= ConvertFromGTK(context
->suggested_action
);
369 if ( wxIsDragResultOk( drop_target
->OnData( x
, y
, result
) ) )
371 wxLogTrace(TRACE_DND
, wxT( "Drop target: OnData returned TRUE") );
373 /* tell GTK that data transfer was successfull */
374 gtk_drag_finish( context
, TRUE
, FALSE
, time
);
378 wxLogTrace(TRACE_DND
, wxT( "Drop target: OnData returned FALSE") );
380 /* tell GTK that data transfer was not successfull */
381 gtk_drag_finish( context
, FALSE
, FALSE
, time
);
384 /* after this, invalidate the drop_target's drag data */
385 drop_target
->SetDragData( (GtkSelectionData
*) NULL
);
388 //----------------------------------------------------------------------------
390 //----------------------------------------------------------------------------
392 wxDropTarget::wxDropTarget( wxDataObject
*data
)
393 : wxDropTargetBase( data
)
395 m_firstMotion
= TRUE
;
396 m_dragContext
= (GdkDragContext
*) NULL
;
397 m_dragWidget
= (GtkWidget
*) NULL
;
398 m_dragData
= (GtkSelectionData
*) NULL
;
402 wxDragResult
wxDropTarget::OnDragOver( wxCoord
WXUNUSED(x
),
406 // GetMatchingPair() checks for m_dataObject too, no need to do it here
408 // disable the debug message from GetMatchingPair() - there are too many
414 return (GetMatchingPair() != (GdkAtom
) 0) ? def
: wxDragNone
;
417 bool wxDropTarget::OnDrop( wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
) )
422 return (GetMatchingPair() != (GdkAtom
) 0);
425 wxDragResult
wxDropTarget::OnData( wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
),
431 if (GetMatchingPair() == (GdkAtom
) 0)
434 return GetData() ? def
: wxDragNone
;
437 GdkAtom
wxDropTarget::GetMatchingPair()
445 GList
*child
= m_dragContext
->targets
;
448 GdkAtom formatAtom
= (GdkAtom
) GPOINTER_TO_INT(child
->data
);
449 wxDataFormat
format( formatAtom
);
452 wxLogTrace(TRACE_DND
, wxT("Drop target: drag has format: %s"),
453 format
.GetId().c_str());
456 if (m_dataObject
->IsSupportedFormat( format
))
465 bool wxDropTarget::GetData()
473 wxDataFormat
dragFormat( m_dragData
->target
);
475 if (!m_dataObject
->IsSupportedFormat( dragFormat
))
478 m_dataObject
->SetData( dragFormat
, (size_t)m_dragData
->length
, (const void*)m_dragData
->data
);
483 void wxDropTarget::UnregisterWidget( GtkWidget
*widget
)
485 wxCHECK_RET( widget
!= NULL
, wxT("unregister widget is NULL") );
487 gtk_drag_dest_unset( widget
);
489 gtk_signal_disconnect_by_func( GTK_OBJECT(widget
),
490 GTK_SIGNAL_FUNC(target_drag_leave
), (gpointer
) this );
492 gtk_signal_disconnect_by_func( GTK_OBJECT(widget
),
493 GTK_SIGNAL_FUNC(target_drag_motion
), (gpointer
) this );
495 gtk_signal_disconnect_by_func( GTK_OBJECT(widget
),
496 GTK_SIGNAL_FUNC(target_drag_drop
), (gpointer
) this );
498 gtk_signal_disconnect_by_func( GTK_OBJECT(widget
),
499 GTK_SIGNAL_FUNC(target_drag_data_received
), (gpointer
) this );
502 void wxDropTarget::RegisterWidget( GtkWidget
*widget
)
504 wxCHECK_RET( widget
!= NULL
, wxT("register widget is NULL") );
506 /* gtk_drag_dest_set() determines what default behaviour we'd like
507 GTK to supply. we don't want to specify out targets (=formats)
508 or actions in advance (i.e. not GTK_DEST_DEFAULT_MOTION and
509 not GTK_DEST_DEFAULT_DROP). instead we react individually to
510 "drag_motion" and "drag_drop" events. this makes it possible
511 to allow dropping on only a small area. we should set
512 GTK_DEST_DEFAULT_HIGHLIGHT as this will switch on the nice
513 highlighting if dragging over standard controls, but this
514 seems to be broken without the other two. */
516 gtk_drag_dest_set( widget
,
517 (GtkDestDefaults
) 0, /* no default behaviour */
518 (GtkTargetEntry
*) NULL
, /* we don't supply any formats here */
519 0, /* number of targets = 0 */
520 (GdkDragAction
) 0 ); /* we don't supply any actions here */
522 gtk_signal_connect( GTK_OBJECT(widget
), "drag_leave",
523 GTK_SIGNAL_FUNC(target_drag_leave
), (gpointer
) this );
525 gtk_signal_connect( GTK_OBJECT(widget
), "drag_motion",
526 GTK_SIGNAL_FUNC(target_drag_motion
), (gpointer
) this );
528 gtk_signal_connect( GTK_OBJECT(widget
), "drag_drop",
529 GTK_SIGNAL_FUNC(target_drag_drop
), (gpointer
) this );
531 gtk_signal_connect( GTK_OBJECT(widget
), "drag_data_received",
532 GTK_SIGNAL_FUNC(target_drag_data_received
), (gpointer
) this );
535 //----------------------------------------------------------------------------
537 //----------------------------------------------------------------------------
540 source_drag_data_get (GtkWidget
*WXUNUSED(widget
),
541 GdkDragContext
*WXUNUSED(context
),
542 GtkSelectionData
*selection_data
,
543 guint
WXUNUSED(info
),
544 guint
WXUNUSED(time
),
545 wxDropSource
*drop_source
)
547 if (g_isIdle
) wxapp_install_idle_handler();
549 wxDataFormat
format( selection_data
->target
);
551 wxLogTrace(TRACE_DND
, wxT("Drop source: format requested: %s"),
552 format
.GetId().c_str());
554 drop_source
->m_retValue
= wxDragCancel
;
556 wxDataObject
*data
= drop_source
->GetDataObject();
560 wxLogTrace(TRACE_DND
, wxT("Drop source: no data object") );
564 if (!data
->IsSupportedFormat(format
))
566 wxLogTrace(TRACE_DND
, wxT("Drop source: unsupported format") );
570 if (data
->GetDataSize(format
) == 0)
572 wxLogTrace(TRACE_DND
, wxT("Drop source: empty data") );
576 size_t size
= data
->GetDataSize(format
);
578 // printf( "data size: %d.\n", (int)data_size );
580 guchar
*d
= new guchar
[size
];
582 if (!data
->GetDataHere( format
, (void*)d
))
589 /* disable GUI threads */
592 gtk_selection_data_set( selection_data
,
593 selection_data
->target
,
599 /* enable GUI threads */
605 //----------------------------------------------------------------------------
606 // "drag_data_delete"
607 //----------------------------------------------------------------------------
609 static void source_drag_data_delete( GtkWidget
*WXUNUSED(widget
),
610 GdkDragContext
*context
,
611 wxDropSource
*WXUNUSED(drop_source
) )
614 wxapp_install_idle_handler();
616 // printf( "Drag source: drag_data_delete\n" );
619 //----------------------------------------------------------------------------
621 //----------------------------------------------------------------------------
623 static void source_drag_begin( GtkWidget
*WXUNUSED(widget
),
624 GdkDragContext
*WXUNUSED(context
),
625 wxDropSource
*WXUNUSED(drop_source
) )
628 wxapp_install_idle_handler();
630 // printf( "Drag source: drag_begin.\n" );
633 //----------------------------------------------------------------------------
635 //----------------------------------------------------------------------------
637 static void source_drag_end( GtkWidget
*WXUNUSED(widget
),
638 GdkDragContext
*WXUNUSED(context
),
639 wxDropSource
*drop_source
)
641 if (g_isIdle
) wxapp_install_idle_handler();
643 // printf( "Drag source: drag_end.\n" );
645 drop_source
->m_waiting
= FALSE
;
648 //-----------------------------------------------------------------------------
649 // "configure_event" from m_iconWindow
650 //-----------------------------------------------------------------------------
653 gtk_dnd_window_configure_callback( GtkWidget
*WXUNUSED(widget
), GdkEventConfigure
*WXUNUSED(event
), wxDropSource
*source
)
656 wxapp_install_idle_handler();
658 source
->GiveFeedback( ConvertFromGTK(source
->m_dragContext
->action
) );
663 //---------------------------------------------------------------------------
665 //---------------------------------------------------------------------------
667 wxDropSource::wxDropSource(wxWindow
*win
,
668 const wxIcon
&iconCopy
,
669 const wxIcon
&iconMove
,
670 const wxIcon
&iconNone
)
674 m_iconWindow
= (GtkWidget
*) NULL
;
677 m_widget
= win
->m_widget
;
678 if (win
->m_wxwindow
) m_widget
= win
->m_wxwindow
;
680 m_retValue
= wxDragCancel
;
682 SetIcons(iconCopy
, iconMove
, iconNone
);
685 wxDropSource::wxDropSource(wxDataObject
& data
,
687 const wxIcon
&iconCopy
,
688 const wxIcon
&iconMove
,
689 const wxIcon
&iconNone
)
695 m_iconWindow
= (GtkWidget
*) NULL
;
698 m_widget
= win
->m_widget
;
699 if (win
->m_wxwindow
) m_widget
= win
->m_wxwindow
;
701 m_retValue
= wxDragCancel
;
703 SetIcons(iconCopy
, iconMove
, iconNone
);
706 void wxDropSource::SetIcons(const wxIcon
&iconCopy
,
707 const wxIcon
&iconMove
,
708 const wxIcon
&iconNone
)
710 m_iconCopy
= iconCopy
;
711 m_iconMove
= iconMove
;
712 m_iconNone
= iconNone
;
714 if ( !m_iconCopy
.Ok() )
715 m_iconCopy
= wxIcon(page_xpm
);
716 if ( !m_iconMove
.Ok() )
717 m_iconMove
= m_iconCopy
;
718 if ( !m_iconNone
.Ok() )
719 m_iconNone
= m_iconCopy
;
722 wxDropSource::~wxDropSource()
726 void wxDropSource::PrepareIcon( int action
, GdkDragContext
*context
)
728 // get the right icon to display
730 if ( action
& GDK_ACTION_MOVE
)
732 else if ( action
& GDK_ACTION_COPY
)
738 if ( icon
->GetMask() )
739 mask
= icon
->GetMask()->GetBitmap();
741 mask
= (GdkBitmap
*)NULL
;
743 GdkPixmap
*pixmap
= icon
->GetPixmap();
746 gdk_window_get_size (pixmap
, &width
, &height
);
748 GdkColormap
*colormap
= gtk_widget_get_colormap( m_widget
);
750 gtk_widget_push_visual (gdk_colormap_get_visual (colormap
));
752 gtk_widget_push_colormap (colormap
);
754 m_iconWindow
= gtk_window_new (GTK_WINDOW_POPUP
);
755 gtk_widget_set_events (m_iconWindow
, GDK_BUTTON_PRESS_MASK
| GDK_BUTTON_RELEASE_MASK
);
756 gtk_widget_set_app_paintable (GTK_WIDGET (m_iconWindow
), TRUE
);
759 gtk_widget_pop_visual ();
761 gtk_widget_pop_colormap ();
763 gtk_widget_set_usize (m_iconWindow
, width
, height
);
764 gtk_widget_realize (m_iconWindow
);
766 gtk_signal_connect( GTK_OBJECT(m_iconWindow
), "configure_event",
767 GTK_SIGNAL_FUNC(gtk_dnd_window_configure_callback
), (gpointer
)this );
769 gdk_window_set_back_pixmap (m_iconWindow
->window
, pixmap
, FALSE
);
772 gtk_widget_shape_combine_mask (m_iconWindow
, mask
, 0, 0);
774 gtk_drag_set_icon_widget( context
, m_iconWindow
, 0, 0 );
777 wxDragResult
wxDropSource::DoDragDrop(int flags
)
779 wxCHECK_MSG( m_data
&& m_data
->GetFormatCount(), wxDragNone
,
780 wxT("Drop source: no data") );
783 if (g_blockEventsOnDrag
)
787 g_blockEventsOnDrag
= TRUE
;
793 GtkTargetList
*target_list
= gtk_target_list_new( (GtkTargetEntry
*) NULL
, 0 );
795 wxDataFormat
*array
= new wxDataFormat
[ m_data
->GetFormatCount() ];
796 m_data
->GetAllFormats( array
);
797 size_t count
= m_data
->GetFormatCount();
798 for (size_t i
= 0; i
< count
; i
++)
800 GdkAtom atom
= array
[i
];
801 wxLogTrace(TRACE_DND
, wxT("Drop source: Supported atom %s"), gdk_atom_name( atom
));
802 gtk_target_list_add( target_list
, atom
, 0, 0 );
806 GdkEventMotion event
;
807 event
.window
= m_widget
->window
;
810 GdkModifierType state
;
811 gdk_window_get_pointer( event
.window
, &x
, &y
, &state
);
815 event
.time
= (guint32
)GDK_CURRENT_TIME
;
817 /* GTK wants to know which button was pressed which caused the dragging */
818 int button_number
= 0;
819 if (event
.state
& GDK_BUTTON1_MASK
) button_number
= 1;
820 else if (event
.state
& GDK_BUTTON2_MASK
) button_number
= 2;
821 else if (event
.state
& GDK_BUTTON3_MASK
) button_number
= 3;
824 /* disable GUI threads */
827 /* don't start dragging if no button is down */
830 int action
= GDK_ACTION_COPY
;
831 if ( flags
& wxDrag_AllowMove
)
832 action
|= GDK_ACTION_MOVE
;
834 // VZ: as we already use g_blockEventsOnDrag it shouldn't be that bad
835 // to use a global to pass the flags to the drop target but I'd
836 // surely prefer a better way to do it
837 gs_flagsForDrag
= flags
;
839 GdkDragContext
*context
= gtk_drag_begin( m_widget
,
841 (GdkDragAction
)action
,
842 button_number
, /* number of mouse button which started drag */
843 (GdkEvent
*) &event
);
845 m_dragContext
= context
;
847 PrepareIcon( action
, context
);
850 gtk_main_iteration();
852 m_retValue
= ConvertFromGTK(context
->action
);
853 if ( m_retValue
== wxDragNone
)
854 m_retValue
= wxDragCancel
;
858 /* re-enable GUI threads */
861 g_blockEventsOnDrag
= FALSE
;
868 void wxDropSource::RegisterWindow()
870 if (!m_widget
) return;
872 gtk_signal_connect( GTK_OBJECT(m_widget
), "drag_data_get",
873 GTK_SIGNAL_FUNC (source_drag_data_get
), (gpointer
) this);
874 gtk_signal_connect (GTK_OBJECT(m_widget
), "drag_data_delete",
875 GTK_SIGNAL_FUNC (source_drag_data_delete
), (gpointer
) this );
876 gtk_signal_connect (GTK_OBJECT(m_widget
), "drag_begin",
877 GTK_SIGNAL_FUNC (source_drag_begin
), (gpointer
) this );
878 gtk_signal_connect (GTK_OBJECT(m_widget
), "drag_end",
879 GTK_SIGNAL_FUNC (source_drag_end
), (gpointer
) this );
883 void wxDropSource::UnregisterWindow()
885 if (!m_widget
) return;
887 gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget
),
888 GTK_SIGNAL_FUNC(source_drag_data_get
), (gpointer
) this );
889 gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget
),
890 GTK_SIGNAL_FUNC(source_drag_data_delete
), (gpointer
) this );
891 gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget
),
892 GTK_SIGNAL_FUNC(source_drag_begin
), (gpointer
) this );
893 gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget
),
894 GTK_SIGNAL_FUNC(source_drag_end
), (gpointer
) this );
898 // wxUSE_DRAG_AND_DROP