oleimpl2.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992-1998 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Foundation Classes Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Microsoft Foundation Classes product.
  10. // Note: Must include AFXOLE.H first
  11. #undef AFX_DATA
  12. #define AFX_DATA AFX_OLE_DATA
  13. /////////////////////////////////////////////////////////////////////////////
  14. // COleFrameHook - AFX_INTERNAL
  15. class COleFrameHook : public CCmdTarget
  16. {
  17. // Construction & Destruction
  18. public:
  19. COleFrameHook(CFrameWnd* pFrameWnd, COleClientItem* pItem);
  20. // Implementation
  21. public:
  22. ~COleFrameHook();
  23. CFrameWnd* m_pFrameWnd;
  24. LPOLEINPLACEACTIVEOBJECT m_lpActiveObject;
  25. COleClientItem* m_pActiveItem; // item this COleFrameHook is for
  26. HWND m_hWnd; // actual HWND this hook is attached to
  27. BOOL m_bInModalState; // TRUE if EnableModeless(FALSE) has been called
  28. BOOL m_bToolBarHidden; // TRUE if toolbar needs to be shown OnUIDeactivate
  29. HACCEL m_hAccelTable; // accelerator to be used while in-place object active
  30. UINT m_nModelessCount; // !0 if server's EnableModeless has been called
  31. CString m_strObjName; // name of the active in-place object
  32. // Overrides for implementation
  33. public:
  34. virtual void OnRecalcLayout(); // for border space re-negotiation
  35. virtual BOOL OnPreTranslateMessage(MSG* pMsg);
  36. virtual void OnActivate(BOOL bActive); // for OnFrameWindowActivate
  37. virtual BOOL OnDocActivate(BOOL bActive); // for OnDocWindowActivate
  38. virtual BOOL OnContextHelp(BOOL bEnter);
  39. virtual void OnEnableModeless(BOOL bEnable);
  40. virtual BOOL OnUpdateFrameTitle();
  41. virtual void OnPaletteChanged(CWnd* pFocusWnd);
  42. virtual BOOL OnQueryNewPalette();
  43. virtual BOOL OnInitMenuPopup(CMenu* pMenu, int nIndex, BOOL bSysMenu);
  44. virtual void OnInitMenu(CMenu* pMenu);
  45. virtual BOOL OnMenuSelect(UINT nItemID, UINT nFlags, HMENU hSysMenu);
  46. // implementation helpers
  47. BOOL NotifyAllInPlace(
  48. BOOL bParam, BOOL (COleFrameHook::*pNotifyFunc)(BOOL bParam));
  49. BOOL DoContextSensitiveHelp(BOOL bEnter);
  50. BOOL DoEnableModeless(BOOL bEnable);
  51. // Interface Maps
  52. public:
  53. #ifdef _AFXDLL
  54. virtual LPUNKNOWN GetInterfaceHook(const void*);
  55. #endif
  56. BEGIN_INTERFACE_PART(OleInPlaceFrame, IOleInPlaceFrame)
  57. INIT_INTERFACE_PART(COleFrameHook, OleInPlaceFrame)
  58. STDMETHOD(GetWindow)(HWND*);
  59. STDMETHOD(ContextSensitiveHelp)(BOOL);
  60. STDMETHOD(GetBorder)(LPRECT);
  61. STDMETHOD(RequestBorderSpace)(LPCBORDERWIDTHS);
  62. STDMETHOD(SetBorderSpace)(LPCBORDERWIDTHS);
  63. STDMETHOD(SetActiveObject)(LPOLEINPLACEACTIVEOBJECT, LPCOLESTR);
  64. STDMETHOD(InsertMenus)(HMENU, LPOLEMENUGROUPWIDTHS);
  65. STDMETHOD(SetMenu)(HMENU, HOLEMENU, HWND);
  66. STDMETHOD(RemoveMenus)(HMENU);
  67. STDMETHOD(SetStatusText)(LPCOLESTR);
  68. STDMETHOD(EnableModeless)(BOOL);
  69. STDMETHOD(TranslateAccelerator)(LPMSG, WORD);
  70. END_INTERFACE_PART(OleInPlaceFrame)
  71. //WINBUG: this interface is here because some applications
  72. // are broken and require IOleCommandTarget to be
  73. // implemented before they'll properly activate
  74. BEGIN_INTERFACE_PART(OleCommandTarget, IOleCommandTarget)
  75. INIT_INTERFACE_PART(COleFrameHook, OleCommandTarget)
  76. STDMETHOD(Exec)(const GUID*, DWORD, DWORD,
  77. VARIANTARG*, VARIANTARG*);
  78. STDMETHOD(QueryStatus)(const GUID*, ULONG, OLECMD[], OLECMDTEXT*);
  79. END_INTERFACE_PART(OleCommandTarget)
  80. DECLARE_INTERFACE_MAP()
  81. friend COleClientItem;
  82. };
  83. /////////////////////////////////////////////////////////////////////////////
  84. // Helper for implementing OLE enumerators
  85. // Note: the following interface is not an actual OLE interface, but is useful
  86. // for describing an abstract (not typesafe) enumerator.
  87. #undef INTERFACE
  88. #define INTERFACE IEnumVOID
  89. DECLARE_INTERFACE_(IEnumVOID, IUnknown)
  90. {
  91. STDMETHOD(QueryInterface)(REFIID, LPVOID*) PURE;
  92. STDMETHOD_(ULONG,AddRef)() PURE;
  93. STDMETHOD_(ULONG,Release)() PURE;
  94. STDMETHOD(Next)(ULONG, void*, ULONG*) PURE;
  95. STDMETHOD(Skip)(ULONG) PURE;
  96. STDMETHOD(Reset)() PURE;
  97. STDMETHOD(Clone)(IEnumVOID**) PURE;
  98. };
  99. class CEnumArray : public CCmdTarget
  100. {
  101. // Constructors
  102. public:
  103. CEnumArray(size_t nSize,
  104. const void* pvEnum, UINT nCount, BOOL bNeedFree = FALSE);
  105. // Implementation
  106. public:
  107. virtual ~CEnumArray();
  108. protected:
  109. size_t m_nSizeElem; // size of each item in the array
  110. CCmdTarget* m_pClonedFrom; // used to keep original alive for clones
  111. BYTE* m_pvEnum; // pointer data to enumerate
  112. UINT m_nCurPos; // current position in m_pvEnum
  113. UINT m_nSize; // total number of items in m_pvEnum
  114. BOOL m_bNeedFree; // free on release?
  115. virtual BOOL OnNext(void* pv);
  116. virtual BOOL OnSkip();
  117. virtual void OnReset();
  118. virtual CEnumArray* OnClone();
  119. // Interface Maps
  120. public:
  121. BEGIN_INTERFACE_PART(EnumVOID, IEnumVOID)
  122. INIT_INTERFACE_PART(CEnumArray, EnumVOID)
  123. STDMETHOD(Next)(ULONG, void*, ULONG*);
  124. STDMETHOD(Skip)(ULONG);
  125. STDMETHOD(Reset)();
  126. STDMETHOD(Clone)(IEnumVOID**);
  127. END_INTERFACE_PART(EnumVOID)
  128. };
  129. /////////////////////////////////////////////////////////////////////////////
  130. // COleDispatchImpl - IDispatch implementation
  131. // Note: This class is only designed to be used as a CCmdTarget member
  132. // (at the offset specified by CCmdTarget::m_xDispatch))
  133. // It WILL NOT work in other classes or at different offsets!
  134. class COleDispatchImpl : public IDispatch
  135. {
  136. public:
  137. #ifndef _AFX_NO_NESTED_DERIVATION
  138. // required for METHOD_PROLOGUE_EX
  139. size_t m_nOffset;
  140. COleDispatchImpl::COleDispatchImpl()
  141. { m_nOffset = offsetof(CCmdTarget, m_xDispatch); }
  142. #endif
  143. STDMETHOD_(ULONG, AddRef)();
  144. STDMETHOD_(ULONG, Release)();
  145. STDMETHOD(QueryInterface)(REFIID, LPVOID*);
  146. STDMETHOD(GetTypeInfoCount)(UINT*);
  147. STDMETHOD(GetTypeInfo)(UINT, LCID, LPTYPEINFO*);
  148. STDMETHOD(GetIDsOfNames)(REFIID, LPOLESTR*, UINT, LCID, DISPID*);
  149. STDMETHOD(Invoke)(DISPID, REFIID, LCID, WORD, DISPPARAMS*, LPVARIANT,
  150. LPEXCEPINFO, UINT*);
  151. // special method for disconnect
  152. virtual void Disconnect();
  153. };
  154. /////////////////////////////////////////////////////////////////////////////
  155. // OLE data (like AUX_DATA)
  156. struct OLE_DATA
  157. {
  158. // OLE 1.0 clipboard formats
  159. UINT cfNative, cfOwnerLink, cfObjectLink;
  160. // OLE 2.0 clipboard formats
  161. UINT cfEmbeddedObject, cfEmbedSource, cfLinkSource;
  162. UINT cfObjectDescriptor, cfLinkSourceDescriptor;
  163. UINT cfFileName, cfFileNameW;
  164. //RichEdit formats
  165. UINT cfRichTextFormat;
  166. UINT cfRichTextAndObjects;
  167. OLE_DATA();
  168. };
  169. extern OLE_DATA _oleData;
  170. /////////////////////////////////////////////////////////////////////////////
  171. // _AFX_OLE_STATE
  172. #undef AFX_DATA
  173. #define AFX_DATA
  174. class _AFX_OLE_STATE : public CNoTrackObject
  175. {
  176. public:
  177. _AFX_OLE_STATE();
  178. virtual ~_AFX_OLE_STATE();
  179. CView* m_pActivateView; // activation view
  180. COleDataSource* m_pClipboardSource;
  181. DWORD m_dwReserved; // was "parking space" window
  182. #ifdef _AFXDLL
  183. HINSTANCE m_hInstOLE; // handle of OLE32.DLL
  184. HINSTANCE m_hInstOLEAUT; // handle of OLEAUT32.DLL
  185. HINSTANCE m_hInstOLEDLG; // handle of OLEDLG.DLL
  186. HINSTANCE m_hInstUrlMon;
  187. #endif
  188. long m_nReserved; // was reference count on parking window
  189. };
  190. EXTERN_PROCESS_LOCAL(_AFX_OLE_STATE, _afxOleState)
  191. /////////////////////////////////////////////////////////////////////////////
  192. // Global helper functions
  193. // menu merging/unmerging
  194. HMENU AFXAPI AfxMergeMenus(HMENU hMenuShared, HMENU hMenuSource,
  195. LONG* lpMenuWidths, int iWidthIndex, BOOL bMergeHelpMenus = FALSE);
  196. void AFXAPI AfxUnmergeMenus(HMENU hMenuShared, HMENU hMenuSource,
  197. HMENU hHelpMenuPopup = NULL);
  198. // helpers for IOleCommandTarget
  199. HRESULT AFXAPI _AfxQueryStatusOleCommandHelper(CCmdTarget* pTarget,
  200. const GUID* pguidCmdGroup, ULONG cCmds, OLECMD rgCmds[],
  201. OLECMDTEXT* pcmdtext);
  202. HRESULT AFXAPI _AfxExecOleCommandHelper(CCmdTarget* pTarget,
  203. const GUID* pguidCmdGroup, DWORD nCmdID, DWORD nCmdExecOpt,
  204. VARIANTARG* pvarargIn, VARIANTARG* pvarargOut);
  205. // helpers for exceptions
  206. void AFXAPI _AfxFillOleFileException(CFileException*, SCODE sc);
  207. void AFXAPI _AfxThrowOleFileException(SCODE sc);
  208. // helper used during object creation
  209. LPFORMATETC AFXAPI _AfxFillFormatEtc(LPFORMATETC lpFormatEtc,
  210. CLIPFORMAT cfFormat, LPFORMATETC lpFormatEtcFill);
  211. // helper to copy clipboard data
  212. BOOL AFXAPI _AfxCopyStgMedium(
  213. CLIPFORMAT cfFormat, LPSTGMEDIUM lpDest, LPSTGMEDIUM lpSource);
  214. // helper for reliable and small Release calls
  215. DWORD AFXAPI _AfxRelease(LPUNKNOWN* plpUnknown);
  216. #ifndef MFC_DEBUG
  217. // generate smaller code in release build
  218. #define RELEASE(lpUnk) _AfxRelease((LPUNKNOWN*)&lpUnk)
  219. #else
  220. // generate larger but typesafe code in debug build
  221. #define RELEASE(lpUnk) do \
  222. { if ((lpUnk) != NULL) { (lpUnk)->Release(); (lpUnk) = NULL; } } while (0)
  223. #endif
  224. // helpers from OLESTD.C (from original OLE2UI sample)
  225. HGLOBAL AFXAPI _AfxOleGetObjectDescriptorData(CLSID clsid, DWORD dwDrawAspect,
  226. SIZEL sizel, POINTL pointl, DWORD dwStatus, LPCOLESTR lpszFullUserTypeName,
  227. LPCOLESTR lpszSrcOfCopy);
  228. HGLOBAL AFXAPI _AfxOleGetObjectDescriptorData(LPOLEOBJECT lpOleObj,
  229. LPCOLESTR lpszSrcOfCopy, DWORD dwDrawAspect, POINTL pointl, LPSIZEL lpSizelHim);
  230. SCODE AFXAPI _AfxOleDoConvert(LPSTORAGE lpStg, REFCLSID rClsidNew);
  231. SCODE AFXAPI _AfxOleDoTreatAsClass(
  232. LPCTSTR lpszUserType, REFCLSID rclsid, REFCLSID rclsidNew);
  233. DVTARGETDEVICE* AFXAPI _AfxOleCreateTargetDevice(LPPRINTDLG lpPrintDlg);
  234. DVTARGETDEVICE* AFXAPI _AfxOleCreateTargetDevice(LPDEVNAMES pDN, LPDEVMODE pDM);
  235. UINT AFXAPI _AfxOleGetUserTypeOfClass(
  236. REFCLSID rclsid, LPTSTR lpszUserType, UINT cch, HKEY hKey);
  237. DWORD AFXAPI _AfxOleGetLenFilePrefixOfMoniker(LPMONIKER lpmk);
  238. DVTARGETDEVICE* AFXAPI _AfxOleCopyTargetDevice(DVTARGETDEVICE* ptdSrc);
  239. void AFXAPI _AfxOleCopyFormatEtc(LPFORMATETC petcDest, LPFORMATETC petcSrc);
  240. HDC AFXAPI _AfxOleCreateDC(DVTARGETDEVICE* ptd);
  241. void AFXAPI _AfxDeleteMetafilePict(HGLOBAL hMetaPict);
  242. BOOL AFXAPI _AfxOlePropertiesEnabled();
  243. // helper(s) for reliable and small QueryInterface calls
  244. LPUNKNOWN AFXAPI _AfxQueryInterface(LPUNKNOWN lpUnknown, REFIID riid);
  245. #define QUERYINTERFACE(lpUnknown, iface) \
  246. (iface*)_AfxQueryInterface(lpUnknown, IID_##iface)
  247. // helpers for conversion between himetric and pixels
  248. #define HIMETRIC_PER_INCH 2540
  249. #define MAP_PIX_TO_LOGHIM(x,ppli) MulDiv(HIMETRIC_PER_INCH, (x), (ppli))
  250. #define MAP_LOGHIM_TO_PIX(x,ppli) MulDiv((ppli), (x), HIMETRIC_PER_INCH)
  251. // helper for GUID comparison
  252. inline BOOL _AfxIsEqualGUID(REFGUID guid1, REFGUID guid2)
  253. {
  254. return ((DWORD*)&guid1)[0] == ((DWORD*)&guid2)[0] &&
  255. ((DWORD*)&guid1)[1] == ((DWORD*)&guid2)[1] &&
  256. ((DWORD*)&guid1)[2] == ((DWORD*)&guid2)[2] &&
  257. ((DWORD*)&guid1)[3] == ((DWORD*)&guid2)[3];
  258. }
  259. HRESULT AFXAPI _AfxReadFromStream(LPSTREAM pStream, void* lpBuf, UINT nCount, DWORD& nRead);
  260. /////////////////////////////////////////////////////////////////////////////
  261. // implementation types and constants
  262. #define OLE_MAXITEMNAME (_countof("Embedding ")+_countof("4294967295")-_countof(""))
  263. typedef LPVOID* LPLP;
  264. #undef AFX_DATA
  265. #define AFX_DATA
  266. /////////////////////////////////////////////////////////////////////////////