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.

240 lines
5.4 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1995 - 1995.
  5. //
  6. // File: menu.cxx
  7. //
  8. // Contents: Implementation of IContextMenu
  9. //
  10. // History: 20-Dec-95 BruceFo Created
  11. //
  12. //----------------------------------------------------------------------------
  13. #include "headers.hxx"
  14. #pragma hdrstop
  15. #include "util.hxx"
  16. #include "dutil.hxx"
  17. #include "menu.hxx"
  18. #include "menuutil.hxx"
  19. #include "shares.h"
  20. #include "resource.h"
  21. CSharesCM::CSharesCM(
  22. IN HWND hwnd
  23. )
  24. :
  25. m_ulRefs(0),
  26. m_hwnd(hwnd),
  27. m_cidl(0),
  28. m_apidl(NULL),
  29. m_psf(NULL)
  30. {
  31. AddRef();
  32. }
  33. HRESULT
  34. CSharesCM::InitInstance(
  35. IN PWSTR pszMachine,
  36. IN UINT cidl,
  37. IN LPCITEMIDLIST* apidl,
  38. IN IShellFolder* psf
  39. )
  40. {
  41. m_pszMachine = pszMachine;
  42. m_cidl = cidl;
  43. m_apidl = ILA_Clone(cidl, apidl);
  44. if (NULL == m_apidl)
  45. {
  46. return E_OUTOFMEMORY;
  47. }
  48. appAssert(NULL != psf);
  49. m_psf = psf;
  50. m_psf->AddRef();
  51. return S_OK;
  52. }
  53. CSharesCM::~CSharesCM()
  54. {
  55. ILA_Free(m_cidl, m_apidl);
  56. m_cidl = 0;
  57. m_apidl = NULL;
  58. appAssert(NULL != m_psf);
  59. m_psf->Release();
  60. m_psf = NULL;
  61. }
  62. STDMETHODIMP
  63. CSharesCM::QueryContextMenu(
  64. HMENU hmenu,
  65. UINT indexMenu,
  66. UINT idCmdFirst,
  67. UINT idCmdLast,
  68. UINT uFlags
  69. )
  70. {
  71. if (uFlags & CMF_DVFILE)
  72. {
  73. // This IContextMenu was created to add items to the DefView "File"
  74. // menu. This menu already has 4 standard items: Create Shortcut,
  75. // Delete, Rename, and Properties. Since we only want Delete and
  76. // Properties, and don't need to add anything, we simply do nothing
  77. // and let DefView do the work.
  78. return ResultFromShort(0);
  79. }
  80. else
  81. {
  82. // Got an IContextMenu because of a double-click on the item (to get
  83. // the default item) or a right-click on the item (to display the
  84. // entire context menu). So, put it up.
  85. QCMINFO qcm = { hmenu, indexMenu, idCmdFirst, idCmdLast };
  86. MyMergeMenu(g_hInstance, POPUP_SHARE, 0, &qcm);
  87. ULONG dwInOut = SFGAO_CANDELETE | SFGAO_HASPROPSHEET | SFGAO_CANRENAME;
  88. HRESULT hr = m_psf->GetAttributesOf(m_cidl, (LPCITEMIDLIST*)m_apidl, &dwInOut);
  89. CHECK_HRESULT(hr);
  90. if (FAILED(hr))
  91. {
  92. return hr;
  93. }
  94. if (!(dwInOut & SFGAO_CANDELETE))
  95. {
  96. EnableMenuItem(hmenu, idCmdFirst + SHARED_FILE_DELETE, MF_GRAYED | MF_BYCOMMAND);
  97. }
  98. if (!(dwInOut & SFGAO_CANRENAME))
  99. {
  100. EnableMenuItem(hmenu, idCmdFirst + SHARED_FILE_RENAME, MF_GRAYED | MF_BYCOMMAND);
  101. }
  102. if (!(dwInOut & SFGAO_HASPROPSHEET))
  103. {
  104. EnableMenuItem(hmenu, idCmdFirst + SHARED_FILE_PROPERTIES, MF_GRAYED | MF_BYCOMMAND);
  105. }
  106. SetMenuDefaultItem(hmenu, idCmdFirst + SHARED_FILE_PROPERTIES, FALSE);
  107. return ResultFromShort(qcm.idCmdFirst - idCmdFirst);
  108. }
  109. }
  110. STDMETHODIMP
  111. CSharesCM::InvokeCommand(
  112. LPCMINVOKECOMMANDINFO lpici
  113. )
  114. {
  115. HRESULT hr = S_OK;
  116. LPIDSHARE pids;
  117. UINT i;
  118. UINT idCmd = (UINT)LOWORD(lpici->lpVerb);
  119. if (HIWORD(lpici->lpVerb))
  120. {
  121. // Deal with string commands
  122. PSTR pszCmd = (PSTR)lpici->lpVerb;
  123. // Check for "delete" and "properties" that come from the toolbar or
  124. // the shell view.
  125. if (0 == lstrcmpA(pszCmd, "delete"))
  126. {
  127. idCmd = SHARED_FILE_DELETE;
  128. }
  129. else if (0 == lstrcmpA(pszCmd, "rename"))
  130. {
  131. idCmd = SHARED_FILE_RENAME;
  132. }
  133. else if (0 == lstrcmpA(pszCmd, "properties"))
  134. {
  135. idCmd = SHARED_FILE_PROPERTIES;
  136. }
  137. else
  138. {
  139. return E_INVALIDARG;
  140. }
  141. }
  142. switch(idCmd)
  143. {
  144. case SHARED_FILE_DELETE:
  145. {
  146. for (UINT i = 0; i < m_cidl; i++)
  147. {
  148. pids = (LPIDSHARE)m_apidl[i];
  149. hr = ShareDoDelete(m_hwnd, m_pszMachine, Share_GetName(pids));
  150. CHECK_HRESULT(hr);
  151. // even if failure, keep going
  152. }
  153. break;
  154. }
  155. case SHARED_FILE_RENAME:
  156. {
  157. appAssert(!"Shouldn't get rename command here!");
  158. hr = E_FAIL;
  159. break;
  160. }
  161. case SHARED_FILE_PROPERTIES:
  162. {
  163. // should we do multiple-select properties?
  164. appAssert(m_cidl == 1);
  165. pids = (LPIDSHARE)m_apidl[0];
  166. // pass in a pointer to our own IUnknown
  167. IUnknown* punk;
  168. hr = QueryInterface(IID_IUnknown, (LPVOID*)&punk);
  169. if (SUCCEEDED(hr))
  170. {
  171. hr = ShareDoProperties(punk, m_pszMachine, Share_GetName(pids));
  172. punk->Release();
  173. }
  174. break;
  175. }
  176. } // switch(wParam)
  177. return hr;
  178. }
  179. STDMETHODIMP
  180. CSharesCM::GetCommandString(
  181. UINT_PTR idCmd,
  182. UINT uType,
  183. UINT * pwReserved,
  184. LPSTR pszName,
  185. UINT cchMax
  186. )
  187. {
  188. HRESULT hr = E_FAIL;
  189. *((LPWSTR)pszName) = TEXT('\0');
  190. if (uType == GCS_HELPTEXT)
  191. {
  192. LoadStringW(g_hInstance, (UINT)(idCmd + IDS_MH_FSIDM_FIRST), (LPWSTR)pszName, cchMax);
  193. hr = S_OK;
  194. }
  195. else if (uType == GCS_VERB)
  196. {
  197. switch(idCmd)
  198. {
  199. case SHARED_FILE_DELETE:
  200. case SHARED_FILE_PROPERTIES:
  201. break;
  202. case SHARED_FILE_RENAME:
  203. StrNCopy((LPWSTR)pszName, c_szRename, cchMax);
  204. hr = S_OK;
  205. break;
  206. }
  207. }
  208. return hr;
  209. }