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.

542 lines
18 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // File: ctr.h
  4. //
  5. // Module: CMDIAL32.DLL
  6. //
  7. // Synopsis: Header for the Ole Container object to host the future splash
  8. // Animation control.
  9. //
  10. // Copyright (c) 1998 Microsoft Corporation
  11. //
  12. // Author: nickball Created 02/10/98
  13. //
  14. //+----------------------------------------------------------------------------
  15. #ifndef __CTR_H_DEFINED__
  16. #define __CTR_H_DEFINED__
  17. #include "state.h"
  18. //
  19. // Typedefs for OLE32 APIs
  20. //
  21. typedef HRESULT (STDAPICALLTYPE *pfnOle32Initialize)(LPVOID);
  22. typedef HRESULT (STDAPICALLTYPE *pfnOle32Uninitialize)();
  23. typedef HRESULT (STDAPICALLTYPE *pfnOle32SetContainedObject) (LPUNKNOWN, BOOL);
  24. typedef HRESULT (STDAPICALLTYPE *pfnOle32CoCreateInstance) (REFCLSID, LPUNKNOWN, DWORD, REFIID, LPVOID *);
  25. typedef struct _Ole32LinkageStruct {
  26. HINSTANCE hInstOle32;
  27. union {
  28. struct {
  29. pfnOle32Initialize pfnOleInitialize;
  30. pfnOle32Uninitialize pfnOleUninitialize;
  31. pfnOle32SetContainedObject pfnOleSetContainedObject;
  32. pfnOle32CoCreateInstance pfnCoCreateInstance;
  33. };
  34. void *apvPfnOle32[5];
  35. };
  36. } Ole32LinkageStruct;
  37. //
  38. // Typedefs for OLEAUT32 APIs
  39. //
  40. typedef HRESULT (STDAPICALLTYPE *pfnOleAutVariantClear) (VARIANTARG FAR*);
  41. typedef HRESULT (STDAPICALLTYPE *pfnOleAutVariantCopy) (VARIANTARG FAR*, VARIANTARG FAR*);
  42. typedef VOID (STDAPICALLTYPE *pfnOleAutVariantInit) (VARIANTARG FAR*);
  43. typedef HRESULT (STDAPICALLTYPE *pfnOleAutVariantChangeType) (VARIANTARG FAR*, VARIANTARG FAR*, unsigned short, VARTYPE);
  44. typedef BSTR (STDAPICALLTYPE *pfnOleAutSysAllocString) (OLECHAR FAR*);
  45. typedef VOID (STDAPICALLTYPE *pfnOleAutSysFreeString) (BSTR);
  46. typedef struct _OleAutLinkageStruct {
  47. HINSTANCE hInstOleAut;
  48. union {
  49. struct {
  50. pfnOleAutVariantClear pfnVariantClear;
  51. pfnOleAutVariantCopy pfnVariantCopy;
  52. pfnOleAutVariantInit pfnVariantInit;
  53. pfnOleAutVariantChangeType pfnVariantChangeType;
  54. pfnOleAutSysAllocString pfnSysAllocString;
  55. pfnOleAutSysFreeString pfnSysFreeString;
  56. };
  57. void *apvPfnOleAut[7];
  58. };
  59. } OleAutLinkageStruct;
  60. //
  61. // Simple wrapper class for dynamic access to OleAut32 APIs that we care about
  62. //
  63. class CDynamicOleAut
  64. {
  65. public:
  66. CDynamicOleAut(VOID);
  67. ~CDynamicOleAut(VOID);
  68. BOOL Initialized(VOID);
  69. HRESULT DynVariantClear(VARIANTARG FAR*);
  70. HRESULT DynVariantCopy(VARIANTARG FAR*, VARIANTARG FAR*);
  71. VOID DynVariantInit(VARIANTARG FAR*);
  72. HRESULT DynVariantChangeType(VARIANTARG FAR*, VARIANTARG FAR*, unsigned short, VARTYPE);
  73. BSTR DynSysAllocString(OLECHAR FAR*);
  74. VOID DynSysFreeString(BSTR);
  75. private:
  76. OleAutLinkageStruct m_OleAutLink;
  77. };
  78. //---------------------------------------------------------------
  79. // IOleObject
  80. //---------------------------------------------------------------
  81. enum OLE_SERVER_STATE
  82. {
  83. OS_PASSIVE,
  84. OS_LOADED, // handler but no server
  85. OS_RUNNING, // server running, invisible
  86. OS_INPLACE, // server running, inplace-active, no U.I.
  87. OS_UIACTIVE, // server running, inplace-active, w/ U.I.
  88. OS_OPEN // server running, open-edited
  89. };
  90. struct BagProp
  91. {
  92. BSTR bstrName; // name of property
  93. VARIANT varValue; // value of property
  94. };
  95. typedef BagProp FAR * LPBAGPROP;
  96. DECLARE_FORMSDATAARY(CAryBagProps, BagProp, LPBAGPROP);
  97. // prototypes for HIMETRIC stuff.
  98. //
  99. void
  100. InitPixelsPerInch(VOID);
  101. int
  102. HPixFromHimetric(long lHi);
  103. int
  104. VPixFromHimetric(long lHi);
  105. long
  106. HimetricFromHPix(int iPix);
  107. long
  108. HimetricFromVPix(int iPix);
  109. class CICMOCCtr;
  110. typedef CICMOCCtr FAR * LPICMOCCtr;
  111. //+---------------------------------------------------------------------------
  112. //
  113. // Class: COleContainer ()
  114. //
  115. // Purpose: our implementation of IOleContainer. does nothing. Not sure
  116. // if we need it for FutureSplash - needed it for Web Browser
  117. // OC
  118. //
  119. //----------------------------------------------------------------------------
  120. class COleContainer : public IOleContainer
  121. {
  122. public:
  123. // IUnknown stuff
  124. STDMETHOD(QueryInterface)(REFIID riid, LPVOID FAR * ppv);
  125. STDMETHOD_(ULONG, AddRef)(VOID);
  126. STDMETHOD_(ULONG, Release)(VOID);
  127. STDMETHOD(EnumObjects)(DWORD grfFlags, IEnumUnknown **ppenum);
  128. STDMETHOD(LockContainer)(BOOL fLock);
  129. STDMETHOD(ParseDisplayName)(
  130. IBindCtx *pbc,
  131. LPOLESTR pszDisplayName,
  132. ULONG *pchEaten,
  133. IMoniker **ppmkOut);
  134. COleContainer(LPICMOCCtr pCtr);
  135. protected:
  136. LPICMOCCtr m_pCtr;
  137. };
  138. //+---------------------------------------------------------------------------
  139. //
  140. // Class: COleClientSite ()
  141. //
  142. // Purpose: our implementation of IOleClientSite
  143. //
  144. // Interface: COleClientSite -- ctor
  145. // QueryInterface -- gimme an interface!
  146. // AddRef -- bump up refcount
  147. // Release -- bump down refcount
  148. // SaveObject -- returns E_FAIL
  149. // GetMoniker -- E_NOTIMPL
  150. // GetContainer -- returns our COleContainer impl
  151. // ShowObject -- just say OK
  152. // OnShowWindow -- just say OK
  153. // RequestNewObjectLayout -- E_NOTIMPL
  154. //
  155. // Notes: probably the most important thing our IOleClientSite
  156. // implementation does is hand off our IOleContainer
  157. // implementation when GetContainer() is called.
  158. //
  159. //----------------------------------------------------------------------------
  160. class COleClientSite : public IOleClientSite
  161. {
  162. public:
  163. COleClientSite(LPICMOCCtr pCtr);
  164. // IUnknown stuff
  165. STDMETHOD(QueryInterface)(REFIID riid, LPVOID FAR * ppv);
  166. STDMETHOD_(ULONG, AddRef)(VOID);
  167. STDMETHOD_(ULONG, Release)(VOID);
  168. // IOleClientSite stuff
  169. STDMETHOD(SaveObject)(VOID);
  170. STDMETHOD(GetMoniker)(
  171. DWORD dwAssign,
  172. DWORD dwWhichMoniker,
  173. LPMONIKER FAR * ppmk);
  174. STDMETHOD(GetContainer)(LPOLECONTAINER FAR * pOleCtr);
  175. STDMETHOD(ShowObject)(VOID);
  176. STDMETHOD(OnShowWindow)(BOOL bShow);
  177. STDMETHOD(RequestNewObjectLayout)(VOID);
  178. protected:
  179. LPICMOCCtr m_pCtr; // pointer to the CICMOCCtr object.
  180. };
  181. //+---------------------------------------------------------------------------
  182. //
  183. // Class: CAdviseSink ()
  184. //
  185. // Purpose: IAdviseSink implementation
  186. //
  187. //----------------------------------------------------------------------------
  188. class CAdviseSink : public IAdviseSink
  189. {
  190. public:
  191. CAdviseSink(LPICMOCCtr pCtr);
  192. // IUnknown stuff
  193. STDMETHOD(QueryInterface)(REFIID riid, LPVOID FAR * ppv);
  194. STDMETHOD_(ULONG, AddRef)(VOID);
  195. STDMETHOD_(ULONG, Release)(VOID);
  196. // IAdviseSink stuff
  197. STDMETHOD_(VOID, OnDataChange)(LPFORMATETC pFE, LPSTGMEDIUM pStgMedium);
  198. STDMETHOD_(VOID, OnViewChange)(DWORD dwAspect, LONG lIndex);
  199. STDMETHOD_(VOID, OnRename)(LPMONIKER pmkNew);
  200. STDMETHOD_(VOID, OnSave)(VOID);
  201. STDMETHOD_(VOID, OnClose)(VOID);
  202. protected:
  203. LPICMOCCtr m_pCtr; // pointer to the CICMOCCtr object.
  204. LPUNKNOWN m_pUnkOuter; // pointer to CICMOCCtr's IUnknown
  205. };
  206. //+---------------------------------------------------------------------------
  207. //
  208. // Class: CInPlaceFrame ()
  209. //
  210. // Purpose:
  211. //
  212. // Interface: CInPlaceFrame -- ctor
  213. // QueryInterface -- gimme an interface!
  214. // AddRef -- bump up refcount
  215. // Release -- decrement refcount
  216. // GetWindow -- from IOleWindow - returns frame hWnd
  217. // ContextSensitiveHelp -- never implemented by design
  218. // GetBorder -- for toolbar negotiation
  219. // RequestBorderSpace -- ditto
  220. // SetBorderSpace -- ditto
  221. // SetActiveObject -- called whenever URL changes
  222. // InsertMenus -- menu negotiation
  223. // SetMenu -- ditto
  224. // RemoveMenus -- ditto
  225. // SetStatusText -- called by OC to set status text
  226. // EnableModeless -- we have no modeless dlgs.
  227. // TranslateAccelerator -- calls ::TranslateAccelerator
  228. //
  229. //----------------------------------------------------------------------------
  230. class CInPlaceFrame : public IOleInPlaceFrame
  231. {
  232. public:
  233. CInPlaceFrame(LPICMOCCtr pCtr);
  234. // IUnknown stuff
  235. STDMETHOD(QueryInterface)(REFIID riid, LPVOID FAR * ppv);
  236. STDMETHOD_(ULONG, AddRef)(VOID);
  237. STDMETHOD_(ULONG, Release)(VOID);
  238. // IOleWindow stuff
  239. STDMETHOD(GetWindow)(HWND * phwnd);
  240. STDMETHOD(ContextSensitiveHelp)(BOOL fEnterMode);
  241. // IOleInPlaceUIWindow stuff
  242. STDMETHOD(GetBorder)(LPRECT lprectBorder);
  243. STDMETHOD(RequestBorderSpace)(LPCBORDERWIDTHS pborderwidths);
  244. STDMETHOD(SetBorderSpace)(LPCBORDERWIDTHS pborderwidths);
  245. STDMETHOD(SetActiveObject)(
  246. IOleInPlaceActiveObject * pActiveObject,
  247. LPCOLESTR pszObjName);
  248. // IOleInPlaceFrame stuff
  249. STDMETHOD(InsertMenus)(
  250. HMENU hmenuShared,
  251. LPOLEMENUGROUPWIDTHS lpMenuWidths);
  252. STDMETHOD(SetMenu)(
  253. HMENU hmenuShared,
  254. HOLEMENU holemenu,
  255. HWND hwndActiveObject);
  256. STDMETHOD(RemoveMenus)(HMENU hmenuShared);
  257. STDMETHOD(SetStatusText)(LPCOLESTR pszStatusText);
  258. STDMETHOD(EnableModeless)(BOOL fEnable);
  259. STDMETHOD(TranslateAccelerator)(LPMSG lpmsg, WORD wID);
  260. protected:
  261. LPICMOCCtr m_pCtr; // pointer to the CICMOCCtr object.
  262. };
  263. //+---------------------------------------------------------------------------
  264. //
  265. // Class: CInPlaceSite ()
  266. //
  267. // Purpose: IOleInPlaceSite implementation.
  268. //
  269. // Interface: CInPlaceSite -- ctor
  270. // QueryInterface -- get a new interface
  271. // AddRef -- bump ref count
  272. // Release -- decrement ref count
  273. // GetWindow -- returns frame window
  274. // ContextSensitiveHelp -- never implemented by design
  275. // CanInPlaceActivate -- returns S_OK.
  276. // OnInPlaceActivate -- caches IOleInPlaceObject ptr
  277. // OnUIActivate -- returns S_OK - sets state
  278. // GetWindowContext -- returns IOleInPlaceFrame,
  279. // IOleInPlaceUIWindow,
  280. // PosRect and ClipRect
  281. // Scroll -- never implemented by design.
  282. // OnUIDeactivate -- obvious
  283. // OnInPlaceDeactivate -- releases cached IOleInPlaceObject
  284. // DiscardUndoState -- returns S_OK.
  285. // DeactivateAndUndo -- deactivates in place active object
  286. // OnPosRectChange -- never implemented by design
  287. //
  288. //----------------------------------------------------------------------------
  289. class CInPlaceSite : public IOleInPlaceSite
  290. {
  291. public:
  292. CInPlaceSite(LPICMOCCtr pCtr);
  293. // IUnknown stuff
  294. STDMETHOD(QueryInterface)(REFIID riid, LPVOID FAR * ppv);
  295. STDMETHOD_(ULONG, AddRef)(VOID);
  296. STDMETHOD_(ULONG, Release)(VOID);
  297. // IOleWindow stuff
  298. STDMETHOD(GetWindow)(HWND * phwnd);
  299. STDMETHOD(ContextSensitiveHelp)(BOOL fEnterMode);
  300. // IOleInPlaceSite stuff
  301. STDMETHOD(CanInPlaceActivate)(VOID);
  302. STDMETHOD(OnInPlaceActivate)(VOID);
  303. STDMETHOD(OnUIActivate)(VOID);
  304. STDMETHOD(GetWindowContext)(
  305. IOleInPlaceFrame **ppFrame,
  306. IOleInPlaceUIWindow **ppDoc,
  307. LPRECT prcPosRect,
  308. LPRECT prcClipRect,
  309. LPOLEINPLACEFRAMEINFO pFrameInfo);
  310. STDMETHOD(Scroll)(SIZE scrollExtant);
  311. STDMETHOD(OnUIDeactivate)(BOOL fUndoable);
  312. STDMETHOD(OnInPlaceDeactivate)(VOID);
  313. STDMETHOD(DiscardUndoState)(VOID);
  314. STDMETHOD(DeactivateAndUndo)(VOID);
  315. STDMETHOD(OnPosRectChange)(LPCRECT lprcPosRect);
  316. protected:
  317. LPICMOCCtr m_pCtr; // pointer to the CICMOCCtr object.
  318. };
  319. class CPropertyBag : public IPropertyBag
  320. {
  321. public:
  322. CPropertyBag(LPICMOCCtr pCtr);
  323. ~CPropertyBag(VOID);
  324. // IUnknown stuff
  325. STDMETHOD(QueryInterface)(REFIID riid, LPVOID FAR * ppv);
  326. STDMETHOD_(ULONG, AddRef)(VOID);
  327. STDMETHOD_(ULONG, Release)(VOID);
  328. // IPropertyBag methods.
  329. STDMETHOD(Read)(LPCOLESTR pszName, LPVARIANT pVar, LPERRORLOG pErrorLog);
  330. STDMETHOD(Write)(LPCOLESTR pszName, LPVARIANT pVar)
  331. {
  332. return E_NOTIMPL;
  333. }
  334. HRESULT AddPropertyToBag(LPTSTR szName, LPTSTR szValue);
  335. protected:
  336. CAryBagProps m_aryBagProps;
  337. LPICMOCCtr m_pCtr;
  338. };
  339. //+---------------------------------------------------------------------------
  340. //
  341. // Class: CICMOCCtr ()
  342. //
  343. // Purpose: This is the one, the big kahuna. CICMOCCtr is the
  344. // ICM OLE Controls container that contains a single
  345. // OLE Control, the FutureSplash OC. It contains
  346. // sub-objects which implement the various interfaces
  347. // we have to support (could have used multiple inheritance,
  348. // but this seemed more straightforward for our needs).
  349. //
  350. // Conventions: Interfaces we implement are contained objects
  351. // of a class trivially derived from the interface,
  352. // e.g., IOleInPlaceFrame is a contained
  353. // instance of CInPlaceFrame called m_IPF.
  354. //
  355. // Interfaces we hold on the Future Splash OC
  356. // are pointers to the actual OLE interface.
  357. // e.g., our pointer to the control's
  358. // IOleControl interface is m_pOC.
  359. //
  360. // The contained sub-objects are all friends
  361. // of the container - they are all conceptually
  362. // the same object, but are implemented
  363. // separately so as to cause the compiler to
  364. // generate the correct vtable.
  365. //
  366. //----------------------------------------------------------------------------
  367. class CICMOCCtr : public IUnknown
  368. {
  369. public:
  370. friend CInPlaceSite;
  371. friend CInPlaceFrame;
  372. friend COleClientSite;
  373. friend CPropertyBag;
  374. // IUnknown stuff
  375. STDMETHOD(QueryInterface)(REFIID riid, LPVOID FAR * ppv);
  376. STDMETHOD_(ULONG, AddRef)(VOID);
  377. STDMETHOD_(ULONG, Release)(VOID);
  378. VOID Paint(HDC hDC, LPRECT lpr);
  379. VOID Paint(VOID);
  380. HRESULT CreateFSOC(Ole32LinkageStruct *pOle32Link);
  381. HRESULT GetSize(LPRECT prc);
  382. HRESULT SetSize(LPRECT prc, BOOL fMoveFrameWindow = TRUE);
  383. HWND GetMainWindow(VOID)
  384. {
  385. MYDBGASSERT(m_hWndMainDlg && ::IsWindow(m_hWndMainDlg));
  386. return m_hWndMainDlg;
  387. }
  388. HWND GetFrameWindow(VOID)
  389. {
  390. MYDBGASSERT(m_hWndFrame && ::IsWindow(m_hWndFrame));
  391. return m_hWndFrame;
  392. }
  393. LRESULT OnActivateApp(WPARAM wParam, LPARAM lParam);
  394. //
  395. // Whenever we display a modal dialog, we need to let
  396. // our embeddings (the WebBrowser OC) know to disable
  397. // any modeless dialogs the embedding is displaying.
  398. //
  399. VOID EnableEmbeddingModelessDlgs(BOOL fEnable)
  400. {
  401. LPOLEINPLACEACTIVEOBJECT pIPAO = GetIPAObject();
  402. if (pIPAO)
  403. pIPAO->EnableModeless(fEnable);
  404. }
  405. VOID DoLayout(INT cxMain, INT cyMain);
  406. CICMOCCtr(const HWND hWndMainDlg, const HWND hWndFrame);
  407. ~CICMOCCtr(VOID);
  408. VOID ShutDown(VOID);
  409. BOOL Initialized(VOID);
  410. OLE_SERVER_STATE GetState(VOID) {return m_state;}
  411. VOID SetState(OLE_SERVER_STATE state) {m_state = state;}
  412. HRESULT EnableModeless(BOOL fEnable);
  413. BOOL ModelessEnabled(VOID){return m_fModelessEnabled;}
  414. LRESULT SetFocus(VOID);
  415. HRESULT AddPropertyToBag(LPTSTR szName, LPTSTR szValue)
  416. {
  417. return m_PB.AddPropertyToBag(szName, szValue);
  418. }
  419. VOID MapStateToFrame(ProgState ps);
  420. HRESULT SetFrame(LONG lFrame);
  421. VOID SetFrameMapping(ProgState ps, LONG lFrame)
  422. {
  423. m_alStateMappings[ps] = lFrame;
  424. }
  425. LPOLEINPLACEACTIVEOBJECT GetIPAObject(VOID) {return m_pActiveObj;}
  426. protected:
  427. HRESULT _SetExtent(LPRECT prc);
  428. HRESULT _DisplayStatusText(LPCOLESTR pStrStatusText);
  429. VOID _ResetToolSpace(VOID)
  430. {
  431. ::memset(&m_rcToolSpace, 0, sizeof m_rcToolSpace);
  432. }
  433. VOID _AdjustForTools(LPRECT prc);
  434. VOID _DeactivateControl(VOID);
  435. HRESULT _TransAccelerator(LPMSG lpmsg, WORD wID);
  436. VOID _GetDoVerbRect(LPRECT prc);
  437. // map states to frames.
  438. LONG m_alStateMappings[NUMSTATES];
  439. BORDERWIDTHS m_rcToolSpace; // for FS OC
  440. COleClientSite m_CS; // clientsite
  441. CAdviseSink m_AS; // advise sink
  442. CInPlaceFrame m_IPF; // inplace frame
  443. CInPlaceSite m_IPS; // inplace site object
  444. COleContainer m_OCtr; // IOleContainer
  445. CDynamicOleAut m_DOA; // Dynamic OLEAUT32
  446. CPropertyBag m_PB; // IPropertyBag - Must never precede CDynamicOleAut
  447. HWND m_hWndMainDlg; // hwnd for ICM dialog
  448. HWND m_hWndFrame; // hWnd that contains OC Site
  449. LPUNKNOWN m_pUnk; // the object itself.
  450. LPVIEWOBJECT m_pVO; // pointer to IViewObject
  451. LPOLEOBJECT m_pOO; // pointer to IOleObject
  452. LPOLEINPLACEOBJECT m_pIPO; // pointer to InPlaceActiveObject
  453. LPDISPATCH m_pDisp; // IDispatch to FS OC
  454. LPOLEINPLACEACTIVEOBJECT m_pActiveObj; // current active object
  455. LPOLECONTROL m_pOC; // IOleControl interface for OC
  456. ULONG m_Ref; // refcount
  457. OLE_SERVER_STATE m_state; // current OLE state of OC
  458. DWORD m_dwMiscStatus;// misc status bits for OC
  459. BOOL m_fModelessEnabled; // OC is putting up modal dlg?
  460. };
  461. extern "C" CLSID const CLSID_FS;
  462. #endif