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 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/.
28 #include <X11/cursorfont.h>
30 #include "gdkprivate-x11.h"
31 #include "gdkcursor.h"
32 #include "gdkpixmap-x11.h"
34 #include <gdk/gdkpixmap.h>
37 * gdk_cursor_new_for_display:
38 * @display: the #GdkDisplay for which the cursor will be created
39 * @cursor_type: cursor to create
41 * Creates a new cursor from the set of builtin cursors.
42 * Some useful ones are:
45 * <inlinegraphic format="PNG" fileref="right_ptr.png"></inlinegraphic> #GDK_RIGHT_PTR (right-facing arrow)
48 * <inlinegraphic format="PNG" fileref="crosshair.png"></inlinegraphic> #GDK_CROSSHAIR (crosshair)
51 * <inlinegraphic format="PNG" fileref="xterm.png"></inlinegraphic> #GDK_XTERM (I-beam)
54 * <inlinegraphic format="PNG" fileref="watch.png"></inlinegraphic> #GDK_WATCH (busy)
57 * <inlinegraphic format="PNG" fileref="fleur.png"></inlinegraphic> #GDK_FLEUR (for moving objects)
60 * <inlinegraphic format="PNG" fileref="hand1.png"></inlinegraphic> #GDK_HAND1 (a right-pointing hand)
63 * <inlinegraphic format="PNG" fileref="hand2.png"></inlinegraphic> #GDK_HAND2 (a left-pointing hand)
66 * <inlinegraphic format="PNG" fileref="left_side.png"></inlinegraphic> #GDK_LEFT_SIDE (resize left side)
69 * <inlinegraphic format="PNG" fileref="right_side.png"></inlinegraphic> #GDK_RIGHT_SIDE (resize right side)
72 * <inlinegraphic format="PNG" fileref="top_left_corner.png"></inlinegraphic> #GDK_TOP_LEFT_CORNER (resize northwest corner)
75 * <inlinegraphic format="PNG" fileref="top_right_corner.png"></inlinegraphic> #GDK_TOP_RIGHT_CORNER (resize northeast corner)
78 * <inlinegraphic format="PNG" fileref="bottom_left_corner.png"></inlinegraphic> #GDK_BOTTOM_LEFT_CORNER (resize southwest corner)
81 * <inlinegraphic format="PNG" fileref="bottom_right_corner.png"></inlinegraphic> #GDK_BOTTOM_RIGHT_CORNER (resize southeast corner)
84 * <inlinegraphic format="PNG" fileref="top_side.png"></inlinegraphic> #GDK_TOP_SIDE (resize top side)
87 * <inlinegraphic format="PNG" fileref="bottom_side.png"></inlinegraphic> #GDK_BOTTOM_SIDE (resize bottom side)
90 * <inlinegraphic format="PNG" fileref="sb_h_double_arrow.png"></inlinegraphic> #GDK_SB_H_DOUBLE_ARROW (move vertical splitter)
93 * <inlinegraphic format="PNG" fileref="sb_v_double_arrow.png"></inlinegraphic> #GDK_SB_V_DOUBLE_ARROW (move horizontal splitter)
97 * To make the cursor invisible, use gdk_cursor_new_from_pixmap() to create
98 * a cursor with no pixels in it.
100 * Return value: a new #GdkCursor
103 gdk_cursor_new_for_display (GdkDisplay *display,
104 GdkCursorType cursor_type)
106 GdkCursorPrivate *private;
110 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
115 xcursor = XCreateFontCursor (GDK_DISPLAY_XDISPLAY (display), cursor_type);
117 private = g_new (GdkCursorPrivate, 1);
118 private->display = display;
119 private->xcursor = xcursor;
120 cursor = (GdkCursor *) private;
121 cursor->type = cursor_type;
122 cursor->ref_count = 1;
128 gdk_cursor_new_from_pixmap (GdkPixmap *source,
135 GdkCursorPrivate *private;
137 Pixmap source_pixmap, mask_pixmap;
142 g_return_val_if_fail (GDK_IS_PIXMAP (source), NULL);
143 g_return_val_if_fail (GDK_IS_PIXMAP (mask), NULL);
144 g_return_val_if_fail (fg != NULL, NULL);
145 g_return_val_if_fail (bg != NULL, NULL);
147 source_pixmap = GDK_PIXMAP_XID (source);
148 mask_pixmap = GDK_PIXMAP_XID (mask);
149 display = GDK_PIXMAP_DISPLAY (source);
151 xfg.pixel = fg->pixel;
154 xfg.green = fg->green;
155 xbg.pixel = bg->pixel;
158 xbg.green = bg->green;
163 xcursor = XCreatePixmapCursor (GDK_DISPLAY_XDISPLAY (display),
164 source_pixmap, mask_pixmap, &xfg, &xbg, x, y);
165 private = g_new (GdkCursorPrivate, 1);
166 private->display = display;
167 private->xcursor = xcursor;
168 cursor = (GdkCursor *) private;
169 cursor->type = GDK_CURSOR_IS_PIXMAP;
170 cursor->ref_count = 1;
176 _gdk_cursor_destroy (GdkCursor *cursor)
178 GdkCursorPrivate *private;
180 g_return_if_fail (cursor != NULL);
181 g_return_if_fail (cursor->ref_count == 0);
183 private = (GdkCursorPrivate *) cursor;
184 if (!private->display->closed && private->xcursor)
185 XFreeCursor (GDK_DISPLAY_XDISPLAY (private->display), private->xcursor);
191 gdk_x11_cursor_get_xdisplay (GdkCursor *cursor)
193 g_return_val_if_fail (cursor != NULL, NULL);
195 return GDK_DISPLAY_XDISPLAY(((GdkCursorPrivate *)cursor)->display);
199 gdk_x11_cursor_get_xcursor (GdkCursor *cursor)
201 g_return_val_if_fail (cursor != NULL, None);
203 return ((GdkCursorPrivate *)cursor)->xcursor;
207 * gdk_cursor_get_display:
208 * @cursor : a #GdkCursor.
210 * Returns the display on which the GdkCursor is defined
212 * Returns : the #GdkDisplay associated to @cursor
216 gdk_cursor_get_display (GdkCursor *cursor)
218 g_return_val_if_fail (cursor != NULL, NULL);
220 return ((GdkCursorPrivate *)cursor)->display;