+ wxCHECK_RET( widget != NULL, wxT("register widget is NULL") );
+
+ /* gtk_drag_dest_set() determines what default behaviour we'd like
+ GTK to supply. we don't want to specify out targets (=formats)
+ or actions in advance (i.e. not GTK_DEST_DEFAULT_MOTION and
+ not GTK_DEST_DEFAULT_DROP). instead we react individually to
+ "drag_motion" and "drag_drop" events. this makes it possible
+ to allow dropping on only a small area. we should set
+ GTK_DEST_DEFAULT_HIGHLIGHT as this will switch on the nice
+ highlighting if dragging over standard controls, but this
+ seems to be broken without the other two. */
+
+ gtk_drag_dest_set( widget,
+ (GtkDestDefaults) 0, /* no default behaviour */
+ NULL, /* we don't supply any formats here */
+ 0, /* number of targets = 0 */
+ (GdkDragAction) 0 ); /* we don't supply any actions here */
+
+ gtk_signal_connect( GTK_OBJECT(widget), "drag_leave",
+ GTK_SIGNAL_FUNC(target_drag_leave), (gpointer) this );
+
+ gtk_signal_connect( GTK_OBJECT(widget), "drag_motion",
+ GTK_SIGNAL_FUNC(target_drag_motion), (gpointer) this );
+
+ gtk_signal_connect( GTK_OBJECT(widget), "drag_drop",
+ GTK_SIGNAL_FUNC(target_drag_drop), (gpointer) this );
+
+ gtk_signal_connect( GTK_OBJECT(widget), "drag_data_received",
+ GTK_SIGNAL_FUNC(target_drag_data_received), (gpointer) this );
+}
+
+//----------------------------------------------------------------------------
+// "drag_data_get"
+//----------------------------------------------------------------------------
+
+extern "C" {
+static void
+source_drag_data_get (GtkWidget *WXUNUSED(widget),
+ GdkDragContext *WXUNUSED(context),
+ GtkSelectionData *selection_data,
+ guint WXUNUSED(info),
+ guint WXUNUSED(time),
+ wxDropSource *drop_source )
+{
+ if (g_isIdle) wxapp_install_idle_handler();
+
+ wxDataFormat format( selection_data->target );
+
+ wxLogTrace(TRACE_DND, wxT("Drop source: format requested: %s"),
+ format.GetId().c_str());
+
+ drop_source->m_retValue = wxDragCancel;
+
+ wxDataObject *data = drop_source->GetDataObject();
+
+ if (!data)
+ {
+ wxLogTrace(TRACE_DND, wxT("Drop source: no data object") );
+ return;
+ }
+
+ if (!data->IsSupportedFormat(format))
+ {
+ wxLogTrace(TRACE_DND, wxT("Drop source: unsupported format") );
+ return;
+ }
+
+ if (data->GetDataSize(format) == 0)
+ {
+ wxLogTrace(TRACE_DND, wxT("Drop source: empty data") );
+ return;
+ }
+
+ size_t size = data->GetDataSize(format);
+
+// printf( "data size: %d.\n", (int)data_size );
+
+ guchar *d = new guchar[size];
+
+ if (!data->GetDataHere( format, (void*)d ))
+ {
+ delete[] d;
+ return;
+ }
+
+#if wxUSE_THREADS
+ /* disable GUI threads */
+#endif
+
+ gtk_selection_data_set( selection_data,
+ selection_data->target,
+ 8, // 8-bit
+ d,
+ size );
+
+#if wxUSE_THREADS
+ /* enable GUI threads */
+#endif
+
+ delete[] d;