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, see <http://www.gnu.org/licenses/>.
19 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
20 * file for a list of people on the GTK+ Team. See the ChangeLog
21 * files for a list of changes. These files are distributed with
22 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
27 #include "gdkcursor.h"
28 #include "gdkcursorprivate.h"
29 #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().
58 * The #GdkCursor structure represents a cursor. Its contents are private.
67 G_DEFINE_ABSTRACT_TYPE (GdkCursor, gdk_cursor, G_TYPE_OBJECT)
70 gdk_cursor_get_property (GObject *object,
75 GdkCursor *cursor = GDK_CURSOR (object);
79 case PROP_CURSOR_TYPE:
80 g_value_set_enum (value, cursor->type);
83 g_value_set_object (value, cursor->display);
86 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
92 gdk_cursor_set_property (GObject *object,
97 GdkCursor *cursor = GDK_CURSOR (object);
101 case PROP_CURSOR_TYPE:
102 cursor->type = g_value_get_enum (value);
105 cursor->display = g_value_get_object (value);
106 /* check that implementations actually provide the display when constructing */
107 g_assert (cursor->display != NULL);
110 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
116 gdk_cursor_class_init (GdkCursorClass *cursor_class)
118 GObjectClass *object_class = G_OBJECT_CLASS (cursor_class);
120 object_class->get_property = gdk_cursor_get_property;
121 object_class->set_property = gdk_cursor_set_property;
123 g_object_class_install_property (object_class,
125 g_param_spec_enum ("cursor-type",
127 P_("Standard cursor type"),
128 GDK_TYPE_CURSOR_TYPE, GDK_X_CURSOR,
129 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
131 g_object_class_install_property (object_class,
133 g_param_spec_object ("display",
135 P_("Display of this cursor"),
137 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
141 gdk_cursor_init (GdkCursor *cursor)
147 * @cursor: a #GdkCursor
149 * Adds a reference to @cursor.
151 * Return value: (transfer full): Same @cursor that was passed in
153 * Deprecated: 3.0: Use g_object_ref() instead
156 gdk_cursor_ref (GdkCursor *cursor)
158 g_return_val_if_fail (cursor != NULL, NULL);
160 return g_object_ref (cursor);
165 * @cursor: a #GdkCursor
167 * Removes a reference from @cursor, deallocating the cursor
168 * if no references remain.
170 * Deprecated: 3.0: Use g_object_unref() instead
173 gdk_cursor_unref (GdkCursor *cursor)
175 g_return_if_fail (cursor != NULL);
177 g_object_unref (cursor);
182 * @cursor_type: cursor to create
184 * Creates a new cursor from the set of builtin cursors for the default display.
185 * See gdk_cursor_new_for_display().
187 * To make the cursor invisible, use %GDK_BLANK_CURSOR.
189 * Return value: a new #GdkCursor
192 gdk_cursor_new (GdkCursorType cursor_type)
194 return gdk_cursor_new_for_display (gdk_display_get_default(), cursor_type);
198 * gdk_cursor_get_cursor_type:
199 * @cursor: a #GdkCursor
201 * Returns the cursor type for this cursor.
203 * Return value: a #GdkCursorType
208 gdk_cursor_get_cursor_type (GdkCursor *cursor)
210 g_return_val_if_fail (cursor != NULL, GDK_BLANK_CURSOR);
216 * gdk_cursor_new_for_display:
217 * @display: the #GdkDisplay for which the cursor will be created
218 * @cursor_type: cursor to create
220 * Creates a new cursor from the set of builtin cursors.
221 * Some useful ones are:
224 * <inlinegraphic format="PNG" fileref="right_ptr.png"></inlinegraphic> #GDK_RIGHT_PTR (right-facing arrow)
227 * <inlinegraphic format="PNG" fileref="crosshair.png"></inlinegraphic> #GDK_CROSSHAIR (crosshair)
230 * <inlinegraphic format="PNG" fileref="xterm.png"></inlinegraphic> #GDK_XTERM (I-beam)
233 * <inlinegraphic format="PNG" fileref="watch.png"></inlinegraphic> #GDK_WATCH (busy)
236 * <inlinegraphic format="PNG" fileref="fleur.png"></inlinegraphic> #GDK_FLEUR (for moving objects)
239 * <inlinegraphic format="PNG" fileref="hand1.png"></inlinegraphic> #GDK_HAND1 (a right-pointing hand)
242 * <inlinegraphic format="PNG" fileref="hand2.png"></inlinegraphic> #GDK_HAND2 (a left-pointing hand)
245 * <inlinegraphic format="PNG" fileref="left_side.png"></inlinegraphic> #GDK_LEFT_SIDE (resize left side)
248 * <inlinegraphic format="PNG" fileref="right_side.png"></inlinegraphic> #GDK_RIGHT_SIDE (resize right side)
251 * <inlinegraphic format="PNG" fileref="top_left_corner.png"></inlinegraphic> #GDK_TOP_LEFT_CORNER (resize northwest corner)
254 * <inlinegraphic format="PNG" fileref="top_right_corner.png"></inlinegraphic> #GDK_TOP_RIGHT_CORNER (resize northeast corner)
257 * <inlinegraphic format="PNG" fileref="bottom_left_corner.png"></inlinegraphic> #GDK_BOTTOM_LEFT_CORNER (resize southwest corner)
260 * <inlinegraphic format="PNG" fileref="bottom_right_corner.png"></inlinegraphic> #GDK_BOTTOM_RIGHT_CORNER (resize southeast corner)
263 * <inlinegraphic format="PNG" fileref="top_side.png"></inlinegraphic> #GDK_TOP_SIDE (resize top side)
266 * <inlinegraphic format="PNG" fileref="bottom_side.png"></inlinegraphic> #GDK_BOTTOM_SIDE (resize bottom side)
269 * <inlinegraphic format="PNG" fileref="sb_h_double_arrow.png"></inlinegraphic> #GDK_SB_H_DOUBLE_ARROW (move vertical splitter)
272 * <inlinegraphic format="PNG" fileref="sb_v_double_arrow.png"></inlinegraphic> #GDK_SB_V_DOUBLE_ARROW (move horizontal splitter)
275 * #GDK_BLANK_CURSOR (Blank cursor). Since 2.16
279 * Return value: a new #GdkCursor
284 gdk_cursor_new_for_display (GdkDisplay *display,
285 GdkCursorType cursor_type)
287 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
289 return GDK_DISPLAY_GET_CLASS (display)->get_cursor_for_type (display, cursor_type);
293 * gdk_cursor_new_from_name:
294 * @display: the #GdkDisplay for which the cursor will be created
295 * @name: the name of the cursor
297 * Creates a new cursor by looking up @name in the current cursor
300 * Returns: a new #GdkCursor, or %NULL if there is no cursor with
306 gdk_cursor_new_from_name (GdkDisplay *display,
309 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
311 return GDK_DISPLAY_GET_CLASS (display)->get_cursor_for_name (display, name);
315 * gdk_cursor_new_from_pixbuf:
316 * @display: the #GdkDisplay for which the cursor will be created
317 * @pixbuf: the #GdkPixbuf containing the cursor image
318 * @x: the horizontal offset of the 'hotspot' of the cursor.
319 * @y: the vertical offset of the 'hotspot' of the cursor.
321 * Creates a new cursor from a pixbuf.
323 * Not all GDK backends support RGBA cursors. If they are not
324 * supported, a monochrome approximation will be displayed.
325 * The functions gdk_display_supports_cursor_alpha() and
326 * gdk_display_supports_cursor_color() can be used to determine
327 * whether RGBA cursors are supported;
328 * gdk_display_get_default_cursor_size() and
329 * gdk_display_get_maximal_cursor_size() give information about
332 * If @x or @y are <literal>-1</literal>, the pixbuf must have
333 * options named "x_hot" and "y_hot", resp., containing
334 * integer values between %0 and the width resp. height of
335 * the pixbuf. (Since: 3.0)
337 * On the X backend, support for RGBA cursors requires a
338 * sufficently new version of the X Render extension.
340 * Returns: a new #GdkCursor.
345 gdk_cursor_new_from_pixbuf (GdkDisplay *display,
350 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
351 g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL);
353 return GDK_DISPLAY_GET_CLASS (display)->get_cursor_for_pixbuf (display, pixbuf, x, y);
357 * gdk_cursor_get_display:
358 * @cursor: a #GdkCursor.
360 * Returns the display on which the #GdkCursor is defined.
362 * Returns: (transfer none): the #GdkDisplay associated to @cursor
368 gdk_cursor_get_display (GdkCursor *cursor)
370 g_return_val_if_fail (GDK_IS_CURSOR (cursor), NULL);
372 return cursor->display;
376 * gdk_cursor_get_image:
377 * @cursor: a #GdkCursor
379 * Returns a #GdkPixbuf with the image used to display the cursor.
381 * Note that depending on the capabilities of the windowing system and
382 * on the cursor, GDK may not be able to obtain the image data. In this
383 * case, %NULL is returned.
385 * Returns: (transfer full): a #GdkPixbuf representing @cursor, or %NULL
390 gdk_cursor_get_image (GdkCursor *cursor)
392 g_return_val_if_fail (GDK_IS_CURSOR (cursor), NULL);
394 return GDK_CURSOR_GET_CLASS (cursor)->get_image (cursor);