Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

251 lines
8.3 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. TraceEnter(TRACE_ICON, "_GetIconForState");
  100. Trace(TEXT("Find icon for class: %s, state: %d"), pObjectClass, iState);
  101. if ( iState < ARRAYSIZE(state_to_icons) )
  102. {
  103. LPCLASSTORESOURCE pTable = state_to_icons[iState];
  104. for ( i = 0 ; !fFound && pTable[i].pObjectClass ; i++ )
  105. {
  106. if ( !StrCmpIW(pTable[i].pObjectClass, pObjectClass) )
  107. {
  108. Trace(TEXT("Found icon at index %d"), i);
  109. *pindex = -pTable[i].iResource;
  110. fFound = TRUE;
  111. }
  112. }
  113. }
  114. TraceLeaveValue(fFound);
  115. }
  116. /*-----------------------------------------------------------------------------
  117. / _GetIconLocation
  118. / ----------------
  119. / Given a cache record for the icon, attempt to fetch the icon location from
  120. / it.
  121. /
  122. / In:
  123. / pCacheEntry -> locked cacherecord
  124. / dwFlags = flags indicating which icon is required
  125. / pBuffer -> buffer that receives the name
  126. / cchBuffer = maximum size of the name buffer
  127. / piIndex = receives the resource ID of the loaded resource
  128. /
  129. / Out:
  130. / HRESULT
  131. /----------------------------------------------------------------------------*/
  132. HRESULT _GetModuleLocation(LPWSTR pBuffer, INT cchBuffer)
  133. {
  134. HRESULT hr = S_OK;
  135. TraceEnter(TRACE_ICON,"_GetModuleLocation");
  136. if ( !GetModuleFileName(GLOBAL_HINSTANCE, pBuffer, cchBuffer) )
  137. ExitGracefully(hr, E_FAIL, "Failed to get module location");
  138. exit_gracefully:
  139. TraceLeaveResult(hr);
  140. }
  141. HRESULT _GetIconLocation(LPCLASSCACHEENTRY pCacheEntry, DWORD dwFlags, LPWSTR pBuffer, INT cchBuffer, INT* piIndex)
  142. {
  143. HRESULT hr;
  144. INT iState = dwFlags & DSGIF_ISMASK;
  145. TraceEnter(TRACE_ICON, "_GetIconLocation");
  146. if ( !pBuffer || !piIndex || (iState >= ARRAYSIZE(pCacheEntry->pIconName)) )
  147. ExitGracefully(hr, E_INVALIDARG, "No class, buffer or index pointer specified")
  148. // before we get too involved in looking at the cache records lets see if we have
  149. // one already, if not then bail out now.
  150. if ( !pCacheEntry )
  151. ExitGracefully(hr, S_FALSE, "No cache record, returning S_FALSE");
  152. // look up the class in the cache, if that works try and get the icon string
  153. // for the given index, if that yeilds a NULL then try normal. Once we
  154. // have a string pointer then lets copy that and parse out the resource ID.
  155. if ( (pCacheEntry->dwCached & CLASSCACHE_ICONS) &&
  156. (pCacheEntry->pIconName[iState] || pCacheEntry->pIconName[DSGIF_ISNORMAL]) )
  157. {
  158. TraceMsg("Reading icon name from the display specifier strings");
  159. if ( !pCacheEntry->pIconName[iState] )
  160. iState = DSGIF_ISNORMAL;
  161. StrCpyNW(pBuffer, pCacheEntry->pIconName[iState], cchBuffer);
  162. *piIndex = PathParseIconLocationW(pBuffer);
  163. }
  164. else
  165. {
  166. TraceMsg("Attempting to find icon in our fixed resource table");
  167. if ( _GetIconForState(pCacheEntry->pObjectClass, iState, piIndex) ||
  168. _GetIconForState(pCacheEntry->pObjectClass, DSGIF_ISNORMAL, piIndex) )
  169. {
  170. hr = _GetModuleLocation(pBuffer, cchBuffer);
  171. FailGracefully(hr, "Failed to get the module location for dsuiext");
  172. }
  173. else
  174. {
  175. ExitGracefully(hr, S_FALSE, "Failed to find icon bound resources");
  176. }
  177. }
  178. Trace(TEXT("Location: %s, Index: %d"), pBuffer, *piIndex);
  179. hr = S_OK;
  180. exit_gracefully:
  181. //
  182. // if we failed to look up the icon location, and the caller requested the
  183. // default document icon then lets return the shell def document image
  184. //
  185. if ( (hr == S_FALSE) )
  186. {
  187. if ( dwFlags & DSGIF_DEFAULTISCONTAINER )
  188. {
  189. hr = E_FAIL;
  190. if ( _GetIconForState(L"container", iState, piIndex) ||
  191. _GetIconForState(L"container", DSGIF_ISNORMAL, piIndex) )
  192. {
  193. hr = _GetModuleLocation(pBuffer, cchBuffer);
  194. }
  195. else if ( dwFlags & DSGIF_GETDEFAULTICON )
  196. {
  197. StrCpyNW(pBuffer, L"shell32.dll", cchBuffer);
  198. *piIndex = -1;
  199. }
  200. if ( FAILED(hr) )
  201. {
  202. dwFlags &= ~DSGIF_DEFAULTISCONTAINER;
  203. ExitGracefully(hr, S_FALSE, "Failed to look up icon as container");
  204. }
  205. }
  206. hr = S_OK; // its OK, we have a location now.
  207. }
  208. TraceLeaveResult(hr);
  209. }