afxrich.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  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 __AFXRICH_H__
  11. #define __AFXRICH_H__
  12. #ifdef _AFX_NO_RICHEDIT_SUPPORT
  13. #error Windows RichEdit classes not supported in this library variant.
  14. #endif
  15. #ifndef __AFXWIN_H__
  16. #include <afxwin.h>
  17. #endif
  18. #ifndef __AFXDLGS_H__
  19. #include <afxdlgs.h>
  20. #endif
  21. #ifndef __AFXOLE_H__
  22. #include <afxole.h>
  23. #endif
  24. #ifndef _RICHEDIT_
  25. #include <richedit.h>
  26. #endif
  27. #ifndef _RICHOLE_
  28. #include <richole.h>
  29. #define _RICHOLE_
  30. #endif
  31. #ifndef __AFXCMN_H__
  32. #include <afxcmn.h>
  33. #endif
  34. #ifdef _AFX_MINREBUILD
  35. #pragma component(minrebuild, off)
  36. #endif
  37. #ifndef _AFX_FULLTYPEINFO
  38. #pragma component(mintypeinfo, on)
  39. #endif
  40. #ifdef _AFX_PACKING
  41. #pragma pack(push, _AFX_PACKING)
  42. #endif
  43. /////////////////////////////////////////////////////////////////////////////
  44. // AFXRICH - MFC RichEdit classes
  45. // Classes declared in this file
  46. //CObject
  47. //CCmdTarget;
  48. //CWnd
  49. //CView
  50. //CCtrlView
  51. class CRichEditView;// rich text editor view
  52. //CDocument
  53. //COleDocument
  54. class CRichEditDoc;
  55. //CDocItem
  56. //COleClientItem
  57. class CRichEditCntrItem;
  58. #undef AFX_DATA
  59. #define AFX_DATA AFX_OLE_DATA
  60. /////////////////////////////////////////////////////////////////////////////
  61. // CRichEditView
  62. class _AFX_RICHEDIT_STATE; // private to implementation
  63. class CRichEditView : public CCtrlView
  64. {
  65. DECLARE_DYNCREATE(CRichEditView)
  66. // Construction
  67. public:
  68. CRichEditView();
  69. // Attributes
  70. public:
  71. enum WordWrapType
  72. {
  73. WrapNone = 0,
  74. WrapToWindow = 1,
  75. WrapToTargetDevice = 2
  76. };
  77. int m_nWordWrap;
  78. int m_nBulletIndent;
  79. void SetPaperSize(CSize sizePaper);
  80. CSize GetPaperSize() const;
  81. void SetMargins(const CRect& rectMargin);
  82. CRect GetMargins() const;
  83. int GetPrintWidth() const;
  84. CRect GetPrintRect() const;
  85. CRect GetPageRect() const;
  86. //formatting
  87. CHARFORMAT& GetCharFormatSelection();
  88. PARAFORMAT& GetParaFormatSelection();
  89. void SetCharFormat(CHARFORMAT cf);
  90. BOOL SetParaFormat(PARAFORMAT& pf);
  91. CRichEditCntrItem* GetSelectedItem() const;
  92. CRichEditCntrItem* GetInPlaceActiveItem() const;
  93. // CEdit control access
  94. CRichEditCtrl& GetRichEditCtrl() const;
  95. CRichEditDoc* GetDocument() const;
  96. // other attributes
  97. long GetTextLength() const;
  98. static BOOL AFX_CDECL IsRichEditFormat(CLIPFORMAT cf);
  99. BOOL CanPaste() const;
  100. // Operations
  101. public:
  102. void AdjustDialogPosition(CDialog* pDlg);
  103. HRESULT InsertItem(CRichEditCntrItem* pItem);
  104. void InsertFileAsObject(LPCTSTR lpszFileName);
  105. BOOL FindText(LPCTSTR lpszFind, BOOL bCase = TRUE, BOOL bWord = TRUE);
  106. BOOL FindTextSimple(LPCTSTR lpszFind, BOOL bCase = TRUE,
  107. BOOL bWord = TRUE);
  108. long PrintInsideRect(CDC* pDC, RECT& rectLayout, long nIndexStart,
  109. long nIndexStop, BOOL bOutput);
  110. long PrintPage(CDC* pDC, long nIndexStart, long nIndexStop);
  111. void DoPaste(COleDataObject& dataobj, CLIPFORMAT cf,
  112. HMETAFILEPICT hMetaPict);
  113. // Helpers
  114. void OnCharEffect(DWORD dwMask, DWORD dwEffect);
  115. void OnUpdateCharEffect(CCmdUI* pCmdUI, DWORD dwMask, DWORD dwEffect) ;
  116. void OnParaAlign(WORD wAlign);
  117. void OnUpdateParaAlign(CCmdUI* pCmdUI, WORD wAlign);
  118. // Overrideables
  119. protected:
  120. virtual BOOL IsSelected(const CObject* pDocItem) const;
  121. virtual void OnInitialUpdate();
  122. virtual void OnFindNext(LPCTSTR lpszFind, BOOL bNext, BOOL bCase, BOOL bWord);
  123. virtual void OnReplaceSel(LPCTSTR lpszFind, BOOL bNext, BOOL bCase,
  124. BOOL bWord, LPCTSTR lpszReplace);
  125. virtual void OnReplaceAll(LPCTSTR lpszFind, LPCTSTR lpszReplace,
  126. BOOL bCase, BOOL bWord);
  127. virtual void OnTextNotFound(LPCTSTR lpszFind);
  128. virtual void OnPrinterChanged(const CDC& dcPrinter);
  129. virtual void WrapChanged();
  130. // Advanced
  131. virtual BOOL OnPasteNativeObject(LPSTORAGE lpStg);
  132. virtual HMENU GetContextMenu(WORD, LPOLEOBJECT, CHARRANGE* );
  133. virtual HRESULT GetClipboardData(CHARRANGE* lpchrg, DWORD dwReco,
  134. LPDATAOBJECT lpRichDataObj, LPDATAOBJECT* lplpdataobj);
  135. virtual HRESULT QueryAcceptData(LPDATAOBJECT, CLIPFORMAT*, DWORD,
  136. BOOL, HGLOBAL);
  137. // Implementation
  138. public:
  139. LPRICHEDITOLE m_lpRichEditOle;
  140. CDC m_dcTarget;
  141. long m_lInitialSearchPos;
  142. UINT m_nPasteType;
  143. BOOL m_bFirstSearch;
  144. void TextNotFound(LPCTSTR lpszFind);
  145. BOOL FindText(_AFX_RICHEDIT_STATE* pEditState);
  146. BOOL FindTextSimple(_AFX_RICHEDIT_STATE* pEditState);
  147. long FindAndSelect(DWORD dwFlags, FINDTEXTEX& ft);
  148. void Stream(CArchive& ar, BOOL bSelection);
  149. HRESULT GetWindowContext(LPOLEINPLACEFRAME* lplpFrame,
  150. LPOLEINPLACEUIWINDOW* lplpDoc, LPOLEINPLACEFRAMEINFO lpFrameInfo);
  151. HRESULT ShowContainerUI(BOOL b);
  152. static DWORD CALLBACK EditStreamCallBack(DWORD dwCookie,
  153. LPBYTE pbBuff, LONG cb, LONG *pcb);
  154. #ifdef _DEBUG
  155. virtual void AssertValid() const;
  156. virtual void Dump(CDumpContext& dc) const;
  157. #endif
  158. virtual void Serialize(CArchive& ar);
  159. virtual void DeleteContents();
  160. virtual void OnPrepareDC(CDC* pDC, CPrintInfo* pInfo);
  161. static AFX_DATA ULONG lMaxSize; // maximum number of characters supported
  162. protected:
  163. CRect m_rectMargin;
  164. CSize m_sizePaper;
  165. CDWordArray m_aPageStart; // array of starting pages
  166. PARAFORMAT m_paraformat;
  167. CHARFORMAT m_charformat;
  168. BOOL m_bSyncCharFormat;
  169. BOOL m_bSyncParaFormat;
  170. // construction
  171. virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
  172. // printing support
  173. virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
  174. virtual void OnPrint(CDC* pDC, CPrintInfo* pInfo);
  175. virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo = NULL);
  176. BOOL PaginateTo(CDC* pDC, CPrintInfo* pInfo);
  177. // find & replace support
  178. void OnEditFindReplace(BOOL bFindOnly);
  179. BOOL SameAsSelected(LPCTSTR lpszCompare, BOOL bCase, BOOL bWord);
  180. // special overrides for implementation
  181. //{{AFX_MSG(CRichEditView)
  182. afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
  183. afx_msg void OnUpdateNeedSel(CCmdUI* pCmdUI);
  184. afx_msg void OnUpdateNeedClip(CCmdUI* pCmdUI);
  185. afx_msg void OnUpdateNeedText(CCmdUI* pCmdUI);
  186. afx_msg void OnUpdateNeedFind(CCmdUI* pCmdUI);
  187. afx_msg void OnUpdateEditUndo(CCmdUI* pCmdUI);
  188. afx_msg void OnEditCut();
  189. afx_msg void OnEditCopy();
  190. afx_msg void OnEditPaste();
  191. afx_msg void OnEditClear();
  192. afx_msg void OnEditUndo();
  193. afx_msg void OnEditSelectAll();
  194. afx_msg void OnEditFind();
  195. afx_msg void OnEditReplace();
  196. afx_msg void OnEditRepeat();
  197. afx_msg void OnDestroy();
  198. afx_msg void OnEditProperties();
  199. afx_msg void OnUpdateEditProperties(CCmdUI* pCmdUI);
  200. afx_msg void OnInsertObject();
  201. afx_msg void OnCancelEditCntr();
  202. afx_msg void OnCharBold();
  203. afx_msg void OnUpdateCharBold(CCmdUI* pCmdUI);
  204. afx_msg void OnCharItalic();
  205. afx_msg void OnUpdateCharItalic(CCmdUI* pCmdUI);
  206. afx_msg void OnCharUnderline();
  207. afx_msg void OnUpdateCharUnderline(CCmdUI* pCmdUI);
  208. afx_msg void OnParaCenter();
  209. afx_msg void OnUpdateParaCenter(CCmdUI* pCmdUI);
  210. afx_msg void OnParaLeft();
  211. afx_msg void OnUpdateParaLeft(CCmdUI* pCmdUI);
  212. afx_msg void OnParaRight();
  213. afx_msg void OnUpdateParaRight(CCmdUI* pCmdUI);
  214. afx_msg void OnBullet();
  215. afx_msg void OnUpdateBullet(CCmdUI* pCmdUI);
  216. afx_msg void OnFormatFont();
  217. afx_msg void OnColorPick(COLORREF cr);
  218. afx_msg void OnColorDefault();
  219. afx_msg void OnEditPasteSpecial();
  220. afx_msg void OnUpdateEditPasteSpecial(CCmdUI* pCmdUI);
  221. afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
  222. afx_msg void OnDropFiles(HDROP hDropInfo);
  223. afx_msg void OnDevModeChange(LPTSTR lpDeviceName);
  224. //}}AFX_MSG
  225. afx_msg LRESULT OnFindReplaceCmd(WPARAM, LPARAM lParam);
  226. afx_msg void OnSelChange(NMHDR* pNMHDR, LRESULT* pResult);
  227. DECLARE_MESSAGE_MAP()
  228. // Interface Map
  229. public:
  230. BEGIN_INTERFACE_PART(RichEditOleCallback, IRichEditOleCallback)
  231. INIT_INTERFACE_PART(CRichEditView, RichEditOleCallback)
  232. STDMETHOD(GetNewStorage) (LPSTORAGE*);
  233. STDMETHOD(GetInPlaceContext) (LPOLEINPLACEFRAME*,
  234. LPOLEINPLACEUIWINDOW*,
  235. LPOLEINPLACEFRAMEINFO);
  236. STDMETHOD(ShowContainerUI) (BOOL);
  237. STDMETHOD(QueryInsertObject) (LPCLSID, LPSTORAGE, LONG);
  238. STDMETHOD(DeleteObject) (LPOLEOBJECT);
  239. STDMETHOD(QueryAcceptData) (LPDATAOBJECT, CLIPFORMAT*, DWORD,BOOL, HGLOBAL);
  240. STDMETHOD(ContextSensitiveHelp) (BOOL);
  241. STDMETHOD(GetClipboardData) (CHARRANGE*, DWORD, LPDATAOBJECT*);
  242. STDMETHOD(GetDragDropEffect) (BOOL, DWORD, LPDWORD);
  243. STDMETHOD(GetContextMenu) (WORD, LPOLEOBJECT, CHARRANGE*, HMENU*);
  244. END_INTERFACE_PART(RichEditOleCallback)
  245. DECLARE_INTERFACE_MAP()
  246. };
  247. /////////////////////////////////////////////////////////////////////////////
  248. // CRichEditDoc
  249. #ifdef _AFXDLL
  250. class CRichEditDoc : public COleServerDoc
  251. #else
  252. class AFX_NOVTABLE CRichEditDoc : public COleServerDoc
  253. #endif
  254. {
  255. protected: // create from serialization only
  256. CRichEditDoc();
  257. DECLARE_DYNAMIC(CRichEditDoc)
  258. // Attributes
  259. public:
  260. BOOL m_bRTF; // TRUE when formatted, FALSE when plain text
  261. virtual CRichEditCntrItem* CreateClientItem(REOBJECT* preo = NULL) const = 0;
  262. virtual CRichEditView* GetView() const;
  263. int GetStreamFormat() const;
  264. // Implementation
  265. protected:
  266. virtual COleServerItem* OnGetEmbeddedItem();
  267. void MarkItemsClear() const;
  268. void DeleteUnmarkedItems() const;
  269. void UpdateObjectCache();
  270. public:
  271. BOOL m_bUpdateObjectCache;
  272. virtual void SetPathName(LPCTSTR lpszPathName, BOOL bAddToMRU);
  273. virtual void SetTitle(LPCTSTR lpszTitle);
  274. virtual COleClientItem* GetPrimarySelectedItem(CView* pView);
  275. virtual void DeleteContents();
  276. virtual POSITION GetStartPosition() const;
  277. virtual void PreCloseFrame(CFrameWnd* pFrameWnd);
  278. virtual void UpdateModifiedFlag();
  279. virtual BOOL IsModified();
  280. virtual void SetModifiedFlag(BOOL bModified = TRUE);
  281. virtual COleClientItem* GetInPlaceActiveItem(CWnd* pWnd);
  282. CRichEditCntrItem* LookupItem(LPOLEOBJECT lpobj) const;
  283. void InvalidateObjectCache();
  284. virtual void Serialize(CArchive& ar); // overridden for document i/o
  285. #ifdef _DEBUG
  286. virtual void AssertValid() const;
  287. virtual void Dump(CDumpContext& dc) const;
  288. #endif
  289. };
  290. /////////////////////////////////////////////////////////////////////////////
  291. // CRichEditCntrItem
  292. class CRichEditCntrItem : public COleClientItem
  293. {
  294. DECLARE_SERIAL(CRichEditCntrItem)
  295. // Constructors
  296. public:
  297. CRichEditCntrItem(REOBJECT* preo = NULL, CRichEditDoc* pContainer = NULL);
  298. // Note: pContainer is allowed to be NULL to enable IMPLEMENT_SERIAL.
  299. // IMPLEMENT_SERIAL requires the class have a constructor with
  300. // zero arguments. Normally, OLE items are constructed with a
  301. // non-NULL document pointer.
  302. // Operations
  303. void SyncToRichEditObject(REOBJECT& reo);
  304. // Implementation
  305. public:
  306. ~CRichEditCntrItem();
  307. LPOLECLIENTSITE m_lpClientSite;
  308. BOOL m_bMark;
  309. BOOL m_bLock; // lock it during creation to avoid deletion
  310. void Mark(BOOL b);
  311. BOOL IsMarked();
  312. CRichEditDoc* GetDocument();
  313. CRichEditView* GetActiveView();
  314. HRESULT ShowContainerUI(BOOL b);
  315. HRESULT GetWindowContext(LPOLEINPLACEFRAME* lplpFrame,
  316. LPOLEINPLACEUIWINDOW* lplpDoc, LPOLEINPLACEFRAMEINFO lpFrameInfo);
  317. virtual LPOLECLIENTSITE GetClientSite();
  318. virtual BOOL ConvertTo(REFCLSID clsidNew);
  319. virtual BOOL ActivateAs(LPCTSTR lpszUserType, REFCLSID clsidOld,
  320. REFCLSID clsidNew);
  321. virtual void SetDrawAspect(DVASPECT nDrawAspect);
  322. virtual void OnDeactivateUI(BOOL bUndoable);
  323. virtual BOOL CanActivate();
  324. #ifdef _DEBUG
  325. virtual void AssertValid() const;
  326. virtual void Dump(CDumpContext& dc) const;
  327. #endif
  328. protected:
  329. virtual BOOL OnChangeItemPosition(const CRect& rectPos);
  330. };
  331. /////////////////////////////////////////////////////////////////////////////
  332. // Inline function declarations
  333. #ifdef _AFX_PACKING
  334. #pragma pack(pop)
  335. #endif
  336. #ifdef _AFX_ENABLE_INLINES
  337. #define _AFXRICH_INLINE AFX_INLINE
  338. #include <afxrich.inl>
  339. #endif
  340. #undef AFX_DATA
  341. #define AFX_DATA
  342. #ifdef _AFX_MINREBUILD
  343. #pragma component(minrebuild, on)
  344. #endif
  345. #ifndef _AFX_FULLTYPEINFO
  346. #pragma component(mintypeinfo, off)
  347. #endif
  348. #endif //__AFXRICH_H__
  349. /////////////////////////////////////////////////////////////////////////////