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 "gdkcursorprivate.h"
31 #include "gdkdisplayprivate.h"
33 #include "gdkinternals.h"
38 * @Short_description: Standard and pixmap cursors
41 * These functions are used to create and destroy cursors.
42 * There is a number of standard cursors, but it is also
43 * possible to construct new cursors from pixbufs. There
44 * may be limitations as to what kinds of cursors can be
45 * constructed on a given display, see
46 * gdk_display_supports_cursor_alpha(),
47 * gdk_display_supports_cursor_color(),
48 * gdk_display_get_default_cursor_size() and
49 * gdk_display_get_maximal_cursor_size().
51 * Cursors by themselves are not very interesting, they must be be
52 * bound to a window for users to see them. This is done with
53 * gdk_window_set_cursor() or by setting the cursor member of the
54 * #GdkWindowAttr struct passed to gdk_window_new().
60 * The #GdkCursor structure represents a cursor. Its contents are private.
69 G_DEFINE_ABSTRACT_TYPE (GdkCursor, gdk_cursor, G_TYPE_OBJECT)
72 gdk_cursor_get_property (GObject *object,
77 GdkCursor *cursor = GDK_CURSOR (object);
81 case PROP_CURSOR_TYPE:
82 g_value_set_enum (value, cursor->type);
85 g_value_set_object (value, cursor->display);
88 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
94 gdk_cursor_set_property (GObject *object,
99 GdkCursor *cursor = GDK_CURSOR (object);
103 case PROP_CURSOR_TYPE:
104 cursor->type = g_value_get_enum (value);
107 cursor->display = g_value_get_object (value);
108 /* check that implementations actually provide the display when constructing */
109 g_assert (cursor->display != NULL);
112 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
118 gdk_cursor_class_init (GdkCursorClass *cursor_class)
120 GObjectClass *object_class = G_OBJECT_CLASS (cursor_class);
122 object_class->get_property = gdk_cursor_get_property;
123 object_class->set_property = gdk_cursor_set_property;
125 g_object_class_install_property (object_class,
127 g_param_spec_enum ("cursor-type",
129 P_("Standard cursor type"),
130 GDK_TYPE_CURSOR_TYPE, GDK_X_CURSOR,
131 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
133 g_object_class_install_property (object_class,
135 g_param_spec_object ("display",
137 P_("Display of this cursor"),
139 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
143 gdk_cursor_init (GdkCursor *cursor)
149 * @cursor: a #GdkCursor
151 * Adds a reference to @cursor.
153 * Return value: (transfer full): Same @cursor that was passed in
155 * Deprecated: 3.0: Use g_object_ref() instead
158 gdk_cursor_ref (GdkCursor *cursor)
160 g_return_val_if_fail (cursor != NULL, NULL);
162 return g_object_ref (cursor);
167 * @cursor: a #GdkCursor
169 * Removes a reference from @cursor, deallocating the cursor
170 * if no references remain.
172 * Deprecated: 3.0: Use g_object_unref() instead
175 gdk_cursor_unref (GdkCursor *cursor)
177 g_return_if_fail (cursor != NULL);
179 g_object_unref (cursor);
184 * @cursor_type: cursor to create
186 * Creates a new cursor from the set of builtin cursors for the default display.
187 * See gdk_cursor_new_for_display().
189 * To make the cursor invisible, use %GDK_BLANK_CURSOR.
191 * Return value: a new #GdkCursor
194 gdk_cursor_new (GdkCursorType cursor_type)
196 return gdk_cursor_new_for_display (gdk_display_get_default(), cursor_type);
200 * gdk_cursor_get_cursor_type:
201 * @cursor: a #GdkCursor
203 * Returns the cursor type for this cursor.
205 * Return value: a #GdkCursorType
210 gdk_cursor_get_cursor_type (GdkCursor *cursor)
212 g_return_val_if_fail (cursor != NULL, GDK_BLANK_CURSOR);
218 * gdk_cursor_new_for_display:
219 * @display: the #GdkDisplay for which the cursor will be created
220 * @cursor_type: cursor to create
222 * Creates a new cursor from the set of builtin cursors.
223 * Some useful ones are:
226 * <inlinegraphic format="PNG" fileref="right_ptr.png"></inlinegraphic> #GDK_RIGHT_PTR (right-facing arrow)
229 * <inlinegraphic format="PNG" fileref="crosshair.png"></inlinegraphic> #GDK_CROSSHAIR (crosshair)
232 * <inlinegraphic format="PNG" fileref="xterm.png"></inlinegraphic> #GDK_XTERM (I-beam)
235 * <inlinegraphic format="PNG" fileref="watch.png"></inlinegraphic> #GDK_WATCH (busy)
238 * <inlinegraphic format="PNG" fileref="fleur.png"></inlinegraphic> #GDK_FLEUR (for moving objects)
241 * <inlinegraphic format="PNG" fileref="hand1.png"></inlinegraphic> #GDK_HAND1 (a right-pointing hand)
244 * <inlinegraphic format="PNG" fileref="hand2.png"></inlinegraphic> #GDK_HAND2 (a left-pointing hand)
247 * <inlinegraphic format="PNG" fileref="left_side.png"></inlinegraphic> #GDK_LEFT_SIDE (resize left side)
250 * <inlinegraphic format="PNG" fileref="right_side.png"></inlinegraphic> #GDK_RIGHT_SIDE (resize right side)
253 * <inlinegraphic format="PNG" fileref="top_left_corner.png"></inlinegraphic> #GDK_TOP_LEFT_CORNER (resize northwest corner)
256 * <inlinegraphic format="PNG" fileref="top_right_corner.png"></inlinegraphic> #GDK_TOP_RIGHT_CORNER (resize northeast corner)
259 * <inlinegraphic format="PNG" fileref="bottom_left_corner.png"></inlinegraphic> #GDK_BOTTOM_LEFT_CORNER (resize southwest corner)
262 * <inlinegraphic format="PNG" fileref="bottom_right_corner.png"></inlinegraphic> #GDK_BOTTOM_RIGHT_CORNER (resize southeast corner)
265 * <inlinegraphic format="PNG" fileref="top_side.png"></inlinegraphic> #GDK_TOP_SIDE (resize top side)
268 * <inlinegraphic format="PNG" fileref="bottom_side.png"></inlinegraphic> #GDK_BOTTOM_SIDE (resize bottom side)
271 * <inlinegraphic format="PNG" fileref="sb_h_double_arrow.png"></inlinegraphic> #GDK_SB_H_DOUBLE_ARROW (move vertical splitter)
274 * <inlinegraphic format="PNG" fileref="sb_v_double_arrow.png"></inlinegraphic> #GDK_SB_V_DOUBLE_ARROW (move horizontal splitter)
277 * #GDK_BLANK_CURSOR (Blank cursor). Since 2.16
281 * Return value: a new #GdkCursor
286 gdk_cursor_new_for_display (GdkDisplay *display,
287 GdkCursorType cursor_type)
289 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
291 return GDK_DISPLAY_GET_CLASS (display)->get_cursor_for_type (display, cursor_type);
295 * gdk_cursor_new_from_name:
296 * @display: the #GdkDisplay for which the cursor will be created
297 * @name: the name of the cursor
299 * Creates a new cursor by looking up @name in the current cursor
302 * Returns: a new #GdkCursor, or %NULL if there is no cursor with
308 gdk_cursor_new_from_name (GdkDisplay *display,
311 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
313 return GDK_DISPLAY_GET_CLASS (display)->get_cursor_for_name (display, name);
317 * gdk_cursor_new_from_pixbuf:
318 * @display: the #GdkDisplay for which the cursor will be created
319 * @pixbuf: the #GdkPixbuf containing the cursor image
320 * @x: the horizontal offset of the 'hotspot' of the cursor.
321 * @y: the vertical offset of the 'hotspot' of the cursor.
323 * Creates a new cursor from a pixbuf.
325 * Not all GDK backends support RGBA cursors. If they are not
326 * supported, a monochrome approximation will be displayed.
327 * The functions gdk_display_supports_cursor_alpha() and
328 * gdk_display_supports_cursor_color() can be used to determine
329 * whether RGBA cursors are supported;
330 * gdk_display_get_default_cursor_size() and
331 * gdk_display_get_maximal_cursor_size() give information about
334 * If @x or @y are <literal>-1</literal>, the pixbuf must have
335 * options named "x_hot" and "y_hot", resp., containing
336 * integer values between %0 and the width resp. height of
337 * the pixbuf. (Since: 3.0)
339 * On the X backend, support for RGBA cursors requires a
340 * sufficently new version of the X Render extension.
342 * Returns: a new #GdkCursor.
347 gdk_cursor_new_from_pixbuf (GdkDisplay *display,
352 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
353 g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL);
355 return GDK_DISPLAY_GET_CLASS (display)->get_cursor_for_pixbuf (display, pixbuf, x, y);
359 * gdk_cursor_get_display:
360 * @cursor: a #GdkCursor.
362 * Returns the display on which the #GdkCursor is defined.
364 * Returns: (transfer none): the #GdkDisplay associated to @cursor
370 gdk_cursor_get_display (GdkCursor *cursor)
372 g_return_val_if_fail (GDK_IS_CURSOR (cursor), NULL);
374 return cursor->display;
378 * gdk_cursor_get_image:
379 * @cursor: a #GdkCursor
381 * Returns a #GdkPixbuf with the image used to display the cursor.
383 * Note that depending on the capabilities of the windowing system and
384 * on the cursor, GDK may not be able to obtain the image data. In this
385 * case, %NULL is returned.
387 * Returns: (transfer full): a #GdkPixbuf representing @cursor, or %NULL
392 gdk_cursor_get_image (GdkCursor *cursor)
394 g_return_val_if_fail (GDK_IS_CURSOR (cursor), NULL);
396 return GDK_CURSOR_GET_CLASS (cursor)->get_image (cursor);