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.

502 lines
12 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. StringCchCopy(szIconFile, cchMax, c_szTask);
  118. if (pjid->IsTemplate())
  119. {
  120. StringCchCat(szIconFile, cchMax, TEMPLATE_STR);
  121. *piIndex = 0;
  122. }
  123. else
  124. {
  125. StringCchCat(szIconFile, cchMax, 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, nIconSize);
  156. }
  157. else
  158. {
  159. m_JobIcon.GetIcons(((PJOBID)m_pidl)->GetAppName(), nIconIndex, phiconLarge, phiconSmall, nIconSize);
  160. }
  161. return S_OK;
  162. }
  163. //____________________________________________________________________________
  164. //
  165. // Function: JFGetExtractIcon
  166. //
  167. // Synopsis: Function to create IExtractIcon
  168. //
  169. // Arguments: [ppvObj] -- OUT
  170. //
  171. // Returns: HRESULT
  172. //
  173. // History: 1/31/1996 RaviR Created
  174. //
  175. //____________________________________________________________________________
  176. HRESULT
  177. JFGetExtractIcon(
  178. LPVOID * ppvObj,
  179. LPCTSTR pszFolderPath,
  180. LPCITEMIDLIST pidl)
  181. {
  182. Win4Assert(pidl != NULL);
  183. LPITEMIDLIST pidlClone = ILClone(pidl);
  184. if (pidlClone == NULL)
  185. {
  186. CHECK_HRESULT(E_OUTOFMEMORY);
  187. return E_OUTOFMEMORY;
  188. }
  189. CJobsEI* pObj = new CJobsEI(pszFolderPath, pidlClone);
  190. if (NULL == pObj)
  191. {
  192. ILFree(pidlClone);
  193. return E_OUTOFMEMORY;
  194. }
  195. HRESULT hr = pObj->QueryInterface(IID_IExtractIcon, ppvObj);
  196. pObj->Release();
  197. return hr;
  198. }
  199. ////////////////////////////////////////////////////////////////////////////
  200. ////////////////////////////////////////////////////////////////////////////
  201. ////////////////////////////////////////////////////////////////////////////
  202. //////////////////// CJobsEIA //////////////////////////////////////////////
  203. ////////////////////////////////////////////////////////////////////////////
  204. ////////////////////////////////////////////////////////////////////////////
  205. ////////////////////////////////////////////////////////////////////////////
  206. //+---------------------------------------------------------------------------
  207. //
  208. // Function: UnicodeToAnsi
  209. //
  210. // Synopsis: Convert unicode string [pwsz] to multibyte in buffer [sz].
  211. //
  212. // Arguments: [szTo] - destination buffer
  213. // [pwszFrom] - source string
  214. // [cbTo] - size of destination buffer, in bytes
  215. //
  216. // Returns: S_OK - conversion succeeded
  217. // HRESULT_FROM_WIN32 - WideCharToMultiByte failed
  218. //
  219. // Modifies: *[szTo]
  220. //
  221. // History: 10-29-96 DavidMun Created
  222. //
  223. // Notes: The string in [szTo] will be NULL terminated even on
  224. // failure.
  225. //
  226. //----------------------------------------------------------------------------
  227. HRESULT
  228. UnicodeToAnsi(
  229. LPSTR szTo,
  230. LPCWSTR pwszFrom,
  231. ULONG cbTo)
  232. {
  233. HRESULT hr = S_OK;
  234. ULONG cbWritten;
  235. cbWritten = WideCharToMultiByte(CP_ACP,
  236. 0,
  237. pwszFrom,
  238. -1,
  239. szTo,
  240. cbTo,
  241. NULL,
  242. NULL);
  243. if (!cbWritten)
  244. {
  245. szTo[cbTo - 1] = '\0'; // ensure NULL termination
  246. hr = HRESULT_FROM_WIN32(GetLastError());
  247. }
  248. return hr;
  249. }
  250. //____________________________________________________________________________
  251. //
  252. // Class: CJobsEIA
  253. //
  254. // Purpose: Provide IExtractIconA interface to Job Folder objects.
  255. //
  256. // History: 1/24/1996 RaviR Created
  257. //____________________________________________________________________________
  258. class CJobsEIA : public IExtractIconA
  259. {
  260. public:
  261. CJobsEIA(LPCTSTR pszFolderPath, LPITEMIDLIST pidl)
  262. : m_pszFolderPath(pszFolderPath), m_pidl(pidl),
  263. m_JobIcon(), m_ulRefs(1) {}
  264. ~CJobsEIA() { ILFree(m_pidl); }
  265. // IUnknown methods
  266. DECLARE_STANDARD_IUNKNOWN;
  267. // IExtractIcon methods
  268. STDMETHOD(GetIconLocation)(UINT uFlags, LPSTR szIconFile, UINT cchMax,
  269. int *piIndex, UINT *pwFlags);
  270. STDMETHOD(Extract)(LPCSTR pszFile, UINT nIconIndex, HICON *phiconLarge,
  271. HICON *phiconSmall, UINT nIconSize);
  272. private:
  273. CDllRef m_DllRef;
  274. LPCTSTR m_pszFolderPath;
  275. LPITEMIDLIST m_pidl;
  276. CJobIcon m_JobIcon;
  277. };
  278. //____________________________________________________________________________
  279. //
  280. // Member: IUnknown methods
  281. //____________________________________________________________________________
  282. IMPLEMENT_STANDARD_IUNKNOWN(CJobsEIA);
  283. STDMETHODIMP
  284. CJobsEIA::QueryInterface(REFIID riid, LPVOID* ppvObj)
  285. {
  286. if (IsEqualIID(IID_IUnknown, riid) ||
  287. IsEqualIID(IID_IExtractIconA, riid))
  288. {
  289. *ppvObj = (IUnknown*)(IExtractIconA*) this;
  290. this->AddRef();
  291. return S_OK;
  292. }
  293. *ppvObj = NULL;
  294. return E_NOINTERFACE;
  295. }
  296. //____________________________________________________________________________
  297. //
  298. // Member: CJobsEIA::GetIconLocation
  299. //
  300. // Arguments: [uFlags] -- IN
  301. // [szIconFile] -- IN
  302. // [cchMax] -- IN
  303. // [piIndex] -- IN
  304. // [pwFlags] -- IN
  305. //
  306. // Returns: HTRESULT
  307. //
  308. // History: 1/5/1996 RaviR Created
  309. //
  310. //____________________________________________________________________________
  311. STDMETHODIMP
  312. CJobsEIA::GetIconLocation(
  313. UINT uFlags,
  314. LPSTR szIconFile,
  315. UINT cchMax,
  316. int * piIndex,
  317. UINT * pwFlags)
  318. {
  319. TRACE(CJobsEIA, GetIconLocation);
  320. HRESULT hr = S_OK;
  321. szIconFile[0] = '\0'; // init
  322. if (uFlags & GIL_OPENICON)
  323. {
  324. return S_FALSE;
  325. }
  326. *pwFlags = GIL_NOTFILENAME | GIL_PERINSTANCE;
  327. WCHAR wcBuff[MAX_PATH +1];
  328. PJOBID pjid = (PJOBID)m_pidl;
  329. StringCchCopy(wcBuff, MAX_PATH+1, c_szTask);
  330. if (pjid->IsTemplate())
  331. {
  332. StringCchCat(wcBuff, MAX_PATH+1, TEMPLATE_STR);
  333. *piIndex = 0;
  334. }
  335. else
  336. {
  337. StringCchCat(wcBuff, MAX_PATH+1, pjid->GetAppName());
  338. *piIndex = ! pjid->IsJobFlagOn(TASK_FLAG_DISABLED);
  339. }
  340. hr = UnicodeToAnsi(szIconFile, wcBuff, cchMax);
  341. return hr;
  342. }
  343. //____________________________________________________________________________
  344. //
  345. // Member: CJobsEIA::Extract
  346. //
  347. // Arguments: [pszFile] -- IN
  348. // [nIconIndex] -- IN
  349. // [phiconLarge] -- IN
  350. // [phiconSmall] -- IN
  351. // [nIconSize] -- IN
  352. //
  353. // Returns: HTRESULT
  354. //
  355. // History: 1/5/1996 RaviR Created
  356. //
  357. //____________________________________________________________________________
  358. STDMETHODIMP
  359. CJobsEIA::Extract(
  360. LPCSTR pszFile,
  361. UINT nIconIndex,
  362. HICON* phiconLarge,
  363. HICON* phiconSmall,
  364. UINT nIconSize)
  365. {
  366. TRACE(CJobsEIA, Extract);
  367. if (((PJOBID)m_pidl)->IsTemplate())
  368. {
  369. m_JobIcon.GetTemplateIcons(phiconLarge, phiconSmall, nIconSize);
  370. }
  371. else
  372. {
  373. m_JobIcon.GetIcons(((PJOBID)m_pidl)->GetAppName(), nIconIndex, phiconLarge, phiconSmall, nIconSize);
  374. }
  375. return S_OK;
  376. }
  377. //____________________________________________________________________________
  378. //
  379. // Function: JFGetExtractIconA
  380. //
  381. // Synopsis: Function to create IExtractIconA
  382. //
  383. // Arguments: [ppvObj] -- OUT
  384. //
  385. // Returns: HRESULT
  386. //
  387. // History: 1/31/1996 RaviR Created
  388. //
  389. //____________________________________________________________________________
  390. HRESULT
  391. JFGetExtractIconA(
  392. LPVOID * ppvObj,
  393. LPCTSTR pszFolderPath,
  394. LPCITEMIDLIST pidl)
  395. {
  396. Win4Assert(pidl != NULL);
  397. LPITEMIDLIST pidlClone = ILClone(pidl);
  398. if (pidlClone == NULL)
  399. {
  400. CHECK_HRESULT(E_OUTOFMEMORY);
  401. return E_OUTOFMEMORY;
  402. }
  403. CJobsEIA* pObj = new CJobsEIA(pszFolderPath, pidlClone);
  404. if (NULL == pObj)
  405. {
  406. ILFree(pidlClone);
  407. return E_OUTOFMEMORY;
  408. }
  409. HRESULT hr = pObj->QueryInterface(IID_IExtractIcon, ppvObj);
  410. pObj->Release();
  411. return hr;
  412. }