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>
35 #include "gdkscreen-x11.h"
38 * gdk_cursor_new_for_screen:
39 * @screen: the #GdkScreen where the cursor will be defined
40 * @cursor_type: cursor to create
42 * Creates a new cursor from the set of builtin cursors.
43 * Some useful ones are:
46 * <inlinegraphic format="png" fileref="right_ptr.png"></inlinegraphic> #GDK_RIGHT_PTR (right-facing arrow)
49 * <inlinegraphic format="png" fileref="crosshair.png"></inlinegraphic> #GDK_CROSSHAIR (crosshair)
52 * <inlinegraphic format="png" fileref="xterm.png"></inlinegraphic> #GDK_XTERM (I-beam)
55 * <inlinegraphic format="png" fileref="watch.png"></inlinegraphic> #GDK_WATCH (busy)
58 * <inlinegraphic format="png" fileref="fleur.png"></inlinegraphic> #GDK_FLEUR (for moving objects)
61 * <inlinegraphic format="png" fileref="hand1.png"></inlinegraphic> #GDK_HAND1 (a right-pointing hand)
64 * <inlinegraphic format="png" fileref="hand2.png"></inlinegraphic> #GDK_HAND2 (a left-pointing hand)
67 * <inlinegraphic format="png" fileref="left_side.png"></inlinegraphic> #GDK_LEFT_SIDE (resize left side)
70 * <inlinegraphic format="png" fileref="right_side.png"></inlinegraphic> #GDK_RIGHT_SIDE (resize right side)
73 * <inlinegraphic format="png" fileref="top_left_corner.png"></inlinegraphic> #GDK_TOP_LEFT_CORNER (resize northwest corner)
76 * <inlinegraphic format="png" fileref="top_right_corner.png"></inlinegraphic> #GDK_TOP_RIGHT_CORNER (resize northeast corner)
79 * <inlinegraphic format="png" fileref="bottom_left_corner.png"></inlinegraphic> #GDK_BOTTOM_LEFT_CORNER (resize southwest corner)
82 * <inlinegraphic format="png" fileref="bottom_right_corner.png"></inlinegraphic> #GDK_BOTTOM_RIGHT_CORNER (resize southeast corner)
85 * <inlinegraphic format="png" fileref="top_side.png"></inlinegraphic> #GDK_TOP_SIDE (resize top side)
88 * <inlinegraphic format="png" fileref="bottom_side.png"></inlinegraphic> #GDK_BOTTOM_SIDE (resize bottom side)
91 * <inlinegraphic format="png" fileref="sb_h_double_arrow.png"></inlinegraphic> #GDK_SB_H_DOUBLE_ARROW (move vertical splitter)
94 * <inlinegraphic format="png" fileref="sb_v_double_arrow.png"></inlinegraphic> #GDK_SB_V_DOUBLE_ARROW (move horizontal splitter)
98 * To make the cursor invisible, use gdk_cursor_new_from_pixmap() to create
99 * a cursor with no pixels in it.
101 * Return value: a new #GdkCursor
104 gdk_cursor_new_for_screen (GdkScreen *screen,
105 GdkCursorType cursor_type)
107 GdkCursorPrivate *private;
111 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
113 xcursor = XCreateFontCursor (GDK_SCREEN_XDISPLAY (screen), cursor_type);
114 private = g_new (GdkCursorPrivate, 1);
115 private->screen = screen;
116 private->xcursor = xcursor;
117 cursor = (GdkCursor *) private;
118 cursor->type = cursor_type;
119 cursor->ref_count = 1;
126 * @cursor_type: cursor to create
128 * Creates a new cursor from the set of builtin cursors for the default screen.
129 * See gdk_cursor_new_for_screen().
131 * To make the cursor invisible, use gdk_cursor_new_from_pixmap() to create
132 * a cursor with no pixels in it.
134 * Return value: a new #GdkCursor
137 gdk_cursor_new (GdkCursorType cursor_type)
139 return gdk_cursor_new_for_screen (gdk_get_default_screen(), cursor_type);
143 gdk_cursor_new_from_pixmap (GdkPixmap *source,
150 GdkCursorPrivate *private;
152 Pixmap source_pixmap, mask_pixmap;
157 g_return_val_if_fail (GDK_IS_PIXMAP (source), NULL);
158 g_return_val_if_fail (GDK_IS_PIXMAP (mask), NULL);
159 g_return_val_if_fail (fg != NULL, NULL);
160 g_return_val_if_fail (bg != NULL, NULL);
162 source_pixmap = GDK_PIXMAP_XID (source);
163 mask_pixmap = GDK_PIXMAP_XID (mask);
164 screen = GDK_PIXMAP_SCREEN (source);
166 xfg.pixel = fg->pixel;
169 xfg.green = fg->green;
170 xbg.pixel = bg->pixel;
173 xbg.green = bg->green;
175 xcursor = XCreatePixmapCursor (GDK_SCREEN_XDISPLAY (screen),
176 source_pixmap, mask_pixmap, &xfg, &xbg, x, y);
177 private = g_new (GdkCursorPrivate, 1);
178 private->screen = screen;
179 private->xcursor = xcursor;
180 cursor = (GdkCursor *) private;
181 cursor->type = GDK_CURSOR_IS_PIXMAP;
182 cursor->ref_count = 1;
188 _gdk_cursor_destroy (GdkCursor *cursor)
190 GdkCursorPrivate *private;
192 g_return_if_fail (cursor != NULL);
193 g_return_if_fail (cursor->ref_count == 0);
195 private = (GdkCursorPrivate *) cursor;
196 XFreeCursor (GDK_SCREEN_XDISPLAY (private->screen), private->xcursor);
202 gdk_x11_cursor_get_xdisplay (GdkCursor *cursor)
204 g_return_val_if_fail (cursor != NULL, NULL);
206 return GDK_SCREEN_XDISPLAY(((GdkCursorPrivate *)cursor)->screen);
210 gdk_x11_cursor_get_xcursor (GdkCursor *cursor)
212 g_return_val_if_fail (cursor != NULL, None);
214 return ((GdkCursorPrivate *)cursor)->xcursor;
218 * gdk_cursor_get_screen:
219 * @cursor : a #GdkCursor.
221 * Returns the screen on which the GdkCursor is defined
223 * Returns : the #GdkScreen associated to @cursor
227 gdk_cursor_get_screen (GdkCursor *cursor)
229 g_return_val_if_fail (cursor != NULL, NULL);
231 return ((GdkCursorPrivate *)cursor)->screen;