Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

412 lines
13 KiB

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