6f55c4c5788f8bbbc3962e77dad69d26687c2c95
[reactos.git] / reactos / lib / shell32 / cpanelfolder.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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 #include "config.h"
22 #include "wine/port.h"
23
24 #include <stdlib.h>
25 #include <string.h>
26 #include <stdarg.h>
27 #include <stdio.h>
28
29 #define COBJMACROS
30 #define NONAMELESSUNION
31 #define NONAMELESSSTRUCT
32
33 #include "winerror.h"
34 #include "windef.h"
35 #include "winbase.h"
36 #include "winreg.h"
37 #include "wingdi.h"
38 #include "winuser.h"
39
40 #include "ole2.h"
41 #include "shlguid.h"
42
43 #include "cpanel.h"
44 #include "enumidlist.h"
45 #include "pidl.h"
46 #include "undocshell.h"
47 #include "shell32_main.h"
48 #include "shresdef.h"
49 #include "shlwapi.h"
50 #include "wine/debug.h"
51 #include "debughlp.h"
52 #include "shfldr.h"
53
54 WINE_DEFAULT_DEBUG_CHANNEL(shell);
55
56 /***********************************************************************
57 * control panel implementation in shell namespace
58 */
59
60 typedef struct {
61 const IShellFolder2Vtbl *lpVtbl;
62 DWORD ref;
63 const IPersistFolder2Vtbl *lpVtblPersistFolder2;
64 const IShellExecuteHookWVtbl *lpVtblShellExecuteHookW;
65 const IShellExecuteHookAVtbl *lpVtblShellExecuteHookA;
66
67 IUnknown *pUnkOuter; /* used for aggregation */
68
69 /* both paths are parsible from the desktop */
70 LPITEMIDLIST pidlRoot; /* absolute pidl */
71 int dwAttributes; /* attributes returned by GetAttributesOf FIXME: use it */
72 } ICPanelImpl;
73
74 static const IShellFolder2Vtbl vt_ShellFolder2;
75 static const IPersistFolder2Vtbl vt_PersistFolder2;
76 static const IShellExecuteHookWVtbl vt_ShellExecuteHookW;
77 static const IShellExecuteHookAVtbl vt_ShellExecuteHookA;
78
79 #define _IPersistFolder2_Offset ((int)(&(((ICPanelImpl*)0)->lpVtblPersistFolder2)))
80 #define _ICOM_THIS_From_IPersistFolder2(class, name) class* This = (class*)(((char*)name)-_IPersistFolder2_Offset);
81
82 #define IShellExecuteHookW_Offset ((int)(&(((ICPanelImpl*)0)->lpVtblShellExecuteHookW)))
83 #define _ICOM_THIS_From_IShellExecuteHookW(class, name) class* This = (class*)(((char*)name)-IShellExecuteHookW_Offset);
84
85 #define IShellExecuteHookA_Offset ((int)(&(((ICPanelImpl*)0)->lpVtblShellExecuteHookA)))
86 #define _ICOM_THIS_From_IShellExecuteHookA(class, name) class* This = (class*)(((char*)name)-IShellExecuteHookA_Offset);
87
88
89 /*
90 converts This to an interface pointer
91 */
92 #define _IUnknown_(This) (IUnknown*)&(This->lpVtbl)
93 #define _IShellFolder_(This) (IShellFolder*)&(This->lpVtbl)
94 #define _IShellFolder2_(This) (IShellFolder2*)&(This->lpVtbl)
95
96 #define _IPersist_(This) (IPersist*)&(This->lpVtblPersistFolder2)
97 #define _IPersistFolder_(This) (IPersistFolder*)&(This->lpVtblPersistFolder2)
98 #define _IPersistFolder2_(This) (IPersistFolder2*)&(This->lpVtblPersistFolder2)
99 #define _IShellExecuteHookW_(This) (IShellExecuteHookW*)&(This->lpVtblShellExecuteHookW)
100 #define _IShellExecuteHookA_(This) (IShellExecuteHookA*)&(This->lpVtblShellExecuteHookA)
101
102 /***********************************************************************
103 * IShellFolder [ControlPanel] implementation
104 */
105
106 static shvheader ControlPanelSFHeader[] = {
107 {IDS_SHV_COLUMN8, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 15},/*FIXME*/
108 {IDS_SHV_COLUMN9, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 200},/*FIXME*/
109 };
110
111 #define CONROLPANELSHELLVIEWCOLUMNS 2
112
113 /**************************************************************************
114 * IControlPanel_Constructor
115 */
116 HRESULT WINAPI IControlPanel_Constructor(IUnknown* pUnkOuter, REFIID riid, LPVOID * ppv)
117 {
118 ICPanelImpl *sf;
119
120 TRACE("unkOut=%p %s\n", pUnkOuter, shdebugstr_guid(riid));
121
122 if (!ppv)
123 return E_POINTER;
124 if (pUnkOuter && !IsEqualIID (riid, &IID_IUnknown))
125 return CLASS_E_NOAGGREGATION;
126
127 sf = (ICPanelImpl *) LocalAlloc(LMEM_ZEROINIT, sizeof(ICPanelImpl));
128 if (!sf)
129 return E_OUTOFMEMORY;
130
131 sf->ref = 0;
132 sf->lpVtbl = &vt_ShellFolder2;
133 sf->lpVtblPersistFolder2 = &vt_PersistFolder2;
134 sf->lpVtblShellExecuteHookW = &vt_ShellExecuteHookW;
135 sf->lpVtblShellExecuteHookA = &vt_ShellExecuteHookA;
136 sf->pidlRoot = _ILCreateControlPanel(); /* my qualified pidl */
137 sf->pUnkOuter = pUnkOuter ? pUnkOuter : _IUnknown_ (sf);
138
139 if (!SUCCEEDED(IUnknown_QueryInterface(_IUnknown_(sf), riid, ppv))) {
140 IUnknown_Release(_IUnknown_(sf));
141 return E_NOINTERFACE;
142 }
143
144 TRACE("--(%p)\n", sf);
145 return S_OK;
146 }
147
148 /**************************************************************************
149 * ISF_ControlPanel_fnQueryInterface
150 *
151 * NOTES supports not IPersist/IPersistFolder
152 */
153 static HRESULT WINAPI ISF_ControlPanel_fnQueryInterface(IShellFolder2 * iface, REFIID riid, LPVOID * ppvObject)
154 {
155 ICPanelImpl *This = (ICPanelImpl *)iface;
156
157 TRACE("(%p)->(%s,%p)\n", This, shdebugstr_guid(riid), ppvObject);
158
159 *ppvObject = NULL;
160
161 if (IsEqualIID(riid, &IID_IUnknown) ||
162 IsEqualIID(riid, &IID_IShellFolder) || IsEqualIID(riid, &IID_IShellFolder2))
163 *ppvObject = This;
164 else if (IsEqualIID(riid, &IID_IPersist) ||
165 IsEqualIID(riid, &IID_IPersistFolder) || IsEqualIID(riid, &IID_IPersistFolder2))
166 *ppvObject = _IPersistFolder2_(This);
167 else if (IsEqualIID(riid, &IID_IShellExecuteHookW))
168 *ppvObject = _IShellExecuteHookW_(This);
169 else if (IsEqualIID(riid, &IID_IShellExecuteHookA))
170 *ppvObject = _IShellExecuteHookA_(This);
171
172 if (*ppvObject) {
173 IUnknown_AddRef((IUnknown *)(*ppvObject));
174 TRACE("-- Interface:(%p)->(%p)\n", ppvObject, *ppvObject);
175 return S_OK;
176 }
177 TRACE("-- Interface: E_NOINTERFACE\n");
178 return E_NOINTERFACE;
179 }
180
181 static ULONG WINAPI ISF_ControlPanel_fnAddRef(IShellFolder2 * iface)
182 {
183 ICPanelImpl *This = (ICPanelImpl *)iface;
184 ULONG refCount = InterlockedIncrement(&This->ref);
185
186 TRACE("(%p)->(count=%lu)\n", This, refCount - 1);
187
188 return refCount;
189 }
190
191 static ULONG WINAPI ISF_ControlPanel_fnRelease(IShellFolder2 * iface)
192 {
193 ICPanelImpl *This = (ICPanelImpl *)iface;
194 ULONG refCount = InterlockedDecrement(&This->ref);
195
196 TRACE("(%p)->(count=%lu)\n", This, refCount + 1);
197
198 if (!refCount) {
199 TRACE("-- destroying IShellFolder(%p)\n", This);
200 if (This->pidlRoot)
201 SHFree(This->pidlRoot);
202 LocalFree((HLOCAL) This);
203 }
204 return refCount;
205 }
206
207 /**************************************************************************
208 * ISF_ControlPanel_fnParseDisplayName
209 */
210 static HRESULT WINAPI
211 ISF_ControlPanel_fnParseDisplayName(IShellFolder2 * iface,
212 HWND hwndOwner,
213 LPBC pbc,
214 LPOLESTR lpszDisplayName,
215 DWORD * pchEaten, LPITEMIDLIST * ppidl, DWORD * pdwAttributes)
216 {
217 ICPanelImpl *This = (ICPanelImpl *)iface;
218
219 HRESULT hr = E_INVALIDARG;
220
221 FIXME("(%p)->(HWND=%p,%p,%p=%s,%p,pidl=%p,%p)\n",
222 This, hwndOwner, pbc, lpszDisplayName, debugstr_w(lpszDisplayName), pchEaten, ppidl, pdwAttributes);
223
224 *ppidl = 0;
225 if (pchEaten)
226 *pchEaten = 0;
227
228 TRACE("(%p)->(-- ret=0x%08lx)\n", This, hr);
229
230 return hr;
231 }
232
233 static LPITEMIDLIST _ILCreateCPanelApplet(LPCSTR name, LPCSTR displayName,
234 LPCSTR comment, int iconIdx)
235 {
236 PIDLCPanelStruct *p;
237 LPITEMIDLIST pidl;
238 PIDLDATA tmp;
239 int size0 = (char*)&tmp.u.cpanel.szName-(char*)&tmp.u.cpanel;
240 int size = size0;
241 int l;
242
243 tmp.type = PT_CPLAPPLET;
244 tmp.u.cpanel.dummy = 0;
245 tmp.u.cpanel.iconIdx = iconIdx;
246
247 l = strlen(name);
248 size += l+1;
249
250 tmp.u.cpanel.offsDispName = l+1;
251 l = strlen(displayName);
252 size += l+1;
253
254 tmp.u.cpanel.offsComment = tmp.u.cpanel.offsDispName+1+l;
255 l = strlen(comment);
256 size += l+1;
257
258 pidl = SHAlloc(size+4);
259 if (!pidl)
260 return NULL;
261
262 pidl->mkid.cb = size+2;
263 memcpy(pidl->mkid.abID, &tmp, 2+size0);
264
265 p = &((PIDLDATA*)pidl->mkid.abID)->u.cpanel;
266 strcpy(p->szName, name);
267 strcpy(p->szName+tmp.u.cpanel.offsDispName, displayName);
268 strcpy(p->szName+tmp.u.cpanel.offsComment, comment);
269
270 *(WORD*)((char*)pidl+(size+2)) = 0;
271
272 pcheck(pidl);
273
274 return pidl;
275 }
276
277 /**************************************************************************
278 * _ILGetCPanelPointer()
279 * gets a pointer to the control panel struct stored in the pidl
280 */
281 static PIDLCPanelStruct* _ILGetCPanelPointer(LPCITEMIDLIST pidl)
282 {
283 LPPIDLDATA pdata = _ILGetDataPointer(pidl);
284
285 if (pdata && pdata->type==PT_CPLAPPLET)
286 return (PIDLCPanelStruct*)&(pdata->u.cpanel);
287
288 return NULL;
289 }
290
291 /**************************************************************************
292 * ISF_ControlPanel_fnEnumObjects
293 */
294 static BOOL SHELL_RegisterCPanelApp(IEnumIDList* list, LPCSTR path)
295 {
296 LPITEMIDLIST pidl;
297 CPlApplet* applet;
298 CPanel panel;
299 CPLINFO info;
300 unsigned i;
301 int iconIdx;
302
303 char displayName[MAX_PATH];
304 char comment[MAX_PATH];
305
306 WCHAR wpath[MAX_PATH];
307
308 MultiByteToWideChar(CP_ACP, 0, path, -1, wpath, MAX_PATH);
309
310 panel.first = NULL;
311 applet = Control_LoadApplet(0, wpath, &panel);
312
313 if (applet)
314 {
315 for(i=0; i<applet->count; ++i)
316 {
317 WideCharToMultiByte(CP_ACP, 0, applet->info[i].szName, -1, displayName, MAX_PATH, 0, 0);
318 WideCharToMultiByte(CP_ACP, 0, applet->info[i].szInfo, -1, comment, MAX_PATH, 0, 0);
319
320 applet->proc(0, CPL_INQUIRE, i, (LPARAM)&info);
321
322 if (info.idIcon > 0)
323 iconIdx = -info.idIcon; /* negative icon index instead of icon number */
324 else
325 iconIdx = 0;
326
327 pidl = _ILCreateCPanelApplet(path, displayName, comment, iconIdx);
328
329 if (pidl)
330 AddToEnumList(list, pidl);
331 }
332 Control_UnloadApplet(applet);
333 }
334 return TRUE;
335 }
336
337 static int SHELL_RegisterRegistryCPanelApps(IEnumIDList* list, HKEY hkey_root, LPCSTR szRepPath)
338 {
339 char name[MAX_PATH];
340 char value[MAX_PATH];
341 HKEY hkey;
342
343 int cnt = 0;
344
345 if (RegOpenKeyA(hkey_root, szRepPath, &hkey) == ERROR_SUCCESS)
346 {
347 int idx = 0;
348
349 for(;; ++idx)
350 {
351 DWORD nameLen = MAX_PATH;
352 DWORD valueLen = MAX_PATH;
353
354 if (RegEnumValueA(hkey, idx, name, &nameLen, NULL, NULL, (LPBYTE)&value, &valueLen) != ERROR_SUCCESS)
355 break;
356
357 if (SHELL_RegisterCPanelApp(list, value))
358 ++cnt;
359 }
360 RegCloseKey(hkey);
361 }
362
363 return cnt;
364 }
365
366 static int SHELL_RegisterCPanelFolders(IEnumIDList* list, HKEY hkey_root, LPCSTR szRepPath)
367 {
368 char name[MAX_PATH];
369 HKEY hkey;
370
371 int cnt = 0;
372
373 if (RegOpenKeyA(hkey_root, szRepPath, &hkey) == ERROR_SUCCESS)
374 {
375 int idx = 0;
376 for(;; ++idx)
377 {
378 if (RegEnumKeyA(hkey, idx, name, MAX_PATH) != ERROR_SUCCESS)
379 break;
380
381 if (*name == '{')
382 {
383 LPITEMIDLIST pidl = _ILCreateGuidFromStrA(name);
384
385 if (pidl && AddToEnumList(list, pidl))
386 ++cnt;
387 }
388 }
389
390 RegCloseKey(hkey);
391 }
392
393 return cnt;
394 }
395
396 /**************************************************************************
397 * CreateCPanelEnumList()
398 */
399 static BOOL CreateCPanelEnumList(
400 IEnumIDList * iface,
401 DWORD dwFlags)
402 {
403 CHAR szPath[MAX_PATH];
404 WIN32_FIND_DATAA wfd;
405 HANDLE hFile;
406
407 TRACE("(%p)->(flags=0x%08lx) \n",iface,dwFlags);
408
409 /* enumerate control panel folders folders */
410 if (dwFlags & SHCONTF_FOLDERS)
411 SHELL_RegisterCPanelFolders(iface, HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ControlPanel\\NameSpace");
412
413 /* enumerate the control panel applets */
414 if (dwFlags & SHCONTF_NONFOLDERS)
415 {
416 LPSTR p;
417
418 GetSystemDirectoryA(szPath, MAX_PATH);
419 p = PathAddBackslashA(szPath);
420 strcpy(p, "*.cpl");
421
422 TRACE("-- (%p)-> enumerate SHCONTF_NONFOLDERS of %s\n",iface,debugstr_a(szPath));
423 hFile = FindFirstFileA(szPath, &wfd);
424
425 if (hFile != INVALID_HANDLE_VALUE)
426 {
427 do
428 {
429 if (!(dwFlags & SHCONTF_INCLUDEHIDDEN) && (wfd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN))
430 continue;
431
432 if (!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
433 strcpy(p, wfd.cFileName);
434 SHELL_RegisterCPanelApp((IEnumIDList*)iface, szPath);
435 }
436 } while(FindNextFileA(hFile, &wfd));
437 FindClose(hFile);
438 }
439
440 SHELL_RegisterRegistryCPanelApps((IEnumIDList*)iface, HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Control Panel\\Cpls");
441 SHELL_RegisterRegistryCPanelApps((IEnumIDList*)iface, HKEY_CURRENT_USER, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Control Panel\\Cpls");
442 }
443 return TRUE;
444 }
445
446 /**************************************************************************
447 * ISF_ControlPanel_fnEnumObjects
448 */
449 static HRESULT WINAPI
450 ISF_ControlPanel_fnEnumObjects(IShellFolder2 * iface, HWND hwndOwner, DWORD dwFlags, LPENUMIDLIST * ppEnumIDList)
451 {
452 ICPanelImpl *This = (ICPanelImpl *)iface;
453
454 TRACE("(%p)->(HWND=%p flags=0x%08lx pplist=%p)\n", This, hwndOwner, dwFlags, ppEnumIDList);
455
456 *ppEnumIDList = IEnumIDList_Constructor();
457 if (*ppEnumIDList)
458 CreateCPanelEnumList(*ppEnumIDList, dwFlags);
459
460 TRACE("--(%p)->(new ID List: %p)\n", This, *ppEnumIDList);
461
462 return(*ppEnumIDList) ? S_OK : E_OUTOFMEMORY;
463 }
464
465 /**************************************************************************
466 * ISF_ControlPanel_fnBindToObject
467 */
468 static HRESULT WINAPI
469 ISF_ControlPanel_fnBindToObject(IShellFolder2 * iface, LPCITEMIDLIST pidl,
470 LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
471 {
472 ICPanelImpl *This = (ICPanelImpl *)iface;
473
474 TRACE("(%p)->(pidl=%p,%p,%s,%p)\n", This, pidl, pbcReserved, shdebugstr_guid(riid), ppvOut);
475
476 return SHELL32_BindToChild(This->pidlRoot, NULL, pidl, riid, ppvOut);
477 }
478
479 /**************************************************************************
480 * ISF_ControlPanel_fnBindToStorage
481 */
482 static HRESULT WINAPI
483 ISF_ControlPanel_fnBindToStorage(IShellFolder2 * iface,
484 LPCITEMIDLIST pidl, LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
485 {
486 ICPanelImpl *This = (ICPanelImpl *)iface;
487
488 FIXME("(%p)->(pidl=%p,%p,%s,%p) stub\n", This, pidl, pbcReserved, shdebugstr_guid(riid), ppvOut);
489
490 *ppvOut = NULL;
491 return E_NOTIMPL;
492 }
493
494 /**************************************************************************
495 * ISF_ControlPanel_fnCompareIDs
496 */
497
498 static HRESULT WINAPI
499 ISF_ControlPanel_fnCompareIDs(IShellFolder2 * iface, LPARAM lParam, LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
500 {
501 ICPanelImpl *This = (ICPanelImpl *)iface;
502
503 int nReturn;
504
505 TRACE("(%p)->(0x%08lx,pidl1=%p,pidl2=%p)\n", This, lParam, pidl1, pidl2);
506 nReturn = SHELL32_CompareIDs(_IShellFolder_(This), lParam, pidl1, pidl2);
507 TRACE("-- %i\n", nReturn);
508 return nReturn;
509 }
510
511 /**************************************************************************
512 * ISF_ControlPanel_fnCreateViewObject
513 */
514 static HRESULT WINAPI
515 ISF_ControlPanel_fnCreateViewObject(IShellFolder2 * iface, HWND hwndOwner, REFIID riid, LPVOID * ppvOut)
516 {
517 ICPanelImpl *This = (ICPanelImpl *)iface;
518
519 LPSHELLVIEW pShellView;
520 HRESULT hr = E_INVALIDARG;
521
522 TRACE("(%p)->(hwnd=%p,%s,%p)\n", This, hwndOwner, shdebugstr_guid(riid), ppvOut);
523
524 if (ppvOut) {
525 *ppvOut = NULL;
526
527 if (IsEqualIID(riid, &IID_IDropTarget)) {
528 WARN("IDropTarget not implemented\n");
529 hr = E_NOTIMPL;
530 } else if (IsEqualIID(riid, &IID_IContextMenu)) {
531 WARN("IContextMenu not implemented\n");
532 hr = E_NOTIMPL;
533 } else if (IsEqualIID(riid, &IID_IShellView)) {
534 pShellView = IShellView_Constructor((IShellFolder *) iface);
535 if (pShellView) {
536 hr = IShellView_QueryInterface(pShellView, riid, ppvOut);
537 IShellView_Release(pShellView);
538 }
539 }
540 }
541 TRACE("--(%p)->(interface=%p)\n", This, ppvOut);
542 return hr;
543 }
544
545 /**************************************************************************
546 * ISF_ControlPanel_fnGetAttributesOf
547 */
548 static HRESULT WINAPI
549 ISF_ControlPanel_fnGetAttributesOf(IShellFolder2 * iface, UINT cidl, LPCITEMIDLIST * apidl, DWORD * rgfInOut)
550 {
551 ICPanelImpl *This = (ICPanelImpl *)iface;
552
553 HRESULT hr = S_OK;
554
555 TRACE("(%p)->(cidl=%d apidl=%p mask=%p (0x%08lx))\n",
556 This, cidl, apidl, rgfInOut, rgfInOut ? *rgfInOut : 0);
557
558 if (!rgfInOut)
559 return E_INVALIDARG;
560 if (cidl && !apidl)
561 return E_INVALIDARG;
562
563 if (*rgfInOut == 0)
564 *rgfInOut = ~0;
565
566 while(cidl > 0 && *apidl) {
567 pdump(*apidl);
568 SHELL32_GetItemAttributes(_IShellFolder_(This), *apidl, rgfInOut);
569 apidl++;
570 cidl--;
571 }
572 /* make sure SFGAO_VALIDATE is cleared, some apps depend on that */
573 *rgfInOut &= ~SFGAO_VALIDATE;
574
575 TRACE("-- result=0x%08lx\n", *rgfInOut);
576 return hr;
577 }
578
579 /**************************************************************************
580 * ISF_ControlPanel_fnGetUIObjectOf
581 *
582 * PARAMETERS
583 * HWND hwndOwner, //[in ] Parent window for any output
584 * UINT cidl, //[in ] array size
585 * LPCITEMIDLIST* apidl, //[in ] simple pidl array
586 * REFIID riid, //[in ] Requested Interface
587 * UINT* prgfInOut, //[ ] reserved
588 * LPVOID* ppvObject) //[out] Resulting Interface
589 *
590 */
591 static HRESULT WINAPI
592 ISF_ControlPanel_fnGetUIObjectOf(IShellFolder2 * iface,
593 HWND hwndOwner,
594 UINT cidl, LPCITEMIDLIST * apidl, REFIID riid, UINT * prgfInOut, LPVOID * ppvOut)
595 {
596 ICPanelImpl *This = (ICPanelImpl *)iface;
597
598 LPITEMIDLIST pidl;
599 IUnknown *pObj = NULL;
600 HRESULT hr = E_INVALIDARG;
601
602 TRACE("(%p)->(%p,%u,apidl=%p,%s,%p,%p)\n",
603 This, hwndOwner, cidl, apidl, shdebugstr_guid(riid), prgfInOut, ppvOut);
604
605 if (ppvOut) {
606 *ppvOut = NULL;
607
608 if (IsEqualIID(riid, &IID_IContextMenu) &&(cidl >= 1)) {
609 pObj = (LPUNKNOWN) ISvItemCm_Constructor((IShellFolder *) iface, This->pidlRoot, apidl, cidl);
610 hr = S_OK;
611 } else if (IsEqualIID(riid, &IID_IDataObject) &&(cidl >= 1)) {
612 pObj = (LPUNKNOWN) IDataObject_Constructor(hwndOwner, This->pidlRoot, apidl, cidl);
613 hr = S_OK;
614 } else if (IsEqualIID(riid, &IID_IExtractIconA) &&(cidl == 1)) {
615 pidl = ILCombine(This->pidlRoot, apidl[0]);
616 pObj = (LPUNKNOWN) IExtractIconA_Constructor(pidl);
617 SHFree(pidl);
618 hr = S_OK;
619 } else if (IsEqualIID(riid, &IID_IExtractIconW) &&(cidl == 1)) {
620 pidl = ILCombine(This->pidlRoot, apidl[0]);
621 pObj = (LPUNKNOWN) IExtractIconW_Constructor(pidl);
622 SHFree(pidl);
623 hr = S_OK;
624 } else if ((IsEqualIID(riid,&IID_IShellLinkW) || IsEqualIID(riid,&IID_IShellLinkA))
625 && (cidl == 1)) {
626 pidl = ILCombine(This->pidlRoot, apidl[0]);
627 hr = IShellLink_ConstructFromFile(NULL, riid, pidl,(LPVOID*)&pObj);
628 SHFree(pidl);
629 } else {
630 hr = E_NOINTERFACE;
631 }
632
633 if (SUCCEEDED(hr) && !pObj)
634 hr = E_OUTOFMEMORY;
635
636 *ppvOut = pObj;
637 }
638 TRACE("(%p)->hr=0x%08lx\n", This, hr);
639 return hr;
640 }
641
642 /**************************************************************************
643 * ISF_ControlPanel_fnGetDisplayNameOf
644 */
645 static HRESULT WINAPI ISF_ControlPanel_fnGetDisplayNameOf(IShellFolder2 * iface, LPCITEMIDLIST pidl, DWORD dwFlags, LPSTRRET strRet)
646 {
647 ICPanelImpl *This = (ICPanelImpl *)iface;
648
649 CHAR szPath[MAX_PATH*2];
650 PIDLCPanelStruct* pcpanel;
651
652 *szPath = '\0';
653
654 TRACE("(%p)->(pidl=%p,0x%08lx,%p)\n", This, pidl, dwFlags, strRet);
655 pdump(pidl);
656
657 if (!pidl || !strRet)
658 return E_INVALIDARG;
659
660 pcpanel = _ILGetCPanelPointer(pidl);
661
662 if (pcpanel) {
663 lstrcpyA(szPath, pcpanel->szName+pcpanel->offsDispName);
664
665 if (!(dwFlags & SHGDN_FORPARSING))
666 FIXME("retrieve display name from control panel app\n");
667 }
668 /* take names of special folders only if its only this folder */
669 else if (_ILIsSpecialFolder(pidl)) {
670 BOOL bSimplePidl = _ILIsPidlSimple(pidl);
671
672 if (bSimplePidl) {
673 _ILSimpleGetText(pidl, szPath, MAX_PATH); /* append my own path */
674 } else {
675 FIXME("special pidl\n");
676 }
677
678 if ((dwFlags & SHGDN_FORPARSING) && !bSimplePidl) { /* go deeper if needed */
679 int len = 0;
680
681 PathAddBackslashA(szPath); /*FIXME*/
682 len = lstrlenA(szPath);
683
684 if (!SUCCEEDED
685 (SHELL32_GetDisplayNameOfChild(iface, pidl, dwFlags | SHGDN_INFOLDER, szPath + len, MAX_PATH - len)))
686 return E_OUTOFMEMORY;
687 }
688 }
689
690 strRet->uType = STRRET_CSTR;
691 lstrcpynA(strRet->u.cStr, szPath, MAX_PATH);
692
693 TRACE("--(%p)->(%s)\n", This, szPath);
694 return S_OK;
695 }
696
697 /**************************************************************************
698 * ISF_ControlPanel_fnSetNameOf
699 * Changes the name of a file object or subfolder, possibly changing its item
700 * identifier in the process.
701 *
702 * PARAMETERS
703 * HWND hwndOwner, //[in ] Owner window for output
704 * LPCITEMIDLIST pidl, //[in ] simple pidl of item to change
705 * LPCOLESTR lpszName, //[in ] the items new display name
706 * DWORD dwFlags, //[in ] SHGNO formatting flags
707 * LPITEMIDLIST* ppidlOut) //[out] simple pidl returned
708 */
709 static HRESULT WINAPI ISF_ControlPanel_fnSetNameOf(IShellFolder2 * iface, HWND hwndOwner, LPCITEMIDLIST pidl, /*simple pidl */
710 LPCOLESTR lpName, DWORD dwFlags, LPITEMIDLIST * pPidlOut)
711 {
712 ICPanelImpl *This = (ICPanelImpl *)iface;
713 FIXME("(%p)->(%p,pidl=%p,%s,%lu,%p)\n", This, hwndOwner, pidl, debugstr_w(lpName), dwFlags, pPidlOut);
714 return E_FAIL;
715 }
716
717 static HRESULT WINAPI ISF_ControlPanel_fnGetDefaultSearchGUID(IShellFolder2 * iface, GUID * pguid)
718 {
719 ICPanelImpl *This = (ICPanelImpl *)iface;
720 FIXME("(%p)\n", This);
721 return E_NOTIMPL;
722 }
723 static HRESULT WINAPI ISF_ControlPanel_fnEnumSearches(IShellFolder2 * iface, IEnumExtraSearch ** ppenum)
724 {
725 ICPanelImpl *This = (ICPanelImpl *)iface;
726 FIXME("(%p)\n", This);
727 return E_NOTIMPL;
728 }
729 static HRESULT WINAPI ISF_ControlPanel_fnGetDefaultColumn(IShellFolder2 * iface, DWORD dwRes, ULONG * pSort, ULONG * pDisplay)
730 {
731 ICPanelImpl *This = (ICPanelImpl *)iface;
732
733 TRACE("(%p)\n", This);
734
735 if (pSort) *pSort = 0;
736 if (pDisplay) *pDisplay = 0;
737 return S_OK;
738 }
739 static HRESULT WINAPI ISF_ControlPanel_fnGetDefaultColumnState(IShellFolder2 * iface, UINT iColumn, DWORD * pcsFlags)
740 {
741 ICPanelImpl *This = (ICPanelImpl *)iface;
742
743 TRACE("(%p)\n", This);
744
745 if (!pcsFlags || iColumn >= CONROLPANELSHELLVIEWCOLUMNS) return E_INVALIDARG;
746 *pcsFlags = ControlPanelSFHeader[iColumn].pcsFlags;
747 return S_OK;
748 }
749 static HRESULT WINAPI ISF_ControlPanel_fnGetDetailsEx(IShellFolder2 * iface, LPCITEMIDLIST pidl, const SHCOLUMNID * pscid, VARIANT * pv)
750 {
751 ICPanelImpl *This = (ICPanelImpl *)iface;
752 FIXME("(%p)\n", This);
753 return E_NOTIMPL;
754 }
755
756 static HRESULT WINAPI ISF_ControlPanel_fnGetDetailsOf(IShellFolder2 * iface, LPCITEMIDLIST pidl, UINT iColumn, SHELLDETAILS * psd)
757 {
758 ICPanelImpl *This = (ICPanelImpl *)iface;
759 HRESULT hr;
760
761 TRACE("(%p)->(%p %i %p)\n", This, pidl, iColumn, psd);
762
763 if (!psd || iColumn >= CONROLPANELSHELLVIEWCOLUMNS)
764 return E_INVALIDARG;
765
766 if (!pidl) {
767 psd->fmt = ControlPanelSFHeader[iColumn].fmt;
768 psd->cxChar = ControlPanelSFHeader[iColumn].cxChar;
769 psd->str.uType = STRRET_CSTR;
770 LoadStringA(shell32_hInstance, ControlPanelSFHeader[iColumn].colnameid, psd->str.u.cStr, MAX_PATH);
771 return S_OK;
772 } else {
773 psd->str.u.cStr[0] = 0x00;
774 psd->str.uType = STRRET_CSTR;
775 switch(iColumn) {
776 case 0: /* name */
777 hr = IShellFolder_GetDisplayNameOf(iface, pidl, SHGDN_NORMAL | SHGDN_INFOLDER, &psd->str);
778 break;
779 case 1: /* comment */
780 _ILGetFileType(pidl, psd->str.u.cStr, MAX_PATH);
781 break;
782 }
783 hr = S_OK;
784 }
785
786 return hr;
787 }
788 static HRESULT WINAPI ISF_ControlPanel_fnMapColumnToSCID(IShellFolder2 * iface, UINT column, SHCOLUMNID * pscid)
789 {
790 ICPanelImpl *This = (ICPanelImpl *)iface;
791 FIXME("(%p)\n", This);
792 return E_NOTIMPL;
793 }
794
795 static const IShellFolder2Vtbl vt_ShellFolder2 =
796 {
797
798 ISF_ControlPanel_fnQueryInterface,
799 ISF_ControlPanel_fnAddRef,
800 ISF_ControlPanel_fnRelease,
801 ISF_ControlPanel_fnParseDisplayName,
802 ISF_ControlPanel_fnEnumObjects,
803 ISF_ControlPanel_fnBindToObject,
804 ISF_ControlPanel_fnBindToStorage,
805 ISF_ControlPanel_fnCompareIDs,
806 ISF_ControlPanel_fnCreateViewObject,
807 ISF_ControlPanel_fnGetAttributesOf,
808 ISF_ControlPanel_fnGetUIObjectOf,
809 ISF_ControlPanel_fnGetDisplayNameOf,
810 ISF_ControlPanel_fnSetNameOf,
811
812 /* ShellFolder2 */
813 ISF_ControlPanel_fnGetDefaultSearchGUID,
814 ISF_ControlPanel_fnEnumSearches,
815 ISF_ControlPanel_fnGetDefaultColumn,
816 ISF_ControlPanel_fnGetDefaultColumnState,
817 ISF_ControlPanel_fnGetDetailsEx,
818 ISF_ControlPanel_fnGetDetailsOf,
819 ISF_ControlPanel_fnMapColumnToSCID
820 };
821
822 /************************************************************************
823 * ICPanel_PersistFolder2_QueryInterface
824 */
825 static HRESULT WINAPI ICPanel_PersistFolder2_QueryInterface(IPersistFolder2 * iface, REFIID iid, LPVOID * ppvObject)
826 {
827 _ICOM_THIS_From_IPersistFolder2(ICPanelImpl, iface);
828
829 TRACE("(%p)\n", This);
830
831 return IUnknown_QueryInterface(_IUnknown_(This), iid, ppvObject);
832 }
833
834 /************************************************************************
835 * ICPanel_PersistFolder2_AddRef
836 */
837 static ULONG WINAPI ICPanel_PersistFolder2_AddRef(IPersistFolder2 * iface)
838 {
839 _ICOM_THIS_From_IPersistFolder2(ICPanelImpl, iface);
840
841 TRACE("(%p)->(count=%lu)\n", This, This->ref);
842
843 return IUnknown_AddRef(_IUnknown_(This));
844 }
845
846 /************************************************************************
847 * ISFPersistFolder_Release
848 */
849 static ULONG WINAPI ICPanel_PersistFolder2_Release(IPersistFolder2 * iface)
850 {
851 _ICOM_THIS_From_IPersistFolder2(ICPanelImpl, iface);
852
853 TRACE("(%p)->(count=%lu)\n", This, This->ref);
854
855 return IUnknown_Release(_IUnknown_(This));
856 }
857
858 /************************************************************************
859 * ICPanel_PersistFolder2_GetClassID
860 */
861 static HRESULT WINAPI ICPanel_PersistFolder2_GetClassID(IPersistFolder2 * iface, CLSID * lpClassId)
862 {
863 _ICOM_THIS_From_IPersistFolder2(ICPanelImpl, iface);
864
865 TRACE("(%p)\n", This);
866
867 if (!lpClassId)
868 return E_POINTER;
869 *lpClassId = CLSID_ControlPanel;
870
871 return S_OK;
872 }
873
874 /************************************************************************
875 * ICPanel_PersistFolder2_Initialize
876 *
877 * NOTES: it makes no sense to change the pidl
878 */
879 static HRESULT WINAPI ICPanel_PersistFolder2_Initialize(IPersistFolder2 * iface, LPCITEMIDLIST pidl)
880 {
881 _ICOM_THIS_From_IPersistFolder2(ICPanelImpl, iface);
882 TRACE("(%p)->(%p)\n", This, pidl);
883 return E_NOTIMPL;
884 }
885
886 /**************************************************************************
887 * IPersistFolder2_fnGetCurFolder
888 */
889 static HRESULT WINAPI ICPanel_PersistFolder2_GetCurFolder(IPersistFolder2 * iface, LPITEMIDLIST * pidl)
890 {
891 _ICOM_THIS_From_IPersistFolder2(ICPanelImpl, iface);
892
893 TRACE("(%p)->(%p)\n", This, pidl);
894
895 if (!pidl)
896 return E_POINTER;
897 *pidl = ILClone(This->pidlRoot);
898 return S_OK;
899 }
900
901 static const IPersistFolder2Vtbl vt_PersistFolder2 =
902 {
903
904 ICPanel_PersistFolder2_QueryInterface,
905 ICPanel_PersistFolder2_AddRef,
906 ICPanel_PersistFolder2_Release,
907 ICPanel_PersistFolder2_GetClassID,
908 ICPanel_PersistFolder2_Initialize,
909 ICPanel_PersistFolder2_GetCurFolder
910 };
911
912 HRESULT CPanel_GetIconLocationW(LPITEMIDLIST pidl,
913 LPWSTR szIconFile, UINT cchMax, int* piIndex)
914 {
915 PIDLCPanelStruct* pcpanel = _ILGetCPanelPointer(pidl);
916
917 if (!pcpanel)
918 return E_INVALIDARG;
919
920 MultiByteToWideChar(CP_ACP, 0, pcpanel->szName, -1, szIconFile, cchMax);
921 *piIndex = pcpanel->iconIdx!=-1? pcpanel->iconIdx: 0;
922
923 return S_OK;
924 }
925
926
927 /**************************************************************************
928 * IShellExecuteHookW Implementation
929 */
930
931 static HRESULT WINAPI IShellExecuteHookW_fnQueryInterface(
932 IShellExecuteHookW* iface, REFIID riid, void** ppvObject)
933 {
934 _ICOM_THIS_From_IShellExecuteHookW(ICPanelImpl, iface);
935
936 TRACE("(%p)->(count=%lu)\n", This, This->ref);
937
938 return IUnknown_QueryInterface(This->pUnkOuter, riid, ppvObject);
939 }
940
941 static ULONG STDMETHODCALLTYPE IShellExecuteHookW_fnAddRef(IShellExecuteHookW* iface)
942 {
943 _ICOM_THIS_From_IShellExecuteHookW(ICPanelImpl, iface);
944
945 TRACE("(%p)->(count=%lu)\n", This, This->ref);
946
947 return IUnknown_AddRef(This->pUnkOuter);
948 }
949
950 static ULONG STDMETHODCALLTYPE IShellExecuteHookW_fnRelease(IShellExecuteHookW* iface)
951 {
952 _ICOM_THIS_From_IShellExecuteHookW(ICPanelImpl, iface);
953
954 TRACE("(%p)\n", This);
955
956 return IUnknown_Release(This->pUnkOuter);
957 }
958
959 static HRESULT WINAPI IShellExecuteHookW_fnExecute(IShellExecuteHookW* iface, LPSHELLEXECUTEINFOW psei)
960 {
961 static const WCHAR wCplopen[] = {'c','p','l','o','p','e','n','\0'};
962 ICPanelImpl *This = (ICPanelImpl *)iface;
963
964 SHELLEXECUTEINFOW sei_tmp;
965 PIDLCPanelStruct* pcpanel;
966 WCHAR path[MAX_PATH];
967 BOOL ret;
968 int l;
969
970 TRACE("(%p)->execute(%p)\n", This, psei);
971
972 if (!psei)
973 return E_INVALIDARG;
974
975 pcpanel = _ILGetCPanelPointer(ILFindLastID(psei->lpIDList));
976
977 if (!pcpanel)
978 return E_INVALIDARG;
979
980 path[0] = '\"';
981 /* Return value from MultiByteToWideChar includes terminating NUL, which
982 * compensates for the starting double quote we just put in */
983 l = MultiByteToWideChar(CP_ACP, 0, pcpanel->szName, -1, path+1, MAX_PATH);
984
985 /* pass applet name to Control_RunDLL to distinguish between applets in one .cpl file */
986 path[l++] = '"';
987 path[l++] = ' ';
988
989 MultiByteToWideChar(CP_ACP, 0, pcpanel->szName+pcpanel->offsDispName, -1, path+l, MAX_PATH);
990
991 memcpy(&sei_tmp, psei, sizeof(sei_tmp));
992 sei_tmp.lpFile = path;
993 sei_tmp.fMask &= ~SEE_MASK_INVOKEIDLIST;
994 sei_tmp.lpVerb = wCplopen;
995
996 ret = ShellExecuteExW(&sei_tmp);
997 if (ret)
998 return S_OK;
999 else
1000 return S_FALSE;
1001 }
1002
1003 static const IShellExecuteHookWVtbl vt_ShellExecuteHookW =
1004 {
1005
1006 IShellExecuteHookW_fnQueryInterface,
1007 IShellExecuteHookW_fnAddRef,
1008 IShellExecuteHookW_fnRelease,
1009
1010 IShellExecuteHookW_fnExecute
1011 };
1012
1013
1014 /**************************************************************************
1015 * IShellExecuteHookA Implementation
1016 */
1017
1018 static HRESULT WINAPI IShellExecuteHookA_fnQueryInterface(IShellExecuteHookA* iface, REFIID riid, void** ppvObject)
1019 {
1020 _ICOM_THIS_From_IShellExecuteHookA(ICPanelImpl, iface);
1021
1022 TRACE("(%p)->(count=%lu)\n", This, This->ref);
1023
1024 return IUnknown_QueryInterface(This->pUnkOuter, riid, ppvObject);
1025 }
1026
1027 static ULONG STDMETHODCALLTYPE IShellExecuteHookA_fnAddRef(IShellExecuteHookA* iface)
1028 {
1029 _ICOM_THIS_From_IShellExecuteHookA(ICPanelImpl, iface);
1030
1031 TRACE("(%p)->(count=%lu)\n", This, This->ref);
1032
1033 return IUnknown_AddRef(This->pUnkOuter);
1034 }
1035
1036 static ULONG STDMETHODCALLTYPE IShellExecuteHookA_fnRelease(IShellExecuteHookA* iface)
1037 {
1038 _ICOM_THIS_From_IShellExecuteHookA(ICPanelImpl, iface);
1039
1040 TRACE("(%p)\n", This);
1041
1042 return IUnknown_Release(This->pUnkOuter);
1043 }
1044
1045 static HRESULT WINAPI IShellExecuteHookA_fnExecute(IShellExecuteHookA* iface, LPSHELLEXECUTEINFOA psei)
1046 {
1047 ICPanelImpl *This = (ICPanelImpl *)iface;
1048
1049 SHELLEXECUTEINFOA sei_tmp;
1050 PIDLCPanelStruct* pcpanel;
1051 char path[MAX_PATH];
1052 BOOL ret;
1053
1054 TRACE("(%p)->execute(%p)\n", This, psei);
1055
1056 if (!psei)
1057 return E_INVALIDARG;
1058
1059 pcpanel = _ILGetCPanelPointer(ILFindLastID(psei->lpIDList));
1060
1061 if (!pcpanel)
1062 return E_INVALIDARG;
1063
1064 path[0] = '\"';
1065 lstrcpyA(path+1, pcpanel->szName);
1066
1067 /* pass applet name to Control_RunDLL to distinguish between applets in one .cpl file */
1068 lstrcatA(path, "\" ");
1069 lstrcatA(path, pcpanel->szName+pcpanel->offsDispName);
1070
1071 memcpy(&sei_tmp, psei, sizeof(sei_tmp));
1072 sei_tmp.lpFile = path;
1073 sei_tmp.fMask &= ~SEE_MASK_INVOKEIDLIST;
1074
1075 ret = ShellExecuteExA(&sei_tmp);
1076 if (ret)
1077 return S_OK;
1078 else
1079 return S_FALSE;
1080 }
1081
1082 static const IShellExecuteHookAVtbl vt_ShellExecuteHookA =
1083 {
1084 IShellExecuteHookA_fnQueryInterface,
1085 IShellExecuteHookA_fnAddRef,
1086 IShellExecuteHookA_fnRelease,
1087 IShellExecuteHookA_fnExecute
1088 };