blob: 1a3289b26d30b7324f2820a2bbc1f670858c32d8 [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
dsinclair89bdd082016-04-06 10:47:54 -07007#include "fpdfsdk/fxedit/include/fxet_edit.h"
Lei Zhangc2fb35f2016-01-05 16:46:58 -08008
Lei Zhang375a8642016-01-11 11:59:17 -08009#include <algorithm>
10
dan sinclair61b2fc72016-03-23 19:21:44 -040011#include "core/fpdfapi/fpdf_font/include/cpdf_font.h"
dsinclairc7a73492016-04-05 12:01:42 -070012#include "core/fpdfdoc/include/cpvt_section.h"
13#include "core/fpdfdoc/include/cpvt_word.h"
14#include "core/fpdfdoc/include/ipvt_fontmap.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070015
dsinclair8f4bf9a2016-05-04 13:51:51 -070016namespace {
17
18const int kEditUndoMaxItems = 10000;
19
20} // namespace
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070021
Nico Weber9d8ec5a2015-08-04 13:00:21 -070022CFX_Edit_Iterator::CFX_Edit_Iterator(CFX_Edit* pEdit,
dsinclairc7a73492016-04-05 12:01:42 -070023 CPDF_VariableText::Iterator* pVTIterator)
Nico Weber9d8ec5a2015-08-04 13:00:21 -070024 : m_pEdit(pEdit), m_pVTIterator(pVTIterator) {}
25
26CFX_Edit_Iterator::~CFX_Edit_Iterator() {}
27
28FX_BOOL CFX_Edit_Iterator::NextWord() {
29 return m_pVTIterator->NextWord();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070030}
31
Nico Weber9d8ec5a2015-08-04 13:00:21 -070032FX_BOOL CFX_Edit_Iterator::NextLine() {
33 return m_pVTIterator->NextLine();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070034}
35
Nico Weber9d8ec5a2015-08-04 13:00:21 -070036FX_BOOL CFX_Edit_Iterator::NextSection() {
37 return m_pVTIterator->NextSection();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070038}
39
Nico Weber9d8ec5a2015-08-04 13:00:21 -070040FX_BOOL CFX_Edit_Iterator::PrevWord() {
41 return m_pVTIterator->PrevWord();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070042}
43
Nico Weber9d8ec5a2015-08-04 13:00:21 -070044FX_BOOL CFX_Edit_Iterator::PrevLine() {
45 return m_pVTIterator->PrevLine();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070046}
47
Nico Weber9d8ec5a2015-08-04 13:00:21 -070048FX_BOOL CFX_Edit_Iterator::PrevSection() {
49 return m_pVTIterator->PrevSection();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070050}
51
Nico Weber9d8ec5a2015-08-04 13:00:21 -070052FX_BOOL CFX_Edit_Iterator::GetWord(CPVT_Word& word) const {
53 ASSERT(m_pEdit);
54
55 if (m_pVTIterator->GetWord(word)) {
56 word.ptWord = m_pEdit->VTToEdit(word.ptWord);
57 return TRUE;
58 }
59 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070060}
61
Nico Weber9d8ec5a2015-08-04 13:00:21 -070062FX_BOOL CFX_Edit_Iterator::GetLine(CPVT_Line& line) const {
63 ASSERT(m_pEdit);
64
65 if (m_pVTIterator->GetLine(line)) {
66 line.ptLine = m_pEdit->VTToEdit(line.ptLine);
67 return TRUE;
68 }
69 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070070}
71
Nico Weber9d8ec5a2015-08-04 13:00:21 -070072FX_BOOL CFX_Edit_Iterator::GetSection(CPVT_Section& section) const {
73 ASSERT(m_pEdit);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070074
Nico Weber9d8ec5a2015-08-04 13:00:21 -070075 if (m_pVTIterator->GetSection(section)) {
76 section.rcSection = m_pEdit->VTToEdit(section.rcSection);
77 return TRUE;
78 }
79 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070080}
81
Nico Weber9d8ec5a2015-08-04 13:00:21 -070082void CFX_Edit_Iterator::SetAt(int32_t nWordIndex) {
83 m_pVTIterator->SetAt(nWordIndex);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070084}
85
Nico Weber9d8ec5a2015-08-04 13:00:21 -070086void CFX_Edit_Iterator::SetAt(const CPVT_WordPlace& place) {
87 m_pVTIterator->SetAt(place);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070088}
89
Nico Weber9d8ec5a2015-08-04 13:00:21 -070090const CPVT_WordPlace& CFX_Edit_Iterator::GetAt() const {
91 return m_pVTIterator->GetAt();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070092}
93
Nico Weber9d8ec5a2015-08-04 13:00:21 -070094IFX_Edit* CFX_Edit_Iterator::GetEdit() const {
95 return m_pEdit;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070096}
97
dsinclairc7a73492016-04-05 12:01:42 -070098CFX_Edit_Provider::CFX_Edit_Provider(IPVT_FontMap* pFontMap)
99 : CPDF_VariableText::Provider(pFontMap), m_pFontMap(pFontMap) {
Lei Zhang96660d62015-12-14 18:27:25 -0800100 ASSERT(m_pFontMap);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700101}
102
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700103CFX_Edit_Provider::~CFX_Edit_Provider() {}
104
dsinclairc7a73492016-04-05 12:01:42 -0700105IPVT_FontMap* CFX_Edit_Provider::GetFontMap() {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700106 return m_pFontMap;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700107}
108
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700109int32_t CFX_Edit_Provider::GetCharWidth(int32_t nFontIndex,
Tom Sepez62a70f92016-03-21 15:00:20 -0700110 uint16_t word,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700111 int32_t nWordStyle) {
112 if (CPDF_Font* pPDFFont = m_pFontMap->GetPDFFont(nFontIndex)) {
tsepezc3255f52016-03-25 14:52:27 -0700113 uint32_t charcode = word;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700114
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700115 if (pPDFFont->IsUnicodeCompatible())
116 charcode = pPDFFont->CharCodeFromUnicode(word);
117 else
118 charcode = m_pFontMap->CharCodeFromUnicode(nFontIndex, word);
119
Wei Li89409932016-03-28 10:33:33 -0700120 if (charcode != CPDF_Font::kInvalidCharCode)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700121 return pPDFFont->GetCharWidthF(charcode);
122 }
123
124 return 0;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700125}
126
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700127int32_t CFX_Edit_Provider::GetTypeAscent(int32_t nFontIndex) {
128 if (CPDF_Font* pPDFFont = m_pFontMap->GetPDFFont(nFontIndex))
129 return pPDFFont->GetTypeAscent();
130
131 return 0;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700132}
133
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700134int32_t CFX_Edit_Provider::GetTypeDescent(int32_t nFontIndex) {
135 if (CPDF_Font* pPDFFont = m_pFontMap->GetPDFFont(nFontIndex))
136 return pPDFFont->GetTypeDescent();
137
138 return 0;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700139}
140
Tom Sepez62a70f92016-03-21 15:00:20 -0700141int32_t CFX_Edit_Provider::GetWordFontIndex(uint16_t word,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700142 int32_t charset,
143 int32_t nFontIndex) {
144 return m_pFontMap->GetWordFontIndex(word, charset, nFontIndex);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700145}
146
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700147int32_t CFX_Edit_Provider::GetDefaultFontIndex() {
148 return 0;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700149}
150
Tom Sepez62a70f92016-03-21 15:00:20 -0700151FX_BOOL CFX_Edit_Provider::IsLatinWord(uint16_t word) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700152 return FX_EDIT_ISLATINWORD(word);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700153}
154
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700155CFX_Edit_Refresh::CFX_Edit_Refresh() {}
156
157CFX_Edit_Refresh::~CFX_Edit_Refresh() {}
158
159void CFX_Edit_Refresh::BeginRefresh() {
160 m_RefreshRects.Empty();
161 m_OldLineRects = m_NewLineRects;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700162}
163
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700164void CFX_Edit_Refresh::Push(const CPVT_WordRange& linerange,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800165 const CFX_FloatRect& rect) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700166 m_NewLineRects.Add(linerange, rect);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700167}
168
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700169void CFX_Edit_Refresh::NoAnalyse() {
170 {
171 for (int32_t i = 0, sz = m_OldLineRects.GetSize(); i < sz; i++)
172 if (CFX_Edit_LineRect* pOldRect = m_OldLineRects.GetAt(i))
173 m_RefreshRects.Add(pOldRect->m_rcLine);
174 }
175
176 {
177 for (int32_t i = 0, sz = m_NewLineRects.GetSize(); i < sz; i++)
178 if (CFX_Edit_LineRect* pNewRect = m_NewLineRects.GetAt(i))
179 m_RefreshRects.Add(pNewRect->m_rcLine);
180 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700181}
182
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700183void CFX_Edit_Refresh::Analyse(int32_t nAlignment) {
184 FX_BOOL bLineTopChanged = FALSE;
Tom Sepez281a9ea2016-02-26 14:24:28 -0800185 CFX_FloatRect rcResult;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700186 FX_FLOAT fWidthDiff;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700187
Lei Zhang375a8642016-01-11 11:59:17 -0800188 int32_t szMax = std::max(m_OldLineRects.GetSize(), m_NewLineRects.GetSize());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700189 int32_t i = 0;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700190
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700191 while (i < szMax) {
192 CFX_Edit_LineRect* pOldRect = m_OldLineRects.GetAt(i);
193 CFX_Edit_LineRect* pNewRect = m_NewLineRects.GetAt(i);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700194
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700195 if (pOldRect) {
196 if (pNewRect) {
197 if (bLineTopChanged) {
198 rcResult = pOldRect->m_rcLine;
199 rcResult.Union(pNewRect->m_rcLine);
200 m_RefreshRects.Add(rcResult);
201 } else {
202 if (*pNewRect != *pOldRect) {
203 if (!pNewRect->IsSameTop(*pOldRect) ||
204 !pNewRect->IsSameHeight(*pOldRect)) {
205 bLineTopChanged = TRUE;
206 continue;
207 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700208
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700209 if (nAlignment == 0) {
210 if (pNewRect->m_wrLine.BeginPos != pOldRect->m_wrLine.BeginPos) {
211 rcResult = pOldRect->m_rcLine;
212 rcResult.Union(pNewRect->m_rcLine);
213 m_RefreshRects.Add(rcResult);
214 } else {
215 if (!pNewRect->IsSameLeft(*pOldRect)) {
216 rcResult = pOldRect->m_rcLine;
217 rcResult.Union(pNewRect->m_rcLine);
218 } else {
219 fWidthDiff =
220 pNewRect->m_rcLine.Width() - pOldRect->m_rcLine.Width();
221 rcResult = pNewRect->m_rcLine;
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800222 if (fWidthDiff > 0.0f) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700223 rcResult.left = rcResult.right - fWidthDiff;
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800224 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700225 rcResult.left = rcResult.right;
thestig8c32dfa2016-04-29 18:14:37 -0700226 rcResult.right -= fWidthDiff;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700227 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700228 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700229 m_RefreshRects.Add(rcResult);
230 }
231 } else {
232 rcResult = pOldRect->m_rcLine;
233 rcResult.Union(pNewRect->m_rcLine);
234 m_RefreshRects.Add(rcResult);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700235 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700236 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700237 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700238 } else {
239 m_RefreshRects.Add(pOldRect->m_rcLine);
240 }
241 } else {
242 if (pNewRect) {
243 m_RefreshRects.Add(pNewRect->m_rcLine);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700244 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700245 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700246 i++;
247 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700248}
249
Tom Sepez281a9ea2016-02-26 14:24:28 -0800250void CFX_Edit_Refresh::AddRefresh(const CFX_FloatRect& rect) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700251 m_RefreshRects.Add(rect);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700252}
253
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700254const CFX_Edit_RectArray* CFX_Edit_Refresh::GetRefreshRects() const {
255 return &m_RefreshRects;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700256}
257
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700258void CFX_Edit_Refresh::EndRefresh() {
259 m_RefreshRects.Empty();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700260}
261
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700262CFX_Edit_Undo::CFX_Edit_Undo(int32_t nBufsize)
263 : m_nCurUndoPos(0),
264 m_nBufSize(nBufsize),
265 m_bModified(FALSE),
266 m_bVirgin(TRUE),
267 m_bWorking(FALSE) {}
268
269CFX_Edit_Undo::~CFX_Edit_Undo() {
270 Reset();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700271}
272
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700273FX_BOOL CFX_Edit_Undo::CanUndo() const {
274 return m_nCurUndoPos > 0;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700275}
276
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700277void CFX_Edit_Undo::Undo() {
278 m_bWorking = TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700279
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700280 if (m_nCurUndoPos > 0) {
281 IFX_Edit_UndoItem* pItem = m_UndoItemStack.GetAt(m_nCurUndoPos - 1);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700282 pItem->Undo();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700283
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700284 m_nCurUndoPos--;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700285 m_bModified = (m_nCurUndoPos != 0);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700286 }
287
288 m_bWorking = FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700289}
290
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700291FX_BOOL CFX_Edit_Undo::CanRedo() const {
292 return m_nCurUndoPos < m_UndoItemStack.GetSize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700293}
294
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700295void CFX_Edit_Undo::Redo() {
296 m_bWorking = TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700297
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700298 int32_t nStackSize = m_UndoItemStack.GetSize();
299
300 if (m_nCurUndoPos < nStackSize) {
301 IFX_Edit_UndoItem* pItem = m_UndoItemStack.GetAt(m_nCurUndoPos);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700302 pItem->Redo();
303
304 m_nCurUndoPos++;
305 m_bModified = (m_nCurUndoPos != 0);
306 }
307
308 m_bWorking = FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700309}
310
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700311FX_BOOL CFX_Edit_Undo::IsWorking() const {
312 return m_bWorking;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700313}
314
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700315void CFX_Edit_Undo::AddItem(IFX_Edit_UndoItem* pItem) {
316 ASSERT(!m_bWorking);
Lei Zhang96660d62015-12-14 18:27:25 -0800317 ASSERT(pItem);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700318 ASSERT(m_nBufSize > 1);
319
320 if (m_nCurUndoPos < m_UndoItemStack.GetSize())
321 RemoveTails();
322
323 if (m_UndoItemStack.GetSize() >= m_nBufSize) {
324 RemoveHeads();
325 m_bVirgin = FALSE;
326 }
327
328 m_UndoItemStack.Add(pItem);
329 m_nCurUndoPos = m_UndoItemStack.GetSize();
330
331 m_bModified = (m_nCurUndoPos != 0);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700332}
333
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700334FX_BOOL CFX_Edit_Undo::IsModified() const {
335 return m_bVirgin ? m_bModified : TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700336}
337
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700338IFX_Edit_UndoItem* CFX_Edit_Undo::GetItem(int32_t nIndex) {
339 if (nIndex >= 0 && nIndex < m_UndoItemStack.GetSize())
340 return m_UndoItemStack.GetAt(nIndex);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700341
thestig1cd352e2016-06-07 17:53:06 -0700342 return nullptr;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700343}
344
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700345void CFX_Edit_Undo::RemoveHeads() {
346 ASSERT(m_UndoItemStack.GetSize() > 1);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700347
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700348 delete m_UndoItemStack.GetAt(0);
349 m_UndoItemStack.RemoveAt(0);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700350}
351
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700352void CFX_Edit_Undo::RemoveTails() {
353 for (int32_t i = m_UndoItemStack.GetSize() - 1; i >= m_nCurUndoPos; i--) {
354 delete m_UndoItemStack.GetAt(i);
355 m_UndoItemStack.RemoveAt(i);
356 }
357}
358
359void CFX_Edit_Undo::Reset() {
360 for (int32_t i = 0, sz = m_UndoItemStack.GetSize(); i < sz; i++) {
361 delete m_UndoItemStack.GetAt(i);
362 }
363 m_nCurUndoPos = 0;
364 m_UndoItemStack.RemoveAll();
365}
366
weili625ad662016-06-15 11:21:33 -0700367CFX_Edit_UndoItem::CFX_Edit_UndoItem() : m_bFirst(TRUE), m_bLast(TRUE) {}
368
369CFX_Edit_UndoItem::~CFX_Edit_UndoItem() {}
370
371CFX_WideString CFX_Edit_UndoItem::GetUndoTitle() {
372 return L"";
373}
374
375void CFX_Edit_UndoItem::SetFirst(FX_BOOL bFirst) {
376 m_bFirst = bFirst;
377}
378
379FX_BOOL CFX_Edit_UndoItem::IsFirst() {
380 return m_bFirst;
381}
382
383void CFX_Edit_UndoItem::SetLast(FX_BOOL bLast) {
384 m_bLast = bLast;
385}
386
387FX_BOOL CFX_Edit_UndoItem::IsLast() {
388 return m_bLast;
389}
390
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700391CFX_Edit_GroupUndoItem::CFX_Edit_GroupUndoItem(const CFX_WideString& sTitle)
392 : m_sTitle(sTitle) {}
393
394CFX_Edit_GroupUndoItem::~CFX_Edit_GroupUndoItem() {
395 for (int i = 0, sz = m_Items.GetSize(); i < sz; i++) {
396 delete m_Items[i];
397 }
398
399 m_Items.RemoveAll();
400}
401
402void CFX_Edit_GroupUndoItem::AddUndoItem(CFX_Edit_UndoItem* pUndoItem) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700403 pUndoItem->SetFirst(FALSE);
404 pUndoItem->SetLast(FALSE);
405
406 m_Items.Add(pUndoItem);
407
408 if (m_sTitle.IsEmpty())
409 m_sTitle = pUndoItem->GetUndoTitle();
410}
411
412void CFX_Edit_GroupUndoItem::UpdateItems() {
413 if (m_Items.GetSize() > 0) {
414 CFX_Edit_UndoItem* pFirstItem = m_Items[0];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700415 pFirstItem->SetFirst(TRUE);
416
417 CFX_Edit_UndoItem* pLastItem = m_Items[m_Items.GetSize() - 1];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700418 pLastItem->SetLast(TRUE);
419 }
420}
421
422void CFX_Edit_GroupUndoItem::Undo() {
423 for (int i = m_Items.GetSize() - 1; i >= 0; i--) {
424 CFX_Edit_UndoItem* pUndoItem = m_Items[i];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700425 pUndoItem->Undo();
426 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700427}
428
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700429void CFX_Edit_GroupUndoItem::Redo() {
430 for (int i = 0, sz = m_Items.GetSize(); i < sz; i++) {
431 CFX_Edit_UndoItem* pUndoItem = m_Items[i];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700432 pUndoItem->Redo();
433 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700434}
435
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700436CFX_WideString CFX_Edit_GroupUndoItem::GetUndoTitle() {
437 return m_sTitle;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700438}
439
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700440CFXEU_InsertWord::CFXEU_InsertWord(CFX_Edit* pEdit,
441 const CPVT_WordPlace& wpOldPlace,
442 const CPVT_WordPlace& wpNewPlace,
Tom Sepez62a70f92016-03-21 15:00:20 -0700443 uint16_t word,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700444 int32_t charset,
445 const CPVT_WordProps* pWordProps)
446 : m_pEdit(pEdit),
447 m_wpOld(wpOldPlace),
448 m_wpNew(wpNewPlace),
449 m_Word(word),
450 m_nCharset(charset),
451 m_WordProps() {
452 if (pWordProps)
453 m_WordProps = *pWordProps;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700454}
455
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700456CFXEU_InsertWord::~CFXEU_InsertWord() {}
457
458void CFXEU_InsertWord::Redo() {
459 if (m_pEdit) {
460 m_pEdit->SelectNone();
461 m_pEdit->SetCaret(m_wpOld);
462 m_pEdit->InsertWord(m_Word, m_nCharset, &m_WordProps, FALSE, TRUE);
463 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700464}
465
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700466void CFXEU_InsertWord::Undo() {
467 if (m_pEdit) {
468 m_pEdit->SelectNone();
469 m_pEdit->SetCaret(m_wpNew);
470 m_pEdit->Backspace(FALSE, TRUE);
471 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700472}
473
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700474CFXEU_InsertReturn::CFXEU_InsertReturn(CFX_Edit* pEdit,
475 const CPVT_WordPlace& wpOldPlace,
476 const CPVT_WordPlace& wpNewPlace,
477 const CPVT_SecProps* pSecProps,
478 const CPVT_WordProps* pWordProps)
479 : m_pEdit(pEdit),
480 m_wpOld(wpOldPlace),
481 m_wpNew(wpNewPlace),
482 m_SecProps(),
483 m_WordProps() {
484 if (pSecProps)
485 m_SecProps = *pSecProps;
486 if (pWordProps)
487 m_WordProps = *pWordProps;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700488}
489
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700490CFXEU_InsertReturn::~CFXEU_InsertReturn() {}
491
492void CFXEU_InsertReturn::Redo() {
493 if (m_pEdit) {
494 m_pEdit->SelectNone();
495 m_pEdit->SetCaret(m_wpOld);
496 m_pEdit->InsertReturn(&m_SecProps, &m_WordProps, FALSE, TRUE);
497 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700498}
499
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700500void CFXEU_InsertReturn::Undo() {
501 if (m_pEdit) {
502 m_pEdit->SelectNone();
503 m_pEdit->SetCaret(m_wpNew);
504 m_pEdit->Backspace(FALSE, TRUE);
505 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700506}
507
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700508CFXEU_Backspace::CFXEU_Backspace(CFX_Edit* pEdit,
509 const CPVT_WordPlace& wpOldPlace,
510 const CPVT_WordPlace& wpNewPlace,
Tom Sepez62a70f92016-03-21 15:00:20 -0700511 uint16_t word,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700512 int32_t charset,
513 const CPVT_SecProps& SecProps,
514 const CPVT_WordProps& WordProps)
515 : m_pEdit(pEdit),
516 m_wpOld(wpOldPlace),
517 m_wpNew(wpNewPlace),
518 m_Word(word),
519 m_nCharset(charset),
520 m_SecProps(SecProps),
521 m_WordProps(WordProps) {}
522
523CFXEU_Backspace::~CFXEU_Backspace() {}
524
525void CFXEU_Backspace::Redo() {
526 if (m_pEdit) {
527 m_pEdit->SelectNone();
528 m_pEdit->SetCaret(m_wpOld);
529 m_pEdit->Backspace(FALSE, TRUE);
530 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700531}
532
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700533void CFXEU_Backspace::Undo() {
534 if (m_pEdit) {
535 m_pEdit->SelectNone();
536 m_pEdit->SetCaret(m_wpNew);
537 if (m_wpNew.SecCmp(m_wpOld) != 0) {
538 m_pEdit->InsertReturn(&m_SecProps, &m_WordProps, FALSE, TRUE);
539 } else {
540 m_pEdit->InsertWord(m_Word, m_nCharset, &m_WordProps, FALSE, TRUE);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700541 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700542 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700543}
544
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700545CFXEU_Delete::CFXEU_Delete(CFX_Edit* pEdit,
546 const CPVT_WordPlace& wpOldPlace,
547 const CPVT_WordPlace& wpNewPlace,
Tom Sepez62a70f92016-03-21 15:00:20 -0700548 uint16_t word,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700549 int32_t charset,
550 const CPVT_SecProps& SecProps,
551 const CPVT_WordProps& WordProps,
552 FX_BOOL bSecEnd)
553 : m_pEdit(pEdit),
554 m_wpOld(wpOldPlace),
555 m_wpNew(wpNewPlace),
556 m_Word(word),
557 m_nCharset(charset),
558 m_SecProps(SecProps),
559 m_WordProps(WordProps),
560 m_bSecEnd(bSecEnd) {}
561
562CFXEU_Delete::~CFXEU_Delete() {}
563
564void CFXEU_Delete::Redo() {
565 if (m_pEdit) {
566 m_pEdit->SelectNone();
567 m_pEdit->SetCaret(m_wpOld);
568 m_pEdit->Delete(FALSE, TRUE);
569 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700570}
571
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700572void CFXEU_Delete::Undo() {
573 if (m_pEdit) {
574 m_pEdit->SelectNone();
575 m_pEdit->SetCaret(m_wpNew);
576 if (m_bSecEnd) {
577 m_pEdit->InsertReturn(&m_SecProps, &m_WordProps, FALSE, TRUE);
578 } else {
579 m_pEdit->InsertWord(m_Word, m_nCharset, &m_WordProps, FALSE, TRUE);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700580 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700581 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700582}
583
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700584CFXEU_Clear::CFXEU_Clear(CFX_Edit* pEdit,
585 const CPVT_WordRange& wrSel,
586 const CFX_WideString& swText)
587 : m_pEdit(pEdit), m_wrSel(wrSel), m_swText(swText) {}
588
589CFXEU_Clear::~CFXEU_Clear() {}
590
591void CFXEU_Clear::Redo() {
592 if (m_pEdit) {
593 m_pEdit->SelectNone();
594 m_pEdit->SetSel(m_wrSel.BeginPos, m_wrSel.EndPos);
595 m_pEdit->Clear(FALSE, TRUE);
596 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700597}
598
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700599void CFXEU_Clear::Undo() {
600 if (m_pEdit) {
601 m_pEdit->SelectNone();
602 m_pEdit->SetCaret(m_wrSel.BeginPos);
thestig1cd352e2016-06-07 17:53:06 -0700603 m_pEdit->InsertText(m_swText.c_str(), DEFAULT_CHARSET, nullptr, nullptr,
604 FALSE, TRUE);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700605 m_pEdit->SetSel(m_wrSel.BeginPos, m_wrSel.EndPos);
606 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700607}
608
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700609CFXEU_ClearRich::CFXEU_ClearRich(CFX_Edit* pEdit,
610 const CPVT_WordPlace& wpOldPlace,
611 const CPVT_WordPlace& wpNewPlace,
612 const CPVT_WordRange& wrSel,
Tom Sepez62a70f92016-03-21 15:00:20 -0700613 uint16_t word,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700614 int32_t charset,
615 const CPVT_SecProps& SecProps,
616 const CPVT_WordProps& WordProps)
617 : m_pEdit(pEdit),
618 m_wpOld(wpOldPlace),
619 m_wpNew(wpNewPlace),
620 m_wrSel(wrSel),
621 m_Word(word),
622 m_nCharset(charset),
623 m_SecProps(SecProps),
624 m_WordProps(WordProps) {}
625
626CFXEU_ClearRich::~CFXEU_ClearRich() {}
627
628void CFXEU_ClearRich::Redo() {
629 if (m_pEdit && IsLast()) {
630 m_pEdit->SelectNone();
631 m_pEdit->SetSel(m_wrSel.BeginPos, m_wrSel.EndPos);
632 m_pEdit->Clear(FALSE, TRUE);
633 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700634}
635
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700636void CFXEU_ClearRich::Undo() {
637 if (m_pEdit) {
638 m_pEdit->SelectNone();
639 m_pEdit->SetCaret(m_wpOld);
640 if (m_wpNew.SecCmp(m_wpOld) != 0) {
641 m_pEdit->InsertReturn(&m_SecProps, &m_WordProps, FALSE, FALSE);
642 } else {
643 m_pEdit->InsertWord(m_Word, m_nCharset, &m_WordProps, FALSE, FALSE);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700644 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700645
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700646 if (IsFirst()) {
647 m_pEdit->PaintInsertText(m_wrSel.BeginPos, m_wrSel.EndPos);
648 m_pEdit->SetSel(m_wrSel.BeginPos, m_wrSel.EndPos);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700649 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700650 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700651}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700652CFXEU_InsertText::CFXEU_InsertText(CFX_Edit* pEdit,
653 const CPVT_WordPlace& wpOldPlace,
654 const CPVT_WordPlace& wpNewPlace,
655 const CFX_WideString& swText,
656 int32_t charset,
657 const CPVT_SecProps* pSecProps,
658 const CPVT_WordProps* pWordProps)
659 : m_pEdit(pEdit),
660 m_wpOld(wpOldPlace),
661 m_wpNew(wpNewPlace),
662 m_swText(swText),
663 m_nCharset(charset),
664 m_SecProps(),
665 m_WordProps() {
666 if (pSecProps)
667 m_SecProps = *pSecProps;
668 if (pWordProps)
669 m_WordProps = *pWordProps;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700670}
671
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700672CFXEU_InsertText::~CFXEU_InsertText() {}
673
674void CFXEU_InsertText::Redo() {
675 if (m_pEdit && IsLast()) {
676 m_pEdit->SelectNone();
677 m_pEdit->SetCaret(m_wpOld);
678 m_pEdit->InsertText(m_swText.c_str(), m_nCharset, &m_SecProps, &m_WordProps,
679 FALSE, TRUE);
680 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700681}
682
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700683void CFXEU_InsertText::Undo() {
684 if (m_pEdit) {
685 m_pEdit->SelectNone();
686 m_pEdit->SetSel(m_wpOld, m_wpNew);
687 m_pEdit->Clear(FALSE, TRUE);
688 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700689}
690
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700691CFXEU_SetSecProps::CFXEU_SetSecProps(CFX_Edit* pEdit,
692 const CPVT_WordPlace& place,
693 EDIT_PROPS_E ep,
694 const CPVT_SecProps& oldsecprops,
695 const CPVT_WordProps& oldwordprops,
696 const CPVT_SecProps& newsecprops,
697 const CPVT_WordProps& newwordprops,
698 const CPVT_WordRange& range)
699 : m_pEdit(pEdit),
700 m_wpPlace(place),
701 m_wrPlace(range),
702 m_eProps(ep),
703 m_OldSecProps(oldsecprops),
704 m_NewSecProps(newsecprops),
705 m_OldWordProps(oldwordprops),
706 m_NewWordProps(newwordprops) {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700707
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700708CFXEU_SetSecProps::~CFXEU_SetSecProps() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700709
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700710void CFXEU_SetSecProps::Redo() {
711 if (m_pEdit) {
712 m_pEdit->SetSecProps(m_eProps, m_wpPlace, &m_NewSecProps, &m_NewWordProps,
713 m_wrPlace, FALSE);
714 if (IsLast()) {
715 m_pEdit->SelectNone();
716 m_pEdit->PaintSetProps(m_eProps, m_wrPlace);
717 m_pEdit->SetSel(m_wrPlace.BeginPos, m_wrPlace.EndPos);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700718 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700719 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700720}
721
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700722void CFXEU_SetSecProps::Undo() {
723 if (m_pEdit) {
724 m_pEdit->SetSecProps(m_eProps, m_wpPlace, &m_OldSecProps, &m_OldWordProps,
725 m_wrPlace, FALSE);
726 if (IsFirst()) {
727 m_pEdit->SelectNone();
728 m_pEdit->PaintSetProps(m_eProps, m_wrPlace);
729 m_pEdit->SetSel(m_wrPlace.BeginPos, m_wrPlace.EndPos);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700730 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700731 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700732}
733
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700734CFXEU_SetWordProps::CFXEU_SetWordProps(CFX_Edit* pEdit,
735 const CPVT_WordPlace& place,
736 EDIT_PROPS_E ep,
737 const CPVT_WordProps& oldprops,
738 const CPVT_WordProps& newprops,
739 const CPVT_WordRange& range)
740 : m_pEdit(pEdit),
741 m_wpPlace(place),
742 m_wrPlace(range),
743 m_eProps(ep),
744 m_OldWordProps(oldprops),
745 m_NewWordProps(newprops) {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700746
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700747CFXEU_SetWordProps::~CFXEU_SetWordProps() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700748
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700749void CFXEU_SetWordProps::Redo() {
750 if (m_pEdit) {
751 m_pEdit->SetWordProps(m_eProps, m_wpPlace, &m_NewWordProps, m_wrPlace,
752 FALSE);
753 if (IsLast()) {
754 m_pEdit->SelectNone();
755 m_pEdit->PaintSetProps(m_eProps, m_wrPlace);
756 m_pEdit->SetSel(m_wrPlace.BeginPos, m_wrPlace.EndPos);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700757 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700758 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700759}
760
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700761void CFXEU_SetWordProps::Undo() {
762 if (m_pEdit) {
763 m_pEdit->SetWordProps(m_eProps, m_wpPlace, &m_OldWordProps, m_wrPlace,
764 FALSE);
765 if (IsFirst()) {
766 m_pEdit->SelectNone();
767 m_pEdit->PaintSetProps(m_eProps, m_wrPlace);
768 m_pEdit->SetSel(m_wrPlace.BeginPos, m_wrPlace.EndPos);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700769 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700770 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700771}
772
dsinclairc7a73492016-04-05 12:01:42 -0700773CFX_Edit::CFX_Edit(CPDF_VariableText* pVT)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700774 : m_pVT(pVT),
thestig821d59e2016-05-11 12:59:22 -0700775 m_pNotify(nullptr),
776 m_pOprNotify(nullptr),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700777 m_wpCaret(-1, -1, -1),
778 m_wpOldCaret(-1, -1, -1),
779 m_SelState(),
780 m_ptScrollPos(0, 0),
781 m_ptRefreshScrollPos(0, 0),
782 m_bEnableScroll(FALSE),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700783 m_ptCaret(0.0f, 0.0f),
dsinclair8f4bf9a2016-05-04 13:51:51 -0700784 m_Undo(kEditUndoMaxItems),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700785 m_nAlignment(0),
786 m_bNotifyFlag(FALSE),
787 m_bEnableOverflow(FALSE),
788 m_bEnableRefresh(TRUE),
789 m_rcOldContent(0.0f, 0.0f, 0.0f, 0.0f),
790 m_bEnableUndo(TRUE),
791 m_bNotify(TRUE),
792 m_bOprNotify(FALSE),
thestig821d59e2016-05-11 12:59:22 -0700793 m_pGroupUndoItem(nullptr) {
Lei Zhang96660d62015-12-14 18:27:25 -0800794 ASSERT(pVT);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700795}
796
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700797CFX_Edit::~CFX_Edit() {
Lei Zhang412e9082015-12-14 18:34:00 -0800798 ASSERT(!m_pGroupUndoItem);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700799}
800
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700801void CFX_Edit::Initialize() {
802 m_pVT->Initialize();
803 SetCaret(m_pVT->GetBeginWordPlace());
804 SetCaretOrigin();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700805}
806
dsinclairc7a73492016-04-05 12:01:42 -0700807void CFX_Edit::SetFontMap(IPVT_FontMap* pFontMap) {
thestig821d59e2016-05-11 12:59:22 -0700808 m_pVTProvider.reset(new CFX_Edit_Provider(pFontMap));
809 m_pVT->SetProvider(m_pVTProvider.get());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700810}
811
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700812void CFX_Edit::SetNotify(IFX_Edit_Notify* pNotify) {
813 m_pNotify = pNotify;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700814}
815
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700816void CFX_Edit::SetOprNotify(IFX_Edit_OprNotify* pOprNotify) {
817 m_pOprNotify = pOprNotify;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700818}
819
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700820IFX_Edit_Iterator* CFX_Edit::GetIterator() {
821 if (!m_pIterator)
thestig821d59e2016-05-11 12:59:22 -0700822 m_pIterator.reset(new CFX_Edit_Iterator(this, m_pVT->GetIterator()));
823 return m_pIterator.get();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700824}
825
dsinclairc7a73492016-04-05 12:01:42 -0700826CPDF_VariableText* CFX_Edit::GetVariableText() {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700827 return m_pVT;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700828}
829
dsinclairc7a73492016-04-05 12:01:42 -0700830IPVT_FontMap* CFX_Edit::GetFontMap() {
thestig821d59e2016-05-11 12:59:22 -0700831 return m_pVTProvider ? m_pVTProvider->GetFontMap() : nullptr;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700832}
833
Tom Sepez281a9ea2016-02-26 14:24:28 -0800834void CFX_Edit::SetPlateRect(const CFX_FloatRect& rect, FX_BOOL bPaint) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700835 m_pVT->SetPlateRect(rect);
Tom Sepez281a9ea2016-02-26 14:24:28 -0800836 m_ptScrollPos = CFX_FloatPoint(rect.left, rect.top);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700837 if (bPaint)
838 Paint();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700839}
840
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800841void CFX_Edit::SetAlignmentH(int32_t nFormat, FX_BOOL bPaint) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700842 m_pVT->SetAlignment(nFormat);
843 if (bPaint)
844 Paint();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700845}
846
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800847void CFX_Edit::SetAlignmentV(int32_t nFormat, FX_BOOL bPaint) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700848 m_nAlignment = nFormat;
849 if (bPaint)
850 Paint();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700851}
852
Tom Sepez62a70f92016-03-21 15:00:20 -0700853void CFX_Edit::SetPasswordChar(uint16_t wSubWord, FX_BOOL bPaint) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700854 m_pVT->SetPasswordChar(wSubWord);
855 if (bPaint)
856 Paint();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700857}
858
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800859void CFX_Edit::SetLimitChar(int32_t nLimitChar, FX_BOOL bPaint) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700860 m_pVT->SetLimitChar(nLimitChar);
861 if (bPaint)
862 Paint();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700863}
864
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800865void CFX_Edit::SetCharArray(int32_t nCharArray, FX_BOOL bPaint) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700866 m_pVT->SetCharArray(nCharArray);
867 if (bPaint)
868 Paint();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700869}
870
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800871void CFX_Edit::SetCharSpace(FX_FLOAT fCharSpace, FX_BOOL bPaint) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700872 m_pVT->SetCharSpace(fCharSpace);
873 if (bPaint)
874 Paint();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700875}
876
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800877void CFX_Edit::SetHorzScale(int32_t nHorzScale, FX_BOOL bPaint) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700878 m_pVT->SetHorzScale(nHorzScale);
879 if (bPaint)
880 Paint();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700881}
882
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800883void CFX_Edit::SetMultiLine(FX_BOOL bMultiLine, FX_BOOL bPaint) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700884 m_pVT->SetMultiLine(bMultiLine);
885 if (bPaint)
886 Paint();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700887}
888
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800889void CFX_Edit::SetAutoReturn(FX_BOOL bAuto, FX_BOOL bPaint) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700890 m_pVT->SetAutoReturn(bAuto);
891 if (bPaint)
892 Paint();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700893}
894
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800895void CFX_Edit::SetLineLeading(FX_FLOAT fLineLeading, FX_BOOL bPaint) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700896 m_pVT->SetLineLeading(fLineLeading);
897 if (bPaint)
898 Paint();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700899}
900
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800901void CFX_Edit::SetAutoFontSize(FX_BOOL bAuto, FX_BOOL bPaint) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700902 m_pVT->SetAutoFontSize(bAuto);
903 if (bPaint)
904 Paint();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700905}
906
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800907void CFX_Edit::SetFontSize(FX_FLOAT fFontSize, FX_BOOL bPaint) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700908 m_pVT->SetFontSize(fFontSize);
909 if (bPaint)
910 Paint();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700911}
912
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800913void CFX_Edit::SetAutoScroll(FX_BOOL bAuto, FX_BOOL bPaint) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700914 m_bEnableScroll = bAuto;
915 if (bPaint)
916 Paint();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700917}
918
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800919void CFX_Edit::SetTextOverflow(FX_BOOL bAllowed, FX_BOOL bPaint) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700920 m_bEnableOverflow = bAllowed;
921 if (bPaint)
922 Paint();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700923}
924
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700925void CFX_Edit::SetSel(int32_t nStartChar, int32_t nEndChar) {
926 if (m_pVT->IsValid()) {
927 if (nStartChar == 0 && nEndChar < 0) {
928 SelectAll();
929 } else if (nStartChar < 0) {
930 SelectNone();
931 } else {
932 if (nStartChar < nEndChar) {
933 SetSel(m_pVT->WordIndexToWordPlace(nStartChar),
934 m_pVT->WordIndexToWordPlace(nEndChar));
935 } else {
936 SetSel(m_pVT->WordIndexToWordPlace(nEndChar),
937 m_pVT->WordIndexToWordPlace(nStartChar));
938 }
939 }
940 }
941}
942
943void CFX_Edit::SetSel(const CPVT_WordPlace& begin, const CPVT_WordPlace& end) {
944 if (m_pVT->IsValid()) {
945 SelectNone();
946
947 m_SelState.Set(begin, end);
948
949 SetCaret(m_SelState.EndPos);
950
951 if (m_SelState.IsExist()) {
952 ScrollToCaret();
953 CPVT_WordRange wr(m_SelState.BeginPos, m_SelState.EndPos);
954 Refresh(RP_OPTIONAL, &wr);
955 SetCaretInfo();
956 } else {
957 ScrollToCaret();
958 SetCaretInfo();
959 }
960 }
961}
962
963void CFX_Edit::GetSel(int32_t& nStartChar, int32_t& nEndChar) const {
964 nStartChar = -1;
965 nEndChar = -1;
966
967 if (m_pVT->IsValid()) {
968 if (m_SelState.IsExist()) {
969 if (m_SelState.BeginPos.WordCmp(m_SelState.EndPos) < 0) {
970 nStartChar = m_pVT->WordPlaceToWordIndex(m_SelState.BeginPos);
971 nEndChar = m_pVT->WordPlaceToWordIndex(m_SelState.EndPos);
972 } else {
973 nStartChar = m_pVT->WordPlaceToWordIndex(m_SelState.EndPos);
974 nEndChar = m_pVT->WordPlaceToWordIndex(m_SelState.BeginPos);
975 }
976 } else {
977 nStartChar = m_pVT->WordPlaceToWordIndex(m_wpCaret);
978 nEndChar = m_pVT->WordPlaceToWordIndex(m_wpCaret);
979 }
980 }
981}
982
983int32_t CFX_Edit::GetCaret() const {
984 if (m_pVT->IsValid())
985 return m_pVT->WordPlaceToWordIndex(m_wpCaret);
986
987 return -1;
988}
989
990CPVT_WordPlace CFX_Edit::GetCaretWordPlace() const {
991 return m_wpCaret;
992}
993
994CFX_WideString CFX_Edit::GetText() const {
995 CFX_WideString swRet;
996
thestig821d59e2016-05-11 12:59:22 -0700997 if (!m_pVT->IsValid())
998 return swRet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700999
thestig821d59e2016-05-11 12:59:22 -07001000 CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator();
1001 pIterator->SetAt(0);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001002
thestig821d59e2016-05-11 12:59:22 -07001003 CPVT_Word wordinfo;
1004 CPVT_WordPlace oldplace = pIterator->GetAt();
1005 while (pIterator->NextWord()) {
1006 CPVT_WordPlace place = pIterator->GetAt();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001007
thestig821d59e2016-05-11 12:59:22 -07001008 if (pIterator->GetWord(wordinfo))
1009 swRet += wordinfo.Word;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001010
thestig821d59e2016-05-11 12:59:22 -07001011 if (oldplace.SecCmp(place) != 0)
1012 swRet += L"\r\n";
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001013
thestig821d59e2016-05-11 12:59:22 -07001014 oldplace = place;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001015 }
1016
1017 return swRet;
1018}
1019
1020CFX_WideString CFX_Edit::GetRangeText(const CPVT_WordRange& range) const {
1021 CFX_WideString swRet;
1022
thestig821d59e2016-05-11 12:59:22 -07001023 if (!m_pVT->IsValid())
1024 return swRet;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001025
thestig821d59e2016-05-11 12:59:22 -07001026 CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator();
1027 CPVT_WordRange wrTemp = range;
1028 m_pVT->UpdateWordPlace(wrTemp.BeginPos);
1029 m_pVT->UpdateWordPlace(wrTemp.EndPos);
1030 pIterator->SetAt(wrTemp.BeginPos);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001031
thestig821d59e2016-05-11 12:59:22 -07001032 CPVT_Word wordinfo;
1033 CPVT_WordPlace oldplace = wrTemp.BeginPos;
1034 while (pIterator->NextWord()) {
1035 CPVT_WordPlace place = pIterator->GetAt();
1036 if (place.WordCmp(wrTemp.EndPos) > 0)
1037 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001038
thestig821d59e2016-05-11 12:59:22 -07001039 if (pIterator->GetWord(wordinfo))
1040 swRet += wordinfo.Word;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001041
thestig821d59e2016-05-11 12:59:22 -07001042 if (oldplace.SecCmp(place) != 0)
1043 swRet += L"\r\n";
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001044
thestig821d59e2016-05-11 12:59:22 -07001045 oldplace = place;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001046 }
1047
1048 return swRet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001049}
1050
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001051CFX_WideString CFX_Edit::GetSelText() const {
1052 return GetRangeText(m_SelState.ConvertToWordRange());
1053}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001054
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001055int32_t CFX_Edit::GetTotalWords() const {
1056 return m_pVT->GetTotalWords();
1057}
1058
1059int32_t CFX_Edit::GetTotalLines() const {
thestig821d59e2016-05-11 12:59:22 -07001060 int32_t nLines = 1;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001061
thestig821d59e2016-05-11 12:59:22 -07001062 CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator();
1063 pIterator->SetAt(0);
1064 while (pIterator->NextLine())
1065 ++nLines;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001066
thestig821d59e2016-05-11 12:59:22 -07001067 return nLines;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001068}
1069
1070CPVT_WordRange CFX_Edit::GetSelectWordRange() const {
1071 return m_SelState.ConvertToWordRange();
1072}
1073
1074CPVT_WordRange CFX_Edit::CombineWordRange(const CPVT_WordRange& wr1,
1075 const CPVT_WordRange& wr2) {
1076 CPVT_WordRange wrRet;
1077
1078 if (wr1.BeginPos.WordCmp(wr2.BeginPos) < 0) {
1079 wrRet.BeginPos = wr1.BeginPos;
1080 } else {
1081 wrRet.BeginPos = wr2.BeginPos;
1082 }
1083
1084 if (wr1.EndPos.WordCmp(wr2.EndPos) < 0) {
1085 wrRet.EndPos = wr2.EndPos;
1086 } else {
1087 wrRet.EndPos = wr1.EndPos;
1088 }
1089
1090 return wrRet;
1091}
1092
1093FX_BOOL CFX_Edit::IsRichText() const {
1094 return m_pVT->IsRichText();
1095}
1096
Lei Zhangc2fb35f2016-01-05 16:46:58 -08001097void CFX_Edit::SetRichText(FX_BOOL bRichText, FX_BOOL bPaint) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001098 m_pVT->SetRichText(bRichText);
1099 if (bPaint)
1100 Paint();
1101}
1102
1103FX_BOOL CFX_Edit::SetRichFontIndex(int32_t nFontIndex) {
1104 CPVT_WordProps WordProps;
1105 WordProps.nFontIndex = nFontIndex;
thestig1cd352e2016-06-07 17:53:06 -07001106 return SetRichTextProps(EP_FONTINDEX, nullptr, &WordProps);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001107}
1108
1109FX_BOOL CFX_Edit::SetRichFontSize(FX_FLOAT fFontSize) {
1110 CPVT_WordProps WordProps;
1111 WordProps.fFontSize = fFontSize;
thestig1cd352e2016-06-07 17:53:06 -07001112 return SetRichTextProps(EP_FONTSIZE, nullptr, &WordProps);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001113}
1114
1115FX_BOOL CFX_Edit::SetRichTextColor(FX_COLORREF dwColor) {
1116 CPVT_WordProps WordProps;
1117 WordProps.dwWordColor = dwColor;
thestig1cd352e2016-06-07 17:53:06 -07001118 return SetRichTextProps(EP_WORDCOLOR, nullptr, &WordProps);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001119}
1120
dsinclairc7a73492016-04-05 12:01:42 -07001121FX_BOOL CFX_Edit::SetRichTextScript(CPDF_VariableText::ScriptType nScriptType) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001122 CPVT_WordProps WordProps;
1123 WordProps.nScriptType = nScriptType;
thestig1cd352e2016-06-07 17:53:06 -07001124 return SetRichTextProps(EP_SCRIPTTYPE, nullptr, &WordProps);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001125}
1126
1127FX_BOOL CFX_Edit::SetRichTextBold(FX_BOOL bBold) {
1128 CPVT_WordProps WordProps;
1129 if (bBold)
1130 WordProps.nWordStyle |= PVTWORD_STYLE_BOLD;
thestig1cd352e2016-06-07 17:53:06 -07001131 return SetRichTextProps(EP_BOLD, nullptr, &WordProps);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001132}
1133
1134FX_BOOL CFX_Edit::SetRichTextItalic(FX_BOOL bItalic) {
1135 CPVT_WordProps WordProps;
1136 if (bItalic)
1137 WordProps.nWordStyle |= PVTWORD_STYLE_ITALIC;
thestig1cd352e2016-06-07 17:53:06 -07001138 return SetRichTextProps(EP_ITALIC, nullptr, &WordProps);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001139}
1140
1141FX_BOOL CFX_Edit::SetRichTextUnderline(FX_BOOL bUnderline) {
1142 CPVT_WordProps WordProps;
1143 if (bUnderline)
1144 WordProps.nWordStyle |= PVTWORD_STYLE_UNDERLINE;
thestig1cd352e2016-06-07 17:53:06 -07001145 return SetRichTextProps(EP_UNDERLINE, nullptr, &WordProps);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001146}
1147
1148FX_BOOL CFX_Edit::SetRichTextCrossout(FX_BOOL bCrossout) {
1149 CPVT_WordProps WordProps;
1150 if (bCrossout)
1151 WordProps.nWordStyle |= PVTWORD_STYLE_CROSSOUT;
thestig1cd352e2016-06-07 17:53:06 -07001152 return SetRichTextProps(EP_CROSSOUT, nullptr, &WordProps);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001153}
1154
1155FX_BOOL CFX_Edit::SetRichTextCharSpace(FX_FLOAT fCharSpace) {
1156 CPVT_WordProps WordProps;
1157 WordProps.fCharSpace = fCharSpace;
thestig1cd352e2016-06-07 17:53:06 -07001158 return SetRichTextProps(EP_CHARSPACE, nullptr, &WordProps);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001159}
1160
Lei Zhangc2fb35f2016-01-05 16:46:58 -08001161FX_BOOL CFX_Edit::SetRichTextHorzScale(int32_t nHorzScale) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001162 CPVT_WordProps WordProps;
1163 WordProps.nHorzScale = nHorzScale;
thestig1cd352e2016-06-07 17:53:06 -07001164 return SetRichTextProps(EP_HORZSCALE, nullptr, &WordProps);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001165}
1166
1167FX_BOOL CFX_Edit::SetRichTextLineLeading(FX_FLOAT fLineLeading) {
1168 CPVT_SecProps SecProps;
1169 SecProps.fLineLeading = fLineLeading;
thestig1cd352e2016-06-07 17:53:06 -07001170 return SetRichTextProps(EP_LINELEADING, &SecProps, nullptr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001171}
1172
1173FX_BOOL CFX_Edit::SetRichTextLineIndent(FX_FLOAT fLineIndent) {
1174 CPVT_SecProps SecProps;
1175 SecProps.fLineIndent = fLineIndent;
thestig1cd352e2016-06-07 17:53:06 -07001176 return SetRichTextProps(EP_LINEINDENT, &SecProps, nullptr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001177}
1178
1179FX_BOOL CFX_Edit::SetRichTextAlignment(int32_t nAlignment) {
1180 CPVT_SecProps SecProps;
1181 SecProps.nAlignment = nAlignment;
thestig1cd352e2016-06-07 17:53:06 -07001182 return SetRichTextProps(EP_ALIGNMENT, &SecProps, nullptr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001183}
1184
1185FX_BOOL CFX_Edit::SetRichTextProps(EDIT_PROPS_E eProps,
1186 const CPVT_SecProps* pSecProps,
1187 const CPVT_WordProps* pWordProps) {
thestig821d59e2016-05-11 12:59:22 -07001188 if (!m_pVT->IsValid() || !m_pVT->IsRichText())
1189 return FALSE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001190
thestig821d59e2016-05-11 12:59:22 -07001191 CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator();
1192 CPVT_WordRange wrTemp = m_SelState.ConvertToWordRange();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001193
thestig821d59e2016-05-11 12:59:22 -07001194 m_pVT->UpdateWordPlace(wrTemp.BeginPos);
1195 m_pVT->UpdateWordPlace(wrTemp.EndPos);
1196 pIterator->SetAt(wrTemp.BeginPos);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001197
thestig821d59e2016-05-11 12:59:22 -07001198 BeginGroupUndo(L"");
1199 FX_BOOL bSet =
1200 SetSecProps(eProps, wrTemp.BeginPos, pSecProps, pWordProps, wrTemp, TRUE);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001201
thestig821d59e2016-05-11 12:59:22 -07001202 while (pIterator->NextWord()) {
1203 CPVT_WordPlace place = pIterator->GetAt();
1204 if (place.WordCmp(wrTemp.EndPos) > 0)
1205 break;
1206 FX_BOOL bSet1 =
1207 SetSecProps(eProps, place, pSecProps, pWordProps, wrTemp, TRUE);
1208 FX_BOOL bSet2 = SetWordProps(eProps, place, pWordProps, wrTemp, TRUE);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001209
thestig821d59e2016-05-11 12:59:22 -07001210 if (!bSet)
1211 bSet = (bSet1 || bSet2);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001212 }
1213
thestig821d59e2016-05-11 12:59:22 -07001214 EndGroupUndo();
1215
1216 if (bSet)
1217 PaintSetProps(eProps, wrTemp);
1218
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001219 return bSet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001220}
1221
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001222void CFX_Edit::PaintSetProps(EDIT_PROPS_E eProps, const CPVT_WordRange& wr) {
1223 switch (eProps) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001224 case EP_LINELEADING:
1225 case EP_LINEINDENT:
1226 case EP_ALIGNMENT:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001227 RearrangePart(wr);
1228 ScrollToCaret();
1229 Refresh(RP_ANALYSE);
1230 SetCaretOrigin();
1231 SetCaretInfo();
1232 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001233 case EP_WORDCOLOR:
1234 case EP_UNDERLINE:
1235 case EP_CROSSOUT:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001236 Refresh(RP_OPTIONAL, &wr);
1237 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001238 case EP_FONTINDEX:
1239 case EP_FONTSIZE:
1240 case EP_SCRIPTTYPE:
1241 case EP_CHARSPACE:
1242 case EP_HORZSCALE:
1243 case EP_BOLD:
1244 case EP_ITALIC:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001245 RearrangePart(wr);
1246 ScrollToCaret();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001247
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001248 CPVT_WordRange wrRefresh(m_pVT->GetSectionBeginPlace(wr.BeginPos),
1249 m_pVT->GetSectionEndPlace(wr.EndPos));
1250 Refresh(RP_ANALYSE, &wrRefresh);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001251
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001252 SetCaretOrigin();
1253 SetCaretInfo();
1254 break;
1255 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001256}
1257
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001258FX_BOOL CFX_Edit::SetSecProps(EDIT_PROPS_E eProps,
1259 const CPVT_WordPlace& place,
1260 const CPVT_SecProps* pSecProps,
1261 const CPVT_WordProps* pWordProps,
1262 const CPVT_WordRange& wr,
1263 FX_BOOL bAddUndo) {
thestig821d59e2016-05-11 12:59:22 -07001264 if (!m_pVT->IsValid() || !m_pVT->IsRichText())
1265 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001266
thestig821d59e2016-05-11 12:59:22 -07001267 CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator();
1268 FX_BOOL bSet = FALSE;
1269 CPVT_Section secinfo;
1270 CPVT_Section OldSecinfo;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001271
thestig821d59e2016-05-11 12:59:22 -07001272 CPVT_WordPlace oldplace = pIterator->GetAt();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001273
thestig821d59e2016-05-11 12:59:22 -07001274 if (eProps == EP_LINELEADING || eProps == EP_LINEINDENT ||
1275 eProps == EP_ALIGNMENT) {
1276 if (pSecProps) {
1277 pIterator->SetAt(place);
1278 if (pIterator->GetSection(secinfo)) {
1279 if (bAddUndo)
1280 OldSecinfo = secinfo;
1281
1282 switch (eProps) {
1283 case EP_LINELEADING:
1284 if (!FX_EDIT_IsFloatEqual(secinfo.SecProps.fLineLeading,
1285 pSecProps->fLineLeading)) {
1286 secinfo.SecProps.fLineLeading = pSecProps->fLineLeading;
1287 bSet = TRUE;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001288 }
thestig821d59e2016-05-11 12:59:22 -07001289 break;
1290 case EP_LINEINDENT:
1291 if (!FX_EDIT_IsFloatEqual(secinfo.SecProps.fLineIndent,
1292 pSecProps->fLineIndent)) {
1293 secinfo.SecProps.fLineIndent = pSecProps->fLineIndent;
1294 bSet = TRUE;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001295 }
thestig821d59e2016-05-11 12:59:22 -07001296 break;
1297 case EP_ALIGNMENT:
1298 if (secinfo.SecProps.nAlignment != pSecProps->nAlignment) {
1299 secinfo.SecProps.nAlignment = pSecProps->nAlignment;
1300 bSet = TRUE;
1301 }
1302 break;
1303 default:
1304 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001305 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001306 }
thestig821d59e2016-05-11 12:59:22 -07001307 }
1308 } else {
1309 if (pWordProps && place == m_pVT->GetSectionBeginPlace(place)) {
1310 pIterator->SetAt(place);
1311 if (pIterator->GetSection(secinfo)) {
1312 if (bAddUndo)
1313 OldSecinfo = secinfo;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001314
thestig821d59e2016-05-11 12:59:22 -07001315 switch (eProps) {
1316 case EP_FONTINDEX:
1317 if (secinfo.WordProps.nFontIndex != pWordProps->nFontIndex) {
1318 secinfo.WordProps.nFontIndex = pWordProps->nFontIndex;
1319 bSet = TRUE;
1320 }
1321 break;
1322 case EP_FONTSIZE:
1323 if (!FX_EDIT_IsFloatEqual(secinfo.WordProps.fFontSize,
1324 pWordProps->fFontSize)) {
1325 secinfo.WordProps.fFontSize = pWordProps->fFontSize;
1326 bSet = TRUE;
1327 }
1328 break;
1329 case EP_WORDCOLOR:
1330 if (secinfo.WordProps.dwWordColor != pWordProps->dwWordColor) {
1331 secinfo.WordProps.dwWordColor = pWordProps->dwWordColor;
1332 bSet = TRUE;
1333 }
1334 break;
1335 case EP_SCRIPTTYPE:
1336 if (secinfo.WordProps.nScriptType != pWordProps->nScriptType) {
1337 secinfo.WordProps.nScriptType = pWordProps->nScriptType;
1338 bSet = TRUE;
1339 }
1340 break;
1341 case EP_CHARSPACE:
1342 if (!FX_EDIT_IsFloatEqual(secinfo.WordProps.fCharSpace,
1343 pWordProps->fCharSpace)) {
1344 secinfo.WordProps.fCharSpace = pWordProps->fCharSpace;
1345 bSet = TRUE;
1346 }
1347 break;
1348 case EP_HORZSCALE:
1349 if (secinfo.WordProps.nHorzScale != pWordProps->nHorzScale) {
1350 secinfo.WordProps.nHorzScale = pWordProps->nHorzScale;
1351 bSet = TRUE;
1352 }
1353 break;
1354 case EP_UNDERLINE:
1355 if (pWordProps->nWordStyle & PVTWORD_STYLE_UNDERLINE) {
1356 if ((secinfo.WordProps.nWordStyle & PVTWORD_STYLE_UNDERLINE) ==
1357 0) {
1358 secinfo.WordProps.nWordStyle |= PVTWORD_STYLE_UNDERLINE;
1359 bSet = TRUE;
1360 }
1361 } else {
1362 if ((secinfo.WordProps.nWordStyle & PVTWORD_STYLE_UNDERLINE) !=
1363 0) {
1364 secinfo.WordProps.nWordStyle &= ~PVTWORD_STYLE_UNDERLINE;
1365 bSet = TRUE;
1366 }
1367 }
1368 break;
1369 case EP_CROSSOUT:
1370 if (pWordProps->nWordStyle & PVTWORD_STYLE_CROSSOUT) {
1371 if ((secinfo.WordProps.nWordStyle & PVTWORD_STYLE_CROSSOUT) ==
1372 0) {
1373 secinfo.WordProps.nWordStyle |= PVTWORD_STYLE_CROSSOUT;
1374 bSet = TRUE;
1375 }
1376 } else {
1377 if ((secinfo.WordProps.nWordStyle & PVTWORD_STYLE_CROSSOUT) !=
1378 0) {
1379 secinfo.WordProps.nWordStyle &= ~PVTWORD_STYLE_CROSSOUT;
1380 bSet = TRUE;
1381 }
1382 }
1383 break;
1384 case EP_BOLD:
1385 if (pWordProps->nWordStyle & PVTWORD_STYLE_BOLD) {
1386 if ((secinfo.WordProps.nWordStyle & PVTWORD_STYLE_BOLD) == 0) {
1387 secinfo.WordProps.nWordStyle |= PVTWORD_STYLE_BOLD;
1388 bSet = TRUE;
1389 }
1390 } else {
1391 if ((secinfo.WordProps.nWordStyle & PVTWORD_STYLE_BOLD) != 0) {
1392 secinfo.WordProps.nWordStyle &= ~PVTWORD_STYLE_BOLD;
1393 bSet = TRUE;
1394 }
1395 }
1396 break;
1397 case EP_ITALIC:
1398 if (pWordProps->nWordStyle & PVTWORD_STYLE_ITALIC) {
1399 if ((secinfo.WordProps.nWordStyle & PVTWORD_STYLE_ITALIC) == 0) {
1400 secinfo.WordProps.nWordStyle |= PVTWORD_STYLE_ITALIC;
1401 bSet = TRUE;
1402 }
1403 } else {
1404 if ((secinfo.WordProps.nWordStyle & PVTWORD_STYLE_ITALIC) != 0) {
1405 secinfo.WordProps.nWordStyle &= ~PVTWORD_STYLE_ITALIC;
1406 bSet = TRUE;
1407 }
1408 }
1409 break;
1410 default:
1411 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001412 }
1413 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001414 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001415 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001416
thestig821d59e2016-05-11 12:59:22 -07001417 if (bSet) {
1418 pIterator->SetSection(secinfo);
1419
1420 if (bAddUndo && m_bEnableUndo) {
1421 AddEditUndoItem(new CFXEU_SetSecProps(
1422 this, place, eProps, OldSecinfo.SecProps, OldSecinfo.WordProps,
1423 secinfo.SecProps, secinfo.WordProps, wr));
1424 }
1425 }
1426
1427 pIterator->SetAt(oldplace);
1428
1429 return bSet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001430}
1431
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001432FX_BOOL CFX_Edit::SetWordProps(EDIT_PROPS_E eProps,
1433 const CPVT_WordPlace& place,
1434 const CPVT_WordProps* pWordProps,
1435 const CPVT_WordRange& wr,
1436 FX_BOOL bAddUndo) {
thestig821d59e2016-05-11 12:59:22 -07001437 if (!m_pVT->IsValid() || !m_pVT->IsRichText())
1438 return FALSE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001439
thestig821d59e2016-05-11 12:59:22 -07001440 CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator();
1441 FX_BOOL bSet = FALSE;
1442 CPVT_Word wordinfo;
1443 CPVT_Word OldWordinfo;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001444
thestig821d59e2016-05-11 12:59:22 -07001445 CPVT_WordPlace oldplace = pIterator->GetAt();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001446
thestig821d59e2016-05-11 12:59:22 -07001447 if (pWordProps) {
1448 pIterator->SetAt(place);
1449 if (pIterator->GetWord(wordinfo)) {
1450 if (bAddUndo)
1451 OldWordinfo = wordinfo;
1452
1453 switch (eProps) {
1454 case EP_FONTINDEX:
1455 if (wordinfo.WordProps.nFontIndex != pWordProps->nFontIndex) {
1456 if (IPVT_FontMap* pFontMap = GetFontMap()) {
1457 wordinfo.WordProps.nFontIndex = pFontMap->GetWordFontIndex(
1458 wordinfo.Word, wordinfo.nCharset, pWordProps->nFontIndex);
1459 }
1460 bSet = TRUE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001461 }
thestig821d59e2016-05-11 12:59:22 -07001462 break;
1463 case EP_FONTSIZE:
1464 if (!FX_EDIT_IsFloatEqual(wordinfo.WordProps.fFontSize,
1465 pWordProps->fFontSize)) {
1466 wordinfo.WordProps.fFontSize = pWordProps->fFontSize;
1467 bSet = TRUE;
1468 }
1469 break;
1470 case EP_WORDCOLOR:
1471 if (wordinfo.WordProps.dwWordColor != pWordProps->dwWordColor) {
1472 wordinfo.WordProps.dwWordColor = pWordProps->dwWordColor;
1473 bSet = TRUE;
1474 }
1475 break;
1476 case EP_SCRIPTTYPE:
1477 if (wordinfo.WordProps.nScriptType != pWordProps->nScriptType) {
1478 wordinfo.WordProps.nScriptType = pWordProps->nScriptType;
1479 bSet = TRUE;
1480 }
1481 break;
1482 case EP_CHARSPACE:
1483 if (!FX_EDIT_IsFloatEqual(wordinfo.WordProps.fCharSpace,
1484 pWordProps->fCharSpace)) {
1485 wordinfo.WordProps.fCharSpace = pWordProps->fCharSpace;
1486 bSet = TRUE;
1487 }
1488 break;
1489 case EP_HORZSCALE:
1490 if (wordinfo.WordProps.nHorzScale != pWordProps->nHorzScale) {
1491 wordinfo.WordProps.nHorzScale = pWordProps->nHorzScale;
1492 bSet = TRUE;
1493 }
1494 break;
1495 case EP_UNDERLINE:
1496 if (pWordProps->nWordStyle & PVTWORD_STYLE_UNDERLINE) {
1497 if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_UNDERLINE) ==
1498 0) {
1499 wordinfo.WordProps.nWordStyle |= PVTWORD_STYLE_UNDERLINE;
1500 bSet = TRUE;
1501 }
1502 } else {
1503 if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_UNDERLINE) !=
1504 0) {
1505 wordinfo.WordProps.nWordStyle &= ~PVTWORD_STYLE_UNDERLINE;
1506 bSet = TRUE;
1507 }
1508 }
1509 break;
1510 case EP_CROSSOUT:
1511 if (pWordProps->nWordStyle & PVTWORD_STYLE_CROSSOUT) {
1512 if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_CROSSOUT) == 0) {
1513 wordinfo.WordProps.nWordStyle |= PVTWORD_STYLE_CROSSOUT;
1514 bSet = TRUE;
1515 }
1516 } else {
1517 if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_CROSSOUT) != 0) {
1518 wordinfo.WordProps.nWordStyle &= ~PVTWORD_STYLE_CROSSOUT;
1519 bSet = TRUE;
1520 }
1521 }
1522 break;
1523 case EP_BOLD:
1524 if (pWordProps->nWordStyle & PVTWORD_STYLE_BOLD) {
1525 if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_BOLD) == 0) {
1526 wordinfo.WordProps.nWordStyle |= PVTWORD_STYLE_BOLD;
1527 bSet = TRUE;
1528 }
1529 } else {
1530 if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_BOLD) != 0) {
1531 wordinfo.WordProps.nWordStyle &= ~PVTWORD_STYLE_BOLD;
1532 bSet = TRUE;
1533 }
1534 }
1535 break;
1536 case EP_ITALIC:
1537 if (pWordProps->nWordStyle & PVTWORD_STYLE_ITALIC) {
1538 if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_ITALIC) == 0) {
1539 wordinfo.WordProps.nWordStyle |= PVTWORD_STYLE_ITALIC;
1540 bSet = TRUE;
1541 }
1542 } else {
1543 if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_ITALIC) != 0) {
1544 wordinfo.WordProps.nWordStyle &= ~PVTWORD_STYLE_ITALIC;
1545 bSet = TRUE;
1546 }
1547 }
1548 break;
1549 default:
1550 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001551 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001552 }
1553 }
1554
thestig821d59e2016-05-11 12:59:22 -07001555 if (bSet) {
1556 pIterator->SetWord(wordinfo);
1557
1558 if (bAddUndo && m_bEnableUndo) {
1559 AddEditUndoItem(new CFXEU_SetWordProps(
1560 this, place, eProps, OldWordinfo.WordProps, wordinfo.WordProps, wr));
1561 }
1562 }
1563
1564 pIterator->SetAt(oldplace);
1565 return bSet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001566}
1567
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001568void CFX_Edit::SetText(const FX_WCHAR* text,
Lei Zhangc2fb35f2016-01-05 16:46:58 -08001569 int32_t charset,
1570 const CPVT_SecProps* pSecProps,
1571 const CPVT_WordProps* pWordProps) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001572 SetText(text, charset, pSecProps, pWordProps, TRUE, TRUE);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001573}
1574
Tom Sepez62a70f92016-03-21 15:00:20 -07001575FX_BOOL CFX_Edit::InsertWord(uint16_t word,
Lei Zhangc2fb35f2016-01-05 16:46:58 -08001576 int32_t charset,
1577 const CPVT_WordProps* pWordProps) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001578 return InsertWord(word, charset, pWordProps, TRUE, TRUE);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001579}
1580
Lei Zhangc2fb35f2016-01-05 16:46:58 -08001581FX_BOOL CFX_Edit::InsertReturn(const CPVT_SecProps* pSecProps,
1582 const CPVT_WordProps* pWordProps) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001583 return InsertReturn(pSecProps, pWordProps, TRUE, TRUE);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001584}
1585
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001586FX_BOOL CFX_Edit::Backspace() {
1587 return Backspace(TRUE, TRUE);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001588}
1589
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001590FX_BOOL CFX_Edit::Delete() {
1591 return Delete(TRUE, TRUE);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001592}
1593
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001594FX_BOOL CFX_Edit::Clear() {
1595 return Clear(TRUE, TRUE);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001596}
1597
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001598FX_BOOL CFX_Edit::InsertText(const FX_WCHAR* text,
Lei Zhangc2fb35f2016-01-05 16:46:58 -08001599 int32_t charset,
1600 const CPVT_SecProps* pSecProps,
1601 const CPVT_WordProps* pWordProps) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001602 return InsertText(text, charset, pSecProps, pWordProps, TRUE, TRUE);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001603}
1604
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001605FX_FLOAT CFX_Edit::GetFontSize() const {
1606 return m_pVT->GetFontSize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001607}
1608
Tom Sepez62a70f92016-03-21 15:00:20 -07001609uint16_t CFX_Edit::GetPasswordChar() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001610 return m_pVT->GetPasswordChar();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001611}
1612
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001613int32_t CFX_Edit::GetCharArray() const {
1614 return m_pVT->GetCharArray();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001615}
1616
Tom Sepez281a9ea2016-02-26 14:24:28 -08001617CFX_FloatRect CFX_Edit::GetPlateRect() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001618 return m_pVT->GetPlateRect();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001619}
1620
Tom Sepez281a9ea2016-02-26 14:24:28 -08001621CFX_FloatRect CFX_Edit::GetContentRect() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001622 return VTToEdit(m_pVT->GetContentRect());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001623}
1624
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001625int32_t CFX_Edit::GetHorzScale() const {
1626 return m_pVT->GetHorzScale();
1627}
1628
1629FX_FLOAT CFX_Edit::GetCharSpace() const {
1630 return m_pVT->GetCharSpace();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001631}
1632
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001633CPVT_WordRange CFX_Edit::GetWholeWordRange() const {
1634 if (m_pVT->IsValid())
1635 return CPVT_WordRange(m_pVT->GetBeginWordPlace(), m_pVT->GetEndWordPlace());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001636
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001637 return CPVT_WordRange();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001638}
1639
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001640CPVT_WordRange CFX_Edit::GetVisibleWordRange() const {
1641 if (m_bEnableOverflow)
1642 return GetWholeWordRange();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001643
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001644 if (m_pVT->IsValid()) {
Tom Sepez281a9ea2016-02-26 14:24:28 -08001645 CFX_FloatRect rcPlate = m_pVT->GetPlateRect();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001646
Tom Sepez281a9ea2016-02-26 14:24:28 -08001647 CPVT_WordPlace place1 = m_pVT->SearchWordPlace(
1648 EditToVT(CFX_FloatPoint(rcPlate.left, rcPlate.top)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001649 CPVT_WordPlace place2 = m_pVT->SearchWordPlace(
Tom Sepez281a9ea2016-02-26 14:24:28 -08001650 EditToVT(CFX_FloatPoint(rcPlate.right, rcPlate.bottom)));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001651
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001652 return CPVT_WordRange(place1, place2);
1653 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07001654
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001655 return CPVT_WordRange();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001656}
1657
Tom Sepez281a9ea2016-02-26 14:24:28 -08001658CPVT_WordPlace CFX_Edit::SearchWordPlace(const CFX_FloatPoint& point) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001659 if (m_pVT->IsValid()) {
1660 return m_pVT->SearchWordPlace(EditToVT(point));
1661 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001662
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001663 return CPVT_WordPlace();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001664}
1665
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001666void CFX_Edit::Paint() {
1667 if (m_pVT->IsValid()) {
1668 RearrangeAll();
1669 ScrollToCaret();
1670 Refresh(RP_NOANALYSE);
1671 SetCaretOrigin();
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001672 SetCaretInfo();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001673 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001674}
1675
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001676void CFX_Edit::RearrangeAll() {
1677 if (m_pVT->IsValid()) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001678 m_pVT->UpdateWordPlace(m_wpCaret);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001679 m_pVT->RearrangeAll();
1680 m_pVT->UpdateWordPlace(m_wpCaret);
1681 SetScrollInfo();
1682 SetContentChanged();
1683 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001684}
1685
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001686void CFX_Edit::RearrangePart(const CPVT_WordRange& range) {
1687 if (m_pVT->IsValid()) {
1688 m_pVT->UpdateWordPlace(m_wpCaret);
1689 m_pVT->RearrangePart(range);
1690 m_pVT->UpdateWordPlace(m_wpCaret);
1691 SetScrollInfo();
1692 SetContentChanged();
1693 }
1694}
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07001695
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001696void CFX_Edit::SetContentChanged() {
1697 if (m_bNotify && m_pNotify) {
Tom Sepez281a9ea2016-02-26 14:24:28 -08001698 CFX_FloatRect rcContent = m_pVT->GetContentRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001699 if (rcContent.Width() != m_rcOldContent.Width() ||
1700 rcContent.Height() != m_rcOldContent.Height()) {
1701 if (!m_bNotifyFlag) {
1702 m_bNotifyFlag = TRUE;
1703 m_pNotify->IOnContentChange(rcContent);
1704 m_bNotifyFlag = FALSE;
1705 }
1706 m_rcOldContent = rcContent;
1707 }
1708 }
1709}
1710
1711void CFX_Edit::SelectAll() {
1712 if (m_pVT->IsValid()) {
Lei Zhang375a8642016-01-11 11:59:17 -08001713 m_SelState = CFX_Edit_Select(GetWholeWordRange());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001714 SetCaret(m_SelState.EndPos);
1715
1716 ScrollToCaret();
1717 CPVT_WordRange wrVisible = GetVisibleWordRange();
1718 Refresh(RP_OPTIONAL, &wrVisible);
1719 SetCaretInfo();
1720 }
1721}
1722
1723void CFX_Edit::SelectNone() {
1724 if (m_pVT->IsValid()) {
1725 if (m_SelState.IsExist()) {
1726 CPVT_WordRange wrTemp = m_SelState.ConvertToWordRange();
1727 m_SelState.Default();
1728 Refresh(RP_OPTIONAL, &wrTemp);
1729 }
1730 }
1731}
1732
1733FX_BOOL CFX_Edit::IsSelected() const {
1734 return m_SelState.IsExist();
1735}
1736
Tom Sepez281a9ea2016-02-26 14:24:28 -08001737CFX_FloatPoint CFX_Edit::VTToEdit(const CFX_FloatPoint& point) const {
1738 CFX_FloatRect rcContent = m_pVT->GetContentRect();
1739 CFX_FloatRect rcPlate = m_pVT->GetPlateRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001740
1741 FX_FLOAT fPadding = 0.0f;
1742
1743 switch (m_nAlignment) {
1744 case 0:
1745 fPadding = 0.0f;
1746 break;
1747 case 1:
1748 fPadding = (rcPlate.Height() - rcContent.Height()) * 0.5f;
1749 break;
1750 case 2:
1751 fPadding = rcPlate.Height() - rcContent.Height();
1752 break;
1753 }
1754
Tom Sepez281a9ea2016-02-26 14:24:28 -08001755 return CFX_FloatPoint(point.x - (m_ptScrollPos.x - rcPlate.left),
1756 point.y - (m_ptScrollPos.y + fPadding - rcPlate.top));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001757}
1758
Tom Sepez281a9ea2016-02-26 14:24:28 -08001759CFX_FloatPoint CFX_Edit::EditToVT(const CFX_FloatPoint& point) const {
1760 CFX_FloatRect rcContent = m_pVT->GetContentRect();
1761 CFX_FloatRect rcPlate = m_pVT->GetPlateRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001762
1763 FX_FLOAT fPadding = 0.0f;
1764
1765 switch (m_nAlignment) {
1766 case 0:
1767 fPadding = 0.0f;
1768 break;
1769 case 1:
1770 fPadding = (rcPlate.Height() - rcContent.Height()) * 0.5f;
1771 break;
1772 case 2:
1773 fPadding = rcPlate.Height() - rcContent.Height();
1774 break;
1775 }
1776
Tom Sepez281a9ea2016-02-26 14:24:28 -08001777 return CFX_FloatPoint(point.x + (m_ptScrollPos.x - rcPlate.left),
1778 point.y + (m_ptScrollPos.y + fPadding - rcPlate.top));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001779}
1780
Tom Sepez281a9ea2016-02-26 14:24:28 -08001781CFX_FloatRect CFX_Edit::VTToEdit(const CFX_FloatRect& rect) const {
1782 CFX_FloatPoint ptLeftBottom =
1783 VTToEdit(CFX_FloatPoint(rect.left, rect.bottom));
1784 CFX_FloatPoint ptRightTop = VTToEdit(CFX_FloatPoint(rect.right, rect.top));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001785
Tom Sepez281a9ea2016-02-26 14:24:28 -08001786 return CFX_FloatRect(ptLeftBottom.x, ptLeftBottom.y, ptRightTop.x,
1787 ptRightTop.y);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001788}
1789
Tom Sepez281a9ea2016-02-26 14:24:28 -08001790CFX_FloatRect CFX_Edit::EditToVT(const CFX_FloatRect& rect) const {
1791 CFX_FloatPoint ptLeftBottom =
1792 EditToVT(CFX_FloatPoint(rect.left, rect.bottom));
1793 CFX_FloatPoint ptRightTop = EditToVT(CFX_FloatPoint(rect.right, rect.top));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001794
Tom Sepez281a9ea2016-02-26 14:24:28 -08001795 return CFX_FloatRect(ptLeftBottom.x, ptLeftBottom.y, ptRightTop.x,
1796 ptRightTop.y);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001797}
1798
1799void CFX_Edit::SetScrollInfo() {
1800 if (m_bNotify && m_pNotify) {
Tom Sepez281a9ea2016-02-26 14:24:28 -08001801 CFX_FloatRect rcPlate = m_pVT->GetPlateRect();
1802 CFX_FloatRect rcContent = m_pVT->GetContentRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001803
1804 if (!m_bNotifyFlag) {
1805 m_bNotifyFlag = TRUE;
1806 m_pNotify->IOnSetScrollInfoX(rcPlate.left, rcPlate.right, rcContent.left,
1807 rcContent.right, rcPlate.Width() / 3,
1808 rcPlate.Width());
1809
1810 m_pNotify->IOnSetScrollInfoY(rcPlate.bottom, rcPlate.top,
1811 rcContent.bottom, rcContent.top,
1812 rcPlate.Height() / 3, rcPlate.Height());
1813 m_bNotifyFlag = FALSE;
1814 }
1815 }
1816}
1817
1818void CFX_Edit::SetScrollPosX(FX_FLOAT fx) {
1819 if (!m_bEnableScroll)
1820 return;
1821
1822 if (m_pVT->IsValid()) {
1823 if (!FX_EDIT_IsFloatEqual(m_ptScrollPos.x, fx)) {
1824 m_ptScrollPos.x = fx;
1825 Refresh(RP_NOANALYSE);
1826
1827 if (m_bNotify && m_pNotify) {
1828 if (!m_bNotifyFlag) {
1829 m_bNotifyFlag = TRUE;
1830 m_pNotify->IOnSetScrollPosX(fx);
1831 m_bNotifyFlag = FALSE;
1832 }
1833 }
1834 }
1835 }
1836}
1837
1838void CFX_Edit::SetScrollPosY(FX_FLOAT fy) {
1839 if (!m_bEnableScroll)
1840 return;
1841
1842 if (m_pVT->IsValid()) {
1843 if (!FX_EDIT_IsFloatEqual(m_ptScrollPos.y, fy)) {
1844 m_ptScrollPos.y = fy;
1845 Refresh(RP_NOANALYSE);
1846
1847 if (m_bNotify && m_pNotify) {
1848 if (!m_bNotifyFlag) {
1849 m_bNotifyFlag = TRUE;
1850 m_pNotify->IOnSetScrollPosY(fy);
1851 m_bNotifyFlag = FALSE;
1852 }
1853 }
1854 }
1855 }
1856}
1857
Tom Sepez281a9ea2016-02-26 14:24:28 -08001858void CFX_Edit::SetScrollPos(const CFX_FloatPoint& point) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001859 SetScrollPosX(point.x);
1860 SetScrollPosY(point.y);
1861 SetScrollLimit();
1862 SetCaretInfo();
1863}
1864
Tom Sepez281a9ea2016-02-26 14:24:28 -08001865CFX_FloatPoint CFX_Edit::GetScrollPos() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001866 return m_ptScrollPos;
1867}
1868
1869void CFX_Edit::SetScrollLimit() {
1870 if (m_pVT->IsValid()) {
Tom Sepez281a9ea2016-02-26 14:24:28 -08001871 CFX_FloatRect rcContent = m_pVT->GetContentRect();
1872 CFX_FloatRect rcPlate = m_pVT->GetPlateRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001873
1874 if (rcPlate.Width() > rcContent.Width()) {
1875 SetScrollPosX(rcPlate.left);
1876 } else {
1877 if (FX_EDIT_IsFloatSmaller(m_ptScrollPos.x, rcContent.left)) {
1878 SetScrollPosX(rcContent.left);
1879 } else if (FX_EDIT_IsFloatBigger(m_ptScrollPos.x,
1880 rcContent.right - rcPlate.Width())) {
1881 SetScrollPosX(rcContent.right - rcPlate.Width());
1882 }
1883 }
1884
1885 if (rcPlate.Height() > rcContent.Height()) {
1886 SetScrollPosY(rcPlate.top);
1887 } else {
1888 if (FX_EDIT_IsFloatSmaller(m_ptScrollPos.y,
1889 rcContent.bottom + rcPlate.Height())) {
1890 SetScrollPosY(rcContent.bottom + rcPlate.Height());
1891 } else if (FX_EDIT_IsFloatBigger(m_ptScrollPos.y, rcContent.top)) {
1892 SetScrollPosY(rcContent.top);
1893 }
1894 }
1895 }
1896}
1897
1898void CFX_Edit::ScrollToCaret() {
1899 SetScrollLimit();
1900
thestig821d59e2016-05-11 12:59:22 -07001901 if (!m_pVT->IsValid())
1902 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001903
thestig821d59e2016-05-11 12:59:22 -07001904 CFX_FloatPoint ptHead(0, 0);
1905 CFX_FloatPoint ptFoot(0, 0);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001906
thestig821d59e2016-05-11 12:59:22 -07001907 CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator();
1908 pIterator->SetAt(m_wpCaret);
1909
1910 CPVT_Word word;
1911 CPVT_Line line;
1912 if (pIterator->GetWord(word)) {
1913 ptHead.x = word.ptWord.x + word.fWidth;
1914 ptHead.y = word.ptWord.y + word.fAscent;
1915 ptFoot.x = word.ptWord.x + word.fWidth;
1916 ptFoot.y = word.ptWord.y + word.fDescent;
1917 } else if (pIterator->GetLine(line)) {
1918 ptHead.x = line.ptLine.x;
1919 ptHead.y = line.ptLine.y + line.fLineAscent;
1920 ptFoot.x = line.ptLine.x;
1921 ptFoot.y = line.ptLine.y + line.fLineDescent;
1922 }
1923
1924 CFX_FloatPoint ptHeadEdit = VTToEdit(ptHead);
1925 CFX_FloatPoint ptFootEdit = VTToEdit(ptFoot);
1926
1927 CFX_FloatRect rcPlate = m_pVT->GetPlateRect();
1928
1929 if (!FX_EDIT_IsFloatEqual(rcPlate.left, rcPlate.right)) {
1930 if (FX_EDIT_IsFloatSmaller(ptHeadEdit.x, rcPlate.left) ||
1931 FX_EDIT_IsFloatEqual(ptHeadEdit.x, rcPlate.left)) {
1932 SetScrollPosX(ptHead.x);
1933 } else if (FX_EDIT_IsFloatBigger(ptHeadEdit.x, rcPlate.right)) {
1934 SetScrollPosX(ptHead.x - rcPlate.Width());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001935 }
thestig821d59e2016-05-11 12:59:22 -07001936 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001937
thestig821d59e2016-05-11 12:59:22 -07001938 if (!FX_EDIT_IsFloatEqual(rcPlate.top, rcPlate.bottom)) {
1939 if (FX_EDIT_IsFloatSmaller(ptFootEdit.y, rcPlate.bottom) ||
1940 FX_EDIT_IsFloatEqual(ptFootEdit.y, rcPlate.bottom)) {
1941 if (FX_EDIT_IsFloatSmaller(ptHeadEdit.y, rcPlate.top)) {
1942 SetScrollPosY(ptFoot.y + rcPlate.Height());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001943 }
thestig821d59e2016-05-11 12:59:22 -07001944 } else if (FX_EDIT_IsFloatBigger(ptHeadEdit.y, rcPlate.top)) {
1945 if (FX_EDIT_IsFloatBigger(ptFootEdit.y, rcPlate.bottom)) {
1946 SetScrollPosY(ptHead.y);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001947 }
1948 }
1949 }
1950}
1951
1952void CFX_Edit::Refresh(REFRESH_PLAN_E ePlan,
1953 const CPVT_WordRange* pRange1,
1954 const CPVT_WordRange* pRange2) {
1955 if (m_bEnableRefresh && m_pVT->IsValid()) {
1956 m_Refresh.BeginRefresh();
1957 RefreshPushLineRects(GetVisibleWordRange());
1958
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001959 m_Refresh.NoAnalyse();
1960 m_ptRefreshScrollPos = m_ptScrollPos;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001961
1962 if (m_bNotify && m_pNotify) {
1963 if (!m_bNotifyFlag) {
1964 m_bNotifyFlag = TRUE;
1965 if (const CFX_Edit_RectArray* pRects = m_Refresh.GetRefreshRects()) {
1966 for (int32_t i = 0, sz = pRects->GetSize(); i < sz; i++)
1967 m_pNotify->IOnInvalidateRect(pRects->GetAt(i));
1968 }
1969 m_bNotifyFlag = FALSE;
1970 }
1971 }
1972
1973 m_Refresh.EndRefresh();
1974 }
1975}
1976
1977void CFX_Edit::RefreshPushLineRects(const CPVT_WordRange& wr) {
thestig821d59e2016-05-11 12:59:22 -07001978 if (!m_pVT->IsValid())
1979 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001980
thestig821d59e2016-05-11 12:59:22 -07001981 CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator();
1982 CPVT_WordPlace wpBegin = wr.BeginPos;
1983 m_pVT->UpdateWordPlace(wpBegin);
1984 CPVT_WordPlace wpEnd = wr.EndPos;
1985 m_pVT->UpdateWordPlace(wpEnd);
1986 pIterator->SetAt(wpBegin);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001987
thestig821d59e2016-05-11 12:59:22 -07001988 CPVT_Line lineinfo;
1989 do {
1990 if (!pIterator->GetLine(lineinfo))
1991 break;
1992 if (lineinfo.lineplace.LineCmp(wpEnd) > 0)
1993 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001994
thestig821d59e2016-05-11 12:59:22 -07001995 CFX_FloatRect rcLine(lineinfo.ptLine.x,
1996 lineinfo.ptLine.y + lineinfo.fLineDescent,
1997 lineinfo.ptLine.x + lineinfo.fLineWidth,
1998 lineinfo.ptLine.y + lineinfo.fLineAscent);
1999
2000 m_Refresh.Push(CPVT_WordRange(lineinfo.lineplace, lineinfo.lineEnd),
2001 VTToEdit(rcLine));
2002 } while (pIterator->NextLine());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002003}
2004
2005void CFX_Edit::RefreshPushRandomRects(const CPVT_WordRange& wr) {
thestig821d59e2016-05-11 12:59:22 -07002006 if (!m_pVT->IsValid())
2007 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002008
thestig821d59e2016-05-11 12:59:22 -07002009 CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator();
2010 CPVT_WordRange wrTemp = wr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002011
thestig821d59e2016-05-11 12:59:22 -07002012 m_pVT->UpdateWordPlace(wrTemp.BeginPos);
2013 m_pVT->UpdateWordPlace(wrTemp.EndPos);
2014 pIterator->SetAt(wrTemp.BeginPos);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002015
thestig821d59e2016-05-11 12:59:22 -07002016 CPVT_Word wordinfo;
2017 CPVT_Line lineinfo;
2018 CPVT_WordPlace place;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002019
thestig821d59e2016-05-11 12:59:22 -07002020 while (pIterator->NextWord()) {
2021 place = pIterator->GetAt();
2022 if (place.WordCmp(wrTemp.EndPos) > 0)
2023 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002024
thestig821d59e2016-05-11 12:59:22 -07002025 pIterator->GetWord(wordinfo);
2026 pIterator->GetLine(lineinfo);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002027
thestig821d59e2016-05-11 12:59:22 -07002028 if (place.LineCmp(wrTemp.BeginPos) == 0 ||
2029 place.LineCmp(wrTemp.EndPos) == 0) {
2030 CFX_FloatRect rcWord(wordinfo.ptWord.x,
2031 lineinfo.ptLine.y + lineinfo.fLineDescent,
2032 wordinfo.ptWord.x + wordinfo.fWidth,
2033 lineinfo.ptLine.y + lineinfo.fLineAscent);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002034
thestig821d59e2016-05-11 12:59:22 -07002035 m_Refresh.AddRefresh(VTToEdit(rcWord));
2036 } else {
2037 CFX_FloatRect rcLine(lineinfo.ptLine.x,
2038 lineinfo.ptLine.y + lineinfo.fLineDescent,
2039 lineinfo.ptLine.x + lineinfo.fLineWidth,
2040 lineinfo.ptLine.y + lineinfo.fLineAscent);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002041
thestig821d59e2016-05-11 12:59:22 -07002042 m_Refresh.AddRefresh(VTToEdit(rcLine));
2043
2044 pIterator->NextLine();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002045 }
2046 }
2047}
2048
2049void CFX_Edit::RefreshWordRange(const CPVT_WordRange& wr) {
thestig821d59e2016-05-11 12:59:22 -07002050 CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator();
2051 CPVT_WordRange wrTemp = wr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002052
thestig821d59e2016-05-11 12:59:22 -07002053 m_pVT->UpdateWordPlace(wrTemp.BeginPos);
2054 m_pVT->UpdateWordPlace(wrTemp.EndPos);
2055 pIterator->SetAt(wrTemp.BeginPos);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002056
thestig821d59e2016-05-11 12:59:22 -07002057 CPVT_Word wordinfo;
2058 CPVT_Line lineinfo;
2059 CPVT_WordPlace place;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002060
thestig821d59e2016-05-11 12:59:22 -07002061 while (pIterator->NextWord()) {
2062 place = pIterator->GetAt();
2063 if (place.WordCmp(wrTemp.EndPos) > 0)
2064 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002065
thestig821d59e2016-05-11 12:59:22 -07002066 pIterator->GetWord(wordinfo);
2067 pIterator->GetLine(lineinfo);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002068
thestig821d59e2016-05-11 12:59:22 -07002069 if (place.LineCmp(wrTemp.BeginPos) == 0 ||
2070 place.LineCmp(wrTemp.EndPos) == 0) {
2071 CFX_FloatRect rcWord(wordinfo.ptWord.x,
2072 lineinfo.ptLine.y + lineinfo.fLineDescent,
2073 wordinfo.ptWord.x + wordinfo.fWidth,
2074 lineinfo.ptLine.y + lineinfo.fLineAscent);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002075
thestig821d59e2016-05-11 12:59:22 -07002076 if (m_bNotify && m_pNotify) {
2077 if (!m_bNotifyFlag) {
2078 m_bNotifyFlag = TRUE;
2079 CFX_FloatRect rcRefresh = VTToEdit(rcWord);
2080 m_pNotify->IOnInvalidateRect(&rcRefresh);
2081 m_bNotifyFlag = FALSE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002082 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002083 }
thestig821d59e2016-05-11 12:59:22 -07002084 } else {
2085 CFX_FloatRect rcLine(lineinfo.ptLine.x,
2086 lineinfo.ptLine.y + lineinfo.fLineDescent,
2087 lineinfo.ptLine.x + lineinfo.fLineWidth,
2088 lineinfo.ptLine.y + lineinfo.fLineAscent);
2089
2090 if (m_bNotify && m_pNotify) {
2091 if (!m_bNotifyFlag) {
2092 m_bNotifyFlag = TRUE;
2093 CFX_FloatRect rcRefresh = VTToEdit(rcLine);
2094 m_pNotify->IOnInvalidateRect(&rcRefresh);
2095 m_bNotifyFlag = FALSE;
2096 }
2097 }
2098
2099 pIterator->NextLine();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002100 }
2101 }
2102}
2103
2104void CFX_Edit::SetCaret(const CPVT_WordPlace& place) {
2105 m_wpOldCaret = m_wpCaret;
2106 m_wpCaret = place;
2107}
2108
2109void CFX_Edit::SetCaretInfo() {
2110 if (m_bNotify && m_pNotify) {
2111 if (!m_bNotifyFlag) {
Tom Sepez281a9ea2016-02-26 14:24:28 -08002112 CFX_FloatPoint ptHead(0.0f, 0.0f), ptFoot(0.0f, 0.0f);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002113
thestig821d59e2016-05-11 12:59:22 -07002114 CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator();
2115 pIterator->SetAt(m_wpCaret);
2116 CPVT_Word word;
2117 CPVT_Line line;
2118 if (pIterator->GetWord(word)) {
2119 ptHead.x = word.ptWord.x + word.fWidth;
2120 ptHead.y = word.ptWord.y + word.fAscent;
2121 ptFoot.x = word.ptWord.x + word.fWidth;
2122 ptFoot.y = word.ptWord.y + word.fDescent;
2123 } else if (pIterator->GetLine(line)) {
2124 ptHead.x = line.ptLine.x;
2125 ptHead.y = line.ptLine.y + line.fLineAscent;
2126 ptFoot.x = line.ptLine.x;
2127 ptFoot.y = line.ptLine.y + line.fLineDescent;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002128 }
2129
2130 m_bNotifyFlag = TRUE;
2131 m_pNotify->IOnSetCaret(!m_SelState.IsExist(), VTToEdit(ptHead),
2132 VTToEdit(ptFoot), m_wpCaret);
2133 m_bNotifyFlag = FALSE;
2134 }
2135 }
2136
2137 SetCaretChange();
2138}
2139
2140void CFX_Edit::SetCaretChange() {
2141 if (m_wpCaret == m_wpOldCaret)
2142 return;
2143
thestig821d59e2016-05-11 12:59:22 -07002144 if (!m_bNotify || !m_pVT->IsRichText() || !m_pNotify)
2145 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002146
thestig821d59e2016-05-11 12:59:22 -07002147 CPVT_SecProps SecProps;
2148 CPVT_WordProps WordProps;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002149
thestig821d59e2016-05-11 12:59:22 -07002150 CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator();
2151 pIterator->SetAt(m_wpCaret);
2152 CPVT_Word word;
2153 CPVT_Section section;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002154
thestig821d59e2016-05-11 12:59:22 -07002155 if (pIterator->GetSection(section)) {
2156 SecProps = section.SecProps;
2157 WordProps = section.WordProps;
2158 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002159
thestig821d59e2016-05-11 12:59:22 -07002160 if (pIterator->GetWord(word))
2161 WordProps = word.WordProps;
2162
2163 if (!m_bNotifyFlag) {
2164 m_bNotifyFlag = TRUE;
2165 m_pNotify->IOnCaretChange(SecProps, WordProps);
2166 m_bNotifyFlag = FALSE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002167 }
2168}
2169
2170void CFX_Edit::SetCaret(int32_t nPos) {
2171 if (m_pVT->IsValid()) {
2172 SelectNone();
2173 SetCaret(m_pVT->WordIndexToWordPlace(nPos));
2174 m_SelState.Set(m_wpCaret, m_wpCaret);
2175
2176 ScrollToCaret();
2177 SetCaretOrigin();
2178 SetCaretInfo();
2179 }
2180}
2181
Tom Sepez281a9ea2016-02-26 14:24:28 -08002182void CFX_Edit::OnMouseDown(const CFX_FloatPoint& point,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002183 FX_BOOL bShift,
2184 FX_BOOL bCtrl) {
2185 if (m_pVT->IsValid()) {
2186 SelectNone();
2187 SetCaret(m_pVT->SearchWordPlace(EditToVT(point)));
2188 m_SelState.Set(m_wpCaret, m_wpCaret);
2189
2190 ScrollToCaret();
2191 SetCaretOrigin();
2192 SetCaretInfo();
2193 }
2194}
2195
Tom Sepez281a9ea2016-02-26 14:24:28 -08002196void CFX_Edit::OnMouseMove(const CFX_FloatPoint& point,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002197 FX_BOOL bShift,
2198 FX_BOOL bCtrl) {
2199 if (m_pVT->IsValid()) {
2200 SetCaret(m_pVT->SearchWordPlace(EditToVT(point)));
2201
2202 if (m_wpCaret != m_wpOldCaret) {
2203 m_SelState.SetEndPos(m_wpCaret);
2204
2205 ScrollToCaret();
2206 CPVT_WordRange wr(m_wpOldCaret, m_wpCaret);
2207 Refresh(RP_OPTIONAL, &wr);
2208 SetCaretOrigin();
2209 SetCaretInfo();
2210 }
2211 }
2212}
2213
2214void CFX_Edit::OnVK_UP(FX_BOOL bShift, FX_BOOL bCtrl) {
2215 if (m_pVT->IsValid()) {
2216 SetCaret(m_pVT->GetUpWordPlace(m_wpCaret, m_ptCaret));
2217
2218 if (bShift) {
2219 if (m_SelState.IsExist())
2220 m_SelState.SetEndPos(m_wpCaret);
2221 else
2222 m_SelState.Set(m_wpOldCaret, m_wpCaret);
2223
2224 if (m_wpOldCaret != m_wpCaret) {
2225 ScrollToCaret();
2226 CPVT_WordRange wr(m_wpOldCaret, m_wpCaret);
2227 Refresh(RP_OPTIONAL, &wr);
2228 SetCaretInfo();
2229 }
2230 } else {
2231 SelectNone();
2232
2233 ScrollToCaret();
2234 SetCaretInfo();
2235 }
2236 }
2237}
2238
2239void CFX_Edit::OnVK_DOWN(FX_BOOL bShift, FX_BOOL bCtrl) {
2240 if (m_pVT->IsValid()) {
2241 SetCaret(m_pVT->GetDownWordPlace(m_wpCaret, m_ptCaret));
2242
2243 if (bShift) {
2244 if (m_SelState.IsExist())
2245 m_SelState.SetEndPos(m_wpCaret);
2246 else
2247 m_SelState.Set(m_wpOldCaret, m_wpCaret);
2248
2249 if (m_wpOldCaret != m_wpCaret) {
2250 ScrollToCaret();
2251 CPVT_WordRange wr(m_wpOldCaret, m_wpCaret);
2252 Refresh(RP_OPTIONAL, &wr);
2253 SetCaretInfo();
2254 }
2255 } else {
2256 SelectNone();
2257
2258 ScrollToCaret();
2259 SetCaretInfo();
2260 }
2261 }
2262}
2263
2264void CFX_Edit::OnVK_LEFT(FX_BOOL bShift, FX_BOOL bCtrl) {
2265 if (m_pVT->IsValid()) {
2266 if (bShift) {
2267 if (m_wpCaret == m_pVT->GetLineBeginPlace(m_wpCaret) &&
2268 m_wpCaret != m_pVT->GetSectionBeginPlace(m_wpCaret))
2269 SetCaret(m_pVT->GetPrevWordPlace(m_wpCaret));
2270
2271 SetCaret(m_pVT->GetPrevWordPlace(m_wpCaret));
2272
2273 if (m_SelState.IsExist())
2274 m_SelState.SetEndPos(m_wpCaret);
2275 else
2276 m_SelState.Set(m_wpOldCaret, m_wpCaret);
2277
2278 if (m_wpOldCaret != m_wpCaret) {
2279 ScrollToCaret();
2280 CPVT_WordRange wr(m_wpOldCaret, m_wpCaret);
2281 Refresh(RP_OPTIONAL, &wr);
2282 SetCaretInfo();
2283 }
2284 } else {
2285 if (m_SelState.IsExist()) {
2286 if (m_SelState.BeginPos.WordCmp(m_SelState.EndPos) < 0)
2287 SetCaret(m_SelState.BeginPos);
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002288 else
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002289 SetCaret(m_SelState.EndPos);
2290
2291 SelectNone();
2292 ScrollToCaret();
2293 SetCaretInfo();
2294 } else {
2295 if (m_wpCaret == m_pVT->GetLineBeginPlace(m_wpCaret) &&
2296 m_wpCaret != m_pVT->GetSectionBeginPlace(m_wpCaret))
2297 SetCaret(m_pVT->GetPrevWordPlace(m_wpCaret));
2298
2299 SetCaret(m_pVT->GetPrevWordPlace(m_wpCaret));
2300
2301 ScrollToCaret();
2302 SetCaretOrigin();
2303 SetCaretInfo();
2304 }
2305 }
2306 }
2307}
2308
2309void CFX_Edit::OnVK_RIGHT(FX_BOOL bShift, FX_BOOL bCtrl) {
2310 if (m_pVT->IsValid()) {
2311 if (bShift) {
2312 SetCaret(m_pVT->GetNextWordPlace(m_wpCaret));
2313
2314 if (m_wpCaret == m_pVT->GetLineEndPlace(m_wpCaret) &&
2315 m_wpCaret != m_pVT->GetSectionEndPlace(m_wpCaret))
2316 SetCaret(m_pVT->GetNextWordPlace(m_wpCaret));
2317
2318 if (m_SelState.IsExist())
2319 m_SelState.SetEndPos(m_wpCaret);
2320 else
2321 m_SelState.Set(m_wpOldCaret, m_wpCaret);
2322
2323 if (m_wpOldCaret != m_wpCaret) {
2324 ScrollToCaret();
2325 CPVT_WordRange wr(m_wpOldCaret, m_wpCaret);
2326 Refresh(RP_OPTIONAL, &wr);
2327 SetCaretInfo();
2328 }
2329 } else {
2330 if (m_SelState.IsExist()) {
2331 if (m_SelState.BeginPos.WordCmp(m_SelState.EndPos) > 0)
2332 SetCaret(m_SelState.BeginPos);
2333 else
2334 SetCaret(m_SelState.EndPos);
2335
2336 SelectNone();
2337 ScrollToCaret();
2338 SetCaretInfo();
2339 } else {
2340 SetCaret(m_pVT->GetNextWordPlace(m_wpCaret));
2341
2342 if (m_wpCaret == m_pVT->GetLineEndPlace(m_wpCaret) &&
2343 m_wpCaret != m_pVT->GetSectionEndPlace(m_wpCaret))
2344 SetCaret(m_pVT->GetNextWordPlace(m_wpCaret));
2345
2346 ScrollToCaret();
2347 SetCaretOrigin();
2348 SetCaretInfo();
2349 }
2350 }
2351 }
2352}
2353
2354void CFX_Edit::OnVK_HOME(FX_BOOL bShift, FX_BOOL bCtrl) {
2355 if (m_pVT->IsValid()) {
2356 if (bShift) {
2357 if (bCtrl)
2358 SetCaret(m_pVT->GetBeginWordPlace());
2359 else
2360 SetCaret(m_pVT->GetLineBeginPlace(m_wpCaret));
2361
2362 if (m_SelState.IsExist())
2363 m_SelState.SetEndPos(m_wpCaret);
2364 else
2365 m_SelState.Set(m_wpOldCaret, m_wpCaret);
2366
2367 ScrollToCaret();
2368 CPVT_WordRange wr(m_wpOldCaret, m_wpCaret);
2369 Refresh(RP_OPTIONAL, &wr);
2370 SetCaretInfo();
2371 } else {
2372 if (m_SelState.IsExist()) {
2373 if (m_SelState.BeginPos.WordCmp(m_SelState.EndPos) < 0)
2374 SetCaret(m_SelState.BeginPos);
2375 else
2376 SetCaret(m_SelState.EndPos);
2377
2378 SelectNone();
2379 ScrollToCaret();
2380 SetCaretInfo();
2381 } else {
2382 if (bCtrl)
2383 SetCaret(m_pVT->GetBeginWordPlace());
2384 else
2385 SetCaret(m_pVT->GetLineBeginPlace(m_wpCaret));
2386
2387 ScrollToCaret();
2388 SetCaretOrigin();
2389 SetCaretInfo();
2390 }
2391 }
2392 }
2393}
2394
2395void CFX_Edit::OnVK_END(FX_BOOL bShift, FX_BOOL bCtrl) {
2396 if (m_pVT->IsValid()) {
2397 if (bShift) {
2398 if (bCtrl)
2399 SetCaret(m_pVT->GetEndWordPlace());
2400 else
2401 SetCaret(m_pVT->GetLineEndPlace(m_wpCaret));
2402
2403 if (m_SelState.IsExist())
2404 m_SelState.SetEndPos(m_wpCaret);
2405 else
2406 m_SelState.Set(m_wpOldCaret, m_wpCaret);
2407
2408 ScrollToCaret();
2409 CPVT_WordRange wr(m_wpOldCaret, m_wpCaret);
2410 Refresh(RP_OPTIONAL, &wr);
2411 SetCaretInfo();
2412 } else {
2413 if (m_SelState.IsExist()) {
2414 if (m_SelState.BeginPos.WordCmp(m_SelState.EndPos) > 0)
2415 SetCaret(m_SelState.BeginPos);
2416 else
2417 SetCaret(m_SelState.EndPos);
2418
2419 SelectNone();
2420 ScrollToCaret();
2421 SetCaretInfo();
2422 } else {
2423 if (bCtrl)
2424 SetCaret(m_pVT->GetEndWordPlace());
2425 else
2426 SetCaret(m_pVT->GetLineEndPlace(m_wpCaret));
2427
2428 ScrollToCaret();
2429 SetCaretOrigin();
2430 SetCaretInfo();
2431 }
2432 }
2433 }
2434}
2435
2436void CFX_Edit::SetText(const FX_WCHAR* text,
2437 int32_t charset,
2438 const CPVT_SecProps* pSecProps,
2439 const CPVT_WordProps* pWordProps,
2440 FX_BOOL bAddUndo,
2441 FX_BOOL bPaint) {
2442 Empty();
2443 DoInsertText(CPVT_WordPlace(0, 0, -1), text, charset, pSecProps, pWordProps);
2444 if (bPaint)
2445 Paint();
2446 if (m_bOprNotify && m_pOprNotify)
2447 m_pOprNotify->OnSetText(m_wpCaret, m_wpOldCaret);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002448}
2449
Tom Sepez62a70f92016-03-21 15:00:20 -07002450FX_BOOL CFX_Edit::InsertWord(uint16_t word,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002451 int32_t charset,
2452 const CPVT_WordProps* pWordProps,
2453 FX_BOOL bAddUndo,
2454 FX_BOOL bPaint) {
2455 if (IsTextOverflow())
2456 return FALSE;
2457
2458 if (m_pVT->IsValid()) {
2459 m_pVT->UpdateWordPlace(m_wpCaret);
2460
2461 SetCaret(m_pVT->InsertWord(
2462 m_wpCaret, word, GetCharSetFromUnicode(word, charset), pWordProps));
2463 m_SelState.Set(m_wpCaret, m_wpCaret);
2464
2465 if (m_wpCaret != m_wpOldCaret) {
2466 if (bAddUndo && m_bEnableUndo) {
2467 AddEditUndoItem(new CFXEU_InsertWord(this, m_wpOldCaret, m_wpCaret,
2468 word, charset, pWordProps));
2469 }
2470
2471 if (bPaint)
2472 PaintInsertText(m_wpOldCaret, m_wpCaret);
2473
2474 if (m_bOprNotify && m_pOprNotify)
2475 m_pOprNotify->OnInsertWord(m_wpCaret, m_wpOldCaret);
2476
2477 return TRUE;
2478 }
2479 }
2480
2481 return FALSE;
2482}
2483
2484FX_BOOL CFX_Edit::InsertReturn(const CPVT_SecProps* pSecProps,
2485 const CPVT_WordProps* pWordProps,
2486 FX_BOOL bAddUndo,
2487 FX_BOOL bPaint) {
2488 if (IsTextOverflow())
2489 return FALSE;
2490
2491 if (m_pVT->IsValid()) {
2492 m_pVT->UpdateWordPlace(m_wpCaret);
2493 SetCaret(m_pVT->InsertSection(m_wpCaret, pSecProps, pWordProps));
2494 m_SelState.Set(m_wpCaret, m_wpCaret);
2495
2496 if (m_wpCaret != m_wpOldCaret) {
2497 if (bAddUndo && m_bEnableUndo) {
2498 AddEditUndoItem(new CFXEU_InsertReturn(this, m_wpOldCaret, m_wpCaret,
2499 pSecProps, pWordProps));
2500 }
2501
2502 if (bPaint) {
2503 RearrangePart(CPVT_WordRange(m_wpOldCaret, m_wpCaret));
2504 ScrollToCaret();
2505 CPVT_WordRange wr(m_wpOldCaret, GetVisibleWordRange().EndPos);
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002506 Refresh(RP_ANALYSE, &wr);
2507 SetCaretOrigin();
2508 SetCaretInfo();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002509 }
2510
2511 if (m_bOprNotify && m_pOprNotify)
2512 m_pOprNotify->OnInsertReturn(m_wpCaret, m_wpOldCaret);
2513
2514 return TRUE;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002515 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002516 }
2517
2518 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002519}
2520
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002521FX_BOOL CFX_Edit::Backspace(FX_BOOL bAddUndo, FX_BOOL bPaint) {
2522 if (m_pVT->IsValid()) {
2523 if (m_wpCaret == m_pVT->GetBeginWordPlace())
2524 return FALSE;
2525
2526 CPVT_Section section;
2527 CPVT_Word word;
2528
2529 if (bAddUndo) {
thestig821d59e2016-05-11 12:59:22 -07002530 CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator();
2531 pIterator->SetAt(m_wpCaret);
2532 pIterator->GetSection(section);
2533 pIterator->GetWord(word);
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002534 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002535
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002536 m_pVT->UpdateWordPlace(m_wpCaret);
2537 SetCaret(m_pVT->BackSpaceWord(m_wpCaret));
2538 m_SelState.Set(m_wpCaret, m_wpCaret);
2539
2540 if (m_wpCaret != m_wpOldCaret) {
2541 if (bAddUndo && m_bEnableUndo) {
2542 if (m_wpCaret.SecCmp(m_wpOldCaret) != 0)
2543 AddEditUndoItem(new CFXEU_Backspace(
2544 this, m_wpOldCaret, m_wpCaret, word.Word, word.nCharset,
2545 section.SecProps, section.WordProps));
2546 else
2547 AddEditUndoItem(new CFXEU_Backspace(
2548 this, m_wpOldCaret, m_wpCaret, word.Word, word.nCharset,
2549 section.SecProps, word.WordProps));
2550 }
2551
2552 if (bPaint) {
2553 RearrangePart(CPVT_WordRange(m_wpCaret, m_wpOldCaret));
2554 ScrollToCaret();
2555
2556 CPVT_WordRange wr;
2557 if (m_wpCaret.SecCmp(m_wpOldCaret) != 0)
2558 wr = CPVT_WordRange(m_pVT->GetPrevWordPlace(m_wpCaret),
2559 GetVisibleWordRange().EndPos);
2560 else if (m_wpCaret.LineCmp(m_wpOldCaret) != 0)
2561 wr = CPVT_WordRange(m_pVT->GetLineBeginPlace(m_wpCaret),
2562 m_pVT->GetSectionEndPlace(m_wpCaret));
2563 else
2564 wr = CPVT_WordRange(m_pVT->GetPrevWordPlace(m_wpCaret),
2565 m_pVT->GetSectionEndPlace(m_wpCaret));
2566
2567 Refresh(RP_ANALYSE, &wr);
2568
2569 SetCaretOrigin();
2570 SetCaretInfo();
2571 }
2572
2573 if (m_bOprNotify && m_pOprNotify)
2574 m_pOprNotify->OnBackSpace(m_wpCaret, m_wpOldCaret);
2575
2576 return TRUE;
2577 }
2578 }
2579
2580 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002581}
2582
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002583FX_BOOL CFX_Edit::Delete(FX_BOOL bAddUndo, FX_BOOL bPaint) {
2584 if (m_pVT->IsValid()) {
2585 if (m_wpCaret == m_pVT->GetEndWordPlace())
2586 return FALSE;
2587
2588 CPVT_Section section;
2589 CPVT_Word word;
2590
2591 if (bAddUndo) {
thestig821d59e2016-05-11 12:59:22 -07002592 CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator();
2593 pIterator->SetAt(m_pVT->GetNextWordPlace(m_wpCaret));
2594 pIterator->GetSection(section);
2595 pIterator->GetWord(word);
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002596 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002597
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002598 m_pVT->UpdateWordPlace(m_wpCaret);
2599 FX_BOOL bSecEnd = (m_wpCaret == m_pVT->GetSectionEndPlace(m_wpCaret));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002600
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002601 SetCaret(m_pVT->DeleteWord(m_wpCaret));
2602 m_SelState.Set(m_wpCaret, m_wpCaret);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002603
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002604 if (bAddUndo && m_bEnableUndo) {
2605 if (bSecEnd)
2606 AddEditUndoItem(new CFXEU_Delete(
2607 this, m_wpOldCaret, m_wpCaret, word.Word, word.nCharset,
2608 section.SecProps, section.WordProps, bSecEnd));
2609 else
2610 AddEditUndoItem(new CFXEU_Delete(
2611 this, m_wpOldCaret, m_wpCaret, word.Word, word.nCharset,
2612 section.SecProps, word.WordProps, bSecEnd));
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002613 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002614
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002615 if (bPaint) {
2616 RearrangePart(CPVT_WordRange(m_wpOldCaret, m_wpCaret));
2617 ScrollToCaret();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002618
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002619 CPVT_WordRange wr;
2620 if (bSecEnd)
2621 wr = CPVT_WordRange(m_pVT->GetPrevWordPlace(m_wpOldCaret),
2622 GetVisibleWordRange().EndPos);
2623 else if (m_wpCaret.LineCmp(m_wpOldCaret) != 0)
2624 wr = CPVT_WordRange(m_pVT->GetLineBeginPlace(m_wpCaret),
2625 m_pVT->GetSectionEndPlace(m_wpCaret));
2626 else
2627 wr = CPVT_WordRange(m_pVT->GetPrevWordPlace(m_wpOldCaret),
2628 m_pVT->GetSectionEndPlace(m_wpCaret));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002629
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002630 Refresh(RP_ANALYSE, &wr);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002631
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002632 SetCaretOrigin();
2633 SetCaretInfo();
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002634 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002635
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002636 if (m_bOprNotify && m_pOprNotify)
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002637 m_pOprNotify->OnDelete(m_wpCaret, m_wpOldCaret);
2638
2639 return TRUE;
2640 }
2641
2642 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002643}
2644
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002645FX_BOOL CFX_Edit::Empty() {
2646 if (m_pVT->IsValid()) {
2647 m_pVT->DeleteWords(GetWholeWordRange());
2648 SetCaret(m_pVT->GetBeginWordPlace());
2649
2650 return TRUE;
2651 }
2652
2653 return FALSE;
2654}
2655
2656FX_BOOL CFX_Edit::Clear(FX_BOOL bAddUndo, FX_BOOL bPaint) {
thestig821d59e2016-05-11 12:59:22 -07002657 if (!m_pVT->IsValid())
2658 return FALSE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002659
thestig821d59e2016-05-11 12:59:22 -07002660 if (!m_SelState.IsExist())
2661 return FALSE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002662
thestig821d59e2016-05-11 12:59:22 -07002663 CPVT_WordRange range = m_SelState.ConvertToWordRange();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002664
thestig821d59e2016-05-11 12:59:22 -07002665 if (bAddUndo && m_bEnableUndo) {
2666 if (m_pVT->IsRichText()) {
2667 BeginGroupUndo(L"");
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002668
thestig821d59e2016-05-11 12:59:22 -07002669 CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator();
2670 pIterator->SetAt(range.EndPos);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002671
thestig821d59e2016-05-11 12:59:22 -07002672 CPVT_Word wordinfo;
2673 CPVT_Section secinfo;
2674 do {
2675 CPVT_WordPlace place = pIterator->GetAt();
2676 if (place.WordCmp(range.BeginPos) <= 0)
2677 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002678
thestig821d59e2016-05-11 12:59:22 -07002679 CPVT_WordPlace oldplace = m_pVT->GetPrevWordPlace(place);
2680
2681 if (oldplace.SecCmp(place) != 0) {
2682 if (pIterator->GetSection(secinfo)) {
2683 AddEditUndoItem(new CFXEU_ClearRich(
2684 this, oldplace, place, range, wordinfo.Word, wordinfo.nCharset,
2685 secinfo.SecProps, secinfo.WordProps));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002686 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002687 } else {
thestig821d59e2016-05-11 12:59:22 -07002688 if (pIterator->GetWord(wordinfo)) {
2689 oldplace = m_pVT->AdjustLineHeader(oldplace, TRUE);
2690 place = m_pVT->AdjustLineHeader(place, TRUE);
2691
2692 AddEditUndoItem(new CFXEU_ClearRich(
2693 this, oldplace, place, range, wordinfo.Word, wordinfo.nCharset,
2694 secinfo.SecProps, wordinfo.WordProps));
2695 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002696 }
thestig821d59e2016-05-11 12:59:22 -07002697 } while (pIterator->PrevWord());
2698 EndGroupUndo();
2699 } else {
2700 AddEditUndoItem(new CFXEU_Clear(this, range, GetSelText()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002701 }
2702 }
2703
thestig821d59e2016-05-11 12:59:22 -07002704 SelectNone();
2705 SetCaret(m_pVT->DeleteWords(range));
2706 m_SelState.Set(m_wpCaret, m_wpCaret);
2707
2708 if (bPaint) {
2709 RearrangePart(range);
2710 ScrollToCaret();
2711
2712 CPVT_WordRange wr(m_wpOldCaret, GetVisibleWordRange().EndPos);
2713 Refresh(RP_ANALYSE, &wr);
2714
2715 SetCaretOrigin();
2716 SetCaretInfo();
2717 }
2718
2719 if (m_bOprNotify && m_pOprNotify)
2720 m_pOprNotify->OnClear(m_wpCaret, m_wpOldCaret);
2721
2722 return TRUE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002723}
2724
2725FX_BOOL CFX_Edit::InsertText(const FX_WCHAR* text,
2726 int32_t charset,
2727 const CPVT_SecProps* pSecProps,
2728 const CPVT_WordProps* pWordProps,
2729 FX_BOOL bAddUndo,
2730 FX_BOOL bPaint) {
2731 if (IsTextOverflow())
2732 return FALSE;
2733
2734 m_pVT->UpdateWordPlace(m_wpCaret);
2735 SetCaret(DoInsertText(m_wpCaret, text, charset, pSecProps, pWordProps));
2736 m_SelState.Set(m_wpCaret, m_wpCaret);
2737
2738 if (m_wpCaret != m_wpOldCaret) {
2739 if (bAddUndo && m_bEnableUndo) {
2740 AddEditUndoItem(new CFXEU_InsertText(this, m_wpOldCaret, m_wpCaret, text,
2741 charset, pSecProps, pWordProps));
2742 }
2743
2744 if (bPaint)
2745 PaintInsertText(m_wpOldCaret, m_wpCaret);
2746
2747 if (m_bOprNotify && m_pOprNotify)
2748 m_pOprNotify->OnInsertText(m_wpCaret, m_wpOldCaret);
2749
2750 return TRUE;
2751 }
2752 return FALSE;
2753}
2754
2755void CFX_Edit::PaintInsertText(const CPVT_WordPlace& wpOld,
2756 const CPVT_WordPlace& wpNew) {
2757 if (m_pVT->IsValid()) {
2758 RearrangePart(CPVT_WordRange(wpOld, wpNew));
2759 ScrollToCaret();
2760
2761 CPVT_WordRange wr;
2762 if (m_wpCaret.LineCmp(wpOld) != 0)
2763 wr = CPVT_WordRange(m_pVT->GetLineBeginPlace(wpOld),
2764 m_pVT->GetSectionEndPlace(wpNew));
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002765 else
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002766 wr = CPVT_WordRange(wpOld, m_pVT->GetSectionEndPlace(wpNew));
2767 Refresh(RP_ANALYSE, &wr);
2768 SetCaretOrigin();
2769 SetCaretInfo();
2770 }
2771}
2772
2773FX_BOOL CFX_Edit::Redo() {
2774 if (m_bEnableUndo) {
2775 if (m_Undo.CanRedo()) {
2776 m_Undo.Redo();
2777 return TRUE;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002778 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002779 }
2780
2781 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002782}
2783
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002784FX_BOOL CFX_Edit::Undo() {
2785 if (m_bEnableUndo) {
2786 if (m_Undo.CanUndo()) {
2787 m_Undo.Undo();
2788 return TRUE;
2789 }
2790 }
2791
2792 return FALSE;
2793}
2794
2795void CFX_Edit::SetCaretOrigin() {
thestig821d59e2016-05-11 12:59:22 -07002796 if (!m_pVT->IsValid())
2797 return;
2798
2799 CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator();
2800 pIterator->SetAt(m_wpCaret);
2801 CPVT_Word word;
2802 CPVT_Line line;
2803 if (pIterator->GetWord(word)) {
2804 m_ptCaret.x = word.ptWord.x + word.fWidth;
2805 m_ptCaret.y = word.ptWord.y;
2806 } else if (pIterator->GetLine(line)) {
2807 m_ptCaret.x = line.ptLine.x;
2808 m_ptCaret.y = line.ptLine.y;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002809 }
2810}
2811
2812int32_t CFX_Edit::WordPlaceToWordIndex(const CPVT_WordPlace& place) const {
2813 if (m_pVT->IsValid())
2814 return m_pVT->WordPlaceToWordIndex(place);
2815
2816 return -1;
2817}
2818
2819CPVT_WordPlace CFX_Edit::WordIndexToWordPlace(int32_t index) const {
2820 if (m_pVT->IsValid())
2821 return m_pVT->WordIndexToWordPlace(index);
2822
2823 return CPVT_WordPlace();
2824}
2825
2826FX_BOOL CFX_Edit::IsTextFull() const {
2827 int32_t nTotalWords = m_pVT->GetTotalWords();
2828 int32_t nLimitChar = m_pVT->GetLimitChar();
2829 int32_t nCharArray = m_pVT->GetCharArray();
2830
2831 return IsTextOverflow() || (nLimitChar > 0 && nTotalWords >= nLimitChar) ||
2832 (nCharArray > 0 && nTotalWords >= nCharArray);
2833}
2834
2835FX_BOOL CFX_Edit::IsTextOverflow() const {
2836 if (!m_bEnableScroll && !m_bEnableOverflow) {
Tom Sepez281a9ea2016-02-26 14:24:28 -08002837 CFX_FloatRect rcPlate = m_pVT->GetPlateRect();
2838 CFX_FloatRect rcContent = m_pVT->GetContentRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002839
2840 if (m_pVT->IsMultiLine() && GetTotalLines() > 1) {
2841 if (FX_EDIT_IsFloatBigger(rcContent.Height(), rcPlate.Height()))
2842 return TRUE;
2843 }
2844
2845 if (FX_EDIT_IsFloatBigger(rcContent.Width(), rcPlate.Width()))
2846 return TRUE;
2847 }
2848
2849 return FALSE;
2850}
2851
2852CPVT_WordPlace CFX_Edit::GetLineBeginPlace(const CPVT_WordPlace& place) const {
2853 return m_pVT->GetLineBeginPlace(place);
2854}
2855
2856CPVT_WordPlace CFX_Edit::GetLineEndPlace(const CPVT_WordPlace& place) const {
2857 return m_pVT->GetLineEndPlace(place);
2858}
2859
2860CPVT_WordPlace CFX_Edit::GetSectionBeginPlace(
2861 const CPVT_WordPlace& place) const {
2862 return m_pVT->GetSectionBeginPlace(place);
2863}
2864
2865CPVT_WordPlace CFX_Edit::GetSectionEndPlace(const CPVT_WordPlace& place) const {
2866 return m_pVT->GetSectionEndPlace(place);
2867}
2868
2869FX_BOOL CFX_Edit::CanUndo() const {
2870 if (m_bEnableUndo) {
2871 return m_Undo.CanUndo();
2872 }
2873
2874 return FALSE;
2875}
2876
2877FX_BOOL CFX_Edit::CanRedo() const {
2878 if (m_bEnableUndo) {
2879 return m_Undo.CanRedo();
2880 }
2881
2882 return FALSE;
2883}
2884
2885FX_BOOL CFX_Edit::IsModified() const {
2886 if (m_bEnableUndo) {
2887 return m_Undo.IsModified();
2888 }
2889
2890 return FALSE;
2891}
2892
2893void CFX_Edit::EnableRefresh(FX_BOOL bRefresh) {
2894 m_bEnableRefresh = bRefresh;
2895}
2896
2897void CFX_Edit::EnableUndo(FX_BOOL bUndo) {
2898 m_bEnableUndo = bUndo;
2899}
2900
2901void CFX_Edit::EnableNotify(FX_BOOL bNotify) {
2902 m_bNotify = bNotify;
2903}
2904
2905void CFX_Edit::EnableOprNotify(FX_BOOL bNotify) {
2906 m_bOprNotify = bNotify;
2907}
2908
2909FX_FLOAT CFX_Edit::GetLineTop(const CPVT_WordPlace& place) const {
thestig821d59e2016-05-11 12:59:22 -07002910 CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator();
2911 CPVT_WordPlace wpOld = pIterator->GetAt();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002912
thestig821d59e2016-05-11 12:59:22 -07002913 pIterator->SetAt(place);
2914 CPVT_Line line;
2915 pIterator->GetLine(line);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002916
thestig821d59e2016-05-11 12:59:22 -07002917 pIterator->SetAt(wpOld);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002918
thestig821d59e2016-05-11 12:59:22 -07002919 return line.ptLine.y + line.fLineAscent;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002920}
2921
2922FX_FLOAT CFX_Edit::GetLineBottom(const CPVT_WordPlace& place) const {
thestig821d59e2016-05-11 12:59:22 -07002923 CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator();
2924 CPVT_WordPlace wpOld = pIterator->GetAt();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002925
thestig821d59e2016-05-11 12:59:22 -07002926 pIterator->SetAt(place);
2927 CPVT_Line line;
2928 pIterator->GetLine(line);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002929
thestig821d59e2016-05-11 12:59:22 -07002930 pIterator->SetAt(wpOld);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002931
thestig821d59e2016-05-11 12:59:22 -07002932 return line.ptLine.y + line.fLineDescent;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002933}
2934
2935CPVT_WordPlace CFX_Edit::DoInsertText(const CPVT_WordPlace& place,
2936 const FX_WCHAR* text,
2937 int32_t charset,
2938 const CPVT_SecProps* pSecProps,
2939 const CPVT_WordProps* pWordProps) {
2940 CPVT_WordPlace wp = place;
2941
2942 if (m_pVT->IsValid()) {
2943 CFX_WideString sText = text;
2944
2945 for (int32_t i = 0, sz = sText.GetLength(); i < sz; i++) {
Tom Sepez62a70f92016-03-21 15:00:20 -07002946 uint16_t word = sText[i];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002947 switch (word) {
2948 case 0x0D:
2949 wp = m_pVT->InsertSection(wp, pSecProps, pWordProps);
2950 if (sText[i + 1] == 0x0A)
2951 i++;
2952 break;
2953 case 0x0A:
2954 wp = m_pVT->InsertSection(wp, pSecProps, pWordProps);
2955 if (sText[i + 1] == 0x0D)
2956 i++;
2957 break;
2958 case 0x09:
2959 word = 0x20;
2960 default:
2961 wp = m_pVT->InsertWord(wp, word, GetCharSetFromUnicode(word, charset),
2962 pWordProps);
2963 break;
2964 }
2965 }
2966 }
2967
2968 return wp;
2969}
2970
Tom Sepez62a70f92016-03-21 15:00:20 -07002971int32_t CFX_Edit::GetCharSetFromUnicode(uint16_t word, int32_t nOldCharset) {
dsinclairc7a73492016-04-05 12:01:42 -07002972 if (IPVT_FontMap* pFontMap = GetFontMap())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002973 return pFontMap->CharSetFromUnicode(word, nOldCharset);
2974 return nOldCharset;
2975}
2976
2977void CFX_Edit::BeginGroupUndo(const CFX_WideString& sTitle) {
Lei Zhang412e9082015-12-14 18:34:00 -08002978 ASSERT(!m_pGroupUndoItem);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002979
2980 m_pGroupUndoItem = new CFX_Edit_GroupUndoItem(sTitle);
2981}
2982
2983void CFX_Edit::EndGroupUndo() {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002984 m_pGroupUndoItem->UpdateItems();
2985 m_Undo.AddItem(m_pGroupUndoItem);
2986 if (m_bOprNotify && m_pOprNotify)
2987 m_pOprNotify->OnAddUndo(m_pGroupUndoItem);
thestig1cd352e2016-06-07 17:53:06 -07002988 m_pGroupUndoItem = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002989}
2990
2991void CFX_Edit::AddEditUndoItem(CFX_Edit_UndoItem* pEditUndoItem) {
Lei Zhangc2fb35f2016-01-05 16:46:58 -08002992 if (m_pGroupUndoItem) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002993 m_pGroupUndoItem->AddUndoItem(pEditUndoItem);
Lei Zhangc2fb35f2016-01-05 16:46:58 -08002994 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002995 m_Undo.AddItem(pEditUndoItem);
Tom Sepez2f2ffec2015-07-23 14:42:09 -07002996 if (m_bOprNotify && m_pOprNotify)
Nico Weber9d8ec5a2015-08-04 13:00:21 -07002997 m_pOprNotify->OnAddUndo(pEditUndoItem);
2998 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002999}
3000
Nico Weber9d8ec5a2015-08-04 13:00:21 -07003001void CFX_Edit::AddUndoItem(IFX_Edit_UndoItem* pUndoItem) {
3002 m_Undo.AddItem(pUndoItem);
3003 if (m_bOprNotify && m_pOprNotify)
3004 m_pOprNotify->OnAddUndo(pUndoItem);
3005}
weili625ad662016-06-15 11:21:33 -07003006
3007CFX_Edit_LineRectArray::CFX_Edit_LineRectArray() {}
3008
3009CFX_Edit_LineRectArray::~CFX_Edit_LineRectArray() {
3010 Empty();
3011}
3012
3013void CFX_Edit_LineRectArray::Empty() {
3014 for (int32_t i = 0, sz = m_LineRects.GetSize(); i < sz; i++)
3015 delete m_LineRects.GetAt(i);
3016
3017 m_LineRects.RemoveAll();
3018}
3019
3020void CFX_Edit_LineRectArray::RemoveAll() {
3021 m_LineRects.RemoveAll();
3022}
3023
3024void CFX_Edit_LineRectArray::operator=(CFX_Edit_LineRectArray& rects) {
3025 Empty();
3026 for (int32_t i = 0, sz = rects.GetSize(); i < sz; i++)
3027 m_LineRects.Add(rects.GetAt(i));
3028
3029 rects.RemoveAll();
3030}
3031
3032void CFX_Edit_LineRectArray::Add(const CPVT_WordRange& wrLine,
3033 const CFX_FloatRect& rcLine) {
3034 m_LineRects.Add(new CFX_Edit_LineRect(wrLine, rcLine));
3035}
3036
3037int32_t CFX_Edit_LineRectArray::GetSize() const {
3038 return m_LineRects.GetSize();
3039}
3040
3041CFX_Edit_LineRect* CFX_Edit_LineRectArray::GetAt(int32_t nIndex) const {
3042 if (nIndex < 0 || nIndex >= m_LineRects.GetSize())
3043 return nullptr;
3044
3045 return m_LineRects.GetAt(nIndex);
3046}
3047
3048CFX_Edit_Select::CFX_Edit_Select() {}
3049
3050CFX_Edit_Select::CFX_Edit_Select(const CPVT_WordPlace& begin,
3051 const CPVT_WordPlace& end) {
3052 Set(begin, end);
3053}
3054
3055CFX_Edit_Select::CFX_Edit_Select(const CPVT_WordRange& range) {
3056 Set(range.BeginPos, range.EndPos);
3057}
3058
3059CPVT_WordRange CFX_Edit_Select::ConvertToWordRange() const {
3060 return CPVT_WordRange(BeginPos, EndPos);
3061}
3062
3063void CFX_Edit_Select::Default() {
3064 BeginPos.Default();
3065 EndPos.Default();
3066}
3067
3068void CFX_Edit_Select::Set(const CPVT_WordPlace& begin,
3069 const CPVT_WordPlace& end) {
3070 BeginPos = begin;
3071 EndPos = end;
3072}
3073
3074void CFX_Edit_Select::SetBeginPos(const CPVT_WordPlace& begin) {
3075 BeginPos = begin;
3076}
3077
3078void CFX_Edit_Select::SetEndPos(const CPVT_WordPlace& end) {
3079 EndPos = end;
3080}
3081
3082FX_BOOL CFX_Edit_Select::IsExist() const {
3083 return BeginPos != EndPos;
3084}
3085
3086FX_BOOL CFX_Edit_Select::operator!=(const CPVT_WordRange& wr) const {
3087 return wr.BeginPos != BeginPos || wr.EndPos != EndPos;
3088}
3089
3090CFX_Edit_RectArray::CFX_Edit_RectArray() {}
3091
3092CFX_Edit_RectArray::~CFX_Edit_RectArray() {
3093 Empty();
3094}
3095
3096void CFX_Edit_RectArray::Empty() {
3097 for (int32_t i = 0, sz = m_Rects.GetSize(); i < sz; i++)
3098 delete m_Rects.GetAt(i);
3099
3100 m_Rects.RemoveAll();
3101}
3102
3103void CFX_Edit_RectArray::Add(const CFX_FloatRect& rect) {
3104 // check for overlapped area
3105 for (int32_t i = 0, sz = m_Rects.GetSize(); i < sz; i++) {
3106 CFX_FloatRect* pRect = m_Rects.GetAt(i);
3107 if (pRect && pRect->Contains(rect))
3108 return;
3109 }
3110
3111 m_Rects.Add(new CFX_FloatRect(rect));
3112}
3113
3114int32_t CFX_Edit_RectArray::GetSize() const {
3115 return m_Rects.GetSize();
3116}
3117
3118CFX_FloatRect* CFX_Edit_RectArray::GetAt(int32_t nIndex) const {
3119 if (nIndex < 0 || nIndex >= m_Rects.GetSize())
3120 return nullptr;
3121
3122 return m_Rects.GetAt(nIndex);
3123}