1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 1995-1997 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 Library 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 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library 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.
20 #include <X11/Xatom.h>
25 /* Nothing much here now, but we have to make a start some time ;-) */
28 gdk_dnd_set_drag_cursors(GdkCursor *default_cursor, GdkCursor *goahead_cursor)
30 gdk_dnd.c->gdk_cursor_dragdefault =
31 ((GdkCursorPrivate *)default_cursor)->xcursor;
32 gdk_dnd.c->gdk_cursor_dragok = ((GdkCursorPrivate *)goahead_cursor)->xcursor;
34 if(gdk_dnd.dnd_grabbed)
36 if(gdk_dnd.c->drag_pm_default)
37 /* We were displaying pixmaps for the drag */
39 gdk_window_hide(gdk_dnd.c->drag_pm_default);
40 gdk_window_unref(gdk_dnd.c->drag_pm_default);
41 if(gdk_dnd.c->drag_pm_ok)
43 gdk_window_hide(gdk_dnd.c->drag_pm_ok);
44 gdk_window_unref(gdk_dnd.c->drag_pm_ok);
46 gdk_dnd.c->drag_pm_default = gdk_dnd.c->drag_pm_ok = NULL;
47 g_list_free(gdk_dnd.c->xids);
48 gdk_dnd.c->xids = NULL;
50 gdk_dnd_display_drag_cursor(-1, -1,
51 gdk_dnd.dnd_drag_target?TRUE:FALSE,
57 gdk_dnd_set_drag_shape(GdkWindow *default_pixmapwin,
58 GdkPoint *default_hotspot,
59 GdkWindow *goahead_pixmapwin,
60 GdkPoint *goahead_hotspot)
62 g_return_if_fail(default_pixmapwin != NULL);
64 g_list_free(gdk_dnd.c->xids); gdk_dnd.c->xids = NULL;
65 if(gdk_dnd.c->drag_pm_default)
67 gdk_window_hide(gdk_dnd.c->drag_pm_default);
68 gdk_window_unref(gdk_dnd.c->drag_pm_default);
70 if(gdk_dnd.c->drag_pm_ok)
72 gdk_window_hide(gdk_dnd.c->drag_pm_ok);
73 gdk_window_unref(gdk_dnd.c->drag_pm_ok);
76 gdk_dnd.c->drag_pm_ok = NULL;
78 gdk_window_ref(default_pixmapwin);
79 gdk_dnd.c->drag_pm_default = default_pixmapwin;
80 gdk_dnd.c->default_hotspot = *default_hotspot;
81 gdk_dnd.c->xids = g_list_append(gdk_dnd.c->xids, GUINT_TO_POINTER (((GdkWindowPrivate *)default_pixmapwin)->xwindow));
84 gdk_window_ref(goahead_pixmapwin);
85 gdk_dnd.c->xids = g_list_append(gdk_dnd.c->xids, GUINT_TO_POINTER (((GdkWindowPrivate *)goahead_pixmapwin)->xwindow));
86 gdk_dnd.c->drag_pm_ok = goahead_pixmapwin;
87 gdk_dnd.c->ok_hotspot = *goahead_hotspot;
90 if(gdk_dnd.dnd_grabbed)
92 gdk_dnd_display_drag_cursor(-1, -1,
93 gdk_dnd.dnd_drag_target?TRUE:FALSE,
95 XChangeActivePointerGrab (gdk_display,
99 EnterWindowMask | LeaveWindowMask,
106 gdk_dnd_display_drag_cursor(gint x, gint y, gboolean drag_ok,
107 gboolean change_made)
109 if(!gdk_dnd.dnd_grabbed)
112 if(gdk_dnd.c->drag_pm_default)
114 /* We're doing pixmaps here... */
115 GdkWindow *mypix, *opix;
121 if(x == -2 && y == -2) /* Hide the cursors */
123 gdk_window_hide(gdk_dnd.c->drag_pm_ok);
124 gdk_window_hide(gdk_dnd.c->drag_pm_default);
125 GDK_NOTE(DND, g_message("Hiding both drag cursors\n"));
129 if(x == -1 && y == -1) /* We're supposed to find it out for ourselves */
130 XQueryPointer(gdk_display, gdk_root_window,
131 &wtmp, &wtmp, &x, &y, &itmp, &itmp, &masktmp);
135 GDK_NOTE(DND, g_message("Switching to drag_ok cursor\n"));
136 mypix = gdk_dnd.c->drag_pm_ok;
137 opix = gdk_dnd.c->drag_pm_default;
138 myhotspot = &gdk_dnd.c->ok_hotspot;
142 GDK_NOTE(DND, g_message("Switching to drag_default cursor\n"));
143 mypix = gdk_dnd.c->drag_pm_default;
144 opix = gdk_dnd.c->drag_pm_ok;
145 myhotspot = &gdk_dnd.c->default_hotspot;
147 gdk_window_move(mypix, x - myhotspot->x, y - myhotspot->y);
150 GDK_NOTE(DND, g_message("Cursors switched, hide & show\n"));
151 gdk_window_hide(opix);
153 gdk_window_move(mypix, x - myhotspot->x, y - myhotspot->y);
156 gdk_window_show(mypix); /* There ought to be a way to know if
157 a window is already mapped etc. */
163 /* Move cursors around */
165 c = gdk_dnd.c->gdk_cursor_dragok;
167 c = gdk_dnd.c->gdk_cursor_dragdefault;
168 XChangeActivePointerGrab (gdk_display,
172 EnterWindowMask | LeaveWindowMask,