home *** CD-ROM | disk | FTP | other *** search
/ Troubleshooting Netware Systems / CSTRIAL0196.BIN / attach / msj / v10n08 / oleq0895.exe / OLEIMPL.H < prev    next >
C/C++ Source or Header  |  1995-08-01  |  9KB  |  262 lines

  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992 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 Microsoft
  7. // QuickHelp and/or WinHelp 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.  
  49.     // implementation helpers
  50.     BOOL NotifyAllInPlace(
  51.         BOOL bParam, BOOL (COleFrameHook::*pNotifyFunc)(BOOL bParam));
  52.     BOOL DoContextSensitiveHelp(BOOL bEnter);
  53.     BOOL DoEnableModeless(BOOL bEnable);
  54.  
  55. // Interface Maps
  56. public:
  57.     BEGIN_INTERFACE_PART(OleInPlaceUIWindow, IOleInPlaceUIWindow)
  58.         INIT_INTERFACE_PART(COleFrameHook, OleInPlaceUIWindow)
  59.         STDMETHOD(GetWindow)(HWND*);
  60.         STDMETHOD(ContextSensitiveHelp)(BOOL);
  61.         STDMETHOD(GetBorder)(LPRECT);
  62.         STDMETHOD(RequestBorderSpace)(LPCBORDERWIDTHS);
  63.         STDMETHOD(SetBorderSpace)(LPCBORDERWIDTHS);
  64.         STDMETHOD(SetActiveObject)(LPOLEINPLACEACTIVEOBJECT, LPCTSTR);
  65.     END_INTERFACE_PART(OleInPlaceUIWindow)
  66.  
  67. #ifndef _AFX_NO_NESTED_DERIVATION
  68.     BEGIN_INTERFACE_PART_DERIVE(OleInPlaceFrame, XOleInPlaceUIWindow)
  69.         INIT_INTERFACE_PART_DERIVE(COleFrameHook, OleInPlaceFrame)
  70. #else
  71.     BEGIN_INTERFACE_PART(OleInPlaceFrame, IOleInPlaceFrame)
  72.         STDMETHOD(GetWindow)(HWND*);
  73.         STDMETHOD(ContextSensitiveHelp)(BOOL);
  74.         STDMETHOD(GetBorder)(LPRECT);
  75.         STDMETHOD(RequestBorderSpace)(LPCBORDERWIDTHS);
  76.         STDMETHOD(SetBorderSpace)(LPCBORDERWIDTHS);
  77.         STDMETHOD(SetActiveObject)(LPOLEINPLACEACTIVEOBJECT, LPCTSTR);
  78. #endif
  79.         STDMETHOD(InsertMenus)(HMENU, LPOLEMENUGROUPWIDTHS);
  80.         STDMETHOD(SetMenu)(HMENU, HOLEMENU, HWND);
  81.         STDMETHOD(RemoveMenus)(HMENU);
  82.         STDMETHOD(SetStatusText)(LPCTSTR);
  83.         STDMETHOD(EnableModeless)(BOOL);
  84.         STDMETHOD(TranslateAccelerator)(LPMSG, WORD);
  85.     END_INTERFACE_PART(OleInPlaceFrame)
  86.  
  87.     DECLARE_INTERFACE_MAP()
  88.  
  89.     friend COleClientItem;
  90. };
  91.  
  92. /////////////////////////////////////////////////////////////////////////////
  93. // Helper for implementing OLE enumerators
  94.  
  95. // Note: the following interface is not an actual OLE interface, but is useful
  96. //  for describing an abstract (not typesafe) enumerator.
  97.  
  98. #undef  INTERFACE
  99. #define INTERFACE   IEnumVOID
  100.  
  101. DECLARE_INTERFACE_(IEnumVOID, IUnknown)
  102. {
  103.     STDMETHOD(QueryInterface)(REFIID, LPVOID*) PURE;
  104.     STDMETHOD_(ULONG,AddRef)()  PURE;
  105.     STDMETHOD_(ULONG,Release)() PURE;
  106.     STDMETHOD(Next)(ULONG, void*, ULONG*) PURE;
  107.     STDMETHOD(Skip)(ULONG) PURE;
  108.     STDMETHOD(Reset)() PURE;
  109.     STDMETHOD(Clone)(IEnumVOID**) PURE;
  110. };
  111.  
  112. class CEnumArray : public CCmdTarget
  113. {
  114. // Constructors
  115. public:
  116.     CEnumArray(size_t nSize,
  117.         const void* pvEnum, UINT nCount, BOOL bNeedFree = FALSE);
  118.  
  119. // Implementation
  120. public:
  121.     virtual ~CEnumArray();
  122.  
  123. protected:
  124.     size_t m_nSizeElem;     // size of each item in the array
  125.     CCmdTarget* m_pClonedFrom;  // used to keep original alive for clones
  126.  
  127.     BYTE* m_pvEnum;     // pointer data to enumerate
  128.     UINT m_nCurPos;     // current position in m_pvEnum
  129.     UINT m_nSize;       // total number of items in m_pvEnum
  130.     BOOL m_bNeedFree;   // free on release?
  131.  
  132. #ifdef _AFXCTL
  133.     AFX_MODULE_STATE* m_pModuleState;
  134. #endif
  135.  
  136.     virtual BOOL OnNext(void* pv);
  137.     virtual BOOL OnSkip();
  138.     virtual void OnReset();
  139.     virtual CEnumArray* OnClone();
  140.  
  141. // Interface Maps
  142. public:
  143.     BEGIN_INTERFACE_PART(EnumVOID, IEnumVOID)
  144.         INIT_INTERFACE_PART(CEnumArray, EnumVOID)
  145.         STDMETHOD(Next)(ULONG, void*, ULONG*);
  146.         STDMETHOD(Skip)(ULONG);
  147.         STDMETHOD(Reset)();
  148.         STDMETHOD(Clone)(IEnumVOID**);
  149.     END_INTERFACE_PART(EnumVOID)
  150. };
  151.  
  152. /////////////////////////////////////////////////////////////////////////////
  153. // COleDispatchImpl - IDispatch implementation
  154.  
  155. // Note: This class is only designed to be used as a CCmdTarget member
  156. //  (at the offset specified by CCmdTarget::m_xDispatch))
  157. // It WILL NOT work in other classes or at different offsets!
  158.  
  159. class COleDispatchImpl : public IDispatch
  160. {
  161. public:
  162.     // required for METHOD_PROLOGUE_EX
  163.     size_t m_nOffset;
  164.     COleDispatchImpl::COleDispatchImpl()
  165.         { m_nOffset = offsetof(CCmdTarget, m_xDispatch); }
  166.  
  167.     STDMETHOD_(ULONG, AddRef)();
  168.     STDMETHOD_(ULONG, Release)();
  169.     STDMETHOD(QueryInterface)(REFIID, LPVOID*);
  170.  
  171.     STDMETHOD(GetTypeInfoCount)(UINT*);
  172.     STDMETHOD(GetTypeInfo)(UINT, LCID, LPTYPEINFO*);
  173.     STDMETHOD(GetIDsOfNames)(REFIID, LPTSTR*, UINT, LCID, DISPID*);
  174.     STDMETHOD(Invoke)(DISPID, REFIID, LCID, WORD, DISPPARAMS*, LPVARIANT,
  175.         LPEXCEPINFO, UINT*);
  176.  
  177.     // special method for disconnect
  178.     virtual void Disconnect();
  179. };
  180.  
  181. /////////////////////////////////////////////////////////////////////////////
  182. // OLE 2.0 data (like AUX_DATA)
  183.  
  184. struct OLE_DATA
  185. {
  186.     // OLE 1.0 clipboard formats
  187.     UINT    cfNative, cfOwnerLink, cfObjectLink;
  188.  
  189.     // OLE 2.0 clipboard formats
  190.     UINT    cfEmbeddedObject, cfEmbedSource, cfLinkSource;
  191.     UINT    cfObjectDescriptor, cfLinkSourceDescriptor;
  192.     UINT    cfFileName, cfFileNameW;
  193.  
  194.     OLE_DATA();
  195. };
  196.  
  197. extern OLE_DATA _oleData;
  198.  
  199. /////////////////////////////////////////////////////////////////////////////
  200. // Global helper functions
  201.  
  202. // menu merging/unmerging
  203. void AFXAPI AfxMergeMenus(CMenu* pMenuShared, CMenu* pMenuSource,
  204.     LONG* lpMenuWidths, int iWidthIndex);
  205. void AFXAPI AfxUnmergeMenus(CMenu* pMenuShared, CMenu* pMenuSource);
  206.  
  207. // helpers for exceptions
  208. void AFXAPI _AfxFillOleFileException(CFileException*, SCODE sc);
  209. void AFXAPI _AfxThrowOleFileException(SCODE sc);
  210.  
  211. // helper used during object creation
  212. LPFORMATETC AFXAPI _AfxFillFormatEtc(LPFORMATETC lpFormatEtc,
  213.     CLIPFORMAT cfFormat, LPFORMATETC lpFormatEtcFill);
  214.  
  215. // helper to copy clipboard data
  216. BOOL AFXAPI _AfxCopyStgMedium(
  217.     CLIPFORMAT cfFormat, LPSTGMEDIUM lpDest, LPSTGMEDIUM lpSource);
  218.  
  219. // helper for reliable and small Release calls
  220. DWORD AFXAPI _AfxRelease(LPUNKNOWN* plpUnknown);
  221. #define RELEASE(lpUnk) _AfxRelease((LPUNKNOWN*)&lpUnk)
  222.  
  223. // helpers from OLESTD.C (from original OLE2UI sample)
  224. HGLOBAL AFXAPI _AfxOleGetObjectDescriptorData(CLSID clsid, DWORD dwDrawAspect,
  225.     SIZEL sizel, POINTL pointl, DWORD dwStatus, LPCTSTR lpszFullUserTypeName,
  226.     LPCTSTR lpszSrcOfCopy);
  227. HGLOBAL AFXAPI _AfxOleGetObjectDescriptorData(LPOLEOBJECT lpOleObj,
  228.     LPCTSTR lpszSrcOfCopy, DWORD dwDrawAspect, POINTL pointl, LPSIZEL lpSizelHim);
  229. SCODE AFXAPI _AfxOleDoConvert(LPSTORAGE lpStg, REFCLSID rClsidNew);
  230. SCODE AFXAPI _AfxOleDoTreatAsClass(
  231.     LPCTSTR lpszUserType, REFCLSID rclsid, REFCLSID rclsidNew);
  232. DVTARGETDEVICE* AFXAPI _AfxOleCreateTargetDevice(LPPRINTDLG lpPrintDlg);
  233. UINT AFXAPI _AfxOleGetUserTypeOfClass(
  234.     REFCLSID rclsid, LPTSTR lpszUserType, UINT cch, HKEY hKey);
  235. DWORD AFXAPI _AfxOleGetLenFilePrefixOfMoniker(LPMONIKER lpmk);
  236. DVTARGETDEVICE* AFXAPI _AfxOleCopyTargetDevice(DVTARGETDEVICE* ptdSrc);
  237. void AFXAPI _AfxOleCopyFormatEtc(LPFORMATETC petcDest, LPFORMATETC petcSrc);
  238. HDC AFXAPI _AfxOleCreateDC(DVTARGETDEVICE* ptd);
  239. void AFXAPI _AfxDeleteMetafilePict(HGLOBAL hMetaPict);
  240. BOOL AFXAPI _AfxOlePropertiesEnabled();
  241.  
  242. // helper(s) for reliable and small QueryInterface calls
  243. LPUNKNOWN AFXAPI _AfxQueryInterface(LPUNKNOWN lpUnknown, REFIID riid);
  244. #define QUERYINTERFACE(lpUnknown, iface) \
  245.     (iface*)_AfxQueryInterface(lpUnknown, IID_##iface)
  246.  
  247. // WRAPINTERFACE is used in situations where ANSI -> UNICODE is involved
  248. //  (with OLE2ANSI this is handled the same as UNICODE)
  249. #define WRAPINTERFACE QUERYINTERFACE
  250.  
  251. /////////////////////////////////////////////////////////////////////////////
  252. // implementation types and constants
  253.  
  254. #define OLE_MAXITEMNAME (_countof("Embedding ")+_countof("4294967295")-_countof(""))
  255.  
  256. typedef LPVOID* LPLP;
  257.  
  258. #undef AFX_DATA
  259. #define AFX_DATA
  260.  
  261. /////////////////////////////////////////////////////////////////////////////
  262.