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"
33 #include <gdk/gdkpixmap.h>
37 * @cursor_type: cursor to create
39 * Creates a new cursor from the set of builtin cursors.
40 * Some useful ones are:
43 * <inlinegraphic format="png" fileref="right_ptr.png"></inlinegraphic> #GDK_RIGHT_PTR (right-facing arrow)
46 * <inlinegraphic format="png" fileref="crosshair.png"></inlinegraphic> #GDK_CROSSHAIR (crosshair)
49 * <inlinegraphic format="png" fileref="xterm.png"></inlinegraphic> #GDK_XTERM (I-beam)
52 * <inlinegraphic format="png" fileref="watch.png"></inlinegraphic> #GDK_WATCH (busy)
55 * <inlinegraphic format="png" fileref="fleur.png"></inlinegraphic> #GDK_FLEUR (for moving objects)
58 * <inlinegraphic format="png" fileref="hand1.png"></inlinegraphic> #GDK_HAND1 (a right-pointing hand)
61 * <inlinegraphic format="png" fileref="hand2.png"></inlinegraphic> #GDK_HAND2 (a left-pointing hand)
64 * <inlinegraphic format="png" fileref="left_side.png"></inlinegraphic> #GDK_LEFT_SIDE (resize left side)
67 * <inlinegraphic format="png" fileref="right_side.png"></inlinegraphic> #GDK_RIGHT_SIDE (resize right side)
70 * <inlinegraphic format="png" fileref="top_left_corner.png"></inlinegraphic> #GDK_TOP_LEFT_CORNER (resize northwest corner)
73 * <inlinegraphic format="png" fileref="top_right_corner.png"></inlinegraphic> #GDK_TOP_RIGHT_CORNER (resize northeast corner)
76 * <inlinegraphic format="png" fileref="bottom_left_corner.png"></inlinegraphic> #GDK_BOTTOM_LEFT_CORNER (resize southwest corner)
79 * <inlinegraphic format="png" fileref="bottom_right_corner.png"></inlinegraphic> #GDK_BOTTOM_RIGHT_CORNER (resize southeast corner)
82 * <inlinegraphic format="png" fileref="top_side.png"></inlinegraphic> #GDK_TOP_SIDE (resize top side)
85 * <inlinegraphic format="png" fileref="bottom_side.png"></inlinegraphic> #GDK_BOTTOM_SIDE (resize bottom side)
88 * <inlinegraphic format="png" fileref="sb_h_double_arrow.png"></inlinegraphic> #GDK_SB_H_DOUBLE_ARROW (move vertical splitter)
91 * <inlinegraphic format="png" fileref="sb_v_double_arrow.png"></inlinegraphic> #GDK_SB_V_DOUBLE_ARROW (move horizontal splitter)
95 * To make the cursor invisible, use gdk_cursor_new_from_pixmap() to create
96 * a cursor with no pixels in it.
98 * Return value: a new #GdkCursor
101 gdk_cursor_new (GdkCursorType cursor_type)
103 GdkCursorPrivate *private;
107 xcursor = XCreateFontCursor (gdk_display, cursor_type);
108 private = g_new (GdkCursorPrivate, 1);
109 private->xdisplay = gdk_display;
110 private->xcursor = xcursor;
111 cursor = (GdkCursor*) private;
112 cursor->type = cursor_type;
113 cursor->ref_count = 1;
119 gdk_cursor_new_from_pixmap (GdkPixmap *source,
126 GdkCursorPrivate *private;
128 Pixmap source_pixmap, mask_pixmap;
132 g_return_val_if_fail (GDK_IS_PIXMAP (source), NULL);
133 g_return_val_if_fail (GDK_IS_PIXMAP (mask), NULL);
134 g_return_val_if_fail (fg != NULL, NULL);
135 g_return_val_if_fail (bg != NULL, NULL);
137 source_pixmap = GDK_PIXMAP_XID (source);
138 mask_pixmap = GDK_PIXMAP_XID (mask);
140 xfg.pixel = fg->pixel;
143 xfg.green = fg->green;
144 xbg.pixel = bg->pixel;
147 xbg.green = bg->green;
149 xcursor = XCreatePixmapCursor (gdk_display, source_pixmap, mask_pixmap, &xfg, &xbg, x, y);
150 private = g_new (GdkCursorPrivate, 1);
151 private->xdisplay = gdk_display;
152 private->xcursor = xcursor;
153 cursor = (GdkCursor *) private;
154 cursor->type = GDK_CURSOR_IS_PIXMAP;
155 cursor->ref_count = 1;
161 _gdk_cursor_destroy (GdkCursor *cursor)
163 GdkCursorPrivate *private;
165 g_return_if_fail (cursor != NULL);
166 g_return_if_fail (cursor->ref_count == 0);
168 private = (GdkCursorPrivate *) cursor;
169 XFreeCursor (private->xdisplay, private->xcursor);
175 gdk_x11_cursor_get_xdisplay (GdkCursor *cursor)
177 g_return_val_if_fail (cursor != NULL, NULL);
179 return ((GdkCursorPrivate *)cursor)->xdisplay;
183 gdk_x11_cursor_get_xcursor (GdkCursor *cursor)
185 g_return_val_if_fail (cursor != NULL, None);
187 return ((GdkCursorPrivate *)cursor)->xcursor;