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.

259 lines
5.7 KiB

  1. //____________________________________________________________________________
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1995 - 1996.
  5. //
  6. // File: icon.cxx
  7. //
  8. // Contents:
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 4/5/1996 RaviR Created
  15. //
  16. //____________________________________________________________________________
  17. #include "..\pch\headers.hxx"
  18. #pragma hdrstop
  19. #include "dbg.h"
  20. #include "macros.h"
  21. #include "..\inc\resource.h"
  22. #include "resource.h"
  23. #include "jobicons.hxx"
  24. extern HINSTANCE g_hInstance;
  25. CJobIcon::CJobIcon(void)
  26. {
  27. m_himlSmall = NULL; // init so that if creation of m_himlLarge fails,
  28. // the destrucor will not fault.
  29. //
  30. // Large
  31. //
  32. int cx = GetSystemMetrics(SM_CXICON);
  33. int cy = GetSystemMetrics(SM_CYICON);
  34. m_himlLarge = ImageList_Create(cx, cy, TRUE, 1, 1);
  35. if (m_himlLarge == NULL)
  36. {
  37. DEBUG_OUT((DEB_ERROR, "ImageList_Create(large) returned NULL.\n"));
  38. return;
  39. }
  40. HBITMAP hBmp = LoadBitmap(g_hInstance, MAKEINTRESOURCE(BMP_JOBSTATEL));
  41. if (hBmp == NULL)
  42. {
  43. DEBUG_OUT((DEB_ERROR, "LoadBitmap(state-large) returned NULL.\n"));
  44. return;
  45. }
  46. int i = ImageList_AddMasked(m_himlLarge, hBmp, RGB(0, 255, 0));
  47. if (i != 0)
  48. {
  49. DEBUG_OUT((DEB_ERROR, "ImageList_AddMasked returned <%d> expected 0.\n", i));
  50. }
  51. DeleteObject(hBmp);
  52. //
  53. // Small
  54. //
  55. cx = GetSystemMetrics(SM_CXSMICON);
  56. cy = GetSystemMetrics(SM_CYSMICON);
  57. m_himlSmall = ImageList_Create(cx, cy, TRUE, 1, 1);
  58. if (m_himlSmall == NULL)
  59. {
  60. DEBUG_OUT((DEB_ERROR, "ImageList_Create(small) returned NULL.\n"));
  61. return;
  62. }
  63. hBmp = LoadBitmap(g_hInstance, MAKEINTRESOURCE(BMP_JOBSTATES));
  64. if (hBmp == NULL)
  65. {
  66. DEBUG_OUT((DEB_ERROR, "LoadBitmap(state-small) returned NULL.\n"));
  67. return;
  68. }
  69. i = ImageList_AddMasked(m_himlSmall, hBmp, RGB(0, 255, 0));
  70. if (i != 0)
  71. {
  72. DEBUG_OUT((DEB_ERROR, "ImageList_AddMasked returned <%d> expected 0.\n", i));
  73. }
  74. DeleteObject(hBmp);
  75. }
  76. HICON
  77. GetDefaultAppIcon(
  78. BOOL fLarge)
  79. {
  80. TRACE_FUNCTION(GetDefaultAppIcon);
  81. HICON hicon = 0;
  82. int cx = GetSystemMetrics(fLarge ? SM_CXICON : SM_CXSMICON);
  83. int cy = GetSystemMetrics(fLarge ? SM_CYICON : SM_CYSMICON);
  84. hicon = (HICON)LoadImage(g_hInstance, (LPCTSTR)IDI_GENERIC, IMAGE_ICON,
  85. cx, cy, LR_DEFAULTCOLOR);
  86. return hicon;
  87. }
  88. void
  89. CJobIcon::GetIcons(
  90. LPCTSTR pszApp,
  91. BOOL fEnabled,
  92. HICON * phiconLarge,
  93. HICON * phiconSmall)
  94. {
  95. TRACE(CJobIcon, GetIcons);
  96. UINT count;
  97. if (pszApp != NULL && *pszApp != TEXT('\0'))
  98. {
  99. count = ExtractIconEx(pszApp, 0, phiconLarge, phiconSmall, 1);
  100. }
  101. _OverlayIcons(phiconLarge, phiconSmall, fEnabled);
  102. }
  103. //+--------------------------------------------------------------------------
  104. //
  105. // Member: CJobIcon::GetTemplateIcons
  106. //
  107. // Synopsis: Fill out pointers with large and small template icons
  108. //
  109. // Arguments: [phiconLarge] - NULL or ptr to icon handle to fill
  110. // [phiconSmall] - ditto
  111. //
  112. // History: 5-15-1997 DavidMun Created
  113. //
  114. //---------------------------------------------------------------------------
  115. void
  116. CJobIcon::GetTemplateIcons(
  117. HICON * phiconLarge,
  118. HICON * phiconSmall)
  119. {
  120. TRACE(CJobIcon, GetTemplateIcons);
  121. if (phiconLarge)
  122. {
  123. int cx = GetSystemMetrics(SM_CXICON);
  124. int cy = GetSystemMetrics(SM_CYICON);
  125. *phiconLarge = (HICON) LoadImage(g_hInstance,
  126. MAKEINTRESOURCE(IDI_TEMPLATE),
  127. IMAGE_ICON,
  128. cx,
  129. cy,
  130. LR_DEFAULTCOLOR);
  131. if (!*phiconLarge)
  132. {
  133. DEBUG_OUT_LASTERROR;
  134. }
  135. }
  136. if (phiconSmall)
  137. {
  138. int cx = GetSystemMetrics(SM_CXSMICON);
  139. int cy = GetSystemMetrics(SM_CYSMICON);
  140. *phiconSmall = (HICON) LoadImage(g_hInstance,
  141. MAKEINTRESOURCE(IDI_TEMPLATE),
  142. IMAGE_ICON,
  143. cx,
  144. cy,
  145. LR_DEFAULTCOLOR);
  146. if (!*phiconSmall)
  147. {
  148. DEBUG_OUT_LASTERROR;
  149. }
  150. }
  151. }
  152. void
  153. CJobIcon::_OverlayIcons(
  154. HICON * phiconLarge,
  155. HICON * phiconSmall,
  156. BOOL fEnabled)
  157. {
  158. HICON hiconTemp;
  159. if (phiconLarge != NULL)
  160. {
  161. if (*phiconLarge == NULL)
  162. {
  163. *phiconLarge = GetDefaultAppIcon(TRUE);
  164. }
  165. hiconTemp = OverlayStateIcon(*phiconLarge, fEnabled);
  166. DestroyIcon(*phiconLarge);
  167. *phiconLarge = hiconTemp;
  168. }
  169. if (phiconSmall != NULL)
  170. {
  171. if (*phiconSmall == NULL)
  172. {
  173. *phiconSmall = GetDefaultAppIcon(FALSE);
  174. }
  175. hiconTemp = OverlayStateIcon(*phiconSmall, fEnabled, FALSE);
  176. DestroyIcon(*phiconSmall);
  177. *phiconSmall = hiconTemp;
  178. }
  179. }
  180. HICON
  181. CJobIcon::OverlayStateIcon(
  182. HICON hicon,
  183. BOOL fEnabled,
  184. BOOL fLarge)
  185. {
  186. TRACE(CJobIcon, OverlayStateIcon);
  187. HICON hiconOut;
  188. // dont destroy rhiml !!
  189. HIMAGELIST &rhiml = (fLarge == TRUE) ? m_himlLarge : m_himlSmall;
  190. int i = ImageList_AddIcon(rhiml, hicon);
  191. HIMAGELIST himlNew = ImageList_Merge(rhiml, i, rhiml,
  192. (fEnabled ? 0 : 1), 0, 0);
  193. ImageList_Remove(rhiml, i);
  194. hiconOut = ImageList_GetIcon(himlNew, 0, 0);
  195. if (himlNew != NULL)
  196. {
  197. ImageList_Destroy(himlNew);
  198. }
  199. return hiconOut;
  200. }