1
0

HTMLContainer2.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. #ifndef NULLSOFT_HTMLCONTAINERH
  2. #define NULLSOFT_HTMLCONTAINERH
  3. #include <ocidl.h>
  4. #include <mshtmhst.h>
  5. #include <mshtmdid.h>
  6. #include <shlobj.h>
  7. #include <urlmon.h>
  8. /**************************************************************************
  9. class definitions
  10. **************************************************************************/
  11. #ifndef DOCHOSTUIFLAG_HOST_NAVIGATES
  12. #define DOCHOSTUIFLAG_HOST_NAVIGATES 0x02000000
  13. #endif
  14. #ifndef DOCHOSTUIFLAG_ENABLE_REDIRECT_NOTIFICATION
  15. #define DOCHOSTUIFLAG_ENABLE_REDIRECT_NOTIFICATION 0x04000000
  16. #endif
  17. #ifndef DOCHOSTUIFLAG_USE_WINDOWLESS_SELECTCONTROL
  18. #define DOCHOSTUIFLAG_USE_WINDOWLESS_SELECTCONTROL 0x08000000
  19. #endif
  20. #ifndef DOCHOSTUIFLAG_USE_WINDOWED_SELECTCONTROL
  21. #define DOCHOSTUIFLAG_USE_WINDOWED_SELECTCONTROL 0x10000000
  22. #endif
  23. #ifndef DOCHOSTUIFLAG_ENABLE_ACTIVEX_INACTIVATE_MODE
  24. #define DOCHOSTUIFLAG_ENABLE_ACTIVEX_INACTIVATE_MODE 0x20000000
  25. #endif
  26. class HTMLContainer2;
  27. typedef BOOL( CALLBACK *BROWSERCB )( HTMLContainer2 *pContiner, DISPID dispId, DISPPARAMS FAR *pDispParams, LPVOID pUser ); // return TRUE to block normal processing
  28. typedef enum tagCONTAINERSTYLE
  29. {
  30. CSTYLE_NORMAL = 0x00, // nothing
  31. CSTYLE_NAVIGATE2_NOCLICKSOUND = 0x01, // prevents click sound in Nvigate2 calls
  32. CSTYLE_NOCLICKSOUND = 0x02, // prevents all click sounds ( requires testing )
  33. } CONTAINERSTYLE;
  34. BOOL HTMLContainer2_Initialize();
  35. BOOL HTMLContainer2_Uninitialize();
  36. class HTMLContainer2 : public IOleClientSite,
  37. public IOleInPlaceSite,
  38. public IOleInPlaceFrame,
  39. public IOleControlSite,
  40. public IDocHostUIHandler2,
  41. public IDocHostShowUI,
  42. public IOleCommandTarget,
  43. public IServiceProvider,
  44. public IDispatch
  45. {
  46. public:
  47. typedef enum
  48. {
  49. uiToolbar = 1,
  50. uiStatusbar = 2,
  51. uiMenubar = 3,
  52. uiAddressbar = 4,
  53. } uiElement;
  54. typedef enum
  55. {
  56. wndLeft = 0x0001,
  57. wndTop = 0x0002,
  58. wndWidth = 0x0004,
  59. wndHeight = 0x0008,
  60. wndRelative = 0x0010,
  61. } windowPosFlags;
  62. typedef enum
  63. {
  64. msgNavigate2 = 0,
  65. msgNavigateToName = 1,
  66. } redirectedMessage;
  67. protected:
  68. HTMLContainer2( HWND waWindow, HWND hwndParent );
  69. virtual ~HTMLContainer2( void );
  70. public:
  71. // *** IUnknown Methods ***
  72. STDMETHOD( QueryInterface )( REFIID riid, PVOID *ppvObject );
  73. STDMETHOD_( ULONG, AddRef )( void );
  74. STDMETHOD_( ULONG, Release )( void );
  75. protected:
  76. // *** IOleInPlaceUIWindow Methods ***
  77. STDMETHOD( GetBorder )( LPRECT lprectBorder );
  78. STDMETHOD( RequestBorderSpace )( LPCBORDERWIDTHS lpborderwidths );
  79. STDMETHOD( SetBorderSpace )( LPCBORDERWIDTHS lpborderwidths );
  80. STDMETHOD( SetActiveObject )( IOleInPlaceActiveObject *pActiveObject,
  81. LPCOLESTR lpszObjName );
  82. // *** IOleClientSite Methods ***
  83. STDMETHOD( SaveObject )( );
  84. STDMETHOD( GetMoniker )( DWORD dwAssign, DWORD dwWhichMoniker, LPMONIKER *ppMk );
  85. STDMETHOD( GetContainer )( LPOLECONTAINER *ppContainer );
  86. STDMETHOD( ShowObject )( );
  87. STDMETHOD( OnShowWindow )( BOOL fShow );
  88. STDMETHOD( RequestNewObjectLayout )( );
  89. // *** IOleWindow Methods ***
  90. STDMETHOD( GetWindow ) ( HWND *phwnd );
  91. STDMETHOD( ContextSensitiveHelp ) ( BOOL fEnterMode );
  92. // *** IOleInPlaceSite Methods ***
  93. STDMETHOD( CanInPlaceActivate ) ( void );
  94. STDMETHOD( OnInPlaceActivate ) ( void );
  95. STDMETHOD( OnUIActivate ) ( void );
  96. STDMETHOD( GetWindowContext ) ( IOleInPlaceFrame **ppFrame, IOleInPlaceUIWindow **ppDoc, LPRECT lprcPosRect, LPRECT lprcClipRect, LPOLEINPLACEFRAMEINFO lpFrameInfo );
  97. STDMETHOD( Scroll ) ( SIZE scrollExtent );
  98. STDMETHOD( OnUIDeactivate ) ( BOOL fUndoable );
  99. STDMETHOD( OnInPlaceDeactivate ) ( void );
  100. STDMETHOD( DiscardUndoState ) ( void );
  101. STDMETHOD( DeactivateAndUndo ) ( void );
  102. STDMETHOD( OnPosRectChange ) ( LPCRECT lprcPosRect );
  103. // *** IOleInPlaceFrame Methods ***
  104. STDMETHOD( InsertMenus )( HMENU hmenuShared, LPOLEMENUGROUPWIDTHS lpMenuWidths );
  105. STDMETHOD( SetMenu )( HMENU hmenuShared, HOLEMENU holemenu, HWND hwndActiveObject );
  106. STDMETHOD( RemoveMenus )( HMENU hmenuShared );
  107. STDMETHOD( SetStatusText )( LPCOLESTR pszStatusText );
  108. STDMETHOD( EnableModeless )( BOOL fEnable );
  109. STDMETHOD( TranslateAccelerator )( LPMSG lpmsg, WORD wID );
  110. // *** IOleControlSite Methods ***
  111. STDMETHOD( OnControlInfoChanged )( void );
  112. STDMETHOD( LockInPlaceActive )( BOOL fLock );
  113. STDMETHOD( GetExtendedControl )( IDispatch **ppDisp );
  114. STDMETHOD( TransformCoords )( POINTL *pptlHimetric, POINTF *pptfContainer, DWORD dwFlags );
  115. STDMETHOD( TranslateAccelerator )( LPMSG pMsg, DWORD grfModifiers );
  116. STDMETHOD( OnFocus )( BOOL fGotFocus );
  117. STDMETHOD( ShowPropertyFrame )( void );
  118. // *** IDispatch Methods ***
  119. STDMETHOD( GetIDsOfNames )( REFIID riid, OLECHAR FAR *FAR *rgszNames, unsigned int cNames, LCID lcid, DISPID FAR *rgdispid );
  120. STDMETHOD( GetTypeInfo )( unsigned int itinfo, LCID lcid, ITypeInfo FAR *FAR *pptinfo );
  121. STDMETHOD( GetTypeInfoCount )( unsigned int FAR *pctinfo );
  122. STDMETHOD( Invoke )( DISPID dispid, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS FAR *pdispparams, VARIANT FAR *pvarResult, EXCEPINFO FAR *pexecinfo, unsigned int FAR *puArgErr );
  123. // *** IDocHostUIHandler Methods ***
  124. STDMETHOD( ShowContextMenu )( DWORD dwID, POINT __RPC_FAR *ppt, IUnknown __RPC_FAR *pcmdtReserved, IDispatch __RPC_FAR *pdispReserved );
  125. STDMETHOD( GetHostInfo )( DOCHOSTUIINFO __RPC_FAR *pInfo );
  126. STDMETHOD( ShowUI )( DWORD dwID, IOleInPlaceActiveObject __RPC_FAR *pActiveObject, IOleCommandTarget __RPC_FAR *pCommandTarget, IOleInPlaceFrame __RPC_FAR *pFrame, IOleInPlaceUIWindow __RPC_FAR *pDoc );
  127. STDMETHOD( HideUI )( void );
  128. STDMETHOD( UpdateUI )( void );
  129. STDMETHOD( OnDocWindowActivate )( BOOL fActivate );
  130. STDMETHOD( OnFrameWindowActivate )( BOOL fActivate );
  131. STDMETHOD( ResizeBorder )( LPCRECT prcBorder, IOleInPlaceUIWindow __RPC_FAR *pUIWindow, BOOL fRameWindow );
  132. STDMETHOD( TranslateAccelerator )( LPMSG lpMsg, const GUID __RPC_FAR *pguidCmdGroup, DWORD nCmdID );
  133. STDMETHOD( GetOptionKeyPath )( LPOLESTR __RPC_FAR *pchKey, DWORD dw );
  134. STDMETHOD( GetDropTarget )( IDropTarget __RPC_FAR *pDropTarget, IDropTarget __RPC_FAR *__RPC_FAR *ppDropTarget );
  135. STDMETHOD( GetExternal )( IDispatch __RPC_FAR *__RPC_FAR *ppDispatch );
  136. STDMETHOD( TranslateUrl )( DWORD dwTranslate, OLECHAR __RPC_FAR *pchURLIn, OLECHAR __RPC_FAR *__RPC_FAR *ppchURLOut );
  137. STDMETHOD( FilterDataObject )( IDataObject __RPC_FAR *pDO, IDataObject __RPC_FAR *__RPC_FAR *ppDORet );
  138. // STDMETHOD (EnableModeless)(BOOL fEnable);
  139. // *** IDocHostUIHandler2 Methods ***
  140. STDMETHOD( GetOverrideKeyPath )( LPOLESTR __RPC_FAR *pchKey, DWORD dw );
  141. // *** IDocHostShowUI ***
  142. STDMETHOD( ShowHelp )( HWND hwnd, LPOLESTR pszHelpFile, UINT uCommand, DWORD dwData, POINT ptMouse, IDispatch *pDispatchObjectHit );
  143. STDMETHOD( ShowMessage )( HWND hwnd, LPOLESTR lpstrText, LPOLESTR lpstrCaption, DWORD dwType, LPOLESTR lpstrHelpFile, DWORD dwHelpContext, LRESULT *plResult );
  144. /*** IOleCommandTarget ***/
  145. STDMETHOD( QueryStatus )( const GUID *pguidCmdGroup, ULONG cCmds, OLECMD *prgCmds, OLECMDTEXT *pCmdText );
  146. STDMETHOD( Exec )( const GUID *pguidCmdGroup, DWORD nCmdID, DWORD nCmdExecOpt, VARIANTARG *pvaIn, VARIANTARG *pvaOut );
  147. /*** IServiceProvider ***/
  148. STDMETHOD( QueryService )( REFGUID guidService, REFIID riid, void **ppv );
  149. public:
  150. STDMETHOD( Initialize )( void );
  151. STDMETHOD( Finish )( void );
  152. STDMETHOD( UnadviseBrowserEvents )( void );
  153. STDMETHOD( SetLocation )( int x, int y, int width, int height );
  154. STDMETHOD( SetFocus )( BOOL fFocused );
  155. virtual BOOL TranslateKey( LPMSG pMsg );
  156. HWND GetHostHWND( void );
  157. HWND GetParentHWND( void );
  158. HRESULT NavigateEx( IWebBrowser2 *pWeb2, VARIANT *URL, VARIANT *Flags, VARIANT *TargetFrameName, VARIANT *PostData, VARIANT *Headers );
  159. HRESULT Navigate2( VARIANT *URL, VARIANT *Flags, VARIANT *TargetFrameName, VARIANT *PostData, VARIANT *Headers );
  160. HRESULT PostNavigate2( VARIANT *URL, VARIANT *Flags, VARIANT *TargetFrameName, VARIANT *PostData, VARIANT *Headers ); // navigate using postmessage API
  161. HRESULT NavigateToName( LPCWSTR pszUrl, UINT fFlags );
  162. HRESULT NavigateToNameEx( IWebBrowser2 *pWeb2, LPCWSTR pszUrl, UINT fFlags );
  163. HRESULT PostNavigateToName( LPCWSTR pszUrl, UINT fFlags );
  164. HRESULT WriteHTML( LPCWSTR pszHTML );
  165. HRESULT WriteDocument( BSTR data ); // if succeeded will free bstr
  166. HRESULT InvokeScriptFunction( LPCWSTR pszFuncName, LCID lcid, DISPPARAMS FAR *pDispParams, VARIANT FAR *pVarResult, EXCEPINFO FAR *pExcepInfo, UINT FAR *puArgErr );
  167. HRESULT GetIDispatch( IDispatch **pDisp );
  168. HRESULT GetIUnknown( IUnknown **pUnk );
  169. HRESULT GetIWebBrowser2( IWebBrowser2 **pWeb2 );
  170. // Registers cursors to use with browser// set hCurToUse = NULL to remove
  171. // hCurToUse will be destryoed using DestroyCursor, make sure that this is not shared resource (use CopyCursor)
  172. STDMETHOD( RegisterBrowserCursor )( INT nSysCurID, HCURSOR hCurToUse );
  173. // used by MTBrowser
  174. BROWSERCB RegisterBrowserEventCB( BROWSERCB fnBrowserCB, LPVOID pUserData );
  175. static HRESULT InternetSetFeatureEnabled( INTERNETFEATURELIST FeatureEntry, DWORD dwFlags, BOOL fEnable );
  176. static HRESULT InternetIsFeatureEnabled( INTERNETFEATURELIST FeatureEntry, DWORD dwFlags );
  177. protected:
  178. virtual void OnBeforeNavigate( IDispatch *pDispatch, VARIANT *URL, VARIANT *Flags, VARIANT *TargetFrameName, VARIANT *PostData, VARIANT *Headers, VARIANT_BOOL *Cancel );
  179. virtual void OnNavigateError( IDispatch *pDispatch, VARIANT *URL, VARIANT *TargetFrameName, VARIANT *StatusCode, VARIANT_BOOL *Cancel ){}
  180. virtual void OnNavigateComplete( IDispatch *pDispatch, VARIANT *URL ) {}
  181. virtual void OnDocumentComplete( IDispatch *pDispatch, VARIANT *URL ) {}
  182. virtual void OnDocumentReady( IDispatch *pDispatch, VARIANT *URL ) {} // top frame OnDocumentComplete
  183. virtual void OnDownloadBegin( void ) {}
  184. virtual void OnDownloadComplete( void ) {}
  185. virtual void OnFileDownload( VARIANT_BOOL *ActiveDocument, VARIANT_BOOL *Cancel ) {}
  186. virtual void OnNewWindow2( IDispatch **ppDisp, VARIANT_BOOL *Cancel ) {}
  187. virtual void OnNewWindow3( IDispatch **ppDisp, VARIANT_BOOL *Cancel, DWORD dwFlags, BSTR bstrUrlContext, BSTR bstrUrl ) {}
  188. virtual void OnProgressChange( long Progress, long ProgressMax ) {}
  189. virtual void OnStatusTextChange( LPCWSTR pszText ) {}
  190. virtual void OnCommandStateChange( LONG commandId, VARIANT_BOOL Enable ) {}
  191. virtual void OnSetSecureLockIcon( UINT secureLockIcon ) {}
  192. virtual void OnNavigateCancelled( LPCWSTR pszUrl, VARIANT_BOOL *Cancel ) {}
  193. virtual void OnTitleChange( BSTR pszText ) {}
  194. virtual void OnVisibleChange( VARIANT_BOOL fVisible ) {}
  195. virtual void OnWindowClosing( VARIANT_BOOL IsChildWindow, VARIANT_BOOL *Cancel ) {}
  196. virtual void OnShowUiElement( UINT elementId, VARIANT_BOOL fSHow ) {}
  197. virtual void OnWindowSetResizable( VARIANT_BOOL Enable ) {}
  198. virtual void OnClientToHostWindow( LONG *CX, LONG *CY ) {}
  199. virtual void OnSetWindowPos( UINT flags, LONG x, LONG y, LONG cx, LONG cy ) {}
  200. virtual void OnEnableFullscreen( VARIANT_BOOL Enable ) {}
  201. virtual COLORREF OnGetHostBkColor( void );
  202. virtual DWORD OnGetHostInfoFlags( void );
  203. virtual OLECHAR *OnGetHostCSS( void ); // use CoTaskMemAlloc to allocate string
  204. virtual OLECHAR *OnGetHostNamespace( void ); // use CoTaskMemAlloc to allocate string
  205. virtual DWORD OnGetDownlodFlags( void );
  206. virtual LPCWSTR OnGetUserAgent( void );
  207. virtual DWORD GetContainerStyle( void );
  208. BOOL ValidateURLHost( LPCWSTR pszUrl );
  209. HRESULT IsFrameset( IWebBrowser2 *pWeb2 );
  210. HRESULT GetFramesCount( IWebBrowser2 *pWeb2, INT *frameCount );
  211. HRESULT GetAppVersion( BSTR *p );
  212. HRESULT GetUserAgent( BSTR *p );
  213. virtual HANDLE InitializePopupHook( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { return NULL; }
  214. virtual void DeletePopupHook( HANDLE hHoook ) {}
  215. virtual void InitializeMenuPopup( HWND hwnd, HMENU hMenu, INT iPos, BOOL fWindowMenu ) {}
  216. virtual void ProcessRedirectedMessage( HWND hwnd, UINT messageId, LPARAM param );
  217. HRESULT PostRedirectMessage( UINT messageId, LPARAM param );
  218. virtual BOOL InputLangChangeRequest( HWND hwnd, UINT flags, HKL hkl ) { return FALSE; }
  219. virtual void InputLangChange( UINT charset, HKL hkl ) {}
  220. virtual void OnClosePopupInternal() {}
  221. private:
  222. /// helpers
  223. friend static HRESULT HTMLContainer2_OnShowUiElementHelper( HTMLContainer2 *instance, UINT elementId, DISPPARAMS *pDispParams );
  224. protected:
  225. LONG ref; // ref count
  226. IUnknown *pUnk; // IUnknown of contained object
  227. RECT rect; //
  228. HWND hParent; // window handle of the container
  229. private:
  230. DWORD dwCookie;
  231. DWORD dwFlags;
  232. BROWSERCB fnBrwoserCB;
  233. LPVOID userData;
  234. BOOL bNavigating;
  235. VOID *hCursors;
  236. INT nCursors;
  237. BOOL ensureChakraLoaded;
  238. HWND winampWindow;
  239. friend static LRESULT SubclassControl_WindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
  240. };
  241. #endif