Source code of Windows XP (NT5)
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.

3825 lines
95 KiB

  1. #include "precomp.h"
  2. //
  3. // CM.CPP
  4. // Cursor Manager
  5. //
  6. // Copyright(c) Microsoft 1997-
  7. //
  8. #define MLZ_FILE_ZONE ZONE_CORE
  9. //
  10. // CM_ShareStarting()
  11. // Creates resources used by the share
  12. //
  13. BOOL ASShare::CM_ShareStarting(void)
  14. {
  15. BOOL rc = FALSE;
  16. HBITMAP hbmpT;
  17. ICONINFO cursorInfo;
  18. char szTmp[MAX_CURSOR_TAG_FONT_NAME_LENGTH];
  19. DebugEntry(ASShare::CM_ShareStarting);
  20. //
  21. // Create the hatching brush we will use to make shadow cursors
  22. // distinguishable from real cursors.
  23. //
  24. hbmpT = LoadBitmap(g_asInstance, MAKEINTRESOURCE(IDB_HATCH32X32) );
  25. m_cmHatchBrush = CreatePatternBrush(hbmpT);
  26. DeleteBitmap(hbmpT);
  27. if (!m_cmHatchBrush)
  28. {
  29. ERROR_OUT(("CM_ShareStarting: Failed to created hatched brush"));
  30. DC_QUIT;
  31. }
  32. m_cmArrowCursor = LoadCursor(NULL, IDC_ARROW);
  33. if (!m_cmArrowCursor)
  34. {
  35. ERROR_OUT(("CM_ShareStarting: Failed to load cursors"));
  36. DC_QUIT;
  37. }
  38. // Get the arrow hotspot
  39. GetIconInfo(m_cmArrowCursor, &cursorInfo);
  40. m_cmArrowCursorHotSpot.x = cursorInfo.xHotspot;
  41. m_cmArrowCursorHotSpot.y = cursorInfo.yHotspot;
  42. DeleteBitmap(cursorInfo.hbmMask);
  43. if (cursorInfo.hbmColor)
  44. DeleteBitmap(cursorInfo.hbmColor);
  45. //
  46. // Get the size of the cursor on this system. (Cursor bitmaps are word
  47. // padded 1bpp).
  48. //
  49. m_cmCursorWidth = GetSystemMetrics(SM_CXCURSOR);
  50. m_cmCursorHeight = GetSystemMetrics(SM_CYCURSOR);
  51. //
  52. // Load the name of the font which will be used for creating cursor
  53. // tags. It makes sense to have this in a resource, so it can be
  54. // localized.
  55. //
  56. LoadString(g_asInstance, IDS_FONT_CURSORTAG, szTmp, sizeof(szTmp));
  57. m_cmCursorTagFont = CreateFont(CURSOR_TAG_FONT_HEIGHT, 0, 0, 0, FW_NORMAL,
  58. FALSE, FALSE, FALSE, DEFAULT_CHARSET,
  59. OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS,
  60. DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE,
  61. szTmp);
  62. if (!m_cmCursorTagFont)
  63. {
  64. ERROR_OUT(("CM_ShareStarting: couldn't create cursor tag font"));
  65. DC_QUIT;
  66. }
  67. rc = TRUE;
  68. DC_EXIT_POINT:
  69. DebugExitBOOL(ASShare::CM_ShareStarting, rc);
  70. return(rc);
  71. }
  72. //
  73. // CM_ShareEnded()
  74. // Frees resources used by the share
  75. //
  76. void ASShare::CM_ShareEnded(void)
  77. {
  78. DebugEntry(ASShare::CM_ShareEnded);
  79. //
  80. // Free cursor tag font
  81. //
  82. if (m_cmCursorTagFont != NULL)
  83. {
  84. DeleteFont(m_cmCursorTagFont);
  85. m_cmCursorTagFont = NULL;
  86. }
  87. //
  88. // Free shadow cursor dither brush
  89. //
  90. if (m_cmHatchBrush != NULL)
  91. {
  92. DeleteBrush(m_cmHatchBrush);
  93. m_cmHatchBrush = NULL;
  94. }
  95. DebugExitVOID(ASShare::CM_ShareEnded);
  96. }
  97. //
  98. // CM_PartyJoiningShare()
  99. //
  100. BOOL ASShare::CM_PartyJoiningShare(ASPerson * pasPerson)
  101. {
  102. BOOL rc = FALSE;
  103. DebugEntry(ASShare::CM_PartyJoiningShare);
  104. ValidatePerson(pasPerson);
  105. pasPerson->cmhRemoteCursor = m_cmArrowCursor;
  106. pasPerson->cmHotSpot = m_cmArrowCursorHotSpot;
  107. ASSERT(pasPerson->cmPos.x == 0);
  108. ASSERT(pasPerson->cmPos.y == 0);
  109. rc = TRUE;
  110. DebugExitBOOL(ASShare::CM_PartyJoiningShare, rc);
  111. return(rc);
  112. }
  113. //
  114. // CM_PartyLeftShare()
  115. //
  116. // See cm.h for description.
  117. //
  118. void ASShare::CM_PartyLeftShare(ASPerson * pasPerson)
  119. {
  120. DebugEntry(ASShare::CM_PartyLeftShare);
  121. ValidatePerson(pasPerson);
  122. ASSERT(!pasPerson->ccmRxCache);
  123. ASSERT(!pasPerson->acmRxCache);
  124. DebugExitVOID(ASShare::CM_PartyLeftShare);
  125. }
  126. //
  127. // CM_HostStarting()
  128. //
  129. // Called when we start to host. Creates the outgoing cursor cache
  130. //
  131. BOOL ASHost::CM_HostStarting(void)
  132. {
  133. BOOL rc = FALSE;
  134. DebugEntry(ASHost::CM_HostStarting);
  135. //
  136. // Calculate actual size of cache we will use -- if 3.0 share, it's
  137. // what we advertise in our caps, but if 2.x share, it's <= to that
  138. // amount, being the min of everybody in the share.
  139. //
  140. // We however create the cache the size we want, knowing that in a 2.x
  141. // share we'll use some subset of it. That's cool.
  142. //
  143. m_pShare->CM_RecalcCaps(TRUE);
  144. if (!CH_CreateCache(&m_cmTxCacheHandle, TSHR_CM_CACHE_ENTRIES,
  145. 1, 0, NULL))
  146. {
  147. ERROR_OUT(("Could not create CM cache"));
  148. DC_QUIT;
  149. }
  150. rc = TRUE;
  151. DC_EXIT_POINT:
  152. DebugExitBOOL(ASHost::CM_HostStarting, rc);
  153. return(rc);
  154. }
  155. //
  156. // CM_HostEnded()
  157. //
  158. // Called when we stop hosting, so we can free cursor data
  159. //
  160. void ASHost::CM_HostEnded(void)
  161. {
  162. DebugEntry(ASHost::CM_HostEnded);
  163. //
  164. // Destroy the outgoing cursor cache
  165. //
  166. if (m_cmTxCacheHandle)
  167. {
  168. CH_DestroyCache(m_cmTxCacheHandle);
  169. m_cmTxCacheHandle = 0;
  170. m_cmNumTxCacheEntries = 0;
  171. }
  172. DebugExitVOID(ASHost::CM_HostEnded);
  173. }
  174. //
  175. // CM_ViewStarting()
  176. //
  177. // Called when somebody we're viewing starts to host. We create
  178. // the incoming cursor cache (well, we create it if they are 3.0; 2.x
  179. // nodes populated it even when not hosting).
  180. //
  181. BOOL ASShare::CM_ViewStarting(ASPerson * pasPerson)
  182. {
  183. BOOL rc = FALSE;
  184. DebugEntry(ASShare::CM_ViewStarting);
  185. ValidatePerson(pasPerson);
  186. if (!CMCreateIncoming(pasPerson))
  187. {
  188. ERROR_OUT(("CM_ViewStarting: can't create cursor cache for [%d]",
  189. pasPerson->mcsID));
  190. DC_QUIT;
  191. }
  192. rc = TRUE;
  193. DC_EXIT_POINT:
  194. DebugExitBOOL(ASShare::CM_ViewStarting, rc);
  195. return(rc);
  196. }
  197. //
  198. // CM_ViewEnded()
  199. //
  200. // Called when somebody we are viewing has stopped hosting. We free up
  201. // cursor data needed to handle what they send us (well, for 3.0 dudes we
  202. // do; for 2.x dudes we keep it as long as they are in a share).
  203. //
  204. void ASShare::CM_ViewEnded(ASPerson * pasPerson)
  205. {
  206. DebugEntry(ASShare::CM_ViewEnded);
  207. ValidatePerson(pasPerson);
  208. // Free cursor cache
  209. CMFreeIncoming(pasPerson);
  210. DebugExitVOID(ASShare::CM_ViewEnded);
  211. }
  212. //
  213. // CMCreateIncoming()
  214. // Creates cursor cache for person.
  215. // If 3.0 node, we create it when they start to host
  216. // If 2.x node, we create it when they join the share
  217. //
  218. BOOL ASShare::CMCreateIncoming(ASPerson * pasPerson)
  219. {
  220. BOOL rc = FALSE;
  221. DebugEntry(ASShare::CMCreateIncoming);
  222. if (!pasPerson->cpcCaps.cursor.capsCursorCacheSize)
  223. {
  224. //
  225. // This person has no cursor cache; don't create one.
  226. //
  227. WARNING_OUT(("CMCreateIncoming: person [%d] has no cursor cache size", pasPerson->mcsID));
  228. rc = TRUE;
  229. DC_QUIT;
  230. }
  231. pasPerson->ccmRxCache = pasPerson->cpcCaps.cursor.capsCursorCacheSize;
  232. pasPerson->acmRxCache = new CACHEDCURSOR[pasPerson->ccmRxCache];
  233. if (!pasPerson->acmRxCache)
  234. {
  235. ERROR_OUT(("CMCreateIncoming: can't create cursor cache for node [%d]", pasPerson->mcsID));
  236. DC_QUIT;
  237. }
  238. ZeroMemory(pasPerson->acmRxCache, sizeof(CACHEDCURSOR) * pasPerson->ccmRxCache);
  239. rc = TRUE;
  240. DC_EXIT_POINT:
  241. DebugExitBOOL(ASShare::CMCreateIncoming, rc);
  242. return(rc);
  243. }
  244. //
  245. // CMFreeIncoming()
  246. // Frees cursor cache for person.
  247. // If 3.0 node, we free it when they stop hosting
  248. // If 2.x node, we free it when they leave the share
  249. //
  250. void ASShare::CMFreeIncoming(ASPerson * pasPerson)
  251. {
  252. UINT irx;
  253. POINT cursorPos;
  254. HWND hwnd;
  255. HCURSOR hCurCursor;
  256. DebugEntry(ASShare::CMFreeIncoming);
  257. hCurCursor = ::GetCursor();
  258. if (pasPerson->acmRxCache)
  259. {
  260. for (irx = 0; irx < pasPerson->ccmRxCache; irx++)
  261. {
  262. if (pasPerson->acmRxCache[irx].hCursor != NULL)
  263. {
  264. if (pasPerson->acmRxCache[irx].hCursor == hCurCursor)
  265. {
  266. //
  267. // We're about to destroy the current cursor. Reset it.
  268. // Note that this can only happen when there's an active
  269. // frame for this host. And that frame must be about
  270. // to go away, in which case USER will jiggle the cursor
  271. // anyway. So we don't need to do more than this.
  272. //
  273. ::SetCursor(m_cmArrowCursor);
  274. }
  275. if (pasPerson->acmRxCache[irx].hCursor == pasPerson->cmhRemoteCursor)
  276. {
  277. pasPerson->cmhRemoteCursor = NULL;
  278. }
  279. ::DestroyCursor(pasPerson->acmRxCache[irx].hCursor);
  280. pasPerson->acmRxCache[irx].hCursor = NULL;
  281. }
  282. }
  283. pasPerson->ccmRxCache = 0;
  284. delete[] pasPerson->acmRxCache;
  285. pasPerson->acmRxCache = NULL;
  286. }
  287. DebugExitVOID(ASShare::CMFreeIncoming);
  288. }
  289. //
  290. // CM_Periodic()
  291. //
  292. void ASHost::CM_Periodic(void)
  293. {
  294. HWND hwnd;
  295. DebugEntry(ASHost::CM_Periodic);
  296. CM_MaybeSendCursorMovedPacket();
  297. //
  298. // Find out which window is currently controlling the cursor
  299. // appearance.
  300. //
  301. hwnd = CMGetControllingWindow();
  302. if (hwnd)
  303. {
  304. UINT cursorType;
  305. CURSORDESCRIPTION desiredCursor;
  306. UINT idDelta;
  307. //
  308. // Send a cursor shape update for the controlling window if necessary
  309. //
  310. if (m_pShare->HET_WindowIsHosted(hwnd))
  311. cursorType = CM_CT_DISPLAYEDCURSOR;
  312. else
  313. cursorType = CM_CT_DEFAULTCURSOR;
  314. switch (cursorType)
  315. {
  316. case CM_CT_DEFAULTCURSOR:
  317. if ((m_cmLastCursorShape.type == CM_CD_SYSTEMCURSOR) &&
  318. (m_cmLastCursorShape.id == CM_IDC_ARROW) )
  319. {
  320. //
  321. // No change.
  322. //
  323. DC_QUIT;
  324. }
  325. desiredCursor.type = CM_CD_SYSTEMCURSOR;
  326. desiredCursor.id = CM_IDC_ARROW;
  327. break;
  328. case CM_CT_DISPLAYEDCURSOR:
  329. CMGetCurrentCursor(&desiredCursor);
  330. if (desiredCursor.type == m_cmLastCursorShape.type)
  331. {
  332. switch (desiredCursor.type)
  333. {
  334. case CM_CD_SYSTEMCURSOR:
  335. if (desiredCursor.id == m_cmLastCursorShape.id)
  336. {
  337. //
  338. // Same cursor as last time.
  339. //
  340. DC_QUIT;
  341. }
  342. break;
  343. case CM_CD_BITMAPCURSOR:
  344. //
  345. // If the cursor has already been used, ignore it.
  346. // Check if stamp is less than or equal to the last
  347. // one - assume any sufficiently large difference
  348. // is due to overflow.
  349. //
  350. idDelta = (UINT)
  351. (desiredCursor.id - m_cmLastCursorShape.id);
  352. if (((idDelta == 0) || (idDelta > 0x10000000)) &&
  353. ((g_asSharedMemory->cmCursorHidden != FALSE) == (m_cmfCursorHidden != FALSE)))
  354. {
  355. TRACE_OUT(( "No change in cursor"));
  356. DC_QUIT;
  357. }
  358. break;
  359. default:
  360. ERROR_OUT(("Invalid cursor definition"));
  361. break;
  362. }
  363. }
  364. break;
  365. default:
  366. ERROR_OUT(("cursorType invalid"));
  367. DC_QUIT;
  368. }
  369. if (desiredCursor.type == CM_CD_SYSTEMCURSOR)
  370. {
  371. if (!CMSendSystemCursor(desiredCursor.id))
  372. {
  373. //
  374. // We failed to send the system cursor, so we just exit without
  375. // updating m_cmLastCursorShape. We will attempt to send it again
  376. // on the next call to CM_Periodic.
  377. //
  378. DC_QUIT;
  379. }
  380. m_cmLastCursorShape.type = desiredCursor.type;
  381. m_cmLastCursorShape.id = desiredCursor.id;
  382. }
  383. else
  384. {
  385. //
  386. // Save the 'hidden' state.
  387. //
  388. m_cmfCursorHidden = (g_asSharedMemory->cmCursorHidden != FALSE);
  389. if (!CMSendBitmapCursor())
  390. {
  391. //
  392. // We failed to send the bitmap cursor, so we just exit without
  393. // updating m_cmLastCursorShape. We will attempt to send it again
  394. // on the next call to CM_Periodic.
  395. //
  396. DC_QUIT;
  397. }
  398. m_cmLastCursorShape.type = desiredCursor.type;
  399. m_cmLastCursorShape.id = desiredCursor.id;
  400. }
  401. }
  402. DC_EXIT_POINT:
  403. DebugExitVOID(ASHost::CM_Periodic);
  404. }
  405. //
  406. // CM_SyncOutgoing()
  407. // Forces a send of the current cursor shape/pos when we start to host or
  408. // somebody new joins the conference
  409. //
  410. void ASHost::CM_SyncOutgoing(void)
  411. {
  412. DebugEntry(ASHost::CM_SyncOutgoing);
  413. //
  414. // Mark the last cursor as unknown. On next timer tick we'll send the
  415. // current one.
  416. //
  417. m_cmLastCursorShape.type = CM_CD_UNKNOWN;
  418. m_cmLastCursorPos.x = -1;
  419. m_cmLastCursorPos.y = -1;
  420. //
  421. // Clear the cursor cache.
  422. //
  423. if (m_cmTxCacheHandle != 0)
  424. {
  425. CH_ClearCache(m_cmTxCacheHandle);
  426. }
  427. DebugExitVOID(ASHost::CM_SyncOutgoing);
  428. }
  429. //
  430. // CM_DrawShadowCursor(..)
  431. //
  432. void ASShare::CM_DrawShadowCursor(ASPerson * pasHost, HDC hdc)
  433. {
  434. HBRUSH hbrOld;
  435. HDC hdcMem;
  436. HBITMAP hbmp;
  437. HBITMAP hbmpOld;
  438. HPALETTE hpalScreen = NULL;
  439. HPALETTE hpalOldDIB = NULL;
  440. POINT ptFrame;
  441. DebugEntry(ASShare::CM_DrawShadowCursor);
  442. ValidateView(pasHost);
  443. //
  444. // Draw the shadow cursor if there is one.
  445. //
  446. if (pasHost->cmShadowOff || !pasHost->cmhRemoteCursor)
  447. {
  448. TRACE_OUT(("CM_DrawShadowCursor: no cursor to draw"));
  449. DC_QUIT;
  450. }
  451. //
  452. // The cursor position is always kept in the host's screen coordinates.
  453. // When we paint our view frame, we adjust the DC so that painting
  454. // in host coordinates works right, even though the view frame may
  455. // be scrolled over.
  456. //
  457. ptFrame.x = pasHost->cmPos.x - pasHost->cmHotSpot.x - pasHost->m_pView->m_viewPos.x;
  458. ptFrame.y = pasHost->cmPos.y - pasHost->cmHotSpot.y - pasHost->m_pView->m_viewPos.y;
  459. //
  460. // We draw a greyed cursor using the following steps.
  461. // - copy the destination window rectangle to a memory bitmap.
  462. // - draw the cursor into the memory bitmap
  463. //
  464. // [the memory bitmap now contains the window background + a non-greyed
  465. // cursor]
  466. //
  467. // - blt the window bitmap back to the memory using a 3-way ROP and a
  468. // hatched pattern bitmap. The ROP is chosen such that the 0s and 1s
  469. // in the pattern bitmap select either a bitmap pel or a destination
  470. // pel for the final result. The pattern bitmap is such that most
  471. // of the bitmap pels are copied, but a few destination pels are
  472. // left unchanged, giving a greying effect.
  473. //
  474. // - copy the resulting bitmap back into the window.
  475. //
  476. // The last two steps are done so that the cursor does not appear to
  477. // change shape as it is moved. If the 3 way blt is done back to the
  478. // screen at stage 3, the pattern stays relative to the screen coords
  479. // and hence as the cursor moves, it will lose different pels each
  480. // time and appear to deform.
  481. //
  482. // The ROP is calculated to copy the source pel where the pattern is 1
  483. // and to leave the destination pel unchanged where the pattern is 0:
  484. //
  485. // P S D R
  486. //
  487. // 0 0 0 0
  488. // 0 0 1 1
  489. // 0 1 0 0
  490. // 0 1 1 1
  491. // 1 0 0 0
  492. // 1 0 1 0
  493. // 1 1 0 1
  494. // 1 1 1 1
  495. //
  496. // ^
  497. // Read upwards -> 0xCA
  498. //
  499. // From the table in the SDK, this gives a full ROP value of 0x00CA0749
  500. //
  501. //
  502. #define GREY_ROP 0x00CA0749
  503. if (NULL == (hdcMem = CreateCompatibleDC(hdc)))
  504. {
  505. WARNING_OUT(( "Failed to create memory DC"));
  506. DC_QUIT;
  507. }
  508. if (NULL == (hbmp = CreateCompatibleBitmap(hdc, CM_MAX_CURSOR_WIDTH, CM_MAX_CURSOR_HEIGHT)))
  509. {
  510. WARNING_OUT(( "Failed to create bitmap"));
  511. DeleteDC(hdcMem);
  512. DC_QUIT;
  513. }
  514. if (NULL == (hbmpOld = SelectBitmap(hdcMem, hbmp)))
  515. {
  516. WARNING_OUT(( "Failed to select bitmap"));
  517. DeleteBitmap(hbmp);
  518. DeleteDC(hdcMem);
  519. DC_QUIT;
  520. }
  521. hbrOld = SelectBrush(hdcMem, m_cmHatchBrush);
  522. //
  523. //
  524. // We need to make sure that we have the same logical palette selected
  525. // into both DCs otherwise we will corrupt the background color info
  526. // when we do the blitting.
  527. //
  528. //
  529. hpalScreen = SelectPalette(hdc,
  530. (HPALETTE)GetStockObject(DEFAULT_PALETTE),
  531. FALSE );
  532. SelectPalette( hdc, hpalScreen, FALSE );
  533. hpalOldDIB = SelectPalette( hdcMem, hpalScreen, FALSE );
  534. RealizePalette(hdcMem);
  535. BitBlt( hdcMem,
  536. 0,
  537. 0,
  538. CM_MAX_CURSOR_WIDTH,
  539. CM_MAX_CURSOR_HEIGHT,
  540. hdc,
  541. ptFrame.x,
  542. ptFrame.y,
  543. SRCCOPY );
  544. DrawIcon(hdcMem, 0, 0, pasHost->cmhRemoteCursor);
  545. CMDrawCursorTag(pasHost, hdcMem);
  546. BitBlt( hdcMem,
  547. 0,
  548. 0,
  549. CM_MAX_CURSOR_WIDTH,
  550. CM_MAX_CURSOR_HEIGHT,
  551. hdc,
  552. ptFrame.x,
  553. ptFrame.y,
  554. GREY_ROP );
  555. BitBlt( hdc,
  556. ptFrame.x,
  557. ptFrame.y,
  558. CM_MAX_CURSOR_WIDTH,
  559. CM_MAX_CURSOR_HEIGHT,
  560. hdcMem,
  561. 0,
  562. 0,
  563. SRCCOPY );
  564. SelectBrush(hdcMem, hbrOld);
  565. SelectBitmap(hdcMem, hbmpOld);
  566. DeleteBitmap(hbmp);
  567. if (hpalOldDIB != NULL)
  568. {
  569. SelectPalette(hdcMem, hpalOldDIB, FALSE);
  570. }
  571. DeleteDC(hdcMem);
  572. DC_EXIT_POINT:
  573. DebugExitVOID(ASShare::CM_DrawShadowCursor);
  574. }
  575. //
  576. // CM_ReceivedPacket(..)
  577. //
  578. void ASShare::CM_ReceivedPacket
  579. (
  580. ASPerson * pasPerson,
  581. PS20DATAPACKET pPacket
  582. )
  583. {
  584. PCMPACKETHEADER pCMPacket;
  585. DebugEntry(ASShare::CM_ReceivedPacket);
  586. ValidatePerson(pasPerson);
  587. pCMPacket = (PCMPACKETHEADER)pPacket;
  588. //
  589. // Switch on the packet type
  590. //
  591. switch (pCMPacket->type)
  592. {
  593. case CM_CURSOR_ID:
  594. case CM_CURSOR_MONO_BITMAP:
  595. case CM_CURSOR_COLOR_BITMAP:
  596. case CM_CURSOR_COLOR_CACHE:
  597. CMReceivedCursorShapePacket(pasPerson, pCMPacket);
  598. break;
  599. case CM_CURSOR_MOVE:
  600. CMReceivedCursorMovedPacket(pasPerson, pCMPacket);
  601. break;
  602. default:
  603. ERROR_OUT(("Invalid CM data packet from [%d] of type %d",
  604. pasPerson->mcsID, pCMPacket->type));
  605. break;
  606. }
  607. DebugExitVOID(ASShare::CM_ReceivedPacket);
  608. }
  609. //
  610. // CM_ApplicationMovedCursor(..)
  611. //
  612. void ASHost::CM_ApplicationMovedCursor(void)
  613. {
  614. DebugEntry(ASHost::CM_ApplicationMovedCursor);
  615. WARNING_OUT(("CM host: cursor moved by app, tell viewers"));
  616. m_cmfSyncPos = TRUE;
  617. CM_MaybeSendCursorMovedPacket();
  618. DebugExitVOID(ASHost::CM_ApplicationMovedCursor);
  619. }
  620. //
  621. // CM_RecalcCaps()
  622. //
  623. // This calculates the CM hosting caps when
  624. // * we start to host
  625. // * we're hosting and somebody joins the share
  626. // * we're hosting and somebody leaves the share
  627. //
  628. // This can GO AWAY WHEN 2.x COMPAT IS GONE -- no more min() of cache size
  629. //
  630. void ASShare::CM_RecalcCaps(BOOL fJoiner)
  631. {
  632. ASPerson * pasT;
  633. DebugEntry(ASShare::CM_RecalcCaps);
  634. if (!m_pHost || !fJoiner)
  635. {
  636. //
  637. // Nothing to do if we're not hosting. And also, if somebody has
  638. // left, no recalculation -- 2.x didn't.
  639. //
  640. DC_QUIT;
  641. }
  642. ValidatePerson(m_pasLocal);
  643. m_pHost->m_cmNumTxCacheEntries = m_pasLocal->cpcCaps.cursor.capsCursorCacheSize;
  644. m_pHost->m_cmfUseColorCursorProtocol =
  645. (m_pasLocal->cpcCaps.cursor.capsSupportsColorCursors == CAPS_SUPPORTED);
  646. DC_EXIT_POINT:
  647. DebugExitVOID(ASShare::CM_RecalcCaps);
  648. }
  649. //
  650. // FUNCTION: CMReceivedCursorShapePacket
  651. //
  652. // DESCRIPTION:
  653. //
  654. // Processes a received cursor shape packet.
  655. //
  656. // PARAMETERS:
  657. //
  658. // personID - ID of the packet sender
  659. //
  660. // pCMPacket - pointer to the received cursor shape packet
  661. //
  662. // RETURNS: Nothing
  663. //
  664. //
  665. void ASShare::CMReceivedCursorShapePacket
  666. (
  667. ASPerson * pasPerson,
  668. PCMPACKETHEADER pCMPacket
  669. )
  670. {
  671. BOOL fSetCursorToNULL = FALSE;
  672. HCURSOR hNewCursor;
  673. HCURSOR hOldCursor = NULL;
  674. POINT newHotSpot;
  675. UINT cacheID;
  676. DebugEntry(ASShare::CMReceivedCursorShapePacket);
  677. ValidatePerson(pasPerson);
  678. //
  679. // Now create or load the new cursor.
  680. //
  681. switch (pCMPacket->type)
  682. {
  683. case CM_CURSOR_ID:
  684. CMProcessCursorIDPacket((PCMPACKETID)pCMPacket,
  685. &hNewCursor, &newHotSpot);
  686. break;
  687. case CM_CURSOR_MONO_BITMAP:
  688. case CM_CURSOR_COLOR_BITMAP:
  689. if (pCMPacket->type == CM_CURSOR_MONO_BITMAP)
  690. {
  691. cacheID = CMProcessMonoCursorPacket((PCMPACKETMONOBITMAP)pCMPacket,
  692. &hNewCursor, &newHotSpot);
  693. }
  694. else
  695. {
  696. cacheID = CMProcessColorCursorPacket((PCMPACKETCOLORBITMAP)pCMPacket,
  697. &hNewCursor, &newHotSpot );
  698. }
  699. ASSERT(pasPerson->acmRxCache);
  700. ASSERT(cacheID < pasPerson->ccmRxCache);
  701. hOldCursor = pasPerson->acmRxCache[cacheID].hCursor;
  702. if (hNewCursor != NULL)
  703. {
  704. TRACE_OUT(("Cursor using cache %u", cacheID));
  705. pasPerson->acmRxCache[cacheID].hCursor = hNewCursor;
  706. pasPerson->acmRxCache[cacheID].hotSpot = newHotSpot;
  707. }
  708. else
  709. {
  710. //
  711. // use default cursor.
  712. //
  713. TRACE_OUT(( "color cursor failed so use arrow"));
  714. pasPerson->acmRxCache[cacheID].hCursor = NULL;
  715. pasPerson->acmRxCache[cacheID].hotSpot.x = 0;
  716. pasPerson->acmRxCache[cacheID].hotSpot.y = 0;
  717. hNewCursor = m_cmArrowCursor;
  718. newHotSpot = m_cmArrowCursorHotSpot;
  719. }
  720. break;
  721. case CM_CURSOR_COLOR_CACHE:
  722. cacheID = ((PCMPACKETCOLORCACHE)pCMPacket)->cacheIndex;
  723. ASSERT(pasPerson->acmRxCache);
  724. ASSERT(cacheID < pasPerson->ccmRxCache);
  725. //
  726. // If the caching failed last time then use the default arrow
  727. // cursor.
  728. //
  729. if (pasPerson->acmRxCache[cacheID].hCursor == NULL)
  730. {
  731. TRACE_OUT(( "cache empty so use arrow"));
  732. hNewCursor = m_cmArrowCursor;
  733. newHotSpot = m_cmArrowCursorHotSpot;
  734. }
  735. else
  736. {
  737. hNewCursor = pasPerson->acmRxCache[cacheID].hCursor;
  738. newHotSpot = pasPerson->acmRxCache[cacheID].hotSpot;
  739. }
  740. break;
  741. default:
  742. WARNING_OUT(( "Unknown cursor type: %u", pCMPacket->type));
  743. DC_QUIT;
  744. }
  745. //
  746. // Destroy the old cursor. Note that for bitmap cursor packets,
  747. // we will set the cursor to the new image twice.
  748. //
  749. if (hOldCursor)
  750. {
  751. if (hOldCursor == ::GetCursor())
  752. {
  753. ::SetCursor(hNewCursor);
  754. }
  755. ::DestroyCursor(hOldCursor);
  756. }
  757. pasPerson->cmhRemoteCursor = hNewCursor;
  758. //
  759. // Decide what to do with the new cursor...
  760. //
  761. if (!pasPerson->cmShadowOff)
  762. {
  763. //
  764. // The shadow cursor is enabled so update it. It won't change state
  765. // or move, it will just repaint with the new image and/or hotspot.
  766. //
  767. TRACE_OUT(("Update shadow cursor"));
  768. CM_UpdateShadowCursor(pasPerson, pasPerson->cmShadowOff,
  769. pasPerson->cmPos.x, pasPerson->cmPos.y,
  770. newHotSpot.x, newHotSpot.y);
  771. }
  772. else
  773. {
  774. HWND hwnd;
  775. // Update the hotspot.
  776. pasPerson->cmHotSpot = newHotSpot;
  777. // Refresh if no old cursor
  778. ASSERT(pasPerson->m_pView);
  779. hwnd = CMGetControllingWindow();
  780. if (hwnd == pasPerson->m_pView->m_viewClient)
  781. {
  782. SendMessage(hwnd, WM_SETCURSOR, (WPARAM)hwnd, MAKELONG(HTCLIENT, 0));
  783. }
  784. }
  785. DC_EXIT_POINT:
  786. DebugExitVOID(ASShare::CMReceivedCursorShapePacket);
  787. }
  788. //
  789. // FUNCTION: CMProcessMonoCursorPacket
  790. //
  791. // DESCRIPTION:
  792. //
  793. // Processes a received mono cursor packet.
  794. //
  795. // PARAMETERS:
  796. //
  797. // pCMPacket - pointer to the received cursor ID packet
  798. //
  799. // phNewCursor - pointer to a HCURSOR variable that receives the handle
  800. // of a cursor that corresponds to the received packet
  801. //
  802. // pNewHotSpot - pointer to a POINT variable that receives the hot-spot
  803. // of the new cursor
  804. //
  805. // RETURNS: Nothing
  806. //
  807. //
  808. UINT ASShare::CMProcessMonoCursorPacket
  809. (
  810. PCMPACKETMONOBITMAP pCMPacket,
  811. HCURSOR* phNewCursor,
  812. LPPOINT pNewHotSpot
  813. )
  814. {
  815. UINT cbReceivedMaskBytes;
  816. LPBYTE pANDMask;
  817. LPBYTE pXORMask;
  818. DebugEntry(ASShare::CMProcessMonoCursorPacket);
  819. //
  820. // Work out the size (in bytes) of the two bitmap masks we have just
  821. // received. (Cursor bitmaps are 1bpp and word padded).
  822. //
  823. cbReceivedMaskBytes = pCMPacket->height * CM_BYTES_FROM_WIDTH(pCMPacket->width);
  824. //
  825. // NOTE: Compressed cursors are an R.11 remnant. NM 1.0 and 2.0 never
  826. // sent them specially compressed. Therefore the code to handle
  827. // decompression should be unnecessary. Let's find out!
  828. //
  829. ASSERT(pCMPacket->header.type == CM_CURSOR_MONO_BITMAP);
  830. //
  831. // Get the XOR and AND masks
  832. //
  833. pXORMask = pCMPacket->aBits;
  834. pANDMask = pXORMask + cbReceivedMaskBytes;
  835. //
  836. // Create a cursor from the definition supplied in the packet.
  837. //
  838. *phNewCursor = CMCreateMonoCursor(pCMPacket->xHotSpot,
  839. pCMPacket->yHotSpot, pCMPacket->width, pCMPacket->height,
  840. pANDMask, pXORMask);
  841. if (*phNewCursor == NULL)
  842. {
  843. WARNING_OUT(( "Failed to create hRemoteCursor"));
  844. DC_QUIT;
  845. }
  846. //
  847. // Return the hot spot.
  848. //
  849. pNewHotSpot->x = pCMPacket->xHotSpot;
  850. pNewHotSpot->y = pCMPacket->yHotSpot;
  851. DC_EXIT_POINT:
  852. DebugExitDWORD(ASShare::CMProcessMonoCursorPacket, 0);
  853. return(0);
  854. }
  855. //
  856. // FUNCTION: CMProcessColorCursorPacket
  857. //
  858. // DESCRIPTION:
  859. //
  860. // Processes a received color cursor packet.
  861. //
  862. // PARAMETERS:
  863. //
  864. // pCMPacket - pointer to the received cursor ID packet
  865. //
  866. // phNewCursor - pointer to a HCURSOR variable that receives the handle
  867. // of a cursor that corresponds to the received packet
  868. //
  869. // pNewHotSpot - pointer to a POINT variable that receives the hot-spot
  870. // of the new cursor
  871. //
  872. // RETURNS: Nothing
  873. //
  874. //
  875. UINT ASShare::CMProcessColorCursorPacket
  876. (
  877. PCMPACKETCOLORBITMAP pCMPacket,
  878. HCURSOR* phNewCursor,
  879. LPPOINT pNewHotSpot
  880. )
  881. {
  882. LPBYTE pXORBitmap;
  883. LPBYTE pANDMask;
  884. DebugEntry(ASShare::CMProcessColorCursorPacket);
  885. //
  886. // Calculate the pointers to the XOR bitmap and the AND mask within the
  887. // color cursor data.
  888. //
  889. pXORBitmap = pCMPacket->aBits;
  890. pANDMask = pXORBitmap + pCMPacket->cbXORBitmap;
  891. //
  892. // Create a cursor from the definition supplied in the packet.
  893. //
  894. *phNewCursor = CMCreateColorCursor(pCMPacket->xHotSpot, pCMPacket->yHotSpot,
  895. pCMPacket->cxWidth, pCMPacket->cyHeight, pANDMask, pXORBitmap,
  896. pCMPacket->cbANDMask, pCMPacket->cbXORBitmap);
  897. if (*phNewCursor == NULL)
  898. {
  899. WARNING_OUT(( "Failed to create color cursor"));
  900. DC_QUIT;
  901. }
  902. //
  903. // Return the hot spot.
  904. //
  905. pNewHotSpot->x = pCMPacket->xHotSpot;
  906. pNewHotSpot->y = pCMPacket->yHotSpot;
  907. DC_EXIT_POINT:
  908. DebugExitDWORD(ASShare::CMProcessColorCursorPacket, pCMPacket->cacheIndex);
  909. return(pCMPacket->cacheIndex);
  910. }
  911. //
  912. // FUNCTION: CMReceivedCursorMovedPacket
  913. //
  914. // DESCRIPTION:
  915. //
  916. // Processes a received cursor movement packet.
  917. //
  918. // PARAMETERS:
  919. //
  920. // personID - ID of the sender of this packet
  921. //
  922. // pCMPacket - pointer to the received cursor movement packet
  923. //
  924. // RETURNS: Nothing
  925. //
  926. //
  927. void ASShare::CMReceivedCursorMovedPacket
  928. (
  929. ASPerson * pasFrom,
  930. PCMPACKETHEADER pCMHeader
  931. )
  932. {
  933. ASPerson * pasControlling;
  934. PCMPACKETMOVE pCMPacket = (PCMPACKETMOVE)pCMHeader;
  935. DebugEntry(ASShare::CMReceivedCursorMovedPacket);
  936. //
  937. // Handle an incoming cursor moved packet.
  938. //
  939. ValidatePerson(pasFrom);
  940. TRACE_OUT(("Received cursor move packet from [%d] to pos (%d,%d)",
  941. pasFrom->mcsID, pCMPacket->xPos, pCMPacket->yPos));
  942. CM_UpdateShadowCursor(pasFrom, pasFrom->cmShadowOff,
  943. pCMPacket->xPos, pCMPacket->yPos,
  944. pasFrom->cmHotSpot.x, pasFrom->cmHotSpot.y);
  945. //
  946. // If we're in control of this person and it's a sync, we need to
  947. // move our cursor too, to reflect where the app really stuck it.
  948. //
  949. if ((pasFrom->m_caControlledBy == m_pasLocal) &&
  950. (pCMPacket->header.flags & CM_SYNC_CURSORPOS))
  951. {
  952. //
  953. // If our mouse is over this host's client area,
  954. // autoscroll to pos or move our cursor
  955. //
  956. WARNING_OUT(("CM SYNC pos to {%04d, %04d}", pCMPacket->xPos,
  957. pCMPacket->yPos));
  958. VIEW_SyncCursorPos(pasFrom, pCMPacket->xPos, pCMPacket->yPos);
  959. }
  960. DebugExitVOID(ASShare::CMReceivedCursorMovedPacket);
  961. }
  962. //
  963. // CM_UpdateShadowCursor()
  964. //
  965. // This repaints the host's shadow cursor in the view frame we have for him.
  966. // It is used when
  967. // * the cursor image has changed
  968. // * the cursor tag has changed (due to control changes)
  969. // * the cursor hotspot has changed
  970. // * the cursor state is changing between on and off
  971. // * the cursor has moved
  972. //
  973. void ASShare::CM_UpdateShadowCursor
  974. (
  975. ASPerson * pasPerson,
  976. BOOL cmShadowOff,
  977. int xNewPos,
  978. int yNewPos,
  979. int xNewHot,
  980. int yNewHot
  981. )
  982. {
  983. RECT rcInval;
  984. DebugEntry(ASShare::CM_UpdateShadowCursor);
  985. //
  986. // Is the remote cursor currently on?
  987. //
  988. if (!pasPerson->cmShadowOff)
  989. {
  990. if (pasPerson->m_pView)
  991. {
  992. //
  993. // We need to invalidate the old rectangle where the cursor
  994. // was. We need to adjust for the hotspot. Also, adjust for
  995. // any scrolling we may have done in the view frame.
  996. //
  997. rcInval.left = pasPerson->cmPos.x - pasPerson->cmHotSpot.x;
  998. rcInval.top = pasPerson->cmPos.y - pasPerson->cmHotSpot.y;
  999. rcInval.right = rcInval.left + m_cmCursorWidth;
  1000. rcInval.bottom = rcInval.top + m_cmCursorHeight;
  1001. VIEW_InvalidateRect(pasPerson, &rcInval);
  1002. }
  1003. }
  1004. // Update the state, position, and hotspot
  1005. pasPerson->cmShadowOff = cmShadowOff;
  1006. pasPerson->cmPos.x = xNewPos;
  1007. pasPerson->cmPos.y = yNewPos;
  1008. pasPerson->cmHotSpot.x = xNewHot;
  1009. pasPerson->cmHotSpot.y = yNewHot;
  1010. if (!pasPerson->cmShadowOff)
  1011. {
  1012. if (pasPerson->m_pView)
  1013. {
  1014. //
  1015. // We need to invalidate the new rectangle where the cursor is
  1016. // moving to. Again, we need to adjust for the hotspot, and any
  1017. // scrolling done in the view frame.
  1018. //
  1019. rcInval.left = pasPerson->cmPos.x - pasPerson->cmHotSpot.x;
  1020. rcInval.top = pasPerson->cmPos.y - pasPerson->cmHotSpot.y;
  1021. rcInval.right = rcInval.left + m_cmCursorWidth;
  1022. rcInval.bottom = rcInval.top + m_cmCursorHeight;
  1023. VIEW_InvalidateRect(pasPerson, &rcInval);
  1024. }
  1025. }
  1026. DebugExitVOID(ASShare::CM_UpdateShadowCursor);
  1027. }
  1028. void ASHost::CM_MaybeSendCursorMovedPacket(void)
  1029. {
  1030. PCMPACKETMOVE pCMPacket;
  1031. POINT cursorPos;
  1032. #ifdef _DEBUG
  1033. UINT sentSize;
  1034. #endif
  1035. DebugEntry(ASHost::CM_MaybeSendCursorMovedPacket);
  1036. //
  1037. // Get the cursor position.
  1038. //
  1039. GetCursorPos(&cursorPos);
  1040. //
  1041. // Has it changed?
  1042. //
  1043. if (m_cmfSyncPos ||
  1044. (cursorPos.x != m_cmLastCursorPos.x) ||
  1045. (cursorPos.y != m_cmLastCursorPos.y))
  1046. {
  1047. //
  1048. // Try to allocate a packet.
  1049. //
  1050. pCMPacket = (PCMPACKETMOVE)m_pShare->SC_AllocPkt(PROT_STR_MISC, g_s20BroadcastID,
  1051. sizeof(*pCMPacket));
  1052. if (!pCMPacket)
  1053. {
  1054. WARNING_OUT(("Failed to alloc CM move packet"));
  1055. DC_QUIT;
  1056. }
  1057. TRACE_OUT(("Sending cursor moved packet to pos (%d, %d)",
  1058. cursorPos.x, cursorPos.y));
  1059. //
  1060. // Fill in the fields
  1061. //
  1062. pCMPacket->header.header.data.dataType = DT_CM;
  1063. pCMPacket->header.type = CM_CURSOR_MOVE;
  1064. pCMPacket->header.flags = 0;
  1065. if (m_cmfSyncPos)
  1066. {
  1067. pCMPacket->header.flags |= CM_SYNC_CURSORPOS;
  1068. }
  1069. pCMPacket->xPos = (TSHR_UINT16)cursorPos.x;
  1070. pCMPacket->yPos = (TSHR_UINT16)cursorPos.y;
  1071. //
  1072. // Compress and send the packet.
  1073. //
  1074. if (m_pShare->m_scfViewSelf)
  1075. m_pShare->CM_ReceivedPacket(m_pShare->m_pasLocal, &(pCMPacket->header.header));
  1076. #ifdef _DEBUG
  1077. sentSize =
  1078. #endif // _DEBUG
  1079. m_pShare->DCS_CompressAndSendPacket(PROT_STR_MISC, g_s20BroadcastID,
  1080. &(pCMPacket->header.header), sizeof(*pCMPacket));
  1081. TRACE_OUT(("CM MOVE packet size: %08d, sent %08d", sizeof(*pCMPacket), sentSize));
  1082. m_cmfSyncPos = FALSE;
  1083. m_cmLastCursorPos = cursorPos;
  1084. }
  1085. DC_EXIT_POINT:
  1086. DebugExitVOID(ASHost::CM_MaybeSendCursorMovedPacket);
  1087. }
  1088. //
  1089. // FUNCTION: CMSendCursorShape
  1090. //
  1091. // DESCRIPTION:
  1092. //
  1093. // Sends a packet containing the given cursor shape (bitmap). If the
  1094. // same shape is located in the cache then a cached cursor packet is sent.
  1095. //
  1096. // PARAMETERS:
  1097. //
  1098. // pCursorShape - pointer to the cursor shape
  1099. //
  1100. // cbCursorDataSize - pointer to the cursor data size
  1101. //
  1102. // RETURNS: TRUE if successful, FALSE otherwise.
  1103. //
  1104. //
  1105. BOOL ASHost::CMSendCursorShape
  1106. (
  1107. LPCM_SHAPE pCursorShape,
  1108. UINT cbCursorDataSize
  1109. )
  1110. {
  1111. BOOL rc = FALSE;
  1112. BOOL fInCache;
  1113. LPCM_SHAPE pCacheData;
  1114. UINT iCacheEntry;
  1115. DebugEntry(ASHost::CMSendCursorShape);
  1116. fInCache = CH_SearchCache(m_cmTxCacheHandle,
  1117. (LPBYTE)pCursorShape,
  1118. cbCursorDataSize,
  1119. 0,
  1120. &iCacheEntry );
  1121. if (!fInCache)
  1122. {
  1123. pCacheData = (LPCM_SHAPE)new BYTE[cbCursorDataSize];
  1124. if (pCacheData == NULL)
  1125. {
  1126. WARNING_OUT(("Failed to alloc CM_SHAPE data"));
  1127. DC_QUIT;
  1128. }
  1129. memcpy(pCacheData, pCursorShape, cbCursorDataSize);
  1130. iCacheEntry = CH_CacheData(m_cmTxCacheHandle,
  1131. (LPBYTE)pCacheData,
  1132. cbCursorDataSize,
  1133. 0);
  1134. TRACE_OUT(( "Cache new cursor: pShape 0x%p, iEntry %u",
  1135. pCursorShape, iCacheEntry));
  1136. if (!CMSendColorBitmapCursor(pCacheData, iCacheEntry ))
  1137. {
  1138. CH_RemoveCacheEntry(m_cmTxCacheHandle, iCacheEntry);
  1139. DC_QUIT;
  1140. }
  1141. }
  1142. else
  1143. {
  1144. TRACE_OUT(("Cursor in cache: pShape 0x%p, iEntry %u",
  1145. pCursorShape, iCacheEntry));
  1146. if (!CMSendCachedCursor(iCacheEntry))
  1147. {
  1148. DC_QUIT;
  1149. }
  1150. }
  1151. //
  1152. // Return success.
  1153. //
  1154. rc = TRUE;
  1155. DC_EXIT_POINT:
  1156. DebugExitDWORD(ASHost::CMSendCursorShape, rc);
  1157. return(rc);
  1158. }
  1159. //
  1160. // FUNCTION: CMCopy1bppTo1bpp
  1161. //
  1162. // DESCRIPTION:
  1163. //
  1164. // Color conversion utility function to copy 1bpp cursor data to 1bpp (no
  1165. // conversion required).
  1166. //
  1167. // Data is assumed to be padded to word boundaries, and that the
  1168. // destination buffer is big enough to receive the 1bpp cursor data.
  1169. //
  1170. // PARAMETERS:
  1171. //
  1172. // pSrc - pointer to source data
  1173. //
  1174. // pDst - pointer to destination buffer
  1175. //
  1176. // cx - width of cursor in pixels
  1177. //
  1178. // cy - height of cursor in pixels
  1179. //
  1180. // RETURNS: Nothing
  1181. //
  1182. //
  1183. void CMCopy1bppTo1bpp( LPBYTE pSrc,
  1184. LPBYTE pDst,
  1185. UINT cx,
  1186. UINT cy )
  1187. {
  1188. UINT cbRowWidth;
  1189. DebugEntry(CMCopy1bppTo1bpp);
  1190. cbRowWidth = ((cx + 15)/16) * 2;
  1191. memcpy(pDst, pSrc, (cbRowWidth * cy));
  1192. DebugExitVOID(CMCopy1bppTo1bpp);
  1193. }
  1194. //
  1195. // FUNCTION: CMCopy4bppTo1bpp
  1196. //
  1197. // DESCRIPTION:
  1198. //
  1199. // Color conversion utility function to copy 4bpp cursor data to 1bpp.
  1200. //
  1201. // Data is assumed to be padded to word boundaries, and that the
  1202. // destination buffer is big enough to receive the 1bpp cursor data.
  1203. //
  1204. // PARAMETERS:
  1205. //
  1206. // pSrc - pointer to source data
  1207. //
  1208. // pDst - pointer to destination buffer
  1209. //
  1210. // cx - width of cursor in pixels
  1211. //
  1212. // cy - height of cursor in pixels
  1213. //
  1214. // RETURNS: Nothing
  1215. //
  1216. //
  1217. void CMCopy4bppTo1bpp( LPBYTE pSrc,
  1218. LPBYTE pDst,
  1219. UINT cx,
  1220. UINT cy )
  1221. {
  1222. UINT x;
  1223. UINT y;
  1224. UINT cbDstRowWidth;
  1225. UINT cbSrcRowWidth;
  1226. UINT cbUnpaddedDstRowWidth;
  1227. BOOL fPadByteNeeded;
  1228. BYTE Mask;
  1229. DebugEntry(CMCopy4bppTo1bpp);
  1230. cbDstRowWidth = ((cx + 15)/16) * 2;
  1231. cbUnpaddedDstRowWidth = (cx + 7) / 8;
  1232. cbSrcRowWidth = (cx + 1) / 2;
  1233. fPadByteNeeded = ((cbDstRowWidth - cbUnpaddedDstRowWidth) > 0);
  1234. for (y = 0; y < cy; y++)
  1235. {
  1236. *pDst = 0;
  1237. Mask = 0x80;
  1238. for (x = 0; x < cbSrcRowWidth; x++)
  1239. {
  1240. if (Mask == 0)
  1241. {
  1242. Mask = 0x80;
  1243. pDst++;
  1244. *pDst = 0;
  1245. }
  1246. if ((*pSrc & 0xF0) != 0)
  1247. {
  1248. *pDst |= Mask;
  1249. }
  1250. if ((*pSrc & 0x0F) != 0)
  1251. {
  1252. *pDst |= (Mask >> 1);
  1253. }
  1254. Mask >>= 2;
  1255. pSrc++;
  1256. }
  1257. if (fPadByteNeeded)
  1258. {
  1259. pDst++;
  1260. *pDst = 0;
  1261. }
  1262. pDst++;
  1263. }
  1264. DebugExitVOID(CMCopy4bppTo1bpp);
  1265. }
  1266. //
  1267. // FUNCTION: CMCopy8bppTo1bpp
  1268. //
  1269. // DESCRIPTION:
  1270. //
  1271. // Color conversion utility function to copy 8bpp cursor data to 1bpp.
  1272. //
  1273. // Data is assumed to be padded to word boundaries, and that the
  1274. // destination buffer is big enough to receive the 1bpp cursor data.
  1275. //
  1276. // PARAMETERS:
  1277. //
  1278. // pSrc - pointer to source data
  1279. //
  1280. // pDst - pointer to destination buffer
  1281. //
  1282. // cx - width of cursor in pixels
  1283. //
  1284. // cy - height of cursor in pixels
  1285. //
  1286. // RETURNS: Nothing
  1287. //
  1288. //
  1289. void CMCopy8bppTo1bpp( LPBYTE pSrc,
  1290. LPBYTE pDst,
  1291. UINT cx,
  1292. UINT cy )
  1293. {
  1294. UINT x;
  1295. UINT y;
  1296. UINT cbDstRowWidth;
  1297. UINT cbSrcRowWidth;
  1298. UINT cbUnpaddedDstRowWidth;
  1299. BOOL fPadByteNeeded;
  1300. BYTE Mask;
  1301. DebugEntry(CMCopy8bppTo1bpp);
  1302. cbDstRowWidth = ((cx + 15)/16) * 2;
  1303. cbUnpaddedDstRowWidth = (cx + 7) / 8;
  1304. cbSrcRowWidth = cx;
  1305. fPadByteNeeded = ((cbDstRowWidth - cbUnpaddedDstRowWidth) > 0);
  1306. for (y = 0; y < cy; y++)
  1307. {
  1308. *pDst = 0;
  1309. Mask = 0x80;
  1310. for (x = 0; x < cbSrcRowWidth; x++)
  1311. {
  1312. if (Mask == 0x00)
  1313. {
  1314. Mask = 0x80;
  1315. pDst++;
  1316. *pDst = 0;
  1317. }
  1318. if (*pSrc != 0)
  1319. {
  1320. *pDst |= Mask;
  1321. }
  1322. Mask >>= 1;
  1323. pSrc++;
  1324. }
  1325. if (fPadByteNeeded)
  1326. {
  1327. pDst++;
  1328. *pDst = 0;
  1329. }
  1330. pDst++;
  1331. }
  1332. DebugExitVOID(CMCopy8bppTo1bpp);
  1333. }
  1334. //
  1335. // FUNCTION: CMCopy16bppTo1bpp
  1336. //
  1337. // DESCRIPTION:
  1338. //
  1339. // Color conversion utility function to copy 16bpp cursor data to 1bpp.
  1340. //
  1341. // Data is assumed to be padded to word boundaries, and that the
  1342. // destination buffer is big enough to receive the 1bpp cursor data.
  1343. //
  1344. // PARAMETERS:
  1345. //
  1346. // pSrc - pointer to source data
  1347. //
  1348. // pDst - pointer to destination buffer
  1349. //
  1350. // cx - width of cursor in pixels
  1351. //
  1352. // cy - height of cursor in pixels
  1353. //
  1354. // RETURNS: Nothing
  1355. //
  1356. //
  1357. void CMCopy16bppTo1bpp( LPBYTE pSrc,
  1358. LPBYTE pDst,
  1359. UINT cx,
  1360. UINT cy )
  1361. {
  1362. UINT x;
  1363. UINT y;
  1364. UINT cbDstRowWidth;
  1365. UINT cbUnpaddedDstRowWidth;
  1366. BOOL fPadByteNeeded;
  1367. BYTE Mask;
  1368. DebugEntry(CMCopy16bppTo1bpp);
  1369. cbDstRowWidth = ((cx + 15)/16) * 2;
  1370. cbUnpaddedDstRowWidth = (cx + 7) / 8;
  1371. fPadByteNeeded = ((cbDstRowWidth - cbUnpaddedDstRowWidth) > 0);
  1372. for (y = 0; y < cy; y++)
  1373. {
  1374. *pDst = 0;
  1375. Mask = 0x80;
  1376. for (x = 0; x < cx; x++)
  1377. {
  1378. if (Mask == 0)
  1379. {
  1380. Mask = 0x80;
  1381. pDst++;
  1382. *pDst = 0;
  1383. }
  1384. if (*(LPTSHR_UINT16)pSrc != 0)
  1385. {
  1386. *pDst |= Mask;
  1387. }
  1388. Mask >>= 1;
  1389. pSrc += 2;
  1390. }
  1391. if (fPadByteNeeded)
  1392. {
  1393. pDst++;
  1394. *pDst = 0;
  1395. }
  1396. pDst++;
  1397. }
  1398. DebugExitVOID(CMCopy16bppTo1bpp);
  1399. }
  1400. //
  1401. // FUNCTION: CMCopy24bppTo1bpp
  1402. //
  1403. // DESCRIPTION:
  1404. //
  1405. // Color conversion utility function to copy 24bpp cursor data to 1bpp.
  1406. //
  1407. // Data is assumed to be padded to word boundaries, and that the
  1408. // destination buffer is big enough to receive the 1bpp cursor data.
  1409. //
  1410. // PARAMETERS:
  1411. //
  1412. // pSrc - pointer to source data
  1413. //
  1414. // pDst - pointer to destination buffer
  1415. //
  1416. // cx - width of cursor in pixels
  1417. //
  1418. // cy - height of cursor in pixels
  1419. //
  1420. // RETURNS: Nothing
  1421. //
  1422. //
  1423. void CMCopy24bppTo1bpp( LPBYTE pSrc,
  1424. LPBYTE pDst,
  1425. UINT cx,
  1426. UINT cy )
  1427. {
  1428. UINT x;
  1429. UINT y;
  1430. UINT cbDstRowWidth;
  1431. UINT cbUnpaddedDstRowWidth;
  1432. BOOL fPadByteNeeded;
  1433. BYTE Mask;
  1434. UINT intensity;
  1435. DebugEntry(CMCopy24bppTo1bpp);
  1436. cbDstRowWidth = ((cx + 15)/16) * 2;
  1437. cbUnpaddedDstRowWidth = (cx + 7) / 8;
  1438. fPadByteNeeded = ((cbDstRowWidth - cbUnpaddedDstRowWidth) > 0);
  1439. for (y = 0; y < cy; y++)
  1440. {
  1441. *pDst = 0;
  1442. Mask = 0x80;
  1443. for (x = 0; x < cx; x++)
  1444. {
  1445. if (Mask == 0)
  1446. {
  1447. Mask = 0x80;
  1448. pDst++;
  1449. *pDst = 0;
  1450. }
  1451. //
  1452. // Work out the intensity of the RGB value. There are three
  1453. // possible results
  1454. // 1) intensity <=CM_BLACK_THRESHOLD
  1455. // -- we leave the dest as blck
  1456. // 2) intensity > CM_WHITE_THRESHOLD
  1457. // -- we definitely map to white
  1458. // 3) otherwise
  1459. // -- we map to white in a grid hatching fashion
  1460. //
  1461. intensity = ((UINT)pSrc[0]*(UINT)pSrc[0]) +
  1462. ((UINT)pSrc[1]*(UINT)pSrc[1]) +
  1463. ((UINT)pSrc[2]*(UINT)pSrc[2]);
  1464. if ( (intensity > CM_WHITE_THRESHOLD) ||
  1465. ((intensity > CM_BLACK_THRESHOLD) && (((x ^ y) & 1) == 1)))
  1466. {
  1467. *pDst |= Mask;
  1468. }
  1469. Mask >>= 1;
  1470. pSrc += 3;
  1471. }
  1472. if (fPadByteNeeded)
  1473. {
  1474. pDst++;
  1475. *pDst = 0;
  1476. }
  1477. pDst++;
  1478. }
  1479. DebugExitVOID(CMCopy24bppTo1bpp);
  1480. }
  1481. //
  1482. // FUNCTION: CMSendCachedCursor
  1483. //
  1484. // DESCRIPTION:
  1485. //
  1486. // Sends a packet containing the given cache entry id.
  1487. //
  1488. // PARAMETERS:
  1489. //
  1490. // iCacheEntry - cache index
  1491. //
  1492. // RETURNS: TRUE if packet sent, FALSE otherwise.
  1493. //
  1494. //
  1495. BOOL ASHost::CMSendCachedCursor(UINT iCacheEntry)
  1496. {
  1497. BOOL rc = FALSE;
  1498. PCMPACKETCOLORCACHE pCMPacket;
  1499. #ifdef _DEBUG
  1500. UINT sentSize;
  1501. #endif // _DEBUG
  1502. DebugEntry(ASHost::CMSendCachedCursor);
  1503. TRACE_OUT(( "Send cached cursor(%u)", iCacheEntry));
  1504. pCMPacket = (PCMPACKETCOLORCACHE)m_pShare->SC_AllocPkt(PROT_STR_MISC, g_s20BroadcastID,
  1505. sizeof(*pCMPacket));
  1506. if (!pCMPacket)
  1507. {
  1508. WARNING_OUT(("Failed to alloc CM cached image packet"));
  1509. DC_QUIT;
  1510. }
  1511. //
  1512. // Fill in the packet.
  1513. //
  1514. pCMPacket->header.header.data.dataType = DT_CM;
  1515. pCMPacket->header.type = CM_CURSOR_COLOR_CACHE;
  1516. pCMPacket->cacheIndex = (TSHR_UINT16)iCacheEntry;
  1517. //
  1518. // Send it
  1519. //
  1520. if (m_pShare->m_scfViewSelf)
  1521. m_pShare->CM_ReceivedPacket(m_pShare->m_pasLocal, &(pCMPacket->header.header));
  1522. #ifdef _DEBUG
  1523. sentSize =
  1524. #endif // _DEBUG
  1525. m_pShare->DCS_CompressAndSendPacket(PROT_STR_MISC, g_s20BroadcastID,
  1526. &(pCMPacket->header.header), sizeof(*pCMPacket));
  1527. TRACE_OUT(("CM COLOR CACHE packet size: %08d, sent %08d", sizeof(*pCMPacket),
  1528. sentSize));
  1529. rc = TRUE;
  1530. DC_EXIT_POINT:
  1531. DebugExitBOOL(ASHost::CMSendCachedCursor, rc);
  1532. return(rc);
  1533. }
  1534. //
  1535. // FUNCTION: CMGetControllingWindow
  1536. //
  1537. // DESCRIPTION:
  1538. //
  1539. // Determines the window that is controlling the cursor's current shape.
  1540. //
  1541. // PARAMETERS: None
  1542. //
  1543. // RETURNS: the window that is controlling the cursor's current shape.
  1544. //
  1545. //
  1546. HWND CMGetControllingWindow(void)
  1547. {
  1548. POINT cursorPos;
  1549. HWND hwnd;
  1550. DebugEntry(CMGetControllingWindow);
  1551. //
  1552. // If a SysErrPopup Window (which is always System Modal) is present
  1553. // then WindowFromPoint enters a infinite recursion loop, trashing the
  1554. // stack and crashing the whole system.
  1555. // If there is a SysModal window Window ensure WindowFromPoint is not
  1556. // executed.
  1557. //
  1558. // The window controlling the cursor appearance is:
  1559. //
  1560. // - the local window that has the mouse capture (if any)
  1561. // - the window that is under the current mouse position
  1562. //
  1563. //
  1564. hwnd = GetCapture();
  1565. if (!hwnd)
  1566. {
  1567. //
  1568. // Get the current mouse position.
  1569. //
  1570. GetCursorPos(&cursorPos);
  1571. hwnd = WindowFromPoint(cursorPos);
  1572. }
  1573. DebugExitDWORD(CMGetControllingWindow, HandleToUlong(hwnd));
  1574. return(hwnd);
  1575. }
  1576. //
  1577. // FUNCTION: CMGetCurrentCursor
  1578. //
  1579. // DESCRIPTION:
  1580. //
  1581. // Returns a description of the current cursor
  1582. //
  1583. // PARAMETERS:
  1584. //
  1585. // pCursor - pointer to a CURSORDESCRIPTION variable that receives details
  1586. // of the current cursor
  1587. //
  1588. // RETURNS: Nothing
  1589. //
  1590. //
  1591. void CMGetCurrentCursor(LPCURSORDESCRIPTION pCursor)
  1592. {
  1593. LPCM_FAST_DATA lpcmShared;
  1594. DebugEntry(CMGetCurrentCursor);
  1595. lpcmShared = CM_SHM_START_READING;
  1596. pCursor->type = CM_CD_BITMAPCURSOR;
  1597. pCursor->id = lpcmShared->cmCursorStamp;
  1598. CM_SHM_STOP_READING;
  1599. DebugExitVOID(CMGetCurrentCursor);
  1600. }
  1601. //
  1602. // FUNCTION: CMSendSystemCursor
  1603. //
  1604. // DESCRIPTION:
  1605. //
  1606. // Sends a packet containing the given system cursor IDC.
  1607. //
  1608. // PARAMETERS:
  1609. //
  1610. // cursorIDC - the IDC of the system cursor to send
  1611. //
  1612. // RETURNS: TRUE if successful, FALSE otherwise.
  1613. //
  1614. //
  1615. BOOL ASHost::CMSendSystemCursor(UINT cursorIDC)
  1616. {
  1617. BOOL rc = FALSE;
  1618. PCMPACKETID pCMPacket;
  1619. #ifdef _DEBUG
  1620. UINT sentSize;
  1621. #endif // _DEBUG
  1622. DebugEntry(ASHost::CMSendSystemCursor);
  1623. ASSERT((cursorIDC == CM_IDC_NULL) || (cursorIDC == CM_IDC_ARROW));
  1624. //
  1625. // The cursor is one of the system cursors - create a PROTCURSOR packet
  1626. //
  1627. pCMPacket = (PCMPACKETID)m_pShare->SC_AllocPkt(PROT_STR_MISC, g_s20BroadcastID,
  1628. sizeof(*pCMPacket));
  1629. if (!pCMPacket)
  1630. {
  1631. WARNING_OUT(("Failed to alloc CM system image packet"));
  1632. DC_QUIT;
  1633. }
  1634. //
  1635. // Fill in the packet.
  1636. //
  1637. pCMPacket->header.header.data.dataType = DT_CM;
  1638. pCMPacket->header.type = CM_CURSOR_ID;
  1639. pCMPacket->idc = cursorIDC;
  1640. TRACE_OUT(( "Send CMCURSORID %ld", cursorIDC));
  1641. //
  1642. // Send it
  1643. //
  1644. if (m_pShare->m_scfViewSelf)
  1645. m_pShare->CM_ReceivedPacket(m_pShare->m_pasLocal, &(pCMPacket->header.header));
  1646. #ifdef _DEBUG
  1647. sentSize =
  1648. #endif // _DEBUG
  1649. m_pShare->DCS_CompressAndSendPacket(PROT_STR_MISC, g_s20BroadcastID,
  1650. &(pCMPacket->header.header), sizeof(*pCMPacket));
  1651. TRACE_OUT(("CM ID packet size: %08d, sent %08d", sizeof(*pCMPacket),
  1652. sentSize));
  1653. //
  1654. // Indicate that we successfully sent a packet.
  1655. //
  1656. rc = TRUE;
  1657. DC_EXIT_POINT:
  1658. DebugExitBOOL(ASHost::CMSendSystemCursor, rc);
  1659. return(rc);
  1660. }
  1661. //
  1662. // FUNCTION: CMSendBitmapCursor
  1663. //
  1664. // DESCRIPTION:
  1665. //
  1666. // Sends the current cursor as a bitmap.
  1667. //
  1668. // PARAMETERS: None
  1669. //
  1670. // RETURNS: TRUE if successful, FALSE otherwise.
  1671. //
  1672. //
  1673. BOOL ASHost::CMSendBitmapCursor(void)
  1674. {
  1675. BOOL rc = FALSE;
  1676. LPCM_SHAPE pCursor;
  1677. UINT cbCursorDataSize;
  1678. DebugEntry(ASHost::CMSendBitmapCursor);
  1679. //
  1680. // If cursor is hidden, send Null cursor
  1681. //
  1682. if (m_cmfCursorHidden)
  1683. {
  1684. TRACE_OUT(( "Send Null cursor (cursor hidden)"));
  1685. CMSendSystemCursor(CM_IDC_NULL);
  1686. DC_QUIT;
  1687. }
  1688. //
  1689. // Get a pointer to the current cursor shape.
  1690. //
  1691. if (!CMGetCursorShape(&pCursor, &cbCursorDataSize))
  1692. {
  1693. DC_QUIT;
  1694. }
  1695. //
  1696. // If this is a Null pointer, send the relevant packet.
  1697. //
  1698. if (CM_CURSOR_IS_NULL(pCursor))
  1699. {
  1700. TRACE_OUT(( "Send Null cursor"));
  1701. CMSendSystemCursor(CM_IDC_NULL);
  1702. DC_QUIT;
  1703. }
  1704. //
  1705. // If all of the parties in the call support the color cursor protocol
  1706. // then we try to send the cursor using that protocol, otherwise we
  1707. // send a mono cursor.
  1708. //
  1709. if (m_cmfUseColorCursorProtocol)
  1710. {
  1711. if (!CMSendCursorShape(pCursor, cbCursorDataSize))
  1712. {
  1713. DC_QUIT;
  1714. }
  1715. }
  1716. else
  1717. {
  1718. //
  1719. // We cannot send cursors that are not 32x32 using the mono
  1720. // protocol.
  1721. //
  1722. if ((pCursor->hdr.cx != 32) || (pCursor->hdr.cy != 32))
  1723. {
  1724. //
  1725. // Maybe copy and alter the cursor definition so that it is
  1726. // 32x32 ?
  1727. //
  1728. WARNING_OUT(( "Non-standard cursor (%d x %d)", pCursor->hdr.cx,
  1729. pCursor->hdr.cy ));
  1730. DC_QUIT;
  1731. }
  1732. if (!CMSendMonoBitmapCursor(pCursor))
  1733. {
  1734. DC_QUIT;
  1735. }
  1736. }
  1737. //
  1738. // Return success.
  1739. //
  1740. rc = TRUE;
  1741. DC_EXIT_POINT:
  1742. DebugExitDWORD(ASHost::CMSendBitmapCursor, rc);
  1743. return(rc);
  1744. }
  1745. //
  1746. // FUNCTION: CMCalculateColorCursorSize
  1747. //
  1748. // DESCRIPTION:
  1749. //
  1750. // Calculates the size in bytes of a given color cursor.
  1751. //
  1752. // PARAMETERS:
  1753. //
  1754. // pCursor - pointer to the cursor shape
  1755. //
  1756. // pcbANDMaskSize - pointer to a UINT variable that receives the AND mask
  1757. // size in bytes
  1758. //
  1759. // pcbXORBitmapSize - pointer to a UINT variable that receives the XOR
  1760. // bitmap size in bytes
  1761. //
  1762. // RETURNS: Nothing
  1763. //
  1764. //
  1765. void CMCalculateColorCursorSize( LPCM_SHAPE pCursor,
  1766. LPUINT pcbANDMaskSize,
  1767. LPUINT pcbXORBitmapSize)
  1768. {
  1769. DebugEntry(CMCalculcateColorCursorSize);
  1770. *pcbANDMaskSize = CURSOR_AND_MASK_SIZE(pCursor);
  1771. *pcbXORBitmapSize = CURSOR_DIB_BITS_SIZE( pCursor->hdr.cx,
  1772. pCursor->hdr.cy,
  1773. 24 );
  1774. DebugExitVOID(CMCalculateColorCursorSize);
  1775. }
  1776. //
  1777. // FUNCTION: CMSendColorBitmapCursor
  1778. //
  1779. // DESCRIPTION:
  1780. //
  1781. // Sends a given cursor as a color bitmap.
  1782. //
  1783. // PARAMETERS:
  1784. //
  1785. // pCursor - pointer to the cursor shape
  1786. //
  1787. // iCacheEntry - cache index to store in the transmitted packet
  1788. //
  1789. // RETURNS: TRUE if packet sent, FALSE otherwise
  1790. //
  1791. //
  1792. BOOL ASHost::CMSendColorBitmapCursor(LPCM_SHAPE pCursor, UINT iCacheEntry)
  1793. {
  1794. UINT cbPacketSize;
  1795. PCMPACKETCOLORBITMAP pCMPacket;
  1796. BOOL rc = FALSE;
  1797. UINT cbANDMaskSize;
  1798. UINT cbXORBitmapSize;
  1799. UINT cbColorCursorSize;
  1800. #ifdef _DEBUG
  1801. UINT sentSize;
  1802. #endif // _DEBUG
  1803. DebugEntry(ASHost::CMSendColorBitmapCursor);
  1804. CMCalculateColorCursorSize(pCursor, &cbANDMaskSize, &cbXORBitmapSize );
  1805. cbColorCursorSize = cbANDMaskSize + cbXORBitmapSize;
  1806. //
  1807. // Allocate a packet.
  1808. //
  1809. cbPacketSize = sizeof(CMPACKETCOLORBITMAP) + (cbColorCursorSize - 1);
  1810. pCMPacket = (PCMPACKETCOLORBITMAP)m_pShare->SC_AllocPkt(PROT_STR_MISC,
  1811. g_s20BroadcastID, cbPacketSize);
  1812. if (!pCMPacket)
  1813. {
  1814. WARNING_OUT(("Failed to alloc CM color image packet, size %u", cbPacketSize));
  1815. DC_QUIT;
  1816. }
  1817. //
  1818. // Fill in the packet.
  1819. //
  1820. pCMPacket->header.header.data.dataType = DT_CM;
  1821. //
  1822. // Fill in fields.
  1823. //
  1824. pCMPacket->header.type = CM_CURSOR_COLOR_BITMAP;
  1825. pCMPacket->cacheIndex = (TSHR_UINT16)iCacheEntry;
  1826. if (!CMGetColorCursorDetails(pCursor,
  1827. &(pCMPacket->cxWidth), &(pCMPacket->cyHeight),
  1828. &(pCMPacket->xHotSpot), &(pCMPacket->yHotSpot),
  1829. pCMPacket->aBits + cbXORBitmapSize,
  1830. &(pCMPacket->cbANDMask),
  1831. pCMPacket->aBits,
  1832. &(pCMPacket->cbXORBitmap )))
  1833. {
  1834. //
  1835. // Failed to get a cursor details. Must free up SNI packet
  1836. //
  1837. S20_FreeDataPkt(&(pCMPacket->header.header));
  1838. DC_QUIT;
  1839. }
  1840. ASSERT((pCMPacket->cbANDMask == cbANDMaskSize));
  1841. ASSERT((pCMPacket->cbXORBitmap == cbXORBitmapSize));
  1842. //
  1843. // Send it
  1844. //
  1845. if (m_pShare->m_scfViewSelf)
  1846. m_pShare->CM_ReceivedPacket(m_pShare->m_pasLocal, &(pCMPacket->header.header));
  1847. #ifdef _DEBUG
  1848. sentSize =
  1849. #endif // _DEBUG
  1850. m_pShare->DCS_CompressAndSendPacket(PROT_STR_MISC, g_s20BroadcastID,
  1851. &(pCMPacket->header.header), sizeof(*pCMPacket));
  1852. TRACE_OUT(("CM COLOR BITMAP packet size: %08d, sent %08d", sizeof(*pCMPacket),
  1853. sentSize));
  1854. //
  1855. // Indicate that we successfully sent a packet.
  1856. //
  1857. rc = TRUE;
  1858. DC_EXIT_POINT:
  1859. DebugExitBOOL(ASHost::CMSendColorBitmapCursor, rc);
  1860. return(rc);
  1861. }
  1862. //
  1863. // FUNCTION: CMSendMonoBitmapCursor
  1864. //
  1865. // DESCRIPTION:
  1866. //
  1867. // Sends a given cursor as a mono bitmap
  1868. //
  1869. // PARAMETERS:
  1870. //
  1871. // pCursor - pointer to the cursor shape
  1872. //
  1873. // RETURNS: TRUE if packet sent, FALSE otherwise
  1874. //
  1875. //
  1876. BOOL ASHost::CMSendMonoBitmapCursor(LPCM_SHAPE pCursor)
  1877. {
  1878. UINT cbPacketSize;
  1879. PCMPACKETMONOBITMAP pCMPacket;
  1880. BOOL rc = FALSE;
  1881. TSHR_UINT16 cbANDMaskSize;
  1882. TSHR_UINT16 cbXORBitmapSize;
  1883. #ifdef _DEBUG
  1884. UINT sentSize;
  1885. #endif // _DEBUG
  1886. DebugEntry(AShare::CMSendMonoBitmapCursor);
  1887. //
  1888. // Calculate the sizes of the converted (1bpp) AND and XOR bitmaps.
  1889. //
  1890. cbANDMaskSize = (TSHR_UINT16)CURSOR_AND_MASK_SIZE(pCursor);
  1891. cbXORBitmapSize = cbANDMaskSize;
  1892. //
  1893. // Allocate a packet.
  1894. //
  1895. cbPacketSize = sizeof(CMPACKETMONOBITMAP) +
  1896. (cbANDMaskSize + cbXORBitmapSize - 1);
  1897. pCMPacket = (PCMPACKETMONOBITMAP)m_pShare->SC_AllocPkt(PROT_STR_MISC,
  1898. g_s20BroadcastID, cbPacketSize);
  1899. if (!pCMPacket)
  1900. {
  1901. WARNING_OUT(("Failed to alloc CM mono image packet, size %u", cbPacketSize));
  1902. DC_QUIT;
  1903. }
  1904. //
  1905. // Fill FF in to initialize the XOR and AND bits
  1906. //
  1907. FillMemory((LPBYTE)(pCMPacket+1)-1, cbANDMaskSize + cbXORBitmapSize, 0xFF);
  1908. //
  1909. // Fill in the packet.
  1910. //
  1911. pCMPacket->header.header.data.dataType = DT_CM;
  1912. //
  1913. // Fill in fields.
  1914. //
  1915. pCMPacket->header.type = CM_CURSOR_MONO_BITMAP;
  1916. CMGetMonoCursorDetails(pCursor,
  1917. &(pCMPacket->width),
  1918. &(pCMPacket->height),
  1919. &(pCMPacket->xHotSpot),
  1920. &(pCMPacket->yHotSpot),
  1921. pCMPacket->aBits + cbXORBitmapSize,
  1922. &cbANDMaskSize,
  1923. pCMPacket->aBits,
  1924. &cbXORBitmapSize );
  1925. pCMPacket->cbBits = (TSHR_UINT16) (cbANDMaskSize + cbXORBitmapSize);
  1926. TRACE_OUT(( "Mono cursor cx:%u cy:%u xhs:%u yhs:%u cbAND:%u cbXOR:%u",
  1927. pCMPacket->width, pCMPacket->height,
  1928. pCMPacket->xHotSpot, pCMPacket->yHotSpot,
  1929. cbANDMaskSize, cbXORBitmapSize));
  1930. //
  1931. // Send it
  1932. //
  1933. if (m_pShare->m_scfViewSelf)
  1934. m_pShare->CM_ReceivedPacket(m_pShare->m_pasLocal, &(pCMPacket->header.header));
  1935. #ifdef _DEBUG
  1936. sentSize =
  1937. #endif // _DEBUG
  1938. m_pShare->DCS_CompressAndSendPacket(PROT_STR_MISC, g_s20BroadcastID,
  1939. &(pCMPacket->header.header), sizeof(*pCMPacket));
  1940. TRACE_OUT(("CM MONO BITMAP packet size: %08d, sent %08d", sizeof(*pCMPacket),
  1941. sentSize));
  1942. //
  1943. // Indicate that we successfully sent a packet.
  1944. //
  1945. rc = TRUE;
  1946. DC_EXIT_POINT:
  1947. DebugExitDWORD(ASHost::CMSendMonoBitmapCursor, rc);
  1948. return(rc);
  1949. }
  1950. //
  1951. // FUNCTION: CMCreateMonoCursor
  1952. //
  1953. // DESCRIPTION: Creates a mono cursor
  1954. //
  1955. // PARAMETERS:
  1956. //
  1957. // xHotSpot - x position of the hotspot
  1958. //
  1959. // yHotSpot - y position of the hotspot
  1960. //
  1961. // cxWidth - width of the cursor
  1962. //
  1963. // cyHeight - height of the cursor
  1964. //
  1965. // pANDMask - pointer to a 1bpp, word-padded AND mask
  1966. //
  1967. // pXORBitmap - pointer to a 1bpp, word-padded XOR bitmap
  1968. //
  1969. // RETURNS: a valid cursor id, or NULL if the function fails
  1970. //
  1971. //
  1972. HCURSOR ASShare::CMCreateMonoCursor(UINT xHotSpot,
  1973. UINT yHotSpot,
  1974. UINT cxWidth,
  1975. UINT cyHeight,
  1976. LPBYTE pANDMask,
  1977. LPBYTE pXORBitmap)
  1978. {
  1979. HCURSOR rc;
  1980. DebugEntry(ASShare::CMCreateMonoCursor);
  1981. //
  1982. // Attempt to create the mono cursor.
  1983. //
  1984. rc = CreateCursor(g_asInstance, xHotSpot, yHotSpot, cxWidth, cyHeight,
  1985. pANDMask, pXORBitmap);
  1986. //
  1987. // Check that the cursor handle is not null.
  1988. //
  1989. if (NULL == rc)
  1990. {
  1991. //
  1992. // Substitute the default arrow cursor.
  1993. //
  1994. rc = m_cmArrowCursor;
  1995. WARNING_OUT(( "Could not create cursor - substituting default arrow"));
  1996. }
  1997. //
  1998. // Return the cursor
  1999. //
  2000. DebugExitDWORD(ASShare::CMCreateMonoCursor, HandleToUlong(rc));
  2001. return(rc);
  2002. }
  2003. //
  2004. // FUNCTION: CMCreateColorCursor
  2005. //
  2006. // DESCRIPTION:
  2007. //
  2008. // Creates a color cursor.
  2009. //
  2010. // PARAMETERS:
  2011. //
  2012. // xHotSpot - x position of the hotspot
  2013. //
  2014. // yHotSpot - y position of the hotspot
  2015. //
  2016. // cxWidth - width of the cursor
  2017. //
  2018. // cyHeight - height of the cursor
  2019. //
  2020. // pANDMask - pointer to a 1bpp, word-padded AND mask
  2021. //
  2022. // pXORBitmap - pointer to a 24bpp, word-padded XOR bitmap
  2023. //
  2024. // cbANDMask - the size in bytes of the AND mask
  2025. //
  2026. // cbXORBitmap - the size in bytes of the XOR bitmap
  2027. //
  2028. // RETURNS: a valid cursor id, or NULL if the function fails
  2029. //
  2030. //
  2031. HCURSOR ASShare::CMCreateColorCursor
  2032. (
  2033. UINT xHotSpot,
  2034. UINT yHotSpot,
  2035. UINT cxWidth,
  2036. UINT cyHeight,
  2037. LPBYTE pANDMask,
  2038. LPBYTE pXORBitmap,
  2039. UINT cbANDMask,
  2040. UINT cbXORBitmap
  2041. )
  2042. {
  2043. HCURSOR rc = 0;
  2044. UINT cbAllocSize;
  2045. LPBITMAPINFO pbmi = NULL;
  2046. HDC hdc = NULL;
  2047. ICONINFO iconInfo;
  2048. HBITMAP hbmXORBitmap = NULL;
  2049. HBITMAP hbmANDMask = NULL;
  2050. HWND hwndDesktop = NULL;
  2051. DebugEntry(ASShare::CMCreateColorCursor);
  2052. TRACE_OUT(("xhs(%u) yhs(%u) cx(%u) cy(%u) cbXOR(%u) cbAND(%u)",
  2053. xHotSpot,
  2054. yHotSpot,
  2055. cxWidth,
  2056. cyHeight,
  2057. cbXORBitmap,
  2058. cbANDMask ));
  2059. //
  2060. // We need a BITMAPINFO structure plus one additional RGBQUAD (there is
  2061. // one included within the BITMAPINFO). We use this to pass the 24bpp
  2062. // XOR bitmap (which has no color table) and the 1bpp AND mask (which
  2063. // requires 2 colors).
  2064. //
  2065. cbAllocSize = sizeof(*pbmi) + sizeof(RGBQUAD);
  2066. pbmi = (LPBITMAPINFO)new BYTE[cbAllocSize];
  2067. if (pbmi == NULL)
  2068. {
  2069. WARNING_OUT(( "Failed to alloc bmi(%x)", cbAllocSize));
  2070. DC_QUIT;
  2071. }
  2072. //
  2073. // Get a screen DC that we can pass to CreateDIBitmap. We do not use
  2074. // CreateCompatibleDC(NULL) here because that results in Windows
  2075. // creating a mono bitmap.
  2076. //
  2077. hwndDesktop = GetDesktopWindow();
  2078. hdc = GetWindowDC(hwndDesktop);
  2079. if (hdc == NULL)
  2080. {
  2081. WARNING_OUT(( "Failed to create DC"));
  2082. DC_QUIT;
  2083. }
  2084. pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  2085. pbmi->bmiHeader.biWidth = cxWidth;
  2086. pbmi->bmiHeader.biHeight = cyHeight;
  2087. pbmi->bmiHeader.biPlanes = 1;
  2088. pbmi->bmiHeader.biBitCount = 24;
  2089. pbmi->bmiHeader.biCompression = 0;
  2090. pbmi->bmiHeader.biSizeImage = cbXORBitmap;
  2091. pbmi->bmiHeader.biXPelsPerMeter = 0;
  2092. pbmi->bmiHeader.biYPelsPerMeter = 0;
  2093. pbmi->bmiHeader.biClrUsed = 0;
  2094. pbmi->bmiHeader.biClrImportant = 0;
  2095. hbmXORBitmap = CreateDIBitmap( hdc,
  2096. (LPBITMAPINFOHEADER)pbmi,
  2097. CBM_INIT,
  2098. pXORBitmap,
  2099. pbmi,
  2100. DIB_RGB_COLORS );
  2101. ReleaseDC(hwndDesktop, hdc);
  2102. if (hbmXORBitmap == NULL)
  2103. {
  2104. WARNING_OUT(( "Failed to create XOR bitmap"));
  2105. DC_QUIT;
  2106. }
  2107. //
  2108. // Create MONOCHROME mask bitmap. This works on both Win95 and NT.
  2109. // COLOR masks don't work on Win95, just NT.
  2110. //
  2111. hdc = CreateCompatibleDC(NULL);
  2112. if (!hdc)
  2113. {
  2114. WARNING_OUT(("Failed to get screen dc"));
  2115. DC_QUIT;
  2116. }
  2117. pbmi->bmiHeader.biBitCount = 1;
  2118. pbmi->bmiHeader.biCompression = 0;
  2119. pbmi->bmiHeader.biSizeImage = cbANDMask;
  2120. // Black
  2121. pbmi->bmiColors[0].rgbRed = 0x00;
  2122. pbmi->bmiColors[0].rgbGreen = 0x00;
  2123. pbmi->bmiColors[0].rgbBlue = 0x00;
  2124. pbmi->bmiColors[0].rgbReserved = 0x00;
  2125. // White
  2126. pbmi->bmiColors[1].rgbRed = 0xFF;
  2127. pbmi->bmiColors[1].rgbGreen = 0xFF;
  2128. pbmi->bmiColors[1].rgbBlue = 0xFF;
  2129. pbmi->bmiColors[1].rgbReserved = 0x00;
  2130. hbmANDMask = CreateDIBitmap( hdc,
  2131. (LPBITMAPINFOHEADER)pbmi,
  2132. CBM_INIT,
  2133. pANDMask,
  2134. pbmi,
  2135. DIB_RGB_COLORS );
  2136. DeleteDC(hdc);
  2137. if (hbmANDMask == NULL)
  2138. {
  2139. WARNING_OUT(( "Failed to create AND mask"));
  2140. DC_QUIT;
  2141. }
  2142. #ifdef _DEBUG
  2143. //
  2144. // Make sure the AND mask is monochrome
  2145. //
  2146. {
  2147. BITMAP bmp;
  2148. GetObject(hbmANDMask, sizeof(BITMAP), &bmp);
  2149. ASSERT(bmp.bmPlanes == 1);
  2150. ASSERT(bmp.bmBitsPixel == 1);
  2151. }
  2152. #endif
  2153. iconInfo.fIcon = FALSE;
  2154. iconInfo.xHotspot = xHotSpot;
  2155. iconInfo.yHotspot = yHotSpot;
  2156. iconInfo.hbmMask = hbmANDMask;
  2157. iconInfo.hbmColor = hbmXORBitmap;
  2158. rc = CreateIconIndirect(&iconInfo);
  2159. TRACE_OUT(( "CreateCursor(%x) cx(%u)cy(%u)", rc, cxWidth, cyHeight));
  2160. DC_EXIT_POINT:
  2161. if (hbmXORBitmap != NULL)
  2162. {
  2163. DeleteBitmap(hbmXORBitmap);
  2164. }
  2165. if (hbmANDMask != NULL)
  2166. {
  2167. DeleteBitmap(hbmANDMask);
  2168. }
  2169. if (pbmi != NULL)
  2170. {
  2171. delete[] pbmi;
  2172. }
  2173. //
  2174. // Check that we have successfully managed to create the cursor. If
  2175. // not then substitute the default cursor.
  2176. //
  2177. if (rc == 0)
  2178. {
  2179. //
  2180. // Substitute the default arrow cursor.
  2181. //
  2182. rc = m_cmArrowCursor;
  2183. WARNING_OUT(( "Could not create cursor - substituting default arrow"));
  2184. }
  2185. DebugExitDWORD(ASShare::CMCreateColorCursor, HandleToUlong(rc));
  2186. return(rc);
  2187. }
  2188. //
  2189. // FUNCTION: CMCreateAbbreviatedName
  2190. //
  2191. // DESCRIPTION:
  2192. //
  2193. // This function attempts to take a name, and create an abbreviation from
  2194. // the first characters of the first and last name.
  2195. //
  2196. // PARAMETERS:
  2197. //
  2198. // szTagName - a pointer to a string containing the name to abbreviate.
  2199. // szBuf - a pointer to a buffer into which the abbreviation will
  2200. // be created.
  2201. // cbBuf - size of buffer pointed to by szBuf.
  2202. //
  2203. // RETURNS:
  2204. //
  2205. // TRUE: Success. szBuf filled in.
  2206. // FALSE: Failure. szBuf is not filled in.
  2207. //
  2208. //
  2209. BOOL CMCreateAbbreviatedName(LPCSTR szTagName, LPSTR szBuf,
  2210. UINT cbBuf)
  2211. {
  2212. BOOL rc = FALSE;
  2213. LPSTR p;
  2214. LPSTR q;
  2215. DebugEntry(CMCreateAbbreviatedName);
  2216. //
  2217. // This function isn't DBCS safe, so we don't abbreviate in DBCS
  2218. // character sets.
  2219. //
  2220. if (TRUE == GetSystemMetrics(SM_DBCSENABLED))
  2221. {
  2222. DC_QUIT;
  2223. }
  2224. //
  2225. // Try to create initials. If that doesn't work, fail the call.
  2226. //
  2227. if ((NULL != (p = (LPSTR)_StrChr(szTagName, ' '))) && ('\0' != *(p+1)))
  2228. {
  2229. //
  2230. // Is there enough room for initials?
  2231. //
  2232. if (cbBuf < NTRUNCLETTERS)
  2233. {
  2234. DC_QUIT;
  2235. }
  2236. q = szBuf;
  2237. *q++ = *szTagName;
  2238. *q++ = '.';
  2239. *q++ = *(p+1);
  2240. *q++ = '.';
  2241. *q = '\0';
  2242. AnsiUpper(szBuf);
  2243. rc = TRUE;
  2244. }
  2245. DC_EXIT_POINT:
  2246. DebugExitBOOL(CMCreateAbbreviatedName, rc);
  2247. return rc;
  2248. }
  2249. //
  2250. // FUNCTION: CMDrawCursorTag
  2251. //
  2252. // DESCRIPTION:
  2253. //
  2254. // PARAMETERS:
  2255. //
  2256. // hdcWindow - DC handle of the window to be drawn to
  2257. //
  2258. // cursorID - handle of cursor to drawn
  2259. //
  2260. // RETURNS: Nothing.
  2261. //
  2262. //
  2263. void ASShare::CMDrawCursorTag
  2264. (
  2265. ASPerson * pasHost,
  2266. HDC hdc
  2267. )
  2268. {
  2269. ASPerson * pasPerson;
  2270. char ShortName[TSHR_MAX_PERSON_NAME_LEN];
  2271. HFONT hOldFont = NULL;
  2272. RECT rect;
  2273. UINT cCharsFit;
  2274. LPSTR p;
  2275. DebugEntry(ASShare::CMDrawCursorTag);
  2276. pasPerson = pasHost->m_caControlledBy;
  2277. if (!pasPerson)
  2278. {
  2279. // Nothing to do
  2280. DC_QUIT;
  2281. }
  2282. ValidatePerson(pasPerson);
  2283. //
  2284. // Try to abbreviate the person's name, so it will fit into the tag.
  2285. // If the abbreviation fails, just copy the entire name for now.
  2286. //
  2287. if (!(CMCreateAbbreviatedName(pasPerson->scName, ShortName, sizeof(ShortName))))
  2288. {
  2289. lstrcpyn(ShortName, pasPerson->scName, sizeof(ShortName));
  2290. }
  2291. //
  2292. // Select the cursor tag font into the DC.
  2293. //
  2294. hOldFont = SelectFont(hdc, m_cmCursorTagFont);
  2295. if (hOldFont == NULL)
  2296. {
  2297. WARNING_OUT(("CMDrawCursorTag failed"));
  2298. DC_QUIT;
  2299. }
  2300. //
  2301. // Create the tag background...
  2302. //
  2303. PatBlt(hdc, TAGXOFF, TAGYOFF, TAGXSIZ, TAGYSIZ, WHITENESS);
  2304. //
  2305. // See how many characters of the name or abbreviation we can fit into
  2306. // the tag. First assume the whole thing fits.
  2307. //
  2308. cCharsFit = lstrlen(ShortName);
  2309. //
  2310. // Determine how many characters actually fit.
  2311. //
  2312. rect.left = rect.top = rect.right = rect.bottom = 0;
  2313. for (p = AnsiNext(ShortName); ; p = AnsiNext(p))
  2314. {
  2315. if (DrawText(hdc, ShortName, p - ShortName, &rect,
  2316. DT_CALCRECT | DT_SINGLELINE | DT_NOPREFIX))
  2317. {
  2318. if (rect.right > TAGXSIZ)
  2319. {
  2320. //
  2321. // This number of characters does not fit into the tag. Try
  2322. // the next smaller number.
  2323. //
  2324. cCharsFit = AnsiPrev(ShortName, p) - ShortName;
  2325. break;
  2326. }
  2327. }
  2328. if ( '\0' == *p)
  2329. break;
  2330. }
  2331. //
  2332. // Now draw the text. Note that DrawText does not return a documented
  2333. // error code, so we don't check.
  2334. //
  2335. rect.left = TAGXOFF;
  2336. rect.top = TAGYOFF;
  2337. rect.right = TAGXOFF + TAGXSIZ;
  2338. rect.bottom = TAGYOFF + TAGYSIZ;
  2339. DrawText(hdc, ShortName, cCharsFit, &rect,
  2340. DT_CENTER | DT_SINGLELINE | DT_NOPREFIX);
  2341. DC_EXIT_POINT:
  2342. //
  2343. // Perform necessary cleanup.
  2344. //
  2345. if (hOldFont)
  2346. {
  2347. SelectFont(hdc, hOldFont);
  2348. }
  2349. DebugExitVOID(ASShare::CMDrawCursorTag);
  2350. }
  2351. //
  2352. // FUNCTION: CMGetCursorShape
  2353. //
  2354. // DESCRIPTION:
  2355. //
  2356. // Returns a pointer to a DCCURSORSHAPE structure that defines the bit
  2357. // definition of the currently displayed cursor.
  2358. //
  2359. // A DCCURSORSHAPE structure is OS-specific. The higher level code does
  2360. // not look at any individual fields in this structure - it just compares
  2361. // the whole data block with others in the cursor cache. If two
  2362. // DCCURSORSHAPE structures contain the same the data, then the
  2363. // corresponding cursors are assumed to be the same.
  2364. //
  2365. // The LPCM_SHAPE returned here is passed back into
  2366. // CMGetColorCursorDetails or CMGetMonoCursorDetails to retrieve the
  2367. // specific details.
  2368. //
  2369. // PARAMETERS:
  2370. //
  2371. // ppCursorShape - pointer to a LPCM_SHAPE variable that receives the
  2372. // pointer to the DCCURSORSHAPE structure
  2373. //
  2374. // pcbCursorDataSize - pointer to a UINT variable that receives the size
  2375. // in bytes of the DCCURSORSHAPE structure
  2376. //
  2377. // RETURNS: Success TRUE/FALSE
  2378. //
  2379. //
  2380. BOOL CMGetCursorShape(LPCM_SHAPE * ppCursorShape,
  2381. LPUINT pcbCursorDataSize )
  2382. {
  2383. LPCM_FAST_DATA lpcmShared;
  2384. BOOL rc = FALSE;
  2385. DebugEntry(CMGetCursorShape);
  2386. lpcmShared = CM_SHM_START_READING;
  2387. //
  2388. // Check that a cursor has been written to shared memory - may happen
  2389. // on start-up before the display driver has written a cursor - or if
  2390. // the display driver is not working.
  2391. //
  2392. if (lpcmShared->cmCursorShapeData.hdr.cBitsPerPel == 0)
  2393. {
  2394. TRACE_OUT(( "No cursor in shared memory"));
  2395. DC_QUIT;
  2396. }
  2397. *ppCursorShape = (LPCM_SHAPE)&lpcmShared->cmCursorShapeData;
  2398. *pcbCursorDataSize = CURSORSHAPE_SIZE(&lpcmShared->cmCursorShapeData);
  2399. rc = TRUE;
  2400. DC_EXIT_POINT:
  2401. CM_SHM_STOP_READING;
  2402. DebugExitDWORD(CMGetCursorShape, rc);
  2403. return(rc);
  2404. }
  2405. //
  2406. // FUNCTION: CMGetColorCursorDetails
  2407. //
  2408. // DESCRIPTION:
  2409. //
  2410. // Returns details of a cursor at 24bpp, given a DCCURSORSHAPE structure.
  2411. //
  2412. // PARAMETERS:
  2413. //
  2414. // pCursor - pointer to a DCCURSORSHAPE structure from which this function
  2415. // extracts the details
  2416. //
  2417. // pcxWidth - pointer to a TSHR_UINT16 variable that receives the cursor width
  2418. // in pixels
  2419. //
  2420. // pcyHeight - pointer to a TSHR_UINT16 variable that receives the cursor
  2421. // height in pixels
  2422. //
  2423. // pxHotSpot - pointer to a TSHR_UINT16 variable that receives the cursor
  2424. // hotspot x coordinate
  2425. //
  2426. // pyHotSpot - pointer to a TSHR_UINT16 variable that receives the cursor
  2427. // hotspot y coordinate
  2428. //
  2429. // pANDMask - pointer to a buffer that receives the cursor AND mask
  2430. //
  2431. // pcbANDMask - pointer to a TSHR_UINT16 variable that receives the size in
  2432. // bytes of the cursor AND mask
  2433. //
  2434. // pXORBitmap - pointer to a buffer that receives the cursor XOR bitmap at
  2435. // 24bpp
  2436. //
  2437. // pcbXORBitmap - pointer to a TSHR_UINT16 variable that receives the size in
  2438. // bytes of the cursor XOR bitmap
  2439. //
  2440. //
  2441. BOOL ASHost::CMGetColorCursorDetails
  2442. (
  2443. LPCM_SHAPE pCursor,
  2444. LPTSHR_UINT16 pcxWidth,
  2445. LPTSHR_UINT16 pcyHeight,
  2446. LPTSHR_UINT16 pxHotSpot,
  2447. LPTSHR_UINT16 pyHotSpot,
  2448. LPBYTE pANDMask,
  2449. LPTSHR_UINT16 pcbANDMask,
  2450. LPBYTE pXORBitmap,
  2451. LPTSHR_UINT16 pcbXORBitmap
  2452. )
  2453. {
  2454. BOOL rc = FALSE;
  2455. LPCM_SHAPE_HEADER pCursorHdr;
  2456. HDC hdcScreen = NULL;
  2457. HBITMAP hbmp = NULL;
  2458. UINT cbANDMaskSize;
  2459. UINT cbXORBitmapSize;
  2460. HDC hdcTmp = NULL;
  2461. UINT cbANDMaskRowWidth;
  2462. UINT cbSrcRowOffset;
  2463. UINT cbDstRowOffset;
  2464. UINT y;
  2465. LPUINT pDestBitmasks;
  2466. BITMAPINFO_ours bmi;
  2467. BITMAPINFO_ours srcbmi;
  2468. HBITMAP oldBitmap;
  2469. void * pBmBits = NULL;
  2470. int numColors;
  2471. int ii;
  2472. LPCM_FAST_DATA lpcmShared;
  2473. DebugEntry(ASHost::CMGetColorCursorDetails);
  2474. if (pCursor == NULL)
  2475. {
  2476. DC_QUIT;
  2477. }
  2478. pCursorHdr = &(pCursor->hdr);
  2479. //
  2480. // Copy the cursor size and hotspot coords.
  2481. //
  2482. *pcxWidth = pCursorHdr->cx;
  2483. *pcyHeight = pCursorHdr->cy;
  2484. *pxHotSpot = (TSHR_UINT16)pCursorHdr->ptHotSpot.x;
  2485. *pyHotSpot = (TSHR_UINT16)pCursorHdr->ptHotSpot.y;
  2486. TRACE_OUT(( "cx(%u) cy(%u) cbWidth %d planes(%u) bpp(%u)",
  2487. pCursorHdr->cx,
  2488. pCursorHdr->cy,
  2489. pCursorHdr->cbRowWidth,
  2490. pCursorHdr->cPlanes,
  2491. pCursorHdr->cBitsPerPel ));
  2492. cbANDMaskSize = CURSOR_AND_MASK_SIZE(pCursor);
  2493. cbXORBitmapSize = CURSOR_XOR_BITMAP_SIZE(pCursor);
  2494. //
  2495. // Copy the AND mask - this is always mono.
  2496. //
  2497. // The AND mask is currently in top-down format (the top row of the
  2498. // bitmap comes first).
  2499. //
  2500. // The protocol sends bitmaps in Device Independent format, which is
  2501. // bottom-up. We therefore have to flip the rows as we copy the mask.
  2502. //
  2503. cbANDMaskRowWidth = pCursorHdr->cbRowWidth;
  2504. cbSrcRowOffset = 0;
  2505. cbDstRowOffset = cbANDMaskRowWidth * (pCursorHdr->cy-1);
  2506. for (y = 0; y < pCursorHdr->cy; y++)
  2507. {
  2508. memcpy( pANDMask + cbDstRowOffset,
  2509. pCursor->Masks + cbSrcRowOffset,
  2510. cbANDMaskRowWidth );
  2511. cbSrcRowOffset += cbANDMaskRowWidth;
  2512. cbDstRowOffset -= cbANDMaskRowWidth;
  2513. }
  2514. //
  2515. // The XOR mask is color and is in DIB format - at 1bpp for mono
  2516. // cursors, or the display driver bpp.
  2517. //
  2518. // We create a bitmap of the same size, set the bits into it and then
  2519. // get the bits out in 24bpp DIB format.
  2520. //
  2521. hdcTmp = CreateCompatibleDC(NULL);
  2522. if (hdcTmp == NULL)
  2523. {
  2524. ERROR_OUT(( "failed to create DC"));
  2525. DC_QUIT;
  2526. }
  2527. //
  2528. // Setup source bitmap information.
  2529. //
  2530. m_pShare->USR_InitDIBitmapHeader((BITMAPINFOHEADER *)&srcbmi, pCursorHdr->cBitsPerPel);
  2531. srcbmi.bmiHeader.biWidth = pCursorHdr->cx;
  2532. srcbmi.bmiHeader.biHeight = pCursorHdr->cy;
  2533. numColors = COLORS_FOR_BPP(pCursorHdr->cBitsPerPel);
  2534. //
  2535. // Setup source palette info.
  2536. //
  2537. if (pCursorHdr->cBitsPerPel > 8)
  2538. {
  2539. //
  2540. // If the device bpp is > 8, we have to set up the DIB section to
  2541. // use the same bitmasks as the device. This means setting the
  2542. // compression type to BI_BITFIELDS and setting the first 3 DWORDS
  2543. // of the bitmap info color table to be the bitmasks for R, G and B
  2544. // respectively.
  2545. // But not for 24bpp. No bitmask or palette are used - it is
  2546. // always 8,8,8 RGB.
  2547. //
  2548. if (pCursorHdr->cBitsPerPel != 24)
  2549. {
  2550. TRACE_OUT(( "Copy bitfields"));
  2551. srcbmi.bmiHeader.biCompression = BI_BITFIELDS;
  2552. lpcmShared = CM_SHM_START_READING;
  2553. pDestBitmasks = (LPUINT)(srcbmi.bmiColors);
  2554. pDestBitmasks[0] = lpcmShared->bitmasks[0];
  2555. pDestBitmasks[1] = lpcmShared->bitmasks[1];
  2556. pDestBitmasks[2] = lpcmShared->bitmasks[2];
  2557. CM_SHM_STOP_READING;
  2558. }
  2559. else
  2560. {
  2561. TRACE_OUT(( "24bpp cursor: no bitmasks"));
  2562. }
  2563. }
  2564. else
  2565. {
  2566. TRACE_OUT(( "Get palette %d", numColors));
  2567. lpcmShared = CM_SHM_START_READING;
  2568. //
  2569. // Flip the palette - its RGB in the kernel, and needs to be BGR
  2570. // here.
  2571. //
  2572. for (ii = 0; ii < numColors; ii++)
  2573. {
  2574. srcbmi.bmiColors[ii].rgbRed = lpcmShared->colorTable[ii].peRed;
  2575. srcbmi.bmiColors[ii].rgbGreen = lpcmShared->colorTable[ii].peGreen;
  2576. srcbmi.bmiColors[ii].rgbBlue = lpcmShared->colorTable[ii].peBlue;
  2577. }
  2578. CM_SHM_STOP_READING;
  2579. }
  2580. //
  2581. // Create source bitmap and write in the bitmap bits.
  2582. //
  2583. hbmp = CreateDIBSection(hdcTmp,
  2584. (BITMAPINFO *)&srcbmi,
  2585. DIB_RGB_COLORS,
  2586. &pBmBits,
  2587. NULL,
  2588. 0);
  2589. if (hbmp == NULL)
  2590. {
  2591. ERROR_OUT(( "Failed to create bitmap"));
  2592. DC_QUIT;
  2593. }
  2594. TRACE_OUT(( "Copy %d bytes of data into bitmap 0x%08x",
  2595. cbXORBitmapSize, pBmBits));
  2596. memcpy(pBmBits, pCursor->Masks + cbANDMaskSize, cbXORBitmapSize);
  2597. //
  2598. // Set up the structure required by GetDIBits - 24bpp. Set the height
  2599. // -ve to allow for top-down ordering of the bitmap.
  2600. //
  2601. m_pShare->USR_InitDIBitmapHeader((BITMAPINFOHEADER *)&bmi, 24);
  2602. bmi.bmiHeader.biWidth = pCursorHdr->cx;
  2603. bmi.bmiHeader.biHeight = -pCursorHdr->cy;
  2604. if (GetDIBits(hdcTmp,
  2605. hbmp,
  2606. 0,
  2607. pCursorHdr->cy,
  2608. pXORBitmap,
  2609. (LPBITMAPINFO)&bmi,
  2610. DIB_RGB_COLORS) == 0)
  2611. {
  2612. ERROR_OUT(( "GetDIBits failed hdc(%x) hbmp(%x) cy(%d)",
  2613. (TSHR_UINT16)hdcTmp,
  2614. (TSHR_UINT16)hbmp,
  2615. pCursorHdr->cy ));
  2616. DC_QUIT;
  2617. }
  2618. *pcbANDMask = (TSHR_UINT16) CURSOR_AND_MASK_SIZE(pCursor);
  2619. *pcbXORBitmap = (TSHR_UINT16) CURSOR_DIB_BITS_SIZE(pCursor->hdr.cx,
  2620. pCursor->hdr.cy,
  2621. 24);
  2622. //
  2623. // Return success.
  2624. //
  2625. rc = TRUE;
  2626. DC_EXIT_POINT:
  2627. //
  2628. // Clean up before exit.
  2629. //
  2630. if (hdcTmp)
  2631. {
  2632. DeleteDC(hdcTmp);
  2633. }
  2634. if (hbmp != NULL)
  2635. {
  2636. DeleteBitmap(hbmp);
  2637. }
  2638. DebugExitBOOL(ASHost::CMGetColorCursorDetails, rc);
  2639. return(rc);
  2640. }
  2641. //
  2642. // FUNCTION: CMGetMonoCursorDetails
  2643. //
  2644. // DESCRIPTION:
  2645. //
  2646. // Returns details of a cursor at 1bpp, given a DCCURSORSHAPE structure.
  2647. //
  2648. // PARAMETERS:
  2649. //
  2650. // pCursor - pointer to a DCCURSORSHAPE structure from which this function
  2651. // extracts the details
  2652. //
  2653. // pcxWidth - pointer to a TSHR_UINT16 variable that receives the cursor width
  2654. // in pixels
  2655. //
  2656. // pcyHeight - pointer to a TSHR_UINT16 variable that receives the cursor
  2657. // height in pixels
  2658. //
  2659. // pxHotSpot - pointer to a TSHR_UINT16 variable that receives the cursor
  2660. // hotspot x coordinate
  2661. //
  2662. // pyHotSpot - pointer to a TSHR_UINT16 variable that receives the cursor
  2663. // hotspot y coordinate
  2664. //
  2665. // pANDMask - pointer to a buffer that receives the cursor AND mask
  2666. //
  2667. // pcbANDMask - pointer to a TSHR_UINT16 variable that receives the size in
  2668. // bytes of the cursor AND mask
  2669. //
  2670. // pXORBitmap - pointer to a buffer that receives the cursor XOR bitmap at
  2671. // 1bpp
  2672. //
  2673. // pcbXORBitmap - pointer to a TSHR_UINT16 variable that receives the size in
  2674. // bytes of the cursor XOR bitmap
  2675. //
  2676. //
  2677. BOOL CMGetMonoCursorDetails(LPCM_SHAPE pCursor,
  2678. LPTSHR_UINT16 pcxWidth,
  2679. LPTSHR_UINT16 pcyHeight,
  2680. LPTSHR_UINT16 pxHotSpot,
  2681. LPTSHR_UINT16 pyHotSpot,
  2682. LPBYTE pANDMask,
  2683. LPTSHR_UINT16 pcbANDMask,
  2684. LPBYTE pXORBitmap,
  2685. LPTSHR_UINT16 pcbXORBitmap)
  2686. {
  2687. BOOL rc = FALSE;
  2688. LPCM_SHAPE_HEADER pCursorHdr;
  2689. UINT x;
  2690. UINT y;
  2691. LPBYTE pSrcRow;
  2692. UINT cbDstRowWidth;
  2693. LPBYTE pDstData;
  2694. UINT cbSrcANDMaskSize;
  2695. LPBYTE pSrcXORMask;
  2696. PFNCMCOPYTOMONO pfnCopyToMono;
  2697. DebugEntry(CMGetMonoCursor);
  2698. pCursorHdr = &(pCursor->hdr);
  2699. TRACE_OUT(( "cx(%u) cy(%u) cbWidth %d planes(%u) bpp(%u)",
  2700. pCursorHdr->cx,
  2701. pCursorHdr->cy,
  2702. pCursorHdr->cbRowWidth,
  2703. pCursorHdr->cPlanes,
  2704. pCursorHdr->cBitsPerPel ));
  2705. //
  2706. // Copy the cursor size and hotspot coords.
  2707. //
  2708. *pcxWidth = pCursorHdr->cx;
  2709. *pcyHeight = pCursorHdr->cy;
  2710. *pxHotSpot = (TSHR_UINT16)pCursorHdr->ptHotSpot.x;
  2711. *pyHotSpot = (TSHR_UINT16)pCursorHdr->ptHotSpot.y;
  2712. //
  2713. // Copy the AND mask - this is always mono...
  2714. // The rows are padded to word (16-bit) boundaries.
  2715. //
  2716. pDstData = pANDMask;
  2717. pSrcRow = pCursor->Masks;
  2718. cbDstRowWidth = ((pCursorHdr->cx + 15)/16) * 2;
  2719. for (y = 0; y < pCursorHdr->cy; y++)
  2720. {
  2721. for (x = 0; x < cbDstRowWidth; x++)
  2722. {
  2723. if (x < pCursorHdr->cbRowWidth)
  2724. {
  2725. //
  2726. // Copy data from the cursor definition.
  2727. //
  2728. *pDstData++ = pSrcRow[x];
  2729. }
  2730. else
  2731. {
  2732. //
  2733. // Padding required.
  2734. //
  2735. *pDstData++ = 0xFF;
  2736. }
  2737. }
  2738. pSrcRow += pCursorHdr->cbRowWidth;
  2739. }
  2740. //
  2741. // Copy the XOR mask - this may be color. We convert to mono by:
  2742. //
  2743. // - turning all zero values into a binary 0
  2744. // - turning all non-zero value into a binary 1
  2745. //
  2746. //
  2747. switch (pCursorHdr->cBitsPerPel)
  2748. {
  2749. case 1:
  2750. TRACE_OUT(( "1bpp"));
  2751. pfnCopyToMono = CMCopy1bppTo1bpp;
  2752. break;
  2753. case 4:
  2754. TRACE_OUT(( "4bpp"));
  2755. pfnCopyToMono = CMCopy4bppTo1bpp;
  2756. break;
  2757. case 8:
  2758. TRACE_OUT(( "8bpp"));
  2759. pfnCopyToMono = CMCopy8bppTo1bpp;
  2760. break;
  2761. case 16:
  2762. TRACE_OUT(( "16bpp"));
  2763. pfnCopyToMono = CMCopy16bppTo1bpp;
  2764. break;
  2765. case 24:
  2766. TRACE_OUT(( "24bpp"));
  2767. pfnCopyToMono = CMCopy24bppTo1bpp;
  2768. break;
  2769. default:
  2770. ERROR_OUT(( "Unexpected bpp: %d", pCursorHdr->cBitsPerPel));
  2771. DC_QUIT;
  2772. }
  2773. cbSrcANDMaskSize = pCursorHdr->cbRowWidth * pCursorHdr->cy;
  2774. pSrcXORMask = pCursor->Masks + cbSrcANDMaskSize;
  2775. (*pfnCopyToMono)( pSrcXORMask,
  2776. pXORBitmap,
  2777. pCursorHdr->cx,
  2778. pCursorHdr->cy );
  2779. *pcbANDMask = (TSHR_UINT16) (cbDstRowWidth * pCursorHdr->cy);
  2780. *pcbXORBitmap = (TSHR_UINT16) *pcbANDMask;
  2781. //
  2782. // Return success.
  2783. //
  2784. rc = TRUE;
  2785. DC_EXIT_POINT:
  2786. DebugExitDWORD(CMGetMonoCursor, rc);
  2787. return(rc);
  2788. }
  2789. //
  2790. // FUNCTION: CMSetCursorTransform
  2791. //
  2792. // DESCRIPTION:
  2793. //
  2794. // This function is responsible for setting cursor transforms.
  2795. //
  2796. // PARAMETERS:
  2797. //
  2798. // cWidth - the width in pels of the AND mask and the XOR DIB
  2799. // cHeight - the height in pels of the AND mask and the XOR DIB
  2800. // pOrigANDMask - a pointer to the bits of a WORD padded AND mask (the
  2801. // bits are top-down)
  2802. // pOrigXORDIB - a pointer to a DIB of the size given by cWidth and
  2803. // cHeight.
  2804. //
  2805. //
  2806. BOOL ASHost::CMSetCursorTransform
  2807. (
  2808. LPBYTE pOrigANDMask,
  2809. LPBITMAPINFO pOrigXORDIB
  2810. )
  2811. {
  2812. BOOL rc = FALSE;
  2813. LPBYTE pBits = NULL;
  2814. UINT cbSize;
  2815. CM_DRV_XFORM_INFO drvXformInfo;
  2816. UINT srcRowLength;
  2817. DebugEntry(ASHost::CMSetCursorTransform);
  2818. //
  2819. // The transform should be monochrome
  2820. //
  2821. ASSERT(pOrigXORDIB->bmiHeader.biBitCount == 1);
  2822. //
  2823. // For mono tags, create a single 1bpp DIB with AND followed by XOR
  2824. // data. Since both the AND mask and the XOR bitmap are word
  2825. // aligned we need to know the word aligned row length for
  2826. // allocating memory.
  2827. //
  2828. //
  2829. // Calculate the source and destination row lengths (in bytes).
  2830. //
  2831. srcRowLength = ((m_pShare->m_cmCursorWidth + 15)/16) * 2;
  2832. cbSize = srcRowLength * m_pShare->m_cmCursorHeight;
  2833. pBits = new BYTE[cbSize * 2];
  2834. if (!pBits)
  2835. {
  2836. ERROR_OUT(( "Alloc %lu bytes failed", cbSize * 2));
  2837. DC_QUIT;
  2838. }
  2839. //
  2840. // Copy the packed 1bpp AND and XOR bits to the buffer
  2841. //
  2842. TRACE_OUT(( "Copy %d bytes from 0x%08x", cbSize, pOrigANDMask));
  2843. //
  2844. // Copy the AND and XOR 1bpp masks.
  2845. //
  2846. memcpy(pBits, pOrigANDMask, cbSize);
  2847. memcpy(pBits + cbSize, POINTER_TO_DIB_BITS(pOrigXORDIB), cbSize);
  2848. //
  2849. // Call the display driver to set the pointer transform.
  2850. //
  2851. drvXformInfo.width = m_pShare->m_cmCursorWidth;
  2852. drvXformInfo.height = m_pShare->m_cmCursorHeight;
  2853. drvXformInfo.pANDMask = pBits;
  2854. drvXformInfo.result = FALSE;
  2855. if (!OSI_FunctionRequest(CM_ESC_XFORM, (LPOSI_ESCAPE_HEADER)&drvXformInfo,
  2856. sizeof(drvXformInfo)) ||
  2857. !drvXformInfo.result)
  2858. {
  2859. ERROR_OUT(("CM_ESC_XFORM failed"));
  2860. DC_QUIT;
  2861. }
  2862. //
  2863. // Set flag inidicating that transform is applied.
  2864. //
  2865. m_cmfCursorTransformApplied = TRUE;
  2866. rc = TRUE;
  2867. DC_EXIT_POINT:
  2868. //
  2869. // Release allocated memory, bitmaps, DCs.
  2870. //
  2871. if (pBits)
  2872. {
  2873. delete[] pBits;
  2874. }
  2875. DebugExitBOOL(ASHost::CMSetCursorTransform, rc);
  2876. return(rc);
  2877. }
  2878. //
  2879. // FUNCTION: CMRemoveCursorTransform
  2880. //
  2881. // DESCRIPTION:
  2882. // This function is responsible for removing cursor transforms.
  2883. //
  2884. // PARAMETERS: None.
  2885. //
  2886. void ASHost::CMRemoveCursorTransform(void)
  2887. {
  2888. DebugEntry(ASHost::CMRemoveCursorTransform);
  2889. //
  2890. // Check to see if there is currently a transform applied.
  2891. //
  2892. if (m_cmfCursorTransformApplied)
  2893. {
  2894. CM_DRV_XFORM_INFO drvXformInfo;
  2895. //
  2896. // Call down to the display driver to remove the pointer tag.
  2897. //
  2898. drvXformInfo.pANDMask = NULL;
  2899. drvXformInfo.result = FALSE;
  2900. OSI_FunctionRequest(CM_ESC_XFORM, (LPOSI_ESCAPE_HEADER)&drvXformInfo,
  2901. sizeof(drvXformInfo));
  2902. m_cmfCursorTransformApplied = FALSE;
  2903. }
  2904. DebugExitVOID(ASHost::CMRemoveCursorTransform);
  2905. }
  2906. //
  2907. // FUNCTION: CMProcessCursorIDPacket
  2908. //
  2909. // DESCRIPTION:
  2910. //
  2911. // Processes a received cursor ID packet.
  2912. //
  2913. // PARAMETERS:
  2914. //
  2915. // pCMPacket - pointer to the received cursor ID packet
  2916. //
  2917. // phNewCursor - pointer to a HCURSOR variable that receives the handle
  2918. // of a cursor that corresponds to the received packet
  2919. //
  2920. // pNewHotSpot - pointer to a POINT variable that receives the hot-spot
  2921. // of the new cursor
  2922. //
  2923. // RETURNS: Nothing
  2924. //
  2925. //
  2926. void ASShare::CMProcessCursorIDPacket
  2927. (
  2928. PCMPACKETID pCMPacket,
  2929. HCURSOR* phNewCursor,
  2930. LPPOINT pNewHotSpot
  2931. )
  2932. {
  2933. DebugEntry(ASShare::CMProcessCursorIDPacket);
  2934. //
  2935. // We only support NULL and ARROW
  2936. //
  2937. //
  2938. // If the IDC is not NULL then load the cursor.
  2939. //
  2940. if (pCMPacket->idc != CM_IDC_NULL)
  2941. {
  2942. if (pCMPacket->idc != CM_IDC_ARROW)
  2943. {
  2944. WARNING_OUT(("ProcessCursorIDPacket: unrecognized ID, using arrow"));
  2945. }
  2946. *phNewCursor = m_cmArrowCursor;
  2947. *pNewHotSpot = m_cmArrowCursorHotSpot;
  2948. }
  2949. else
  2950. {
  2951. // NULL is used for hidden cursors
  2952. *phNewCursor = NULL;
  2953. pNewHotSpot->x = 0;
  2954. pNewHotSpot->y = 0;
  2955. }
  2956. DebugExitVOID(ASShare::CMProcessCursorIDPacket);
  2957. }
  2958. //
  2959. // CM_Controlled()
  2960. //
  2961. // Called when we start/stop being controlled.
  2962. //
  2963. extern CURTAGINFO g_cti;
  2964. void ASHost::CM_Controlled(ASPerson * pasController)
  2965. {
  2966. char szAbbreviatedName[128];
  2967. DebugEntry(ASHost::CM_Controlled);
  2968. //
  2969. // If we are not being controlled, turn off the cursor tag. Note that
  2970. // being detached means we aren't controlled.
  2971. //
  2972. if (!pasController)
  2973. {
  2974. // We're not being controlled by a remote. No cursor xform
  2975. CMRemoveCursorTransform();
  2976. }
  2977. else
  2978. {
  2979. BOOL fAbbreviated = CMCreateAbbreviatedName(pasController->scName,
  2980. szAbbreviatedName, sizeof(szAbbreviatedName));
  2981. if ( !fAbbreviated )
  2982. {
  2983. lstrcpyn(szAbbreviatedName, pasController->scName,
  2984. ARRAY_ELEMENTS(szAbbreviatedName));
  2985. }
  2986. if (!CMGetCursorTagInfo(szAbbreviatedName))
  2987. {
  2988. ERROR_OUT(("GetCurTagInfo failed, not setting cursor tag"));
  2989. }
  2990. else
  2991. {
  2992. CMSetCursorTransform(&g_cti.aAndBits[0], &g_cti.bmInfo);
  2993. }
  2994. }
  2995. DebugExitVOID(ASHost::CM_Controlled);
  2996. }
  2997. // This initializes our single, volatile data for
  2998. // creating cursor tags.
  2999. CURTAGINFO g_cti = {
  3000. 32, // height of masks
  3001. 32, // width of masks
  3002. // bits describing the AND mask, this is a 12x24 rectangle in lower right
  3003. // if the tag size is changed, the mask will have to be edited, the
  3004. // following helps draw attention to this
  3005. #if ( TAGXOFF != 8 || TAGYOFF != 20 || TAGXSIZ != 24 || TAGYSIZ != 12 )
  3006. #error "Bitmap mask may be incorrect"
  3007. #endif
  3008. { 0xff, 0xff, 0xff, 0xff, // line 1
  3009. 0xff, 0xff, 0xff, 0xff, // line 2
  3010. 0xff, 0xff, 0xff, 0xff, // line 3
  3011. 0xff, 0xff, 0xff, 0xff, // line 4
  3012. 0xff, 0xff, 0xff, 0xff, // line 5
  3013. 0xff, 0xff, 0xff, 0xff, // line 6
  3014. 0xff, 0xff, 0xff, 0xff, // line 7
  3015. 0xff, 0xff, 0xff, 0xff, // line 8
  3016. 0xff, 0xff, 0xff, 0xff, // line 9
  3017. 0xff, 0xff, 0xff, 0xff, // line 10
  3018. 0xff, 0xff, 0xff, 0xff, // line 11
  3019. 0xff, 0xff, 0xff, 0xff, // line 12
  3020. 0xff, 0xff, 0xff, 0xff, // line 13
  3021. 0xff, 0xff, 0xff, 0xff, // line 14
  3022. 0xff, 0xff, 0xff, 0xff, // line 15
  3023. 0xff, 0xff, 0xff, 0xff, // line 16
  3024. 0xff, 0xff, 0xff, 0xff, // line 17
  3025. 0xff, 0xff, 0xff, 0xff, // line 18
  3026. 0xff, 0xff, 0xff, 0xff, // line 19
  3027. 0xff, 0xff, 0xff, 0xff, // line 20
  3028. 0xff, 0x00, 0x00, 0x00, // line 21
  3029. 0xff, 0x00, 0x00, 0x00, // line 22
  3030. 0xff, 0x00, 0x00, 0x00, // line 23
  3031. 0xff, 0x00, 0x00, 0x00, // line 24
  3032. 0xff, 0x00, 0x00, 0x00, // line 25
  3033. 0xff, 0x00, 0x00, 0x00, // line 26
  3034. 0xff, 0x00, 0x00, 0x00, // line 27
  3035. 0xff, 0x00, 0x00, 0x00, // line 28
  3036. 0xff, 0x00, 0x00, 0x00, // line 29
  3037. 0xff, 0x00, 0x00, 0x00, // line 30
  3038. 0xff, 0x00, 0x00, 0x00, // line 31
  3039. 0xff, 0x00, 0x00, 0x00 // line 32
  3040. },
  3041. // Initialize the BITMAPINFO structure:
  3042. {
  3043. // Initialize the BITMAPINFOHEADER structure:
  3044. {
  3045. sizeof(BITMAPINFOHEADER),
  3046. 32, // width
  3047. -32, // height (top down bitmap)
  3048. 1, // planes
  3049. 1, // bits per pixel
  3050. BI_RGB, // compression format (none)
  3051. 0, // not used for uncompressed bitmaps
  3052. 0, // xpels per meter, not set
  3053. 0, // ypels per meter, not set
  3054. 0, // biClrsUsed, indicates 2 color entries follow this struct
  3055. 0 // biClrsImportant (all)
  3056. },
  3057. // Initialize the foreground color (part of BITMAPINFO struct)
  3058. // This is BLACK
  3059. { 0x0, 0x0, 0x0, 0x0 },
  3060. },
  3061. // Initialize the background color (part of single RGBQUAD struct following
  3062. // BITMAPINFO STRUCTURE
  3063. { 0xff, 0xff, 0xff, 0x00 },
  3064. // Because this is a packed bitmap, the bitmap bits follow:
  3065. // These will be written into dynamically to create the tag
  3066. { 0, }
  3067. };
  3068. //
  3069. // This function isn't DBCS safe, so we don't abbreviate in
  3070. // DBCS character sets
  3071. //
  3072. BOOL ASShare::CMCreateAbbreviatedName
  3073. (
  3074. LPCSTR szTagName,
  3075. LPSTR szBuf,
  3076. UINT cbBuf
  3077. )
  3078. {
  3079. BOOL rc = FALSE;
  3080. DebugEntry(ASShare::CMCreateAbbreviatedName);
  3081. if (GetSystemMetrics(SM_DBCSENABLED))
  3082. {
  3083. TRACE_OUT(("Do not attempt to abbreviate on DBCS system"));
  3084. DC_QUIT;
  3085. }
  3086. // We will try to create initials first
  3087. LPSTR p;
  3088. if ( NULL != (p = (LPSTR) _StrChr ( szTagName, ' ' )))
  3089. {
  3090. // Enough room for initials?
  3091. if (cbBuf < NTRUNCLETTERS)
  3092. {
  3093. TRACE_OUT(("CMCreateAbbreviatedName: not enough room for initials"));
  3094. DC_QUIT;
  3095. }
  3096. char * q = szBuf;
  3097. *q++ = *szTagName;
  3098. *q++ = '.';
  3099. *q++ = *(p+1);
  3100. *q++ = '.';
  3101. *q = '\0';
  3102. CharUpper ( q );
  3103. rc = TRUE;
  3104. }
  3105. DC_EXIT_POINT:
  3106. DebugExitBOOL(ASShare::CMCreateAbbreviatedName, rc);
  3107. return(rc);
  3108. }
  3109. // This function will create the appropriate data in the
  3110. // volatile global and return a pointer to it.
  3111. BOOL ASHost::CMGetCursorTagInfo(LPCSTR szTagName)
  3112. {
  3113. HDC hdc = NULL;
  3114. HDC hdcScratch = NULL;
  3115. HBITMAP hBmpOld = NULL;
  3116. HBITMAP hBitmap = NULL;
  3117. PCURTAGINFO pctiRet = NULL;
  3118. RECT rect;
  3119. HFONT hOldFont;
  3120. BOOL rc = FALSE;
  3121. DebugEntry(ASHost::CMGetCursorTagInfo);
  3122. hdcScratch = CreateCompatibleDC(NULL);
  3123. if (!hdcScratch)
  3124. {
  3125. ERROR_OUT(("CMGetCursorTagInfo: couldn't get scratch DC"));
  3126. DC_QUIT;
  3127. }
  3128. hBitmap = CreateDIBitmap(hdcScratch,
  3129. &(g_cti.bmInfo.bmiHeader),
  3130. 0, // don't initialize bits
  3131. NULL, // don't initialize bits
  3132. &(g_cti.bmInfo),
  3133. DIB_RGB_COLORS );
  3134. if (!hBitmap)
  3135. {
  3136. ERROR_OUT(("CMGetCursorTagInfo: failed to create bitmap"));
  3137. DC_QUIT;
  3138. }
  3139. hBmpOld = SelectBitmap(hdcScratch, hBitmap);
  3140. hOldFont = SelectFont(hdcScratch, m_pShare->m_cmCursorTagFont);
  3141. // Create the tag background...
  3142. PatBlt ( hdcScratch, 0, 0, 32, 32, BLACKNESS );
  3143. PatBlt ( hdcScratch, TAGXOFF, TAGYOFF, TAGXSIZ, TAGYSIZ, WHITENESS );
  3144. // Now see how many characters of the name or abbreviation
  3145. // we can fit into the tag
  3146. int cCharsFit;
  3147. SIZE size;
  3148. LPSTR p;
  3149. // First assume the whole thing fits
  3150. cCharsFit = lstrlen(szTagName);
  3151. // Now try to find out how big a part actually fits
  3152. rect.left = rect.top = rect.right = rect.bottom = 0;
  3153. for ( p = CharNext(szTagName); ; p = CharNext(p) )
  3154. {
  3155. if ( DrawText(hdcScratch, szTagName, (int)(p - szTagName), &rect,
  3156. DT_CALCRECT | DT_SINGLELINE | DT_NOPREFIX ) )
  3157. {
  3158. if ( rect.right > TAGXSIZ )
  3159. {
  3160. // This number of characters no longer fits into the
  3161. // tag. Take the next smaller number and leave the loop
  3162. cCharsFit = (int)(CharPrev(szTagName, p) - szTagName);
  3163. break;
  3164. }
  3165. }
  3166. if ( NULL == *p )
  3167. break;
  3168. }
  3169. TRACE_OUT(("Tag: [%s], showing %d chars", szTagName, cCharsFit ));
  3170. // Now draw the text...
  3171. // DrawText doesn't return a documented error...
  3172. rect.top = TAGYOFF;
  3173. rect.left = TAGXOFF;
  3174. rect.bottom = TAGYOFF + TAGYSIZ;
  3175. rect.right = TAGXOFF + TAGXSIZ;
  3176. DrawText ( hdcScratch, szTagName, cCharsFit, &rect,
  3177. DT_CENTER | DT_SINGLELINE | DT_NOPREFIX );
  3178. SelectFont (hdcScratch, hOldFont);
  3179. // Now get the bitmap bits into the global volatile data area
  3180. // Make sure the number of scan lines requested is returned
  3181. if ( 32 != GetDIBits ( hdcScratch,
  3182. hBitmap,
  3183. 0,
  3184. 32,
  3185. g_cti.aXorBits,
  3186. &(g_cti.bmInfo),
  3187. DIB_RGB_COLORS ))
  3188. {
  3189. ERROR_OUT(("CMGetCursorTagInfo: GetDIBits failed"));
  3190. DC_QUIT;
  3191. }
  3192. // Reset the foreground and background colors to black
  3193. // and white respectively no matter what GetDIBits has filled in.
  3194. // REVIEW: how do we get GetDIBits to fill in the expected (B&W) color
  3195. // table?
  3196. g_cti.bmInfo.bmiColors[0].rgbBlue = 0x0;
  3197. g_cti.bmInfo.bmiColors[0].rgbGreen = 0x0;
  3198. g_cti.bmInfo.bmiColors[0].rgbRed = 0x0;
  3199. g_cti.bmInfo.bmiColors[0].rgbReserved = 0;
  3200. g_cti.rgbBackground[0].rgbBlue = 0xff;
  3201. g_cti.rgbBackground[0].rgbGreen = 0xff;
  3202. g_cti.rgbBackground[0].rgbRed = 0xff;
  3203. g_cti.rgbBackground[0].rgbReserved = 0;
  3204. // Finally, we are happy
  3205. rc = TRUE;
  3206. DC_EXIT_POINT:
  3207. // Perform necessary cleanup
  3208. if (hBmpOld)
  3209. SelectBitmap ( hdcScratch, hBmpOld);
  3210. if ( hBitmap )
  3211. DeleteBitmap ( hBitmap );
  3212. if ( hdcScratch )
  3213. DeleteDC ( hdcScratch );
  3214. DebugExitBOOL(ASHost::CMGetCursorTagInfo, rc);
  3215. return(rc);
  3216. }
  3217.