+ if (g_isIdle) wxapp_install_idle_handler();
+
+// printf( "drag_begin.\n" );
+}
+
+//----------------------------------------------------------------------------
+// "drag_end"
+//----------------------------------------------------------------------------
+
+static void source_drag_end( GtkWidget *WXUNUSED(widget),
+ GdkDragContext *WXUNUSED(context),
+ wxDropSource *drop_source )
+{
+ if (g_isIdle) wxapp_install_idle_handler();
+
+// printf( "drag_end.\n" );
+
+ drop_source->m_waiting = FALSE;
+}
+
+//---------------------------------------------------------------------------
+// wxDropSource
+//---------------------------------------------------------------------------
+
+wxDropSource::wxDropSource( wxWindow *win, const wxIcon &go, const wxIcon &stop )
+{
+ g_blockEventsOnDrag = TRUE;
+ m_waiting = TRUE;
+
+ m_window = win;
+ m_widget = win->m_widget;
+ if (win->m_wxwindow) m_widget = win->m_wxwindow;
+
+ m_data = (wxDataBroker*) NULL;
+ m_retValue = wxDragCancel;
+
+ m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY );
+ m_goaheadCursor = wxCursor( wxCURSOR_HAND );
+
+ m_goIcon = go;
+ if (wxNullIcon == go) m_goIcon = wxIcon( page_xpm );
+ m_stopIcon = stop;
+ if (wxNullIcon == stop) m_stopIcon = wxIcon( gv_xpm );
+}
+
+wxDropSource::wxDropSource( wxDataObject *data, wxWindow *win, const wxIcon &go, const wxIcon &stop )
+{
+ m_waiting = TRUE;
+
+ m_window = win;
+ m_widget = win->m_widget;
+ if (win->m_wxwindow) m_widget = win->m_wxwindow;
+ m_retValue = wxDragCancel;
+
+ if (data)
+ {
+ m_data = new wxDataBroker();
+ m_data->Add( data );
+ }
+ else
+ {
+ m_data = (wxDataBroker*) NULL;
+ }
+
+ m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY );
+ m_goaheadCursor = wxCursor( wxCURSOR_HAND );
+
+ m_goIcon = go;
+ if (wxNullIcon == go) m_goIcon = wxIcon( page_xpm );
+ m_stopIcon = stop;
+ if (wxNullIcon == stop) m_stopIcon = wxIcon( gv_xpm );
+}
+
+wxDropSource::wxDropSource( wxDataBroker *data, wxWindow *win )
+{
+ m_window = win;
+ m_widget = win->m_widget;
+ if (win->m_wxwindow) m_widget = win->m_wxwindow;
+ m_retValue = wxDragCancel;
+
+ m_data = data;
+
+ m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY );
+ m_goaheadCursor = wxCursor( wxCURSOR_HAND );
+}
+
+void wxDropSource::SetData( wxDataObject *data )
+{
+ if (m_data) delete m_data;
+
+ if (data)
+ {
+ m_data = new wxDataBroker();
+ m_data->Add( data );
+ }
+ else
+ {
+ m_data = (wxDataBroker*) NULL;
+ }
+}
+
+void wxDropSource::SetData( wxDataBroker *data )
+{
+ if (m_data) delete m_data;
+
+ m_data = data;
+}
+
+wxDropSource::~wxDropSource(void)
+{
+ if (m_data) delete m_data;
+
+ g_blockEventsOnDrag = FALSE;
+}
+
+wxDragResult wxDropSource::DoDragDrop( bool WXUNUSED(bAllowMove) )
+{
+ wxASSERT_MSG( m_data, _T("wxDragSource: no data") );
+
+ if (!m_data) return (wxDragResult) wxDragNone;
+
+ g_blockEventsOnDrag = TRUE;
+
+ RegisterWindow();
+
+ m_waiting = TRUE;
+
+ GdkAtom atom = gdk_atom_intern( "STRING", FALSE );
+// printf( "atom id: %d.\n", (int)atom );
+
+ GtkTargetList *target_list = gtk_target_list_new( (GtkTargetEntry*) NULL, 0 );
+ gtk_target_list_add( target_list, atom, 0, 0 );
+
+ GdkEventMotion event;
+ event.window = m_widget->window;
+ int x = 0;
+ int y = 0;
+ GdkModifierType state;
+ gdk_window_get_pointer( event.window, &x, &y, &state );
+ event.x = x;
+ event.y = y;
+ event.state = state;
+ event.time = GDK_CURRENT_TIME;
+
+ /* GTK wants to know which button was pressed which caused the dragging */
+ int button_number = 0;
+ if (event.state & GDK_BUTTON1_MASK) button_number = 1;
+ else if (event.state & GDK_BUTTON2_MASK) button_number = 2;
+ else if (event.state & GDK_BUTTON3_MASK) button_number = 3;
+
+#if wxUSE_THREADS
+ /* disable GUI threads */
+ wxapp_uninstall_thread_wakeup();
+#endif
+
+ /* don't start dragging if no button is down */
+ if (button_number)
+ {
+ GdkDragContext *context = gtk_drag_begin( m_widget,
+ target_list,
+ GDK_ACTION_COPY,
+ button_number, /* number of mouse button which started drag */
+ (GdkEvent*) &event );
+
+ wxMask *mask = m_goIcon.GetMask();
+ GdkBitmap *bm = (GdkBitmap *) NULL;
+ if (mask) bm = mask->GetBitmap();
+ GdkPixmap *pm = m_goIcon.GetPixmap();
+
+ gtk_drag_set_icon_pixmap( context,
+ gtk_widget_get_colormap( m_widget ),
+ pm,
+ bm,
+ 0,
+ 0 );
+
+ while (m_waiting) gtk_main_iteration();;
+ }
+
+#if wxUSE_THREADS
+ /* re-enable GUI threads */
+ wxapp_install_thread_wakeup();
+#endif
+
+ g_blockEventsOnDrag = FALSE;
+
+ UnregisterWindow();
+
+ return m_retValue;
+}
+
+void wxDropSource::RegisterWindow()
+{
+ if (!m_widget) return;
+
+ gtk_signal_connect( GTK_OBJECT(m_widget), "drag_data_get",
+ GTK_SIGNAL_FUNC (source_drag_data_get), (gpointer) this);
+ gtk_signal_connect (GTK_OBJECT(m_widget), "drag_data_delete",
+ GTK_SIGNAL_FUNC (source_drag_data_delete), (gpointer) this );
+ gtk_signal_connect (GTK_OBJECT(m_widget), "drag_begin",
+ GTK_SIGNAL_FUNC (source_drag_begin), (gpointer) this );
+ gtk_signal_connect (GTK_OBJECT(m_widget), "drag_end",
+ GTK_SIGNAL_FUNC (source_drag_end), (gpointer) this );
+
+}
+
+void wxDropSource::UnregisterWindow()
+{
+ if (!m_widget) return;
+
+ gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget),
+ GTK_SIGNAL_FUNC(source_drag_data_get), (gpointer) this );
+ gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget),
+ GTK_SIGNAL_FUNC(source_drag_data_delete), (gpointer) this );
+ gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget),
+ GTK_SIGNAL_FUNC(source_drag_begin), (gpointer) this );
+ gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget),
+ GTK_SIGNAL_FUNC(source_drag_end), (gpointer) this );
+}
+
+#endif