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.

370 lines
12 KiB

  1. /****************************************************************************/
  2. // acmapi.c
  3. //
  4. // Cursor manager
  5. //
  6. // Copyright (C) 1997-1999 Microsoft Corp.
  7. /****************************************************************************/
  8. #include <adcg.h>
  9. extern "C" {
  10. #define TRC_GROUP TRC_GROUP_CORE
  11. #define TRC_FILE "cmapi"
  12. #include <atrcapi.h>
  13. }
  14. #include "cm.h"
  15. #include "autil.h"
  16. #include "cd.h"
  17. #include "ih.h"
  18. CCM::CCM(CObjs* objs)
  19. {
  20. _pClientObjects = objs;
  21. }
  22. CCM::~CCM()
  23. {
  24. }
  25. /****************************************************************************/
  26. /* Name: CM_Init */
  27. /* */
  28. /* Purpose: Cursor Manager initialization */
  29. /****************************************************************************/
  30. DCVOID DCAPI CCM::CM_Init(DCVOID)
  31. {
  32. DC_BEGIN_FN("CM_Init");
  33. _pUt = _pClientObjects->_pUtObject;
  34. _pUh = _pClientObjects->_pUHObject;
  35. _pCd = _pClientObjects->_pCdObject;
  36. _pIh = _pClientObjects->_pIhObject;
  37. _pUi = _pClientObjects->_pUiObject;
  38. DC_MEMSET(&_CM, 0, sizeof(_CM));
  39. #if !defined(OS_WINCE) || defined(OS_WINCEATTACHTHREADINPUT)
  40. #ifdef OS_WIN32
  41. /************************************************************************/
  42. /* Attach input */
  43. /************************************************************************/
  44. if (!AttachThreadInput(GetCurrentThreadId(),
  45. GetWindowThreadProcessId(_pUi->UI_GetUIContainerWindow(),
  46. NULL),
  47. TRUE))
  48. {
  49. TRC_ALT((TB, _T("Failed AttachThreadInput")));
  50. }
  51. #endif
  52. #endif // !defined(OS_WINCE) || defined(OS_WINCEATTACHTHREADINPUT)
  53. DC_END_FN();
  54. } /* CM_Init */
  55. /****************************************************************************/
  56. /* Name: CM_Enable */
  57. /* */
  58. /* Purpose: Enables _CM. */
  59. /****************************************************************************/
  60. DCVOID DCAPI CCM::CM_Enable(ULONG_PTR unused)
  61. {
  62. #ifdef DC_DEBUG
  63. DCINT i;
  64. #endif
  65. DC_BEGIN_FN("CM_Enable");
  66. DC_IGNORE_PARAMETER(unused);
  67. #ifdef DC_DEBUG
  68. /************************************************************************/
  69. /* Check that cursor cache is empty */
  70. /************************************************************************/
  71. for (i = 0; i < CM_CURSOR_CACHE_SIZE; i++)
  72. {
  73. if (_CM.cursorCache[i] != NULL) {
  74. TRC_ERR((TB, _T("Cursor cache not empty")));
  75. }
  76. }
  77. #endif
  78. DC_END_FN();
  79. } /* CM_Enable */
  80. /****************************************************************************/
  81. /* Name: CM_Disable */
  82. /* */
  83. /* Purpose: Disables _CM. */
  84. /****************************************************************************/
  85. DCVOID DCAPI CCM::CM_Disable(ULONG_PTR unused)
  86. {
  87. DCINT i;
  88. DC_BEGIN_FN("CM_Disable");
  89. DC_IGNORE_PARAMETER(unused);
  90. TRC_NRM((TB, _T("CM disabled so cleaning up cached cursors")));
  91. /************************************************************************/
  92. /* Destroy any cached cursors. */
  93. /************************************************************************/
  94. for (i = 0; i < CM_CURSOR_CACHE_SIZE; i++)
  95. {
  96. if (_CM.cursorCache[i] != NULL)
  97. {
  98. #ifndef OS_WINCE
  99. DestroyCursor(_CM.cursorCache[i]);
  100. #else
  101. DestroyIcon(_CM.cursorCache[i]);
  102. #endif
  103. }
  104. _CM.cursorCache[i] = NULL;
  105. }
  106. DC_END_FN();
  107. } /* CM_Disable */
  108. /****************************************************************************/
  109. // CM_NullSystemPointerPDU
  110. //
  111. // Handles a null-pointer PDU from server.
  112. /****************************************************************************/
  113. void DCAPI CCM::CM_NullSystemPointerPDU(void)
  114. {
  115. DC_BEGIN_FN("CM_NullSystemPointerPDU");
  116. // Call IH to enable it to set the cursor shape. Must do this
  117. // synchronously as we may receive a very large number of cursor
  118. // shape changes - for example when running MS Office 97 setup.
  119. TRC_NRM((TB, _T("Set cursor handle to NULL")));
  120. _pCd->CD_DecoupleSimpleNotification(CD_SND_COMPONENT, _pIh,
  121. CD_NOTIFICATION_FUNC(CIH,IH_SetCursorShape),
  122. (ULONG_PTR)(LPVOID)NULL);
  123. DC_END_FN();
  124. }
  125. /****************************************************************************/
  126. // CM_DefaultSystemPointerPDU
  127. //
  128. // Handles a default-pointer PDU from server.
  129. /****************************************************************************/
  130. void DCAPI CCM::CM_DefaultSystemPointerPDU(void)
  131. {
  132. DC_BEGIN_FN("CM_DefaultSystemPointerPDU");
  133. // Call IH to enable it to set the cursor shape. Must do this
  134. // synchronously as we may receive a very large number of cursor
  135. // shape changes - for example when running MS Office 97 setup.
  136. TRC_NRM((TB, _T("Set cursor handle to default arrow")));
  137. _pCd->CD_DecoupleSimpleNotification(CD_SND_COMPONENT, _pIh,
  138. CD_NOTIFICATION_FUNC(CIH, IH_SetCursorShape),
  139. (ULONG_PTR)(LPVOID)CM_DEFAULT_ARROW_CURSOR_HANDLE);
  140. DC_END_FN();
  141. }
  142. /****************************************************************************/
  143. // CM_MonoPointerPDU
  144. //
  145. // Handles a default-pointer PDU from server.
  146. /****************************************************************************/
  147. HRESULT DCAPI CCM::CM_MonoPointerPDU(
  148. TS_MONOPOINTERATTRIBUTE UNALIGNED FAR *pAttr,
  149. DCUINT dataLen)
  150. {
  151. HRESULT hr = S_OK;
  152. HCURSOR oldHandle, newHandle;
  153. DC_BEGIN_FN("CM_MonoPointerPDU");
  154. // Save old mono cursor handle.
  155. TRC_NRM((TB, _T("Mono Pointer")));
  156. oldHandle = _CM.cursorCache[CM_MONO_CACHE_INDEX];
  157. // Create the new cursor.
  158. // SECURITY: 555587 Must pass size of order on to create<XXX>cursor
  159. hr = CMCreateMonoCursor(pAttr, dataLen, &newHandle);
  160. DC_QUIT_ON_FAIL(hr);
  161. _CM.cursorCache[CM_MONO_CACHE_INDEX] = newHandle;
  162. if (newHandle == NULL) {
  163. // Failed to create cursor - use default.
  164. TRC_ALT((TB, _T("Failed to create mono cursor")));
  165. newHandle = CM_DEFAULT_ARROW_CURSOR_HANDLE;
  166. }
  167. // Call IH to enable it to set the cursor shape. Must do this
  168. // synchronously as we may receive a very large number of cursor
  169. // shape changes - for example when running MS Office 97 setup.
  170. TRC_NRM((TB, _T("Set cursor handle to %p"), newHandle));
  171. _pCd->CD_DecoupleSimpleNotification(CD_SND_COMPONENT, _pIh,
  172. CD_NOTIFICATION_FUNC(CIH, IH_SetCursorShape),
  173. (ULONG_PTR)(LPVOID)newHandle);
  174. // Destroy any old handle if required, and remove from cache.
  175. if (oldHandle != NULL) {
  176. #ifndef OS_WINCE
  177. DestroyCursor(oldHandle);
  178. #else // OS_WINCE
  179. DestroyIcon(oldHandle);
  180. #endif // OS_WINCE
  181. }
  182. DC_EXIT_POINT:
  183. DC_END_FN();
  184. return hr;
  185. }
  186. /****************************************************************************/
  187. // CM_PositionPDU
  188. //
  189. // Handles a position-pointer PDU from server.
  190. /****************************************************************************/
  191. void DCAPI CCM::CM_PositionPDU(TS_POINT16 UNALIGNED FAR *pPoint)
  192. {
  193. POINT MousePos;
  194. DC_BEGIN_FN("CM_PositionPDU");
  195. // Adjust position to local screen coordinates.
  196. MousePos.x = pPoint->x;
  197. MousePos.y = pPoint->y;
  198. TRC_NRM((TB, _T("PointerPositionUpdate: (%d, %d)"), MousePos.x, MousePos.y));
  199. // Decouple to IH - can only set the pointer if we have the
  200. // input focus.
  201. _pCd->CD_DecoupleNotification(CD_SND_COMPONENT, _pIh, CD_NOTIFICATION_FUNC(CIH,IH_SetCursorPos),
  202. &MousePos,sizeof(MousePos));
  203. DC_END_FN();
  204. }
  205. /****************************************************************************/
  206. // CM_ColorPointerPDU
  207. //
  208. // Handles a color-pointer PDU from server.
  209. /****************************************************************************/
  210. HRESULT DCAPI CCM::CM_ColorPointerPDU(
  211. TS_COLORPOINTERATTRIBUTE UNALIGNED FAR *pAttr,
  212. DCUINT dataLen)
  213. {
  214. HRESULT hr = S_OK;
  215. HCURSOR oldHandle, newHandle;
  216. DC_BEGIN_FN("CM_ColorPointerPDU");
  217. // Create a new color cursor.
  218. // SECURITY: 555587 Must pass dataLen to CMCreate<XXX>Cursor
  219. hr = CMCreateNewColorCursor(pAttr->cacheIndex, pAttr, dataLen, &newHandle, &oldHandle);
  220. DC_QUIT_ON_FAIL(hr);
  221. // Call IH to enable it to set the cursor shape. Must do this
  222. // synchronously as we may receive a very large number of cursor
  223. // shape changes - for example when running MS Office 97 setup.
  224. TRC_NRM((TB, _T("Set cursor handle to %p"), newHandle));
  225. _pCd->CD_DecoupleSimpleNotification(CD_SND_COMPONENT, _pIh,
  226. CD_NOTIFICATION_FUNC(CIH,IH_SetCursorShape),
  227. (ULONG_PTR)(LPVOID)newHandle);
  228. // Destroy any old handle if required, and remove from cache.
  229. if (oldHandle != NULL) {
  230. #ifndef OS_WINCE
  231. DestroyCursor(oldHandle);
  232. #else // OS_WINCE
  233. DestroyIcon(oldHandle);
  234. #endif // OS_WINCE
  235. }
  236. DC_EXIT_POINT:
  237. DC_END_FN();
  238. return hr;
  239. }
  240. /****************************************************************************/
  241. // CM_CachedPointerPDU
  242. //
  243. // Handles a cached-pointer PDU from server.
  244. /****************************************************************************/
  245. void DCAPI CCM::CM_CachedPointerPDU(unsigned CacheIndex)
  246. {
  247. HCURSOR newHandle;
  248. DC_BEGIN_FN("CM_CachedPointerPDU");
  249. // Get the cursor handle from the cache.
  250. // SECURITY: Not checking cacheIndex because we can succeeded
  251. // even with an invalid index
  252. newHandle = CMGetCachedCursor(CacheIndex);
  253. // Call IH to enable it to set the cursor shape. Must do this
  254. // synchronously as we may receive a very large number of cursor
  255. // shape changes - for example when running MS Office 97 setup.
  256. TRC_NRM((TB, _T("Set cursor handle to %p"), newHandle));
  257. _pCd->CD_DecoupleSimpleNotification(CD_SND_COMPONENT, _pIh,
  258. CD_NOTIFICATION_FUNC(CIH,IH_SetCursorShape),
  259. (ULONG_PTR)(LPVOID)newHandle);
  260. DC_END_FN();
  261. }
  262. /****************************************************************************/
  263. // CM_PointerPDU
  264. //
  265. // Handles a new-protocol pointer PDU from server.
  266. /****************************************************************************/
  267. HRESULT DCAPI CCM::CM_PointerPDU(TS_POINTERATTRIBUTE UNALIGNED FAR *pAttr,
  268. DCUINT dataLen)
  269. {
  270. HRESULT hr = S_OK;
  271. HCURSOR oldHandle, newHandle;
  272. DC_BEGIN_FN("CM_PointerPDU");
  273. // Create a new cursor - may be mono or color.
  274. // SECURITY: 555587 must pass data length to CMCreate<XXX>Cursor
  275. hr = CMCreateNewCursor(pAttr, dataLen, &newHandle, &oldHandle);
  276. DC_QUIT_ON_FAIL(hr);
  277. // Call IH to enable it to set the cursor shape. Must do this
  278. // synchronously as we may receive a very large number of cursor
  279. // shape changes - for example when running MS Office 97 setup.
  280. TRC_NRM((TB, _T("Set cursor handle to %p"), newHandle));
  281. _pCd->CD_DecoupleSimpleNotification(CD_SND_COMPONENT, _pIh,
  282. CD_NOTIFICATION_FUNC(CIH,IH_SetCursorShape),
  283. (ULONG_PTR)(LPVOID)newHandle);
  284. // Destroy any old handle if required, and remove from cache.
  285. if (oldHandle != NULL) {
  286. #ifndef OS_WINCE
  287. DestroyCursor(oldHandle);
  288. #else // OS_WINCE
  289. DestroyIcon(oldHandle);
  290. #endif // OS_WINCE
  291. }
  292. DC_EXIT_POINT:
  293. DC_END_FN();
  294. return hr;
  295. }