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.

468 lines
11 KiB

  1. //____________________________________________________________________________
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1995 - 1996.
  5. //
  6. // File: xicon.cxx
  7. //
  8. // Contents: implementation of CJobsEI & CJobsEIA classes.
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 1/4/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 "dll.hxx"
  23. #include "jobidl.hxx"
  24. #include "util.hxx"
  25. #include "jobicons.hxx"
  26. //
  27. // extern
  28. //
  29. extern HINSTANCE g_hInstance;
  30. //#undef DEB_TRACE
  31. //#define DEB_TRACE DEB_USER1
  32. const TCHAR c_szTask[] = TEXT("task!");
  33. extern const TCHAR TEMPLATE_STR[] = TEXT("wizard:");
  34. //____________________________________________________________________________
  35. //
  36. // Class: CJobsEI
  37. //
  38. // Purpose: Provide IExtractIcon interface to Job Folder objects.
  39. //
  40. // History: 1/24/1996 RaviR Created
  41. //____________________________________________________________________________
  42. class CJobsEI : public IExtractIcon
  43. {
  44. public:
  45. CJobsEI(LPCTSTR pszFolderPath, LPITEMIDLIST pidl)
  46. : m_pszFolderPath(pszFolderPath), m_pidl(pidl),
  47. m_JobIcon(), m_ulRefs(1) {}
  48. ~CJobsEI() { ILFree(m_pidl); }
  49. // IUnknown methods
  50. DECLARE_STANDARD_IUNKNOWN;
  51. // IExtractIcon methods
  52. STDMETHOD(GetIconLocation)(UINT uFlags, LPTSTR szIconFile, UINT cchMax,
  53. int *piIndex, UINT *pwFlags);
  54. STDMETHOD(Extract)(LPCTSTR pszFile, UINT nIconIndex, HICON *phiconLarge,
  55. HICON *phiconSmall, UINT nIconSize);
  56. private:
  57. CDllRef m_DllRef;
  58. LPCTSTR m_pszFolderPath;
  59. LPITEMIDLIST m_pidl;
  60. CJobIcon m_JobIcon;
  61. };
  62. //____________________________________________________________________________
  63. //
  64. // Member: IUnknown methods
  65. //____________________________________________________________________________
  66. IMPLEMENT_STANDARD_IUNKNOWN(CJobsEI);
  67. STDMETHODIMP
  68. CJobsEI::QueryInterface(REFIID riid, LPVOID* ppvObj)
  69. {
  70. if (IsEqualIID(IID_IUnknown, riid) ||
  71. IsEqualIID(IID_IExtractIcon, riid))
  72. {
  73. *ppvObj = (IUnknown*)(IExtractIcon*) this;
  74. this->AddRef();
  75. return S_OK;
  76. }
  77. *ppvObj = NULL;
  78. return E_NOINTERFACE;
  79. }
  80. //____________________________________________________________________________
  81. //
  82. // Member: CJobsEI::IExtractIcon::GetIconLocation
  83. //
  84. // Arguments: [uFlags] -- IN
  85. // [szIconFile] -- IN
  86. // [cchMax] -- IN
  87. // [piIndex] -- IN
  88. // [pwFlags] -- IN
  89. //
  90. // Returns: HTRESULT
  91. //
  92. // History: 1/5/1996 RaviR Created
  93. //
  94. //____________________________________________________________________________
  95. STDMETHODIMP
  96. CJobsEI::GetIconLocation(
  97. UINT uFlags,
  98. LPTSTR szIconFile,
  99. UINT cchMax,
  100. int * piIndex,
  101. UINT * pwFlags)
  102. {
  103. TRACE(CJobsEI, GetIconLocation);
  104. szIconFile[0] = '\0'; // init
  105. if (uFlags & GIL_OPENICON)
  106. {
  107. return S_FALSE;
  108. }
  109. *pwFlags = GIL_NOTFILENAME | GIL_PERINSTANCE;
  110. PJOBID pjid = (PJOBID)m_pidl;
  111. if (cchMax <= (UINT)(lstrlen(c_szTask) + lstrlen(pjid->GetAppName())))
  112. {
  113. DEBUG_OUT((DEB_ERROR,
  114. "CJobsEI::GetIconLocation: insufficient buffer\n"));
  115. return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
  116. }
  117. lstrcpy(szIconFile, c_szTask);
  118. if (pjid->IsTemplate())
  119. {
  120. lstrcat(szIconFile, TEMPLATE_STR);
  121. *piIndex = 0;
  122. }
  123. else
  124. {
  125. lstrcat(szIconFile, pjid->GetAppName());
  126. *piIndex = ! pjid->IsJobFlagOn(TASK_FLAG_DISABLED);
  127. }
  128. return S_OK;
  129. }
  130. //____________________________________________________________________________
  131. //
  132. // Member: CJobsEI::Extract
  133. //
  134. // Arguments: [pszFile] -- IN
  135. // [nIconIndex] -- IN
  136. // [phiconLarge] -- IN
  137. // [phiconSmall] -- IN
  138. // [nIconSize] -- IN
  139. //
  140. // Returns: STDMETHODIMP
  141. //
  142. // History: 1/5/1996 RaviR Created
  143. //____________________________________________________________________________
  144. STDMETHODIMP
  145. CJobsEI::Extract(
  146. LPCTSTR pszFile,
  147. UINT nIconIndex,
  148. HICON * phiconLarge,
  149. HICON * phiconSmall,
  150. UINT nIconSize)
  151. {
  152. TRACE(CJobsEI, Extract);
  153. if (((PJOBID)m_pidl)->IsTemplate())
  154. {
  155. m_JobIcon.GetTemplateIcons(phiconLarge, phiconSmall);
  156. }
  157. else
  158. {
  159. m_JobIcon.GetIcons(((PJOBID)m_pidl)->GetAppName(),
  160. nIconIndex,
  161. phiconLarge,
  162. phiconSmall);
  163. }
  164. return S_OK;
  165. }
  166. //____________________________________________________________________________
  167. //
  168. // Function: JFGetExtractIcon
  169. //
  170. // Synopsis: Function to create IExtractIcon
  171. //
  172. // Arguments: [ppvObj] -- OUT
  173. //
  174. // Returns: HRESULT
  175. //
  176. // History: 1/31/1996 RaviR Created
  177. //
  178. //____________________________________________________________________________
  179. HRESULT
  180. JFGetExtractIcon(
  181. LPVOID * ppvObj,
  182. LPCTSTR pszFolderPath,
  183. LPCITEMIDLIST pidl)
  184. {
  185. Win4Assert(pidl != NULL);
  186. LPITEMIDLIST pidlClone = ILClone(pidl);
  187. if (pidlClone == NULL)
  188. {
  189. CHECK_HRESULT(E_OUTOFMEMORY);
  190. return E_OUTOFMEMORY;
  191. }
  192. CJobsEI* pObj = new CJobsEI(pszFolderPath, pidlClone);
  193. if (NULL == pObj)
  194. {
  195. ILFree(pidlClone);
  196. return E_OUTOFMEMORY;
  197. }
  198. HRESULT hr = pObj->QueryInterface(IID_IExtractIcon, ppvObj);
  199. pObj->Release();
  200. return hr;
  201. }
  202. ////////////////////////////////////////////////////////////////////////////
  203. ////////////////////////////////////////////////////////////////////////////
  204. ////////////////////////////////////////////////////////////////////////////
  205. //////////////////// CJobsEIA //////////////////////////////////////////////
  206. ////////////////////////////////////////////////////////////////////////////
  207. ////////////////////////////////////////////////////////////////////////////
  208. ////////////////////////////////////////////////////////////////////////////
  209. #ifdef UNICODE
  210. //____________________________________________________________________________
  211. //
  212. // Class: CJobsEIA
  213. //
  214. // Purpose: Provide IExtractIconA interface to Job Folder objects.
  215. //
  216. // History: 1/24/1996 RaviR Created
  217. //____________________________________________________________________________
  218. class CJobsEIA : public IExtractIconA
  219. {
  220. public:
  221. CJobsEIA(LPCTSTR pszFolderPath, LPITEMIDLIST pidl)
  222. : m_pszFolderPath(pszFolderPath), m_pidl(pidl),
  223. m_JobIcon(), m_ulRefs(1) {}
  224. ~CJobsEIA() { ILFree(m_pidl); }
  225. // IUnknown methods
  226. DECLARE_STANDARD_IUNKNOWN;
  227. // IExtractIcon methods
  228. STDMETHOD(GetIconLocation)(UINT uFlags, LPSTR szIconFile, UINT cchMax,
  229. int *piIndex, UINT *pwFlags);
  230. STDMETHOD(Extract)(LPCSTR pszFile, UINT nIconIndex, HICON *phiconLarge,
  231. HICON *phiconSmall, UINT nIconSize);
  232. private:
  233. CDllRef m_DllRef;
  234. LPCTSTR m_pszFolderPath;
  235. LPITEMIDLIST m_pidl;
  236. CJobIcon m_JobIcon;
  237. };
  238. //____________________________________________________________________________
  239. //
  240. // Member: IUnknown methods
  241. //____________________________________________________________________________
  242. IMPLEMENT_STANDARD_IUNKNOWN(CJobsEIA);
  243. STDMETHODIMP
  244. CJobsEIA::QueryInterface(REFIID riid, LPVOID* ppvObj)
  245. {
  246. if (IsEqualIID(IID_IUnknown, riid) ||
  247. IsEqualIID(IID_IExtractIconA, riid))
  248. {
  249. *ppvObj = (IUnknown*)(IExtractIconA*) this;
  250. this->AddRef();
  251. return S_OK;
  252. }
  253. *ppvObj = NULL;
  254. return E_NOINTERFACE;
  255. }
  256. //____________________________________________________________________________
  257. //
  258. // Member: CJobsEIA::GetIconLocation
  259. //
  260. // Arguments: [uFlags] -- IN
  261. // [szIconFile] -- IN
  262. // [cchMax] -- IN
  263. // [piIndex] -- IN
  264. // [pwFlags] -- IN
  265. //
  266. // Returns: HTRESULT
  267. //
  268. // History: 1/5/1996 RaviR Created
  269. //
  270. //____________________________________________________________________________
  271. STDMETHODIMP
  272. CJobsEIA::GetIconLocation(
  273. UINT uFlags,
  274. LPSTR szIconFile,
  275. UINT cchMax,
  276. int * piIndex,
  277. UINT * pwFlags)
  278. {
  279. TRACE(CJobsEIA, GetIconLocation);
  280. HRESULT hr = S_OK;
  281. szIconFile[0] = '\0'; // init
  282. if (uFlags & GIL_OPENICON)
  283. {
  284. return S_FALSE;
  285. }
  286. *pwFlags = GIL_NOTFILENAME | GIL_PERINSTANCE;
  287. WCHAR wcBuff[MAX_PATH];
  288. PJOBID pjid = (PJOBID)m_pidl;
  289. lstrcpy(wcBuff, c_szTask);
  290. if (pjid->IsTemplate())
  291. {
  292. lstrcat(wcBuff, TEMPLATE_STR);
  293. *piIndex = 0;
  294. }
  295. else
  296. {
  297. lstrcat(wcBuff, pjid->GetAppName());
  298. *piIndex = ! pjid->IsJobFlagOn(TASK_FLAG_DISABLED);
  299. }
  300. hr = UnicodeToAnsi(szIconFile, wcBuff, cchMax);
  301. return hr;
  302. }
  303. //____________________________________________________________________________
  304. //
  305. // Member: CJobsEIA::Extract
  306. //
  307. // Arguments: [pszFile] -- IN
  308. // [nIconIndex] -- IN
  309. // [phiconLarge] -- IN
  310. // [phiconSmall] -- IN
  311. // [nIconSize] -- IN
  312. //
  313. // Returns: HTRESULT
  314. //
  315. // History: 1/5/1996 RaviR Created
  316. //
  317. //____________________________________________________________________________
  318. STDMETHODIMP
  319. CJobsEIA::Extract(
  320. LPCSTR pszFile,
  321. UINT nIconIndex,
  322. HICON* phiconLarge,
  323. HICON* phiconSmall,
  324. UINT nIconSize)
  325. {
  326. TRACE(CJobsEIA, Extract);
  327. if (((PJOBID)m_pidl)->IsTemplate())
  328. {
  329. m_JobIcon.GetTemplateIcons(phiconLarge, phiconSmall);
  330. }
  331. else
  332. {
  333. m_JobIcon.GetIcons(((PJOBID)m_pidl)->GetAppName(),
  334. nIconIndex,
  335. phiconLarge,
  336. phiconSmall);
  337. }
  338. return S_OK;
  339. }
  340. //____________________________________________________________________________
  341. //
  342. // Function: JFGetExtractIconA
  343. //
  344. // Synopsis: Function to create IExtractIconA
  345. //
  346. // Arguments: [ppvObj] -- OUT
  347. //
  348. // Returns: HRESULT
  349. //
  350. // History: 1/31/1996 RaviR Created
  351. //
  352. //____________________________________________________________________________
  353. HRESULT
  354. JFGetExtractIconA(
  355. LPVOID * ppvObj,
  356. LPCTSTR pszFolderPath,
  357. LPCITEMIDLIST pidl)
  358. {
  359. Win4Assert(pidl != NULL);
  360. LPITEMIDLIST pidlClone = ILClone(pidl);
  361. if (pidlClone == NULL)
  362. {
  363. CHECK_HRESULT(E_OUTOFMEMORY);
  364. return E_OUTOFMEMORY;
  365. }
  366. CJobsEIA* pObj = new CJobsEIA(pszFolderPath, pidlClone);
  367. if (NULL == pObj)
  368. {
  369. ILFree(pidlClone);
  370. return E_OUTOFMEMORY;
  371. }
  372. HRESULT hr = pObj->QueryInterface(IID_IExtractIcon, ppvObj);
  373. pObj->Release();
  374. return hr;
  375. }
  376. #endif // UNICODE