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 #pragma once
9 
10 #include "shellfind.h"
11 
12 class CFindFolder :
13         public CWindowImpl<CFindFolder>,
14         public CComCoClass<CFindFolder, &CLSID_FindFolder>,
15         public CComObjectRootEx<CComMultiThreadModelNoCS>,
16         public IShellFolder2,
17         public IPersistFolder2,
18         public IShellFolderViewCB,
19         public IConnectionPointContainerImpl<CFindFolder>,
20         public IConnectionPointImpl<CFindFolder, &DIID_DSearchCommandEvents>
21 {
22     // *** IShellFolder2 methods ***
23     STDMETHODIMP GetDefaultSearchGUID(GUID *pguid);
24 
25     STDMETHODIMP EnumSearches(IEnumExtraSearch **ppenum);
26 
27     STDMETHODIMP GetDefaultColumn(DWORD dwRes, ULONG *pSort, ULONG *pDisplay);
28 
29     STDMETHODIMP GetDefaultColumnState(UINT iColumn, DWORD *pcsFlags);
30 
31     STDMETHODIMP GetDetailsEx(PCUITEMID_CHILD pidl, const SHCOLUMNID *pscid, VARIANT *pv);
32 
33     STDMETHODIMP GetDetailsOf(PCUITEMID_CHILD pidl, UINT iColumn, SHELLDETAILS *pDetails);
34 
35     STDMETHODIMP MapColumnToSCID(UINT iColumn, SHCOLUMNID *pscid);
36 
37 
38     // *** IShellFolder methods ***
39     STDMETHODIMP ParseDisplayName(HWND hwndOwner, LPBC pbc, LPOLESTR lpszDisplayName, ULONG *pchEaten,
40                                   PIDLIST_RELATIVE *ppidl, ULONG *pdwAttributes);
41 
42     STDMETHODIMP EnumObjects(HWND hwndOwner, DWORD dwFlags, LPENUMIDLIST *ppEnumIDList);
43 
44     STDMETHODIMP BindToObject(PCUIDLIST_RELATIVE pidl, LPBC pbcReserved, REFIID riid, LPVOID *ppvOut);
45 
46     STDMETHODIMP BindToStorage(PCUIDLIST_RELATIVE pidl, LPBC pbcReserved, REFIID riid, LPVOID *ppvOut);
47 
48     STDMETHODIMP CompareIDs(LPARAM lParam, PCUIDLIST_RELATIVE pidl1, PCUIDLIST_RELATIVE pidl2);
49 
50     STDMETHODIMP CreateViewObject(HWND hwndOwner, REFIID riid, LPVOID *ppvOut);
51 
52     STDMETHODIMP GetAttributesOf(UINT cidl, PCUITEMID_CHILD_ARRAY apidl, DWORD *rgfInOut);
53 
54     STDMETHODIMP GetUIObjectOf(HWND hwndOwner, UINT cidl, PCUITEMID_CHILD_ARRAY apidl, REFIID riid, UINT *prgfInOut,
55                                LPVOID *ppvOut);
56 
57 
58     STDMETHODIMP GetDisplayNameOf(PCUITEMID_CHILD pidl, DWORD dwFlags, LPSTRRET pName);
59     STDMETHODIMP SetNameOf(HWND hwndOwner, PCUITEMID_CHILD pidl, LPCOLESTR lpName, DWORD dwFlags,
60                            PITEMID_CHILD *pPidlOut);
61 
62     //// *** IShellFolderViewCB methods ***
63     STDMETHODIMP MessageSFVCB(UINT uMsg, WPARAM wParam, LPARAM lParam);
64 
65 private:
66     LPITEMIDLIST m_pidl;
67     CComPtr<IShellFolder2> m_pisfInner;
68     CComPtr<IShellFolderView> m_shellFolderView;
69     CComPtr<IShellBrowser> m_shellBrowser;
70     HANDLE m_hStopEvent;
71 
72     void NotifyConnections(DISPID id);
73     static DWORD WINAPI SearchThreadProc(LPVOID lpParameter);
74 
75     //// *** IPersistFolder2 methods ***
76     STDMETHODIMP GetCurFolder(PIDLIST_ABSOLUTE *pidl);
77 
78 
79     // *** IPersistFolder methods ***
80     STDMETHODIMP Initialize(PCIDLIST_ABSOLUTE pidl);
81 
82 
83     // *** IPersist methods ***
84     STDMETHODIMP GetClassID(CLSID *pClassId);
85 
86     // *** Message handlers ***
87     LRESULT StartSearch(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
88 
89     LRESULT StopSearch(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
90 
91     LRESULT AddResult(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
92 
93     LRESULT UpdateStatus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
94 
95 public:
96     CFindFolder();
97 
98     DECLARE_REGISTRY_RESOURCEID(IDR_FINDFOLDER)
99 
100     DECLARE_NOT_AGGREGATABLE(CFindFolder)
101 
102     DECLARE_PROTECT_FINAL_CONSTRUCT()
103 
104     BEGIN_CONNECTION_POINT_MAP(CFindFolder)
105         CONNECTION_POINT_ENTRY(DIID_DSearchCommandEvents)
106     END_CONNECTION_POINT_MAP()
107 
108     BEGIN_MSG_MAP(CFindFolder)
109         MESSAGE_HANDLER(WM_SEARCH_START, StartSearch)
110         MESSAGE_HANDLER(WM_SEARCH_STOP, StopSearch)
111         MESSAGE_HANDLER(WM_SEARCH_ADD_RESULT, AddResult)
112         MESSAGE_HANDLER(WM_SEARCH_UPDATE_STATUS, UpdateStatus)
113     END_MSG_MAP()
114 
115     BEGIN_COM_MAP(CFindFolder)
116         COM_INTERFACE_ENTRY_IID(IID_IShellFolder2, IShellFolder2)
117         COM_INTERFACE_ENTRY_IID(IID_IShellFolder, IShellFolder)
118         COM_INTERFACE_ENTRY_IID(IID_IShellFolderViewCB, IShellFolderViewCB)
119         COM_INTERFACE_ENTRY_IID(IID_IPersistFolder2, IPersistFolder2)
120         COM_INTERFACE_ENTRY_IID(IID_IPersistFolder, IPersistFolder)
121         COM_INTERFACE_ENTRY_IID(IID_IPersist, IPersist)
122         COM_INTERFACE_ENTRY_IID(IID_IConnectionPointContainer, IConnectionPointContainer)
123     END_COM_MAP()
124 };
125 
126