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