Reactos
1/*
2 * FolderItemVerb(s) implementation
3 *
4 * Copyright 2015 Mark Jansen
5 *
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.
10 *
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.
15 *
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
19 */
20
21#include "precomp.h"
22
23WINE_DEFAULT_DEBUG_CHANNEL(shell);
24
25
26CFolderItemVerb::CFolderItemVerb()
27{
28}
29
30CFolderItemVerb::~CFolderItemVerb()
31{
32}
33
34void CFolderItemVerb::Init(IContextMenu* menu, BSTR name)
35{
36 m_contextmenu = menu;
37 m_name.m_str = name;
38}
39
40// *** FolderItemVerb methods ***
41
42HRESULT STDMETHODCALLTYPE CFolderItemVerb::get_Application(IDispatch **ppid)
43{
44 TRACE("(%p, %p)\n", this, ppid);
45
46 if (ppid)
47 *ppid = NULL;
48
49 return E_NOTIMPL;
50}
51
52HRESULT STDMETHODCALLTYPE CFolderItemVerb::get_Parent(IDispatch **ppid)
53{
54 TRACE("(%p, %p)\n", this, ppid);
55
56 if (ppid)
57 *ppid = NULL;
58
59 return E_NOTIMPL;
60}
61
62HRESULT STDMETHODCALLTYPE CFolderItemVerb::get_Name(BSTR *pbs)
63{
64 if (!pbs)
65 return E_POINTER;
66 *pbs = SysAllocString(m_name);
67 return S_OK;
68}
69
70HRESULT STDMETHODCALLTYPE CFolderItemVerb::DoIt()
71{
72 TRACE("(%p, %p)\n", this);
73 return E_NOTIMPL;
74}
75
76
77
78
79
80
81CFolderItemVerbs::CFolderItemVerbs()
82 :m_menu(NULL)
83 ,m_count(0)
84{
85}
86
87CFolderItemVerbs::~CFolderItemVerbs()
88{
89 DestroyMenu(m_menu);
90}
91
92HRESULT CFolderItemVerbs::Init(LPITEMIDLIST idlist)
93{
94 HRESULT hr = SHELL_GetUIObjectOfAbsoluteItem(NULL, idlist, IID_PPV_ARG(IContextMenu, &m_contextmenu));
95 if (FAILED_UNEXPECTEDLY(hr))
96 return hr;
97
98 m_menu = CreatePopupMenu();
99 hr = m_contextmenu->QueryContextMenu(m_menu, 0, FCIDM_SHVIEWFIRST, FCIDM_SHVIEWLAST, CMF_NORMAL);
100 if (!SUCCEEDED(hr))
101 return hr;
102
103 m_count = GetMenuItemCount(m_menu);
104 return hr;
105}
106
107
108// *** FolderItemVerbs methods ***
109HRESULT STDMETHODCALLTYPE CFolderItemVerbs::get_Count(LONG *plCount)
110{
111 if (!plCount)
112 return E_INVALIDARG;
113 *plCount = m_count;
114 return S_OK;
115}
116
117HRESULT STDMETHODCALLTYPE CFolderItemVerbs::get_Application(IDispatch **ppid)
118{
119 TRACE("(%p, %p)\n", this, ppid);
120
121 if (ppid)
122 *ppid = NULL;
123
124 return E_NOTIMPL;
125}
126
127HRESULT STDMETHODCALLTYPE CFolderItemVerbs::get_Parent(IDispatch **ppid)
128{
129 TRACE("(%p, %p)\n", this, ppid);
130
131 if (ppid)
132 *ppid = NULL;
133
134 return E_NOTIMPL;
135}
136
137HRESULT STDMETHODCALLTYPE CFolderItemVerbs::Item(VARIANT indexVar, FolderItemVerb **ppid)
138{
139 if (!ppid)
140 return E_POINTER;
141
142 CComVariant var;
143
144 HRESULT hr = VariantChangeType(&var, &indexVar, 0, VT_I4);
145 if (FAILED_UNEXPECTEDLY(hr))
146 return E_INVALIDARG;
147
148 int index = V_I4(&var);
149
150 if (index > m_count)
151 return S_OK;
152
153 BSTR name = NULL;
154
155 if(index == m_count)
156 {
157 name = SysAllocStringLen(NULL, 0);
158 }
159 else
160 {
161 MENUITEMINFOW info = { sizeof(info), 0 };
162 info.fMask = MIIM_STRING;
163 if (!GetMenuItemInfoW(m_menu, index, TRUE, &info))
164 return E_FAIL;
165 name = SysAllocStringLen(NULL, info.cch);
166 if (name)
167 {
168 info.dwTypeData = name;
169 info.cch++;
170 GetMenuItemInfoW(m_menu, index, TRUE, &info);
171 }
172 }
173
174 if (!name)
175 return E_OUTOFMEMORY;
176
177 CFolderItemVerb* verb = new CComObject<CFolderItemVerb>();
178 verb->Init(m_contextmenu, name);
179 verb->AddRef();
180 *ppid = verb;
181
182 return S_OK;
183}
184
185HRESULT STDMETHODCALLTYPE CFolderItemVerbs::_NewEnum(IUnknown **ppunk)
186{
187 TRACE("(%p, %p)\n", this, ppunk);
188 return E_NOTIMPL;
189}
190
191