4 static char Copyright
[] = "Copyright Martin Ayotte, 1993";
10 #include <X11/Intrinsic.h>
11 #include <X11/cursorfont.h>
15 #include <sys/types.h>
19 #include "prototypes.h"
26 static int ShowCursCount
= 0;
27 static HCURSOR hActiveCursor
;
28 static HCURSOR hEmptyCursor
= 0;
30 extern HINSTANCE hSysRes
;
31 extern Window winHasCursor
;
33 /**********************************************************************
34 * LoadCursor [USER.173]
36 HCURSOR
LoadCursor(HANDLE instance
, LPSTR cursor_name
)
43 CURSORDESCRIP
*lpcurdesc
;
51 printf("LoadCursor: instance = %04x, name = %08x\n",
52 instance
, cursor_name
);
54 hCursor
= GlobalAlloc(GMEM_MOVEABLE
, sizeof(CURSORALLOC
) + 1024L);
55 if (hCursor
== (HCURSOR
)NULL
) return 0;
57 printf("LoadCursor Alloc hCursor=%X\n", hCursor
);
59 lpcur
= (CURSORALLOC
*)GlobalLock(hCursor
);
60 memset(lpcur
, 0, sizeof(CURSORALLOC
));
61 if (instance
== (HANDLE
)NULL
) {
63 switch((LONG
)cursor_name
) {
65 lpcur
->xcursor
= XCreateFontCursor(XT_display
, XC_top_left_arrow
);
66 GlobalUnlock(hCursor
);
69 lpcur
->xcursor
= XCreateFontCursor(XT_display
, XC_crosshair
);
70 GlobalUnlock(hCursor
);
73 lpcur
->xcursor
= XCreateFontCursor(XT_display
, XC_xterm
);
74 GlobalUnlock(hCursor
);
77 lpcur
->xcursor
= XCreateFontCursor(XT_display
, XC_watch
);
78 GlobalUnlock(hCursor
);
84 if (!(hdc
= GetDC(GetDesktopWindow()))) return 0;
85 rsc_mem
= RSC_LoadResource(instance
, cursor_name
, NE_RSCTYPE_GROUP_CURSOR
,
87 if (rsc_mem
== (HANDLE
)NULL
) {
88 printf("LoadCursor / Cursor %08X not Found !\n", cursor_name
);
89 ReleaseDC(GetDesktopWindow(), hdc
);
92 lp
= (WORD
*)GlobalLock(rsc_mem
);
95 ReleaseDC(GetDesktopWindow(), hdc
);
98 lpcurdesc
= (CURSORDESCRIP
*)(lp
+ 3);
100 printf("LoadCursor / image_size=%d\n", image_size
);
101 printf("LoadCursor / curReserved=%X\n", *lp
);
102 printf("LoadCursor / curResourceType=%X\n", *(lp
+ 1));
103 printf("LoadCursor / curResourceCount=%X\n", *(lp
+ 2));
104 printf("LoadCursor / cursor Width=%d\n", (int)lpcurdesc
->Width
);
105 printf("LoadCursor / cursor Height=%d\n", (int)lpcurdesc
->Height
);
106 printf("LoadCursor / cursor curXHotspot=%d\n", (int)lpcurdesc
->curXHotspot
);
107 printf("LoadCursor / cursor curYHotspot=%d\n", (int)lpcurdesc
->curYHotspot
);
108 printf("LoadCursor / cursor curDIBSize=%lX\n", (DWORD
)lpcurdesc
->curDIBSize
);
109 printf("LoadCursor / cursor curDIBOffset=%lX\n", (DWORD
)lpcurdesc
->curDIBOffset
);
111 lpcur
->descriptor
= *lpcurdesc
;
112 GlobalUnlock(rsc_mem
);
114 rsc_mem
= RSC_LoadResource(instance
,
115 MAKEINTRESOURCE(lpcurdesc
->curDIBOffset
),
116 NE_RSCTYPE_CURSOR
, &image_size
);
117 if (rsc_mem
== (HANDLE
)NULL
) {
118 printf("LoadCursor / Cursor %08X Bitmap not Found !\n", cursor_name
);
119 ReleaseDC(GetDesktopWindow(), hdc
);
122 lp
= (WORD
*)GlobalLock(rsc_mem
);
125 ReleaseDC(GetDesktopWindow(), hdc
);
129 for (j
= 0; j
< 16; j
++)
130 printf("%04X ", *(lp
+ j
));
132 if (*lp == sizeof(BITMAPINFOHEADER))
133 lpcur->hBitmap = ConvertInfoBitmap(hdc, (BITMAPINFO *)lp);
137 lp
+= sizeof(BITMAP
);
138 for (i
= 0; i
< 81; i
++) {
139 char temp
= *((char *)lp
+ 162 + i
);
140 *((char *)lp
+ 162 + i
) = *((char *)lp
+ 324 - i
);
141 *((char *)lp
+ 324 - i
) = temp
;
143 lpcur
->pixshape
= XCreatePixmapFromBitmapData(
144 XT_display
, DefaultRootWindow(XT_display
),
145 ((char *)lp
+ 211), 32, 32,
147 lpcurdesc->Width / 2, lpcurdesc->Height / 4,
149 WhitePixel(XT_display
, DefaultScreen(XT_display
)),
150 BlackPixel(XT_display
, DefaultScreen(XT_display
)), 1);
151 lpcur
->pixmask
= XCreatePixmapFromBitmapData(
152 XT_display
, DefaultRootWindow(XT_display
),
153 ((char *)lp
+ 211), 32, 32,
154 WhitePixel(XT_display
, DefaultScreen(XT_display
)),
155 BlackPixel(XT_display
, DefaultScreen(XT_display
)), 1);
156 memset(&bkcolor
, 0, sizeof(XColor
));
157 memset(&fgcolor
, 0, sizeof(XColor
));
158 bkcolor
.pixel
= WhitePixel(XT_display
, DefaultScreen(XT_display
));
159 fgcolor
.pixel
= BlackPixel(XT_display
, DefaultScreen(XT_display
));
160 printf("LoadCursor / before XCreatePixmapCursor !\n");
161 lpcur
->xcursor
= XCreatePixmapCursor(XT_display
,
162 lpcur
->pixshape
, lpcur
->pixmask
,
163 &fgcolor
, &bkcolor
, lpcur
->descriptor
.curXHotspot
,
164 lpcur
->descriptor
.curYHotspot
);
165 GlobalUnlock(rsc_mem
);
168 hCursor = CreateCursor(instance, lpcur->descriptor.curXHotspot,
169 lpcur->descriptor.curYHotspot, 32, 32,
170 (LPSTR)lp + 211, , (LPSTR)lp + 211);
172 XFreePixmap(XT_display
, lpcur
->pixshape
);
173 XFreePixmap(XT_display
, lpcur
->pixmask
);
174 ReleaseDC(GetDesktopWindow(), hdc
);
175 GlobalUnlock(hCursor
);
181 /**********************************************************************
182 * CreateCursor [USER.406]
184 HCURSOR
CreateCursor(HANDLE instance
, short nXhotspot
, short nYhotspot
,
185 short nWidth
, short nHeight
, LPSTR lpANDbitPlane
, LPSTR lpXORbitPlane
)
196 #ifdef DEBUG_RESOURCE
197 printf("CreateCursor: inst=%04x nXhotspot=%d nYhotspot=%d nWidth=%d nHeight=%d\n",
198 nXhotspot
, nYhotspot
, nWidth
, nHeight
);
199 printf("CreateCursor: inst=%04x lpANDbitPlane=%08X lpXORbitPlane=%08X\n",
200 LPSTR lpANDbitPlane
, LPSTR lpXORbitPlane
);
202 if (!(hdc
= GetDC(GetDesktopWindow()))) return 0;
203 hCursor
= GlobalAlloc(GMEM_MOVEABLE
, sizeof(CURSORALLOC
) + 1024L);
204 if (hCursor
== (HCURSOR
)NULL
) {
205 ReleaseDC(GetDesktopWindow(), hdc
);
208 printf("CreateCursor Alloc hCursor=%X\n", hCursor
);
209 lpcur
= (CURSORALLOC
*)GlobalLock(hCursor
);
210 memset(lpcur
, 0, sizeof(CURSORALLOC
));
211 lpcur
->descriptor
.curXHotspot
= nXhotspot
;
212 lpcur
->descriptor
.curYHotspot
= nYhotspot
;
213 lpcur
->pixshape
= XCreatePixmapFromBitmapData(
214 XT_display
, DefaultRootWindow(XT_display
),
215 lpXORbitPlane
, nWidth
, nHeight
,
216 WhitePixel(XT_display
, DefaultScreen(XT_display
)),
217 BlackPixel(XT_display
, DefaultScreen(XT_display
)), 1);
218 lpcur
->pixmask
= XCreatePixmapFromBitmapData(
219 XT_display
, DefaultRootWindow(XT_display
),
220 lpANDbitPlane
, nWidth
, nHeight
,
221 WhitePixel(XT_display
, DefaultScreen(XT_display
)),
222 BlackPixel(XT_display
, DefaultScreen(XT_display
)), 1);
223 memset(&bkcolor
, 0, sizeof(XColor
));
224 memset(&fgcolor
, 0, sizeof(XColor
));
225 bkcolor
.pixel
= WhitePixel(XT_display
, DefaultScreen(XT_display
));
226 fgcolor
.pixel
= BlackPixel(XT_display
, DefaultScreen(XT_display
));
227 lpcur
->xcursor
= XCreatePixmapCursor(XT_display
,
228 lpcur
->pixshape
, lpcur
->pixmask
,
229 &fgcolor
, &bkcolor
, lpcur
->descriptor
.curXHotspot
,
230 lpcur
->descriptor
.curYHotspot
);
231 XFreePixmap(XT_display
, lpcur
->pixshape
);
232 XFreePixmap(XT_display
, lpcur
->pixmask
);
233 ReleaseDC(GetDesktopWindow(), hdc
);
234 GlobalUnlock(hCursor
);
240 /**********************************************************************
241 * DestroyCursor [USER.458]
243 BOOL
DestroyCursor(HCURSOR hCursor
)
246 if (hCursor
== (HCURSOR
)NULL
) return FALSE
;
247 lpcur
= (CURSORALLOC
*)GlobalLock(hCursor
);
248 if (lpcur
->hBitmap
!= (HBITMAP
)NULL
) DeleteObject(lpcur
->hBitmap
);
249 GlobalUnlock(hCursor
);
255 /**********************************************************************
256 * SetCursor [USER.69]
258 HCURSOR
SetCursor(HCURSOR hCursor
)
268 unsigned int mousebut
;
270 printf("SetCursor / hCursor=%04X !\n", hCursor
);
272 if (hCursor
== (HCURSOR
)NULL
) return FALSE
;
273 lpcur
= (CURSORALLOC
*)GlobalLock(hCursor
);
274 hOldCursor
= hActiveCursor
;
276 printf("SetCursor / lpcur->xcursor=%08X !\n", &lpcur
->xcursor
);
277 XQueryPointer(XT_display
, DefaultRootWindow(XT_display
),
278 &root
, &child
, &rootX
, &rootY
, &childX
, &childY
, &mousebut
);
279 printf("SetCursor / winHasCursor=%08X !\n", winHasCursor
);
280 printf("SetCursor / child=%08X !\n", child
);
282 if (hActiveCursor
!= hCursor
) ShowCursCount
= 0;
283 if ((ShowCursCount
>= 0) & (winHasCursor
!= 0)) {
284 /* XUndefineCursor(XT_display, winHasCursor); */
285 XDefineCursor(XT_display
, winHasCursor
, lpcur
->xcursor
);
287 GlobalUnlock(hCursor
);
288 hActiveCursor
= hCursor
;
293 /**********************************************************************
294 * SetCursorPos [USER.70]
296 void SetCursorPos(short x
, short y
)
301 unsigned int mousebut
;
303 printf("SetCursorPos // x=%d y=%d\n", x
, y
);
305 XQueryPointer(XT_display
, DefaultRootWindow(XT_display
),
306 &root
, &child
, &rootX
, &rootY
, &childX
, &childY
, &mousebut
);
307 XWarpPointer(XT_display
, child
, root
, 0, 0,
308 DisplayWidth(XT_display
, DefaultScreen(XT_display
)),
309 DisplayHeight(XT_display
, DefaultScreen(XT_display
)),
314 /**********************************************************************
315 * GetCursorPos [USER.17]
317 void GetCursorPos(LPPOINT lpRetPoint
)
322 unsigned int mousebut
;
323 if (lpRetPoint
!= NULL
) {
324 XQueryPointer(XT_display
, DefaultRootWindow(XT_display
),
325 &root
, &child
, &rootX
, &rootY
, &childX
, &childY
, &mousebut
);
327 printf("GetCursorPos // x=%d y=%d\n", rootX
, rootY
);
329 lpRetPoint
->x
= rootX
;
330 lpRetPoint
->y
= rootY
;
335 /**********************************************************************
336 * ShowCursor [USER.71]
338 int ShowCursor(BOOL bShow
)
342 printf("ShowCursor bShow=%d ShowCount=%d !\n", bShow
, ShowCursCount
);
348 if (ShowCursCount
>= 0) {
349 /* if (hCursor == (HCURSOR)NULL) */
350 hCursor
= LoadCursor((HINSTANCE
)NULL
, IDC_ARROW
);
354 /* XUndefineCursor(XT_display, winHasCursor); */
355 if (hEmptyCursor
== (HCURSOR
)NULL
)
356 hEmptyCursor
= CreateCursor((HINSTANCE
)NULL
, 1, 1, 1, 1,
357 "\xFF\xFF", "\xFF\xFF");
358 hCursor
= SetCursor(hEmptyCursor
);
359 hActiveCursor
= hCursor
;
365 /**********************************************************************
366 * ClipCursor [USER.16]
368 void ClipCursor(LPRECT lpNewClipRect
)
370 CopyRect(&ClipCursorRect
, lpNewClipRect
);
374 /**********************************************************************
375 * GetClipCursor [USER.309]
377 void GetClipCursor(LPRECT lpRetClipRect
)
379 if (lpRetClipRect
!= NULL
)
380 CopyRect(lpRetClipRect
, &ClipCursorRect
);