blob: 387f6e700d49824676a91714208856ff1df88cf7 [file] [log] [blame]
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001// 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.
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
Dan Sinclairc411eb92017-07-25 09:39:30 -04007#ifndef FPDFSDK_PWL_CPWL_EDIT_IMPL_H_
8#define FPDFSDK_PWL_CPWL_EDIT_IMPL_H_
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07009
Tom Sepez3509d162017-01-30 13:22:02 -080010#include <deque>
thestig821d59e2016-05-11 12:59:22 -070011#include <memory>
tsepez6745f962017-01-04 10:09:45 -080012#include <vector>
thestig821d59e2016-05-11 12:59:22 -070013
Dan Sinclairce813f82017-10-05 15:12:58 -040014#include "core/fpdfdoc/cpdf_variabletext.h"
15#include "core/fpdfdoc/cpvt_wordrange.h"
Dan Sinclairaee0db02017-09-21 16:53:58 -040016#include "core/fxcrt/unowned_ptr.h"
Dan Sinclairc08dc392017-07-24 08:57:35 -040017
18#define FX_EDIT_ISLATINWORD(u) \
19 (u == 0x2D || (u <= 0x005A && u >= 0x0041) || \
20 (u <= 0x007A && u >= 0x0061) || (u <= 0x02AF && u >= 0x00C0))
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070021
dsinclair8faac622016-09-15 12:41:50 -070022class CFFL_FormFiller;
Dan Sinclair6b0158f2017-07-24 09:42:55 -040023class CPWL_EditImpl;
24class CPWL_EditImpl_Iterator;
25class CPWL_EditImpl_Provider;
dsinclaire35af1e2016-07-13 11:26:20 -070026class CFX_RenderDevice;
27class CFX_SystemHandler;
dsinclair8faac622016-09-15 12:41:50 -070028class CPWL_Edit;
29class CPWL_EditCtrl;
dsinclaire35af1e2016-07-13 11:26:20 -070030class IFX_Edit_UndoItem;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070031
Dan Sinclair6b0158f2017-07-24 09:42:55 -040032struct CPWL_EditImpl_LineRect {
33 CPWL_EditImpl_LineRect(const CPVT_WordRange& wrLine,
34 const CFX_FloatRect& rcLine)
Nico Weber9d8ec5a2015-08-04 13:00:21 -070035 : m_wrLine(wrLine), m_rcLine(rcLine) {}
36
Nico Weber9d8ec5a2015-08-04 13:00:21 -070037 CPVT_WordRange m_wrLine;
Tom Sepez281a9ea2016-02-26 14:24:28 -080038 CFX_FloatRect m_rcLine;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070039};
40
Dan Sinclair6b0158f2017-07-24 09:42:55 -040041class CPWL_EditImpl_LineRectArray {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070042 public:
Dan Sinclair6b0158f2017-07-24 09:42:55 -040043 CPWL_EditImpl_LineRectArray();
44 ~CPWL_EditImpl_LineRectArray();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070045
Dan Sinclair6b0158f2017-07-24 09:42:55 -040046 void operator=(CPWL_EditImpl_LineRectArray&& rects);
weili625ad662016-06-15 11:21:33 -070047 void Add(const CPVT_WordRange& wrLine, const CFX_FloatRect& rcLine);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070048
weili625ad662016-06-15 11:21:33 -070049 int32_t GetSize() const;
Dan Sinclair6b0158f2017-07-24 09:42:55 -040050 CPWL_EditImpl_LineRect* GetAt(int32_t nIndex) const;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070051
weili625ad662016-06-15 11:21:33 -070052 private:
Dan Sinclair6b0158f2017-07-24 09:42:55 -040053 std::vector<std::unique_ptr<CPWL_EditImpl_LineRect>> m_LineRects;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070054};
55
Dan Sinclair6b0158f2017-07-24 09:42:55 -040056class CPWL_EditImpl_RectArray {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070057 public:
Dan Sinclair6b0158f2017-07-24 09:42:55 -040058 CPWL_EditImpl_RectArray();
59 ~CPWL_EditImpl_RectArray();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070060
Tom Sepez3509d162017-01-30 13:22:02 -080061 void Clear();
weili625ad662016-06-15 11:21:33 -070062 void Add(const CFX_FloatRect& rect);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070063
weili625ad662016-06-15 11:21:33 -070064 int32_t GetSize() const;
65 CFX_FloatRect* GetAt(int32_t nIndex) const;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070066
weili625ad662016-06-15 11:21:33 -070067 private:
Tom Sepez3509d162017-01-30 13:22:02 -080068 std::vector<std::unique_ptr<CFX_FloatRect>> m_Rects;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070069};
70
Dan Sinclair6b0158f2017-07-24 09:42:55 -040071class CPWL_EditImpl_Refresh {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070072 public:
Dan Sinclair6b0158f2017-07-24 09:42:55 -040073 CPWL_EditImpl_Refresh();
74 ~CPWL_EditImpl_Refresh();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070075
Nico Weber9d8ec5a2015-08-04 13:00:21 -070076 void BeginRefresh();
Tom Sepez281a9ea2016-02-26 14:24:28 -080077 void Push(const CPVT_WordRange& linerange, const CFX_FloatRect& rect);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070078 void NoAnalyse();
Dan Sinclair6b0158f2017-07-24 09:42:55 -040079 const CPWL_EditImpl_RectArray* GetRefreshRects() const;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070080 void EndRefresh();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070081
Nico Weber9d8ec5a2015-08-04 13:00:21 -070082 private:
Dan Sinclair6b0158f2017-07-24 09:42:55 -040083 CPWL_EditImpl_LineRectArray m_NewLineRects;
84 CPWL_EditImpl_LineRectArray m_OldLineRects;
85 CPWL_EditImpl_RectArray m_RefreshRects;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070086};
87
Dan Sinclair6b0158f2017-07-24 09:42:55 -040088class CPWL_EditImpl_Select {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070089 public:
Dan Sinclair6b0158f2017-07-24 09:42:55 -040090 CPWL_EditImpl_Select();
91 explicit CPWL_EditImpl_Select(const CPVT_WordRange& range);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070092
Tom Sepez52f69b32017-03-21 13:42:38 -070093 void Reset();
weili625ad662016-06-15 11:21:33 -070094 void Set(const CPVT_WordPlace& begin, const CPVT_WordPlace& end);
weili625ad662016-06-15 11:21:33 -070095 void SetEndPos(const CPVT_WordPlace& end);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070096
weili625ad662016-06-15 11:21:33 -070097 CPVT_WordRange ConvertToWordRange() const;
Tom Sepez52f69b32017-03-21 13:42:38 -070098 bool IsEmpty() const;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070099
Tom Sepez3509d162017-01-30 13:22:02 -0800100 CPVT_WordPlace BeginPos;
101 CPVT_WordPlace EndPos;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700102};
103
Dan Sinclair6b0158f2017-07-24 09:42:55 -0400104class CPWL_EditImpl_Undo {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700105 public:
Lei Zhangbff66f12017-08-15 13:26:44 -0700106 CPWL_EditImpl_Undo();
Dan Sinclair6b0158f2017-07-24 09:42:55 -0400107 ~CPWL_EditImpl_Undo();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700108
Tom Sepez3509d162017-01-30 13:22:02 -0800109 void AddItem(std::unique_ptr<IFX_Edit_UndoItem> pItem);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700110 void Undo();
111 void Redo();
tsepez4cf55152016-11-02 14:37:54 -0700112 bool CanUndo() const;
113 bool CanRedo() const;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700114
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700115 private:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700116 void RemoveHeads();
117 void RemoveTails();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700118
Tom Sepez3509d162017-01-30 13:22:02 -0800119 std::deque<std::unique_ptr<IFX_Edit_UndoItem>> m_UndoItemStack;
120 size_t m_nCurUndoPos;
tsepez4cf55152016-11-02 14:37:54 -0700121 bool m_bWorking;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700122};
123
dsinclaire35af1e2016-07-13 11:26:20 -0700124class IFX_Edit_UndoItem {
125 public:
126 virtual ~IFX_Edit_UndoItem() {}
127
128 virtual void Undo() = 0;
129 virtual void Redo() = 0;
dsinclaire35af1e2016-07-13 11:26:20 -0700130};
131
Lei Zhangae9c5ca2017-08-12 07:15:14 -0700132class CFXEU_InsertWord : public IFX_Edit_UndoItem {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700133 public:
Dan Sinclair6b0158f2017-07-24 09:42:55 -0400134 CFXEU_InsertWord(CPWL_EditImpl* pEdit,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700135 const CPVT_WordPlace& wpOldPlace,
136 const CPVT_WordPlace& wpNewPlace,
Tom Sepez62a70f92016-03-21 15:00:20 -0700137 uint16_t word,
Dan Sinclair671a7992017-10-05 14:36:33 -0400138 int32_t charset);
Lei Zhang2b1a2d52015-08-14 22:16:22 -0700139 ~CFXEU_InsertWord() override;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700140
Lei Zhangae9c5ca2017-08-12 07:15:14 -0700141 // IFX_Edit_UndoItem:
Lei Zhang2b1a2d52015-08-14 22:16:22 -0700142 void Redo() override;
143 void Undo() override;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700144
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700145 private:
Dan Sinclairaee0db02017-09-21 16:53:58 -0400146 UnownedPtr<CPWL_EditImpl> m_pEdit;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700147
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700148 CPVT_WordPlace m_wpOld;
149 CPVT_WordPlace m_wpNew;
Tom Sepez62a70f92016-03-21 15:00:20 -0700150 uint16_t m_Word;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700151 int32_t m_nCharset;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700152};
153
Lei Zhangae9c5ca2017-08-12 07:15:14 -0700154class CFXEU_InsertReturn : public IFX_Edit_UndoItem {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700155 public:
Dan Sinclair6b0158f2017-07-24 09:42:55 -0400156 CFXEU_InsertReturn(CPWL_EditImpl* pEdit,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700157 const CPVT_WordPlace& wpOldPlace,
Dan Sinclair671a7992017-10-05 14:36:33 -0400158 const CPVT_WordPlace& wpNewPlace);
Lei Zhang2b1a2d52015-08-14 22:16:22 -0700159 ~CFXEU_InsertReturn() override;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700160
Lei Zhangae9c5ca2017-08-12 07:15:14 -0700161 // IFX_Edit_UndoItem:
Lei Zhang2b1a2d52015-08-14 22:16:22 -0700162 void Redo() override;
163 void Undo() override;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700164
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700165 private:
Dan Sinclairaee0db02017-09-21 16:53:58 -0400166 UnownedPtr<CPWL_EditImpl> m_pEdit;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700167
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700168 CPVT_WordPlace m_wpOld;
169 CPVT_WordPlace m_wpNew;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700170};
171
Lei Zhangae9c5ca2017-08-12 07:15:14 -0700172class CFXEU_Backspace : public IFX_Edit_UndoItem {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700173 public:
Dan Sinclair6b0158f2017-07-24 09:42:55 -0400174 CFXEU_Backspace(CPWL_EditImpl* pEdit,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700175 const CPVT_WordPlace& wpOldPlace,
176 const CPVT_WordPlace& wpNewPlace,
Tom Sepez62a70f92016-03-21 15:00:20 -0700177 uint16_t word,
Dan Sinclair671a7992017-10-05 14:36:33 -0400178 int32_t charset);
Lei Zhang2b1a2d52015-08-14 22:16:22 -0700179 ~CFXEU_Backspace() override;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700180
Lei Zhangae9c5ca2017-08-12 07:15:14 -0700181 // IFX_Edit_UndoItem:
Lei Zhang2b1a2d52015-08-14 22:16:22 -0700182 void Redo() override;
183 void Undo() override;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700184
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700185 private:
Dan Sinclairaee0db02017-09-21 16:53:58 -0400186 UnownedPtr<CPWL_EditImpl> m_pEdit;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700187
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700188 CPVT_WordPlace m_wpOld;
189 CPVT_WordPlace m_wpNew;
Tom Sepez62a70f92016-03-21 15:00:20 -0700190 uint16_t m_Word;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700191 int32_t m_nCharset;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700192};
193
Lei Zhangae9c5ca2017-08-12 07:15:14 -0700194class CFXEU_Delete : public IFX_Edit_UndoItem {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700195 public:
Dan Sinclair6b0158f2017-07-24 09:42:55 -0400196 CFXEU_Delete(CPWL_EditImpl* pEdit,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700197 const CPVT_WordPlace& wpOldPlace,
198 const CPVT_WordPlace& wpNewPlace,
Tom Sepez62a70f92016-03-21 15:00:20 -0700199 uint16_t word,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700200 int32_t charset,
tsepez4cf55152016-11-02 14:37:54 -0700201 bool bSecEnd);
Lei Zhang2b1a2d52015-08-14 22:16:22 -0700202 ~CFXEU_Delete() override;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700203
Lei Zhangae9c5ca2017-08-12 07:15:14 -0700204 // IFX_Edit_UndoItem:
Lei Zhang2b1a2d52015-08-14 22:16:22 -0700205 void Redo() override;
206 void Undo() override;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700207
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700208 private:
Dan Sinclairaee0db02017-09-21 16:53:58 -0400209 UnownedPtr<CPWL_EditImpl> m_pEdit;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700210
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700211 CPVT_WordPlace m_wpOld;
212 CPVT_WordPlace m_wpNew;
Tom Sepez62a70f92016-03-21 15:00:20 -0700213 uint16_t m_Word;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700214 int32_t m_nCharset;
tsepez4cf55152016-11-02 14:37:54 -0700215 bool m_bSecEnd;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700216};
217
Lei Zhangae9c5ca2017-08-12 07:15:14 -0700218class CFXEU_Clear : public IFX_Edit_UndoItem {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700219 public:
Dan Sinclair6b0158f2017-07-24 09:42:55 -0400220 CFXEU_Clear(CPWL_EditImpl* pEdit,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700221 const CPVT_WordRange& wrSel,
Ryan Harrison275e2602017-09-18 14:23:18 -0400222 const WideString& swText);
Lei Zhang2b1a2d52015-08-14 22:16:22 -0700223 ~CFXEU_Clear() override;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700224
Lei Zhangae9c5ca2017-08-12 07:15:14 -0700225 // IFX_Edit_UndoItem:
Lei Zhang2b1a2d52015-08-14 22:16:22 -0700226 void Redo() override;
227 void Undo() override;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700228
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700229 private:
Dan Sinclairaee0db02017-09-21 16:53:58 -0400230 UnownedPtr<CPWL_EditImpl> m_pEdit;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700231
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700232 CPVT_WordRange m_wrSel;
Ryan Harrison275e2602017-09-18 14:23:18 -0400233 WideString m_swText;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700234};
235
Lei Zhangae9c5ca2017-08-12 07:15:14 -0700236class CFXEU_InsertText : public IFX_Edit_UndoItem {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700237 public:
Dan Sinclair6b0158f2017-07-24 09:42:55 -0400238 CFXEU_InsertText(CPWL_EditImpl* pEdit,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700239 const CPVT_WordPlace& wpOldPlace,
240 const CPVT_WordPlace& wpNewPlace,
Ryan Harrison275e2602017-09-18 14:23:18 -0400241 const WideString& swText,
dsinclairefd5a992016-07-18 10:04:07 -0700242 int32_t charset);
Lei Zhang2b1a2d52015-08-14 22:16:22 -0700243 ~CFXEU_InsertText() override;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700244
Lei Zhangae9c5ca2017-08-12 07:15:14 -0700245 // IFX_Edit_UndoItem:
Lei Zhang2b1a2d52015-08-14 22:16:22 -0700246 void Redo() override;
247 void Undo() override;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700248
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700249 private:
Dan Sinclairaee0db02017-09-21 16:53:58 -0400250 UnownedPtr<CPWL_EditImpl> m_pEdit;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700251
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700252 CPVT_WordPlace m_wpOld;
253 CPVT_WordPlace m_wpNew;
Ryan Harrison275e2602017-09-18 14:23:18 -0400254 WideString m_swText;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700255 int32_t m_nCharset;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700256};
257
Dan Sinclair6b0158f2017-07-24 09:42:55 -0400258class CPWL_EditImpl {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700259 public:
dsinclaire35af1e2016-07-13 11:26:20 -0700260 static void DrawEdit(CFX_RenderDevice* pDevice,
Lei Zhangeb14e042017-08-15 13:56:43 -0700261 const CFX_Matrix& mtUser2Device,
Dan Sinclair6b0158f2017-07-24 09:42:55 -0400262 CPWL_EditImpl* pEdit,
dsinclaire35af1e2016-07-13 11:26:20 -0700263 FX_COLORREF crTextFill,
dsinclaire35af1e2016-07-13 11:26:20 -0700264 const CFX_FloatRect& rcClip,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500265 const CFX_PointF& ptOffset,
dsinclaire35af1e2016-07-13 11:26:20 -0700266 const CPVT_WordRange* pRange,
267 CFX_SystemHandler* pSystemHandler,
dsinclair8faac622016-09-15 12:41:50 -0700268 CFFL_FormFiller* pFFLData);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700269
Dan Sinclair6b0158f2017-07-24 09:42:55 -0400270 CPWL_EditImpl();
271 ~CPWL_EditImpl();
dsinclaire35af1e2016-07-13 11:26:20 -0700272
273 void SetFontMap(IPVT_FontMap* pFontMap);
274 void SetNotify(CPWL_EditCtrl* pNotify);
Lei Zhang5688d622017-08-12 07:04:19 -0700275 void SetOperationNotify(CPWL_Edit* pOperationNotify);
dsinclaire35af1e2016-07-13 11:26:20 -0700276
277 // Returns an iterator for the contents. Should not be released.
Dan Sinclair6b0158f2017-07-24 09:42:55 -0400278 CPWL_EditImpl_Iterator* GetIterator();
dsinclaire35af1e2016-07-13 11:26:20 -0700279 IPVT_FontMap* GetFontMap();
280 void Initialize();
281
282 // Set the bounding box of the text area.
dsinclairefd5a992016-07-18 10:04:07 -0700283 void SetPlateRect(const CFX_FloatRect& rect);
Dan Sinclairf528eee2017-02-14 11:52:07 -0500284 void SetScrollPos(const CFX_PointF& point);
dsinclaire35af1e2016-07-13 11:26:20 -0700285
286 // Set the horizontal text alignment. (nFormat [0:left, 1:middle, 2:right])
tsepez4cf55152016-11-02 14:37:54 -0700287 void SetAlignmentH(int32_t nFormat, bool bPaint);
dsinclaire35af1e2016-07-13 11:26:20 -0700288 // Set the vertical text alignment. (nFormat [0:left, 1:middle, 2:right])
tsepez4cf55152016-11-02 14:37:54 -0700289 void SetAlignmentV(int32_t nFormat, bool bPaint);
dsinclaire35af1e2016-07-13 11:26:20 -0700290
291 // Set the substitution character for hidden text.
tsepez4cf55152016-11-02 14:37:54 -0700292 void SetPasswordChar(uint16_t wSubWord, bool bPaint);
dsinclaire35af1e2016-07-13 11:26:20 -0700293
294 // Set the maximum number of words in the text.
dsinclairefd5a992016-07-18 10:04:07 -0700295 void SetLimitChar(int32_t nLimitChar);
296 void SetCharArray(int32_t nCharArray);
Dan Sinclair05df0752017-03-14 14:43:42 -0400297 void SetCharSpace(float fCharSpace);
tsepez4cf55152016-11-02 14:37:54 -0700298 void SetMultiLine(bool bMultiLine, bool bPaint);
299 void SetAutoReturn(bool bAuto, bool bPaint);
300 void SetAutoFontSize(bool bAuto, bool bPaint);
301 void SetAutoScroll(bool bAuto, bool bPaint);
Dan Sinclair05df0752017-03-14 14:43:42 -0400302 void SetFontSize(float fFontSize);
tsepez4cf55152016-11-02 14:37:54 -0700303 void SetTextOverflow(bool bAllowed, bool bPaint);
Dan Sinclairf528eee2017-02-14 11:52:07 -0500304 void OnMouseDown(const CFX_PointF& point, bool bShift, bool bCtrl);
305 void OnMouseMove(const CFX_PointF& point, bool bShift, bool bCtrl);
tsepez4cf55152016-11-02 14:37:54 -0700306 void OnVK_UP(bool bShift, bool bCtrl);
307 void OnVK_DOWN(bool bShift, bool bCtrl);
308 void OnVK_LEFT(bool bShift, bool bCtrl);
309 void OnVK_RIGHT(bool bShift, bool bCtrl);
310 void OnVK_HOME(bool bShift, bool bCtrl);
311 void OnVK_END(bool bShift, bool bCtrl);
Ryan Harrison275e2602017-09-18 14:23:18 -0400312 void SetText(const WideString& sText);
tsepez4cf55152016-11-02 14:37:54 -0700313 bool InsertWord(uint16_t word, int32_t charset);
314 bool InsertReturn();
315 bool Backspace();
316 bool Delete();
Diana Gage22bf7a52017-07-21 11:33:18 -0700317 bool ClearSelection();
Ryan Harrison275e2602017-09-18 14:23:18 -0400318 bool InsertText(const WideString& sText, int32_t charset);
tsepez4cf55152016-11-02 14:37:54 -0700319 bool Redo();
320 bool Undo();
dsinclaire35af1e2016-07-13 11:26:20 -0700321 CPVT_WordPlace WordIndexToWordPlace(int32_t index) const;
Dan Sinclairf528eee2017-02-14 11:52:07 -0500322 CPVT_WordPlace SearchWordPlace(const CFX_PointF& point) const;
dsinclaire35af1e2016-07-13 11:26:20 -0700323 int32_t GetCaret() const;
324 CPVT_WordPlace GetCaretWordPlace() const;
Ryan Harrison275e2602017-09-18 14:23:18 -0400325 WideString GetSelectedText() const;
326 WideString GetText() const;
Dan Sinclair05df0752017-03-14 14:43:42 -0400327 float GetFontSize() const;
dsinclaire35af1e2016-07-13 11:26:20 -0700328 uint16_t GetPasswordChar() const;
Dan Sinclairf528eee2017-02-14 11:52:07 -0500329 CFX_PointF GetScrollPos() const;
dsinclaire35af1e2016-07-13 11:26:20 -0700330 int32_t GetCharArray() const;
dsinclaire35af1e2016-07-13 11:26:20 -0700331 CFX_FloatRect GetContentRect() const;
Ryan Harrison275e2602017-09-18 14:23:18 -0400332 WideString GetRangeText(const CPVT_WordRange& range) const;
dsinclaire35af1e2016-07-13 11:26:20 -0700333 int32_t GetHorzScale() const;
Dan Sinclair05df0752017-03-14 14:43:42 -0400334 float GetCharSpace() const;
Diana Gage4d02e902017-07-20 17:20:31 -0700335 void SetSelection(int32_t nStartChar, int32_t nEndChar);
336 void GetSelection(int32_t& nStartChar, int32_t& nEndChar) const;
dsinclaire35af1e2016-07-13 11:26:20 -0700337 void SelectAll();
338 void SelectNone();
tsepez4cf55152016-11-02 14:37:54 -0700339 bool IsSelected() const;
dsinclaire35af1e2016-07-13 11:26:20 -0700340 void Paint();
tsepez4cf55152016-11-02 14:37:54 -0700341 void EnableRefresh(bool bRefresh);
dsinclaire35af1e2016-07-13 11:26:20 -0700342 void RefreshWordRange(const CPVT_WordRange& wr);
dsinclaire35af1e2016-07-13 11:26:20 -0700343 CPVT_WordRange GetWholeWordRange() const;
344 CPVT_WordRange GetSelectWordRange() const;
tsepez4cf55152016-11-02 14:37:54 -0700345 void EnableUndo(bool bUndo);
tsepez4cf55152016-11-02 14:37:54 -0700346 bool IsTextFull() const;
347 bool IsTextOverflow() const;
348 bool CanUndo() const;
349 bool CanRedo() const;
dsinclaire35af1e2016-07-13 11:26:20 -0700350 CPVT_WordRange GetVisibleWordRange() const;
Lei Zhang2b1a2d52015-08-14 22:16:22 -0700351
tsepez4cf55152016-11-02 14:37:54 -0700352 bool Empty();
Lei Zhang2b1a2d52015-08-14 22:16:22 -0700353
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700354 CPVT_WordPlace DoInsertText(const CPVT_WordPlace& place,
Ryan Harrison275e2602017-09-18 14:23:18 -0400355 const WideString& sText,
dsinclairefd5a992016-07-18 10:04:07 -0700356 int32_t charset);
Tom Sepez62a70f92016-03-21 15:00:20 -0700357 int32_t GetCharSetFromUnicode(uint16_t word, int32_t nOldCharset);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700358
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700359 int32_t GetTotalLines() const;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700360
Ryan Harrison275e2602017-09-18 14:23:18 -0400361 ByteString GetPDFWordString(int32_t nFontIndex,
362 uint16_t Word,
363 uint16_t SubWord);
Dan Sinclairc08dc392017-07-24 08:57:35 -0400364
Diana Gage4d02e902017-07-20 17:20:31 -0700365 void SetSelection(const CPVT_WordPlace& begin, const CPVT_WordPlace& end);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700366
Dan Sinclair6dc4fb82017-10-17 09:08:26 -0400367 bool Delete(bool bAddUndo, bool bPaint);
368 bool Clear(bool bAddUndo, bool bPaint);
369 bool InsertText(const WideString& sText,
370 int32_t charset,
371 bool bAddUndo,
372 bool bPaint);
373 bool InsertWord(uint16_t word, int32_t charset, bool bAddUndo, bool bPaint);
374 bool InsertReturn(bool bAddUndo, bool bPaint);
375 bool Backspace(bool bAddUndo, bool bPaint);
376 void SetCaret(const CPVT_WordPlace& place);
377
378 CFX_PointF VTToEdit(const CFX_PointF& point) const;
379
380 private:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700381 void RearrangeAll();
382 void RearrangePart(const CPVT_WordRange& range);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700383 void ScrollToCaret();
384 void SetScrollInfo();
Dan Sinclair05df0752017-03-14 14:43:42 -0400385 void SetScrollPosX(float fx);
386 void SetScrollPosY(float fy);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700387 void SetScrollLimit();
388 void SetContentChanged();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700389
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700390 void PaintInsertText(const CPVT_WordPlace& wpOld,
391 const CPVT_WordPlace& wpNew);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700392
Dan Sinclair6dc4fb82017-10-17 09:08:26 -0400393 CFX_PointF EditToVT(const CFX_PointF& point) const;
394 CFX_FloatRect VTToEdit(const CFX_FloatRect& rect) const;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700395
dsinclairefd5a992016-07-18 10:04:07 -0700396 void Refresh();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700397 void RefreshPushLineRects(const CPVT_WordRange& wr);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700398
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700399 void SetCaretInfo();
400 void SetCaretOrigin();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700401
Lei Zhangae9c5ca2017-08-12 07:15:14 -0700402 void AddEditUndoItem(std::unique_ptr<IFX_Edit_UndoItem> pEditUndoItem);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700403
dsinclaire35af1e2016-07-13 11:26:20 -0700404 std::unique_ptr<CPDF_VariableText> m_pVT;
Dan Sinclairaee0db02017-09-21 16:53:58 -0400405 UnownedPtr<CPWL_EditCtrl> m_pNotify;
406 UnownedPtr<CPWL_Edit> m_pOperationNotify;
Dan Sinclair6b0158f2017-07-24 09:42:55 -0400407 std::unique_ptr<CPWL_EditImpl_Provider> m_pVTProvider;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700408 CPVT_WordPlace m_wpCaret;
409 CPVT_WordPlace m_wpOldCaret;
Dan Sinclair6b0158f2017-07-24 09:42:55 -0400410 CPWL_EditImpl_Select m_SelState;
Dan Sinclairf528eee2017-02-14 11:52:07 -0500411 CFX_PointF m_ptScrollPos;
412 CFX_PointF m_ptRefreshScrollPos;
tsepez4cf55152016-11-02 14:37:54 -0700413 bool m_bEnableScroll;
Dan Sinclair6b0158f2017-07-24 09:42:55 -0400414 std::unique_ptr<CPWL_EditImpl_Iterator> m_pIterator;
415 CPWL_EditImpl_Refresh m_Refresh;
Dan Sinclairf528eee2017-02-14 11:52:07 -0500416 CFX_PointF m_ptCaret;
Dan Sinclair6b0158f2017-07-24 09:42:55 -0400417 CPWL_EditImpl_Undo m_Undo;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700418 int32_t m_nAlignment;
tsepez4cf55152016-11-02 14:37:54 -0700419 bool m_bNotifyFlag;
420 bool m_bEnableOverflow;
421 bool m_bEnableRefresh;
Tom Sepez281a9ea2016-02-26 14:24:28 -0800422 CFX_FloatRect m_rcOldContent;
tsepez4cf55152016-11-02 14:37:54 -0700423 bool m_bEnableUndo;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700424};
425
Dan Sinclair6b0158f2017-07-24 09:42:55 -0400426class CPWL_EditImpl_Iterator {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700427 public:
Dan Sinclair6b0158f2017-07-24 09:42:55 -0400428 CPWL_EditImpl_Iterator(CPWL_EditImpl* pEdit,
429 CPDF_VariableText::Iterator* pVTIterator);
430 ~CPWL_EditImpl_Iterator();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700431
tsepez4cf55152016-11-02 14:37:54 -0700432 bool NextWord();
433 bool PrevWord();
434 bool GetWord(CPVT_Word& word) const;
435 bool GetLine(CPVT_Line& line) const;
dsinclaire35af1e2016-07-13 11:26:20 -0700436 void SetAt(int32_t nWordIndex);
437 void SetAt(const CPVT_WordPlace& place);
438 const CPVT_WordPlace& GetAt() const;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700439
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700440 private:
Dan Sinclairaee0db02017-09-21 16:53:58 -0400441 UnownedPtr<CPWL_EditImpl> m_pEdit;
dsinclairc7a73492016-04-05 12:01:42 -0700442 CPDF_VariableText::Iterator* m_pVTIterator;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700443};
444
Dan Sinclair6b0158f2017-07-24 09:42:55 -0400445class CPWL_EditImpl_Provider : public CPDF_VariableText::Provider {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700446 public:
Dan Sinclair6b0158f2017-07-24 09:42:55 -0400447 explicit CPWL_EditImpl_Provider(IPVT_FontMap* pFontMap);
448 ~CPWL_EditImpl_Provider() override;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700449
Tom Sepezd0409af2017-05-25 15:53:57 -0700450 IPVT_FontMap* GetFontMap() const;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700451
dsinclairc7a73492016-04-05 12:01:42 -0700452 // CPDF_VariableText::Provider:
npm41d6bbe2016-09-14 11:54:44 -0700453 int32_t GetCharWidth(int32_t nFontIndex, uint16_t word) override;
Lei Zhang5fd907b2015-11-19 22:20:59 -0800454 int32_t GetTypeAscent(int32_t nFontIndex) override;
455 int32_t GetTypeDescent(int32_t nFontIndex) override;
Tom Sepez62a70f92016-03-21 15:00:20 -0700456 int32_t GetWordFontIndex(uint16_t word,
Lei Zhang5fd907b2015-11-19 22:20:59 -0800457 int32_t charset,
458 int32_t nFontIndex) override;
459 int32_t GetDefaultFontIndex() override;
tsepez4cf55152016-11-02 14:37:54 -0700460 bool IsLatinWord(uint16_t word) override;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700461
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700462 private:
dsinclairc7a73492016-04-05 12:01:42 -0700463 IPVT_FontMap* m_pFontMap;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700464};
465
Dan Sinclairc411eb92017-07-25 09:39:30 -0400466#endif // FPDFSDK_PWL_CPWL_EDIT_IMPL_H_