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