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/.
29 #include "gdkcursor.h"
30 #include "gdkdisplayprivate.h"
31 #include "gdkinternals.h"
36 * @Short_description: Standard and pixmap cursors
39 * These functions are used to create and destroy cursors.
40 * There is a number of standard cursors, but it is also
41 * possible to construct new cursors from pixbufs. There
42 * may be limitations as to what kinds of cursors can be
43 * constructed on a given display, see
44 * gdk_display_supports_cursor_alpha(),
45 * gdk_display_supports_cursor_color(),
46 * gdk_display_get_default_cursor_size() and
47 * gdk_display_get_maximal_cursor_size().
49 * Cursors by themselves are not very interesting, they must be be
50 * bound to a window for users to see them. This is done with
51 * gdk_window_set_cursor() or by setting the cursor member of the
52 * #GdkWindowAttr struct passed to gdk_window_new().
56 G_DEFINE_BOXED_TYPE (GdkCursor, gdk_cursor,
62 * @cursor: a #GdkCursor
64 * Adds a reference to @cursor.
66 * Return value: Same @cursor that was passed in
69 gdk_cursor_ref (GdkCursor *cursor)
71 g_return_val_if_fail (cursor != NULL, NULL);
72 g_return_val_if_fail (cursor->ref_count > 0, NULL);
74 cursor->ref_count += 1;
81 * @cursor: a #GdkCursor
83 * Removes a reference from @cursor, deallocating the cursor
84 * if no references remain.
87 gdk_cursor_unref (GdkCursor *cursor)
89 g_return_if_fail (cursor != NULL);
90 g_return_if_fail (cursor->ref_count > 0);
92 cursor->ref_count -= 1;
94 if (cursor->ref_count == 0)
95 _gdk_cursor_destroy (cursor);
100 * @cursor_type: cursor to create
102 * Creates a new cursor from the set of builtin cursors for the default display.
103 * See gdk_cursor_new_for_display().
105 * To make the cursor invisible, use %GDK_BLANK_CURSOR.
107 * Return value: a new #GdkCursor
110 gdk_cursor_new (GdkCursorType cursor_type)
112 return gdk_cursor_new_for_display (gdk_display_get_default(), cursor_type);
116 * gdk_cursor_get_cursor_type:
117 * @cursor: a #GdkCursor
119 * Returns the cursor type for this cursor.
121 * Return value: a #GdkCursorType
126 gdk_cursor_get_cursor_type (GdkCursor *cursor)
128 g_return_val_if_fail (cursor != NULL, GDK_BLANK_CURSOR);
134 * gdk_cursor_new_for_display:
135 * @display: the #GdkDisplay for which the cursor will be created
136 * @cursor_type: cursor to create
138 * Creates a new cursor from the set of builtin cursors.
139 * Some useful ones are:
142 * <inlinegraphic format="PNG" fileref="right_ptr.png"></inlinegraphic> #GDK_RIGHT_PTR (right-facing arrow)
145 * <inlinegraphic format="PNG" fileref="crosshair.png"></inlinegraphic> #GDK_CROSSHAIR (crosshair)
148 * <inlinegraphic format="PNG" fileref="xterm.png"></inlinegraphic> #GDK_XTERM (I-beam)
151 * <inlinegraphic format="PNG" fileref="watch.png"></inlinegraphic> #GDK_WATCH (busy)
154 * <inlinegraphic format="PNG" fileref="fleur.png"></inlinegraphic> #GDK_FLEUR (for moving objects)
157 * <inlinegraphic format="PNG" fileref="hand1.png"></inlinegraphic> #GDK_HAND1 (a right-pointing hand)
160 * <inlinegraphic format="PNG" fileref="hand2.png"></inlinegraphic> #GDK_HAND2 (a left-pointing hand)
163 * <inlinegraphic format="PNG" fileref="left_side.png"></inlinegraphic> #GDK_LEFT_SIDE (resize left side)
166 * <inlinegraphic format="PNG" fileref="right_side.png"></inlinegraphic> #GDK_RIGHT_SIDE (resize right side)
169 * <inlinegraphic format="PNG" fileref="top_left_corner.png"></inlinegraphic> #GDK_TOP_LEFT_CORNER (resize northwest corner)
172 * <inlinegraphic format="PNG" fileref="top_right_corner.png"></inlinegraphic> #GDK_TOP_RIGHT_CORNER (resize northeast corner)
175 * <inlinegraphic format="PNG" fileref="bottom_left_corner.png"></inlinegraphic> #GDK_BOTTOM_LEFT_CORNER (resize southwest corner)
178 * <inlinegraphic format="PNG" fileref="bottom_right_corner.png"></inlinegraphic> #GDK_BOTTOM_RIGHT_CORNER (resize southeast corner)
181 * <inlinegraphic format="PNG" fileref="top_side.png"></inlinegraphic> #GDK_TOP_SIDE (resize top side)
184 * <inlinegraphic format="PNG" fileref="bottom_side.png"></inlinegraphic> #GDK_BOTTOM_SIDE (resize bottom side)
187 * <inlinegraphic format="PNG" fileref="sb_h_double_arrow.png"></inlinegraphic> #GDK_SB_H_DOUBLE_ARROW (move vertical splitter)
190 * <inlinegraphic format="PNG" fileref="sb_v_double_arrow.png"></inlinegraphic> #GDK_SB_V_DOUBLE_ARROW (move horizontal splitter)
193 * #GDK_BLANK_CURSOR (Blank cursor). Since 2.16
197 * Return value: a new #GdkCursor
202 gdk_cursor_new_for_display (GdkDisplay *display,
203 GdkCursorType cursor_type)
205 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
207 return GDK_DISPLAY_GET_CLASS (display)->get_cursor_for_type (display, cursor_type);
211 * gdk_cursor_new_from_name:
212 * @display: the #GdkDisplay for which the cursor will be created
213 * @name: the name of the cursor
215 * Creates a new cursor by looking up @name in the current cursor
218 * Returns: a new #GdkCursor, or %NULL if there is no cursor with
224 gdk_cursor_new_from_name (GdkDisplay *display,
227 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
229 return GDK_DISPLAY_GET_CLASS (display)->get_cursor_for_name (display, name);
233 * gdk_cursor_new_from_pixbuf:
234 * @display: the #GdkDisplay for which the cursor will be created
235 * @pixbuf: the #GdkPixbuf containing the cursor image
236 * @x: the horizontal offset of the 'hotspot' of the cursor.
237 * @y: the vertical offset of the 'hotspot' of the cursor.
239 * Creates a new cursor from a pixbuf.
241 * Not all GDK backends support RGBA cursors. If they are not
242 * supported, a monochrome approximation will be displayed.
243 * The functions gdk_display_supports_cursor_alpha() and
244 * gdk_display_supports_cursor_color() can be used to determine
245 * whether RGBA cursors are supported;
246 * gdk_display_get_default_cursor_size() and
247 * gdk_display_get_maximal_cursor_size() give information about
250 * If @x or @y are <literal>-1</literal>, the pixbuf must have
251 * options named "x_hot" and "y_hot", resp., containing
252 * integer values between %0 and the width resp. height of
253 * the pixbuf. (Since: 3.0)
255 * On the X backend, support for RGBA cursors requires a
256 * sufficently new version of the X Render extension.
258 * Returns: a new #GdkCursor.
263 gdk_cursor_new_from_pixbuf (GdkDisplay *display,
268 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
269 g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL);
271 return GDK_DISPLAY_GET_CLASS (display)->get_cursor_for_pixbuf (display, pixbuf, x, y);