• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 _FDE_TXTEDTBLOCK_H
8 #define _FDE_TXTEDTBLOCK_H
9 #ifdef FDE_USEFORMATBLOCK
10 class CFDE_TxtEdtEngine;
11 class CFDE_TxtEdtBlock;
12 class CFDE_TxtEdtFieldFormatParser;
13 class CFDE_TxtEdtField;
14 class CFDE_TxtEdtField_Integer;
15 class CFDE_TxtEdtField_Float;
16 class CFDE_TxtEdtField_Password;
17 class CFDE_TxtEdtField_String;
18 class CFDE_TxtEdtField_Fixed;
19 #define FDE_FORMAT_EDIT_FIELD_HADERSIZE 3
20 #define FDE_FORMAT_EDIT_FIELD_TAILSIZE 1
21 enum FDE_FORMAT_FIELD_INSERT_RET {
22   FDE_FORMAT_FIELD_INSERT_RET_S_NORMAL = 0,
23   FDE_FORMAT_FIELD_INSERT_RET_S_FULL,
24   FDE_FORMAT_FIELD_INSERT_RET_F_FULL,
25   FDE_FORMAT_FIELD_INSERT_RET_F_INVALIDATE,
26 };
27 enum FDE_FORMAT_FIELD_DELETE_RET {
28   FDE_FORMAT_FIELD_DELETE_RET_S = 0,
29   FDE_FORMAT_FIELD_DELETE_RET_F_INVALIDATE,
30   FDE_FORMAT_FIELD_DELETE_RET_F_BOUNDARY,
31 };
32 enum FDE_FORMAT_FIELD_VALIDATE_RET {
33   FDE_FORMAT_FIELD_VALIDATE_S = 0,
34   FDE_FORMAT_FIELD_VALIDATE_F_FULL,
35   FDE_FORMAT_FIELD_VALIDATE_F_INVALIDATE,
36 };
37 enum FDE_FORMAT_CARET_DIRECTION {
38   FDE_FORMAT_CARET_FORWARD,
39   FDE_FORMAT_CARET_MIDDLE,
40   FDE_FORMAT_CARET_BACKWARD
41 };
42 class CFDE_TxtEdtBlock {
43  public:
44   CFDE_TxtEdtBlock(CFDE_TxtEdtEngine* pEngine,
45                    const CFX_WideString& wsBlock,
46                    int32_t nPosition);
47   ~CFDE_TxtEdtBlock();
48   void GetDisplayText(CFX_WideString& wsDisplay);
49   int32_t GetLength() const;
50   void GetBlockText(CFX_WideString& wsBlock);
51   int32_t CountField() const;
52   void GetFieldText(int32_t nIndex, CFX_WideString& wsField);
53   int32_t GetFieldTextLength() const;
54 
55   int32_t GetPos() const;
56   void GetRealText(CFX_WideString& wsText) const;
57   void Backup();
58   void Restore();
SetIndex(int32_t nIndex)59   void SetIndex(int32_t nIndex) { m_nIndex = nIndex; }
GetIndex()60   int32_t GetIndex() const { return m_nIndex; }
61 
62  private:
63   CFDE_TxtEdtEngine* m_pEngine;
64   int32_t m_nDisplayLength;
65   int32_t m_nIndex;
66 
67   int32_t m_nPosition;
68   CFX_ArrayTemplate<CFDE_TxtEdtField*> m_FieldArr;
69   CFX_ArrayTemplate<CFDE_TxtEdtField*> m_EditFieldArr;
70 };
71 class CFDE_TxtEdtFieldFormatParser {
72  public:
73   CFDE_TxtEdtFieldFormatParser();
74   ~CFDE_TxtEdtFieldFormatParser();
75   FX_BOOL Parse(const CFX_WideString& wsFormat);
76   int32_t CountItems() const;
77   void GetItem(int32_t nIndex,
78                CFX_WideString& wsKey,
79                CFX_WideString& wsValue) const;
80 
81  private:
82   typedef struct {
83     int32_t nKeyStart;
84     int32_t nKeyCount;
85     int32_t nValStart;
86     int32_t nValCount;
87   } FDE_TXTEDTFORMATITEM, *FDE_LPTXTEDTFORMATITEM;
88 
89   CFX_WideString m_wsFormat;
90   CFX_ArrayTemplate<FDE_LPTXTEDTFORMATITEM> m_ItemArr;
91 };
92 class CFDE_TxtEdtField {
93  public:
94   static CFDE_TxtEdtField* Create(const CFX_WideString& wsField,
95                                   int32_t nIndex,
96                                   CFDE_TxtEdtBlock* pBlock);
97   virtual void Release();
98   virtual int32_t Insert(int32_t nIndex,
99                          const CFX_WideString& wsIns,
100                          int32_t& nCaret,
101                          FX_BOOL& bBefore);
102   virtual int32_t Delete(int32_t nIndex,
103                          int32_t nCount,
104                          CFX_WideString& wsDel,
105                          int32_t& nCaret,
106                          FX_BOOL& bBefore);
107   virtual int32_t Replace(int32_t nIndex,
108                           int32_t nCount,
109                           const CFX_WideString& wsIns,
110                           CFX_WideString& wsDel,
111                           int32_t& nCaret,
112                           FX_BOOL& bBefore);
113   virtual void GetDisplayText(CFX_WideString& wsDisplay);
114   virtual int32_t GetDisplayLength();
115   virtual void GetFieldText(CFX_WideString& wsField);
116   virtual int32_t GetFieldTextLength() const;
117   virtual int32_t GetRealIndex(int32_t nIndex) const;
118 
119   virtual int32_t NormalizeCaretPos(
120       int32_t nIndex,
121       FDE_FORMAT_CARET_DIRECTION eDirection = FDE_FORMAT_CARET_MIDDLE) const;
122 
123   virtual FX_BOOL GetEditableRange(int32_t& nBgn, int32_t& nEnd) const;
124   virtual void Backup();
125   virtual void Restore();
IsFix()126   virtual FX_BOOL IsFix() const { return FALSE; }
SetIndex(int32_t nIndex)127   void SetIndex(int32_t nIndex) { m_nIndex = nIndex; }
GetIndex()128   int32_t GetIndex() const { return m_nIndex; }
GetBlockIndex()129   int32_t GetBlockIndex() const { return m_pBlock->GetIndex(); }
130 
131  protected:
132   CFDE_TxtEdtField(int32_t nIndex, CFDE_TxtEdtBlock* pBlock);
~CFDE_TxtEdtField()133   virtual ~CFDE_TxtEdtField() {}
134   virtual int32_t Validate(const CFX_WideString& wsText) const;
135   virtual void GetNormalizedFieldText(CFX_WideString& wsField) const;
136   int32_t m_nLength;
137   CFX_WideString m_wsField;
138   CFX_WideString m_wsBackup;
139   FX_WCHAR m_wcFill;
140   FX_BOOL m_bReserveSpace;
141   FX_BOOL m_bLeftAlignment;
142   int32_t m_nIndex;
143   CFDE_TxtEdtBlock* m_pBlock;
144 };
145 class CFDE_TxtEdtField_Integer : public CFDE_TxtEdtField {
146  public:
147   CFDE_TxtEdtField_Integer(const CFX_WideString& wsField,
148                            int32_t nIndex,
149                            CFDE_TxtEdtBlock* pBlock);
150 
151  protected:
~CFDE_TxtEdtField_Integer()152   virtual ~CFDE_TxtEdtField_Integer() {}
153   virtual int32_t Validate(const CFX_WideString& wsText) const;
154 
155  private:
156   FX_BOOL m_bSign;
157 };
158 class CFDE_TxtEdtField_Float : public CFDE_TxtEdtField {
159  public:
160   CFDE_TxtEdtField_Float(const CFX_WideString& wsField,
161                          int32_t nIndex,
162                          CFDE_TxtEdtBlock* pBlock);
163 
164  protected:
~CFDE_TxtEdtField_Float()165   virtual ~CFDE_TxtEdtField_Float() {}
166   virtual int32_t Validate(const CFX_WideString& wsText) const;
167 
168  private:
169   FX_BOOL m_bSigned;
170   int32_t m_nIntPartlength;
171   int32_t m_nDecPartLength;
172 };
173 class CFDE_TxtEdtField_Password : public CFDE_TxtEdtField {
174  public:
175   CFDE_TxtEdtField_Password(const CFX_WideString& wsField,
176                             int32_t nIndex,
177                             CFDE_TxtEdtBlock* pBlock);
178 
179  protected:
~CFDE_TxtEdtField_Password()180   virtual ~CFDE_TxtEdtField_Password() {}
181   virtual void GetNormalizedFieldText(CFX_WideString& wsField) const;
182 
183  private:
184   FX_WCHAR m_wcAlias;
185 };
186 class CFDE_TxtEdtField_String : public CFDE_TxtEdtField {
187  public:
188   CFDE_TxtEdtField_String(const CFX_WideString& wsField,
189                           int32_t nIndex,
190                           CFDE_TxtEdtBlock* pBlock);
191 
192  protected:
~CFDE_TxtEdtField_String()193   virtual ~CFDE_TxtEdtField_String() {}
194 };
195 class CFDE_TxtEdtField_Fixed : public CFDE_TxtEdtField {
196  public:
197   CFDE_TxtEdtField_Fixed(const CFX_WideString& wsField,
198                          int32_t nIndex,
199                          CFDE_TxtEdtBlock* pBlock);
Insert(int32_t nIndex,const CFX_WideString & wsIns,int32_t & nCaret,FX_BOOL & bBefore)200   virtual int32_t Insert(int32_t nIndex,
201                          const CFX_WideString& wsIns,
202                          int32_t& nCaret,
203                          FX_BOOL& bBefore) {
204     return FALSE;
205   }
Delete(int32_t nIndex,int32_t nCount,CFX_WideString & wsDel,int32_t & nCaret,FX_BOOL & bBefore)206   virtual int32_t Delete(int32_t nIndex,
207                          int32_t nCount,
208                          CFX_WideString& wsDel,
209                          int32_t& nCaret,
210                          FX_BOOL& bBefore) {
211     return FALSE;
212   }
Replace(int32_t nIndex,int32_t nCount,const CFX_WideString & wsIns,CFX_WideString & wsDel,int32_t & nCaret,FX_BOOL & bBefore)213   virtual int32_t Replace(int32_t nIndex,
214                           int32_t nCount,
215                           const CFX_WideString& wsIns,
216                           CFX_WideString& wsDel,
217                           int32_t& nCaret,
218                           FX_BOOL& bBefore) {
219     return FALSE;
220   }
221   virtual void GetDisplayText(CFX_WideString& wsDisplay);
222   virtual int32_t NormalizeCaretPos(
223       int32_t nIndex,
224       FDE_FORMAT_CARET_DIRECTION eDirection) const;
GetEditableRange(int32_t & nBgn,int32_t & nEnd)225   virtual FX_BOOL GetEditableRange(int32_t& nBgn, int32_t& nEnd) const {
226     return FALSE;
227   }
Backup()228   virtual void Backup() {}
Restore()229   virtual void Restore() {}
230 
IsFix()231   virtual FX_BOOL IsFix() const { return TRUE; }
232 
233  protected:
~CFDE_TxtEdtField_Fixed()234   virtual ~CFDE_TxtEdtField_Fixed() {}
235 };
236 #endif
237 #endif
238