afxole.h 67 KB

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