1 // Copyright 2014 PDFium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6 7 #ifndef XFA_FDE_CFDE_TXTEDTENGINE_H_ 8 #define XFA_FDE_CFDE_TXTEDTENGINE_H_ 9 10 #include <memory> 11 12 #include "core/fxcrt/cfx_retain_ptr.h" 13 #include "xfa/fde/ifde_txtedtengine.h" 14 15 class CFDE_TxtEdtBuf; 16 class CFDE_TxtEdtParag; 17 class CFX_TxtBreak; 18 class IFDE_TxtEdtDoRecord; 19 class IFX_CharIter; 20 21 class CFDE_TxtEdtEngine { 22 public: 23 CFDE_TxtEdtEngine(); 24 ~CFDE_TxtEdtEngine(); 25 26 void SetEditParams(const FDE_TXTEDTPARAMS& params); 27 FDE_TXTEDTPARAMS* GetEditParams(); 28 29 int32_t CountPages() const; 30 IFDE_TxtEdtPage* GetPage(int32_t nIndex); 31 32 void SetTextByStream(const CFX_RetainPtr<IFGAS_Stream>& pStream); 33 void SetText(const CFX_WideString& wsText); 34 int32_t GetTextLength() const; 35 CFX_WideString GetText(int32_t nStart, int32_t nCount) const; 36 void ClearText(); 37 38 int32_t GetCaretRect(CFX_RectF& rtCaret) const; 39 int32_t GetCaretPos() const; 40 int32_t SetCaretPos(int32_t nIndex, bool bBefore); 41 int32_t MoveCaretPos(FDE_TXTEDTMOVECARET eMoveCaret, 42 bool bShift = false, 43 bool bCtrl = false); 44 void Lock(); 45 void Unlock(); 46 bool IsLocked() const; 47 48 int32_t Insert(int32_t nStart, const FX_WCHAR* lpText, int32_t nLength); 49 int32_t Delete(int32_t nStart, bool bBackspace = false); 50 int32_t DeleteRange(int32_t nStart, int32_t nCount = -1); 51 int32_t Replace(int32_t nStart, 52 int32_t nLength, 53 const CFX_WideString& wsReplace); 54 55 void SetLimit(int32_t nLimit); 56 void SetAliasChar(FX_WCHAR wcAlias); 57 58 void RemoveSelRange(int32_t nStart, int32_t nCount); 59 60 void AddSelRange(int32_t nStart, int32_t nCount); 61 int32_t CountSelRanges() const; 62 int32_t GetSelRange(int32_t nIndex, int32_t* nStart) const; 63 void ClearSelection(); 64 65 bool Redo(const IFDE_TxtEdtDoRecord* pRecord); 66 bool Undo(const IFDE_TxtEdtDoRecord* pRecord); 67 68 int32_t StartLayout(); 69 int32_t DoLayout(IFX_Pause* pPause); 70 void EndLayout(); 71 72 int32_t CountParags() const; 73 CFDE_TxtEdtParag* GetParag(int32_t nParagIndex) const; 74 IFX_CharIter* CreateCharIter(); 75 CFDE_TxtEdtBuf* GetTextBuf() const; 76 int32_t GetTextBufLength() const; 77 CFX_TxtBreak* GetTextBreak() const; 78 int32_t GetLineCount() const; 79 int32_t GetPageLineCount() const; 80 81 int32_t Line2Parag(int32_t nStartParag, 82 int32_t nStartLineofParag, 83 int32_t nLineIndex, 84 int32_t& nStartLine) const; GetAliasChar()85 FX_WCHAR GetAliasChar() const { return m_wcAliasChar; } 86 87 private: 88 friend class CFDE_TxtEdtDoRecord_Insert; 89 friend class CFDE_TxtEdtDoRecord_DeleteRange; 90 friend class CFDE_TxtEdtPage; 91 92 struct FDE_TXTEDTSELRANGE { 93 int32_t nStart; 94 int32_t nCount; 95 }; 96 97 struct FDE_TXTEDTPARAGPOS { 98 int32_t nParagIndex; 99 int32_t nCharIndex; 100 }; 101 102 void Inner_Insert(int32_t nStart, const FX_WCHAR* lpText, int32_t nLength); 103 CFX_WideString GetPreDeleteText(int32_t nIndex, int32_t nLength); 104 CFX_WideString GetPreInsertText(int32_t nIndex, 105 const FX_WCHAR* lpText, 106 int32_t nLength); 107 CFX_WideString GetPreReplaceText(int32_t nIndex, 108 int32_t nOriginLength, 109 const FX_WCHAR* lpText, 110 int32_t nLength); 111 112 void Inner_DeleteRange(int32_t nStart, int32_t nCount = -1); 113 void DeleteRange_DoRecord(int32_t nStart, int32_t nCount, bool bSel = false); 114 void ResetEngine(); 115 void RebuildParagraphs(); 116 void RemoveAllParags(); 117 void RemoveAllPages(); 118 void UpdateParags(); 119 void UpdatePages(); 120 void UpdateTxtBreak(); 121 122 bool ReplaceParagEnd(FX_WCHAR*& lpText, 123 int32_t& nLength, 124 bool bPreIsCR = false); 125 void RecoverParagEnd(CFX_WideString& wsText) const; 126 int32_t MovePage2Char(int32_t nIndex); 127 void TextPos2ParagPos(int32_t nIndex, FDE_TXTEDTPARAGPOS& ParagPos) const; 128 int32_t MoveForward(bool& bBefore); 129 int32_t MoveBackward(bool& bBefore); 130 bool MoveUp(CFX_PointF& ptCaret); 131 bool MoveDown(CFX_PointF& ptCaret); 132 bool MoveLineStart(); 133 bool MoveLineEnd(); 134 bool MoveParagStart(); 135 bool MoveParagEnd(); 136 bool MoveHome(); 137 bool MoveEnd(); 138 bool IsFitArea(CFX_WideString& wsText); 139 void UpdateCaretRect(int32_t nIndex, bool bBefore = true); 140 void GetCaretRect(CFX_RectF& rtCaret, 141 int32_t nPageIndex, 142 int32_t nCaret, 143 bool bBefore = true); 144 void UpdateCaretIndex(const CFX_PointF& ptCaret); 145 146 bool IsSelect(); 147 void DeleteSelect(); 148 149 std::unique_ptr<CFDE_TxtEdtBuf> m_pTxtBuf; 150 std::unique_ptr<CFX_TxtBreak> m_pTextBreak; 151 FDE_TXTEDTPARAMS m_Param; 152 CFX_ArrayTemplate<IFDE_TxtEdtPage*> m_PagePtrArray; 153 CFX_ArrayTemplate<CFDE_TxtEdtParag*> m_ParagPtrArray; 154 CFX_ArrayTemplate<FDE_TXTEDTSELRANGE*> m_SelRangePtrArr; 155 int32_t m_nPageLineCount; 156 int32_t m_nLineCount; 157 int32_t m_nAnchorPos; 158 int32_t m_nLayoutPos; 159 FX_FLOAT m_fCaretPosReserve; 160 int32_t m_nCaret; 161 bool m_bBefore; 162 int32_t m_nCaretPage; 163 CFX_RectF m_rtCaret; 164 uint32_t m_dwFindFlags; 165 bool m_bLock; 166 int32_t m_nLimit; 167 FX_WCHAR m_wcAliasChar; 168 int32_t m_nFirstLineEnd; 169 bool m_bAutoLineEnd; 170 FX_WCHAR m_wLineEnd; 171 FDE_TXTEDT_TEXTCHANGE_INFO m_ChangeInfo; 172 }; 173 174 #endif // XFA_FDE_CFDE_TXTEDTENGINE_H_ 175