[SHELL] IPersistFolder::Initialize takes a PCIDLIST_ABSOLUTE. CORE-16385
[reactos.git] / dll / win32 / shell32 / folders / CMyDocsFolder.cpp
1 /*
2 * Virtual MyDocuments Folder
3 *
4 * Copyright 2007 Johannes Anderwald
5 * Copyright 2009 Andrew Hill
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 */
21
22 #include <precomp.h>
23
24 WINE_DEFAULT_DEBUG_CHANNEL (mydocs);
25
26 CMyDocsFolder::CMyDocsFolder()
27 {
28 m_pidlInner = NULL;
29 }
30
31 CMyDocsFolder::~CMyDocsFolder()
32 {
33 if(m_pidlInner)
34 SHFree(m_pidlInner);
35 }
36
37 HRESULT WINAPI CMyDocsFolder::ParseDisplayName(HWND hwndOwner, LPBC pbc, LPOLESTR lpszDisplayName,
38 ULONG *pchEaten, PIDLIST_RELATIVE *ppidl, ULONG *pdwAttributes)
39 {
40 return m_pisfInner->ParseDisplayName(hwndOwner, pbc, lpszDisplayName, pchEaten, ppidl, pdwAttributes);
41 }
42
43 HRESULT WINAPI CMyDocsFolder::EnumObjects(HWND hwndOwner, DWORD dwFlags, LPENUMIDLIST *ppEnumIDList)
44 {
45 return m_pisfInner->EnumObjects(hwndOwner, dwFlags, ppEnumIDList);
46 }
47
48 HRESULT WINAPI CMyDocsFolder::BindToObject(PCUIDLIST_RELATIVE pidl, LPBC pbcReserved, REFIID riid, LPVOID *ppvOut)
49 {
50 return m_pisfInner->BindToObject(pidl, pbcReserved, riid, ppvOut);
51 }
52
53 HRESULT WINAPI CMyDocsFolder::BindToStorage(PCUIDLIST_RELATIVE pidl, LPBC pbcReserved, REFIID riid, LPVOID *ppvOut)
54 {
55 return m_pisfInner->BindToStorage(pidl, pbcReserved, riid, ppvOut);
56 }
57
58 HRESULT WINAPI CMyDocsFolder::CompareIDs(LPARAM lParam, PCUIDLIST_RELATIVE pidl1, PCUIDLIST_RELATIVE pidl2)
59 {
60 return m_pisfInner->CompareIDs(lParam, pidl1, pidl2);
61 }
62
63 HRESULT WINAPI CMyDocsFolder::CreateViewObject(HWND hwndOwner, REFIID riid, LPVOID *ppvOut)
64 {
65 return m_pisfInner->CreateViewObject(hwndOwner, riid, ppvOut);
66 }
67
68 HRESULT WINAPI CMyDocsFolder::GetAttributesOf(UINT cidl, PCUITEMID_CHILD_ARRAY apidl, DWORD *rgfInOut)
69 {
70 static const DWORD dwMyDocumentsAttributes =
71 SFGAO_STORAGE | SFGAO_HASPROPSHEET | SFGAO_STORAGEANCESTOR | SFGAO_CANCOPY |
72 SFGAO_FILESYSANCESTOR | SFGAO_FOLDER | SFGAO_FILESYSTEM | SFGAO_HASSUBFOLDER | SFGAO_CANRENAME | SFGAO_CANDELETE;
73
74 if(cidl)
75 return m_pisfInner->GetAttributesOf(cidl, apidl, rgfInOut);
76
77 if (!rgfInOut)
78 return E_INVALIDARG;
79
80 if (*rgfInOut == 0)
81 *rgfInOut = ~0;
82
83 *rgfInOut &= dwMyDocumentsAttributes;
84
85 /* make sure SFGAO_VALIDATE is cleared, some apps depend on that */
86 *rgfInOut &= ~SFGAO_VALIDATE;
87
88 return S_OK;
89 }
90
91 HRESULT WINAPI CMyDocsFolder::GetUIObjectOf(HWND hwndOwner, UINT cidl, PCUITEMID_CHILD_ARRAY apidl,
92 REFIID riid, UINT * prgfInOut, LPVOID * ppvOut)
93 {
94 return m_pisfInner->GetUIObjectOf(hwndOwner, cidl, apidl, riid, prgfInOut, ppvOut);
95 }
96
97 HRESULT WINAPI CMyDocsFolder::GetDisplayNameOf(PCUITEMID_CHILD pidl, DWORD dwFlags, LPSTRRET strRet)
98 {
99 if (!strRet || !pidl)
100 return E_INVALIDARG;
101
102 /* If we got an fs item just forward to the fs folder */
103 if (!_ILIsSpecialFolder(pidl))
104 return m_pisfInner->GetDisplayNameOf(pidl, dwFlags, strRet);
105
106 /* The caller wants our path. Let fs folder handle it */
107 if ((GET_SHGDN_RELATION (dwFlags) == SHGDN_NORMAL) &&
108 (GET_SHGDN_FOR (dwFlags) & SHGDN_FORPARSING))
109 {
110 /* Give an empty pidl to the fs folder to make it tell us its path */
111 if (pidl->mkid.cb)
112 pidl = ILGetNext(pidl);
113 return m_pisfInner->GetDisplayNameOf(pidl, dwFlags, strRet);
114 }
115
116 ERR("Got empty pidl without SHGDN_FORPARSING\n");
117 return E_INVALIDARG;
118 }
119
120 HRESULT WINAPI CMyDocsFolder::SetNameOf(HWND hwndOwner, PCUITEMID_CHILD pidl, /* simple pidl */
121 LPCOLESTR lpName, DWORD dwFlags, PITEMID_CHILD *pPidlOut)
122 {
123 return m_pisfInner->SetNameOf(hwndOwner, pidl, lpName, dwFlags, pPidlOut);
124 }
125
126 HRESULT WINAPI CMyDocsFolder::GetDefaultSearchGUID(GUID *pguid)
127 {
128 return m_pisfInner->GetDefaultSearchGUID(pguid);
129 }
130
131 HRESULT WINAPI CMyDocsFolder::EnumSearches(IEnumExtraSearch ** ppenum)
132 {
133 return m_pisfInner->EnumSearches(ppenum);
134 }
135
136 HRESULT WINAPI CMyDocsFolder::GetDefaultColumn(DWORD dwRes, ULONG *pSort, ULONG *pDisplay)
137 {
138 return m_pisfInner->GetDefaultColumn(dwRes, pSort, pDisplay);
139 }
140
141 HRESULT WINAPI CMyDocsFolder::GetDefaultColumnState(UINT iColumn, DWORD *pcsFlags)
142 {
143 return m_pisfInner->GetDefaultColumnState(iColumn, pcsFlags);
144 }
145
146 HRESULT WINAPI CMyDocsFolder::GetDetailsEx(PCUITEMID_CHILD pidl, const SHCOLUMNID *pscid, VARIANT *pv)
147 {
148 return m_pisfInner->GetDetailsEx(pidl, pscid, pv);
149 }
150
151 HRESULT WINAPI CMyDocsFolder::GetDetailsOf(PCUITEMID_CHILD pidl, UINT iColumn, SHELLDETAILS *psd)
152 {
153 return m_pisfInner->GetDetailsOf(pidl, iColumn, psd);
154 }
155
156 HRESULT WINAPI CMyDocsFolder::MapColumnToSCID(UINT column, SHCOLUMNID *pscid)
157 {
158 return m_pisfInner->MapColumnToSCID(column, pscid);
159 }
160
161 HRESULT WINAPI CMyDocsFolder::GetClassID(CLSID *lpClassId)
162 {
163 if (!lpClassId)
164 return E_POINTER;
165
166 memcpy(lpClassId, &CLSID_MyDocuments, sizeof(GUID));
167
168 return S_OK;
169 }
170
171 HRESULT WINAPI CMyDocsFolder::Initialize(PCIDLIST_ABSOLUTE pidl)
172 {
173 m_pidlInner = ILClone(pidl);
174 if (!m_pidlInner)
175 return E_OUTOFMEMORY;
176
177 return SHELL32_CoCreateInitSF(m_pidlInner,
178 &CLSID_ShellFSFolder,
179 CSIDL_PERSONAL,
180 IID_PPV_ARG(IShellFolder2, &m_pisfInner));
181 }
182
183 HRESULT WINAPI CMyDocsFolder::GetCurFolder(PIDLIST_ABSOLUTE *pidl)
184 {
185 if (!pidl)
186 return E_POINTER;
187 *pidl = ILClone(m_pidlInner);
188 return S_OK;
189 }