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.

430 lines
9.1 KiB

  1. //____________________________________________________________________________
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1995 - 1996.
  5. //
  6. // File: enum.cxx
  7. //
  8. // Contents: Implementation of IEnumIDList
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 1/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\common.hxx"
  22. #include "..\inc\policy.hxx"
  23. #include "dll.hxx"
  24. #include "jobidl.hxx"
  25. #include "util.hxx"
  26. #include "bitflag.hxx"
  27. //#undef DEB_TRACE
  28. //#define DEB_TRACE DEB_USER1
  29. //
  30. // Private flags
  31. //
  32. #define JE_LOCAL 0x0001
  33. #define JE_ENUMERATED_TEMPLATE 0x0002
  34. //____________________________________________________________________________
  35. //
  36. // Class: CJobsEnum
  37. //
  38. // Purpose: Enumerates jobs in a folder.
  39. //
  40. // History: 1/25/1996 RaviR Created
  41. //____________________________________________________________________________
  42. class CJobsEnum : public IEnumIDList,
  43. public CBitFlag
  44. {
  45. public:
  46. CJobsEnum(ULONG uFlags, LPCTSTR pszFolderPath, IEnumWorkItems *pEnumJobs);
  47. ~CJobsEnum(void);
  48. // IUnknown methods
  49. DECLARE_STANDARD_IUNKNOWN;
  50. // IEnumIDList methods
  51. STDMETHOD(Next)(ULONG celt, LPITEMIDLIST* rgelt, ULONG* pceltFetched);
  52. STDMETHOD(Skip)(ULONG celt);
  53. STDMETHOD(Reset)(void);
  54. STDMETHOD(Clone)(IEnumIDList** ppenum);
  55. private:
  56. ULONG m_uShellFlags; // SHCONTF flags passed in by shell
  57. IEnumWorkItems * m_pEnumJobs;
  58. LPCTSTR m_pszFolderPath;
  59. CDllRef m_DllRef;
  60. };
  61. //____________________________________________________________________________
  62. //
  63. // Member: CJobsEnum::CJobsEnum, Constructor
  64. //
  65. // History: 1/5/1996 RaviR Created
  66. //
  67. //____________________________________________________________________________
  68. inline
  69. CJobsEnum::CJobsEnum(
  70. ULONG uFlags,
  71. LPCTSTR pszFolderPath,
  72. IEnumWorkItems * pEnumJobs)
  73. :
  74. m_ulRefs(1),
  75. m_uShellFlags(uFlags),
  76. m_pEnumJobs(pEnumJobs),
  77. m_pszFolderPath(pszFolderPath)
  78. {
  79. TRACE(CJobsEnum, CJobsEnum);
  80. DEBUG_OUT((DEB_USER1, "FolderPath = %ws\n", pszFolderPath));
  81. if (IsLocalFilename(pszFolderPath))
  82. {
  83. _SetFlag(JE_LOCAL);
  84. }
  85. Win4Assert(m_pEnumJobs != NULL);
  86. m_pEnumJobs->AddRef();
  87. //
  88. // Policy - do not allow the template item if we are not
  89. // allowing job creation
  90. // -- Later, we prevent this flag from being cleared
  91. //
  92. if (RegReadPolicyKey(TS_KEYPOLICY_DENY_CREATE_TASK))
  93. {
  94. DEBUG_OUT((DEB_ITRACE, "Policy CREATE_TASK active - no template wizard\n"));
  95. //
  96. // This next flag means that we have ALREADY shown the template.
  97. // Setting it will force us never to enumerate it
  98. //
  99. _SetFlag(JE_ENUMERATED_TEMPLATE);
  100. }
  101. }
  102. //____________________________________________________________________________
  103. //
  104. // Member: CJobsEnum::~CJobsEnum, Destructor
  105. //____________________________________________________________________________
  106. inline
  107. CJobsEnum::~CJobsEnum()
  108. {
  109. TRACE(CJobsEnum, ~CJobsEnum);
  110. if (m_pEnumJobs != NULL)
  111. {
  112. m_pEnumJobs->Release();
  113. }
  114. // Note: No need to free m_pszFolderPath.
  115. }
  116. //____________________________________________________________________________
  117. //
  118. // Member: IUnknown methods
  119. //____________________________________________________________________________
  120. IMPLEMENT_STANDARD_IUNKNOWN(CJobsEnum);
  121. STDMETHODIMP
  122. CJobsEnum::QueryInterface(REFIID riid, LPVOID* ppvObj)
  123. {
  124. if (IsEqualIID(IID_IUnknown, riid) ||
  125. IsEqualIID(IID_IEnumIDList, riid))
  126. {
  127. *ppvObj = (IUnknown*)(IEnumIDList*) this;
  128. this->AddRef();
  129. return S_OK;
  130. }
  131. *ppvObj = NULL;
  132. return E_NOINTERFACE;
  133. }
  134. //____________________________________________________________________________
  135. //
  136. // Member: CJobsEnum::IEnumIDList::Next
  137. //
  138. // Arguments: [celt] -- IN
  139. // [ppidlOut] -- IN
  140. // [pceltFetched] -- IN
  141. //
  142. // Returns: HRESULT.
  143. //
  144. // History: 1/5/1996 RaviR Created
  145. // 2-12-1997 DavidMun Handle NULL pceltFetched
  146. //
  147. //____________________________________________________________________________
  148. STDMETHODIMP
  149. CJobsEnum::Next(
  150. ULONG celt,
  151. LPITEMIDLIST* ppidlOut,
  152. ULONG* pceltFetched)
  153. {
  154. TRACE(CJobsEnum, Next);
  155. HRESULT hr = S_OK;
  156. CJobID jid;
  157. if (!(m_uShellFlags & SHCONTF_NONFOLDERS))
  158. {
  159. return S_FALSE;
  160. }
  161. if (m_pEnumJobs == NULL)
  162. {
  163. return E_FAIL;
  164. }
  165. if (pceltFetched == NULL && celt != 1)
  166. {
  167. return E_INVALIDARG;
  168. }
  169. if (pceltFetched)
  170. {
  171. *pceltFetched = 0;
  172. }
  173. ULONG curr = 0;
  174. LPWSTR * ppwszJob = NULL;
  175. ULONG ulTemp;
  176. if (_IsFlagSet(JE_LOCAL) &&
  177. !_IsFlagSet(JE_ENUMERATED_TEMPLATE) &&
  178. celt)
  179. {
  180. jid.InitToTemplate();
  181. ppidlOut[curr] = ILClone((LPCITEMIDLIST)(&jid));
  182. if (!ppidlOut[curr])
  183. {
  184. return E_OUTOFMEMORY;
  185. }
  186. DEBUG_OUT((DEB_ITRACE, "Created template\n"));
  187. curr++;
  188. _SetFlag(JE_ENUMERATED_TEMPLATE);
  189. }
  190. while (curr < celt)
  191. {
  192. hr = m_pEnumJobs->Next(1, &ppwszJob, &ulTemp);
  193. CHECK_HRESULT(hr);
  194. if (FAILED(hr))
  195. {
  196. break;
  197. }
  198. else if (ulTemp == 0)
  199. {
  200. hr = S_FALSE;
  201. break;
  202. }
  203. LPTSTR pszJob = (LPTSTR)*ppwszJob;
  204. #if !defined(UNICODE)
  205. char szBuff[MAX_PATH];
  206. UnicodeToAnsi(szBuff, *ppwszJob, MAX_PATH);
  207. pszJob = szBuff;
  208. #endif
  209. hr = jid.Load(m_pszFolderPath, pszJob);
  210. CoTaskMemFree(*ppwszJob);
  211. CoTaskMemFree(ppwszJob);
  212. if (S_OK == hr)
  213. {
  214. ppidlOut[curr] = ILClone((LPCITEMIDLIST)(&jid));
  215. if (NULL != ppidlOut[curr])
  216. {
  217. ++curr;
  218. hr = S_OK;
  219. }
  220. else
  221. {
  222. hr = E_OUTOFMEMORY;
  223. }
  224. }
  225. if (hr == E_OUTOFMEMORY)
  226. {
  227. break;
  228. }
  229. }
  230. if (curr > 0 && curr < celt)
  231. {
  232. hr = S_FALSE;
  233. }
  234. if (pceltFetched)
  235. {
  236. *pceltFetched = curr;
  237. }
  238. return hr;
  239. }
  240. //____________________________________________________________________________
  241. //
  242. // Member: CJobsEnum::Skip
  243. //
  244. // Arguments: [celt] -- IN
  245. //
  246. // Returns: HRESULT.
  247. //
  248. // History: 1/5/1996 RaviR Created
  249. //
  250. //____________________________________________________________________________
  251. STDMETHODIMP
  252. CJobsEnum::Skip(
  253. ULONG celt)
  254. {
  255. TRACE(CJobsEnum, Skip);
  256. if (!celt)
  257. {
  258. return E_INVALIDARG;
  259. }
  260. if (_IsFlagSet(JE_LOCAL) && !_IsFlagSet(JE_ENUMERATED_TEMPLATE))
  261. {
  262. celt--;
  263. _SetFlag(JE_ENUMERATED_TEMPLATE);
  264. if (!celt)
  265. {
  266. return S_OK;
  267. }
  268. }
  269. return m_pEnumJobs->Skip(celt);
  270. }
  271. //____________________________________________________________________________
  272. //
  273. // Member: CJobsEnum::Reset
  274. //
  275. // Returns: HRESULT.
  276. //
  277. // History: 1/5/1996 RaviR Created
  278. //
  279. //____________________________________________________________________________
  280. STDMETHODIMP
  281. CJobsEnum::Reset(void)
  282. {
  283. TRACE(CJobsEnum, Reset);
  284. //
  285. // Policy - don't clear flag if we are not allowing job creation
  286. //
  287. if (! RegReadPolicyKey(TS_KEYPOLICY_DENY_CREATE_TASK))
  288. {
  289. DEBUG_OUT((DEB_ITRACE, "Policy CREATE_TASK active - prevent template wiz\n"));
  290. //
  291. // Not clearing this flag maintains that we will have enumerated
  292. // the template on the next go around
  293. //
  294. _ClearFlag(JE_ENUMERATED_TEMPLATE);
  295. }
  296. return m_pEnumJobs->Reset();
  297. }
  298. //____________________________________________________________________________
  299. //
  300. // Member: CJobsEnum::Clone
  301. //
  302. // Arguments: [ppenum] -- IN
  303. //
  304. // Returns: HRESULT.
  305. //
  306. // History: 1/5/1996 RaviR Created
  307. //
  308. //____________________________________________________________________________
  309. STDMETHODIMP
  310. CJobsEnum::Clone(
  311. IEnumIDList** ppenum)
  312. {
  313. TRACE(CJobsEnum, Clone);
  314. return E_FAIL; // not supported
  315. }
  316. //____________________________________________________________________________
  317. //
  318. // Function: JFGetEnumIDList
  319. //
  320. // Synopsis: Function to create the object to enumearte the JobIDList
  321. //
  322. // Arguments: [uFlags] -- IN
  323. // [pszFolderPath] -- IN
  324. // [pEnumJobs] -- IN
  325. // [riid] -- IN
  326. // [ppvObj] -- OUT
  327. //
  328. // Returns: HRESULT
  329. //
  330. // History: 1/24/1996 RaviR Created
  331. //
  332. //____________________________________________________________________________
  333. HRESULT
  334. JFGetEnumIDList(
  335. ULONG uFlags,
  336. LPCTSTR pszFolderPath,
  337. IEnumWorkItems * pEnumJobs,
  338. LPVOID * ppvObj)
  339. {
  340. CJobsEnum * pEnum = new CJobsEnum(uFlags, pszFolderPath, pEnumJobs);
  341. if (NULL == pEnum)
  342. {
  343. CHECK_HRESULT(E_OUTOFMEMORY);
  344. return E_OUTOFMEMORY;
  345. }
  346. pEnumJobs->Reset();
  347. HRESULT hr = pEnum->QueryInterface(IID_IEnumIDList, ppvObj);
  348. pEnum->Release();
  349. return hr;
  350. }