Leaked source code of windows server 2003
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.

1975 lines
67 KiB

  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. #ifndef __AFXOLE_H__
  11. #define __AFXOLE_H__
  12. #ifdef _AFX_NO_OLE_SUPPORT
  13. #error OLE classes not supported in this library variant.
  14. #endif
  15. #ifndef __AFXEXT_H__
  16. #include <afxext.h>
  17. #endif
  18. #ifndef __AFXDISP_H__
  19. #include <afxdisp.h>
  20. #endif
  21. // include OLE Compound Document headers
  22. #ifndef _OLE2_H_
  23. #include <ole2.h>
  24. #endif
  25. // ActiveX Document support
  26. #ifndef __docobj_h__
  27. #include <docobj.h>
  28. #endif
  29. // URL Monikers support
  30. #ifndef __urlmon_h__
  31. #include <urlmon.h>
  32. #endif
  33. #ifndef __AFXCOM_H__
  34. #include <afxcom_.h>
  35. #endif
  36. #ifdef _AFX_MINREBUILD
  37. #pragma component(minrebuild, off)
  38. #endif
  39. #ifndef _AFX_FULLTYPEINFO
  40. #pragma component(mintypeinfo, on)
  41. #endif
  42. #ifdef _AFX_PACKING
  43. #pragma pack(push, _AFX_PACKING)
  44. #endif
  45. #ifndef _AFX_NOFORCE_LIBS
  46. #pragma comment(lib, "urlmon.lib")
  47. #endif // !_AFX_NOFORCE_LIBS
  48. /////////////////////////////////////////////////////////////////////////////
  49. // AFXOLE.H - MFC OLE support
  50. // Classes declared in this file
  51. //CDocument
  52. class COleDocument; // OLE container document
  53. class COleLinkingDoc; // supports links to embeddings
  54. class COleServerDoc; // OLE server document
  55. class CDocObjectServer; // might be owned by a COleServerDoc
  56. //CCmdTarget
  57. class CDocItem; // part of a document
  58. class COleClientItem; // embedded ole object from outside
  59. #if _MFC_VER >= 0x0600
  60. class COleDocObjectItem;// ActiveX Document item
  61. #endif
  62. class COleServerItem; // ole object to export
  63. class COleDataSource; // clipboard data source mechanism
  64. class COleDropSource; // drag/drop source
  65. class COleDropTarget; // drag/drop target
  66. class COleMessageFilter; // concurrency management
  67. //CFrameWnd
  68. class COleIPFrameWnd; // frame window for in-place servers
  69. //CControlBar
  70. class COleResizeBar; // implements in-place resizing
  71. //CFile
  72. class COleStreamFile; // CFile wrapper for IStream interface
  73. class CMonikerFile; // bound to via IMoniker
  74. class CAsyncMonikerFile;// asynchronous IMoniker
  75. class COleDataObject; // wrapper for IDataObject interface
  76. /////////////////////////////////////////////////////////////////////////////
  77. // AFXDLL support
  78. #undef AFX_DATA
  79. #define AFX_DATA AFX_OLE_DATA
  80. /////////////////////////////////////////////////////////////////////////////
  81. // backward compatibility
  82. // COleClientDoc is now obsolete -- use COleDocument instead
  83. #define COleClientDoc COleDocument
  84. // COleServer has been replaced by the more general COleObjectFactory
  85. #define COleServer COleObjectFactory
  86. /////////////////////////////////////////////////////////////////////////////
  87. // Useful OLE specific types (some from OLE 1.0 headers)
  88. // Codes for CallBack events
  89. enum OLE_NOTIFICATION
  90. {
  91. OLE_CHANGED, // representation of a draw aspect has changed
  92. OLE_SAVED, // the item has committed its storage
  93. OLE_CLOSED, // the item has closed
  94. OLE_RENAMED, // the item has changed its moniker
  95. OLE_CHANGED_STATE, // the item state (open, active, etc.) has changed
  96. OLE_CHANGED_ASPECT, // the item draw aspect has changed
  97. };
  98. // Object types
  99. enum OLE_OBJTYPE
  100. {
  101. OT_UNKNOWN = 0,
  102. // These are OLE 1.0 types and OLE 2.0 types as returned from GetType().
  103. OT_LINK = 1,
  104. OT_EMBEDDED = 2,
  105. OT_STATIC = 3,
  106. // All OLE2 objects are written with this tag when serialized. This
  107. // differentiates them from OLE 1.0 objects written with MFC 2.0.
  108. // This value will never be returned from GetType().
  109. OT_OLE2 = 256,
  110. };
  111. /////////////////////////////////////////////////////////////////////////////
  112. // COleDataObject -- simple wrapper for IDataObject
  113. class COleDataObject
  114. {
  115. // Constructors
  116. public:
  117. COleDataObject();
  118. // Operations
  119. void Attach(LPDATAOBJECT lpDataObject, BOOL bAutoRelease = TRUE);
  120. LPDATAOBJECT Detach(); // detach and get ownership of m_lpDataObject
  121. void Release(); // detach and Release ownership of m_lpDataObject
  122. BOOL AttachClipboard(); // attach to current clipboard object
  123. // Attributes
  124. void BeginEnumFormats();
  125. BOOL GetNextFormat(LPFORMATETC lpFormatEtc);
  126. CFile* GetFileData(CLIPFORMAT cfFormat, LPFORMATETC lpFormatEtc = NULL);
  127. HGLOBAL GetGlobalData(CLIPFORMAT cfFormat, LPFORMATETC lpFormatEtc = NULL);
  128. BOOL GetData(CLIPFORMAT cfFormat, LPSTGMEDIUM lpStgMedium,
  129. LPFORMATETC lpFormatEtc = NULL);
  130. BOOL IsDataAvailable(CLIPFORMAT cfFormat, LPFORMATETC lpFormatEtc = NULL);
  131. // Implementation
  132. public:
  133. LPDATAOBJECT m_lpDataObject;
  134. LPENUMFORMATETC m_lpEnumerator;
  135. ~COleDataObject();
  136. // advanced use and implementation
  137. LPDATAOBJECT GetIDataObject(BOOL bAddRef);
  138. void EnsureClipboardObject();
  139. BOOL m_bClipboard; // TRUE if represents the Win32 clipboard
  140. protected:
  141. BOOL m_bAutoRelease; // TRUE if destructor should call Release
  142. private:
  143. // Disable the copy constructor and assignment by default so you will get
  144. // compiler errors instead of unexpected behaviour if you pass objects
  145. // by value or assign objects.
  146. COleDataObject(const COleDataObject&); // no implementation
  147. void operator=(const COleDataObject&); // no implementation
  148. };
  149. /////////////////////////////////////////////////////////////////////////////
  150. // COleDataSource -- wrapper for implementing IDataObject
  151. // (works similar to how data is provided on the clipboard)
  152. struct AFX_DATACACHE_ENTRY;
  153. class COleDropSource;
  154. class COleDataSource : public CCmdTarget
  155. {
  156. // Constructors
  157. public:
  158. COleDataSource();
  159. // Operations
  160. void Empty(); // empty cache (similar to ::EmptyClipboard)
  161. // CacheData & DelayRenderData operations similar to ::SetClipboardData
  162. void CacheGlobalData(CLIPFORMAT cfFormat, HGLOBAL hGlobal,
  163. LPFORMATETC lpFormatEtc = NULL); // for HGLOBAL based data
  164. void DelayRenderFileData(CLIPFORMAT cfFormat,
  165. LPFORMATETC lpFormatEtc = NULL); // for CFile* based delayed render
  166. // Clipboard and Drag/Drop access
  167. DROPEFFECT DoDragDrop(
  168. DWORD dwEffects = DROPEFFECT_COPY|DROPEFFECT_MOVE|DROPEFFECT_LINK,
  169. LPCRECT lpRectStartDrag = NULL,
  170. COleDropSource* pDropSource = NULL);
  171. void SetClipboard();
  172. static void PASCAL FlushClipboard();
  173. static COleDataSource* PASCAL GetClipboardOwner();
  174. // Advanced: STGMEDIUM based cached data
  175. void CacheData(CLIPFORMAT cfFormat, LPSTGMEDIUM lpStgMedium,
  176. LPFORMATETC lpFormatEtc = NULL); // for LPSTGMEDIUM based data
  177. // Advanced: STGMEDIUM or HGLOBAL based delayed render
  178. void DelayRenderData(CLIPFORMAT cfFormat, LPFORMATETC lpFormatEtc = NULL);
  179. // Advanced: support for SetData in COleServerItem
  180. // (not generally useful for clipboard or drag/drop operations)
  181. void DelaySetData(CLIPFORMAT cfFormat, LPFORMATETC lpFormatEtc = NULL);
  182. // Overidables
  183. virtual BOOL OnRenderGlobalData(LPFORMATETC lpFormatEtc, HGLOBAL* phGlobal);
  184. virtual BOOL OnRenderFileData(LPFORMATETC lpFormatEtc, CFile* pFile);
  185. virtual BOOL OnRenderData(LPFORMATETC lpFormatEtc, LPSTGMEDIUM lpStgMedium);
  186. // OnRenderFileData and OnRenderGlobalData are called by
  187. // the default implementation of OnRenderData.
  188. virtual BOOL OnSetData(LPFORMATETC lpFormatEtc, LPSTGMEDIUM lpStgMedium,
  189. BOOL bRelease);
  190. // used only in COleServerItem implementation
  191. // Implementation
  192. public:
  193. virtual ~COleDataSource();
  194. #ifdef _DEBUG
  195. virtual void AssertValid() const;
  196. virtual void Dump(CDumpContext& dc) const;
  197. #endif
  198. protected:
  199. AFX_DATACACHE_ENTRY* m_pDataCache; // data cache itself
  200. UINT m_nMaxSize; // current allocated size
  201. UINT m_nSize; // current size of the cache
  202. UINT m_nGrowBy; // number of cache elements to grow by for new allocs
  203. AFX_DATACACHE_ENTRY* Lookup(
  204. LPFORMATETC lpFormatEtc, DATADIR nDataDir) const;
  205. AFX_DATACACHE_ENTRY* GetCacheEntry(
  206. LPFORMATETC lpFormatEtc, DATADIR nDataDir);
  207. // Interface Maps
  208. public:
  209. BEGIN_INTERFACE_PART(DataObject, IDataObject)
  210. INIT_INTERFACE_PART(COleDataSource, DataObject)
  211. STDMETHOD(GetData)(LPFORMATETC, LPSTGMEDIUM);
  212. STDMETHOD(GetDataHere)(LPFORMATETC, LPSTGMEDIUM);
  213. STDMETHOD(QueryGetData)(LPFORMATETC);
  214. STDMETHOD(GetCanonicalFormatEtc)(LPFORMATETC, LPFORMATETC);
  215. STDMETHOD(SetData)(LPFORMATETC, LPSTGMEDIUM, BOOL);
  216. STDMETHOD(EnumFormatEtc)(DWORD, LPENUMFORMATETC*);
  217. STDMETHOD(DAdvise)(LPFORMATETC, DWORD, LPADVISESINK, LPDWORD);
  218. STDMETHOD(DUnadvise)(DWORD);
  219. STDMETHOD(EnumDAdvise)(LPENUMSTATDATA*);
  220. END_INTERFACE_PART(DataObject)
  221. DECLARE_INTERFACE_MAP()
  222. friend class COleServerItem;
  223. };
  224. //////////////////////////////////////////////////////////////////////////////
  225. // DocItem support
  226. #ifdef _AFXDLL
  227. class CDocItem : public CCmdTarget
  228. #else
  229. class AFX_NOVTABLE CDocItem : public CCmdTarget
  230. #endif
  231. {
  232. DECLARE_SERIAL(CDocItem)
  233. // Constructors
  234. protected: // abstract class
  235. CDocItem();
  236. // Attributes
  237. public:
  238. CDocument* GetDocument() const; // return container document
  239. // Overridables
  240. public:
  241. // Raw data access (native format)
  242. virtual BOOL IsBlank() const;
  243. // Implementation
  244. protected:
  245. COleDocument* m_pDocument;
  246. public:
  247. virtual void Serialize(CArchive& ar); // for Native data
  248. virtual ~CDocItem();
  249. #ifdef _DEBUG
  250. virtual void AssertValid() const;
  251. virtual void Dump(CDumpContext& dc) const;
  252. #endif
  253. friend class COleDocument; // for access to back pointer
  254. };
  255. //////////////////////////////////////////////////////////////////////////////
  256. // COleDocument - common OLE container behavior (enables server functionality)
  257. class COleDocument : public CDocument
  258. {
  259. DECLARE_DYNAMIC(COleDocument)
  260. // Constructors
  261. public:
  262. COleDocument();
  263. // Attributes
  264. BOOL HasBlankItems() const; // check for BLANK items
  265. virtual COleClientItem* GetInPlaceActiveItem(CWnd* pWnd);
  266. // return in-place active item for this view or NULL if none
  267. // Operations
  268. // iterating over existing items
  269. virtual POSITION GetStartPosition() const;
  270. virtual CDocItem* GetNextItem(POSITION& pos) const;
  271. // iterator helpers (helpers use virtual GetNextItem above)
  272. COleClientItem* GetNextClientItem(POSITION& pos) const;
  273. COleServerItem* GetNextServerItem(POSITION& pos) const;
  274. // adding new items - called from item constructors
  275. virtual void AddItem(CDocItem* pItem);
  276. virtual void RemoveItem(CDocItem* pItem);
  277. void EnableCompoundFile(BOOL bEnable = TRUE);
  278. // enable compound file support (only call during constructor)
  279. virtual void UpdateModifiedFlag();
  280. // scan for modified items -- mark document modified
  281. // printer-device caching/control
  282. BOOL ApplyPrintDevice(const DVTARGETDEVICE* ptd);
  283. BOOL ApplyPrintDevice(const PRINTDLG* ppd);
  284. // these apply the target device to all COleClientItem objects
  285. // Overridables
  286. virtual COleClientItem* GetPrimarySelectedItem(CView* pView);
  287. // return primary selected item or NULL if none
  288. virtual void OnShowViews(BOOL bVisible);
  289. // called during app-idle when visibility of a document has changed
  290. // Implementation
  291. public:
  292. CObList m_docItemList; // not owned items
  293. #ifdef _DEBUG
  294. virtual void AssertValid() const;
  295. virtual void Dump(CDumpContext& dc) const;
  296. #endif
  297. CFrameWnd* GetFirstFrame();
  298. // document handling overrides
  299. virtual void SetPathName(LPCTSTR lpszPathName, BOOL bAddToMRU = TRUE);
  300. virtual ~COleDocument();
  301. virtual void DeleteContents(); // delete client items in list
  302. virtual void Serialize(CArchive& ar); // serialize items to file
  303. virtual void PreCloseFrame(CFrameWnd* pFrame);
  304. virtual BOOL SaveModified();
  305. virtual void OnIdle();
  306. // compound file implementation
  307. virtual BOOL OnNewDocument();
  308. virtual BOOL OnOpenDocument(LPCTSTR lpszPathName);
  309. virtual BOOL OnSaveDocument(LPCTSTR lpszPathName);
  310. virtual void OnCloseDocument();
  311. void CommitItems(BOOL bSuccess); // called during File.Save & File.Save As
  312. // minimal linking protocol
  313. virtual LPMONIKER GetMoniker(OLEGETMONIKER nAssign);
  314. virtual LPOLEITEMCONTAINER GetContainer();
  315. protected:
  316. // document state implementation
  317. UINT m_dwNextItemNumber;// serial number for next item in this document
  318. BOOL m_bLastVisible; // TRUE if one or more views was last visible
  319. // 'docfile' support
  320. BOOL m_bCompoundFile; // TRUE if use compound files
  321. LPSTORAGE m_lpRootStg; // root storage for the document
  322. BOOL m_bSameAsLoad; // TRUE = file-save, FALSE = Save [Copy] As
  323. BOOL m_bRemember; // if FALSE, indicates Save Copy As
  324. DVTARGETDEVICE* m_ptd; // current document target device
  325. // implementation helpers
  326. virtual void LoadFromStorage();
  327. virtual void SaveToStorage(CObject* pObject = NULL);
  328. CDocItem* GetNextItemOfKind(POSITION& pos, CRuntimeClass* pClass) const;
  329. // command handling
  330. #if _MFC_VER >= 0x600
  331. public:
  332. #endif
  333. virtual BOOL OnCmdMsg(UINT nID, int nCode, void* pExtra,
  334. AFX_CMDHANDLERINFO* pHandlerInfo);
  335. #if _MFC_VER >= 0x600
  336. protected:
  337. #endif
  338. afx_msg void OnUpdatePasteMenu(CCmdUI* pCmdUI);
  339. afx_msg void OnUpdatePasteLinkMenu(CCmdUI* pCmdUI);
  340. afx_msg void OnUpdateEditLinksMenu(CCmdUI* pCmdUI);
  341. afx_msg void OnEditLinks();
  342. afx_msg void OnEditConvert();
  343. afx_msg void OnUpdateEditChangeIcon(CCmdUI* pCmdUI);
  344. afx_msg void OnEditChangeIcon();
  345. afx_msg void OnUpdateObjectVerbMenu(CCmdUI* pCmdUI);
  346. afx_msg void OnFileSendMail();
  347. friend class COleClientItem;
  348. friend class COleServerItem;
  349. };
  350. /////////////////////////////////////////////////////////////////////////////
  351. // COleClientItem - Supports OLE2 non-inplace editing.
  352. // implements IOleClientSite, IAdviseSink, and IOleInPlaceSite
  353. class COleFrameHook; // forward reference (see ..\src\oleimpl2.h)
  354. class COleClientItem : public CDocItem
  355. {
  356. DECLARE_DYNAMIC(COleClientItem)
  357. // Constructors
  358. public:
  359. COleClientItem(COleDocument* pContainerDoc = NULL);
  360. // create from the clipboard
  361. BOOL CreateFromClipboard(OLERENDER render = OLERENDER_DRAW,
  362. CLIPFORMAT cfFormat = 0, LPFORMATETC lpFormatEtc = NULL);
  363. BOOL CreateLinkFromClipboard(OLERENDER render = OLERENDER_DRAW,
  364. CLIPFORMAT cfFormat = 0, LPFORMATETC lpFormatEtc = NULL);
  365. BOOL CreateStaticFromClipboard(OLERENDER render = OLERENDER_DRAW,
  366. CLIPFORMAT cfFormat = 0, LPFORMATETC lpFormatEtc = NULL);
  367. // create from a class ID (Insert New Object dialog)
  368. BOOL CreateNewItem(REFCLSID clsid, OLERENDER render = OLERENDER_DRAW,
  369. CLIPFORMAT cfFormat = 0, LPFORMATETC lpFormatEtc = NULL);
  370. // create from COleDataObject
  371. BOOL CreateFromData(COleDataObject* pDataObject,
  372. OLERENDER render = OLERENDER_DRAW,
  373. CLIPFORMAT cfFormat = 0, LPFORMATETC lpFormatEtc = NULL);
  374. BOOL CreateLinkFromData(COleDataObject* pDataObject,
  375. OLERENDER render = OLERENDER_DRAW,
  376. CLIPFORMAT cfFormat = 0, LPFORMATETC lpFormatEtc = NULL);
  377. BOOL CreateStaticFromData(COleDataObject* pDataObject,
  378. OLERENDER render = OLERENDER_DRAW,
  379. CLIPFORMAT cfFormat = 0, LPFORMATETC lpFormatEtc = NULL);
  380. // create from file (package support)
  381. BOOL CreateFromFile(LPCTSTR lpszFileName, REFCLSID clsid = CLSID_NULL,
  382. OLERENDER render = OLERENDER_DRAW,
  383. CLIPFORMAT cfFormat = 0, LPFORMATETC lpFormatEtc = NULL);
  384. BOOL CreateLinkFromFile(LPCTSTR lpszFileName,
  385. OLERENDER render = OLERENDER_DRAW,
  386. CLIPFORMAT cfFormat = 0, LPFORMATETC lpFormatEtc = NULL);
  387. // create a copy
  388. BOOL CreateCloneFrom(const COleClientItem* pSrcItem);
  389. // General Attributes
  390. public:
  391. #if _MFC_VER >= 0x0600
  392. HICON GetIconFromRegistry() const;
  393. static HICON GetIconFromRegistry(CLSID& clsid);
  394. #endif
  395. SCODE GetLastStatus() const;
  396. OLE_OBJTYPE GetType() const; // OT_LINK, OT_EMBEDDED, OT_STATIC
  397. void GetClassID(CLSID* pClassID) const;
  398. void GetUserType(USERCLASSTYPE nUserClassType, CString& rString);
  399. BOOL GetExtent(LPSIZE lpSize, DVASPECT nDrawAspect = (DVASPECT)-1);
  400. // will return FALSE if item is BLANK
  401. BOOL GetCachedExtent(LPSIZE lpSize, DVASPECT nDrawAspect = (DVASPECT)-1);
  402. // getting/setting iconic cache
  403. HGLOBAL GetIconicMetafile();
  404. BOOL SetIconicMetafile(HGLOBAL hMetaPict);
  405. // setting/getting default display aspect
  406. DVASPECT GetDrawAspect() const;
  407. virtual void SetDrawAspect(DVASPECT nDrawAspect);
  408. // for printer presentation cache
  409. BOOL SetPrintDevice(const DVTARGETDEVICE* ptd);
  410. BOOL SetPrintDevice(const PRINTDLG* ppd);
  411. // Item state
  412. enum ItemState
  413. { emptyState, loadedState, openState, activeState, activeUIState };
  414. UINT GetItemState() const;
  415. BOOL IsModified() const;
  416. BOOL IsRunning() const;
  417. BOOL IsInPlaceActive() const;
  418. BOOL IsOpen() const;
  419. CView* GetActiveView() const;
  420. // Data access
  421. void AttachDataObject(COleDataObject& rDataObject) const;
  422. // other rare access information
  423. COleDocument* GetDocument() const; // return container
  424. // helpers for checking clipboard data availability
  425. static BOOL PASCAL CanPaste();
  426. static BOOL PASCAL CanPasteLink();
  427. // helpers for checking COleDataObject, useful in drag drop
  428. static BOOL PASCAL CanCreateFromData(const COleDataObject* pDataObject);
  429. static BOOL PASCAL CanCreateLinkFromData(const COleDataObject* pDataObject);
  430. // General Operations
  431. virtual void Release(OLECLOSE dwCloseOption = OLECLOSE_NOSAVE);
  432. // cleanup, detach (close if needed)
  433. void Close(OLECLOSE dwCloseOption = OLECLOSE_SAVEIFDIRTY);
  434. // close without releasing the item
  435. void Delete(BOOL bAutoDelete = TRUE);
  436. // logically delete from file -- not part of the document anymore
  437. void Run(); // insure item is in running state
  438. // Drawing
  439. BOOL Draw(CDC* pDC, LPCRECT lpBounds,
  440. DVASPECT nDrawAspect = (DVASPECT)-1); // defaults to m_nDrawAspect
  441. // Activation
  442. virtual BOOL DoVerb(LONG nVerb, CView* pView, LPMSG lpMsg = NULL);
  443. void Activate(LONG nVerb, CView* pView, LPMSG lpMsg = NULL);
  444. // In-place Activation
  445. void Deactivate(); // completely deactivate
  446. void DeactivateUI(); // deactivate the user interface
  447. BOOL ReactivateAndUndo(); // reactivate then perform undo command
  448. BOOL SetItemRects(LPCRECT lpPosRect = NULL, LPCRECT lpClipRect = NULL);
  449. CWnd* GetInPlaceWindow();
  450. // Clipboard operations
  451. void CopyToClipboard(BOOL bIncludeLink = FALSE);
  452. DROPEFFECT DoDragDrop(LPCRECT lpItemRect, CPoint ptOffset,
  453. BOOL bIncludeLink = FALSE,
  454. DWORD dwEffects = DROPEFFECT_COPY|DROPEFFECT_MOVE,
  455. LPCRECT lpRectStartDrag = NULL);
  456. void GetClipboardData(COleDataSource* pDataSource,
  457. BOOL bIncludeLink = FALSE, LPPOINT lpOffset = NULL,
  458. LPSIZE lpSize = NULL);
  459. // called for creating a COleDataSource by CopyToClipboard and DoDragDrop
  460. virtual COleDataSource* OnGetClipboardData(BOOL bIncludeLink,
  461. LPPOINT lpOffset, LPSIZE lpSize);
  462. // Operations that apply to embedded items only
  463. void SetHostNames(LPCTSTR lpszHost, LPCTSTR lpszHostObj);
  464. void SetExtent(const CSize& size, DVASPECT nDrawAspect = DVASPECT_CONTENT);
  465. // Operations that apply to linked items only
  466. // (link options are rarely changed, except through Links dialog)
  467. OLEUPDATE GetLinkUpdateOptions();
  468. void SetLinkUpdateOptions(OLEUPDATE dwUpdateOpt);
  469. // Link-source update status (also useful for embeddings that contain links)
  470. BOOL UpdateLink(); // make up-to-date
  471. BOOL IsLinkUpToDate() const; // is link up-to-date
  472. // object conversion
  473. virtual BOOL ConvertTo(REFCLSID clsidNew);
  474. virtual BOOL ActivateAs(LPCTSTR lpszUserType, REFCLSID clsidOld, REFCLSID clsidNew);
  475. BOOL Reload(); // for lazy reload after ActivateAs
  476. // Overridables (notifications of IAdviseSink, IOleClientSite and IOleInPlaceSite)
  477. // Callbacks/notifications from the server you must/should implement
  478. virtual void OnChange(OLE_NOTIFICATION nCode, DWORD dwParam);
  479. // implement OnChange to invalidate when item changes
  480. protected:
  481. virtual void OnGetItemPosition(CRect& rPosition);
  482. // implement OnGetItemPosition if you support in-place activation
  483. // Common overrides for in-place activation
  484. virtual BOOL OnScrollBy(CSize sizeExtent);
  485. // Common overrides for applications supporting undo
  486. virtual void OnDiscardUndoState();
  487. virtual void OnDeactivateAndUndo();
  488. public:
  489. virtual void OnDeactivateUI(BOOL bUndoable);
  490. protected:
  491. // Common overrides for applications supporting links to embeddings
  492. virtual void OnShowItem();
  493. // Advanced overrides for in-place activation
  494. virtual void OnGetClipRect(CRect& rClipRect);
  495. virtual BOOL CanActivate();
  496. public:
  497. virtual void OnActivate();
  498. virtual void OnActivateUI();
  499. virtual void OnDeactivate();
  500. protected:
  501. virtual BOOL OnGetWindowContext(CFrameWnd** ppMainFrame,
  502. CFrameWnd** ppDocFrame, LPOLEINPLACEFRAMEINFO lpFrameInfo);
  503. virtual BOOL OnChangeItemPosition(const CRect& rectPos);
  504. // default calls SetItemRects and caches the pos rect
  505. public:
  506. // Advanced overrides for menu/title handling (rarely overridden)
  507. virtual void OnInsertMenus(CMenu* pMenuShared,
  508. LPOLEMENUGROUPWIDTHS lpMenuWidths);
  509. virtual void OnSetMenu(CMenu* pMenuShared, HOLEMENU holemenu,
  510. HWND hwndActiveObject);
  511. virtual void OnRemoveMenus(CMenu* pMenuShared);
  512. virtual BOOL OnUpdateFrameTitle();
  513. // Advanced override for control bar handling
  514. virtual BOOL OnShowControlBars(CFrameWnd* pFrameWnd, BOOL bShow);
  515. // Implementation
  516. public:
  517. // data to support non-inplace activated items
  518. LPOLEOBJECT m_lpObject; // in case you want direct access to the OLE object
  519. LPVIEWOBJECT2 m_lpViewObject;// IViewObject for IOleObject above
  520. DWORD m_dwItemNumber; // serial number for this item in this document
  521. DVASPECT m_nDrawAspect; // current default display aspect
  522. SCODE m_scLast; // last error code encountered
  523. LPSTORAGE m_lpStorage; // provides storage for m_lpObject
  524. LPLOCKBYTES m_lpLockBytes; // part of implementation of m_lpStorage
  525. DWORD m_dwConnection; // advise connection to the m_lpObject
  526. BYTE m_bLinkUnavail; // TRUE if link is currently unavailable
  527. BYTE m_bMoniker; // TRUE if moniker is assigned
  528. BYTE m_bLocked; // TRUE if object has external lock
  529. BYTE m_bNeedCommit; // TRUE if need CommitItem
  530. BYTE m_bClosing; // TRUE if currently doing COleClientItem::Close
  531. BYTE m_bReserved[3]; // (reserved for future use)
  532. // for compound file support
  533. LPSTORAGE m_lpNewStorage; // used during Save As situations
  534. // item state & item type
  535. ItemState m_nItemState; // item state (see ItemState enumeration)
  536. OLE_OBJTYPE m_nItemType; // item type (depends on how created)
  537. // data valid when in-place activated
  538. CView* m_pView; // view when object is in-place activated
  539. DWORD m_dwContainerStyle; // style of the container wnd before activation
  540. COleFrameHook* m_pInPlaceFrame;// frame window when in-place active
  541. COleFrameHook* m_pInPlaceDoc; // doc window when in-place (may be NULL)
  542. HWND m_hWndServer; // HWND of in-place server window
  543. public:
  544. virtual ~COleClientItem();
  545. virtual void Serialize(CArchive& ar);
  546. #ifdef _DEBUG
  547. virtual void AssertValid() const;
  548. virtual void Dump(CDumpContext& dc) const;
  549. #endif
  550. // Implementation
  551. public:
  552. virtual BOOL ReportError(SCODE sc) const;
  553. virtual BOOL FreezeLink(); // converts to static: for edit links dialog
  554. DWORD GetNewItemNumber(); // generates new item number
  555. void GetItemName(LPTSTR lpszItemName) const; // gets readable item name
  556. void UpdateItemType(); // update m_nItemType
  557. protected:
  558. // clipboard helpers
  559. void GetEmbeddedItemData(LPSTGMEDIUM lpStgMedium);
  560. void AddCachedData(COleDataSource* pDataSource);
  561. BOOL GetLinkSourceData(LPSTGMEDIUM lpStgMedium);
  562. void GetObjectDescriptorData(LPPOINT lpOffset, LPSIZE lpSize,
  563. LPSTGMEDIUM lpStgMedium);
  564. // interface helpers
  565. virtual LPOLECLIENTSITE GetClientSite();
  566. // helpers for printer-cached representation
  567. BOOL GetPrintDeviceInfo(LPOLECACHE* plpOleCache,
  568. DVTARGETDEVICE** pptd, DWORD* pdwConnection);
  569. // Advanced Overridables for implementation
  570. protected:
  571. virtual BOOL FinishCreate(SCODE sc);
  572. virtual void CheckGeneral(SCODE sc);
  573. virtual void OnDataChange(LPFORMATETC lpFormatEtc,
  574. LPSTGMEDIUM lpStgMedium);
  575. public:
  576. // for storage hookability (override to use 'docfiles')
  577. virtual void GetItemStorage(); // allocate storage for new item
  578. virtual void ReadItem(CArchive& ar); // read item from archive
  579. virtual void WriteItem(CArchive& ar); // write item to archive
  580. virtual void CommitItem(BOOL bSuccess); // commit item's storage
  581. // compound & flat file implementations of above
  582. void GetItemStorageFlat();
  583. void ReadItemFlat(CArchive& ar);
  584. void WriteItemFlat(CArchive& ar);
  585. void GetItemStorageCompound();
  586. void ReadItemCompound(CArchive& ar);
  587. void WriteItemCompound(CArchive& ar);
  588. // Interface Maps
  589. public:
  590. BEGIN_INTERFACE_PART(OleClientSite, IOleClientSite)
  591. INIT_INTERFACE_PART(COleClientItem, OleClientSite)
  592. STDMETHOD(SaveObject)();
  593. STDMETHOD(GetMoniker)(DWORD, DWORD, LPMONIKER*);
  594. STDMETHOD(GetContainer)(LPOLECONTAINER*);
  595. STDMETHOD(ShowObject)();
  596. STDMETHOD(OnShowWindow)(BOOL);
  597. STDMETHOD(RequestNewObjectLayout)();
  598. END_INTERFACE_PART(OleClientSite)
  599. BEGIN_INTERFACE_PART(AdviseSink, IAdviseSink)
  600. INIT_INTERFACE_PART(COleClientItem, AdviseSink)
  601. STDMETHOD_(void,OnDataChange)(LPFORMATETC, LPSTGMEDIUM);
  602. STDMETHOD_(void,OnViewChange)(DWORD, LONG);
  603. STDMETHOD_(void,OnRename)(LPMONIKER);
  604. STDMETHOD_(void,OnSave)();
  605. STDMETHOD_(void,OnClose)();
  606. END_INTERFACE_PART(AdviseSink)
  607. BEGIN_INTERFACE_PART(OleIPSite, IOleInPlaceSite)
  608. INIT_INTERFACE_PART(COleClientItem, OleIPSite)
  609. STDMETHOD(GetWindow)(HWND*);
  610. STDMETHOD(ContextSensitiveHelp)(BOOL);
  611. STDMETHOD(CanInPlaceActivate)();
  612. STDMETHOD(OnInPlaceActivate)();
  613. STDMETHOD(OnUIActivate)();
  614. STDMETHOD(GetWindowContext)(LPOLEINPLACEFRAME*,
  615. LPOLEINPLACEUIWINDOW*, LPRECT, LPRECT, LPOLEINPLACEFRAMEINFO);
  616. STDMETHOD(Scroll)(SIZE);
  617. STDMETHOD(OnUIDeactivate)(BOOL);
  618. STDMETHOD(OnInPlaceDeactivate)();
  619. STDMETHOD(DiscardUndoState)();
  620. STDMETHOD(DeactivateAndUndo)();
  621. STDMETHOD(OnPosRectChange)(LPCRECT);
  622. END_INTERFACE_PART(OleIPSite)
  623. DECLARE_INTERFACE_MAP()
  624. // Friendship declarations (to avoid many public members)
  625. friend class COleUIWindow;
  626. friend class COleFrameWindow;
  627. friend class COleLinkingDoc;
  628. };
  629. #if _MFC_VER >= 0x0600
  630. class COleDocObjectItem : public COleClientItem
  631. {
  632. friend class COleFrameHook;
  633. DECLARE_DYNAMIC(COleDocObjectItem)
  634. // Constructors
  635. public:
  636. COleDocObjectItem(COleDocument* pContainerDoc = NULL);
  637. //Overridables
  638. public:
  639. LPOLEDOCUMENTVIEW GetActiveView() const;
  640. virtual void Release(OLECLOSE dwCloseOption = OLECLOSE_NOSAVE);
  641. virtual void OnInsertMenus(CMenu* pMenuShared,
  642. LPOLEMENUGROUPWIDTHS lpMenuWidths);
  643. virtual void OnRemoveMenus(CMenu *pMenuShared);
  644. // Operations
  645. public:
  646. static BOOL OnPreparePrinting(CView* pCaller, CPrintInfo* pInfo,
  647. BOOL bPrintAll = TRUE);
  648. static void OnPrint(CView* pCaller, CPrintInfo* pInfo,
  649. BOOL bPrintAll = TRUE);
  650. BOOL GetPageCount(LPLONG pnFirstPage, LPLONG pcPages);
  651. HRESULT ExecCommand(DWORD nCmdID,
  652. DWORD nCmdExecOpt = OLECMDEXECOPT_DONTPROMPTUSER,
  653. const GUID* pguidCmdGroup = NULL);
  654. // Implementation
  655. public:
  656. virtual ~COleDocObjectItem();
  657. CMenu* m_pHelpPopupMenu;
  658. protected:
  659. virtual void OnGetItemPosition(CRect& rPosition);
  660. virtual CMenu* GetHelpMenu(UINT& nPosition);
  661. void ActivateAndShow();
  662. LPOLEDOCUMENTVIEW m_pActiveView;
  663. LPPRINT m_pIPrint;
  664. BOOL SupportsIPrint();
  665. BOOL m_bInHelpMenu;
  666. BEGIN_INTERFACE_PART(OleDocumentSite, IOleDocumentSite)
  667. INIT_INTERFACE_PART(COleDocObjectItem, OleDocumentSite)
  668. STDMETHOD(ActivateMe)(LPOLEDOCUMENTVIEW pViewToActivate);
  669. END_INTERFACE_PART(OleDocumentSite)
  670. DECLARE_INTERFACE_MAP()
  671. };
  672. #endif
  673. /////////////////////////////////////////////////////////////////////////////
  674. // COleServerItem - IOleObject & IDataObject OLE component
  675. #ifdef _AFXDLL
  676. class COleServerItem : public CDocItem
  677. #else
  678. class AFX_NOVTABLE COleServerItem : public CDocItem
  679. #endif
  680. {
  681. DECLARE_DYNAMIC(COleServerItem)
  682. protected:
  683. // NOTE: many members in this class are protected - since everything
  684. // in this class is designed for implementing an OLE server.
  685. // Requests will come from OLE containers through non-C++ mechanisms,
  686. // which will result in virtual functions in this class being called.
  687. // Constructors
  688. COleServerItem(COleServerDoc* pServerDoc, BOOL bAutoDelete);
  689. // If your COleServerItem is an integral part of your data,
  690. // bAutoDelete should be FALSE. If your COleServerItem can be
  691. // deleted when a link is released, it can be TRUE.
  692. COleDataSource* GetDataSource();
  693. // Use this data source to add conversion formats that your
  694. // server should support. Usually such formats are
  695. // added in the item's constructor.
  696. // Public Attributes
  697. public:
  698. COleServerDoc* GetDocument() const; // return server document
  699. // naming (for links only)
  700. const CString& GetItemName() const; // get name of linked item
  701. void SetItemName(LPCTSTR lpszItemName); // set name of linked item
  702. // link state
  703. BOOL IsConnected() const; // returns TRUE if item has a client
  704. BOOL IsLinkedItem() const; // returns TRUE if item is not embedded item
  705. // extents
  706. CSize m_sizeExtent;
  707. // HIMETRIC size -- the default implementation of OnSetExtent
  708. // updates this member variable. This member tells the server how
  709. // much of the object is visible in the container document.
  710. // Operations
  711. public:
  712. void NotifyChanged(DVASPECT nDrawAspect = DVASPECT_CONTENT);
  713. // call this after you change item
  714. void CopyToClipboard(BOOL bIncludeLink = FALSE);
  715. // helper for implementing server 'copy to clipboard'
  716. DROPEFFECT DoDragDrop(LPCRECT lpRectItem, CPoint ptOffset,
  717. BOOL bIncludeLink = FALSE,
  718. DWORD dwEffects = DROPEFFECT_COPY|DROPEFFECT_MOVE,
  719. LPCRECT lpRectStartDrag = NULL);
  720. void GetClipboardData(COleDataSource* pDataSource,
  721. BOOL bIncludeLink = FALSE, LPPOINT lpOffset = NULL,
  722. LPSIZE lpSize = NULL);
  723. // Overridables
  724. // overridables you must implement for yourself
  725. virtual BOOL OnDraw(CDC* pDC, CSize& rSize) = 0;
  726. // drawing for metafile format (return FALSE if not supported or error)
  727. // (called for DVASPECT_CONTENT only)
  728. // overridables you may want to implement yourself
  729. virtual void OnUpdate(COleServerItem* pSender,
  730. LPARAM lHint, CObject* pHint, DVASPECT nDrawAspect);
  731. // the default implementation always calls NotifyChanged
  732. virtual BOOL OnDrawEx(CDC* pDC, DVASPECT nDrawAspect, CSize& rSize);
  733. // advanced drawing -- called for DVASPECT other than DVASPECT_CONTENT
  734. virtual BOOL OnSetExtent(DVASPECT nDrawAspect, const CSize& size);
  735. virtual BOOL OnGetExtent(DVASPECT nDrawAspect, CSize& rSize);
  736. // default implementation uses m_sizeExtent
  737. // overridables you do not have to implement
  738. virtual void OnDoVerb(LONG iVerb);
  739. // default routes to OnShow &/or OnOpen
  740. virtual BOOL OnSetColorScheme(const LOGPALETTE* lpLogPalette);
  741. // default does nothing
  742. virtual COleDataSource* OnGetClipboardData(BOOL bIncludeLink,
  743. LPPOINT lpOffset, LPSIZE lpSize);
  744. // called for access to clipboard data
  745. virtual BOOL OnQueryUpdateItems();
  746. // called to determine if there are any contained out-of-date links
  747. virtual void OnUpdateItems();
  748. // called to update any out-of-date links
  749. protected:
  750. virtual void OnShow();
  751. // show item in the user interface (may edit in-place)
  752. virtual void OnOpen();
  753. // show item in the user interface (must open fully)
  754. virtual void OnHide();
  755. // hide document (and sometimes application)
  756. // very advanced overridables
  757. public:
  758. virtual BOOL OnInitFromData(COleDataObject* pDataObject, BOOL bCreation);
  759. // initialize object from IDataObject
  760. // see COleDataSource for a description of these overridables
  761. virtual BOOL OnRenderGlobalData(LPFORMATETC lpFormatEtc, HGLOBAL* phGlobal);
  762. virtual BOOL OnRenderFileData(LPFORMATETC lpFormatEtc, CFile* pFile);
  763. virtual BOOL OnRenderData(LPFORMATETC lpFormatEtc, LPSTGMEDIUM lpStgMedium);
  764. // HGLOBAL version will be called first, then CFile* version
  765. virtual BOOL OnSetData(LPFORMATETC lpFormatEtc, LPSTGMEDIUM lpStgMedium,
  766. BOOL bRelease);
  767. // Rare -- only if you support SetData (programmatic paste)
  768. // advanced helpers for CopyToClipboard
  769. void GetEmbedSourceData(LPSTGMEDIUM lpStgMedium);
  770. void AddOtherClipboardData(COleDataSource* pDataSource);
  771. BOOL GetLinkSourceData(LPSTGMEDIUM lpStgMedium);
  772. void GetObjectDescriptorData(LPPOINT lpOffset, LPSIZE lpSize,
  773. LPSTGMEDIUM lpStgMedium);
  774. // Implementation
  775. public:
  776. BOOL m_bNeedUnlock; // if TRUE need to pDoc->LockExternal(FALSE)
  777. BOOL m_bAutoDelete; // if TRUE will OnRelease will 'delete this'
  778. // special version of OnFinalRelease to implement document locking
  779. virtual void OnFinalRelease();
  780. protected:
  781. CString m_strItemName; // simple item name
  782. public:
  783. LPOLEADVISEHOLDER m_lpOleAdviseHolder; // may be NULL
  784. LPDATAADVISEHOLDER m_lpDataAdviseHolder; // may be NULL
  785. virtual ~COleServerItem();
  786. #ifdef _DEBUG
  787. virtual void AssertValid() const;
  788. virtual void Dump(CDumpContext& dc) const;
  789. #endif
  790. // implementation helpers
  791. void NotifyClient(OLE_NOTIFICATION wNotification, DWORD_PTR dwParam);
  792. LPDATAOBJECT GetDataObject();
  793. LPOLEOBJECT GetOleObject();
  794. LPMONIKER GetMoniker(OLEGETMONIKER nAssign);
  795. protected:
  796. virtual BOOL GetMetafileData(LPFORMATETC lpFormatEtc, LPSTGMEDIUM pmedium);
  797. // calls OnDraw or OnDrawEx
  798. virtual void OnSaveEmbedding(LPSTORAGE lpStorage);
  799. virtual BOOL IsBlank() const;
  800. // CItemDataSource implements OnRender reflections to COleServerItem
  801. class CItemDataSource : public COleDataSource
  802. {
  803. protected:
  804. // the GetData and SetData interfaces forward to m_pItem
  805. virtual BOOL OnRenderGlobalData(LPFORMATETC lpFormatEtc, HGLOBAL* phGlobal);
  806. virtual BOOL OnRenderFileData(LPFORMATETC lpFormatEtc, CFile* pFile);
  807. virtual BOOL OnRenderData(LPFORMATETC lpFormatEtc, LPSTGMEDIUM lpStgMedium);
  808. // HGLOBAL version will be called first, then CFile* version
  809. virtual BOOL OnSetData(LPFORMATETC lpFormatEtc, LPSTGMEDIUM lpStgMedium,
  810. BOOL bRelease);
  811. };
  812. CItemDataSource m_dataSource;
  813. // data source used to implement IDataObject
  814. // Interface Maps
  815. // (Note: these interface maps are used just for link implementation)
  816. public:
  817. BEGIN_INTERFACE_PART(OleObject, IOleObject)
  818. INIT_INTERFACE_PART(COleServerItem, OleObject)
  819. STDMETHOD(SetClientSite)(LPOLECLIENTSITE);
  820. STDMETHOD(GetClientSite)(LPOLECLIENTSITE*);
  821. STDMETHOD(SetHostNames)(LPCOLESTR, LPCOLESTR);
  822. STDMETHOD(Close)(DWORD);
  823. STDMETHOD(SetMoniker)(DWORD, LPMONIKER);
  824. STDMETHOD(GetMoniker)(DWORD, DWORD, LPMONIKER*);
  825. STDMETHOD(InitFromData)(LPDATAOBJECT, BOOL, DWORD);
  826. STDMETHOD(GetClipboardData)(DWORD, LPDATAOBJECT*);
  827. STDMETHOD(DoVerb)(LONG, LPMSG, LPOLECLIENTSITE, LONG, HWND, LPCRECT);
  828. STDMETHOD(EnumVerbs)(LPENUMOLEVERB*);
  829. STDMETHOD(Update)();
  830. STDMETHOD(IsUpToDate)();
  831. STDMETHOD(GetUserClassID)(LPCLSID);
  832. STDMETHOD(GetUserType)(DWORD, LPOLESTR*);
  833. STDMETHOD(SetExtent)(DWORD, LPSIZEL);
  834. STDMETHOD(GetExtent)(DWORD, LPSIZEL);
  835. STDMETHOD(Advise)(LPADVISESINK, LPDWORD);
  836. STDMETHOD(Unadvise)(DWORD);
  837. STDMETHOD(EnumAdvise)(LPENUMSTATDATA*);
  838. STDMETHOD(GetMiscStatus)(DWORD, LPDWORD);
  839. STDMETHOD(SetColorScheme)(LPLOGPALETTE);
  840. END_INTERFACE_PART(OleObject)
  841. BEGIN_INTERFACE_PART(DataObject, IDataObject)
  842. INIT_INTERFACE_PART(COleServerItem, DataObject)
  843. STDMETHOD(GetData)(LPFORMATETC, LPSTGMEDIUM);
  844. STDMETHOD(GetDataHere)(LPFORMATETC, LPSTGMEDIUM);
  845. STDMETHOD(QueryGetData)(LPFORMATETC);
  846. STDMETHOD(GetCanonicalFormatEtc)(LPFORMATETC, LPFORMATETC);
  847. STDMETHOD(SetData)(LPFORMATETC, LPSTGMEDIUM, BOOL);
  848. STDMETHOD(EnumFormatEtc)(DWORD, LPENUMFORMATETC*);
  849. STDMETHOD(DAdvise)(LPFORMATETC, DWORD, LPADVISESINK, LPDWORD);
  850. STDMETHOD(DUnadvise)(DWORD);
  851. STDMETHOD(EnumDAdvise)(LPENUMSTATDATA*);
  852. END_INTERFACE_PART(DataObject)
  853. DECLARE_INTERFACE_MAP()
  854. friend class CItemDataSource;
  855. friend class COleServerDoc;
  856. friend class COleLinkingDoc;
  857. };
  858. /////////////////////////////////////////////////////////////////////////////
  859. // COleLinkingDoc -
  860. // (enables linking to embeddings - beginnings of server fuctionality)
  861. class COleLinkingDoc : public COleDocument
  862. {
  863. DECLARE_DYNAMIC(COleLinkingDoc)
  864. // Constructors
  865. public:
  866. COleLinkingDoc();
  867. // Operations
  868. BOOL Register(COleObjectFactory* pFactory, LPCTSTR lpszPathName);
  869. // notify the running object table and connect to pServer
  870. void Revoke();
  871. // revoke from running object table
  872. // Overridables
  873. protected:
  874. virtual COleServerItem* OnGetLinkedItem(LPCTSTR lpszItemName);
  875. // return item for the named linked item (for supporting links)
  876. virtual COleClientItem* OnFindEmbeddedItem(LPCTSTR lpszItemName);
  877. // return item for the named embedded item (for links to embeddings)
  878. // Implementation
  879. public:
  880. COleObjectFactory* m_pFactory; // back-pointer to server
  881. #ifdef _DEBUG
  882. virtual void AssertValid() const;
  883. virtual void Dump(CDumpContext& dc) const;
  884. #endif
  885. virtual ~COleLinkingDoc();
  886. // overrides for updating of monikers & running object table registration
  887. virtual BOOL OnNewDocument();
  888. virtual BOOL OnOpenDocument(LPCTSTR lpszPathName);
  889. virtual BOOL OnSaveDocument(LPCTSTR lpszPathName);
  890. virtual void OnCloseDocument();
  891. virtual LPOLEITEMCONTAINER GetContainer();
  892. virtual LPMONIKER GetMoniker(OLEGETMONIKER nAssign);
  893. // special handling of error messages during save/load
  894. virtual void ReportSaveLoadException(LPCTSTR lpszPathName,
  895. CException* e, BOOL bSaving, UINT nIDPDefault);
  896. void BeginDeferErrors();
  897. SCODE EndDeferErrors(SCODE sc);
  898. protected:
  899. BOOL m_bDeferErrors; // TRUE if in non-interactive OLE mode
  900. CException* m_pLastException;
  901. DWORD m_dwRegister; // file moniker's registration in the ROT
  902. LPMONIKER m_lpMonikerROT; // file moniker that is registered
  903. CString m_strMoniker; // filename used to create moniker
  904. BOOL m_bVisibleLock; // TRUE if user is holding lock on document
  905. // implementation helpers
  906. virtual BOOL RegisterIfServerAttached(LPCTSTR lpszPathName, BOOL bMessage);
  907. void LockExternal(BOOL bLock, BOOL bRemoveRefs);
  908. void UpdateVisibleLock(BOOL bVisible, BOOL bRemoveRefs);
  909. virtual void OnShowViews(BOOL bVisible);
  910. virtual void SaveToStorage(CObject* pObject = NULL);
  911. // Interface Maps
  912. public:
  913. BEGIN_INTERFACE_PART(PersistFile, IPersistFile)
  914. INIT_INTERFACE_PART(COleLinkingDoc, PersistFile)
  915. STDMETHOD(GetClassID)(LPCLSID);
  916. STDMETHOD(IsDirty)();
  917. STDMETHOD(Load)(LPCOLESTR, DWORD);
  918. STDMETHOD(Save)(LPCOLESTR, BOOL);
  919. STDMETHOD(SaveCompleted)(LPCOLESTR);
  920. STDMETHOD(GetCurFile)(LPOLESTR*);
  921. END_INTERFACE_PART(PersistFile)
  922. BEGIN_INTERFACE_PART(OleItemContainer, IOleItemContainer)
  923. INIT_INTERFACE_PART(COleLinkingDoc, OleItemContainer)
  924. STDMETHOD(ParseDisplayName)(LPBC, LPOLESTR, ULONG*, LPMONIKER*);
  925. STDMETHOD(EnumObjects)(DWORD, LPENUMUNKNOWN*);
  926. STDMETHOD(LockContainer)(BOOL);
  927. STDMETHOD(GetObject)(LPOLESTR, DWORD, LPBINDCTX, REFIID, LPVOID*);
  928. STDMETHOD(GetObjectStorage)(LPOLESTR, LPBINDCTX, REFIID, LPVOID*);
  929. STDMETHOD(IsRunning)(LPOLESTR);
  930. END_INTERFACE_PART(OleItemContainer)
  931. DECLARE_INTERFACE_MAP()
  932. friend class COleClientItem;
  933. friend class COleClientItem::XOleClientSite;
  934. friend class COleServerItem::XOleObject;
  935. };
  936. //////////////////////////////////////////////////////////////////////////////
  937. // COleServerDoc - registered server document containing COleServerItems
  938. #ifdef _AFXDLL
  939. class COleServerDoc : public COleLinkingDoc
  940. #else
  941. class AFX_NOVTABLE COleServerDoc : public COleLinkingDoc
  942. #endif
  943. {
  944. DECLARE_DYNAMIC(COleServerDoc)
  945. // Constructors and Destructors
  946. public:
  947. COleServerDoc();
  948. // Attributes
  949. BOOL IsEmbedded() const; // TRUE if document is an embedding
  950. BOOL IsDocObject() const; // TRUE if document is a DocObject
  951. COleServerItem* GetEmbeddedItem();
  952. // return embedded item for document (will allocate if necessary)
  953. // attributes specific to in-place activation
  954. BOOL IsInPlaceActive() const;
  955. void GetItemPosition(LPRECT lpPosRect) const;
  956. // get current position rectangle of in-place edit
  957. void GetItemClipRect(LPRECT lpClipRect) const;
  958. // get current clipping rectangle of in-place edit
  959. BOOL GetZoomFactor(LPSIZE lpSizeNum = NULL, LPSIZE lpSizeDenom = NULL,
  960. LPCRECT lpPosRect = NULL) const;
  961. // returns the zoom factor in pixels
  962. // Operations
  963. void NotifyChanged();
  964. // call this after you change some global attribute like
  965. // document dimensions
  966. void UpdateAllItems(COleServerItem* pSender,
  967. LPARAM lHint = 0L, CObject* pHint = NULL,
  968. DVASPECT nDrawAspect = DVASPECT_CONTENT);
  969. // changes to the entire document (automatically notifies clients)
  970. void NotifyRename(LPCTSTR lpszNewName);
  971. void NotifySaved();
  972. void NotifyClosed(); // call this after you close document
  973. // specific operations for embedded documents
  974. void SaveEmbedding(); // call this to save embedded (before closing)
  975. // specific to in-place activation
  976. BOOL ActivateInPlace();
  977. void ActivateDocObject();
  978. void RequestPositionChange(LPCRECT lpPosRect);
  979. BOOL ScrollContainerBy(CSize sizeScroll);
  980. BOOL DeactivateAndUndo();
  981. BOOL DiscardUndoState();
  982. public:
  983. // Overridables for standard user interface (full server)
  984. virtual BOOL OnUpdateDocument(); // implementation of embedded update
  985. protected:
  986. // Overridables you must implement for yourself
  987. virtual COleServerItem* OnGetEmbeddedItem() = 0;
  988. // return item representing entire (embedded) document
  989. // Overridables you do not have to implement
  990. virtual void OnClose(OLECLOSE dwCloseOption);
  991. virtual void OnSetHostNames(LPCTSTR lpszHost, LPCTSTR lpszHostObj);
  992. virtual HRESULT OnExecOleCmd(const GUID* pguidCmdGroup, DWORD nCmdID,
  993. DWORD nCmdExecOpt, VARIANTARG* pvarargIn, VARIANTARG* pvarargOut);
  994. virtual CDocObjectServer* GetDocObjectServer(LPOLEDOCUMENTSITE pDocSite);
  995. // Advanced overridables
  996. LPUNKNOWN GetInterfaceHook(const void* piid);
  997. virtual void OnShowDocument(BOOL bShow);
  998. // show first frame for document or hide all frames for document
  999. // Advanced overridables for in-place activation
  1000. public:
  1001. virtual void OnDeactivate();
  1002. virtual void OnDeactivateUI(BOOL bUndoable);
  1003. protected:
  1004. virtual void OnSetItemRects(LPCRECT lpPosRect, LPCRECT lpClipRect);
  1005. virtual BOOL OnReactivateAndUndo();
  1006. virtual void OnFrameWindowActivate(BOOL bActivate);
  1007. virtual void OnDocWindowActivate(BOOL bActivate);
  1008. virtual void OnShowControlBars(CFrameWnd* pFrameWnd, BOOL bShow);
  1009. virtual COleIPFrameWnd* CreateInPlaceFrame(CWnd* pParentWnd);
  1010. virtual void DestroyInPlaceFrame(COleIPFrameWnd* pFrameWnd);
  1011. public:
  1012. virtual void OnResizeBorder(LPCRECT lpRectBorder,
  1013. LPOLEINPLACEUIWINDOW lpUIWindow, BOOL bFrame);
  1014. // Implementation
  1015. protected:
  1016. LPOLECLIENTSITE m_lpClientSite; // for embedded item
  1017. CString m_strHostObj; // name of document in container
  1018. BOOL m_bCntrVisible; // TRUE if OnShowWindow(TRUE) called
  1019. BOOL m_bClosing; // TRUE if shutting down
  1020. COleServerItem* m_pEmbeddedItem; // pointer to embedded item for document
  1021. COleIPFrameWnd* m_pInPlaceFrame; // not NULL if in-place activated
  1022. CWnd* m_pOrigParent; // not NULL if existing view used
  1023. DWORD m_dwOrigStyle; // original style of in-place view
  1024. DWORD m_dwOrigStyleEx; // original extended style
  1025. CDocObjectServer* m_pDocObjectServer; // if DocObject, ptr to doc site
  1026. public:
  1027. virtual ~COleServerDoc();
  1028. #ifdef _DEBUG
  1029. virtual void AssertValid() const;
  1030. virtual void Dump(CDumpContext& dc) const;
  1031. #endif
  1032. // overridables for implementation
  1033. virtual BOOL OnSaveDocument(LPCTSTR lpszPathName);
  1034. virtual void OnCloseDocument();
  1035. virtual void DeleteContents(); // delete auto-delete server items
  1036. virtual LPMONIKER GetMoniker(OLEGETMONIKER nAssign);
  1037. virtual COleServerItem* OnGetLinkedItem(LPCTSTR lpszItemName);
  1038. // return item for the named linked item (only if supporting links)
  1039. virtual BOOL CanCloseFrame(CFrameWnd* pFrame);
  1040. protected:
  1041. // overrides to handle server user-interface
  1042. virtual BOOL SaveModified(); // return TRUE if ok to continue
  1043. virtual HMENU GetDefaultMenu(); // return menu based on doc type
  1044. virtual HACCEL GetDefaultAccelerator(); // return accel table based on doc type
  1045. virtual BOOL GetFileTypeString(CString& rString);
  1046. // IPersistStorage implementation
  1047. virtual void OnNewEmbedding(LPSTORAGE lpStorage);
  1048. virtual void OnOpenEmbedding(LPSTORAGE lpStorage);
  1049. virtual void OnSaveEmbedding(LPSTORAGE lpStorage);
  1050. // Implementation helpers
  1051. void NotifyAllItems(OLE_NOTIFICATION wNotification, DWORD_PTR dwParam);
  1052. BOOL SaveModifiedPrompt();
  1053. void ConnectView(CWnd* pParentWnd, CView* pView);
  1054. void UpdateUsingHostObj(UINT nIDS, CCmdUI* pCmdUI);
  1055. // Message Maps
  1056. //{{AFX_MSG(COleServerDoc)
  1057. afx_msg void OnFileUpdate();
  1058. afx_msg void OnFileSaveCopyAs();
  1059. afx_msg void OnUpdateFileUpdate(CCmdUI* pCmdUI);
  1060. afx_msg void OnUpdateFileExit(CCmdUI* pCmdUI);
  1061. //}}AFX_MSG
  1062. DECLARE_MESSAGE_MAP()
  1063. // Interface Maps
  1064. public:
  1065. BEGIN_INTERFACE_PART(PersistStorage, IPersistStorage)
  1066. INIT_INTERFACE_PART(COleServerDoc, PersistStorage)
  1067. STDMETHOD(GetClassID)(LPCLSID);
  1068. STDMETHOD(IsDirty)();
  1069. STDMETHOD(InitNew)(LPSTORAGE);
  1070. STDMETHOD(Load)(LPSTORAGE);
  1071. STDMETHOD(Save)(LPSTORAGE, BOOL);
  1072. STDMETHOD(SaveCompleted)(LPSTORAGE);
  1073. STDMETHOD(HandsOffStorage)();
  1074. END_INTERFACE_PART(PersistStorage)
  1075. BEGIN_INTERFACE_PART(OleObject, IOleObject)
  1076. INIT_INTERFACE_PART(COleServerDoc, OleObject)
  1077. STDMETHOD(SetClientSite)(LPOLECLIENTSITE);
  1078. STDMETHOD(GetClientSite)(LPOLECLIENTSITE*);
  1079. STDMETHOD(SetHostNames)(LPCOLESTR, LPCOLESTR);
  1080. STDMETHOD(Close)(DWORD);
  1081. STDMETHOD(SetMoniker)(DWORD, LPMONIKER);
  1082. STDMETHOD(GetMoniker)(DWORD, DWORD, LPMONIKER*);
  1083. STDMETHOD(InitFromData)(LPDATAOBJECT, BOOL, DWORD);
  1084. STDMETHOD(GetClipboardData)(DWORD, LPDATAOBJECT*);
  1085. STDMETHOD(DoVerb)(LONG, LPMSG, LPOLECLIENTSITE, LONG, HWND, LPCRECT);
  1086. STDMETHOD(EnumVerbs)(IEnumOLEVERB**);
  1087. STDMETHOD(Update)();
  1088. STDMETHOD(IsUpToDate)();
  1089. STDMETHOD(GetUserClassID)(CLSID*);
  1090. STDMETHOD(GetUserType)(DWORD, LPOLESTR*);
  1091. STDMETHOD(SetExtent)(DWORD, LPSIZEL);
  1092. STDMETHOD(GetExtent)(DWORD, LPSIZEL);
  1093. STDMETHOD(Advise)(LPADVISESINK, LPDWORD);
  1094. STDMETHOD(Unadvise)(DWORD);
  1095. STDMETHOD(EnumAdvise)(LPENUMSTATDATA*);
  1096. STDMETHOD(GetMiscStatus)(DWORD, LPDWORD);
  1097. STDMETHOD(SetColorScheme)(LPLOGPALETTE);
  1098. END_INTERFACE_PART(OleObject)
  1099. BEGIN_INTERFACE_PART(DataObject, IDataObject)
  1100. INIT_INTERFACE_PART(COleServerDoc, DataObject)
  1101. STDMETHOD(GetData)(LPFORMATETC, LPSTGMEDIUM);
  1102. STDMETHOD(GetDataHere)(LPFORMATETC, LPSTGMEDIUM);
  1103. STDMETHOD(QueryGetData)(LPFORMATETC);
  1104. STDMETHOD(GetCanonicalFormatEtc)(LPFORMATETC, LPFORMATETC);
  1105. STDMETHOD(SetData)(LPFORMATETC, LPSTGMEDIUM, BOOL);
  1106. STDMETHOD(EnumFormatEtc)(DWORD, LPENUMFORMATETC*);
  1107. STDMETHOD(DAdvise)(LPFORMATETC, DWORD, LPADVISESINK, LPDWORD);
  1108. STDMETHOD(DUnadvise)(DWORD);
  1109. STDMETHOD(EnumDAdvise)(LPENUMSTATDATA*);
  1110. END_INTERFACE_PART(DataObject)
  1111. BEGIN_INTERFACE_PART(OleInPlaceObject, IOleInPlaceObject)
  1112. INIT_INTERFACE_PART(COleServerDoc, OleInPlaceObject)
  1113. STDMETHOD(GetWindow)(HWND*);
  1114. STDMETHOD(ContextSensitiveHelp)(BOOL);
  1115. STDMETHOD(InPlaceDeactivate)();
  1116. STDMETHOD(UIDeactivate)();
  1117. STDMETHOD(SetObjectRects)(LPCRECT, LPCRECT);
  1118. STDMETHOD(ReactivateAndUndo)();
  1119. END_INTERFACE_PART(OleInPlaceObject)
  1120. BEGIN_INTERFACE_PART(OleInPlaceActiveObject, IOleInPlaceActiveObject)
  1121. INIT_INTERFACE_PART(COleServerDoc, OleInPlaceActiveObject)
  1122. STDMETHOD(GetWindow)(HWND*);
  1123. STDMETHOD(ContextSensitiveHelp)(BOOL);
  1124. STDMETHOD(TranslateAccelerator)(LPMSG);
  1125. STDMETHOD(OnFrameWindowActivate)(BOOL);
  1126. STDMETHOD(OnDocWindowActivate)(BOOL);
  1127. STDMETHOD(ResizeBorder)(LPCRECT, LPOLEINPLACEUIWINDOW, BOOL);
  1128. STDMETHOD(EnableModeless)(BOOL);
  1129. END_INTERFACE_PART(OleInPlaceActiveObject)
  1130. DECLARE_INTERFACE_MAP()
  1131. friend class COleServer;
  1132. friend class COleServerItem;
  1133. friend class CDocObjectServer;
  1134. };
  1135. //////////////////////////////////////////////////////////////////////////////
  1136. // COleIPFrameWnd
  1137. class COleCntrFrameWnd;
  1138. class COleIPFrameWnd : public CFrameWnd
  1139. {
  1140. DECLARE_DYNCREATE(COleIPFrameWnd)
  1141. // Constructors
  1142. public:
  1143. COleIPFrameWnd();
  1144. // Overridables
  1145. public:
  1146. virtual BOOL OnCreateControlBars(CWnd* pWndFrame, CWnd* pWndDoc);
  1147. // create control bars on container windows (pWndDoc can be NULL)
  1148. virtual BOOL OnCreateControlBars(CFrameWnd* pWndFrame, CFrameWnd* pWndDoc);
  1149. // create control bars on container windows (pWndDoc can be NULL)
  1150. virtual void RepositionFrame(LPCRECT lpPosRect, LPCRECT lpClipRect);
  1151. // Advanced: reposition frame to wrap around new lpPosRect
  1152. // Implementation
  1153. public:
  1154. BOOL m_bUIActive; // TRUE if currently in uiacitve state
  1155. virtual BOOL LoadFrame(UINT nIDResource,
  1156. DWORD dwDefaultStyle = WS_CHILD|WS_BORDER|WS_CLIPSIBLINGS,
  1157. CWnd* pParentWnd = NULL,
  1158. CCreateContext* pContext = NULL);
  1159. virtual void RecalcLayout(BOOL bNotify = TRUE);
  1160. virtual BOOL PreTranslateMessage(MSG* pMsg);
  1161. virtual LRESULT OnSetMessageString(WPARAM wParam, LPARAM lParam);
  1162. virtual ~COleIPFrameWnd();
  1163. #ifdef _DEBUG
  1164. virtual void AssertValid() const;
  1165. virtual void Dump(CDumpContext& dc) const;
  1166. #endif
  1167. protected:
  1168. // in-place state
  1169. OLEINPLACEFRAMEINFO m_frameInfo;
  1170. LPOLEINPLACEFRAME m_lpFrame;
  1171. LPOLEINPLACEUIWINDOW m_lpDocFrame;
  1172. COleCntrFrameWnd* m_pMainFrame;
  1173. COleCntrFrameWnd* m_pDocFrame;
  1174. HMENU m_hSharedMenu;
  1175. OLEMENUGROUPWIDTHS m_menuWidths;
  1176. HOLEMENU m_hOleMenu;
  1177. CRect m_rectPos; // client area rect of the item
  1178. CRect m_rectClip; // area to which frame should be clipped
  1179. BOOL m_bInsideRecalc;
  1180. #if _MFC_VER >= 0x0600
  1181. HMENU _m_Reserved;
  1182. #else
  1183. HMENU m_hMenuHelpPopup; // shared Help menu for DocObjects
  1184. #endif
  1185. // Advanced: in-place activation virtual implementation
  1186. virtual BOOL BuildSharedMenu();
  1187. virtual void DestroySharedMenu();
  1188. virtual HMENU GetInPlaceMenu();
  1189. // Advanced: possible override to change in-place sizing behavior
  1190. virtual void OnRequestPositionChange(LPCRECT lpRect);
  1191. protected:
  1192. //{{AFX_MSG(COleIPFrameWnd)
  1193. afx_msg void OnSize(UINT nType, int cx, int cy);
  1194. afx_msg LRESULT OnRecalcParent(WPARAM wParam, LPARAM lParam);
  1195. afx_msg void OnIdleUpdateCmdUI();
  1196. afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
  1197. afx_msg void OnDestroy();
  1198. afx_msg LRESULT OnResizeChild(WPARAM wParam, LPARAM lParam);
  1199. afx_msg void OnContextHelp();
  1200. afx_msg void OnUpdateControlBarMenu(CCmdUI* pCmdUI);
  1201. afx_msg BOOL OnBarCheck(UINT nID);
  1202. afx_msg void OnWindowPosChanging(LPWINDOWPOS lpWndPos);
  1203. //}}AFX_MSG
  1204. DECLARE_MESSAGE_MAP()
  1205. friend class COleServerDoc;
  1206. friend class COleCntrFrameWnd;
  1207. friend class CDocObjectServer;
  1208. };
  1209. /////////////////////////////////////////////////////////////////////////////
  1210. // COleResizeBar - supports in-place resizing in server applications
  1211. class COleResizeBar : public CControlBar
  1212. {
  1213. DECLARE_DYNAMIC(COleResizeBar)
  1214. // Constructors
  1215. public:
  1216. COleResizeBar();
  1217. BOOL Create(CWnd* pParentWnd, DWORD dwStyle = WS_CHILD | WS_VISIBLE,
  1218. UINT nID = AFX_IDW_RESIZE_BAR);
  1219. // Implementation
  1220. public:
  1221. virtual ~COleResizeBar();
  1222. virtual void OnUpdateCmdUI(CFrameWnd* pTarget, BOOL bDisableIfNoHndler);
  1223. protected:
  1224. CRectTracker m_tracker; // implemented with a tracker
  1225. protected:
  1226. //{{AFX_MSG(COleResizeBar)
  1227. afx_msg BOOL OnEraseBkgnd(CDC* pDC);
  1228. afx_msg void OnPaint();
  1229. afx_msg void OnSize(UINT nType, int cx, int cy);
  1230. afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
  1231. afx_msg void OnLButtonDown(UINT, CPoint point);
  1232. afx_msg LRESULT OnSizeParent(WPARAM wParam, LPARAM lParam);
  1233. //}}AFX_MSG
  1234. DECLARE_MESSAGE_MAP()
  1235. };
  1236. /////////////////////////////////////////////////////////////////////////////
  1237. // COleStreamFile - implementation of CFile which uses an IStream
  1238. class COleStreamFile : public CFile
  1239. {
  1240. DECLARE_DYNAMIC(COleStreamFile)
  1241. // Constructors and Destructors
  1242. public:
  1243. COleStreamFile(LPSTREAM lpStream = NULL);
  1244. // Operations
  1245. // Note: OpenStream and CreateStream can accept eith STGM_ flags or
  1246. // CFile::OpenFlags bits since common values are guaranteed to have
  1247. // the same semantics.
  1248. BOOL OpenStream(LPSTORAGE lpStorage, LPCTSTR lpszStreamName,
  1249. DWORD nOpenFlags = modeReadWrite|shareExclusive,
  1250. CFileException* pError = NULL);
  1251. BOOL CreateStream(LPSTORAGE lpStorage, LPCTSTR lpszStreamName,
  1252. DWORD nOpenFlags = modeReadWrite|shareExclusive|modeCreate,
  1253. CFileException* pError = NULL);
  1254. BOOL CreateMemoryStream(CFileException* pError = NULL);
  1255. // attach & detach can be used when Open/Create functions aren't adequate
  1256. void Attach(LPSTREAM lpStream);
  1257. LPSTREAM Detach();
  1258. IStream* GetStream() const;
  1259. // Returns the current stream
  1260. // Implementation
  1261. public:
  1262. LPSTREAM m_lpStream;
  1263. #ifdef _DEBUG
  1264. virtual void AssertValid() const;
  1265. virtual void Dump(CDumpContext& dc) const;
  1266. #endif
  1267. virtual ~COleStreamFile();
  1268. // attributes for implementation
  1269. BOOL GetStatus(CFileStatus& rStatus) const;
  1270. virtual DWORD GetPosition() const;
  1271. virtual const CString GetStorageName() const;
  1272. // overrides for implementation
  1273. virtual CFile* Duplicate() const;
  1274. virtual LONG Seek(LONG lOff, UINT nFrom);
  1275. virtual void SetLength(DWORD dwNewLen);
  1276. virtual DWORD GetLength() const;
  1277. virtual UINT Read(void* lpBuf, UINT nCount);
  1278. virtual void Write(const void* lpBuf, UINT nCount);
  1279. virtual void LockRange(DWORD dwPos, DWORD dwCount);
  1280. virtual void UnlockRange(DWORD dwPos, DWORD dwCount);
  1281. virtual void Abort();
  1282. virtual void Flush();
  1283. virtual void Close();
  1284. protected:
  1285. CString m_strStorageName;
  1286. };
  1287. /////////////////////////////////////////////////////////////////////////////
  1288. // CMonikerFile - implementation of COleStreamFile that uses an IMoniker to
  1289. // get the IStream
  1290. class CMonikerFile: public COleStreamFile
  1291. {
  1292. DECLARE_DYNAMIC(CMonikerFile)
  1293. public:
  1294. CMonikerFile();
  1295. virtual BOOL Open(LPCTSTR lpszURL, CFileException* pError=NULL);
  1296. // Uses synchronous URLMonikers to create a moniker.
  1297. // Opens the URL specified.
  1298. // If provided, pError will be set in case of error.
  1299. // Return value: TRUE if successful, FALSE otherwise.
  1300. virtual BOOL Open(IMoniker* pMoniker, CFileException* pError=NULL);
  1301. // Binds to the provided moniker to obtain a stream.
  1302. // If provided, pError will be set in case of error.
  1303. // Return value: TRUE if successful, FALSE otherwise.
  1304. virtual void Close();
  1305. // Detaches the stream, Release()s it, and the moniker. Close may be
  1306. // called on unopened, or already closed streams.
  1307. BOOL Detach(CFileException* pError = NULL);
  1308. // Closes the stream. If there is an error when closing, then the
  1309. // error code will be placed in pError and the function will return FALSE.
  1310. IMoniker* GetMoniker() const;
  1311. // Returns the current moniker. The moniker returned is not AddRef()'ed.
  1312. protected:
  1313. // Overidables
  1314. IBindCtx* CreateBindContext(CFileException* pError);
  1315. // A hook so users can provide a particular IBindCtx, potentially one
  1316. // on which the user has registered one or more objects.
  1317. // Implementation
  1318. protected:
  1319. virtual BOOL Open(LPCTSTR lpszUrl, IBindHost* pBindHost,
  1320. IBindStatusCallback* pBSC, IBindCtx* pBindCtx, CFileException* pError);
  1321. BOOL Attach(LPCTSTR lpszUrl, IBindHost* pBindHost,
  1322. IBindStatusCallback* pBSC, IBindCtx* pBindCtx, CFileException* pError);
  1323. virtual BOOL Open(IMoniker* pMoniker, IBindHost* pBindHost,
  1324. IBindStatusCallback* pBSC, IBindCtx* pBindCtx, CFileException* pError);
  1325. BOOL Attach(IMoniker* pMoniker, IBindHost* pBindHost,
  1326. IBindStatusCallback* pBSC, IBindCtx* pBindCtx, CFileException* pError);
  1327. virtual BOOL PostBindToStream(CFileException* pError);
  1328. static IBindHost* CreateBindHost();
  1329. public:
  1330. virtual ~CMonikerFile();
  1331. // Closes the stream, and releases the moniker if needed.
  1332. virtual void Flush();
  1333. #ifdef _DEBUG
  1334. virtual void AssertValid() const;
  1335. virtual void Dump(CDumpContext& dc) const;
  1336. // Calls COleStreamFile::Dump(), and prints out moniker value.
  1337. #endif
  1338. protected:
  1339. IPTR(IMoniker) m_Moniker;
  1340. // The moniker provided or created to which this class is bound.
  1341. CMonikerFile(const CMonikerFile&);
  1342. // Prevents copying.
  1343. };
  1344. /////////////////////////////////////////////////////////////////////////////
  1345. // CAsyncMonikerFile - implementation of COleStreamFile that uses an
  1346. // asynchronous IMoniker to get the IStream
  1347. class _AfxBindStatusCallback; // Forward declaration
  1348. class CAsyncMonikerFile: public CMonikerFile
  1349. {
  1350. DECLARE_DYNAMIC(CAsyncMonikerFile)
  1351. public:
  1352. CAsyncMonikerFile();
  1353. // Creates the IBindStatusCallback used internally to provide asynchronous
  1354. // operation.
  1355. //All Open overloads call one of these two.
  1356. virtual BOOL Open(LPCTSTR lpszURL, IBindHost* pBindHost,
  1357. CFileException* pError=NULL);
  1358. virtual BOOL Open(IMoniker* pMoniker, IBindHost* pBindHost,
  1359. CFileException* pError=NULL);
  1360. //Open overloads that take monikers
  1361. virtual BOOL Open(IMoniker* pMoniker, CFileException* pError=NULL);
  1362. virtual BOOL Open(IMoniker* pMoniker, IServiceProvider* pServiceProvider,
  1363. CFileException* pError=NULL);
  1364. virtual BOOL Open(IMoniker* pMoniker, IUnknown* pUnknown,
  1365. CFileException* pError=NULL);
  1366. //Open overloads that take strings
  1367. virtual BOOL Open(LPCTSTR lpszURL, CFileException* pError=NULL);
  1368. virtual BOOL Open(LPCTSTR lpszURL, IServiceProvider* pServiceProvider,
  1369. CFileException* pError=NULL);
  1370. virtual BOOL Open(LPCTSTR lpszURL, IUnknown* pUnknown,
  1371. CFileException* pError=NULL);
  1372. virtual void Close();
  1373. IBinding* GetBinding() const;
  1374. // Returns the binding provided when the asychronous transfer begins.
  1375. // With the IBinding*, the user may abort, or pause the transfer.
  1376. // NULL may be returned if for any reason the transfer could not be
  1377. // made asynchronous, or if the IBinding* has not yet been provided by
  1378. // the system.
  1379. FORMATETC* GetFormatEtc() const;
  1380. // Returns the FORMATETC for the currently opened stream. NULL will be
  1381. // returned if this is called from outside the context of OnDataAvailable.
  1382. // If you want to keep the FORMATETC beyond this call, make a copy of it.
  1383. // The FORMATETC indicates the format of the data in the stream.
  1384. protected:
  1385. // Overidables
  1386. virtual IUnknown* CreateBindStatusCallback(IUnknown* pUnkControlling);
  1387. virtual DWORD GetBindInfo() const;
  1388. // Returns the settings returned by IBindStatusCallback::GetBindInfo.
  1389. // The default values returned should work for most cases and should not
  1390. // be changed lightly.
  1391. virtual LONG GetPriority() const;
  1392. // Returns the priority at which the asynchronous transfer will take
  1393. // place. The value is one of the standard thread priority flags.
  1394. // By default THREAD_PRIORITY_NORMAL is returned.
  1395. virtual void OnDataAvailable(DWORD dwSize, DWORD bscfFlag);
  1396. // Called when there is data available to be read. dwSize indicates
  1397. // the cumulative number of bytes which can be read. The bscfFlag may be used
  1398. // to identify first, last, and intermediate blocks of data.
  1399. virtual void OnLowResource();
  1400. // This is called when resources are low.
  1401. virtual void OnStartBinding();
  1402. // Called when the binding is starting up.
  1403. virtual void OnProgress(ULONG ulProgress, ULONG ulProgressMax,
  1404. ULONG ulStatusCode, LPCTSTR szStatusText);
  1405. virtual void OnStopBinding(HRESULT hresult, LPCTSTR szError);
  1406. // Called when the transfer is stopped. This function releases the
  1407. // IBinding and should nearly always be call when overidden.
  1408. // Implementation
  1409. public:
  1410. virtual ~CAsyncMonikerFile();
  1411. #ifdef _DEBUG
  1412. virtual void AssertValid() const;
  1413. virtual void Dump(CDumpContext& dc) const;
  1414. // Calls CMonikerFile::Dump(), and prints out IBinding,
  1415. // IBindStatusCallback, and m_pFormatEtc values.
  1416. #endif
  1417. virtual UINT Read(void* lpBuf, UINT nCount);
  1418. protected:
  1419. friend class _AfxBindStatusCallback;
  1420. _AfxBindStatusCallback* m_pAfxBSCCurrent;
  1421. BOOL m_bStopBindingReceived;
  1422. void EndCallbacks();
  1423. IPTR(IBinding) m_Binding;
  1424. FORMATETC* m_pFormatEtc;
  1425. void SetBinding(IBinding* pBinding);
  1426. // Sets and AddRefs m_Binding
  1427. void SetFormatEtc(FORMATETC* pFormatEtc);
  1428. // Sets the FORMATETC for the current stream.
  1429. virtual BOOL PostBindToStream(CFileException* pError);
  1430. };
  1431. /////////////////////////////////////////////////////////////////////////////
  1432. // COleDropSource (advanced drop source support)
  1433. class COleDropSource : public CCmdTarget
  1434. {
  1435. // Constructors
  1436. public:
  1437. COleDropSource();
  1438. // Overridables
  1439. virtual SCODE QueryContinueDrag(BOOL bEscapePressed, DWORD dwKeyState);
  1440. virtual SCODE GiveFeedback(DROPEFFECT dropEffect);
  1441. virtual BOOL OnBeginDrag(CWnd* pWnd);
  1442. // Implementation
  1443. public:
  1444. #ifdef _DEBUG
  1445. virtual void Dump(CDumpContext& dc) const;
  1446. #endif
  1447. public:
  1448. BEGIN_INTERFACE_PART(DropSource, IDropSource)
  1449. INIT_INTERFACE_PART(COleDropSource, DropSource)
  1450. STDMETHOD(QueryContinueDrag)(BOOL, DWORD);
  1451. STDMETHOD(GiveFeedback)(DWORD);
  1452. END_INTERFACE_PART(DropSource)
  1453. DECLARE_INTERFACE_MAP()
  1454. CRect m_rectStartDrag; // when mouse leaves this rect, drag drop starts
  1455. BOOL m_bDragStarted; // has drag really started yet?
  1456. DWORD m_dwButtonCancel; // which button will cancel (going down)
  1457. DWORD m_dwButtonDrop; // which button will confirm (going up)
  1458. // metrics for drag start determination
  1459. static AFX_DATA UINT nDragMinDist; // min. amount mouse must move for drag
  1460. static AFX_DATA UINT nDragDelay; // delay before drag starts
  1461. friend class COleDataSource;
  1462. };
  1463. /////////////////////////////////////////////////////////////////////////////
  1464. // COleDropTarget (advanced drop target support)
  1465. class COleDropTarget : public CCmdTarget
  1466. {
  1467. // Constructors
  1468. public:
  1469. COleDropTarget();
  1470. // Operations
  1471. BOOL Register(CWnd* pWnd);
  1472. virtual void Revoke(); // virtual for implementation
  1473. // Overridables
  1474. virtual DROPEFFECT OnDragEnter(CWnd* pWnd, COleDataObject* pDataObject,
  1475. DWORD dwKeyState, CPoint point);
  1476. virtual DROPEFFECT OnDragOver(CWnd* pWnd, COleDataObject* pDataObject,
  1477. DWORD dwKeyState, CPoint point);
  1478. virtual BOOL OnDrop(CWnd* pWnd, COleDataObject* pDataObject,
  1479. DROPEFFECT dropEffect, CPoint point);
  1480. virtual DROPEFFECT OnDropEx(CWnd* pWnd, COleDataObject* pDataObject,
  1481. DROPEFFECT dropDefault, DROPEFFECT dropList, CPoint point);
  1482. virtual void OnDragLeave(CWnd* pWnd);
  1483. virtual DROPEFFECT OnDragScroll(CWnd* pWnd, DWORD dwKeyState,
  1484. CPoint point);
  1485. // Implementation
  1486. public:
  1487. virtual ~COleDropTarget();
  1488. #ifdef _DEBUG
  1489. virtual void AssertValid() const;
  1490. virtual void Dump(CDumpContext& dc) const;
  1491. #endif
  1492. protected:
  1493. HWND m_hWnd; // HWND this IDropTarget is attached to
  1494. LPDATAOBJECT m_lpDataObject; // != NULL between OnDragEnter, OnDragLeave
  1495. UINT m_nTimerID; // != MAKEWORD(-1, -1) when in scroll area
  1496. DWORD m_dwLastTick; // only valid when m_nTimerID valid
  1497. UINT m_nScrollDelay; // time to next scroll
  1498. // metrics for drag-scrolling
  1499. static AFX_DATA int nScrollInset;
  1500. static AFX_DATA UINT nScrollDelay;
  1501. static AFX_DATA UINT nScrollInterval;
  1502. // implementation helpers
  1503. void SetupTimer(CView* pView, UINT nTimerID);
  1504. void CancelTimer(CWnd* pWnd);
  1505. // Interface Maps
  1506. public:
  1507. BEGIN_INTERFACE_PART(DropTarget, IDropTarget)
  1508. INIT_INTERFACE_PART(COleDropTarget, DropTarget)
  1509. STDMETHOD(DragEnter)(LPDATAOBJECT, DWORD, POINTL, LPDWORD);
  1510. STDMETHOD(DragOver)(DWORD, POINTL, LPDWORD);
  1511. STDMETHOD(DragLeave)();
  1512. STDMETHOD(Drop)(LPDATAOBJECT, DWORD, POINTL pt, LPDWORD);
  1513. END_INTERFACE_PART(DropTarget)
  1514. DECLARE_INTERFACE_MAP()
  1515. };
  1516. /////////////////////////////////////////////////////////////////////////////
  1517. // COleMessageFilter (implements IMessageFilter)
  1518. class COleMessageFilter : public CCmdTarget
  1519. {
  1520. // Constructors
  1521. public:
  1522. COleMessageFilter();
  1523. // Operations
  1524. BOOL Register();
  1525. void Revoke();
  1526. // for controlling the busy state of the server application (called app)
  1527. virtual void BeginBusyState();
  1528. virtual void EndBusyState();
  1529. void SetBusyReply(SERVERCALL nBusyReply);
  1530. // for controlling actions taken against rejected/retried calls
  1531. void SetRetryReply(DWORD nRetryReply = 0);
  1532. // only used when the "not responding" dialog is disabled
  1533. void SetMessagePendingDelay(DWORD nTimeout = 5000);
  1534. // used to determine amount of time before significant message
  1535. void EnableBusyDialog(BOOL bEnableBusy = TRUE);
  1536. void EnableNotRespondingDialog(BOOL bEnableNotResponding = TRUE);
  1537. // used to enable/disable the two types of busy dialogs
  1538. // Overridables
  1539. virtual BOOL OnMessagePending(const MSG* pMsg);
  1540. // return TRUE to eat the message (usually only if processed)
  1541. // Implementation
  1542. public:
  1543. #ifdef _DEBUG
  1544. virtual void AssertValid() const;
  1545. virtual void Dump(CDumpContext& dc) const;
  1546. #endif
  1547. virtual ~COleMessageFilter();
  1548. virtual BOOL IsSignificantMessage(MSG* pMsg);
  1549. // determine if any significant messages are present in the queue
  1550. virtual int OnBusyDialog(HTASK htaskBusy);
  1551. virtual int OnNotRespondingDialog(HTASK htaskBusy);
  1552. // these functions display the busy dialog
  1553. protected:
  1554. BOOL m_bRegistered;
  1555. LONG m_nBusyCount; // for BeginBusyState & EndBusyState
  1556. BOOL m_bEnableBusy;
  1557. BOOL m_bEnableNotResponding;
  1558. BOOL m_bUnblocking;
  1559. DWORD m_nRetryReply; // only used if m_bEnableNotResponding == FALSE
  1560. DWORD m_nBusyReply;
  1561. DWORD m_nTimeout;
  1562. // Interface Maps
  1563. public:
  1564. BEGIN_INTERFACE_PART(MessageFilter, IMessageFilter)
  1565. INIT_INTERFACE_PART(COleMessageFilter, MessageFilter)
  1566. STDMETHOD_(DWORD, HandleInComingCall)(DWORD, HTASK, DWORD,
  1567. LPINTERFACEINFO);
  1568. STDMETHOD_(DWORD, RetryRejectedCall)(HTASK, DWORD, DWORD);
  1569. STDMETHOD_(DWORD, MessagePending)(HTASK, DWORD, DWORD);
  1570. END_INTERFACE_PART(MessageFilter)
  1571. DECLARE_INTERFACE_MAP()
  1572. };
  1573. /////////////////////////////////////////////////////////////////////////////
  1574. // message map entries for OLE verbs
  1575. #define ON_STDOLEVERB(iVerb, memberFxn) \
  1576. { 0xC002, 0, (UINT)iVerb, (UINT)iVerb, (UINT)-1, \
  1577. (AFX_PMSG)(BOOL (AFX_MSG_CALL CCmdTarget::*)(LPMSG, HWND, LPCRECT))&memberFxn },
  1578. #define ON_OLEVERB(idsVerbName, memberFxn) \
  1579. { 0xC002, 0, 1, 1, idsVerbName, \
  1580. (AFX_PMSG)(BOOL (AFX_MSG_CALL CCmdTarget::*)(LPMSG, HWND, LPCRECT))&memberFxn },
  1581. /////////////////////////////////////////////////////////////////////////////
  1582. // global helpers and debugging
  1583. void AFXAPI AfxOleSetEditMenu(COleClientItem* pClient, CMenu* pMenu,
  1584. UINT iMenuItem, UINT nIDVerbMin, UINT nIDVerbMax = 0, UINT nIDConvert = 0);
  1585. #ifdef _DEBUG
  1586. // Mapping SCODEs to readable text
  1587. LPCTSTR AFXAPI AfxGetFullScodeString(SCODE sc);
  1588. LPCTSTR AFXAPI AfxGetScodeString(SCODE sc);
  1589. LPCTSTR AFXAPI AfxGetScodeRangeString(SCODE sc);
  1590. LPCTSTR AFXAPI AfxGetSeverityString(SCODE sc);
  1591. LPCTSTR AFXAPI AfxGetFacilityString(SCODE sc);
  1592. // Mapping IIDs to readable text
  1593. LPCTSTR AFXAPI AfxGetIIDString(REFIID iid);
  1594. #endif
  1595. /////////////////////////////////////////////////////////////////////////////
  1596. // Inline function declarations
  1597. #ifdef _AFX_PACKING
  1598. #pragma pack(pop)
  1599. #endif
  1600. #ifdef _AFX_ENABLE_INLINES
  1601. #define _AFXOLE_INLINE AFX_INLINE
  1602. #define _AFXOLECLI_INLINE AFX_INLINE
  1603. #define _AFXOLESVR_INLINE AFX_INLINE
  1604. #define _AFXOLEDOBJ_INLINE AFX_INLINE
  1605. #define _AFXOLEMONIKER_INLINE AFX_INLINE
  1606. #include <afxole.inl>
  1607. #undef _AFXOLE_INLINE
  1608. #undef _AFXOLECLI_INLINE
  1609. #undef _AFXOLESVR_INLINE
  1610. #undef _AFXOLEDOBJ_INLINE
  1611. #undef _AFXOLEMONIKER_INLINE
  1612. #endif
  1613. #undef AFX_DATA
  1614. #define AFX_DATA
  1615. #ifdef _AFX_MINREBUILD
  1616. #pragma component(minrebuild, on)
  1617. #endif
  1618. #ifndef _AFX_FULLTYPEINFO
  1619. #pragma component(mintypeinfo, off)
  1620. #endif
  1621. #endif //__AFXOLE_H__
  1622. /////////////////////////////////////////////////////////////////////////////