home *** CD-ROM | disk | FTP | other *** search
/ Supercompiler 1997 / SUPERCOMPILER97.iso / MS_VC.50 / VC / MFC / SRC / OLEIMPL2.H < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-30  |  10.4 KB  |  312 lines

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