]> Pileus Git - ~andy/gtk/blob - gdk/x11/gdkcursor-x11.c
Start implementing display/screen closing scheme; keep a flag for whether
[~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   if (display->closed)
113     xcursor = None;
114   else
115     xcursor = XCreateFontCursor (GDK_DISPLAY_XDISPLAY (display), cursor_type);
116   
117   private = g_new (GdkCursorPrivate, 1);
118   private->display = display;
119   private->xcursor = xcursor;
120   cursor = (GdkCursor *) private;
121   cursor->type = cursor_type;
122   cursor->ref_count = 1;
123   
124   return cursor;
125 }
126
127 GdkCursor*
128 gdk_cursor_new_from_pixmap (GdkPixmap *source,
129                             GdkPixmap *mask,
130                             GdkColor  *fg,
131                             GdkColor  *bg,
132                             gint       x,
133                             gint       y)
134 {
135   GdkCursorPrivate *private;
136   GdkCursor *cursor;
137   Pixmap source_pixmap, mask_pixmap;
138   Cursor xcursor;
139   XColor xfg, xbg;
140   GdkDisplay *display;
141
142   g_return_val_if_fail (GDK_IS_PIXMAP (source), NULL);
143   g_return_val_if_fail (GDK_IS_PIXMAP (mask), NULL);
144   g_return_val_if_fail (fg != NULL, NULL);
145   g_return_val_if_fail (bg != NULL, NULL);
146
147   source_pixmap = GDK_PIXMAP_XID (source);
148   mask_pixmap   = GDK_PIXMAP_XID (mask);
149   display = GDK_PIXMAP_DISPLAY (source);
150
151   xfg.pixel = fg->pixel;
152   xfg.red = fg->red;
153   xfg.blue = fg->blue;
154   xfg.green = fg->green;
155   xbg.pixel = bg->pixel;
156   xbg.red = bg->red;
157   xbg.blue = bg->blue;
158   xbg.green = bg->green;
159   
160   if (display->closed)
161     xcursor = None;
162   else
163     xcursor = XCreatePixmapCursor (GDK_DISPLAY_XDISPLAY (display),
164                                    source_pixmap, mask_pixmap, &xfg, &xbg, x, y);
165   private = g_new (GdkCursorPrivate, 1);
166   private->display = display;
167   private->xcursor = xcursor;
168   cursor = (GdkCursor *) private;
169   cursor->type = GDK_CURSOR_IS_PIXMAP;
170   cursor->ref_count = 1;
171   
172   return cursor;
173 }
174
175 void
176 _gdk_cursor_destroy (GdkCursor *cursor)
177 {
178   GdkCursorPrivate *private;
179
180   g_return_if_fail (cursor != NULL);
181   g_return_if_fail (cursor->ref_count == 0);
182
183   private = (GdkCursorPrivate *) cursor;
184   if (!private->display->closed && private->xcursor)
185     XFreeCursor (GDK_DISPLAY_XDISPLAY (private->display), private->xcursor);
186
187   g_free (private);
188 }
189
190 Display *
191 gdk_x11_cursor_get_xdisplay (GdkCursor *cursor)
192 {
193   g_return_val_if_fail (cursor != NULL, NULL);
194
195   return GDK_DISPLAY_XDISPLAY(((GdkCursorPrivate *)cursor)->display);
196 }
197
198 Cursor
199 gdk_x11_cursor_get_xcursor (GdkCursor *cursor)
200 {
201   g_return_val_if_fail (cursor != NULL, None);
202
203   return ((GdkCursorPrivate *)cursor)->xcursor;
204 }
205
206 /** 
207  * gdk_cursor_get_display:
208  * @cursor : a #GdkCursor.
209  *
210  * Returns the display on which the GdkCursor is defined
211  *
212  * Returns : the #GdkDisplay associated to @cursor
213  */
214
215 GdkDisplay *
216 gdk_cursor_get_display (GdkCursor *cursor)
217 {
218   g_return_val_if_fail (cursor != NULL, NULL);
219
220   return ((GdkCursorPrivate *)cursor)->display;
221 }