]> Pileus Git - ~andy/gtk/blob - gdk/gdkcursor.c
gdk: Move GdkCursor definition into a private header
[~andy/gtk] / gdk / gdkcursor.c
1 /* GDK - The GIMP Drawing Kit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 /*
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/. 
25  */
26
27 #include "config.h"
28
29 #include "gdkcursor.h"
30 #include "gdkcursorprivate.h"
31 #include "gdkdisplayprivate.h"
32 #include "gdkinternals.h"
33
34
35 /**
36  * SECTION:cursors
37  * @Short_description: Standard and pixmap cursors
38  * @Title: Cursors
39  *
40  * These functions are used to create and destroy cursors.
41  * There is a number of standard cursors, but it is also
42  * possible to construct new cursors from pixbufs. There
43  * may be limitations as to what kinds of cursors can be
44  * constructed on a given display, see
45  * gdk_display_supports_cursor_alpha(),
46  * gdk_display_supports_cursor_color(),
47  * gdk_display_get_default_cursor_size() and
48  * gdk_display_get_maximal_cursor_size().
49  *
50  * Cursors by themselves are not very interesting, they must be be
51  * bound to a window for users to see them. This is done with
52  * gdk_window_set_cursor() or by setting the cursor member of the
53  * #GdkWindowAttr struct passed to gdk_window_new().
54  */
55
56 /**
57  * GdkCursor:
58  *
59  * The #GdkCursor structure represents a cursor. Its contents are private.
60  */
61
62 G_DEFINE_BOXED_TYPE (GdkCursor, gdk_cursor,
63                      gdk_cursor_ref,
64                      gdk_cursor_unref)
65
66 /**
67  * gdk_cursor_ref:
68  * @cursor: a #GdkCursor
69  *
70  * Adds a reference to @cursor.
71  *
72  * Return value: Same @cursor that was passed in
73  */
74 GdkCursor*
75 gdk_cursor_ref (GdkCursor *cursor)
76 {
77   g_return_val_if_fail (cursor != NULL, NULL);
78   g_return_val_if_fail (cursor->ref_count > 0, NULL);
79
80   cursor->ref_count += 1;
81
82   return cursor;
83 }
84
85 /**
86  * gdk_cursor_unref:
87  * @cursor: a #GdkCursor
88  *
89  * Removes a reference from @cursor, deallocating the cursor
90  * if no references remain.
91  */
92 void
93 gdk_cursor_unref (GdkCursor *cursor)
94 {
95   g_return_if_fail (cursor != NULL);
96   g_return_if_fail (cursor->ref_count > 0);
97
98   cursor->ref_count -= 1;
99
100   if (cursor->ref_count == 0)
101     _gdk_cursor_destroy (cursor);
102 }
103
104 /**
105  * gdk_cursor_new:
106  * @cursor_type: cursor to create
107  *
108  * Creates a new cursor from the set of builtin cursors for the default display.
109  * See gdk_cursor_new_for_display().
110  *
111  * To make the cursor invisible, use %GDK_BLANK_CURSOR.
112  *
113  * Return value: a new #GdkCursor
114  */
115 GdkCursor*
116 gdk_cursor_new (GdkCursorType cursor_type)
117 {
118   return gdk_cursor_new_for_display (gdk_display_get_default(), cursor_type);
119 }
120
121 /**
122  * gdk_cursor_get_cursor_type:
123  * @cursor:  a #GdkCursor
124  *
125  * Returns the cursor type for this cursor.
126  *
127  * Return value: a #GdkCursorType
128  *
129  * Since: 2.22
130  **/
131 GdkCursorType
132 gdk_cursor_get_cursor_type (GdkCursor *cursor)
133 {
134   g_return_val_if_fail (cursor != NULL, GDK_BLANK_CURSOR);
135
136   return cursor->type;
137 }
138
139 /**
140  * gdk_cursor_new_for_display:
141  * @display: the #GdkDisplay for which the cursor will be created
142  * @cursor_type: cursor to create
143  *
144  * Creates a new cursor from the set of builtin cursors.
145  * Some useful ones are:
146  * <itemizedlist>
147  * <listitem><para>
148  *  <inlinegraphic format="PNG" fileref="right_ptr.png"></inlinegraphic> #GDK_RIGHT_PTR (right-facing arrow)
149  * </para></listitem>
150  * <listitem><para>
151  *  <inlinegraphic format="PNG" fileref="crosshair.png"></inlinegraphic> #GDK_CROSSHAIR (crosshair)
152  * </para></listitem>
153  * <listitem><para>
154  *  <inlinegraphic format="PNG" fileref="xterm.png"></inlinegraphic> #GDK_XTERM (I-beam)
155  * </para></listitem>
156  * <listitem><para>
157  * <inlinegraphic format="PNG" fileref="watch.png"></inlinegraphic> #GDK_WATCH (busy)
158  * </para></listitem>
159  * <listitem><para>
160  * <inlinegraphic format="PNG" fileref="fleur.png"></inlinegraphic> #GDK_FLEUR (for moving objects)
161  * </para></listitem>
162  * <listitem><para>
163  * <inlinegraphic format="PNG" fileref="hand1.png"></inlinegraphic> #GDK_HAND1 (a right-pointing hand)
164  * </para></listitem>
165  * <listitem><para>
166  * <inlinegraphic format="PNG" fileref="hand2.png"></inlinegraphic> #GDK_HAND2 (a left-pointing hand)
167  * </para></listitem>
168  * <listitem><para>
169  * <inlinegraphic format="PNG" fileref="left_side.png"></inlinegraphic> #GDK_LEFT_SIDE (resize left side)
170  * </para></listitem>
171  * <listitem><para>
172  * <inlinegraphic format="PNG" fileref="right_side.png"></inlinegraphic> #GDK_RIGHT_SIDE (resize right side)
173  * </para></listitem>
174  * <listitem><para>
175  * <inlinegraphic format="PNG" fileref="top_left_corner.png"></inlinegraphic> #GDK_TOP_LEFT_CORNER (resize northwest corner)
176  * </para></listitem>
177  * <listitem><para>
178  * <inlinegraphic format="PNG" fileref="top_right_corner.png"></inlinegraphic> #GDK_TOP_RIGHT_CORNER (resize northeast corner)
179  * </para></listitem>
180  * <listitem><para>
181  * <inlinegraphic format="PNG" fileref="bottom_left_corner.png"></inlinegraphic> #GDK_BOTTOM_LEFT_CORNER (resize southwest corner)
182  * </para></listitem>
183  * <listitem><para>
184  * <inlinegraphic format="PNG" fileref="bottom_right_corner.png"></inlinegraphic> #GDK_BOTTOM_RIGHT_CORNER (resize southeast corner)
185  * </para></listitem>
186  * <listitem><para>
187  * <inlinegraphic format="PNG" fileref="top_side.png"></inlinegraphic> #GDK_TOP_SIDE (resize top side)
188  * </para></listitem>
189  * <listitem><para>
190  * <inlinegraphic format="PNG" fileref="bottom_side.png"></inlinegraphic> #GDK_BOTTOM_SIDE (resize bottom side)
191  * </para></listitem>
192  * <listitem><para>
193  * <inlinegraphic format="PNG" fileref="sb_h_double_arrow.png"></inlinegraphic> #GDK_SB_H_DOUBLE_ARROW (move vertical splitter)
194  * </para></listitem>
195  * <listitem><para>
196  * <inlinegraphic format="PNG" fileref="sb_v_double_arrow.png"></inlinegraphic> #GDK_SB_V_DOUBLE_ARROW (move horizontal splitter)
197  * </para></listitem>
198  * <listitem><para>
199  * #GDK_BLANK_CURSOR (Blank cursor). Since 2.16
200  * </para></listitem>
201  * </itemizedlist>
202  *
203  * Return value: a new #GdkCursor
204  *
205  * Since: 2.2
206  **/
207 GdkCursor*
208 gdk_cursor_new_for_display (GdkDisplay    *display,
209                             GdkCursorType  cursor_type)
210 {
211   g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
212
213   return GDK_DISPLAY_GET_CLASS (display)->get_cursor_for_type (display, cursor_type);
214 }
215
216 /**
217  * gdk_cursor_new_from_name:
218  * @display: the #GdkDisplay for which the cursor will be created
219  * @name: the name of the cursor
220  *
221  * Creates a new cursor by looking up @name in the current cursor
222  * theme.
223  *
224  * Returns: a new #GdkCursor, or %NULL if there is no cursor with
225  *   the given name
226  *
227  * Since: 2.8
228  */
229 GdkCursor*
230 gdk_cursor_new_from_name (GdkDisplay  *display,
231                           const gchar *name)
232 {
233   g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
234
235   return GDK_DISPLAY_GET_CLASS (display)->get_cursor_for_name (display, name);
236 }
237
238 /**
239  * gdk_cursor_new_from_pixbuf:
240  * @display: the #GdkDisplay for which the cursor will be created
241  * @pixbuf: the #GdkPixbuf containing the cursor image
242  * @x: the horizontal offset of the 'hotspot' of the cursor.
243  * @y: the vertical offset of the 'hotspot' of the cursor.
244  *
245  * Creates a new cursor from a pixbuf.
246  *
247  * Not all GDK backends support RGBA cursors. If they are not
248  * supported, a monochrome approximation will be displayed.
249  * The functions gdk_display_supports_cursor_alpha() and
250  * gdk_display_supports_cursor_color() can be used to determine
251  * whether RGBA cursors are supported;
252  * gdk_display_get_default_cursor_size() and
253  * gdk_display_get_maximal_cursor_size() give information about
254  * cursor sizes.
255  *
256  * If @x or @y are <literal>-1</literal>, the pixbuf must have
257  * options named "x_hot" and "y_hot", resp., containing
258  * integer values between %0 and the width resp. height of
259  * the pixbuf. (Since: 3.0)
260  *
261  * On the X backend, support for RGBA cursors requires a
262  * sufficently new version of the X Render extension.
263  *
264  * Returns: a new #GdkCursor.
265  *
266  * Since: 2.4
267  */
268 GdkCursor *
269 gdk_cursor_new_from_pixbuf (GdkDisplay *display,
270                             GdkPixbuf  *pixbuf,
271                             gint        x,
272                             gint        y)
273 {
274   g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
275   g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL);
276
277   return GDK_DISPLAY_GET_CLASS (display)->get_cursor_for_pixbuf (display, pixbuf, x, y);
278 }