Leaked source code of windows server 2003
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.

340 lines
13 KiB

  1. /******************************************************************************
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. Events.h
  5. Abstract:
  6. This file contains the declaration of the classes related to events.
  7. Revision History:
  8. Davide Massarenti (dmassare) 10/31/99
  9. modified
  10. ******************************************************************************/
  11. #if !defined(__INCLUDED___PCH___EVENTS_H___)
  12. #define __INCLUDED___PCH___EVENTS_H___
  13. #include <MPC_COM.h>
  14. #include <dispex.h>
  15. #include <ocmm.h>
  16. #include <HelpSession.h>
  17. /////////////////////////////////////////////////////////////////////////////
  18. class CPCHEvent;
  19. class CPCHEvents;
  20. class CPCHWebBrowserEvents;
  21. class CPCHHelpCenterExternal;
  22. /////////////////////////////////////////////////////////////////////////////
  23. /////////////////////////////////////////////////////////////////////////////
  24. /*
  25. // DISPID_STATUSTEXTCHANGE void StatusTextChange([in] BSTR Text);
  26. // DISPID_PROGRESSCHANGE void ProgressChange([in] long Progress, [in] long ProgressMax);
  27. // DISPID_COMMANDSTATECHANGE void CommandStateChange([in] long Command, [in] VARIANT_BOOL Enable);
  28. // DISPID_DOWNLOADBEGIN void DownloadBegin();
  29. // DISPID_DOWNLOADCOMPLETE void DownloadComplete();
  30. // DISPID_TITLECHANGE void TitleChange([in] BSTR Text);
  31. // DISPID_PROPERTYCHANGE void PropertyChange([in] BSTR szProperty);
  32. // DISPID_BEFORENAVIGATE2 void BeforeNavigate2([in] IDispatch* pDisp, [in] VARIANT* URL, [in] VARIANT* Flags, [in] VARIANT* TargetFrameName, [in] VARIANT* PostData, [in] VARIANT* Headers, [in, out] VARIANT_BOOL* Cancel);
  33. // DISPID_NEWWINDOW2 void NewWindow2([in, out] IDispatch** ppDisp, [in, out] VARIANT_BOOL* Cancel);
  34. // DISPID_NAVIGATECOMPLETE2 void NavigateComplete2([in] IDispatch* pDisp, [in] VARIANT* URL);
  35. // DISPID_DOCUMENTCOMPLETE void DocumentComplete([in] IDispatch* pDisp, [in] VARIANT* URL);
  36. // DISPID_ONQUIT void OnQuit();
  37. // DISPID_ONVISIBLE void OnVisible([in] VARIANT_BOOL Visible);
  38. // DISPID_ONTOOLBAR void OnToolBar([in] VARIANT_BOOL ToolBar);
  39. // DISPID_ONMENUBAR void OnMenuBar([in] VARIANT_BOOL MenuBar);
  40. // DISPID_ONSTATUSBAR void OnStatusBar([in] VARIANT_BOOL StatusBar);
  41. // DISPID_ONFULLSCREEN void OnFullScreen([in] VARIANT_BOOL FullScreen);
  42. // DISPID_ONTHEATERMODE void OnTheaterMode([in] VARIANT_BOOL TheaterMode);
  43. */
  44. ////////////////////////////////////////////////////////////////////////////////
  45. class CPCHTimerHandle
  46. {
  47. struct CallbackBase : public ITimerSink
  48. {
  49. long m_lRef;
  50. public:
  51. CallbackBase();
  52. virtual void Detach() = 0;
  53. ////////////////////
  54. //
  55. // IUnknown
  56. //
  57. STDMETHOD_(ULONG, AddRef)();
  58. STDMETHOD_(ULONG, Release)();
  59. STDMETHOD(QueryInterface)( REFIID iid, void ** ppvObject );
  60. };
  61. template <class C> class Callback : public CallbackBase
  62. {
  63. public:
  64. typedef HRESULT (C::*CLASS_METHOD)( /*[in]*/ VARIANT );
  65. private:
  66. C* m_pThis;
  67. CLASS_METHOD m_pCallback;
  68. public:
  69. Callback( /*[in]*/ C* pThis, /*[in]*/ CLASS_METHOD pCallback )
  70. {
  71. m_pThis = pThis;
  72. m_pCallback = pCallback;
  73. }
  74. virtual void Detach()
  75. {
  76. m_pThis = NULL;
  77. m_pCallback = NULL;
  78. }
  79. //
  80. // ITimerSink
  81. //
  82. STDMETHOD(OnTimer)( /*[in]*/ VARIANT vtimeAdvise )
  83. {
  84. if(m_pThis == NULL || m_pCallback == NULL) return S_FALSE;
  85. return (m_pThis->*m_pCallback)( vtimeAdvise );
  86. }
  87. };
  88. ////////////////////
  89. CComPtr<ITimer> m_timer;
  90. DWORD m_dwCookie;
  91. CallbackBase* m_callback;
  92. ////////////////////
  93. HRESULT Advise ( /*[in]*/ CallbackBase* callback, /*[in]*/ DWORD dwWait );
  94. void Unadvise( );
  95. public:
  96. CPCHTimerHandle();
  97. ~CPCHTimerHandle();
  98. void Initialize( /*[in]*/ ITimer* timer );
  99. template <class C> HRESULT Start( /*[in/out]*/ C* pThis, /*[in]*/ HRESULT (C::*pCallback)( /*[in]*/ VARIANT ), /*[in]*/ DWORD dwWait )
  100. {
  101. if(pThis == NULL || pCallback == NULL) return E_INVALIDARG;
  102. return Advise( new Callback<C>( pThis, pCallback ), dwWait );
  103. }
  104. void Stop()
  105. {
  106. Unadvise();
  107. }
  108. };
  109. ////////////////////////////////////////////////////////////////////////////////
  110. typedef IDispEventImpl<0,CPCHWebBrowserEvents,&DIID_DWebBrowserEvents2,&LIBID_SHDocVw,1> CPCHWebBrowserEvents_DWebBrowserEvents2;
  111. class CPCHWebBrowserEvents :
  112. public CPCHWebBrowserEvents_DWebBrowserEvents2
  113. {
  114. CPCHHelpCenterExternal* m_parent;
  115. HscPanel m_idPanel;
  116. CComPtr<IWebBrowser2> m_pWB2;
  117. bool m_fLoading;
  118. CPCHTimerHandle m_TimerDelay;
  119. CPCHTimerHandle m_TimerExpire;
  120. ////////////////////
  121. enum TimerMode
  122. {
  123. TIMERMODE_STOP ,
  124. TIMERMODE_RESTART ,
  125. TIMERMODE_MORETIME,
  126. TIMERMODE_COMPLETE,
  127. };
  128. void TimerControl( /*[in]*/ TimerMode mode );
  129. public:
  130. BEGIN_SINK_MAP(CPCHWebBrowserEvents)
  131. SINK_ENTRY_EX(0,DIID_DWebBrowserEvents2,DISPID_BEFORENAVIGATE2 ,BeforeNavigate2 )
  132. SINK_ENTRY_EX(0,DIID_DWebBrowserEvents2,DISPID_NEWWINDOW2 ,NewWindow2 )
  133. SINK_ENTRY_EX(0,DIID_DWebBrowserEvents2,DISPID_NAVIGATECOMPLETE2,NavigateComplete2)
  134. SINK_ENTRY_EX(0,DIID_DWebBrowserEvents2,DISPID_DOCUMENTCOMPLETE ,DocumentComplete )
  135. END_SINK_MAP()
  136. CPCHWebBrowserEvents();
  137. virtual ~CPCHWebBrowserEvents();
  138. void Initialize( /*[in]*/ CPCHHelpCenterExternal* parent, /*[in]*/ HscPanel idPanel );
  139. void Passivate ( );
  140. void Attach ( /*[in]*/ IWebBrowser2* pWB );
  141. void Detach ( );
  142. void NotifyStartOfNavigation( /*[in]*/ BSTR url );
  143. void NotifyEndOfNavigation ( );
  144. void NotifyStop ( );
  145. ////////////////////////////////////////
  146. HRESULT OnTimer( VARIANT vtimeAdvise );
  147. public:
  148. // Event Handlers
  149. void __stdcall BeforeNavigate2 ( IDispatch* pDisp, VARIANT* URL, VARIANT* Flags, VARIANT* TargetFrameName, VARIANT* PostData, VARIANT* Headers, VARIANT_BOOL* Cancel );
  150. void __stdcall NewWindow2 ( IDispatch* *ppDisp, VARIANT_BOOL* Cancel );
  151. void __stdcall NavigateComplete2( IDispatch* pDisp, VARIANT* URL );
  152. void __stdcall DocumentComplete ( IDispatch* pDisp, VARIANT* URL );
  153. };
  154. /////////////////////////////////////////////////////////////////////////////
  155. /////////////////////////////////////////////////////////////////////////////
  156. class ATL_NO_VTABLE CPCHEvent : // Hungarian: hce
  157. public CComObjectRootEx<CComSingleThreadModel>,
  158. public IDispatchImpl<IPCHEvent, &IID_IPCHEvent, &LIBID_HelpCenterTypeLib>
  159. {
  160. friend class CPCHEvents;
  161. DISPID m_idAction;
  162. VARIANT_BOOL m_fCancel;
  163. CComBSTR m_bstrURL;
  164. CComBSTR m_bstrFrame;
  165. CComBSTR m_bstrPanel;
  166. CComBSTR m_bstrPlace;
  167. CComBSTR m_bstrContextData;
  168. CComPtr<CPCHHelpSessionItem> m_hsiCurrentContext;
  169. CComPtr<CPCHHelpSessionItem> m_hsiPreviousContext;
  170. CComPtr<CPCHHelpSessionItem> m_hsiNextContext;
  171. public:
  172. BEGIN_COM_MAP(CPCHEvent)
  173. COM_INTERFACE_ENTRY(IDispatch)
  174. COM_INTERFACE_ENTRY(IPCHEvent)
  175. END_COM_MAP()
  176. CPCHEvent();
  177. virtual ~CPCHEvent();
  178. //
  179. // IPCHEvent
  180. //
  181. public:
  182. STDMETHOD(get_Action )( /*[out, retval]*/ BSTR * pVal );
  183. STDMETHOD(put_Cancel )( /*[in ]*/ VARIANT_BOOL newVal );
  184. STDMETHOD(get_Cancel )( /*[out, retval]*/ VARIANT_BOOL * pVal );
  185. HRESULT put_URL ( /*[in]*/ BSTR newVal ); // Internal method.
  186. STDMETHOD(get_URL )( /*[out, retval]*/ BSTR * pVal );
  187. HRESULT put_Frame ( /*[in]*/ BSTR newVal ); // Internal method.
  188. STDMETHOD(get_Frame )( /*[out, retval]*/ BSTR * pVal );
  189. HRESULT put_Panel ( /*[in]*/ BSTR newVal ); // Internal method.
  190. STDMETHOD(get_Panel )( /*[out, retval]*/ BSTR * pVal );
  191. HRESULT put_Place ( /*[in]*/ BSTR newVal ); // Internal method.
  192. STDMETHOD(get_Place )( /*[out, retval]*/ BSTR * pVal );
  193. STDMETHOD(get_CurrentContext )( /*[out, retval]*/ IPCHHelpSessionItem* * pVal );
  194. STDMETHOD(get_PreviousContext)( /*[out, retval]*/ IPCHHelpSessionItem* * pVal );
  195. STDMETHOD(get_NextContext )( /*[out, retval]*/ IPCHHelpSessionItem* * pVal );
  196. };
  197. /////////////////////////////////////////////////////////////////////////////
  198. /////////////////////////////////////////////////////////////////////////////
  199. class CPCHEvents
  200. {
  201. class EventRegistration
  202. {
  203. public:
  204. long m_lCookie;
  205. DISPID m_id;
  206. long m_lPriority;
  207. MPC::CComPtrThreadNeutral<IDispatch> m_fnCallback;
  208. bool operator==( /*[in]*/ const long lCookie ) const;
  209. bool operator< ( /*[in]*/ const long lPriority ) const;
  210. };
  211. typedef std::list<EventRegistration> List;
  212. typedef List::iterator Iter;
  213. typedef List::const_iterator IterConst;
  214. CPCHHelpCenterExternal* m_parent;
  215. List m_lstEvents;
  216. List m_lstEvents_Staging;
  217. long m_lLastCookie;
  218. public:
  219. CPCHEvents();
  220. ~CPCHEvents();
  221. void Initialize( /*[in]*/ CPCHHelpCenterExternal* parent );
  222. void Passivate ( );
  223. HRESULT RegisterEvents ( /*[in]*/ long id, /*[in]*/ long pri, /*[in]*/ IDispatch* function, /*[out,retval]*/ long *cookie );
  224. HRESULT RegisterEvents ( /*[in]*/ BSTR id, /*[in]*/ long pri, /*[in]*/ IDispatch* function, /*[out,retval]*/ long *cookie );
  225. HRESULT UnregisterEvents( /*[in]*/ long cookie );
  226. HRESULT FireEvent( /*[in]*/ CPCHEvent* eventObj );
  227. ////////////////////////////////////////
  228. HRESULT FireEvent_Generic ( /*[in]*/ DISPID id , /*[out,retval]*/ VARIANT_BOOL *Cancel = NULL );
  229. HRESULT FireEvent_BeforeNavigate ( /*[in]*/ BSTR bstrURL ,
  230. /*[in]*/ BSTR bstrFrame,
  231. /*[in]*/ HscPanel idPanel , /*[out,retval]*/ VARIANT_BOOL *Cancel = NULL );
  232. HRESULT FireEvent_NavigateComplete ( /*[in]*/ BSTR bstrURL ,
  233. /*[in]*/ HscPanel idPanel , /*[out,retval]*/ VARIANT_BOOL *Cancel = NULL );
  234. HRESULT FireEvent_BeforeTransition ( /*[in]*/ BSTR bstrPlace, /*[out,retval]*/ VARIANT_BOOL *Cancel = NULL );
  235. HRESULT FireEvent_Transition ( /*[in]*/ BSTR bstrPlace );
  236. HRESULT FireEvent_BeforeContextSwitch( /*[in]*/ HscContext iVal ,
  237. /*[in]*/ BSTR bstrInfo ,
  238. /*[in]*/ BSTR bstrURL , /*[out,retval]*/ VARIANT_BOOL *Cancel = NULL );
  239. HRESULT FireEvent_ContextSwitch ( );
  240. HRESULT FireEvent_PersistLoad ( );
  241. HRESULT FireEvent_PersistSave ( );
  242. HRESULT FireEvent_TravelDone ( );
  243. HRESULT FireEvent_Shutdown ( /*[out,retval]*/ VARIANT_BOOL *Cancel = NULL );
  244. HRESULT FireEvent_Print ( /*[out,retval]*/ VARIANT_BOOL *Cancel = NULL );
  245. HRESULT FireEvent_SwitchedHelpFiles ( );
  246. HRESULT FireEvent_FavoritesUpdate ( );
  247. HRESULT FireEvent_OptionsChanged ( );
  248. HRESULT FireEvent_CssChanged ( );
  249. ////////////////////////////////////////
  250. static DISPID Lookup ( LPCWSTR szName );
  251. static LPCWSTR ReverseLookup( DISPID idEvent );
  252. };
  253. #endif // !defined(__INCLUDED___PCH___EVENTS_H___)