Version resources cleanup.
[wine/wine64.git] / dlls / shell32 / cpanelfolder.c
blob9a70dbda7289177d8a3d47bdbe97619fd96d5d82
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "config.h"
22 #include "wine/port.h"
24 #include <stdlib.h>
25 #include <string.h>
26 #include <stdarg.h>
27 #include <stdio.h>
29 #define COBJMACROS
30 #define NONAMELESSUNION
31 #define NONAMELESSSTRUCT
33 #include "winerror.h"
34 #include "windef.h"
35 #include "winbase.h"
36 #include "winreg.h"
37 #include "wingdi.h"
38 #include "winuser.h"
40 #include "ole2.h"
41 #include "shlguid.h"
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 "shellfolder.h"
51 #include "wine/debug.h"
52 #include "debughlp.h"
53 #include "shfldr.h"
55 WINE_DEFAULT_DEBUG_CHANNEL(shell);
57 /***********************************************************************
58 * control panel implementation in shell namespace
61 typedef struct {
62 IShellFolder2Vtbl *lpVtbl;
63 DWORD ref;
64 IPersistFolder2Vtbl *lpVtblPersistFolder2;
65 IShellExecuteHookWVtbl *lpVtblShellExecuteHookW;
66 IShellExecuteHookAVtbl *lpVtblShellExecuteHookA;
68 IUnknown *pUnkOuter; /* used for aggregation */
70 /* both paths are parsible from the desktop */
71 LPITEMIDLIST pidlRoot; /* absolute pidl */
72 int dwAttributes; /* attributes returned by GetAttributesOf FIXME: use it */
73 } ICPanelImpl;
75 static IShellFolder2Vtbl vt_ShellFolder2;
76 static IPersistFolder2Vtbl vt_PersistFolder2;
77 static IShellExecuteHookWVtbl vt_ShellExecuteHookW;
78 static IShellExecuteHookAVtbl vt_ShellExecuteHookA;
80 #define _IPersistFolder2_Offset ((int)(&(((ICPanelImpl*)0)->lpVtblPersistFolder2)))
81 #define _ICOM_THIS_From_IPersistFolder2(class, name) class* This = (class*)(((char*)name)-_IPersistFolder2_Offset);
83 #define IShellExecuteHookW_Offset ((int)(&(((ICPanelImpl*)0)->lpVtblShellExecuteHookW)))
84 #define _ICOM_THIS_From_IShellExecuteHookW(class, name) class* This = (class*)(((char*)name)-IShellExecuteHookW_Offset);
86 #define IShellExecuteHookA_Offset ((int)(&(((ICPanelImpl*)0)->lpVtblShellExecuteHookA)))
87 #define _ICOM_THIS_From_IShellExecuteHookA(class, name) class* This = (class*)(((char*)name)-IShellExecuteHookA_Offset);
91 converts This to a interface pointer
93 #define _IUnknown_(This) (IUnknown*)&(This->lpVtbl)
94 #define _IShellFolder_(This) (IShellFolder*)&(This->lpVtbl)
95 #define _IShellFolder2_(This) (IShellFolder2*)&(This->lpVtbl)
97 #define _IPersist_(This) (IPersist*)&(This->lpVtblPersistFolder2)
98 #define _IPersistFolder_(This) (IPersistFolder*)&(This->lpVtblPersistFolder2)
99 #define _IPersistFolder2_(This) (IPersistFolder2*)&(This->lpVtblPersistFolder2)
100 #define _IShellExecuteHookW_(This) (IShellExecuteHookW*)&(This->lpVtblShellExecuteHookW)
101 #define _IShellExecuteHookA_(This) (IShellExecuteHookA*)&(This->lpVtblShellExecuteHookA)
103 /***********************************************************************
104 * IShellFolder [ControlPanel] implementation
107 static shvheader ControlPanelSFHeader[] = {
108 {IDS_SHV_COLUMN8, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 15},/*FIXME*/
109 {IDS_SHV_COLUMN9, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 200},/*FIXME*/
112 #define CONROLPANELSHELLVIEWCOLUMNS 2
114 /**************************************************************************
115 * IControlPanel_Constructor
117 HRESULT WINAPI IControlPanel_Constructor(IUnknown* pUnkOuter, REFIID riid, LPVOID * ppv)
119 ICPanelImpl *sf;
121 TRACE("unkOut=%p %s\n", pUnkOuter, shdebugstr_guid(riid));
123 if (!ppv)
124 return E_POINTER;
125 if (pUnkOuter && !IsEqualIID (riid, &IID_IUnknown))
126 return CLASS_E_NOAGGREGATION;
128 sf = (ICPanelImpl *) LocalAlloc(GMEM_ZEROINIT, sizeof(ICPanelImpl));
129 if (!sf)
130 return E_OUTOFMEMORY;
132 sf->ref = 0;
133 sf->lpVtbl = &vt_ShellFolder2;
134 sf->lpVtblPersistFolder2 = &vt_PersistFolder2;
135 sf->lpVtblShellExecuteHookW = &vt_ShellExecuteHookW;
136 sf->lpVtblShellExecuteHookA = &vt_ShellExecuteHookA;
137 sf->pidlRoot = _ILCreateControlPanel(); /* my qualified pidl */
138 sf->pUnkOuter = pUnkOuter ? pUnkOuter : _IUnknown_ (sf);
140 if (!SUCCEEDED(IUnknown_QueryInterface(_IUnknown_(sf), riid, ppv))) {
141 IUnknown_Release(_IUnknown_(sf));
142 return E_NOINTERFACE;
145 TRACE("--(%p)\n", sf);
146 return S_OK;
149 /**************************************************************************
150 * ISF_ControlPanel_fnQueryInterface
152 * NOTES supports not IPersist/IPersistFolder
154 static HRESULT WINAPI ISF_ControlPanel_fnQueryInterface(IShellFolder2 * iface, REFIID riid, LPVOID * ppvObject)
156 ICPanelImpl *This = (ICPanelImpl *)iface;
158 TRACE("(%p)->(%s,%p)\n", This, shdebugstr_guid(riid), ppvObject);
160 *ppvObject = NULL;
162 if (IsEqualIID(riid, &IID_IUnknown) ||
163 IsEqualIID(riid, &IID_IShellFolder) || IsEqualIID(riid, &IID_IShellFolder2))
164 *ppvObject = This;
165 else if (IsEqualIID(riid, &IID_IPersist) ||
166 IsEqualIID(riid, &IID_IPersistFolder) || IsEqualIID(riid, &IID_IPersistFolder2))
167 *ppvObject = _IPersistFolder2_(This);
168 else if (IsEqualIID(riid, &IID_IShellExecuteHookW))
169 *ppvObject = _IShellExecuteHookW_(This);
170 else if (IsEqualIID(riid, &IID_IShellExecuteHookA))
171 *ppvObject = _IShellExecuteHookA_(This);
173 if (*ppvObject) {
174 IUnknown_AddRef((IUnknown *)(*ppvObject));
175 TRACE("-- Interface:(%p)->(%p)\n", ppvObject, *ppvObject);
176 return S_OK;
178 TRACE("-- Interface: E_NOINTERFACE\n");
179 return E_NOINTERFACE;
182 static ULONG WINAPI ISF_ControlPanel_fnAddRef(IShellFolder2 * iface)
184 ICPanelImpl *This = (ICPanelImpl *)iface;
186 TRACE("(%p)->(count=%lu)\n", This, This->ref);
188 return ++(This->ref);
191 static ULONG WINAPI ISF_ControlPanel_fnRelease(IShellFolder2 * iface)
193 ICPanelImpl *This = (ICPanelImpl *)iface;
195 TRACE("(%p)->(count=%lu)\n", This, This->ref);
197 if (!--(This->ref)) {
198 TRACE("-- destroying IShellFolder(%p)\n", This);
199 if (This->pidlRoot)
200 SHFree(This->pidlRoot);
201 LocalFree((HLOCAL) This);
202 return 0;
204 return This->ref;
207 /**************************************************************************
208 * ISF_ControlPanel_fnParseDisplayName
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)
217 ICPanelImpl *This = (ICPanelImpl *)iface;
219 HRESULT hr = E_INVALIDARG;
221 FIXME("(%p)->(HWND=%p,%p,%p=%s,%p,pidl=%p,%p)\n",
222 This, hwndOwner, pbc, lpszDisplayName, debugstr_w(lpszDisplayName), pchEaten, ppidl, pdwAttributes);
224 *ppidl = 0;
225 if (pchEaten)
226 *pchEaten = 0;
228 TRACE("(%p)->(-- ret=0x%08lx)\n", This, hr);
230 return hr;
233 static LPITEMIDLIST _ILCreateCPanelApplet(LPCSTR name, LPCSTR displayName,
234 LPCSTR comment, int iconIdx)
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;
243 tmp.type = PT_CPLAPPLET;
244 tmp.u.cpanel.dummy = 0;
245 tmp.u.cpanel.iconIdx = iconIdx;
247 l = strlen(name);
248 size += l+1;
250 tmp.u.cpanel.offsDispName = l+1;
251 l = strlen(displayName);
252 size += l+1;
254 tmp.u.cpanel.offsComment = tmp.u.cpanel.offsDispName+1+l;
255 l = strlen(comment);
256 size += l+1;
258 pidl = SHAlloc(size+4);
259 if (!pidl)
260 return NULL;
262 pidl->mkid.cb = size+2;
263 memcpy(pidl->mkid.abID, &tmp, 2+size0);
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);
270 *(WORD*)((char*)pidl+(size+2)) = 0;
272 pcheck(pidl);
274 return pidl;
277 /**************************************************************************
278 * _ILGetCPanelPointer()
279 * gets a pointer to the control panel struct stored in the pidl
281 static PIDLCPanelStruct* _ILGetCPanelPointer(LPCITEMIDLIST pidl)
283 LPPIDLDATA pdata = _ILGetDataPointer(pidl);
285 if (pdata && pdata->type==PT_CPLAPPLET)
286 return (PIDLCPanelStruct*)&(pdata->u.cpanel);
288 return NULL;
291 /**************************************************************************
292 * ISF_ControlPanel_fnEnumObjects
294 static BOOL SHELL_RegisterCPanelApp(IEnumIDList* list, LPCSTR path)
296 LPITEMIDLIST pidl;
297 CPlApplet* applet;
298 CPanel panel;
299 CPLINFO info;
300 unsigned i;
301 int iconIdx;
303 char displayName[MAX_PATH];
304 char comment[MAX_PATH];
306 WCHAR wpath[MAX_PATH];
308 MultiByteToWideChar(CP_ACP, 0, path, -1, wpath, MAX_PATH);
310 panel.first = NULL;
311 applet = Control_LoadApplet(0, wpath, &panel);
313 if (applet)
315 for(i=0; i<applet->count; ++i)
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);
320 applet->proc(0, CPL_INQUIRE, i, (LPARAM)&info);
322 if (info.idIcon > 0)
323 iconIdx = -info.idIcon; /* negative icon index instead of icon number */
324 else
325 iconIdx = 0;
327 pidl = _ILCreateCPanelApplet(path, displayName, comment, iconIdx);
329 if (pidl)
330 AddToEnumList(list, pidl);
332 Control_UnloadApplet(applet);
334 return TRUE;
337 static int SHELL_RegisterRegistryCPanelApps(IEnumIDList* list, HKEY hkey_root, LPCSTR szRepPath)
339 char name[MAX_PATH];
340 char value[MAX_PATH];
341 HKEY hkey;
343 int cnt = 0;
345 if (RegOpenKeyA(hkey_root, szRepPath, &hkey) == ERROR_SUCCESS)
347 int idx = 0;
349 for(;; ++idx)
351 DWORD nameLen = MAX_PATH;
352 DWORD valueLen = MAX_PATH;
354 if (RegEnumValueA(hkey, idx, name, &nameLen, NULL, NULL, (LPBYTE)&value, &valueLen) != ERROR_SUCCESS)
355 break;
357 if (SHELL_RegisterCPanelApp(list, value))
358 ++cnt;
360 RegCloseKey(hkey);
363 return cnt;
366 static int SHELL_RegisterCPanelFolders(IEnumIDList* list, HKEY hkey_root, LPCSTR szRepPath)
368 char name[MAX_PATH];
369 HKEY hkey;
371 int cnt = 0;
373 if (RegOpenKeyA(hkey_root, szRepPath, &hkey) == ERROR_SUCCESS)
375 int idx = 0;
376 for(;; ++idx)
378 if (RegEnumKeyA(hkey, idx, name, MAX_PATH) != ERROR_SUCCESS)
379 break;
381 if (*name == '{')
383 LPITEMIDLIST pidl = _ILCreateGuidFromStrA(name);
385 if (pidl && AddToEnumList(list, pidl))
386 ++cnt;
390 RegCloseKey(hkey);
393 return cnt;
396 /**************************************************************************
397 * CreateCPanelEnumList()
399 static BOOL CreateCPanelEnumList(
400 IEnumIDList * iface,
401 DWORD dwFlags)
403 CHAR szPath[MAX_PATH];
404 WIN32_FIND_DATAA wfd;
405 HANDLE hFile;
407 TRACE("(%p)->(flags=0x%08lx) \n",iface,dwFlags);
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");
413 /* enumerate the control panel applets */
414 if (dwFlags & SHCONTF_NONFOLDERS)
416 LPSTR p;
418 GetSystemDirectoryA(szPath, MAX_PATH);
419 p = PathAddBackslashA(szPath);
420 strcpy(p, "*.cpl");
422 TRACE("-- (%p)-> enumerate SHCONTF_NONFOLDERS of %s\n",iface,debugstr_a(szPath));
423 hFile = FindFirstFileA(szPath, &wfd);
425 if (hFile != INVALID_HANDLE_VALUE)
429 if (!(dwFlags & SHCONTF_INCLUDEHIDDEN) && (wfd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN))
430 continue;
432 if (!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
433 strcpy(p, wfd.cFileName);
434 SHELL_RegisterCPanelApp((IEnumIDList*)iface, szPath);
436 } while(FindNextFileA(hFile, &wfd));
437 FindClose(hFile);
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");
443 return TRUE;
446 /**************************************************************************
447 * ISF_ControlPanel_fnEnumObjects
449 static HRESULT WINAPI
450 ISF_ControlPanel_fnEnumObjects(IShellFolder2 * iface, HWND hwndOwner, DWORD dwFlags, LPENUMIDLIST * ppEnumIDList)
452 ICPanelImpl *This = (ICPanelImpl *)iface;
454 TRACE("(%p)->(HWND=%p flags=0x%08lx pplist=%p)\n", This, hwndOwner, dwFlags, ppEnumIDList);
456 *ppEnumIDList = IEnumIDList_Constructor();
457 if (*ppEnumIDList)
458 CreateCPanelEnumList(*ppEnumIDList, dwFlags);
460 TRACE("--(%p)->(new ID List: %p)\n", This, *ppEnumIDList);
462 return(*ppEnumIDList) ? S_OK : E_OUTOFMEMORY;
465 /**************************************************************************
466 * ISF_ControlPanel_fnBindToObject
468 static HRESULT WINAPI
469 ISF_ControlPanel_fnBindToObject(IShellFolder2 * iface, LPCITEMIDLIST pidl,
470 LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
472 ICPanelImpl *This = (ICPanelImpl *)iface;
474 TRACE("(%p)->(pidl=%p,%p,%s,%p)\n", This, pidl, pbcReserved, shdebugstr_guid(riid), ppvOut);
476 return SHELL32_BindToChild(This->pidlRoot, NULL, pidl, riid, ppvOut);
479 /**************************************************************************
480 * ISF_ControlPanel_fnBindToStorage
482 static HRESULT WINAPI
483 ISF_ControlPanel_fnBindToStorage(IShellFolder2 * iface,
484 LPCITEMIDLIST pidl, LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
486 ICPanelImpl *This = (ICPanelImpl *)iface;
488 FIXME("(%p)->(pidl=%p,%p,%s,%p) stub\n", This, pidl, pbcReserved, shdebugstr_guid(riid), ppvOut);
490 *ppvOut = NULL;
491 return E_NOTIMPL;
494 /**************************************************************************
495 * ISF_ControlPanel_fnCompareIDs
498 static HRESULT WINAPI
499 ISF_ControlPanel_fnCompareIDs(IShellFolder2 * iface, LPARAM lParam, LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
501 ICPanelImpl *This = (ICPanelImpl *)iface;
503 int nReturn;
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;
511 /**************************************************************************
512 * ISF_ControlPanel_fnCreateViewObject
514 static HRESULT WINAPI
515 ISF_ControlPanel_fnCreateViewObject(IShellFolder2 * iface, HWND hwndOwner, REFIID riid, LPVOID * ppvOut)
517 ICPanelImpl *This = (ICPanelImpl *)iface;
519 LPSHELLVIEW pShellView;
520 HRESULT hr = E_INVALIDARG;
522 TRACE("(%p)->(hwnd=%p,%s,%p)\n", This, hwndOwner, shdebugstr_guid(riid), ppvOut);
524 if (ppvOut) {
525 *ppvOut = NULL;
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);
541 TRACE("--(%p)->(interface=%p)\n", This, ppvOut);
542 return hr;
545 /**************************************************************************
546 * ISF_ControlPanel_fnGetAttributesOf
548 static HRESULT WINAPI
549 ISF_ControlPanel_fnGetAttributesOf(IShellFolder2 * iface, UINT cidl, LPCITEMIDLIST * apidl, DWORD * rgfInOut)
551 ICPanelImpl *This = (ICPanelImpl *)iface;
553 HRESULT hr = S_OK;
555 TRACE("(%p)->(cidl=%d apidl=%p mask=0x%08lx)\n", This, cidl, apidl, *rgfInOut);
557 if ((!cidl) ||(!apidl) ||(!rgfInOut))
558 return E_INVALIDARG;
560 if (*rgfInOut == 0)
561 *rgfInOut = ~0;
563 while(cidl > 0 && *apidl) {
564 pdump(*apidl);
565 SHELL32_GetItemAttributes(_IShellFolder_(This), *apidl, rgfInOut);
566 apidl++;
567 cidl--;
570 TRACE("-- result=0x%08lx\n", *rgfInOut);
571 return hr;
574 /**************************************************************************
575 * ISF_ControlPanel_fnGetUIObjectOf
577 * PARAMETERS
578 * HWND hwndOwner, //[in ] Parent window for any output
579 * UINT cidl, //[in ] array size
580 * LPCITEMIDLIST* apidl, //[in ] simple pidl array
581 * REFIID riid, //[in ] Requested Interface
582 * UINT* prgfInOut, //[ ] reserved
583 * LPVOID* ppvObject) //[out] Resulting Interface
586 static HRESULT WINAPI
587 ISF_ControlPanel_fnGetUIObjectOf(IShellFolder2 * iface,
588 HWND hwndOwner,
589 UINT cidl, LPCITEMIDLIST * apidl, REFIID riid, UINT * prgfInOut, LPVOID * ppvOut)
591 ICPanelImpl *This = (ICPanelImpl *)iface;
593 LPITEMIDLIST pidl;
594 IUnknown *pObj = NULL;
595 HRESULT hr = E_INVALIDARG;
597 TRACE("(%p)->(%p,%u,apidl=%p,%s,%p,%p)\n",
598 This, hwndOwner, cidl, apidl, shdebugstr_guid(riid), prgfInOut, ppvOut);
600 if (ppvOut) {
601 *ppvOut = NULL;
603 if (IsEqualIID(riid, &IID_IContextMenu) &&(cidl >= 1)) {
604 pObj = (LPUNKNOWN) ISvItemCm_Constructor((IShellFolder *) iface, This->pidlRoot, apidl, cidl);
605 hr = S_OK;
606 } else if (IsEqualIID(riid, &IID_IDataObject) &&(cidl >= 1)) {
607 pObj = (LPUNKNOWN) IDataObject_Constructor(hwndOwner, This->pidlRoot, apidl, cidl);
608 hr = S_OK;
609 } else if (IsEqualIID(riid, &IID_IExtractIconA) &&(cidl == 1)) {
610 pidl = ILCombine(This->pidlRoot, apidl[0]);
611 pObj = (LPUNKNOWN) IExtractIconA_Constructor(pidl);
612 SHFree(pidl);
613 hr = S_OK;
614 } else if (IsEqualIID(riid, &IID_IExtractIconW) &&(cidl == 1)) {
615 pidl = ILCombine(This->pidlRoot, apidl[0]);
616 pObj = (LPUNKNOWN) IExtractIconW_Constructor(pidl);
617 SHFree(pidl);
618 hr = S_OK;
619 } else if ((IsEqualIID(riid,&IID_IShellLinkW) || IsEqualIID(riid,&IID_IShellLinkA))
620 && (cidl == 1)) {
621 pidl = ILCombine(This->pidlRoot, apidl[0]);
622 hr = IShellLink_ConstructFromFile(NULL, riid, pidl,(LPVOID*)&pObj);
623 SHFree(pidl);
624 } else {
625 hr = E_NOINTERFACE;
628 if (SUCCEEDED(hr) && !pObj)
629 hr = E_OUTOFMEMORY;
631 *ppvOut = pObj;
633 TRACE("(%p)->hr=0x%08lx\n", This, hr);
634 return hr;
637 /**************************************************************************
638 * ISF_ControlPanel_fnGetDisplayNameOf
640 static HRESULT WINAPI ISF_ControlPanel_fnGetDisplayNameOf(IShellFolder2 * iface, LPCITEMIDLIST pidl, DWORD dwFlags, LPSTRRET strRet)
642 ICPanelImpl *This = (ICPanelImpl *)iface;
644 CHAR szPath[MAX_PATH*2];
645 PIDLCPanelStruct* pcpanel;
647 *szPath = '\0';
649 TRACE("(%p)->(pidl=%p,0x%08lx,%p)\n", This, pidl, dwFlags, strRet);
650 pdump(pidl);
652 if (!pidl || !strRet)
653 return E_INVALIDARG;
655 pcpanel = _ILGetCPanelPointer(pidl);
657 if (pcpanel) {
658 lstrcpyA(szPath, pcpanel->szName+pcpanel->offsDispName);
660 if (!(dwFlags & SHGDN_FORPARSING))
661 FIXME("retrieve display name from control panel app\n");
663 /* take names of special folders only if its only this folder */
664 else if (_ILIsSpecialFolder(pidl)) {
665 BOOL bSimplePidl = _ILIsPidlSimple(pidl);
667 if (bSimplePidl) {
668 _ILSimpleGetText(pidl, szPath, MAX_PATH); /* append my own path */
669 } else {
670 FIXME("special pidl\n");
673 if ((dwFlags & SHGDN_FORPARSING) && !bSimplePidl) { /* go deeper if needed */
674 int len = 0;
676 PathAddBackslashA(szPath); /*FIXME*/
677 len = lstrlenA(szPath);
679 if (!SUCCEEDED
680 (SHELL32_GetDisplayNameOfChild(iface, pidl, dwFlags | SHGDN_INFOLDER, szPath + len, MAX_PATH - len)))
681 return E_OUTOFMEMORY;
685 strRet->uType = STRRET_CSTR;
686 lstrcpynA(strRet->u.cStr, szPath, MAX_PATH);
688 TRACE("--(%p)->(%s)\n", This, szPath);
689 return S_OK;
692 /**************************************************************************
693 * ISF_ControlPanel_fnSetNameOf
694 * Changes the name of a file object or subfolder, possibly changing its item
695 * identifier in the process.
697 * PARAMETERS
698 * HWND hwndOwner, //[in ] Owner window for output
699 * LPCITEMIDLIST pidl, //[in ] simple pidl of item to change
700 * LPCOLESTR lpszName, //[in ] the items new display name
701 * DWORD dwFlags, //[in ] SHGNO formatting flags
702 * LPITEMIDLIST* ppidlOut) //[out] simple pidl returned
704 static HRESULT WINAPI ISF_ControlPanel_fnSetNameOf(IShellFolder2 * iface, HWND hwndOwner, LPCITEMIDLIST pidl, /*simple pidl */
705 LPCOLESTR lpName, DWORD dwFlags, LPITEMIDLIST * pPidlOut)
707 ICPanelImpl *This = (ICPanelImpl *)iface;
708 FIXME("(%p)->(%p,pidl=%p,%s,%lu,%p)\n", This, hwndOwner, pidl, debugstr_w(lpName), dwFlags, pPidlOut);
709 return E_FAIL;
712 static HRESULT WINAPI ISF_ControlPanel_fnGetDefaultSearchGUID(IShellFolder2 * iface, GUID * pguid)
714 ICPanelImpl *This = (ICPanelImpl *)iface;
715 FIXME("(%p)\n", This);
716 return E_NOTIMPL;
718 static HRESULT WINAPI ISF_ControlPanel_fnEnumSearches(IShellFolder2 * iface, IEnumExtraSearch ** ppenum)
720 ICPanelImpl *This = (ICPanelImpl *)iface;
721 FIXME("(%p)\n", This);
722 return E_NOTIMPL;
724 static HRESULT WINAPI ISF_ControlPanel_fnGetDefaultColumn(IShellFolder2 * iface, DWORD dwRes, ULONG * pSort, ULONG * pDisplay)
726 ICPanelImpl *This = (ICPanelImpl *)iface;
728 TRACE("(%p)\n", This);
730 if (pSort) *pSort = 0;
731 if (pDisplay) *pDisplay = 0;
732 return S_OK;
734 static HRESULT WINAPI ISF_ControlPanel_fnGetDefaultColumnState(IShellFolder2 * iface, UINT iColumn, DWORD * pcsFlags)
736 ICPanelImpl *This = (ICPanelImpl *)iface;
738 TRACE("(%p)\n", This);
740 if (!pcsFlags || iColumn >= CONROLPANELSHELLVIEWCOLUMNS) return E_INVALIDARG;
741 *pcsFlags = ControlPanelSFHeader[iColumn].pcsFlags;
742 return S_OK;
744 static HRESULT WINAPI ISF_ControlPanel_fnGetDetailsEx(IShellFolder2 * iface, LPCITEMIDLIST pidl, const SHCOLUMNID * pscid, VARIANT * pv)
746 ICPanelImpl *This = (ICPanelImpl *)iface;
747 FIXME("(%p)\n", This);
748 return E_NOTIMPL;
751 static HRESULT WINAPI ISF_ControlPanel_fnGetDetailsOf(IShellFolder2 * iface, LPCITEMIDLIST pidl, UINT iColumn, SHELLDETAILS * psd)
753 ICPanelImpl *This = (ICPanelImpl *)iface;
754 HRESULT hr;
756 TRACE("(%p)->(%p %i %p)\n", This, pidl, iColumn, psd);
758 if (!psd || iColumn >= CONROLPANELSHELLVIEWCOLUMNS)
759 return E_INVALIDARG;
761 if (!pidl) {
762 psd->fmt = ControlPanelSFHeader[iColumn].fmt;
763 psd->cxChar = ControlPanelSFHeader[iColumn].cxChar;
764 psd->str.uType = STRRET_CSTR;
765 LoadStringA(shell32_hInstance, ControlPanelSFHeader[iColumn].colnameid, psd->str.u.cStr, MAX_PATH);
766 return S_OK;
767 } else {
768 psd->str.u.cStr[0] = 0x00;
769 psd->str.uType = STRRET_CSTR;
770 switch(iColumn) {
771 case 0: /* name */
772 hr = IShellFolder_GetDisplayNameOf(iface, pidl, SHGDN_NORMAL | SHGDN_INFOLDER, &psd->str);
773 break;
774 case 1: /* comment */
775 _ILGetFileType(pidl, psd->str.u.cStr, MAX_PATH);
776 break;
778 hr = S_OK;
781 return hr;
783 static HRESULT WINAPI ISF_ControlPanel_fnMapColumnToSCID(IShellFolder2 * iface, UINT column, SHCOLUMNID * pscid)
785 ICPanelImpl *This = (ICPanelImpl *)iface;
786 FIXME("(%p)\n", This);
787 return E_NOTIMPL;
790 static IShellFolder2Vtbl vt_ShellFolder2 =
793 ISF_ControlPanel_fnQueryInterface,
794 ISF_ControlPanel_fnAddRef,
795 ISF_ControlPanel_fnRelease,
796 ISF_ControlPanel_fnParseDisplayName,
797 ISF_ControlPanel_fnEnumObjects,
798 ISF_ControlPanel_fnBindToObject,
799 ISF_ControlPanel_fnBindToStorage,
800 ISF_ControlPanel_fnCompareIDs,
801 ISF_ControlPanel_fnCreateViewObject,
802 ISF_ControlPanel_fnGetAttributesOf,
803 ISF_ControlPanel_fnGetUIObjectOf,
804 ISF_ControlPanel_fnGetDisplayNameOf,
805 ISF_ControlPanel_fnSetNameOf,
807 /* ShellFolder2 */
808 ISF_ControlPanel_fnGetDefaultSearchGUID,
809 ISF_ControlPanel_fnEnumSearches,
810 ISF_ControlPanel_fnGetDefaultColumn,
811 ISF_ControlPanel_fnGetDefaultColumnState,
812 ISF_ControlPanel_fnGetDetailsEx,
813 ISF_ControlPanel_fnGetDetailsOf,
814 ISF_ControlPanel_fnMapColumnToSCID
817 /************************************************************************
818 * ICPanel_PersistFolder2_QueryInterface
820 static HRESULT WINAPI ICPanel_PersistFolder2_QueryInterface(IPersistFolder2 * iface, REFIID iid, LPVOID * ppvObject)
822 _ICOM_THIS_From_IPersistFolder2(ICPanelImpl, iface);
824 TRACE("(%p)\n", This);
826 return IUnknown_QueryInterface(_IUnknown_(This), iid, ppvObject);
829 /************************************************************************
830 * ICPanel_PersistFolder2_AddRef
832 static ULONG WINAPI ICPanel_PersistFolder2_AddRef(IPersistFolder2 * iface)
834 _ICOM_THIS_From_IPersistFolder2(ICPanelImpl, iface);
836 TRACE("(%p)->(count=%lu)\n", This, This->ref);
838 return IUnknown_AddRef(_IUnknown_(This));
841 /************************************************************************
842 * ISFPersistFolder_Release
844 static ULONG WINAPI ICPanel_PersistFolder2_Release(IPersistFolder2 * iface)
846 _ICOM_THIS_From_IPersistFolder2(ICPanelImpl, iface);
848 TRACE("(%p)->(count=%lu)\n", This, This->ref);
850 return IUnknown_Release(_IUnknown_(This));
853 /************************************************************************
854 * ICPanel_PersistFolder2_GetClassID
856 static HRESULT WINAPI ICPanel_PersistFolder2_GetClassID(IPersistFolder2 * iface, CLSID * lpClassId)
858 _ICOM_THIS_From_IPersistFolder2(ICPanelImpl, iface);
860 TRACE("(%p)\n", This);
862 if (!lpClassId)
863 return E_POINTER;
864 *lpClassId = CLSID_ControlPanel;
866 return S_OK;
869 /************************************************************************
870 * ICPanel_PersistFolder2_Initialize
872 * NOTES: it makes no sense to change the pidl
874 static HRESULT WINAPI ICPanel_PersistFolder2_Initialize(IPersistFolder2 * iface, LPCITEMIDLIST pidl)
876 _ICOM_THIS_From_IPersistFolder2(ICPanelImpl, iface);
877 TRACE("(%p)->(%p)\n", This, pidl);
878 return E_NOTIMPL;
881 /**************************************************************************
882 * IPersistFolder2_fnGetCurFolder
884 static HRESULT WINAPI ICPanel_PersistFolder2_GetCurFolder(IPersistFolder2 * iface, LPITEMIDLIST * pidl)
886 _ICOM_THIS_From_IPersistFolder2(ICPanelImpl, iface);
888 TRACE("(%p)->(%p)\n", This, pidl);
890 if (!pidl)
891 return E_POINTER;
892 *pidl = ILClone(This->pidlRoot);
893 return S_OK;
896 static IPersistFolder2Vtbl vt_PersistFolder2 =
899 ICPanel_PersistFolder2_QueryInterface,
900 ICPanel_PersistFolder2_AddRef,
901 ICPanel_PersistFolder2_Release,
902 ICPanel_PersistFolder2_GetClassID,
903 ICPanel_PersistFolder2_Initialize,
904 ICPanel_PersistFolder2_GetCurFolder
907 HRESULT WINAPI CPanel_GetIconLocationA(LPITEMIDLIST pidl, LPSTR szIconFile, UINT cchMax, int* piIndex)
909 PIDLCPanelStruct* pcpanel = _ILGetCPanelPointer(pidl);
911 if (!pcpanel)
912 return E_INVALIDARG;
914 lstrcpyA(szIconFile, pcpanel->szName);
915 *piIndex = pcpanel->iconIdx!=-1? pcpanel->iconIdx: 0;
917 return S_OK;
920 HRESULT WINAPI CPanel_GetIconLocationW(LPITEMIDLIST pidl, LPWSTR szIconFile, UINT cchMax, int* piIndex)
922 PIDLCPanelStruct* pcpanel = _ILGetCPanelPointer(pidl);
924 if (!pcpanel)
925 return E_INVALIDARG;
927 MultiByteToWideChar(CP_ACP, 0, pcpanel->szName, -1, szIconFile, cchMax);
928 *piIndex = pcpanel->iconIdx!=-1? pcpanel->iconIdx: 0;
930 return S_OK;
934 /**************************************************************************
935 * IShellExecuteHookW Implementation
938 static HRESULT WINAPI IShellExecuteHookW_fnQueryInterface(IShellExecuteHookW* iface, REFIID riid, void** ppvObject)
940 _ICOM_THIS_From_IShellExecuteHookW(ICPanelImpl, iface);
942 TRACE("(%p)->(count=%lu)\n", This, This->ref);
944 return IUnknown_QueryInterface(This->pUnkOuter, riid, ppvObject);
947 static ULONG STDMETHODCALLTYPE IShellExecuteHookW_fnAddRef(IShellExecuteHookW* iface)
949 _ICOM_THIS_From_IShellExecuteHookW(ICPanelImpl, iface);
951 TRACE("(%p)->(count=%lu)\n", This, This->ref);
953 return IUnknown_AddRef(This->pUnkOuter);
956 static ULONG STDMETHODCALLTYPE IShellExecuteHookW_fnRelease(IShellExecuteHookW* iface)
958 _ICOM_THIS_From_IShellExecuteHookW(ICPanelImpl, iface);
960 TRACE("(%p)\n", This);
962 return IUnknown_Release(This->pUnkOuter);
965 static HRESULT WINAPI IShellExecuteHookW_fnExecute(IShellExecuteHookW* iface, LPSHELLEXECUTEINFOW psei)
967 ICPanelImpl *This = (ICPanelImpl *)iface;
969 SHELLEXECUTEINFOW sei_tmp;
970 PIDLCPanelStruct* pcpanel;
971 WCHAR path[MAX_PATH];
972 BOOL ret;
973 int l;
975 TRACE("(%p)->execute(%p)\n", This, psei);
977 if (!psei)
978 return E_INVALIDARG;
980 pcpanel = _ILGetCPanelPointer(ILFindLastID(psei->lpIDList));
982 if (!pcpanel)
983 return E_INVALIDARG;
985 path[0] = '\"';
986 l = 1 + MultiByteToWideChar(CP_ACP, 0, pcpanel->szName, -1, path+1, MAX_PATH);
988 /* pass applet name to Control_RunDLL to distinguish between applets in one .cpl file */
989 path[++l] = '"';
990 path[++l] = ' ';
992 MultiByteToWideChar(CP_ACP, 0, pcpanel->szName+pcpanel->offsDispName, -1, path+l, MAX_PATH);
994 memcpy(&sei_tmp, psei, sizeof(sei_tmp));
995 sei_tmp.lpFile = path;
996 sei_tmp.fMask &= ~SEE_MASK_INVOKEIDLIST;
998 ret = ShellExecuteExW(&sei_tmp);
999 if (ret)
1000 return S_OK;
1001 else
1002 return S_FALSE;
1005 static IShellExecuteHookWVtbl vt_ShellExecuteHookW =
1008 IShellExecuteHookW_fnQueryInterface,
1009 IShellExecuteHookW_fnAddRef,
1010 IShellExecuteHookW_fnRelease,
1012 IShellExecuteHookW_fnExecute
1016 /**************************************************************************
1017 * IShellExecuteHookA Implementation
1020 static HRESULT WINAPI IShellExecuteHookA_fnQueryInterface(IShellExecuteHookA* iface, REFIID riid, void** ppvObject)
1022 _ICOM_THIS_From_IShellExecuteHookA(ICPanelImpl, iface);
1024 TRACE("(%p)->(count=%lu)\n", This, This->ref);
1026 return IUnknown_QueryInterface(This->pUnkOuter, riid, ppvObject);
1029 static ULONG STDMETHODCALLTYPE IShellExecuteHookA_fnAddRef(IShellExecuteHookA* iface)
1031 _ICOM_THIS_From_IShellExecuteHookA(ICPanelImpl, iface);
1033 TRACE("(%p)->(count=%lu)\n", This, This->ref);
1035 return IUnknown_AddRef(This->pUnkOuter);
1038 static ULONG STDMETHODCALLTYPE IShellExecuteHookA_fnRelease(IShellExecuteHookA* iface)
1040 _ICOM_THIS_From_IShellExecuteHookA(ICPanelImpl, iface);
1042 TRACE("(%p)\n", This);
1044 return IUnknown_Release(This->pUnkOuter);
1047 static HRESULT WINAPI IShellExecuteHookA_fnExecute(IShellExecuteHookA* iface, LPSHELLEXECUTEINFOA psei)
1049 ICPanelImpl *This = (ICPanelImpl *)iface;
1051 SHELLEXECUTEINFOA sei_tmp;
1052 PIDLCPanelStruct* pcpanel;
1053 char path[MAX_PATH];
1054 BOOL ret;
1056 TRACE("(%p)->execute(%p)\n", This, psei);
1058 if (!psei)
1059 return E_INVALIDARG;
1061 pcpanel = _ILGetCPanelPointer(ILFindLastID(psei->lpIDList));
1063 if (!pcpanel)
1064 return E_INVALIDARG;
1066 path[0] = '\"';
1067 lstrcpyA(path+1, pcpanel->szName);
1069 /* pass applet name to Control_RunDLL to distinguish between applets in one .cpl file */
1070 lstrcatA(path, "\" ");
1071 lstrcatA(path, pcpanel->szName+pcpanel->offsDispName);
1073 memcpy(&sei_tmp, psei, sizeof(sei_tmp));
1074 sei_tmp.lpFile = path;
1075 sei_tmp.fMask &= ~SEE_MASK_INVOKEIDLIST;
1077 ret = ShellExecuteExA(&sei_tmp);
1078 if (ret)
1079 return S_OK;
1080 else
1081 return S_FALSE;
1084 static IShellExecuteHookAVtbl vt_ShellExecuteHookA =
1087 IShellExecuteHookA_fnQueryInterface,
1088 IShellExecuteHookA_fnAddRef,
1089 IShellExecuteHookA_fnRelease,
1091 IShellExecuteHookA_fnExecute