Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

393 lines
11 KiB

  1. /*++
  2. *
  3. * WOW v1.0
  4. *
  5. * Copyright (c) 1991, Microsoft Corporation
  6. *
  7. * WUCURSOR.C
  8. * WOW32 16-bit User API support
  9. *
  10. * History:
  11. * Created 07-Mar-1991 by Jeff Parsons (jeffpar)
  12. --*/
  13. #include "precomp.h"
  14. #pragma hdrstop
  15. MODNAME(wucursor.c);
  16. /*++
  17. void ClipCursor(<lpRect>)
  18. LPRECT <lpRect>;
  19. The %ClipCursor% function confines the cursor to the rectangle on the
  20. display screen given by the <lpRect> parameter. If a subsequent cursor
  21. position, given with the %SetCursorPos% function or the mouse, lies outside
  22. the rectangle, Windows automatically adjusts the position to keep the cursor
  23. inside. If <lpRect> is NULL, the cursor is free to move anywhere on the
  24. display screen.
  25. <lpRect>
  26. Points to a %RECT% structure that contains the screen coordinates
  27. of the upper-left and lower-right corners of the confining rectangle.
  28. This function does not return a value.
  29. The cursor is a shared resource. An application that has confined the cursor
  30. to a given rectangle must free it before relinquishing control to another
  31. application.
  32. --*/
  33. ULONG FASTCALL WU32ClipCursor(PVDMFRAME pFrame)
  34. {
  35. RECT t1, *p1;
  36. register PCLIPCURSOR16 parg16;
  37. GETARGPTR(pFrame, sizeof(CLIPCURSOR16), parg16);
  38. p1 = GETRECT16(parg16->f1, &t1);
  39. ClipCursor(
  40. p1
  41. );
  42. FREEARGPTR(parg16);
  43. RETURN(0);
  44. }
  45. /*++
  46. HCURSOR CreateCursor(<hInstance>, <nXhotspot>, <nYhotspot>, <nWidth>,
  47. <nHeight>, <lpANDbitPlane>, <lpXORbitPlane>)
  48. HANDLE <hInstance>;
  49. int <nXhotspot>;
  50. int <nYhotspot>;
  51. int <nWidth>;
  52. int <nHeight>;
  53. LPSTR <lpANDbitPlane>;
  54. LPSTR <lpXORbitPlane>;
  55. The %CreateCursor% function creates a cursor that has specified width,
  56. height, and bit patterns.
  57. <hInstance>
  58. Identifies an instance of the module creating the cursor.
  59. <nXhotspot>
  60. Specifies the horizontal position of the cursor hotspot.
  61. <nYhotspot>
  62. Specifies the vertical position of the cursor hotspot.
  63. <nWidth>
  64. Specifies the width in pixels of the cursor.
  65. <nHeight>
  66. Specifies the height in pixels of the cursor.
  67. <lpANDbitPlane>
  68. Points to an array of bytes containing the bit values for the AND mask
  69. of the cursor. This can be the bits of a device-dependent monochrome
  70. bitmap.
  71. <lpXORbitPlane>
  72. Points to an array of bytes containing the bit values for the XOR mask
  73. of the cursor. This can be the bits of a device-dependent monochrome
  74. bitmap.
  75. The return value identifies the cursor if the function was successful.
  76. Otherwise, it is NULL.
  77. --*/
  78. ULONG FASTCALL WU32CreateCursor(PVDMFRAME pFrame)
  79. {
  80. ULONG ul;
  81. register PCREATECURSOR16 parg16;
  82. int nWidth;
  83. int nHeight;
  84. int nPlanes;
  85. int nBitsPixel;
  86. DWORD nBytesAND;
  87. DWORD nBytesXOR;
  88. LPBYTE lpBitsAND;
  89. LPBYTE lpBitsXOR;
  90. int ScanLen16;
  91. HANDLE h32;
  92. HAND16 h16;
  93. HAND16 hInst16;
  94. GETARGPTR(pFrame, sizeof(CREATECURSOR16), parg16);
  95. hInst16 = parg16->f1;
  96. nWidth = INT32(parg16->f4);
  97. nHeight = INT32(parg16->f5);
  98. nPlanes = 1; /* MONOCHROME BITMAP */
  99. nBitsPixel = 1; /* MONOCHROME BITMAP */
  100. /*
  101. ** Convert the AND mask bits
  102. */
  103. ScanLen16 = (((nWidth*nBitsPixel)+15)/16) * 2 ; // bytes/scan in 16 bit world
  104. nBytesAND = ScanLen16*nHeight*nPlanes;
  105. GETVDMPTR(parg16->f6, nBytesAND, lpBitsAND);
  106. /*
  107. ** Convert the XOR mask bits
  108. */
  109. ScanLen16 = (((nWidth*nBitsPixel)+15)/16) * 2 ; // bytes/scan in 16 bit world
  110. nBytesXOR = ScanLen16*nHeight*nPlanes;
  111. GETVDMPTR(parg16->f7, nBytesXOR, lpBitsXOR);
  112. h32 = (HANDLE)CreateCursor(HMODINST32(hInst16),INT32(parg16->f2),
  113. INT32(parg16->f3),
  114. nWidth, nHeight, lpBitsAND, lpBitsXOR);
  115. if (h32) {
  116. h16 = (HAND16)W32Create16BitCursorIcon(hInst16,
  117. INT32(parg16->f2), INT32(parg16->f3),
  118. nWidth, nHeight, nPlanes, nBitsPixel,
  119. lpBitsAND, lpBitsXOR,
  120. nBytesAND, nBytesXOR);
  121. ul = SetupCursorIconAlias(hInst16, h32, h16,
  122. HANDLE_TYPE_CURSOR, NULL, (WORD)NULL);
  123. } else {
  124. ul = 0;
  125. }
  126. FREEARGPTR(parg16);
  127. RETURN(ul);
  128. }
  129. /*++
  130. BOOL DestroyCursor(<hCursor>)
  131. HCURSOR <hCursor>;
  132. The %DestroyCursor% function destroys a cursor that was previously created
  133. by the %CreateCursor% function and frees any memory that the cursor
  134. occupied. It should not be used to destroy any cursor that was not created
  135. with the %CreateCursor% function.
  136. <hCursor>
  137. Identifies the cursor to be destroyed. The cursor must not be in current
  138. use.
  139. The return value is TRUE if the function was successful. It is FALSE if
  140. the function failed.
  141. --*/
  142. ULONG FASTCALL WU32DestroyCursor(PVDMFRAME pFrame)
  143. {
  144. ULONG ul;
  145. register PDESTROYCURSOR16 parg16;
  146. GETARGPTR(pFrame, sizeof(DESTROYCURSOR16), parg16);
  147. if (ul = GETBOOL16(DestroyCursor(HCURSOR32(parg16->f1))))
  148. FREEHCURSOR16(parg16->f1);
  149. FREEARGPTR(parg16);
  150. RETURN(ul);
  151. }
  152. /*++
  153. HCURSOR SetCursor(<hCursor>)
  154. HCURSOR <hCursor>;
  155. The %SetCursor% function sets the cursor shape to the shape specified by the
  156. <hCursor> parameter. The cursor is set only if the new shape is different
  157. from the current shape. Otherwise, the function returns immediately. The
  158. %SetCursor% function is quite fast if the cursor identified by the <hCursor>
  159. parameter is the same as the current cursor.
  160. If <hCursor> is NULL, the cursor is removed from the screen.
  161. <hCursor>
  162. Identifes the cursor resource. The resource must have been loaded
  163. previously by using the %LoadCursor% function.
  164. The return value identifies the cursor resource that defines the previous
  165. cursor shape. It is NULL if there is no previous shape.
  166. The cursor is a shared resource. A window that uses the cursor should set
  167. the shape only when the cursor is in its client area or when it is capturing
  168. all mouse input. In systems without a mouse, the window should restore the
  169. previous cursor shape before the cursor leaves the client area or before the
  170. window relinquishes control to another window.
  171. Any application that needs to change the shape of the cursor while it is in
  172. a window must make sure the class cursor for the given window's class is set
  173. to NULL. If the class cursor is not NULL, Windows restores the previous
  174. shape each time the mouse is moved.
  175. --*/
  176. ULONG FASTCALL WU32SetCursor(PVDMFRAME pFrame)
  177. {
  178. ULONG ul;
  179. register PSETCURSOR16 parg16;
  180. GETARGPTR(pFrame, sizeof(SETCURSOR16), parg16);
  181. ul = GETHCURSOR16(SetCursor(
  182. HCURSOR32(parg16->f1)
  183. ));
  184. FREEARGPTR(parg16);
  185. RETURN(ul);
  186. }
  187. /*++
  188. void SetCursorPos(<X>, <Y>)
  189. int <X>;
  190. int <Y>;
  191. The %SetCursorPos% function moves the cursor to the screen coordinates given
  192. by the <X> and <Y> parameters. If the new coordinates are not within the
  193. screen rectangle set by the most recent %ClipCursor% function, Windows
  194. automatically adjusts the coordinates so that the cursor stays within the
  195. rectangle.
  196. <X>
  197. Specifies the new x-coordinate (in screen coordinates) of the cursor.
  198. <Y>
  199. Specifies the new <y>-coordinate (in screen coordinates) of the
  200. cursor.
  201. This function does not return a value.
  202. The cursor is a shared resource. A window should move the cursor only when
  203. the cursor is in its client area.
  204. --*/
  205. ULONG FASTCALL WU32SetCursorPos(PVDMFRAME pFrame)
  206. {
  207. register PSETCURSORPOS16 parg16;
  208. GETARGPTR(pFrame, sizeof(SETCURSORPOS16), parg16);
  209. SetCursorPos(
  210. INT32(parg16->f1),
  211. INT32(parg16->f2)
  212. );
  213. FREEARGPTR(parg16);
  214. RETURN(0);
  215. }
  216. /*++
  217. int ShowCursor(<fShow>)
  218. BOOL <fShow>;
  219. The %ShowCursor% function shows or hides the cursor. When the %ShowCursor%
  220. function is called, an internal display counter is incremented by one if the
  221. <fShow> parameter is TRUE, or decremented by one if the <fShow> parameter is
  222. FALSE. If the internal display counter is greater then or equal to zero, the
  223. cursor is displayed. If the counter is less then zero, the cursor is
  224. hidden. Calls to the %ShowCursor% function are accumulative: for each call
  225. to hide the cursor, a corresponding call must be made to show the cursor.
  226. <fShow>
  227. Specifies whether the display count is to be increased or decreased. The
  228. display count is increased if fShow is TRUE. Otherwise, it is
  229. decreased.
  230. The return value specifies the new display count.
  231. When Windows is first started, the display count is zero if a mouse is
  232. installed or -1 if no mouse is installed.
  233. The cursor is a shared resource. A window that hides the cursor should show
  234. the cursor before the cursor leaves its client area, or before the window
  235. relinquishes control to another window.
  236. --*/
  237. ULONG FASTCALL WU32ShowCursor(PVDMFRAME pFrame)
  238. {
  239. ULONG ul;
  240. register PSHOWCURSOR16 parg16;
  241. GETARGPTR(pFrame, sizeof(SHOWCURSOR16), parg16);
  242. ul = GETINT16(ShowCursor(
  243. BOOL32(parg16->f1)
  244. ));
  245. FREEARGPTR(parg16);
  246. RETURN(ul);
  247. }
  248. //**************************************************************************
  249. // This handles both LoadIcon and LoadCursor
  250. //
  251. //**************************************************************************
  252. ULONG FASTCALL WU32LoadCursor(PVDMFRAME pFrame)
  253. {
  254. ULONG ul = 0;
  255. PSZ psz2;
  256. LPBYTE pResData = NULL;
  257. register PLOADCURSOR16 parg16;
  258. BOOL fIsCursor;
  259. HAND16 hInst16;
  260. HAND16 hRes16;
  261. LPWSTR lpUniName_CursorIcon;
  262. GETARGPTR(pFrame, sizeof(LOADCURSOR16), parg16);
  263. GETPSZIDPTR(parg16->f2, psz2);
  264. GETMISCPTR (parg16->f3, pResData);
  265. fIsCursor = ((WORD)parg16->f7 == (WORD)RT_CURSOR);
  266. hInst16 = FETCHWORD(parg16->f1);
  267. hRes16 = parg16->f5;
  268. if (HIWORD(psz2) != (WORD) NULL) {
  269. if (!(MBToWCS(psz2, -1, &lpUniName_CursorIcon, -1, TRUE))) {
  270. FREEMISCPTR(pResData);
  271. FREEPSZIDPTR(psz2);
  272. FREEARGPTR(parg16);
  273. RETURN(ul);
  274. }
  275. }
  276. else {
  277. lpUniName_CursorIcon = (LPWSTR)psz2;
  278. }
  279. ul = (ULONG) (pfnOut.pfnServerLoadCreateCursorIcon)(HINSTRES32(hInst16),
  280. (LPTSTR) NULL, // pszModName unused by user32
  281. parg16->f6,
  282. (LPCTSTR) lpUniName_CursorIcon,
  283. parg16->f4,
  284. pResData,
  285. (LPTSTR) parg16->f7,
  286. 0);
  287. if (ul)
  288. ul = SetupResCursorIconAlias(hInst16, (HAND32)ul,
  289. psz2, hRes16,
  290. fIsCursor ? HANDLE_TYPE_CURSOR : HANDLE_TYPE_ICON);
  291. if (HIWORD(psz2) != (WORD) NULL) {
  292. LocalFree (lpUniName_CursorIcon);
  293. }
  294. FREEMISCPTR(pResData);
  295. FREEPSZIDPTR(psz2);
  296. FREEARGPTR(parg16);
  297. RETURN(ul);
  298. }