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.

407 lines
8.9 KiB

  1. //____________________________________________________________________________
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1995 - 1996.
  5. //
  6. // File: menubg.cxx
  7. //
  8. // Contents: IContextMenu implementaion.
  9. //
  10. // Classes: CJobsCMBG, implementing IContextMenu for the background
  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\resource.h"
  22. #include "resource.h"
  23. #include "jobidl.hxx"
  24. #include "sch_cls.hxx" // sched\inc
  25. #include "job_cls.hxx" // sched\inc
  26. #include "misc.hxx" // sched\inc
  27. #include "policy.hxx" // sched\inc
  28. #include "jobfldr.hxx"
  29. #include "util.hxx"
  30. //
  31. // extern
  32. //
  33. extern HINSTANCE g_hInstance;
  34. HRESULT
  35. PromptForServiceStart(
  36. HWND hwnd);
  37. BOOL
  38. UserCanChangeService(
  39. LPCTSTR ptszServer);
  40. //
  41. // Forward declaration of local functions
  42. //
  43. HRESULT
  44. JFCreateNewQueue(
  45. HWND hwnd);
  46. extern "C" UINT g_cfPreferredDropEffect;
  47. //____________________________________________________________________________
  48. //
  49. // Class: CJobsCMBG
  50. //
  51. // Purpose: Provide IContextMenu interface to Job Folder (background).
  52. //
  53. // History: 1/24/1996 RaviR Created
  54. //____________________________________________________________________________
  55. class CJobsCMBG : public IContextMenu
  56. {
  57. public:
  58. CJobsCMBG(HWND hwnd, CJobFolder * pCJobFolder)
  59. : m_ulRefs(1), m_hwnd(hwnd), m_pCJobFolder(pCJobFolder) {}
  60. ~CJobsCMBG() {}
  61. // IUnknown methods
  62. DECLARE_STANDARD_IUNKNOWN;
  63. // IContextMenu methods
  64. STDMETHOD(QueryContextMenu)(HMENU hmenu, UINT indexMenu, UINT idCmdFirst,
  65. UINT idCmdLast, UINT uFlags);
  66. STDMETHOD(InvokeCommand)(LPCMINVOKECOMMANDINFO lpici);
  67. STDMETHOD(GetCommandString)(UINT_PTR idCmd, UINT uType, UINT * pwReserved,
  68. LPSTR pszName, UINT cchMax);
  69. private:
  70. HWND m_hwnd;
  71. CJobFolder * m_pCJobFolder;
  72. };
  73. //____________________________________________________________________________
  74. //
  75. // Member: IUnknown methods
  76. //____________________________________________________________________________
  77. IMPLEMENT_STANDARD_IUNKNOWN(CJobsCMBG);
  78. STDMETHODIMP
  79. CJobsCMBG::QueryInterface(REFIID riid, LPVOID* ppvObj)
  80. {
  81. if (IsEqualIID(IID_IUnknown, riid) ||
  82. IsEqualIID(IID_IContextMenu, riid))
  83. {
  84. *ppvObj = (IUnknown*)(IContextMenu*) this;
  85. this->AddRef();
  86. return S_OK;
  87. }
  88. *ppvObj = NULL;
  89. return E_NOINTERFACE;
  90. }
  91. //____________________________________________________________________________
  92. //
  93. // Member: CJobsCMBG::QueryContextMenu
  94. //
  95. // Arguments: [hmenu] -- IN
  96. // [indexMenu] -- IN
  97. // [idCmdFirst] -- IN
  98. // [idCmdLast] -- IN
  99. // [uFlags] -- IN
  100. //
  101. // Returns: STDMETHODIMP
  102. //
  103. // History: 1/8/1996 RaviR Created
  104. //
  105. //____________________________________________________________________________
  106. STDMETHODIMP
  107. CJobsCMBG::QueryContextMenu(
  108. HMENU hmenu,
  109. UINT indexMenu,
  110. UINT idCmdFirst,
  111. UINT idCmdLast,
  112. UINT uFlags)
  113. {
  114. TRACE(CJobsCMBG, QueryContextMenu);
  115. QCMINFO qcm = { hmenu, indexMenu, idCmdFirst, idCmdLast };
  116. UtMergeMenu(g_hInstance, POPUP_JOBSBG_MERGE,
  117. POPUP_JOBSBG_POPUPMERGE, (LPQCMINFO)&qcm);
  118. return ResultFromShort(qcm.idCmdFirst - idCmdFirst);
  119. }
  120. HRESULT
  121. DataObj_GetDWORD(
  122. IDataObject * pdtobj,
  123. UINT cf,
  124. DWORD * pdwOut)
  125. {
  126. STGMEDIUM medium;
  127. FORMATETC fmte = {(CLIPFORMAT)cf, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
  128. HRESULT hr;
  129. medium.pUnkForRelease = NULL;
  130. medium.hGlobal = NULL;
  131. hr = pdtobj->GetData(&fmte, &medium);
  132. if (SUCCEEDED(hr))
  133. {
  134. DWORD *pdw = (DWORD *)GlobalLock(medium.hGlobal);
  135. if (pdw)
  136. {
  137. *pdwOut = *pdw;
  138. GlobalUnlock(medium.hGlobal);
  139. }
  140. else
  141. {
  142. hr = E_UNEXPECTED;
  143. }
  144. ReleaseStgMedium(&medium);
  145. }
  146. return hr;
  147. }
  148. //____________________________________________________________________________
  149. //
  150. // Member: CJobsCMBG::InvokeCommand
  151. //
  152. // Arguments: [lpici] -- IN
  153. //
  154. // Returns: STDMETHODIMP
  155. //
  156. // History: 1/8/1996 RaviR Created
  157. //
  158. //____________________________________________________________________________
  159. STDMETHODIMP
  160. CJobsCMBG::InvokeCommand(
  161. LPCMINVOKECOMMANDINFO lpici)
  162. {
  163. TRACE(CJobsCMBG, InvokeCommand);
  164. #define SORT_BY(X) \
  165. case FSIDM_SORTBY##X: ShellFolderView_ReArrange(m_hwnd, COLUMN_##X); break
  166. UINT idCmd;
  167. HRESULT hr = S_OK;
  168. if (HIWORD(lpici->lpVerb))
  169. {
  170. // Deal with string commands
  171. PSTR pszCmd = (PSTR)lpici->lpVerb;
  172. if (0 == lstrcmpA(pszCmd, "paste"))
  173. {
  174. idCmd = CMIDM_PASTE;
  175. }
  176. else
  177. {
  178. DEBUG_OUT((DEB_ERROR, "Unprocessed InvokeCommandBG<%s>\n", pszCmd));
  179. return E_INVALIDARG;
  180. }
  181. }
  182. else
  183. {
  184. idCmd = LOWORD(lpici->lpVerb);
  185. }
  186. switch (idCmd)
  187. {
  188. SORT_BY(NAME);
  189. SORT_BY(NEXTRUNTIME);
  190. SORT_BY(LASTRUNTIME);
  191. SORT_BY(SCHEDULE);
  192. #if !defined(_CHICAGO_)
  193. SORT_BY(LASTEXITCODE);
  194. SORT_BY(CREATOR);
  195. #endif // !defined(_CHICAGO_)
  196. case FSIDM_NEWJOB:
  197. if (UserCanChangeService(m_pCJobFolder->GetMachine()))
  198. {
  199. PromptForServiceStart(m_hwnd);
  200. }
  201. hr = m_pCJobFolder->CreateAJobForApp(NULL);
  202. break;
  203. case CMIDM_PASTE:
  204. {
  205. //
  206. // Policy - if cannot create a job, then
  207. // paste is not allowed
  208. //
  209. if (! RegReadPolicyKey(TS_KEYPOLICY_DENY_CREATE_TASK))
  210. {
  211. LPDATAOBJECT pdtobj = NULL;
  212. hr = OleGetClipboard(&pdtobj);
  213. CHECK_HRESULT(hr);
  214. BREAK_ON_FAIL(hr);
  215. // GetPreferred drop effect
  216. DWORD dw;
  217. hr = DataObj_GetDWORD(pdtobj, g_cfPreferredDropEffect, &dw);
  218. CHECK_HRESULT(hr);
  219. if (FAILED(hr))
  220. {
  221. dw = DROPEFFECT_COPY;
  222. }
  223. hr = m_pCJobFolder->CopyToFolder(pdtobj,
  224. (dw & DROPEFFECT_MOVE) ? TRUE : FALSE,
  225. FALSE, NULL);
  226. pdtobj->Release();
  227. }
  228. break;
  229. }
  230. default:
  231. return E_INVALIDARG;
  232. }
  233. return hr;
  234. }
  235. //____________________________________________________________________________
  236. //
  237. // Member: CJobsCMBG::GetCommandString
  238. //
  239. // Arguments: [idCmd] -- IN
  240. // [uType] -- IN
  241. // [pwReserved] -- IN
  242. // [pszName] -- IN
  243. // [cchMax] -- IN
  244. //
  245. // Returns: STDMETHODIMP
  246. //
  247. // History: 1/8/1996 RaviR Created
  248. //
  249. //____________________________________________________________________________
  250. STDMETHODIMP
  251. CJobsCMBG::GetCommandString(
  252. UINT_PTR idCmd,
  253. UINT uType,
  254. UINT * pwReserved,
  255. LPSTR pszName,
  256. UINT cchMax)
  257. {
  258. TRACE(CJobsCMBG, GetCommandString);
  259. #if DBG==1
  260. char * aType[] = {"GCS_VERBA", "GCS_HELPTEXTA", "GCS_VALIDATEA", "Unused",
  261. "GCS_VERBW", "GCS_HELPTEXTW", "GCS_VALIDATEW", "UNICODE"};
  262. DEBUG_OUT((DEB_USER5, "GetCommandString <id,type> = <%d, %d, %s>\n",
  263. idCmd, uType, aType[uType]));
  264. #endif // DBG==1
  265. *((LPTSTR)pszName) = TEXT('\0');
  266. if (uType == GCS_HELPTEXT)
  267. {
  268. LoadString(g_hInstance, (UINT)idCmd + IDS_MH_FSIDM_FIRST,
  269. (LPTSTR)pszName, cchMax);
  270. return S_OK;
  271. }
  272. return E_FAIL;
  273. }
  274. //____________________________________________________________________________
  275. //
  276. // Function: JFCreateNewQueue
  277. //
  278. // Synopsis: S
  279. //
  280. // Arguments: [hwnd] -- IN
  281. //
  282. // Returns: HRESULT
  283. //
  284. // History: 3/26/1996 RaviR Created
  285. //
  286. //____________________________________________________________________________
  287. HRESULT
  288. JFCreateNewQueue(
  289. HWND hwnd)
  290. {
  291. MessageBoxA(hwnd, "Creating a New Queue is NOTIMPL", "Job Folder", MB_OK);
  292. return S_FALSE;
  293. }
  294. //____________________________________________________________________________
  295. //
  296. // Function: JFGetFolderContextMenu
  297. //
  298. // Synopsis: S
  299. //
  300. // Arguments: [hwnd] -- IN
  301. // [riid] -- IN
  302. // [ppvObj] -- OUT
  303. //
  304. // Returns: HRESULT
  305. //
  306. // History: 1/24/1996 RaviR Created
  307. //
  308. //____________________________________________________________________________
  309. HRESULT
  310. JFGetFolderContextMenu(
  311. HWND hwnd,
  312. CJobFolder * pCJobFolder,
  313. LPVOID * ppvObj)
  314. {
  315. CJobsCMBG* pObj = new CJobsCMBG(hwnd, pCJobFolder);
  316. if (NULL == pObj)
  317. {
  318. return E_OUTOFMEMORY;
  319. }
  320. HRESULT hr = pObj->QueryInterface(IID_IContextMenu, ppvObj);
  321. pObj->Release();
  322. return hr;
  323. }