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