home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / MFCINC.PAK / AFXRICH.H < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  12.0 KB  |  397 lines

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