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();
305 // this does happen somehow, see bug 555111
306 wxCHECK_MSG( format
, FALSE
, _T("no matching GdkAtom for format?") )
309 GdkDragAction action = GDK_ACTION_MOVE;
310 if (result == wxDragCopy) action == GDK_ACTION_COPY;
311 context->action = action;
313 /* this should trigger an "drag_data_received" event */
314 gtk_drag_get_data( widget
,
320 /* re-enable GUI threads */
324 /* after this, invalidate the drop_target's GdkDragContext */
325 drop_target
->SetDragContext( (GdkDragContext
*) NULL
);
327 /* after this, invalidate the drop_target's drag widget */
328 drop_target
->SetDragWidget( (GtkWidget
*) NULL
);
330 /* this has to be done because GDK has no "drag_enter" event */
331 drop_target
->m_firstMotion
= TRUE
;
336 // ----------------------------------------------------------------------------
337 // "drag_data_received"
338 // ----------------------------------------------------------------------------
340 static void target_drag_data_received( GtkWidget
*WXUNUSED(widget
),
341 GdkDragContext
*context
,
344 GtkSelectionData
*data
,
345 guint
WXUNUSED(info
),
347 wxDropTarget
*drop_target
)
349 if (g_isIdle
) wxapp_install_idle_handler();
351 /* Owen Taylor: "call gtk_drag_finish() with
354 if ((data
->length
<= 0) || (data
->format
!= 8))
356 /* negative data length and non 8-bit data format
357 qualifies for junk */
358 gtk_drag_finish (context
, FALSE
, FALSE
, time
);
363 wxLogTrace(TRACE_DND
, wxT( "Drop target: data received event") );
365 /* inform the wxDropTarget about the current GtkSelectionData.
366 this is only valid for the duration of this call */
367 drop_target
->SetDragData( data
);
369 wxDragResult result
= ConvertFromGTK(context
->suggested_action
);
371 if ( wxIsDragResultOk( drop_target
->OnData( x
, y
, result
) ) )
373 wxLogTrace(TRACE_DND
, wxT( "Drop target: OnData returned TRUE") );
375 /* tell GTK that data transfer was successfull */
376 gtk_drag_finish( context
, TRUE
, FALSE
, time
);
380 wxLogTrace(TRACE_DND
, wxT( "Drop target: OnData returned FALSE") );
382 /* tell GTK that data transfer was not successfull */
383 gtk_drag_finish( context
, FALSE
, FALSE
, time
);
386 /* after this, invalidate the drop_target's drag data */
387 drop_target
->SetDragData( (GtkSelectionData
*) NULL
);
390 //----------------------------------------------------------------------------
392 //----------------------------------------------------------------------------
394 wxDropTarget::wxDropTarget( wxDataObject
*data
)
395 : wxDropTargetBase( data
)
397 m_firstMotion
= TRUE
;
398 m_dragContext
= (GdkDragContext
*) NULL
;
399 m_dragWidget
= (GtkWidget
*) NULL
;
400 m_dragData
= (GtkSelectionData
*) NULL
;
404 wxDragResult
wxDropTarget::OnDragOver( wxCoord
WXUNUSED(x
),
408 // GetMatchingPair() checks for m_dataObject too, no need to do it here
410 // disable the debug message from GetMatchingPair() - there are too many
416 return (GetMatchingPair() != (GdkAtom
) 0) ? def
: wxDragNone
;
419 bool wxDropTarget::OnDrop( wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
) )
424 return (GetMatchingPair() != (GdkAtom
) 0);
427 wxDragResult
wxDropTarget::OnData( wxCoord
WXUNUSED(x
), wxCoord
WXUNUSED(y
),
433 if (GetMatchingPair() == (GdkAtom
) 0)
436 return GetData() ? def
: wxDragNone
;
439 GdkAtom
wxDropTarget::GetMatchingPair()
447 GList
*child
= m_dragContext
->targets
;
450 GdkAtom formatAtom
= (GdkAtom
) GPOINTER_TO_INT(child
->data
);
451 wxDataFormat
format( formatAtom
);
454 wxLogTrace(TRACE_DND
, wxT("Drop target: drag has format: %s"),
455 format
.GetId().c_str());
458 if (m_dataObject
->IsSupportedFormat( format
))
467 bool wxDropTarget::GetData()
475 wxDataFormat
dragFormat( m_dragData
->target
);
477 if (!m_dataObject
->IsSupportedFormat( dragFormat
))
480 m_dataObject
->SetData( dragFormat
, (size_t)m_dragData
->length
, (const void*)m_dragData
->data
);
485 void wxDropTarget::UnregisterWidget( GtkWidget
*widget
)
487 wxCHECK_RET( widget
!= NULL
, wxT("unregister widget is NULL") );
489 gtk_drag_dest_unset( widget
);
491 gtk_signal_disconnect_by_func( GTK_OBJECT(widget
),
492 GTK_SIGNAL_FUNC(target_drag_leave
), (gpointer
) this );
494 gtk_signal_disconnect_by_func( GTK_OBJECT(widget
),
495 GTK_SIGNAL_FUNC(target_drag_motion
), (gpointer
) this );
497 gtk_signal_disconnect_by_func( GTK_OBJECT(widget
),
498 GTK_SIGNAL_FUNC(target_drag_drop
), (gpointer
) this );
500 gtk_signal_disconnect_by_func( GTK_OBJECT(widget
),
501 GTK_SIGNAL_FUNC(target_drag_data_received
), (gpointer
) this );
504 void wxDropTarget::RegisterWidget( GtkWidget
*widget
)
506 wxCHECK_RET( widget
!= NULL
, wxT("register widget is NULL") );
508 /* gtk_drag_dest_set() determines what default behaviour we'd like
509 GTK to supply. we don't want to specify out targets (=formats)
510 or actions in advance (i.e. not GTK_DEST_DEFAULT_MOTION and
511 not GTK_DEST_DEFAULT_DROP). instead we react individually to
512 "drag_motion" and "drag_drop" events. this makes it possible
513 to allow dropping on only a small area. we should set
514 GTK_DEST_DEFAULT_HIGHLIGHT as this will switch on the nice
515 highlighting if dragging over standard controls, but this
516 seems to be broken without the other two. */
518 gtk_drag_dest_set( widget
,
519 (GtkDestDefaults
) 0, /* no default behaviour */
520 (GtkTargetEntry
*) NULL
, /* we don't supply any formats here */
521 0, /* number of targets = 0 */
522 (GdkDragAction
) 0 ); /* we don't supply any actions here */
524 gtk_signal_connect( GTK_OBJECT(widget
), "drag_leave",
525 GTK_SIGNAL_FUNC(target_drag_leave
), (gpointer
) this );
527 gtk_signal_connect( GTK_OBJECT(widget
), "drag_motion",
528 GTK_SIGNAL_FUNC(target_drag_motion
), (gpointer
) this );
530 gtk_signal_connect( GTK_OBJECT(widget
), "drag_drop",
531 GTK_SIGNAL_FUNC(target_drag_drop
), (gpointer
) this );
533 gtk_signal_connect( GTK_OBJECT(widget
), "drag_data_received",
534 GTK_SIGNAL_FUNC(target_drag_data_received
), (gpointer
) this );
537 //----------------------------------------------------------------------------
539 //----------------------------------------------------------------------------
542 source_drag_data_get (GtkWidget
*WXUNUSED(widget
),
543 GdkDragContext
*WXUNUSED(context
),
544 GtkSelectionData
*selection_data
,
545 guint
WXUNUSED(info
),
546 guint
WXUNUSED(time
),
547 wxDropSource
*drop_source
)
549 if (g_isIdle
) wxapp_install_idle_handler();
551 wxDataFormat
format( selection_data
->target
);
553 wxLogTrace(TRACE_DND
, wxT("Drop source: format requested: %s"),
554 format
.GetId().c_str());
556 drop_source
->m_retValue
= wxDragCancel
;
558 wxDataObject
*data
= drop_source
->GetDataObject();
562 wxLogTrace(TRACE_DND
, wxT("Drop source: no data object") );
566 if (!data
->IsSupportedFormat(format
))
568 wxLogTrace(TRACE_DND
, wxT("Drop source: unsupported format") );
572 if (data
->GetDataSize(format
) == 0)
574 wxLogTrace(TRACE_DND
, wxT("Drop source: empty data") );
578 size_t size
= data
->GetDataSize(format
);
580 // printf( "data size: %d.\n", (int)data_size );
582 guchar
*d
= new guchar
[size
];
584 if (!data
->GetDataHere( format
, (void*)d
))
591 /* disable GUI threads */
594 gtk_selection_data_set( selection_data
,
595 selection_data
->target
,
601 /* enable GUI threads */
607 //----------------------------------------------------------------------------
608 // "drag_data_delete"
609 //----------------------------------------------------------------------------
611 static void source_drag_data_delete( GtkWidget
*WXUNUSED(widget
),
612 GdkDragContext
*context
,
613 wxDropSource
*WXUNUSED(drop_source
) )
616 wxapp_install_idle_handler();
618 // printf( "Drag source: drag_data_delete\n" );
621 //----------------------------------------------------------------------------
623 //----------------------------------------------------------------------------
625 static void source_drag_begin( GtkWidget
*WXUNUSED(widget
),
626 GdkDragContext
*WXUNUSED(context
),
627 wxDropSource
*WXUNUSED(drop_source
) )
630 wxapp_install_idle_handler();
632 // printf( "Drag source: drag_begin.\n" );
635 //----------------------------------------------------------------------------
637 //----------------------------------------------------------------------------
639 static void source_drag_end( GtkWidget
*WXUNUSED(widget
),
640 GdkDragContext
*WXUNUSED(context
),
641 wxDropSource
*drop_source
)
643 if (g_isIdle
) wxapp_install_idle_handler();
645 // printf( "Drag source: drag_end.\n" );
647 drop_source
->m_waiting
= FALSE
;
650 //-----------------------------------------------------------------------------
651 // "configure_event" from m_iconWindow
652 //-----------------------------------------------------------------------------
655 gtk_dnd_window_configure_callback( GtkWidget
*WXUNUSED(widget
), GdkEventConfigure
*WXUNUSED(event
), wxDropSource
*source
)
658 wxapp_install_idle_handler();
660 source
->GiveFeedback( ConvertFromGTK(source
->m_dragContext
->action
) );
665 //---------------------------------------------------------------------------
667 //---------------------------------------------------------------------------
669 wxDropSource::wxDropSource(wxWindow
*win
,
670 const wxIcon
&iconCopy
,
671 const wxIcon
&iconMove
,
672 const wxIcon
&iconNone
)
676 m_iconWindow
= (GtkWidget
*) NULL
;
679 m_widget
= win
->m_widget
;
680 if (win
->m_wxwindow
) m_widget
= win
->m_wxwindow
;
682 m_retValue
= wxDragCancel
;
684 SetIcons(iconCopy
, iconMove
, iconNone
);
687 wxDropSource::wxDropSource(wxDataObject
& data
,
689 const wxIcon
&iconCopy
,
690 const wxIcon
&iconMove
,
691 const wxIcon
&iconNone
)
697 m_iconWindow
= (GtkWidget
*) NULL
;
700 m_widget
= win
->m_widget
;
701 if (win
->m_wxwindow
) m_widget
= win
->m_wxwindow
;
703 m_retValue
= wxDragCancel
;
705 SetIcons(iconCopy
, iconMove
, iconNone
);
708 void wxDropSource::SetIcons(const wxIcon
&iconCopy
,
709 const wxIcon
&iconMove
,
710 const wxIcon
&iconNone
)
712 m_iconCopy
= iconCopy
;
713 m_iconMove
= iconMove
;
714 m_iconNone
= iconNone
;
716 if ( !m_iconCopy
.Ok() )
717 m_iconCopy
= wxIcon(page_xpm
);
718 if ( !m_iconMove
.Ok() )
719 m_iconMove
= m_iconCopy
;
720 if ( !m_iconNone
.Ok() )
721 m_iconNone
= m_iconCopy
;
724 wxDropSource::~wxDropSource()
728 void wxDropSource::PrepareIcon( int action
, GdkDragContext
*context
)
730 // get the right icon to display
732 if ( action
& GDK_ACTION_MOVE
)
734 else if ( action
& GDK_ACTION_COPY
)
740 if ( icon
->GetMask() )
741 mask
= icon
->GetMask()->GetBitmap();
743 mask
= (GdkBitmap
*)NULL
;
745 GdkPixmap
*pixmap
= icon
->GetPixmap();
748 gdk_window_get_size (pixmap
, &width
, &height
);
750 GdkColormap
*colormap
= gtk_widget_get_colormap( m_widget
);
752 gtk_widget_push_visual (gdk_colormap_get_visual (colormap
));
754 gtk_widget_push_colormap (colormap
);
756 m_iconWindow
= gtk_window_new (GTK_WINDOW_POPUP
);
757 gtk_widget_set_events (m_iconWindow
, GDK_BUTTON_PRESS_MASK
| GDK_BUTTON_RELEASE_MASK
);
758 gtk_widget_set_app_paintable (GTK_WIDGET (m_iconWindow
), TRUE
);
761 gtk_widget_pop_visual ();
763 gtk_widget_pop_colormap ();
765 gtk_widget_set_usize (m_iconWindow
, width
, height
);
766 gtk_widget_realize (m_iconWindow
);
768 gtk_signal_connect( GTK_OBJECT(m_iconWindow
), "configure_event",
769 GTK_SIGNAL_FUNC(gtk_dnd_window_configure_callback
), (gpointer
)this );
771 gdk_window_set_back_pixmap (m_iconWindow
->window
, pixmap
, FALSE
);
774 gtk_widget_shape_combine_mask (m_iconWindow
, mask
, 0, 0);
776 gtk_drag_set_icon_widget( context
, m_iconWindow
, 0, 0 );
779 wxDragResult
wxDropSource::DoDragDrop(int flags
)
781 wxCHECK_MSG( m_data
&& m_data
->GetFormatCount(), wxDragNone
,
782 wxT("Drop source: no data") );
785 if (g_blockEventsOnDrag
)
789 g_blockEventsOnDrag
= TRUE
;
795 GtkTargetList
*target_list
= gtk_target_list_new( (GtkTargetEntry
*) NULL
, 0 );
797 wxDataFormat
*array
= new wxDataFormat
[ m_data
->GetFormatCount() ];
798 m_data
->GetAllFormats( array
);
799 size_t count
= m_data
->GetFormatCount();
800 for (size_t i
= 0; i
< count
; i
++)
802 GdkAtom atom
= array
[i
];
803 wxLogTrace(TRACE_DND
, wxT("Drop source: Supported atom %s"), gdk_atom_name( atom
));
804 gtk_target_list_add( target_list
, atom
, 0, 0 );
808 GdkEventMotion event
;
809 event
.window
= m_widget
->window
;
812 GdkModifierType state
;
813 gdk_window_get_pointer( event
.window
, &x
, &y
, &state
);
817 event
.time
= (guint32
)GDK_CURRENT_TIME
;
819 /* GTK wants to know which button was pressed which caused the dragging */
820 int button_number
= 0;
821 if (event
.state
& GDK_BUTTON1_MASK
) button_number
= 1;
822 else if (event
.state
& GDK_BUTTON2_MASK
) button_number
= 2;
823 else if (event
.state
& GDK_BUTTON3_MASK
) button_number
= 3;
826 /* disable GUI threads */
829 /* don't start dragging if no button is down */
832 int action
= GDK_ACTION_COPY
;
833 if ( flags
& wxDrag_AllowMove
)
834 action
|= GDK_ACTION_MOVE
;
836 // VZ: as we already use g_blockEventsOnDrag it shouldn't be that bad
837 // to use a global to pass the flags to the drop target but I'd
838 // surely prefer a better way to do it
839 gs_flagsForDrag
= flags
;
841 GdkDragContext
*context
= gtk_drag_begin( m_widget
,
843 (GdkDragAction
)action
,
844 button_number
, /* number of mouse button which started drag */
845 (GdkEvent
*) &event
);
847 m_dragContext
= context
;
849 PrepareIcon( action
, context
);
852 gtk_main_iteration();
854 m_retValue
= ConvertFromGTK(context
->action
);
855 if ( m_retValue
== wxDragNone
)
856 m_retValue
= wxDragCancel
;
860 /* re-enable GUI threads */
863 g_blockEventsOnDrag
= FALSE
;
870 void wxDropSource::RegisterWindow()
872 if (!m_widget
) return;
874 gtk_signal_connect( GTK_OBJECT(m_widget
), "drag_data_get",
875 GTK_SIGNAL_FUNC (source_drag_data_get
), (gpointer
) this);
876 gtk_signal_connect (GTK_OBJECT(m_widget
), "drag_data_delete",
877 GTK_SIGNAL_FUNC (source_drag_data_delete
), (gpointer
) this );
878 gtk_signal_connect (GTK_OBJECT(m_widget
), "drag_begin",
879 GTK_SIGNAL_FUNC (source_drag_begin
), (gpointer
) this );
880 gtk_signal_connect (GTK_OBJECT(m_widget
), "drag_end",
881 GTK_SIGNAL_FUNC (source_drag_end
), (gpointer
) this );
885 void wxDropSource::UnregisterWindow()
887 if (!m_widget
) return;
889 gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget
),
890 GTK_SIGNAL_FUNC(source_drag_data_get
), (gpointer
) this );
891 gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget
),
892 GTK_SIGNAL_FUNC(source_drag_data_delete
), (gpointer
) this );
893 gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget
),
894 GTK_SIGNAL_FUNC(source_drag_begin
), (gpointer
) this );
895 gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget
),
896 GTK_SIGNAL_FUNC(source_drag_end
), (gpointer
) this );
900 // wxUSE_DRAG_AND_DROP