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 _IFDE_TXTEDTENGINE_H 8 #define _IFDE_TXTEDTENGINE_H 9 class IFDE_TxtEdtBuf; 10 class IFDE_TxtEdtPage; 11 class IFDE_TxtEdtEngine; 12 class IFDE_TxtEdtEventSink; 13 class IFDE_TxtEdtParag; 14 #define FDE_TXTEDT_FIND_FLAGS_Prev (0L << 0) 15 #define FDE_TXTEDT_FIND_FLAGS_Next (1L << 0) 16 #define FDE_TXTEDT_FIND_FLAGS_WholeWord (1L << 1) 17 #define FDE_TXTEDT_FIND_FLAGS_NoCase (1L << 2) 18 typedef struct _FDE_HTXTEDTFIND { void* pData; } * FDE_HTXTEDTFIND; 19 #define FDE_TEXTEDITMODE_MultiLines (1L << 0) 20 #define FDE_TEXTEDITMODE_AutoLineWrap (1L << 1) 21 #define FDE_TEXTEDITMODE_ReadOnly (1L << 2) 22 #define FDE_TEXTEDITMODE_LimitArea_Vert (1L << 3) 23 #define FDE_TEXTEDITMODE_LimitArea_Horz (1L << 4) 24 #define FDE_TEXTEDITMODE_NoRedoUndo (1L << 5) 25 #define FDE_TEXTEDITMODE_FIELD_TAB (1L << 6) 26 #define FDE_TEXTEDITMODE_FIELD_AUTO (1L << 7) 27 #define FDE_TEXTEDITMODE_Validate (1L << 8) 28 #define FDE_TEXTEDITMODE_Password (1L << 9) 29 #define FDE_TEXTEDITALIGN_Left (0L << 0) 30 #define FDE_TEXTEDITALIGN_Center (1L << 0) 31 #define FDE_TEXTEDITALIGN_Right (2L << 0) 32 #define FDE_TEXTEDITALIGN_Normal (1L << 3) 33 #define FDE_TEXTEDITALIGN_Justified (1L << 4) 34 #define FDE_TEXTEDITALIGN_Distributed (1L << 5) 35 #define FDE_TEXTEDITLAYOUT_DocVertical (1L << 0) 36 #define FDE_TEXTEDITLAYOUT_CharVertial (1L << 1) 37 #define FDE_TEXTEDITLAYOUT_LineReserve (1L << 2) 38 #define FDE_TEXTEDITLAYOUT_RTL (1L << 3) 39 #define FDE_TEXTEDITLAYOUT_CombText (1L << 4) 40 #define FDE_TEXTEDITLAYOUT_ExpandTab (1L << 5) 41 #define FDE_TEXTEDITLAYOUT_ArabicContext (1L << 6) 42 #define FDE_TEXTEDITLAYOUT_ArabicShapes (1L << 7) 43 #define FDE_TEXTEDITLAYOUT_LastLineHeight (1L << 8) 44 enum FDE_TXTEDTMOVECARET { 45 MC_MoveNone = 0, 46 MC_Left, 47 MC_Right, 48 MC_Up, 49 MC_Down, 50 MC_WordBackward, 51 MC_WordForward, 52 MC_LineStart, 53 MC_LineEnd, 54 MC_ParagStart, 55 MC_ParagEnd, 56 MC_PageUp, 57 MC_PageDown, 58 MC_Home, 59 MC_End, 60 }; 61 enum FDE_TXTEDT_MODIFY_RET { 62 FDE_TXTEDT_MODIFY_RET_F_Tab = -6, 63 FDE_TXTEDT_MODIFY_RET_F_Locked = -5, 64 FDE_TXTEDT_MODIFY_RET_F_Invalidate = -4, 65 FDE_TXTEDT_MODIFY_RET_F_Boundary = -3, 66 FDE_TXTEDT_MODIFY_RET_F_Full = -2, 67 FDE_TXTEDT_MODIFY_RET_F_Normal = -1, 68 FDE_TXTEDT_MODIFY_RET_S_Normal = 0, 69 FDE_TXTEDT_MODIFY_RET_S_Full = 1, 70 FDE_TXTEDT_MODIFY_RET_S_Part = 2, 71 FDE_TXTEDT_MODIFY_RET_S_Empty = 3, 72 FDE_TXTEDT_MODIFY_RET_T_Tab = 4, 73 }; 74 enum FDE_TXTEDIT_LINEEND { 75 FDE_TXTEDIT_LINEEND_Auto, 76 FDE_TXTEDIT_LINEEND_CRLF, 77 FDE_TXTEDIT_LINEEND_CR, 78 FDE_TXTEDIT_LINEEND_LF, 79 }; 80 struct _FDE_TXTEDTPARAMS { _FDE_TXTEDTPARAMS_FDE_TXTEDTPARAMS81 _FDE_TXTEDTPARAMS() 82 : fPlateWidth(0), 83 fPlateHeight(0), 84 nLineCount(0), 85 dwLayoutStyles(0), 86 dwAlignment(0), 87 dwMode(0), 88 pFont(NULL), 89 fFontSize(10.0f), 90 dwFontColor(0xff000000), 91 fLineSpace(10.0f), 92 fTabWidth(36), 93 bTabEquidistant(FALSE), 94 wDefChar(0xFEFF), 95 wLineBreakChar('\n'), 96 nCharRotation(0), 97 nLineEnd(0), 98 nHorzScale(100), 99 fCharSpace(0), 100 pEventSink(NULL) {} 101 FX_FLOAT fPlateWidth; 102 FX_FLOAT fPlateHeight; 103 int32_t nLineCount; 104 FX_DWORD dwLayoutStyles; 105 FX_DWORD dwAlignment; 106 FX_DWORD dwMode; 107 IFX_Font* pFont; 108 FX_FLOAT fFontSize; 109 FX_ARGB dwFontColor; 110 FX_FLOAT fLineSpace; 111 FX_FLOAT fTabWidth; 112 FX_BOOL bTabEquidistant; 113 FX_WCHAR wDefChar; 114 FX_WCHAR wLineBreakChar; 115 int32_t nCharRotation; 116 int32_t nLineEnd; 117 int32_t nHorzScale; 118 FX_FLOAT fCharSpace; 119 IFDE_TxtEdtEventSink* pEventSink; 120 }; 121 typedef _FDE_TXTEDTPARAMS FDE_TXTEDTPARAMS; 122 typedef _FDE_TXTEDTPARAMS* FDE_LPTXTEDTPARAMS; 123 enum FDE_TXTEDT_TEXTCHANGE_TYPE { 124 FDE_TXTEDT_TEXTCHANGE_TYPE_Insert = 0, 125 FDE_TXTEDT_TEXTCHANGE_TYPE_Delete, 126 FDE_TXTEDT_TEXTCHANGE_TYPE_Replace, 127 }; 128 struct _FDE_TXTEDT_TEXTCHANGE_INFO { 129 int32_t nChangeType; 130 CFX_WideString wsInsert; 131 CFX_WideString wsDelete; 132 CFX_WideString wsPrevText; 133 }; 134 typedef _FDE_TXTEDT_TEXTCHANGE_INFO FDE_TXTEDT_TEXTCHANGE_INFO; 135 typedef _FDE_TXTEDT_TEXTCHANGE_INFO* FDE_LPTXTEDT_TEXTCHANGE_INFO; 136 class IFDE_TxtEdtEventSink { 137 public: ~IFDE_TxtEdtEventSink()138 virtual ~IFDE_TxtEdtEventSink() {} 139 virtual void On_CaretChanged(IFDE_TxtEdtEngine* pEdit, 140 int32_t nPage, 141 FX_BOOL bVisible = TRUE) = 0; 142 virtual void On_TextChanged(IFDE_TxtEdtEngine* pEdit, 143 FDE_TXTEDT_TEXTCHANGE_INFO& ChangeInfo) = 0; 144 virtual void On_PageCountChanged(IFDE_TxtEdtEngine* pEdit) = 0; 145 virtual void On_SelChanged(IFDE_TxtEdtEngine* pEdit) = 0; 146 virtual FX_BOOL On_PageLoad(IFDE_TxtEdtEngine* pEdit, 147 int32_t nPageIndex, 148 int32_t nPurpose) = 0; 149 virtual FX_BOOL On_PageUnload(IFDE_TxtEdtEngine* pEdit, 150 int32_t nPageIndex, 151 int32_t nPurpose) = 0; 152 virtual FX_BOOL On_PageChange(IFDE_TxtEdtEngine* pEdit, 153 int32_t nPageIndex) = 0; 154 virtual void On_AddDoRecord(IFDE_TxtEdtEngine* pEdit, 155 const CFX_ByteStringC& bsDoRecord) = 0; 156 virtual FX_BOOL On_ValidateField(IFDE_TxtEdtEngine* pEdit, 157 int32_t nBlockIndex, 158 int32_t nFieldIndex, 159 const CFX_WideString& wsFieldText, 160 int32_t nCharIndex) = 0; 161 virtual FX_BOOL On_ValidateBlock(IFDE_TxtEdtEngine* pEdit, 162 int32_t nBlockIndex) = 0; 163 virtual FX_BOOL On_GetBlockFormatText(IFDE_TxtEdtEngine* pEdit, 164 int32_t nBlockIndex, 165 CFX_WideString& wsBlockText) = 0; 166 virtual FX_BOOL On_Validate(IFDE_TxtEdtEngine* pEdit, 167 CFX_WideString& wsText) = 0; 168 }; 169 class IFX_CharIter { 170 public: ~IFX_CharIter()171 virtual ~IFX_CharIter() {} 172 virtual void Release() = 0; 173 virtual FX_BOOL Next(FX_BOOL bPrev = FALSE) = 0; 174 virtual FX_WCHAR GetChar() = 0; 175 virtual void SetAt(int32_t nIndex) = 0; 176 virtual int32_t GetAt() const = 0; 177 virtual FX_BOOL IsEOF(FX_BOOL bTail = TRUE) const = 0; 178 virtual IFX_CharIter* Clone() = 0; 179 }; 180 class IFDE_TxtEdtEngine { 181 public: 182 static IFDE_TxtEdtEngine* Create(); 183 ~IFDE_TxtEdtEngine()184 virtual ~IFDE_TxtEdtEngine() {} 185 virtual void Release() = 0; 186 virtual void SetEditParams(const FDE_TXTEDTPARAMS& params) = 0; 187 virtual const FDE_TXTEDTPARAMS* GetEditParams() const = 0; 188 189 virtual int32_t CountPages() const = 0; 190 virtual IFDE_TxtEdtPage* GetPage(int32_t nIndex) = 0; 191 virtual FX_BOOL SetBufChunkSize(int32_t nChunkSize) = 0; 192 virtual void SetTextByStream(IFX_Stream* pStream) = 0; 193 virtual void SetText(const CFX_WideString& wsText) = 0; 194 virtual int32_t GetTextLength() const = 0; 195 virtual void GetText(CFX_WideString& wsText, 196 int32_t nStart, 197 int32_t nCount = -1) = 0; 198 virtual void ClearText() = 0; 199 200 virtual int32_t GetCaretRect(CFX_RectF& rtCaret) const = 0; 201 virtual int32_t GetCaretPos() const = 0; 202 virtual int32_t SetCaretPos(int32_t nIndex, FX_BOOL bBefore = TRUE) = 0; 203 virtual int32_t MoveCaretPos(FDE_TXTEDTMOVECARET eMoveCaret, 204 FX_BOOL bShift = FALSE, 205 FX_BOOL bCtrl = FALSE) = 0; 206 207 virtual void Lock() = 0; 208 virtual void Unlock() = 0; 209 virtual FX_BOOL IsLocked() const = 0; 210 211 virtual int32_t Insert(int32_t nStart, 212 const FX_WCHAR* lpText, 213 int32_t nLength) = 0; 214 virtual int32_t Delete(int32_t nStart, FX_BOOL bBackspace = FALSE) = 0; 215 virtual int32_t DeleteRange(int32_t nStart, int32_t nCount = -1) = 0; 216 virtual int32_t Replace(int32_t nStart, 217 int32_t nLength, 218 const CFX_WideString& wsReplace) = 0; 219 virtual void SetLimit(int32_t nLimit) = 0; 220 virtual void SetAliasChar(FX_WCHAR wAlias) = 0; 221 virtual void SetFormatBlock(int32_t nIndex, 222 const CFX_WideString& wsBlockFormat) = 0; 223 virtual int32_t CountEditBlocks() const = 0; 224 virtual void GetEditBlockText(int32_t nIndex, 225 CFX_WideString& wsBlockText) const = 0; 226 virtual int32_t CountEditFields(int32_t nBlockIndex) const = 0; 227 virtual void GetEditFieldText(int32_t nBlockIndex, 228 int32_t nFieldIndex, 229 CFX_WideString& wsFieldText) const = 0; 230 virtual void StartEdit() = 0; 231 virtual void EndEdit() = 0; 232 virtual void AddSelRange(int32_t nStart, int32_t nCount = -1) = 0; 233 virtual int32_t CountSelRanges() = 0; 234 virtual int32_t GetSelRange(int32_t nIndex, int32_t& nStart) = 0; 235 virtual void ClearSelection() = 0; 236 237 virtual FX_BOOL Redo(const CFX_ByteStringC& bsRedo) = 0; 238 virtual FX_BOOL Undo(const CFX_ByteStringC& bsUndo) = 0; 239 240 virtual int32_t StartLayout() = 0; 241 virtual int32_t DoLayout(IFX_Pause* pPause) = 0; 242 virtual void EndLayout() = 0; 243 244 virtual FX_BOOL Optimize(IFX_Pause* pPause = NULL) = 0; 245 virtual int32_t CountParags() const = 0; 246 virtual IFDE_TxtEdtParag* GetParag(int32_t nParagIndex) const = 0; 247 virtual IFX_CharIter* CreateCharIter() = 0; 248 }; 249 class IFDE_TxtEdtParag { 250 public: ~IFDE_TxtEdtParag()251 virtual ~IFDE_TxtEdtParag() {} 252 virtual int32_t GetTextLength() const = 0; 253 virtual int32_t GetStartIndex() const = 0; 254 virtual int32_t CountLines() const = 0; 255 virtual void GetLineRange(int32_t nLineIndex, 256 int32_t& nStart, 257 int32_t& nCount) const = 0; 258 }; 259 #endif 260