- if (motif_find_drag_window (FALSE))
- {
- MotifTargetTableHeader *header = NULL;
- guchar *target_bytes = NULL;
- guchar *p;
- gboolean success = FALSE;
-
- gdk_error_trap_push ();
- XGetWindowProperty (gdk_display, motif_drag_window,
- motif_drag_targets_atom,
- 0, (sizeof(MotifTargetTableHeader)+3)/4, FALSE,
- motif_drag_targets_atom,
- &type, &format, &nitems, &bytes_after,
- (guchar **)&header);
-
- if (gdk_error_trap_pop () || (format != 8) || (nitems < sizeof (MotifTargetTableHeader)))
- goto error;
-
- header->n_lists = card16_to_host (header->n_lists, header->byte_order);
- header->total_size = card32_to_host (header->total_size, header->byte_order);
-
- gdk_error_trap_push ();
- XGetWindowProperty (gdk_display, motif_drag_window, motif_drag_targets_atom,
- (sizeof(MotifTargetTableHeader)+3)/4,
- (header->total_size + 3)/4 - (sizeof(MotifTargetTableHeader) + 3)/4,
- FALSE,
- motif_drag_targets_atom, &type, &format, &nitems,
- &bytes_after, &target_bytes);
-
- if (gdk_error_trap_pop () || (format != 8) || (bytes_after != 0) ||
- (nitems != header->total_size - sizeof(MotifTargetTableHeader)))
- goto error;
-
- motif_n_target_lists = header->n_lists;
- motif_target_lists = g_new0 (GList *, motif_n_target_lists);
-
- p = target_bytes;
- for (i=0; i<header->n_lists; i++)
- {
- gint n_targets;
- guint32 *targets;
-
- if (p + sizeof(guint16) - target_bytes > nitems)
- goto error;
-
- n_targets = card16_to_host (*(gushort *)p, header->byte_order);
-
- /* We need to make a copy of the targets, since it may
- * be unaligned
- */
- targets = g_new (guint32, n_targets);
- memcpy (targets, p + sizeof(guint16), sizeof(guint32) * n_targets);
-
- p += sizeof(guint16) + n_targets * sizeof(guint32);
- if (p - target_bytes > nitems)
- goto error;
-
- for (j=0; j<n_targets; j++)
- motif_target_lists[i] =
- g_list_prepend (motif_target_lists[i],
- GUINT_TO_POINTER (card32_to_host (targets[j],
- header->byte_order)));
- g_free (targets);
- motif_target_lists[i] = g_list_reverse (motif_target_lists[i]);
- }
-
- success = TRUE;
-
- error:
- if (header)
- XFree (header);
-
- if (target_bytes)
- XFree (target_bytes);
-
- if (!success)
- {
- if (motif_target_lists)
- {
- g_free (motif_target_lists);
- motif_target_lists = NULL;
- motif_n_target_lists = 0;
- }
- g_warning ("Error reading Motif target table\n");
- }
- }
-}
-
-static gint
-targets_sort_func (gconstpointer a, gconstpointer b)
-{
- return (GPOINTER_TO_UINT (a) < GPOINTER_TO_UINT (b)) ?
- -1 : ((GPOINTER_TO_UINT (a) > GPOINTER_TO_UINT (b)) ? 1 : 0);
-}
-
-/* Check if given (sorted) list is in the targets table */
-static gboolean
-motif_target_table_check (GList *sorted)
-{
- GList *tmp_list1, *tmp_list2;
- gint i;
-
- for (i=0; i<motif_n_target_lists; i++)
- {
- tmp_list1 = motif_target_lists[i];
- tmp_list2 = sorted;
-
- while (tmp_list1 && tmp_list2)
- {
- if (tmp_list1->data != tmp_list2->data)
- break;
-
- tmp_list1 = tmp_list1->next;
- tmp_list2 = tmp_list2->next;
- }
- if (!tmp_list1 && !tmp_list2) /* Found it */
- return i;
- }
-
- return -1;
-}
-
-static gint
-motif_add_to_target_table (GList *targets)
-{
- GList *sorted = NULL;
- gint index = -1;
- gint i;
- GList *tmp_list;
-
- /* make a sorted copy of the list */
-
- while (targets)
- {
- sorted = g_list_insert_sorted (sorted, targets->data, targets_sort_func);
- targets = targets->next;
- }
-
- /* First check if it is their already */
-
- if (motif_target_lists)
- index = motif_target_table_check (sorted);
-
- /* We need to grab the server while doing this, to ensure
- * atomiticity. Ugh
- */
-
- if (index < 0)
- {
- /* We need to make sure that it exists _before_ we grab the
- * server, since we can't open a new connection after we
- * grab the server.
- */
- motif_find_drag_window (TRUE);
-
- XGrabServer(gdk_display);
- motif_read_target_table();
-
- /* Check again, in case it was added in the meantime */
-
- if (motif_target_lists)
- index = motif_target_table_check (sorted);
-
- if (index < 0)
- {
- guint32 total_size = 0;
- guchar *data;
- guchar *p;
- guint16 *p16;
- MotifTargetTableHeader *header;
-
- if (!motif_target_lists)
- {
- motif_target_lists = g_new (GList *, 1);
- motif_n_target_lists = 1;
- }
- else
- {
- motif_n_target_lists++;
- motif_target_lists = g_realloc (motif_target_lists,
- sizeof(GList *) * motif_n_target_lists);
- }
- motif_target_lists[motif_n_target_lists - 1] = sorted;
- sorted = NULL;
- index = motif_n_target_lists - 1;
-
- total_size = sizeof (MotifTargetTableHeader);
- for (i = 0; i < motif_n_target_lists ; i++)
- total_size += sizeof(guint16) + sizeof(guint32) * g_list_length (motif_target_lists[i]);
-
- data = g_malloc (total_size);
-
- header = (MotifTargetTableHeader *)data;
- p = data + sizeof(MotifTargetTableHeader);
-
- header->byte_order = local_byte_order;
- header->protocol_version = 0;
- header->n_lists = motif_n_target_lists;
- header->total_size = total_size;
-
- for (i = 0; i < motif_n_target_lists ; i++)
- {
- guint16 n_targets = g_list_length (motif_target_lists[i]);
- guint32 *targets = g_new (guint32, n_targets);
- guint32 *p32 = targets;
-
- tmp_list = motif_target_lists[i];
- while (tmp_list)
- {
- *p32 = GPOINTER_TO_UINT (tmp_list->data);
-
- tmp_list = tmp_list->next;
- p32++;
- }
-
- p16 = (guint16 *)p;
- p += sizeof(guint16);
-
- memcpy (p, targets, n_targets * sizeof(guint32));
-
- *p16 = n_targets;
- p += sizeof(guint32) * n_targets;
- g_free (targets);
- }
-
- XChangeProperty (gdk_display, motif_drag_window,
- motif_drag_targets_atom,
- motif_drag_targets_atom,
- 8, PropModeReplace,
- data, total_size);
- }
- XUngrabServer(gdk_display);
- }
-
- g_list_free (sorted);
- return index;
-}
-
-/* Translate flags */
-
-static void
-motif_dnd_translate_flags (GdkDragContext *context, guint16 flags)
-{
- guint recommended_op = flags & 0x000f;
- guint possible_ops = (flags & 0x0f0) >> 4;
-
- switch (recommended_op)
- {
- case XmDROP_MOVE:
- context->suggested_action = GDK_ACTION_MOVE;
- break;
- case XmDROP_COPY:
- context->suggested_action = GDK_ACTION_COPY;
- break;
- case XmDROP_LINK:
- context->suggested_action = GDK_ACTION_LINK;
- break;
- default:
- context->suggested_action = GDK_ACTION_COPY;
- break;
- }
-
- context->actions = 0;
- if (possible_ops & XmDROP_MOVE)
- context->actions |= GDK_ACTION_MOVE;
- if (possible_ops & XmDROP_COPY)
- context->actions |= GDK_ACTION_COPY;
- if (possible_ops & XmDROP_LINK)
- context->actions |= GDK_ACTION_LINK;
-}
-
-static guint16
-motif_dnd_get_flags (GdkDragContext *context)
-{
- guint16 flags = 0;
-
- switch (context->suggested_action)
- {
- case GDK_ACTION_MOVE:
- flags = XmDROP_MOVE;
- break;
- case GDK_ACTION_COPY:
- flags = XmDROP_COPY;
- break;
- case GDK_ACTION_LINK:
- flags = XmDROP_LINK;
- break;
- default:
- flags = XmDROP_NOOP;
- break;
- }
-
- if (context->actions & GDK_ACTION_MOVE)
- flags |= XmDROP_MOVE << 8;
- if (context->actions & GDK_ACTION_COPY)
- flags |= XmDROP_COPY << 8;
- if (context->actions & GDK_ACTION_LINK)
- flags |= XmDROP_LINK << 8;
-
- return flags;
-}
-
-/* Source Side */
-
-static void
-motif_set_targets (GdkDragContext *context)
-{
- GdkDragContextPrivateX11 *private = PRIVATE_DATA (context);
- MotifDragInitiatorInfo info;
- gint i;
- static GdkAtom motif_drag_initiator_info = GDK_NONE;
-
- if (!motif_drag_initiator_info)
- motif_drag_initiator_info = gdk_atom_intern ("_MOTIF_DRAG_INITIATOR_INFO", FALSE);
-
- info.byte_order = local_byte_order;
- info.protocol_version = 0;
-
- info.targets_index = motif_add_to_target_table (context->targets);
-
- for (i=0; ; i++)
- {
- gchar buf[20];
- g_snprintf(buf, 20, "_GDK_SELECTION_%d", i);
-
- private->motif_selection = gdk_atom_intern (buf, FALSE);
- if (!XGetSelectionOwner (gdk_display, private->motif_selection))
- break;
- }
-
- info.selection_atom = private->motif_selection;
-
- XChangeProperty (GDK_DRAWABLE_XDISPLAY (context->source_window),
- GDK_DRAWABLE_XID (context->source_window),
- private->motif_selection,
- motif_drag_initiator_info, 8, PropModeReplace,
- (guchar *)&info, sizeof (info));
-
- private->motif_targets_set = 1;
-}
-
-guint32
-motif_check_dest (Window win)
-{
- gboolean retval = FALSE;
- MotifDragReceiverInfo *info;
- Atom type = None;
- int format;
- unsigned long nitems, after;
-
- if (!motif_drag_receiver_info_atom)
- motif_drag_receiver_info_atom = gdk_atom_intern ("_MOTIF_DRAG_RECEIVER_INFO", FALSE);
-
- gdk_error_trap_push ();
- XGetWindowProperty (gdk_display, win,
- motif_drag_receiver_info_atom,
- 0, (sizeof(*info)+3)/4, False, AnyPropertyType,
- &type, &format, &nitems, &after,
- (guchar **)&info);
-
- if (gdk_error_trap_pop() == 0)
- {
- if (type != None)
- {
- if ((format == 8) && (nitems == sizeof(*info)))
- {
- if ((info->protocol_version == 0) &&
- ((info->protocol_style == XmDRAG_PREFER_PREREGISTER) ||
- (info->protocol_style == XmDRAG_PREFER_DYNAMIC) ||
- (info->protocol_style == XmDRAG_DYNAMIC)))
- retval = TRUE;
- }
- else
- {
- GDK_NOTE (DND,
- g_warning ("Invalid Motif drag receiver property on window %ld\n", win));
- }
-
- XFree (info);
- }
- }
-
- return retval ? win : GDK_NONE;
-
-}
-
-static void
-motif_send_enter (GdkDragContext *context,
- guint32 time)
-{
- XEvent xev;
- GdkDragContextPrivateX11 *private = PRIVATE_DATA (context);
-
- xev.xclient.type = ClientMessage;
- xev.xclient.message_type = gdk_atom_intern ("_MOTIF_DRAG_AND_DROP_MESSAGE", FALSE);
- xev.xclient.format = 8;
- xev.xclient.window = GDK_DRAWABLE_XID (context->dest_window);
-
- MOTIF_XCLIENT_BYTE (&xev, 0) = XmTOP_LEVEL_ENTER;
- MOTIF_XCLIENT_BYTE (&xev, 1) = local_byte_order;
- MOTIF_XCLIENT_SHORT (&xev, 1) = 0;
- MOTIF_XCLIENT_LONG (&xev, 1) = time;
- MOTIF_XCLIENT_LONG (&xev, 2) = GDK_DRAWABLE_XID (context->source_window);
-
- if (!private->motif_targets_set)
- motif_set_targets (context);
-
- MOTIF_XCLIENT_LONG (&xev, 3) = private->motif_selection;
-
- if (!gdk_send_xevent (GDK_DRAWABLE_XID (context->dest_window),
- FALSE, 0, &xev))
- GDK_NOTE (DND,
- g_message ("Send event to %lx failed",
- GDK_DRAWABLE_XID (context->dest_window)));
-}
-
-static void
-motif_send_leave (GdkDragContext *context,
- guint32 time)
-{
- XEvent xev;
-
- xev.xclient.type = ClientMessage;
- xev.xclient.message_type = gdk_atom_intern ("_MOTIF_DRAG_AND_DROP_MESSAGE", FALSE);
- xev.xclient.format = 8;
- xev.xclient.window = GDK_DRAWABLE_XID (context->dest_window);
-
- MOTIF_XCLIENT_BYTE (&xev, 0) = XmTOP_LEVEL_LEAVE;
- MOTIF_XCLIENT_BYTE (&xev, 1) = local_byte_order;
- MOTIF_XCLIENT_SHORT (&xev, 1) = 0;
- MOTIF_XCLIENT_LONG (&xev, 1) = time;
- MOTIF_XCLIENT_LONG (&xev, 2) = GDK_DRAWABLE_XID (context->source_window);
- MOTIF_XCLIENT_LONG (&xev, 3) = 0;
-
- if (!gdk_send_xevent (GDK_DRAWABLE_XID (context->dest_window),
- FALSE, 0, &xev))
- GDK_NOTE (DND,
- g_message ("Send event to %lx failed",
- GDK_DRAWABLE_XID (context->dest_window)));
-}
-
-static gboolean
-motif_send_motion (GdkDragContext *context,
- gint x_root,
- gint y_root,
- GdkDragAction action,
- guint32 time)
-{
- gboolean retval;
- XEvent xev;
- GdkDragContextPrivateX11 *private = PRIVATE_DATA (context);
-
- xev.xclient.type = ClientMessage;
- xev.xclient.message_type = gdk_atom_intern ("_MOTIF_DRAG_AND_DROP_MESSAGE", FALSE);
- xev.xclient.format = 8;
- xev.xclient.window = GDK_DRAWABLE_XID (context->dest_window);
-
- MOTIF_XCLIENT_BYTE (&xev, 1) = local_byte_order;
- MOTIF_XCLIENT_SHORT (&xev, 1) = motif_dnd_get_flags (context);
- MOTIF_XCLIENT_LONG (&xev, 1) = time;
-
- if ((context->suggested_action != private->old_action) ||
- (context->actions != private->old_actions))
- {
- MOTIF_XCLIENT_BYTE (&xev, 0) = XmOPERATION_CHANGED;
-
- /* private->drag_status = GDK_DRAG_STATUS_ACTION_WAIT; */
- retval = TRUE;
- }
- else
- {
- MOTIF_XCLIENT_BYTE (&xev, 0) = XmDRAG_MOTION;
-
- MOTIF_XCLIENT_SHORT (&xev, 4) = x_root;
- MOTIF_XCLIENT_SHORT (&xev, 5) = y_root;
-
- private->drag_status = GDK_DRAG_STATUS_MOTION_WAIT;
- retval = FALSE;
- }
-
- if (!gdk_send_xevent (GDK_DRAWABLE_XID (context->dest_window),
- FALSE, 0, &xev))
- GDK_NOTE (DND,
- g_message ("Send event to %lx failed",
- GDK_DRAWABLE_XID (context->dest_window)));
-
- return retval;
-}
-
-static void
-motif_send_drop (GdkDragContext *context, guint32 time)
-{
- XEvent xev;
- GdkDragContextPrivateX11 *private = PRIVATE_DATA (context);
-
- xev.xclient.type = ClientMessage;
- xev.xclient.message_type = gdk_atom_intern ("_MOTIF_DRAG_AND_DROP_MESSAGE", FALSE);
- xev.xclient.format = 8;
- xev.xclient.window = GDK_DRAWABLE_XID (context->dest_window);
-
- MOTIF_XCLIENT_BYTE (&xev, 0) = XmDROP_START;
- MOTIF_XCLIENT_BYTE (&xev, 1) = local_byte_order;
- MOTIF_XCLIENT_SHORT (&xev, 1) = motif_dnd_get_flags (context);
- MOTIF_XCLIENT_LONG (&xev, 1) = time;
-
- MOTIF_XCLIENT_SHORT (&xev, 4) = private->last_x;
- MOTIF_XCLIENT_SHORT (&xev, 5) = private->last_y;
-
- MOTIF_XCLIENT_LONG (&xev, 3) = private->motif_selection;
- MOTIF_XCLIENT_LONG (&xev, 4) = GDK_DRAWABLE_XID (context->source_window);
-
- if (!gdk_send_xevent (GDK_DRAWABLE_XID (context->dest_window),
- FALSE, 0, &xev))
- GDK_NOTE (DND,
- g_message ("Send event to %lx failed",
- GDK_DRAWABLE_XID (context->dest_window)));
-}
-
-/* Target Side */
-
-static gboolean
-motif_read_initiator_info (Window source_window,
- Atom atom,
- GList **targets,
- GdkAtom *selection)
-{
- GList *tmp_list;
- static GdkAtom motif_drag_initiator_info = GDK_NONE;
- GdkAtom type;
- gint format;
- gulong nitems;
- gulong bytes_after;
-
- MotifDragInitiatorInfo *initiator_info;
-
- if (!motif_drag_initiator_info)
- motif_drag_initiator_info = gdk_atom_intern ("_MOTIF_DRAG_INITIATOR_INFO", FALSE);
-
- gdk_error_trap_push ();
- XGetWindowProperty (gdk_display, source_window, atom,
- 0, sizeof(*initiator_info), FALSE,
- motif_drag_initiator_info,
- &type, &format, &nitems, &bytes_after,
- (guchar **)&initiator_info);
-
- if (gdk_error_trap_pop () || (format != 8) || (nitems != sizeof (MotifDragInitiatorInfo)) || (bytes_after != 0))
- {
- g_warning ("Error reading initiator info\n");
- return FALSE;
- }
-
- motif_read_target_table ();
-
- initiator_info->targets_index =
- card16_to_host (initiator_info->targets_index, initiator_info->byte_order);
- initiator_info->selection_atom =
- card32_to_host (initiator_info->selection_atom, initiator_info->byte_order);
-
- if (initiator_info->targets_index >= motif_n_target_lists)
- {
- g_warning ("Invalid target index in TOP_LEVEL_ENTER MESSAGE");
- XFree (initiator_info);
- return GDK_FILTER_REMOVE;
- }
-
- tmp_list = g_list_last (motif_target_lists[initiator_info->targets_index]);
-
- *targets = NULL;
- while (tmp_list)
- {
- *targets = g_list_prepend (*targets,
- tmp_list->data);
- tmp_list = tmp_list->prev;
- }
-
-#ifdef G_ENABLE_DEBUG
- if (gdk_debug_flags & GDK_DEBUG_DND)
- print_target_list (*targets);
-#endif /* G_ENABLE_DEBUG */
-
- *selection = initiator_info->selection_atom;
-
- XFree (initiator_info);
-
- return TRUE;
-}
-
-static GdkDragContext *
-motif_drag_context_new (GdkWindow *dest_window,
- guint32 timestamp,
- guint32 source_window,
- guint32 atom)
-{
- GdkDragContext *new_context;
- GdkDragContextPrivateX11 *private;
-
- /* FIXME, current_dest_drag really shouldn't be NULL'd
- * if we error below.
- */
- if (current_dest_drag != NULL)
- {
- if (timestamp >= current_dest_drag->start_time)
- {
- gdk_drag_context_unref (current_dest_drag);
- current_dest_drag = NULL;
- }
- else
- return NULL;
- }
-
- new_context = gdk_drag_context_new ();
- private = PRIVATE_DATA (new_context);
-
- new_context->protocol = GDK_DRAG_PROTO_MOTIF;
- new_context->is_source = FALSE;
-
- new_context->source_window = gdk_window_lookup (source_window);
- if (new_context->source_window)
- gdk_window_ref (new_context->source_window);
- else
- {
- new_context->source_window = gdk_window_foreign_new (source_window);
- if (!new_context->source_window)
- {
- gdk_drag_context_unref (new_context);
- return NULL;
- }
- }
-
- new_context->dest_window = dest_window;
- gdk_window_ref (dest_window);
- new_context->start_time = timestamp;
-
- if (!motif_read_initiator_info(source_window,
- atom,
- &new_context->targets,
- &private->motif_selection))
- {
- gdk_drag_context_unref (new_context);
- return NULL;
- }
-
- return new_context;
-}
-
-/*
- * The MOTIF drag protocol has no real provisions for distinguishing
- * multiple simultaneous drops. If the sources grab the pointer
- * when doing drags, that shouldn't happen, in any case. If it
- * does, we can't do much except hope for the best.
- */
-
-static GdkFilterReturn
-motif_top_level_enter (GdkEvent *event,
- guint16 flags,
- guint32 timestamp,
- guint32 source_window,
- guint32 atom)
-{
- GdkDragContext *new_context;
-
- GDK_NOTE(DND, g_message ("Motif DND top level enter: flags: %#4x time: %d source_widow: %#4x atom: %d",
- flags, timestamp, source_window, atom));
-
- new_context = motif_drag_context_new (event->any.window, timestamp, source_window, atom);
- if (!new_context)
- return GDK_FILTER_REMOVE;
-
- event->dnd.type = GDK_DRAG_ENTER;
- event->dnd.context = new_context;
- gdk_drag_context_ref (new_context);
-
- current_dest_drag = new_context;
-
- return GDK_FILTER_TRANSLATE;
-}
-
-GdkFilterReturn
-motif_top_level_leave (GdkEvent *event,
- guint16 flags,
- guint32 timestamp)
-{
- GDK_NOTE(DND, g_message ("Motif DND top level leave: flags: %#4x time: %d",
- flags, timestamp));
-
- if ((current_dest_drag != NULL) &&
- (current_dest_drag->protocol == GDK_DRAG_PROTO_MOTIF) &&
- (timestamp >= current_dest_drag->start_time))
- {
- event->dnd.type = GDK_DRAG_LEAVE;
- /* Pass ownership of context to the event */
- event->dnd.context = current_dest_drag;
-
- current_dest_drag = NULL;
-
- return GDK_FILTER_TRANSLATE;
- }
- else
- return GDK_FILTER_REMOVE;
-}
-
-GdkFilterReturn
-motif_motion (GdkEvent *event,
- guint16 flags,
- guint32 timestamp,
- gint16 x_root,
- gint16 y_root)
-{
- GdkDragContextPrivateX11 *private;
-
- GDK_NOTE(DND, g_message ("Motif DND motion: flags: %#4x time: %d (%d, %d)",
- flags, timestamp, x_root, y_root));
-
- if ((current_dest_drag != NULL) &&
- (current_dest_drag->protocol == GDK_DRAG_PROTO_MOTIF) &&
- (timestamp >= current_dest_drag->start_time))
- {
- private = PRIVATE_DATA (current_dest_drag);
-
- event->dnd.type = GDK_DRAG_MOTION;
- event->dnd.context = current_dest_drag;
- gdk_drag_context_ref (current_dest_drag);
-
- event->dnd.time = timestamp;
-
- motif_dnd_translate_flags (current_dest_drag, flags);
-
- event->dnd.x_root = x_root;
- event->dnd.y_root = y_root;
-
- private->last_x = x_root;
- private->last_y = y_root;
-
- private->drag_status = GDK_DRAG_STATUS_MOTION_WAIT;
-
- return GDK_FILTER_TRANSLATE;
- }
-
- return GDK_FILTER_REMOVE;
-}
-
-GdkFilterReturn
-motif_operation_changed (GdkEvent *event,
- guint16 flags,
- guint32 timestamp)
-{
- GdkDragContextPrivateX11 *private;
-
- GDK_NOTE(DND, g_message ("Motif DND operation changed: flags: %#4x time: %d",
- flags, timestamp));
-
- if ((current_dest_drag != NULL) &&
- (current_dest_drag->protocol == GDK_DRAG_PROTO_MOTIF) &&
- (timestamp >= current_dest_drag->start_time))
- {
- event->dnd.type = GDK_DRAG_MOTION;
- event->dnd.send_event = FALSE;
- event->dnd.context = current_dest_drag;
- gdk_drag_context_ref (current_dest_drag);
-
- event->dnd.time = timestamp;
- private = PRIVATE_DATA (current_dest_drag);
-
- motif_dnd_translate_flags (current_dest_drag, flags);
-
- event->dnd.x_root = private->last_x;
- event->dnd.y_root = private->last_y;
-
- private->drag_status = GDK_DRAG_STATUS_ACTION_WAIT;
-
- return GDK_FILTER_TRANSLATE;
- }
-
- return GDK_FILTER_REMOVE;
-}
-
-GdkFilterReturn
-motif_drop_start (GdkEvent *event,
- guint16 flags,
- guint32 timestamp,
- guint32 source_window,
- guint32 atom,
- gint16 x_root,
- gint16 y_root)
-{
- GdkDragContext *new_context;
-
-
- GDK_NOTE(DND, g_message ("Motif DND drop start: flags: %#4x time: %d (%d, %d) source_widow: %#4x atom: %d",
- flags, timestamp, x_root, y_root, source_window, atom));
-
- new_context = motif_drag_context_new (event->any.window, timestamp, source_window, atom);
- if (!new_context)
- return GDK_FILTER_REMOVE;
-
- motif_dnd_translate_flags (new_context, flags);
-
- event->dnd.type = GDK_DROP_START;
- event->dnd.context = new_context;
- event->dnd.time = timestamp;
- event->dnd.x_root = x_root;
- event->dnd.y_root = y_root;
-
- gdk_drag_context_ref (new_context);
- current_dest_drag = new_context;
-
- return GDK_FILTER_TRANSLATE;
-}
-
-GdkFilterReturn
-motif_drag_status (GdkEvent *event,
- guint16 flags,
- guint32 timestamp)
-{
- GdkDragContext *context;
-
- GDK_NOTE (DND,
- g_message ("Motif status message: flags %x", flags));
-
- context = gdk_drag_context_find (TRUE,
- GDK_DRAWABLE_XID (event->any.window),
- None);
-
- if (context)
- {
- GdkDragContextPrivateX11 *private = PRIVATE_DATA (context);
- if ((private->drag_status == GDK_DRAG_STATUS_MOTION_WAIT) ||
- (private->drag_status == GDK_DRAG_STATUS_ACTION_WAIT))
- private->drag_status = GDK_DRAG_STATUS_DRAG;
-
- event->dnd.type = GDK_DRAG_STATUS;
- event->dnd.send_event = FALSE;
- event->dnd.context = context;
- gdk_drag_context_ref (context);
-
- event->dnd.time = timestamp;
-
- if ((flags & 0x00f0) >> 4 == XmDROP_SITE_VALID)
- {
- switch (flags & 0x000f)
- {
- case XmDROP_NOOP:
- context->action = 0;
- break;
- case XmDROP_MOVE:
- context->action = GDK_ACTION_MOVE;
- break;
- case XmDROP_COPY:
- context->action = GDK_ACTION_COPY;
- break;
- case XmDROP_LINK:
- context->action = GDK_ACTION_LINK;
- break;
- }
- }
- else
- context->action = 0;
-
- return GDK_FILTER_TRANSLATE;
- }
- return GDK_FILTER_REMOVE;
-}
-
-GdkFilterReturn
-motif_dnd_filter (GdkXEvent *xev,
- GdkEvent *event,
- gpointer data)
-{
- XEvent *xevent = (XEvent *)xev;
-
- guint8 reason;
- guint16 flags;
- guint32 timestamp;
- guint32 source_window;
- GdkAtom atom;
- gint16 x_root, y_root;
- gboolean is_reply;
-
- /* First read some fields common to all Motif DND messages */
-
- reason = MOTIF_UNPACK_BYTE (xevent, 0);
- flags = MOTIF_UNPACK_SHORT (xevent, 1);
- timestamp = MOTIF_UNPACK_LONG (xevent, 1);
-
- is_reply = ((reason & 0x80) != 0);
-
- switch (reason & 0x7f)
- {
- case XmTOP_LEVEL_ENTER:
- source_window = MOTIF_UNPACK_LONG (xevent, 2);
- atom = MOTIF_UNPACK_LONG (xevent, 3);
- return motif_top_level_enter (event, flags, timestamp, source_window, atom);
- case XmTOP_LEVEL_LEAVE:
- return motif_top_level_leave (event, flags, timestamp);
-
- case XmDRAG_MOTION:
- x_root = MOTIF_UNPACK_SHORT (xevent, 4);
- y_root = MOTIF_UNPACK_SHORT (xevent, 5);
-
- if (!is_reply)
- return motif_motion (event, flags, timestamp, x_root, y_root);
- else
- return motif_drag_status (event, flags, timestamp);
-
- case XmDROP_SITE_ENTER:
- return motif_drag_status (event, flags, timestamp);
-
- case XmDROP_SITE_LEAVE:
- return motif_drag_status (event,
- XmNO_DROP_SITE << 8 | XmDROP_NOOP,
- timestamp);
- case XmDROP_START:
- x_root = MOTIF_UNPACK_SHORT (xevent, 4);
- y_root = MOTIF_UNPACK_SHORT (xevent, 5);
- atom = MOTIF_UNPACK_LONG (xevent, 3);
- source_window = MOTIF_UNPACK_LONG (xevent, 4);
-
- if (!is_reply)
- return motif_drop_start (event, flags, timestamp, source_window, atom, x_root, y_root);
-
- break;
- case XmOPERATION_CHANGED:
- if (!is_reply)
- return motif_operation_changed (event, flags, timestamp);
- else
- return motif_drag_status (event, flags, timestamp);
-
- break;
- /* To the best of my knowledge, these next two messages are
- * not part of the protocol, though they are defined in
- * the header files.
- */
- case XmDROP_FINISH:
- case XmDRAG_DROP_FINISH:
- break;
- }
-
- return GDK_FILTER_REMOVE;
-}
-
-/*************************************************************
- ***************************** XDND **************************
- *************************************************************/
-
-/* Utility functions */
-
-static struct {
- gchar *name;
- GdkAtom atom;
- GdkDragAction action;
-} xdnd_actions_table[] = {
- { "XdndActionCopy", GDK_NONE, GDK_ACTION_COPY },
- { "XdndActionMove", GDK_NONE, GDK_ACTION_MOVE },
- { "XdndActionLink", GDK_NONE, GDK_ACTION_LINK },
- { "XdndActionAsk", GDK_NONE, GDK_ACTION_ASK },
- { "XdndActionPrivate", GDK_NONE, GDK_ACTION_COPY },
- };
-
-static const gint xdnd_n_actions = sizeof(xdnd_actions_table) / sizeof(xdnd_actions_table[0]);
-static gboolean xdnd_actions_initialized = FALSE;
-
-static void
-xdnd_initialize_actions (void)
-{
- gint i;
-
- xdnd_actions_initialized = TRUE;
- for (i=0; i < xdnd_n_actions; i++)
- xdnd_actions_table[i].atom = gdk_atom_intern (xdnd_actions_table[i].name, FALSE);
-}
-
-static GdkDragAction
-xdnd_action_from_atom (GdkAtom atom)
-{
- gint i;
-
- if (!xdnd_actions_initialized)
- xdnd_initialize_actions();
-
- for (i=0; i<xdnd_n_actions; i++)
- if (atom == xdnd_actions_table[i].atom)
- return xdnd_actions_table[i].action;
-
- return 0;