Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

407 lines
12 KiB

  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992-1998 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Foundation Classes Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Microsoft Foundation Classes product.
  10. #ifndef __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. #if _MFC_VER >= 0x0600
  91. BOOL SetParaFormat(PARAFORMAT& pf);
  92. #else
  93. void SetParaFormat(PARAFORMAT& pf);
  94. #endif
  95. CRichEditCntrItem* GetSelectedItem() const;
  96. CRichEditCntrItem* GetInPlaceActiveItem() const;
  97. // CEdit control access
  98. CRichEditCtrl& GetRichEditCtrl() const;
  99. CRichEditDoc* GetDocument() const;
  100. // other attributes
  101. long GetTextLength() const;
  102. static BOOL AFX_CDECL IsRichEditFormat(CLIPFORMAT cf);
  103. BOOL CanPaste() const;
  104. // Operations
  105. public:
  106. void AdjustDialogPosition(CDialog* pDlg);
  107. HRESULT InsertItem(CRichEditCntrItem* pItem);
  108. void InsertFileAsObject(LPCTSTR lpszFileName);
  109. BOOL FindText(LPCTSTR lpszFind, BOOL bCase = TRUE, BOOL bWord = TRUE);
  110. BOOL FindTextSimple(LPCTSTR lpszFind, BOOL bCase = TRUE,
  111. BOOL bWord = TRUE);
  112. long PrintInsideRect(CDC* pDC, RECT& rectLayout, long nIndexStart,
  113. long nIndexStop, BOOL bOutput);
  114. long PrintPage(CDC* pDC, long nIndexStart, long nIndexStop);
  115. void DoPaste(COleDataObject& dataobj, CLIPFORMAT cf,
  116. HMETAFILEPICT hMetaPict);
  117. // Helpers
  118. void OnCharEffect(DWORD dwMask, DWORD dwEffect);
  119. void OnUpdateCharEffect(CCmdUI* pCmdUI, DWORD dwMask, DWORD dwEffect) ;
  120. void OnParaAlign(WORD wAlign);
  121. void OnUpdateParaAlign(CCmdUI* pCmdUI, WORD wAlign);
  122. // Overrideables
  123. protected:
  124. virtual BOOL IsSelected(const CObject* pDocItem) const;
  125. virtual void OnInitialUpdate();
  126. virtual void OnFindNext(LPCTSTR lpszFind, BOOL bNext, BOOL bCase, BOOL bWord);
  127. virtual void OnReplaceSel(LPCTSTR lpszFind, BOOL bNext, BOOL bCase,
  128. BOOL bWord, LPCTSTR lpszReplace);
  129. virtual void OnReplaceAll(LPCTSTR lpszFind, LPCTSTR lpszReplace,
  130. BOOL bCase, BOOL bWord);
  131. virtual void OnTextNotFound(LPCTSTR lpszFind);
  132. virtual void OnPrinterChanged(const CDC& dcPrinter);
  133. virtual void WrapChanged();
  134. // Advanced
  135. virtual BOOL OnPasteNativeObject(LPSTORAGE lpStg);
  136. virtual HMENU GetContextMenu(WORD, LPOLEOBJECT, CHARRANGE* );
  137. virtual HRESULT GetClipboardData(CHARRANGE* lpchrg, DWORD dwReco,
  138. LPDATAOBJECT lpRichDataObj, LPDATAOBJECT* lplpdataobj);
  139. virtual HRESULT QueryAcceptData(LPDATAOBJECT, CLIPFORMAT*, DWORD,
  140. BOOL, HGLOBAL);
  141. // Implementation
  142. public:
  143. LPRICHEDITOLE m_lpRichEditOle;
  144. CDC m_dcTarget;
  145. long m_lInitialSearchPos;
  146. UINT m_nPasteType;
  147. BOOL m_bFirstSearch;
  148. void TextNotFound(LPCTSTR lpszFind);
  149. BOOL FindText(_AFX_RICHEDIT_STATE* pEditState);
  150. BOOL FindTextSimple(_AFX_RICHEDIT_STATE* pEditState);
  151. long FindAndSelect(DWORD dwFlags, FINDTEXTEX& ft);
  152. void Stream(CArchive& ar, BOOL bSelection);
  153. HRESULT GetWindowContext(LPOLEINPLACEFRAME* lplpFrame,
  154. LPOLEINPLACEUIWINDOW* lplpDoc, LPOLEINPLACEFRAMEINFO lpFrameInfo);
  155. HRESULT ShowContainerUI(BOOL b);
  156. static DWORD CALLBACK EditStreamCallBack(DWORD_PTR dwCookie,
  157. LPBYTE pbBuff, LONG cb, LONG *pcb);
  158. #ifdef _DEBUG
  159. virtual void AssertValid() const;
  160. virtual void Dump(CDumpContext& dc) const;
  161. #endif
  162. virtual void Serialize(CArchive& ar);
  163. virtual void DeleteContents();
  164. virtual void OnPrepareDC(CDC* pDC, CPrintInfo* pInfo);
  165. static AFX_DATA ULONG lMaxSize; // maximum number of characters supported
  166. protected:
  167. CRect m_rectMargin;
  168. CSize m_sizePaper;
  169. CDWordArray m_aPageStart; // array of starting pages
  170. PARAFORMAT m_paraformat;
  171. CHARFORMAT m_charformat;
  172. BOOL m_bSyncCharFormat;
  173. BOOL m_bSyncParaFormat;
  174. // construction
  175. virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
  176. // printing support
  177. virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
  178. virtual void OnPrint(CDC* pDC, CPrintInfo* pInfo);
  179. virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo = NULL);
  180. BOOL PaginateTo(CDC* pDC, CPrintInfo* pInfo);
  181. // find & replace support
  182. void OnEditFindReplace(BOOL bFindOnly);
  183. BOOL SameAsSelected(LPCTSTR lpszCompare, BOOL bCase, BOOL bWord);
  184. // special overrides for implementation
  185. //{{AFX_MSG(CRichEditView)
  186. afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
  187. afx_msg void OnUpdateNeedSel(CCmdUI* pCmdUI);
  188. afx_msg void OnUpdateNeedClip(CCmdUI* pCmdUI);
  189. afx_msg void OnUpdateNeedText(CCmdUI* pCmdUI);
  190. afx_msg void OnUpdateNeedFind(CCmdUI* pCmdUI);
  191. afx_msg void OnUpdateEditUndo(CCmdUI* pCmdUI);
  192. afx_msg void OnEditCut();
  193. afx_msg void OnEditCopy();
  194. afx_msg void OnEditPaste();
  195. afx_msg void OnEditClear();
  196. afx_msg void OnEditUndo();
  197. afx_msg void OnEditSelectAll();
  198. afx_msg void OnEditFind();
  199. afx_msg void OnEditReplace();
  200. afx_msg void OnEditRepeat();
  201. afx_msg void OnDestroy();
  202. afx_msg void OnEditProperties();
  203. afx_msg void OnUpdateEditProperties(CCmdUI* pCmdUI);
  204. afx_msg void OnInsertObject();
  205. afx_msg void OnCancelEditCntr();
  206. afx_msg void OnCharBold();
  207. afx_msg void OnUpdateCharBold(CCmdUI* pCmdUI);
  208. afx_msg void OnCharItalic();
  209. afx_msg void OnUpdateCharItalic(CCmdUI* pCmdUI);
  210. afx_msg void OnCharUnderline();
  211. afx_msg void OnUpdateCharUnderline(CCmdUI* pCmdUI);
  212. afx_msg void OnParaCenter();
  213. afx_msg void OnUpdateParaCenter(CCmdUI* pCmdUI);
  214. afx_msg void OnParaLeft();
  215. afx_msg void OnUpdateParaLeft(CCmdUI* pCmdUI);
  216. afx_msg void OnParaRight();
  217. afx_msg void OnUpdateParaRight(CCmdUI* pCmdUI);
  218. afx_msg void OnBullet();
  219. afx_msg void OnUpdateBullet(CCmdUI* pCmdUI);
  220. afx_msg void OnFormatFont();
  221. afx_msg void OnColorPick(COLORREF cr);
  222. afx_msg void OnColorDefault();
  223. afx_msg void OnEditPasteSpecial();
  224. afx_msg void OnUpdateEditPasteSpecial(CCmdUI* pCmdUI);
  225. afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
  226. afx_msg void OnDropFiles(HDROP hDropInfo);
  227. afx_msg void OnDevModeChange(LPTSTR lpDeviceName);
  228. //}}AFX_MSG
  229. afx_msg LRESULT OnFindReplaceCmd(WPARAM, LPARAM lParam);
  230. afx_msg void OnSelChange(NMHDR* pNMHDR, LRESULT* pResult);
  231. DECLARE_MESSAGE_MAP()
  232. // Interface Map
  233. public:
  234. BEGIN_INTERFACE_PART(RichEditOleCallback, IRichEditOleCallback)
  235. INIT_INTERFACE_PART(CRichEditView, RichEditOleCallback)
  236. STDMETHOD(GetNewStorage) (LPSTORAGE*);
  237. STDMETHOD(GetInPlaceContext) (LPOLEINPLACEFRAME*,
  238. LPOLEINPLACEUIWINDOW*,
  239. LPOLEINPLACEFRAMEINFO);
  240. STDMETHOD(ShowContainerUI) (BOOL);
  241. STDMETHOD(QueryInsertObject) (LPCLSID, LPSTORAGE, LONG);
  242. STDMETHOD(DeleteObject) (LPOLEOBJECT);
  243. STDMETHOD(QueryAcceptData) (LPDATAOBJECT, CLIPFORMAT*, DWORD,BOOL, HGLOBAL);
  244. STDMETHOD(ContextSensitiveHelp) (BOOL);
  245. STDMETHOD(GetClipboardData) (CHARRANGE*, DWORD, LPDATAOBJECT*);
  246. STDMETHOD(GetDragDropEffect) (BOOL, DWORD, LPDWORD);
  247. STDMETHOD(GetContextMenu) (WORD, LPOLEOBJECT, CHARRANGE*, HMENU*);
  248. END_INTERFACE_PART(RichEditOleCallback)
  249. DECLARE_INTERFACE_MAP()
  250. };
  251. /////////////////////////////////////////////////////////////////////////////
  252. // CRichEditDoc
  253. #ifdef _AFXDLL
  254. class CRichEditDoc : public COleServerDoc
  255. #else
  256. class AFX_NOVTABLE CRichEditDoc : public COleServerDoc
  257. #endif
  258. {
  259. protected: // create from serialization only
  260. CRichEditDoc();
  261. DECLARE_DYNAMIC(CRichEditDoc)
  262. // Attributes
  263. public:
  264. BOOL m_bRTF; // TRUE when formatted, FALSE when plain text
  265. virtual CRichEditCntrItem* CreateClientItem(REOBJECT* preo = NULL) const = 0;
  266. virtual CRichEditView* GetView() const;
  267. int GetStreamFormat() const;
  268. // Implementation
  269. protected:
  270. virtual COleServerItem* OnGetEmbeddedItem();
  271. void MarkItemsClear() const;
  272. void DeleteUnmarkedItems() const;
  273. void UpdateObjectCache();
  274. public:
  275. BOOL m_bUpdateObjectCache;
  276. virtual void SetPathName(LPCTSTR lpszPathName, BOOL bAddToMRU);
  277. virtual void SetTitle(LPCTSTR lpszTitle);
  278. virtual COleClientItem* GetPrimarySelectedItem(CView* pView);
  279. virtual void DeleteContents();
  280. virtual POSITION GetStartPosition() const;
  281. virtual void PreCloseFrame(CFrameWnd* pFrameWnd);
  282. virtual void UpdateModifiedFlag();
  283. virtual BOOL IsModified();
  284. virtual void SetModifiedFlag(BOOL bModified = TRUE);
  285. virtual COleClientItem* GetInPlaceActiveItem(CWnd* pWnd);
  286. CRichEditCntrItem* LookupItem(LPOLEOBJECT lpobj) const;
  287. void InvalidateObjectCache();
  288. virtual void Serialize(CArchive& ar); // overridden for document i/o
  289. #ifdef _DEBUG
  290. virtual void AssertValid() const;
  291. virtual void Dump(CDumpContext& dc) const;
  292. #endif
  293. };
  294. /////////////////////////////////////////////////////////////////////////////
  295. // CRichEditCntrItem
  296. class CRichEditCntrItem : public COleClientItem
  297. {
  298. DECLARE_SERIAL(CRichEditCntrItem)
  299. // Constructors
  300. public:
  301. CRichEditCntrItem(REOBJECT* preo = NULL, CRichEditDoc* pContainer = NULL);
  302. // Note: pContainer is allowed to be NULL to enable IMPLEMENT_SERIAL.
  303. // IMPLEMENT_SERIAL requires the class have a constructor with
  304. // zero arguments. Normally, OLE items are constructed with a
  305. // non-NULL document pointer.
  306. // Operations
  307. void SyncToRichEditObject(REOBJECT& reo);
  308. // Implementation
  309. public:
  310. ~CRichEditCntrItem();
  311. LPOLECLIENTSITE m_lpClientSite;
  312. BOOL m_bMark;
  313. BOOL m_bLock; // lock it during creation to avoid deletion
  314. void Mark(BOOL b);
  315. BOOL IsMarked();
  316. CRichEditDoc* GetDocument();
  317. CRichEditView* GetActiveView();
  318. HRESULT ShowContainerUI(BOOL b);
  319. HRESULT GetWindowContext(LPOLEINPLACEFRAME* lplpFrame,
  320. LPOLEINPLACEUIWINDOW* lplpDoc, LPOLEINPLACEFRAMEINFO lpFrameInfo);
  321. virtual LPOLECLIENTSITE GetClientSite();
  322. virtual BOOL ConvertTo(REFCLSID clsidNew);
  323. virtual BOOL ActivateAs(LPCTSTR lpszUserType, REFCLSID clsidOld,
  324. REFCLSID clsidNew);
  325. virtual void SetDrawAspect(DVASPECT nDrawAspect);
  326. virtual void OnDeactivateUI(BOOL bUndoable);
  327. virtual BOOL CanActivate();
  328. #ifdef _DEBUG
  329. virtual void AssertValid() const;
  330. virtual void Dump(CDumpContext& dc) const;
  331. #endif
  332. protected:
  333. virtual BOOL OnChangeItemPosition(const CRect& rectPos);
  334. };
  335. /////////////////////////////////////////////////////////////////////////////
  336. // Inline function declarations
  337. #ifdef _AFX_PACKING
  338. #pragma pack(pop)
  339. #endif
  340. #ifdef _AFX_ENABLE_INLINES
  341. #define _AFXRICH_INLINE AFX_INLINE
  342. #include <afxrich.inl>
  343. #endif
  344. #undef AFX_DATA
  345. #define AFX_DATA
  346. #ifdef _AFX_MINREBUILD
  347. #pragma component(minrebuild, on)
  348. #endif
  349. #ifndef _AFX_FULLTYPEINFO
  350. #pragma component(mintypeinfo, off)
  351. #endif
  352. #endif //__AFXRICH_H__
  353. /////////////////////////////////////////////////////////////////////////////