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.

404 lines
17 KiB

  1. #ifndef __SHVOCX_H__
  2. #define __SHVOCX_H__
  3. #include "shocx.h"
  4. #include "basesb.h"
  5. #include "sfview.h"
  6. #include "util.h" // for BSTR functions
  7. #include "cobjsafe.h"
  8. #include "ipstg.h"
  9. #include "fldset.h"
  10. class CWebBrowserOC;
  11. #define CS_BACK 0x0001
  12. #define CS_FORE 0x0002
  13. #define AUTOSIZE_OFF 0x00000000L
  14. #define AUTOSIZE_ON 0x00000001L
  15. #define AUTOSIZE_PERCENTWIDTH 0x00000002L
  16. #define AUTOSIZE_FULLSIZE 0x00000004L
  17. #define VB_CLASSNAME_LENGTH 20
  18. //
  19. // NOTES:
  20. //
  21. // A CWebBrowserSB object is ALWAYS paired with CWebBrowserOC, and bahaves
  22. // as a "ShellExplorer" OC together. CWebBrowserOC exports OLE control
  23. // interfaces and an OLE automation interface (IWebBrowser) to the
  24. // container. CWebBrowserSB exports IShellBrowser interface and a few other
  25. // interfaces to the containee (IShellView object and DocObject).
  26. //
  27. // It's important to know that those objects have pointers (not interface
  28. // pointers but explicit object pointers) to each other. In order to avoid
  29. // a circular reference, we don't AddRef to the pointer to CWebBrowserOC
  30. // (_psvo).
  31. //
  32. class CWebBrowserSB : public CBASEBROWSER
  33. {
  34. public:
  35. // IUnknown
  36. STDMETHODIMP QueryInterface(REFIID riid, void **ppvObj);
  37. STDMETHODIMP_(ULONG) AddRef() { return CBASEBROWSER::AddRef(); };
  38. STDMETHODIMP_(ULONG) Release() { return CBASEBROWSER::Release(); };
  39. // IOleInPlaceUIWindow (also IOleWindow)
  40. STDMETHODIMP EnableModelessSB(BOOL fEnable);
  41. STDMETHODIMP TranslateAcceleratorSB(LPMSG lpmsg, WORD wID);
  42. STDMETHODIMP SendControlMsg(UINT id, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *pret);
  43. STDMETHODIMP OnViewWindowActive(struct IShellView * ppshv);
  44. // IBrowserService
  45. STDMETHODIMP GetParentSite(struct IOleInPlaceSite** ppipsite);
  46. STDMETHODIMP GetOleObject(struct IOleObject** ppobjv);
  47. STDMETHODIMP SetNavigateState(BNSTATE bnstate);
  48. STDMETHODIMP_(LRESULT) WndProcBS(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  49. STDMETHODIMP_(LRESULT) OnNotify(NMHDR * pnm);
  50. STDMETHODIMP ReleaseShellView();
  51. STDMETHODIMP ActivatePendingView();
  52. STDMETHODIMP SetTopBrowser();
  53. STDMETHODIMP GetFolderSetData(struct tagFolderSetData* pfsd) { /* we modify base directly */ return S_OK; };
  54. STDMETHODIMP _SwitchActivationNow();
  55. // IShellBrowser
  56. STDMETHODIMP BrowseObject(LPCITEMIDLIST pidl, UINT wFlags);
  57. // IServiceProvider
  58. STDMETHODIMP QueryService(REFGUID guidService, REFIID riid, void **ppvObj);
  59. HRESULT QueryServiceItsOwn(REFGUID guidService, REFIID riid, void **ppvObj)
  60. { return CBASEBROWSER::QueryService(guidService, riid, ppvObj); }
  61. // IOleCommandTarget
  62. STDMETHODIMP QueryStatus(const GUID *pguidCmdGroup,
  63. ULONG cCmds, OLECMD rgCmds[], OLECMDTEXT *pcmdtext);
  64. STDMETHODIMP Exec(const GUID *pguidCmdGroup,
  65. DWORD nCmdID, DWORD nCmdexecopt, VARIANTARG *pvarargIn, VARIANTARG *pvarargOut);
  66. CWebBrowserSB(IUnknown* pauto, CWebBrowserOC* psvo);
  67. void ReleaseShellExplorer(void) { _psvo = NULL; } // NOTE: Note that we haven't AddRef'ed it.
  68. IShellView* GetShellView() { return _bbd._psv;};
  69. // Load/Save to be called by CWebBrowserOC's IPS::Save
  70. HRESULT Load(IStream *pStm);
  71. HRESULT Save(IStream *pStm /*, BOOL fClearDirty */);
  72. protected:
  73. ~CWebBrowserSB();
  74. virtual LRESULT _DefWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  75. virtual void _ViewChange(DWORD dwAspect, LONG lindex);
  76. //ViewStateStream related
  77. STDMETHODIMP_(IStream*) v_GetViewStream(LPCITEMIDLIST pidl, DWORD grfMode, LPCWSTR pwszName);
  78. // se DIRECTION_ flags below
  79. HRESULT _EnableModeless(BOOL fEnable, BOOL fDirection);
  80. HRESULT _TranslateAccelerator(LPMSG lpmsg, WORD wID, BOOL fDirection);
  81. HRESULT _IncludeByPidl(struct IShellView *psv, LPCITEMIDLIST pidl);
  82. HRESULT _IncludeByName(struct IShellView *psv, LPCTSTR pszInclude, LPCTSTR pszExclude);
  83. HRESULT _QueryServiceParent(REFGUID guidService, REFIID riid, void **ppvObj);
  84. BOOL _IsDesktopOC(void);
  85. virtual BOOL _HeyMoe_IsWiseGuy(void);
  86. friend CWebBrowserOC;
  87. CWebBrowserOC* _psvo;
  88. long _cbScriptNesting;
  89. };
  90. #define DIRECTION_FORWARD_TO_CHILD FALSE
  91. #define DIRECTION_FORWARD_TO_PARENT TRUE
  92. class CWebBrowserOC : public CShellOcx
  93. , public IWebBrowser2 // wrapped _pauto
  94. , public CImpIExpDispSupport // wrapped _pauto
  95. , public IExpDispSupportOC
  96. , public IPersistString
  97. , public IOleCommandTarget
  98. , public CObjectSafety
  99. , public ITargetEmbedding
  100. , public CImpIPersistStorage
  101. , public IPersistHistory
  102. {
  103. public:
  104. // IUnknown (we multiply inherit from IUnknown, disambiguate here)
  105. STDMETHOD(QueryInterface)(REFIID riid, void **ppvObj) { return CShellOcx::QueryInterface(riid, ppvObj); }
  106. STDMETHOD_(ULONG, AddRef)() { return CShellOcx::AddRef(); }
  107. STDMETHOD_(ULONG, Release)() { return CShellOcx::Release(); }
  108. // IDispatch (we multiply inherit from IDispatch, disambiguate here)
  109. STDMETHOD(GetTypeInfoCount)(UINT *pctinfo) { return CShellOcx::GetTypeInfoCount(pctinfo); }
  110. STDMETHOD(GetTypeInfo)(UINT itinfo, LCID lcid, ITypeInfo **pptinfo)
  111. { return CShellOcx::GetTypeInfo(itinfo, lcid, pptinfo); }
  112. STDMETHOD(GetIDsOfNames)(REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgdispid)
  113. { return CShellOcx::GetIDsOfNames(riid,rgszNames,cNames,lcid,rgdispid); }
  114. STDMETHOD(Invoke)(DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pdispparams, VARIANT *pvarResult, EXCEPINFO *pexcepinfo, UINT *puArgErr);
  115. // IPersistXXX disambiguate here
  116. STDMETHODIMP IsDirty(void) {return CShellOcx::IsDirty();}
  117. // IOleCommandTarget
  118. STDMETHOD(QueryStatus)(const GUID *pguidCmdGroup,
  119. ULONG cCmds, OLECMD rgCmds[], OLECMDTEXT *pcmdtext);
  120. STDMETHOD(Exec)(const GUID *pguidCmdGroup,
  121. DWORD nCmdID, DWORD nCmdexecopt, VARIANTARG *pvarargIn, VARIANTARG *pvarargOut);
  122. // IObjectSafety
  123. STDMETHOD(SetInterfaceSafetyOptions)(REFIID riid, DWORD dwOptionSetMask, DWORD dwEnabledOptions);
  124. // IWebBrowser
  125. STDMETHOD(GoBack)();
  126. STDMETHOD(GoForward)();
  127. STDMETHOD(GoHome)();
  128. STDMETHOD(GoSearch)();
  129. STDMETHOD(Navigate)(BSTR URL, VARIANT *Flags, VARIANT *TargetFrameName, VARIANT *PostData, VARIANT *Headers);
  130. STDMETHOD(Refresh)();
  131. STDMETHOD(Refresh2)(VARIANT *Level);
  132. STDMETHOD(Stop)();
  133. STDMETHOD(get_Application)(IDispatch **ppDisp);
  134. STDMETHOD(get_Parent)(IDispatch **ppDisp);
  135. STDMETHOD(get_Container)(IDispatch **ppDisp);
  136. STDMETHOD(get_Document)(IDispatch **ppDisp);
  137. STDMETHOD(get_TopLevelContainer)(VARIANT_BOOL *pBool);
  138. STDMETHOD(get_Type)(BSTR * pbstrType);
  139. STDMETHOD(get_Left)(long * pl);
  140. STDMETHOD(put_Left)(long Left);
  141. STDMETHOD(get_Top)(long * pl);
  142. STDMETHOD(put_Top)(long Top);
  143. STDMETHOD(get_Width)(long * pl);
  144. STDMETHOD(put_Width)(long Width);
  145. STDMETHOD(get_Height)(long * pl);
  146. STDMETHOD(put_Height)(long Height);
  147. STDMETHOD(get_LocationName)(BSTR * pbstrLocationName);
  148. STDMETHOD(get_LocationURL)(BSTR * pbstrLocationURL);
  149. STDMETHOD(get_Busy)(VARIANT_BOOL * pBool);
  150. /* IWebBrowserApp methods */
  151. STDMETHOD(Quit)(THIS);
  152. STDMETHOD(ClientToWindow)(THIS_ int FAR* pcx, int FAR* pcy);
  153. STDMETHOD(PutProperty)(THIS_ BSTR szProperty, VARIANT vtValue);
  154. STDMETHOD(GetProperty)(THIS_ BSTR szProperty, VARIANT FAR* pvtValue);
  155. STDMETHOD(get_Name)(THIS_ BSTR FAR* pbstrName);
  156. STDMETHOD(get_HWND)(THIS_ LONG_PTR* pHWND);
  157. STDMETHOD(get_FullName)(THIS_ BSTR FAR* pbstrFullName);
  158. STDMETHOD(get_Path)(THIS_ BSTR FAR* pbstrPath);
  159. STDMETHOD(get_FullScreen)(THIS_ VARIANT_BOOL FAR* pBool);
  160. STDMETHOD(put_FullScreen)(THIS_ VARIANT_BOOL Value);
  161. STDMETHOD(get_Visible)(THIS_ VARIANT_BOOL FAR* pBool);
  162. STDMETHOD(put_Visible)(THIS_ VARIANT_BOOL Value);
  163. STDMETHOD(get_StatusBar)(THIS_ VARIANT_BOOL FAR* pBool);
  164. STDMETHOD(put_StatusBar)(THIS_ VARIANT_BOOL Value);
  165. STDMETHOD(get_StatusText)(THIS_ BSTR FAR* pbstr);
  166. STDMETHOD(put_StatusText)(THIS_ BSTR bstr);
  167. STDMETHOD(get_ToolBar)(THIS_ int FAR* pBool);
  168. STDMETHOD(put_ToolBar)(THIS_ int Value);
  169. STDMETHOD(get_MenuBar)(THIS_ VARIANT_BOOL FAR* pValue);
  170. STDMETHOD(put_MenuBar)(THIS_ VARIANT_BOOL Value);
  171. // IWebBrowser2 methods
  172. STDMETHOD(Navigate2)(THIS_ VARIANT FAR* URL, VARIANT FAR* Flags, VARIANT FAR* TargetFrameName, VARIANT FAR* PostData, VARIANT FAR* Headers);
  173. STDMETHOD(ShowBrowserBar)(THIS_ VARIANT FAR* pvaClsid, VARIANT FAR* pvaShow, VARIANT FAR* pvaSize);
  174. STDMETHOD(QueryStatusWB)(THIS_ OLECMDID cmdID, OLECMDF FAR* pcmdf);
  175. STDMETHOD(ExecWB)(THIS_ OLECMDID cmdID, OLECMDEXECOPT cmdexecopt, VARIANT FAR* pvaIn, VARIANT FAR* pvaOut);
  176. STDMETHOD(get_ReadyState)(THIS_ READYSTATE FAR* plReadyState);
  177. STDMETHOD(get_Offline)(THIS_ VARIANT_BOOL FAR* pbOffline);
  178. STDMETHOD(put_Offline)(THIS_ VARIANT_BOOL bOffline);
  179. STDMETHOD(get_Silent)(THIS_ VARIANT_BOOL FAR* pbSilent);
  180. STDMETHOD(put_Silent)(THIS_ VARIANT_BOOL bSilent);
  181. STDMETHOD(get_RegisterAsBrowser)(THIS_ VARIANT_BOOL FAR* pbRegister);
  182. STDMETHOD(put_RegisterAsBrowser)(THIS_ VARIANT_BOOL bRegister);
  183. STDMETHOD(get_RegisterAsDropTarget)(THIS_ VARIANT_BOOL FAR* pbRegister);
  184. STDMETHOD(put_RegisterAsDropTarget)(THIS_ VARIANT_BOOL bRegister);
  185. STDMETHOD(get_TheaterMode)(THIS_ VARIANT_BOOL FAR* pValue);
  186. STDMETHOD(put_TheaterMode)(THIS_ VARIANT_BOOL Value);
  187. STDMETHOD(get_AddressBar)(THIS_ VARIANT_BOOL FAR* Value);
  188. STDMETHOD(put_AddressBar)(THIS_ VARIANT_BOOL Value);
  189. STDMETHOD(get_Resizable)(THIS_ VARIANT_BOOL FAR* Value) { return E_NOTIMPL; }
  190. STDMETHOD(put_Resizable)(THIS_ VARIANT_BOOL Value);
  191. // *** CImpIExpDispSupport override ***
  192. STDMETHODIMP OnTranslateAccelerator(MSG *pMsg,DWORD grfModifiers);
  193. STDMETHODIMP OnInvoke(DISPID dispidMember, REFIID iid, LCID lcid, WORD wFlags, DISPPARAMS FAR* pdispparams,
  194. VARIANT FAR* pVarResult,EXCEPINFO FAR* pexcepinfo,UINT FAR* puArgErr);
  195. // *** IExpDispSupportOC ***
  196. STDMETHODIMP OnOnControlInfoChanged();
  197. STDMETHODIMP GetDoVerbMSG(MSG *pMsg);
  198. // IPersist
  199. STDMETHOD(GetClassID)(CLSID *pClassID) { return CShellOcx::GetClassID(pClassID); }
  200. // IPersistString
  201. STDMETHOD(Initialize)(LPCWSTR pwszInit);
  202. // ITargetEmbedding
  203. STDMETHOD(GetTargetFrame)(ITargetFrame **ppTargetFrame);
  204. // IPersistStreamInit
  205. STDMETHOD(Load)(IStream *pStm);
  206. STDMETHOD(Save)(IStream *pStm, BOOL fClearDirty);
  207. STDMETHOD(InitNew)(void);
  208. // IPersistPropertyBag
  209. STDMETHOD(Load)(IPropertyBag *pBag, IErrorLog *pErrorLog);
  210. STDMETHOD(Save)(IPropertyBag *pBag, BOOL fClearDirty, BOOL fSaveAllProperties);
  211. // IOleObject
  212. STDMETHODIMP Close(DWORD dwSaveOption);
  213. STDMETHODIMP DoVerb(
  214. LONG iVerb,
  215. LPMSG lpmsg,
  216. IOleClientSite *pActiveSite,
  217. LONG lindex,
  218. HWND hwndParent,
  219. LPCRECT lprcPosRect);
  220. STDMETHODIMP SetHostNames(LPCOLESTR szContainerApp, LPCOLESTR szContainerObj);
  221. // IViewObject2
  222. STDMETHODIMP Draw(
  223. DWORD dwDrawAspect,
  224. LONG lindex,
  225. void *pvAspect,
  226. DVTARGETDEVICE *ptd,
  227. HDC hdcTargetDev,
  228. HDC hdcDraw,
  229. LPCRECTL lprcBounds,
  230. LPCRECTL lprcWBounds,
  231. BOOL ( __stdcall *pfnContinue )(ULONG_PTR dwContinue),
  232. ULONG_PTR dwContinue);
  233. STDMETHODIMP GetColorSet(DWORD, LONG, void *, DVTARGETDEVICE *,
  234. HDC, LOGPALETTE **);
  235. virtual HRESULT STDMETHODCALLTYPE SetExtent( DWORD dwDrawAspect,
  236. SIZEL *psizel);
  237. // IOleControl
  238. STDMETHODIMP GetControlInfo(LPCONTROLINFO pCI);
  239. STDMETHODIMP OnMnemonic(LPMSG pMsg);
  240. STDMETHODIMP OnAmbientPropertyChange(DISPID dispid);
  241. STDMETHODIMP FreezeEvents(BOOL bFreeze);
  242. // IOleInPlaceActiveObject
  243. virtual HRESULT __stdcall OnFrameWindowActivate(BOOL fActivate);
  244. STDMETHODIMP TranslateAccelerator(LPMSG lpmsg);
  245. STDMETHODIMP EnableModeless(BOOL fEnable);
  246. // *** CShellOcx's CImpIConnectionPointContainer override ***
  247. STDMETHODIMP EnumConnectionPoints(LPENUMCONNECTIONPOINTS * ppEnum);
  248. // *** IPersistHistory
  249. STDMETHODIMP LoadHistory(IStream *pStream, IBindCtx *pbc);
  250. STDMETHODIMP SaveHistory(IStream *pStream);
  251. STDMETHODIMP SetPositionCookie(DWORD dwPositionCookie);
  252. STDMETHODIMP GetPositionCookie(DWORD *pdwPositioncookie);
  253. // random public functions
  254. friend HRESULT CWebBrowserOC_SavePersistData(IStream *pstm, SIZE* psizeObj,
  255. FOLDERSETTINGS* pfs, IShellLinkA* plink, SHELLVIEWID* pvid,
  256. BOOL fOffline = FALSE, BOOL fSilent = FALSE,
  257. BOOL fRegisterAsBrowser = FALSE, BOOL fRegisterAsDropTarget = TRUE,
  258. BOOL fEmulateOldStream = FALSE, DWORD * pdwExtra = NULL);
  259. protected:
  260. CWebBrowserOC(IUnknown* punkOuter, LPCOBJECTINFO poi);
  261. ~CWebBrowserOC();
  262. BOOL _InitializeOC(IUnknown* punkOuter);
  263. IUnknown* _GetInner() { return CShellOcx::_GetInner(); }
  264. friend HRESULT CWebBrowserOC_CreateInstance(IUnknown* punkOuter, IUnknown** ppunk, LPCOBJECTINFO poi);
  265. // Override private virtual function
  266. virtual LRESULT v_WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  267. virtual HRESULT v_InternalQueryInterface(REFIID riid, void **ppvObj);
  268. virtual void _OnSetClientSite(void);
  269. virtual HRESULT _OnActivateChange(IOleClientSite* pActiveSite, UINT uState);
  270. virtual void _OnInPlaceActivate(void);
  271. virtual void _OnInPlaceDeactivate(void);
  272. virtual CConnectionPoint* _FindCConnectionPointNoRef(BOOL fdisp, REFIID iid);
  273. // Private non-virtual
  274. LRESULT _OnPaintPrint(HDC hdcPrint);
  275. LRESULT _OnCreate(LPCREATESTRUCT lpcs);
  276. HRESULT _BrowseObject(LPCITEMIDLIST pidlBrowseTo);
  277. void _InitDefault(void);
  278. void _OnSetShellView(IShellView*);
  279. void _OnReleaseShellView(void);
  280. BOOL _GetViewInfo(SHELLVIEWID* pvid);
  281. void _RegisterWindow();
  282. void _UnregisterWindow();
  283. HRESULT _SetDownloadState(HRESULT hresRet, DWORD nCmdexecopt, VARIANTARG *pvarargIn);
  284. void _OnLoaded(BOOL fUpdateBrowserReadyState);
  285. HMODULE _GetBrowseUI();
  286. BOOL _HeyMoe_IsWiseGuy(void) {return _fHostedInImagineer;}
  287. void _OnSetSecureLockIcon(int lock);
  288. BOOL AccessAllowedToNamedFrame(VARIANT *varTargetFrameName);
  289. static LRESULT CALLBACK s_DVWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  290. IUnknown* _pauto; // we aggregate this and pass it to the shellbrowser
  291. IWebBrowser2* _pautoWB2;
  292. IExpDispSupport*_pautoEDS;
  293. BOOL _fInit:1; // TRUE iff we are initialized
  294. BOOL _fEmulateOldStream:1; // TRUE iff we emulate ie30 stream format
  295. BOOL _fNavigateOnSetClientSite:1; // set when Loaded before SetClientSite
  296. BOOL _fShouldRegisterAsBrowser:1; // TRUE iff OC should be registered in windows list
  297. BOOL _fDidRegisterAsBrowser:1; // TRUE iff registered in windows list
  298. BOOL _fTopLevel:1; // TRUE iff we're the topmost CBaseBrowser around
  299. BOOL _fVisible:1; // BETA1: bindable props of the OC that we can't
  300. BOOL _fNoMenuBar:1; // call IEDisp's version of the props.
  301. BOOL _fNoToolBar:1; // for beta2 we should let us call
  302. BOOL _fNoStatusBar:1; // iedisp's version to get the events
  303. BOOL _fFullScreen:1; // to fire and persistence correct.
  304. BOOL _fTheaterMode:1;
  305. BOOL _fNoAddressBar:1;
  306. BOOL _fHostedInVB5:1; // Our immediate container is the VB5 forms engine.
  307. BOOL _fHostedInImagineer:1; //
  308. BOOL _fIncrementedSessionCount:1; // We incremented session count and need to decrement it
  309. BOOL _fInsideInvokeCall; // Currently processing an invoke call
  310. MSG *_pmsgDoVerb; // valid only when _fDoVerbMSGValid
  311. long _cbCookie; // our cookie for registering in windows list
  312. SIZE _szIdeal; // ideal size of view, based on _size.cx
  313. SIZE _szNotify; // last size we notified conainer
  314. FOLDERSETTINGS _fs; // FolderViewMode and FolderFlags
  315. // cached draw aspect incase we are not READSTATE_INTERACTIVE when we get SetExtent
  316. DWORD _dwDrawAspect;
  317. friend CWebBrowserSB;
  318. CWebBrowserSB* _psb;
  319. ITargetFramePriv* _pTargetFramePriv; // QueryService(IID_ITARGETFRAME2)
  320. IShellLinkA* _plinkA; // used in save/load code only
  321. IOleCommandTarget* _pctContainer; // container
  322. HGLOBAL _hmemSB; // Initializing stream
  323. CConnectionPoint m_cpWB1Events; // CShellOcx holds the WB2 event source
  324. LPMESSAGEFILTER _lpMF; // Pointer to message filter for cross-thread containers (e.g., AOL)
  325. HMODULE _hBrowseUI; // Handle for use in design mode brand drawing
  326. DWORD _cPendingFreezeEvents;
  327. };
  328. #define IS_INITIALIZED if(!_fInit){TraceMsg(TF_WARNING,"shvocx: BOGUS CONTAINER calling when we haven't been initialized"); _InitDefault();}
  329. #endif // __SHVOCX_H__