blob: 5d9c314a565bccb5a3f6faa611d7744b7e6aec9f [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
dsinclairbc5e6d22016-10-04 11:08:49 -070011#include "core/fpdfapi/font/cpdf_font.h"
dsinclair1727aee2016-09-29 13:12:56 -070012#include "core/fpdfdoc/cpvt_word.h"
dsinclaira52ab742016-09-29 13:59:29 -070013#include "core/fxcrt/fx_safe_types.h"
14#include "core/fxcrt/fx_xml.h"
dsinclair74a34fc2016-09-29 16:41:42 -070015#include "core/fxge/cfx_graphstatedata.h"
16#include "core/fxge/cfx_pathdata.h"
17#include "core/fxge/cfx_renderdevice.h"
18#include "core/fxge/fx_font.h"
dsinclair0bb385b2016-09-29 17:03:59 -070019#include "fpdfsdk/fxedit/fxet_edit.h"
dan sinclair89e904b2016-03-23 19:29:15 -040020#include "fpdfsdk/pdfwindow/PWL_Caret.h"
21#include "fpdfsdk/pdfwindow/PWL_EditCtrl.h"
22#include "fpdfsdk/pdfwindow/PWL_FontMap.h"
23#include "fpdfsdk/pdfwindow/PWL_ScrollBar.h"
24#include "fpdfsdk/pdfwindow/PWL_Utils.h"
25#include "fpdfsdk/pdfwindow/PWL_Wnd.h"
Lei Zhangc2fb35f2016-01-05 16:46:58 -080026#include "public/fpdf_fwlevent.h"
Tom Sepezab277682016-02-17 10:07:21 -080027#include "third_party/base/stl_util.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070028
Nico Weber9d8ec5a2015-08-04 13:00:21 -070029CPWL_Edit::CPWL_Edit()
tsepez4cf55152016-11-02 14:37:54 -070030 : m_pFillerNotify(nullptr), m_bFocus(false), m_pFormFiller(nullptr) {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070031
Nico Weber9d8ec5a2015-08-04 13:00:21 -070032CPWL_Edit::~CPWL_Edit() {
tsepez4cf55152016-11-02 14:37:54 -070033 ASSERT(m_bFocus == false);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070034}
35
Nico Weber9d8ec5a2015-08-04 13:00:21 -070036CFX_ByteString CPWL_Edit::GetClassName() const {
37 return PWL_CLASSNAME_EDIT;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070038}
39
Nico Weber9d8ec5a2015-08-04 13:00:21 -070040void CPWL_Edit::OnDestroy() {}
41
tsepez067990c2016-09-13 06:46:40 -070042void CPWL_Edit::SetText(const CFX_WideString& csText) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070043 CFX_WideString swText = csText;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070044 if (HasFlag(PES_RICH)) {
45 CFX_ByteString sValue = CFX_ByteString::FromUnicode(swText);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070046 if (CXML_Element* pXML =
47 CXML_Element::Parse(sValue.c_str(), sValue.GetLength())) {
48 int32_t nCount = pXML->CountChildren();
tsepez4cf55152016-11-02 14:37:54 -070049 bool bFirst = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070050
tsepez774bdde2016-04-14 09:49:44 -070051 swText.clear();
Nico Weber9d8ec5a2015-08-04 13:00:21 -070052
53 for (int32_t i = 0; i < nCount; i++) {
54 if (CXML_Element* pSubElement = pXML->GetElement(i)) {
55 CFX_ByteString tag = pSubElement->GetTagName();
56 if (tag.EqualNoCase("p")) {
57 int nChild = pSubElement->CountChildren();
58 CFX_WideString swSection;
59 for (int32_t j = 0; j < nChild; j++) {
60 swSection += pSubElement->GetContent(j);
61 }
62
63 if (bFirst)
tsepez4cf55152016-11-02 14:37:54 -070064 bFirst = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070065 else
66 swText += FWL_VKEY_Return;
67 swText += swSection;
68 }
69 }
70 }
71
72 delete pXML;
73 }
74 }
75
tsepez067990c2016-09-13 06:46:40 -070076 m_pEdit->SetText(swText);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070077}
78
Nico Weber9d8ec5a2015-08-04 13:00:21 -070079void CPWL_Edit::RePosChildWnd() {
80 if (CPWL_ScrollBar* pVSB = GetVScrollBar()) {
Tom Sepez281a9ea2016-02-26 14:24:28 -080081 CFX_FloatRect rcWindow = m_rcOldWindow;
82 CFX_FloatRect rcVScroll =
83 CFX_FloatRect(rcWindow.right, rcWindow.bottom,
84 rcWindow.right + PWL_SCROLLBAR_WIDTH, rcWindow.top);
tsepez4cf55152016-11-02 14:37:54 -070085 pVSB->Move(rcVScroll, true, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070086 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070087
Nico Weber9d8ec5a2015-08-04 13:00:21 -070088 if (m_pEditCaret && !HasFlag(PES_TEXTOVERFLOW))
89 m_pEditCaret->SetClipRect(CPWL_Utils::InflateRect(
Dan Sinclair50cce602016-02-24 09:51:16 -050090 GetClientRect(), 1.0f)); // +1 for caret beside border
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070091
Nico Weber9d8ec5a2015-08-04 13:00:21 -070092 CPWL_EditCtrl::RePosChildWnd();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070093}
94
Tom Sepez281a9ea2016-02-26 14:24:28 -080095CFX_FloatRect CPWL_Edit::GetClientRect() const {
96 CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(
Nico Weber9d8ec5a2015-08-04 13:00:21 -070097 GetWindowRect(), (FX_FLOAT)(GetBorderWidth() + GetInnerBorderWidth()));
98
99 if (CPWL_ScrollBar* pVSB = GetVScrollBar()) {
100 if (pVSB->IsVisible()) {
101 rcClient.right -= PWL_SCROLLBAR_WIDTH;
102 }
103 }
104
105 return rcClient;
106}
107
tsepez4cf55152016-11-02 14:37:54 -0700108void CPWL_Edit::SetAlignFormatV(PWL_EDIT_ALIGNFORMAT_V nFormat, bool bPaint) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700109 m_pEdit->SetAlignmentV((int32_t)nFormat, bPaint);
110}
111
tsepez4cf55152016-11-02 14:37:54 -0700112bool CPWL_Edit::CanSelectAll() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700113 return GetSelectWordRange() != m_pEdit->GetWholeWordRange();
114}
115
tsepez4cf55152016-11-02 14:37:54 -0700116bool CPWL_Edit::CanClear() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700117 return !IsReadOnly() && m_pEdit->IsSelected();
118}
119
tsepez4cf55152016-11-02 14:37:54 -0700120bool CPWL_Edit::CanCopy() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700121 return !HasFlag(PES_PASSWORD) && !HasFlag(PES_NOREAD) &&
122 m_pEdit->IsSelected();
123}
124
tsepez4cf55152016-11-02 14:37:54 -0700125bool CPWL_Edit::CanCut() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700126 return CanCopy() && !IsReadOnly();
127}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700128void CPWL_Edit::CutText() {
129 if (!CanCut())
130 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700131 m_pEdit->Clear();
132}
133
134void CPWL_Edit::OnCreated() {
135 CPWL_EditCtrl::OnCreated();
136
137 if (CPWL_ScrollBar* pScroll = GetVScrollBar()) {
138 pScroll->RemoveFlag(PWS_AUTOTRANSPARENT);
139 pScroll->SetTransparency(255);
140 }
141
142 SetParamByFlag();
143
144 m_rcOldWindow = GetWindowRect();
145
146 m_pEdit->SetOprNotify(this);
tsepez4cf55152016-11-02 14:37:54 -0700147 m_pEdit->EnableOprNotify(true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700148}
149
150void CPWL_Edit::SetParamByFlag() {
151 if (HasFlag(PES_RIGHT)) {
tsepez4cf55152016-11-02 14:37:54 -0700152 m_pEdit->SetAlignmentH(2, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700153 } else if (HasFlag(PES_MIDDLE)) {
tsepez4cf55152016-11-02 14:37:54 -0700154 m_pEdit->SetAlignmentH(1, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700155 } else {
tsepez4cf55152016-11-02 14:37:54 -0700156 m_pEdit->SetAlignmentH(0, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700157 }
158
159 if (HasFlag(PES_BOTTOM)) {
tsepez4cf55152016-11-02 14:37:54 -0700160 m_pEdit->SetAlignmentV(2, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700161 } else if (HasFlag(PES_CENTER)) {
tsepez4cf55152016-11-02 14:37:54 -0700162 m_pEdit->SetAlignmentV(1, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700163 } else {
tsepez4cf55152016-11-02 14:37:54 -0700164 m_pEdit->SetAlignmentV(0, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700165 }
166
167 if (HasFlag(PES_PASSWORD)) {
tsepez4cf55152016-11-02 14:37:54 -0700168 m_pEdit->SetPasswordChar('*', false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700169 }
170
tsepez4cf55152016-11-02 14:37:54 -0700171 m_pEdit->SetMultiLine(HasFlag(PES_MULTILINE), false);
172 m_pEdit->SetAutoReturn(HasFlag(PES_AUTORETURN), false);
173 m_pEdit->SetAutoFontSize(HasFlag(PWS_AUTOFONTSIZE), false);
174 m_pEdit->SetAutoScroll(HasFlag(PES_AUTOSCROLL), false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700175 m_pEdit->EnableUndo(HasFlag(PES_UNDO));
176
177 if (HasFlag(PES_TEXTOVERFLOW)) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800178 SetClipRect(CFX_FloatRect(0.0f, 0.0f, 0.0f, 0.0f));
tsepez4cf55152016-11-02 14:37:54 -0700179 m_pEdit->SetTextOverflow(true, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700180 } else {
181 if (m_pEditCaret) {
182 m_pEditCaret->SetClipRect(CPWL_Utils::InflateRect(
Dan Sinclair50cce602016-02-24 09:51:16 -0500183 GetClientRect(), 1.0f)); // +1 for caret beside border
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700184 }
185 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700186}
187
188void CPWL_Edit::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) {
189 CPWL_Wnd::GetThisAppearanceStream(sAppStream);
190
Tom Sepez281a9ea2016-02-26 14:24:28 -0800191 CFX_FloatRect rcClient = GetClientRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700192 CFX_ByteTextBuf sLine;
193
194 int32_t nCharArray = m_pEdit->GetCharArray();
195
196 if (nCharArray > 0) {
197 switch (GetBorderStyle()) {
dsinclair92cb5e52016-05-16 11:38:28 -0700198 case BorderStyle::SOLID: {
tsepez4cf55152016-11-02 14:37:54 -0700199 sLine << "q\n"
200 << GetBorderWidth() << " w\n"
201 << CPWL_Utils::GetColorAppStream(GetBorderColor(), false)
tsepez4c3debb2016-04-08 12:20:38 -0700202 .AsStringC()
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700203 << " 2 J 0 j\n";
204
205 for (int32_t i = 1; i < nCharArray; i++) {
206 sLine << rcClient.left +
207 ((rcClient.right - rcClient.left) / nCharArray) * i
208 << " " << rcClient.bottom << " m\n"
209 << rcClient.left +
210 ((rcClient.right - rcClient.left) / nCharArray) * i
211 << " " << rcClient.top << " l S\n";
212 }
213
214 sLine << "Q\n";
dsinclair92cb5e52016-05-16 11:38:28 -0700215 break;
216 }
217 case BorderStyle::DASH: {
tsepez4cf55152016-11-02 14:37:54 -0700218 sLine << "q\n"
219 << GetBorderWidth() << " w\n"
220 << CPWL_Utils::GetColorAppStream(GetBorderColor(), false)
tsepez4c3debb2016-04-08 12:20:38 -0700221 .AsStringC()
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700222 << " 2 J 0 j\n"
223 << "[" << GetBorderDash().nDash << " " << GetBorderDash().nGap
224 << "] " << GetBorderDash().nPhase << " d\n";
225
226 for (int32_t i = 1; i < nCharArray; i++) {
227 sLine << rcClient.left +
228 ((rcClient.right - rcClient.left) / nCharArray) * i
229 << " " << rcClient.bottom << " m\n"
230 << rcClient.left +
231 ((rcClient.right - rcClient.left) / nCharArray) * i
232 << " " << rcClient.top << " l S\n";
233 }
234
235 sLine << "Q\n";
dsinclair92cb5e52016-05-16 11:38:28 -0700236 break;
237 }
238 default:
239 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700240 }
241 }
242
243 sAppStream << sLine;
244
245 CFX_ByteTextBuf sText;
Dan Sinclairf528eee2017-02-14 11:52:07 -0500246 CFX_PointF ptOffset;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700247 CPVT_WordRange wrWhole = m_pEdit->GetWholeWordRange();
248 CPVT_WordRange wrSelect = GetSelectWordRange();
249 CPVT_WordRange wrVisible =
tsepez63f545c2016-09-13 16:08:49 -0700250 HasFlag(PES_TEXTOVERFLOW) ? wrWhole : m_pEdit->GetVisibleWordRange();
251
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700252 CPVT_WordRange wrSelBefore(wrWhole.BeginPos, wrSelect.BeginPos);
253 CPVT_WordRange wrSelAfter(wrSelect.EndPos, wrWhole.EndPos);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700254 CPVT_WordRange wrTemp =
255 CPWL_Utils::OverlapWordRange(GetSelectWordRange(), wrVisible);
256 CFX_ByteString sEditSel =
dsinclaire35af1e2016-07-13 11:26:20 -0700257 CPWL_Utils::GetEditSelAppStream(m_pEdit.get(), ptOffset, &wrTemp);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700258
259 if (sEditSel.GetLength() > 0)
tsepez4c3debb2016-04-08 12:20:38 -0700260 sText << CPWL_Utils::GetColorAppStream(PWL_DEFAULT_SELBACKCOLOR).AsStringC()
261 << sEditSel.AsStringC();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700262
263 wrTemp = CPWL_Utils::OverlapWordRange(wrVisible, wrSelBefore);
264 CFX_ByteString sEditBefore = CPWL_Utils::GetEditAppStream(
dsinclaire35af1e2016-07-13 11:26:20 -0700265 m_pEdit.get(), ptOffset, &wrTemp, !HasFlag(PES_CHARARRAY),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700266 m_pEdit->GetPasswordChar());
267
268 if (sEditBefore.GetLength() > 0)
tsepez4c3debb2016-04-08 12:20:38 -0700269 sText << "BT\n" << CPWL_Utils::GetColorAppStream(GetTextColor()).AsStringC()
270 << sEditBefore.AsStringC() << "ET\n";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700271
272 wrTemp = CPWL_Utils::OverlapWordRange(wrVisible, wrSelect);
273 CFX_ByteString sEditMid = CPWL_Utils::GetEditAppStream(
dsinclaire35af1e2016-07-13 11:26:20 -0700274 m_pEdit.get(), ptOffset, &wrTemp, !HasFlag(PES_CHARARRAY),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700275 m_pEdit->GetPasswordChar());
276
277 if (sEditMid.GetLength() > 0)
278 sText << "BT\n"
279 << CPWL_Utils::GetColorAppStream(CPWL_Color(COLORTYPE_GRAY, 1))
tsepez4c3debb2016-04-08 12:20:38 -0700280 .AsStringC()
281 << sEditMid.AsStringC() << "ET\n";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700282
283 wrTemp = CPWL_Utils::OverlapWordRange(wrVisible, wrSelAfter);
284 CFX_ByteString sEditAfter = CPWL_Utils::GetEditAppStream(
dsinclaire35af1e2016-07-13 11:26:20 -0700285 m_pEdit.get(), ptOffset, &wrTemp, !HasFlag(PES_CHARARRAY),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700286 m_pEdit->GetPasswordChar());
287
288 if (sEditAfter.GetLength() > 0)
tsepez4c3debb2016-04-08 12:20:38 -0700289 sText << "BT\n" << CPWL_Utils::GetColorAppStream(GetTextColor()).AsStringC()
290 << sEditAfter.AsStringC() << "ET\n";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700291
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700292 if (sText.GetLength() > 0) {
weilidb444d22016-06-02 15:48:15 -0700293 CFX_FloatRect rect = GetClientRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700294 sAppStream << "q\n/Tx BMC\n";
295
296 if (!HasFlag(PES_TEXTOVERFLOW))
weilidb444d22016-06-02 15:48:15 -0700297 sAppStream << rect.left << " " << rect.bottom << " "
298 << rect.right - rect.left << " " << rect.top - rect.bottom
299 << " re W n\n";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700300
301 sAppStream << sText;
302
303 sAppStream << "EMC\nQ\n";
304 }
305}
306
307void CPWL_Edit::DrawThisAppearance(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800308 CFX_Matrix* pUser2Device) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700309 CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device);
310
Tom Sepez281a9ea2016-02-26 14:24:28 -0800311 CFX_FloatRect rcClient = GetClientRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700312 CFX_ByteTextBuf sLine;
313
314 int32_t nCharArray = m_pEdit->GetCharArray();
315 FX_SAFE_INT32 nCharArraySafe = nCharArray;
316 nCharArraySafe -= 1;
317 nCharArraySafe *= 2;
318
319 if (nCharArray > 0 && nCharArraySafe.IsValid()) {
320 switch (GetBorderStyle()) {
dsinclair92cb5e52016-05-16 11:38:28 -0700321 case BorderStyle::SOLID: {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700322 CFX_GraphStateData gsd;
323 gsd.m_LineWidth = (FX_FLOAT)GetBorderWidth();
324
325 CFX_PathData path;
326 path.SetPointCount(nCharArraySafe.ValueOrDie());
327
328 for (int32_t i = 0; i < nCharArray - 1; i++) {
329 path.SetPoint(
330 i * 2,
331 rcClient.left +
332 ((rcClient.right - rcClient.left) / nCharArray) * (i + 1),
Nicolas Pena79365f72017-02-07 14:21:36 -0500333 rcClient.bottom, FXPT_TYPE::MoveTo, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700334 path.SetPoint(
335 i * 2 + 1,
336 rcClient.left +
337 ((rcClient.right - rcClient.left) / nCharArray) * (i + 1),
Nicolas Pena79365f72017-02-07 14:21:36 -0500338 rcClient.top, FXPT_TYPE::LineTo, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700339 }
dsinclair92cb5e52016-05-16 11:38:28 -0700340 if (path.GetPointCount() > 0) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700341 pDevice->DrawPath(
342 &path, pUser2Device, &gsd, 0,
343 CPWL_Utils::PWLColorToFXColor(GetBorderColor(), 255),
344 FXFILL_ALTERNATE);
dsinclair92cb5e52016-05-16 11:38:28 -0700345 }
346 break;
347 }
348 case BorderStyle::DASH: {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700349 CFX_GraphStateData gsd;
350 gsd.m_LineWidth = (FX_FLOAT)GetBorderWidth();
351
352 gsd.SetDashCount(2);
353 gsd.m_DashArray[0] = (FX_FLOAT)GetBorderDash().nDash;
354 gsd.m_DashArray[1] = (FX_FLOAT)GetBorderDash().nGap;
355 gsd.m_DashPhase = (FX_FLOAT)GetBorderDash().nPhase;
356
357 CFX_PathData path;
358 path.SetPointCount(nCharArraySafe.ValueOrDie());
359
360 for (int32_t i = 0; i < nCharArray - 1; i++) {
361 path.SetPoint(
362 i * 2,
363 rcClient.left +
364 ((rcClient.right - rcClient.left) / nCharArray) * (i + 1),
Nicolas Pena79365f72017-02-07 14:21:36 -0500365 rcClient.bottom, FXPT_TYPE::MoveTo, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700366 path.SetPoint(
367 i * 2 + 1,
368 rcClient.left +
369 ((rcClient.right - rcClient.left) / nCharArray) * (i + 1),
Nicolas Pena79365f72017-02-07 14:21:36 -0500370 rcClient.top, FXPT_TYPE::LineTo, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700371 }
dsinclair92cb5e52016-05-16 11:38:28 -0700372 if (path.GetPointCount() > 0) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700373 pDevice->DrawPath(
374 &path, pUser2Device, &gsd, 0,
375 CPWL_Utils::PWLColorToFXColor(GetBorderColor(), 255),
376 FXFILL_ALTERNATE);
dsinclair92cb5e52016-05-16 11:38:28 -0700377 }
378 break;
379 }
380 default:
381 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700382 }
383 }
384
Tom Sepez281a9ea2016-02-26 14:24:28 -0800385 CFX_FloatRect rcClip;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700386 CPVT_WordRange wrRange = m_pEdit->GetVisibleWordRange();
thestig1cd352e2016-06-07 17:53:06 -0700387 CPVT_WordRange* pRange = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700388 if (!HasFlag(PES_TEXTOVERFLOW)) {
389 rcClip = GetClientRect();
390 pRange = &wrRange;
391 }
tsepez63f545c2016-09-13 16:08:49 -0700392
dsinclairb9590102016-04-27 06:38:59 -0700393 CFX_SystemHandler* pSysHandler = GetSystemHandler();
dsinclaire35af1e2016-07-13 11:26:20 -0700394 CFX_Edit::DrawEdit(
395 pDevice, pUser2Device, m_pEdit.get(),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700396 CPWL_Utils::PWLColorToFXColor(GetTextColor(), GetTransparency()),
397 CPWL_Utils::PWLColorToFXColor(GetTextStrokeColor(), GetTransparency()),
Dan Sinclairf528eee2017-02-14 11:52:07 -0500398 rcClip, CFX_PointF(), pRange, pSysHandler, m_pFormFiller);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700399}
400
Dan Sinclairf528eee2017-02-14 11:52:07 -0500401bool CPWL_Edit::OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700402 CPWL_Wnd::OnLButtonDown(point, nFlag);
403
404 if (HasFlag(PES_TEXTOVERFLOW) || ClientHitTest(point)) {
405 if (m_bMouseDown)
406 InvalidateRect();
407
tsepez4cf55152016-11-02 14:37:54 -0700408 m_bMouseDown = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700409 SetCapture();
410
411 m_pEdit->OnMouseDown(point, IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
412 }
413
tsepez4cf55152016-11-02 14:37:54 -0700414 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700415}
416
Dan Sinclairf528eee2017-02-14 11:52:07 -0500417bool CPWL_Edit::OnLButtonDblClk(const CFX_PointF& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700418 CPWL_Wnd::OnLButtonDblClk(point, nFlag);
419
420 if (HasFlag(PES_TEXTOVERFLOW) || ClientHitTest(point)) {
421 m_pEdit->SelectAll();
422 }
423
tsepez4cf55152016-11-02 14:37:54 -0700424 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700425}
426
Dan Sinclairf528eee2017-02-14 11:52:07 -0500427bool CPWL_Edit::OnRButtonUp(const CFX_PointF& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700428 if (m_bMouseDown)
tsepez4cf55152016-11-02 14:37:54 -0700429 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700430
431 CPWL_Wnd::OnRButtonUp(point, nFlag);
432
433 if (!HasFlag(PES_TEXTOVERFLOW) && !ClientHitTest(point))
tsepez4cf55152016-11-02 14:37:54 -0700434 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700435
dsinclairb9590102016-04-27 06:38:59 -0700436 CFX_SystemHandler* pSH = GetSystemHandler();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700437 if (!pSH)
tsepez4cf55152016-11-02 14:37:54 -0700438 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700439
440 SetFocus();
441
tsepez4cf55152016-11-02 14:37:54 -0700442 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700443}
444
445void CPWL_Edit::OnSetFocus() {
tsepez4cf55152016-11-02 14:37:54 -0700446 SetEditCaret(true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700447 if (!IsReadOnly()) {
448 if (IPWL_FocusHandler* pFocusHandler = GetFocusHandler())
449 pFocusHandler->OnSetFocus(this);
450 }
tsepez4cf55152016-11-02 14:37:54 -0700451 m_bFocus = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700452}
453
454void CPWL_Edit::OnKillFocus() {
tsepez4cf55152016-11-02 14:37:54 -0700455 ShowVScrollBar(false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700456 m_pEdit->SelectNone();
Dan Sinclairf528eee2017-02-14 11:52:07 -0500457 SetCaret(false, CFX_PointF(), CFX_PointF());
thestig907a5222016-06-21 14:38:27 -0700458 SetCharSet(FXFONT_ANSI_CHARSET);
tsepez4cf55152016-11-02 14:37:54 -0700459 m_bFocus = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700460}
461
dsinclairefd5a992016-07-18 10:04:07 -0700462void CPWL_Edit::SetCharSpace(FX_FLOAT fCharSpace) {
463 m_pEdit->SetCharSpace(fCharSpace);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700464}
465
466CFX_ByteString CPWL_Edit::GetSelectAppearanceStream(
Dan Sinclairf528eee2017-02-14 11:52:07 -0500467 const CFX_PointF& ptOffset) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700468 CPVT_WordRange wr = GetSelectWordRange();
dsinclaire35af1e2016-07-13 11:26:20 -0700469 return CPWL_Utils::GetEditSelAppStream(m_pEdit.get(), ptOffset, &wr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700470}
471
472CPVT_WordRange CPWL_Edit::GetSelectWordRange() const {
473 if (m_pEdit->IsSelected()) {
474 int32_t nStart = -1;
475 int32_t nEnd = -1;
476
477 m_pEdit->GetSel(nStart, nEnd);
478
479 CPVT_WordPlace wpStart = m_pEdit->WordIndexToWordPlace(nStart);
480 CPVT_WordPlace wpEnd = m_pEdit->WordIndexToWordPlace(nEnd);
481
482 return CPVT_WordRange(wpStart, wpEnd);
483 }
484
485 return CPVT_WordRange();
486}
487
488CFX_ByteString CPWL_Edit::GetTextAppearanceStream(
Dan Sinclairf528eee2017-02-14 11:52:07 -0500489 const CFX_PointF& ptOffset) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700490 CFX_ByteTextBuf sRet;
dsinclaire35af1e2016-07-13 11:26:20 -0700491 CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream(m_pEdit.get(), ptOffset);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700492 if (sEdit.GetLength() > 0) {
tsepez4c3debb2016-04-08 12:20:38 -0700493 sRet << "BT\n" << CPWL_Utils::GetColorAppStream(GetTextColor()).AsStringC()
494 << sEdit.AsStringC() << "ET\n";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700495 }
tsepez71a452f2016-05-13 17:51:27 -0700496 return sRet.MakeString();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700497}
498
499CFX_ByteString CPWL_Edit::GetCaretAppearanceStream(
Dan Sinclairf528eee2017-02-14 11:52:07 -0500500 const CFX_PointF& ptOffset) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700501 if (m_pEditCaret)
502 return m_pEditCaret->GetCaretAppearanceStream(ptOffset);
503
504 return CFX_ByteString();
505}
506
Dan Sinclairf528eee2017-02-14 11:52:07 -0500507CFX_PointF CPWL_Edit::GetWordRightBottomPoint(const CPVT_WordPlace& wpWord) {
dsinclaire35af1e2016-07-13 11:26:20 -0700508 CFX_Edit_Iterator* pIterator = m_pEdit->GetIterator();
thestig821d59e2016-05-11 12:59:22 -0700509 CPVT_WordPlace wpOld = pIterator->GetAt();
510 pIterator->SetAt(wpWord);
tsepez63f545c2016-09-13 16:08:49 -0700511
Dan Sinclairf528eee2017-02-14 11:52:07 -0500512 CFX_PointF pt;
thestig821d59e2016-05-11 12:59:22 -0700513 CPVT_Word word;
514 if (pIterator->GetWord(word)) {
Dan Sinclairf528eee2017-02-14 11:52:07 -0500515 pt = CFX_PointF(word.ptWord.x + word.fWidth, word.ptWord.y + word.fDescent);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700516 }
thestig821d59e2016-05-11 12:59:22 -0700517 pIterator->SetAt(wpOld);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700518 return pt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700519}
520
tsepez4cf55152016-11-02 14:37:54 -0700521bool CPWL_Edit::IsTextFull() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700522 return m_pEdit->IsTextFull();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700523}
524
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700525FX_FLOAT CPWL_Edit::GetCharArrayAutoFontSize(CPDF_Font* pFont,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800526 const CFX_FloatRect& rcPlate,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700527 int32_t nCharArray) {
528 if (pFont && !pFont->IsStandardFont()) {
529 FX_RECT rcBBox;
530 pFont->GetFontBBox(rcBBox);
531
Tom Sepez281a9ea2016-02-26 14:24:28 -0800532 CFX_FloatRect rcCell = rcPlate;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700533 FX_FLOAT xdiv = rcCell.Width() / nCharArray * 1000.0f / rcBBox.Width();
534 FX_FLOAT ydiv = -rcCell.Height() * 1000.0f / rcBBox.Height();
535
536 return xdiv < ydiv ? xdiv : ydiv;
537 }
538
539 return 0.0f;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700540}
541
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700542void CPWL_Edit::SetCharArray(int32_t nCharArray) {
543 if (HasFlag(PES_CHARARRAY) && nCharArray > 0) {
544 m_pEdit->SetCharArray(nCharArray);
tsepez4cf55152016-11-02 14:37:54 -0700545 m_pEdit->SetTextOverflow(true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700546
547 if (HasFlag(PWS_AUTOFONTSIZE)) {
dsinclairc7a73492016-04-05 12:01:42 -0700548 if (IPVT_FontMap* pFontMap = GetFontMap()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700549 FX_FLOAT fFontSize = GetCharArrayAutoFontSize(
550 pFontMap->GetPDFFont(0), GetClientRect(), nCharArray);
551 if (fFontSize > 0.0f) {
tsepez4cf55152016-11-02 14:37:54 -0700552 m_pEdit->SetAutoFontSize(false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700553 m_pEdit->SetFontSize(fFontSize);
554 }
555 }
556 }
557 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700558}
559
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700560void CPWL_Edit::SetLimitChar(int32_t nLimitChar) {
561 m_pEdit->SetLimitChar(nLimitChar);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700562}
563
tsepez067990c2016-09-13 06:46:40 -0700564void CPWL_Edit::ReplaceSel(const CFX_WideString& wsText) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700565 m_pEdit->Clear();
npmea3c3be2016-09-19 07:24:33 -0700566 m_pEdit->InsertText(wsText, FXFONT_DEFAULT_CHARSET);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700567}
568
Tom Sepez281a9ea2016-02-26 14:24:28 -0800569CFX_FloatRect CPWL_Edit::GetFocusRect() const {
570 return CFX_FloatRect();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700571}
572
tsepez4cf55152016-11-02 14:37:54 -0700573void CPWL_Edit::ShowVScrollBar(bool bShow) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700574 if (CPWL_ScrollBar* pScroll = GetVScrollBar()) {
575 if (bShow) {
576 if (!pScroll->IsVisible()) {
tsepez4cf55152016-11-02 14:37:54 -0700577 pScroll->SetVisible(true);
Tom Sepez281a9ea2016-02-26 14:24:28 -0800578 CFX_FloatRect rcWindow = GetWindowRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700579 m_rcOldWindow = rcWindow;
580 rcWindow.right += PWL_SCROLLBAR_WIDTH;
tsepez4cf55152016-11-02 14:37:54 -0700581 Move(rcWindow, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700582 }
583 } else {
584 if (pScroll->IsVisible()) {
tsepez4cf55152016-11-02 14:37:54 -0700585 pScroll->SetVisible(false);
586 Move(m_rcOldWindow, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700587 }
588 }
589 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700590}
591
tsepez4cf55152016-11-02 14:37:54 -0700592bool CPWL_Edit::IsVScrollBarVisible() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700593 if (CPWL_ScrollBar* pScroll = GetVScrollBar()) {
594 return pScroll->IsVisible();
595 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700596
tsepez4cf55152016-11-02 14:37:54 -0700597 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700598}
599
tsepez4cf55152016-11-02 14:37:54 -0700600bool CPWL_Edit::OnKeyDown(uint16_t nChar, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700601 if (m_bMouseDown)
tsepez4cf55152016-11-02 14:37:54 -0700602 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700603
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700604 if (nChar == FWL_VKEY_Delete) {
605 if (m_pFillerNotify) {
tsepez4cf55152016-11-02 14:37:54 -0700606 bool bRC = true;
607 bool bExit = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700608 CFX_WideString strChange;
609 CFX_WideString strChangeEx;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700610
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700611 int nSelStart = 0;
612 int nSelEnd = 0;
613 GetSel(nSelStart, nSelEnd);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700614
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700615 if (nSelStart == nSelEnd)
616 nSelEnd = nSelStart + 1;
Lei Zhanga5b47042015-10-19 14:32:16 -0700617 m_pFillerNotify->OnBeforeKeyStroke(GetAttachedData(), strChange,
tsepez4cf55152016-11-02 14:37:54 -0700618 strChangeEx, nSelStart, nSelEnd, true,
Lei Zhanga5b47042015-10-19 14:32:16 -0700619 bRC, bExit, nFlag);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700620 if (!bRC)
tsepez4cf55152016-11-02 14:37:54 -0700621 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700622 if (bExit)
tsepez4cf55152016-11-02 14:37:54 -0700623 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700624 }
625 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700626
tsepez4cf55152016-11-02 14:37:54 -0700627 bool bRet = CPWL_EditCtrl::OnKeyDown(nChar, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700628
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700629 // In case of implementation swallow the OnKeyDown event.
630 if (IsProceedtoOnChar(nChar, nFlag))
tsepez4cf55152016-11-02 14:37:54 -0700631 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700632
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700633 return bRet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700634}
635
636/**
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700637*In case of implementation swallow the OnKeyDown event.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700638*If the event is swallowed, implementation may do other unexpected things, which
639*is not the control means to do.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700640*/
tsepez4cf55152016-11-02 14:37:54 -0700641bool CPWL_Edit::IsProceedtoOnChar(uint16_t nKeyCode, uint32_t nFlag) {
642 bool bCtrl = IsCTRLpressed(nFlag);
643 bool bAlt = IsALTpressed(nFlag);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700644 if (bCtrl && !bAlt) {
645 // hot keys for edit control.
646 switch (nKeyCode) {
647 case 'C':
648 case 'V':
649 case 'X':
650 case 'A':
651 case 'Z':
tsepez4cf55152016-11-02 14:37:54 -0700652 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700653 default:
654 break;
655 }
656 }
657 // control characters.
658 switch (nKeyCode) {
659 case FWL_VKEY_Escape:
660 case FWL_VKEY_Back:
661 case FWL_VKEY_Return:
662 case FWL_VKEY_Space:
tsepez4cf55152016-11-02 14:37:54 -0700663 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700664 default:
tsepez4cf55152016-11-02 14:37:54 -0700665 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700666 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700667}
668
tsepez4cf55152016-11-02 14:37:54 -0700669bool CPWL_Edit::OnChar(uint16_t nChar, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700670 if (m_bMouseDown)
tsepez4cf55152016-11-02 14:37:54 -0700671 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700672
tsepez4cf55152016-11-02 14:37:54 -0700673 bool bRC = true;
674 bool bExit = false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700675
Lei Zhanga5b47042015-10-19 14:32:16 -0700676 if (!IsCTRLpressed(nFlag)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700677 if (m_pFillerNotify) {
678 CFX_WideString swChange;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700679
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700680 int nSelStart = 0;
681 int nSelEnd = 0;
682 GetSel(nSelStart, nSelEnd);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700683
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700684 switch (nChar) {
685 case FWL_VKEY_Back:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700686 if (nSelStart == nSelEnd)
687 nSelStart = nSelEnd - 1;
688 break;
689 case FWL_VKEY_Return:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700690 break;
691 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700692 swChange += nChar;
693 break;
694 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700695
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700696 CFX_WideString strChangeEx;
Lei Zhanga5b47042015-10-19 14:32:16 -0700697 m_pFillerNotify->OnBeforeKeyStroke(GetAttachedData(), swChange,
tsepez4cf55152016-11-02 14:37:54 -0700698 strChangeEx, nSelStart, nSelEnd, true,
Lei Zhanga5b47042015-10-19 14:32:16 -0700699 bRC, bExit, nFlag);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700700 }
701 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700702
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700703 if (!bRC)
tsepez4cf55152016-11-02 14:37:54 -0700704 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700705 if (bExit)
tsepez4cf55152016-11-02 14:37:54 -0700706 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700707
dsinclairc7a73492016-04-05 12:01:42 -0700708 if (IPVT_FontMap* pFontMap = GetFontMap()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700709 int32_t nOldCharSet = GetCharSet();
npmea3c3be2016-09-19 07:24:33 -0700710 int32_t nNewCharSet =
711 pFontMap->CharSetFromUnicode(nChar, FXFONT_DEFAULT_CHARSET);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700712 if (nOldCharSet != nNewCharSet) {
713 SetCharSet(nNewCharSet);
714 }
715 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700716
Lei Zhanga5b47042015-10-19 14:32:16 -0700717 return CPWL_EditCtrl::OnChar(nChar, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700718}
719
tsepez4cf55152016-11-02 14:37:54 -0700720bool CPWL_Edit::OnMouseWheel(short zDelta,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500721 const CFX_PointF& point,
tsepez4cf55152016-11-02 14:37:54 -0700722 uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700723 if (HasFlag(PES_MULTILINE)) {
Dan Sinclairf528eee2017-02-14 11:52:07 -0500724 CFX_PointF ptScroll = GetScrollPos();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700725
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700726 if (zDelta > 0) {
727 ptScroll.y += GetFontSize();
728 } else {
729 ptScroll.y -= GetFontSize();
730 }
731 SetScrollPos(ptScroll);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700732
tsepez4cf55152016-11-02 14:37:54 -0700733 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700734 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700735
tsepez4cf55152016-11-02 14:37:54 -0700736 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700737}
738
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700739void CPWL_Edit::OnInsertReturn(const CPVT_WordPlace& place,
740 const CPVT_WordPlace& oldplace) {
741 if (HasFlag(PES_SPELLCHECK)) {
742 m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace),
743 GetLatinWordsRange(place)));
744 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700745}
746
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700747void CPWL_Edit::OnBackSpace(const CPVT_WordPlace& place,
748 const CPVT_WordPlace& oldplace) {
749 if (HasFlag(PES_SPELLCHECK)) {
750 m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace),
751 GetLatinWordsRange(place)));
752 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700753}
754
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700755void CPWL_Edit::OnDelete(const CPVT_WordPlace& place,
756 const CPVT_WordPlace& oldplace) {
757 if (HasFlag(PES_SPELLCHECK)) {
758 m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace),
759 GetLatinWordsRange(place)));
760 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700761}
762
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700763void CPWL_Edit::OnClear(const CPVT_WordPlace& place,
764 const CPVT_WordPlace& oldplace) {
765 if (HasFlag(PES_SPELLCHECK)) {
766 m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace),
767 GetLatinWordsRange(place)));
768 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700769}
770
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700771void CPWL_Edit::OnInsertWord(const CPVT_WordPlace& place,
772 const CPVT_WordPlace& oldplace) {
773 if (HasFlag(PES_SPELLCHECK)) {
774 m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace),
775 GetLatinWordsRange(place)));
776 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700777}
778
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700779void CPWL_Edit::OnInsertText(const CPVT_WordPlace& place,
780 const CPVT_WordPlace& oldplace) {
781 if (HasFlag(PES_SPELLCHECK)) {
782 m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace),
783 GetLatinWordsRange(place)));
784 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700785}
786
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700787CPVT_WordRange CPWL_Edit::CombineWordRange(const CPVT_WordRange& wr1,
788 const CPVT_WordRange& wr2) {
789 CPVT_WordRange wrRet;
790
791 if (wr1.BeginPos.WordCmp(wr2.BeginPos) < 0) {
792 wrRet.BeginPos = wr1.BeginPos;
793 } else {
794 wrRet.BeginPos = wr2.BeginPos;
795 }
796
797 if (wr1.EndPos.WordCmp(wr2.EndPos) < 0) {
798 wrRet.EndPos = wr2.EndPos;
799 } else {
800 wrRet.EndPos = wr1.EndPos;
801 }
802
803 return wrRet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700804}
805
Dan Sinclairf528eee2017-02-14 11:52:07 -0500806CPVT_WordRange CPWL_Edit::GetLatinWordsRange(const CFX_PointF& point) const {
tsepez4cf55152016-11-02 14:37:54 -0700807 return GetSameWordsRange(m_pEdit->SearchWordPlace(point), true, false);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700808}
809
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700810CPVT_WordRange CPWL_Edit::GetLatinWordsRange(
811 const CPVT_WordPlace& place) const {
tsepez4cf55152016-11-02 14:37:54 -0700812 return GetSameWordsRange(place, true, false);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700813}
814
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700815CPVT_WordRange CPWL_Edit::GetArabicWordsRange(
816 const CPVT_WordPlace& place) const {
tsepez4cf55152016-11-02 14:37:54 -0700817 return GetSameWordsRange(place, false, true);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700818}
819
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700820#define PWL_ISARABICWORD(word) \
821 ((word >= 0x0600 && word <= 0x06FF) || (word >= 0xFB50 && word <= 0xFEFC))
822
823CPVT_WordRange CPWL_Edit::GetSameWordsRange(const CPVT_WordPlace& place,
tsepez4cf55152016-11-02 14:37:54 -0700824 bool bLatin,
825 bool bArabic) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700826 CPVT_WordRange range;
827
dsinclaire35af1e2016-07-13 11:26:20 -0700828 CFX_Edit_Iterator* pIterator = m_pEdit->GetIterator();
thestig821d59e2016-05-11 12:59:22 -0700829 CPVT_Word wordinfo;
830 CPVT_WordPlace wpStart(place), wpEnd(place);
831 pIterator->SetAt(place);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700832
thestig821d59e2016-05-11 12:59:22 -0700833 if (bLatin) {
834 while (pIterator->NextWord()) {
835 if (!pIterator->GetWord(wordinfo) ||
836 !FX_EDIT_ISLATINWORD(wordinfo.Word)) {
837 break;
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800838 }
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800839
thestig821d59e2016-05-11 12:59:22 -0700840 wpEnd = pIterator->GetAt();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700841 }
thestig821d59e2016-05-11 12:59:22 -0700842 } else if (bArabic) {
843 while (pIterator->NextWord()) {
844 if (!pIterator->GetWord(wordinfo) || !PWL_ISARABICWORD(wordinfo.Word))
845 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700846
thestig821d59e2016-05-11 12:59:22 -0700847 wpEnd = pIterator->GetAt();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700848 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700849 }
850
thestig821d59e2016-05-11 12:59:22 -0700851 pIterator->SetAt(place);
852
853 if (bLatin) {
854 do {
855 if (!pIterator->GetWord(wordinfo) ||
856 !FX_EDIT_ISLATINWORD(wordinfo.Word)) {
857 break;
858 }
859
860 wpStart = pIterator->GetAt();
861 } while (pIterator->PrevWord());
862 } else if (bArabic) {
863 do {
864 if (!pIterator->GetWord(wordinfo) || !PWL_ISARABICWORD(wordinfo.Word))
865 break;
866
867 wpStart = pIterator->GetAt();
868 } while (pIterator->PrevWord());
869 }
870
871 range.Set(wpStart, wpEnd);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700872 return range;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700873}