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.

310 lines
10 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1996.
  5. //
  6. // File: deflink.h
  7. //
  8. // Contents: Declares the default link object
  9. //
  10. // Classes: CDefLink
  11. //
  12. // Functions:
  13. //
  14. // History: dd-mmm-yy Author Comment
  15. // 01-Feb-95 t-ScottH added Dump method to CDefLink
  16. // added DLFlag to indicate if aggregated
  17. // (in _DEBUG only)
  18. // 21-Nov-94 alexgo memory optimization
  19. // 25-Jan-94 alexgo first pass at converting to Cairo-style
  20. // memory allocations.
  21. // 13-Nov-93 alexgo 32bit port
  22. //
  23. //--------------------------------------------------------------------------
  24. #include "olepres.h"
  25. #include "olecache.h"
  26. #include "dacache.h"
  27. #include <oaholder.h>
  28. typedef enum tagDLFlags
  29. {
  30. DL_SAME_AS_LOAD = 0x0001,
  31. DL_NO_SCRIBBLE_MODE = 0x0002,
  32. DL_DIRTY_LINK = 0x0004,
  33. DL_LOCKED_CONTAINER = 0x0008,
  34. DL_LOCKED_RUNNABLEOBJECT = 0x0010,
  35. DL_LOCKED_OLEITEMCONTAINER = 0x0020,
  36. DL_CLEANEDUP = 0x0040,
  37. #ifdef _DEBUG
  38. DL_AGGREGATED = 0x10000
  39. #endif // _DEBUG
  40. } DLFlags;
  41. //+-------------------------------------------------------------------------
  42. //
  43. // Class: CDefLink
  44. //
  45. // Purpose: The "embedding" for a link; the default object that implements
  46. // a link connection
  47. //
  48. // Interface: IUnknown
  49. // IDataObject
  50. // IOleObject
  51. // IOleLink
  52. // IRunnableObject
  53. // IAdviseSink
  54. // IPersistStorage
  55. //
  56. // History: dd-mmm-yy Author Comment
  57. // 01-Feb-95 t-ScottH add Dump method (_DEBUG only)
  58. // 21-Nov-94 alexgo memory optimization
  59. // 13-Nov-93 alexgo 32bit port
  60. //
  61. // Notes:
  62. //
  63. //--------------------------------------------------------------------------
  64. class FAR CDefLink : public CRefExportCount, public IDataObject,
  65. public IOleObject, public IOleLink, public IRunnableObject,
  66. public IPersistStorage, public CThreadCheck
  67. {
  68. public:
  69. static IUnknown FAR* Create(IUnknown FAR* pUnkOuter);
  70. class CPrivUnknown : public IUnknown
  71. {
  72. public:
  73. STDMETHOD(QueryInterface) ( REFIID riid, LPVOID FAR* ppvObj);
  74. STDMETHOD_(ULONG,AddRef) (void);
  75. STDMETHOD_(ULONG,Release) (void);
  76. };
  77. friend class CPrivUnknown;
  78. CPrivUnknown m_Unknown;
  79. // IUnknown methods
  80. STDMETHOD(QueryInterface) ( REFIID riid, LPVOID FAR* ppvObj);
  81. STDMETHOD_(ULONG,AddRef) (void);
  82. STDMETHOD_(ULONG,Release) (void);
  83. // IDataObject methods
  84. INTERNAL_(IDataObject *) GetDataDelegate(void);
  85. INTERNAL_(void) ReleaseDataDelegate(void);
  86. STDMETHOD(GetData) ( LPFORMATETC pformatetcIn,
  87. LPSTGMEDIUM pmedium );
  88. STDMETHOD(GetDataHere) ( LPFORMATETC pformatetc,
  89. LPSTGMEDIUM pmedium );
  90. STDMETHOD(QueryGetData) ( LPFORMATETC pformatetc );
  91. STDMETHOD(GetCanonicalFormatEtc) ( LPFORMATETC pformatetc,
  92. LPFORMATETC pformatetcOut);
  93. STDMETHOD(SetData) ( LPFORMATETC pformatetc,
  94. LPSTGMEDIUM pmedium,
  95. BOOL fRelease);
  96. STDMETHOD(EnumFormatEtc) ( DWORD dwDirection,
  97. LPENUMFORMATETC *ppenumFormatEtc);
  98. STDMETHOD(DAdvise) ( FORMATETC *pFormatetc, DWORD advf,
  99. IAdviseSink *pAdvSink,
  100. DWORD *pdwConnection);
  101. STDMETHOD(DUnadvise) ( DWORD dwConnection);
  102. STDMETHOD(EnumDAdvise) ( LPENUMSTATDATA *ppenumAdvise);
  103. // IOleObject methods
  104. INTERNAL_(IOleObject FAR*) GetOleDelegate(void);
  105. INTERNAL_(void) ReleaseOleDelegate(void);
  106. // *** IOleObject methods ***
  107. STDMETHOD(SetClientSite)(LPOLECLIENTSITE pClientSite);
  108. STDMETHOD(GetClientSite)(LPOLECLIENTSITE *ppClientSite);
  109. STDMETHOD(SetHostNames)(LPCOLESTR szContainerApp,
  110. LPCOLESTR szContainerObj);
  111. STDMETHOD(Close) ( DWORD reserved);
  112. STDMETHOD(SetMoniker) ( DWORD dwWhichMoniker, LPMONIKER pmk);
  113. STDMETHOD(GetMoniker) ( DWORD dwAssign, DWORD dwWhichMoniker,
  114. LPMONIKER *ppmk);
  115. STDMETHOD(InitFromData) ( LPDATAOBJECT pDataObject,
  116. BOOL fCreation,
  117. DWORD dwReserved);
  118. STDMETHOD(GetClipboardData) ( DWORD dwReserved,
  119. LPDATAOBJECT *ppDataObject);
  120. STDMETHOD(DoVerb) ( LONG iVerb,
  121. LPMSG lpmsg,
  122. LPOLECLIENTSITE pActiveSite,
  123. LONG lindex,
  124. HWND hwndParent,
  125. const RECT *lprcPosRect);
  126. STDMETHOD(EnumVerbs) ( IEnumOLEVERB **ppenumOleVerb);
  127. STDMETHOD(Update) (void);
  128. STDMETHOD(IsUpToDate) (void);
  129. STDMETHOD(GetUserClassID) ( CLSID *pClsid);
  130. STDMETHOD(GetUserType) ( DWORD dwFormOfType,
  131. LPOLESTR *pszUserType);
  132. STDMETHOD(SetExtent) ( DWORD dwDrawAspect, LPSIZEL lpsizel);
  133. STDMETHOD(GetExtent) ( DWORD dwDrawAspect, LPSIZEL lpsizel);
  134. STDMETHOD(Advise)(IAdviseSink FAR* pAdvSink,
  135. DWORD *pdwConnection);
  136. STDMETHOD(Unadvise)( DWORD dwConnection);
  137. STDMETHOD(EnumAdvise) ( LPENUMSTATDATA *ppenumAdvise);
  138. STDMETHOD(GetMiscStatus) ( DWORD dwAspect,
  139. DWORD *pdwStatus);
  140. STDMETHOD(SetColorScheme) ( LPLOGPALETTE lpLogpal);
  141. // IOleLink methods
  142. STDMETHOD(SetUpdateOptions) ( DWORD dwUpdateOpt);
  143. STDMETHOD(GetUpdateOptions) ( LPDWORD pdwUpdateOpt);
  144. STDMETHOD(SetSourceMoniker) ( LPMONIKER pmk, REFCLSID rclsid);
  145. STDMETHOD(GetSourceMoniker) ( LPMONIKER *ppmk);
  146. STDMETHOD(SetSourceDisplayName) ( LPCOLESTR lpszStatusText);
  147. STDMETHOD(GetSourceDisplayName) (
  148. LPOLESTR *lplpszDisplayName);
  149. STDMETHOD(BindToSource) ( DWORD bindflags, LPBINDCTX pbc);
  150. STDMETHOD(BindIfRunning) (void);
  151. STDMETHOD(GetBoundSource) ( LPUNKNOWN *pUnk);
  152. STDMETHOD(UnbindSource) (void);
  153. STDMETHOD(Update) ( LPBINDCTX pbc);
  154. // IRunnableObject methods
  155. INTERNAL_(IRunnableObject FAR*) GetRODelegate(void);
  156. INTERNAL_(void) ReleaseRODelegate(void);
  157. STDMETHOD(GetRunningClass) (LPCLSID lpClsid);
  158. STDMETHOD(Run) (LPBINDCTX pbc);
  159. STDMETHOD_(BOOL,IsRunning) (void);
  160. STDMETHOD(LockRunning)(BOOL fLock, BOOL fLastUnlockCloses);
  161. STDMETHOD(SetContainedObject)(BOOL fContained);
  162. // IPersistStorage methods
  163. STDMETHOD(GetClassID) ( LPCLSID pClassID);
  164. STDMETHOD(IsDirty) (void);
  165. STDMETHOD(InitNew) ( LPSTORAGE pstg);
  166. STDMETHOD(Load) ( LPSTORAGE pstg);
  167. STDMETHOD(Save) ( LPSTORAGE pstgSave, BOOL fSameAsLoad);
  168. STDMETHOD(SaveCompleted) ( LPSTORAGE pstgNew);
  169. STDMETHOD(HandsOffStorage) ( void);
  170. // will really check to see if the server is still
  171. // running and do appropriate cleanups if we have
  172. // crashed
  173. STDMETHOD_(BOOL, IsReallyRunning)(void);
  174. // NOTE: the advise sink has a separate controlling unknown from the
  175. // other interfaces; the lifetime of the memory for this implementation
  176. // is still the same as the default handler. The ramifications of
  177. // this are that when the default handler goes away it must make sure
  178. // that all pointers back to the sink are released; see the special
  179. // code in the dtor of the default handler.
  180. class CAdvSinkImpl : public IAdviseSink
  181. {
  182. public:
  183. STDMETHOD(QueryInterface) ( REFIID iid, LPVOID *ppvObj);
  184. STDMETHOD_(ULONG,AddRef) (void);
  185. STDMETHOD_(ULONG,Release) (void);
  186. // *** IAdviseSink methods ***
  187. STDMETHOD_(void,OnDataChange)( FORMATETC *pFormatetc,
  188. STGMEDIUM *pStgmed);
  189. STDMETHOD_(void,OnViewChange)( DWORD aspects, LONG lindex);
  190. STDMETHOD_(void,OnRename)( IMoniker *pmk);
  191. STDMETHOD_(void,OnSave)(void);
  192. STDMETHOD_(void,OnClose)(void);
  193. };
  194. friend class CAdvSinkImpl;
  195. CAdvSinkImpl m_AdviseSink;
  196. #ifdef _DEBUG
  197. HRESULT Dump(char **ppszDump, ULONG ulFlag, int nIndentLevel);
  198. // need to be able to access CDefLink private data members in the
  199. // following debugger extension APIs
  200. // this allows the debugger extension APIs to copy memory from the
  201. // debuggee process memory to the debugger's process memory
  202. // this is required since the Dump method follows pointers to other
  203. // structures and classes
  204. friend DEBUG_EXTENSION_API(dump_deflink);
  205. #endif // _DEBUG
  206. private:
  207. CDefLink( IUnknown *pUnkOuter);
  208. virtual void CleanupFn(void);
  209. ~CDefLink (void);
  210. INTERNAL_(void) UpdateUserClassID();
  211. INTERNAL_(void) BeginUpdates(void);
  212. INTERNAL_(void) EndUpdates(void);
  213. INTERNAL_(void) UpdateAutoOnSave(void);
  214. INTERNAL_(void) UpdateRelMkFromAbsMk(IMoniker *pmkContainer);
  215. INTERNAL UpdateMksFromAbs(IMoniker *pmkContainer, IMoniker *pmkAbs);
  216. INTERNAL GetAbsMkFromRel(LPMONIKER *ppmkAbs, IMoniker **ppmkContainer );
  217. INTERNAL SetUpdateTimes( void );
  218. #ifdef _TRACKLINK_
  219. INTERNAL EnableTracking( IMoniker * pmk, ULONG ulFlags );
  220. #endif
  221. INTERNAL_(IOleItemContainer FAR*) GetOleItemContainerDelegate(void);
  222. INTERNAL_(void) ReleaseOleItemContainerDelegate(void);
  223. INTERNAL_(void) CheckDelete(void);
  224. DWORD m_flags; // DLFlags enumeration
  225. DWORD m_dwObjFlags; // OBJFLAGS of the OLESTREAM
  226. IDataObject * m_pDataDelegate;
  227. IOleObject * m_pOleDelegate;
  228. IRunnableObject * m_pRODelegate;
  229. IOleItemContainer * m_pOleItemContainerDelegate;
  230. // Member variables for caching MiscStatus bits
  231. HRESULT m_ContentSRVMSHResult;
  232. DWORD m_ContentSRVMSBits;
  233. HRESULT m_ContentREGMSHResult;
  234. DWORD m_ContentREGMSBits;
  235. ULONG m_cRefsOnLink;
  236. IUnknown * m_pUnkOuter;
  237. IMoniker * m_pMonikerAbs; // THE absolute moniker
  238. // of the link source
  239. IMoniker * m_pMonikerRel; // THE relative moniker
  240. // of the link source
  241. IUnknown * m_pUnkDelegate; // from mk bind; non-null
  242. // if running
  243. DWORD m_dwUpdateOpt;
  244. CLSID m_clsid; // last known clsid of
  245. // link source;
  246. // NOTE: may be NULL
  247. IStorage * m_pStg;
  248. // data cache
  249. COleCache * m_pCOleCache; // cache (always non-NULL)
  250. // ole advise info
  251. COAHolder * m_pCOAHolder; // OleAdviseHolder
  252. DWORD m_dwConnOle; // if running, ole advise conn.
  253. LPDATAADVCACHE m_pDataAdvCache;// data advise cache
  254. IOleClientSite * m_pAppClientSite;// not passed to server!
  255. DWORD m_dwConnTime; // dwConnection for time
  256. // changes
  257. FILETIME m_ltChangeOfUpdate;
  258. FILETIME m_ltKnownUpToDate;
  259. FILETIME m_rtUpdate;
  260. };