Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

351 lines
12 KiB

  1. #ifndef __SRCHASST_H_
  2. #define __SRCHASST_H_
  3. #include "caggunk.h"
  4. #include "dspsprt.h"
  5. class CSearch : public ISearch,
  6. protected CImpIDispatch
  7. {
  8. public:
  9. //IUnknown methods
  10. STDMETHODIMP QueryInterface(REFIID riid, LPVOID * ppv);
  11. STDMETHODIMP_(ULONG) AddRef(void);
  12. STDMETHODIMP_(ULONG) Release(void);
  13. //IDispatch members
  14. virtual STDMETHODIMP GetTypeInfoCount(UINT * pctinfo)
  15. { return CImpIDispatch::GetTypeInfoCount(pctinfo); }
  16. virtual STDMETHODIMP GetTypeInfo(UINT itinfo, LCID lcid, ITypeInfo **pptinfo)
  17. { return CImpIDispatch::GetTypeInfo(itinfo, lcid, pptinfo); }
  18. virtual STDMETHODIMP GetIDsOfNames(REFIID riid, OLECHAR **rgszNames, UINT cNames, LCID lcid, DISPID * rgdispid)
  19. { return CImpIDispatch::GetIDsOfNames(riid, rgszNames, cNames, lcid, rgdispid); }
  20. virtual STDMETHODIMP Invoke(DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS * pdispparams, VARIANT * pvarResult, EXCEPINFO * pexcepinfo, UINT * puArgErr)
  21. { return CImpIDispatch::Invoke(dispidMember, riid, lcid, wFlags, pdispparams, pvarResult, pexcepinfo, puArgErr); }
  22. //ISearch methods
  23. STDMETHODIMP get_Title(BSTR *pbstrTitle);
  24. STDMETHODIMP get_Id(BSTR *pbstrId);
  25. STDMETHODIMP get_Url(BSTR *pbstrUrl);
  26. private:
  27. CSearch(GUID *pguid, BSTR bstrTitle, BSTR bstrUrl);
  28. ~CSearch();
  29. LONG _cRef;
  30. BSTR _bstrTitle;
  31. BSTR _bstrUrl;
  32. TCHAR _szId[40];
  33. friend HRESULT CSearch_Create(GUID *pguid, BSTR bstrTitle, BSTR bstrUrl, ISearch **ppSearch);
  34. };
  35. class CSearchCollection : public ISearches,
  36. protected CImpIDispatch
  37. {
  38. public:
  39. //IUnknown methods
  40. STDMETHODIMP QueryInterface(REFIID riid, LPVOID * ppv);
  41. STDMETHODIMP_(ULONG) AddRef(void);
  42. STDMETHODIMP_(ULONG) Release(void);
  43. //IDispatch members
  44. virtual STDMETHODIMP GetTypeInfoCount(UINT * pctinfo)
  45. { return CImpIDispatch::GetTypeInfoCount(pctinfo); }
  46. virtual STDMETHODIMP GetTypeInfo(UINT itinfo, LCID lcid, ITypeInfo **pptinfo)
  47. { return CImpIDispatch::GetTypeInfo(itinfo, lcid, pptinfo); }
  48. virtual STDMETHODIMP GetIDsOfNames(REFIID riid, OLECHAR **rgszNames, UINT cNames, LCID lcid, DISPID * rgdispid)
  49. { return CImpIDispatch::GetIDsOfNames(riid, rgszNames, cNames, lcid, rgdispid); }
  50. virtual STDMETHODIMP Invoke(DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS * pdispparams, VARIANT * pvarResult, EXCEPINFO * pexcepinfo, UINT * puArgErr)
  51. { return CImpIDispatch::Invoke(dispidMember, riid, lcid, wFlags, pdispparams, pvarResult, pexcepinfo, puArgErr); }
  52. STDMETHODIMP get_Count(long *plCount);
  53. STDMETHODIMP get_Default(BSTR *pbstr);
  54. STDMETHODIMP Item(VARIANT index, ISearch **ppid);
  55. STDMETHODIMP _NewEnum(IUnknown **ppunk);
  56. private:
  57. CSearchCollection(IFolderSearches *pfs);
  58. ~CSearchCollection();
  59. LONG _cRef;
  60. TCHAR _szDefault[40];
  61. HDSA _hdsaItems;
  62. friend HRESULT CSearchCollection_Create(IFolderSearches *pfs, ISearches **ppSearches);
  63. };
  64. //////////////////////////////////////////////////////////////////////////////
  65. // CProxy_SearchAssistantEvents
  66. template <class T>
  67. class CProxy_SearchAssistantEvents : public IConnectionPointImpl<T, &
  68. DIID__SearchAssistantEvents, CComDynamicUnkArray>
  69. {
  70. public:
  71. //methods:
  72. //_SearchAssistantEvents : IDispatch
  73. public:
  74. void Fire_OnNextMenuSelect(int idItem)
  75. {
  76. VARIANTARG* pvars = new VARIANTARG[1];
  77. if (NULL != pvars)
  78. {
  79. for (int i = 0; i < 1; i++)
  80. VariantInit(&pvars[i]);
  81. T* pT = (T*)this;
  82. pT->Lock();
  83. IUnknown** pp = m_vec.begin();
  84. while (pp < m_vec.end())
  85. {
  86. if (*pp != NULL)
  87. {
  88. pvars[0].vt = VT_I4;
  89. pvars[0].lVal= idItem;
  90. DISPPARAMS disp = { pvars, NULL, 1, 0 };
  91. IDispatch* pDispatch = reinterpret_cast<IDispatch*>(*pp);
  92. pDispatch->Invoke(0x1, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &disp, NULL, NULL, NULL);
  93. }
  94. pp++;
  95. }
  96. pT->Unlock();
  97. delete[] pvars;
  98. }
  99. }
  100. void Fire_OnNewSearch()
  101. {
  102. T* pT = (T*)this;
  103. pT->Lock();
  104. IUnknown** pp = m_vec.begin();
  105. while (pp < m_vec.end())
  106. {
  107. if (*pp != NULL)
  108. {
  109. DISPPARAMS disp = { NULL, NULL, 0, 0 };
  110. IDispatch* pDispatch = reinterpret_cast<IDispatch*>(*pp);
  111. pDispatch->Invoke(0x2, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &disp, NULL, NULL, NULL);
  112. }
  113. pp++;
  114. }
  115. pT->Unlock();
  116. }
  117. };
  118. /////////////////////////////////////////////////////////////////////////////
  119. // CSearchAssistantOC
  120. class ATL_NO_VTABLE CSearchAssistantOC :
  121. public CComObjectRootEx<CComSingleThreadModel>,
  122. public CComCoClass<CSearchAssistantOC, &CLSID_SearchAssistantOC>,
  123. public CComControl<CSearchAssistantOC>,
  124. #ifndef UNIX
  125. public IDispatchImpl<ISearchAssistantOC3, &IID_ISearchAssistantOC3, &LIBID_SHDocVw>,
  126. public IProvideClassInfo2Impl<&CLSID_SearchAssistantOC, &DIID__SearchAssistantEvents, &LIBID_SHDocVw>,
  127. #else
  128. public IDispatchImpl<ISearchAssistantOC3, &IID_ISearchAssistantOC3, &LIBID_SHDocVw, 1, 0, CComTypeInfoHolder>,
  129. public IProvideClassInfo2Impl<&CLSID_SearchAssistantOC, &DIID__SearchAssistantEvents, &LIBID_SHDocVw, 1, 0, CComTypeInfoHolder>,
  130. #endif
  131. public IPersistStreamInitImpl<CSearchAssistantOC>,
  132. public IPersistStorageImpl<CSearchAssistantOC>,
  133. public IQuickActivateImpl<CSearchAssistantOC>,
  134. public IOleControlImpl<CSearchAssistantOC>,
  135. public IOleObjectImpl<CSearchAssistantOC>,
  136. public IOleInPlaceActiveObjectImpl<CSearchAssistantOC>,
  137. public IViewObjectExImpl<CSearchAssistantOC>,
  138. public IOleInPlaceObjectWindowlessImpl<CSearchAssistantOC>,
  139. public IDataObjectImpl<CSearchAssistantOC>,
  140. public CProxy_SearchAssistantEvents<CSearchAssistantOC>,
  141. public IConnectionPointContainerImpl<CSearchAssistantOC>,
  142. public ISpecifyPropertyPagesImpl<CSearchAssistantOC>,
  143. #ifndef UNIX
  144. public IObjectSafetyImpl<CSearchAssistantOC, INTERFACESAFE_FOR_UNTRUSTED_CALLER>,
  145. #else
  146. public IObjectSafety,
  147. #endif
  148. public IOleCommandTarget,
  149. public IObjectWithSite // HACKHACK: need non-IOleClientSite host for FindXXX methods.
  150. {
  151. public:
  152. CSearchAssistantOC();
  153. ~CSearchAssistantOC();
  154. BEGIN_COM_MAP(CSearchAssistantOC)
  155. COM_INTERFACE_ENTRY(ISearchAssistantOC3)
  156. COM_INTERFACE_ENTRY_IID(IID_ISearchAssistantOC, ISearchAssistantOC3)
  157. COM_INTERFACE_ENTRY(IDispatch)
  158. COM_INTERFACE_ENTRY(IOleCommandTarget)
  159. COM_INTERFACE_ENTRY_IMPL(IViewObjectEx)
  160. COM_INTERFACE_ENTRY_IMPL_IID(IID_IViewObject2, IViewObjectEx)
  161. COM_INTERFACE_ENTRY_IMPL_IID(IID_IViewObject, IViewObjectEx)
  162. COM_INTERFACE_ENTRY_IMPL(IOleInPlaceObjectWindowless)
  163. COM_INTERFACE_ENTRY_IMPL_IID(IID_IOleInPlaceObject, IOleInPlaceObjectWindowless)
  164. COM_INTERFACE_ENTRY_IMPL_IID(IID_IOleWindow, IOleInPlaceObjectWindowless)
  165. COM_INTERFACE_ENTRY_IMPL(IOleInPlaceActiveObject)
  166. COM_INTERFACE_ENTRY_IMPL(IOleControl)
  167. COM_INTERFACE_ENTRY_IMPL(IOleObject)
  168. COM_INTERFACE_ENTRY_IMPL(IQuickActivate)
  169. COM_INTERFACE_ENTRY_IMPL(IPersistStorage)
  170. COM_INTERFACE_ENTRY_IMPL(IPersistStreamInit)
  171. COM_INTERFACE_ENTRY_IMPL(ISpecifyPropertyPages)
  172. COM_INTERFACE_ENTRY_IMPL(IDataObject)
  173. COM_INTERFACE_ENTRY(IProvideClassInfo)
  174. COM_INTERFACE_ENTRY(IProvideClassInfo2)
  175. COM_INTERFACE_ENTRY_IMPL(IConnectionPointContainer)
  176. COM_INTERFACE_ENTRY(IObjectSafety)
  177. COM_INTERFACE_ENTRY(IObjectWithSite)
  178. END_COM_MAP()
  179. BEGIN_PROPERTY_MAP(CSearchAssistantOC)
  180. // Example entries
  181. // PROP_ENTRY("Property Description", dispid, clsid)
  182. #ifndef UNDER_CE
  183. PROP_PAGE(CLSID_StockColorPage)
  184. #endif
  185. END_PROPERTY_MAP()
  186. BEGIN_CONNECTION_POINT_MAP(CSearchAssistantOC)
  187. CONNECTION_POINT_ENTRY(DIID__SearchAssistantEvents)
  188. END_CONNECTION_POINT_MAP()
  189. BEGIN_MSG_MAP(CSearchAssistantOC)
  190. MESSAGE_HANDLER(WM_PAINT, OnPaint)
  191. MESSAGE_HANDLER(WM_SETFOCUS, OnSetFocus)
  192. MESSAGE_HANDLER(WM_KILLFOCUS, OnKillFocus)
  193. END_MSG_MAP()
  194. // IViewObjectEx
  195. STDMETHOD(GetViewStatus)(DWORD* pdwStatus)
  196. {
  197. ATLTRACE(_T("IViewObjectExImpl::GetViewStatus\n"));
  198. *pdwStatus = 0;
  199. return S_OK;
  200. }
  201. public:
  202. // *** ISearchAssistantOC methods ***
  203. STDMETHOD(AddNextMenuItem)(BSTR bstrText, long idItem);
  204. STDMETHOD(SetDefaultSearchUrl)(BSTR bstrUrl);
  205. STDMETHOD(NavigateToDefaultSearch)();
  206. STDMETHOD(IsRestricted)(BSTR bstrGuid, VARIANT_BOOL *pVal);
  207. STDMETHOD(get_ShellFeaturesEnabled)(VARIANT_BOOL *pVal);
  208. STDMETHOD(get_SearchAssistantDefault)(VARIANT_BOOL *pVal);
  209. STDMETHOD(get_Searches)(ISearches **ppid);
  210. STDMETHOD(get_InWebFolder)(VARIANT_BOOL *pVal);
  211. STDMETHOD(PutProperty)(VARIANT_BOOL bPerLocale, BSTR bstrName, BSTR bstrValue);
  212. STDMETHOD(GetProperty)(VARIANT_BOOL bPerLocale, BSTR bstrName, BSTR *pbstrValue);
  213. STDMETHOD(put_EventHandled)(VARIANT_BOOL bHandled);
  214. STDMETHOD(ResetNextMenu)();
  215. STDMETHOD(FindOnWeb)() ;
  216. STDMETHOD(FindFilesOrFolders)() ;
  217. STDMETHOD(FindComputer)() ;
  218. STDMETHOD(FindPrinter)() ;
  219. STDMETHOD(FindPeople)() ;
  220. STDMETHOD(GetSearchAssistantURL)(VARIANT_BOOL bSubstitute, VARIANT_BOOL bCustomize, BSTR *pbstrValue);
  221. STDMETHOD(NotifySearchSettingsChanged)();
  222. STDMETHOD(put_ASProvider)(BSTR Provider);
  223. STDMETHOD(get_ASProvider)(BSTR *pProvider);
  224. STDMETHOD(put_ASSetting)(int Setting);
  225. STDMETHOD(get_ASSetting)(int *pSetting);
  226. STDMETHOD(NETDetectNextNavigate)();
  227. STDMETHOD(PutFindText)(BSTR FindText);
  228. STDMETHOD(get_Version)(int *pVersion);
  229. STDMETHOD(EncodeString)(BSTR bstrValue, BSTR bstrCharSet, VARIANT_BOOL bUseUTF8, BSTR *pbstrResult);
  230. // *** ISearchAssistantOC2 methods ***
  231. STDMETHOD(get_ShowFindPrinter)(VARIANT_BOOL *pbShowFindPrinter);
  232. // *** ISearchAssistantOC3 methods ***
  233. STDMETHOD(get_SearchCompanionAvailable)(VARIANT_BOOL *pbAvailable);
  234. STDMETHOD(put_UseSearchCompanion)(VARIANT_BOOL bUseSC);
  235. STDMETHOD(get_UseSearchCompanion)(VARIANT_BOOL *pbUseSC);
  236. // *** IObjectWithSite ***
  237. STDMETHOD(SetSite)(IUnknown*) ;
  238. STDMETHOD(GetSite)(REFIID, void**) ;
  239. #ifdef UNIX
  240. // *** IObjectSafety ***
  241. STDMETHOD(GetInterfaceSafetyOptions)(REFIID riid, DWORD *pdwSupportedOptions, DWORD *pdwEnabledOptions)
  242. {
  243. ATLTRACE(_T("IObjectSafetyImpl::GetInterfaceSafetyOptions\n"));
  244. if (pdwSupportedOptions == NULL || pdwEnabledOptions == NULL)
  245. return E_POINTER;
  246. HRESULT hr = S_OK;
  247. if (riid == IID_IDispatch)
  248. {
  249. *pdwSupportedOptions = INTERFACESAFE_FOR_UNTRUSTED_CALLER;
  250. *pdwEnabledOptions = m_dwSafety & INTERFACESAFE_FOR_UNTRUSTED_CALLER;
  251. }
  252. else
  253. {
  254. *pdwSupportedOptions = 0;
  255. *pdwEnabledOptions = 0;
  256. hr = E_NOINTERFACE;
  257. }
  258. return hr;
  259. }
  260. STDMETHOD(SetInterfaceSafetyOptions)(REFIID riid, DWORD dwOptionSetMask, DWORD dwEnabledOptions)
  261. {
  262. ATLTRACE(_T("IObjectSafetyImpl::SetInterfaceSafetyOptions\n"));
  263. /* // If we're being asked to set our safe for scripting option then oblige */
  264. if (riid == IID_IDispatch)
  265. {
  266. /* // Store our current safety level to return in GetInterfaceSafetyOptions */
  267. m_dwSafety = dwEnabledOptions & dwOptionSetMask;
  268. return S_OK;
  269. }
  270. return E_NOINTERFACE;
  271. }
  272. #endif
  273. // *** IOleObject overrides ***
  274. STDMETHOD(SetClientSite)(IOleClientSite *pClientSite);
  275. STDMETHOD(QueryStatus)(const GUID *pguidCmdGroup,
  276. ULONG cCmds,
  277. OLECMD prgCmds[],
  278. OLECMDTEXT *pCmdText);
  279. STDMETHOD(Exec)(const GUID *pguidCmdGroup,
  280. DWORD nCmdID,
  281. DWORD nCmdexecopt,
  282. VARIANT *pvaIn,
  283. VARIANT *pvaOut);
  284. HRESULT OnDraw(ATL_DRAWINFO& di);
  285. BOOL IsTrustedSite();
  286. HRESULT ShowSearchBand( REFGUID guidSearch ) ;
  287. static HRESULT UpdateRegistry(BOOL bRegister);
  288. private:
  289. ISearchBandTBHelper *m_pSearchBandTBHelper;
  290. BOOL m_bSafetyInited : 1;
  291. BOOL m_bIsTrustedSite : 1;
  292. IUnknown* m_punkSite ; // to accomodate clients who aren't hosting us as an OC.
  293. VARIANT_BOOL m_bEventHandled;
  294. STDMETHOD(LocalZoneCheck)(); // for wininet netdetect security
  295. #ifdef UNIX
  296. DWORD m_dwSafety;
  297. #endif
  298. };
  299. #define CP_BOGUS ((UINT)-1)
  300. #define CP_UTF_8 65001
  301. #endif // __SRCHASST_H_