1 /*
2  * Fonts folder
3  *
4  * Copyright 2008       Johannes Anderwald <johannes.anderwald@reactos.org>
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 (shell);
25 
26 CFontsFolder::CFontsFolder()
27 {
28     m_pidlInner = NULL;
29 }
30 
31 CFontsFolder::~CFontsFolder()
32 {
33     if(m_pidlInner)
34         SHFree(m_pidlInner);
35 }
36 
37 HRESULT WINAPI CFontsFolder::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 CFontsFolder::EnumObjects(HWND hwndOwner, DWORD dwFlags, LPENUMIDLIST *ppEnumIDList)
44 {
45     return m_pisfInner->EnumObjects(hwndOwner, dwFlags, ppEnumIDList);
46 }
47 
48 HRESULT WINAPI CFontsFolder::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 CFontsFolder::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 CFontsFolder::CompareIDs(LPARAM lParam, PCUIDLIST_RELATIVE pidl1, PCUIDLIST_RELATIVE pidl2)
59 {
60     return m_pisfInner->CompareIDs(lParam, pidl1, pidl2);
61 }
62 
63 HRESULT WINAPI CFontsFolder::CreateViewObject(HWND hwndOwner, REFIID riid, LPVOID *ppvOut)
64 {
65     return m_pisfInner->CreateViewObject(hwndOwner, riid, ppvOut);
66 }
67 
68 HRESULT WINAPI CFontsFolder::GetAttributesOf(UINT cidl, PCUITEMID_CHILD_ARRAY apidl, DWORD *rgfInOut)
69 {
70     static const DWORD dwFontsAttributes =
71         SFGAO_STORAGE | SFGAO_STORAGEANCESTOR | SFGAO_FILESYSANCESTOR |
72         SFGAO_FOLDER | SFGAO_FILESYSTEM | SFGAO_HASSUBFOLDER;
73 
74     if(cidl)
75         return m_pisfInner->GetAttributesOf(cidl, apidl, rgfInOut);
76 
77     if (!rgfInOut || !apidl)
78         return E_INVALIDARG;
79 
80     if (*rgfInOut == 0)
81         *rgfInOut = ~0;
82 
83     *rgfInOut &= dwFontsAttributes;
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 CFontsFolder::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 CFontsFolder::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 tell us its path */
111         if (pidl->mkid.cb)
112             pidl = ILGetNext(pidl);
113 
114         return m_pisfInner->GetDisplayNameOf(pidl, dwFlags, strRet);
115     }
116 
117     ERR("Got empty pidl without SHGDN_FORPARSING\n");
118     return E_INVALIDARG;
119 }
120 
121 HRESULT WINAPI CFontsFolder::SetNameOf(HWND hwndOwner, PCUITEMID_CHILD pidl,    /* simple pidl */
122         LPCOLESTR lpName, DWORD dwFlags, PITEMID_CHILD *pPidlOut)
123 {
124     return m_pisfInner->SetNameOf(hwndOwner, pidl, lpName, dwFlags, pPidlOut);
125 }
126 
127 HRESULT WINAPI CFontsFolder::GetDefaultSearchGUID(GUID *pguid)
128 {
129     return m_pisfInner->GetDefaultSearchGUID(pguid);
130 }
131 
132 HRESULT WINAPI CFontsFolder::EnumSearches(IEnumExtraSearch ** ppenum)
133 {
134     return m_pisfInner->EnumSearches(ppenum);
135 }
136 
137 HRESULT WINAPI CFontsFolder::GetDefaultColumn(DWORD dwRes, ULONG *pSort, ULONG *pDisplay)
138 {
139     return m_pisfInner->GetDefaultColumn(dwRes, pSort, pDisplay);
140 }
141 
142 HRESULT WINAPI CFontsFolder::GetDefaultColumnState(UINT iColumn, DWORD *pcsFlags)
143 {
144     return m_pisfInner->GetDefaultColumnState(iColumn, pcsFlags);
145 }
146 
147 HRESULT WINAPI CFontsFolder::GetDetailsEx(PCUITEMID_CHILD pidl, const SHCOLUMNID *pscid, VARIANT *pv)
148 {
149     return m_pisfInner->GetDetailsEx(pidl, pscid, pv);
150 }
151 
152 HRESULT WINAPI CFontsFolder::GetDetailsOf(PCUITEMID_CHILD pidl, UINT iColumn, SHELLDETAILS *psd)
153 {
154     return m_pisfInner->GetDetailsOf(pidl, iColumn, psd);
155 }
156 
157 HRESULT WINAPI CFontsFolder::MapColumnToSCID(UINT column, SHCOLUMNID *pscid)
158 {
159     return m_pisfInner->MapColumnToSCID(column, pscid);
160 }
161 
162 HRESULT WINAPI CFontsFolder::GetClassID(CLSID *lpClassId)
163 {
164     if (!lpClassId)
165         return E_POINTER;
166 
167     *lpClassId = CLSID_FontsFolderShortcut;
168 
169     return S_OK;
170 }
171 
172 HRESULT WINAPI CFontsFolder::Initialize(LPCITEMIDLIST pidl)
173 {
174     m_pidlInner = ILClone(pidl);
175     if (!m_pidlInner)
176         return E_OUTOFMEMORY;
177 
178     return SHELL32_CoCreateInitSF(m_pidlInner,
179                                   &CLSID_ShellFSFolder,
180                                   CSIDL_FONTS,
181                                   IID_PPV_ARG(IShellFolder2, &m_pisfInner));
182 }
183 
184 HRESULT WINAPI CFontsFolder::GetCurFolder(LPITEMIDLIST *pidl)
185 {
186     if (!pidl)
187         return E_POINTER;
188     *pidl = ILClone(m_pidlInner);
189     return S_OK;
190 }
191