• 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_TXTEDTBUF_H
8 #define _FDE_TXTEDTBUF_H
9 class IFX_CharIter;
10 class CFDE_TxtEdtBufIter;
11 class CFDE_TxtEdtBuf;
12 class CFDE_TxtEdtBufIter : public IFX_CharIter {
13  public:
14 #ifdef FDE_USEFORMATBLOCK
15   CFDE_TxtEdtBufIter(CFDE_TxtEdtBuf* pBuf, FX_BOOL bForDisplay = TRUE);
16 #else
17   CFDE_TxtEdtBufIter(CFDE_TxtEdtBuf* pBuf, FX_WCHAR wcAlias = 0);
18 #endif
19 
20   virtual void Release();
21   virtual FX_BOOL Next(FX_BOOL bPrev = FALSE);
22   virtual FX_WCHAR GetChar();
23   virtual void SetAt(int32_t nIndex);
24   virtual int32_t GetAt() const;
25   virtual FX_BOOL IsEOF(FX_BOOL bTail = TRUE) const;
26   virtual IFX_CharIter* Clone();
27 
28  protected:
29   ~CFDE_TxtEdtBufIter();
30 
31  private:
32   CFDE_TxtEdtBuf* m_pBuf;
33   int32_t m_nCurChunk;
34   int32_t m_nCurIndex;
35   int32_t m_nIndex;
36 #ifdef FDE_USEFORMATBLOCK
37   FX_BOOL m_bForDisplay;
38   int32_t m_nAliasCount;
39 #endif
40   FX_WCHAR m_Alias;
41 };
42 class CFDE_TxtEdtBuf : public IFDE_TxtEdtBuf {
43   friend class CFDE_TxtEdtBufIter;
44   struct _FDE_CHUNKHEADER {
45     int32_t nUsed;
46     FX_WCHAR wChars[1];
47   };
48   typedef _FDE_CHUNKHEADER FDE_CHUNKHEADER;
49   typedef _FDE_CHUNKHEADER* FDE_LPCHUNKHEADER;
50   struct _FDE_CHUNKPLACE {
51     int32_t nChunkIndex;
52     int32_t nCharIndex;
53   };
54   typedef _FDE_CHUNKPLACE FDE_CHUNKPLACE;
55   typedef _FDE_CHUNKPLACE* FDE_LPCHUNKPLACE;
56 
57  public:
58   CFDE_TxtEdtBuf(int32_t nDefChunkSize = FDE_DEFCHUNKLENGTH);
59 
60   virtual void Release();
61   virtual FX_BOOL SetChunkSize(int32_t nChunkSize);
62   virtual int32_t GetChunkSize() const;
63   virtual int32_t GetTextLength() const;
64   virtual void SetText(const CFX_WideString& wsText);
65   virtual void GetText(CFX_WideString& wsText) const;
66   virtual FX_WCHAR GetCharByIndex(int32_t nIndex) const;
67   virtual void GetRange(CFX_WideString& wsText,
68                         int32_t nBegine,
69                         int32_t nCount = -1) const;
70 
71   virtual void Insert(int32_t nPos,
72                       const FX_WCHAR* lpText,
73                       int32_t nLength = 1);
74   virtual void Delete(int32_t nIndex, int32_t nLength = 1);
75   virtual void Clear(FX_BOOL bRelease = TRUE);
76 
77   virtual FX_BOOL Optimize(IFX_Pause* pPause = NULL);
78 
79  protected:
80   virtual ~CFDE_TxtEdtBuf();
81 
82  private:
83   void ResetChunkBuffer(int32_t nDefChunkCount, int32_t nChunkSize);
84   int32_t CP2Index(const FDE_CHUNKPLACE& cp) const;
85   void Index2CP(int32_t nIndex, FDE_CHUNKPLACE& cp) const;
86 
87   int32_t m_nChunkSize;
88 
89   int32_t m_nTotal;
90   FX_BOOL m_bChanged;
91   CFX_PtrArray m_Chunks;
92   IFX_MEMAllocator* m_pAllocator;
93 };
94 #endif
95