blob: e836594378ca91c838e6d8757e545b1b02f2e8b7 [file] [log] [blame]
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001// Copyright 2014 PDFium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
dan sinclair89e904b2016-03-23 19:29:15 -04007#include "fpdfsdk/pdfwindow/PWL_Edit.h"
Lei Zhangc2fb35f2016-01-05 16:46:58 -08008
Dan Sinclair3ebd1212016-03-09 09:59:23 -05009#include <vector>
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_word.h"
Dan Sinclaira8a28e02016-03-23 15:41:39 -040013#include "core/fxcrt/include/fx_safe_types.h"
14#include "core/fxcrt/include/fx_xml.h"
dsinclair48baa5f2016-04-06 10:00:40 -070015#include "core/fxge/include/fx_ge.h"
dan sinclair89e904b2016-03-23 19:29:15 -040016#include "fpdfsdk/pdfwindow/PWL_Caret.h"
17#include "fpdfsdk/pdfwindow/PWL_EditCtrl.h"
18#include "fpdfsdk/pdfwindow/PWL_FontMap.h"
19#include "fpdfsdk/pdfwindow/PWL_ScrollBar.h"
20#include "fpdfsdk/pdfwindow/PWL_Utils.h"
21#include "fpdfsdk/pdfwindow/PWL_Wnd.h"
Lei Zhangc2fb35f2016-01-05 16:46:58 -080022#include "public/fpdf_fwlevent.h"
Tom Sepezab277682016-02-17 10:07:21 -080023#include "third_party/base/stl_util.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070024
Nico Weber9d8ec5a2015-08-04 13:00:21 -070025CPWL_Edit::CPWL_Edit()
dsinclair8da140e2016-04-07 12:39:44 -070026 : m_pFillerNotify(nullptr), m_bFocus(FALSE), m_pFormFiller(nullptr) {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070027
Nico Weber9d8ec5a2015-08-04 13:00:21 -070028CPWL_Edit::~CPWL_Edit() {
29 ASSERT(m_bFocus == FALSE);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070030}
31
Nico Weber9d8ec5a2015-08-04 13:00:21 -070032CFX_ByteString CPWL_Edit::GetClassName() const {
33 return PWL_CLASSNAME_EDIT;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070034}
35
Nico Weber9d8ec5a2015-08-04 13:00:21 -070036void CPWL_Edit::OnDestroy() {}
37
38void CPWL_Edit::SetText(const FX_WCHAR* csText) {
39 CFX_WideString swText = csText;
40
41 if (HasFlag(PES_RICH)) {
42 CFX_ByteString sValue = CFX_ByteString::FromUnicode(swText);
43
44 if (CXML_Element* pXML =
45 CXML_Element::Parse(sValue.c_str(), sValue.GetLength())) {
46 int32_t nCount = pXML->CountChildren();
47 FX_BOOL bFirst = TRUE;
48
49 swText.Empty();
50
51 for (int32_t i = 0; i < nCount; i++) {
52 if (CXML_Element* pSubElement = pXML->GetElement(i)) {
53 CFX_ByteString tag = pSubElement->GetTagName();
54 if (tag.EqualNoCase("p")) {
55 int nChild = pSubElement->CountChildren();
56 CFX_WideString swSection;
57 for (int32_t j = 0; j < nChild; j++) {
58 swSection += pSubElement->GetContent(j);
59 }
60
61 if (bFirst)
62 bFirst = FALSE;
63 else
64 swText += FWL_VKEY_Return;
65 swText += swSection;
66 }
67 }
68 }
69
70 delete pXML;
71 }
72 }
73
74 m_pEdit->SetText(swText.c_str());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070075}
76
Nico Weber9d8ec5a2015-08-04 13:00:21 -070077void CPWL_Edit::RePosChildWnd() {
78 if (CPWL_ScrollBar* pVSB = GetVScrollBar()) {
Tom Sepez281a9ea2016-02-26 14:24:28 -080079 CFX_FloatRect rcWindow = m_rcOldWindow;
80 CFX_FloatRect rcVScroll =
81 CFX_FloatRect(rcWindow.right, rcWindow.bottom,
82 rcWindow.right + PWL_SCROLLBAR_WIDTH, rcWindow.top);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070083 pVSB->Move(rcVScroll, TRUE, FALSE);
84 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070085
Nico Weber9d8ec5a2015-08-04 13:00:21 -070086 if (m_pEditCaret && !HasFlag(PES_TEXTOVERFLOW))
87 m_pEditCaret->SetClipRect(CPWL_Utils::InflateRect(
Dan Sinclair50cce602016-02-24 09:51:16 -050088 GetClientRect(), 1.0f)); // +1 for caret beside border
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070089
Nico Weber9d8ec5a2015-08-04 13:00:21 -070090 CPWL_EditCtrl::RePosChildWnd();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070091}
92
Tom Sepez281a9ea2016-02-26 14:24:28 -080093CFX_FloatRect CPWL_Edit::GetClientRect() const {
94 CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(
Nico Weber9d8ec5a2015-08-04 13:00:21 -070095 GetWindowRect(), (FX_FLOAT)(GetBorderWidth() + GetInnerBorderWidth()));
96
97 if (CPWL_ScrollBar* pVSB = GetVScrollBar()) {
98 if (pVSB->IsVisible()) {
99 rcClient.right -= PWL_SCROLLBAR_WIDTH;
100 }
101 }
102
103 return rcClient;
104}
105
106void CPWL_Edit::SetAlignFormatH(PWL_EDIT_ALIGNFORMAT_H nFormat,
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800107 FX_BOOL bPaint) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700108 m_pEdit->SetAlignmentH((int32_t)nFormat, bPaint);
109}
110
111void CPWL_Edit::SetAlignFormatV(PWL_EDIT_ALIGNFORMAT_V nFormat,
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800112 FX_BOOL bPaint) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700113 m_pEdit->SetAlignmentV((int32_t)nFormat, bPaint);
114}
115
116FX_BOOL CPWL_Edit::CanSelectAll() const {
117 return GetSelectWordRange() != m_pEdit->GetWholeWordRange();
118}
119
120FX_BOOL CPWL_Edit::CanClear() const {
121 return !IsReadOnly() && m_pEdit->IsSelected();
122}
123
124FX_BOOL CPWL_Edit::CanCopy() const {
125 return !HasFlag(PES_PASSWORD) && !HasFlag(PES_NOREAD) &&
126 m_pEdit->IsSelected();
127}
128
129FX_BOOL CPWL_Edit::CanCut() const {
130 return CanCopy() && !IsReadOnly();
131}
132
133FX_BOOL CPWL_Edit::CanPaste() const {
134 if (IsReadOnly())
135 return FALSE;
136
137 CFX_WideString swClipboard;
138 if (IFX_SystemHandler* pSH = GetSystemHandler())
139 swClipboard = pSH->GetClipboardText(GetAttachedHWnd());
140
141 return !swClipboard.IsEmpty();
142}
143
144void CPWL_Edit::CopyText() {
145 if (!CanCopy())
146 return;
147
148 CFX_WideString str = m_pEdit->GetSelText();
149
150 if (IFX_SystemHandler* pSH = GetSystemHandler())
151 pSH->SetClipboardText(GetAttachedHWnd(), str);
152}
153
154void CPWL_Edit::PasteText() {
155 if (!CanPaste())
156 return;
157
158 CFX_WideString swClipboard;
159 if (IFX_SystemHandler* pSH = GetSystemHandler())
160 swClipboard = pSH->GetClipboardText(GetAttachedHWnd());
161
162 if (m_pFillerNotify) {
163 FX_BOOL bRC = TRUE;
164 FX_BOOL bExit = FALSE;
165 CFX_WideString strChangeEx;
166 int nSelStart = 0;
167 int nSelEnd = 0;
168 GetSel(nSelStart, nSelEnd);
Lei Zhanga5b47042015-10-19 14:32:16 -0700169 m_pFillerNotify->OnBeforeKeyStroke(GetAttachedData(), swClipboard,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700170 strChangeEx, nSelStart, nSelEnd, TRUE,
171 bRC, bExit, 0);
172 if (!bRC)
173 return;
174 if (bExit)
175 return;
176 }
177
178 if (swClipboard.GetLength() > 0) {
179 Clear();
180 InsertText(swClipboard.c_str());
181 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700182}
183
184void CPWL_Edit::CutText() {
185 if (!CanCut())
186 return;
187
188 CFX_WideString str = m_pEdit->GetSelText();
189
190 if (IFX_SystemHandler* pSH = GetSystemHandler())
191 pSH->SetClipboardText(GetAttachedHWnd(), str);
192
193 m_pEdit->Clear();
194}
195
196void CPWL_Edit::OnCreated() {
197 CPWL_EditCtrl::OnCreated();
198
199 if (CPWL_ScrollBar* pScroll = GetVScrollBar()) {
200 pScroll->RemoveFlag(PWS_AUTOTRANSPARENT);
201 pScroll->SetTransparency(255);
202 }
203
204 SetParamByFlag();
205
206 m_rcOldWindow = GetWindowRect();
207
208 m_pEdit->SetOprNotify(this);
209 m_pEdit->EnableOprNotify(TRUE);
210}
211
212void CPWL_Edit::SetParamByFlag() {
213 if (HasFlag(PES_RIGHT)) {
214 m_pEdit->SetAlignmentH(2, FALSE);
215 } else if (HasFlag(PES_MIDDLE)) {
216 m_pEdit->SetAlignmentH(1, FALSE);
217 } else {
218 m_pEdit->SetAlignmentH(0, FALSE);
219 }
220
221 if (HasFlag(PES_BOTTOM)) {
222 m_pEdit->SetAlignmentV(2, FALSE);
223 } else if (HasFlag(PES_CENTER)) {
224 m_pEdit->SetAlignmentV(1, FALSE);
225 } else {
226 m_pEdit->SetAlignmentV(0, FALSE);
227 }
228
229 if (HasFlag(PES_PASSWORD)) {
230 m_pEdit->SetPasswordChar('*', FALSE);
231 }
232
233 m_pEdit->SetMultiLine(HasFlag(PES_MULTILINE), FALSE);
234 m_pEdit->SetAutoReturn(HasFlag(PES_AUTORETURN), FALSE);
235 m_pEdit->SetAutoFontSize(HasFlag(PWS_AUTOFONTSIZE), FALSE);
236 m_pEdit->SetAutoScroll(HasFlag(PES_AUTOSCROLL), FALSE);
237 m_pEdit->EnableUndo(HasFlag(PES_UNDO));
238
239 if (HasFlag(PES_TEXTOVERFLOW)) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800240 SetClipRect(CFX_FloatRect(0.0f, 0.0f, 0.0f, 0.0f));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700241 m_pEdit->SetTextOverflow(TRUE, FALSE);
242 } else {
243 if (m_pEditCaret) {
244 m_pEditCaret->SetClipRect(CPWL_Utils::InflateRect(
Dan Sinclair50cce602016-02-24 09:51:16 -0500245 GetClientRect(), 1.0f)); // +1 for caret beside border
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700246 }
247 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700248}
249
250void CPWL_Edit::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) {
251 CPWL_Wnd::GetThisAppearanceStream(sAppStream);
252
Tom Sepez281a9ea2016-02-26 14:24:28 -0800253 CFX_FloatRect rcClient = GetClientRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700254 CFX_ByteTextBuf sLine;
255
256 int32_t nCharArray = m_pEdit->GetCharArray();
257
258 if (nCharArray > 0) {
259 switch (GetBorderStyle()) {
260 case PBS_SOLID: {
261 sLine << "q\n" << GetBorderWidth() << " w\n"
262 << CPWL_Utils::GetColorAppStream(GetBorderColor(), FALSE)
tsepez28f97ff2016-04-04 16:41:35 -0700263 .AsByteStringC()
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700264 << " 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)
tsepez28f97ff2016-04-04 16:41:35 -0700280 .AsByteStringC()
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700281 << " 2 J 0 j\n"
282 << "[" << GetBorderDash().nDash << " " << GetBorderDash().nGap
283 << "] " << GetBorderDash().nPhase << " d\n";
284
285 for (int32_t i = 1; i < nCharArray; i++) {
286 sLine << rcClient.left +
287 ((rcClient.right - rcClient.left) / nCharArray) * i
288 << " " << rcClient.bottom << " m\n"
289 << rcClient.left +
290 ((rcClient.right - rcClient.left) / nCharArray) * i
291 << " " << rcClient.top << " l S\n";
292 }
293
294 sLine << "Q\n";
295 } break;
296 }
297 }
298
299 sAppStream << sLine;
300
301 CFX_ByteTextBuf sText;
302
Tom Sepez281a9ea2016-02-26 14:24:28 -0800303 CFX_FloatPoint ptOffset = CFX_FloatPoint(0.0f, 0.0f);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700304
305 CPVT_WordRange wrWhole = m_pEdit->GetWholeWordRange();
306 CPVT_WordRange wrSelect = GetSelectWordRange();
307 CPVT_WordRange wrVisible =
308 (HasFlag(PES_TEXTOVERFLOW) ? wrWhole : m_pEdit->GetVisibleWordRange());
309 CPVT_WordRange wrSelBefore(wrWhole.BeginPos, wrSelect.BeginPos);
310 CPVT_WordRange wrSelAfter(wrSelect.EndPos, wrWhole.EndPos);
311
312 CPVT_WordRange wrTemp =
313 CPWL_Utils::OverlapWordRange(GetSelectWordRange(), wrVisible);
314 CFX_ByteString sEditSel =
315 CPWL_Utils::GetEditSelAppStream(m_pEdit, ptOffset, &wrTemp);
316
317 if (sEditSel.GetLength() > 0)
318 sText << CPWL_Utils::GetColorAppStream(PWL_DEFAULT_SELBACKCOLOR)
tsepez28f97ff2016-04-04 16:41:35 -0700319 .AsByteStringC()
320 << sEditSel.AsByteStringC();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700321
322 wrTemp = CPWL_Utils::OverlapWordRange(wrVisible, wrSelBefore);
323 CFX_ByteString sEditBefore = CPWL_Utils::GetEditAppStream(
324 m_pEdit, ptOffset, &wrTemp, !HasFlag(PES_CHARARRAY),
325 m_pEdit->GetPasswordChar());
326
327 if (sEditBefore.GetLength() > 0)
tsepez28f97ff2016-04-04 16:41:35 -0700328 sText << "BT\n"
329 << CPWL_Utils::GetColorAppStream(GetTextColor()).AsByteStringC()
330 << sEditBefore.AsByteStringC() << "ET\n";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700331
332 wrTemp = CPWL_Utils::OverlapWordRange(wrVisible, wrSelect);
333 CFX_ByteString sEditMid = CPWL_Utils::GetEditAppStream(
334 m_pEdit, ptOffset, &wrTemp, !HasFlag(PES_CHARARRAY),
335 m_pEdit->GetPasswordChar());
336
337 if (sEditMid.GetLength() > 0)
338 sText << "BT\n"
339 << CPWL_Utils::GetColorAppStream(CPWL_Color(COLORTYPE_GRAY, 1))
tsepez28f97ff2016-04-04 16:41:35 -0700340 .AsByteStringC()
341 << sEditMid.AsByteStringC() << "ET\n";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700342
343 wrTemp = CPWL_Utils::OverlapWordRange(wrVisible, wrSelAfter);
344 CFX_ByteString sEditAfter = CPWL_Utils::GetEditAppStream(
345 m_pEdit, ptOffset, &wrTemp, !HasFlag(PES_CHARARRAY),
346 m_pEdit->GetPasswordChar());
347
348 if (sEditAfter.GetLength() > 0)
tsepez28f97ff2016-04-04 16:41:35 -0700349 sText << "BT\n"
350 << CPWL_Utils::GetColorAppStream(GetTextColor()).AsByteStringC()
351 << sEditAfter.AsByteStringC() << "ET\n";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700352
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700353 if (sText.GetLength() > 0) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800354 CFX_FloatRect rcClient = GetClientRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700355 sAppStream << "q\n/Tx BMC\n";
356
357 if (!HasFlag(PES_TEXTOVERFLOW))
358 sAppStream << rcClient.left << " " << rcClient.bottom << " "
359 << rcClient.right - rcClient.left << " "
360 << rcClient.top - rcClient.bottom << " re W n\n";
361
362 sAppStream << sText;
363
364 sAppStream << "EMC\nQ\n";
365 }
366}
367
368void CPWL_Edit::DrawThisAppearance(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800369 CFX_Matrix* pUser2Device) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700370 CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device);
371
Tom Sepez281a9ea2016-02-26 14:24:28 -0800372 CFX_FloatRect rcClient = GetClientRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700373 CFX_ByteTextBuf sLine;
374
375 int32_t nCharArray = m_pEdit->GetCharArray();
376 FX_SAFE_INT32 nCharArraySafe = nCharArray;
377 nCharArraySafe -= 1;
378 nCharArraySafe *= 2;
379
380 if (nCharArray > 0 && nCharArraySafe.IsValid()) {
381 switch (GetBorderStyle()) {
382 case PBS_SOLID: {
383 CFX_GraphStateData gsd;
384 gsd.m_LineWidth = (FX_FLOAT)GetBorderWidth();
385
386 CFX_PathData path;
387 path.SetPointCount(nCharArraySafe.ValueOrDie());
388
389 for (int32_t i = 0; i < nCharArray - 1; i++) {
390 path.SetPoint(
391 i * 2,
392 rcClient.left +
393 ((rcClient.right - rcClient.left) / nCharArray) * (i + 1),
394 rcClient.bottom, FXPT_MOVETO);
395 path.SetPoint(
396 i * 2 + 1,
397 rcClient.left +
398 ((rcClient.right - rcClient.left) / nCharArray) * (i + 1),
399 rcClient.top, FXPT_LINETO);
400 }
401 if (path.GetPointCount() > 0)
402 pDevice->DrawPath(
403 &path, pUser2Device, &gsd, 0,
404 CPWL_Utils::PWLColorToFXColor(GetBorderColor(), 255),
405 FXFILL_ALTERNATE);
406 } break;
407 case PBS_DASH: {
408 CFX_GraphStateData gsd;
409 gsd.m_LineWidth = (FX_FLOAT)GetBorderWidth();
410
411 gsd.SetDashCount(2);
412 gsd.m_DashArray[0] = (FX_FLOAT)GetBorderDash().nDash;
413 gsd.m_DashArray[1] = (FX_FLOAT)GetBorderDash().nGap;
414 gsd.m_DashPhase = (FX_FLOAT)GetBorderDash().nPhase;
415
416 CFX_PathData path;
417 path.SetPointCount(nCharArraySafe.ValueOrDie());
418
419 for (int32_t i = 0; i < nCharArray - 1; i++) {
420 path.SetPoint(
421 i * 2,
422 rcClient.left +
423 ((rcClient.right - rcClient.left) / nCharArray) * (i + 1),
424 rcClient.bottom, FXPT_MOVETO);
425 path.SetPoint(
426 i * 2 + 1,
427 rcClient.left +
428 ((rcClient.right - rcClient.left) / nCharArray) * (i + 1),
429 rcClient.top, FXPT_LINETO);
430 }
431 if (path.GetPointCount() > 0)
432 pDevice->DrawPath(
433 &path, pUser2Device, &gsd, 0,
434 CPWL_Utils::PWLColorToFXColor(GetBorderColor(), 255),
435 FXFILL_ALTERNATE);
436 } break;
437 }
438 }
439
Tom Sepez281a9ea2016-02-26 14:24:28 -0800440 CFX_FloatRect rcClip;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700441 CPVT_WordRange wrRange = m_pEdit->GetVisibleWordRange();
442 CPVT_WordRange* pRange = NULL;
443
444 if (!HasFlag(PES_TEXTOVERFLOW)) {
445 rcClip = GetClientRect();
446 pRange = &wrRange;
447 }
448 IFX_SystemHandler* pSysHandler = GetSystemHandler();
449 IFX_Edit::DrawEdit(
450 pDevice, pUser2Device, m_pEdit,
451 CPWL_Utils::PWLColorToFXColor(GetTextColor(), GetTransparency()),
452 CPWL_Utils::PWLColorToFXColor(GetTextStrokeColor(), GetTransparency()),
Tom Sepez281a9ea2016-02-26 14:24:28 -0800453 rcClip, CFX_FloatPoint(0.0f, 0.0f), pRange, pSysHandler, m_pFormFiller);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700454}
455
tsepezc3255f52016-03-25 14:52:27 -0700456FX_BOOL CPWL_Edit::OnLButtonDown(const CFX_FloatPoint& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700457 CPWL_Wnd::OnLButtonDown(point, nFlag);
458
459 if (HasFlag(PES_TEXTOVERFLOW) || ClientHitTest(point)) {
460 if (m_bMouseDown)
461 InvalidateRect();
462
463 m_bMouseDown = TRUE;
464 SetCapture();
465
466 m_pEdit->OnMouseDown(point, IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
467 }
468
469 return TRUE;
470}
471
Tom Sepez281a9ea2016-02-26 14:24:28 -0800472FX_BOOL CPWL_Edit::OnLButtonDblClk(const CFX_FloatPoint& point,
tsepezc3255f52016-03-25 14:52:27 -0700473 uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700474 CPWL_Wnd::OnLButtonDblClk(point, nFlag);
475
476 if (HasFlag(PES_TEXTOVERFLOW) || ClientHitTest(point)) {
477 m_pEdit->SelectAll();
478 }
479
480 return TRUE;
481}
482
483#define WM_PWLEDIT_UNDO 0x01
484#define WM_PWLEDIT_REDO 0x02
485#define WM_PWLEDIT_CUT 0x03
486#define WM_PWLEDIT_COPY 0x04
487#define WM_PWLEDIT_PASTE 0x05
488#define WM_PWLEDIT_DELETE 0x06
489#define WM_PWLEDIT_SELECTALL 0x07
490#define WM_PWLEDIT_SUGGEST 0x08
491
tsepezc3255f52016-03-25 14:52:27 -0700492FX_BOOL CPWL_Edit::OnRButtonUp(const CFX_FloatPoint& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700493 if (m_bMouseDown)
494 return FALSE;
495
496 CPWL_Wnd::OnRButtonUp(point, nFlag);
497
498 if (!HasFlag(PES_TEXTOVERFLOW) && !ClientHitTest(point))
499 return TRUE;
500
501 IFX_SystemHandler* pSH = GetSystemHandler();
502 if (!pSH)
503 return FALSE;
504
505 SetFocus();
506
507 CPVT_WordRange wrLatin = GetLatinWordsRange(point);
508 CFX_WideString swLatin = m_pEdit->GetRangeText(wrLatin);
509
510 FX_HMENU hPopup = pSH->CreatePopupMenu();
511 if (!hPopup)
512 return FALSE;
513
Tom Sepezab277682016-02-17 10:07:21 -0800514 std::vector<CFX_ByteString> sSuggestWords;
Tom Sepez281a9ea2016-02-26 14:24:28 -0800515 CFX_FloatPoint ptPopup = point;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700516
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700517 IPWL_Provider* pProvider = GetProvider();
518
519 if (HasFlag(PES_UNDO)) {
520 pSH->AppendMenuItem(
521 hPopup, WM_PWLEDIT_UNDO,
522 pProvider ? pProvider->LoadPopupMenuString(0) : L"&Undo");
523 pSH->AppendMenuItem(
524 hPopup, WM_PWLEDIT_REDO,
525 pProvider ? pProvider->LoadPopupMenuString(1) : L"&Redo");
526 pSH->AppendMenuItem(hPopup, 0, L"");
527
528 if (!m_pEdit->CanUndo())
529 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_UNDO, FALSE);
530 if (!m_pEdit->CanRedo())
531 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_REDO, FALSE);
532 }
533
534 pSH->AppendMenuItem(hPopup, WM_PWLEDIT_CUT,
535 pProvider ? pProvider->LoadPopupMenuString(2) : L"Cu&t");
536 pSH->AppendMenuItem(hPopup, WM_PWLEDIT_COPY,
537 pProvider ? pProvider->LoadPopupMenuString(3) : L"&Copy");
538 pSH->AppendMenuItem(
539 hPopup, WM_PWLEDIT_PASTE,
540 pProvider ? pProvider->LoadPopupMenuString(4) : L"&Paste");
541 pSH->AppendMenuItem(
542 hPopup, WM_PWLEDIT_DELETE,
543 pProvider ? pProvider->LoadPopupMenuString(5) : L"&Delete");
544
545 CFX_WideString swText = pSH->GetClipboardText(GetAttachedHWnd());
546 if (swText.IsEmpty())
547 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_PASTE, FALSE);
548
549 if (!m_pEdit->IsSelected()) {
550 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_CUT, FALSE);
551 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_COPY, FALSE);
552 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_DELETE, FALSE);
553 }
554
555 if (IsReadOnly()) {
556 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_CUT, FALSE);
557 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_DELETE, FALSE);
558 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_PASTE, FALSE);
559 }
560
561 if (HasFlag(PES_PASSWORD)) {
562 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_CUT, FALSE);
563 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_COPY, FALSE);
564 }
565
566 if (HasFlag(PES_NOREAD)) {
567 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_CUT, FALSE);
568 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_COPY, FALSE);
569 }
570
571 pSH->AppendMenuItem(hPopup, 0, L"");
572 pSH->AppendMenuItem(
573 hPopup, WM_PWLEDIT_SELECTALL,
574 pProvider ? pProvider->LoadPopupMenuString(6) : L"&Select All");
575
576 if (m_pEdit->GetTotalWords() == 0) {
577 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_SELECTALL, FALSE);
578 }
579
580 int32_t x, y;
581 PWLtoWnd(ptPopup, x, y);
582 pSH->ClientToScreen(GetAttachedHWnd(), x, y);
583 pSH->SetCursor(FXCT_ARROW);
584 int32_t nCmd = pSH->TrackPopupMenu(hPopup, x, y, GetAttachedHWnd());
585
586 switch (nCmd) {
587 case WM_PWLEDIT_UNDO:
588 Undo();
589 break;
590 case WM_PWLEDIT_REDO:
591 Redo();
592 break;
593 case WM_PWLEDIT_CUT:
594 CutText();
595 break;
596 case WM_PWLEDIT_COPY:
597 CopyText();
598 break;
599 case WM_PWLEDIT_PASTE:
600 PasteText();
601 break;
602 case WM_PWLEDIT_DELETE:
603 Clear();
604 break;
605 case WM_PWLEDIT_SELECTALL:
606 SelectAll();
607 break;
608 case WM_PWLEDIT_SUGGEST + 0:
609 SetSel(m_pEdit->WordPlaceToWordIndex(wrLatin.BeginPos),
610 m_pEdit->WordPlaceToWordIndex(wrLatin.EndPos));
611 ReplaceSel(sSuggestWords[0].UTF8Decode().c_str());
612 break;
613 case WM_PWLEDIT_SUGGEST + 1:
614 SetSel(m_pEdit->WordPlaceToWordIndex(wrLatin.BeginPos),
615 m_pEdit->WordPlaceToWordIndex(wrLatin.EndPos));
616 ReplaceSel(sSuggestWords[1].UTF8Decode().c_str());
617 break;
618 case WM_PWLEDIT_SUGGEST + 2:
619 SetSel(m_pEdit->WordPlaceToWordIndex(wrLatin.BeginPos),
620 m_pEdit->WordPlaceToWordIndex(wrLatin.EndPos));
621 ReplaceSel(sSuggestWords[2].UTF8Decode().c_str());
622 break;
623 case WM_PWLEDIT_SUGGEST + 3:
624 SetSel(m_pEdit->WordPlaceToWordIndex(wrLatin.BeginPos),
625 m_pEdit->WordPlaceToWordIndex(wrLatin.EndPos));
626 ReplaceSel(sSuggestWords[3].UTF8Decode().c_str());
627 break;
628 case WM_PWLEDIT_SUGGEST + 4:
629 SetSel(m_pEdit->WordPlaceToWordIndex(wrLatin.BeginPos),
630 m_pEdit->WordPlaceToWordIndex(wrLatin.EndPos));
631 ReplaceSel(sSuggestWords[4].UTF8Decode().c_str());
632 break;
633 default:
634 break;
635 }
636
637 pSH->DestroyMenu(hPopup);
638
639 return TRUE;
640}
641
642void CPWL_Edit::OnSetFocus() {
643 SetEditCaret(TRUE);
644
645 if (!IsReadOnly()) {
646 if (IPWL_FocusHandler* pFocusHandler = GetFocusHandler())
647 pFocusHandler->OnSetFocus(this);
648 }
649
650 m_bFocus = TRUE;
651}
652
653void CPWL_Edit::OnKillFocus() {
654 ShowVScrollBar(FALSE);
655
656 m_pEdit->SelectNone();
Tom Sepez281a9ea2016-02-26 14:24:28 -0800657 SetCaret(FALSE, CFX_FloatPoint(0.0f, 0.0f), CFX_FloatPoint(0.0f, 0.0f));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700658
659 SetCharSet(0);
660
661 if (!IsReadOnly()) {
662 if (IPWL_FocusHandler* pFocusHandler = GetFocusHandler())
663 pFocusHandler->OnKillFocus(this);
664 }
665
666 m_bFocus = FALSE;
667}
668
669void CPWL_Edit::SetHorzScale(int32_t nHorzScale, FX_BOOL bPaint /* = TRUE*/) {
670 m_pEdit->SetHorzScale(nHorzScale, bPaint);
671}
672
673void CPWL_Edit::SetCharSpace(FX_FLOAT fCharSpace, FX_BOOL bPaint /* = TRUE*/) {
674 m_pEdit->SetCharSpace(fCharSpace, bPaint);
675}
676
677void CPWL_Edit::SetLineLeading(FX_FLOAT fLineLeading,
678 FX_BOOL bPaint /* = TRUE*/) {
679 m_pEdit->SetLineLeading(fLineLeading, bPaint);
680}
681
682CFX_ByteString CPWL_Edit::GetSelectAppearanceStream(
Tom Sepez281a9ea2016-02-26 14:24:28 -0800683 const CFX_FloatPoint& ptOffset) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700684 CPVT_WordRange wr = GetSelectWordRange();
685 return CPWL_Utils::GetEditSelAppStream(m_pEdit, ptOffset, &wr);
686}
687
688CPVT_WordRange CPWL_Edit::GetSelectWordRange() const {
689 if (m_pEdit->IsSelected()) {
690 int32_t nStart = -1;
691 int32_t nEnd = -1;
692
693 m_pEdit->GetSel(nStart, nEnd);
694
695 CPVT_WordPlace wpStart = m_pEdit->WordIndexToWordPlace(nStart);
696 CPVT_WordPlace wpEnd = m_pEdit->WordIndexToWordPlace(nEnd);
697
698 return CPVT_WordRange(wpStart, wpEnd);
699 }
700
701 return CPVT_WordRange();
702}
703
704CFX_ByteString CPWL_Edit::GetTextAppearanceStream(
Tom Sepez281a9ea2016-02-26 14:24:28 -0800705 const CFX_FloatPoint& ptOffset) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700706 CFX_ByteTextBuf sRet;
707 CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream(m_pEdit, ptOffset);
708
709 if (sEdit.GetLength() > 0) {
tsepez28f97ff2016-04-04 16:41:35 -0700710 sRet << "BT\n"
711 << CPWL_Utils::GetColorAppStream(GetTextColor()).AsByteStringC()
712 << sEdit.AsByteStringC() << "ET\n";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700713 }
714
715 return sRet.GetByteString();
716}
717
718CFX_ByteString CPWL_Edit::GetCaretAppearanceStream(
Tom Sepez281a9ea2016-02-26 14:24:28 -0800719 const CFX_FloatPoint& ptOffset) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700720 if (m_pEditCaret)
721 return m_pEditCaret->GetCaretAppearanceStream(ptOffset);
722
723 return CFX_ByteString();
724}
725
Tom Sepez281a9ea2016-02-26 14:24:28 -0800726CFX_FloatPoint CPWL_Edit::GetWordRightBottomPoint(
727 const CPVT_WordPlace& wpWord) {
728 CFX_FloatPoint pt(0.0f, 0.0f);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700729
730 if (IFX_Edit_Iterator* pIterator = m_pEdit->GetIterator()) {
731 CPVT_WordPlace wpOld = pIterator->GetAt();
732 pIterator->SetAt(wpWord);
733 CPVT_Word word;
734 if (pIterator->GetWord(word)) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800735 pt = CFX_FloatPoint(word.ptWord.x + word.fWidth,
736 word.ptWord.y + word.fDescent);
Lei Zhang60f507b2015-06-13 00:41:00 -0700737 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700738
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700739 pIterator->SetAt(wpOld);
740 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700741
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700742 return pt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700743}
744
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700745FX_BOOL CPWL_Edit::IsTextFull() const {
746 return m_pEdit->IsTextFull();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700747}
748
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700749FX_FLOAT CPWL_Edit::GetCharArrayAutoFontSize(CPDF_Font* pFont,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800750 const CFX_FloatRect& rcPlate,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700751 int32_t nCharArray) {
752 if (pFont && !pFont->IsStandardFont()) {
753 FX_RECT rcBBox;
754 pFont->GetFontBBox(rcBBox);
755
Tom Sepez281a9ea2016-02-26 14:24:28 -0800756 CFX_FloatRect rcCell = rcPlate;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700757 FX_FLOAT xdiv = rcCell.Width() / nCharArray * 1000.0f / rcBBox.Width();
758 FX_FLOAT ydiv = -rcCell.Height() * 1000.0f / rcBBox.Height();
759
760 return xdiv < ydiv ? xdiv : ydiv;
761 }
762
763 return 0.0f;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700764}
765
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700766void CPWL_Edit::SetCharArray(int32_t nCharArray) {
767 if (HasFlag(PES_CHARARRAY) && nCharArray > 0) {
768 m_pEdit->SetCharArray(nCharArray);
769 m_pEdit->SetTextOverflow(TRUE);
770
771 if (HasFlag(PWS_AUTOFONTSIZE)) {
dsinclairc7a73492016-04-05 12:01:42 -0700772 if (IPVT_FontMap* pFontMap = GetFontMap()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700773 FX_FLOAT fFontSize = GetCharArrayAutoFontSize(
774 pFontMap->GetPDFFont(0), GetClientRect(), nCharArray);
775 if (fFontSize > 0.0f) {
776 m_pEdit->SetAutoFontSize(FALSE);
777 m_pEdit->SetFontSize(fFontSize);
778 }
779 }
780 }
781 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700782}
783
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700784void CPWL_Edit::SetLimitChar(int32_t nLimitChar) {
785 m_pEdit->SetLimitChar(nLimitChar);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700786}
787
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700788void CPWL_Edit::ReplaceSel(const FX_WCHAR* csText) {
789 m_pEdit->Clear();
790 m_pEdit->InsertText(csText);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700791}
792
Tom Sepez281a9ea2016-02-26 14:24:28 -0800793CFX_FloatRect CPWL_Edit::GetFocusRect() const {
794 return CFX_FloatRect();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700795}
796
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700797void CPWL_Edit::ShowVScrollBar(FX_BOOL bShow) {
798 if (CPWL_ScrollBar* pScroll = GetVScrollBar()) {
799 if (bShow) {
800 if (!pScroll->IsVisible()) {
801 pScroll->SetVisible(TRUE);
Tom Sepez281a9ea2016-02-26 14:24:28 -0800802 CFX_FloatRect rcWindow = GetWindowRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700803 m_rcOldWindow = rcWindow;
804 rcWindow.right += PWL_SCROLLBAR_WIDTH;
805 Move(rcWindow, TRUE, TRUE);
806 }
807 } else {
808 if (pScroll->IsVisible()) {
809 pScroll->SetVisible(FALSE);
810 Move(m_rcOldWindow, TRUE, TRUE);
811 }
812 }
813 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700814}
815
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700816FX_BOOL CPWL_Edit::IsVScrollBarVisible() const {
817 if (CPWL_ScrollBar* pScroll = GetVScrollBar()) {
818 return pScroll->IsVisible();
819 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700820
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700821 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700822}
823
tsepezc3255f52016-03-25 14:52:27 -0700824FX_BOOL CPWL_Edit::OnKeyDown(uint16_t nChar, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700825 if (m_bMouseDown)
826 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700827
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700828 if (nChar == FWL_VKEY_Delete) {
829 if (m_pFillerNotify) {
830 FX_BOOL bRC = TRUE;
831 FX_BOOL bExit = FALSE;
832 CFX_WideString strChange;
833 CFX_WideString strChangeEx;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700834
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700835 int nSelStart = 0;
836 int nSelEnd = 0;
837 GetSel(nSelStart, nSelEnd);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700838
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700839 if (nSelStart == nSelEnd)
840 nSelEnd = nSelStart + 1;
Lei Zhanga5b47042015-10-19 14:32:16 -0700841 m_pFillerNotify->OnBeforeKeyStroke(GetAttachedData(), strChange,
842 strChangeEx, nSelStart, nSelEnd, TRUE,
843 bRC, bExit, nFlag);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700844 if (!bRC)
845 return FALSE;
846 if (bExit)
847 return FALSE;
848 }
849 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700850
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700851 FX_BOOL bRet = CPWL_EditCtrl::OnKeyDown(nChar, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700852
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700853 // In case of implementation swallow the OnKeyDown event.
854 if (IsProceedtoOnChar(nChar, nFlag))
855 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700856
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700857 return bRet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700858}
859
860/**
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700861*In case of implementation swallow the OnKeyDown event.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700862*If the event is swallowed, implementation may do other unexpected things, which
863*is not the control means to do.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700864*/
tsepezc3255f52016-03-25 14:52:27 -0700865FX_BOOL CPWL_Edit::IsProceedtoOnChar(uint16_t nKeyCode, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700866 FX_BOOL bCtrl = IsCTRLpressed(nFlag);
867 FX_BOOL bAlt = IsALTpressed(nFlag);
868 if (bCtrl && !bAlt) {
869 // hot keys for edit control.
870 switch (nKeyCode) {
871 case 'C':
872 case 'V':
873 case 'X':
874 case 'A':
875 case 'Z':
876 return TRUE;
877 default:
878 break;
879 }
880 }
881 // control characters.
882 switch (nKeyCode) {
883 case FWL_VKEY_Escape:
884 case FWL_VKEY_Back:
885 case FWL_VKEY_Return:
886 case FWL_VKEY_Space:
887 return TRUE;
888 default:
Lei Zhanga5b47042015-10-19 14:32:16 -0700889 return FALSE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700890 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700891}
892
tsepezc3255f52016-03-25 14:52:27 -0700893FX_BOOL CPWL_Edit::OnChar(uint16_t nChar, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700894 if (m_bMouseDown)
895 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700896
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700897 FX_BOOL bRC = TRUE;
898 FX_BOOL bExit = FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700899
Lei Zhanga5b47042015-10-19 14:32:16 -0700900 if (!IsCTRLpressed(nFlag)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700901 if (m_pFillerNotify) {
902 CFX_WideString swChange;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700903
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700904 int nSelStart = 0;
905 int nSelEnd = 0;
906 GetSel(nSelStart, nSelEnd);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700907
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700908 switch (nChar) {
909 case FWL_VKEY_Back:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700910 if (nSelStart == nSelEnd)
911 nSelStart = nSelEnd - 1;
912 break;
913 case FWL_VKEY_Return:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700914 break;
915 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700916 swChange += nChar;
917 break;
918 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700919
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700920 CFX_WideString strChangeEx;
Lei Zhanga5b47042015-10-19 14:32:16 -0700921 m_pFillerNotify->OnBeforeKeyStroke(GetAttachedData(), swChange,
922 strChangeEx, nSelStart, nSelEnd, TRUE,
923 bRC, bExit, nFlag);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700924 }
925 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700926
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700927 if (!bRC)
928 return TRUE;
929 if (bExit)
930 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700931
dsinclairc7a73492016-04-05 12:01:42 -0700932 if (IPVT_FontMap* pFontMap = GetFontMap()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700933 int32_t nOldCharSet = GetCharSet();
934 int32_t nNewCharSet = pFontMap->CharSetFromUnicode(nChar, DEFAULT_CHARSET);
935 if (nOldCharSet != nNewCharSet) {
936 SetCharSet(nNewCharSet);
937 }
938 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700939
Lei Zhanga5b47042015-10-19 14:32:16 -0700940 return CPWL_EditCtrl::OnChar(nChar, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700941}
942
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700943FX_BOOL CPWL_Edit::OnMouseWheel(short zDelta,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800944 const CFX_FloatPoint& point,
tsepezc3255f52016-03-25 14:52:27 -0700945 uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700946 if (HasFlag(PES_MULTILINE)) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800947 CFX_FloatPoint ptScroll = GetScrollPos();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700948
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700949 if (zDelta > 0) {
950 ptScroll.y += GetFontSize();
951 } else {
952 ptScroll.y -= GetFontSize();
953 }
954 SetScrollPos(ptScroll);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700955
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700956 return TRUE;
957 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700958
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700959 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700960}
961
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700962void CPWL_Edit::OnInsertReturn(const CPVT_WordPlace& place,
963 const CPVT_WordPlace& oldplace) {
964 if (HasFlag(PES_SPELLCHECK)) {
965 m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace),
966 GetLatinWordsRange(place)));
967 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700968
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700969 if (m_pEditNotify) {
970 m_pEditNotify->OnInsertReturn(place, oldplace);
971 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700972}
973
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700974void CPWL_Edit::OnBackSpace(const CPVT_WordPlace& place,
975 const CPVT_WordPlace& oldplace) {
976 if (HasFlag(PES_SPELLCHECK)) {
977 m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace),
978 GetLatinWordsRange(place)));
979 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700980
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700981 if (m_pEditNotify) {
982 m_pEditNotify->OnBackSpace(place, oldplace);
983 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700984}
985
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700986void CPWL_Edit::OnDelete(const CPVT_WordPlace& place,
987 const CPVT_WordPlace& oldplace) {
988 if (HasFlag(PES_SPELLCHECK)) {
989 m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace),
990 GetLatinWordsRange(place)));
991 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700992
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700993 if (m_pEditNotify) {
994 m_pEditNotify->OnDelete(place, oldplace);
995 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700996}
997
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700998void CPWL_Edit::OnClear(const CPVT_WordPlace& place,
999 const CPVT_WordPlace& oldplace) {
1000 if (HasFlag(PES_SPELLCHECK)) {
1001 m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace),
1002 GetLatinWordsRange(place)));
1003 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001004
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001005 if (m_pEditNotify) {
1006 m_pEditNotify->OnClear(place, oldplace);
1007 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001008}
1009
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001010void CPWL_Edit::OnInsertWord(const CPVT_WordPlace& place,
1011 const CPVT_WordPlace& oldplace) {
1012 if (HasFlag(PES_SPELLCHECK)) {
1013 m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace),
1014 GetLatinWordsRange(place)));
1015 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001016
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001017 if (m_pEditNotify) {
1018 m_pEditNotify->OnInsertWord(place, oldplace);
1019 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001020}
1021
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001022void CPWL_Edit::OnSetText(const CPVT_WordPlace& place,
1023 const CPVT_WordPlace& oldplace) {}
1024
1025void CPWL_Edit::OnInsertText(const CPVT_WordPlace& place,
1026 const CPVT_WordPlace& oldplace) {
1027 if (HasFlag(PES_SPELLCHECK)) {
1028 m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace),
1029 GetLatinWordsRange(place)));
1030 }
1031
1032 if (m_pEditNotify) {
1033 m_pEditNotify->OnInsertText(place, oldplace);
1034 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001035}
1036
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001037void CPWL_Edit::OnAddUndo(IFX_Edit_UndoItem* pUndoItem) {
1038 if (m_pEditNotify) {
1039 m_pEditNotify->OnAddUndo(this);
1040 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001041}
1042
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001043CPVT_WordRange CPWL_Edit::CombineWordRange(const CPVT_WordRange& wr1,
1044 const CPVT_WordRange& wr2) {
1045 CPVT_WordRange wrRet;
1046
1047 if (wr1.BeginPos.WordCmp(wr2.BeginPos) < 0) {
1048 wrRet.BeginPos = wr1.BeginPos;
1049 } else {
1050 wrRet.BeginPos = wr2.BeginPos;
1051 }
1052
1053 if (wr1.EndPos.WordCmp(wr2.EndPos) < 0) {
1054 wrRet.EndPos = wr2.EndPos;
1055 } else {
1056 wrRet.EndPos = wr1.EndPos;
1057 }
1058
1059 return wrRet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001060}
1061
Tom Sepez281a9ea2016-02-26 14:24:28 -08001062CPVT_WordRange CPWL_Edit::GetLatinWordsRange(
1063 const CFX_FloatPoint& point) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001064 return GetSameWordsRange(m_pEdit->SearchWordPlace(point), TRUE, FALSE);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001065}
1066
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001067CPVT_WordRange CPWL_Edit::GetLatinWordsRange(
1068 const CPVT_WordPlace& place) const {
1069 return GetSameWordsRange(place, TRUE, FALSE);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001070}
1071
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001072CPVT_WordRange CPWL_Edit::GetArabicWordsRange(
1073 const CPVT_WordPlace& place) const {
1074 return GetSameWordsRange(place, FALSE, TRUE);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001075}
1076
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001077#define PWL_ISARABICWORD(word) \
1078 ((word >= 0x0600 && word <= 0x06FF) || (word >= 0xFB50 && word <= 0xFEFC))
1079
1080CPVT_WordRange CPWL_Edit::GetSameWordsRange(const CPVT_WordPlace& place,
1081 FX_BOOL bLatin,
1082 FX_BOOL bArabic) const {
1083 CPVT_WordRange range;
1084
1085 if (IFX_Edit_Iterator* pIterator = m_pEdit->GetIterator()) {
1086 CPVT_Word wordinfo;
1087 CPVT_WordPlace wpStart(place), wpEnd(place);
1088 pIterator->SetAt(place);
1089
1090 if (bLatin) {
1091 while (pIterator->NextWord()) {
Lei Zhangc2fb35f2016-01-05 16:46:58 -08001092 if (!pIterator->GetWord(wordinfo) ||
1093 !FX_EDIT_ISLATINWORD(wordinfo.Word)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001094 break;
Lei Zhangc2fb35f2016-01-05 16:46:58 -08001095 }
1096
1097 wpEnd = pIterator->GetAt();
1098 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001099 } else if (bArabic) {
1100 while (pIterator->NextWord()) {
Lei Zhangc2fb35f2016-01-05 16:46:58 -08001101 if (!pIterator->GetWord(wordinfo) || !PWL_ISARABICWORD(wordinfo.Word))
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001102 break;
Lei Zhangc2fb35f2016-01-05 16:46:58 -08001103
1104 wpEnd = pIterator->GetAt();
1105 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001106 }
1107
1108 pIterator->SetAt(place);
1109
1110 if (bLatin) {
1111 do {
Lei Zhangc2fb35f2016-01-05 16:46:58 -08001112 if (!pIterator->GetWord(wordinfo) ||
1113 !FX_EDIT_ISLATINWORD(wordinfo.Word)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001114 break;
1115 }
Lei Zhangc2fb35f2016-01-05 16:46:58 -08001116
1117 wpStart = pIterator->GetAt();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001118 } while (pIterator->PrevWord());
1119 } else if (bArabic) {
1120 do {
Lei Zhangc2fb35f2016-01-05 16:46:58 -08001121 if (!pIterator->GetWord(wordinfo) || !PWL_ISARABICWORD(wordinfo.Word))
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001122 break;
Lei Zhangc2fb35f2016-01-05 16:46:58 -08001123
1124 wpStart = pIterator->GetAt();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001125 } while (pIterator->PrevWord());
1126 }
1127
1128 range.Set(wpStart, wpEnd);
1129 }
1130
1131 return range;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001132}
1133
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001134void CPWL_Edit::GeneratePageObjects(
Tom Sepez2398d892016-02-17 16:46:26 -08001135 CPDF_PageObjectHolder* pObjectHolder,
Tom Sepez281a9ea2016-02-26 14:24:28 -08001136 const CFX_FloatPoint& ptOffset,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001137 CFX_ArrayTemplate<CPDF_TextObject*>& ObjArray) {
1138 IFX_Edit::GeneratePageObjects(
Tom Sepez2398d892016-02-17 16:46:26 -08001139 pObjectHolder, m_pEdit, ptOffset, NULL,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001140 CPWL_Utils::PWLColorToFXColor(GetTextColor(), GetTransparency()),
1141 ObjArray);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001142}
1143
Tom Sepez2398d892016-02-17 16:46:26 -08001144void CPWL_Edit::GeneratePageObjects(CPDF_PageObjectHolder* pObjectHolder,
Tom Sepez281a9ea2016-02-26 14:24:28 -08001145 const CFX_FloatPoint& ptOffset) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001146 CFX_ArrayTemplate<CPDF_TextObject*> ObjArray;
1147 IFX_Edit::GeneratePageObjects(
Tom Sepez2398d892016-02-17 16:46:26 -08001148 pObjectHolder, m_pEdit, ptOffset, NULL,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001149 CPWL_Utils::PWLColorToFXColor(GetTextColor(), GetTransparency()),
1150 ObjArray);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001151}