[SHELLFIND] Add search command events
authorBrock Mammen <brockmammen@gmail.com>
Sun, 18 Aug 2019 02:41:59 +0000 (21:41 -0500)
committerGiannis Adamopoulos <gadamopoulos@reactos.org>
Sun, 15 Sep 2019 16:46:36 +0000 (19:46 +0300)
dll/win32/browseui/shellfind/CFindFolder.cpp
dll/win32/browseui/shellfind/CFindFolder.h
sdk/include/psdk/exdisp.idl
sdk/include/psdk/exdispid.h

index 535c1af..7b65d83 100644 (file)
@@ -1,11 +1,5 @@
-/*
- * PROJECT:     ReactOS Search Shell Extension
- * LICENSE:     GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
- * PURPOSE:     Search results folder
- * COPYRIGHT:   Copyright 2019 Brock Mammen
- */
-
 #include "CFindFolder.h"
+#include <exdispid.h>
 
 WINE_DEFAULT_DEBUG_CHANNEL(shellfind);
 
@@ -88,6 +82,7 @@ struct _SearchData
     HWND hwnd;
     HANDLE hStopEvent;
     SearchStart *pSearchParams;
+    CFindFolder *pFindFolder;
 };
 
 static LPCSTR WINAPI StrStrNA(LPCSTR lpFirst, LPCSTR lpSrch, UINT cchMax)
@@ -210,20 +205,40 @@ static VOID RecursiveFind(LPCWSTR lpPath, _SearchData *pSearchData)
         FindClose(hFindFile);
 }
 
-static DWORD WINAPI _SearchThreadProc(LPVOID lpParameter)
+DWORD WINAPI CFindFolder::_SearchThreadProc(LPVOID lpParameter)
 {
     _SearchData *data = static_cast<_SearchData*>(lpParameter);
-
     SearchStart* params = (SearchStart *) data->pSearchParams;
 
+    data->pFindFolder->NotifyConnections(DISPID_SEARCHSTART);
+
     RecursiveFind(params->szPath, data);
 
+    data->pFindFolder->NotifyConnections(DISPID_SEARCHCOMPLETE);
+
     SHFree(params);
     SHFree(lpParameter);
 
     return 0;
 }
 
+void CFindFolder::NotifyConnections(DISPID id)
+{
+    DISPPARAMS dispatchParams = {0};
+    CComDynamicUnkArray &subscribers =
+        IConnectionPointImpl<CFindFolder, &DIID_DSearchCommandEvents>::m_vec;
+    for (IUnknown** pSubscriber = subscribers.begin(); pSubscriber < subscribers.end(); pSubscriber++)
+    {
+        if (!*pSubscriber)
+            continue;
+
+        CComPtr<IDispatch> pDispatch;
+        HRESULT hResult = (*pSubscriber)->QueryInterface(IID_PPV_ARG(IDispatch, &pDispatch));
+        if (!FAILED_UNEXPECTEDLY(hResult))
+            pDispatch->Invoke(id, GUID_NULL, 0, DISPATCH_METHOD, &dispatchParams, NULL, NULL, NULL);
+    }
+}
+
 LRESULT CFindFolder::StartSearch(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
 {
     if (!lParam)
index 1768d47..885e49b 100644 (file)
@@ -12,6 +12,8 @@ class CFindFolder :
         public IShellFolder2,
         public IPersistFolder2,
         public IShellFolderViewCB,
+        public IConnectionPointContainerImpl<CFindFolder>,
+        public IConnectionPointImpl<CFindFolder, &DIID_DSearchCommandEvents>,
         public IContextMenuCB
 {
     // *** IShellFolder2 methods ***
@@ -68,6 +70,9 @@ private:
     CComPtr<IShellBrowser> m_shellBrowser;
     HANDLE m_hStopEvent;
 
+    void NotifyConnections(DISPID id);
+    static DWORD WINAPI SearchThreadProc(LPVOID lpParameter);
+
     //// *** IPersistFolder2 methods ***
     STDMETHODIMP GetCurFolder(LPITEMIDLIST *pidl);
 
@@ -95,6 +100,10 @@ public:
 
     DECLARE_PROTECT_FINAL_CONSTRUCT()
 
+    BEGIN_CONNECTION_POINT_MAP(CFindFolder)
+        CONNECTION_POINT_ENTRY(DIID_DSearchCommandEvents)
+    END_CONNECTION_POINT_MAP()
+
     BEGIN_MSG_MAP(CFindFolder)
         MESSAGE_HANDLER(WM_SEARCH_START, StartSearch)
         MESSAGE_HANDLER(WM_SEARCH_ADD_RESULT, AddResult)
@@ -108,6 +117,7 @@ public:
         COM_INTERFACE_ENTRY_IID(IID_IPersistFolder2, IPersistFolder2)
         COM_INTERFACE_ENTRY_IID(IID_IPersistFolder, IPersistFolder)
         COM_INTERFACE_ENTRY_IID(IID_IPersist, IPersist)
+        COM_INTERFACE_ENTRY_IID(IID_IConnectionPointContainer, IConnectionPointContainer)
         COM_INTERFACE_ENTRY_IID(IID_IContextMenuCB, IContextMenuCB)
     END_COM_MAP()
 };
index 3791acb..1471f9e 100644 (file)
@@ -1043,4 +1043,16 @@ coclass SearchAssistantOC {
     [default, source] dispinterface _SearchAssistantEvents;
 }
 
+[
+    uuid(60890160-69f0-11d1-b758-00a0c90564fe),
+    hidden
+]
+dispinterface DSearchCommandEvents {
+    properties:
+    methods:
+    [id(DISPID_SEARCHSTART)]    void SearchStart();
+    [id(DISPID_SEARCHCOMPLETE)] void SearchComplete();
+    [id(DISPID_SEARCHABORT)]    void SearchAbort();
+}
+
 } /* library */
index 012f704..deaafb3 100644 (file)
 #define DISPID_EXPAND                25
 #define DISPID_UNSELECTALL           26
 
+#define DISPID_SEARCHSTART           1
+#define DISPID_SEARCHCOMPLETE        2
+#define DISPID_SEARCHABORT           3
+
 #endif /* EXDISPID_H_ */