1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 1995-1999 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
29 #include "gdkdndprivate.h"
30 #include "gdkdisplay.h"
31 #include "gdkwindow.h"
36 * @title: Drag And Drop
37 * @short_description: Functions for controlling drag and drop handling
39 * These functions provide a low level interface for drag and drop.
40 * The X backend of GDK supports both the Xdnd and Motif drag and drop
41 * protocols transparently, the Win32 backend supports the WM_DROPFILES
44 * GTK+ provides a higher level abstraction based on top of these functions,
45 * and so they are not normally needed in GTK+ applications.
46 * See the <link linkend="gtk-Drag-and-Drop">Drag and Drop</link> section of
47 * the GTK+ documentation for more information.
51 * gdk_drag_context_list_targets:
52 * @context: a #GdkDragContext
54 * Retrieves the list of targets of the context.
56 * Return value: (transfer none) (element-type GdkAtom): a #GList of targets
61 gdk_drag_context_list_targets (GdkDragContext *context)
63 g_return_val_if_fail (GDK_IS_DRAG_CONTEXT (context), NULL);
65 return context->targets;
69 * gdk_drag_context_get_actions:
70 * @context: a #GdkDragContext
72 * Determines the bitmask of actions proposed by the source if
73 * gdk_drag_context_suggested_action() returns GDK_ACTION_ASK.
75 * Return value: the #GdkDragAction flags
80 gdk_drag_context_get_actions (GdkDragContext *context)
82 g_return_val_if_fail (GDK_IS_DRAG_CONTEXT (context), GDK_ACTION_DEFAULT);
84 return context->actions;
88 * gdk_drag_context_get_suggested_action:
89 * @context: a #GdkDragContext
91 * Determines the suggested drag action of the context.
93 * Return value: a #GdkDragAction value
98 gdk_drag_context_get_suggested_action (GdkDragContext *context)
100 g_return_val_if_fail (GDK_IS_DRAG_CONTEXT (context), 0);
102 return context->suggested_action;
106 * gdk_drag_context_get_selected_action:
107 * @context: a #GdkDragContext
109 * Determines the action chosen by the drag destination.
111 * Return value: a #GdkDragAction value
116 gdk_drag_context_get_selected_action (GdkDragContext *context)
118 g_return_val_if_fail (GDK_IS_DRAG_CONTEXT (context), 0);
120 return context->action;
124 * gdk_drag_context_get_source_window:
125 * @context: a #GdkDragContext
127 * Returns the #GdkWindow where the DND operation started.
129 * Return value: (transfer none): a #GdkWindow
134 gdk_drag_context_get_source_window (GdkDragContext *context)
136 g_return_val_if_fail (GDK_IS_DRAG_CONTEXT (context), NULL);
138 return context->source_window;
142 * gdk_drag_context_get_dest_window:
143 * @context: a #GdkDragContext
145 * Returns the destination windw for the DND operation.
147 * Return value: (transfer none): a #GdkWindow
152 gdk_drag_context_get_dest_window (GdkDragContext *context)
154 g_return_val_if_fail (GDK_IS_DRAG_CONTEXT (context), NULL);
156 return context->dest_window;
160 * gdk_drag_context_get_protocol:
161 * @context: a #GdkDragContext
163 * Returns the drag protocol thats used by this context.
165 * Returns: the drag protocol
170 gdk_drag_context_get_protocol (GdkDragContext *context)
172 g_return_val_if_fail (GDK_IS_DRAG_CONTEXT (context), GDK_DRAG_PROTO_NONE);
174 return context->protocol;
178 * gdk_drag_context_set_device:
179 * @context: a #GdkDragContext
180 * @device: a #GdkDevice
182 * Associates a #GdkDevice to @context, so all Drag and Drop events
183 * for @context are emitted as if they came from this device.
186 gdk_drag_context_set_device (GdkDragContext *context,
189 g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
190 g_return_if_fail (GDK_IS_DEVICE (device));
193 g_object_unref (context->device);
195 context->device = device;
198 g_object_ref (context->device);
202 * gdk_drag_context_get_device:
203 * @context: a #GdkDragContext
205 * Returns the #GdkDevice associated to the drag context.
207 * Returns: (transfer none): The #GdkDevice associated to @context.
210 gdk_drag_context_get_device (GdkDragContext *context)
212 g_return_val_if_fail (GDK_IS_DRAG_CONTEXT (context), NULL);
214 return context->device;
217 G_DEFINE_TYPE (GdkDragContext, gdk_drag_context, G_TYPE_OBJECT)
220 gdk_drag_context_init (GdkDragContext *context)
225 gdk_drag_context_finalize (GObject *object)
227 GdkDragContext *context = GDK_DRAG_CONTEXT (object);
229 g_list_free (context->targets);
231 if (context->source_window)
232 g_object_unref (context->source_window);
234 if (context->dest_window)
235 g_object_unref (context->dest_window);
237 G_OBJECT_CLASS (gdk_drag_context_parent_class)->finalize (object);
241 gdk_drag_context_class_init (GdkDragContextClass *klass)
243 GObjectClass *object_class = G_OBJECT_CLASS (klass);
245 object_class->finalize = gdk_drag_context_finalize;
249 * gdk_drag_find_window_for_screen:
250 * @context: a #GdkDragContext
251 * @drag_window: a window which may be at the pointer position, but
252 * should be ignored, since it is put up by the drag source as an icon
253 * @screen: the screen where the destination window is sought
254 * @x_root: the x position of the pointer in root coordinates
255 * @y_root: the y position of the pointer in root coordinates
256 * @dest_window: (out): location to store the destination window in
257 * @protocol: (out): location to store the DND protocol in
259 * Finds the destination window and DND protocol to use at the
260 * given pointer position.
262 * This function is called by the drag source to obtain the
263 * @dest_window and @protocol parameters for gdk_drag_motion().
268 gdk_drag_find_window_for_screen (GdkDragContext *context,
269 GdkWindow *drag_window,
273 GdkWindow **dest_window,
274 GdkDragProtocol *protocol)
276 g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
278 *dest_window = GDK_DRAG_CONTEXT_GET_CLASS (context)
279 ->find_window (context, drag_window, screen, x_root, y_root, protocol);
284 * @context: a #GdkDragContext
285 * @action: the selected action which will be taken when a drop happens,
286 * or 0 to indicate that a drop will not be accepted
287 * @time_: the timestamp for this operation
289 * Selects one of the actions offered by the drag source.
291 * This function is called by the drag destination in response to
292 * gdk_drag_motion() called by the drag source.
295 gdk_drag_status (GdkDragContext *context,
296 GdkDragAction action,
299 g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
301 GDK_DRAG_CONTEXT_GET_CLASS (context)->drag_status (context, action, time_);
306 * @context: a #GdkDragContext
307 * @dest_window: the new destination window, obtained by
308 * gdk_drag_find_window()
309 * @protocol: the DND protocol in use, obtained by gdk_drag_find_window()
310 * @x_root: the x position of the pointer in root coordinates
311 * @y_root: the y position of the pointer in root coordinates
312 * @suggested_action: the suggested action
313 * @possible_actions: the possible actions
314 * @time_: the timestamp for this operation
316 * Updates the drag context when the pointer moves or the
317 * set of actions changes.
319 * This function is called by the drag source.
322 gdk_drag_motion (GdkDragContext *context,
323 GdkWindow *dest_window,
324 GdkDragProtocol protocol,
327 GdkDragAction suggested_action,
328 GdkDragAction possible_actions,
331 g_return_val_if_fail (GDK_IS_DRAG_CONTEXT (context), FALSE);
333 return GDK_DRAG_CONTEXT_GET_CLASS (context)
334 ->drag_motion (context,
346 * @context: a #GdkDragContext
347 * @time_: the timestamp for this operation
349 * Aborts a drag without dropping.
351 * This function is called by the drag source.
354 gdk_drag_abort (GdkDragContext *context,
357 g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
359 GDK_DRAG_CONTEXT_GET_CLASS (context)->drag_abort (context, time_);
364 * @context: a #GdkDragContext
365 * @time_: the timestamp for this operation
367 * Drops on the current destination.
369 * This function is called by the drag source.
372 gdk_drag_drop (GdkDragContext *context,
375 g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
377 GDK_DRAG_CONTEXT_GET_CLASS (context)->drag_drop (context, time_);
382 * @context: a #GdkDragContext
383 * @accepted: %TRUE if the drop is accepted
384 * @time_: the timestamp for this operation
386 * Accepts or rejects a drop.
388 * This function is called by the drag destination in response
389 * to a drop initiated by the drag source.
392 gdk_drop_reply (GdkDragContext *context,
396 g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
398 GDK_DRAG_CONTEXT_GET_CLASS (context)->drop_reply (context, accepted, time_);
403 * @context: a #GtkDragContext
404 * @success: %TRUE if the data was successfully received
405 * @time_: the timestamp for this operation
407 * Ends the drag operation after a drop.
409 * This function is called by the drag destination.
412 gdk_drop_finish (GdkDragContext *context,
416 g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
418 GDK_DRAG_CONTEXT_GET_CLASS (context)->drop_finish (context, success, time_);
422 * gdk_drag_drop_succeeded:
423 * @context: a #GdkDragContext
425 * Returns whether the dropped data has been successfully
426 * transferred. This function is intended to be used while
427 * handling a %GDK_DROP_FINISHED event, its return value is
428 * meaningless at other times.
430 * Return value: %TRUE if the drop was successful.
435 gdk_drag_drop_succeeded (GdkDragContext *context)
437 g_return_val_if_fail (GDK_IS_DRAG_CONTEXT (context), FALSE);
439 return GDK_DRAG_CONTEXT_GET_CLASS (context)->drop_status (context);
443 * gdk_drag_get_selection:
444 * @context: a #GdkDragContext.
446 * Returns the selection atom for the current source window.
448 * Return value: the selection atom, or %GDK_NONE
451 gdk_drag_get_selection (GdkDragContext *context)
453 g_return_val_if_fail (GDK_IS_DRAG_CONTEXT (context), GDK_NONE);
454 g_return_val_if_fail (context->source_window != NULL, GDK_NONE);
456 return GDK_DRAG_CONTEXT_GET_CLASS (context)->get_selection (context);