shell32: Silence buffer overflow compiler warnings.
[wine.git] / dlls / shell32 / cpanelfolder.c
blob114eb6babd318b4afb486b1db0e3bdf53e605e60
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 "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
32 #include "winerror.h"
33 #include "windef.h"
34 #include "winbase.h"
35 #include "winreg.h"
36 #include "wingdi.h"
37 #include "winuser.h"
39 #include "ole2.h"
40 #include "shlguid.h"
42 #include "commctrl.h"
43 #include "cpanel.h"
44 #include "pidl.h"
45 #include "undocshell.h"
46 #include "shell32_main.h"
47 #include "shresdef.h"
48 #include "shlwapi.h"
49 #include "wine/debug.h"
50 #include "debughlp.h"
51 #include "shfldr.h"
53 WINE_DEFAULT_DEBUG_CHANNEL(shell);
55 /***********************************************************************
56 * control panel implementation in shell namespace
59 typedef struct {
60 IShellFolder2 IShellFolder2_iface;
61 IPersistFolder2 IPersistFolder2_iface;
62 IShellExecuteHookW IShellExecuteHookW_iface;
63 IShellExecuteHookA IShellExecuteHookA_iface;
64 LONG ref;
66 IUnknown *pUnkOuter; /* used for aggregation */
68 /* both paths are parsible from the desktop */
69 LPITEMIDLIST pidlRoot; /* absolute pidl */
70 int dwAttributes; /* attributes returned by GetAttributesOf FIXME: use it */
71 } ICPanelImpl;
73 static const IShellFolder2Vtbl vt_ShellFolder2;
74 static const IPersistFolder2Vtbl vt_PersistFolder2;
75 static const IShellExecuteHookWVtbl vt_ShellExecuteHookW;
76 static const IShellExecuteHookAVtbl vt_ShellExecuteHookA;
78 static inline ICPanelImpl *impl_from_IShellFolder2(IShellFolder2 *iface)
80 return CONTAINING_RECORD(iface, ICPanelImpl, IShellFolder2_iface);
83 static inline ICPanelImpl *impl_from_IPersistFolder2(IPersistFolder2 *iface)
85 return CONTAINING_RECORD(iface, ICPanelImpl, IPersistFolder2_iface);
88 static inline ICPanelImpl *impl_from_IShellExecuteHookW(IShellExecuteHookW *iface)
90 return CONTAINING_RECORD(iface, ICPanelImpl, IShellExecuteHookW_iface);
93 static inline ICPanelImpl *impl_from_IShellExecuteHookA(IShellExecuteHookA *iface)
95 return CONTAINING_RECORD(iface, ICPanelImpl, IShellExecuteHookA_iface);
99 /***********************************************************************
100 * IShellFolder [ControlPanel] implementation
103 static const shvheader ControlPanelSFHeader[] =
105 { &FMTID_Storage, PID_STG_NAME, IDS_SHV_COLUMN8, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 15 },/*FIXME*/
106 { NULL, 0, IDS_SHV_COLUMN9, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_LEFT, 80 },/*FIXME*/
109 #define CONROLPANELSHELLVIEWCOLUMNS 2
111 /**************************************************************************
112 * IControlPanel_Constructor
114 HRESULT WINAPI IControlPanel_Constructor(IUnknown* pUnkOuter, REFIID riid, LPVOID * ppv)
116 ICPanelImpl *sf;
118 TRACE("unkOut=%p %s\n", pUnkOuter, shdebugstr_guid(riid));
120 if (!ppv)
121 return E_POINTER;
122 if (pUnkOuter && !IsEqualIID (riid, &IID_IUnknown))
123 return CLASS_E_NOAGGREGATION;
125 sf = LocalAlloc(LMEM_ZEROINIT, sizeof(ICPanelImpl));
126 if (!sf)
127 return E_OUTOFMEMORY;
129 sf->ref = 1;
130 sf->IShellFolder2_iface.lpVtbl = &vt_ShellFolder2;
131 sf->IPersistFolder2_iface.lpVtbl = &vt_PersistFolder2;
132 sf->IShellExecuteHookW_iface.lpVtbl = &vt_ShellExecuteHookW;
133 sf->IShellExecuteHookA_iface.lpVtbl = &vt_ShellExecuteHookA;
134 sf->pidlRoot = _ILCreateControlPanel(); /* my qualified pidl */
135 sf->pUnkOuter = pUnkOuter ? pUnkOuter : (IUnknown *)&sf->IShellFolder2_iface;
137 if (FAILED(IShellFolder2_QueryInterface(&sf->IShellFolder2_iface, riid, ppv))) {
138 IShellFolder2_Release(&sf->IShellFolder2_iface);
139 return E_NOINTERFACE;
141 IShellFolder2_Release(&sf->IShellFolder2_iface);
143 TRACE("--(%p)\n", sf);
144 return S_OK;
147 /**************************************************************************
148 * ISF_ControlPanel_fnQueryInterface
150 * NOTES supports not IPersist/IPersistFolder
152 static HRESULT WINAPI ISF_ControlPanel_fnQueryInterface(IShellFolder2 *iface, REFIID riid,
153 void **ppvObject)
155 ICPanelImpl *This = impl_from_IShellFolder2(iface);
157 TRACE("(%p)->(%s,%p)\n", This, shdebugstr_guid(riid), ppvObject);
159 *ppvObject = NULL;
161 if (IsEqualIID(riid, &IID_IUnknown) ||
162 IsEqualIID(riid, &IID_IShellFolder) || IsEqualIID(riid, &IID_IShellFolder2))
163 *ppvObject = &This->IShellFolder2_iface;
164 else if (IsEqualIID(riid, &IID_IPersist) ||
165 IsEqualIID(riid, &IID_IPersistFolder) || IsEqualIID(riid, &IID_IPersistFolder2))
166 *ppvObject = &This->IPersistFolder2_iface;
167 else if (IsEqualIID(riid, &IID_IShellExecuteHookW))
168 *ppvObject = &This->IShellExecuteHookW_iface;
169 else if (IsEqualIID(riid, &IID_IShellExecuteHookA))
170 *ppvObject = &This->IShellExecuteHookA_iface;
172 if (*ppvObject) {
173 IUnknown_AddRef((IUnknown *)(*ppvObject));
174 TRACE("-- Interface:(%p)->(%p)\n", ppvObject, *ppvObject);
175 return S_OK;
177 TRACE("-- Interface: E_NOINTERFACE\n");
178 return E_NOINTERFACE;
181 static ULONG WINAPI ISF_ControlPanel_fnAddRef(IShellFolder2 *iface)
183 ICPanelImpl *This = impl_from_IShellFolder2(iface);
184 ULONG refCount = InterlockedIncrement(&This->ref);
186 TRACE("(%p)->(count=%u)\n", This, refCount - 1);
188 return refCount;
191 static ULONG WINAPI ISF_ControlPanel_fnRelease(IShellFolder2 *iface)
193 ICPanelImpl *This = impl_from_IShellFolder2(iface);
194 ULONG refCount = InterlockedDecrement(&This->ref);
196 TRACE("(%p)->(count=%u)\n", This, refCount + 1);
198 if (!refCount) {
199 TRACE("-- destroying IShellFolder(%p)\n", This);
200 SHFree(This->pidlRoot);
201 LocalFree(This);
203 return refCount;
206 /**************************************************************************
207 * ISF_ControlPanel_fnParseDisplayName
209 static HRESULT WINAPI ISF_ControlPanel_fnParseDisplayName(IShellFolder2 *iface, HWND hwndOwner,
210 LPBC pbc, LPOLESTR lpszDisplayName, DWORD *pchEaten, LPITEMIDLIST *ppidl,
211 DWORD *pdwAttributes)
213 ICPanelImpl *This = impl_from_IShellFolder2(iface);
215 HRESULT hr = E_INVALIDARG;
217 FIXME("(%p)->(HWND=%p,%p,%p=%s,%p,pidl=%p,%p)\n",
218 This, hwndOwner, pbc, lpszDisplayName, debugstr_w(lpszDisplayName), pchEaten, ppidl, pdwAttributes);
220 *ppidl = 0;
221 if (pchEaten)
222 *pchEaten = 0;
224 TRACE("(%p)->(-- ret=0x%08x)\n", This, hr);
226 return hr;
229 static LPITEMIDLIST _ILCreateCPanelApplet(LPCSTR name, LPCSTR displayName,
230 LPCSTR comment, int iconIdx)
232 PIDLCPanelStruct *p;
233 LPITEMIDLIST pidl;
234 PIDLDATA tmp;
235 int size0 = (char*)tmp.u.cpanel.szName-(char*)&tmp.u.cpanel;
236 int size = size0;
237 int l;
239 tmp.type = PT_CPLAPPLET;
240 tmp.u.cpanel.dummy = 0;
241 tmp.u.cpanel.iconIdx = iconIdx;
243 l = strlen(name);
244 size += l+1;
246 tmp.u.cpanel.offsDispName = l+1;
247 l = strlen(displayName);
248 size += l+1;
250 tmp.u.cpanel.offsComment = tmp.u.cpanel.offsDispName+1+l;
251 l = strlen(comment);
252 size += l+1;
254 pidl = SHAlloc(size+4);
255 if (!pidl)
256 return NULL;
258 pidl->mkid.cb = size+2;
259 memcpy(pidl->mkid.abID, &tmp, 2+size0);
261 p = &((PIDLDATA*)pidl->mkid.abID)->u.cpanel;
262 memcpy(p->szName, name, strlen(name) + 1);
263 memcpy(p->szName+tmp.u.cpanel.offsDispName, displayName, strlen(displayName) + 1);
264 memcpy(p->szName+tmp.u.cpanel.offsComment, comment, strlen(comment) + 1);
266 *(WORD*)((char*)pidl+(size+2)) = 0;
268 pcheck(pidl);
270 return pidl;
273 /**************************************************************************
274 * _ILGetCPanelPointer()
275 * gets a pointer to the control panel struct stored in the pidl
277 static PIDLCPanelStruct* _ILGetCPanelPointer(LPCITEMIDLIST pidl)
279 LPPIDLDATA pdata = _ILGetDataPointer(pidl);
281 if (pdata && pdata->type==PT_CPLAPPLET)
282 return &pdata->u.cpanel;
284 return NULL;
287 /**************************************************************************
288 * ISF_ControlPanel_fnEnumObjects
290 static BOOL SHELL_RegisterCPanelApp(IEnumIDListImpl *list, LPCSTR path)
292 LPITEMIDLIST pidl;
293 CPlApplet* applet;
294 CPanel panel;
295 CPLINFO info;
296 unsigned i;
297 int iconIdx;
299 char displayName[MAX_PATH];
300 char comment[MAX_PATH];
302 WCHAR wpath[MAX_PATH];
304 MultiByteToWideChar(CP_ACP, 0, path, -1, wpath, MAX_PATH);
306 list_init( &panel.applets );
307 applet = Control_LoadApplet(0, wpath, &panel);
309 if (applet)
311 for(i=0; i<applet->count; ++i)
313 WideCharToMultiByte(CP_ACP, 0, applet->info[i].name, -1, displayName, MAX_PATH, 0, 0);
314 WideCharToMultiByte(CP_ACP, 0, applet->info[i].info, -1, comment, MAX_PATH, 0, 0);
316 applet->proc(0, CPL_INQUIRE, i, (LPARAM)&info);
318 if (info.idIcon > 0)
319 iconIdx = -info.idIcon; /* negative icon index instead of icon number */
320 else
321 iconIdx = 0;
323 pidl = _ILCreateCPanelApplet(path, displayName, comment, iconIdx);
325 if (pidl)
326 AddToEnumList(list, pidl);
328 Control_UnloadApplet(applet);
330 return TRUE;
333 static int SHELL_RegisterRegistryCPanelApps(IEnumIDListImpl *list, HKEY hkey_root, LPCSTR szRepPath)
335 char name[MAX_PATH];
336 char value[MAX_PATH];
337 HKEY hkey;
339 int cnt = 0;
341 if (RegOpenKeyA(hkey_root, szRepPath, &hkey) == ERROR_SUCCESS)
343 int idx = 0;
345 for(;; ++idx)
347 DWORD nameLen = MAX_PATH;
348 DWORD valueLen = MAX_PATH;
350 if (RegEnumValueA(hkey, idx, name, &nameLen, NULL, NULL, (LPBYTE)value, &valueLen) != ERROR_SUCCESS)
351 break;
353 if (SHELL_RegisterCPanelApp(list, value))
354 ++cnt;
356 RegCloseKey(hkey);
359 return cnt;
362 static int SHELL_RegisterCPanelFolders(IEnumIDListImpl *list, HKEY hkey_root, LPCSTR szRepPath)
364 char name[MAX_PATH];
365 HKEY hkey;
367 int cnt = 0;
369 if (RegOpenKeyA(hkey_root, szRepPath, &hkey) == ERROR_SUCCESS)
371 int idx = 0;
372 for(;; ++idx)
374 if (RegEnumKeyA(hkey, idx, name, MAX_PATH) != ERROR_SUCCESS)
375 break;
377 if (*name == '{')
379 LPITEMIDLIST pidl = _ILCreateGuidFromStrA(name);
381 if (pidl && AddToEnumList(list, pidl))
382 ++cnt;
386 RegCloseKey(hkey);
389 return cnt;
392 /**************************************************************************
393 * CreateCPanelEnumList()
395 static BOOL CreateCPanelEnumList(IEnumIDListImpl *list, DWORD dwFlags)
397 CHAR szPath[MAX_PATH];
398 WIN32_FIND_DATAA wfd;
399 HANDLE hFile;
401 TRACE("(%p)->(flags=0x%08x)\n", list, dwFlags);
403 /* enumerate control panel folders */
404 if (dwFlags & SHCONTF_FOLDERS)
405 SHELL_RegisterCPanelFolders(list, HKEY_LOCAL_MACHINE,
406 "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ControlPanel\\NameSpace");
408 /* enumerate the control panel applets */
409 if (dwFlags & SHCONTF_NONFOLDERS)
411 LPSTR p;
413 GetSystemDirectoryA(szPath, MAX_PATH);
414 p = PathAddBackslashA(szPath);
415 strcpy(p, "*.cpl");
417 TRACE("-- (%p)-> enumerate SHCONTF_NONFOLDERS of %s\n", list, debugstr_a(szPath));
418 hFile = FindFirstFileA(szPath, &wfd);
420 if (hFile != INVALID_HANDLE_VALUE)
424 if (!(dwFlags & SHCONTF_INCLUDEHIDDEN) && (wfd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN))
425 continue;
427 if (!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
428 strcpy(p, wfd.cFileName);
429 SHELL_RegisterCPanelApp(list, szPath);
431 } while(FindNextFileA(hFile, &wfd));
432 FindClose(hFile);
435 SHELL_RegisterRegistryCPanelApps(list, HKEY_LOCAL_MACHINE,
436 "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Control Panel\\Cpls");
437 SHELL_RegisterRegistryCPanelApps(list, HKEY_CURRENT_USER,
438 "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Control Panel\\Cpls");
440 return TRUE;
443 /**************************************************************************
444 * ISF_ControlPanel_fnEnumObjects
446 static HRESULT WINAPI ISF_ControlPanel_fnEnumObjects(IShellFolder2 *iface, HWND hwndOwner,
447 DWORD dwFlags, LPENUMIDLIST *ppEnumIDList)
449 ICPanelImpl *This = impl_from_IShellFolder2(iface);
450 IEnumIDListImpl *list;
452 TRACE("(%p)->(HWND=%p flags=0x%08x pplist=%p)\n", This, hwndOwner, dwFlags, ppEnumIDList);
454 if (!(list = IEnumIDList_Constructor()))
455 return E_OUTOFMEMORY;
456 CreateCPanelEnumList(list, dwFlags);
457 *ppEnumIDList = &list->IEnumIDList_iface;
459 TRACE("--(%p)->(new ID List: %p)\n", This, *ppEnumIDList);
461 return S_OK;
464 /**************************************************************************
465 * ISF_ControlPanel_fnBindToObject
467 static HRESULT WINAPI ISF_ControlPanel_fnBindToObject(IShellFolder2 *iface, LPCITEMIDLIST pidl,
468 LPBC pbcReserved, REFIID riid, void **ppvOut)
470 ICPanelImpl *This = impl_from_IShellFolder2(iface);
472 TRACE("(%p)->(pidl=%p,%p,%s,%p)\n", This, pidl, pbcReserved, shdebugstr_guid(riid), ppvOut);
474 return SHELL32_BindToChild(This->pidlRoot, NULL, pidl, riid, ppvOut);
477 /**************************************************************************
478 * ISF_ControlPanel_fnBindToStorage
480 static HRESULT WINAPI ISF_ControlPanel_fnBindToStorage(IShellFolder2 *iface, LPCITEMIDLIST pidl,
481 LPBC pbcReserved, REFIID riid, void **ppvOut)
483 ICPanelImpl *This = impl_from_IShellFolder2(iface);
485 FIXME("(%p)->(pidl=%p,%p,%s,%p) stub\n", This, pidl, pbcReserved, shdebugstr_guid(riid), ppvOut);
487 *ppvOut = NULL;
488 return E_NOTIMPL;
491 /**************************************************************************
492 * ISF_ControlPanel_fnCompareIDs
495 static HRESULT WINAPI ISF_ControlPanel_fnCompareIDs(IShellFolder2 *iface, LPARAM lParam,
496 LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
498 ICPanelImpl *This = impl_from_IShellFolder2(iface);
500 int nReturn;
502 TRACE("(%p)->(0x%08lx,pidl1=%p,pidl2=%p)\n", This, lParam, pidl1, pidl2);
503 nReturn = SHELL32_CompareIDs(&This->IShellFolder2_iface, lParam, pidl1, pidl2);
504 TRACE("-- %i\n", nReturn);
505 return nReturn;
508 /**************************************************************************
509 * ISF_ControlPanel_fnCreateViewObject
511 static HRESULT WINAPI ISF_ControlPanel_fnCreateViewObject(IShellFolder2 *iface, HWND hwndOwner,
512 REFIID riid, void **ppvOut)
514 ICPanelImpl *This = impl_from_IShellFolder2(iface);
516 LPSHELLVIEW pShellView;
517 HRESULT hr = E_INVALIDARG;
519 TRACE("(%p)->(hwnd=%p,%s,%p)\n", This, hwndOwner, shdebugstr_guid(riid), ppvOut);
521 if (ppvOut) {
522 *ppvOut = NULL;
524 if (IsEqualIID(riid, &IID_IDropTarget)) {
525 WARN("IDropTarget not implemented\n");
526 hr = E_NOTIMPL;
527 } else if (IsEqualIID(riid, &IID_IContextMenu)) {
528 WARN("IContextMenu not implemented\n");
529 hr = E_NOTIMPL;
530 } else if (IsEqualIID(riid, &IID_IShellView)) {
531 pShellView = IShellView_Constructor((IShellFolder *) iface);
532 if (pShellView) {
533 hr = IShellView_QueryInterface(pShellView, riid, ppvOut);
534 IShellView_Release(pShellView);
538 TRACE("--(%p)->(interface=%p)\n", This, ppvOut);
539 return hr;
542 /**************************************************************************
543 * ISF_ControlPanel_fnGetAttributesOf
545 static HRESULT WINAPI ISF_ControlPanel_fnGetAttributesOf(IShellFolder2 *iface, UINT cidl,
546 LPCITEMIDLIST *apidl, DWORD *rgfInOut)
548 ICPanelImpl *This = impl_from_IShellFolder2(iface);
550 HRESULT hr = S_OK;
552 TRACE("(%p)->(cidl=%d apidl=%p mask=%p (0x%08x))\n",
553 This, cidl, apidl, rgfInOut, rgfInOut ? *rgfInOut : 0);
555 if (!rgfInOut)
556 return E_INVALIDARG;
557 if (cidl && !apidl)
558 return E_INVALIDARG;
560 if (*rgfInOut == 0)
561 *rgfInOut = ~0;
563 while(cidl > 0 && *apidl) {
564 pdump(*apidl);
565 SHELL32_GetItemAttributes(&This->IShellFolder2_iface, *apidl, rgfInOut);
566 apidl++;
567 cidl--;
569 /* make sure SFGAO_VALIDATE is cleared, some apps depend on that */
570 *rgfInOut &= ~SFGAO_VALIDATE;
572 TRACE("-- result=0x%08x\n", *rgfInOut);
573 return hr;
576 /**************************************************************************
577 * ISF_ControlPanel_fnGetUIObjectOf
579 * PARAMETERS
580 * HWND hwndOwner, //[in ] Parent window for any output
581 * UINT cidl, //[in ] array size
582 * LPCITEMIDLIST* apidl, //[in ] simple pidl array
583 * REFIID riid, //[in ] Requested Interface
584 * UINT* prgfInOut, //[ ] reserved
585 * LPVOID* ppvObject) //[out] Resulting Interface
588 static HRESULT WINAPI ISF_ControlPanel_fnGetUIObjectOf(IShellFolder2 *iface, HWND hwndOwner,
589 UINT cidl, LPCITEMIDLIST *apidl, REFIID riid, UINT *prgfInOut, void **ppvOut)
591 ICPanelImpl *This = impl_from_IShellFolder2(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 return ItemMenu_Constructor((IShellFolder*)iface, This->pidlRoot, apidl, cidl, riid, ppvOut);
605 } else if (IsEqualIID(riid, &IID_IDataObject) &&(cidl >= 1)) {
606 pObj = (LPUNKNOWN) IDataObject_Constructor(hwndOwner, This->pidlRoot, apidl, cidl);
607 hr = S_OK;
608 } else if (IsEqualIID(riid, &IID_IExtractIconA) &&(cidl == 1)) {
609 pidl = ILCombine(This->pidlRoot, apidl[0]);
610 pObj = (LPUNKNOWN) IExtractIconA_Constructor(pidl);
611 SHFree(pidl);
612 hr = S_OK;
613 } else if (IsEqualIID(riid, &IID_IExtractIconW) &&(cidl == 1)) {
614 pidl = ILCombine(This->pidlRoot, apidl[0]);
615 pObj = (LPUNKNOWN) IExtractIconW_Constructor(pidl);
616 SHFree(pidl);
617 hr = S_OK;
618 } else if ((IsEqualIID(riid,&IID_IShellLinkW) || IsEqualIID(riid,&IID_IShellLinkA))
619 && (cidl == 1)) {
620 pidl = ILCombine(This->pidlRoot, apidl[0]);
621 hr = IShellLink_ConstructFromFile(NULL, riid, pidl, &pObj);
622 SHFree(pidl);
623 } else {
624 hr = E_NOINTERFACE;
627 if (SUCCEEDED(hr) && !pObj)
628 hr = E_OUTOFMEMORY;
630 *ppvOut = pObj;
632 TRACE("(%p)->hr=0x%08x\n", This, hr);
633 return hr;
636 /**************************************************************************
637 * ISF_ControlPanel_fnGetDisplayNameOf
639 static HRESULT WINAPI ISF_ControlPanel_fnGetDisplayNameOf(IShellFolder2 *iface, LPCITEMIDLIST pidl,
640 DWORD dwFlags, LPSTRRET strRet)
642 ICPanelImpl *This = impl_from_IShellFolder2(iface);
644 CHAR szPath[MAX_PATH];
645 WCHAR wszPath[MAX_PATH+1]; /* +1 for potential backslash */
646 PIDLCPanelStruct* pcpanel;
648 *szPath = '\0';
650 TRACE("(%p)->(pidl=%p,0x%08x,%p)\n", This, pidl, dwFlags, strRet);
651 pdump(pidl);
653 if (!pidl || !strRet)
654 return E_INVALIDARG;
656 pcpanel = _ILGetCPanelPointer(pidl);
658 if (pcpanel) {
659 lstrcpyA(szPath, pcpanel->szName+pcpanel->offsDispName);
661 if (!(dwFlags & SHGDN_FORPARSING))
662 FIXME("retrieve display name from control panel app\n");
664 /* take names of special folders only if it's only this folder */
665 else if (_ILIsSpecialFolder(pidl)) {
666 BOOL bSimplePidl = _ILIsPidlSimple(pidl);
668 if (bSimplePidl) {
669 _ILSimpleGetTextW(pidl, wszPath, MAX_PATH); /* append my own path */
670 } else {
671 FIXME("special pidl\n");
674 if ((dwFlags & SHGDN_FORPARSING) && !bSimplePidl) { /* go deeper if needed */
675 int len = 0;
677 PathAddBackslashW(wszPath);
678 len = lstrlenW(wszPath);
680 if (FAILED(SHELL32_GetDisplayNameOfChild(iface, pidl, dwFlags | SHGDN_INFOLDER, wszPath + len, MAX_PATH + 1 - len)))
681 return E_OUTOFMEMORY;
682 if (!WideCharToMultiByte(CP_ACP, 0, wszPath, -1, szPath, MAX_PATH, NULL, NULL))
683 wszPath[0] = '\0';
687 strRet->uType = STRRET_CSTR;
688 lstrcpynA(strRet->u.cStr, szPath, MAX_PATH);
690 TRACE("--(%p)->(%s)\n", This, szPath);
691 return S_OK;
694 /**************************************************************************
695 * ISF_ControlPanel_fnSetNameOf
696 * Changes the name of a file object or subfolder, possibly changing its item
697 * identifier in the process.
699 * PARAMETERS
700 * HWND hwndOwner, //[in ] Owner window for output
701 * LPCITEMIDLIST pidl, //[in ] simple pidl of item to change
702 * LPCOLESTR lpszName, //[in ] the items new display name
703 * DWORD dwFlags, //[in ] SHGNO formatting flags
704 * LPITEMIDLIST* ppidlOut) //[out] simple pidl returned
706 static HRESULT WINAPI ISF_ControlPanel_fnSetNameOf(IShellFolder2 *iface, HWND hwndOwner,
707 LPCITEMIDLIST pidl, LPCOLESTR lpName, DWORD dwFlags, LPITEMIDLIST *pPidlOut)
709 ICPanelImpl *This = impl_from_IShellFolder2(iface);
710 FIXME("(%p)->(%p,pidl=%p,%s,%u,%p)\n", This, hwndOwner, pidl, debugstr_w(lpName), dwFlags, pPidlOut);
711 return E_FAIL;
714 static HRESULT WINAPI ISF_ControlPanel_fnGetDefaultSearchGUID(IShellFolder2 *iface, GUID *guid)
716 ICPanelImpl *This = impl_from_IShellFolder2(iface);
717 TRACE("(%p)->(%p)\n", This, guid);
718 return E_NOTIMPL;
721 static HRESULT WINAPI ISF_ControlPanel_fnEnumSearches(IShellFolder2 *iface,
722 IEnumExtraSearch **ppenum)
724 ICPanelImpl *This = impl_from_IShellFolder2(iface);
725 FIXME("(%p)\n", This);
726 return E_NOTIMPL;
729 static HRESULT WINAPI ISF_ControlPanel_fnGetDefaultColumn(IShellFolder2 *iface, DWORD reserved,
730 ULONG *sort, ULONG *display)
732 ICPanelImpl *This = impl_from_IShellFolder2(iface);
734 TRACE("(%p)->(%#x %p %p)\n", This, reserved, sort, display);
736 return E_NOTIMPL;
739 static HRESULT WINAPI ISF_ControlPanel_fnGetDefaultColumnState(IShellFolder2 *iface, UINT iColumn,
740 DWORD *pcsFlags)
742 ICPanelImpl *This = impl_from_IShellFolder2(iface);
744 TRACE("(%p)\n", This);
746 if (!pcsFlags || iColumn >= CONROLPANELSHELLVIEWCOLUMNS) return E_INVALIDARG;
747 *pcsFlags = ControlPanelSFHeader[iColumn].pcsFlags;
748 return S_OK;
750 static HRESULT WINAPI ISF_ControlPanel_fnGetDetailsEx(IShellFolder2 *iface, LPCITEMIDLIST pidl,
751 const SHCOLUMNID *pscid, VARIANT *pv)
753 ICPanelImpl *This = impl_from_IShellFolder2(iface);
754 FIXME("(%p)\n", This);
755 return E_NOTIMPL;
758 static HRESULT WINAPI ISF_ControlPanel_fnGetDetailsOf(IShellFolder2 *iface, LPCITEMIDLIST pidl,
759 UINT iColumn, SHELLDETAILS *psd)
761 ICPanelImpl *This = impl_from_IShellFolder2(iface);
762 PIDLCPanelStruct* pcpanel;
763 HRESULT hr;
765 TRACE("(%p)->(%p %i %p)\n", This, pidl, iColumn, psd);
767 if (!psd || iColumn >= CONROLPANELSHELLVIEWCOLUMNS)
768 return E_INVALIDARG;
770 if (!pidl) {
771 psd->fmt = ControlPanelSFHeader[iColumn].fmt;
772 psd->cxChar = ControlPanelSFHeader[iColumn].cxChar;
773 psd->str.uType = STRRET_CSTR;
774 LoadStringA(shell32_hInstance, ControlPanelSFHeader[iColumn].colnameid, psd->str.u.cStr, MAX_PATH);
775 return S_OK;
776 } else {
777 psd->str.u.cStr[0] = 0x00;
778 psd->str.uType = STRRET_CSTR;
779 switch(iColumn) {
780 case 0: /* name */
781 hr = IShellFolder2_GetDisplayNameOf(iface, pidl, SHGDN_NORMAL | SHGDN_INFOLDER, &psd->str);
782 break;
783 case 1: /* comment */
784 pcpanel = _ILGetCPanelPointer(pidl);
786 if (pcpanel)
787 lstrcpyA(psd->str.u.cStr, pcpanel->szName+pcpanel->offsComment);
788 else
789 _ILGetFileType(pidl, psd->str.u.cStr, MAX_PATH);
791 break;
793 hr = S_OK;
796 return hr;
798 static HRESULT WINAPI ISF_ControlPanel_fnMapColumnToSCID(IShellFolder2 *iface, UINT column,
799 SHCOLUMNID *pscid)
801 ICPanelImpl *This = impl_from_IShellFolder2(iface);
802 FIXME("(%p)\n", This);
803 return E_NOTIMPL;
806 static const IShellFolder2Vtbl vt_ShellFolder2 =
809 ISF_ControlPanel_fnQueryInterface,
810 ISF_ControlPanel_fnAddRef,
811 ISF_ControlPanel_fnRelease,
812 ISF_ControlPanel_fnParseDisplayName,
813 ISF_ControlPanel_fnEnumObjects,
814 ISF_ControlPanel_fnBindToObject,
815 ISF_ControlPanel_fnBindToStorage,
816 ISF_ControlPanel_fnCompareIDs,
817 ISF_ControlPanel_fnCreateViewObject,
818 ISF_ControlPanel_fnGetAttributesOf,
819 ISF_ControlPanel_fnGetUIObjectOf,
820 ISF_ControlPanel_fnGetDisplayNameOf,
821 ISF_ControlPanel_fnSetNameOf,
823 /* ShellFolder2 */
824 ISF_ControlPanel_fnGetDefaultSearchGUID,
825 ISF_ControlPanel_fnEnumSearches,
826 ISF_ControlPanel_fnGetDefaultColumn,
827 ISF_ControlPanel_fnGetDefaultColumnState,
828 ISF_ControlPanel_fnGetDetailsEx,
829 ISF_ControlPanel_fnGetDetailsOf,
830 ISF_ControlPanel_fnMapColumnToSCID
833 /************************************************************************
834 * ICPanel_PersistFolder2_QueryInterface
836 static HRESULT WINAPI ICPanel_PersistFolder2_QueryInterface(IPersistFolder2 * iface, REFIID iid, LPVOID * ppvObject)
838 ICPanelImpl *This = impl_from_IPersistFolder2(iface);
840 TRACE("(%p)\n", This);
842 return IShellFolder2_QueryInterface(&This->IShellFolder2_iface, iid, ppvObject);
845 /************************************************************************
846 * ICPanel_PersistFolder2_AddRef
848 static ULONG WINAPI ICPanel_PersistFolder2_AddRef(IPersistFolder2 * iface)
850 ICPanelImpl *This = impl_from_IPersistFolder2(iface);
852 TRACE("(%p)->(count=%u)\n", This, This->ref);
854 return IShellFolder2_AddRef(&This->IShellFolder2_iface);
857 /************************************************************************
858 * ISFPersistFolder_Release
860 static ULONG WINAPI ICPanel_PersistFolder2_Release(IPersistFolder2 * iface)
862 ICPanelImpl *This = impl_from_IPersistFolder2(iface);
864 TRACE("(%p)->(count=%u)\n", This, This->ref);
866 return IShellFolder2_Release(&This->IShellFolder2_iface);
869 /************************************************************************
870 * ICPanel_PersistFolder2_GetClassID
872 static HRESULT WINAPI ICPanel_PersistFolder2_GetClassID(IPersistFolder2 * iface, CLSID * lpClassId)
874 ICPanelImpl *This = impl_from_IPersistFolder2(iface);
876 TRACE("(%p)\n", This);
878 if (!lpClassId)
879 return E_POINTER;
880 *lpClassId = CLSID_ControlPanel;
882 return S_OK;
885 /************************************************************************
886 * ICPanel_PersistFolder2_Initialize
888 * NOTES: it makes no sense to change the pidl
890 static HRESULT WINAPI ICPanel_PersistFolder2_Initialize(IPersistFolder2 * iface, LPCITEMIDLIST pidl)
892 ICPanelImpl *This = impl_from_IPersistFolder2(iface);
893 TRACE("(%p)->(%p)\n", This, pidl);
894 return E_NOTIMPL;
897 /**************************************************************************
898 * IPersistFolder2_fnGetCurFolder
900 static HRESULT WINAPI ICPanel_PersistFolder2_GetCurFolder(IPersistFolder2 * iface, LPITEMIDLIST * pidl)
902 ICPanelImpl *This = impl_from_IPersistFolder2(iface);
904 TRACE("(%p)->(%p)\n", This, pidl);
906 if (!pidl)
907 return E_POINTER;
908 *pidl = ILClone(This->pidlRoot);
909 return S_OK;
912 static const IPersistFolder2Vtbl vt_PersistFolder2 =
915 ICPanel_PersistFolder2_QueryInterface,
916 ICPanel_PersistFolder2_AddRef,
917 ICPanel_PersistFolder2_Release,
918 ICPanel_PersistFolder2_GetClassID,
919 ICPanel_PersistFolder2_Initialize,
920 ICPanel_PersistFolder2_GetCurFolder
923 HRESULT CPanel_GetIconLocationW(LPCITEMIDLIST pidl,
924 LPWSTR szIconFile, UINT cchMax, int* piIndex)
926 PIDLCPanelStruct* pcpanel = _ILGetCPanelPointer(pidl);
928 if (!pcpanel)
929 return E_INVALIDARG;
931 MultiByteToWideChar(CP_ACP, 0, pcpanel->szName, -1, szIconFile, cchMax);
932 *piIndex = pcpanel->iconIdx!=-1? pcpanel->iconIdx: 0;
934 return S_OK;
938 /**************************************************************************
939 * IShellExecuteHookW Implementation
942 static HRESULT WINAPI IShellExecuteHookW_fnQueryInterface(
943 IShellExecuteHookW* iface, REFIID riid, void** ppvObject)
945 ICPanelImpl *This = impl_from_IShellExecuteHookW(iface);
947 TRACE("(%p)->(count=%u)\n", This, This->ref);
949 return IUnknown_QueryInterface(This->pUnkOuter, riid, ppvObject);
952 static ULONG STDMETHODCALLTYPE IShellExecuteHookW_fnAddRef(IShellExecuteHookW* iface)
954 ICPanelImpl *This = impl_from_IShellExecuteHookW(iface);
956 TRACE("(%p)->(count=%u)\n", This, This->ref);
958 return IUnknown_AddRef(This->pUnkOuter);
961 static ULONG STDMETHODCALLTYPE IShellExecuteHookW_fnRelease(IShellExecuteHookW* iface)
963 ICPanelImpl *This = impl_from_IShellExecuteHookW(iface);
965 TRACE("(%p)\n", This);
967 return IUnknown_Release(This->pUnkOuter);
970 static HRESULT WINAPI IShellExecuteHookW_fnExecute(IShellExecuteHookW *iface,
971 LPSHELLEXECUTEINFOW psei)
973 ICPanelImpl *This = impl_from_IShellExecuteHookW(iface);
974 static const WCHAR wCplopen[] = {'c','p','l','o','p','e','n','\0'};
976 SHELLEXECUTEINFOW sei_tmp;
977 PIDLCPanelStruct* pcpanel;
978 WCHAR path[MAX_PATH];
979 WCHAR params[MAX_PATH];
980 BOOL ret;
981 int l;
983 TRACE("(%p)->execute(%p)\n", This, psei);
985 if (!psei)
986 return E_INVALIDARG;
988 pcpanel = _ILGetCPanelPointer(ILFindLastID(psei->lpIDList));
990 if (!pcpanel)
991 return E_INVALIDARG;
993 path[0] = '\"';
994 /* Return value from MultiByteToWideChar includes terminating NUL, which
995 * compensates for the starting double quote we just put in */
996 l = MultiByteToWideChar(CP_ACP, 0, pcpanel->szName, -1, path+1, MAX_PATH-1);
998 /* pass applet name to Control_RunDLL to distinguish between applets in one .cpl file */
999 path[l++] = '"';
1000 path[l] = '\0';
1002 MultiByteToWideChar(CP_ACP, 0, pcpanel->szName+pcpanel->offsDispName, -1, params, MAX_PATH);
1004 sei_tmp = *psei;
1005 sei_tmp.lpFile = path;
1006 sei_tmp.lpParameters = params;
1007 sei_tmp.fMask &= ~SEE_MASK_INVOKEIDLIST;
1008 sei_tmp.lpVerb = wCplopen;
1010 ret = ShellExecuteExW(&sei_tmp);
1011 if (ret)
1012 return S_OK;
1013 else
1014 return S_FALSE;
1017 static const IShellExecuteHookWVtbl vt_ShellExecuteHookW =
1020 IShellExecuteHookW_fnQueryInterface,
1021 IShellExecuteHookW_fnAddRef,
1022 IShellExecuteHookW_fnRelease,
1024 IShellExecuteHookW_fnExecute
1028 /**************************************************************************
1029 * IShellExecuteHookA Implementation
1032 static HRESULT WINAPI IShellExecuteHookA_fnQueryInterface(IShellExecuteHookA* iface, REFIID riid, void** ppvObject)
1034 ICPanelImpl *This = impl_from_IShellExecuteHookA(iface);
1036 TRACE("(%p)->(count=%u)\n", This, This->ref);
1038 return IUnknown_QueryInterface(This->pUnkOuter, riid, ppvObject);
1041 static ULONG STDMETHODCALLTYPE IShellExecuteHookA_fnAddRef(IShellExecuteHookA* iface)
1043 ICPanelImpl *This = impl_from_IShellExecuteHookA(iface);
1045 TRACE("(%p)->(count=%u)\n", This, This->ref);
1047 return IUnknown_AddRef(This->pUnkOuter);
1050 static ULONG STDMETHODCALLTYPE IShellExecuteHookA_fnRelease(IShellExecuteHookA* iface)
1052 ICPanelImpl *This = impl_from_IShellExecuteHookA(iface);
1054 TRACE("(%p)\n", This);
1056 return IUnknown_Release(This->pUnkOuter);
1059 static HRESULT WINAPI IShellExecuteHookA_fnExecute(IShellExecuteHookA *iface,
1060 LPSHELLEXECUTEINFOA psei)
1062 ICPanelImpl *This = impl_from_IShellExecuteHookA(iface);
1064 SHELLEXECUTEINFOA sei_tmp;
1065 PIDLCPanelStruct* pcpanel;
1066 char path[MAX_PATH];
1067 BOOL ret;
1069 TRACE("(%p)->execute(%p)\n", This, psei);
1071 if (!psei)
1072 return E_INVALIDARG;
1074 pcpanel = _ILGetCPanelPointer(ILFindLastID(psei->lpIDList));
1076 if (!pcpanel)
1077 return E_INVALIDARG;
1079 path[0] = '\"';
1080 memcpy(path+1, pcpanel->szName, strlen(pcpanel->szName) + 1);
1082 /* pass applet name to Control_RunDLL to distinguish between applets in one .cpl file */
1083 lstrcatA(path, "\" ");
1084 lstrcatA(path, pcpanel->szName+pcpanel->offsDispName);
1086 sei_tmp = *psei;
1087 sei_tmp.lpFile = path;
1088 sei_tmp.fMask &= ~SEE_MASK_INVOKEIDLIST;
1090 ret = ShellExecuteExA(&sei_tmp);
1091 if (ret)
1092 return S_OK;
1093 else
1094 return S_FALSE;
1097 static const IShellExecuteHookAVtbl vt_ShellExecuteHookA =
1099 IShellExecuteHookA_fnQueryInterface,
1100 IShellExecuteHookA_fnAddRef,
1101 IShellExecuteHookA_fnRelease,
1102 IShellExecuteHookA_fnExecute