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"
18 #if wxUSE_DRAG_AND_DROP
20 #include "wx/window.h"
22 #include "wx/gdicmn.h"
26 #include "wx/gtk/private.h"
28 #include <gdk/gdkprivate.h>
30 #include <gtk/gtkdnd.h>
31 #include <gtk/gtkselection.h>
33 //-----------------------------------------------------------------------------
35 //-----------------------------------------------------------------------------
37 extern void wxapp_install_idle_handler();
40 //-----------------------------------------------------------------------------
42 //-----------------------------------------------------------------------------
47 //----------------------------------------------------------------------------
49 //----------------------------------------------------------------------------
51 extern bool g_blockEventsOnDrag
;
53 // the flags used for the last DoDragDrop()
54 static long gs_flagsForDrag
= 0;
56 // the trace mask we use with wxLogTrace() - call
57 // wxLog::AddTraceMask(TRACE_DND) to enable the trace messages from here
58 // (there are quite a few of them, so don't enable this by default)
59 static const wxChar
*TRACE_DND
= _T("dnd");
61 //----------------------------------------------------------------------------
63 //----------------------------------------------------------------------------
66 static const char * page_xpm
[] = {
67 /* width height ncolors chars_per_pixel */
76 " ................... ",
77 " .XXXXXXXXXXXXXXXXX.. ",
78 " .XXXXXXXXXXXXXXXXX.o. ",
79 " .XXXXXXXXXXXXXXXXX.oo. ",
80 " .XXXXXXXXXXXXXXXXX.ooo. ",
81 " .XXXXXXXXXXXXXXXXX.oooo. ",
82 " .XXXXXXXXXXXXXXXXX....... ",
83 " .XXXXXOOOOOOOOOOXXXooooo. ",
84 " .XXXXXXXXXXXXXXXXXXooooo. ",
85 " .XXXXXOOOOOOOOOOXXXXXXXX. ",
86 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
87 " .XXXXXXXOOOOOOOOOXXXXXXX. ",
88 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
89 " .XXXXXXOOOOOOOOOOXXXXXXX. ",
90 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
91 " .XXXXXOOOOOOOOOOXXXXXXXX. ",
92 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
93 " .XXXXXXXOOOOOOOOOXXXXXXX. ",
94 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
95 " .XXXXXXOOOOOOOOOOXXXXXXX. ",
96 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
97 " .XXXXXOOOOOOOOOOXXXXXXXX. ",
98 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
99 " .XXXXXXOOOOOOOOOOXXXXXXX. ",
100 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
101 " .XXXXXOOOOOOOXXXXXXXXXXX. ",
102 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
103 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
104 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
105 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
106 " .XXXXXXXXXXXXXXXXXXXXXXX. ",
107 " ......................... "};
110 // ============================================================================
112 // ============================================================================
114 // ----------------------------------------------------------------------------
115 // convert between GTK+ and wxWindows DND constants
116 // ----------------------------------------------------------------------------
118 static wxDragResult
ConvertFromGTK(long action
)
122 case GDK_ACTION_COPY
:
125 case GDK_ACTION_LINK
:
128 case GDK_ACTION_MOVE
:
135 // ----------------------------------------------------------------------------
137 // ----------------------------------------------------------------------------
139 static void target_drag_leave( GtkWidget
*WXUNUSED(widget
),
140 GdkDragContext
*context
,
141 guint
WXUNUSED(time
),
142 wxDropTarget
*drop_target
)
144 if (g_isIdle
) wxapp_install_idle_handler();
146 /* inform the wxDropTarget about the current GdkDragContext.
147 this is only valid for the duration of this call */
148 drop_target
->SetDragContext( context
);
150 /* we don't need return values. this event is just for
152 drop_target
->OnLeave();
154 /* this has to be done because GDK has no "drag_enter" event */
155 drop_target
->m_firstMotion
= TRUE
;
157 /* after this, invalidate the drop_target's GdkDragContext */
158 drop_target
->SetDragContext( (GdkDragContext
*) NULL
);
161 // ----------------------------------------------------------------------------
163 // ----------------------------------------------------------------------------
165 static gboolean
target_drag_motion( GtkWidget
*WXUNUSED(widget
),
166 GdkDragContext
*context
,
170 wxDropTarget
*drop_target
)
172 if (g_isIdle
) wxapp_install_idle_handler();
174 /* Owen Taylor: "if the coordinates not in a drop zone,
175 return FALSE, otherwise call gtk_drag_status() and
178 /* inform the wxDropTarget about the current GdkDragContext.
179 this is only valid for the duration of this call */
180 drop_target
->SetDragContext( context
);
182 // GTK+ always supposes that we want to copy the data by default while we
183 // might want to move it, so examine not only suggested_action - which is
184 // only good if we don't have our own preferences - but also the actions
187 if ( (gs_flagsForDrag
& wxDrag_DefaultMove
) == wxDrag_DefaultMove
&&
188 (context
->actions
& GDK_ACTION_MOVE
) )
190 // move is requested by the program and allowed by GTK+ - do it, even
191 // though suggested_action may be currently wxDragCopy
194 else // use whatever GTK+ says we should
196 result
= ConvertFromGTK(context
->suggested_action
);
198 if ( (result
== wxDragMove
) && !(gs_flagsForDrag
& wxDrag_AllowMove
) )
200 // we're requested to move but we can't
205 if (drop_target
->m_firstMotion
)
207 /* the first "drag_motion" event substitutes a "drag_enter" event */
208 result
= drop_target
->OnEnter( x
, y
, result
);
212 /* give program a chance to react (i.e. to say no by returning FALSE) */
213 result
= drop_target
->OnDragOver( x
, y
, result
);
216 bool ret
= wxIsDragResultOk( result
);
219 GdkDragAction action
;
220 if (result
== wxDragCopy
)
221 action
= GDK_ACTION_COPY
;
222 else if (result
== wxDragLink
)
223 action
= GDK_ACTION_LINK
;
225 action
= GDK_ACTION_MOVE
;
227 gdk_drag_status( context
, action
, time
);
230 /* after this, invalidate the drop_target's GdkDragContext */
231 drop_target
->SetDragContext( (GdkDragContext
*) NULL
);
233 /* this has to be done because GDK has no "drag_enter" event */
234 drop_target
->m_firstMotion
= FALSE
;
239 // ----------------------------------------------------------------------------
241 // ----------------------------------------------------------------------------
243 static gboolean
target_drag_drop( GtkWidget
*widget
,
244 GdkDragContext
*context
,
248 wxDropTarget
*drop_target
)
250 if (g_isIdle
) wxapp_install_idle_handler();
252 /* Owen Taylor: "if the drop is not in a drop zone,
253 return FALSE, otherwise, if you aren't accepting
254 the drop, call gtk_drag_finish() with success == FALSE
255 otherwise call gtk_drag_data_get()" */
257 // printf( "drop.\n" );
259 /* this seems to make a difference between not accepting
260 due to wrong target area and due to wrong format. let
261 us hope that this is not required.. */
263 /* inform the wxDropTarget about the current GdkDragContext.
264 this is only valid for the duration of this call */
265 drop_target
->SetDragContext( context
);
267 /* inform the wxDropTarget about the current drag widget.
268 this is only valid for the duration of this call */
269 drop_target
->SetDragWidget( widget
);
271 /* inform the wxDropTarget about the current drag time.
272 this is only valid for the duration of this call */
273 drop_target
->SetDragTime( time
);
276 wxDragResult result = wxDragMove;
277 if (context->suggested_action == GDK_ACTION_COPY) result = wxDragCopy;
280 /* reset the block here as someone might very well
281 show a dialog as a reaction to a drop and this
282 wouldn't work without events */
283 g_blockEventsOnDrag
= FALSE
;
285 bool ret
= drop_target
->OnDrop( x
, y
);
289 wxLogTrace(TRACE_DND
, wxT( "Drop target: OnDrop returned FALSE") );
291 /* cancel the whole thing */
292 gtk_drag_finish( context
,
293 FALSE
, /* no success */
294 FALSE
, /* don't delete data on dropping side */
299 wxLogTrace(TRACE_DND
, wxT( "Drop target: OnDrop returned TRUE") );
302 /* disable GUI threads */
305 GdkAtom format
= drop_target
->GetMatchingPair();
307 // this does happen somehow, see bug 555111
308 wxCHECK_MSG( format
, FALSE
, _T("no matching GdkAtom for format?") )
311 GdkDragAction action = GDK_ACTION_MOVE;
312 if (result == wxDragCopy) action == GDK_ACTION_COPY;
313 context->action = action;
315 /* this should trigger an "drag_data_received" event */
316 gtk_drag_get_data( widget
,
322 /* re-enable GUI threads */
326 /* after this, invalidate the drop_target's GdkDragContext */
327 drop_target
->SetDragContext( (GdkDragContext
*) NULL
);
329 /* after this, invalidate the drop_target's drag widget */
330 drop_target
->SetDragWidget( (GtkWidget
*) NULL
);
332 /* this has to be done because GDK has no "drag_enter" event */
333 drop_target
->m_firstMotion
= TRUE
;
338 // ----------------------------------------------------------------------------
339 // "drag_data_received"
340 // ----------------------------------------------------------------------------
342 static void target_drag_data_received( GtkWidget
*WXUNUSED(widget
),
343 GdkDragContext
*context
,
346 GtkSelectionData
*data
,
347 guint
WXUNUSED(info
),
349 wxDropTarget
*drop_target
)
351 if (g_isIdle
) wxapp_install_idle_handler();
353 /* Owen Taylor: "call gtk_drag_finish() with
356 if ((data
->length
<= 0) || (data
->format
!= 8))
358 /* negative data length and non 8-bit data format
359 qualifies for junk */
360 gtk_drag_finish (context
, FALSE
, FALSE
, time
);
365 wxLogTrace(TRACE_DND
, wxT( "Drop target: data received event") );
367 /* inform the wxDropTarget about the current GtkSelectionData.
368 this is only valid for the duration of this call */
369 drop_target
->SetDragData( data
);
371 wxDragResult result
= ConvertFromGTK(context
->suggested_action
);
373 if ( wxIsDragResultOk( drop_target
->OnData( x
, y
, result
) ) )
375 wxLogTrace(TRACE_DND
, wxT( "Drop target: OnData returned TRUE") );
377 /* tell GTK that data transfer was successfull */
378 gtk_drag_finish( context
, TRUE
, FALSE
, time
);
382 wxLogTrace(TRACE_DND
, wxT( "Drop target: OnData returned FALSE") );
384 /* tell GTK that data transfer was not successfull */
385 gtk_drag_finish( context
, FALSE
, FALSE
, time
);
388 /* after this, invalidate the drop_target's drag data */
389 drop_target
->SetDragData( (GtkSelectionData
*) NULL
);
392 //----------------------------------------------------------------------------
394 //----------------------------------------------------------------------------
396 wxDropTarget::wxDropTarget( wxDataObject
*data
)
397 : wxDropTargetBase( data
)
399 m_firstMotion
= TRUE
;
400 m_dragContext
= (GdkDragContext
*) NULL
;
401 m_dragWidget
= (GtkWidget
*) NULL
;
402 m_dragData
= (GtkSelectionData
*) NULL
;
406 wxDragResult
wxDropTarget::OnDragOver( wxCoord
WXUNUSED(x
),
410 // GetMatchingPair() checks for m_dataObject too, no need to do it here
412 // disable the debug message from GetMatchingPair() - there are too many
418 return (GetMatchingPair() != (GdkAtom
) 0) ? def
: wxDragNone
;
421 bool wxDropTarget::OnDrop( wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
) )
426 return (GetMatchingPair() != (GdkAtom
) 0);
429 wxDragResult
wxDropTarget::OnData( wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
),
435 if (GetMatchingPair() == (GdkAtom
) 0)
438 return GetData() ? def
: wxDragNone
;
441 GdkAtom
wxDropTarget::GetMatchingPair()
449 GList
*child
= m_dragContext
->targets
;
452 GdkAtom formatAtom
= (GdkAtom
) GPOINTER_TO_INT(child
->data
);
453 wxDataFormat
format( formatAtom
);
456 wxLogTrace(TRACE_DND
, wxT("Drop target: drag has format: %s"),
457 format
.GetId().c_str());
460 if (m_dataObject
->IsSupportedFormat( format
))
469 bool wxDropTarget::GetData()
477 wxDataFormat
dragFormat( m_dragData
->target
);
479 if (!m_dataObject
->IsSupportedFormat( dragFormat
))
482 m_dataObject
->SetData( dragFormat
, (size_t)m_dragData
->length
, (const void*)m_dragData
->data
);
487 void wxDropTarget::UnregisterWidget( GtkWidget
*widget
)
489 wxCHECK_RET( widget
!= NULL
, wxT("unregister widget is NULL") );
491 gtk_drag_dest_unset( widget
);
493 gtk_signal_disconnect_by_func( GTK_OBJECT(widget
),
494 GTK_SIGNAL_FUNC(target_drag_leave
), (gpointer
) this );
496 gtk_signal_disconnect_by_func( GTK_OBJECT(widget
),
497 GTK_SIGNAL_FUNC(target_drag_motion
), (gpointer
) this );
499 gtk_signal_disconnect_by_func( GTK_OBJECT(widget
),
500 GTK_SIGNAL_FUNC(target_drag_drop
), (gpointer
) this );
502 gtk_signal_disconnect_by_func( GTK_OBJECT(widget
),
503 GTK_SIGNAL_FUNC(target_drag_data_received
), (gpointer
) this );
506 void wxDropTarget::RegisterWidget( GtkWidget
*widget
)
508 wxCHECK_RET( widget
!= NULL
, wxT("register widget is NULL") );
510 /* gtk_drag_dest_set() determines what default behaviour we'd like
511 GTK to supply. we don't want to specify out targets (=formats)
512 or actions in advance (i.e. not GTK_DEST_DEFAULT_MOTION and
513 not GTK_DEST_DEFAULT_DROP). instead we react individually to
514 "drag_motion" and "drag_drop" events. this makes it possible
515 to allow dropping on only a small area. we should set
516 GTK_DEST_DEFAULT_HIGHLIGHT as this will switch on the nice
517 highlighting if dragging over standard controls, but this
518 seems to be broken without the other two. */
520 gtk_drag_dest_set( widget
,
521 (GtkDestDefaults
) 0, /* no default behaviour */
522 (GtkTargetEntry
*) NULL
, /* we don't supply any formats here */
523 0, /* number of targets = 0 */
524 (GdkDragAction
) 0 ); /* we don't supply any actions here */
526 gtk_signal_connect( GTK_OBJECT(widget
), "drag_leave",
527 GTK_SIGNAL_FUNC(target_drag_leave
), (gpointer
) this );
529 gtk_signal_connect( GTK_OBJECT(widget
), "drag_motion",
530 GTK_SIGNAL_FUNC(target_drag_motion
), (gpointer
) this );
532 gtk_signal_connect( GTK_OBJECT(widget
), "drag_drop",
533 GTK_SIGNAL_FUNC(target_drag_drop
), (gpointer
) this );
535 gtk_signal_connect( GTK_OBJECT(widget
), "drag_data_received",
536 GTK_SIGNAL_FUNC(target_drag_data_received
), (gpointer
) this );
539 //----------------------------------------------------------------------------
541 //----------------------------------------------------------------------------
544 source_drag_data_get (GtkWidget
*WXUNUSED(widget
),
545 GdkDragContext
*WXUNUSED(context
),
546 GtkSelectionData
*selection_data
,
547 guint
WXUNUSED(info
),
548 guint
WXUNUSED(time
),
549 wxDropSource
*drop_source
)
551 if (g_isIdle
) wxapp_install_idle_handler();
553 wxDataFormat
format( selection_data
->target
);
555 wxLogTrace(TRACE_DND
, wxT("Drop source: format requested: %s"),
556 format
.GetId().c_str());
558 drop_source
->m_retValue
= wxDragCancel
;
560 wxDataObject
*data
= drop_source
->GetDataObject();
564 wxLogTrace(TRACE_DND
, wxT("Drop source: no data object") );
568 if (!data
->IsSupportedFormat(format
))
570 wxLogTrace(TRACE_DND
, wxT("Drop source: unsupported format") );
574 if (data
->GetDataSize(format
) == 0)
576 wxLogTrace(TRACE_DND
, wxT("Drop source: empty data") );
580 size_t size
= data
->GetDataSize(format
);
582 // printf( "data size: %d.\n", (int)data_size );
584 guchar
*d
= new guchar
[size
];
586 if (!data
->GetDataHere( format
, (void*)d
))
593 /* disable GUI threads */
596 gtk_selection_data_set( selection_data
,
597 selection_data
->target
,
603 /* enable GUI threads */
609 //----------------------------------------------------------------------------
610 // "drag_data_delete"
611 //----------------------------------------------------------------------------
613 static void source_drag_data_delete( GtkWidget
*WXUNUSED(widget
),
614 GdkDragContext
*context
,
615 wxDropSource
*WXUNUSED(drop_source
) )
618 wxapp_install_idle_handler();
620 // printf( "Drag source: drag_data_delete\n" );
623 //----------------------------------------------------------------------------
625 //----------------------------------------------------------------------------
627 static void source_drag_begin( GtkWidget
*WXUNUSED(widget
),
628 GdkDragContext
*WXUNUSED(context
),
629 wxDropSource
*WXUNUSED(drop_source
) )
632 wxapp_install_idle_handler();
634 // printf( "Drag source: drag_begin.\n" );
637 //----------------------------------------------------------------------------
639 //----------------------------------------------------------------------------
641 static void source_drag_end( GtkWidget
*WXUNUSED(widget
),
642 GdkDragContext
*WXUNUSED(context
),
643 wxDropSource
*drop_source
)
645 if (g_isIdle
) wxapp_install_idle_handler();
647 // printf( "Drag source: drag_end.\n" );
649 drop_source
->m_waiting
= FALSE
;
652 //-----------------------------------------------------------------------------
653 // "configure_event" from m_iconWindow
654 //-----------------------------------------------------------------------------
657 gtk_dnd_window_configure_callback( GtkWidget
*WXUNUSED(widget
), GdkEventConfigure
*WXUNUSED(event
), wxDropSource
*source
)
660 wxapp_install_idle_handler();
662 source
->GiveFeedback( ConvertFromGTK(source
->m_dragContext
->action
) );
667 //---------------------------------------------------------------------------
669 //---------------------------------------------------------------------------
671 wxDropSource::wxDropSource(wxWindow
*win
,
672 const wxIcon
&iconCopy
,
673 const wxIcon
&iconMove
,
674 const wxIcon
&iconNone
)
678 m_iconWindow
= (GtkWidget
*) NULL
;
681 m_widget
= win
->m_widget
;
682 if (win
->m_wxwindow
) m_widget
= win
->m_wxwindow
;
684 m_retValue
= wxDragCancel
;
686 SetIcons(iconCopy
, iconMove
, iconNone
);
689 wxDropSource::wxDropSource(wxDataObject
& data
,
691 const wxIcon
&iconCopy
,
692 const wxIcon
&iconMove
,
693 const wxIcon
&iconNone
)
699 m_iconWindow
= (GtkWidget
*) NULL
;
702 m_widget
= win
->m_widget
;
703 if (win
->m_wxwindow
) m_widget
= win
->m_wxwindow
;
705 m_retValue
= wxDragCancel
;
707 SetIcons(iconCopy
, iconMove
, iconNone
);
710 void wxDropSource::SetIcons(const wxIcon
&iconCopy
,
711 const wxIcon
&iconMove
,
712 const wxIcon
&iconNone
)
714 m_iconCopy
= iconCopy
;
715 m_iconMove
= iconMove
;
716 m_iconNone
= iconNone
;
718 if ( !m_iconCopy
.Ok() )
719 m_iconCopy
= wxIcon(page_xpm
);
720 if ( !m_iconMove
.Ok() )
721 m_iconMove
= m_iconCopy
;
722 if ( !m_iconNone
.Ok() )
723 m_iconNone
= m_iconCopy
;
726 wxDropSource::~wxDropSource()
730 void wxDropSource::PrepareIcon( int action
, GdkDragContext
*context
)
732 // get the right icon to display
734 if ( action
& GDK_ACTION_MOVE
)
736 else if ( action
& GDK_ACTION_COPY
)
742 if ( icon
->GetMask() )
743 mask
= icon
->GetMask()->GetBitmap();
745 mask
= (GdkBitmap
*)NULL
;
747 GdkPixmap
*pixmap
= icon
->GetPixmap();
750 gdk_window_get_size (pixmap
, &width
, &height
);
752 GdkColormap
*colormap
= gtk_widget_get_colormap( m_widget
);
754 gtk_widget_push_visual (gdk_colormap_get_visual (colormap
));
756 gtk_widget_push_colormap (colormap
);
758 m_iconWindow
= gtk_window_new (GTK_WINDOW_POPUP
);
759 gtk_widget_set_events (m_iconWindow
, GDK_BUTTON_PRESS_MASK
| GDK_BUTTON_RELEASE_MASK
);
760 gtk_widget_set_app_paintable (GTK_WIDGET (m_iconWindow
), TRUE
);
763 gtk_widget_pop_visual ();
765 gtk_widget_pop_colormap ();
767 gtk_widget_set_usize (m_iconWindow
, width
, height
);
768 gtk_widget_realize (m_iconWindow
);
770 gtk_signal_connect( GTK_OBJECT(m_iconWindow
), "configure_event",
771 GTK_SIGNAL_FUNC(gtk_dnd_window_configure_callback
), (gpointer
)this );
773 gdk_window_set_back_pixmap (m_iconWindow
->window
, pixmap
, FALSE
);
776 gtk_widget_shape_combine_mask (m_iconWindow
, mask
, 0, 0);
778 gtk_drag_set_icon_widget( context
, m_iconWindow
, 0, 0 );
781 wxDragResult
wxDropSource::DoDragDrop(int flags
)
783 wxCHECK_MSG( m_data
&& m_data
->GetFormatCount(), wxDragNone
,
784 wxT("Drop source: no data") );
787 if (g_blockEventsOnDrag
)
791 g_blockEventsOnDrag
= TRUE
;
797 GtkTargetList
*target_list
= gtk_target_list_new( (GtkTargetEntry
*) NULL
, 0 );
799 wxDataFormat
*array
= new wxDataFormat
[ m_data
->GetFormatCount() ];
800 m_data
->GetAllFormats( array
);
801 size_t count
= m_data
->GetFormatCount();
802 for (size_t i
= 0; i
< count
; i
++)
804 GdkAtom atom
= array
[i
];
805 wxLogTrace(TRACE_DND
, wxT("Drop source: Supported atom %s"), gdk_atom_name( atom
));
806 gtk_target_list_add( target_list
, atom
, 0, 0 );
810 GdkEventMotion event
;
811 event
.window
= m_widget
->window
;
814 GdkModifierType state
;
815 gdk_window_get_pointer( event
.window
, &x
, &y
, &state
);
819 event
.time
= (guint32
)GDK_CURRENT_TIME
;
821 /* GTK wants to know which button was pressed which caused the dragging */
822 int button_number
= 0;
823 if (event
.state
& GDK_BUTTON1_MASK
) button_number
= 1;
824 else if (event
.state
& GDK_BUTTON2_MASK
) button_number
= 2;
825 else if (event
.state
& GDK_BUTTON3_MASK
) button_number
= 3;
828 /* disable GUI threads */
831 /* don't start dragging if no button is down */
834 int action
= GDK_ACTION_COPY
;
835 if ( flags
& wxDrag_AllowMove
)
836 action
|= GDK_ACTION_MOVE
;
838 // VZ: as we already use g_blockEventsOnDrag it shouldn't be that bad
839 // to use a global to pass the flags to the drop target but I'd
840 // surely prefer a better way to do it
841 gs_flagsForDrag
= flags
;
843 GdkDragContext
*context
= gtk_drag_begin( m_widget
,
845 (GdkDragAction
)action
,
846 button_number
, /* number of mouse button which started drag */
847 (GdkEvent
*) &event
);
849 m_dragContext
= context
;
851 PrepareIcon( action
, context
);
854 gtk_main_iteration();
856 m_retValue
= ConvertFromGTK(context
->action
);
857 if ( m_retValue
== wxDragNone
)
858 m_retValue
= wxDragCancel
;
862 /* re-enable GUI threads */
865 g_blockEventsOnDrag
= FALSE
;
872 void wxDropSource::RegisterWindow()
874 if (!m_widget
) return;
876 gtk_signal_connect( GTK_OBJECT(m_widget
), "drag_data_get",
877 GTK_SIGNAL_FUNC (source_drag_data_get
), (gpointer
) this);
878 gtk_signal_connect (GTK_OBJECT(m_widget
), "drag_data_delete",
879 GTK_SIGNAL_FUNC (source_drag_data_delete
), (gpointer
) this );
880 gtk_signal_connect (GTK_OBJECT(m_widget
), "drag_begin",
881 GTK_SIGNAL_FUNC (source_drag_begin
), (gpointer
) this );
882 gtk_signal_connect (GTK_OBJECT(m_widget
), "drag_end",
883 GTK_SIGNAL_FUNC (source_drag_end
), (gpointer
) this );
887 void wxDropSource::UnregisterWindow()
889 if (!m_widget
) return;
891 gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget
),
892 GTK_SIGNAL_FUNC(source_drag_data_get
), (gpointer
) this );
893 gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget
),
894 GTK_SIGNAL_FUNC(source_drag_data_delete
), (gpointer
) this );
895 gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget
),
896 GTK_SIGNAL_FUNC(source_drag_begin
), (gpointer
) this );
897 gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget
),
898 GTK_SIGNAL_FUNC(source_drag_end
), (gpointer
) this );
902 // wxUSE_DRAG_AND_DROP