+static gint
+gtk_dnd_window_configure_callback( GtkWidget *WXUNUSED(widget), GdkEventConfigure *WXUNUSED(event), wxDropSource *source )
+{
+ if (g_isIdle)
+ wxapp_install_idle_handler();
+
+ wxDragResult action = wxDragNone;
+ if (source->m_dragContext->action == GDK_ACTION_COPY) action = wxDragCopy;
+ if (source->m_dragContext->action == GDK_ACTION_LINK) action = wxDragLink;
+ if (source->m_dragContext->action == GDK_ACTION_MOVE) action = wxDragMove;
+
+ source->GiveFeedback( action );
+
+ return 0;
+}
+
+//---------------------------------------------------------------------------
+// wxDropSource
+//---------------------------------------------------------------------------
+
+wxDropSource::wxDropSource(wxWindow *win,
+ const wxIcon &iconCopy,
+ const wxIcon &iconMove,
+ const wxIcon &iconNone)
+{
+ m_waiting = TRUE;
+
+ m_iconWindow = (GtkWidget*) NULL;
+
+ m_window = win;
+ m_widget = win->m_widget;
+ if (win->m_wxwindow) m_widget = win->m_wxwindow;
+
+ m_retValue = wxDragCancel;
+
+ SetIcons(iconCopy, iconMove, iconNone);
+}
+
+wxDropSource::wxDropSource(wxDataObject& data,
+ wxWindow *win,
+ const wxIcon &iconCopy,
+ const wxIcon &iconMove,
+ const wxIcon &iconNone)
+{
+ 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;
+
+ SetIcons(iconCopy, iconMove, iconNone);
+}
+
+void wxDropSource::SetIcons(const wxIcon &iconCopy,
+ const wxIcon &iconMove,
+ const wxIcon &iconNone)
+{
+ m_iconCopy = iconCopy;
+ m_iconMove = iconMove;
+ m_iconNone = iconNone;
+
+ if ( !m_iconCopy.Ok() )
+ m_iconCopy = wxIcon(page_xpm);
+ if ( !m_iconMove.Ok() )
+ m_iconMove = m_iconCopy;
+ if ( !m_iconNone.Ok() )
+ m_iconNone = m_iconCopy;
+}
+
+wxDropSource::~wxDropSource()
+{
+}
+
+void wxDropSource::PrepareIcon( int action, GdkDragContext *context )
+{
+ // get the right icon to display
+ wxIcon *icon = NULL;
+ if ( action & GDK_ACTION_MOVE )
+ icon = &m_iconMove;
+ else if ( action & GDK_ACTION_COPY )
+ icon = &m_iconCopy;
+ else
+ icon = &m_iconNone;
+
+ GdkBitmap *mask;
+ if ( icon->GetMask() )
+ mask = icon->GetMask()->GetBitmap();
+ else
+ mask = (GdkBitmap *)NULL;
+
+ GdkPixmap *pixmap = icon->GetPixmap();
+
+ gint width,height;
+ gdk_window_get_size (pixmap, &width, &height);
+
+ GdkColormap *colormap = gtk_widget_get_colormap( m_widget );
+#ifndef __WXGTK20__
+ gtk_widget_push_visual (gdk_colormap_get_visual (colormap));
+#endif
+ 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);
+
+#ifndef __WXGTK20__
+ gtk_widget_pop_visual ();
+#endif
+ 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, 0, 0 );
+}
+
+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;
+
+ // still in drag
+ if (g_blockEventsOnDrag)
+ return (wxDragResult) wxDragNone;
+
+ // disabled for now
+ 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];
+ wxLogTrace(TRACE_DND, 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)
+ {
+ int action = GDK_ACTION_COPY;
+ if ( allowMove )
+ action |= GDK_ACTION_MOVE;
+ GdkDragContext *context = gtk_drag_begin( m_widget,
+ target_list,
+ (GdkDragAction)action,
+ button_number, /* number of mouse button which started drag */
+ (GdkEvent*) &event );
+
+ m_dragContext = context;
+
+ PrepareIcon( action, context );
+
+ while (m_waiting) gtk_main_iteration();
+
+ if (context->action == GDK_ACTION_COPY)
+ m_retValue = wxDragCopy;
+ if (context->action == GDK_ACTION_LINK)
+ m_retValue = wxDragLink;
+ 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