2f1009924438316f566de3b9b6c4d2d9ac934a6d
[reactos.git] / reactos / dll / win32 / shell32 / shfldr_cpanel.c
1 /*
2 * Control panel folder
3 *
4 * Copyright 2003 Martin Fuchs
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
22 #include <precomp.h>
23
24
25 WINE_DEFAULT_DEBUG_CHANNEL(shell);
26
27 /***********************************************************************
28 * control panel implementation in shell namespace
29 */
30
31 typedef struct {
32 const IShellFolder2Vtbl *lpVtbl;
33 LONG ref;
34 const IPersistFolder2Vtbl *lpVtblPersistFolder2;
35 const IShellExecuteHookWVtbl *lpVtblShellExecuteHookW;
36 const IShellExecuteHookAVtbl *lpVtblShellExecuteHookA;
37 const IContextMenu2Vtbl *lpVtblContextMenu;
38 IUnknown *pUnkOuter; /* used for aggregation */
39
40 /* both paths are parsible from the desktop */
41 LPITEMIDLIST pidlRoot; /* absolute pidl */
42 int dwAttributes; /* attributes returned by GetAttributesOf FIXME: use it */
43 LPCITEMIDLIST *apidl;
44 UINT cidl;
45 } ICPanelImpl, *LPICPanelImpl;
46
47 static const IShellFolder2Vtbl vt_ShellFolder2;
48 static const IPersistFolder2Vtbl vt_PersistFolder2;
49 static const IShellExecuteHookWVtbl vt_ShellExecuteHookW;
50 static const IShellExecuteHookAVtbl vt_ShellExecuteHookA;
51 static const IContextMenu2Vtbl vt_ContextMenu;
52
53 static LPICPanelImpl __inline impl_from_IPersistFolder2( IPersistFolder2 *iface )
54 {
55 return (LPICPanelImpl)((char*)iface - FIELD_OFFSET(ICPanelImpl, lpVtblPersistFolder2));
56 }
57
58 static LPICPanelImpl __inline impl_from_IContextMenu( IContextMenu2 *iface )
59 {
60 return (LPICPanelImpl)((char*)iface - FIELD_OFFSET(ICPanelImpl, lpVtblContextMenu));
61 }
62
63
64 static LPICPanelImpl __inline impl_from_IShellExecuteHookW( IShellExecuteHookW *iface )
65 {
66 return (LPICPanelImpl)((char*)iface - FIELD_OFFSET(ICPanelImpl, lpVtblShellExecuteHookW));
67 }
68
69 static LPICPanelImpl __inline impl_from_IShellExecuteHookA( IShellExecuteHookA *iface )
70 {
71 return (LPICPanelImpl)((char*)iface - FIELD_OFFSET(ICPanelImpl, lpVtblShellExecuteHookA));
72 }
73
74
75 /*
76 converts This to an interface pointer
77 */
78 #define _IUnknown_(This) (IUnknown*)&(This->lpVtbl)
79 #define _IShellFolder_(This) (IShellFolder*)&(This->lpVtbl)
80 #define _IShellFolder2_(This) (IShellFolder2*)&(This->lpVtbl)
81
82 #define _IPersist_(This) (IPersist*)&(This->lpVtblPersistFolder2)
83 #define _IPersistFolder_(This) (IPersistFolder*)&(This->lpVtblPersistFolder2)
84 #define _IPersistFolder2_(This) (IPersistFolder2*)&(This->lpVtblPersistFolder2)
85 #define _IShellExecuteHookW_(This) (IShellExecuteHookW*)&(This->lpVtblShellExecuteHookW)
86 #define _IShellExecuteHookA_(This) (IShellExecuteHookA*)&(This->lpVtblShellExecuteHookA)
87
88
89 /***********************************************************************
90 * IShellFolder [ControlPanel] implementation
91 */
92
93 static const shvheader ControlPanelSFHeader[] = {
94 {IDS_SHV_COLUMN8, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 15},/*FIXME*/
95 {IDS_SHV_COLUMN9, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 200},/*FIXME*/
96 };
97
98 #define CONROLPANELSHELLVIEWCOLUMNS 2
99
100 /**************************************************************************
101 * IControlPanel_Constructor
102 */
103 HRESULT WINAPI IControlPanel_Constructor(IUnknown* pUnkOuter, REFIID riid, LPVOID * ppv)
104 {
105 ICPanelImpl *sf;
106
107 TRACE("unkOut=%p %s\n", pUnkOuter, shdebugstr_guid(riid));
108
109 if (!ppv)
110 return E_POINTER;
111 if (pUnkOuter && !IsEqualIID (riid, &IID_IUnknown))
112 return CLASS_E_NOAGGREGATION;
113
114 sf = (ICPanelImpl *) LocalAlloc(LMEM_ZEROINIT, sizeof(ICPanelImpl));
115 if (!sf)
116 return E_OUTOFMEMORY;
117
118 sf->ref = 0;
119 sf->apidl = NULL;
120 sf->cidl = 0;
121 sf->lpVtbl = &vt_ShellFolder2;
122 sf->lpVtblPersistFolder2 = &vt_PersistFolder2;
123 sf->lpVtblShellExecuteHookW = &vt_ShellExecuteHookW;
124 sf->lpVtblShellExecuteHookA = &vt_ShellExecuteHookA;
125 sf->lpVtblContextMenu = &vt_ContextMenu;
126 sf->pidlRoot = _ILCreateControlPanel(); /* my qualified pidl */
127 sf->pUnkOuter = pUnkOuter ? pUnkOuter : _IUnknown_ (sf);
128
129 if (!SUCCEEDED(IUnknown_QueryInterface(_IUnknown_(sf), riid, ppv))) {
130 IUnknown_Release(_IUnknown_(sf));
131 return E_NOINTERFACE;
132 }
133
134 TRACE("--(%p)\n", sf);
135 return S_OK;
136 }
137
138 /**************************************************************************
139 * ISF_ControlPanel_fnQueryInterface
140 *
141 * NOTES supports not IPersist/IPersistFolder
142 */
143 static HRESULT WINAPI ISF_ControlPanel_fnQueryInterface(IShellFolder2 * iface, REFIID riid, LPVOID * ppvObject)
144 {
145 ICPanelImpl *This = (ICPanelImpl *)iface;
146
147 TRACE("(%p)->(%s,%p)\n", This, shdebugstr_guid(riid), ppvObject);
148
149 *ppvObject = NULL;
150
151 if (IsEqualIID(riid, &IID_IUnknown) ||
152 IsEqualIID(riid, &IID_IShellFolder) || IsEqualIID(riid, &IID_IShellFolder2))
153 *ppvObject = This;
154 else if (IsEqualIID(riid, &IID_IPersist) ||
155 IsEqualIID(riid, &IID_IPersistFolder) || IsEqualIID(riid, &IID_IPersistFolder2))
156 *ppvObject = _IPersistFolder2_(This);
157 else if (IsEqualIID(riid, &IID_IShellExecuteHookW))
158 *ppvObject = _IShellExecuteHookW_(This);
159 else if (IsEqualIID(riid, &IID_IShellExecuteHookA))
160 *ppvObject = _IShellExecuteHookA_(This);
161
162 if (*ppvObject) {
163 IUnknown_AddRef((IUnknown *)(*ppvObject));
164 TRACE("-- Interface:(%p)->(%p)\n", ppvObject, *ppvObject);
165 return S_OK;
166 }
167 TRACE("-- Interface: E_NOINTERFACE\n");
168 return E_NOINTERFACE;
169 }
170
171 static ULONG WINAPI ISF_ControlPanel_fnAddRef(IShellFolder2 * iface)
172 {
173 ICPanelImpl *This = (ICPanelImpl *)iface;
174 ULONG refCount = InterlockedIncrement(&This->ref);
175
176 TRACE("(%p)->(count=%u)\n", This, refCount - 1);
177
178 return refCount;
179 }
180
181 static ULONG WINAPI ISF_ControlPanel_fnRelease(IShellFolder2 * iface)
182 {
183 ICPanelImpl *This = (ICPanelImpl *)iface;
184 ULONG refCount = InterlockedDecrement(&This->ref);
185
186 TRACE("(%p)->(count=%u)\n", This, refCount + 1);
187
188 if (!refCount) {
189 TRACE("-- destroying IShellFolder(%p)\n", This);
190 SHFree(This->pidlRoot);
191 LocalFree((HLOCAL) This);
192 }
193 return refCount;
194 }
195
196 /**************************************************************************
197 * ISF_ControlPanel_fnParseDisplayName
198 */
199 static HRESULT WINAPI
200 ISF_ControlPanel_fnParseDisplayName(IShellFolder2 * iface,
201 HWND hwndOwner,
202 LPBC pbc,
203 LPOLESTR lpszDisplayName,
204 DWORD * pchEaten, LPITEMIDLIST * ppidl, DWORD * pdwAttributes)
205 {
206 ICPanelImpl *This = (ICPanelImpl *)iface;
207
208 HRESULT hr = E_INVALIDARG;
209
210 FIXME("(%p)->(HWND=%p,%p,%p=%s,%p,pidl=%p,%p)\n",
211 This, hwndOwner, pbc, lpszDisplayName, debugstr_w(lpszDisplayName), pchEaten, ppidl, pdwAttributes);
212
213 *ppidl = 0;
214 if (pchEaten)
215 *pchEaten = 0;
216
217 TRACE("(%p)->(-- ret=0x%08x)\n", This, hr);
218
219 return hr;
220 }
221
222 static LPITEMIDLIST _ILCreateCPanelApplet(LPCSTR name, LPCSTR displayName,
223 LPCSTR comment, int iconIdx)
224 {
225 PIDLCPanelStruct *p;
226 LPITEMIDLIST pidl;
227 PIDLDATA tmp;
228 int size0 = (char*)&tmp.u.cpanel.szName-(char*)&tmp.u.cpanel;
229 int size = size0;
230 int l;
231
232 tmp.type = PT_CPLAPPLET;
233 tmp.u.cpanel.dummy = 0;
234 tmp.u.cpanel.iconIdx = iconIdx;
235
236 l = strlen(name);
237 size += l+1;
238
239 tmp.u.cpanel.offsDispName = l+1;
240 l = strlen(displayName);
241 size += l+1;
242
243 tmp.u.cpanel.offsComment = tmp.u.cpanel.offsDispName+1+l;
244 l = strlen(comment);
245 size += l+1;
246
247 pidl = SHAlloc(size+4);
248 if (!pidl)
249 return NULL;
250
251 pidl->mkid.cb = size+2;
252 memcpy(pidl->mkid.abID, &tmp, 2+size0);
253
254 p = &((PIDLDATA*)pidl->mkid.abID)->u.cpanel;
255 strcpy(p->szName, name);
256 strcpy(p->szName+tmp.u.cpanel.offsDispName, displayName);
257 strcpy(p->szName+tmp.u.cpanel.offsComment, comment);
258
259 *(WORD*)((char*)pidl+(size+2)) = 0;
260
261 pcheck(pidl);
262
263 return pidl;
264 }
265
266 /**************************************************************************
267 * _ILGetCPanelPointer()
268 * gets a pointer to the control panel struct stored in the pidl
269 */
270 static PIDLCPanelStruct* _ILGetCPanelPointer(LPCITEMIDLIST pidl)
271 {
272 LPPIDLDATA pdata = _ILGetDataPointer(pidl);
273
274 if (pdata && pdata->type==PT_CPLAPPLET)
275 return (PIDLCPanelStruct*)&(pdata->u.cpanel);
276
277 return NULL;
278 }
279
280 /**************************************************************************
281 * ISF_ControlPanel_fnEnumObjects
282 */
283 static BOOL SHELL_RegisterCPanelApp(IEnumIDList* list, LPCSTR path)
284 {
285 LPITEMIDLIST pidl;
286 CPlApplet* applet;
287 CPanel panel;
288 CPLINFO info;
289 unsigned i;
290 int iconIdx;
291
292 char displayName[MAX_PATH];
293 char comment[MAX_PATH];
294
295 WCHAR wpath[MAX_PATH];
296
297 MultiByteToWideChar(CP_ACP, 0, path, -1, wpath, MAX_PATH);
298
299 panel.first = NULL;
300 applet = Control_LoadApplet(0, wpath, &panel);
301
302 if (applet)
303 {
304 for(i=0; i<applet->count; ++i)
305 {
306 WideCharToMultiByte(CP_ACP, 0, applet->info[i].szName, -1, displayName, MAX_PATH, 0, 0);
307 WideCharToMultiByte(CP_ACP, 0, applet->info[i].szInfo, -1, comment, MAX_PATH, 0, 0);
308
309 applet->proc(0, CPL_INQUIRE, i, (LPARAM)&info);
310
311 if (info.idIcon > 0)
312 iconIdx = -info.idIcon; /* negative icon index instead of icon number */
313 else
314 iconIdx = 0;
315
316 pidl = _ILCreateCPanelApplet(path, displayName, comment, iconIdx);
317
318 if (pidl)
319 AddToEnumList(list, pidl);
320 }
321 Control_UnloadApplet(applet);
322 }
323 return TRUE;
324 }
325
326 static int SHELL_RegisterRegistryCPanelApps(IEnumIDList* list, HKEY hkey_root, LPCSTR szRepPath)
327 {
328 char name[MAX_PATH];
329 char value[MAX_PATH];
330 HKEY hkey;
331
332 int cnt = 0;
333
334 if (RegOpenKeyA(hkey_root, szRepPath, &hkey) == ERROR_SUCCESS)
335 {
336 int idx = 0;
337
338 for(;; ++idx)
339 {
340 DWORD nameLen = MAX_PATH;
341 DWORD valueLen = MAX_PATH;
342
343 if (RegEnumValueA(hkey, idx, name, &nameLen, NULL, NULL, (LPBYTE)&value, &valueLen) != ERROR_SUCCESS)
344 break;
345
346 if (SHELL_RegisterCPanelApp(list, value))
347 ++cnt;
348 }
349 RegCloseKey(hkey);
350 }
351
352 return cnt;
353 }
354
355 static int SHELL_RegisterCPanelFolders(IEnumIDList* list, HKEY hkey_root, LPCSTR szRepPath)
356 {
357 char name[MAX_PATH];
358 HKEY hkey;
359
360 int cnt = 0;
361
362 if (RegOpenKeyA(hkey_root, szRepPath, &hkey) == ERROR_SUCCESS)
363 {
364 int idx = 0;
365 for(;; ++idx)
366 {
367 if (RegEnumKeyA(hkey, idx, name, MAX_PATH) != ERROR_SUCCESS)
368 break;
369
370 if (*name == '{')
371 {
372 LPITEMIDLIST pidl = _ILCreateGuidFromStrA(name);
373
374 if (pidl && AddToEnumList(list, pidl))
375 ++cnt;
376 }
377 }
378
379 RegCloseKey(hkey);
380 }
381
382 return cnt;
383 }
384
385 /**************************************************************************
386 * CreateCPanelEnumList()
387 */
388 static BOOL CreateCPanelEnumList(
389 IEnumIDList * iface,
390 DWORD dwFlags)
391 {
392 CHAR szPath[MAX_PATH];
393 WIN32_FIND_DATAA wfd;
394 HANDLE hFile;
395
396 TRACE("(%p)->(flags=0x%08x)\n", iface, dwFlags);
397
398 /* enumerate control panel folders */
399 if (dwFlags & SHCONTF_FOLDERS)
400 SHELL_RegisterCPanelFolders(iface, HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ControlPanel\\NameSpace");
401
402 /* enumerate the control panel applets */
403 if (dwFlags & SHCONTF_NONFOLDERS)
404 {
405 LPSTR p;
406
407 GetSystemDirectoryA(szPath, MAX_PATH);
408 p = PathAddBackslashA(szPath);
409 strcpy(p, "*.cpl");
410
411 TRACE("-- (%p)-> enumerate SHCONTF_NONFOLDERS of %s\n",iface,debugstr_a(szPath));
412 hFile = FindFirstFileA(szPath, &wfd);
413
414 if (hFile != INVALID_HANDLE_VALUE)
415 {
416 do
417 {
418 if (!(dwFlags & SHCONTF_INCLUDEHIDDEN) && (wfd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN))
419 continue;
420
421 if (!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
422 strcpy(p, wfd.cFileName);
423 if (strcmp(wfd.cFileName, "ncpa.cpl"))
424 SHELL_RegisterCPanelApp((IEnumIDList*)iface, szPath);
425 }
426 } while(FindNextFileA(hFile, &wfd));
427 FindClose(hFile);
428 }
429
430 SHELL_RegisterRegistryCPanelApps((IEnumIDList*)iface, HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Control Panel\\Cpls");
431 SHELL_RegisterRegistryCPanelApps((IEnumIDList*)iface, HKEY_CURRENT_USER, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Control Panel\\Cpls");
432 }
433 return TRUE;
434 }
435
436 /**************************************************************************
437 * ISF_ControlPanel_fnEnumObjects
438 */
439 static HRESULT WINAPI
440 ISF_ControlPanel_fnEnumObjects(IShellFolder2 * iface, HWND hwndOwner, DWORD dwFlags, LPENUMIDLIST * ppEnumIDList)
441 {
442 ICPanelImpl *This = (ICPanelImpl *)iface;
443
444 TRACE("(%p)->(HWND=%p flags=0x%08x pplist=%p)\n", This, hwndOwner, dwFlags, ppEnumIDList);
445
446 *ppEnumIDList = IEnumIDList_Constructor();
447 if (*ppEnumIDList)
448 CreateCPanelEnumList(*ppEnumIDList, dwFlags);
449
450 TRACE("--(%p)->(new ID List: %p)\n", This, *ppEnumIDList);
451
452 return(*ppEnumIDList) ? S_OK : E_OUTOFMEMORY;
453 }
454
455 /**************************************************************************
456 * ISF_ControlPanel_fnBindToObject
457 */
458 static HRESULT WINAPI
459 ISF_ControlPanel_fnBindToObject(IShellFolder2 * iface, LPCITEMIDLIST pidl,
460 LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
461 {
462 ICPanelImpl *This = (ICPanelImpl *)iface;
463
464 TRACE("(%p)->(pidl=%p,%p,%s,%p)\n", This, pidl, pbcReserved, shdebugstr_guid(riid), ppvOut);
465
466 return SHELL32_BindToChild(This->pidlRoot, NULL, pidl, riid, ppvOut);
467 }
468
469 /**************************************************************************
470 * ISF_ControlPanel_fnBindToStorage
471 */
472 static HRESULT WINAPI
473 ISF_ControlPanel_fnBindToStorage(IShellFolder2 * iface,
474 LPCITEMIDLIST pidl, LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
475 {
476 ICPanelImpl *This = (ICPanelImpl *)iface;
477
478 FIXME("(%p)->(pidl=%p,%p,%s,%p) stub\n", This, pidl, pbcReserved, shdebugstr_guid(riid), ppvOut);
479
480 *ppvOut = NULL;
481 return E_NOTIMPL;
482 }
483
484 /**************************************************************************
485 * ISF_ControlPanel_fnCompareIDs
486 */
487
488 static HRESULT WINAPI
489 ISF_ControlPanel_fnCompareIDs(IShellFolder2 * iface, LPARAM lParam, LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
490 {
491 ICPanelImpl *This = (ICPanelImpl *)iface;
492
493 int nReturn;
494
495 TRACE("(%p)->(0x%08lx,pidl1=%p,pidl2=%p)\n", This, lParam, pidl1, pidl2);
496 nReturn = SHELL32_CompareIDs(_IShellFolder_(This), lParam, pidl1, pidl2);
497 TRACE("-- %i\n", nReturn);
498 return nReturn;
499 }
500
501 /**************************************************************************
502 * ISF_ControlPanel_fnCreateViewObject
503 */
504 static HRESULT WINAPI
505 ISF_ControlPanel_fnCreateViewObject(IShellFolder2 * iface, HWND hwndOwner, REFIID riid, LPVOID * ppvOut)
506 {
507 ICPanelImpl *This = (ICPanelImpl *)iface;
508
509 LPSHELLVIEW pShellView;
510 HRESULT hr = E_INVALIDARG;
511
512 TRACE("(%p)->(hwnd=%p,%s,%p)\n", This, hwndOwner, shdebugstr_guid(riid), ppvOut);
513
514 if (ppvOut) {
515 *ppvOut = NULL;
516
517 if (IsEqualIID(riid, &IID_IDropTarget)) {
518 WARN("IDropTarget not implemented\n");
519 hr = E_NOTIMPL;
520 } else if (IsEqualIID(riid, &IID_IContextMenu)) {
521 WARN("IContextMenu not implemented\n");
522 hr = E_NOTIMPL;
523 } else if (IsEqualIID(riid, &IID_IShellView)) {
524 pShellView = IShellView_Constructor((IShellFolder *) iface);
525 if (pShellView) {
526 hr = IShellView_QueryInterface(pShellView, riid, ppvOut);
527 IShellView_Release(pShellView);
528 }
529 }
530 }
531 TRACE("--(%p)->(interface=%p)\n", This, ppvOut);
532 return hr;
533 }
534
535 /**************************************************************************
536 * ISF_ControlPanel_fnGetAttributesOf
537 */
538 static HRESULT WINAPI
539 ISF_ControlPanel_fnGetAttributesOf(IShellFolder2 * iface, UINT cidl, LPCITEMIDLIST * apidl, DWORD * rgfInOut)
540 {
541 ICPanelImpl *This = (ICPanelImpl *)iface;
542
543 HRESULT hr = S_OK;
544
545 TRACE("(%p)->(cidl=%d apidl=%p mask=%p (0x%08x))\n",
546 This, cidl, apidl, rgfInOut, rgfInOut ? *rgfInOut : 0);
547
548 if (!rgfInOut)
549 return E_INVALIDARG;
550 if (cidl && !apidl)
551 return E_INVALIDARG;
552
553 if (*rgfInOut == 0)
554 *rgfInOut = ~0;
555
556 while(cidl > 0 && *apidl) {
557 pdump(*apidl);
558 SHELL32_GetItemAttributes(_IShellFolder_(This), *apidl, rgfInOut);
559 apidl++;
560 cidl--;
561 }
562 /* make sure SFGAO_VALIDATE is cleared, some apps depend on that */
563 *rgfInOut &= ~SFGAO_VALIDATE;
564
565 TRACE("-- result=0x%08x\n", *rgfInOut);
566 return hr;
567 }
568
569 /**************************************************************************
570 * ISF_ControlPanel_fnGetUIObjectOf
571 *
572 * PARAMETERS
573 * HWND hwndOwner, //[in ] Parent window for any output
574 * UINT cidl, //[in ] array size
575 * LPCITEMIDLIST* apidl, //[in ] simple pidl array
576 * REFIID riid, //[in ] Requested Interface
577 * UINT* prgfInOut, //[ ] reserved
578 * LPVOID* ppvObject) //[out] Resulting Interface
579 *
580 */
581 static HRESULT WINAPI
582 ISF_ControlPanel_fnGetUIObjectOf(IShellFolder2 * iface,
583 HWND hwndOwner,
584 UINT cidl, LPCITEMIDLIST * apidl, REFIID riid, UINT * prgfInOut, LPVOID * ppvOut)
585 {
586 ICPanelImpl *This = (ICPanelImpl *)iface;
587
588 LPITEMIDLIST pidl;
589 IUnknown *pObj = NULL;
590 HRESULT hr = E_INVALIDARG;
591
592 TRACE("(%p)->(%p,%u,apidl=%p,%s,%p,%p)\n",
593 This, hwndOwner, cidl, apidl, shdebugstr_guid(riid), prgfInOut, ppvOut);
594
595 if (ppvOut) {
596 *ppvOut = NULL;
597
598 if (IsEqualIID(riid, &IID_IContextMenu) &&(cidl >= 1)) {
599 // TODO
600 // create a seperate item struct
601 //
602 pObj = (IUnknown*)(&This->lpVtblContextMenu);
603 This->apidl = apidl;
604 This->cidl = cidl;
605 IUnknown_AddRef(pObj);
606 hr = S_OK;
607 } else if (IsEqualIID(riid, &IID_IDataObject) &&(cidl >= 1)) {
608 pObj = (LPUNKNOWN) IDataObject_Constructor(hwndOwner, This->pidlRoot, apidl, cidl);
609 hr = S_OK;
610 } else if (IsEqualIID(riid, &IID_IExtractIconA) &&(cidl == 1)) {
611 pidl = ILCombine(This->pidlRoot, apidl[0]);
612 pObj = (LPUNKNOWN) IExtractIconA_Constructor(pidl);
613 SHFree(pidl);
614 hr = S_OK;
615 } else if (IsEqualIID(riid, &IID_IExtractIconW) &&(cidl == 1)) {
616 pidl = ILCombine(This->pidlRoot, apidl[0]);
617 pObj = (LPUNKNOWN) IExtractIconW_Constructor(pidl);
618 SHFree(pidl);
619 hr = S_OK;
620 } else if ((IsEqualIID(riid,&IID_IShellLinkW) || IsEqualIID(riid,&IID_IShellLinkA))
621 && (cidl == 1)) {
622 pidl = ILCombine(This->pidlRoot, apidl[0]);
623 hr = IShellLink_ConstructFromFile(NULL, riid, pidl,(LPVOID*)&pObj);
624 SHFree(pidl);
625 } else {
626 hr = E_NOINTERFACE;
627 }
628
629 if (SUCCEEDED(hr) && !pObj)
630 hr = E_OUTOFMEMORY;
631
632 *ppvOut = pObj;
633 }
634 TRACE("(%p)->hr=0x%08x\n", This, hr);
635 return hr;
636 }
637
638 /**************************************************************************
639 * ISF_ControlPanel_fnGetDisplayNameOf
640 */
641 static HRESULT WINAPI ISF_ControlPanel_fnGetDisplayNameOf(IShellFolder2 * iface, LPCITEMIDLIST pidl, DWORD dwFlags, LPSTRRET strRet)
642 {
643 ICPanelImpl *This = (ICPanelImpl *)iface;
644
645 CHAR szPath[MAX_PATH];
646 WCHAR wszPath[MAX_PATH+1]; /* +1 for potential backslash */
647 PIDLCPanelStruct* pcpanel;
648
649 *szPath = '\0';
650
651 TRACE("(%p)->(pidl=%p,0x%08x,%p)\n", This, pidl, dwFlags, strRet);
652 pdump(pidl);
653
654 if (!pidl || !strRet)
655 return E_INVALIDARG;
656
657 pcpanel = _ILGetCPanelPointer(pidl);
658
659 if (pcpanel) {
660 lstrcpyA(szPath, pcpanel->szName+pcpanel->offsDispName);
661
662 if (!(dwFlags & SHGDN_FORPARSING))
663 FIXME("retrieve display name from control panel app\n");
664 }
665 /* take names of special folders only if it's only this folder */
666 else if (_ILIsSpecialFolder(pidl)) {
667 BOOL bSimplePidl = _ILIsPidlSimple(pidl);
668
669 if (bSimplePidl) {
670 _ILSimpleGetTextW(pidl, wszPath, MAX_PATH); /* append my own path */
671 } else {
672 FIXME("special pidl\n");
673 }
674
675 if ((dwFlags & SHGDN_FORPARSING) && !bSimplePidl) { /* go deeper if needed */
676 int len = 0;
677
678 PathAddBackslashW(wszPath);
679 len = wcslen(wszPath);
680
681 if (!SUCCEEDED
682 (SHELL32_GetDisplayNameOfChild(iface, pidl, dwFlags, wszPath + len, MAX_PATH + 1 - len)))
683 return E_OUTOFMEMORY;
684 if (!WideCharToMultiByte(CP_ACP, 0, wszPath, -1, szPath, MAX_PATH, NULL, NULL))
685 wszPath[0] = '\0';
686 } else {
687 if (bSimplePidl) {
688 if (!WideCharToMultiByte(CP_ACP, 0, wszPath, -1, szPath, MAX_PATH, NULL, NULL))
689 wszPath[0] = '\0';
690 }
691 }
692 }
693
694 strRet->uType = STRRET_CSTR;
695 lstrcpynA(strRet->u.cStr, szPath, MAX_PATH);
696
697 TRACE("--(%p)->(%s)\n", This, szPath);
698 return S_OK;
699 }
700
701 /**************************************************************************
702 * ISF_ControlPanel_fnSetNameOf
703 * Changes the name of a file object or subfolder, possibly changing its item
704 * identifier in the process.
705 *
706 * PARAMETERS
707 * HWND hwndOwner, //[in ] Owner window for output
708 * LPCITEMIDLIST pidl, //[in ] simple pidl of item to change
709 * LPCOLESTR lpszName, //[in ] the items new display name
710 * DWORD dwFlags, //[in ] SHGNO formatting flags
711 * LPITEMIDLIST* ppidlOut) //[out] simple pidl returned
712 */
713 static HRESULT WINAPI ISF_ControlPanel_fnSetNameOf(IShellFolder2 * iface, HWND hwndOwner, LPCITEMIDLIST pidl, /*simple pidl */
714 LPCOLESTR lpName, DWORD dwFlags, LPITEMIDLIST * pPidlOut)
715 {
716 ICPanelImpl *This = (ICPanelImpl *)iface;
717 FIXME("(%p)->(%p,pidl=%p,%s,%u,%p)\n", This, hwndOwner, pidl, debugstr_w(lpName), dwFlags, pPidlOut);
718 return E_FAIL;
719 }
720
721 static HRESULT WINAPI ISF_ControlPanel_fnGetDefaultSearchGUID(IShellFolder2 * iface, GUID * pguid)
722 {
723 ICPanelImpl *This = (ICPanelImpl *)iface;
724 FIXME("(%p)\n", This);
725 return E_NOTIMPL;
726 }
727 static HRESULT WINAPI ISF_ControlPanel_fnEnumSearches(IShellFolder2 * iface, IEnumExtraSearch ** ppenum)
728 {
729 ICPanelImpl *This = (ICPanelImpl *)iface;
730 FIXME("(%p)\n", This);
731 return E_NOTIMPL;
732 }
733 static HRESULT WINAPI ISF_ControlPanel_fnGetDefaultColumn(IShellFolder2 * iface, DWORD dwRes, ULONG * pSort, ULONG * pDisplay)
734 {
735 ICPanelImpl *This = (ICPanelImpl *)iface;
736
737 TRACE("(%p)\n", This);
738
739 if (pSort) *pSort = 0;
740 if (pDisplay) *pDisplay = 0;
741 return S_OK;
742 }
743 static HRESULT WINAPI ISF_ControlPanel_fnGetDefaultColumnState(IShellFolder2 * iface, UINT iColumn, DWORD * pcsFlags)
744 {
745 ICPanelImpl *This = (ICPanelImpl *)iface;
746
747 TRACE("(%p)\n", This);
748
749 if (!pcsFlags || iColumn >= CONROLPANELSHELLVIEWCOLUMNS) return E_INVALIDARG;
750 *pcsFlags = ControlPanelSFHeader[iColumn].pcsFlags;
751 return S_OK;
752 }
753 static HRESULT WINAPI ISF_ControlPanel_fnGetDetailsEx(IShellFolder2 * iface, LPCITEMIDLIST pidl, const SHCOLUMNID * pscid, VARIANT * pv)
754 {
755 ICPanelImpl *This = (ICPanelImpl *)iface;
756 FIXME("(%p)\n", This);
757 return E_NOTIMPL;
758 }
759
760 static HRESULT WINAPI ISF_ControlPanel_fnGetDetailsOf(IShellFolder2 * iface, LPCITEMIDLIST pidl, UINT iColumn, SHELLDETAILS * psd)
761 {
762 ICPanelImpl *This = (ICPanelImpl *)iface;
763 HRESULT hr;
764
765 TRACE("(%p)->(%p %i %p)\n", This, pidl, iColumn, psd);
766
767 if (!psd || iColumn >= CONROLPANELSHELLVIEWCOLUMNS)
768 return E_INVALIDARG;
769
770 if (!pidl) {
771 psd->fmt = ControlPanelSFHeader[iColumn].fmt;
772 psd->cxChar = ControlPanelSFHeader[iColumn].cxChar;
773 psd->str.uType = STRRET_CSTR;
774 LoadStringA(shell32_hInstance, ControlPanelSFHeader[iColumn].colnameid, psd->str.u.cStr, MAX_PATH);
775 return S_OK;
776 } else {
777 psd->str.u.cStr[0] = 0x00;
778 psd->str.uType = STRRET_CSTR;
779 switch(iColumn) {
780 case 0: /* name */
781 hr = IShellFolder_GetDisplayNameOf(iface, pidl, SHGDN_NORMAL | SHGDN_INFOLDER, &psd->str);
782 break;
783 case 1: /* comment */
784 _ILGetFileType(pidl, psd->str.u.cStr, MAX_PATH);
785 break;
786 }
787 hr = S_OK;
788 }
789
790 return hr;
791 }
792 static HRESULT WINAPI ISF_ControlPanel_fnMapColumnToSCID(IShellFolder2 * iface, UINT column, SHCOLUMNID * pscid)
793 {
794 ICPanelImpl *This = (ICPanelImpl *)iface;
795 FIXME("(%p)\n", This);
796 return E_NOTIMPL;
797 }
798
799 static const IShellFolder2Vtbl vt_ShellFolder2 =
800 {
801
802 ISF_ControlPanel_fnQueryInterface,
803 ISF_ControlPanel_fnAddRef,
804 ISF_ControlPanel_fnRelease,
805 ISF_ControlPanel_fnParseDisplayName,
806 ISF_ControlPanel_fnEnumObjects,
807 ISF_ControlPanel_fnBindToObject,
808 ISF_ControlPanel_fnBindToStorage,
809 ISF_ControlPanel_fnCompareIDs,
810 ISF_ControlPanel_fnCreateViewObject,
811 ISF_ControlPanel_fnGetAttributesOf,
812 ISF_ControlPanel_fnGetUIObjectOf,
813 ISF_ControlPanel_fnGetDisplayNameOf,
814 ISF_ControlPanel_fnSetNameOf,
815
816 /* ShellFolder2 */
817 ISF_ControlPanel_fnGetDefaultSearchGUID,
818 ISF_ControlPanel_fnEnumSearches,
819 ISF_ControlPanel_fnGetDefaultColumn,
820 ISF_ControlPanel_fnGetDefaultColumnState,
821 ISF_ControlPanel_fnGetDetailsEx,
822 ISF_ControlPanel_fnGetDetailsOf,
823 ISF_ControlPanel_fnMapColumnToSCID
824 };
825
826 /************************************************************************
827 * ICPanel_PersistFolder2_QueryInterface
828 */
829 static HRESULT WINAPI ICPanel_PersistFolder2_QueryInterface(IPersistFolder2 * iface, REFIID iid, LPVOID * ppvObject)
830 {
831 ICPanelImpl *This = impl_from_IPersistFolder2(iface);
832
833 TRACE("(%p)\n", This);
834
835 return IUnknown_QueryInterface(_IUnknown_(This), iid, ppvObject);
836 }
837
838 /************************************************************************
839 * ICPanel_PersistFolder2_AddRef
840 */
841 static ULONG WINAPI ICPanel_PersistFolder2_AddRef(IPersistFolder2 * iface)
842 {
843 ICPanelImpl *This = impl_from_IPersistFolder2(iface);
844
845 TRACE("(%p)->(count=%u)\n", This, This->ref);
846
847 return IUnknown_AddRef(_IUnknown_(This));
848 }
849
850 /************************************************************************
851 * ISFPersistFolder_Release
852 */
853 static ULONG WINAPI ICPanel_PersistFolder2_Release(IPersistFolder2 * iface)
854 {
855 ICPanelImpl *This = impl_from_IPersistFolder2(iface);
856
857 TRACE("(%p)->(count=%u)\n", This, This->ref);
858
859 return IUnknown_Release(_IUnknown_(This));
860 }
861
862 /************************************************************************
863 * ICPanel_PersistFolder2_GetClassID
864 */
865 static HRESULT WINAPI ICPanel_PersistFolder2_GetClassID(IPersistFolder2 * iface, CLSID * lpClassId)
866 {
867 ICPanelImpl *This = impl_from_IPersistFolder2(iface);
868
869 TRACE("(%p)\n", This);
870
871 if (!lpClassId)
872 return E_POINTER;
873 *lpClassId = CLSID_ControlPanel;
874
875 return S_OK;
876 }
877
878 /************************************************************************
879 * ICPanel_PersistFolder2_Initialize
880 *
881 * NOTES: it makes no sense to change the pidl
882 */
883 static HRESULT WINAPI ICPanel_PersistFolder2_Initialize(IPersistFolder2 * iface, LPCITEMIDLIST pidl)
884 {
885 ICPanelImpl *This = impl_from_IPersistFolder2(iface);
886 if (This->pidlRoot)
887 SHFree((LPVOID)This->pidlRoot);
888
889 This->pidlRoot = ILClone(pidl);
890 return S_OK;
891 }
892
893 /**************************************************************************
894 * IPersistFolder2_fnGetCurFolder
895 */
896 static HRESULT WINAPI ICPanel_PersistFolder2_GetCurFolder(IPersistFolder2 * iface, LPITEMIDLIST * pidl)
897 {
898 ICPanelImpl *This = impl_from_IPersistFolder2(iface);
899
900 TRACE("(%p)->(%p)\n", This, pidl);
901
902 if (!pidl)
903 return E_POINTER;
904 *pidl = ILClone(This->pidlRoot);
905 return S_OK;
906 }
907
908 static const IPersistFolder2Vtbl vt_PersistFolder2 =
909 {
910
911 ICPanel_PersistFolder2_QueryInterface,
912 ICPanel_PersistFolder2_AddRef,
913 ICPanel_PersistFolder2_Release,
914 ICPanel_PersistFolder2_GetClassID,
915 ICPanel_PersistFolder2_Initialize,
916 ICPanel_PersistFolder2_GetCurFolder
917 };
918
919 HRESULT CPanel_GetIconLocationW(LPCITEMIDLIST pidl,
920 LPWSTR szIconFile, UINT cchMax, int* piIndex)
921 {
922 PIDLCPanelStruct* pcpanel = _ILGetCPanelPointer(pidl);
923
924 if (!pcpanel)
925 return E_INVALIDARG;
926
927 MultiByteToWideChar(CP_ACP, 0, pcpanel->szName, -1, szIconFile, cchMax);
928 *piIndex = pcpanel->iconIdx!=-1? pcpanel->iconIdx: 0;
929
930 return S_OK;
931 }
932
933
934 /**************************************************************************
935 * IShellExecuteHookW Implementation
936 */
937
938 static HRESULT WINAPI IShellExecuteHookW_fnQueryInterface(
939 IShellExecuteHookW* iface, REFIID riid, void** ppvObject)
940 {
941 ICPanelImpl *This = impl_from_IShellExecuteHookW(iface);
942
943 TRACE("(%p)->(count=%u)\n", This, This->ref);
944
945 return IUnknown_QueryInterface(This->pUnkOuter, riid, ppvObject);
946 }
947
948 static ULONG STDMETHODCALLTYPE IShellExecuteHookW_fnAddRef(IShellExecuteHookW* iface)
949 {
950 ICPanelImpl *This = impl_from_IShellExecuteHookW(iface);
951
952 TRACE("(%p)->(count=%u)\n", This, This->ref);
953
954 return IUnknown_AddRef(This->pUnkOuter);
955 }
956
957 static ULONG STDMETHODCALLTYPE IShellExecuteHookW_fnRelease(IShellExecuteHookW* iface)
958 {
959 ICPanelImpl *This = impl_from_IShellExecuteHookW(iface);
960
961 TRACE("(%p)\n", This);
962
963 return IUnknown_Release(This->pUnkOuter);
964 }
965
966 HRESULT
967 ExecuteAppletFromCLSID(LPOLESTR pOleStr)
968 {
969 WCHAR szCmd[MAX_PATH];
970 WCHAR szExpCmd[MAX_PATH];
971 PROCESS_INFORMATION pi;
972 STARTUPINFOW si;
973 WCHAR szBuffer[90] = { 'C', 'L', 'S', 'I', 'D', '\\', 0 };
974 DWORD dwType, dwSize;
975
976 wcscpy(&szBuffer[6], pOleStr);
977 wcscat(szBuffer, L"\\shell\\open\\command");
978
979 dwSize = sizeof(szCmd);
980 if (RegGetValueW(HKEY_CLASSES_ROOT, szBuffer, NULL, RRF_RT_REG_SZ, &dwType, (PVOID)szCmd, &dwSize) != ERROR_SUCCESS)
981 {
982 ERR("RegGetValueW failed with %u\n", GetLastError());
983 return E_FAIL;
984 }
985
986 #if 0
987 if (dwType != RRF_RT_REG_SZ && dwType != RRF_RT_REG_EXPAND_SZ)
988 return E_FAIL;
989 #endif
990
991 if (!ExpandEnvironmentStringsW(szCmd, szExpCmd, sizeof(szExpCmd)/sizeof(WCHAR)))
992 return E_FAIL;
993
994 ZeroMemory(&si, sizeof(si));
995 si.cb = sizeof(si);
996 if (!CreateProcessW(NULL, szExpCmd, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
997 return E_FAIL;
998
999 CloseHandle(pi.hProcess);
1000 CloseHandle(pi.hThread);
1001 return S_OK;
1002 }
1003
1004
1005 static HRESULT WINAPI IShellExecuteHookW_fnExecute(IShellExecuteHookW* iface, LPSHELLEXECUTEINFOW psei)
1006 {
1007 static const WCHAR wCplopen[] = {'c','p','l','o','p','e','n','\0'};
1008 ICPanelImpl *This = (ICPanelImpl *)iface;
1009
1010 SHELLEXECUTEINFOW sei_tmp;
1011 PIDLCPanelStruct* pcpanel;
1012 WCHAR path[MAX_PATH];
1013 WCHAR params[MAX_PATH];
1014 BOOL ret;
1015 HRESULT hr;
1016 int l;
1017
1018 TRACE("(%p)->execute(%p)\n", This, psei);
1019
1020 if (!psei)
1021 return E_INVALIDARG;
1022
1023 pcpanel = _ILGetCPanelPointer(ILFindLastID(psei->lpIDList));
1024
1025 if (!pcpanel)
1026 {
1027 LPOLESTR pOleStr;
1028
1029 IID * iid = _ILGetGUIDPointer(ILFindLastID(psei->lpIDList));
1030 if (!iid)
1031 return E_INVALIDARG;
1032 if (StringFromCLSID(iid, &pOleStr) == S_OK)
1033 {
1034
1035 hr = ExecuteAppletFromCLSID(pOleStr);
1036 CoTaskMemFree(pOleStr);
1037 return hr;
1038 }
1039
1040 return E_INVALIDARG;
1041 }
1042 path[0] = '\"';
1043 /* Return value from MultiByteToWideChar includes terminating NUL, which
1044 * compensates for the starting double quote we just put in */
1045 l = MultiByteToWideChar(CP_ACP, 0, pcpanel->szName, -1, path+1, MAX_PATH);
1046
1047 /* pass applet name to Control_RunDLL to distinguish between applets in one .cpl file */
1048 path[l++] = '"';
1049 path[l] = '\0';
1050
1051 MultiByteToWideChar(CP_ACP, 0, pcpanel->szName+pcpanel->offsDispName, -1, params, MAX_PATH);
1052
1053 memcpy(&sei_tmp, psei, sizeof(sei_tmp));
1054 sei_tmp.lpFile = path;
1055 sei_tmp.lpParameters = params;
1056 sei_tmp.fMask &= ~SEE_MASK_INVOKEIDLIST;
1057 sei_tmp.lpVerb = wCplopen;
1058
1059 ret = ShellExecuteExW(&sei_tmp);
1060 if (ret)
1061 return S_OK;
1062 else
1063 return S_FALSE;
1064 }
1065
1066 static const IShellExecuteHookWVtbl vt_ShellExecuteHookW =
1067 {
1068
1069 IShellExecuteHookW_fnQueryInterface,
1070 IShellExecuteHookW_fnAddRef,
1071 IShellExecuteHookW_fnRelease,
1072
1073 IShellExecuteHookW_fnExecute
1074 };
1075
1076
1077 /**************************************************************************
1078 * IShellExecuteHookA Implementation
1079 */
1080
1081 static HRESULT WINAPI IShellExecuteHookA_fnQueryInterface(IShellExecuteHookA* iface, REFIID riid, void** ppvObject)
1082 {
1083 ICPanelImpl *This = impl_from_IShellExecuteHookA(iface);
1084
1085 TRACE("(%p)->(count=%u)\n", This, This->ref);
1086
1087 return IUnknown_QueryInterface(This->pUnkOuter, riid, ppvObject);
1088 }
1089
1090 static ULONG STDMETHODCALLTYPE IShellExecuteHookA_fnAddRef(IShellExecuteHookA* iface)
1091 {
1092 ICPanelImpl *This = impl_from_IShellExecuteHookA(iface);
1093
1094 TRACE("(%p)->(count=%u)\n", This, This->ref);
1095
1096 return IUnknown_AddRef(This->pUnkOuter);
1097 }
1098
1099 static ULONG STDMETHODCALLTYPE IShellExecuteHookA_fnRelease(IShellExecuteHookA* iface)
1100 {
1101 ICPanelImpl *This = impl_from_IShellExecuteHookA(iface);
1102
1103 TRACE("(%p)\n", This);
1104
1105 return IUnknown_Release(This->pUnkOuter);
1106 }
1107
1108 static HRESULT WINAPI IShellExecuteHookA_fnExecute(IShellExecuteHookA* iface, LPSHELLEXECUTEINFOA psei)
1109 {
1110 ICPanelImpl *This = (ICPanelImpl *)iface;
1111
1112 SHELLEXECUTEINFOA sei_tmp;
1113 PIDLCPanelStruct* pcpanel;
1114 char path[MAX_PATH];
1115 BOOL ret;
1116
1117 TRACE("(%p)->execute(%p)\n", This, psei);
1118
1119 if (!psei)
1120 return E_INVALIDARG;
1121
1122 pcpanel = _ILGetCPanelPointer(ILFindLastID(psei->lpIDList));
1123
1124 if (!pcpanel)
1125 return E_INVALIDARG;
1126
1127 path[0] = '\"';
1128 lstrcpyA(path+1, pcpanel->szName);
1129
1130 /* pass applet name to Control_RunDLL to distinguish between applets in one .cpl file */
1131 lstrcatA(path, "\" ");
1132 lstrcatA(path, pcpanel->szName+pcpanel->offsDispName);
1133
1134 memcpy(&sei_tmp, psei, sizeof(sei_tmp));
1135 sei_tmp.lpFile = path;
1136 sei_tmp.fMask &= ~SEE_MASK_INVOKEIDLIST;
1137
1138 ret = ShellExecuteExA(&sei_tmp);
1139 if (ret)
1140 return S_OK;
1141 else
1142 return S_FALSE;
1143 }
1144
1145 static const IShellExecuteHookAVtbl vt_ShellExecuteHookA =
1146 {
1147 IShellExecuteHookA_fnQueryInterface,
1148 IShellExecuteHookA_fnAddRef,
1149 IShellExecuteHookA_fnRelease,
1150 IShellExecuteHookA_fnExecute
1151 };
1152
1153 /**************************************************************************
1154 * IContextMenu2 Implementation
1155 */
1156
1157 /************************************************************************
1158 * ICPanel_IContextMenu_QueryInterface
1159 */
1160 static HRESULT WINAPI ICPanel_IContextMenu2_QueryInterface(IContextMenu2 * iface, REFIID iid, LPVOID * ppvObject)
1161 {
1162 ICPanelImpl *This = impl_from_IContextMenu(iface);
1163
1164 TRACE("(%p)\n", This);
1165
1166 return IUnknown_QueryInterface(_IUnknown_(This), iid, ppvObject);
1167 }
1168
1169 /************************************************************************
1170 * ICPanel_IContextMenu_AddRef
1171 */
1172 static ULONG WINAPI ICPanel_IContextMenu2_AddRef(IContextMenu2 * iface)
1173 {
1174 ICPanelImpl *This = impl_from_IContextMenu(iface);
1175
1176 TRACE("(%p)->(count=%u)\n", This, This->ref);
1177
1178 return IUnknown_AddRef(_IUnknown_(This));
1179 }
1180
1181 /************************************************************************
1182 * ICPanel_IContextMenu_Release
1183 */
1184 static ULONG WINAPI ICPanel_IContextMenu2_Release(IContextMenu2 * iface)
1185 {
1186 ICPanelImpl *This = impl_from_IContextMenu(iface);
1187
1188 TRACE("(%p)->(count=%u)\n", This, This->ref);
1189
1190 return IUnknown_Release(_IUnknown_(This));
1191 }
1192
1193 /**************************************************************************
1194 * ICPanel_IContextMenu_QueryContextMenu()
1195 */
1196 static HRESULT WINAPI ICPanel_IContextMenu2_QueryContextMenu(
1197 IContextMenu2 *iface,
1198 HMENU hMenu,
1199 UINT indexMenu,
1200 UINT idCmdFirst,
1201 UINT idCmdLast,
1202 UINT uFlags)
1203 {
1204 WCHAR szBuffer[30] = {0};
1205 ULONG Count = 1;
1206
1207 ICPanelImpl *This = impl_from_IContextMenu(iface);
1208
1209 TRACE("(%p)->(hmenu=%p indexmenu=%x cmdfirst=%x cmdlast=%x flags=%x )\n",
1210 This, hMenu, indexMenu, idCmdFirst, idCmdLast, uFlags);
1211
1212 if (LoadStringW(shell32_hInstance, IDS_OPEN, szBuffer, sizeof(szBuffer)/sizeof(WCHAR)))
1213 {
1214 szBuffer[(sizeof(szBuffer)/sizeof(WCHAR))-1] = L'\0';
1215 _InsertMenuItemW(hMenu, indexMenu++, TRUE, IDS_OPEN, MFT_STRING, szBuffer, MFS_DEFAULT); //FIXME identifier
1216 Count++;
1217 }
1218
1219 if (LoadStringW(shell32_hInstance, IDS_CREATELINK, szBuffer, sizeof(szBuffer)/sizeof(WCHAR)))
1220 {
1221 if (Count)
1222 {
1223 _InsertMenuItemW(hMenu, indexMenu++, TRUE, idCmdFirst + Count, MFT_SEPARATOR, NULL, MFS_ENABLED);
1224 }
1225 szBuffer[(sizeof(szBuffer)/sizeof(WCHAR))-1] = L'\0';
1226
1227 _InsertMenuItemW(hMenu, indexMenu++, TRUE, IDS_CREATELINK, MFT_STRING, szBuffer, MFS_ENABLED); //FIXME identifier
1228 Count++;
1229 }
1230 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, Count);
1231 }
1232
1233
1234 /**************************************************************************
1235 * ICPanel_IContextMenu_InvokeCommand()
1236 */
1237 static HRESULT WINAPI ICPanel_IContextMenu2_InvokeCommand(
1238 IContextMenu2 *iface,
1239 LPCMINVOKECOMMANDINFO lpcmi)
1240 {
1241 SHELLEXECUTEINFOW sei;
1242 WCHAR szPath[MAX_PATH];
1243 char szTarget[MAX_PATH];
1244 STRRET strret;
1245 WCHAR* pszPath;
1246 INT Length, cLength;
1247 PIDLCPanelStruct *pcpanel;
1248 IPersistFile * ppf;
1249 IShellLinkA * isl;
1250 ICPanelImpl *This = impl_from_IContextMenu(iface);
1251
1252 TRACE("(%p)->(invcom=%p verb=%p wnd=%p)\n",This,lpcmi,lpcmi->lpVerb, lpcmi->hwnd);
1253
1254 if (lpcmi->lpVerb == MAKEINTRESOURCEA(IDS_OPEN)) //FIXME
1255 {
1256 ZeroMemory(&sei, sizeof(sei));
1257 sei.cbSize = sizeof(sei);
1258 sei.fMask = SEE_MASK_INVOKEIDLIST;
1259 sei.lpIDList = ILCombine(This->pidlRoot, This->apidl[0]);
1260 sei.hwnd = lpcmi->hwnd;
1261 sei.nShow = SW_SHOWNORMAL;
1262 sei.lpVerb = L"open";
1263 ShellExecuteExW(&sei);
1264 if (sei.hInstApp <= (HINSTANCE)32)
1265 return E_FAIL;
1266 }
1267 else if (lpcmi->lpVerb == MAKEINTRESOURCEA(IDS_CREATELINK)) //FIXME
1268 {
1269 if (!SHGetSpecialFolderPathW(NULL, szPath, CSIDL_DESKTOPDIRECTORY, FALSE))
1270 return E_FAIL;
1271
1272 pszPath = PathAddBackslashW(szPath);
1273 if (!pszPath)
1274 return E_FAIL;
1275
1276 if (IShellFolder_GetDisplayNameOf((IShellFolder*)This, This->apidl[0], SHGDN_FORPARSING, &strret) != S_OK)
1277 return E_FAIL;
1278
1279 Length = MAX_PATH - (pszPath - szPath);
1280 cLength = strlen(strret.u.cStr);
1281 if (Length < cLength + 5)
1282 {
1283 FIXME("\n");
1284 return E_FAIL;
1285 }
1286
1287 if (MultiByteToWideChar(CP_ACP, 0, strret.u.cStr, cLength +1, pszPath, Length))
1288 {
1289 pszPath += cLength;
1290 Length -= cLength;
1291 }
1292
1293 if (Length > 10)
1294 {
1295 wcscpy(pszPath, L" - ");
1296 cLength = LoadStringW(shell32_hInstance, IDS_LNK_FILE, &pszPath[3], Length -4) + 3;
1297 if (cLength + 5 > Length)
1298 cLength = Length - 5;
1299 Length -= cLength;
1300 pszPath += cLength;
1301 }
1302 wcscpy(pszPath, L".lnk");
1303
1304 pcpanel = _ILGetCPanelPointer(ILFindLastID(This->apidl[0]));
1305 if (pcpanel)
1306 {
1307 strncpy(szTarget, pcpanel->szName, MAX_PATH);
1308 }
1309 else
1310 {
1311 FIXME("\n");
1312 return E_FAIL;
1313 }
1314 if (SUCCEEDED(IShellLink_Constructor(NULL, &IID_IShellLinkA, (LPVOID*)&isl)))
1315 {
1316 IShellLinkA_SetPath(isl, szTarget);
1317 if (SUCCEEDED(IShellLinkA_QueryInterface(isl, &IID_IPersistFile, (LPVOID*)&ppf)))
1318 {
1319 IPersistFile_Save(ppf, szPath, TRUE);
1320 IPersistFile_Release(ppf);
1321 }
1322 IShellLinkA_Release(isl);
1323 }
1324 return NOERROR;
1325 }
1326 return S_OK;
1327 }
1328
1329 /**************************************************************************
1330 * ICPanel_IContextMenu_GetCommandString()
1331 *
1332 */
1333 static HRESULT WINAPI ICPanel_IContextMenu2_GetCommandString(
1334 IContextMenu2 *iface,
1335 UINT_PTR idCommand,
1336 UINT uFlags,
1337 UINT* lpReserved,
1338 LPSTR lpszName,
1339 UINT uMaxNameLen)
1340 {
1341 ICPanelImpl *This = impl_from_IContextMenu(iface);
1342
1343 TRACE("(%p)->(idcom=%lx flags=%x %p name=%p len=%x)\n",This, idCommand, uFlags, lpReserved, lpszName, uMaxNameLen);
1344
1345
1346 FIXME("unknown command string\n");
1347 return E_FAIL;
1348 }
1349
1350
1351
1352 /**************************************************************************
1353 * ICPanel_IContextMenu_HandleMenuMsg()
1354 */
1355 static HRESULT WINAPI ICPanel_IContextMenu2_HandleMenuMsg(
1356 IContextMenu2 *iface,
1357 UINT uMsg,
1358 WPARAM wParam,
1359 LPARAM lParam)
1360 {
1361 ICPanelImpl *This = impl_from_IContextMenu(iface);
1362
1363 TRACE("ICPanel_IContextMenu_HandleMenuMsg (%p)->(msg=%x wp=%lx lp=%lx)\n",This, uMsg, wParam, lParam);
1364
1365 return E_NOTIMPL;
1366 }
1367
1368 static const IContextMenu2Vtbl vt_ContextMenu =
1369 {
1370 ICPanel_IContextMenu2_QueryInterface,
1371 ICPanel_IContextMenu2_AddRef,
1372 ICPanel_IContextMenu2_Release,
1373 ICPanel_IContextMenu2_QueryContextMenu,
1374 ICPanel_IContextMenu2_InvokeCommand,
1375 ICPanel_IContextMenu2_GetCommandString,
1376 ICPanel_IContextMenu2_HandleMenuMsg
1377 };
1378