widl: Properly align name table entries.
[wine.git] / dlls / shell32 / cpanelfolder.c
blob69af6734f57b498ae82a045d734e2f1b82d5c476
1 /*
2 * Control panel folder
4 * Copyright 2003 Martin Fuchs
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.
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.
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
21 #include <stdlib.h>
22 #include <string.h>
23 #include <stdarg.h>
24 #include <stdio.h>
26 #define COBJMACROS
27 #include "winerror.h"
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winreg.h"
31 #include "wingdi.h"
32 #include "winuser.h"
34 #include "ole2.h"
35 #include "shlguid.h"
37 #include "commctrl.h"
38 #include "cpanel.h"
39 #include "pidl.h"
40 #include "shell32_main.h"
41 #include "shresdef.h"
42 #include "shlwapi.h"
43 #include "wine/debug.h"
44 #include "debughlp.h"
45 #include "shfldr.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(shell);
49 /***********************************************************************
50 * control panel implementation in shell namespace
53 typedef struct {
54 IShellFolder2 IShellFolder2_iface;
55 IPersistFolder2 IPersistFolder2_iface;
56 IShellExecuteHookW IShellExecuteHookW_iface;
57 IShellExecuteHookA IShellExecuteHookA_iface;
58 LONG ref;
60 IUnknown *pUnkOuter; /* used for aggregation */
62 /* both paths are parsible from the desktop */
63 LPITEMIDLIST pidlRoot; /* absolute pidl */
64 int dwAttributes; /* attributes returned by GetAttributesOf FIXME: use it */
65 } ICPanelImpl;
67 static const WCHAR name_spaceW[] = L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ControlPanel\\NameSpace";
69 static const IShellFolder2Vtbl vt_ShellFolder2;
70 static const IPersistFolder2Vtbl vt_PersistFolder2;
71 static const IShellExecuteHookWVtbl vt_ShellExecuteHookW;
72 static const IShellExecuteHookAVtbl vt_ShellExecuteHookA;
74 static inline ICPanelImpl *impl_from_IShellFolder2(IShellFolder2 *iface)
76 return CONTAINING_RECORD(iface, ICPanelImpl, IShellFolder2_iface);
79 static inline ICPanelImpl *impl_from_IPersistFolder2(IPersistFolder2 *iface)
81 return CONTAINING_RECORD(iface, ICPanelImpl, IPersistFolder2_iface);
84 static inline ICPanelImpl *impl_from_IShellExecuteHookW(IShellExecuteHookW *iface)
86 return CONTAINING_RECORD(iface, ICPanelImpl, IShellExecuteHookW_iface);
89 static inline ICPanelImpl *impl_from_IShellExecuteHookA(IShellExecuteHookA *iface)
91 return CONTAINING_RECORD(iface, ICPanelImpl, IShellExecuteHookA_iface);
95 /***********************************************************************
96 * IShellFolder [ControlPanel] implementation
99 static const shvheader ControlPanelSFHeader[] =
101 { &FMTID_Storage, PID_STG_NAME, IDS_SHV_COLUMN8, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 15 },/*FIXME*/
102 { NULL, 0, IDS_SHV_COLUMN9, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_LEFT, 80 },/*FIXME*/
105 #define CONROLPANELSHELLVIEWCOLUMNS 2
107 /**************************************************************************
108 * IControlPanel_Constructor
110 HRESULT WINAPI IControlPanel_Constructor(IUnknown* pUnkOuter, REFIID riid, LPVOID * ppv)
112 ICPanelImpl *sf;
114 TRACE("unkOut=%p %s\n", pUnkOuter, shdebugstr_guid(riid));
116 if (!ppv)
117 return E_POINTER;
118 if (pUnkOuter && !IsEqualIID (riid, &IID_IUnknown))
119 return CLASS_E_NOAGGREGATION;
121 sf = LocalAlloc(LMEM_ZEROINIT, sizeof(ICPanelImpl));
122 if (!sf)
123 return E_OUTOFMEMORY;
125 sf->ref = 1;
126 sf->IShellFolder2_iface.lpVtbl = &vt_ShellFolder2;
127 sf->IPersistFolder2_iface.lpVtbl = &vt_PersistFolder2;
128 sf->IShellExecuteHookW_iface.lpVtbl = &vt_ShellExecuteHookW;
129 sf->IShellExecuteHookA_iface.lpVtbl = &vt_ShellExecuteHookA;
130 sf->pidlRoot = _ILCreateControlPanel(); /* my qualified pidl */
131 sf->pUnkOuter = pUnkOuter ? pUnkOuter : (IUnknown *)&sf->IShellFolder2_iface;
133 if (FAILED(IShellFolder2_QueryInterface(&sf->IShellFolder2_iface, riid, ppv))) {
134 IShellFolder2_Release(&sf->IShellFolder2_iface);
135 return E_NOINTERFACE;
137 IShellFolder2_Release(&sf->IShellFolder2_iface);
139 TRACE("--(%p)\n", sf);
140 return S_OK;
143 /**************************************************************************
144 * ISF_ControlPanel_fnQueryInterface
146 * NOTES supports not IPersist/IPersistFolder
148 static HRESULT WINAPI ISF_ControlPanel_fnQueryInterface(IShellFolder2 *iface, REFIID riid,
149 void **ppvObject)
151 ICPanelImpl *This = impl_from_IShellFolder2(iface);
153 TRACE("(%p)->(%s,%p)\n", This, shdebugstr_guid(riid), ppvObject);
155 *ppvObject = NULL;
157 if (IsEqualIID(riid, &IID_IUnknown) ||
158 IsEqualIID(riid, &IID_IShellFolder) || IsEqualIID(riid, &IID_IShellFolder2))
159 *ppvObject = &This->IShellFolder2_iface;
160 else if (IsEqualIID(riid, &IID_IPersist) ||
161 IsEqualIID(riid, &IID_IPersistFolder) || IsEqualIID(riid, &IID_IPersistFolder2))
162 *ppvObject = &This->IPersistFolder2_iface;
163 else if (IsEqualIID(riid, &IID_IShellExecuteHookW))
164 *ppvObject = &This->IShellExecuteHookW_iface;
165 else if (IsEqualIID(riid, &IID_IShellExecuteHookA))
166 *ppvObject = &This->IShellExecuteHookA_iface;
168 if (*ppvObject) {
169 IUnknown_AddRef((IUnknown *)(*ppvObject));
170 TRACE("-- Interface:(%p)->(%p)\n", ppvObject, *ppvObject);
171 return S_OK;
173 TRACE("-- Interface: E_NOINTERFACE\n");
174 return E_NOINTERFACE;
177 static ULONG WINAPI ISF_ControlPanel_fnAddRef(IShellFolder2 *iface)
179 ICPanelImpl *This = impl_from_IShellFolder2(iface);
180 ULONG refCount = InterlockedIncrement(&This->ref);
182 TRACE("(%p)->(count=%lu)\n", This, refCount - 1);
184 return refCount;
187 static ULONG WINAPI ISF_ControlPanel_fnRelease(IShellFolder2 *iface)
189 ICPanelImpl *This = impl_from_IShellFolder2(iface);
190 ULONG refCount = InterlockedDecrement(&This->ref);
192 TRACE("(%p)->(count=%lu)\n", This, refCount + 1);
194 if (!refCount) {
195 TRACE("-- destroying IShellFolder(%p)\n", This);
196 SHFree(This->pidlRoot);
197 LocalFree(This);
199 return refCount;
202 /**************************************************************************
203 * ISF_ControlPanel_fnParseDisplayName
205 static HRESULT WINAPI ISF_ControlPanel_fnParseDisplayName(IShellFolder2 *iface, HWND hwndOwner,
206 LPBC pbc, LPOLESTR lpszDisplayName, DWORD *pchEaten, LPITEMIDLIST *ppidl,
207 DWORD *pdwAttributes)
209 ICPanelImpl *This = impl_from_IShellFolder2(iface);
211 HRESULT hr = E_INVALIDARG;
213 FIXME("(%p)->(HWND=%p,%p,%p=%s,%p,pidl=%p,%p)\n",
214 This, hwndOwner, pbc, lpszDisplayName, debugstr_w(lpszDisplayName), pchEaten, ppidl, pdwAttributes);
216 *ppidl = 0;
217 if (pchEaten)
218 *pchEaten = 0;
220 TRACE("(%p)->(-- ret=0x%08lx)\n", This, hr);
222 return hr;
225 static LPITEMIDLIST _ILCreateCPanelApplet(LPCSTR name, LPCSTR displayName,
226 LPCSTR comment, int iconIdx)
228 PIDLCPanelStruct *p;
229 LPITEMIDLIST pidl;
230 PIDLDATA tmp;
231 int size0 = (char*)tmp.u.cpanel.szName-(char*)&tmp.u.cpanel;
232 int size = size0;
233 int l;
235 tmp.type = PT_CPLAPPLET;
236 tmp.u.cpanel.dummy = 0;
237 tmp.u.cpanel.iconIdx = iconIdx;
239 l = strlen(name);
240 size += l+1;
242 tmp.u.cpanel.offsDispName = l+1;
243 l = strlen(displayName);
244 size += l+1;
246 tmp.u.cpanel.offsComment = tmp.u.cpanel.offsDispName+1+l;
247 l = strlen(comment);
248 size += l+1;
250 pidl = SHAlloc(size+4);
251 if (!pidl)
252 return NULL;
254 pidl->mkid.cb = size+2;
255 memcpy(pidl->mkid.abID, &tmp, 2+size0);
257 p = &((PIDLDATA*)pidl->mkid.abID)->u.cpanel;
258 memcpy(p->szName, name, strlen(name) + 1);
259 memcpy(p->szName+tmp.u.cpanel.offsDispName, displayName, strlen(displayName) + 1);
260 memcpy(p->szName+tmp.u.cpanel.offsComment, comment, strlen(comment) + 1);
262 *(WORD*)((char*)pidl+(size+2)) = 0;
264 pcheck(pidl);
266 return pidl;
269 /**************************************************************************
270 * _ILGetCPanelPointer()
271 * gets a pointer to the control panel struct stored in the pidl
273 static PIDLCPanelStruct* _ILGetCPanelPointer(LPCITEMIDLIST pidl)
275 LPPIDLDATA pdata = _ILGetDataPointer(pidl);
277 if (pdata && pdata->type==PT_CPLAPPLET)
278 return &pdata->u.cpanel;
280 return NULL;
283 /**************************************************************************
284 * ISF_ControlPanel_fnEnumObjects
286 static BOOL SHELL_RegisterCPanelApp(IEnumIDListImpl *list, LPCSTR path)
288 LPITEMIDLIST pidl;
289 CPlApplet* applet;
290 CPanel panel;
291 CPLINFO info;
292 unsigned i;
293 int iconIdx;
295 char displayName[MAX_PATH];
296 char comment[MAX_PATH];
298 WCHAR wpath[MAX_PATH];
300 MultiByteToWideChar(CP_ACP, 0, path, -1, wpath, MAX_PATH);
302 list_init( &panel.applets );
303 applet = Control_LoadApplet(0, wpath, &panel);
305 if (applet)
307 for(i=0; i<applet->count; ++i)
309 WideCharToMultiByte(CP_ACP, 0, applet->info[i].name, -1, displayName, MAX_PATH, 0, 0);
310 WideCharToMultiByte(CP_ACP, 0, applet->info[i].info, -1, comment, MAX_PATH, 0, 0);
312 applet->proc(0, CPL_INQUIRE, i, (LPARAM)&info);
314 if (info.idIcon > 0)
315 iconIdx = -info.idIcon; /* negative icon index instead of icon number */
316 else
317 iconIdx = 0;
319 pidl = _ILCreateCPanelApplet(path, displayName, comment, iconIdx);
321 if (pidl)
322 AddToEnumList(list, pidl);
324 Control_UnloadApplet(applet);
326 return TRUE;
329 static int SHELL_RegisterRegistryCPanelApps(IEnumIDListImpl *list, HKEY hkey_root, LPCSTR szRepPath)
331 char name[MAX_PATH];
332 char value[MAX_PATH];
333 HKEY hkey;
335 int cnt = 0;
337 if (RegOpenKeyA(hkey_root, szRepPath, &hkey) == ERROR_SUCCESS)
339 int idx = 0;
341 for(;; ++idx)
343 DWORD nameLen = MAX_PATH;
344 DWORD valueLen = MAX_PATH;
346 if (RegEnumValueA(hkey, idx, name, &nameLen, NULL, NULL, (LPBYTE)value, &valueLen) != ERROR_SUCCESS)
347 break;
349 if (SHELL_RegisterCPanelApp(list, value))
350 ++cnt;
352 RegCloseKey(hkey);
355 return cnt;
358 static int SHELL_RegisterCPanelFolders(IEnumIDListImpl *list, HKEY hkey_root, const WCHAR *reg_path)
360 char name[MAX_PATH];
361 HKEY hkey;
363 int cnt = 0;
365 if (RegOpenKeyW(hkey_root, reg_path, &hkey) == ERROR_SUCCESS)
367 int idx = 0;
368 for(;; ++idx)
370 if (RegEnumKeyA(hkey, idx, name, MAX_PATH) != ERROR_SUCCESS)
371 break;
373 if (*name == '{')
375 LPITEMIDLIST pidl = _ILCreateGuidFromStrA(name);
377 if (pidl && AddToEnumList(list, pidl))
378 ++cnt;
382 RegCloseKey(hkey);
385 return cnt;
388 /**************************************************************************
389 * CreateCPanelEnumList()
391 static BOOL CreateCPanelEnumList(IEnumIDListImpl *list, DWORD dwFlags)
393 CHAR szPath[MAX_PATH];
394 WIN32_FIND_DATAA wfd;
395 HANDLE hFile;
397 TRACE("(%p)->(flags=0x%08lx)\n", list, dwFlags);
399 /* enumerate control panel folders */
400 if (dwFlags & SHCONTF_FOLDERS)
401 SHELL_RegisterCPanelFolders(list, HKEY_LOCAL_MACHINE, name_spaceW);
403 /* enumerate the control panel applets */
404 if (dwFlags & SHCONTF_NONFOLDERS)
406 LPSTR p;
408 GetSystemDirectoryA(szPath, MAX_PATH);
409 p = PathAddBackslashA(szPath);
410 strcpy(p, "*.cpl");
412 TRACE("-- (%p)-> enumerate SHCONTF_NONFOLDERS of %s\n", list, debugstr_a(szPath));
413 hFile = FindFirstFileA(szPath, &wfd);
415 if (hFile != INVALID_HANDLE_VALUE)
419 if (!(dwFlags & SHCONTF_INCLUDEHIDDEN) && (wfd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN))
420 continue;
422 if (!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
423 strcpy(p, wfd.cFileName);
424 SHELL_RegisterCPanelApp(list, szPath);
426 } while(FindNextFileA(hFile, &wfd));
427 FindClose(hFile);
430 SHELL_RegisterRegistryCPanelApps(list, HKEY_LOCAL_MACHINE,
431 "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Control Panel\\Cpls");
432 SHELL_RegisterRegistryCPanelApps(list, HKEY_CURRENT_USER,
433 "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Control Panel\\Cpls");
435 return TRUE;
438 /**************************************************************************
439 * ISF_ControlPanel_fnEnumObjects
441 static HRESULT WINAPI ISF_ControlPanel_fnEnumObjects(IShellFolder2 *iface, HWND hwndOwner,
442 DWORD dwFlags, LPENUMIDLIST *ppEnumIDList)
444 ICPanelImpl *This = impl_from_IShellFolder2(iface);
445 IEnumIDListImpl *list;
447 TRACE("(%p)->(HWND=%p flags=0x%08lx pplist=%p)\n", This, hwndOwner, dwFlags, ppEnumIDList);
449 if (!(list = IEnumIDList_Constructor()))
450 return E_OUTOFMEMORY;
451 CreateCPanelEnumList(list, dwFlags);
452 *ppEnumIDList = &list->IEnumIDList_iface;
454 TRACE("--(%p)->(new ID List: %p)\n", This, *ppEnumIDList);
456 return S_OK;
459 /**************************************************************************
460 * ISF_ControlPanel_fnBindToObject
462 static HRESULT WINAPI ISF_ControlPanel_fnBindToObject(IShellFolder2 *iface, LPCITEMIDLIST pidl,
463 LPBC pbcReserved, REFIID riid, void **ppvOut)
465 ICPanelImpl *This = impl_from_IShellFolder2(iface);
467 TRACE("(%p)->(pidl=%p,%p,%s,%p)\n", This, pidl, pbcReserved, shdebugstr_guid(riid), ppvOut);
469 return SHELL32_BindToChild(This->pidlRoot, &CLSID_ShellFSFolder, NULL, pidl, riid, ppvOut);
472 /**************************************************************************
473 * ISF_ControlPanel_fnBindToStorage
475 static HRESULT WINAPI ISF_ControlPanel_fnBindToStorage(IShellFolder2 *iface, LPCITEMIDLIST pidl,
476 LPBC pbcReserved, REFIID riid, void **ppvOut)
478 ICPanelImpl *This = impl_from_IShellFolder2(iface);
480 FIXME("(%p)->(pidl=%p,%p,%s,%p) stub\n", This, pidl, pbcReserved, shdebugstr_guid(riid), ppvOut);
482 *ppvOut = NULL;
483 return E_NOTIMPL;
486 /**************************************************************************
487 * ISF_ControlPanel_fnCompareIDs
490 static HRESULT WINAPI ISF_ControlPanel_fnCompareIDs(IShellFolder2 *iface, LPARAM lParam,
491 LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
493 ICPanelImpl *This = impl_from_IShellFolder2(iface);
495 int nReturn;
497 TRACE("(%p)->(0x%08Ix,pidl1=%p,pidl2=%p)\n", This, lParam, pidl1, pidl2);
498 nReturn = SHELL32_CompareIDs(&This->IShellFolder2_iface, lParam, pidl1, pidl2);
499 TRACE("-- %i\n", nReturn);
500 return nReturn;
503 /**************************************************************************
504 * ISF_ControlPanel_fnCreateViewObject
506 static HRESULT WINAPI ISF_ControlPanel_fnCreateViewObject(IShellFolder2 *iface, HWND hwndOwner,
507 REFIID riid, void **ppvOut)
509 ICPanelImpl *This = impl_from_IShellFolder2(iface);
511 LPSHELLVIEW pShellView;
512 HRESULT hr = E_INVALIDARG;
514 TRACE("(%p)->(hwnd=%p,%s,%p)\n", This, hwndOwner, shdebugstr_guid(riid), ppvOut);
516 if (ppvOut) {
517 *ppvOut = NULL;
519 if (IsEqualIID(riid, &IID_IDropTarget)) {
520 WARN("IDropTarget not implemented\n");
521 hr = E_NOTIMPL;
522 } else if (IsEqualIID(riid, &IID_IShellView)) {
523 pShellView = IShellView_Constructor((IShellFolder *) iface);
524 if (pShellView) {
525 hr = IShellView_QueryInterface(pShellView, riid, ppvOut);
526 IShellView_Release(pShellView);
528 } else {
529 FIXME("invalid/unsupported interface %s\n", shdebugstr_guid(riid));
530 hr = E_NOINTERFACE;
533 TRACE("--(%p)->(interface=%p)\n", This, ppvOut);
534 return hr;
537 static BOOL validate_name_space(const ITEMIDLIST *pidl)
539 HKEY hkey, hitem;
540 WCHAR *guidW;
541 GUID *guid;
542 LSTATUS r;
544 if (!_ILIsPidlSimple(pidl))
545 return FALSE;
547 guid = _ILGetGUIDPointer(pidl);
548 if (!guid)
549 return FALSE;
550 if (StringFromCLSID(guid, &guidW) != S_OK)
551 return FALSE;
553 r = RegOpenKeyW(HKEY_LOCAL_MACHINE, name_spaceW, &hkey);
554 if (r == ERROR_SUCCESS)
556 r = RegOpenKeyW(hkey, guidW, &hitem);
557 if (r == ERROR_SUCCESS)
558 RegCloseKey(hitem);
559 RegCloseKey(hkey);
561 CoTaskMemFree(guidW);
562 return r == ERROR_SUCCESS;
565 /**************************************************************************
566 * ISF_ControlPanel_fnGetAttributesOf
568 static HRESULT WINAPI ISF_ControlPanel_fnGetAttributesOf(IShellFolder2 *iface, UINT cidl,
569 LPCITEMIDLIST *apidl, DWORD *rgfInOut)
571 ICPanelImpl *This = impl_from_IShellFolder2(iface);
573 HRESULT hr = S_OK;
575 TRACE("(%p)->(cidl=%d apidl=%p mask=%p (0x%08lx))\n",
576 This, cidl, apidl, rgfInOut, rgfInOut ? *rgfInOut : 0);
578 if (!rgfInOut)
579 return E_INVALIDARG;
580 if (cidl && !apidl)
581 return E_INVALIDARG;
583 if (*rgfInOut == 0)
584 *rgfInOut = ~0;
586 while(cidl > 0 && *apidl) {
587 pdump(*apidl);
589 /* TODO: panel with GUID can contain sub-items but we don't support it yet */
590 if (!(*rgfInOut & SFGAO_VALIDATE) || _ILGetCPanelPointer(*apidl)
591 || validate_name_space(*apidl))
592 *rgfInOut &= SFGAO_CANLINK;
593 else
594 *rgfInOut &= SFGAO_VALIDATE;
596 apidl++;
597 cidl--;
600 TRACE("-- result=0x%08lx\n", *rgfInOut);
601 return hr;
604 /**************************************************************************
605 * ISF_ControlPanel_fnGetUIObjectOf
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
616 static HRESULT WINAPI ISF_ControlPanel_fnGetUIObjectOf(IShellFolder2 *iface, HWND hwndOwner,
617 UINT cidl, LPCITEMIDLIST *apidl, REFIID riid, UINT *prgfInOut, void **ppvOut)
619 ICPanelImpl *This = impl_from_IShellFolder2(iface);
621 LPITEMIDLIST pidl;
622 IUnknown *pObj = NULL;
623 HRESULT hr = E_INVALIDARG;
625 TRACE("(%p)->(%p,%u,apidl=%p,%s,%p,%p)\n",
626 This, hwndOwner, cidl, apidl, shdebugstr_guid(riid), prgfInOut, ppvOut);
628 if (ppvOut) {
629 *ppvOut = NULL;
631 if (IsEqualIID(riid, &IID_IContextMenu) &&(cidl >= 1)) {
632 return ItemMenu_Constructor((IShellFolder*)iface, This->pidlRoot, apidl, cidl, riid, ppvOut);
633 } else if (IsEqualIID(riid, &IID_IDataObject) &&(cidl >= 1)) {
634 pObj = (LPUNKNOWN) IDataObject_Constructor(hwndOwner, This->pidlRoot, apidl, cidl);
635 hr = S_OK;
636 } else if (IsEqualIID(riid, &IID_IExtractIconA) &&(cidl == 1)) {
637 pidl = ILCombine(This->pidlRoot, apidl[0]);
638 pObj = (LPUNKNOWN) IExtractIconA_Constructor(pidl);
639 ILFree(pidl);
640 hr = S_OK;
641 } else if (IsEqualIID(riid, &IID_IExtractIconW) &&(cidl == 1)) {
642 pidl = ILCombine(This->pidlRoot, apidl[0]);
643 pObj = (LPUNKNOWN) IExtractIconW_Constructor(pidl);
644 ILFree(pidl);
645 hr = S_OK;
646 } else if ((IsEqualIID(riid,&IID_IShellLinkW) || IsEqualIID(riid,&IID_IShellLinkA))
647 && (cidl == 1)) {
648 pidl = ILCombine(This->pidlRoot, apidl[0]);
649 hr = IShellLink_ConstructFromFile(NULL, riid, pidl, &pObj);
650 ILFree(pidl);
651 } else {
652 hr = E_NOINTERFACE;
655 if (SUCCEEDED(hr) && !pObj)
656 hr = E_OUTOFMEMORY;
658 *ppvOut = pObj;
660 TRACE("(%p)->hr=0x%08lx\n", This, hr);
661 return hr;
664 /**************************************************************************
665 * ISF_ControlPanel_fnGetDisplayNameOf
667 static HRESULT WINAPI ISF_ControlPanel_fnGetDisplayNameOf(IShellFolder2 *iface, LPCITEMIDLIST pidl,
668 DWORD dwFlags, LPSTRRET strRet)
670 ICPanelImpl *This = impl_from_IShellFolder2(iface);
672 CHAR szPath[MAX_PATH];
673 WCHAR wszPath[MAX_PATH+1]; /* +1 for potential backslash */
674 PIDLCPanelStruct* pcpanel;
676 *szPath = '\0';
678 TRACE("(%p)->(pidl=%p,0x%08lx,%p)\n", This, pidl, dwFlags, strRet);
679 pdump(pidl);
681 if (!pidl || !strRet)
682 return E_INVALIDARG;
684 pcpanel = _ILGetCPanelPointer(pidl);
686 if (pcpanel) {
687 lstrcpyA(szPath, pcpanel->szName+pcpanel->offsDispName);
689 if (!(dwFlags & SHGDN_FORPARSING))
690 FIXME("retrieve display name from control panel app\n");
692 /* take names of special folders only if it's only this folder */
693 else if (_ILIsSpecialFolder(pidl)) {
694 BOOL bSimplePidl = _ILIsPidlSimple(pidl);
696 if (bSimplePidl) {
697 _ILSimpleGetTextW(pidl, wszPath, MAX_PATH); /* append my own path */
698 } else {
699 FIXME("special pidl\n");
702 if ((dwFlags & SHGDN_FORPARSING) && !bSimplePidl) { /* go deeper if needed */
703 int len = 0;
705 PathAddBackslashW(wszPath);
706 len = lstrlenW(wszPath);
708 if (FAILED(SHELL32_GetDisplayNameOfChild(iface, pidl, dwFlags | SHGDN_INFOLDER, wszPath + len, MAX_PATH + 1 - len)))
709 return E_OUTOFMEMORY;
710 if (!WideCharToMultiByte(CP_ACP, 0, wszPath, -1, szPath, MAX_PATH, NULL, NULL))
711 wszPath[0] = '\0';
715 strRet->uType = STRRET_CSTR;
716 lstrcpynA(strRet->cStr, szPath, MAX_PATH);
718 TRACE("--(%p)->(%s)\n", This, szPath);
719 return S_OK;
722 /**************************************************************************
723 * ISF_ControlPanel_fnSetNameOf
724 * Changes the name of a file object or subfolder, possibly changing its item
725 * identifier in the process.
727 * PARAMETERS
728 * HWND hwndOwner, //[in ] Owner window for output
729 * LPCITEMIDLIST pidl, //[in ] simple pidl of item to change
730 * LPCOLESTR lpszName, //[in ] the items new display name
731 * DWORD dwFlags, //[in ] SHGNO formatting flags
732 * LPITEMIDLIST* ppidlOut) //[out] simple pidl returned
734 static HRESULT WINAPI ISF_ControlPanel_fnSetNameOf(IShellFolder2 *iface, HWND hwndOwner,
735 LPCITEMIDLIST pidl, LPCOLESTR lpName, DWORD dwFlags, LPITEMIDLIST *pPidlOut)
737 ICPanelImpl *This = impl_from_IShellFolder2(iface);
738 FIXME("(%p)->(%p,pidl=%p,%s,%lu,%p)\n", This, hwndOwner, pidl, debugstr_w(lpName), dwFlags, pPidlOut);
739 return E_FAIL;
742 static HRESULT WINAPI ISF_ControlPanel_fnGetDefaultSearchGUID(IShellFolder2 *iface, GUID *guid)
744 ICPanelImpl *This = impl_from_IShellFolder2(iface);
745 TRACE("(%p)->(%p)\n", This, guid);
746 return E_NOTIMPL;
749 static HRESULT WINAPI ISF_ControlPanel_fnEnumSearches(IShellFolder2 *iface,
750 IEnumExtraSearch **ppenum)
752 ICPanelImpl *This = impl_from_IShellFolder2(iface);
753 FIXME("(%p)\n", This);
754 return E_NOTIMPL;
757 static HRESULT WINAPI ISF_ControlPanel_fnGetDefaultColumn(IShellFolder2 *iface, DWORD reserved,
758 ULONG *sort, ULONG *display)
760 ICPanelImpl *This = impl_from_IShellFolder2(iface);
762 TRACE("(%p)->(%#lx %p %p)\n", This, reserved, sort, display);
764 return E_NOTIMPL;
767 static HRESULT WINAPI ISF_ControlPanel_fnGetDefaultColumnState(IShellFolder2 *iface, UINT iColumn,
768 DWORD *pcsFlags)
770 ICPanelImpl *This = impl_from_IShellFolder2(iface);
772 TRACE("(%p)\n", This);
774 if (!pcsFlags || iColumn >= CONROLPANELSHELLVIEWCOLUMNS) return E_INVALIDARG;
775 *pcsFlags = ControlPanelSFHeader[iColumn].pcsFlags;
776 return S_OK;
778 static HRESULT WINAPI ISF_ControlPanel_fnGetDetailsEx(IShellFolder2 *iface, LPCITEMIDLIST pidl,
779 const SHCOLUMNID *pscid, VARIANT *pv)
781 ICPanelImpl *This = impl_from_IShellFolder2(iface);
782 FIXME("(%p)\n", This);
783 return E_NOTIMPL;
786 static HRESULT WINAPI ISF_ControlPanel_fnGetDetailsOf(IShellFolder2 *iface, LPCITEMIDLIST pidl,
787 UINT iColumn, SHELLDETAILS *psd)
789 ICPanelImpl *This = impl_from_IShellFolder2(iface);
790 PIDLCPanelStruct* pcpanel;
792 TRACE("(%p)->(%p %i %p)\n", This, pidl, iColumn, psd);
794 if (!psd || iColumn >= CONROLPANELSHELLVIEWCOLUMNS)
795 return E_INVALIDARG;
797 if (!pidl)
798 return SHELL32_GetColumnDetails(ControlPanelSFHeader, iColumn, psd);
800 psd->str.cStr[0] = 0x00;
801 psd->str.uType = STRRET_CSTR;
802 switch(iColumn)
804 case 1: /* comment */
805 pcpanel = _ILGetCPanelPointer(pidl);
807 if (pcpanel)
808 lstrcpyA(psd->str.cStr, pcpanel->szName+pcpanel->offsComment);
809 else
810 _ILGetFileType(pidl, psd->str.cStr, MAX_PATH);
811 break;
813 default:
814 return shellfolder_get_file_details( iface, pidl, ControlPanelSFHeader, iColumn, psd );
816 return S_OK;
818 static HRESULT WINAPI ISF_ControlPanel_fnMapColumnToSCID(IShellFolder2 *iface, UINT column,
819 SHCOLUMNID *pscid)
821 ICPanelImpl *This = impl_from_IShellFolder2(iface);
822 FIXME("(%p)\n", This);
823 return E_NOTIMPL;
826 static const IShellFolder2Vtbl vt_ShellFolder2 =
829 ISF_ControlPanel_fnQueryInterface,
830 ISF_ControlPanel_fnAddRef,
831 ISF_ControlPanel_fnRelease,
832 ISF_ControlPanel_fnParseDisplayName,
833 ISF_ControlPanel_fnEnumObjects,
834 ISF_ControlPanel_fnBindToObject,
835 ISF_ControlPanel_fnBindToStorage,
836 ISF_ControlPanel_fnCompareIDs,
837 ISF_ControlPanel_fnCreateViewObject,
838 ISF_ControlPanel_fnGetAttributesOf,
839 ISF_ControlPanel_fnGetUIObjectOf,
840 ISF_ControlPanel_fnGetDisplayNameOf,
841 ISF_ControlPanel_fnSetNameOf,
843 /* ShellFolder2 */
844 ISF_ControlPanel_fnGetDefaultSearchGUID,
845 ISF_ControlPanel_fnEnumSearches,
846 ISF_ControlPanel_fnGetDefaultColumn,
847 ISF_ControlPanel_fnGetDefaultColumnState,
848 ISF_ControlPanel_fnGetDetailsEx,
849 ISF_ControlPanel_fnGetDetailsOf,
850 ISF_ControlPanel_fnMapColumnToSCID
853 /************************************************************************
854 * ICPanel_PersistFolder2_QueryInterface
856 static HRESULT WINAPI ICPanel_PersistFolder2_QueryInterface(IPersistFolder2 * iface, REFIID iid, LPVOID * ppvObject)
858 ICPanelImpl *This = impl_from_IPersistFolder2(iface);
860 TRACE("(%p)\n", This);
862 return IShellFolder2_QueryInterface(&This->IShellFolder2_iface, iid, ppvObject);
865 /************************************************************************
866 * ICPanel_PersistFolder2_AddRef
868 static ULONG WINAPI ICPanel_PersistFolder2_AddRef(IPersistFolder2 * iface)
870 ICPanelImpl *This = impl_from_IPersistFolder2(iface);
872 TRACE("(%p)->(count=%lu)\n", This, This->ref);
874 return IShellFolder2_AddRef(&This->IShellFolder2_iface);
877 /************************************************************************
878 * ISFPersistFolder_Release
880 static ULONG WINAPI ICPanel_PersistFolder2_Release(IPersistFolder2 * iface)
882 ICPanelImpl *This = impl_from_IPersistFolder2(iface);
884 TRACE("(%p)->(count=%lu)\n", This, This->ref);
886 return IShellFolder2_Release(&This->IShellFolder2_iface);
889 /************************************************************************
890 * ICPanel_PersistFolder2_GetClassID
892 static HRESULT WINAPI ICPanel_PersistFolder2_GetClassID(IPersistFolder2 * iface, CLSID * lpClassId)
894 ICPanelImpl *This = impl_from_IPersistFolder2(iface);
896 TRACE("(%p)\n", This);
898 if (!lpClassId)
899 return E_POINTER;
900 *lpClassId = CLSID_ControlPanel;
902 return S_OK;
905 /************************************************************************
906 * ICPanel_PersistFolder2_Initialize
908 * NOTES: it makes no sense to change the pidl
910 static HRESULT WINAPI ICPanel_PersistFolder2_Initialize(IPersistFolder2 * iface, LPCITEMIDLIST pidl)
912 ICPanelImpl *This = impl_from_IPersistFolder2(iface);
913 TRACE("(%p)->(%p)\n", This, pidl);
914 return E_NOTIMPL;
917 /**************************************************************************
918 * IPersistFolder2_fnGetCurFolder
920 static HRESULT WINAPI ICPanel_PersistFolder2_GetCurFolder(IPersistFolder2 * iface, LPITEMIDLIST * pidl)
922 ICPanelImpl *This = impl_from_IPersistFolder2(iface);
924 TRACE("(%p)->(%p)\n", This, pidl);
926 if (!pidl)
927 return E_POINTER;
928 *pidl = ILClone(This->pidlRoot);
929 return S_OK;
932 static const IPersistFolder2Vtbl vt_PersistFolder2 =
935 ICPanel_PersistFolder2_QueryInterface,
936 ICPanel_PersistFolder2_AddRef,
937 ICPanel_PersistFolder2_Release,
938 ICPanel_PersistFolder2_GetClassID,
939 ICPanel_PersistFolder2_Initialize,
940 ICPanel_PersistFolder2_GetCurFolder
943 HRESULT CPanel_GetIconLocationW(LPCITEMIDLIST pidl,
944 LPWSTR szIconFile, UINT cchMax, int* piIndex)
946 PIDLCPanelStruct* pcpanel = _ILGetCPanelPointer(pidl);
948 if (!pcpanel)
949 return E_INVALIDARG;
951 MultiByteToWideChar(CP_ACP, 0, pcpanel->szName, -1, szIconFile, cchMax);
952 *piIndex = pcpanel->iconIdx!=-1? pcpanel->iconIdx: 0;
954 return S_OK;
958 /**************************************************************************
959 * IShellExecuteHookW Implementation
962 static HRESULT WINAPI IShellExecuteHookW_fnQueryInterface(
963 IShellExecuteHookW* iface, REFIID riid, void** ppvObject)
965 ICPanelImpl *This = impl_from_IShellExecuteHookW(iface);
967 TRACE("(%p)->(count=%lu)\n", This, This->ref);
969 return IUnknown_QueryInterface(This->pUnkOuter, riid, ppvObject);
972 static ULONG STDMETHODCALLTYPE IShellExecuteHookW_fnAddRef(IShellExecuteHookW* iface)
974 ICPanelImpl *This = impl_from_IShellExecuteHookW(iface);
976 TRACE("(%p)->(count=%lu)\n", This, This->ref);
978 return IUnknown_AddRef(This->pUnkOuter);
981 static ULONG STDMETHODCALLTYPE IShellExecuteHookW_fnRelease(IShellExecuteHookW* iface)
983 ICPanelImpl *This = impl_from_IShellExecuteHookW(iface);
985 TRACE("(%p)\n", This);
987 return IUnknown_Release(This->pUnkOuter);
990 static HRESULT WINAPI IShellExecuteHookW_fnExecute(IShellExecuteHookW *iface,
991 LPSHELLEXECUTEINFOW psei)
993 ICPanelImpl *This = impl_from_IShellExecuteHookW(iface);
994 SHELLEXECUTEINFOW sei_tmp;
995 PIDLCPanelStruct* pcpanel;
996 WCHAR path[MAX_PATH];
997 WCHAR params[MAX_PATH];
998 BOOL ret;
999 int l;
1001 TRACE("(%p)->execute(%p)\n", This, psei);
1003 if (!psei)
1004 return E_INVALIDARG;
1006 pcpanel = _ILGetCPanelPointer(ILFindLastID(psei->lpIDList));
1008 if (!pcpanel)
1009 return E_INVALIDARG;
1011 path[0] = '\"';
1012 /* Return value from MultiByteToWideChar includes terminating NUL, which
1013 * compensates for the starting double quote we just put in */
1014 l = MultiByteToWideChar(CP_ACP, 0, pcpanel->szName, -1, path+1, MAX_PATH-1);
1016 /* pass applet name to Control_RunDLL to distinguish between applets in one .cpl file */
1017 path[l++] = '"';
1018 path[l] = '\0';
1020 MultiByteToWideChar(CP_ACP, 0, pcpanel->szName+pcpanel->offsDispName, -1, params, MAX_PATH);
1022 sei_tmp = *psei;
1023 sei_tmp.lpFile = path;
1024 sei_tmp.lpParameters = params;
1025 sei_tmp.fMask &= ~SEE_MASK_INVOKEIDLIST;
1026 sei_tmp.lpVerb = L"cplopen";
1028 ret = ShellExecuteExW(&sei_tmp);
1029 if (ret)
1030 return S_OK;
1031 else
1032 return S_FALSE;
1035 static const IShellExecuteHookWVtbl vt_ShellExecuteHookW =
1038 IShellExecuteHookW_fnQueryInterface,
1039 IShellExecuteHookW_fnAddRef,
1040 IShellExecuteHookW_fnRelease,
1042 IShellExecuteHookW_fnExecute
1046 /**************************************************************************
1047 * IShellExecuteHookA Implementation
1050 static HRESULT WINAPI IShellExecuteHookA_fnQueryInterface(IShellExecuteHookA* iface, REFIID riid, void** ppvObject)
1052 ICPanelImpl *This = impl_from_IShellExecuteHookA(iface);
1054 TRACE("(%p)->(count=%lu)\n", This, This->ref);
1056 return IUnknown_QueryInterface(This->pUnkOuter, riid, ppvObject);
1059 static ULONG STDMETHODCALLTYPE IShellExecuteHookA_fnAddRef(IShellExecuteHookA* iface)
1061 ICPanelImpl *This = impl_from_IShellExecuteHookA(iface);
1063 TRACE("(%p)->(count=%lu)\n", This, This->ref);
1065 return IUnknown_AddRef(This->pUnkOuter);
1068 static ULONG STDMETHODCALLTYPE IShellExecuteHookA_fnRelease(IShellExecuteHookA* iface)
1070 ICPanelImpl *This = impl_from_IShellExecuteHookA(iface);
1072 TRACE("(%p)\n", This);
1074 return IUnknown_Release(This->pUnkOuter);
1077 static HRESULT WINAPI IShellExecuteHookA_fnExecute(IShellExecuteHookA *iface,
1078 LPSHELLEXECUTEINFOA psei)
1080 ICPanelImpl *This = impl_from_IShellExecuteHookA(iface);
1082 SHELLEXECUTEINFOA sei_tmp;
1083 PIDLCPanelStruct* pcpanel;
1084 char path[MAX_PATH];
1085 BOOL ret;
1087 TRACE("(%p)->execute(%p)\n", This, psei);
1089 if (!psei)
1090 return E_INVALIDARG;
1092 pcpanel = _ILGetCPanelPointer(ILFindLastID(psei->lpIDList));
1094 if (!pcpanel)
1095 return E_INVALIDARG;
1097 path[0] = '\"';
1098 memcpy(path+1, pcpanel->szName, strlen(pcpanel->szName) + 1);
1100 /* pass applet name to Control_RunDLL to distinguish between applets in one .cpl file */
1101 lstrcatA(path, "\" ");
1102 lstrcatA(path, pcpanel->szName+pcpanel->offsDispName);
1104 sei_tmp = *psei;
1105 sei_tmp.lpFile = path;
1106 sei_tmp.fMask &= ~SEE_MASK_INVOKEIDLIST;
1108 ret = ShellExecuteExA(&sei_tmp);
1109 if (ret)
1110 return S_OK;
1111 else
1112 return S_FALSE;
1115 static const IShellExecuteHookAVtbl vt_ShellExecuteHookA =
1117 IShellExecuteHookA_fnQueryInterface,
1118 IShellExecuteHookA_fnAddRef,
1119 IShellExecuteHookA_fnRelease,
1120 IShellExecuteHookA_fnExecute