blob: 1ba8e7d72f824ca22775299037c69c62c5c4a4b0 [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)
Dan Sinclaira0061af2017-02-23 09:25:17 -0500269 sText << "BT\n"
270 << CPWL_Utils::GetColorAppStream(GetTextColor()).AsStringC()
tsepez4c3debb2016-04-08 12:20:38 -0700271 << sEditBefore.AsStringC() << "ET\n";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700272
273 wrTemp = CPWL_Utils::OverlapWordRange(wrVisible, wrSelect);
274 CFX_ByteString sEditMid = CPWL_Utils::GetEditAppStream(
dsinclaire35af1e2016-07-13 11:26:20 -0700275 m_pEdit.get(), ptOffset, &wrTemp, !HasFlag(PES_CHARARRAY),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700276 m_pEdit->GetPasswordChar());
277
278 if (sEditMid.GetLength() > 0)
279 sText << "BT\n"
280 << CPWL_Utils::GetColorAppStream(CPWL_Color(COLORTYPE_GRAY, 1))
tsepez4c3debb2016-04-08 12:20:38 -0700281 .AsStringC()
282 << sEditMid.AsStringC() << "ET\n";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700283
284 wrTemp = CPWL_Utils::OverlapWordRange(wrVisible, wrSelAfter);
285 CFX_ByteString sEditAfter = CPWL_Utils::GetEditAppStream(
dsinclaire35af1e2016-07-13 11:26:20 -0700286 m_pEdit.get(), ptOffset, &wrTemp, !HasFlag(PES_CHARARRAY),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700287 m_pEdit->GetPasswordChar());
288
289 if (sEditAfter.GetLength() > 0)
Dan Sinclaira0061af2017-02-23 09:25:17 -0500290 sText << "BT\n"
291 << CPWL_Utils::GetColorAppStream(GetTextColor()).AsStringC()
tsepez4c3debb2016-04-08 12:20:38 -0700292 << sEditAfter.AsStringC() << "ET\n";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700293
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700294 if (sText.GetLength() > 0) {
weilidb444d22016-06-02 15:48:15 -0700295 CFX_FloatRect rect = GetClientRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700296 sAppStream << "q\n/Tx BMC\n";
297
298 if (!HasFlag(PES_TEXTOVERFLOW))
weilidb444d22016-06-02 15:48:15 -0700299 sAppStream << rect.left << " " << rect.bottom << " "
300 << rect.right - rect.left << " " << rect.top - rect.bottom
301 << " re W n\n";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700302
303 sAppStream << sText;
304
305 sAppStream << "EMC\nQ\n";
306 }
307}
308
309void CPWL_Edit::DrawThisAppearance(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800310 CFX_Matrix* pUser2Device) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700311 CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device);
312
Tom Sepez281a9ea2016-02-26 14:24:28 -0800313 CFX_FloatRect rcClient = GetClientRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700314 CFX_ByteTextBuf sLine;
315
316 int32_t nCharArray = m_pEdit->GetCharArray();
317 FX_SAFE_INT32 nCharArraySafe = nCharArray;
318 nCharArraySafe -= 1;
319 nCharArraySafe *= 2;
320
321 if (nCharArray > 0 && nCharArraySafe.IsValid()) {
322 switch (GetBorderStyle()) {
dsinclair92cb5e52016-05-16 11:38:28 -0700323 case BorderStyle::SOLID: {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700324 CFX_GraphStateData gsd;
325 gsd.m_LineWidth = (FX_FLOAT)GetBorderWidth();
326
327 CFX_PathData path;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700328
329 for (int32_t i = 0; i < nCharArray - 1; i++) {
Dan Sinclaire4602322017-02-15 11:07:32 -0500330 path.AppendPoint(
dan sinclairb147e072017-02-22 19:56:15 -0500331 CFX_PointF(
332 rcClient.left +
333 ((rcClient.right - rcClient.left) / nCharArray) * (i + 1),
334 rcClient.bottom),
335 FXPT_TYPE::MoveTo, false);
Dan Sinclaire4602322017-02-15 11:07:32 -0500336 path.AppendPoint(
dan sinclairb147e072017-02-22 19:56:15 -0500337 CFX_PointF(
338 rcClient.left +
339 ((rcClient.right - rcClient.left) / nCharArray) * (i + 1),
340 rcClient.top),
341 FXPT_TYPE::LineTo, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700342 }
Dan Sinclaire4602322017-02-15 11:07:32 -0500343 if (!path.GetPoints().empty()) {
Dan Sinclairfc54e052017-02-23 09:59:05 -0500344 pDevice->DrawPath(&path, pUser2Device, &gsd, 0,
345 GetBorderColor().ToFXColor(255), FXFILL_ALTERNATE);
dsinclair92cb5e52016-05-16 11:38:28 -0700346 }
347 break;
348 }
349 case BorderStyle::DASH: {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700350 CFX_GraphStateData gsd;
351 gsd.m_LineWidth = (FX_FLOAT)GetBorderWidth();
352
353 gsd.SetDashCount(2);
354 gsd.m_DashArray[0] = (FX_FLOAT)GetBorderDash().nDash;
355 gsd.m_DashArray[1] = (FX_FLOAT)GetBorderDash().nGap;
356 gsd.m_DashPhase = (FX_FLOAT)GetBorderDash().nPhase;
357
358 CFX_PathData path;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700359 for (int32_t i = 0; i < nCharArray - 1; i++) {
Dan Sinclaire4602322017-02-15 11:07:32 -0500360 path.AppendPoint(
dan sinclairb147e072017-02-22 19:56:15 -0500361 CFX_PointF(
362 rcClient.left +
363 ((rcClient.right - rcClient.left) / nCharArray) * (i + 1),
364 rcClient.bottom),
365 FXPT_TYPE::MoveTo, false);
Dan Sinclaire4602322017-02-15 11:07:32 -0500366 path.AppendPoint(
dan sinclairb147e072017-02-22 19:56:15 -0500367 CFX_PointF(
368 rcClient.left +
369 ((rcClient.right - rcClient.left) / nCharArray) * (i + 1),
370 rcClient.top),
371 FXPT_TYPE::LineTo, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700372 }
Dan Sinclaire4602322017-02-15 11:07:32 -0500373 if (!path.GetPoints().empty()) {
Dan Sinclairfc54e052017-02-23 09:59:05 -0500374 pDevice->DrawPath(&path, pUser2Device, &gsd, 0,
375 GetBorderColor().ToFXColor(255), FXFILL_ALTERNATE);
dsinclair92cb5e52016-05-16 11:38:28 -0700376 }
377 break;
378 }
379 default:
380 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700381 }
382 }
383
Tom Sepez281a9ea2016-02-26 14:24:28 -0800384 CFX_FloatRect rcClip;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700385 CPVT_WordRange wrRange = m_pEdit->GetVisibleWordRange();
thestig1cd352e2016-06-07 17:53:06 -0700386 CPVT_WordRange* pRange = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700387 if (!HasFlag(PES_TEXTOVERFLOW)) {
388 rcClip = GetClientRect();
389 pRange = &wrRange;
390 }
tsepez63f545c2016-09-13 16:08:49 -0700391
dsinclairb9590102016-04-27 06:38:59 -0700392 CFX_SystemHandler* pSysHandler = GetSystemHandler();
Dan Sinclairfc54e052017-02-23 09:59:05 -0500393 CFX_Edit::DrawEdit(pDevice, pUser2Device, m_pEdit.get(),
394 GetTextColor().ToFXColor(GetTransparency()), rcClip,
395 CFX_PointF(), pRange, pSysHandler, m_pFormFiller);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700396}
397
Dan Sinclairf528eee2017-02-14 11:52:07 -0500398bool CPWL_Edit::OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700399 CPWL_Wnd::OnLButtonDown(point, nFlag);
400
401 if (HasFlag(PES_TEXTOVERFLOW) || ClientHitTest(point)) {
402 if (m_bMouseDown)
403 InvalidateRect();
404
tsepez4cf55152016-11-02 14:37:54 -0700405 m_bMouseDown = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700406 SetCapture();
407
408 m_pEdit->OnMouseDown(point, IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
409 }
410
tsepez4cf55152016-11-02 14:37:54 -0700411 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700412}
413
Dan Sinclairf528eee2017-02-14 11:52:07 -0500414bool CPWL_Edit::OnLButtonDblClk(const CFX_PointF& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700415 CPWL_Wnd::OnLButtonDblClk(point, nFlag);
416
417 if (HasFlag(PES_TEXTOVERFLOW) || ClientHitTest(point)) {
418 m_pEdit->SelectAll();
419 }
420
tsepez4cf55152016-11-02 14:37:54 -0700421 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700422}
423
Dan Sinclairf528eee2017-02-14 11:52:07 -0500424bool CPWL_Edit::OnRButtonUp(const CFX_PointF& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700425 if (m_bMouseDown)
tsepez4cf55152016-11-02 14:37:54 -0700426 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700427
428 CPWL_Wnd::OnRButtonUp(point, nFlag);
429
430 if (!HasFlag(PES_TEXTOVERFLOW) && !ClientHitTest(point))
tsepez4cf55152016-11-02 14:37:54 -0700431 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700432
dsinclairb9590102016-04-27 06:38:59 -0700433 CFX_SystemHandler* pSH = GetSystemHandler();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700434 if (!pSH)
tsepez4cf55152016-11-02 14:37:54 -0700435 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700436
437 SetFocus();
438
tsepez4cf55152016-11-02 14:37:54 -0700439 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700440}
441
442void CPWL_Edit::OnSetFocus() {
tsepez4cf55152016-11-02 14:37:54 -0700443 SetEditCaret(true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700444 if (!IsReadOnly()) {
445 if (IPWL_FocusHandler* pFocusHandler = GetFocusHandler())
446 pFocusHandler->OnSetFocus(this);
447 }
tsepez4cf55152016-11-02 14:37:54 -0700448 m_bFocus = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700449}
450
451void CPWL_Edit::OnKillFocus() {
tsepez4cf55152016-11-02 14:37:54 -0700452 ShowVScrollBar(false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700453 m_pEdit->SelectNone();
Dan Sinclairf528eee2017-02-14 11:52:07 -0500454 SetCaret(false, CFX_PointF(), CFX_PointF());
thestig907a5222016-06-21 14:38:27 -0700455 SetCharSet(FXFONT_ANSI_CHARSET);
tsepez4cf55152016-11-02 14:37:54 -0700456 m_bFocus = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700457}
458
dsinclairefd5a992016-07-18 10:04:07 -0700459void CPWL_Edit::SetCharSpace(FX_FLOAT fCharSpace) {
460 m_pEdit->SetCharSpace(fCharSpace);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700461}
462
463CFX_ByteString CPWL_Edit::GetSelectAppearanceStream(
Dan Sinclairf528eee2017-02-14 11:52:07 -0500464 const CFX_PointF& ptOffset) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700465 CPVT_WordRange wr = GetSelectWordRange();
dsinclaire35af1e2016-07-13 11:26:20 -0700466 return CPWL_Utils::GetEditSelAppStream(m_pEdit.get(), ptOffset, &wr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700467}
468
469CPVT_WordRange CPWL_Edit::GetSelectWordRange() const {
470 if (m_pEdit->IsSelected()) {
471 int32_t nStart = -1;
472 int32_t nEnd = -1;
473
474 m_pEdit->GetSel(nStart, nEnd);
475
476 CPVT_WordPlace wpStart = m_pEdit->WordIndexToWordPlace(nStart);
477 CPVT_WordPlace wpEnd = m_pEdit->WordIndexToWordPlace(nEnd);
478
479 return CPVT_WordRange(wpStart, wpEnd);
480 }
481
482 return CPVT_WordRange();
483}
484
485CFX_ByteString CPWL_Edit::GetTextAppearanceStream(
Dan Sinclairf528eee2017-02-14 11:52:07 -0500486 const CFX_PointF& ptOffset) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700487 CFX_ByteTextBuf sRet;
dsinclaire35af1e2016-07-13 11:26:20 -0700488 CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream(m_pEdit.get(), ptOffset);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700489 if (sEdit.GetLength() > 0) {
Dan Sinclaira0061af2017-02-23 09:25:17 -0500490 sRet << "BT\n"
491 << CPWL_Utils::GetColorAppStream(GetTextColor()).AsStringC()
tsepez4c3debb2016-04-08 12:20:38 -0700492 << sEdit.AsStringC() << "ET\n";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700493 }
tsepez71a452f2016-05-13 17:51:27 -0700494 return sRet.MakeString();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700495}
496
497CFX_ByteString CPWL_Edit::GetCaretAppearanceStream(
Dan Sinclairf528eee2017-02-14 11:52:07 -0500498 const CFX_PointF& ptOffset) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700499 if (m_pEditCaret)
500 return m_pEditCaret->GetCaretAppearanceStream(ptOffset);
501
502 return CFX_ByteString();
503}
504
Dan Sinclairf528eee2017-02-14 11:52:07 -0500505CFX_PointF CPWL_Edit::GetWordRightBottomPoint(const CPVT_WordPlace& wpWord) {
dsinclaire35af1e2016-07-13 11:26:20 -0700506 CFX_Edit_Iterator* pIterator = m_pEdit->GetIterator();
thestig821d59e2016-05-11 12:59:22 -0700507 CPVT_WordPlace wpOld = pIterator->GetAt();
508 pIterator->SetAt(wpWord);
tsepez63f545c2016-09-13 16:08:49 -0700509
Dan Sinclairf528eee2017-02-14 11:52:07 -0500510 CFX_PointF pt;
thestig821d59e2016-05-11 12:59:22 -0700511 CPVT_Word word;
512 if (pIterator->GetWord(word)) {
Dan Sinclairf528eee2017-02-14 11:52:07 -0500513 pt = CFX_PointF(word.ptWord.x + word.fWidth, word.ptWord.y + word.fDescent);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700514 }
thestig821d59e2016-05-11 12:59:22 -0700515 pIterator->SetAt(wpOld);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700516 return pt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700517}
518
tsepez4cf55152016-11-02 14:37:54 -0700519bool CPWL_Edit::IsTextFull() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700520 return m_pEdit->IsTextFull();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700521}
522
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700523FX_FLOAT CPWL_Edit::GetCharArrayAutoFontSize(CPDF_Font* pFont,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800524 const CFX_FloatRect& rcPlate,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700525 int32_t nCharArray) {
526 if (pFont && !pFont->IsStandardFont()) {
527 FX_RECT rcBBox;
528 pFont->GetFontBBox(rcBBox);
529
Tom Sepez281a9ea2016-02-26 14:24:28 -0800530 CFX_FloatRect rcCell = rcPlate;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700531 FX_FLOAT xdiv = rcCell.Width() / nCharArray * 1000.0f / rcBBox.Width();
532 FX_FLOAT ydiv = -rcCell.Height() * 1000.0f / rcBBox.Height();
533
534 return xdiv < ydiv ? xdiv : ydiv;
535 }
536
537 return 0.0f;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700538}
539
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700540void CPWL_Edit::SetCharArray(int32_t nCharArray) {
541 if (HasFlag(PES_CHARARRAY) && nCharArray > 0) {
542 m_pEdit->SetCharArray(nCharArray);
tsepez4cf55152016-11-02 14:37:54 -0700543 m_pEdit->SetTextOverflow(true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700544
545 if (HasFlag(PWS_AUTOFONTSIZE)) {
dsinclairc7a73492016-04-05 12:01:42 -0700546 if (IPVT_FontMap* pFontMap = GetFontMap()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700547 FX_FLOAT fFontSize = GetCharArrayAutoFontSize(
548 pFontMap->GetPDFFont(0), GetClientRect(), nCharArray);
549 if (fFontSize > 0.0f) {
tsepez4cf55152016-11-02 14:37:54 -0700550 m_pEdit->SetAutoFontSize(false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700551 m_pEdit->SetFontSize(fFontSize);
552 }
553 }
554 }
555 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700556}
557
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700558void CPWL_Edit::SetLimitChar(int32_t nLimitChar) {
559 m_pEdit->SetLimitChar(nLimitChar);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700560}
561
tsepez067990c2016-09-13 06:46:40 -0700562void CPWL_Edit::ReplaceSel(const CFX_WideString& wsText) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700563 m_pEdit->Clear();
npmea3c3be2016-09-19 07:24:33 -0700564 m_pEdit->InsertText(wsText, FXFONT_DEFAULT_CHARSET);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700565}
566
Tom Sepez281a9ea2016-02-26 14:24:28 -0800567CFX_FloatRect CPWL_Edit::GetFocusRect() const {
568 return CFX_FloatRect();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700569}
570
tsepez4cf55152016-11-02 14:37:54 -0700571void CPWL_Edit::ShowVScrollBar(bool bShow) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700572 if (CPWL_ScrollBar* pScroll = GetVScrollBar()) {
573 if (bShow) {
574 if (!pScroll->IsVisible()) {
tsepez4cf55152016-11-02 14:37:54 -0700575 pScroll->SetVisible(true);
Tom Sepez281a9ea2016-02-26 14:24:28 -0800576 CFX_FloatRect rcWindow = GetWindowRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700577 m_rcOldWindow = rcWindow;
578 rcWindow.right += PWL_SCROLLBAR_WIDTH;
tsepez4cf55152016-11-02 14:37:54 -0700579 Move(rcWindow, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700580 }
581 } else {
582 if (pScroll->IsVisible()) {
tsepez4cf55152016-11-02 14:37:54 -0700583 pScroll->SetVisible(false);
584 Move(m_rcOldWindow, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700585 }
586 }
587 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700588}
589
tsepez4cf55152016-11-02 14:37:54 -0700590bool CPWL_Edit::IsVScrollBarVisible() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700591 if (CPWL_ScrollBar* pScroll = GetVScrollBar()) {
592 return pScroll->IsVisible();
593 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700594
tsepez4cf55152016-11-02 14:37:54 -0700595 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700596}
597
tsepez4cf55152016-11-02 14:37:54 -0700598bool CPWL_Edit::OnKeyDown(uint16_t nChar, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700599 if (m_bMouseDown)
tsepez4cf55152016-11-02 14:37:54 -0700600 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700601
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700602 if (nChar == FWL_VKEY_Delete) {
603 if (m_pFillerNotify) {
tsepez4cf55152016-11-02 14:37:54 -0700604 bool bRC = true;
605 bool bExit = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700606 CFX_WideString strChange;
607 CFX_WideString strChangeEx;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700608
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700609 int nSelStart = 0;
610 int nSelEnd = 0;
611 GetSel(nSelStart, nSelEnd);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700612
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700613 if (nSelStart == nSelEnd)
614 nSelEnd = nSelStart + 1;
Lei Zhanga5b47042015-10-19 14:32:16 -0700615 m_pFillerNotify->OnBeforeKeyStroke(GetAttachedData(), strChange,
tsepez4cf55152016-11-02 14:37:54 -0700616 strChangeEx, nSelStart, nSelEnd, true,
Lei Zhanga5b47042015-10-19 14:32:16 -0700617 bRC, bExit, nFlag);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700618 if (!bRC)
tsepez4cf55152016-11-02 14:37:54 -0700619 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700620 if (bExit)
tsepez4cf55152016-11-02 14:37:54 -0700621 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700622 }
623 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700624
tsepez4cf55152016-11-02 14:37:54 -0700625 bool bRet = CPWL_EditCtrl::OnKeyDown(nChar, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700626
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700627 // In case of implementation swallow the OnKeyDown event.
628 if (IsProceedtoOnChar(nChar, nFlag))
tsepez4cf55152016-11-02 14:37:54 -0700629 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700630
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700631 return bRet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700632}
633
634/**
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700635*In case of implementation swallow the OnKeyDown event.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700636*If the event is swallowed, implementation may do other unexpected things, which
637*is not the control means to do.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700638*/
tsepez4cf55152016-11-02 14:37:54 -0700639bool CPWL_Edit::IsProceedtoOnChar(uint16_t nKeyCode, uint32_t nFlag) {
640 bool bCtrl = IsCTRLpressed(nFlag);
641 bool bAlt = IsALTpressed(nFlag);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700642 if (bCtrl && !bAlt) {
643 // hot keys for edit control.
644 switch (nKeyCode) {
645 case 'C':
646 case 'V':
647 case 'X':
648 case 'A':
649 case 'Z':
tsepez4cf55152016-11-02 14:37:54 -0700650 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700651 default:
652 break;
653 }
654 }
655 // control characters.
656 switch (nKeyCode) {
657 case FWL_VKEY_Escape:
658 case FWL_VKEY_Back:
659 case FWL_VKEY_Return:
660 case FWL_VKEY_Space:
tsepez4cf55152016-11-02 14:37:54 -0700661 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700662 default:
tsepez4cf55152016-11-02 14:37:54 -0700663 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700664 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700665}
666
tsepez4cf55152016-11-02 14:37:54 -0700667bool CPWL_Edit::OnChar(uint16_t nChar, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700668 if (m_bMouseDown)
tsepez4cf55152016-11-02 14:37:54 -0700669 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700670
tsepez4cf55152016-11-02 14:37:54 -0700671 bool bRC = true;
672 bool bExit = false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700673
Lei Zhanga5b47042015-10-19 14:32:16 -0700674 if (!IsCTRLpressed(nFlag)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700675 if (m_pFillerNotify) {
676 CFX_WideString swChange;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700677
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700678 int nSelStart = 0;
679 int nSelEnd = 0;
680 GetSel(nSelStart, nSelEnd);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700681
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700682 switch (nChar) {
683 case FWL_VKEY_Back:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700684 if (nSelStart == nSelEnd)
685 nSelStart = nSelEnd - 1;
686 break;
687 case FWL_VKEY_Return:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700688 break;
689 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700690 swChange += nChar;
691 break;
692 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700693
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700694 CFX_WideString strChangeEx;
Lei Zhanga5b47042015-10-19 14:32:16 -0700695 m_pFillerNotify->OnBeforeKeyStroke(GetAttachedData(), swChange,
tsepez4cf55152016-11-02 14:37:54 -0700696 strChangeEx, nSelStart, nSelEnd, true,
Lei Zhanga5b47042015-10-19 14:32:16 -0700697 bRC, bExit, nFlag);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700698 }
699 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700700
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700701 if (!bRC)
tsepez4cf55152016-11-02 14:37:54 -0700702 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700703 if (bExit)
tsepez4cf55152016-11-02 14:37:54 -0700704 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700705
dsinclairc7a73492016-04-05 12:01:42 -0700706 if (IPVT_FontMap* pFontMap = GetFontMap()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700707 int32_t nOldCharSet = GetCharSet();
npmea3c3be2016-09-19 07:24:33 -0700708 int32_t nNewCharSet =
709 pFontMap->CharSetFromUnicode(nChar, FXFONT_DEFAULT_CHARSET);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700710 if (nOldCharSet != nNewCharSet) {
711 SetCharSet(nNewCharSet);
712 }
713 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700714
Lei Zhanga5b47042015-10-19 14:32:16 -0700715 return CPWL_EditCtrl::OnChar(nChar, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700716}
717
tsepez4cf55152016-11-02 14:37:54 -0700718bool CPWL_Edit::OnMouseWheel(short zDelta,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500719 const CFX_PointF& point,
tsepez4cf55152016-11-02 14:37:54 -0700720 uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700721 if (HasFlag(PES_MULTILINE)) {
Dan Sinclairf528eee2017-02-14 11:52:07 -0500722 CFX_PointF ptScroll = GetScrollPos();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700723
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700724 if (zDelta > 0) {
725 ptScroll.y += GetFontSize();
726 } else {
727 ptScroll.y -= GetFontSize();
728 }
729 SetScrollPos(ptScroll);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700730
tsepez4cf55152016-11-02 14:37:54 -0700731 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700732 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700733
tsepez4cf55152016-11-02 14:37:54 -0700734 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700735}
736
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700737void CPWL_Edit::OnInsertReturn(const CPVT_WordPlace& place,
738 const CPVT_WordPlace& oldplace) {
739 if (HasFlag(PES_SPELLCHECK)) {
740 m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace),
741 GetLatinWordsRange(place)));
742 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700743}
744
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700745void CPWL_Edit::OnBackSpace(const CPVT_WordPlace& place,
746 const CPVT_WordPlace& oldplace) {
747 if (HasFlag(PES_SPELLCHECK)) {
748 m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace),
749 GetLatinWordsRange(place)));
750 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700751}
752
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700753void CPWL_Edit::OnDelete(const CPVT_WordPlace& place,
754 const CPVT_WordPlace& oldplace) {
755 if (HasFlag(PES_SPELLCHECK)) {
756 m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace),
757 GetLatinWordsRange(place)));
758 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700759}
760
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700761void CPWL_Edit::OnClear(const CPVT_WordPlace& place,
762 const CPVT_WordPlace& oldplace) {
763 if (HasFlag(PES_SPELLCHECK)) {
764 m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace),
765 GetLatinWordsRange(place)));
766 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700767}
768
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700769void CPWL_Edit::OnInsertWord(const CPVT_WordPlace& place,
770 const CPVT_WordPlace& oldplace) {
771 if (HasFlag(PES_SPELLCHECK)) {
772 m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace),
773 GetLatinWordsRange(place)));
774 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700775}
776
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700777void CPWL_Edit::OnInsertText(const CPVT_WordPlace& place,
778 const CPVT_WordPlace& oldplace) {
779 if (HasFlag(PES_SPELLCHECK)) {
780 m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace),
781 GetLatinWordsRange(place)));
782 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700783}
784
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700785CPVT_WordRange CPWL_Edit::CombineWordRange(const CPVT_WordRange& wr1,
786 const CPVT_WordRange& wr2) {
787 CPVT_WordRange wrRet;
788
789 if (wr1.BeginPos.WordCmp(wr2.BeginPos) < 0) {
790 wrRet.BeginPos = wr1.BeginPos;
791 } else {
792 wrRet.BeginPos = wr2.BeginPos;
793 }
794
795 if (wr1.EndPos.WordCmp(wr2.EndPos) < 0) {
796 wrRet.EndPos = wr2.EndPos;
797 } else {
798 wrRet.EndPos = wr1.EndPos;
799 }
800
801 return wrRet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700802}
803
Dan Sinclairf528eee2017-02-14 11:52:07 -0500804CPVT_WordRange CPWL_Edit::GetLatinWordsRange(const CFX_PointF& point) const {
tsepez4cf55152016-11-02 14:37:54 -0700805 return GetSameWordsRange(m_pEdit->SearchWordPlace(point), true, false);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700806}
807
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700808CPVT_WordRange CPWL_Edit::GetLatinWordsRange(
809 const CPVT_WordPlace& place) const {
tsepez4cf55152016-11-02 14:37:54 -0700810 return GetSameWordsRange(place, true, false);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700811}
812
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700813CPVT_WordRange CPWL_Edit::GetArabicWordsRange(
814 const CPVT_WordPlace& place) const {
tsepez4cf55152016-11-02 14:37:54 -0700815 return GetSameWordsRange(place, false, true);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700816}
817
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700818#define PWL_ISARABICWORD(word) \
819 ((word >= 0x0600 && word <= 0x06FF) || (word >= 0xFB50 && word <= 0xFEFC))
820
821CPVT_WordRange CPWL_Edit::GetSameWordsRange(const CPVT_WordPlace& place,
tsepez4cf55152016-11-02 14:37:54 -0700822 bool bLatin,
823 bool bArabic) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700824 CPVT_WordRange range;
825
dsinclaire35af1e2016-07-13 11:26:20 -0700826 CFX_Edit_Iterator* pIterator = m_pEdit->GetIterator();
thestig821d59e2016-05-11 12:59:22 -0700827 CPVT_Word wordinfo;
828 CPVT_WordPlace wpStart(place), wpEnd(place);
829 pIterator->SetAt(place);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700830
thestig821d59e2016-05-11 12:59:22 -0700831 if (bLatin) {
832 while (pIterator->NextWord()) {
833 if (!pIterator->GetWord(wordinfo) ||
834 !FX_EDIT_ISLATINWORD(wordinfo.Word)) {
835 break;
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800836 }
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800837
thestig821d59e2016-05-11 12:59:22 -0700838 wpEnd = pIterator->GetAt();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700839 }
thestig821d59e2016-05-11 12:59:22 -0700840 } else if (bArabic) {
841 while (pIterator->NextWord()) {
842 if (!pIterator->GetWord(wordinfo) || !PWL_ISARABICWORD(wordinfo.Word))
843 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700844
thestig821d59e2016-05-11 12:59:22 -0700845 wpEnd = pIterator->GetAt();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700846 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700847 }
848
thestig821d59e2016-05-11 12:59:22 -0700849 pIterator->SetAt(place);
850
851 if (bLatin) {
852 do {
853 if (!pIterator->GetWord(wordinfo) ||
854 !FX_EDIT_ISLATINWORD(wordinfo.Word)) {
855 break;
856 }
857
858 wpStart = pIterator->GetAt();
859 } while (pIterator->PrevWord());
860 } else if (bArabic) {
861 do {
862 if (!pIterator->GetWord(wordinfo) || !PWL_ISARABICWORD(wordinfo.Word))
863 break;
864
865 wpStart = pIterator->GetAt();
866 } while (pIterator->PrevWord());
867 }
868
869 range.Set(wpStart, wpEnd);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700870 return range;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700871}