]> Pileus Git - ~andy/gtk/blob - gdk/win32/gdkcursor-win32.c
c5482c92b2f1426e0f970759dc8eea63080196ee
[~andy/gtk] / gdk / win32 / gdkcursor-win32.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 Library 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  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library 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 #include "config.h"
21
22 #include <gdk/gdk.h>
23 #include "gdkprivate.h"
24
25 static const struct { const char *name; int type; } cursors[] = {
26   { "x_cursor", 0 },
27   { "arrow", 2 },
28   { "based_arrow_down", 4 },
29   { "based_arrow_up", 6 },
30   { "boat", 8 },
31   { "bogosity", 10 },
32   { "bottom_left_corner", 12 },
33   { "bottom_right_corner", 14 },
34   { "bottom_side", 16 },
35   { "bottom_tee", 18 },
36   { "box_spiral", 20 },
37   { "center_ptr", 22 },
38   { "circle", 24 },
39   { "clock", 26 },
40   { "coffee_mug", 28 },
41   { "cross", 30 },
42   { "cross_reverse", 32 },
43   { "crosshair", 34 },
44   { "diamond_cross", 36 },
45   { "dot", 38 },
46   { "dotbox", 40 },
47   { "double_arrow", 42 },
48   { "draft_large", 44 },
49   { "draft_small", 46 },
50   { "draped_box", 48 },
51   { "exchange", 50 },
52   { "fleur", 52 },
53   { "gobbler", 54 },
54   { "gumby", 56 },
55   { "hand1", 58 },
56   { "hand2", 60 },
57   { "heart", 62 },
58   { "icon", 64 },
59   { "iron_cross", 66 },
60   { "left_ptr", 68 },
61   { "left_side", 70 },
62   { "left_tee", 72 },
63   { "leftbutton", 74 },
64   { "ll_angle", 76 },
65   { "lr_angle", 78 },
66   { "man", 80 },
67   { "middlebutton", 82 },
68   { "mouse", 84 },
69   { "pencil", 86 },
70   { "pirate", 88 },
71   { "plus", 90 },
72   { "question_arrow", 92 },
73   { "right_ptr", 94 },
74   { "right_side", 96 },
75   { "right_tee", 98 },
76   { "rightbutton", 100 },
77   { "rtl_logo", 102 },
78   { "sailboat", 104 },
79   { "sb_down_arrow", 106 },
80   { "sb_h_double_arrow", 108 },
81   { "sb_left_arrow", 110 },
82   { "sb_right_arrow", 112 },
83   { "sb_up_arrow", 114 },
84   { "sb_v_double_arrow", 116 },
85   { "shuttle", 118 },
86   { "sizing", 120 },
87   { "spider", 122 },
88   { "spraycan", 124 },
89   { "star", 126 },
90   { "target", 128 },
91   { "tcross", 130 },
92   { "top_left_arrow", 132 },
93   { "top_left_corner", 134 },
94   { "top_right_corner", 136 },
95   { "top_side", 138 },
96   { "top_tee", 140 },
97   { "trek", 142 },
98   { "ul_angle", 144 },
99   { "umbrella", 146 },
100   { "ur_angle", 148 },
101   { "watch", 150 },
102   { "xterm", 152 },
103   { NULL, 0 }
104 };  
105
106 GdkCursor*
107 gdk_cursor_new (GdkCursorType cursor_type)
108 {
109   GdkCursorPrivate *private;
110   GdkCursor *cursor;
111   HCURSOR xcursor;
112
113   int i;
114
115   for (i = 0; cursors[i].name != NULL && cursors[i].type != cursor_type; i++)
116     ;
117   if (cursors[i].name != NULL)
118     {
119       xcursor = LoadCursor (gdk_DLLInstance, cursors[i].name);
120       if (xcursor == NULL)
121         g_warning ("gdk_cursor_new: LoadCursor failed");
122       GDK_NOTE (MISC, g_print ("gdk_cursor_new: %#x %d\n",
123                                xcursor, cursor_type));
124     }
125   else
126     {
127       g_warning ("gdk_cursor_new: no cursor %d found",
128                  cursor_type);
129       xcursor = NULL;
130     }
131
132   private = g_new (GdkCursorPrivate, 1);
133   private->xcursor = xcursor;
134   cursor = (GdkCursor*) private;
135   cursor->type = cursor_type;
136
137   return cursor;
138 }
139
140 GdkCursor*
141 gdk_cursor_new_from_pixmap (GdkPixmap *source, GdkPixmap *mask, GdkColor *fg, GdkColor *bg, gint x, gint y)
142 {
143 #if 0                           /* I don't understand cursors, sigh */
144   GdkCursorPrivate *private;
145   GdkCursor *cursor;
146   GdkPixmap *s2;
147   GdkPixmapPrivate *source_private, *mask_private;
148   GdkPixmapPrivate *s2_private;
149   GdkGC *gc;
150   ICONINFO iconinfo;
151   HCURSOR xcursor;
152   HBITMAP invmask;
153   HDC hdc1, hdc2;
154   HGDIOBJ oldbm1, oldbm2;
155   
156   source_private = (GdkPixmapPrivate *) source;
157   mask_private   = (GdkPixmapPrivate *) mask;
158
159   s2 = gdk_pixmap_new (source, source_private->width, source_private->height, 1);
160   gc = gdk_gc_new (s2);
161   gdk_gc_set_foreground (gc, fg);
162   gdk_gc_set_background (gc, bg);
163   gdk_draw_pixmap (s2, gc, source, 0, 0, 0, 0,
164                    source_private->width, source_private->height);
165   gdk_gc_unref (gc);
166   
167   iconinfo.fIcon = FALSE;
168   iconinfo.xHotspot = x;
169   iconinfo.yHotspot = y;
170 #if 1
171   invmask = CreateBitmap (mask_private->width, mask_private->height, 1, 1, NULL);
172   hdc1 = CreateCompatibleDC (gdk_DC);
173   oldbm1 = SelectObject (hdc1, invmask);
174   hdc2 = CreateCompatibleDC (gdk_DC);
175   oldbm2 = SelectObject (hdc2, mask_private->xwindow);
176   BitBlt (hdc1, 0, 0, mask_private->width, mask_private->height, hdc2, 0, 0, NOTSRCCOPY);
177   SelectObject (hdc2, oldbm2);
178   DeleteDC (hdc2);
179   SelectObject (hdc1, oldbm1);
180   DeleteDC (hdc1);
181   iconinfo.hbmMask = invmask;
182 #else
183   iconinfo.hbmMask = mask_private->xwindow;;
184 #endif
185   iconinfo.hbmColor = ((GdkPixmapPrivate *) s2)->xwindow;
186
187   if ((xcursor = CreateIconIndirect (&iconinfo)) == NULL)
188     {
189       g_warning ("gdk_cursor_new_from_private: CreateIconIndirect failed");
190       gdk_pixmap_unref (s2);
191       return gdk_cursor_new (GDK_PIRATE);
192     }
193
194   GDK_NOTE (MISC,
195             g_print ("gdk_cursor_new_from_private: %#x (%dx%d) %#x (%dx%d) = %#x\n",
196                      source_private->xwindow,
197                      source_private->width, source_private->height,
198                      mask_private->xwindow,
199                      mask_private->width, mask_private->height,
200                      xcursor));
201
202   gdk_pixmap_unref (s2);
203   private = g_new (GdkCursorPrivate, 1);
204   private->xcursor = xcursor;
205   cursor = (GdkCursor*) private;
206   cursor->type = GDK_CURSOR_IS_PIXMAP;
207
208   return cursor;
209 #else  /* Just return some cursor ;-) */
210   return gdk_cursor_new (GDK_PIRATE);
211 #endif
212 }
213
214 void
215 gdk_cursor_destroy (GdkCursor *cursor)
216 {
217   GdkCursorPrivate *private;
218
219   g_return_if_fail (cursor != NULL);
220   private = (GdkCursorPrivate *) cursor;
221
222   if (cursor->type == GDK_CURSOR_IS_PIXMAP)
223     DestroyIcon (private->xcursor);
224
225   g_free (private);
226 }