]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkdnd.c
Merge libgdk and libgtk
[~andy/gtk] / gtk / gtkdnd.c
index 08496d5761dfd69687fff5dbf1f688b026de046d..502e21b6e6a7d2a79f13406f95996c35f2bda01c 100644 (file)
@@ -30,9 +30,7 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include "gdkconfig.h"
-
-#include "gdk/gdkkeysyms.h"
+#include "gdk/gdk.h"
 
 #ifdef GDK_WINDOWING_X11
 #include <X11/Xlib.h>
@@ -52,6 +50,7 @@
 #include "gtkwindow.h"
 #include "gtkintl.h"
 #include "gtkdndcursors.h"
+#include "gtkselectionprivate.h"
 
 static GSList *source_widgets = NULL;
 
@@ -981,7 +980,6 @@ gtk_drag_get_data (GtkWidget      *widget,
 
   g_return_if_fail (GTK_IS_WIDGET (widget));
   g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
-  g_return_if_fail (!context->is_source);
 
   selection_widget = gtk_drag_get_ipc_widget (widget);
 
@@ -1016,14 +1014,13 @@ gtk_drag_get_source_widget (GdkDragContext *context)
   GSList *tmp_list;
 
   g_return_val_if_fail (GDK_IS_DRAG_CONTEXT (context), NULL);
-  g_return_val_if_fail (!context->is_source, NULL);
   
   tmp_list = source_widgets;
   while (tmp_list)
     {
       GtkWidget *ipc_widget = tmp_list->data;
 
-      if (gtk_widget_get_window (ipc_widget) == context->source_window)
+      if (gtk_widget_get_window (ipc_widget) == gdk_drag_context_get_source_window (context))
        {
          GtkDragSourceInfo *info;
          info = g_object_get_data (G_OBJECT (ipc_widget), "gtk-info");
@@ -1057,13 +1054,12 @@ gtk_drag_finish (GdkDragContext *context,
   GdkAtom target = GDK_NONE;
 
   g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
-  g_return_if_fail (!context->is_source);
 
   if (success && del)
     {
       target = gdk_atom_intern_static_string ("DELETE");
     }
-  else if (context->protocol == GDK_DRAG_PROTO_MOTIF)
+  else if (gdk_drag_context_get_protocol (context) == GDK_DRAG_PROTO_MOTIF)
     {
       target = gdk_atom_intern_static_string (success ? 
                                              "XmTRANSFER_SUCCESS" : 
@@ -1072,7 +1068,7 @@ gtk_drag_finish (GdkDragContext *context,
 
   if (target != GDK_NONE)
     {
-      GtkWidget *selection_widget = gtk_drag_get_ipc_widget_for_screen (gdk_window_get_screen (context->source_window));
+      GtkWidget *selection_widget = gtk_drag_get_ipc_widget_for_screen (gdk_window_get_screen (gdk_drag_context_get_source_window (context)));
 
       g_object_ref (context);
       
@@ -1639,7 +1635,7 @@ _gtk_drag_dest_handle_event (GtkWidget *toplevel,
        else if (event->type == GDK_DROP_START && !info->proxy_source)
          {
            gdk_drop_reply (context, found, event->dnd.time);
-            if ((context->protocol == GDK_DRAG_PROTO_MOTIF) && !found)
+            if ((gdk_drag_context_get_protocol (context) == GDK_DRAG_PROTO_MOTIF) && !found)
              gtk_drag_finish (context, FALSE, FALSE, event->dnd.time);
          }
       }
@@ -1657,7 +1653,7 @@ _gtk_drag_dest_handle_event (GtkWidget *toplevel,
  * @target_list: (allow-none): list of droppable targets, or %NULL to use
  *    gtk_drag_dest_get_target_list (@widget).
  *
- * Looks for a match between @context->targets and the
+ * Looks for a match between the supported targets of @context and the
  * @dest_target_list, returning the first matching target, otherwise
  * returning %GDK_NONE. @dest_target_list should usually be the return
  * value from gtk_drag_dest_get_target_list(), but some widgets may
@@ -1665,7 +1661,8 @@ _gtk_drag_dest_handle_event (GtkWidget *toplevel,
  * that case, they will have to implement a drag_motion handler that
  * passes the correct target list to this function.
  *
- * Return value: first target that the source offers and the dest can accept, or %GDK_NONE
+ * Return value: first target that the source offers and the dest can
+ *     accept, or %GDK_NONE
  **/
 GdkAtom
 gtk_drag_dest_find_target (GtkWidget      *widget,
@@ -1678,7 +1675,6 @@ gtk_drag_dest_find_target (GtkWidget      *widget,
 
   g_return_val_if_fail (GTK_IS_WIDGET (widget), GDK_NONE);
   g_return_val_if_fail (GDK_IS_DRAG_CONTEXT (context), GDK_NONE);
-  g_return_val_if_fail (!context->is_source, GDK_NONE);
 
 
   source_widget = gtk_drag_get_source_widget (context);
@@ -1693,7 +1689,7 @@ gtk_drag_dest_find_target (GtkWidget      *widget,
   while (tmp_target)
     {
       GtkTargetPair *pair = tmp_target->data;
-      tmp_source = context->targets;
+      tmp_source = gdk_drag_context_list_targets (context);
       while (tmp_source)
        {
          if (tmp_source->data == GUINT_TO_POINTER (pair->target))
@@ -1723,6 +1719,7 @@ gtk_drag_selection_received (GtkWidget        *widget,
   GdkDragContext *context;
   GtkDragDestInfo *info;
   GtkWidget *drop_widget;
+  GdkAtom target;
 
   drop_widget = data;
 
@@ -1730,23 +1727,24 @@ gtk_drag_selection_received (GtkWidget        *widget,
   info = gtk_drag_get_dest_info (context, FALSE);
 
   if (info->proxy_data && 
-      info->proxy_data->target == selection_data->target)
+      gtk_selection_data_get_target (info->proxy_data) == gtk_selection_data_get_target (selection_data))
     {
       gtk_selection_data_set (info->proxy_data,
-                             selection_data->type,
-                             selection_data->format,
-                             selection_data->data,
-                             selection_data->length);
+                             gtk_selection_data_get_data_type (selection_data),
+                             gtk_selection_data_get_format (selection_data),
+                             gtk_selection_data_get_data (selection_data),
+                             gtk_selection_data_get_length (selection_data));
       gtk_main_quit ();
       return;
     }
 
-  if (selection_data->target == gdk_atom_intern_static_string ("DELETE"))
+  target = gtk_selection_data_get_target (selection_data);
+  if (target == gdk_atom_intern_static_string ("DELETE"))
     {
       gtk_drag_finish (context, TRUE, FALSE, time);
     }
-  else if ((selection_data->target == gdk_atom_intern_static_string ("XmTRANSFER_SUCCESS")) ||
-          (selection_data->target == gdk_atom_intern_static_string ("XmTRANSFER_FAILURE")))
+  else if ((target == gdk_atom_intern_static_string ("XmTRANSFER_SUCCESS")) ||
+          (target == gdk_atom_intern_static_string ("XmTRANSFER_FAILURE")))
     {
       /* Do nothing */
     }
@@ -1761,11 +1759,11 @@ gtk_drag_selection_received (GtkWidget        *widget,
          guint target_info;
 
          if (gtk_target_list_find (site->target_list, 
-                                   selection_data->target,
+                                   target,
                                    &target_info))
            {
              if (!(site->flags & GTK_DEST_DEFAULT_DROP) ||
-                 selection_data->length >= 0)
+                 gtk_selection_data_get_length (selection_data) >= 0)
                g_signal_emit_by_name (drop_widget,
                                       "drag-data-received",
                                       context, info->drop_x, info->drop_y,
@@ -1786,8 +1784,8 @@ gtk_drag_selection_received (GtkWidget        *widget,
        {
 
          gtk_drag_finish (context, 
-                          (selection_data->length >= 0),
-                          (context->action == GDK_ACTION_MOVE),
+                          (gtk_selection_data_get_length (selection_data) >= 0),
+                          (gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE),
                           time);
        }
       
@@ -1906,7 +1904,7 @@ gtk_drag_find_widget (GtkWidget           *widget,
 }
 
 static void
-gtk_drag_proxy_begin (GtkWidget       *widget, 
+gtk_drag_proxy_begin (GtkWidget       *widget,
                      GtkDragDestInfo *dest_info,
                      guint32          time)
 {
@@ -1924,7 +1922,7 @@ gtk_drag_proxy_begin (GtkWidget       *widget,
   
   ipc_widget = gtk_drag_get_ipc_widget (widget);
   context = gdk_drag_begin (gtk_widget_get_window (ipc_widget),
-                           dest_info->context->targets);
+                           gdk_drag_context_list_targets (dest_info->context));
 
   source_info = gtk_drag_get_source_info (context, TRUE);
 
@@ -1932,10 +1930,10 @@ gtk_drag_proxy_begin (GtkWidget       *widget,
   source_info->widget = g_object_ref (widget);
 
   source_info->target_list = gtk_target_list_new (NULL, 0);
-  tmp_list = dest_info->context->targets;
+  tmp_list = gdk_drag_context_list_targets (dest_info->context);
   while (tmp_list)
     {
-      gtk_target_list_add (source_info->target_list, 
+      gtk_target_list_add (source_info->target_list,
                           GDK_POINTER_TO_ATOM (tmp_list->data), 0, 0);
       tmp_list = tmp_list->next;
     }
@@ -2123,8 +2121,9 @@ gtk_drag_dest_motion (GtkWidget        *widget,
                       dest_window, proto,
                       current_event->dnd.x_root, 
                       current_event->dnd.y_root, 
-                      context->suggested_action, 
-                      context->actions, time);
+                       gdk_drag_context_get_suggested_action (context),
+                       gdk_drag_context_get_actions (context),
+                       time);
 
       if (!site->proxy_window && dest_window)
        g_object_unref (dest_window);
@@ -2141,8 +2140,8 @@ gtk_drag_dest_motion (GtkWidget        *widget,
 
   if (site->track_motion || site->flags & GTK_DEST_DEFAULT_MOTION)
     {
-      if (context->suggested_action & site->actions)
-       action = context->suggested_action;
+      if (gdk_drag_context_get_suggested_action (context) & site->actions)
+       action = gdk_drag_context_get_suggested_action (context);
       else
        {
          gint i;
@@ -2150,7 +2149,7 @@ gtk_drag_dest_motion (GtkWidget        *widget,
          for (i = 0; i < 8; i++)
            {
              if ((site->actions & (1 << i)) &&
-                 (context->actions & (1 << i)))
+                 (gdk_drag_context_get_actions (context) & (1 << i)))
                {
                  action = (1 << i);
                  break;
@@ -2205,7 +2204,7 @@ gtk_drag_dest_drop (GtkWidget          *widget,
   if (site->do_proxy)
     {
       if (info->proxy_source || 
-         (info->context->protocol == GDK_DRAG_PROTO_ROOTWIN))
+         (gdk_drag_context_get_protocol (info->context) == GDK_DRAG_PROTO_ROOTWIN))
        {
          gtk_drag_drop (info->proxy_source, time);
        }
@@ -2245,8 +2244,9 @@ gtk_drag_dest_drop (GtkWidget          *widget,
                           dest_window, proto,
                           current_event->dnd.x_root, 
                           current_event->dnd.y_root, 
-                          context->suggested_action, 
-                          context->actions, time);
+                           gdk_drag_context_get_suggested_action (context),
+                           gdk_drag_context_get_actions (context),
+                           time);
 
          if (!site->proxy_window && dest_window)
            g_object_unref (dest_window);
@@ -3024,7 +3024,6 @@ gtk_drag_set_icon_widget (GdkDragContext    *context,
                          gint               hot_y)
 {
   g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
-  g_return_if_fail (context->is_source);
   g_return_if_fail (GTK_IS_WIDGET (widget));
 
   gtk_drag_set_icon_window (context, widget, hot_x, hot_y, FALSE);
@@ -3097,7 +3096,7 @@ set_icon_stock_pixbuf (GdkDragContext    *context,
   g_return_if_fail (pixbuf != NULL || stock_id != NULL);
   g_return_if_fail (pixbuf == NULL || stock_id == NULL);
 
-  screen = gdk_window_get_screen (context->source_window);
+  screen = gdk_window_get_screen (gdk_drag_context_get_source_window (context));
 
   window = gtk_window_new (GTK_WINDOW_POPUP);
   gtk_window_set_type_hint (GTK_WINDOW (window), GDK_WINDOW_TYPE_HINT_DND);
@@ -3109,8 +3108,8 @@ set_icon_stock_pixbuf (GdkDragContext    *context,
 
   if (stock_id)
     {
-      pixbuf = gtk_widget_render_icon (window, stock_id,
-                                      GTK_ICON_SIZE_DND, NULL);
+      pixbuf = gtk_widget_render_icon_pixbuf (window, stock_id,
+                                              GTK_ICON_SIZE_DND);
 
       if (!pixbuf)
        {
@@ -3123,7 +3122,7 @@ set_icon_stock_pixbuf (GdkDragContext    *context,
   else
     g_object_ref (pixbuf);
 
-  display = gdk_window_get_display (context->source_window);
+  display = gdk_window_get_display (gdk_drag_context_get_source_window (context));
   width = gdk_pixbuf_get_width (pixbuf);
   height = gdk_pixbuf_get_height (pixbuf);
 
@@ -3173,7 +3172,6 @@ gtk_drag_set_icon_pixbuf  (GdkDragContext *context,
                           gint            hot_y)
 {
   g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
-  g_return_if_fail (context->is_source);
   g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
 
   set_icon_stock_pixbuf (context, NULL, pixbuf, hot_x, hot_y, FALSE);
@@ -3196,7 +3194,6 @@ gtk_drag_set_icon_stock  (GdkDragContext *context,
                          gint            hot_y)
 {
   g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
-  g_return_if_fail (context->is_source);
   g_return_if_fail (stock_id != NULL);
   
   set_icon_stock_pixbuf (context, stock_id, NULL, hot_x, hot_y, FALSE);
@@ -3264,13 +3261,12 @@ gtk_drag_set_icon_surface (GdkDragContext    *context,
   cairo_pattern_t *pattern;
       
   g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
-  g_return_if_fail (context->is_source);
   g_return_if_fail (surface != NULL);
 
   _gtk_cairo_surface_extents (surface, &extents);
 
 
-  screen = gdk_window_get_screen (context->source_window);
+  screen = gdk_window_get_screen (gdk_drag_context_get_source_window (context));
 
   window = gtk_window_new (GTK_WINDOW_POPUP);
   gtk_window_set_type_hint (GTK_WINDOW (window), GDK_WINDOW_TYPE_HINT_DND);
@@ -3359,10 +3355,9 @@ gtk_drag_set_icon_name (GdkDragContext *context,
   gint width, height, icon_size;
 
   g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
-  g_return_if_fail (context->is_source);
   g_return_if_fail (icon_name != NULL);
 
-  screen = gdk_window_get_screen (context->source_window);
+  screen = gdk_window_get_screen (gdk_drag_context_get_source_window (context));
   g_return_if_fail (screen != NULL);
 
   settings = gtk_settings_get_for_screen (screen);
@@ -3395,7 +3390,6 @@ void
 gtk_drag_set_icon_default (GdkDragContext *context)
 {
   g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
-  g_return_if_fail (context->is_source);
 
   gtk_drag_set_icon_stock (context, GTK_STOCK_DND, -2, -2);
 }
@@ -3438,7 +3432,7 @@ _gtk_drag_source_handle_event (GtkWidget *widget,
              {
                if (info->proxy_dest->proxy_drop_wait)
                  {
-                   gboolean result = context->action != 0;
+                   gboolean result = gdk_drag_context_get_selected_action (context) != 0;
                    
                    /* Aha - we can finally pass the MOTIF DROP on... */
                    gdk_drop_reply (info->proxy_dest->context, result, info->proxy_dest->proxy_drop_time);
@@ -3450,7 +3444,7 @@ _gtk_drag_source_handle_event (GtkWidget *widget,
                else
                  {
                    gdk_drag_status (info->proxy_dest->context,
-                                    event->dnd.context->action,
+                                    gdk_drag_context_get_selected_action (event->dnd.context),
                                     event->dnd.time);
                  }
              }
@@ -3458,7 +3452,7 @@ _gtk_drag_source_handle_event (GtkWidget *widget,
        else if (info->have_grab)
          {
            cursor = gtk_drag_get_cursor (gtk_widget_get_display (widget),
-                                         event->dnd.context->action,
+                                         gdk_drag_context_get_selected_action (event->dnd.context),
                                          info);
            if (info->cursor != cursor)
              {
@@ -3528,7 +3522,7 @@ gtk_drag_source_check_selection (GtkDragSourceInfo *info,
       tmp_list = tmp_list->next;
     }
   
-  if (info->context->protocol == GDK_DRAG_PROTO_MOTIF)
+  if (gdk_drag_context_get_protocol (info->context) == GDK_DRAG_PROTO_MOTIF)
     {
       gtk_selection_add_target (info->ipc_widget,
                                selection,
@@ -3642,7 +3636,7 @@ static void
 gtk_drag_drop (GtkDragSourceInfo *info, 
               guint32            time)
 {
-  if (info->context->protocol == GDK_DRAG_PROTO_ROOTWIN)
+  if (gdk_drag_context_get_protocol (info->context) == GDK_DRAG_PROTO_ROOTWIN)
     {
       GtkSelectionData selection_data;
       GList *tmp_list;
@@ -3803,7 +3797,7 @@ gtk_drag_selection_get (GtkWidget        *widget,
          info->proxy_dest->proxy_data = selection_data;
          gtk_drag_get_data (info->widget,
                             info->proxy_dest->context,
-                            selection_data->target,
+                            gtk_selection_data_get_target (selection_data),
                             time);
          gtk_main ();
          info->proxy_dest->proxy_data = NULL;
@@ -3811,7 +3805,7 @@ gtk_drag_selection_get (GtkWidget        *widget,
       else
        {
          if (gtk_target_list_find (info->target_list, 
-                                   selection_data->target, 
+                                   gtk_selection_data_get_target (selection_data),
                                    &target_info))
            {
              g_signal_emit_by_name (info->widget, "drag-data-get",
@@ -4330,7 +4324,8 @@ gtk_drag_button_release_cb (GtkWidget      *widget,
   if (event->button != info->button)
     return FALSE;
 
-  if ((info->context->action != 0) && (info->context->dest_window != NULL))
+  if ((gdk_drag_context_get_selected_action (info->context) != 0) &&
+      (gdk_drag_context_get_dest_window (info->context) != NULL))
     {
       gtk_drag_end (info, event->time);
       gtk_drag_drop (info, event->time);