home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / mfc / include / afxrich.h < prev    next >
C/C++ Source or Header  |  1998-06-16  |  12KB  |  404 lines

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