+ m_icon = icon;
+ if (wxNullIcon == icon) m_icon = wxIcon( page_xpm );
+}
+
+wxDropSource::wxDropSource( wxDataObject& data, wxWindow *win, const wxIcon &icon )
+{
+ m_waiting = TRUE;
+
+ SetData( data );
+
+ m_iconWindow = (GtkWidget*) NULL;
+
+ m_window = win;
+ m_widget = win->m_widget;
+ if (win->m_wxwindow) m_widget = win->m_wxwindow;
+
+ m_retValue = wxDragCancel;
+
+ m_icon = icon;
+ if (wxNullIcon == icon) m_icon = wxIcon( page_xpm );
+}
+
+wxDropSource::~wxDropSource()
+{
+}
+
+void wxDropSource::PrepareIcon( int hot_x, int hot_y, GdkDragContext *context )
+{
+ GdkBitmap *mask = (GdkBitmap *) NULL;
+ if (m_icon.GetMask()) mask = m_icon.GetMask()->GetBitmap();
+ GdkPixmap *pixmap = m_icon.GetPixmap();
+
+ gint width,height;
+ gdk_window_get_size (pixmap, &width, &height);
+
+ GdkColormap *colormap = gtk_widget_get_colormap( m_widget );
+ gtk_widget_push_visual (gdk_colormap_get_visual (colormap));
+ gtk_widget_push_colormap (colormap);
+
+ m_iconWindow = gtk_window_new (GTK_WINDOW_POPUP);
+ gtk_widget_set_events (m_iconWindow, GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
+ gtk_widget_set_app_paintable (GTK_WIDGET (m_iconWindow), TRUE);
+
+ gtk_widget_pop_visual ();
+ gtk_widget_pop_colormap ();
+
+ gtk_widget_set_usize (m_iconWindow, width, height);
+ gtk_widget_realize (m_iconWindow);
+
+ gtk_signal_connect( GTK_OBJECT(m_iconWindow), "configure_event",
+ GTK_SIGNAL_FUNC(gtk_dnd_window_configure_callback), (gpointer)this );
+
+ gdk_window_set_back_pixmap (m_iconWindow->window, pixmap, FALSE);
+
+ if (mask)
+ gtk_widget_shape_combine_mask (m_iconWindow, mask, 0, 0);
+
+ gtk_drag_set_icon_widget( context, m_iconWindow, hot_x, hot_y );
+}
+
+wxDragResult wxDropSource::DoDragDrop( bool allowMove )
+{
+ wxASSERT_MSG( m_data, wxT("Drop source: no data") );
+
+ if (!m_data)
+ return (wxDragResult) wxDragNone;
+
+ if (m_data->GetFormatCount() == 0)
+ return (wxDragResult) wxDragNone;
+
+ g_blockEventsOnDrag = TRUE;
+
+ RegisterWindow();
+
+ m_waiting = TRUE;
+
+ GtkTargetList *target_list = gtk_target_list_new( (GtkTargetEntry*) NULL, 0 );
+
+ wxDataFormat *array = new wxDataFormat[ m_data->GetFormatCount() ];
+ m_data->GetAllFormats( array );
+ for (size_t i = 0; i < m_data->GetFormatCount(); i++)
+ {
+ GdkAtom atom = array[i];
+ wxLogDebug( wxT("Drop source: Supported atom %s"), gdk_atom_name( atom ) );
+ gtk_target_list_add( target_list, atom, 0, 0 );
+ }
+ delete[] array;
+
+ 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 = (guint32)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)
+ {
+ GdkDragAction action = GDK_ACTION_COPY;
+ if (allowMove) action = (GdkDragAction)(GDK_ACTION_MOVE|GDK_ACTION_COPY);
+ GdkDragContext *context = gtk_drag_begin( m_widget,
+ target_list,
+ action,
+ button_number, /* number of mouse button which started drag */
+ (GdkEvent*) &event );
+
+ m_dragContext = context;
+
+ PrepareIcon( 0, 0, context );
+
+ while (m_waiting) gtk_main_iteration();
+
+ if (context->action == GDK_ACTION_COPY)
+ m_retValue = wxDragCopy;
+ if (context->action == GDK_ACTION_MOVE)
+ m_retValue = wxDragMove;
+ }
+
+#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
+ // wxUSE_DRAG_AND_DROP