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.

1564 lines
54 KiB

  1. // Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1993 Microsoft Corporation,
  3. // All rights reserved.
  4. // This source code is only intended as a supplement to the
  5. // Microsoft Foundation Classes Reference and Microsoft
  6. // QuickHelp and/or WinHelp documentation provided with the library.
  7. // See these sources for detailed information regarding the
  8. // Microsoft Foundation Classes product.
  9. #ifndef __AFXOLE_H__
  10. #define __AFXOLE_H__
  11. #ifndef __AFXEXT_H__
  12. #include <afxext.h>
  13. #endif
  14. #ifndef __AFXDISP_H__
  15. #include <afxdisp.h>
  16. #endif
  17. // include OLE 2.0 Compound Document interfaces
  18. #define FARSTRUCT
  19. #include <ole2.h>
  20. /////////////////////////////////////////////////////////////////////////////
  21. // AFXOLE.H - MFC OLE support
  22. // Classes declared in this file
  23. //CDocument
  24. class COleDocument; // OLE container document
  25. class COleLinkingDoc; // supports links to embeddings
  26. class COleServerDoc; // OLE server document
  27. //CCmdTarget
  28. class CDocItem; // part of a document
  29. class COleClientItem; // embedded ole object from outside
  30. class COleServerItem; // ole object to export
  31. class COleDataSource; // clipboard data source mechanism
  32. class COleDropSource; // drag/drop source
  33. class COleDropTarget; // drag/drop target
  34. class COleMessageFilter; // concurrency management
  35. //CFrameWnd
  36. class COleIPFrameWnd; // frame window for in-place servers
  37. //CControlBar
  38. class COleResizeBar; // implements in-place resizing
  39. //CFile
  40. class COleStreamFile; // CFile wrapper for IStream interface
  41. class COleDataObject; // wrapper for IDataObject interface
  42. /////////////////////////////////////////////////////////////////////////////
  43. // AFXDLL support
  44. #undef AFXAPP_DATA
  45. #define AFXAPP_DATA AFXAPIEX_DATA
  46. /////////////////////////////////////////////////////////////////////////////
  47. // backward compatibility
  48. // COleClientDoc is now obsolete -- use COleDocument instead
  49. #define COleClientDoc COleDocument
  50. // COleServer has been replaced by the more general COleObjectFactory
  51. #define COleServer COleObjectFactory
  52. /////////////////////////////////////////////////////////////////////////////
  53. // Useful OLE specific types (some from OLE 1.0 headers)
  54. // Codes for CallBack events
  55. enum OLE_NOTIFICATION
  56. {
  57. OLE_CHANGED, // representation of a draw aspect has changed
  58. OLE_SAVED, // the item has committed its storage
  59. OLE_CLOSED, // the item has closed
  60. OLE_RENAMED, // the item has changed its moniker
  61. OLE_CHANGED_STATE, // the item state (open, active, etc.) has changed
  62. OLE_CHANGED_ASPECT, // the item draw aspect has changed
  63. };
  64. // Object types
  65. enum OLE_OBJTYPE
  66. {
  67. OT_UNKNOWN = 0,
  68. // These are OLE 1.0 types and OLE 2.0 types as returned from GetType().
  69. OT_LINK = 1,
  70. OT_EMBEDDED = 2,
  71. OT_STATIC = 3,
  72. // All OLE2 objects are written with this tag when serialized. This
  73. // differentiates them from OLE 1.0 objects written with MFC 2.0.
  74. // This value will never be returned from GetType().
  75. OT_OLE2 = 256,
  76. };
  77. /////////////////////////////////////////////////////////////////////////////
  78. // COleDataObject -- simple wrapper for IDataObject
  79. class COleDataObject
  80. {
  81. // Constructors
  82. public:
  83. COleDataObject();
  84. // Operations
  85. void Attach(LPDATAOBJECT lpDataObject, BOOL bAutoRelease = TRUE);
  86. LPDATAOBJECT Detach(); // detach and get ownership of m_lpDataObject
  87. void Release(); // detach and Release ownership of m_lpDataObject
  88. BOOL AttachClipboard(); // attach to current clipboard object
  89. // Attributes
  90. void BeginEnumFormats();
  91. BOOL GetNextFormat(LPFORMATETC lpFormatEtc);
  92. CFile* GetFileData(CLIPFORMAT cfFormat, LPFORMATETC lpFormatEtc = NULL);
  93. HGLOBAL GetGlobalData(CLIPFORMAT cfFormat, LPFORMATETC lpFormatEtc = NULL);
  94. BOOL GetData(CLIPFORMAT cfFormat, LPSTGMEDIUM lpStgMedium,
  95. LPFORMATETC lpFormatEtc = NULL);
  96. BOOL IsDataAvailable(CLIPFORMAT cfFormat, LPFORMATETC lpFormatEtc = NULL);
  97. // Implementation
  98. public:
  99. LPDATAOBJECT m_lpDataObject;
  100. LPENUMFORMATETC m_lpEnumerator;
  101. ~COleDataObject();
  102. protected:
  103. BOOL m_bAutoRelease; // TRUE if destructor should call Release
  104. private:
  105. // Disable the copy constructor and assignment by default so you will get
  106. // compiler errors instead of unexpected behaviour if you pass objects
  107. // by value or assign objects.
  108. COleDataObject(const COleDataObject&); // no implementation
  109. void operator=(const COleDataObject&); // no implementation
  110. };
  111. /////////////////////////////////////////////////////////////////////////////
  112. // COleDataSource -- wrapper for implementing IDataObject
  113. // (works similar to how data is provided on the clipboard)
  114. struct AFX_DATACACHE_ENTRY;
  115. class COleDropSource;
  116. class COleDataSource : public CCmdTarget
  117. {
  118. // Constructors
  119. public:
  120. COleDataSource();
  121. // Operations
  122. void Empty(); // empty cache (similar to ::EmptyClipboard)
  123. // CacheData & DelayRenderData operations similar to ::SetClipboardData
  124. void CacheGlobalData(CLIPFORMAT cfFormat, HGLOBAL hGlobal,
  125. LPFORMATETC lpFormatEtc = NULL); // for HGLOBAL based data
  126. void DelayRenderFileData(CLIPFORMAT cfFormat,
  127. LPFORMATETC lpFormatEtc = NULL); // for CFile* based delayed render
  128. // Clipboard and Drag/Drop access
  129. DROPEFFECT DoDragDrop(
  130. DWORD dwEffects = DROPEFFECT_COPY|DROPEFFECT_MOVE|DROPEFFECT_LINK,
  131. LPCRECT lpRectStartDrag = NULL,
  132. COleDropSource* pDropSource = NULL);
  133. void SetClipboard();
  134. static void PASCAL FlushClipboard();
  135. static COleDataSource* PASCAL GetClipboardOwner();
  136. // Advanced: STGMEDIUM based cached data
  137. void CacheData(CLIPFORMAT cfFormat, LPSTGMEDIUM lpStgMedium,
  138. LPFORMATETC lpFormatEtc = NULL); // for LPSTGMEDIUM based data
  139. // Advanced: STGMEDIUM or HGLOBAL based delayed render
  140. void DelayRenderData(CLIPFORMAT cfFormat, LPFORMATETC lpFormatEtc = NULL);
  141. // Advanced: support for SetData in COleServerItem
  142. // (not generally useful for clipboard or drag/drop operations)
  143. void DelaySetData(CLIPFORMAT cfFormat, LPFORMATETC lpFormatEtc = NULL);
  144. // Overidables
  145. virtual BOOL OnRenderGlobalData(LPFORMATETC lpFormatEtc, HGLOBAL* phGlobal);
  146. virtual BOOL OnRenderFileData(LPFORMATETC lpFormatEtc, CFile* pFile);
  147. virtual BOOL OnRenderData(LPFORMATETC lpFormatEtc, LPSTGMEDIUM lpStgMedium);
  148. // OnRenderFileData and OnRenderGlobalData are called by
  149. // the default implementation of OnRenderData.
  150. #ifdef _AFXCTL
  151. virtual BOOL OnSetData(LPFORMATETC lpFormatEtc, LPSTGMEDIUM lpStgMedium,
  152. BOOL fRelease);
  153. #else
  154. virtual BOOL OnSetData(LPFORMATETC lpFormatEtc, LPSTGMEDIUM lpStgMedium);
  155. // used only in COleServerItem implementation
  156. #endif
  157. // Implementation
  158. public:
  159. virtual ~COleDataSource();
  160. #ifdef _DEBUG
  161. virtual void AssertValid() const;
  162. virtual void Dump(CDumpContext& dc) const;
  163. #endif
  164. protected:
  165. AFX_DATACACHE_ENTRY* m_pDataCache; // data cache itself
  166. UINT m_nMaxSize; // current allocated size
  167. UINT m_nSize; // current size of the cache
  168. UINT m_nGrowBy; // number of cache elements to grow by for new allocs
  169. AFX_DATACACHE_ENTRY* Lookup(LPFORMATETC lpFormatEtc,
  170. DATADIR dataDir) const;
  171. AFX_DATACACHE_ENTRY* AllocSpace();
  172. // Interface Maps
  173. public:
  174. BEGIN_INTERFACE_PART(DataObject, IDataObject)
  175. STDMETHOD(GetData)(LPFORMATETC, LPSTGMEDIUM);
  176. STDMETHOD(GetDataHere)(LPFORMATETC, LPSTGMEDIUM);
  177. STDMETHOD(QueryGetData)(LPFORMATETC);
  178. STDMETHOD(GetCanonicalFormatEtc)(LPFORMATETC, LPFORMATETC);
  179. STDMETHOD(SetData)(LPFORMATETC, LPSTGMEDIUM, BOOL);
  180. STDMETHOD(EnumFormatEtc)(DWORD, LPENUMFORMATETC FAR*);
  181. STDMETHOD(DAdvise)(LPFORMATETC, DWORD, LPADVISESINK, LPDWORD);
  182. STDMETHOD(DUnadvise)(DWORD);
  183. STDMETHOD(EnumDAdvise)(LPENUMSTATDATA FAR*);
  184. END_INTERFACE_PART(DataObject)
  185. DECLARE_INTERFACE_MAP()
  186. friend class COleServerItem;
  187. };
  188. //////////////////////////////////////////////////////////////////////////////
  189. // DocItem support
  190. class CDocItem : public CCmdTarget
  191. {
  192. DECLARE_SERIAL(CDocItem)
  193. // Constructors
  194. protected: // abstract class
  195. CDocItem();
  196. // Attributes
  197. public:
  198. CDocument* GetDocument() const; // return container document
  199. // Overridables
  200. public:
  201. // Raw data access (native format)
  202. virtual BOOL IsBlank() const;
  203. // Implementation
  204. protected:
  205. COleDocument* m_pDocument;
  206. public:
  207. virtual void Serialize(CArchive& ar); // for Native data
  208. virtual ~CDocItem();
  209. #ifdef _DEBUG
  210. virtual void AssertValid() const;
  211. virtual void Dump(CDumpContext& dc) const;
  212. #endif
  213. friend class COleDocument; // for access to back pointer
  214. };
  215. //////////////////////////////////////////////////////////////////////////////
  216. // COleDocument - common OLE container behavior (enables server functionality)
  217. class COleDocument : public CDocument
  218. {
  219. DECLARE_DYNAMIC(COleDocument)
  220. // Constructors
  221. public:
  222. COleDocument();
  223. // Attributes
  224. BOOL HasBlankItems() const; // check for BLANK items
  225. COleClientItem* GetInPlaceActiveItem(CWnd* pWnd);
  226. // return in-place active item for this view or NULL if none
  227. // Operations
  228. // iterating over existing items
  229. virtual POSITION GetStartPosition() const;
  230. virtual CDocItem* GetNextItem(POSITION& pos) const;
  231. // iterator helpers (helpers use virtual GetNextItem above)
  232. COleClientItem* GetNextClientItem(POSITION& pos) const;
  233. COleServerItem* GetNextServerItem(POSITION& pos) const;
  234. // adding new items - called from item constructors
  235. virtual void AddItem(CDocItem* pItem);
  236. virtual void RemoveItem(CDocItem* pItem);
  237. void EnableCompoundFile(BOOL bEnable = TRUE);
  238. // enable compound file support (only call during constructor)
  239. void UpdateModifiedFlag();
  240. // scan for modified items -- mark document modified
  241. // printer-device caching/control
  242. BOOL ApplyPrintDevice(const DVTARGETDEVICE FAR* ptd);
  243. BOOL ApplyPrintDevice(const PRINTDLG* ppd);
  244. // these apply the target device to all COleClientItem objects
  245. // Overridables
  246. virtual COleClientItem* GetPrimarySelectedItem(CView* pView);
  247. // return primary selected item or NULL if none
  248. virtual void OnShowViews(BOOL bVisible);
  249. // called during app-idle when visibility of a document has changed
  250. // Implementation
  251. public:
  252. CObList m_docItemList; // not owned items
  253. #ifdef _DEBUG
  254. virtual void AssertValid() const;
  255. virtual void Dump(CDumpContext& dc) const;
  256. #endif
  257. CFrameWnd* GetFirstFrame();
  258. // document handling overrides
  259. virtual void SetPathName(const char* pszPathName, BOOL bAddToMRU = TRUE);
  260. virtual ~COleDocument();
  261. virtual void DeleteContents(); // delete client items in list
  262. virtual void Serialize(CArchive& ar); // serialize items to file
  263. virtual void PreCloseFrame(CFrameWnd* pFrame);
  264. virtual BOOL SaveModified();
  265. virtual void OnIdle();
  266. // compound file implementation
  267. virtual BOOL OnNewDocument();
  268. virtual BOOL OnOpenDocument(const char* pszPathName);
  269. virtual BOOL OnSaveDocument(const char* pszPathName);
  270. virtual void OnCloseDocument();
  271. void CommitItems(BOOL bSuccess); // called during File.Save & File.Save As
  272. // minimal linking protocol
  273. virtual LPMONIKER GetMoniker(OLEGETMONIKER nAssign);
  274. virtual LPOLEITEMCONTAINER GetContainer();
  275. protected:
  276. DWORD m_dwNextItemNumber; // serial number for next item in this document
  277. BOOL m_bLastVisible; // TRUE if one or more views was last visible
  278. // 'docfile' support
  279. BOOL m_bCompoundFile; // TRUE if use compound files
  280. LPSTORAGE m_lpRootStg; // root storage for the document
  281. BOOL m_bSameAsLoad; // TRUE = file-save, FALSE = Save [Copy] As
  282. BOOL m_bRemember; // if FALSE, indicates Save Copy As
  283. DVTARGETDEVICE FAR* m_ptd; // current document target device
  284. // implementation helpers
  285. virtual void LoadFromStorage();
  286. virtual void SaveToStorage(CObject* pObject = NULL);
  287. CDocItem* GetNextItemOfKind(POSITION& pos, CRuntimeClass* pClass) const;
  288. // command handling
  289. virtual BOOL OnCmdMsg(UINT nID, int nCode, void* pExtra,
  290. AFX_CMDHANDLERINFO* pHandlerInfo);
  291. afx_msg void OnUpdatePasteMenu(CCmdUI* pCmdUI);
  292. afx_msg void OnUpdatePasteLinkMenu(CCmdUI* pCmdUI);
  293. afx_msg void OnUpdateEditLinksMenu(CCmdUI* pCmdUI);
  294. afx_msg void OnEditLinks();
  295. afx_msg void OnEditConvert();
  296. afx_msg void OnUpdateEditChangeIcon(CCmdUI* pCmdUI);
  297. afx_msg void OnEditChangeIcon();
  298. afx_msg void OnUpdateObjectVerbMenu(CCmdUI* pCmdUI);
  299. afx_msg void OnFileSendMail();
  300. friend class COleClientItem;
  301. friend class COleServerItem;
  302. };
  303. /////////////////////////////////////////////////////////////////////////////
  304. // COleClientItem - Supports OLE2 non-inplace editing.
  305. // implements IOleClientSite, IAdviseSink, and IOleInPlaceSite
  306. class COleFrameHook; // special implementation class
  307. class COleClientItem : public CDocItem
  308. {
  309. DECLARE_DYNAMIC(COleClientItem)
  310. // Constructors
  311. public:
  312. COleClientItem(COleDocument* pContainerDoc = NULL);
  313. // create from the clipboard
  314. BOOL CreateFromClipboard(OLERENDER render = OLERENDER_DRAW,
  315. CLIPFORMAT cfFormat = 0, LPFORMATETC lpFormatEtc = NULL);
  316. BOOL CreateLinkFromClipboard(OLERENDER render = OLERENDER_DRAW,
  317. CLIPFORMAT cfFormat = 0, LPFORMATETC lpFormatEtc = NULL);
  318. BOOL CreateStaticFromClipboard(OLERENDER render = OLERENDER_DRAW,
  319. CLIPFORMAT cfFormat = 0, LPFORMATETC lpFormatEtc = NULL);
  320. // create from a class ID (Insert New Object dialog)
  321. BOOL CreateNewItem(REFCLSID clsid, OLERENDER render = OLERENDER_DRAW,
  322. CLIPFORMAT cfFormat = 0, LPFORMATETC lpFormatEtc = NULL);
  323. // create from COleDataObject
  324. BOOL CreateFromData(COleDataObject* pDataObject,
  325. OLERENDER render = OLERENDER_DRAW,
  326. CLIPFORMAT cfFormat = 0, LPFORMATETC lpFormatEtc = NULL);
  327. BOOL CreateLinkFromData(COleDataObject* pDataObject,
  328. OLERENDER render = OLERENDER_DRAW,
  329. CLIPFORMAT cfFormat = 0, LPFORMATETC lpFormatEtc = NULL);
  330. BOOL CreateStaticFromData(COleDataObject* pDataObject,
  331. OLERENDER render = OLERENDER_DRAW,
  332. CLIPFORMAT cfFormat = 0, LPFORMATETC lpFormatEtc = NULL);
  333. // create from file (package support)
  334. BOOL CreateFromFile(LPCSTR lpszFileName, REFCLSID clsid = CLSID_NULL,
  335. OLERENDER render = OLERENDER_DRAW,
  336. CLIPFORMAT cfFormat = 0, LPFORMATETC lpFormatEtc = NULL);
  337. BOOL CreateLinkFromFile(LPCSTR lpszFileName,
  338. OLERENDER render = OLERENDER_DRAW,
  339. CLIPFORMAT cfFormat = 0, LPFORMATETC lpFormatEtc = NULL);
  340. // create a copy
  341. BOOL CreateCloneFrom(COleClientItem* pSrcItem);
  342. // General Attributes
  343. public:
  344. SCODE GetLastStatus() const;
  345. OLE_OBJTYPE GetType() const; // OT_LINK, OT_EMBEDDED, OT_STATIC
  346. void GetClassID(CLSID FAR* pClassID) const;
  347. void GetUserType(USERCLASSTYPE nUserClassType, CString& rString);
  348. BOOL GetExtent(LPSIZE lpSize, DVASPECT nDrawAspect = (DVASPECT)-1);
  349. // will return FALSE if item is BLANK
  350. HGLOBAL GetIconicMetafile();
  351. BOOL SetIconicMetafile(HGLOBAL hMetaPict);
  352. // getting/setting iconic cache
  353. DVASPECT GetDrawAspect() const;
  354. void SetDrawAspect(DVASPECT nDrawAspect);
  355. // setting/getting default display aspect
  356. // for printer presentation cache
  357. BOOL SetPrintDevice(const DVTARGETDEVICE FAR* ptd);
  358. BOOL SetPrintDevice(const PRINTDLG* ppd);
  359. // Item state
  360. enum ItemState
  361. { emptyState, loadedState, openState, activeState, activeUIState };
  362. UINT GetItemState() const;
  363. BOOL IsModified() const;
  364. BOOL IsRunning() const;
  365. BOOL IsInPlaceActive() const;
  366. BOOL IsOpen() const;
  367. CView* GetActiveView() const;
  368. // Data access
  369. void AttachDataObject(COleDataObject& rDataObject) const;
  370. // other rare access information
  371. COleDocument* GetDocument() const; // return container
  372. // helpers for checking clipboard data availability
  373. static BOOL PASCAL CanPaste();
  374. static BOOL PASCAL CanPasteLink();
  375. // helpers for checking COleDataObject, useful in drag drop
  376. static BOOL PASCAL CanCreateFromData(const COleDataObject* pDataObject);
  377. static BOOL PASCAL CanCreateLinkFromData(const COleDataObject* pDataObject);
  378. // General Operations
  379. virtual void Release(OLECLOSE dwCloseOption = OLECLOSE_NOSAVE);
  380. // cleanup, detach (close if needed)
  381. void Close(OLECLOSE dwCloseOption = OLECLOSE_SAVEIFDIRTY);
  382. // close without releasing the item
  383. void Delete(BOOL bAutoDelete = TRUE);
  384. // logically delete from file -- not part of the document anymore
  385. void Run(); // insure item is in running state
  386. // Drawing
  387. BOOL Draw(CDC* pDC, LPCRECT lpBounds,
  388. DVASPECT nDrawAspect = (DVASPECT)-1); // defaults to m_nDrawAspect
  389. // Activation
  390. virtual BOOL DoVerb(LONG nVerb, CView* pView, LPMSG lpMsg = NULL);
  391. void Activate(LONG nVerb, CView* pView, LPMSG lpMsg = NULL);
  392. // In-place Activation
  393. void Deactivate(); // completely deactivate
  394. void DeactivateUI(); // deactivate the user interface
  395. BOOL ReactivateAndUndo(); // reactivate then perform undo command
  396. BOOL SetItemRects(LPCRECT lpPosRect = NULL, LPCRECT lpClipRect = NULL);
  397. CWnd* GetInPlaceWindow();
  398. // Clipboard operations
  399. void CopyToClipboard(BOOL bIncludeLink = FALSE);
  400. DROPEFFECT DoDragDrop(LPCRECT lpItemRect, CPoint ptOffset,
  401. BOOL bIncludeLink = FALSE,
  402. DWORD dwEffects = DROPEFFECT_COPY|DROPEFFECT_MOVE,
  403. LPCRECT lpRectStartDrag = NULL);
  404. void GetClipboardData(COleDataSource* pDataSource,
  405. BOOL bIncludeLink = FALSE, LPPOINT lpOffset = NULL,
  406. LPSIZE lpSize = NULL);
  407. // called for creating a COleDataSource by CopyToClipboard and DoDragDrop
  408. virtual COleDataSource* OnGetClipboardData(BOOL bIncludeLink,
  409. LPPOINT lpOffset, LPSIZE lpSize);
  410. // Operations that apply to embedded items only
  411. void SetHostNames(LPCSTR lpszHost, LPCSTR lpszHostObj);
  412. void SetExtent(const CSize& size, DVASPECT nDrawAspect = DVASPECT_CONTENT);
  413. // Operations that apply to linked items only
  414. // (link options are rarely changed, except through Links dialog)
  415. OLEUPDATE GetLinkUpdateOptions();
  416. void SetLinkUpdateOptions(OLEUPDATE dwUpdateOpt);
  417. // Link-source update status (also useful for embeddings that contain links)
  418. BOOL UpdateLink(); // make up-to-date
  419. BOOL IsLinkUpToDate() const; // is link up-to-date
  420. // object conversion
  421. BOOL ConvertTo(REFCLSID clsidNew);
  422. BOOL ActivateAs(LPCSTR lpszUserType, REFCLSID clsidOld, REFCLSID clsidNew);
  423. BOOL Reload(); // for lazy reload after ActivateAs
  424. // Overridables (notifications of IAdviseSink, IOleClientSite and IOleInPlaceSite)
  425. // Callbacks/notifications from the server you must/should implement
  426. virtual void OnChange(OLE_NOTIFICATION nCode, DWORD dwParam);
  427. // implement OnChange to invalidate when item changes
  428. protected:
  429. virtual void OnGetItemPosition(CRect& rPosition);
  430. // implement OnGetItemPosition if you support in-place activation
  431. // Common overrides for in-place activation
  432. virtual BOOL OnScrollBy(CSize sizeExtent);
  433. protected:
  434. // Common overrides for applications supporting undo
  435. virtual void OnDeactivateUI(BOOL bUndoable);
  436. virtual void OnDiscardUndoState();
  437. virtual void OnDeactivateAndUndo();
  438. // Common overrides for applications supporting links to embeddings
  439. virtual void OnShowItem();
  440. // Advanced overrides for in-place activation
  441. virtual void OnGetClipRect(CRect& rClipRect);
  442. virtual BOOL CanActivate();
  443. virtual void OnActivate();
  444. virtual void OnActivateUI();
  445. virtual BOOL OnGetWindowContext(CFrameWnd** ppMainFrame,
  446. CFrameWnd** ppDocFrame, LPOLEINPLACEFRAMEINFO lpFrameInfo);
  447. virtual void OnDeactivate();
  448. virtual BOOL OnChangeItemPosition(const CRect& rectPos);
  449. // default calls SetItemRects and caches the pos rect
  450. public:
  451. // Advanced overrides for menu/title handling (rarely overridden)
  452. virtual void OnInsertMenus(CMenu* pMenuShared,
  453. LPOLEMENUGROUPWIDTHS lpMenuWidths);
  454. virtual void OnSetMenu(CMenu* pMenuShared, HOLEMENU holemenu,
  455. HWND hwndActiveObject);
  456. virtual void OnRemoveMenus(CMenu* pMenuShared);
  457. virtual void OnUpdateFrameTitle();
  458. // Advanced override for control bar handling
  459. virtual BOOL OnShowControlBars(CFrameWnd* pFrameWnd, BOOL bShow);
  460. // Implementation
  461. public:
  462. // data to support non-inplace activated items
  463. LPOLEOBJECT m_lpObject; // in case you want direct access to the OLE object
  464. DWORD m_dwItemNumber; // serial number for this item in this document
  465. DVASPECT m_nDrawAspect; // current default display aspect
  466. SCODE m_scLast; // last error code encountered
  467. LPSTORAGE m_lpStorage; // provides storage for m_lpObject
  468. LPLOCKBYTES m_lpLockBytes; // part of implementation of m_lpStorage
  469. DWORD m_dwConnection; // advise connection to the m_lpObject
  470. BYTE m_bLinkUnavail; // TRUE if link is currently unavailable
  471. BYTE m_bMoniker; // TRUE if moniker is assigned
  472. BYTE m_bLocked; // TRUE if object has external lock
  473. BYTE m_bNeedCommit; // TRUE if need CommitItem
  474. BYTE m_bClosing; // TRUE if currently doing COleClientItem::Close
  475. BYTE m_bReserved; // (reserved for future use)
  476. // for compound file support
  477. LPSTORAGE m_lpNewStorage; // used during Save As situations
  478. // item state & item type
  479. ItemState m_nItemState; // item state (see ItemState enumeration)
  480. OLE_OBJTYPE m_nItemType; // item type (depends on how created)
  481. // data valid when in-place activated
  482. CView* m_pView; // view when object is in-place activated
  483. DWORD m_dwContainerStyle; // style of the container wnd before activation
  484. COleFrameHook* m_pInPlaceFrame;// frame window when in-place active
  485. COleFrameHook* m_pInPlaceDoc; // doc window when in-place (may be NULL)
  486. HWND m_hWndServer; // HWND of in-place server window
  487. public:
  488. virtual ~COleClientItem();
  489. virtual void Serialize(CArchive& ar);
  490. #ifdef _DEBUG
  491. virtual void AssertValid() const;
  492. virtual void Dump(CDumpContext& dc) const;
  493. #endif
  494. // Implementation
  495. public:
  496. virtual BOOL ReportError(SCODE sc) const;
  497. virtual BOOL FreezeLink(); // converts to static: for edit links dialog
  498. DWORD GetNewItemNumber(); // generates new item number
  499. void GetItemName(char* pszItemName) const; // gets readable item name
  500. void UpdateItemType(); // update m_nItemType
  501. protected:
  502. // clipboard helpers
  503. void GetEmbeddedItemData(LPSTGMEDIUM lpStgMedium);
  504. void AddCachedData(COleDataSource* pDataSource);
  505. BOOL GetLinkSourceData(LPSTGMEDIUM lpStgMedium);
  506. void GetObjectDescriptorData(LPPOINT lpOffset, LPSIZE lpSize,
  507. LPSTGMEDIUM lpStgMedium);
  508. // interface helpers
  509. LPOLECLIENTSITE GetClientSite();
  510. // helpers for printer-cached representation
  511. BOOL GetPrintDeviceInfo(LPOLECACHE* plpOleCache,
  512. DVTARGETDEVICE FAR** pptd, DWORD* pdwConnection);
  513. // Advanced Overridables for implementation
  514. protected:
  515. virtual BOOL FinishCreate(HRESULT hr);
  516. virtual void CheckGeneral(HRESULT hr);
  517. virtual void OnDataChange(LPFORMATETC lpFormatEtc,
  518. LPSTGMEDIUM lpStgMedium);
  519. public:
  520. // for storage hookability (override to use 'docfiles')
  521. virtual void GetItemStorage(); // allocate storage for new item
  522. virtual void ReadItem(CArchive& ar); // read item from archive
  523. virtual void WriteItem(CArchive& ar); // write item to archive
  524. virtual void CommitItem(BOOL bSuccess); // commit item's storage
  525. // compound & flat file implementations of above
  526. void GetItemStorageFlat();
  527. void ReadItemFlat(CArchive& ar);
  528. void WriteItemFlat(CArchive& ar);
  529. void GetItemStorageCompound();
  530. void ReadItemCompound(CArchive& ar);
  531. void WriteItemCompound(CArchive& ar);
  532. private:
  533. static CView* pActivateView; // activation view
  534. // Interface Maps
  535. protected:
  536. BEGIN_INTERFACE_PART(OleClientSite, IOleClientSite)
  537. STDMETHOD(SaveObject)();
  538. STDMETHOD(GetMoniker)(DWORD, DWORD, LPMONIKER FAR*);
  539. STDMETHOD(GetContainer)(LPOLECONTAINER FAR*);
  540. STDMETHOD(ShowObject)();
  541. STDMETHOD(OnShowWindow)(BOOL);
  542. STDMETHOD(RequestNewObjectLayout)();
  543. END_INTERFACE_PART(OleClientSite)
  544. BEGIN_INTERFACE_PART(AdviseSink, IAdviseSink)
  545. STDMETHOD_(void,OnDataChange)(LPFORMATETC, LPSTGMEDIUM);
  546. STDMETHOD_(void,OnViewChange)(DWORD, LONG);
  547. STDMETHOD_(void,OnRename)(LPMONIKER);
  548. STDMETHOD_(void,OnSave)();
  549. STDMETHOD_(void,OnClose)();
  550. END_INTERFACE_PART(AdviseSink)
  551. BEGIN_INTERFACE_PART(OleIPSite, IOleInPlaceSite)
  552. STDMETHOD(GetWindow)(HWND FAR*);
  553. STDMETHOD(ContextSensitiveHelp)(BOOL);
  554. STDMETHOD(CanInPlaceActivate)();
  555. STDMETHOD(OnInPlaceActivate)();
  556. STDMETHOD(OnUIActivate)();
  557. STDMETHOD(GetWindowContext)(LPOLEINPLACEFRAME FAR*,
  558. LPOLEINPLACEUIWINDOW FAR*, LPRECT, LPRECT, LPOLEINPLACEFRAMEINFO);
  559. STDMETHOD(Scroll)(SIZE);
  560. STDMETHOD(OnUIDeactivate)(BOOL);
  561. STDMETHOD(OnInPlaceDeactivate)();
  562. STDMETHOD(DiscardUndoState)();
  563. STDMETHOD(DeactivateAndUndo)();
  564. STDMETHOD(OnPosRectChange)(LPCRECT);
  565. END_INTERFACE_PART(OleIPSite)
  566. DECLARE_INTERFACE_MAP()
  567. // Friendship declarations (to avoid many public members)
  568. friend class COleUIWindow;
  569. friend class COleFrameWindow;
  570. friend class COleLinkingDoc;
  571. };
  572. /////////////////////////////////////////////////////////////////////////////
  573. // COleServerItem - IOleObject & IDataObject OLE component
  574. class COleServerItem : public CDocItem
  575. {
  576. DECLARE_DYNAMIC(COleServerItem)
  577. protected:
  578. // NOTE: many members in this class are protected - since everything
  579. // in this class is designed for implementing an OLE server.
  580. // Requests will come from OLE containers through non-C++ mechanisms,
  581. // which will result in virtual functions in this class being called.
  582. // Constructors
  583. COleServerItem(COleServerDoc* pServerDoc, BOOL bAutoDelete);
  584. // If your COleServerItem is an integral part of your data,
  585. // bAutoDelete should be FALSE. If your COleServerItem can be
  586. // deleted when a link is released, it can be TRUE.
  587. COleDataSource* GetDataSource();
  588. // Use this data source to add conversion formats that your
  589. // server should support. Usually such formats are
  590. // added in the item's constructor.
  591. // Public Attributes
  592. public:
  593. COleServerDoc* GetDocument() const; // return server document
  594. // naming (for links only)
  595. const CString& GetItemName() const; // get name of linked item
  596. void SetItemName(const char* pszItemName); // set name of linked item
  597. // link state
  598. BOOL IsConnected() const; // returns TRUE if item has a client
  599. BOOL IsLinkedItem() const; // returns TRUE if item is not embedded item
  600. // extents
  601. CSize m_sizeExtent;
  602. // HIMETRIC size -- the default implementation of OnSetExtent
  603. // updates this member variable. This member tells the server how
  604. // much of the object is visible in the container document.
  605. // Operations
  606. public:
  607. void NotifyChanged(DVASPECT nDrawAspect = DVASPECT_CONTENT);
  608. // call this after you change item
  609. void CopyToClipboard(BOOL bIncludeLink = FALSE);
  610. // helper for implementing server 'copy to clipboard'
  611. DROPEFFECT DoDragDrop(LPCRECT lpRectItem, CPoint ptOffset,
  612. BOOL bIncludeLink = FALSE,
  613. DWORD dwEffects = DROPEFFECT_COPY|DROPEFFECT_MOVE,
  614. LPCRECT lpRectStartDrag = NULL);
  615. void GetClipboardData(COleDataSource* pDataSource,
  616. BOOL bIncludeLink = FALSE, LPPOINT lpOffset = NULL,
  617. LPSIZE lpSize = NULL);
  618. // Overridables
  619. // overridables you must implement for yourself
  620. virtual BOOL OnDraw(CDC* pDC, CSize& rSize) = 0;
  621. // drawing for metafile format (return FALSE if not supported or error)
  622. // (called for DVASPECT_CONTENT only)
  623. // overridables you may want to implement yourself
  624. virtual void OnUpdate(COleServerItem* pSender,
  625. LPARAM lHint, CObject* pHint, DVASPECT nDrawAspect);
  626. // the default implementation always calls NotifyChanged
  627. virtual BOOL OnDrawEx(CDC* pDC, DVASPECT nDrawAspect, CSize& rSize);
  628. // advanced drawing -- called for DVASPECT other than DVASPECT_CONTENT
  629. virtual BOOL OnSetExtent(DVASPECT nDrawAspect, const CSize& size);
  630. virtual BOOL OnGetExtent(DVASPECT nDrawAspect, CSize& rSize);
  631. // default implementation uses m_sizeExtent
  632. // overridables you do not have to implement
  633. virtual void OnDoVerb(LONG iVerb);
  634. // default routes to OnShow &/or OnOpen
  635. virtual BOOL OnSetColorScheme(const LOGPALETTE FAR* lpLogPalette);
  636. // default does nothing
  637. virtual COleDataSource* OnGetClipboardData(BOOL bIncludeLink,
  638. LPPOINT lpOffset, LPSIZE lpSize);
  639. // called for access to clipboard data
  640. virtual BOOL OnQueryUpdateItems();
  641. // called to determine if there are any contained out-of-date links
  642. virtual void OnUpdateItems();
  643. // called to update any out-of-date links
  644. protected:
  645. virtual void OnShow();
  646. // show item in the user interface (may edit in-place)
  647. virtual void OnOpen();
  648. // show item in the user interface (must open fully)
  649. virtual void OnHide();
  650. // hide document (and sometimes application)
  651. // very advanced overridables
  652. public:
  653. virtual BOOL OnInitFromData(COleDataObject* pDataObject, BOOL bCreation);
  654. // initialize object from IDataObject
  655. // see COleDataSource for a description of these overridables
  656. virtual BOOL OnRenderGlobalData(LPFORMATETC lpFormatEtc, HGLOBAL* phGlobal);
  657. virtual BOOL OnRenderFileData(LPFORMATETC lpFormatEtc, CFile* pFile);
  658. virtual BOOL OnRenderData(LPFORMATETC lpFormatEtc, LPSTGMEDIUM lpStgMedium);
  659. // HGLOBAL version will be called first, then CFile* version
  660. virtual BOOL OnSetData(LPFORMATETC lpFormatEtc, LPSTGMEDIUM lpStgMedium);
  661. // Rare -- only if you support SetData (programmatic paste)
  662. // advanced helpers for CopyToClipboard
  663. void GetEmbedSourceData(LPSTGMEDIUM lpStgMedium);
  664. void AddOtherClipboardData(COleDataSource* pDataSource);
  665. BOOL GetLinkSourceData(LPSTGMEDIUM lpStgMedium);
  666. void GetObjectDescriptorData(LPPOINT lpOffset, LPSIZE lpSize,
  667. LPSTGMEDIUM lpStgMedium);
  668. // Implementation
  669. public:
  670. BOOL m_bNeedUnlock; // if TRUE need to pDoc->LockExternal(FALSE)
  671. BOOL m_bAutoDelete; // if TRUE will OnRelease will 'delete this'
  672. // special version of OnFinalRelease to implement document locking
  673. virtual void OnFinalRelease();
  674. protected:
  675. CString m_strItemName; // simple item name
  676. public:
  677. LPOLEADVISEHOLDER m_lpOleAdviseHolder; // may be NULL
  678. LPDATAADVISEHOLDER m_lpDataAdviseHolder; // may be NULL
  679. virtual ~COleServerItem();
  680. #ifdef _DEBUG
  681. virtual void AssertValid() const;
  682. virtual void Dump(CDumpContext& dc) const;
  683. #endif
  684. // implementation helpers
  685. void NotifyClient(OLE_NOTIFICATION wNotification, DWORD dwParam);
  686. LPDATAOBJECT GetDataObject();
  687. LPOLEOBJECT GetOleObject();
  688. protected:
  689. virtual BOOL GetMetafileData(LPFORMATETC lpFormatEtc, LPSTGMEDIUM pmedium);
  690. // calls OnDraw or OnDrawEx
  691. virtual void OnSaveEmbedding(LPSTORAGE lpStorage);
  692. virtual BOOL IsBlank() const;
  693. // CItemDataSource implements OnRender reflections to COleServerItem
  694. class CItemDataSource : public COleDataSource
  695. {
  696. protected:
  697. // the GetData and SetData interfaces forward to m_pItem
  698. virtual BOOL OnRenderGlobalData(LPFORMATETC lpFormatEtc, HGLOBAL* phGlobal);
  699. virtual BOOL OnRenderFileData(LPFORMATETC lpFormatEtc, CFile* pFile);
  700. virtual BOOL OnRenderData(LPFORMATETC lpFormatEtc, LPSTGMEDIUM lpStgMedium);
  701. // HGLOBAL version will be called first, then CFile* version
  702. virtual BOOL OnSetData(LPFORMATETC lpFormatEtc, LPSTGMEDIUM lpStgMedium);
  703. // HGLOBAL version will be called first, then CFile* version
  704. };
  705. CItemDataSource m_dataSource;
  706. // data source used to implement IDataObject
  707. // Interface Maps
  708. // (Note: these interface maps are used just for link implementation)
  709. public:
  710. BEGIN_INTERFACE_PART(OleObject, IOleObject)
  711. STDMETHOD(SetClientSite)(LPOLECLIENTSITE);
  712. STDMETHOD(GetClientSite)(LPOLECLIENTSITE FAR*);
  713. STDMETHOD(SetHostNames)(LPCSTR, LPCSTR);
  714. STDMETHOD(Close)(DWORD);
  715. STDMETHOD(SetMoniker)(DWORD, LPMONIKER);
  716. STDMETHOD(GetMoniker)(DWORD, DWORD, LPMONIKER FAR*);
  717. STDMETHOD(InitFromData)(LPDATAOBJECT, BOOL, DWORD);
  718. STDMETHOD(GetClipboardData)(DWORD, LPDATAOBJECT FAR*);
  719. STDMETHOD(DoVerb)(LONG, LPMSG, LPOLECLIENTSITE, LONG, HWND, LPCRECT);
  720. STDMETHOD(EnumVerbs)(IEnumOLEVERB FAR* FAR*);
  721. STDMETHOD(Update)();
  722. STDMETHOD(IsUpToDate)();
  723. STDMETHOD(GetUserClassID)(CLSID FAR*);
  724. STDMETHOD(GetUserType)(DWORD, LPSTR FAR*);
  725. STDMETHOD(SetExtent)(DWORD, LPSIZEL);
  726. STDMETHOD(GetExtent)(DWORD, LPSIZEL);
  727. STDMETHOD(Advise)(LPADVISESINK, LPDWORD);
  728. STDMETHOD(Unadvise)(DWORD);
  729. STDMETHOD(EnumAdvise)(LPENUMSTATDATA FAR*);
  730. STDMETHOD(GetMiscStatus)(DWORD, LPDWORD);
  731. STDMETHOD(SetColorScheme)(LPLOGPALETTE);
  732. END_INTERFACE_PART(OleObject)
  733. BEGIN_INTERFACE_PART(DataObject, IDataObject)
  734. STDMETHOD(GetData)(LPFORMATETC, LPSTGMEDIUM);
  735. STDMETHOD(GetDataHere)(LPFORMATETC, LPSTGMEDIUM);
  736. STDMETHOD(QueryGetData)(LPFORMATETC);
  737. STDMETHOD(GetCanonicalFormatEtc)(LPFORMATETC, LPFORMATETC);
  738. STDMETHOD(SetData)(LPFORMATETC, LPSTGMEDIUM, BOOL);
  739. STDMETHOD(EnumFormatEtc)(DWORD, LPENUMFORMATETC FAR*);
  740. STDMETHOD(DAdvise)(LPFORMATETC, DWORD, LPADVISESINK, LPDWORD);
  741. STDMETHOD(DUnadvise)(DWORD);
  742. STDMETHOD(EnumDAdvise)(LPENUMSTATDATA FAR*);
  743. END_INTERFACE_PART(DataObject)
  744. DECLARE_INTERFACE_MAP()
  745. friend class CItemDataSource;
  746. friend class COleServerDoc;
  747. friend class COleLinkingDoc;
  748. };
  749. /////////////////////////////////////////////////////////////////////////////
  750. // COleLinkingDoc -
  751. // (enables linking to embeddings - beginnings of server fuctionality)
  752. class COleLinkingDoc : public COleDocument
  753. {
  754. DECLARE_DYNAMIC(COleLinkingDoc)
  755. // Constructors
  756. public:
  757. COleLinkingDoc();
  758. // Operations
  759. BOOL Register(COleObjectFactory* pFactory, const char* pszPathName);
  760. // notify the running object table and connect to pServer
  761. void Revoke();
  762. // revoke from running object table
  763. // Overridables
  764. protected:
  765. virtual COleServerItem* OnGetLinkedItem(LPCSTR lpszItemName);
  766. // return item for the named linked item (for supporting links)
  767. virtual COleClientItem* OnFindEmbeddedItem(LPCSTR lpszItemName);
  768. // return item for the named embedded item (for links to embeddings)
  769. // Implementation
  770. public:
  771. COleObjectFactory* m_pFactory; // back-pointer to server
  772. #ifdef _DEBUG
  773. virtual void AssertValid() const;
  774. virtual void Dump(CDumpContext& dc) const;
  775. #endif
  776. virtual ~COleLinkingDoc();
  777. // overrides for updating of monikers & running object table registration
  778. virtual BOOL OnNewDocument();
  779. virtual BOOL OnOpenDocument(const char* pszPathName);
  780. virtual BOOL OnSaveDocument(const char* pszPathName);
  781. virtual void OnCloseDocument();
  782. virtual LPOLEITEMCONTAINER GetContainer();
  783. virtual void OnShowViews(BOOL bVisible);
  784. protected:
  785. DWORD m_dwRegister; // file moniker's registration in the ROT
  786. BOOL m_bVisibleLock; // TRUE if user is holding lock on document
  787. // implementation helpers
  788. void RegisterIfServerAttached(const char* pszPathName);
  789. void LockExternal(BOOL bLock, BOOL bRemoveRefs);
  790. void UpdateVisibleLock(BOOL bVisible, BOOL bRemoveRefs);
  791. virtual void SaveToStorage(CObject* pObject = NULL);
  792. // Interface Maps
  793. protected:
  794. BEGIN_INTERFACE_PART(PersistFile, IPersistFile)
  795. STDMETHOD(GetClassID)(LPCLSID);
  796. STDMETHOD(IsDirty)();
  797. STDMETHOD(Load)(LPCSTR, DWORD);
  798. STDMETHOD(Save)(LPCSTR, BOOL);
  799. STDMETHOD(SaveCompleted)(LPCSTR);
  800. STDMETHOD(GetCurFile)(LPSTR FAR*);
  801. END_INTERFACE_PART(PersistFile)
  802. BEGIN_INTERFACE_PART(OleItemContainer, IOleItemContainer)
  803. STDMETHOD(ParseDisplayName)(LPBC, LPSTR, ULONG FAR*, LPMONIKER FAR*);
  804. STDMETHOD(EnumObjects)(DWORD, LPENUMUNKNOWN FAR*);
  805. STDMETHOD(LockContainer)(BOOL);
  806. STDMETHOD(GetObject)(LPSTR, DWORD, LPBINDCTX, REFIID, LPVOID FAR*);
  807. STDMETHOD(GetObjectStorage)(LPSTR, LPBINDCTX, REFIID, LPVOID FAR*);
  808. STDMETHOD(IsRunning)(LPSTR);
  809. END_INTERFACE_PART(OleItemContainer)
  810. DECLARE_INTERFACE_MAP()
  811. friend class COleClientItem;
  812. friend class COleClientItem::XOleClientSite;
  813. friend class COleServerItem::XOleObject;
  814. };
  815. //////////////////////////////////////////////////////////////////////////////
  816. // COleServerDoc - registered server document containing COleServerItems
  817. class COleServerDoc : public COleLinkingDoc
  818. {
  819. DECLARE_DYNAMIC(COleServerDoc)
  820. // Constructors and Destructors
  821. public:
  822. COleServerDoc();
  823. // Attributes
  824. BOOL IsEmbedded() const; // TRUE if document is an embedding
  825. COleServerItem* GetEmbeddedItem();
  826. // return embedded item for document (will allocate if necessary)
  827. // attributes specific to in-place activation
  828. BOOL IsInPlaceActive() const;
  829. void GetItemPosition(LPRECT lpPosRect) const;
  830. // get current position rectangle of in-place edit
  831. void GetItemClipRect(LPRECT lpClipRect) const;
  832. // get current clipping rectangle of in-place edit
  833. BOOL GetZoomFactor(LPSIZE lpSizeNum = NULL, LPSIZE lpSizeDenom = NULL,
  834. LPCRECT lpPosRect = NULL) const;
  835. // returns the zoom factor in pixels
  836. // Operations
  837. void NotifyChanged();
  838. // call this after you change some global attribute like
  839. // document dimensions
  840. void UpdateAllItems(COleServerItem* pSender,
  841. LPARAM lHint = 0L, CObject* pHint = NULL,
  842. DVASPECT nDrawAspect = DVASPECT_CONTENT);
  843. // changes to the entire document (automatically notifies clients)
  844. void NotifyRename(LPCSTR lpszNewName);
  845. void NotifySaved();
  846. void NotifyClosed(); // call this after you close document
  847. // specific operations for embedded documents
  848. void SaveEmbedding(); // call this to save embedded (before closing)
  849. // specific to in-place activation
  850. BOOL ActivateInPlace();
  851. void RequestPositionChange(LPCRECT lpPosRect);
  852. BOOL ScrollContainerBy(CSize sizeScroll);
  853. BOOL DeactivateAndUndo();
  854. BOOL DiscardUndoState();
  855. public:
  856. // Overridables for standard user interface (full server)
  857. virtual BOOL OnUpdateDocument(); // implementation of embedded update
  858. protected:
  859. // Overridables you must implement for yourself
  860. virtual COleServerItem* OnGetEmbeddedItem() = 0;
  861. // return item representing entire (embedded) document
  862. // Overridables you do not have to implement
  863. virtual void OnClose(OLECLOSE dwCloseOption);
  864. virtual void OnSetHostNames(LPCSTR lpszHost, LPCSTR lpszHostObj);
  865. // Advanced overridables
  866. virtual void OnShowDocument(BOOL bShow);
  867. // show first frame for document or hide all frames for document
  868. // Advanced overridables for in-place activation
  869. virtual void OnDeactivate();
  870. virtual void OnDeactivateUI(BOOL bUndoable);
  871. virtual void OnSetItemRects(LPCRECT lpPosRect, LPCRECT lpClipRect);
  872. virtual BOOL OnReactivateAndUndo();
  873. virtual void OnFrameWindowActivate(BOOL bActivate);
  874. virtual void OnDocWindowActivate(BOOL bActivate);
  875. virtual void OnShowControlBars(LPOLEINPLACEUIWINDOW lpUIWindow, BOOL bShow);
  876. virtual void OnResizeBorder(LPCRECT lpRectBorder,
  877. LPOLEINPLACEUIWINDOW lpUIWindow, BOOL bFrame);
  878. virtual COleIPFrameWnd* CreateInPlaceFrame(CWnd* pParentWnd);
  879. virtual void DestroyInPlaceFrame(COleIPFrameWnd* pFrameWnd);
  880. // Implementation
  881. protected:
  882. LPOLECLIENTSITE m_lpClientSite; // for embedded item
  883. CString m_strHostObj; // name of document in container
  884. BOOL m_bCntrVisible; // TRUE if OnShowWindow(TRUE) called
  885. BOOL m_bClosing; // TRUE if shutting down
  886. COleServerItem* m_pEmbeddedItem; // pointer to embedded item for document
  887. COleIPFrameWnd* m_pInPlaceFrame; // not NULL if in-place activated
  888. CWnd* m_pOrigParent; // not NULL if existing view used
  889. DWORD m_dwOrigStyle; // original style of in-place view
  890. public:
  891. virtual ~COleServerDoc();
  892. #ifdef _DEBUG
  893. virtual void AssertValid() const;
  894. virtual void Dump(CDumpContext& dc) const;
  895. #endif
  896. // overridables for implementation
  897. virtual BOOL OnSaveDocument(const char* pszPathName);
  898. virtual void OnCloseDocument();
  899. virtual void DeleteContents(); // delete auto-delete server items
  900. virtual LPMONIKER GetMoniker(OLEGETMONIKER nAssign);
  901. virtual COleServerItem* OnGetLinkedItem(LPCSTR lpszItemName);
  902. // return item for the named linked item (only if supporting links)
  903. virtual BOOL CanCloseFrame(CFrameWnd* pFrame);
  904. protected:
  905. // overrides to handle server user-interface
  906. virtual BOOL SaveModified(); // return TRUE if ok to continue
  907. virtual HMENU GetDefaultMenu(); // return menu based on doc type
  908. virtual HACCEL GetDefaultAccelerator(); // return accel table based on doc type
  909. virtual BOOL GetFileTypeString(CString& rString);
  910. // IPersistStorage implementation
  911. virtual void OnNewEmbedding(LPSTORAGE lpStorage);
  912. virtual void OnOpenEmbedding(LPSTORAGE lpStorage);
  913. virtual void OnSaveEmbedding(LPSTORAGE lpStorage);
  914. // Implementation helpers
  915. void NotifyAllItems(OLE_NOTIFICATION wNotification, DWORD dwParam);
  916. BOOL SaveModifiedPrompt();
  917. void ConnectView(CWnd* pParentWnd, CView* pView);
  918. void UpdateUsingHostObj(UINT nIDS, CCmdUI* pCmdUI);
  919. // Message Maps
  920. //{{AFX_MSG(COleServerDoc)
  921. afx_msg void OnFileUpdate();
  922. afx_msg void OnFileSaveCopyAs();
  923. afx_msg void OnUpdateFileUpdate(CCmdUI* pCmdUI);
  924. afx_msg void OnUpdateFileExit(CCmdUI* pCmdUI);
  925. //}}AFX_MSG
  926. DECLARE_MESSAGE_MAP()
  927. // Interface Maps
  928. protected:
  929. BEGIN_INTERFACE_PART(PersistStorage, IPersistStorage)
  930. STDMETHOD(GetClassID)(LPCLSID);
  931. STDMETHOD(IsDirty)();
  932. STDMETHOD(InitNew)(LPSTORAGE);
  933. STDMETHOD(Load)(LPSTORAGE);
  934. STDMETHOD(Save)(LPSTORAGE, BOOL);
  935. STDMETHOD(SaveCompleted)(LPSTORAGE);
  936. STDMETHOD(HandsOffStorage)();
  937. END_INTERFACE_PART(PersistStorage)
  938. BEGIN_INTERFACE_PART(OleObject, IOleObject)
  939. STDMETHOD(SetClientSite)(LPOLECLIENTSITE);
  940. STDMETHOD(GetClientSite)(LPOLECLIENTSITE FAR*);
  941. STDMETHOD(SetHostNames)(LPCSTR, LPCSTR);
  942. STDMETHOD(Close)(DWORD);
  943. STDMETHOD(SetMoniker)(DWORD, LPMONIKER);
  944. STDMETHOD(GetMoniker)(DWORD, DWORD, LPMONIKER FAR*);
  945. STDMETHOD(InitFromData)(LPDATAOBJECT, BOOL, DWORD);
  946. STDMETHOD(GetClipboardData)(DWORD, LPDATAOBJECT FAR*);
  947. STDMETHOD(DoVerb)(LONG, LPMSG, LPOLECLIENTSITE, LONG, HWND, LPCRECT);
  948. STDMETHOD(EnumVerbs)(IEnumOLEVERB FAR* FAR*);
  949. STDMETHOD(Update)();
  950. STDMETHOD(IsUpToDate)();
  951. STDMETHOD(GetUserClassID)(CLSID FAR*);
  952. STDMETHOD(GetUserType)(DWORD, LPSTR FAR*);
  953. STDMETHOD(SetExtent)(DWORD, LPSIZEL);
  954. STDMETHOD(GetExtent)(DWORD, LPSIZEL);
  955. STDMETHOD(Advise)(LPADVISESINK, LPDWORD);
  956. STDMETHOD(Unadvise)(DWORD);
  957. STDMETHOD(EnumAdvise)(LPENUMSTATDATA FAR*);
  958. STDMETHOD(GetMiscStatus)(DWORD, LPDWORD);
  959. STDMETHOD(SetColorScheme)(LPLOGPALETTE);
  960. END_INTERFACE_PART(OleObject)
  961. BEGIN_INTERFACE_PART(DataObject, IDataObject)
  962. STDMETHOD(GetData)(LPFORMATETC, LPSTGMEDIUM);
  963. STDMETHOD(GetDataHere)(LPFORMATETC, LPSTGMEDIUM);
  964. STDMETHOD(QueryGetData)(LPFORMATETC);
  965. STDMETHOD(GetCanonicalFormatEtc)(LPFORMATETC, LPFORMATETC);
  966. STDMETHOD(SetData)(LPFORMATETC, LPSTGMEDIUM, BOOL);
  967. STDMETHOD(EnumFormatEtc)(DWORD, LPENUMFORMATETC FAR*);
  968. STDMETHOD(DAdvise)(LPFORMATETC, DWORD, LPADVISESINK, LPDWORD);
  969. STDMETHOD(DUnadvise)(DWORD);
  970. STDMETHOD(EnumDAdvise)(LPENUMSTATDATA FAR*);
  971. END_INTERFACE_PART(DataObject)
  972. BEGIN_INTERFACE_PART(OleInPlaceObject, IOleInPlaceObject)
  973. STDMETHOD(GetWindow)(HWND FAR*);
  974. STDMETHOD(ContextSensitiveHelp)(BOOL);
  975. STDMETHOD(InPlaceDeactivate)();
  976. STDMETHOD(UIDeactivate)();
  977. STDMETHOD(SetObjectRects)(LPCRECT, LPCRECT);
  978. STDMETHOD(ReactivateAndUndo)();
  979. END_INTERFACE_PART(OleInPlaceObject)
  980. BEGIN_INTERFACE_PART(OleInPlaceActiveObject, IOleInPlaceActiveObject)
  981. STDMETHOD(GetWindow)(HWND FAR*);
  982. STDMETHOD(ContextSensitiveHelp)(BOOL);
  983. STDMETHOD(TranslateAccelerator)(LPMSG);
  984. STDMETHOD(OnFrameWindowActivate)(BOOL);
  985. STDMETHOD(OnDocWindowActivate)(BOOL);
  986. STDMETHOD(ResizeBorder)(LPCRECT, LPOLEINPLACEUIWINDOW, BOOL);
  987. STDMETHOD(EnableModeless)(BOOL);
  988. END_INTERFACE_PART(OleInPlaceActiveObject)
  989. DECLARE_INTERFACE_MAP()
  990. friend class COleServer;
  991. friend class COleServerItem;
  992. };
  993. //////////////////////////////////////////////////////////////////////////////
  994. // COleIPFrameWnd
  995. class COleIPFrameWnd : public CFrameWnd
  996. {
  997. DECLARE_DYNCREATE(COleIPFrameWnd)
  998. // Constructors
  999. public:
  1000. COleIPFrameWnd();
  1001. // Overridables
  1002. public:
  1003. virtual BOOL OnCreateControlBars(CWnd* pWndFrame, CWnd* pWndDoc);
  1004. // create control bars on container windows (pWndDoc can be NULL)
  1005. void RepositionFrame(LPCRECT lpPosRect, LPCRECT lpClipRect);
  1006. // Implementation
  1007. public:
  1008. BOOL m_bUIActive; // TRUE if currently in uiacitve state
  1009. virtual BOOL LoadFrame(UINT nIDResource,
  1010. DWORD dwDefaultStyle = WS_CHILD|WS_BORDER|WS_CLIPSIBLINGS,
  1011. CWnd* pParentWnd = NULL,
  1012. CCreateContext* pContext = NULL);
  1013. virtual void RecalcLayout(BOOL bNotify = TRUE);
  1014. virtual BOOL PreTranslateMessage(MSG* pMsg);
  1015. virtual LRESULT OnSetMessageString(WPARAM wParam, LPARAM lParam);
  1016. virtual ~COleIPFrameWnd();
  1017. #ifdef _DEBUG
  1018. virtual void AssertValid() const;
  1019. virtual void Dump(CDumpContext& dc) const;
  1020. #endif
  1021. protected:
  1022. // in-place state
  1023. OLEINPLACEFRAMEINFO m_frameInfo;
  1024. LPOLEINPLACEFRAME m_lpFrame;
  1025. LPOLEINPLACEUIWINDOW m_lpDocFrame;
  1026. HWND m_hWndFrame;
  1027. HWND m_hWndDocFrame;
  1028. HMENU m_hSharedMenu;
  1029. OLEMENUGROUPWIDTHS m_menuWidths;
  1030. HOLEMENU m_hOleMenu;
  1031. CRect m_rectPos; // client area rect of the item
  1032. CRect m_rectClip; // area to which frame should be clipped
  1033. BOOL m_bInsideRecalc;
  1034. // in-place activation support
  1035. BOOL BuildSharedMenu(COleServerDoc* pDoc);
  1036. void DestroySharedMenu(COleServerDoc* pDoc);
  1037. void UpdateControlBars(HWND hWnd);
  1038. protected:
  1039. //{{AFX_MSG(COleIPFrameWnd)
  1040. afx_msg void OnSize(UINT nType, int cx, int cy);
  1041. afx_msg LRESULT OnRecalcParent(WPARAM wParam, LPARAM lParam);
  1042. afx_msg LRESULT OnIdleUpdateCmdUI(WPARAM wParam, LPARAM lParam);
  1043. afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
  1044. afx_msg void OnDestroy();
  1045. afx_msg LRESULT OnResizeChild(WPARAM wParam, LPARAM lParam);
  1046. afx_msg void OnContextHelp();
  1047. //}}AFX_MSG
  1048. DECLARE_MESSAGE_MAP()
  1049. friend class COleServerDoc;
  1050. };
  1051. /////////////////////////////////////////////////////////////////////////////
  1052. // COleResizeBar - supports in-place resizing in server applications
  1053. class COleResizeBar : public CControlBar
  1054. {
  1055. DECLARE_DYNAMIC(COleResizeBar)
  1056. // Constructors
  1057. public:
  1058. COleResizeBar();
  1059. BOOL Create(CWnd* pParentWnd, DWORD dwStyle = WS_CHILD | WS_VISIBLE,
  1060. UINT nID = AFX_IDW_RESIZE_BAR);
  1061. // Implementation
  1062. public:
  1063. virtual ~COleResizeBar();
  1064. virtual void OnUpdateCmdUI(CFrameWnd* pTarget, BOOL bDisableIfNoHndler);
  1065. protected:
  1066. CRectTracker m_tracker; // implemented with a tracker
  1067. protected:
  1068. //{{AFX_MSG(COleResizeBar)
  1069. afx_msg BOOL OnEraseBkgnd(CDC* pDC);
  1070. afx_msg void OnPaint();
  1071. afx_msg void OnSize(UINT nType, int cx, int cy);
  1072. afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
  1073. afx_msg void OnLButtonDown(UINT, CPoint point);
  1074. afx_msg LRESULT OnSizeParent(WPARAM wParam, LPARAM lParam);
  1075. //}}AFX_MSG
  1076. DECLARE_MESSAGE_MAP()
  1077. };
  1078. /////////////////////////////////////////////////////////////////////////////
  1079. // COleStreamFile - implementation of CFile which uses an IStream
  1080. class COleStreamFile : public CFile
  1081. {
  1082. DECLARE_DYNAMIC(COleStreamFile)
  1083. // Constructors and Destructors
  1084. public:
  1085. COleStreamFile(LPSTREAM lpStream = NULL);
  1086. // Operations
  1087. // Note: OpenStream and CreateStream can accept eith STGM_ flags or
  1088. // CFile::OpenFlags bits since common values are guaranteed to have
  1089. // the same semantics.
  1090. BOOL OpenStream(LPSTORAGE lpStorage, LPCSTR lpszStreamName,
  1091. DWORD nOpenFlags = modeReadWrite|shareExclusive,
  1092. CFileException* pError = NULL);
  1093. BOOL CreateStream(LPSTORAGE lpStorage, LPCSTR lpszStreamName,
  1094. DWORD nOpenFlags = modeReadWrite|shareExclusive|modeCreate,
  1095. CFileException* pError = NULL);
  1096. BOOL CreateMemoryStream(CFileException* pError = NULL);
  1097. // attach & detach can be used when Open/Create functions aren't adequate
  1098. void Attach(LPSTREAM lpStream);
  1099. LPSTREAM Detach();
  1100. // Implementation
  1101. public:
  1102. LPSTREAM m_lpStream;
  1103. #ifdef _DEBUG
  1104. virtual void AssertValid() const;
  1105. virtual void Dump(CDumpContext& dc) const;
  1106. #endif
  1107. virtual ~COleStreamFile();
  1108. // attributes for implementation
  1109. BOOL GetStatus(CFileStatus& rStatus) const;
  1110. virtual DWORD GetPosition() const;
  1111. // overrides for implementation
  1112. virtual CFile* Duplicate() const;
  1113. virtual LONG Seek(LONG lOff, UINT nFrom);
  1114. virtual void SetLength(DWORD dwNewLen);
  1115. virtual DWORD GetLength() const;
  1116. virtual UINT Read(void FAR* lpBuf, UINT nCount);
  1117. virtual void Write(const void FAR* lpBuf, UINT nCount);
  1118. virtual void LockRange(DWORD dwPos, DWORD dwCount);
  1119. virtual void UnlockRange(DWORD dwPos, DWORD dwCount);
  1120. virtual void Abort();
  1121. virtual void Flush();
  1122. virtual void Close();
  1123. };
  1124. /////////////////////////////////////////////////////////////////////////////
  1125. // COleDropSource (advanced drop source support)
  1126. class COleDropSource : public CCmdTarget
  1127. {
  1128. // Constructors
  1129. public:
  1130. COleDropSource();
  1131. // Overridables
  1132. virtual SCODE QueryContinueDrag(BOOL bEscapePressed, DWORD dwKeyState);
  1133. virtual SCODE GiveFeedback(DROPEFFECT dropEffect);
  1134. virtual BOOL OnBeginDrag(CWnd* pWnd);
  1135. // Implementation
  1136. public:
  1137. #ifdef _DEBUG
  1138. virtual void Dump(CDumpContext& dc) const;
  1139. #endif
  1140. protected:
  1141. BEGIN_INTERFACE_PART(DropSource, IDropSource)
  1142. STDMETHOD(QueryContinueDrag)(BOOL, DWORD);
  1143. STDMETHOD(GiveFeedback)(DWORD);
  1144. END_INTERFACE_PART(DropSource)
  1145. DECLARE_INTERFACE_MAP()
  1146. CRect m_rectStartDrag; // when mouse leaves this rect, drag drop starts
  1147. BOOL m_bDragStarted; // has drag really started yet?
  1148. // metrics for drag start determination
  1149. static UINT nDragMinDist; // min. amount mouse must move for drag
  1150. static UINT nDragDelay; // delay before drag starts
  1151. friend class COleDataSource;
  1152. };
  1153. /////////////////////////////////////////////////////////////////////////////
  1154. // COleDropTarget (advanced drop target support)
  1155. class COleDropTarget : public CCmdTarget
  1156. {
  1157. // Constructors
  1158. public:
  1159. COleDropTarget();
  1160. // Operations
  1161. BOOL Register(CWnd* pWnd);
  1162. virtual void Revoke(); // virtual for implementation
  1163. // Overridables
  1164. virtual DROPEFFECT OnDragEnter(CWnd* pWnd, COleDataObject* pDataObject,
  1165. DWORD dwKeyState, CPoint point);
  1166. virtual DROPEFFECT OnDragOver(CWnd* pWnd, COleDataObject* pDataObject,
  1167. DWORD dwKeyState, CPoint point);
  1168. virtual BOOL OnDrop(CWnd* pWnd, COleDataObject* pDataObject,
  1169. DROPEFFECT dropEffect, CPoint point);
  1170. virtual void OnDragLeave(CWnd* pWnd);
  1171. virtual BOOL OnDragScroll(CWnd* pWnd, DWORD dwKeyState, CPoint point);
  1172. // Implementation
  1173. public:
  1174. virtual ~COleDropTarget();
  1175. #ifdef _DEBUG
  1176. virtual void AssertValid() const;
  1177. virtual void Dump(CDumpContext& dc) const;
  1178. #endif
  1179. protected:
  1180. HWND m_hWnd; // HWND this IDropTarget is attached to
  1181. LPDATAOBJECT m_lpDataObject; // != NULL between OnDragEnter, OnDragLeave
  1182. UINT m_nTimerID; // != MAKEWORD(-1, -1) when in scroll area
  1183. DWORD m_dwLastTick; // only valid when m_nTimerID valid
  1184. UINT m_nScrollDelay; // time to next scroll
  1185. // metrics for drag-scrolling
  1186. static int nScrollInset;
  1187. static UINT nScrollDelay;
  1188. static UINT nScrollInterval;
  1189. // implementation helpers
  1190. void SetupTimer(CView* pView, UINT nTimerID);
  1191. void CancelTimer(CWnd* pWnd);
  1192. // Interface Maps
  1193. protected:
  1194. BEGIN_INTERFACE_PART(DropTarget, IDropTarget)
  1195. STDMETHOD(DragEnter)(LPDATAOBJECT, DWORD, POINTL, LPDWORD);
  1196. STDMETHOD(DragOver)(DWORD, POINTL, LPDWORD);
  1197. STDMETHOD(DragLeave)();
  1198. STDMETHOD(Drop)(LPDATAOBJECT, DWORD, POINTL pt, LPDWORD);
  1199. END_INTERFACE_PART(DropTarget)
  1200. DECLARE_INTERFACE_MAP()
  1201. };
  1202. /////////////////////////////////////////////////////////////////////////////
  1203. // COleMessageFilter (implements IMessageFilter)
  1204. class COleMessageFilter : public CCmdTarget
  1205. {
  1206. // Constructors
  1207. public:
  1208. COleMessageFilter();
  1209. // Operations
  1210. BOOL Register();
  1211. void Revoke();
  1212. // for controlling the busy state of the server application (called app)
  1213. virtual void BeginBusyState();
  1214. virtual void EndBusyState();
  1215. void SetBusyReply(SERVERCALL nBusyReply);
  1216. // for controlling actions taken against rejected/retried calls
  1217. void SetRetryReply(DWORD nRetryReply = 0);
  1218. // only used when the "not responding" dialog is disabled
  1219. void SetMessagePendingDelay(DWORD nTimeout = 5000);
  1220. // used to determine amount of time before significant message
  1221. void EnableBusyDialog(BOOL bEnableBusy = TRUE);
  1222. void EnableNotRespondingDialog(BOOL bEnableNotResponding = TRUE);
  1223. // used to enable/disable the two types of busy dialogs
  1224. // Overridables
  1225. virtual BOOL OnMessagePending(const MSG* pMsg);
  1226. // return TRUE to eat the message (usually only if processed)
  1227. // Implementation
  1228. public:
  1229. #ifdef _DEBUG
  1230. virtual void AssertValid() const;
  1231. virtual void Dump(CDumpContext& dc) const;
  1232. #endif
  1233. virtual ~COleMessageFilter();
  1234. virtual BOOL IsSignificantMessage(MSG* pMsg);
  1235. // determine if any significant messages are present in the queue
  1236. virtual int OnBusyDialog(HTASK htaskBusy);
  1237. virtual int OnNotRespondingDialog(HTASK htaskBusy);
  1238. // these functions display the busy dialog
  1239. protected:
  1240. BOOL m_bRegistered;
  1241. LONG m_nBusyCount; // for BeginBusyState & EndBusyState
  1242. BOOL m_bEnableBusy;
  1243. BOOL m_bEnableNotResponding;
  1244. BOOL m_bUnblocking;
  1245. DWORD m_nRetryReply; // only used if m_bEnableNotResponding == FALSE
  1246. DWORD m_nBusyReply;
  1247. DWORD m_nTimeout;
  1248. // Interface Maps
  1249. protected:
  1250. BEGIN_INTERFACE_PART(MessageFilter, IMessageFilter)
  1251. STDMETHOD_(DWORD, HandleInComingCall)(DWORD, HTASK, DWORD, DWORD);
  1252. STDMETHOD_(DWORD, RetryRejectedCall)(HTASK, DWORD, DWORD);
  1253. STDMETHOD_(DWORD, MessagePending)(HTASK, DWORD, DWORD);
  1254. END_INTERFACE_PART(MessageFilter)
  1255. DECLARE_INTERFACE_MAP()
  1256. };
  1257. /////////////////////////////////////////////////////////////////////////////
  1258. // global helpers and debugging
  1259. void AFXAPI AfxOleSetEditMenu(COleClientItem* pClient, CMenu* pMenu,
  1260. UINT iMenuItem, UINT nIDVerbMin, UINT nIDVerbMax = 0, UINT nIDConvert = 0);
  1261. #ifdef _DEBUG
  1262. // Mapping SCODEs to readable text
  1263. LPCSTR AFXAPI AfxGetFullScodeString(SCODE sc);
  1264. LPCSTR AFXAPI AfxGetScodeString(SCODE sc);
  1265. LPCSTR AFXAPI AfxGetScodeRangeString(SCODE sc);
  1266. LPCSTR AFXAPI AfxGetSeverityString(SCODE sc);
  1267. LPCSTR AFXAPI AfxGetFacilityString(SCODE sc);
  1268. // Mapping IIDs to readable text
  1269. LPCSTR AFXAPI AfxGetIIDString(REFIID iid);
  1270. #endif
  1271. /////////////////////////////////////////////////////////////////////////////
  1272. // Inline function declarations
  1273. #ifdef _AFX_ENABLE_INLINES
  1274. #ifndef _AFXCTL
  1275. #define _AFXOLE_INLINE inline
  1276. #define _AFXOLECLI_INLINE inline
  1277. #define _AFXOLESVR_INLINE inline
  1278. #endif
  1279. #define _AFXOLEDOBJ_INLINE inline
  1280. #include <afxole.inl>
  1281. #undef _AFXOLE_INLINE
  1282. #undef _AFXOLECLI_INLINE
  1283. #undef _AFXOLESVR_INLINE
  1284. #undef _AFXOLEDOBJ_INLINE
  1285. #endif
  1286. #undef AFXAPP_DATA
  1287. #define AFXAPP_DATA NEAR
  1288. #endif //__AFXOLE_H__
  1289. /////////////////////////////////////////////////////////////////////////////