kernel32: Improve tracing in GlobalAlloc.
[wine/wine64.git] / dlls / shell32 / cpanelfolder.c
blobaa09edf62c2add266eb60cf6d6c60c451b291ae9
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
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 "wine/debug.h"
51 #include "debughlp.h"
52 #include "shfldr.h"
54 WINE_DEFAULT_DEBUG_CHANNEL(shell);
56 /***********************************************************************
57 * control panel implementation in shell namespace
60 typedef struct {
61 const IShellFolder2Vtbl *lpVtbl;
62 LONG ref;
63 const IPersistFolder2Vtbl *lpVtblPersistFolder2;
64 const IShellExecuteHookWVtbl *lpVtblShellExecuteHookW;
65 const IShellExecuteHookAVtbl *lpVtblShellExecuteHookA;
67 IUnknown *pUnkOuter; /* used for aggregation */
69 /* both paths are parsible from the desktop */
70 LPITEMIDLIST pidlRoot; /* absolute pidl */
71 int dwAttributes; /* attributes returned by GetAttributesOf FIXME: use it */
72 } ICPanelImpl;
74 static const IShellFolder2Vtbl vt_ShellFolder2;
75 static const IPersistFolder2Vtbl vt_PersistFolder2;
76 static const IShellExecuteHookWVtbl vt_ShellExecuteHookW;
77 static const IShellExecuteHookAVtbl vt_ShellExecuteHookA;
79 static inline ICPanelImpl *impl_from_IPersistFolder2( IPersistFolder2 *iface )
81 return (ICPanelImpl *)((char*)iface - FIELD_OFFSET(ICPanelImpl, lpVtblPersistFolder2));
84 static inline ICPanelImpl *impl_from_IShellExecuteHookW( IShellExecuteHookW *iface )
86 return (ICPanelImpl *)((char*)iface - FIELD_OFFSET(ICPanelImpl, lpVtblShellExecuteHookW));
89 static inline ICPanelImpl *impl_from_IShellExecuteHookA( IShellExecuteHookA *iface )
91 return (ICPanelImpl *)((char*)iface - FIELD_OFFSET(ICPanelImpl, lpVtblShellExecuteHookA));
96 converts This to an interface pointer
98 #define _IUnknown_(This) (IUnknown*)&(This->lpVtbl)
99 #define _IShellFolder_(This) (IShellFolder*)&(This->lpVtbl)
100 #define _IShellFolder2_(This) (IShellFolder2*)&(This->lpVtbl)
102 #define _IPersist_(This) (IPersist*)&(This->lpVtblPersistFolder2)
103 #define _IPersistFolder_(This) (IPersistFolder*)&(This->lpVtblPersistFolder2)
104 #define _IPersistFolder2_(This) (IPersistFolder2*)&(This->lpVtblPersistFolder2)
105 #define _IShellExecuteHookW_(This) (IShellExecuteHookW*)&(This->lpVtblShellExecuteHookW)
106 #define _IShellExecuteHookA_(This) (IShellExecuteHookA*)&(This->lpVtblShellExecuteHookA)
108 /***********************************************************************
109 * IShellFolder [ControlPanel] implementation
112 static const shvheader ControlPanelSFHeader[] = {
113 {IDS_SHV_COLUMN8, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 15},/*FIXME*/
114 {IDS_SHV_COLUMN9, SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_RIGHT, 200},/*FIXME*/
117 #define CONROLPANELSHELLVIEWCOLUMNS 2
119 /**************************************************************************
120 * IControlPanel_Constructor
122 HRESULT WINAPI IControlPanel_Constructor(IUnknown* pUnkOuter, REFIID riid, LPVOID * ppv)
124 ICPanelImpl *sf;
126 TRACE("unkOut=%p %s\n", pUnkOuter, shdebugstr_guid(riid));
128 if (!ppv)
129 return E_POINTER;
130 if (pUnkOuter && !IsEqualIID (riid, &IID_IUnknown))
131 return CLASS_E_NOAGGREGATION;
133 sf = (ICPanelImpl *) LocalAlloc(LMEM_ZEROINIT, sizeof(ICPanelImpl));
134 if (!sf)
135 return E_OUTOFMEMORY;
137 sf->ref = 0;
138 sf->lpVtbl = &vt_ShellFolder2;
139 sf->lpVtblPersistFolder2 = &vt_PersistFolder2;
140 sf->lpVtblShellExecuteHookW = &vt_ShellExecuteHookW;
141 sf->lpVtblShellExecuteHookA = &vt_ShellExecuteHookA;
142 sf->pidlRoot = _ILCreateControlPanel(); /* my qualified pidl */
143 sf->pUnkOuter = pUnkOuter ? pUnkOuter : _IUnknown_ (sf);
145 if (!SUCCEEDED(IUnknown_QueryInterface(_IUnknown_(sf), riid, ppv))) {
146 IUnknown_Release(_IUnknown_(sf));
147 return E_NOINTERFACE;
150 TRACE("--(%p)\n", sf);
151 return S_OK;
154 /**************************************************************************
155 * ISF_ControlPanel_fnQueryInterface
157 * NOTES supports not IPersist/IPersistFolder
159 static HRESULT WINAPI ISF_ControlPanel_fnQueryInterface(IShellFolder2 * iface, REFIID riid, LPVOID * ppvObject)
161 ICPanelImpl *This = (ICPanelImpl *)iface;
163 TRACE("(%p)->(%s,%p)\n", This, shdebugstr_guid(riid), ppvObject);
165 *ppvObject = NULL;
167 if (IsEqualIID(riid, &IID_IUnknown) ||
168 IsEqualIID(riid, &IID_IShellFolder) || IsEqualIID(riid, &IID_IShellFolder2))
169 *ppvObject = This;
170 else if (IsEqualIID(riid, &IID_IPersist) ||
171 IsEqualIID(riid, &IID_IPersistFolder) || IsEqualIID(riid, &IID_IPersistFolder2))
172 *ppvObject = _IPersistFolder2_(This);
173 else if (IsEqualIID(riid, &IID_IShellExecuteHookW))
174 *ppvObject = _IShellExecuteHookW_(This);
175 else if (IsEqualIID(riid, &IID_IShellExecuteHookA))
176 *ppvObject = _IShellExecuteHookA_(This);
178 if (*ppvObject) {
179 IUnknown_AddRef((IUnknown *)(*ppvObject));
180 TRACE("-- Interface:(%p)->(%p)\n", ppvObject, *ppvObject);
181 return S_OK;
183 TRACE("-- Interface: E_NOINTERFACE\n");
184 return E_NOINTERFACE;
187 static ULONG WINAPI ISF_ControlPanel_fnAddRef(IShellFolder2 * iface)
189 ICPanelImpl *This = (ICPanelImpl *)iface;
190 ULONG refCount = InterlockedIncrement(&This->ref);
192 TRACE("(%p)->(count=%u)\n", This, refCount - 1);
194 return refCount;
197 static ULONG WINAPI ISF_ControlPanel_fnRelease(IShellFolder2 * iface)
199 ICPanelImpl *This = (ICPanelImpl *)iface;
200 ULONG refCount = InterlockedDecrement(&This->ref);
202 TRACE("(%p)->(count=%u)\n", This, refCount + 1);
204 if (!refCount) {
205 TRACE("-- destroying IShellFolder(%p)\n", This);
206 SHFree(This->pidlRoot);
207 LocalFree((HLOCAL) This);
209 return refCount;
212 /**************************************************************************
213 * ISF_ControlPanel_fnParseDisplayName
215 static HRESULT WINAPI
216 ISF_ControlPanel_fnParseDisplayName(IShellFolder2 * iface,
217 HWND hwndOwner,
218 LPBC pbc,
219 LPOLESTR lpszDisplayName,
220 DWORD * pchEaten, LPITEMIDLIST * ppidl, DWORD * pdwAttributes)
222 ICPanelImpl *This = (ICPanelImpl *)iface;
224 HRESULT hr = E_INVALIDARG;
226 FIXME("(%p)->(HWND=%p,%p,%p=%s,%p,pidl=%p,%p)\n",
227 This, hwndOwner, pbc, lpszDisplayName, debugstr_w(lpszDisplayName), pchEaten, ppidl, pdwAttributes);
229 *ppidl = 0;
230 if (pchEaten)
231 *pchEaten = 0;
233 TRACE("(%p)->(-- ret=0x%08x)\n", This, hr);
235 return hr;
238 static LPITEMIDLIST _ILCreateCPanelApplet(LPCSTR name, LPCSTR displayName,
239 LPCSTR comment, int iconIdx)
241 PIDLCPanelStruct *p;
242 LPITEMIDLIST pidl;
243 PIDLDATA tmp;
244 int size0 = (char*)&tmp.u.cpanel.szName-(char*)&tmp.u.cpanel;
245 int size = size0;
246 int l;
248 tmp.type = PT_CPLAPPLET;
249 tmp.u.cpanel.dummy = 0;
250 tmp.u.cpanel.iconIdx = iconIdx;
252 l = strlen(name);
253 size += l+1;
255 tmp.u.cpanel.offsDispName = l+1;
256 l = strlen(displayName);
257 size += l+1;
259 tmp.u.cpanel.offsComment = tmp.u.cpanel.offsDispName+1+l;
260 l = strlen(comment);
261 size += l+1;
263 pidl = SHAlloc(size+4);
264 if (!pidl)
265 return NULL;
267 pidl->mkid.cb = size+2;
268 memcpy(pidl->mkid.abID, &tmp, 2+size0);
270 p = &((PIDLDATA*)pidl->mkid.abID)->u.cpanel;
271 strcpy(p->szName, name);
272 strcpy(p->szName+tmp.u.cpanel.offsDispName, displayName);
273 strcpy(p->szName+tmp.u.cpanel.offsComment, comment);
275 *(WORD*)((char*)pidl+(size+2)) = 0;
277 pcheck(pidl);
279 return pidl;
282 /**************************************************************************
283 * _ILGetCPanelPointer()
284 * gets a pointer to the control panel struct stored in the pidl
286 static PIDLCPanelStruct* _ILGetCPanelPointer(LPCITEMIDLIST pidl)
288 LPPIDLDATA pdata = _ILGetDataPointer(pidl);
290 if (pdata && pdata->type==PT_CPLAPPLET)
291 return (PIDLCPanelStruct*)&(pdata->u.cpanel);
293 return NULL;
296 /**************************************************************************
297 * ISF_ControlPanel_fnEnumObjects
299 static BOOL SHELL_RegisterCPanelApp(IEnumIDList* list, LPCSTR path)
301 LPITEMIDLIST pidl;
302 CPlApplet* applet;
303 CPanel panel;
304 CPLINFO info;
305 unsigned i;
306 int iconIdx;
308 char displayName[MAX_PATH];
309 char comment[MAX_PATH];
311 WCHAR wpath[MAX_PATH];
313 MultiByteToWideChar(CP_ACP, 0, path, -1, wpath, MAX_PATH);
315 panel.first = NULL;
316 applet = Control_LoadApplet(0, wpath, &panel);
318 if (applet)
320 for(i=0; i<applet->count; ++i)
322 WideCharToMultiByte(CP_ACP, 0, applet->info[i].szName, -1, displayName, MAX_PATH, 0, 0);
323 WideCharToMultiByte(CP_ACP, 0, applet->info[i].szInfo, -1, comment, MAX_PATH, 0, 0);
325 applet->proc(0, CPL_INQUIRE, i, (LPARAM)&info);
327 if (info.idIcon > 0)
328 iconIdx = -info.idIcon; /* negative icon index instead of icon number */
329 else
330 iconIdx = 0;
332 pidl = _ILCreateCPanelApplet(path, displayName, comment, iconIdx);
334 if (pidl)
335 AddToEnumList(list, pidl);
337 Control_UnloadApplet(applet);
339 return TRUE;
342 static int SHELL_RegisterRegistryCPanelApps(IEnumIDList* list, HKEY hkey_root, LPCSTR szRepPath)
344 char name[MAX_PATH];
345 char value[MAX_PATH];
346 HKEY hkey;
348 int cnt = 0;
350 if (RegOpenKeyA(hkey_root, szRepPath, &hkey) == ERROR_SUCCESS)
352 int idx = 0;
354 for(;; ++idx)
356 DWORD nameLen = MAX_PATH;
357 DWORD valueLen = MAX_PATH;
359 if (RegEnumValueA(hkey, idx, name, &nameLen, NULL, NULL, (LPBYTE)&value, &valueLen) != ERROR_SUCCESS)
360 break;
362 if (SHELL_RegisterCPanelApp(list, value))
363 ++cnt;
365 RegCloseKey(hkey);
368 return cnt;
371 static int SHELL_RegisterCPanelFolders(IEnumIDList* list, HKEY hkey_root, LPCSTR szRepPath)
373 char name[MAX_PATH];
374 HKEY hkey;
376 int cnt = 0;
378 if (RegOpenKeyA(hkey_root, szRepPath, &hkey) == ERROR_SUCCESS)
380 int idx = 0;
381 for(;; ++idx)
383 if (RegEnumKeyA(hkey, idx, name, MAX_PATH) != ERROR_SUCCESS)
384 break;
386 if (*name == '{')
388 LPITEMIDLIST pidl = _ILCreateGuidFromStrA(name);
390 if (pidl && AddToEnumList(list, pidl))
391 ++cnt;
395 RegCloseKey(hkey);
398 return cnt;
401 /**************************************************************************
402 * CreateCPanelEnumList()
404 static BOOL CreateCPanelEnumList(
405 IEnumIDList * iface,
406 DWORD dwFlags)
408 CHAR szPath[MAX_PATH];
409 WIN32_FIND_DATAA wfd;
410 HANDLE hFile;
412 TRACE("(%p)->(flags=0x%08x)\n", iface, dwFlags);
414 /* enumerate control panel folders */
415 if (dwFlags & SHCONTF_FOLDERS)
416 SHELL_RegisterCPanelFolders(iface, HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ControlPanel\\NameSpace");
418 /* enumerate the control panel applets */
419 if (dwFlags & SHCONTF_NONFOLDERS)
421 LPSTR p;
423 GetSystemDirectoryA(szPath, MAX_PATH);
424 p = PathAddBackslashA(szPath);
425 strcpy(p, "*.cpl");
427 TRACE("-- (%p)-> enumerate SHCONTF_NONFOLDERS of %s\n",iface,debugstr_a(szPath));
428 hFile = FindFirstFileA(szPath, &wfd);
430 if (hFile != INVALID_HANDLE_VALUE)
434 if (!(dwFlags & SHCONTF_INCLUDEHIDDEN) && (wfd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN))
435 continue;
437 if (!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
438 strcpy(p, wfd.cFileName);
439 SHELL_RegisterCPanelApp((IEnumIDList*)iface, szPath);
441 } while(FindNextFileA(hFile, &wfd));
442 FindClose(hFile);
445 SHELL_RegisterRegistryCPanelApps((IEnumIDList*)iface, HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Control Panel\\Cpls");
446 SHELL_RegisterRegistryCPanelApps((IEnumIDList*)iface, HKEY_CURRENT_USER, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Control Panel\\Cpls");
448 return TRUE;
451 /**************************************************************************
452 * ISF_ControlPanel_fnEnumObjects
454 static HRESULT WINAPI
455 ISF_ControlPanel_fnEnumObjects(IShellFolder2 * iface, HWND hwndOwner, DWORD dwFlags, LPENUMIDLIST * ppEnumIDList)
457 ICPanelImpl *This = (ICPanelImpl *)iface;
459 TRACE("(%p)->(HWND=%p flags=0x%08x pplist=%p)\n", This, hwndOwner, dwFlags, ppEnumIDList);
461 *ppEnumIDList = IEnumIDList_Constructor();
462 if (*ppEnumIDList)
463 CreateCPanelEnumList(*ppEnumIDList, dwFlags);
465 TRACE("--(%p)->(new ID List: %p)\n", This, *ppEnumIDList);
467 return(*ppEnumIDList) ? S_OK : E_OUTOFMEMORY;
470 /**************************************************************************
471 * ISF_ControlPanel_fnBindToObject
473 static HRESULT WINAPI
474 ISF_ControlPanel_fnBindToObject(IShellFolder2 * iface, LPCITEMIDLIST pidl,
475 LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
477 ICPanelImpl *This = (ICPanelImpl *)iface;
479 TRACE("(%p)->(pidl=%p,%p,%s,%p)\n", This, pidl, pbcReserved, shdebugstr_guid(riid), ppvOut);
481 return SHELL32_BindToChild(This->pidlRoot, NULL, pidl, riid, ppvOut);
484 /**************************************************************************
485 * ISF_ControlPanel_fnBindToStorage
487 static HRESULT WINAPI
488 ISF_ControlPanel_fnBindToStorage(IShellFolder2 * iface,
489 LPCITEMIDLIST pidl, LPBC pbcReserved, REFIID riid, LPVOID * ppvOut)
491 ICPanelImpl *This = (ICPanelImpl *)iface;
493 FIXME("(%p)->(pidl=%p,%p,%s,%p) stub\n", This, pidl, pbcReserved, shdebugstr_guid(riid), ppvOut);
495 *ppvOut = NULL;
496 return E_NOTIMPL;
499 /**************************************************************************
500 * ISF_ControlPanel_fnCompareIDs
503 static HRESULT WINAPI
504 ISF_ControlPanel_fnCompareIDs(IShellFolder2 * iface, LPARAM lParam, LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
506 ICPanelImpl *This = (ICPanelImpl *)iface;
508 int nReturn;
510 TRACE("(%p)->(0x%08lx,pidl1=%p,pidl2=%p)\n", This, lParam, pidl1, pidl2);
511 nReturn = SHELL32_CompareIDs(_IShellFolder_(This), lParam, pidl1, pidl2);
512 TRACE("-- %i\n", nReturn);
513 return nReturn;
516 /**************************************************************************
517 * ISF_ControlPanel_fnCreateViewObject
519 static HRESULT WINAPI
520 ISF_ControlPanel_fnCreateViewObject(IShellFolder2 * iface, HWND hwndOwner, REFIID riid, LPVOID * ppvOut)
522 ICPanelImpl *This = (ICPanelImpl *)iface;
524 LPSHELLVIEW pShellView;
525 HRESULT hr = E_INVALIDARG;
527 TRACE("(%p)->(hwnd=%p,%s,%p)\n", This, hwndOwner, shdebugstr_guid(riid), ppvOut);
529 if (ppvOut) {
530 *ppvOut = NULL;
532 if (IsEqualIID(riid, &IID_IDropTarget)) {
533 WARN("IDropTarget not implemented\n");
534 hr = E_NOTIMPL;
535 } else if (IsEqualIID(riid, &IID_IContextMenu)) {
536 WARN("IContextMenu not implemented\n");
537 hr = E_NOTIMPL;
538 } else if (IsEqualIID(riid, &IID_IShellView)) {
539 pShellView = IShellView_Constructor((IShellFolder *) iface);
540 if (pShellView) {
541 hr = IShellView_QueryInterface(pShellView, riid, ppvOut);
542 IShellView_Release(pShellView);
546 TRACE("--(%p)->(interface=%p)\n", This, ppvOut);
547 return hr;
550 /**************************************************************************
551 * ISF_ControlPanel_fnGetAttributesOf
553 static HRESULT WINAPI
554 ISF_ControlPanel_fnGetAttributesOf(IShellFolder2 * iface, UINT cidl, LPCITEMIDLIST * apidl, DWORD * rgfInOut)
556 ICPanelImpl *This = (ICPanelImpl *)iface;
558 HRESULT hr = S_OK;
560 TRACE("(%p)->(cidl=%d apidl=%p mask=%p (0x%08x))\n",
561 This, cidl, apidl, rgfInOut, rgfInOut ? *rgfInOut : 0);
563 if (!rgfInOut)
564 return E_INVALIDARG;
565 if (cidl && !apidl)
566 return E_INVALIDARG;
568 if (*rgfInOut == 0)
569 *rgfInOut = ~0;
571 while(cidl > 0 && *apidl) {
572 pdump(*apidl);
573 SHELL32_GetItemAttributes(_IShellFolder_(This), *apidl, rgfInOut);
574 apidl++;
575 cidl--;
577 /* make sure SFGAO_VALIDATE is cleared, some apps depend on that */
578 *rgfInOut &= ~SFGAO_VALIDATE;
580 TRACE("-- result=0x%08x\n", *rgfInOut);
581 return hr;
584 /**************************************************************************
585 * ISF_ControlPanel_fnGetUIObjectOf
587 * PARAMETERS
588 * HWND hwndOwner, //[in ] Parent window for any output
589 * UINT cidl, //[in ] array size
590 * LPCITEMIDLIST* apidl, //[in ] simple pidl array
591 * REFIID riid, //[in ] Requested Interface
592 * UINT* prgfInOut, //[ ] reserved
593 * LPVOID* ppvObject) //[out] Resulting Interface
596 static HRESULT WINAPI
597 ISF_ControlPanel_fnGetUIObjectOf(IShellFolder2 * iface,
598 HWND hwndOwner,
599 UINT cidl, LPCITEMIDLIST * apidl, REFIID riid, UINT * prgfInOut, LPVOID * ppvOut)
601 ICPanelImpl *This = (ICPanelImpl *)iface;
603 LPITEMIDLIST pidl;
604 IUnknown *pObj = NULL;
605 HRESULT hr = E_INVALIDARG;
607 TRACE("(%p)->(%p,%u,apidl=%p,%s,%p,%p)\n",
608 This, hwndOwner, cidl, apidl, shdebugstr_guid(riid), prgfInOut, ppvOut);
610 if (ppvOut) {
611 *ppvOut = NULL;
613 if (IsEqualIID(riid, &IID_IContextMenu) &&(cidl >= 1)) {
614 pObj = (LPUNKNOWN) ISvItemCm_Constructor((IShellFolder *) iface, This->pidlRoot, apidl, cidl);
615 hr = S_OK;
616 } else if (IsEqualIID(riid, &IID_IDataObject) &&(cidl >= 1)) {
617 pObj = (LPUNKNOWN) IDataObject_Constructor(hwndOwner, This->pidlRoot, apidl, cidl);
618 hr = S_OK;
619 } else if (IsEqualIID(riid, &IID_IExtractIconA) &&(cidl == 1)) {
620 pidl = ILCombine(This->pidlRoot, apidl[0]);
621 pObj = (LPUNKNOWN) IExtractIconA_Constructor(pidl);
622 SHFree(pidl);
623 hr = S_OK;
624 } else if (IsEqualIID(riid, &IID_IExtractIconW) &&(cidl == 1)) {
625 pidl = ILCombine(This->pidlRoot, apidl[0]);
626 pObj = (LPUNKNOWN) IExtractIconW_Constructor(pidl);
627 SHFree(pidl);
628 hr = S_OK;
629 } else if ((IsEqualIID(riid,&IID_IShellLinkW) || IsEqualIID(riid,&IID_IShellLinkA))
630 && (cidl == 1)) {
631 pidl = ILCombine(This->pidlRoot, apidl[0]);
632 hr = IShellLink_ConstructFromFile(NULL, riid, pidl,(LPVOID*)&pObj);
633 SHFree(pidl);
634 } else {
635 hr = E_NOINTERFACE;
638 if (SUCCEEDED(hr) && !pObj)
639 hr = E_OUTOFMEMORY;
641 *ppvOut = pObj;
643 TRACE("(%p)->hr=0x%08x\n", This, hr);
644 return hr;
647 /**************************************************************************
648 * ISF_ControlPanel_fnGetDisplayNameOf
650 static HRESULT WINAPI ISF_ControlPanel_fnGetDisplayNameOf(IShellFolder2 * iface, LPCITEMIDLIST pidl, DWORD dwFlags, LPSTRRET strRet)
652 ICPanelImpl *This = (ICPanelImpl *)iface;
654 CHAR szPath[MAX_PATH];
655 WCHAR wszPath[MAX_PATH+1]; /* +1 for potential backslash */
656 PIDLCPanelStruct* pcpanel;
658 *szPath = '\0';
660 TRACE("(%p)->(pidl=%p,0x%08x,%p)\n", This, pidl, dwFlags, strRet);
661 pdump(pidl);
663 if (!pidl || !strRet)
664 return E_INVALIDARG;
666 pcpanel = _ILGetCPanelPointer(pidl);
668 if (pcpanel) {
669 lstrcpyA(szPath, pcpanel->szName+pcpanel->offsDispName);
671 if (!(dwFlags & SHGDN_FORPARSING))
672 FIXME("retrieve display name from control panel app\n");
674 /* take names of special folders only if it's only this folder */
675 else if (_ILIsSpecialFolder(pidl)) {
676 BOOL bSimplePidl = _ILIsPidlSimple(pidl);
678 if (bSimplePidl) {
679 _ILSimpleGetTextW(pidl, wszPath, MAX_PATH); /* append my own path */
680 } else {
681 FIXME("special pidl\n");
684 if ((dwFlags & SHGDN_FORPARSING) && !bSimplePidl) { /* go deeper if needed */
685 int len = 0;
687 PathAddBackslashW(wszPath);
688 len = lstrlenW(wszPath);
690 if (!SUCCEEDED
691 (SHELL32_GetDisplayNameOfChild(iface, pidl, dwFlags | SHGDN_INFOLDER, wszPath + len, MAX_PATH + 1 - len)))
692 return E_OUTOFMEMORY;
693 if (!WideCharToMultiByte(CP_ACP, 0, wszPath, -1, szPath, MAX_PATH, NULL, NULL))
694 wszPath[0] = '\0';
698 strRet->uType = STRRET_CSTR;
699 lstrcpynA(strRet->u.cStr, szPath, MAX_PATH);
701 TRACE("--(%p)->(%s)\n", This, szPath);
702 return S_OK;
705 /**************************************************************************
706 * ISF_ControlPanel_fnSetNameOf
707 * Changes the name of a file object or subfolder, possibly changing its item
708 * identifier in the process.
710 * PARAMETERS
711 * HWND hwndOwner, //[in ] Owner window for output
712 * LPCITEMIDLIST pidl, //[in ] simple pidl of item to change
713 * LPCOLESTR lpszName, //[in ] the items new display name
714 * DWORD dwFlags, //[in ] SHGNO formatting flags
715 * LPITEMIDLIST* ppidlOut) //[out] simple pidl returned
717 static HRESULT WINAPI ISF_ControlPanel_fnSetNameOf(IShellFolder2 * iface, HWND hwndOwner, LPCITEMIDLIST pidl, /*simple pidl */
718 LPCOLESTR lpName, DWORD dwFlags, LPITEMIDLIST * pPidlOut)
720 ICPanelImpl *This = (ICPanelImpl *)iface;
721 FIXME("(%p)->(%p,pidl=%p,%s,%u,%p)\n", This, hwndOwner, pidl, debugstr_w(lpName), dwFlags, pPidlOut);
722 return E_FAIL;
725 static HRESULT WINAPI ISF_ControlPanel_fnGetDefaultSearchGUID(IShellFolder2 * iface, GUID * pguid)
727 ICPanelImpl *This = (ICPanelImpl *)iface;
728 FIXME("(%p)\n", This);
729 return E_NOTIMPL;
731 static HRESULT WINAPI ISF_ControlPanel_fnEnumSearches(IShellFolder2 * iface, IEnumExtraSearch ** ppenum)
733 ICPanelImpl *This = (ICPanelImpl *)iface;
734 FIXME("(%p)\n", This);
735 return E_NOTIMPL;
737 static HRESULT WINAPI ISF_ControlPanel_fnGetDefaultColumn(IShellFolder2 * iface, DWORD dwRes, ULONG * pSort, ULONG * pDisplay)
739 ICPanelImpl *This = (ICPanelImpl *)iface;
741 TRACE("(%p)\n", This);
743 if (pSort) *pSort = 0;
744 if (pDisplay) *pDisplay = 0;
745 return S_OK;
747 static HRESULT WINAPI ISF_ControlPanel_fnGetDefaultColumnState(IShellFolder2 * iface, UINT iColumn, DWORD * pcsFlags)
749 ICPanelImpl *This = (ICPanelImpl *)iface;
751 TRACE("(%p)\n", This);
753 if (!pcsFlags || iColumn >= CONROLPANELSHELLVIEWCOLUMNS) return E_INVALIDARG;
754 *pcsFlags = ControlPanelSFHeader[iColumn].pcsFlags;
755 return S_OK;
757 static HRESULT WINAPI ISF_ControlPanel_fnGetDetailsEx(IShellFolder2 * iface, LPCITEMIDLIST pidl, const SHCOLUMNID * pscid, VARIANT * pv)
759 ICPanelImpl *This = (ICPanelImpl *)iface;
760 FIXME("(%p)\n", This);
761 return E_NOTIMPL;
764 static HRESULT WINAPI ISF_ControlPanel_fnGetDetailsOf(IShellFolder2 * iface, LPCITEMIDLIST pidl, UINT iColumn, SHELLDETAILS * psd)
766 ICPanelImpl *This = (ICPanelImpl *)iface;
767 HRESULT hr;
769 TRACE("(%p)->(%p %i %p)\n", This, pidl, iColumn, psd);
771 if (!psd || iColumn >= CONROLPANELSHELLVIEWCOLUMNS)
772 return E_INVALIDARG;
774 if (!pidl) {
775 psd->fmt = ControlPanelSFHeader[iColumn].fmt;
776 psd->cxChar = ControlPanelSFHeader[iColumn].cxChar;
777 psd->str.uType = STRRET_CSTR;
778 LoadStringA(shell32_hInstance, ControlPanelSFHeader[iColumn].colnameid, psd->str.u.cStr, MAX_PATH);
779 return S_OK;
780 } else {
781 psd->str.u.cStr[0] = 0x00;
782 psd->str.uType = STRRET_CSTR;
783 switch(iColumn) {
784 case 0: /* name */
785 hr = IShellFolder_GetDisplayNameOf(iface, pidl, SHGDN_NORMAL | SHGDN_INFOLDER, &psd->str);
786 break;
787 case 1: /* comment */
788 _ILGetFileType(pidl, psd->str.u.cStr, MAX_PATH);
789 break;
791 hr = S_OK;
794 return hr;
796 static HRESULT WINAPI ISF_ControlPanel_fnMapColumnToSCID(IShellFolder2 * iface, UINT column, SHCOLUMNID * pscid)
798 ICPanelImpl *This = (ICPanelImpl *)iface;
799 FIXME("(%p)\n", This);
800 return E_NOTIMPL;
803 static const IShellFolder2Vtbl vt_ShellFolder2 =
806 ISF_ControlPanel_fnQueryInterface,
807 ISF_ControlPanel_fnAddRef,
808 ISF_ControlPanel_fnRelease,
809 ISF_ControlPanel_fnParseDisplayName,
810 ISF_ControlPanel_fnEnumObjects,
811 ISF_ControlPanel_fnBindToObject,
812 ISF_ControlPanel_fnBindToStorage,
813 ISF_ControlPanel_fnCompareIDs,
814 ISF_ControlPanel_fnCreateViewObject,
815 ISF_ControlPanel_fnGetAttributesOf,
816 ISF_ControlPanel_fnGetUIObjectOf,
817 ISF_ControlPanel_fnGetDisplayNameOf,
818 ISF_ControlPanel_fnSetNameOf,
820 /* ShellFolder2 */
821 ISF_ControlPanel_fnGetDefaultSearchGUID,
822 ISF_ControlPanel_fnEnumSearches,
823 ISF_ControlPanel_fnGetDefaultColumn,
824 ISF_ControlPanel_fnGetDefaultColumnState,
825 ISF_ControlPanel_fnGetDetailsEx,
826 ISF_ControlPanel_fnGetDetailsOf,
827 ISF_ControlPanel_fnMapColumnToSCID
830 /************************************************************************
831 * ICPanel_PersistFolder2_QueryInterface
833 static HRESULT WINAPI ICPanel_PersistFolder2_QueryInterface(IPersistFolder2 * iface, REFIID iid, LPVOID * ppvObject)
835 ICPanelImpl *This = impl_from_IPersistFolder2(iface);
837 TRACE("(%p)\n", This);
839 return IUnknown_QueryInterface(_IUnknown_(This), iid, ppvObject);
842 /************************************************************************
843 * ICPanel_PersistFolder2_AddRef
845 static ULONG WINAPI ICPanel_PersistFolder2_AddRef(IPersistFolder2 * iface)
847 ICPanelImpl *This = impl_from_IPersistFolder2(iface);
849 TRACE("(%p)->(count=%u)\n", This, This->ref);
851 return IUnknown_AddRef(_IUnknown_(This));
854 /************************************************************************
855 * ISFPersistFolder_Release
857 static ULONG WINAPI ICPanel_PersistFolder2_Release(IPersistFolder2 * iface)
859 ICPanelImpl *This = impl_from_IPersistFolder2(iface);
861 TRACE("(%p)->(count=%u)\n", This, This->ref);
863 return IUnknown_Release(_IUnknown_(This));
866 /************************************************************************
867 * ICPanel_PersistFolder2_GetClassID
869 static HRESULT WINAPI ICPanel_PersistFolder2_GetClassID(IPersistFolder2 * iface, CLSID * lpClassId)
871 ICPanelImpl *This = impl_from_IPersistFolder2(iface);
873 TRACE("(%p)\n", This);
875 if (!lpClassId)
876 return E_POINTER;
877 *lpClassId = CLSID_ControlPanel;
879 return S_OK;
882 /************************************************************************
883 * ICPanel_PersistFolder2_Initialize
885 * NOTES: it makes no sense to change the pidl
887 static HRESULT WINAPI ICPanel_PersistFolder2_Initialize(IPersistFolder2 * iface, LPCITEMIDLIST pidl)
889 ICPanelImpl *This = impl_from_IPersistFolder2(iface);
890 TRACE("(%p)->(%p)\n", This, pidl);
891 return E_NOTIMPL;
894 /**************************************************************************
895 * IPersistFolder2_fnGetCurFolder
897 static HRESULT WINAPI ICPanel_PersistFolder2_GetCurFolder(IPersistFolder2 * iface, LPITEMIDLIST * pidl)
899 ICPanelImpl *This = impl_from_IPersistFolder2(iface);
901 TRACE("(%p)->(%p)\n", This, pidl);
903 if (!pidl)
904 return E_POINTER;
905 *pidl = ILClone(This->pidlRoot);
906 return S_OK;
909 static const IPersistFolder2Vtbl vt_PersistFolder2 =
912 ICPanel_PersistFolder2_QueryInterface,
913 ICPanel_PersistFolder2_AddRef,
914 ICPanel_PersistFolder2_Release,
915 ICPanel_PersistFolder2_GetClassID,
916 ICPanel_PersistFolder2_Initialize,
917 ICPanel_PersistFolder2_GetCurFolder
920 HRESULT CPanel_GetIconLocationW(LPCITEMIDLIST pidl,
921 LPWSTR szIconFile, UINT cchMax, int* piIndex)
923 PIDLCPanelStruct* pcpanel = _ILGetCPanelPointer(pidl);
925 if (!pcpanel)
926 return E_INVALIDARG;
928 MultiByteToWideChar(CP_ACP, 0, pcpanel->szName, -1, szIconFile, cchMax);
929 *piIndex = pcpanel->iconIdx!=-1? pcpanel->iconIdx: 0;
931 return S_OK;
935 /**************************************************************************
936 * IShellExecuteHookW Implementation
939 static HRESULT WINAPI IShellExecuteHookW_fnQueryInterface(
940 IShellExecuteHookW* iface, REFIID riid, void** ppvObject)
942 ICPanelImpl *This = impl_from_IShellExecuteHookW(iface);
944 TRACE("(%p)->(count=%u)\n", This, This->ref);
946 return IUnknown_QueryInterface(This->pUnkOuter, riid, ppvObject);
949 static ULONG STDMETHODCALLTYPE IShellExecuteHookW_fnAddRef(IShellExecuteHookW* iface)
951 ICPanelImpl *This = impl_from_IShellExecuteHookW(iface);
953 TRACE("(%p)->(count=%u)\n", This, This->ref);
955 return IUnknown_AddRef(This->pUnkOuter);
958 static ULONG STDMETHODCALLTYPE IShellExecuteHookW_fnRelease(IShellExecuteHookW* iface)
960 ICPanelImpl *This = impl_from_IShellExecuteHookW(iface);
962 TRACE("(%p)\n", This);
964 return IUnknown_Release(This->pUnkOuter);
967 static HRESULT WINAPI IShellExecuteHookW_fnExecute(IShellExecuteHookW* iface, LPSHELLEXECUTEINFOW psei)
969 static const WCHAR wCplopen[] = {'c','p','l','o','p','e','n','\0'};
970 ICPanelImpl *This = (ICPanelImpl *)iface;
972 SHELLEXECUTEINFOW sei_tmp;
973 PIDLCPanelStruct* pcpanel;
974 WCHAR path[MAX_PATH];
975 WCHAR params[MAX_PATH];
976 BOOL ret;
977 int l;
979 TRACE("(%p)->execute(%p)\n", This, psei);
981 if (!psei)
982 return E_INVALIDARG;
984 pcpanel = _ILGetCPanelPointer(ILFindLastID(psei->lpIDList));
986 if (!pcpanel)
987 return E_INVALIDARG;
989 path[0] = '\"';
990 /* Return value from MultiByteToWideChar includes terminating NUL, which
991 * compensates for the starting double quote we just put in */
992 l = MultiByteToWideChar(CP_ACP, 0, pcpanel->szName, -1, path+1, MAX_PATH);
994 /* pass applet name to Control_RunDLL to distinguish between applets in one .cpl file */
995 path[l++] = '"';
996 path[l] = '\0';
998 MultiByteToWideChar(CP_ACP, 0, pcpanel->szName+pcpanel->offsDispName, -1, params, MAX_PATH);
1000 memcpy(&sei_tmp, psei, sizeof(sei_tmp));
1001 sei_tmp.lpFile = path;
1002 sei_tmp.lpParameters = params;
1003 sei_tmp.fMask &= ~SEE_MASK_INVOKEIDLIST;
1004 sei_tmp.lpVerb = wCplopen;
1006 ret = ShellExecuteExW(&sei_tmp);
1007 if (ret)
1008 return S_OK;
1009 else
1010 return S_FALSE;
1013 static const IShellExecuteHookWVtbl vt_ShellExecuteHookW =
1016 IShellExecuteHookW_fnQueryInterface,
1017 IShellExecuteHookW_fnAddRef,
1018 IShellExecuteHookW_fnRelease,
1020 IShellExecuteHookW_fnExecute
1024 /**************************************************************************
1025 * IShellExecuteHookA Implementation
1028 static HRESULT WINAPI IShellExecuteHookA_fnQueryInterface(IShellExecuteHookA* iface, REFIID riid, void** ppvObject)
1030 ICPanelImpl *This = impl_from_IShellExecuteHookA(iface);
1032 TRACE("(%p)->(count=%u)\n", This, This->ref);
1034 return IUnknown_QueryInterface(This->pUnkOuter, riid, ppvObject);
1037 static ULONG STDMETHODCALLTYPE IShellExecuteHookA_fnAddRef(IShellExecuteHookA* iface)
1039 ICPanelImpl *This = impl_from_IShellExecuteHookA(iface);
1041 TRACE("(%p)->(count=%u)\n", This, This->ref);
1043 return IUnknown_AddRef(This->pUnkOuter);
1046 static ULONG STDMETHODCALLTYPE IShellExecuteHookA_fnRelease(IShellExecuteHookA* iface)
1048 ICPanelImpl *This = impl_from_IShellExecuteHookA(iface);
1050 TRACE("(%p)\n", This);
1052 return IUnknown_Release(This->pUnkOuter);
1055 static HRESULT WINAPI IShellExecuteHookA_fnExecute(IShellExecuteHookA* iface, LPSHELLEXECUTEINFOA psei)
1057 ICPanelImpl *This = (ICPanelImpl *)iface;
1059 SHELLEXECUTEINFOA sei_tmp;
1060 PIDLCPanelStruct* pcpanel;
1061 char path[MAX_PATH];
1062 BOOL ret;
1064 TRACE("(%p)->execute(%p)\n", This, psei);
1066 if (!psei)
1067 return E_INVALIDARG;
1069 pcpanel = _ILGetCPanelPointer(ILFindLastID(psei->lpIDList));
1071 if (!pcpanel)
1072 return E_INVALIDARG;
1074 path[0] = '\"';
1075 lstrcpyA(path+1, pcpanel->szName);
1077 /* pass applet name to Control_RunDLL to distinguish between applets in one .cpl file */
1078 lstrcatA(path, "\" ");
1079 lstrcatA(path, pcpanel->szName+pcpanel->offsDispName);
1081 memcpy(&sei_tmp, psei, sizeof(sei_tmp));
1082 sei_tmp.lpFile = path;
1083 sei_tmp.fMask &= ~SEE_MASK_INVOKEIDLIST;
1085 ret = ShellExecuteExA(&sei_tmp);
1086 if (ret)
1087 return S_OK;
1088 else
1089 return S_FALSE;
1092 static const IShellExecuteHookAVtbl vt_ShellExecuteHookA =
1094 IShellExecuteHookA_fnQueryInterface,
1095 IShellExecuteHookA_fnAddRef,
1096 IShellExecuteHookA_fnRelease,
1097 IShellExecuteHookA_fnExecute