UIRichEdit.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. #ifndef __UIRICHEDIT_H__
  2. #define __UIRICHEDIT_H__
  3. #pragma once
  4. namespace DuiLib {
  5. class CTxtWinHost;
  6. class UILIB_API CRichEditUI : public CContainerUI, public IMessageFilterUI
  7. {
  8. public:
  9. CRichEditUI();
  10. ~CRichEditUI();
  11. LPCTSTR GetClass() const;
  12. LPVOID GetInterface(LPCTSTR pstrName);
  13. UINT GetControlFlags() const;
  14. bool IsWantTab();
  15. void SetWantTab(bool bWantTab = true);
  16. bool IsWantReturn();
  17. void SetWantReturn(bool bWantReturn = true);
  18. bool IsWantCtrlReturn();
  19. void SetWantCtrlReturn(bool bWantCtrlReturn = true);
  20. bool IsTransparent();
  21. void SetTransparent(bool bTransparent = true);
  22. bool IsRich();
  23. void SetRich(bool bRich = true);
  24. bool IsReadOnly();
  25. void SetReadOnly(bool bReadOnly = true);
  26. bool GetWordWrap();
  27. void SetWordWrap(bool bWordWrap = true);
  28. int GetFont();
  29. void SetFont(int index);
  30. void SetFont(LPCTSTR pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic);
  31. LONG GetWinStyle();
  32. void SetWinStyle(LONG lStyle);
  33. DWORD GetTextColor();
  34. void SetTextColor(DWORD dwTextColor);
  35. int GetLimitText();
  36. void SetLimitText(int iChars);
  37. long GetTextLength(DWORD dwFlags = GTL_DEFAULT) const;
  38. CDuiString GetText() const;
  39. void SetText(LPCTSTR pstrText);
  40. bool GetModify() const;
  41. void SetModify(bool bModified = true) const;
  42. void GetSel(CHARRANGE &cr) const;
  43. void GetSel(long& nStartChar, long& nEndChar) const;
  44. int SetSel(CHARRANGE &cr);
  45. int SetSel(long nStartChar, long nEndChar);
  46. void ReplaceSel(LPCTSTR lpszNewText, bool bCanUndo);
  47. void ReplaceSelW(LPCWSTR lpszNewText, bool bCanUndo = false);
  48. CDuiString GetSelText() const;
  49. int SetSelAll();
  50. int SetSelNone();
  51. WORD GetSelectionType() const;
  52. bool GetZoom(int& nNum, int& nDen) const;
  53. bool SetZoom(int nNum, int nDen);
  54. bool SetZoomOff();
  55. bool GetAutoURLDetect() const;
  56. bool SetAutoURLDetect(bool bAutoDetect = true);
  57. DWORD GetEventMask() const;
  58. DWORD SetEventMask(DWORD dwEventMask);
  59. CDuiString GetTextRange(long nStartChar, long nEndChar) const;
  60. void HideSelection(bool bHide = true, bool bChangeStyle = false);
  61. void ScrollCaret();
  62. int InsertText(long nInsertAfterChar, LPCTSTR lpstrText, bool bCanUndo = false);
  63. int AppendText(LPCTSTR lpstrText, bool bCanUndo = false);
  64. DWORD GetDefaultCharFormat(CHARFORMAT2 &cf) const;
  65. bool SetDefaultCharFormat(CHARFORMAT2 &cf);
  66. DWORD GetSelectionCharFormat(CHARFORMAT2 &cf) const;
  67. bool SetSelectionCharFormat(CHARFORMAT2 &cf);
  68. bool SetWordCharFormat(CHARFORMAT2 &cf);
  69. DWORD GetParaFormat(PARAFORMAT2 &pf) const;
  70. bool SetParaFormat(PARAFORMAT2 &pf);
  71. bool Redo();
  72. bool Undo();
  73. void Clear();
  74. void Copy();
  75. void Cut();
  76. void Paste();
  77. int GetLineCount() const;
  78. CDuiString GetLine(int nIndex, int nMaxLength) const;
  79. int LineIndex(int nLine = -1) const;
  80. int LineLength(int nLine = -1) const;
  81. bool LineScroll(int nLines, int nChars = 0);
  82. CDuiPoint GetCharPos(long lChar) const;
  83. long LineFromChar(long nIndex) const;
  84. CDuiPoint PosFromChar(UINT nChar) const;
  85. int CharFromPos(CDuiPoint pt) const;
  86. void EmptyUndoBuffer();
  87. UINT SetUndoLimit(UINT nLimit);
  88. long StreamIn(int nFormat, EDITSTREAM &es);
  89. long StreamOut(int nFormat, EDITSTREAM &es);
  90. void DoInit();
  91. // 注意:TxSendMessage和SendMessage是有区别的,TxSendMessage没有multibyte和unicode自动转换的功能,
  92. // 而richedit2.0内部是以unicode实现的,在multibyte程序中,必须自己处理unicode到multibyte的转换
  93. bool SetDropAcceptFile(bool bAccept);
  94. virtual HRESULT TxSendMessage(UINT msg, WPARAM wparam, LPARAM lparam, LRESULT *plresult) const;
  95. IDropTarget* GetTxDropTarget();
  96. virtual bool OnTxViewChanged();
  97. virtual void OnTxNotify(DWORD iNotify, void *pv);
  98. void SetScrollPos(SIZE szPos);
  99. void LineUp();
  100. void LineDown();
  101. void PageUp();
  102. void PageDown();
  103. void HomeUp();
  104. void EndDown();
  105. void LineLeft();
  106. void LineRight();
  107. void PageLeft();
  108. void PageRight();
  109. void HomeLeft();
  110. void EndRight();
  111. SIZE EstimateSize(SIZE szAvailable);
  112. void SetPos(RECT rc, bool bNeedInvalidate = true);
  113. void Move(SIZE szOffset, bool bNeedInvalidate = true);
  114. void DoEvent(TEventUI& event);
  115. void DoPaint(HDC hDC, const RECT& rcPaint);
  116. void SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue);
  117. LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled);
  118. protected:
  119. enum {
  120. DEFAULT_TIMERID = 20,
  121. };
  122. CTxtWinHost* m_pTwh;
  123. bool m_bVScrollBarFixing;
  124. bool m_bWantTab;
  125. bool m_bWantReturn;
  126. bool m_bWantCtrlReturn;
  127. bool m_bTransparent;
  128. bool m_bRich;
  129. bool m_bReadOnly;
  130. bool m_bWordWrap;
  131. DWORD m_dwTextColor;
  132. int m_iFont;
  133. int m_iLimitText;
  134. LONG m_lTwhStyle;
  135. bool m_bDrawCaret;
  136. bool m_bInited;
  137. };
  138. } // namespace DuiLib
  139. #endif // __UIRICHEDIT_H__