f9c1c95716756f47043eb4b93f6360d09e96d944
[reactos.git] / dll / win32 / browseui / shellfind / CFindFolder.cpp
1 /*
2 * PROJECT: ReactOS Search Shell Extension
3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4 * PURPOSE: Search results folder
5 * COPYRIGHT: Copyright 2019 Brock Mammen
6 */
7
8 #include "CFindFolder.h"
9
10 WINE_DEFAULT_DEBUG_CHANNEL(shellfind);
11
12 struct FolderViewColumns
13 {
14 LPCWSTR wzColumnName;
15 DWORD dwDefaultState;
16 int fmt;
17 int cxChar;
18 };
19
20 static FolderViewColumns g_ColumnDefs[] =
21 {
22 {L"Name", SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_LEFT, 30},
23 {L"In Folder", SHCOLSTATE_TYPE_STR | SHCOLSTATE_ONBYDEFAULT, LVCFMT_LEFT, 30},
24 {L"Relevance", SHCOLSTATE_TYPE_STR, LVCFMT_LEFT, 0}
25 };
26
27 // *** IShellFolder2 methods ***
28 STDMETHODIMP CFindFolder::GetDefaultSearchGUID(GUID *pguid)
29 {
30 UNIMPLEMENTED;
31 return E_NOTIMPL;
32 }
33
34 STDMETHODIMP CFindFolder::EnumSearches(IEnumExtraSearch **ppenum)
35 {
36 UNIMPLEMENTED;
37 return E_NOTIMPL;
38 }
39
40 STDMETHODIMP CFindFolder::GetDefaultColumn(DWORD, ULONG *pSort, ULONG *pDisplay)
41 {
42 if (pSort)
43 *pSort = 0;
44 if (pDisplay)
45 *pDisplay = 0;
46 return S_OK;
47 }
48
49 STDMETHODIMP CFindFolder::GetDefaultColumnState(UINT iColumn, DWORD *pcsFlags)
50 {
51 if (!pcsFlags)
52 return E_INVALIDARG;
53 if (iColumn >= _countof(g_ColumnDefs))
54 return m_pisfInner->GetDefaultColumnState(iColumn - _countof(g_ColumnDefs) + 1, pcsFlags);
55 *pcsFlags = g_ColumnDefs[iColumn].dwDefaultState;
56 return S_OK;
57 }
58
59 STDMETHODIMP CFindFolder::GetDetailsEx(PCUITEMID_CHILD pidl, const SHCOLUMNID *pscid, VARIANT *pv)
60 {
61 return m_pisfInner->GetDetailsEx(pidl, pscid, pv);
62 }
63
64 STDMETHODIMP CFindFolder::GetDetailsOf(PCUITEMID_CHILD pidl, UINT iColumn, SHELLDETAILS *pDetails)
65 {
66 if (iColumn >= _countof(g_ColumnDefs))
67 return m_pisfInner->GetDetailsOf(pidl, iColumn - _countof(g_ColumnDefs) + 1, pDetails);
68
69 pDetails->cxChar = g_ColumnDefs[iColumn].cxChar;
70 pDetails->fmt = g_ColumnDefs[iColumn].fmt;
71
72 if (!pidl)
73 return SHSetStrRet(&pDetails->str, g_ColumnDefs[iColumn].wzColumnName);
74
75 return GetDisplayNameOf(pidl, SHGDN_NORMAL, &pDetails->str);
76 }
77
78 STDMETHODIMP CFindFolder::MapColumnToSCID(UINT iColumn, SHCOLUMNID *pscid)
79 {
80 UNIMPLEMENTED;
81 return E_NOTIMPL;
82 }
83
84 // *** IShellFolder methods ***
85 STDMETHODIMP CFindFolder::ParseDisplayName(HWND hwndOwner, LPBC pbc, LPOLESTR lpszDisplayName, ULONG *pchEaten,
86 PIDLIST_RELATIVE *ppidl, ULONG *pdwAttributes)
87 {
88 UNIMPLEMENTED;
89 return E_NOTIMPL;
90 }
91
92 STDMETHODIMP CFindFolder::EnumObjects(HWND hwndOwner, DWORD dwFlags, LPENUMIDLIST *ppEnumIDList)
93 {
94 *ppEnumIDList = NULL;
95 return S_FALSE;
96 }
97
98 STDMETHODIMP CFindFolder::BindToObject(PCUIDLIST_RELATIVE pidl, LPBC pbcReserved, REFIID riid, LPVOID *ppvOut)
99 {
100 UNIMPLEMENTED;
101 return E_NOTIMPL;
102 }
103
104 STDMETHODIMP CFindFolder::BindToStorage(PCUIDLIST_RELATIVE pidl, LPBC pbcReserved, REFIID riid, LPVOID *ppvOut)
105 {
106 UNIMPLEMENTED;
107 return E_NOTIMPL;
108 }
109
110 STDMETHODIMP CFindFolder::CompareIDs(LPARAM lParam, PCUIDLIST_RELATIVE pidl1, PCUIDLIST_RELATIVE pidl2)
111 {
112 return m_pisfInner->CompareIDs(lParam, pidl1, pidl2);
113 }
114
115 STDMETHODIMP CFindFolder::CreateViewObject(HWND hwndOwner, REFIID riid, LPVOID *ppvOut)
116 {
117 if (riid == IID_IShellView)
118 {
119 SFV_CREATE sfvparams = {};
120 sfvparams.cbSize = sizeof(SFV_CREATE);
121 sfvparams.pshf = this;
122 sfvparams.psfvcb = this;
123 return SHCreateShellFolderView(&sfvparams, (IShellView **) ppvOut);
124 }
125 return E_NOINTERFACE;
126 }
127
128 STDMETHODIMP CFindFolder::GetAttributesOf(UINT cidl, PCUITEMID_CHILD_ARRAY apidl, DWORD *rgfInOut)
129 {
130 return m_pisfInner->GetAttributesOf(cidl, apidl, rgfInOut);
131 }
132
133 STDMETHODIMP CFindFolder::GetUIObjectOf(HWND hwndOwner, UINT cidl, PCUITEMID_CHILD_ARRAY apidl, REFIID riid,
134 UINT *prgfInOut, LPVOID *ppvOut)
135 {
136 return m_pisfInner->GetUIObjectOf(hwndOwner, cidl, apidl, riid, prgfInOut, ppvOut);
137 }
138
139 STDMETHODIMP CFindFolder::GetDisplayNameOf(PCUITEMID_CHILD pidl, DWORD dwFlags, LPSTRRET pName)
140 {
141 return m_pisfInner->GetDisplayNameOf(pidl, dwFlags, pName);
142 }
143
144 STDMETHODIMP CFindFolder::SetNameOf(HWND hwndOwner, PCUITEMID_CHILD pidl, LPCOLESTR lpName, DWORD dwFlags,
145 PITEMID_CHILD *pPidlOut)
146 {
147 UNIMPLEMENTED;
148 return E_NOTIMPL;
149 }
150
151 //// *** IShellFolderViewCB method ***
152 STDMETHODIMP CFindFolder::MessageSFVCB(UINT uMsg, WPARAM wParam, LPARAM lParam)
153 {
154 switch (uMsg)
155 {
156 case SFVM_DEFVIEWMODE:
157 {
158 FOLDERVIEWMODE *pViewMode = (FOLDERVIEWMODE *) lParam;
159 *pViewMode = FVM_DETAILS;
160 return S_OK;
161 }
162 }
163 return E_NOTIMPL;
164 }
165
166 //// *** IPersistFolder2 methods ***
167 STDMETHODIMP CFindFolder::GetCurFolder(LPITEMIDLIST *pidl)
168 {
169 *pidl = ILClone(m_pidl);
170 return S_OK;
171 }
172
173 // *** IPersistFolder methods ***
174 STDMETHODIMP CFindFolder::Initialize(LPCITEMIDLIST pidl)
175 {
176 m_pidl = ILClone(pidl);
177 if (!m_pidl)
178 return E_OUTOFMEMORY;
179
180 return SHELL32_CoCreateInitSF(m_pidl,
181 NULL,
182 NULL,
183 &CLSID_ShellFSFolder,
184 IID_PPV_ARG(IShellFolder2, &m_pisfInner));
185 }
186
187 // *** IPersist methods ***
188 STDMETHODIMP CFindFolder::GetClassID(CLSID *pClassId)
189 {
190 if (pClassId == NULL)
191 return E_INVALIDARG;
192 memcpy(pClassId, &CLSID_FindFolder, sizeof(CLSID));
193 return S_OK;
194 }