blob: 0b3887b4136525ce506753a74e8e049e6d1e8604 [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
Lei Zhangc2fb35f2016-01-05 16:46:58 -08007#include "fpdfsdk/include/pdfwindow/PWL_Edit.h"
8
Lei Zhanga688a042015-11-09 13:57:49 -08009#include "core/include/fxcrt/fx_safe_types.h"
10#include "core/include/fxcrt/fx_xml.h"
Lei Zhangbde53d22015-11-12 22:21:30 -080011#include "fpdfsdk/include/pdfwindow/PWL_Caret.h"
Lei Zhangbde53d22015-11-12 22:21:30 -080012#include "fpdfsdk/include/pdfwindow/PWL_EditCtrl.h"
13#include "fpdfsdk/include/pdfwindow/PWL_FontMap.h"
14#include "fpdfsdk/include/pdfwindow/PWL_ScrollBar.h"
15#include "fpdfsdk/include/pdfwindow/PWL_Utils.h"
16#include "fpdfsdk/include/pdfwindow/PWL_Wnd.h"
Lei Zhangc2fb35f2016-01-05 16:46:58 -080017#include "public/fpdf_fwlevent.h"
Tom Sepezab277682016-02-17 10:07:21 -080018#include "third_party/base/stl_util.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070019
Nico Weber9d8ec5a2015-08-04 13:00:21 -070020CPWL_Edit::CPWL_Edit()
21 : m_pFillerNotify(NULL), m_pSpellCheck(NULL), m_bFocus(FALSE) {
22 m_pFormFiller = NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070023}
24
Nico Weber9d8ec5a2015-08-04 13:00:21 -070025CPWL_Edit::~CPWL_Edit() {
26 ASSERT(m_bFocus == FALSE);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070027}
28
Nico Weber9d8ec5a2015-08-04 13:00:21 -070029CFX_ByteString CPWL_Edit::GetClassName() const {
30 return PWL_CLASSNAME_EDIT;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070031}
32
Nico Weber9d8ec5a2015-08-04 13:00:21 -070033void CPWL_Edit::OnDestroy() {}
34
35void CPWL_Edit::SetText(const FX_WCHAR* csText) {
36 CFX_WideString swText = csText;
37
38 if (HasFlag(PES_RICH)) {
39 CFX_ByteString sValue = CFX_ByteString::FromUnicode(swText);
40
41 if (CXML_Element* pXML =
42 CXML_Element::Parse(sValue.c_str(), sValue.GetLength())) {
43 int32_t nCount = pXML->CountChildren();
44 FX_BOOL bFirst = TRUE;
45
46 swText.Empty();
47
48 for (int32_t i = 0; i < nCount; i++) {
49 if (CXML_Element* pSubElement = pXML->GetElement(i)) {
50 CFX_ByteString tag = pSubElement->GetTagName();
51 if (tag.EqualNoCase("p")) {
52 int nChild = pSubElement->CountChildren();
53 CFX_WideString swSection;
54 for (int32_t j = 0; j < nChild; j++) {
55 swSection += pSubElement->GetContent(j);
56 }
57
58 if (bFirst)
59 bFirst = FALSE;
60 else
61 swText += FWL_VKEY_Return;
62 swText += swSection;
63 }
64 }
65 }
66
67 delete pXML;
68 }
69 }
70
71 m_pEdit->SetText(swText.c_str());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070072}
73
Nico Weber9d8ec5a2015-08-04 13:00:21 -070074void CPWL_Edit::RePosChildWnd() {
75 if (CPWL_ScrollBar* pVSB = GetVScrollBar()) {
Tom Sepez281a9ea2016-02-26 14:24:28 -080076 CFX_FloatRect rcWindow = m_rcOldWindow;
77 CFX_FloatRect rcVScroll =
78 CFX_FloatRect(rcWindow.right, rcWindow.bottom,
79 rcWindow.right + PWL_SCROLLBAR_WIDTH, rcWindow.top);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070080 pVSB->Move(rcVScroll, TRUE, FALSE);
81 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070082
Nico Weber9d8ec5a2015-08-04 13:00:21 -070083 if (m_pEditCaret && !HasFlag(PES_TEXTOVERFLOW))
84 m_pEditCaret->SetClipRect(CPWL_Utils::InflateRect(
Dan Sinclair50cce602016-02-24 09:51:16 -050085 GetClientRect(), 1.0f)); // +1 for caret beside border
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070086
Nico Weber9d8ec5a2015-08-04 13:00:21 -070087 CPWL_EditCtrl::RePosChildWnd();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070088}
89
Tom Sepez281a9ea2016-02-26 14:24:28 -080090CFX_FloatRect CPWL_Edit::GetClientRect() const {
91 CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(
Nico Weber9d8ec5a2015-08-04 13:00:21 -070092 GetWindowRect(), (FX_FLOAT)(GetBorderWidth() + GetInnerBorderWidth()));
93
94 if (CPWL_ScrollBar* pVSB = GetVScrollBar()) {
95 if (pVSB->IsVisible()) {
96 rcClient.right -= PWL_SCROLLBAR_WIDTH;
97 }
98 }
99
100 return rcClient;
101}
102
103void CPWL_Edit::SetAlignFormatH(PWL_EDIT_ALIGNFORMAT_H nFormat,
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800104 FX_BOOL bPaint) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700105 m_pEdit->SetAlignmentH((int32_t)nFormat, bPaint);
106}
107
108void CPWL_Edit::SetAlignFormatV(PWL_EDIT_ALIGNFORMAT_V nFormat,
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800109 FX_BOOL bPaint) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700110 m_pEdit->SetAlignmentV((int32_t)nFormat, bPaint);
111}
112
113FX_BOOL CPWL_Edit::CanSelectAll() const {
114 return GetSelectWordRange() != m_pEdit->GetWholeWordRange();
115}
116
117FX_BOOL CPWL_Edit::CanClear() const {
118 return !IsReadOnly() && m_pEdit->IsSelected();
119}
120
121FX_BOOL CPWL_Edit::CanCopy() const {
122 return !HasFlag(PES_PASSWORD) && !HasFlag(PES_NOREAD) &&
123 m_pEdit->IsSelected();
124}
125
126FX_BOOL CPWL_Edit::CanCut() const {
127 return CanCopy() && !IsReadOnly();
128}
129
130FX_BOOL CPWL_Edit::CanPaste() const {
131 if (IsReadOnly())
132 return FALSE;
133
134 CFX_WideString swClipboard;
135 if (IFX_SystemHandler* pSH = GetSystemHandler())
136 swClipboard = pSH->GetClipboardText(GetAttachedHWnd());
137
138 return !swClipboard.IsEmpty();
139}
140
141void CPWL_Edit::CopyText() {
142 if (!CanCopy())
143 return;
144
145 CFX_WideString str = m_pEdit->GetSelText();
146
147 if (IFX_SystemHandler* pSH = GetSystemHandler())
148 pSH->SetClipboardText(GetAttachedHWnd(), str);
149}
150
151void CPWL_Edit::PasteText() {
152 if (!CanPaste())
153 return;
154
155 CFX_WideString swClipboard;
156 if (IFX_SystemHandler* pSH = GetSystemHandler())
157 swClipboard = pSH->GetClipboardText(GetAttachedHWnd());
158
159 if (m_pFillerNotify) {
160 FX_BOOL bRC = TRUE;
161 FX_BOOL bExit = FALSE;
162 CFX_WideString strChangeEx;
163 int nSelStart = 0;
164 int nSelEnd = 0;
165 GetSel(nSelStart, nSelEnd);
Lei Zhanga5b47042015-10-19 14:32:16 -0700166 m_pFillerNotify->OnBeforeKeyStroke(GetAttachedData(), swClipboard,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700167 strChangeEx, nSelStart, nSelEnd, TRUE,
168 bRC, bExit, 0);
169 if (!bRC)
170 return;
171 if (bExit)
172 return;
173 }
174
175 if (swClipboard.GetLength() > 0) {
176 Clear();
177 InsertText(swClipboard.c_str());
178 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700179}
180
181void CPWL_Edit::CutText() {
182 if (!CanCut())
183 return;
184
185 CFX_WideString str = m_pEdit->GetSelText();
186
187 if (IFX_SystemHandler* pSH = GetSystemHandler())
188 pSH->SetClipboardText(GetAttachedHWnd(), str);
189
190 m_pEdit->Clear();
191}
192
193void CPWL_Edit::OnCreated() {
194 CPWL_EditCtrl::OnCreated();
195
196 if (CPWL_ScrollBar* pScroll = GetVScrollBar()) {
197 pScroll->RemoveFlag(PWS_AUTOTRANSPARENT);
198 pScroll->SetTransparency(255);
199 }
200
201 SetParamByFlag();
202
203 m_rcOldWindow = GetWindowRect();
204
205 m_pEdit->SetOprNotify(this);
206 m_pEdit->EnableOprNotify(TRUE);
207}
208
209void CPWL_Edit::SetParamByFlag() {
210 if (HasFlag(PES_RIGHT)) {
211 m_pEdit->SetAlignmentH(2, FALSE);
212 } else if (HasFlag(PES_MIDDLE)) {
213 m_pEdit->SetAlignmentH(1, FALSE);
214 } else {
215 m_pEdit->SetAlignmentH(0, FALSE);
216 }
217
218 if (HasFlag(PES_BOTTOM)) {
219 m_pEdit->SetAlignmentV(2, FALSE);
220 } else if (HasFlag(PES_CENTER)) {
221 m_pEdit->SetAlignmentV(1, FALSE);
222 } else {
223 m_pEdit->SetAlignmentV(0, FALSE);
224 }
225
226 if (HasFlag(PES_PASSWORD)) {
227 m_pEdit->SetPasswordChar('*', FALSE);
228 }
229
230 m_pEdit->SetMultiLine(HasFlag(PES_MULTILINE), FALSE);
231 m_pEdit->SetAutoReturn(HasFlag(PES_AUTORETURN), FALSE);
232 m_pEdit->SetAutoFontSize(HasFlag(PWS_AUTOFONTSIZE), FALSE);
233 m_pEdit->SetAutoScroll(HasFlag(PES_AUTOSCROLL), FALSE);
234 m_pEdit->EnableUndo(HasFlag(PES_UNDO));
235
236 if (HasFlag(PES_TEXTOVERFLOW)) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800237 SetClipRect(CFX_FloatRect(0.0f, 0.0f, 0.0f, 0.0f));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700238 m_pEdit->SetTextOverflow(TRUE, FALSE);
239 } else {
240 if (m_pEditCaret) {
241 m_pEditCaret->SetClipRect(CPWL_Utils::InflateRect(
Dan Sinclair50cce602016-02-24 09:51:16 -0500242 GetClientRect(), 1.0f)); // +1 for caret beside border
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700243 }
244 }
245
246 if (HasFlag(PES_SPELLCHECK)) {
247 m_pSpellCheck = GetCreationParam().pSpellCheck;
248 }
249}
250
251void CPWL_Edit::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) {
252 CPWL_Wnd::GetThisAppearanceStream(sAppStream);
253
Tom Sepez281a9ea2016-02-26 14:24:28 -0800254 CFX_FloatRect rcClient = GetClientRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700255 CFX_ByteTextBuf sLine;
256
257 int32_t nCharArray = m_pEdit->GetCharArray();
258
259 if (nCharArray > 0) {
260 switch (GetBorderStyle()) {
261 case PBS_SOLID: {
262 sLine << "q\n" << GetBorderWidth() << " w\n"
263 << CPWL_Utils::GetColorAppStream(GetBorderColor(), FALSE)
264 << " 2 J 0 j\n";
265
266 for (int32_t i = 1; i < nCharArray; i++) {
267 sLine << rcClient.left +
268 ((rcClient.right - rcClient.left) / nCharArray) * i
269 << " " << rcClient.bottom << " m\n"
270 << rcClient.left +
271 ((rcClient.right - rcClient.left) / nCharArray) * i
272 << " " << rcClient.top << " l S\n";
273 }
274
275 sLine << "Q\n";
276 } break;
277 case PBS_DASH: {
278 sLine << "q\n" << GetBorderWidth() << " w\n"
279 << CPWL_Utils::GetColorAppStream(GetBorderColor(), FALSE)
280 << " 2 J 0 j\n"
281 << "[" << GetBorderDash().nDash << " " << GetBorderDash().nGap
282 << "] " << GetBorderDash().nPhase << " d\n";
283
284 for (int32_t i = 1; i < nCharArray; i++) {
285 sLine << rcClient.left +
286 ((rcClient.right - rcClient.left) / nCharArray) * i
287 << " " << rcClient.bottom << " m\n"
288 << rcClient.left +
289 ((rcClient.right - rcClient.left) / nCharArray) * i
290 << " " << rcClient.top << " l S\n";
291 }
292
293 sLine << "Q\n";
294 } break;
295 }
296 }
297
298 sAppStream << sLine;
299
300 CFX_ByteTextBuf sText;
301
Tom Sepez281a9ea2016-02-26 14:24:28 -0800302 CFX_FloatPoint ptOffset = CFX_FloatPoint(0.0f, 0.0f);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700303
304 CPVT_WordRange wrWhole = m_pEdit->GetWholeWordRange();
305 CPVT_WordRange wrSelect = GetSelectWordRange();
306 CPVT_WordRange wrVisible =
307 (HasFlag(PES_TEXTOVERFLOW) ? wrWhole : m_pEdit->GetVisibleWordRange());
308 CPVT_WordRange wrSelBefore(wrWhole.BeginPos, wrSelect.BeginPos);
309 CPVT_WordRange wrSelAfter(wrSelect.EndPos, wrWhole.EndPos);
310
311 CPVT_WordRange wrTemp =
312 CPWL_Utils::OverlapWordRange(GetSelectWordRange(), wrVisible);
313 CFX_ByteString sEditSel =
314 CPWL_Utils::GetEditSelAppStream(m_pEdit, ptOffset, &wrTemp);
315
316 if (sEditSel.GetLength() > 0)
317 sText << CPWL_Utils::GetColorAppStream(PWL_DEFAULT_SELBACKCOLOR)
318 << sEditSel;
319
320 wrTemp = CPWL_Utils::OverlapWordRange(wrVisible, wrSelBefore);
321 CFX_ByteString sEditBefore = CPWL_Utils::GetEditAppStream(
322 m_pEdit, ptOffset, &wrTemp, !HasFlag(PES_CHARARRAY),
323 m_pEdit->GetPasswordChar());
324
325 if (sEditBefore.GetLength() > 0)
326 sText << "BT\n" << CPWL_Utils::GetColorAppStream(GetTextColor())
327 << sEditBefore << "ET\n";
328
329 wrTemp = CPWL_Utils::OverlapWordRange(wrVisible, wrSelect);
330 CFX_ByteString sEditMid = CPWL_Utils::GetEditAppStream(
331 m_pEdit, ptOffset, &wrTemp, !HasFlag(PES_CHARARRAY),
332 m_pEdit->GetPasswordChar());
333
334 if (sEditMid.GetLength() > 0)
335 sText << "BT\n"
336 << CPWL_Utils::GetColorAppStream(CPWL_Color(COLORTYPE_GRAY, 1))
337 << sEditMid << "ET\n";
338
339 wrTemp = CPWL_Utils::OverlapWordRange(wrVisible, wrSelAfter);
340 CFX_ByteString sEditAfter = CPWL_Utils::GetEditAppStream(
341 m_pEdit, ptOffset, &wrTemp, !HasFlag(PES_CHARARRAY),
342 m_pEdit->GetPasswordChar());
343
344 if (sEditAfter.GetLength() > 0)
345 sText << "BT\n" << CPWL_Utils::GetColorAppStream(GetTextColor())
346 << sEditAfter << "ET\n";
347
348 if (HasFlag(PES_SPELLCHECK)) {
349 CFX_ByteString sSpellCheck = CPWL_Utils::GetSpellCheckAppStream(
350 m_pEdit, m_pSpellCheck, ptOffset, &wrVisible);
351 if (sSpellCheck.GetLength() > 0)
352 sText << CPWL_Utils::GetColorAppStream(CPWL_Color(COLORTYPE_RGB, 1, 0, 0),
353 FALSE)
354 << sSpellCheck;
355 }
356
357 if (sText.GetLength() > 0) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800358 CFX_FloatRect rcClient = GetClientRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700359 sAppStream << "q\n/Tx BMC\n";
360
361 if (!HasFlag(PES_TEXTOVERFLOW))
362 sAppStream << rcClient.left << " " << rcClient.bottom << " "
363 << rcClient.right - rcClient.left << " "
364 << rcClient.top - rcClient.bottom << " re W n\n";
365
366 sAppStream << sText;
367
368 sAppStream << "EMC\nQ\n";
369 }
370}
371
372void CPWL_Edit::DrawThisAppearance(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800373 CFX_Matrix* pUser2Device) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700374 CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device);
375
Tom Sepez281a9ea2016-02-26 14:24:28 -0800376 CFX_FloatRect rcClient = GetClientRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700377 CFX_ByteTextBuf sLine;
378
379 int32_t nCharArray = m_pEdit->GetCharArray();
380 FX_SAFE_INT32 nCharArraySafe = nCharArray;
381 nCharArraySafe -= 1;
382 nCharArraySafe *= 2;
383
384 if (nCharArray > 0 && nCharArraySafe.IsValid()) {
385 switch (GetBorderStyle()) {
386 case PBS_SOLID: {
387 CFX_GraphStateData gsd;
388 gsd.m_LineWidth = (FX_FLOAT)GetBorderWidth();
389
390 CFX_PathData path;
391 path.SetPointCount(nCharArraySafe.ValueOrDie());
392
393 for (int32_t i = 0; i < nCharArray - 1; i++) {
394 path.SetPoint(
395 i * 2,
396 rcClient.left +
397 ((rcClient.right - rcClient.left) / nCharArray) * (i + 1),
398 rcClient.bottom, FXPT_MOVETO);
399 path.SetPoint(
400 i * 2 + 1,
401 rcClient.left +
402 ((rcClient.right - rcClient.left) / nCharArray) * (i + 1),
403 rcClient.top, FXPT_LINETO);
404 }
405 if (path.GetPointCount() > 0)
406 pDevice->DrawPath(
407 &path, pUser2Device, &gsd, 0,
408 CPWL_Utils::PWLColorToFXColor(GetBorderColor(), 255),
409 FXFILL_ALTERNATE);
410 } break;
411 case PBS_DASH: {
412 CFX_GraphStateData gsd;
413 gsd.m_LineWidth = (FX_FLOAT)GetBorderWidth();
414
415 gsd.SetDashCount(2);
416 gsd.m_DashArray[0] = (FX_FLOAT)GetBorderDash().nDash;
417 gsd.m_DashArray[1] = (FX_FLOAT)GetBorderDash().nGap;
418 gsd.m_DashPhase = (FX_FLOAT)GetBorderDash().nPhase;
419
420 CFX_PathData path;
421 path.SetPointCount(nCharArraySafe.ValueOrDie());
422
423 for (int32_t i = 0; i < nCharArray - 1; i++) {
424 path.SetPoint(
425 i * 2,
426 rcClient.left +
427 ((rcClient.right - rcClient.left) / nCharArray) * (i + 1),
428 rcClient.bottom, FXPT_MOVETO);
429 path.SetPoint(
430 i * 2 + 1,
431 rcClient.left +
432 ((rcClient.right - rcClient.left) / nCharArray) * (i + 1),
433 rcClient.top, FXPT_LINETO);
434 }
435 if (path.GetPointCount() > 0)
436 pDevice->DrawPath(
437 &path, pUser2Device, &gsd, 0,
438 CPWL_Utils::PWLColorToFXColor(GetBorderColor(), 255),
439 FXFILL_ALTERNATE);
440 } break;
441 }
442 }
443
Tom Sepez281a9ea2016-02-26 14:24:28 -0800444 CFX_FloatRect rcClip;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700445 CPVT_WordRange wrRange = m_pEdit->GetVisibleWordRange();
446 CPVT_WordRange* pRange = NULL;
447
448 if (!HasFlag(PES_TEXTOVERFLOW)) {
449 rcClip = GetClientRect();
450 pRange = &wrRange;
451 }
452 IFX_SystemHandler* pSysHandler = GetSystemHandler();
453 IFX_Edit::DrawEdit(
454 pDevice, pUser2Device, m_pEdit,
455 CPWL_Utils::PWLColorToFXColor(GetTextColor(), GetTransparency()),
456 CPWL_Utils::PWLColorToFXColor(GetTextStrokeColor(), GetTransparency()),
Tom Sepez281a9ea2016-02-26 14:24:28 -0800457 rcClip, CFX_FloatPoint(0.0f, 0.0f), pRange, pSysHandler, m_pFormFiller);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700458
459 if (HasFlag(PES_SPELLCHECK)) {
460 CPWL_Utils::DrawEditSpellCheck(pDevice, pUser2Device, m_pEdit, rcClip,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800461 CFX_FloatPoint(0.0f, 0.0f), pRange,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700462 GetCreationParam().pSpellCheck);
463 }
464}
465
Tom Sepez281a9ea2016-02-26 14:24:28 -0800466FX_BOOL CPWL_Edit::OnLButtonDown(const CFX_FloatPoint& point, FX_DWORD nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700467 CPWL_Wnd::OnLButtonDown(point, nFlag);
468
469 if (HasFlag(PES_TEXTOVERFLOW) || ClientHitTest(point)) {
470 if (m_bMouseDown)
471 InvalidateRect();
472
473 m_bMouseDown = TRUE;
474 SetCapture();
475
476 m_pEdit->OnMouseDown(point, IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
477 }
478
479 return TRUE;
480}
481
Tom Sepez281a9ea2016-02-26 14:24:28 -0800482FX_BOOL CPWL_Edit::OnLButtonDblClk(const CFX_FloatPoint& point,
483 FX_DWORD nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700484 CPWL_Wnd::OnLButtonDblClk(point, nFlag);
485
486 if (HasFlag(PES_TEXTOVERFLOW) || ClientHitTest(point)) {
487 m_pEdit->SelectAll();
488 }
489
490 return TRUE;
491}
492
493#define WM_PWLEDIT_UNDO 0x01
494#define WM_PWLEDIT_REDO 0x02
495#define WM_PWLEDIT_CUT 0x03
496#define WM_PWLEDIT_COPY 0x04
497#define WM_PWLEDIT_PASTE 0x05
498#define WM_PWLEDIT_DELETE 0x06
499#define WM_PWLEDIT_SELECTALL 0x07
500#define WM_PWLEDIT_SUGGEST 0x08
501
Tom Sepez281a9ea2016-02-26 14:24:28 -0800502FX_BOOL CPWL_Edit::OnRButtonUp(const CFX_FloatPoint& point, FX_DWORD nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700503 if (m_bMouseDown)
504 return FALSE;
505
506 CPWL_Wnd::OnRButtonUp(point, nFlag);
507
508 if (!HasFlag(PES_TEXTOVERFLOW) && !ClientHitTest(point))
509 return TRUE;
510
511 IFX_SystemHandler* pSH = GetSystemHandler();
512 if (!pSH)
513 return FALSE;
514
515 SetFocus();
516
517 CPVT_WordRange wrLatin = GetLatinWordsRange(point);
518 CFX_WideString swLatin = m_pEdit->GetRangeText(wrLatin);
519
520 FX_HMENU hPopup = pSH->CreatePopupMenu();
521 if (!hPopup)
522 return FALSE;
523
Tom Sepezab277682016-02-17 10:07:21 -0800524 std::vector<CFX_ByteString> sSuggestWords;
Tom Sepez281a9ea2016-02-26 14:24:28 -0800525 CFX_FloatPoint ptPopup = point;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700526
527 if (!IsReadOnly()) {
528 if (HasFlag(PES_SPELLCHECK) && !swLatin.IsEmpty()) {
529 if (m_pSpellCheck) {
530 CFX_ByteString sLatin = CFX_ByteString::FromUnicode(swLatin);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700531 if (!m_pSpellCheck->CheckWord(sLatin)) {
532 m_pSpellCheck->SuggestWords(sLatin, sSuggestWords);
533
Tom Sepezab277682016-02-17 10:07:21 -0800534 int32_t nSuggest = pdfium::CollectionSize<int32_t>(sSuggestWords);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700535 for (int32_t nWord = 0; nWord < nSuggest; nWord++) {
536 pSH->AppendMenuItem(hPopup, WM_PWLEDIT_SUGGEST + nWord,
537 sSuggestWords[nWord].UTF8Decode());
538 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700539 if (nSuggest > 0)
540 pSH->AppendMenuItem(hPopup, 0, L"");
541
542 ptPopup = GetWordRightBottomPoint(wrLatin.EndPos);
543 }
544 }
545 }
546 }
547
548 IPWL_Provider* pProvider = GetProvider();
549
550 if (HasFlag(PES_UNDO)) {
551 pSH->AppendMenuItem(
552 hPopup, WM_PWLEDIT_UNDO,
553 pProvider ? pProvider->LoadPopupMenuString(0) : L"&Undo");
554 pSH->AppendMenuItem(
555 hPopup, WM_PWLEDIT_REDO,
556 pProvider ? pProvider->LoadPopupMenuString(1) : L"&Redo");
557 pSH->AppendMenuItem(hPopup, 0, L"");
558
559 if (!m_pEdit->CanUndo())
560 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_UNDO, FALSE);
561 if (!m_pEdit->CanRedo())
562 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_REDO, FALSE);
563 }
564
565 pSH->AppendMenuItem(hPopup, WM_PWLEDIT_CUT,
566 pProvider ? pProvider->LoadPopupMenuString(2) : L"Cu&t");
567 pSH->AppendMenuItem(hPopup, WM_PWLEDIT_COPY,
568 pProvider ? pProvider->LoadPopupMenuString(3) : L"&Copy");
569 pSH->AppendMenuItem(
570 hPopup, WM_PWLEDIT_PASTE,
571 pProvider ? pProvider->LoadPopupMenuString(4) : L"&Paste");
572 pSH->AppendMenuItem(
573 hPopup, WM_PWLEDIT_DELETE,
574 pProvider ? pProvider->LoadPopupMenuString(5) : L"&Delete");
575
576 CFX_WideString swText = pSH->GetClipboardText(GetAttachedHWnd());
577 if (swText.IsEmpty())
578 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_PASTE, FALSE);
579
580 if (!m_pEdit->IsSelected()) {
581 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_CUT, FALSE);
582 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_COPY, FALSE);
583 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_DELETE, FALSE);
584 }
585
586 if (IsReadOnly()) {
587 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_CUT, FALSE);
588 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_DELETE, FALSE);
589 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_PASTE, FALSE);
590 }
591
592 if (HasFlag(PES_PASSWORD)) {
593 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_CUT, FALSE);
594 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_COPY, FALSE);
595 }
596
597 if (HasFlag(PES_NOREAD)) {
598 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_CUT, FALSE);
599 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_COPY, FALSE);
600 }
601
602 pSH->AppendMenuItem(hPopup, 0, L"");
603 pSH->AppendMenuItem(
604 hPopup, WM_PWLEDIT_SELECTALL,
605 pProvider ? pProvider->LoadPopupMenuString(6) : L"&Select All");
606
607 if (m_pEdit->GetTotalWords() == 0) {
608 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_SELECTALL, FALSE);
609 }
610
611 int32_t x, y;
612 PWLtoWnd(ptPopup, x, y);
613 pSH->ClientToScreen(GetAttachedHWnd(), x, y);
614 pSH->SetCursor(FXCT_ARROW);
615 int32_t nCmd = pSH->TrackPopupMenu(hPopup, x, y, GetAttachedHWnd());
616
617 switch (nCmd) {
618 case WM_PWLEDIT_UNDO:
619 Undo();
620 break;
621 case WM_PWLEDIT_REDO:
622 Redo();
623 break;
624 case WM_PWLEDIT_CUT:
625 CutText();
626 break;
627 case WM_PWLEDIT_COPY:
628 CopyText();
629 break;
630 case WM_PWLEDIT_PASTE:
631 PasteText();
632 break;
633 case WM_PWLEDIT_DELETE:
634 Clear();
635 break;
636 case WM_PWLEDIT_SELECTALL:
637 SelectAll();
638 break;
639 case WM_PWLEDIT_SUGGEST + 0:
640 SetSel(m_pEdit->WordPlaceToWordIndex(wrLatin.BeginPos),
641 m_pEdit->WordPlaceToWordIndex(wrLatin.EndPos));
642 ReplaceSel(sSuggestWords[0].UTF8Decode().c_str());
643 break;
644 case WM_PWLEDIT_SUGGEST + 1:
645 SetSel(m_pEdit->WordPlaceToWordIndex(wrLatin.BeginPos),
646 m_pEdit->WordPlaceToWordIndex(wrLatin.EndPos));
647 ReplaceSel(sSuggestWords[1].UTF8Decode().c_str());
648 break;
649 case WM_PWLEDIT_SUGGEST + 2:
650 SetSel(m_pEdit->WordPlaceToWordIndex(wrLatin.BeginPos),
651 m_pEdit->WordPlaceToWordIndex(wrLatin.EndPos));
652 ReplaceSel(sSuggestWords[2].UTF8Decode().c_str());
653 break;
654 case WM_PWLEDIT_SUGGEST + 3:
655 SetSel(m_pEdit->WordPlaceToWordIndex(wrLatin.BeginPos),
656 m_pEdit->WordPlaceToWordIndex(wrLatin.EndPos));
657 ReplaceSel(sSuggestWords[3].UTF8Decode().c_str());
658 break;
659 case WM_PWLEDIT_SUGGEST + 4:
660 SetSel(m_pEdit->WordPlaceToWordIndex(wrLatin.BeginPos),
661 m_pEdit->WordPlaceToWordIndex(wrLatin.EndPos));
662 ReplaceSel(sSuggestWords[4].UTF8Decode().c_str());
663 break;
664 default:
665 break;
666 }
667
668 pSH->DestroyMenu(hPopup);
669
670 return TRUE;
671}
672
673void CPWL_Edit::OnSetFocus() {
674 SetEditCaret(TRUE);
675
676 if (!IsReadOnly()) {
677 if (IPWL_FocusHandler* pFocusHandler = GetFocusHandler())
678 pFocusHandler->OnSetFocus(this);
679 }
680
681 m_bFocus = TRUE;
682}
683
684void CPWL_Edit::OnKillFocus() {
685 ShowVScrollBar(FALSE);
686
687 m_pEdit->SelectNone();
Tom Sepez281a9ea2016-02-26 14:24:28 -0800688 SetCaret(FALSE, CFX_FloatPoint(0.0f, 0.0f), CFX_FloatPoint(0.0f, 0.0f));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700689
690 SetCharSet(0);
691
692 if (!IsReadOnly()) {
693 if (IPWL_FocusHandler* pFocusHandler = GetFocusHandler())
694 pFocusHandler->OnKillFocus(this);
695 }
696
697 m_bFocus = FALSE;
698}
699
700void CPWL_Edit::SetHorzScale(int32_t nHorzScale, FX_BOOL bPaint /* = TRUE*/) {
701 m_pEdit->SetHorzScale(nHorzScale, bPaint);
702}
703
704void CPWL_Edit::SetCharSpace(FX_FLOAT fCharSpace, FX_BOOL bPaint /* = TRUE*/) {
705 m_pEdit->SetCharSpace(fCharSpace, bPaint);
706}
707
708void CPWL_Edit::SetLineLeading(FX_FLOAT fLineLeading,
709 FX_BOOL bPaint /* = TRUE*/) {
710 m_pEdit->SetLineLeading(fLineLeading, bPaint);
711}
712
713CFX_ByteString CPWL_Edit::GetSelectAppearanceStream(
Tom Sepez281a9ea2016-02-26 14:24:28 -0800714 const CFX_FloatPoint& ptOffset) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700715 CPVT_WordRange wr = GetSelectWordRange();
716 return CPWL_Utils::GetEditSelAppStream(m_pEdit, ptOffset, &wr);
717}
718
719CPVT_WordRange CPWL_Edit::GetSelectWordRange() const {
720 if (m_pEdit->IsSelected()) {
721 int32_t nStart = -1;
722 int32_t nEnd = -1;
723
724 m_pEdit->GetSel(nStart, nEnd);
725
726 CPVT_WordPlace wpStart = m_pEdit->WordIndexToWordPlace(nStart);
727 CPVT_WordPlace wpEnd = m_pEdit->WordIndexToWordPlace(nEnd);
728
729 return CPVT_WordRange(wpStart, wpEnd);
730 }
731
732 return CPVT_WordRange();
733}
734
735CFX_ByteString CPWL_Edit::GetTextAppearanceStream(
Tom Sepez281a9ea2016-02-26 14:24:28 -0800736 const CFX_FloatPoint& ptOffset) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700737 CFX_ByteTextBuf sRet;
738 CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream(m_pEdit, ptOffset);
739
740 if (sEdit.GetLength() > 0) {
741 sRet << "BT\n" << CPWL_Utils::GetColorAppStream(GetTextColor()) << sEdit
742 << "ET\n";
743 }
744
745 return sRet.GetByteString();
746}
747
748CFX_ByteString CPWL_Edit::GetCaretAppearanceStream(
Tom Sepez281a9ea2016-02-26 14:24:28 -0800749 const CFX_FloatPoint& ptOffset) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700750 if (m_pEditCaret)
751 return m_pEditCaret->GetCaretAppearanceStream(ptOffset);
752
753 return CFX_ByteString();
754}
755
Tom Sepez281a9ea2016-02-26 14:24:28 -0800756CFX_FloatPoint CPWL_Edit::GetWordRightBottomPoint(
757 const CPVT_WordPlace& wpWord) {
758 CFX_FloatPoint pt(0.0f, 0.0f);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700759
760 if (IFX_Edit_Iterator* pIterator = m_pEdit->GetIterator()) {
761 CPVT_WordPlace wpOld = pIterator->GetAt();
762 pIterator->SetAt(wpWord);
763 CPVT_Word word;
764 if (pIterator->GetWord(word)) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800765 pt = CFX_FloatPoint(word.ptWord.x + word.fWidth,
766 word.ptWord.y + word.fDescent);
Lei Zhang60f507b2015-06-13 00:41:00 -0700767 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700768
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700769 pIterator->SetAt(wpOld);
770 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700771
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700772 return pt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700773}
774
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700775FX_BOOL CPWL_Edit::IsTextFull() const {
776 return m_pEdit->IsTextFull();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700777}
778
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700779FX_FLOAT CPWL_Edit::GetCharArrayAutoFontSize(CPDF_Font* pFont,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800780 const CFX_FloatRect& rcPlate,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700781 int32_t nCharArray) {
782 if (pFont && !pFont->IsStandardFont()) {
783 FX_RECT rcBBox;
784 pFont->GetFontBBox(rcBBox);
785
Tom Sepez281a9ea2016-02-26 14:24:28 -0800786 CFX_FloatRect rcCell = rcPlate;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700787 FX_FLOAT xdiv = rcCell.Width() / nCharArray * 1000.0f / rcBBox.Width();
788 FX_FLOAT ydiv = -rcCell.Height() * 1000.0f / rcBBox.Height();
789
790 return xdiv < ydiv ? xdiv : ydiv;
791 }
792
793 return 0.0f;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700794}
795
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700796void CPWL_Edit::SetCharArray(int32_t nCharArray) {
797 if (HasFlag(PES_CHARARRAY) && nCharArray > 0) {
798 m_pEdit->SetCharArray(nCharArray);
799 m_pEdit->SetTextOverflow(TRUE);
800
801 if (HasFlag(PWS_AUTOFONTSIZE)) {
802 if (IFX_Edit_FontMap* pFontMap = GetFontMap()) {
803 FX_FLOAT fFontSize = GetCharArrayAutoFontSize(
804 pFontMap->GetPDFFont(0), GetClientRect(), nCharArray);
805 if (fFontSize > 0.0f) {
806 m_pEdit->SetAutoFontSize(FALSE);
807 m_pEdit->SetFontSize(fFontSize);
808 }
809 }
810 }
811 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700812}
813
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700814void CPWL_Edit::SetLimitChar(int32_t nLimitChar) {
815 m_pEdit->SetLimitChar(nLimitChar);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700816}
817
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700818void CPWL_Edit::ReplaceSel(const FX_WCHAR* csText) {
819 m_pEdit->Clear();
820 m_pEdit->InsertText(csText);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700821}
822
Tom Sepez281a9ea2016-02-26 14:24:28 -0800823CFX_FloatRect CPWL_Edit::GetFocusRect() const {
824 return CFX_FloatRect();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700825}
826
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700827void CPWL_Edit::ShowVScrollBar(FX_BOOL bShow) {
828 if (CPWL_ScrollBar* pScroll = GetVScrollBar()) {
829 if (bShow) {
830 if (!pScroll->IsVisible()) {
831 pScroll->SetVisible(TRUE);
Tom Sepez281a9ea2016-02-26 14:24:28 -0800832 CFX_FloatRect rcWindow = GetWindowRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700833 m_rcOldWindow = rcWindow;
834 rcWindow.right += PWL_SCROLLBAR_WIDTH;
835 Move(rcWindow, TRUE, TRUE);
836 }
837 } else {
838 if (pScroll->IsVisible()) {
839 pScroll->SetVisible(FALSE);
840 Move(m_rcOldWindow, TRUE, TRUE);
841 }
842 }
843 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700844}
845
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700846FX_BOOL CPWL_Edit::IsVScrollBarVisible() const {
847 if (CPWL_ScrollBar* pScroll = GetVScrollBar()) {
848 return pScroll->IsVisible();
849 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700850
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700851 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700852}
853
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700854void CPWL_Edit::EnableSpellCheck(FX_BOOL bEnabled) {
855 if (bEnabled)
856 AddFlag(PES_SPELLCHECK);
857 else
858 RemoveFlag(PES_SPELLCHECK);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700859}
860
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700861FX_BOOL CPWL_Edit::OnKeyDown(FX_WORD nChar, FX_DWORD nFlag) {
862 if (m_bMouseDown)
863 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700864
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700865 if (nChar == FWL_VKEY_Delete) {
866 if (m_pFillerNotify) {
867 FX_BOOL bRC = TRUE;
868 FX_BOOL bExit = FALSE;
869 CFX_WideString strChange;
870 CFX_WideString strChangeEx;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700871
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700872 int nSelStart = 0;
873 int nSelEnd = 0;
874 GetSel(nSelStart, nSelEnd);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700875
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700876 if (nSelStart == nSelEnd)
877 nSelEnd = nSelStart + 1;
Lei Zhanga5b47042015-10-19 14:32:16 -0700878 m_pFillerNotify->OnBeforeKeyStroke(GetAttachedData(), strChange,
879 strChangeEx, nSelStart, nSelEnd, TRUE,
880 bRC, bExit, nFlag);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700881 if (!bRC)
882 return FALSE;
883 if (bExit)
884 return FALSE;
885 }
886 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700887
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700888 FX_BOOL bRet = CPWL_EditCtrl::OnKeyDown(nChar, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700889
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700890 // In case of implementation swallow the OnKeyDown event.
891 if (IsProceedtoOnChar(nChar, nFlag))
892 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700893
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700894 return bRet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700895}
896
897/**
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700898*In case of implementation swallow the OnKeyDown event.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700899*If the event is swallowed, implementation may do other unexpected things, which
900*is not the control means to do.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700901*/
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700902FX_BOOL CPWL_Edit::IsProceedtoOnChar(FX_WORD nKeyCode, FX_DWORD nFlag) {
903 FX_BOOL bCtrl = IsCTRLpressed(nFlag);
904 FX_BOOL bAlt = IsALTpressed(nFlag);
905 if (bCtrl && !bAlt) {
906 // hot keys for edit control.
907 switch (nKeyCode) {
908 case 'C':
909 case 'V':
910 case 'X':
911 case 'A':
912 case 'Z':
913 return TRUE;
914 default:
915 break;
916 }
917 }
918 // control characters.
919 switch (nKeyCode) {
920 case FWL_VKEY_Escape:
921 case FWL_VKEY_Back:
922 case FWL_VKEY_Return:
923 case FWL_VKEY_Space:
924 return TRUE;
925 default:
Lei Zhanga5b47042015-10-19 14:32:16 -0700926 return FALSE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700927 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700928}
929
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700930FX_BOOL CPWL_Edit::OnChar(FX_WORD nChar, FX_DWORD nFlag) {
931 if (m_bMouseDown)
932 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700933
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700934 FX_BOOL bRC = TRUE;
935 FX_BOOL bExit = FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700936
Lei Zhanga5b47042015-10-19 14:32:16 -0700937 if (!IsCTRLpressed(nFlag)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700938 if (m_pFillerNotify) {
939 CFX_WideString swChange;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700940
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700941 int nSelStart = 0;
942 int nSelEnd = 0;
943 GetSel(nSelStart, nSelEnd);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700944
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700945 switch (nChar) {
946 case FWL_VKEY_Back:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700947 if (nSelStart == nSelEnd)
948 nSelStart = nSelEnd - 1;
949 break;
950 case FWL_VKEY_Return:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700951 break;
952 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700953 swChange += nChar;
954 break;
955 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700956
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700957 CFX_WideString strChangeEx;
Lei Zhanga5b47042015-10-19 14:32:16 -0700958 m_pFillerNotify->OnBeforeKeyStroke(GetAttachedData(), swChange,
959 strChangeEx, nSelStart, nSelEnd, TRUE,
960 bRC, bExit, nFlag);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700961 }
962 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700963
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700964 if (!bRC)
965 return TRUE;
966 if (bExit)
967 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700968
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700969 if (IFX_Edit_FontMap* pFontMap = GetFontMap()) {
970 int32_t nOldCharSet = GetCharSet();
971 int32_t nNewCharSet = pFontMap->CharSetFromUnicode(nChar, DEFAULT_CHARSET);
972 if (nOldCharSet != nNewCharSet) {
973 SetCharSet(nNewCharSet);
974 }
975 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700976
Lei Zhanga5b47042015-10-19 14:32:16 -0700977 return CPWL_EditCtrl::OnChar(nChar, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700978}
979
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700980FX_BOOL CPWL_Edit::OnMouseWheel(short zDelta,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800981 const CFX_FloatPoint& point,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700982 FX_DWORD nFlag) {
983 if (HasFlag(PES_MULTILINE)) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800984 CFX_FloatPoint ptScroll = GetScrollPos();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700985
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700986 if (zDelta > 0) {
987 ptScroll.y += GetFontSize();
988 } else {
989 ptScroll.y -= GetFontSize();
990 }
991 SetScrollPos(ptScroll);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700992
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700993 return TRUE;
994 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700995
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700996 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700997}
998
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700999void CPWL_Edit::OnInsertReturn(const CPVT_WordPlace& place,
1000 const CPVT_WordPlace& oldplace) {
1001 if (HasFlag(PES_SPELLCHECK)) {
1002 m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace),
1003 GetLatinWordsRange(place)));
1004 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001005
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001006 if (m_pEditNotify) {
1007 m_pEditNotify->OnInsertReturn(place, oldplace);
1008 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001009}
1010
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001011void CPWL_Edit::OnBackSpace(const CPVT_WordPlace& place,
1012 const CPVT_WordPlace& oldplace) {
1013 if (HasFlag(PES_SPELLCHECK)) {
1014 m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace),
1015 GetLatinWordsRange(place)));
1016 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001017
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001018 if (m_pEditNotify) {
1019 m_pEditNotify->OnBackSpace(place, oldplace);
1020 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001021}
1022
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001023void CPWL_Edit::OnDelete(const CPVT_WordPlace& place,
1024 const CPVT_WordPlace& oldplace) {
1025 if (HasFlag(PES_SPELLCHECK)) {
1026 m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace),
1027 GetLatinWordsRange(place)));
1028 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001029
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001030 if (m_pEditNotify) {
1031 m_pEditNotify->OnDelete(place, oldplace);
1032 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001033}
1034
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001035void CPWL_Edit::OnClear(const CPVT_WordPlace& place,
1036 const CPVT_WordPlace& oldplace) {
1037 if (HasFlag(PES_SPELLCHECK)) {
1038 m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace),
1039 GetLatinWordsRange(place)));
1040 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001041
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001042 if (m_pEditNotify) {
1043 m_pEditNotify->OnClear(place, oldplace);
1044 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001045}
1046
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001047void CPWL_Edit::OnInsertWord(const CPVT_WordPlace& place,
1048 const CPVT_WordPlace& oldplace) {
1049 if (HasFlag(PES_SPELLCHECK)) {
1050 m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace),
1051 GetLatinWordsRange(place)));
1052 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001053
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001054 if (m_pEditNotify) {
1055 m_pEditNotify->OnInsertWord(place, oldplace);
1056 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001057}
1058
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001059void CPWL_Edit::OnSetText(const CPVT_WordPlace& place,
1060 const CPVT_WordPlace& oldplace) {}
1061
1062void CPWL_Edit::OnInsertText(const CPVT_WordPlace& place,
1063 const CPVT_WordPlace& oldplace) {
1064 if (HasFlag(PES_SPELLCHECK)) {
1065 m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace),
1066 GetLatinWordsRange(place)));
1067 }
1068
1069 if (m_pEditNotify) {
1070 m_pEditNotify->OnInsertText(place, oldplace);
1071 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001072}
1073
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001074void CPWL_Edit::OnAddUndo(IFX_Edit_UndoItem* pUndoItem) {
1075 if (m_pEditNotify) {
1076 m_pEditNotify->OnAddUndo(this);
1077 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001078}
1079
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001080CPVT_WordRange CPWL_Edit::CombineWordRange(const CPVT_WordRange& wr1,
1081 const CPVT_WordRange& wr2) {
1082 CPVT_WordRange wrRet;
1083
1084 if (wr1.BeginPos.WordCmp(wr2.BeginPos) < 0) {
1085 wrRet.BeginPos = wr1.BeginPos;
1086 } else {
1087 wrRet.BeginPos = wr2.BeginPos;
1088 }
1089
1090 if (wr1.EndPos.WordCmp(wr2.EndPos) < 0) {
1091 wrRet.EndPos = wr2.EndPos;
1092 } else {
1093 wrRet.EndPos = wr1.EndPos;
1094 }
1095
1096 return wrRet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001097}
1098
Tom Sepez281a9ea2016-02-26 14:24:28 -08001099CPVT_WordRange CPWL_Edit::GetLatinWordsRange(
1100 const CFX_FloatPoint& point) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001101 return GetSameWordsRange(m_pEdit->SearchWordPlace(point), TRUE, FALSE);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001102}
1103
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001104CPVT_WordRange CPWL_Edit::GetLatinWordsRange(
1105 const CPVT_WordPlace& place) const {
1106 return GetSameWordsRange(place, TRUE, FALSE);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001107}
1108
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001109CPVT_WordRange CPWL_Edit::GetArabicWordsRange(
1110 const CPVT_WordPlace& place) const {
1111 return GetSameWordsRange(place, FALSE, TRUE);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001112}
1113
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001114#define PWL_ISARABICWORD(word) \
1115 ((word >= 0x0600 && word <= 0x06FF) || (word >= 0xFB50 && word <= 0xFEFC))
1116
1117CPVT_WordRange CPWL_Edit::GetSameWordsRange(const CPVT_WordPlace& place,
1118 FX_BOOL bLatin,
1119 FX_BOOL bArabic) const {
1120 CPVT_WordRange range;
1121
1122 if (IFX_Edit_Iterator* pIterator = m_pEdit->GetIterator()) {
1123 CPVT_Word wordinfo;
1124 CPVT_WordPlace wpStart(place), wpEnd(place);
1125 pIterator->SetAt(place);
1126
1127 if (bLatin) {
1128 while (pIterator->NextWord()) {
Lei Zhangc2fb35f2016-01-05 16:46:58 -08001129 if (!pIterator->GetWord(wordinfo) ||
1130 !FX_EDIT_ISLATINWORD(wordinfo.Word)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001131 break;
Lei Zhangc2fb35f2016-01-05 16:46:58 -08001132 }
1133
1134 wpEnd = pIterator->GetAt();
1135 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001136 } else if (bArabic) {
1137 while (pIterator->NextWord()) {
Lei Zhangc2fb35f2016-01-05 16:46:58 -08001138 if (!pIterator->GetWord(wordinfo) || !PWL_ISARABICWORD(wordinfo.Word))
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001139 break;
Lei Zhangc2fb35f2016-01-05 16:46:58 -08001140
1141 wpEnd = pIterator->GetAt();
1142 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001143 }
1144
1145 pIterator->SetAt(place);
1146
1147 if (bLatin) {
1148 do {
Lei Zhangc2fb35f2016-01-05 16:46:58 -08001149 if (!pIterator->GetWord(wordinfo) ||
1150 !FX_EDIT_ISLATINWORD(wordinfo.Word)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001151 break;
1152 }
Lei Zhangc2fb35f2016-01-05 16:46:58 -08001153
1154 wpStart = pIterator->GetAt();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001155 } while (pIterator->PrevWord());
1156 } else if (bArabic) {
1157 do {
Lei Zhangc2fb35f2016-01-05 16:46:58 -08001158 if (!pIterator->GetWord(wordinfo) || !PWL_ISARABICWORD(wordinfo.Word))
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001159 break;
Lei Zhangc2fb35f2016-01-05 16:46:58 -08001160
1161 wpStart = pIterator->GetAt();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001162 } while (pIterator->PrevWord());
1163 }
1164
1165 range.Set(wpStart, wpEnd);
1166 }
1167
1168 return range;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001169}
1170
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001171void CPWL_Edit::GeneratePageObjects(
Tom Sepez2398d892016-02-17 16:46:26 -08001172 CPDF_PageObjectHolder* pObjectHolder,
Tom Sepez281a9ea2016-02-26 14:24:28 -08001173 const CFX_FloatPoint& ptOffset,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001174 CFX_ArrayTemplate<CPDF_TextObject*>& ObjArray) {
1175 IFX_Edit::GeneratePageObjects(
Tom Sepez2398d892016-02-17 16:46:26 -08001176 pObjectHolder, m_pEdit, ptOffset, NULL,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001177 CPWL_Utils::PWLColorToFXColor(GetTextColor(), GetTransparency()),
1178 ObjArray);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001179}
1180
Tom Sepez2398d892016-02-17 16:46:26 -08001181void CPWL_Edit::GeneratePageObjects(CPDF_PageObjectHolder* pObjectHolder,
Tom Sepez281a9ea2016-02-26 14:24:28 -08001182 const CFX_FloatPoint& ptOffset) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001183 CFX_ArrayTemplate<CPDF_TextObject*> ObjArray;
1184 IFX_Edit::GeneratePageObjects(
Tom Sepez2398d892016-02-17 16:46:26 -08001185 pObjectHolder, m_pEdit, ptOffset, NULL,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001186 CPWL_Utils::PWLColorToFXColor(GetTextColor(), GetTransparency()),
1187 ObjArray);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001188}