HRESULT ItemMenu_Constructor(IShellFolder *parent, LPCITEMIDLIST pidl, const LPCITEMIDLIST *apidl, UINT cidl, REFIID riid, void **pObj) { ContextMenu* This; HRESULT hr; UINT i; This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This)); if (!This) return E_OUTOFMEMORY; This->IContextMenu3_iface.lpVtbl = &ItemContextMenuVtbl; This->ref = 1; This->parent = parent; if (parent) IShellFolder_AddRef(parent); This->pidl = ILClone(pidl); This->apidl = _ILCopyaPidl(apidl, cidl); This->cidl = cidl; This->allvalues = TRUE; This->desktop = FALSE; for (i = 0; i < cidl; i++) This->allvalues &= (_ILIsValue(apidl[i]) ? 1 : 0); hr = IContextMenu3_QueryInterface(&This->IContextMenu3_iface, riid, pObj); IContextMenu3_Release(&This->IContextMenu3_iface); return hr; }
/************************************************************************** * ISvItemCm_Constructor() */ IContextMenu2 *ISvItemCm_Constructor(LPSHELLFOLDER pSFParent, LPCITEMIDLIST pidl, const LPCITEMIDLIST *apidl, UINT cidl) { ItemCmImpl* cm; UINT u; cm = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ItemCmImpl)); cm->IContextMenu2_iface.lpVtbl = &cmvt; cm->ref = 1; cm->pidl = ILClone(pidl); cm->pSFParent = pSFParent; if(pSFParent) IShellFolder_AddRef(pSFParent); cm->apidl = _ILCopyaPidl(apidl, cidl); cm->cidl = cidl; cm->bAllValues = 1; for(u = 0; u < cidl; u++) { cm->bAllValues &= (_ILIsValue(apidl[u]) ? 1 : 0); } TRACE("(%p)->()\n",cm); return &cm->IContextMenu2_iface; }
static void DoOpenExplore(ItemCmImpl *This, HWND hwnd, LPCSTR verb) { UINT i, bFolderFound = FALSE; LPITEMIDLIST pidlFQ; SHELLEXECUTEINFOA sei; /* Find the first item in the list that is not a value. These commands should never be invoked if there isn't at least one folder item in the list.*/ for(i = 0; i<This->cidl; i++) { if(!_ILIsValue(This->apidl[i])) { bFolderFound = TRUE; break; } } if (!bFolderFound) return; pidlFQ = ILCombine(This->pidl, This->apidl[i]); ZeroMemory(&sei, sizeof(sei)); sei.cbSize = sizeof(sei); sei.fMask = SEE_MASK_IDLIST | SEE_MASK_CLASSNAME; sei.lpIDList = pidlFQ; sei.lpClass = "Folder"; sei.hwnd = hwnd; sei.nShow = SW_SHOWNORMAL; sei.lpVerb = verb; ShellExecuteExA(&sei); SHFree(pidlFQ); }
/************************************************************************** * CDesktopFolder::GetAttributesOf */ HRESULT WINAPI CDesktopFolder::GetAttributesOf( UINT cidl, PCUITEMID_CHILD_ARRAY apidl, DWORD *rgfInOut) { HRESULT hr = S_OK; TRACE("(%p)->(cidl=%d apidl=%p mask=%p (0x%08x))\n", this, cidl, apidl, rgfInOut, rgfInOut ? *rgfInOut : 0); if (cidl && !apidl) return E_INVALIDARG; if (*rgfInOut == 0) *rgfInOut = ~0; if(cidl == 0) *rgfInOut &= dwDesktopAttributes; else { /* TODO: always add SFGAO_CANLINK */ for (UINT i = 0; i < cidl; ++i) { pdump(*apidl); if (_ILIsDesktop(*apidl)) *rgfInOut &= dwDesktopAttributes; else if (_ILIsMyComputer(apidl[i])) *rgfInOut &= dwMyComputerAttributes; else if (_ILIsNetHood(apidl[i])) *rgfInOut &= dwMyNetPlacesAttributes; else if (_ILIsSpecialFolder(apidl[i])) SHELL32_GetGuidItemAttributes(this, apidl[i], rgfInOut); else if (_ILIsFolder(apidl[i]) || _ILIsValue(apidl[i])) { CComPtr<IShellFolder2> psf; HRESULT hr = _GetSFFromPidl(apidl[i], &psf); if (FAILED_UNEXPECTEDLY(hr)) continue; psf->GetAttributesOf(1, &apidl[i], rgfInOut); } else ERR("Got an unknown pidl type!!!\n"); } } /* make sure SFGAO_VALIDATE is cleared, some apps depend on that */ *rgfInOut &= ~SFGAO_VALIDATE; TRACE("-- result=0x%08x\n", *rgfInOut); return hr; }
/*********************************************************************** * SHELL32_BindToFS [Internal] * * Common code for IShellFolder_BindToObject. * * PARAMS * pidlRoot [I] The parent shell folder's absolute pidl. * pathRoot [I] Absolute dos path of the parent shell folder. * pidlComplete [I] PIDL of the child. Relative to pidlRoot. * riid [I] GUID of the interface, which ppvOut shall be bound to. * ppvOut [O] A reference to the child's interface (riid). * * NOTES * pidlComplete has to contain at least one non empty SHITEMID. * This function makes special assumptions on the shell namespace, which * means you probably can't use it for your IShellFolder implementation. */ HRESULT SHELL32_BindToFS (LPCITEMIDLIST pidlRoot, LPCWSTR pathRoot, LPCITEMIDLIST pidlComplete, REFIID riid, LPVOID * ppvOut) { CComPtr<IShellFolder> pSF; HRESULT hr; LPCITEMIDLIST pidlChild; if (!pidlRoot || !ppvOut || !pidlComplete || !pidlComplete->mkid.cb) return E_INVALIDARG; if (_ILIsValue(pidlComplete)) { ERR("Binding to file is unimplemented\n"); return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND); } if (!_ILIsFolder(pidlComplete) && !_ILIsDrive(pidlComplete)) { ERR("Got an unknown type of pidl!\n"); return E_FAIL; } *ppvOut = NULL; pidlChild = (_ILIsPidlSimple (pidlComplete)) ? pidlComplete : ILCloneFirst (pidlComplete); CLSID clsidFolder = CLSID_ShellFSFolder; DWORD attributes = _ILGetFileAttributes(ILFindLastID(pidlChild), NULL, 0); if ((attributes & (FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_READONLY)) != 0) SHELL32_GetCLSIDForDirectory(pathRoot, pidlChild, &clsidFolder); hr = SHELL32_CoCreateInitSF (pidlRoot, pathRoot, pidlChild, clsidFolder, &pSF); if (pidlChild != pidlComplete) ILFree ((LPITEMIDLIST)pidlChild); if (SUCCEEDED (hr)) { if (_ILIsPidlSimple (pidlComplete)) { /* no sub folders */ hr = pSF->QueryInterface(riid, ppvOut); } else { /* go deeper */ hr = pSF->BindToObject(ILGetNext (pidlComplete), NULL, riid, ppvOut); } } TRACE ("-- returning (%p) %08x\n", *ppvOut, hr); return hr; }
void AddFSClassKeysToArray(PCUITEMID_CHILD pidl, HKEY* array, UINT* cKeys) { if (_ILIsValue(pidl)) { FileStructW* pFileData = _ILGetFileStructW(pidl); LPWSTR extension = PathFindExtension(pFileData->wszName); if (extension) { AddClassKeyToArray(extension, array, cKeys); WCHAR wszClass[MAX_PATH], wszClass2[MAX_PATH]; DWORD dwSize = sizeof(wszClass); if (RegGetValueW(HKEY_CLASSES_ROOT, extension, NULL, RRF_RT_REG_SZ, NULL, wszClass, &dwSize) == ERROR_SUCCESS) { swprintf(wszClass2, L"%s//%s", extension, wszClass); AddClassKeyToArray(wszClass, array, cKeys); AddClassKeyToArray(wszClass2, array, cKeys); } swprintf(wszClass2, L"SystemFileAssociations//%s", extension); AddClassKeyToArray(wszClass2, array, cKeys); if (RegGetValueW(HKEY_CLASSES_ROOT, extension, L"PerceivedType ", RRF_RT_REG_SZ, NULL, wszClass, &dwSize) == ERROR_SUCCESS) { swprintf(wszClass2, L"SystemFileAssociations//%s", wszClass); AddClassKeyToArray(wszClass2, array, cKeys); } } AddClassKeyToArray(L"AllFilesystemObjects", array, cKeys); AddClassKeyToArray(L"*", array, cKeys); } else if (_ILIsFolder(pidl)) { AddClassKeyToArray(L"AllFilesystemObjects", array, cKeys); AddClassKeyToArray(L"Directory", array, cKeys); AddClassKeyToArray(L"Folder", array, cKeys); } else { ERR("Got non FS pidl\n"); } }
/************************************************************************** * DoOpenProperties */ static void DoOpenProperties(ItemCmImpl *This, HWND hwnd) { static const UINT MAX_PROP_PAGES = 99; static const WCHAR wszFolder[] = {'F','o','l','d','e','r', 0}; static const WCHAR wszFiletypeAll[] = {'*',0}; LPSHELLFOLDER lpDesktopSF; LPSHELLFOLDER lpSF; LPDATAOBJECT lpDo; WCHAR wszFiletype[MAX_PATH]; WCHAR wszFilename[MAX_PATH]; PROPSHEETHEADERW psh; HPROPSHEETPAGE hpages[MAX_PROP_PAGES]; HPSXA hpsxa; UINT ret; TRACE("(%p)->(wnd=%p)\n", This, hwnd); ZeroMemory(&psh, sizeof(PROPSHEETHEADERW)); psh.dwSize = sizeof (PROPSHEETHEADERW); psh.hwndParent = hwnd; psh.dwFlags = PSH_PROPTITLE; psh.nPages = 0; psh.u3.phpage = hpages; psh.u2.nStartPage = 0; _ILSimpleGetTextW(This->apidl[0], (LPVOID)&wszFilename, MAX_PATH); psh.pszCaption = (LPCWSTR)&wszFilename; /* Find out where to look for the shell extensions */ if (_ILIsValue(This->apidl[0])) { char sTemp[64]; sTemp[0] = 0; if (_ILGetExtension(This->apidl[0], sTemp, 64)) { HCR_MapTypeToValueA(sTemp, sTemp, 64, TRUE); MultiByteToWideChar(CP_ACP, 0, sTemp, -1, wszFiletype, MAX_PATH); } else { wszFiletype[0] = 0; } } else if (_ILIsFolder(This->apidl[0])) { lstrcpynW(wszFiletype, wszFolder, 64); } else if (_ILIsSpecialFolder(This->apidl[0])) { LPGUID folderGUID; static const WCHAR wszclsid[] = {'C','L','S','I','D','\\', 0}; folderGUID = _ILGetGUIDPointer(This->apidl[0]); lstrcpyW(wszFiletype, wszclsid); StringFromGUID2(folderGUID, &wszFiletype[6], MAX_PATH - 6); } else { FIXME("Requested properties for unknown type.\n"); return; } /* Get a suitable DataObject for accessing the files */ SHGetDesktopFolder(&lpDesktopSF); if (_ILIsPidlSimple(This->pidl)) { ret = IShellFolder_GetUIObjectOf(lpDesktopSF, hwnd, This->cidl, (LPCITEMIDLIST*)This->apidl, &IID_IDataObject, NULL, (LPVOID *)&lpDo); IShellFolder_Release(lpDesktopSF); } else { IShellFolder_BindToObject(lpDesktopSF, This->pidl, NULL, &IID_IShellFolder, (LPVOID*) &lpSF); ret = IShellFolder_GetUIObjectOf(lpSF, hwnd, This->cidl, (LPCITEMIDLIST*)This->apidl, &IID_IDataObject, NULL, (LPVOID *)&lpDo); IShellFolder_Release(lpSF); IShellFolder_Release(lpDesktopSF); } if (SUCCEEDED(ret)) { hpsxa = SHCreatePropSheetExtArrayEx(HKEY_CLASSES_ROOT, wszFiletype, MAX_PROP_PAGES - psh.nPages, lpDo); if (hpsxa != NULL) { SHAddFromPropSheetExtArray(hpsxa, Properties_AddPropSheetCallback, (LPARAM)&psh); SHDestroyPropSheetExtArray(hpsxa); } hpsxa = SHCreatePropSheetExtArrayEx(HKEY_CLASSES_ROOT, wszFiletypeAll, MAX_PROP_PAGES - psh.nPages, lpDo); if (hpsxa != NULL) { SHAddFromPropSheetExtArray(hpsxa, Properties_AddPropSheetCallback, (LPARAM)&psh); SHDestroyPropSheetExtArray(hpsxa); } IDataObject_Release(lpDo); } if (psh.nPages) PropertySheetW(&psh); else FIXME("No property pages found.\n"); }
/*********************************************************************** * SHELL32_BindToChild [Internal] * * Common code for IShellFolder_BindToObject. * * PARAMS * pidlRoot [I] The parent shell folder's absolute pidl. * pathRoot [I] Absolute dos path of the parent shell folder. * pidlComplete [I] PIDL of the child. Relative to pidlRoot. * riid [I] GUID of the interface, which ppvOut shall be bound to. * ppvOut [O] A reference to the child's interface (riid). * * NOTES * pidlComplete has to contain at least one non empty SHITEMID. * This function makes special assumptions on the shell namespace, which * means you probably can't use it for your IShellFolder implementation. */ HRESULT SHELL32_BindToChild (LPCITEMIDLIST pidlRoot, LPCWSTR pathRoot, LPCITEMIDLIST pidlComplete, REFIID riid, LPVOID * ppvOut) { GUID const *clsid; IShellFolder *pSF; HRESULT hr; LPITEMIDLIST pidlChild; TRACE("(%p %s %p %s %p)\n", pidlRoot, debugstr_w(pathRoot), pidlComplete, debugstr_guid(riid), ppvOut); if (!pidlRoot || !ppvOut || _ILIsEmpty(pidlComplete)) return E_INVALIDARG; *ppvOut = NULL; pidlChild = ILCloneFirst (pidlComplete); if ((clsid = _ILGetGUIDPointer (pidlChild))) { /* virtual folder */ hr = SHELL32_CoCreateInitSF (pidlRoot, pathRoot, pidlChild, clsid, (LPVOID *)&pSF); } else if (_ILIsValue(pidlChild)) { /* Don't bind to files */ hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND); } else { /* file system folder */ CLSID clsidFolder = CLSID_ShellFSFolder; static const WCHAR wszCLSID[] = {'C','L','S','I','D',0}; WCHAR wszCLSIDValue[CHARS_IN_GUID], wszFolderPath[MAX_PATH], *pwszPathTail = wszFolderPath; /* see if folder CLSID should be overridden by desktop.ini file */ if (pathRoot) { lstrcpynW(wszFolderPath, pathRoot, MAX_PATH); pwszPathTail = PathAddBackslashW(wszFolderPath); } _ILSimpleGetTextW(pidlChild,pwszPathTail,MAX_PATH - (int)(pwszPathTail - wszFolderPath)); if (SHELL32_GetCustomFolderAttributeFromPath (wszFolderPath, wszDotShellClassInfo, wszCLSID, wszCLSIDValue, CHARS_IN_GUID)) CLSIDFromString (wszCLSIDValue, &clsidFolder); hr = SHELL32_CoCreateInitSF (pidlRoot, pathRoot, pidlChild, &clsidFolder, (LPVOID *)&pSF); } ILFree (pidlChild); if (SUCCEEDED (hr)) { if (_ILIsPidlSimple (pidlComplete)) { /* no sub folders */ hr = IShellFolder_QueryInterface (pSF, riid, ppvOut); } else { /* go deeper */ hr = IShellFolder_BindToObject (pSF, ILGetNext (pidlComplete), NULL, riid, ppvOut); } IShellFolder_Release (pSF); } TRACE ("-- returning (%p) 0x%08x\n", *ppvOut, hr); return hr; }
HRESULT SHELL32_GetFSItemAttributes(IShellFolder * psf, LPCITEMIDLIST pidl, LPDWORD pdwAttributes) { DWORD dwFileAttributes, dwShellAttributes; if (!_ILIsFolder(pidl) && !_ILIsValue(pidl)) { ERR("Got wrong type of pidl!\n"); *pdwAttributes &= SFGAO_CANLINK; return S_OK; } if (*pdwAttributes & ~dwSupportedAttr) { WARN ("attributes 0x%08x not implemented\n", (*pdwAttributes & ~dwSupportedAttr)); *pdwAttributes &= dwSupportedAttr; } dwFileAttributes = _ILGetFileAttributes(pidl, NULL, 0); /* Set common attributes */ dwShellAttributes = *pdwAttributes; dwShellAttributes |= SFGAO_FILESYSTEM | SFGAO_DROPTARGET | SFGAO_HASPROPSHEET | SFGAO_CANDELETE | SFGAO_CANRENAME | SFGAO_CANLINK | SFGAO_CANMOVE | SFGAO_CANCOPY; if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { dwShellAttributes |= (SFGAO_FOLDER | SFGAO_HASSUBFOLDER | SFGAO_FILESYSANCESTOR); } else dwShellAttributes &= ~(SFGAO_FOLDER | SFGAO_HASSUBFOLDER | SFGAO_FILESYSANCESTOR); if (dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) dwShellAttributes |= SFGAO_HIDDEN; else dwShellAttributes &= ~SFGAO_HIDDEN; if (dwFileAttributes & FILE_ATTRIBUTE_READONLY) dwShellAttributes |= SFGAO_READONLY; else dwShellAttributes &= ~SFGAO_READONLY; if (SFGAO_LINK & *pdwAttributes) { char ext[MAX_PATH]; if (!_ILGetExtension(pidl, ext, MAX_PATH) || lstrcmpiA(ext, "lnk")) dwShellAttributes &= ~SFGAO_LINK; } if (SFGAO_HASSUBFOLDER & *pdwAttributes) { CComPtr<IShellFolder> psf2; if (SUCCEEDED(psf->BindToObject(pidl, 0, IID_PPV_ARG(IShellFolder, &psf2)))) { CComPtr<IEnumIDList> pEnumIL; if (SUCCEEDED(psf2->EnumObjects(0, SHCONTF_FOLDERS, &pEnumIL))) { if (pEnumIL->Skip(1) != S_OK) dwShellAttributes &= ~SFGAO_HASSUBFOLDER; } } } *pdwAttributes &= dwShellAttributes; TRACE ("-- 0x%08x\n", *pdwAttributes); return S_OK; }
static HRESULT WINAPI ISF_Desktop_ISFHelper_fnDeleteItems (ISFHelper * iface, UINT cidl, LPCITEMIDLIST * apidl) { IGenericSFImpl *This = impl_from_ISFHelper(iface); UINT i; SHFILEOPSTRUCTW op; WCHAR wszPath[MAX_PATH]; WCHAR wszCaption[50]; WCHAR *wszPathsList; HRESULT ret; WCHAR *wszCurrentPath; UINT bRestoreWithDeskCpl = FALSE; int res; TRACE ("(%p)(%u %p)\n", This, cidl, apidl); if (cidl==0) return S_OK; for(i = 0; i < cidl; i++) { if (_ILIsMyComputer(apidl[i])) bRestoreWithDeskCpl++; else if (_ILIsNetHood(apidl[i])) bRestoreWithDeskCpl++; else if (_ILIsMyDocuments(apidl[i])) bRestoreWithDeskCpl++; } if (bRestoreWithDeskCpl) { /* FIXME use FormatMessage * use a similar message resource as in windows */ LoadStringW(shell32_hInstance, IDS_DELETEMULTIPLE_TEXT, wszPath, sizeof(wszPath)/sizeof(WCHAR)); wszPath[(sizeof(wszPath)/sizeof(WCHAR))-1] = 0; LoadStringW(shell32_hInstance, IDS_DELETEITEM_CAPTION, wszCaption, sizeof(wszCaption)/sizeof(WCHAR)); wszCaption[(sizeof(wszCaption)/sizeof(WCHAR))-1] = 0; res = SHELL_ConfirmMsgBox(GetActiveWindow(), wszPath, wszCaption, NULL, cidl > 1); if (res == IDD_YESTOALL || res == IDYES) { for(i = 0; i < cidl; i++) { if (_ILIsMyComputer(apidl[i])) SetNamespaceExtensionVisibleStatus(L"{20D04FE0-3AEA-1069-A2D8-08002B30309D}", 0x1); else if (_ILIsNetHood(apidl[i])) SetNamespaceExtensionVisibleStatus(L"{208D2C60-3AEA-1069-A2D7-08002B30309D}", 0x1); else if (_ILIsMyDocuments(apidl[i])) SetNamespaceExtensionVisibleStatus(L"{450D8FBA-AD25-11D0-98A8-0800361B1103}", 0x1); } } } if (This->sPathTarget) lstrcpynW(wszPath, This->sPathTarget, MAX_PATH); else wszPath[0] = '\0'; PathAddBackslashW(wszPath); wszPathsList = build_paths_list(wszPath, cidl, apidl); ZeroMemory(&op, sizeof(op)); op.hwnd = GetActiveWindow(); op.wFunc = FO_DELETE; op.pFrom = wszPathsList; op.fFlags = FOF_ALLOWUNDO; if (SHFileOperationW(&op)) { WARN("SHFileOperation failed\n"); ret = E_FAIL; } else ret = S_OK; /* we currently need to manually send the notifies */ wszCurrentPath = wszPathsList; for (i = 0; i < cidl; i++) { LONG wEventId; if (_ILIsFolder(apidl[i])) wEventId = SHCNE_RMDIR; else if (_ILIsValue(apidl[i])) wEventId = SHCNE_DELETE; else continue; /* check if file exists */ if (GetFileAttributesW(wszCurrentPath) == INVALID_FILE_ATTRIBUTES) { LPITEMIDLIST pidl = ILCombine(This->pidlRoot, apidl[i]); SHChangeNotify(wEventId, SHCNF_IDLIST, pidl, NULL); SHFree(pidl); } wszCurrentPath += wcslen(wszCurrentPath)+1; } HeapFree(GetProcessHeap(), 0, wszPathsList); return ret; }