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.

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