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.

197 lines
4.8 KiB

  1. /*++
  2. *
  3. * WOW v1.0
  4. *
  5. * Copyright (c) 1991, Microsoft Corporation
  6. *
  7. * WCURCASH.H
  8. * WOW32 Cursor & Icon cash worker routines.
  9. *
  10. * History:
  11. * Created on Jan 27th-93 by ChandanC
  12. *
  13. --*/
  14. #include "precomp.h"
  15. #pragma hdrstop
  16. STATIC PCURICON pCurIconFirst = NULL; // pointer to first hCurIcon entry
  17. HICON16 W32CheckWOWCashforIconCursors(VPVOID pData, WORD ResType)
  18. {
  19. register PICONCUR16 parg16;
  20. HICON16 hIcon16;
  21. HICON16 hRes16;
  22. PSZ psz;
  23. HAND32 h32;
  24. GETMISCPTR(pData, parg16);
  25. GETPSZIDPTR(parg16->lpStr, psz);
  26. hIcon16 = W32FindCursorIcon (parg16->hInst, psz, ResType, &hRes16);
  27. if (hIcon16) {
  28. if (ResType == (WORD) RT_ICON) {
  29. h32 = HICON32(hIcon16);
  30. ResType = HANDLE_TYPE_ICON;
  31. }
  32. else {
  33. h32 = HCURSOR32(hIcon16);
  34. ResType = HANDLE_TYPE_CURSOR;
  35. }
  36. hIcon16 = SetupResCursorIconAlias((HAND16) parg16->hInst, h32, (HANDLE) hRes16, (UINT) ResType);
  37. }
  38. FREEPSZIDPTR(psz);
  39. FREEMISCPTR(parg16);
  40. return (hIcon16);
  41. }
  42. HICON16 W32FindCursorIcon (WORD hInst, LPSTR psz, WORD ResType, HICON16 *phRes16)
  43. {
  44. PCURICON pTemp;
  45. pTemp = pCurIconFirst;
  46. while (pTemp) {
  47. if (pTemp->ResType == ResType) {
  48. if (pTemp->hInst == hInst) {
  49. if ((HIWORD(psz) != 0) && (HIWORD(pTemp->lpszIcon) != 0)) {
  50. if (!(WOW32_stricmp(psz, (LPSTR)pTemp->lpszIcon))) {
  51. *phRes16 = pTemp->hRes16;
  52. return (pTemp->hIcon16);
  53. }
  54. }
  55. else if ((HIWORD(psz) == 0) && (HIWORD(pTemp->lpszIcon) == 0)) {
  56. if ((WORD) pTemp->lpszIcon == (WORD)psz) {
  57. *phRes16 = pTemp->hRes16;
  58. return (pTemp->hIcon16);
  59. }
  60. }
  61. }
  62. }
  63. pTemp = pTemp->pNext;
  64. }
  65. return 0;
  66. }
  67. BOOL W32AddCursorIconCash (WORD hInst, LPSTR psz1, HICON16 hIcon16, HICON16 hRes16, WORD ResType)
  68. {
  69. PCURICON pCurIcon;
  70. PSZ psz2;
  71. WORD cb;
  72. // if "psz1" is a string, allocate the memory for it
  73. if ((WORD)HIWORD(psz1) != (WORD)NULL) {
  74. cb = strlen(psz1)+1;
  75. if (psz2 = malloc_w_small(cb)) {
  76. memcpy (psz2, psz1, cb);
  77. }
  78. else {
  79. LOGDEBUG (0, ("WOW::W32AddCursorIcon: Memory allocation failed *** \n"));
  80. return (0);
  81. }
  82. }
  83. else {
  84. psz2 = psz1;
  85. }
  86. if (pCurIcon = malloc_w_small (sizeof(CURICON))) {
  87. pCurIcon->pNext = pCurIconFirst;
  88. pCurIconFirst = pCurIcon; // update list head
  89. pCurIcon->hInst = hInst;
  90. pCurIcon->lpszIcon = (DWORD)psz2;
  91. pCurIcon->hIcon16 = hIcon16;
  92. pCurIcon->hRes16 = hRes16;
  93. pCurIcon->ResType = ResType;
  94. pCurIcon->dwThreadID = CURRENTPTD()->dwThreadID;
  95. return (TRUE);
  96. }
  97. else {
  98. LOGDEBUG(0, ("WOW::WAddCursorIcon(): *** memory allocation failed *** \n"));
  99. return (FALSE);
  100. }
  101. }
  102. // This routine deletes a resource (Cursor or Icon) from the cash.
  103. VOID W32DeleteCursorIconCash (HICON16 hRes16)
  104. {
  105. PCURICON pTemp;
  106. PCURICON pTempLast;
  107. pTemp = pCurIconFirst;
  108. while (pTemp) {
  109. if (pTemp->hRes16 == hRes16) {
  110. if (pTemp == pCurIconFirst) {
  111. pCurIconFirst = pTemp->pNext;
  112. }
  113. else {
  114. pTempLast->pNext = pTemp->pNext;
  115. }
  116. // if its a string, delete the memory that we allocated for it
  117. if ((WORD)HIWORD(pTemp->lpszIcon) != (WORD)NULL) {
  118. free_w_small ((PVOID)pTemp->lpszIcon);
  119. }
  120. free_w_small (pTemp);
  121. pTemp = NULL;
  122. }
  123. else {
  124. pTempLast = pTemp;
  125. pTemp = pTemp->pNext;
  126. }
  127. }
  128. }
  129. // This routine deletes all the cursors and Icons when a task terminates.
  130. VOID W32DeleteCursorIconCashForTask ()
  131. {
  132. DWORD dwThreadID;
  133. PCURICON pTemp;
  134. PCURICON pTempLast;
  135. PCURICON pTempNext;
  136. dwThreadID = CURRENTPTD()->dwThreadID;
  137. pTemp = pCurIconFirst;
  138. while (pTemp) {
  139. if (pTemp->dwThreadID == dwThreadID) {
  140. if (pTemp == pCurIconFirst) {
  141. pCurIconFirst = pTemp->pNext;
  142. }
  143. else {
  144. pTempLast->pNext = pTemp->pNext;
  145. }
  146. // if its a string, delete the memory that we allocated for it
  147. if ((WORD)HIWORD(pTemp->lpszIcon) != (WORD)NULL) {
  148. free_w_small ((PVOID)pTemp->lpszIcon);
  149. }
  150. pTempNext = pTemp->pNext;
  151. free_w_small (pTemp);
  152. pTemp = pTempNext;
  153. }
  154. else {
  155. pTempLast = pTemp;
  156. pTemp = pTemp->pNext;
  157. }
  158. }
  159. }