]> Pileus Git - ~andy/gtk/blob - gdk/x11/gdkcursor-x11.c
fix up my list of "cursors that are actually useful" in gdk_cursor_new()
[~andy/gtk] / gdk / x11 / gdkcursor-x11.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 <X11/Xlib.h>
28 #include <X11/cursorfont.h>
29
30 #include "gdkprivate-x11.h"
31 #include "gdkcursor.h"
32 #include "gdkpixmap-x11.h"
33 #include <gdk/gdkpixmap.h>
34
35 /**
36  * gdk_cursor_new:
37  * @cursor_type: cursor to create
38  * 
39  * Creates a new cursor from the set of builtin cursors.
40  * Some useful ones are:
41  * <itemizedlist>
42  * <listitem><para>
43  *  <inlinegraphic format="png" fileref="right_ptr.png"></inlinegraphic> #GDK_RIGHT_PTR (right-facing arrow)
44  * </para></listitem>
45  * <listitem><para>
46  *  <inlinegraphic format="png" fileref="crosshair.png"></inlinegraphic> #GDK_CROSSHAIR (crosshair)
47  * </para></listitem>
48  * <listitem><para>
49  *  <inlinegraphic format="png" fileref="xterm.png"></inlinegraphic> #GDK_XTERM (I-beam)
50  * </para></listitem>
51  * <listitem><para>
52  * <inlinegraphic format="png" fileref="watch.png"></inlinegraphic> #GDK_WATCH (busy)
53  * </para></listitem>
54  * <listitem><para>
55  * <inlinegraphic format="png" fileref="fleur.png"></inlinegraphic> #GDK_FLEUR (for moving objects)
56  * </para></listitem>
57  * <listitem><para>
58  * <inlinegraphic format="png" fileref="hand1.png"></inlinegraphic> #GDK_HAND1 (a right-pointing hand)
59  * </para></listitem>
60  * <listitem><para>
61  * <inlinegraphic format="png" fileref="hand2.png"></inlinegraphic> #GDK_HAND2 (a left-pointing hand)
62  * </para></listitem>
63  * <listitem><para>
64  * <inlinegraphic format="png" fileref="left_side.png"></inlinegraphic> #GDK_LEFT_SIDE (resize left side)
65  * </para></listitem>
66  * <listitem><para>
67  * <inlinegraphic format="png" fileref="right_side.png"></inlinegraphic> #GDK_RIGHT_SIDE (resize right side)
68  * </para></listitem>
69  * <listitem><para>
70  * <inlinegraphic format="png" fileref="top_left_corner.png"></inlinegraphic> #GDK_TOP_LEFT_CORNER (resize northwest corner)
71  * </para></listitem>
72  * <listitem><para>
73  * <inlinegraphic format="png" fileref="top_right_corner.png"></inlinegraphic> #GDK_TOP_RIGHT_CORNER (resize northeast corner)
74  * </para></listitem>
75  * <listitem><para>
76  * <inlinegraphic format="png" fileref="bottom_left_corner.png"></inlinegraphic> #GDK_BOTTOM_LEFT_CORNER (resize southwest corner)
77  * </para></listitem>
78  * <listitem><para>
79  * <inlinegraphic format="png" fileref="bottom_right_corner.png"></inlinegraphic> #GDK_BOTTOM_RIGHT_CORNER (resize southeast corner)
80  * </para></listitem>
81  * <listitem><para>
82  * <inlinegraphic format="png" fileref="top_side.png"></inlinegraphic> #GDK_TOP_SIDE (resize top side)
83  * </para></listitem>
84  * <listitem><para>
85  * <inlinegraphic format="png" fileref="bottom_side.png"></inlinegraphic> #GDK_BOTTOM_SIDE (resize bottom side)
86  * </para></listitem>
87  * <listitem><para>
88  * <inlinegraphic format="png" fileref="sb_h_double_arrow.png"></inlinegraphic> #GDK_SB_H_DOUBLE_ARROW (move vertical splitter)
89  * </para></listitem>
90  * <listitem><para>
91  * <inlinegraphic format="png" fileref="sb_v_double_arrow.png"></inlinegraphic> #GDK_SB_V_DOUBLE_ARROW (move horizontal splitter)
92  * </para></listitem>
93  * </itemizedlist>
94  *
95  * To make the cursor invisible, use gdk_cursor_new_from_pixmap() to create
96  * a cursor with no pixels in it.
97  * 
98  * Return value: a new #GdkCursor
99  **/
100 GdkCursor*
101 gdk_cursor_new (GdkCursorType cursor_type)
102 {
103   GdkCursorPrivate *private;
104   GdkCursor *cursor;
105   Cursor xcursor;
106
107   xcursor = XCreateFontCursor (gdk_display, cursor_type);
108   private = g_new (GdkCursorPrivate, 1);
109   private->xdisplay = gdk_display;
110   private->xcursor = xcursor;
111   cursor = (GdkCursor*) private;
112   cursor->type = cursor_type;
113   cursor->ref_count = 1;
114   
115   return cursor;
116 }
117
118 GdkCursor*
119 gdk_cursor_new_from_pixmap (GdkPixmap *source,
120                             GdkPixmap *mask,
121                             GdkColor  *fg,
122                             GdkColor  *bg,
123                             gint       x,
124                             gint       y)
125 {
126   GdkCursorPrivate *private;
127   GdkCursor *cursor;
128   Pixmap source_pixmap, mask_pixmap;
129   Cursor xcursor;
130   XColor xfg, xbg;
131
132   g_return_val_if_fail (GDK_IS_PIXMAP (source), NULL);
133   g_return_val_if_fail (GDK_IS_PIXMAP (mask), NULL);
134   g_return_val_if_fail (fg != NULL, NULL);
135   g_return_val_if_fail (bg != NULL, NULL);
136
137   source_pixmap = GDK_PIXMAP_XID (source);
138   mask_pixmap   = GDK_PIXMAP_XID (mask);
139
140   xfg.pixel = fg->pixel;
141   xfg.red = fg->red;
142   xfg.blue = fg->blue;
143   xfg.green = fg->green;
144   xbg.pixel = bg->pixel;
145   xbg.red = bg->red;
146   xbg.blue = bg->blue;
147   xbg.green = bg->green;
148   
149   xcursor = XCreatePixmapCursor (gdk_display, source_pixmap, mask_pixmap, &xfg, &xbg, x, y);
150   private = g_new (GdkCursorPrivate, 1);
151   private->xdisplay = gdk_display;
152   private->xcursor = xcursor;
153   cursor = (GdkCursor *) private;
154   cursor->type = GDK_CURSOR_IS_PIXMAP;
155   cursor->ref_count = 1;
156   
157   return cursor;
158 }
159
160 void
161 _gdk_cursor_destroy (GdkCursor *cursor)
162 {
163   GdkCursorPrivate *private;
164
165   g_return_if_fail (cursor != NULL);
166   g_return_if_fail (cursor->ref_count == 0);
167
168   private = (GdkCursorPrivate *) cursor;
169   XFreeCursor (private->xdisplay, private->xcursor);
170
171   g_free (private);
172 }
173
174 Display *
175 gdk_x11_cursor_get_xdisplay (GdkCursor *cursor)
176 {
177   g_return_val_if_fail (cursor != NULL, NULL);
178
179   return ((GdkCursorPrivate *)cursor)->xdisplay;
180 }
181
182 Cursor
183 gdk_x11_cursor_get_xcursor (GdkCursor *cursor)
184 {
185   g_return_val_if_fail (cursor != NULL, None);
186
187   return ((GdkCursorPrivate *)cursor)->xcursor;
188 }