| OLD | NEW |
| (Empty) |
| 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_SRC_FEE_SRC_FEE_FDE_TXTEDTENGINE_H_ | |
| 8 #define XFA_SRC_FEE_SRC_FEE_FDE_TXTEDTENGINE_H_ | |
| 9 | |
| 10 #include "core/include/fxcrt/fx_string.h" | |
| 11 #include "xfa/src/fee/include/ifde_txtedtbuf.h" | |
| 12 #include "xfa/src/fee/include/ifde_txtedtengine.h" | |
| 13 | |
| 14 class IFX_TxtBreak; | |
| 15 class IFX_CharIter; | |
| 16 class CFDE_TxtEdtParag; | |
| 17 class CFDE_TxtEdtDoRecord_Insert; | |
| 18 class CFDE_TxtEdtDoRecord_DeleteRange; | |
| 19 | |
| 20 class IFDE_TxtEdtDoRecord { | |
| 21 public: | |
| 22 static IFDE_TxtEdtDoRecord* Create(const CFX_ByteStringC& bsDoRecord); | |
| 23 virtual ~IFDE_TxtEdtDoRecord() {} | |
| 24 virtual void Release() = 0; | |
| 25 virtual FX_BOOL Redo() = 0; | |
| 26 virtual FX_BOOL Undo() = 0; | |
| 27 virtual void Serialize(CFX_ByteString& bsDoRecord) const = 0; | |
| 28 }; | |
| 29 | |
| 30 class CFDE_TxtEdtEngine : public IFDE_TxtEdtEngine { | |
| 31 friend class CFDE_TxtEdtDoRecord_Insert; | |
| 32 friend class CFDE_TxtEdtDoRecord_DeleteRange; | |
| 33 friend class CFDE_TxtEdtPage; | |
| 34 struct _FDE_TXTEDTSELRANGE { | |
| 35 int32_t nStart; | |
| 36 int32_t nCount; | |
| 37 }; | |
| 38 typedef _FDE_TXTEDTSELRANGE FDE_TXTEDTSELRANGE; | |
| 39 typedef _FDE_TXTEDTSELRANGE* FDE_LPTXTEDTSELRANGE; | |
| 40 struct _FDE_TXTEDTPARAGPOS { | |
| 41 int32_t nParagIndex; | |
| 42 int32_t nCharIndex; | |
| 43 }; | |
| 44 typedef _FDE_TXTEDTPARAGPOS FDE_TXTEDTPARAGPOS; | |
| 45 typedef _FDE_TXTEDTPARAGPOS* FDE_LPTXTEDTPARAGPOS; | |
| 46 | |
| 47 public: | |
| 48 CFDE_TxtEdtEngine(); | |
| 49 virtual void Release(); | |
| 50 | |
| 51 virtual void SetEditParams(const FDE_TXTEDTPARAMS& params); | |
| 52 virtual const FDE_TXTEDTPARAMS* GetEditParams() const; | |
| 53 | |
| 54 virtual int32_t CountPages() const; | |
| 55 virtual IFDE_TxtEdtPage* GetPage(int32_t nIndex); | |
| 56 | |
| 57 virtual FX_BOOL SetBufChunkSize(int32_t nChunkSize); | |
| 58 virtual void SetTextByStream(IFX_Stream* pStream); | |
| 59 virtual void SetText(const CFX_WideString& wsText); | |
| 60 virtual int32_t GetTextLength() const; | |
| 61 virtual void GetText(CFX_WideString& wsText, | |
| 62 int32_t nStart, | |
| 63 int32_t nCount = -1); | |
| 64 virtual void ClearText(); | |
| 65 | |
| 66 virtual int32_t GetCaretRect(CFX_RectF& rtCaret) const; | |
| 67 virtual int32_t GetCaretPos() const; | |
| 68 virtual int32_t SetCaretPos(int32_t nIndex, FX_BOOL bBefore); | |
| 69 virtual int32_t MoveCaretPos(FDE_TXTEDTMOVECARET eMoveCaret, | |
| 70 FX_BOOL bShift = FALSE, | |
| 71 FX_BOOL bCtrl = FALSE); | |
| 72 virtual void Lock(); | |
| 73 virtual void Unlock(); | |
| 74 virtual FX_BOOL IsLocked() const; | |
| 75 | |
| 76 virtual int32_t Insert(int32_t nStart, | |
| 77 const FX_WCHAR* lpText, | |
| 78 int32_t nLength); | |
| 79 virtual int32_t Delete(int32_t nStart, FX_BOOL bBackspace = FALSE); | |
| 80 virtual int32_t DeleteRange(int32_t nStart, int32_t nCount = -1); | |
| 81 virtual int32_t Replace(int32_t nStart, | |
| 82 int32_t nLength, | |
| 83 const CFX_WideString& wsReplace); | |
| 84 | |
| 85 virtual void SetLimit(int32_t nLimit); | |
| 86 virtual void SetAliasChar(FX_WCHAR wcAlias); | |
| 87 | |
| 88 void RemoveSelRange(int32_t nStart, int32_t nCount = -1); | |
| 89 | |
| 90 virtual void AddSelRange(int32_t nStart, int32_t nCount = -1); | |
| 91 virtual int32_t CountSelRanges(); | |
| 92 virtual int32_t GetSelRange(int32_t nIndex, int32_t& nStart); | |
| 93 virtual void ClearSelection(); | |
| 94 | |
| 95 virtual FX_BOOL Redo(const CFX_ByteStringC& bsRedo); | |
| 96 virtual FX_BOOL Undo(const CFX_ByteStringC& bsUndo); | |
| 97 | |
| 98 virtual int32_t StartLayout(); | |
| 99 virtual int32_t DoLayout(IFX_Pause* pPause); | |
| 100 virtual void EndLayout(); | |
| 101 | |
| 102 virtual FX_BOOL Optimize(IFX_Pause* pPause = NULL); | |
| 103 virtual int32_t CountParags() const; | |
| 104 virtual IFDE_TxtEdtParag* GetParag(int32_t nParagIndex) const; | |
| 105 virtual IFX_CharIter* CreateCharIter(); | |
| 106 IFDE_TxtEdtBuf* GetTextBuf() const; | |
| 107 int32_t GetTextBufLength() const; | |
| 108 IFX_TxtBreak* GetTextBreak() const; | |
| 109 int32_t GetLineCount() const; | |
| 110 int32_t GetPageLineCount() const; | |
| 111 | |
| 112 int32_t Line2Parag(int32_t nStartParag, | |
| 113 int32_t nStartLineofParag, | |
| 114 int32_t nLineIndex, | |
| 115 int32_t& nStartLine) const; | |
| 116 FX_WCHAR GetAliasChar() const { return m_wcAliasChar; } | |
| 117 | |
| 118 protected: | |
| 119 virtual ~CFDE_TxtEdtEngine(); | |
| 120 | |
| 121 private: | |
| 122 void Inner_Insert(int32_t nStart, const FX_WCHAR* lpText, int32_t nLength); | |
| 123 void GetPreDeleteText(CFX_WideString& wsText, | |
| 124 int32_t nIndex, | |
| 125 int32_t nLength); | |
| 126 void GetPreInsertText(CFX_WideString& wsText, | |
| 127 int32_t nIndex, | |
| 128 const FX_WCHAR* lpText, | |
| 129 int32_t nLength); | |
| 130 void GetPreReplaceText(CFX_WideString& wsText, | |
| 131 int32_t nIndex, | |
| 132 int32_t nOriginLength, | |
| 133 const FX_WCHAR* lpText, | |
| 134 int32_t nLength); | |
| 135 | |
| 136 void Inner_DeleteRange(int32_t nStart, int32_t nCount = -1); | |
| 137 void DeleteRange_DoRecord(int32_t nStart, | |
| 138 int32_t nCount, | |
| 139 FX_BOOL bSel = FALSE); | |
| 140 void ResetEngine(); | |
| 141 void RebuildParagraphs(); | |
| 142 void RemoveAllParags(); | |
| 143 void RemoveAllPages(); | |
| 144 void UpdateParags(); | |
| 145 void UpdatePages(); | |
| 146 void UpdateTxtBreak(); | |
| 147 | |
| 148 FX_BOOL ReplaceParagEnd(FX_WCHAR*& lpText, | |
| 149 int32_t& nLength, | |
| 150 FX_BOOL bPreIsCR = FALSE); | |
| 151 void RecoverParagEnd(CFX_WideString& wsText); | |
| 152 int32_t MovePage2Char(int32_t nIndex); | |
| 153 void TextPos2ParagPos(int32_t nIndex, FDE_TXTEDTPARAGPOS& ParagPos) const; | |
| 154 int32_t MoveForward(FX_BOOL& bBefore); | |
| 155 int32_t MoveBackward(FX_BOOL& bBefore); | |
| 156 FX_BOOL MoveUp(CFX_PointF& ptCaret); | |
| 157 FX_BOOL MoveDown(CFX_PointF& ptCaret); | |
| 158 FX_BOOL MoveLineStart(); | |
| 159 FX_BOOL MoveLineEnd(); | |
| 160 FX_BOOL MoveParagStart(); | |
| 161 FX_BOOL MoveParagEnd(); | |
| 162 FX_BOOL MoveHome(); | |
| 163 FX_BOOL MoveEnd(); | |
| 164 FX_BOOL IsFitArea(CFX_WideString& wsText); | |
| 165 void UpdateCaretRect(int32_t nIndex, FX_BOOL bBefore = TRUE); | |
| 166 void GetCaretRect(CFX_RectF& rtCaret, | |
| 167 int32_t nPageIndex, | |
| 168 int32_t nCaret, | |
| 169 FX_BOOL bBefore = TRUE); | |
| 170 void UpdateCaretIndex(const CFX_PointF& ptCaret); | |
| 171 | |
| 172 FX_BOOL IsSelect(); | |
| 173 void DeleteSelect(); | |
| 174 | |
| 175 IFDE_TxtEdtBuf* m_pTxtBuf; | |
| 176 IFX_TxtBreak* m_pTextBreak; | |
| 177 FDE_TXTEDTPARAMS m_Param; | |
| 178 CFX_ArrayTemplate<IFDE_TxtEdtPage*> m_PagePtrArray; | |
| 179 CFX_ArrayTemplate<CFDE_TxtEdtParag*> m_ParagPtrArray; | |
| 180 CFX_ArrayTemplate<FDE_LPTXTEDTSELRANGE> m_SelRangePtrArr; | |
| 181 int32_t m_nPageLineCount; | |
| 182 int32_t m_nLineCount; | |
| 183 int32_t m_nAnchorPos; | |
| 184 int32_t m_nLayoutPos; | |
| 185 FX_FLOAT m_fCaretPosReserve; | |
| 186 int32_t m_nCaret; | |
| 187 FX_BOOL m_bBefore; | |
| 188 int32_t m_nCaretPage; | |
| 189 CFX_RectF m_rtCaret; | |
| 190 FX_DWORD m_dwFindFlags; | |
| 191 FX_BOOL m_bLock; | |
| 192 int32_t m_nLimit; | |
| 193 FX_WCHAR m_wcAliasChar; | |
| 194 int32_t m_nFirstLineEnd; | |
| 195 FX_BOOL m_bAutoLineEnd; | |
| 196 FX_WCHAR m_wLineEnd; | |
| 197 FDE_TXTEDT_TEXTCHANGE_INFO m_ChangeInfo; | |
| 198 }; | |
| 199 | |
| 200 class CFDE_TxtEdtDoRecord_Insert : public IFDE_TxtEdtDoRecord { | |
| 201 public: | |
| 202 CFDE_TxtEdtDoRecord_Insert(const CFX_ByteStringC& bsDoRecord); | |
| 203 CFDE_TxtEdtDoRecord_Insert(CFDE_TxtEdtEngine* pEngine, | |
| 204 int32_t nCaret, | |
| 205 const FX_WCHAR* lpText, | |
| 206 int32_t nLength); | |
| 207 virtual void Release(); | |
| 208 virtual FX_BOOL Undo(); | |
| 209 virtual FX_BOOL Redo(); | |
| 210 virtual void Serialize(CFX_ByteString& bsDoRecord) const; | |
| 211 | |
| 212 protected: | |
| 213 ~CFDE_TxtEdtDoRecord_Insert(); | |
| 214 void Deserialize(const CFX_ByteStringC& bsDoRecord); | |
| 215 | |
| 216 private: | |
| 217 CFDE_TxtEdtEngine* m_pEngine; | |
| 218 int32_t m_nCaret; | |
| 219 CFX_WideString m_wsInsert; | |
| 220 }; | |
| 221 | |
| 222 class CFDE_TxtEdtDoRecord_DeleteRange : public IFDE_TxtEdtDoRecord { | |
| 223 public: | |
| 224 CFDE_TxtEdtDoRecord_DeleteRange(const CFX_ByteStringC& bsDoRecord); | |
| 225 CFDE_TxtEdtDoRecord_DeleteRange(CFDE_TxtEdtEngine* pEngine, | |
| 226 int32_t nIndex, | |
| 227 int32_t nCaret, | |
| 228 const CFX_WideString& wsRange, | |
| 229 FX_BOOL bSel = FALSE); | |
| 230 virtual void Release(); | |
| 231 virtual FX_BOOL Undo(); | |
| 232 virtual FX_BOOL Redo(); | |
| 233 virtual void Serialize(CFX_ByteString& bsDoRecord) const; | |
| 234 | |
| 235 protected: | |
| 236 ~CFDE_TxtEdtDoRecord_DeleteRange(); | |
| 237 void Deserialize(const CFX_ByteStringC& bsDoRecord); | |
| 238 | |
| 239 private: | |
| 240 CFDE_TxtEdtEngine* m_pEngine; | |
| 241 FX_BOOL m_bSel; | |
| 242 int32_t m_nIndex; | |
| 243 int32_t m_nCaret; | |
| 244 CFX_WideString m_wsRange; | |
| 245 }; | |
| 246 | |
| 247 #endif // XFA_SRC_FEE_SRC_FEE_FDE_TXTEDTENGINE_H_ | |
| OLD | NEW |