summaryrefslogtreecommitdiff
path: root/xfa/fee/fde_txtedtbuf.h
blob: e0598f5244db75b83fd3069cf73e567437b35393 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Copyright 2014 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

#ifndef XFA_FEE_FDE_TXTEDTBUF_H_
#define XFA_FEE_FDE_TXTEDTBUF_H_

#include "xfa/fee/ifde_txtedtbuf.h"
#include "xfa/fee/ifde_txtedtengine.h"
#include "xfa/fgas/crt/fgas_memory.h"

class IFX_CharIter;
class CFDE_TxtEdtBuf;

class CFDE_TxtEdtBufIter : public IFX_CharIter {
 public:
  CFDE_TxtEdtBufIter(CFDE_TxtEdtBuf* pBuf, FX_WCHAR wcAlias = 0);

  virtual void Release();
  virtual FX_BOOL Next(FX_BOOL bPrev = FALSE);
  virtual FX_WCHAR GetChar();
  virtual void SetAt(int32_t nIndex);
  virtual int32_t GetAt() const;
  virtual FX_BOOL IsEOF(FX_BOOL bTail = TRUE) const;
  virtual IFX_CharIter* Clone();

 protected:
  ~CFDE_TxtEdtBufIter();

 private:
  CFDE_TxtEdtBuf* m_pBuf;
  int32_t m_nCurChunk;
  int32_t m_nCurIndex;
  int32_t m_nIndex;
  FX_WCHAR m_Alias;
};
class CFDE_TxtEdtBuf : public IFDE_TxtEdtBuf {
  friend class CFDE_TxtEdtBufIter;
  struct _FDE_CHUNKHEADER {
    int32_t nUsed;
    FX_WCHAR wChars[1];
  };
  typedef _FDE_CHUNKHEADER FDE_CHUNKHEADER;
  typedef _FDE_CHUNKHEADER* FDE_LPCHUNKHEADER;
  struct _FDE_CHUNKPLACE {
    int32_t nChunkIndex;
    int32_t nCharIndex;
  };
  typedef _FDE_CHUNKPLACE FDE_CHUNKPLACE;
  typedef _FDE_CHUNKPLACE* FDE_LPCHUNKPLACE;

 public:
  CFDE_TxtEdtBuf(int32_t nDefChunkSize = FDE_DEFCHUNKLENGTH);

  virtual void Release();
  virtual FX_BOOL SetChunkSize(int32_t nChunkSize);
  virtual int32_t GetChunkSize() const;
  virtual int32_t GetTextLength() const;
  virtual void SetText(const CFX_WideString& wsText);
  virtual void GetText(CFX_WideString& wsText) const;
  virtual FX_WCHAR GetCharByIndex(int32_t nIndex) const;
  virtual void GetRange(CFX_WideString& wsText,
                        int32_t nBegine,
                        int32_t nCount = -1) const;

  virtual void Insert(int32_t nPos,
                      const FX_WCHAR* lpText,
                      int32_t nLength = 1);
  virtual void Delete(int32_t nIndex, int32_t nLength = 1);
  virtual void Clear(FX_BOOL bRelease = TRUE);

  virtual FX_BOOL Optimize(IFX_Pause* pPause = NULL);

 protected:
  virtual ~CFDE_TxtEdtBuf();

 private:
  void ResetChunkBuffer(int32_t nDefChunkCount, int32_t nChunkSize);
  int32_t CP2Index(const FDE_CHUNKPLACE& cp) const;
  void Index2CP(int32_t nIndex, FDE_CHUNKPLACE& cp) const;

  int32_t m_nChunkSize;

  int32_t m_nTotal;
  FX_BOOL m_bChanged;
  CFX_PtrArray m_Chunks;
  IFX_MEMAllocator* m_pAllocator;
};

#endif  // XFA_FEE_FDE_TXTEDTBUF_H_