ReactOS  0.4.14-dev-368-gfa26425
CDefViewBckgrndMenu Class Reference
Inheritance diagram for CDefViewBckgrndMenu:
Collaboration diagram for CDefViewBckgrndMenu:

Public Member Functions

 CDefViewBckgrndMenu ()
 
 ~CDefViewBckgrndMenu ()
 
HRESULT Initialize (IShellFolder *psf)
 
virtual HRESULT WINAPI QueryContextMenu (HMENU hMenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags)
 
virtual HRESULT WINAPI InvokeCommand (LPCMINVOKECOMMANDINFO lpcmi)
 
virtual HRESULT WINAPI GetCommandString (UINT_PTR idCommand, UINT uFlags, UINT *lpReserved, LPSTR lpszName, UINT uMaxNameLen)
 
virtual HRESULT WINAPI HandleMenuMsg (UINT uMsg, WPARAM wParam, LPARAM lParam)
 
virtual HRESULT WINAPI HandleMenuMsg2 (UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *plResult)
 
virtual HRESULT STDMETHODCALLTYPE SetSite (IUnknown *pUnkSite)
 
virtual HRESULT STDMETHODCALLTYPE GetSite (REFIID riid, void **ppvSite)
 
- Public Member Functions inherited from ATL::CComObjectRootEx< CComMultiThreadModelNoCS >
 ~CComObjectRootEx ()
 
ULONG InternalAddRef ()
 
ULONG InternalRelease ()
 
void Lock ()
 
void Unlock ()
 
HRESULT _AtlInitialConstruct ()
 
- Public Member Functions inherited from ATL::CComObjectRootBase
 CComObjectRootBase ()
 
 ~CComObjectRootBase ()
 
void SetVoid (void *)
 
HRESULT _AtlFinalConstruct ()
 
HRESULT FinalConstruct ()
 
void InternalFinalConstructAddRef ()
 
void InternalFinalConstructRelease ()
 
void FinalRelease ()
 
- Public Member Functions inherited from IUnknown
HRESULT QueryInterface ([in] REFIID riid, [out, iid_is(riid)] void **ppvObject)
 
ULONG AddRef ()
 
ULONG Release ()
 
- Public Member Functions inherited from IObjectWithSite
HRESULT GetSite ([in] REFIID riid, [out, iid_is(riid)] PVOID *ppvSite)
 

Private Member Functions

BOOL _bIsDesktopBrowserMenu ()
 
BOOL _bCanPaste ()
 

Private Attributes

CComPtr< IUnknownm_site
 
CComPtr< IShellFolderm_psf
 
CComPtr< IContextMenum_folderCM
 
UINT m_idCmdFirst
 
UINT m_LastFolderCMId
 

Additional Inherited Members

- Public Types inherited from IContextMenu3
typedef IContextMenu3LPCONTEXTMENU3
 
- Public Types inherited from IContextMenu2
typedef IContextMenu2LPCONTEXTMENU2
 
- Public Types inherited from IContextMenu
typedef struct IContextMenu::tagCMINVOKECOMMANDINFO CMINVOKECOMMANDINFO
 
typedef struct IContextMenu::tagCMINVOKECOMMANDINFOLPCMINVOKECOMMANDINFO
 
typedef struct IContextMenu::tagCMInvokeCommandInfoEx CMINVOKECOMMANDINFOEX
 
typedef struct IContextMenu::tagCMInvokeCommandInfoExLPCMINVOKECOMMANDINFOEX
 
- Public Types inherited from IUnknown
typedef IUnknownLPUNKNOWN
 
- Public Types inherited from IObjectWithSite
typedef IObjectWithSiteLPOBJECTWITHSITE
 
- Static Public Member Functions inherited from ATL::CComObjectRootBase
static void WINAPI ObjectMain (bool)
 
static const struct _ATL_CATMAP_ENTRYGetCategoryMap ()
 
static HRESULT WINAPI InternalQueryInterface (void *pThis, const _ATL_INTMAP_ENTRY *pEntries, REFIID iid, void **ppvObject)
 
- Public Attributes inherited from ATL::CComObjectRootBase
LONG m_dwRef
 
- Public Attributes inherited from IContextMenu
CMIC_MASK_NOZONECHECKS typedef IContextMenuLPCONTEXTMENU
 
- Static Public Attributes inherited from IContextMenu
static CMDSTR_VIEWDETAILSW(const WCHAR []) const WCHAR CMDSTR_NEWFOLDERW [] = {'N','e','w','F','o','l','d','e','r',0}
 
static const WCHAR CMDSTR_VIEWLISTW [] = {'V','i','e','w','L','i','s','t',0}
 
static const WCHAR CMDSTR_VIEWDETAILSW [] = {'V','i','e','w','D','e','t','a','i','l','s',0}
 

Detailed Description

Definition at line 13 of file CDefViewBckgrndMenu.cpp.

Constructor & Destructor Documentation

◆ CDefViewBckgrndMenu()

CDefViewBckgrndMenu::CDefViewBckgrndMenu ( )

Definition at line 56 of file CDefViewBckgrndMenu.cpp.

◆ ~CDefViewBckgrndMenu()

CDefViewBckgrndMenu::~CDefViewBckgrndMenu ( )

Definition at line 62 of file CDefViewBckgrndMenu.cpp.

63 {
64 }

Member Function Documentation

◆ _bCanPaste()

BOOL CDefViewBckgrndMenu::_bCanPaste ( )
private

Definition at line 85 of file CDefViewBckgrndMenu.cpp.

86 {
87  /* If the folder doesn't have a drop target we can't paste */
89  HRESULT hr = m_psf->CreateViewObject(NULL, IID_PPV_ARG(IDropTarget, &pdt));
90  if (FAILED(hr))
91  return FALSE;
92 
93  /* We can only paste if CFSTR_SHELLIDLIST is present in the clipboard */
94  CComPtr<IDataObject> pDataObj;
95  hr = OleGetClipboard(&pDataObj);
96  if (FAILED(hr))
97  return FALSE;
98 
99  STGMEDIUM medium;
100  FORMATETC formatetc;
101 
102  /* Set the FORMATETC structure*/
103  InitFormatEtc(formatetc, RegisterClipboardFormatW(CFSTR_SHELLIDLIST), TYMED_HGLOBAL);
104  hr = pDataObj->GetData(&formatetc, &medium);
105  if (FAILED(hr))
106  return FALSE;
107 
108  ReleaseStgMedium(&medium);
109  return TRUE;
110 }
#define TRUE
Definition: types.h:120
#define CFSTR_SHELLIDLIST
Definition: shlobj.h:469
HRESULT hr
Definition: shlfolder.c:183
#define InitFormatEtc(fe, cf, med)
Definition: editor.h:33
void WINAPI ReleaseStgMedium(STGMEDIUM *pmedium)
Definition: ole2.c:2033
UINT WINAPI RegisterClipboardFormatW(_In_ LPCWSTR)
CComPtr< IShellFolder > m_psf
#define IID_PPV_ARG(Itype, ppType)
HRESULT WINAPI OleGetClipboard(IDataObject **obj)
Definition: clipboard.c:2249
smooth NULL
Definition: ftsmooth.c:416
LONG HRESULT
Definition: typedefs.h:77

Referenced by QueryContextMenu().

◆ _bIsDesktopBrowserMenu()

BOOL CDefViewBckgrndMenu::_bIsDesktopBrowserMenu ( )
private

Definition at line 66 of file CDefViewBckgrndMenu.cpp.

67 {
68  if (!m_site)
69  return FALSE;
70 
71  /* Get a pointer to the shell browser */
75  return FALSE;
76 
77  FOLDERSETTINGS FolderSettings;
78  hr = psv->GetCurrentInfo(&FolderSettings);
80  return FALSE;
81 
82  return ((FolderSettings.fFlags & FWF_DESKTOP) == FWF_DESKTOP);
83 }
HRESULT hr
Definition: shlfolder.c:183
#define SID_IFolderView
#define IID_PPV_ARG(Itype, ppType)
HRESULT WINAPI IUnknown_QueryService(IUnknown *, REFGUID, REFIID, LPVOID *)
Definition: ordinal.c:1448
LONG HRESULT
Definition: typedefs.h:77
#define FAILED_UNEXPECTEDLY(hr)
Definition: shellutils.h:71
CComPtr< IUnknown > m_site

Referenced by QueryContextMenu().

◆ GetCommandString()

HRESULT WINAPI CDefViewBckgrndMenu::GetCommandString ( UINT_PTR  idCommand,
UINT  uFlags,
UINT lpReserved,
LPSTR  lpszName,
UINT  uMaxNameLen 
)
virtual

Implements IContextMenu.

Definition at line 287 of file CDefViewBckgrndMenu.cpp.

288 {
289  if (m_folderCM)
290  {
291  return m_folderCM->GetCommandString(idCommand, uFlags, lpReserved, lpszName, uMaxNameLen);
292  }
293 
294  return E_NOTIMPL;
295 }
CComPtr< IContextMenu > m_folderCM
UINT uFlags
Definition: api.c:59
#define E_NOTIMPL
Definition: ddrawi.h:99

◆ GetSite()

HRESULT WINAPI CDefViewBckgrndMenu::GetSite ( REFIID  riid,
void **  ppvSite 
)
virtual

Definition at line 138 of file CDefViewBckgrndMenu.cpp.

139 {
140  if (!m_site)
141  return E_FAIL;
142 
143  return m_site->QueryInterface(riid, ppvSite);
144 }
REFIID riid
Definition: precomp.h:44
#define E_FAIL
Definition: ddrawi.h:102
CComPtr< IUnknown > m_site

◆ HandleMenuMsg()

HRESULT WINAPI CDefViewBckgrndMenu::HandleMenuMsg ( UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam 
)
virtual

Implements IContextMenu2.

Definition at line 299 of file CDefViewBckgrndMenu.cpp.

300 {
301  if(m_folderCM)
302  {
303  CComPtr<IContextMenu2> pfolderCM2;
304  HRESULT hr = m_folderCM->QueryInterface(IID_PPV_ARG(IContextMenu2, &pfolderCM2));
305  if (FAILED_UNEXPECTEDLY(hr))
306  return hr;
307 
308  return pfolderCM2->HandleMenuMsg(uMsg, wParam, lParam);
309  }
310 
311  return E_NOTIMPL;
312 }
HRESULT hr
Definition: shlfolder.c:183
CComPtr< IContextMenu > m_folderCM
#define IID_PPV_ARG(Itype, ppType)
WPARAM wParam
Definition: combotst.c:138
LONG HRESULT
Definition: typedefs.h:77
#define FAILED_UNEXPECTEDLY(hr)
Definition: shellutils.h:71
#define E_NOTIMPL
Definition: ddrawi.h:99
LPARAM lParam
Definition: combotst.c:139

◆ HandleMenuMsg2()

HRESULT WINAPI CDefViewBckgrndMenu::HandleMenuMsg2 ( UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam,
LRESULT plResult 
)
virtual

Implements IContextMenu3.

Definition at line 316 of file CDefViewBckgrndMenu.cpp.

317 {
318  if(m_folderCM)
319  {
320  CComPtr<IContextMenu3> pfolderCM3;
321  HRESULT hr = m_folderCM->QueryInterface(IID_PPV_ARG(IContextMenu3, &pfolderCM3));
322  if (FAILED_UNEXPECTEDLY(hr))
323  return hr;
324 
325  return pfolderCM3->HandleMenuMsg2(uMsg, wParam, lParam, plResult);
326  }
327 
328  return E_NOTIMPL;
329 }
HRESULT hr
Definition: shlfolder.c:183
CComPtr< IContextMenu > m_folderCM
#define IID_PPV_ARG(Itype, ppType)
WPARAM wParam
Definition: combotst.c:138
LONG HRESULT
Definition: typedefs.h:77
#define FAILED_UNEXPECTEDLY(hr)
Definition: shellutils.h:71
#define E_NOTIMPL
Definition: ddrawi.h:99
LPARAM lParam
Definition: combotst.c:139

◆ Initialize()

HRESULT CDefViewBckgrndMenu::Initialize ( IShellFolder psf)

Definition at line 113 of file CDefViewBckgrndMenu.cpp.

114 {
115  m_psf = psf;
116 
117  /* Get the context menu of the folder. Do it here because someone may call
118  InvokeCommand without calling QueryContextMenu. It is fine if this fails */
119  m_psf->CreateViewObject(NULL, IID_PPV_ARG(IContextMenu, &m_folderCM));
120 
121  return S_OK;
122 }
CComPtr< IShellFolder > m_psf
CComPtr< IContextMenu > m_folderCM
#define IID_PPV_ARG(Itype, ppType)
smooth NULL
Definition: ftsmooth.c:416
#define S_OK
Definition: intsafe.h:59

◆ InvokeCommand()

HRESULT WINAPI CDefViewBckgrndMenu::InvokeCommand ( LPCMINVOKECOMMANDINFO  lpcmi)
virtual

Implements IContextMenu.

Definition at line 216 of file CDefViewBckgrndMenu.cpp.

217 {
218  UINT idCmd = LOWORD(lpcmi->lpVerb);
219 
220  if (HIWORD(lpcmi->lpVerb) && !strcmp(lpcmi->lpVerb, CMDSTR_VIEWLISTA))
221  {
222  idCmd = FCIDM_SHVIEW_LISTVIEW;
223  }
224  else if (HIWORD(lpcmi->lpVerb) && !strcmp(lpcmi->lpVerb, CMDSTR_VIEWDETAILSA))
225  {
226  idCmd = FCIDM_SHVIEW_REPORTVIEW;
227  }
228  else if(HIWORD(lpcmi->lpVerb) != 0 || idCmd < m_LastFolderCMId)
229  {
230  if (m_folderCM)
231  {
232  return m_folderCM->InvokeCommand(lpcmi);
233  }
234  WARN("m_folderCM is NULL!\n");
235  return E_NOTIMPL;
236  }
237  else
238  {
239  /* The default part of the background menu doesn't have shifted ids so we need to convert the id offset to the real id */
240  idCmd += m_idCmdFirst;
241  }
242 
243  /* The commands that are handled by the def view are forwarded to it */
244  switch (idCmd)
245  {
246  case FCIDM_SHVIEW_INSERT:
248  if (m_folderCM)
249  {
250  lpcmi->lpVerb = MAKEINTRESOURCEA(idCmd);
251  return m_folderCM->InvokeCommand(lpcmi);
252  }
253  WARN("m_folderCM is NULL!\n");
254  return E_NOTIMPL;
259  case 0x30: /* FIX IDS in resource files */
260  case 0x31:
261  case 0x32:
262  case 0x33:
266  if (!m_site)
267  return E_FAIL;
268 
269  /* Get a pointer to the shell browser */
272  if (FAILED_UNEXPECTEDLY(hr))
273  return hr;
274 
275  HWND hwndSV = NULL;
276  if (SUCCEEDED(psv->GetWindow(&hwndSV)))
277  SendMessageW(hwndSV, WM_COMMAND, MAKEWPARAM(idCmd, 0), 0);
278  return S_OK;
279  }
280 
281  ERR("Got unknown command id %ul\n", LOWORD(lpcmi->lpVerb));
282  return E_FAIL;
283 }
#define FCIDM_SHVIEW_LISTVIEW
Definition: shresdef.h:751
#define MAKEWPARAM(l, h)
Definition: winuser.h:3948
#define FCIDM_SHVIEW_SNAPTOGRID
Definition: shresdef.h:755
#define FCIDM_SHVIEW_AUTOARRANGE
Definition: shresdef.h:754
HRESULT hr
Definition: shlfolder.c:183
#define WARN(fmt,...)
Definition: debug.h:111
CComPtr< IContextMenu > m_folderCM
#define MAKEINTRESOURCEA(i)
Definition: winuser.h:581
#define SID_IFolderView
#define IID_PPV_ARG(Itype, ppType)
#define E_FAIL
Definition: ddrawi.h:102
HRESULT WINAPI IUnknown_QueryService(IUnknown *, REFGUID, REFIID, LPVOID *)
Definition: ordinal.c:1448
#define FCIDM_SHVIEW_INSERTLINK
Definition: shresdef.h:743
#define FCIDM_SHVIEW_REFRESH
Definition: shresdef.h:763
#define FCIDM_SHVIEW_INSERT
Definition: shresdef.h:741
smooth NULL
Definition: ftsmooth.c:416
LONG HRESULT
Definition: typedefs.h:77
#define FCIDM_SHVIEW_REPORTVIEW
Definition: shresdef.h:752
#define FAILED_UNEXPECTEDLY(hr)
Definition: shellutils.h:71
#define WM_COMMAND
Definition: winuser.h:1722
#define FCIDM_SHVIEW_BIGICON
Definition: shresdef.h:749
CComPtr< IUnknown > m_site
#define ERR(fmt,...)
Definition: debug.h:109
#define S_OK
Definition: intsafe.h:59
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define E_NOTIMPL
Definition: ddrawi.h:99
unsigned int UINT
Definition: ndis.h:50
#define HIWORD(l)
Definition: typedefs.h:246
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define FCIDM_SHVIEW_SMALLICON
Definition: shresdef.h:750
#define LOWORD(l)
Definition: pedump.c:82
#define SUCCEEDED(hr)
Definition: intsafe.h:57

◆ QueryContextMenu()

HRESULT WINAPI CDefViewBckgrndMenu::QueryContextMenu ( HMENU  hMenu,
UINT  indexMenu,
UINT  idCmdFirst,
UINT  idCmdLast,
UINT  uFlags 
)
virtual

Implements IContextMenu.

Definition at line 148 of file CDefViewBckgrndMenu.cpp.

149 {
150  HRESULT hr;
151  HMENU hMenuPart;
152  UINT cIds = 0;
153 
154  /* This is something the implementations of IContextMenu should never really do.
155  However CDefViewBckgrndMenu is more or less an overengineering result, its code could really be part of the
156  CDefView. Given this, I think that abusing the interface here is not that bad since only CDefView is the ony
157  user of this class. Here we need to do two things to keep things as simple as possible.
158  First we want the menu part added by the shell folder to be the first to add so as to make as few id translations
159  as possible. Second, we want to add the default part of the background menu without shifted ids, so as
160  to let the CDefView fill some parts like filling the arrange modes or checking the view mode. In order
161  for that to work we need to save idCmdFirst because our caller will pass id offsets to InvokeCommand.
162  This makes it impossible to concatenate the CDefViewBckgrndMenu with other menus since it abuses IContextMenu
163  but as stated above, its sole user is CDefView and should really be that way. */
164  m_idCmdFirst = idCmdFirst;
165 
166  /* Let the shell folder add any items it wants to add in the background context menu */
167  if (m_folderCM)
168  {
169  hr = m_folderCM->QueryContextMenu(hMenu, indexMenu, idCmdFirst, idCmdLast, uFlags);
170  if (SUCCEEDED(hr))
171  {
173  cIds = m_LastFolderCMId;
174  }
175  else
176  {
177  WARN("QueryContextMenu failed!\n");
178  }
179  }
180  else
181  {
182  WARN("GetUIObjectOf didn't give any context menu!\n");
183  }
184 
185  /* Load the default part of the background context menu */
186  hMenuPart = LoadMenuW(shell32_hInstance, L"MENU_002");
187  if (hMenuPart)
188  {
189  /* Don't show the view submenu for the desktop */
191  {
193  }
194 
195  /* Disable the paste options if it is not possible */
196  if (!_bCanPaste())
197  {
200  }
201 
202  /* merge general background context menu in */
203  Shell_MergeMenus(hMenu, GetSubMenu(hMenuPart, 0), indexMenu, 0, idCmdLast, MM_DONTREMOVESEPS | MM_SUBMENUSHAVEIDS | MM_ADDSEPARATOR);
204  DestroyMenu(hMenuPart);
205  }
206  else
207  {
208  ERR("Failed to load menu from resource!\n");
209  }
210 
211  return MAKE_HRESULT(SEVERITY_SUCCESS, 0, cIds);
212 }
#define MF_BYCOMMAND
Definition: winuser.h:202
UINT WINAPI Shell_MergeMenus(HMENU hmDst, HMENU hmSrc, UINT uInsert, UINT uIDAdjust, UINT uIDAdjustMax, ULONG uFlags)
Definition: shlmenu.c:857
HRESULT hr
Definition: shlfolder.c:183
#define WARN(fmt,...)
Definition: debug.h:111
CComPtr< IContextMenu > m_folderCM
UINT uFlags
Definition: api.c:59
#define SEVERITY_SUCCESS
Definition: winerror.h:64
#define FCIDM_SHVIEW_INSERTLINK
Definition: shresdef.h:743
BOOL WINAPI EnableMenuItem(_In_ HMENU, _In_ UINT, _In_ UINT)
HINSTANCE shell32_hInstance
Definition: misc.cpp:82
#define FCIDM_SHVIEW_INSERT
Definition: shresdef.h:741
#define MAKE_HRESULT(sev, fac, code)
Definition: dmerror.h:30
#define MM_ADDSEPARATOR
Definition: shlobj.h:2319
LONG HRESULT
Definition: typedefs.h:77
BOOL WINAPI DeleteMenu(_In_ HMENU, _In_ UINT, _In_ UINT)
#define FCIDM_SHVIEW_VIEW
Definition: shresdef.h:736
static const WCHAR L[]
Definition: oid.c:1250
HMENU WINAPI GetSubMenu(_In_ HMENU, _In_ int)
BOOL WINAPI DestroyMenu(_In_ HMENU)
#define ERR(fmt,...)
Definition: debug.h:109
unsigned int UINT
Definition: ndis.h:50
#define MM_SUBMENUSHAVEIDS
Definition: shlobj.h:2320
HMENU WINAPI LoadMenuW(_In_opt_ HINSTANCE, _In_ LPCWSTR)
#define MF_GRAYED
Definition: winuser.h:129
static const CLSID *static CLSID *static const GUID VARIANT VARIANT *static IServiceProvider DWORD *static HMENU
Definition: ordinal.c:60
#define LOWORD(l)
Definition: pedump.c:82
#define MM_DONTREMOVESEPS
Definition: shlobj.h:2321
#define SUCCEEDED(hr)
Definition: intsafe.h:57

◆ SetSite()

HRESULT WINAPI CDefViewBckgrndMenu::SetSite ( IUnknown pUnkSite)
virtual

Implements IObjectWithSite.

Definition at line 126 of file CDefViewBckgrndMenu.cpp.

127 {
128  m_site = pUnkSite;
129 
130  if(m_folderCM)
131  IUnknown_SetSite(m_folderCM, pUnkSite);
132 
133  return S_OK;
134 }
CComPtr< IContextMenu > m_folderCM
HRESULT WINAPI IUnknown_SetSite(IUnknown *obj, IUnknown *site)
Definition: ordinal.c:1358
CComPtr< IUnknown > m_site
#define S_OK
Definition: intsafe.h:59

Member Data Documentation

◆ m_folderCM

CComPtr<IContextMenu> CDefViewBckgrndMenu::m_folderCM
private

◆ m_idCmdFirst

UINT CDefViewBckgrndMenu::m_idCmdFirst
private

Definition at line 23 of file CDefViewBckgrndMenu.cpp.

Referenced by CDefViewBckgrndMenu(), InvokeCommand(), and QueryContextMenu().

◆ m_LastFolderCMId

UINT CDefViewBckgrndMenu::m_LastFolderCMId
private

Definition at line 24 of file CDefViewBckgrndMenu.cpp.

Referenced by CDefViewBckgrndMenu(), InvokeCommand(), and QueryContextMenu().

◆ m_psf

CComPtr<IShellFolder> CDefViewBckgrndMenu::m_psf
private

Definition at line 20 of file CDefViewBckgrndMenu.cpp.

Referenced by _bCanPaste(), and Initialize().

◆ m_site

CComPtr<IUnknown> CDefViewBckgrndMenu::m_site
private

Definition at line 19 of file CDefViewBckgrndMenu.cpp.

Referenced by _bIsDesktopBrowserMenu(), GetSite(), InvokeCommand(), and SetSite().


The documentation for this class was generated from the following file: