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.

262 lines
8.4 KiB

  1. #include "pch.h"
  2. #pragma hdrstop
  3. /*-----------------------------------------------------------------------------
  4. / Misc data
  5. /----------------------------------------------------------------------------*/
  6. //
  7. // mapping of class to resource ID's
  8. //
  9. typedef struct
  10. {
  11. LPCWSTR pObjectClass;
  12. INT iResource;
  13. } CLASSTORESOURCE, * LPCLASSTORESOURCE;
  14. CLASSTORESOURCE normalIcons[] =
  15. {
  16. L"builtInDomain", IDI_BUILTINDOMAIN,
  17. L"computer", IDI_COMPUTER,
  18. L"configuration", IDI_CONFIGURATION,
  19. L"rpcContainer", IDI_CONFIGURATION,
  20. L"contact", IDI_CONTACT,
  21. L"container", IDI_CONTAINER,
  22. L"domainDNS", IDI_DOMAINDNS,
  23. L"domainPolicy", IDI_DOMAINPOLICY,
  24. L"group", IDI_GROUP,
  25. L"localGroup", IDI_GROUP,
  26. L"localPolicy", IDI_LOCALPOLICY,
  27. L"nTDSConnection", IDI_NTDSCONNECTION,
  28. L"nTDSDSA", IDI_NTDSDSA,
  29. L"nTDSSettings", IDI_NTDSSETTINGS,
  30. L"organizationalPerson", IDI_ORGANIZATIONALPERSON,
  31. L"organizationalUnit", IDI_ORGANIZATIONALUNIT,
  32. L"person", IDI_PERSON,
  33. L"printQueue", IDI_PRINTQUEUE,
  34. L"remoteMailRecipient", IDI_REMOTEMAILRECIPIENT,
  35. L"server", IDI_SERVER,
  36. L"serverConnection", IDI_SERVERCONNECTION,
  37. L"site", IDI_SITE,
  38. L"sitesContainer", IDI_SITESCONTAINER,
  39. L"storage", IDI_STORAGE,
  40. L"subnet", IDI_SUBNET,
  41. L"subnetContainer", IDI_CONTAINER,
  42. L"user", IDI_USER,
  43. L"volume", IDI_VOLUME,
  44. L"workStationAccount", IDI_WORKSTATIONACCOUNT,
  45. // added daviddv (05jun98) for jonn
  46. L"licensingSiteSettings", IDI_LICENSING,
  47. L"nTDSSiteSettings", IDI_NTDSSITESETTINGS,
  48. L"siteLink", IDI_SITELINK,
  49. L"siteLinkBridge", IDI_SITELINK,
  50. // added daviddv (19jun98) for jonn
  51. L"nTFRSSettings", IDI_NTFRS,
  52. L"nTFRSReplicaSet", IDI_NTFRS,
  53. L"nTFRSSubscriptions", IDI_NTFRS,
  54. L"nTFRSSubscriber", IDI_NTFRS,
  55. L"nTFRSMember", IDI_NTFRS,
  56. // added daviddv (23jun98) for ericb
  57. L"foreignSecurityPrincipal", IDI_FPO,
  58. // added daviddv (29oct98) for jonn
  59. L"interSiteTransport", IDI_CONTAINER,
  60. L"interSiteTransportContainer", IDI_CONTAINER,
  61. L"serversContainer", IDI_CONTAINER,
  62. // added jeffjon (30nov2000) for jccannon
  63. L"inetOrgPerson", IDI_USER,
  64. NULL, NULL,
  65. };
  66. CLASSTORESOURCE openIcons[] =
  67. {
  68. L"container", IDI_CONTAINER_OPEN,
  69. L"subnetContainer", IDI_CONTAINER_OPEN,
  70. L"interSiteTransport", IDI_CONTAINER_OPEN,
  71. L"interSiteTransportContainer", IDI_CONTAINER_OPEN,
  72. L"serversContainer", IDI_CONTAINER_OPEN,
  73. NULL, NULL,
  74. };
  75. CLASSTORESOURCE disabledIcons[] =
  76. {
  77. L"user", IDI_USER_DISABLED,
  78. L"computer", IDI_COMPUTER_DISABLED,
  79. // added jeffjon (15dec2000) for jccannon
  80. L"inetOrgPerson", IDI_USER_DISABLED,
  81. NULL, NULL,
  82. };
  83. //
  84. // mapping of states to icon tables
  85. //
  86. LPCLASSTORESOURCE state_to_icons[] =
  87. {
  88. normalIcons, // DSGIF_ISNORMAL
  89. openIcons, // DSGIF_ISOPEN
  90. disabledIcons, // DSGIF_ISDISABLED
  91. };
  92. //
  93. // Look up a locally stored icon given its class and state.
  94. //
  95. BOOL _GetIconForState(LPWSTR pObjectClass, INT iState, INT* pindex)
  96. {
  97. BOOL fFound = FALSE;
  98. INT i;
  99. USES_CONVERSION;
  100. TraceEnter(TRACE_ICON, "_GetIconForState");
  101. Trace(TEXT("Find icon for class: %s, state: %d"), W2T(pObjectClass), iState);
  102. if ( iState < ARRAYSIZE(state_to_icons) )
  103. {
  104. LPCLASSTORESOURCE pTable = state_to_icons[iState];
  105. for ( i = 0 ; !fFound && pTable[i].pObjectClass ; i++ )
  106. {
  107. if ( !StrCmpIW(pTable[i].pObjectClass, pObjectClass) )
  108. {
  109. Trace(TEXT("Found icon at index %d"), i);
  110. *pindex = -pTable[i].iResource;
  111. fFound = TRUE;
  112. }
  113. }
  114. }
  115. TraceLeaveValue(fFound);
  116. }
  117. /*-----------------------------------------------------------------------------
  118. / _GetIconLocation
  119. / ----------------
  120. / Given a cache record for the icon, attempt to fetch the icon location from
  121. / it.
  122. /
  123. / In:
  124. / pCacheEntry -> locked cacherecord
  125. / dwFlags = flags indicating which icon is required
  126. / pBuffer -> buffer that receives the name
  127. / cchBuffer = maximum size of the name buffer
  128. / piIndex = receives the resource ID of the loaded resource
  129. /
  130. / Out:
  131. / HRESULT
  132. /----------------------------------------------------------------------------*/
  133. HRESULT _GetModuleLocation(LPWSTR pBuffer, INT cchBuffer)
  134. {
  135. HRESULT hr = S_OK;
  136. TraceEnter(TRACE_ICON,"_GetModuleLocation");
  137. #if UNICODE
  138. if ( !GetModuleFileName(GLOBAL_HINSTANCE, pBuffer, cchBuffer) )
  139. ExitGracefully(hr, E_FAIL, "Failed to get module location");
  140. #else
  141. TCHAR szBuffer[MAX_PATH];
  142. if ( !GetModuleFileName(GLOBAL_HINSTANCE, szBuffer, ARRAYSIZE(szBuffer)) )
  143. ExitGracefully(hr, E_FAIL, "Failed to get module location");
  144. MultiByteToWideChar(CP_ACP, 0, szBuffer, -1, pBuffer, cchBuffer);
  145. #endif
  146. exit_gracefully:
  147. TraceLeaveResult(hr);
  148. }
  149. HRESULT _GetIconLocation(LPCLASSCACHEENTRY pCacheEntry, DWORD dwFlags, LPWSTR pBuffer, INT cchBuffer, INT* piIndex)
  150. {
  151. HRESULT hr;
  152. INT iState = dwFlags & DSGIF_ISMASK;
  153. USES_CONVERSION;
  154. TraceEnter(TRACE_ICON, "_GetIconLocation");
  155. if ( !pBuffer || !piIndex || (iState >= ARRAYSIZE(pCacheEntry->pIconName)) )
  156. ExitGracefully(hr, E_INVALIDARG, "No class, buffer or index pointer specified")
  157. // before we get too involved in looking at the cache records lets see if we have
  158. // one already, if not then bail out now.
  159. if ( !pCacheEntry )
  160. ExitGracefully(hr, S_FALSE, "No cache record, returning S_FALSE");
  161. // look up the class in the cache, if that works try and get the icon string
  162. // for the given index, if that yeilds a NULL then try normal. Once we
  163. // have a string pointer then lets copy that and parse out the resource ID.
  164. if ( (pCacheEntry->dwCached & CLASSCACHE_ICONS) &&
  165. (pCacheEntry->pIconName[iState] || pCacheEntry->pIconName[DSGIF_ISNORMAL]) )
  166. {
  167. TraceMsg("Reading icon name from the display specifier strings");
  168. if ( !pCacheEntry->pIconName[iState] )
  169. iState = DSGIF_ISNORMAL;
  170. StrCpyNW(pBuffer, pCacheEntry->pIconName[iState], cchBuffer);
  171. *piIndex = PathParseIconLocationW(pBuffer);
  172. }
  173. else
  174. {
  175. TraceMsg("Attempting to find icon in our fixed resource table");
  176. if ( _GetIconForState(pCacheEntry->pObjectClass, iState, piIndex) ||
  177. _GetIconForState(pCacheEntry->pObjectClass, DSGIF_ISNORMAL, piIndex) )
  178. {
  179. hr = _GetModuleLocation(pBuffer, cchBuffer);
  180. FailGracefully(hr, "Failed to get the module location for dsuiext");
  181. }
  182. else
  183. {
  184. ExitGracefully(hr, S_FALSE, "Failed to find icon bound resources");
  185. }
  186. }
  187. Trace(TEXT("Location: %s, Index: %d"), W2T(pBuffer), *piIndex);
  188. hr = S_OK;
  189. exit_gracefully:
  190. //
  191. // if we failed to look up the icon location, and the caller requested the
  192. // default document icon then lets return the shell def document image
  193. //
  194. if ( (hr == S_FALSE) )
  195. {
  196. if ( dwFlags & DSGIF_DEFAULTISCONTAINER )
  197. {
  198. hr = E_FAIL;
  199. if ( _GetIconForState(L"container", iState, piIndex) ||
  200. _GetIconForState(L"container", DSGIF_ISNORMAL, piIndex) )
  201. {
  202. hr = _GetModuleLocation(pBuffer, cchBuffer);
  203. }
  204. else if ( dwFlags & DSGIF_GETDEFAULTICON )
  205. {
  206. StrCpyNW(pBuffer, L"shell32.dll", cchBuffer);
  207. *piIndex = -1;
  208. }
  209. if ( FAILED(hr) )
  210. {
  211. dwFlags &= ~DSGIF_DEFAULTISCONTAINER;
  212. ExitGracefully(hr, S_FALSE, "Failed to look up icon as container");
  213. }
  214. }
  215. hr = S_OK; // its OK, we have a location now.
  216. }
  217. TraceLeaveResult(hr);
  218. }