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