2 * FolderItemVerb(s) implementation
4 * Copyright 2015 Mark Jansen
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
26 CFolderItemVerb::CFolderItemVerb()
30 CFolderItemVerb::~CFolderItemVerb()
34 void CFolderItemVerb::Init(IContextMenu
* menu
, BSTR name
)
40 // *** FolderItemVerb methods ***
42 HRESULT STDMETHODCALLTYPE
CFolderItemVerb::get_Application(IDispatch
**ppid
)
44 TRACE("(%p, %p)\n", this, ppid
);
48 HRESULT STDMETHODCALLTYPE
CFolderItemVerb::get_Parent(IDispatch
**ppid
)
50 TRACE("(%p, %p)\n", this, ppid
);
54 HRESULT STDMETHODCALLTYPE
CFolderItemVerb::get_Name(BSTR
*pbs
)
58 *pbs
= SysAllocString(m_name
);
62 HRESULT STDMETHODCALLTYPE
CFolderItemVerb::DoIt()
64 TRACE("(%p, %p)\n", this);
73 CFolderItemVerbs::CFolderItemVerbs()
79 CFolderItemVerbs::~CFolderItemVerbs()
84 HRESULT
CFolderItemVerbs::Init(LPITEMIDLIST idlist
)
86 CComPtr
<IShellFolder
> folder
;
88 HRESULT hr
= SHBindToParent(idlist
, IID_PPV_ARG(IShellFolder
, &folder
), &child
);
89 if (FAILED_UNEXPECTEDLY(hr
))
92 hr
= folder
->GetUIObjectOf(NULL
, 1, &child
, IID_IContextMenu
, NULL
, (PVOID
*)&m_contextmenu
);
93 if (FAILED_UNEXPECTEDLY(hr
))
96 m_menu
= CreatePopupMenu();
97 hr
= m_contextmenu
->QueryContextMenu(m_menu
, 0, FCIDM_SHVIEWFIRST
, FCIDM_SHVIEWLAST
, CMF_NORMAL
);
101 m_count
= GetMenuItemCount(m_menu
);
106 // *** FolderItemVerbs methods ***
107 HRESULT STDMETHODCALLTYPE
CFolderItemVerbs::get_Count(LONG
*plCount
)
115 HRESULT STDMETHODCALLTYPE
CFolderItemVerbs::get_Application(IDispatch
**ppid
)
117 TRACE("(%p, %p)\n", this, ppid
);
121 HRESULT STDMETHODCALLTYPE
CFolderItemVerbs::get_Parent(IDispatch
**ppid
)
123 TRACE("(%p, %p)\n", this, ppid
);
127 HRESULT STDMETHODCALLTYPE
CFolderItemVerbs::Item(VARIANT indexVar
, FolderItemVerb
**ppid
)
133 VariantCopyInd(&var
, &indexVar
);
135 HRESULT hr
= VariantChangeType(&var
, &var
, 0, VT_I4
);
136 if (FAILED_UNEXPECTEDLY(hr
))
139 int index
= V_I4(&var
);
147 name
= SysAllocStringLen(NULL
, 0);
150 MENUITEMINFOW info
= { sizeof(info
), 0 };
151 info
.fMask
= MIIM_STRING
;
152 if (!GetMenuItemInfoW(m_menu
, index
, TRUE
, &info
))
154 name
= SysAllocStringLen(NULL
, info
.cch
);
157 info
.dwTypeData
= name
;
159 GetMenuItemInfoW(m_menu
, index
, TRUE
, &info
);
164 return E_OUTOFMEMORY
;
166 CFolderItemVerb
* verb
= new CComObject
<CFolderItemVerb
>();
167 verb
->Init(m_contextmenu
, name
);
174 HRESULT STDMETHODCALLTYPE
CFolderItemVerbs::_NewEnum(IUnknown
**ppunk
)
176 TRACE("(%p, %p)\n", this, ppunk
);