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/.
30 #include "gdkinternals.h"
31 #include "gdkdisplay.h"
32 #include "gdkwindow.h"
37 * @title: Drag And Drop
38 * @short_description: Functions for controlling drag and drop handling
40 * These functions provide a low level interface for drag and drop.
41 * The X backend of GDK supports both the Xdnd and Motif drag and drop
42 * protocols transparently, the Win32 backend supports the WM_DROPFILES
45 * GTK+ provides a higher level abstraction based on top of these functions,
46 * and so they are not normally needed in GTK+ applications.
47 * See the <link linkend="gtk-Drag-and-Drop">Drag and Drop</link> section of
48 * the GTK+ documentation for more information.
52 * gdk_drag_context_list_targets:
53 * @context: a #GdkDragContext
55 * Retrieves the list of targets of the context.
57 * Return value: (transfer none) (element-type GdkAtom): a #GList of targets
62 gdk_drag_context_list_targets (GdkDragContext *context)
64 g_return_val_if_fail (GDK_IS_DRAG_CONTEXT (context), NULL);
66 return context->targets;
70 * gdk_drag_context_get_actions:
71 * @context: a #GdkDragContext
73 * Determines the bitmask of actions proposed by the source if
74 * gdk_drag_context_suggested_action() returns GDK_ACTION_ASK.
76 * Return value: the #GdkDragAction flags
81 gdk_drag_context_get_actions (GdkDragContext *context)
83 g_return_val_if_fail (GDK_IS_DRAG_CONTEXT (context), GDK_ACTION_DEFAULT);
85 return context->actions;
89 * gdk_drag_context_get_suggested_action:
90 * @context: a #GdkDragContext
92 * Determines the suggested drag action of the context.
94 * Return value: a #GdkDragAction value
99 gdk_drag_context_get_suggested_action (GdkDragContext *context)
101 g_return_val_if_fail (GDK_IS_DRAG_CONTEXT (context), 0);
103 return context->suggested_action;
107 * gdk_drag_context_get_selected_action:
108 * @context: a #GdkDragContext
110 * Determines the action chosen by the drag destination.
112 * Return value: a #GdkDragAction value
117 gdk_drag_context_get_selected_action (GdkDragContext *context)
119 g_return_val_if_fail (GDK_IS_DRAG_CONTEXT (context), 0);
121 return context->action;
125 * gdk_drag_context_get_source_window:
126 * @context: a #GdkDragContext
128 * Returns the #GdkWindow where the DND operation started.
130 * Return value: (transfer none): a #GdkWindow
135 gdk_drag_context_get_source_window (GdkDragContext *context)
137 g_return_val_if_fail (GDK_IS_DRAG_CONTEXT (context), NULL);
139 return context->source_window;
143 * gdk_drag_context_get_dest_window:
144 * @context: a #GdkDragContext
146 * Returns the destination windw for the DND operation.
148 * Return value: (transfer none): a #GdkWindow
153 gdk_drag_context_get_dest_window (GdkDragContext *context)
155 g_return_val_if_fail (GDK_IS_DRAG_CONTEXT (context), NULL);
157 return context->dest_window;
161 * gdk_drag_context_get_protocol:
162 * @context: a #GdkDragContext
164 * Returns the drag protocol thats used by this context.
166 * Returns: the drag protocol
171 gdk_drag_context_get_protocol (GdkDragContext *context)
173 g_return_val_if_fail (GDK_IS_DRAG_CONTEXT (context), GDK_DRAG_PROTO_NONE);
175 return context->protocol;
179 * gdk_drag_context_set_device:
180 * @context: a #GdkDragContext
181 * @device: a #GdkDevice
183 * Associates a #GdkDevice to @context, so all Drag and Drop events
184 * for @context are emitted as if they came from this device.
187 gdk_drag_context_set_device (GdkDragContext *context,
190 g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
191 g_return_if_fail (GDK_IS_DEVICE (device));
194 g_object_unref (context->device);
196 context->device = device;
199 g_object_ref (context->device);
203 * gdk_drag_context_get_device:
204 * @context: a #GdkDragContext
206 * Returns the #GdkDevice associated to the drag context.
208 * Returns: (transfer none): The #GdkDevice associated to @context.
211 gdk_drag_context_get_device (GdkDragContext *context)
213 g_return_val_if_fail (GDK_IS_DRAG_CONTEXT (context), NULL);
215 return context->device;
218 G_DEFINE_TYPE (GdkDragContext, gdk_drag_context, G_TYPE_OBJECT)
221 gdk_drag_context_init (GdkDragContext *context)
226 gdk_drag_context_finalize (GObject *object)
228 GdkDragContext *context = GDK_DRAG_CONTEXT (object);
230 g_list_free (context->targets);
232 if (context->source_window)
233 g_object_unref (context->source_window);
235 if (context->dest_window)
236 g_object_unref (context->dest_window);
238 G_OBJECT_CLASS (gdk_drag_context_parent_class)->finalize (object);
242 gdk_drag_context_class_init (GdkDragContextClass *klass)
244 GObjectClass *object_class = G_OBJECT_CLASS (klass);
246 object_class->finalize = gdk_drag_context_finalize;
250 * gdk_drag_find_window_for_screen:
251 * @context: a #GdkDragContext
252 * @drag_window: a window which may be at the pointer position, but
253 * should be ignored, since it is put up by the drag source as an icon
254 * @screen: the screen where the destination window is sought
255 * @x_root: the x position of the pointer in root coordinates
256 * @y_root: the y position of the pointer in root coordinates
257 * @dest_window: (out): location to store the destination window in
258 * @protocol: (out): location to store the DND protocol in
260 * Finds the destination window and DND protocol to use at the
261 * given pointer position.
263 * This function is called by the drag source to obtain the
264 * @dest_window and @protocol parameters for gdk_drag_motion().
269 gdk_drag_find_window_for_screen (GdkDragContext *context,
270 GdkWindow *drag_window,
274 GdkWindow **dest_window,
275 GdkDragProtocol *protocol)
277 g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
279 *dest_window = GDK_DRAG_CONTEXT_GET_CLASS (context)
280 ->find_window (context, drag_window, screen, x_root, y_root, protocol);
285 * @context: a #GdkDragContext
286 * @action: the selected action which will be taken when a drop happens,
287 * or 0 to indicate that a drop will not be accepted
288 * @time_: the timestamp for this operation
290 * Selects one of the actions offered by the drag source.
292 * This function is called by the drag destination in response to
293 * gdk_drag_motion() called by the drag source.
296 gdk_drag_status (GdkDragContext *context,
297 GdkDragAction action,
300 g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
302 GDK_DRAG_CONTEXT_GET_CLASS (context)->drag_status (context, action, time_);
307 * @context: a #GdkDragContext
308 * @dest_window: the new destination window, obtained by
309 * gdk_drag_find_window()
310 * @protocol: the DND protocol in use, obtained by gdk_drag_find_window()
311 * @x_root: the x position of the pointer in root coordinates
312 * @y_root: the y position of the pointer in root coordinates
313 * @suggested_action: the suggested action
314 * @possible_actions: the possible actions
315 * @time_: the timestamp for this operation
317 * Updates the drag context when the pointer moves or the
318 * set of actions changes.
320 * This function is called by the drag source.
323 gdk_drag_motion (GdkDragContext *context,
324 GdkWindow *dest_window,
325 GdkDragProtocol protocol,
328 GdkDragAction suggested_action,
329 GdkDragAction possible_actions,
332 g_return_val_if_fail (GDK_IS_DRAG_CONTEXT (context), FALSE);
334 return GDK_DRAG_CONTEXT_GET_CLASS (context)
335 ->drag_motion (context,
347 * @context: a #GdkDragContext
348 * @time_: the timestamp for this operation
350 * Aborts a drag without dropping.
352 * This function is called by the drag source.
355 gdk_drag_abort (GdkDragContext *context,
358 g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
360 GDK_DRAG_CONTEXT_GET_CLASS (context)->drag_abort (context, time_);
365 * @context: a #GdkDragContext
366 * @time_: the timestamp for this operation
368 * Drops on the current destination.
370 * This function is called by the drag source.
373 gdk_drag_drop (GdkDragContext *context,
376 g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
378 GDK_DRAG_CONTEXT_GET_CLASS (context)->drag_drop (context, time_);
383 * @context: a #GdkDragContext
384 * @accepted: %TRUE if the drop is accepted
385 * @time_: the timestamp for this operation
387 * Accepts or rejects a drop.
389 * This function is called by the drag destination in response
390 * to a drop initiated by the drag source.
393 gdk_drop_reply (GdkDragContext *context,
397 g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
399 GDK_DRAG_CONTEXT_GET_CLASS (context)->drop_reply (context, accepted, time_);
404 * @context: a #GtkDragContext
405 * @success: %TRUE if the data was successfully received
406 * @time_: the timestamp for this operation
408 * Ends the drag operation after a drop.
410 * This function is called by the drag destination.
413 gdk_drop_finish (GdkDragContext *context,
417 g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
419 GDK_DRAG_CONTEXT_GET_CLASS (context)->drop_finish (context, success, time_);
423 * gdk_drag_drop_succeeded:
424 * @context: a #GdkDragContext
426 * Returns whether the dropped data has been successfully
427 * transferred. This function is intended to be used while
428 * handling a %GDK_DROP_FINISHED event, its return value is
429 * meaningless at other times.
431 * Return value: %TRUE if the drop was successful.
436 gdk_drag_drop_succeeded (GdkDragContext *context)
438 g_return_val_if_fail (GDK_IS_DRAG_CONTEXT (context), FALSE);
440 return GDK_DRAG_CONTEXT_GET_CLASS (context)->drop_status (context);
444 * gdk_drag_get_selection:
445 * @context: a #GdkDragContext.
447 * Returns the selection atom for the current source window.
449 * Return value: the selection atom, or %GDK_NONE
452 gdk_drag_get_selection (GdkDragContext *context)
454 g_return_val_if_fail (GDK_IS_DRAG_CONTEXT (context), GDK_NONE);
456 return GDK_DRAG_CONTEXT_GET_CLASS (context)->get_selection (context);