blob: 5c22d219402b1f8f13cccf0b2568ea5a6ac6bf38 [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;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700326
327 for (int32_t i = 0; i < nCharArray - 1; i++) {
Dan Sinclaire4602322017-02-15 11:07:32 -0500328 path.AppendPoint(
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700329 rcClient.left +
330 ((rcClient.right - rcClient.left) / nCharArray) * (i + 1),
Nicolas Pena79365f72017-02-07 14:21:36 -0500331 rcClient.bottom, FXPT_TYPE::MoveTo, false);
Dan Sinclaire4602322017-02-15 11:07:32 -0500332 path.AppendPoint(
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700333 rcClient.left +
334 ((rcClient.right - rcClient.left) / nCharArray) * (i + 1),
Nicolas Pena79365f72017-02-07 14:21:36 -0500335 rcClient.top, FXPT_TYPE::LineTo, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700336 }
Dan Sinclaire4602322017-02-15 11:07:32 -0500337 if (!path.GetPoints().empty()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700338 pDevice->DrawPath(
339 &path, pUser2Device, &gsd, 0,
340 CPWL_Utils::PWLColorToFXColor(GetBorderColor(), 255),
341 FXFILL_ALTERNATE);
dsinclair92cb5e52016-05-16 11:38:28 -0700342 }
343 break;
344 }
345 case BorderStyle::DASH: {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700346 CFX_GraphStateData gsd;
347 gsd.m_LineWidth = (FX_FLOAT)GetBorderWidth();
348
349 gsd.SetDashCount(2);
350 gsd.m_DashArray[0] = (FX_FLOAT)GetBorderDash().nDash;
351 gsd.m_DashArray[1] = (FX_FLOAT)GetBorderDash().nGap;
352 gsd.m_DashPhase = (FX_FLOAT)GetBorderDash().nPhase;
353
354 CFX_PathData path;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700355 for (int32_t i = 0; i < nCharArray - 1; i++) {
Dan Sinclaire4602322017-02-15 11:07:32 -0500356 path.AppendPoint(
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700357 rcClient.left +
358 ((rcClient.right - rcClient.left) / nCharArray) * (i + 1),
Nicolas Pena79365f72017-02-07 14:21:36 -0500359 rcClient.bottom, FXPT_TYPE::MoveTo, false);
Dan Sinclaire4602322017-02-15 11:07:32 -0500360 path.AppendPoint(
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700361 rcClient.left +
362 ((rcClient.right - rcClient.left) / nCharArray) * (i + 1),
Nicolas Pena79365f72017-02-07 14:21:36 -0500363 rcClient.top, FXPT_TYPE::LineTo, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700364 }
Dan Sinclaire4602322017-02-15 11:07:32 -0500365 if (!path.GetPoints().empty()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700366 pDevice->DrawPath(
367 &path, pUser2Device, &gsd, 0,
368 CPWL_Utils::PWLColorToFXColor(GetBorderColor(), 255),
369 FXFILL_ALTERNATE);
dsinclair92cb5e52016-05-16 11:38:28 -0700370 }
371 break;
372 }
373 default:
374 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700375 }
376 }
377
Tom Sepez281a9ea2016-02-26 14:24:28 -0800378 CFX_FloatRect rcClip;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700379 CPVT_WordRange wrRange = m_pEdit->GetVisibleWordRange();
thestig1cd352e2016-06-07 17:53:06 -0700380 CPVT_WordRange* pRange = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700381 if (!HasFlag(PES_TEXTOVERFLOW)) {
382 rcClip = GetClientRect();
383 pRange = &wrRange;
384 }
tsepez63f545c2016-09-13 16:08:49 -0700385
dsinclairb9590102016-04-27 06:38:59 -0700386 CFX_SystemHandler* pSysHandler = GetSystemHandler();
dsinclaire35af1e2016-07-13 11:26:20 -0700387 CFX_Edit::DrawEdit(
388 pDevice, pUser2Device, m_pEdit.get(),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700389 CPWL_Utils::PWLColorToFXColor(GetTextColor(), GetTransparency()),
390 CPWL_Utils::PWLColorToFXColor(GetTextStrokeColor(), GetTransparency()),
Dan Sinclairf528eee2017-02-14 11:52:07 -0500391 rcClip, CFX_PointF(), pRange, pSysHandler, m_pFormFiller);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700392}
393
Dan Sinclairf528eee2017-02-14 11:52:07 -0500394bool CPWL_Edit::OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700395 CPWL_Wnd::OnLButtonDown(point, nFlag);
396
397 if (HasFlag(PES_TEXTOVERFLOW) || ClientHitTest(point)) {
398 if (m_bMouseDown)
399 InvalidateRect();
400
tsepez4cf55152016-11-02 14:37:54 -0700401 m_bMouseDown = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700402 SetCapture();
403
404 m_pEdit->OnMouseDown(point, IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
405 }
406
tsepez4cf55152016-11-02 14:37:54 -0700407 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700408}
409
Dan Sinclairf528eee2017-02-14 11:52:07 -0500410bool CPWL_Edit::OnLButtonDblClk(const CFX_PointF& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700411 CPWL_Wnd::OnLButtonDblClk(point, nFlag);
412
413 if (HasFlag(PES_TEXTOVERFLOW) || ClientHitTest(point)) {
414 m_pEdit->SelectAll();
415 }
416
tsepez4cf55152016-11-02 14:37:54 -0700417 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700418}
419
Dan Sinclairf528eee2017-02-14 11:52:07 -0500420bool CPWL_Edit::OnRButtonUp(const CFX_PointF& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700421 if (m_bMouseDown)
tsepez4cf55152016-11-02 14:37:54 -0700422 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700423
424 CPWL_Wnd::OnRButtonUp(point, nFlag);
425
426 if (!HasFlag(PES_TEXTOVERFLOW) && !ClientHitTest(point))
tsepez4cf55152016-11-02 14:37:54 -0700427 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700428
dsinclairb9590102016-04-27 06:38:59 -0700429 CFX_SystemHandler* pSH = GetSystemHandler();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700430 if (!pSH)
tsepez4cf55152016-11-02 14:37:54 -0700431 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700432
433 SetFocus();
434
tsepez4cf55152016-11-02 14:37:54 -0700435 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700436}
437
438void CPWL_Edit::OnSetFocus() {
tsepez4cf55152016-11-02 14:37:54 -0700439 SetEditCaret(true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700440 if (!IsReadOnly()) {
441 if (IPWL_FocusHandler* pFocusHandler = GetFocusHandler())
442 pFocusHandler->OnSetFocus(this);
443 }
tsepez4cf55152016-11-02 14:37:54 -0700444 m_bFocus = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700445}
446
447void CPWL_Edit::OnKillFocus() {
tsepez4cf55152016-11-02 14:37:54 -0700448 ShowVScrollBar(false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700449 m_pEdit->SelectNone();
Dan Sinclairf528eee2017-02-14 11:52:07 -0500450 SetCaret(false, CFX_PointF(), CFX_PointF());
thestig907a5222016-06-21 14:38:27 -0700451 SetCharSet(FXFONT_ANSI_CHARSET);
tsepez4cf55152016-11-02 14:37:54 -0700452 m_bFocus = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700453}
454
dsinclairefd5a992016-07-18 10:04:07 -0700455void CPWL_Edit::SetCharSpace(FX_FLOAT fCharSpace) {
456 m_pEdit->SetCharSpace(fCharSpace);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700457}
458
459CFX_ByteString CPWL_Edit::GetSelectAppearanceStream(
Dan Sinclairf528eee2017-02-14 11:52:07 -0500460 const CFX_PointF& ptOffset) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700461 CPVT_WordRange wr = GetSelectWordRange();
dsinclaire35af1e2016-07-13 11:26:20 -0700462 return CPWL_Utils::GetEditSelAppStream(m_pEdit.get(), ptOffset, &wr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700463}
464
465CPVT_WordRange CPWL_Edit::GetSelectWordRange() const {
466 if (m_pEdit->IsSelected()) {
467 int32_t nStart = -1;
468 int32_t nEnd = -1;
469
470 m_pEdit->GetSel(nStart, nEnd);
471
472 CPVT_WordPlace wpStart = m_pEdit->WordIndexToWordPlace(nStart);
473 CPVT_WordPlace wpEnd = m_pEdit->WordIndexToWordPlace(nEnd);
474
475 return CPVT_WordRange(wpStart, wpEnd);
476 }
477
478 return CPVT_WordRange();
479}
480
481CFX_ByteString CPWL_Edit::GetTextAppearanceStream(
Dan Sinclairf528eee2017-02-14 11:52:07 -0500482 const CFX_PointF& ptOffset) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700483 CFX_ByteTextBuf sRet;
dsinclaire35af1e2016-07-13 11:26:20 -0700484 CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream(m_pEdit.get(), ptOffset);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700485 if (sEdit.GetLength() > 0) {
tsepez4c3debb2016-04-08 12:20:38 -0700486 sRet << "BT\n" << CPWL_Utils::GetColorAppStream(GetTextColor()).AsStringC()
487 << sEdit.AsStringC() << "ET\n";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700488 }
tsepez71a452f2016-05-13 17:51:27 -0700489 return sRet.MakeString();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700490}
491
492CFX_ByteString CPWL_Edit::GetCaretAppearanceStream(
Dan Sinclairf528eee2017-02-14 11:52:07 -0500493 const CFX_PointF& ptOffset) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700494 if (m_pEditCaret)
495 return m_pEditCaret->GetCaretAppearanceStream(ptOffset);
496
497 return CFX_ByteString();
498}
499
Dan Sinclairf528eee2017-02-14 11:52:07 -0500500CFX_PointF CPWL_Edit::GetWordRightBottomPoint(const CPVT_WordPlace& wpWord) {
dsinclaire35af1e2016-07-13 11:26:20 -0700501 CFX_Edit_Iterator* pIterator = m_pEdit->GetIterator();
thestig821d59e2016-05-11 12:59:22 -0700502 CPVT_WordPlace wpOld = pIterator->GetAt();
503 pIterator->SetAt(wpWord);
tsepez63f545c2016-09-13 16:08:49 -0700504
Dan Sinclairf528eee2017-02-14 11:52:07 -0500505 CFX_PointF pt;
thestig821d59e2016-05-11 12:59:22 -0700506 CPVT_Word word;
507 if (pIterator->GetWord(word)) {
Dan Sinclairf528eee2017-02-14 11:52:07 -0500508 pt = CFX_PointF(word.ptWord.x + word.fWidth, word.ptWord.y + word.fDescent);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700509 }
thestig821d59e2016-05-11 12:59:22 -0700510 pIterator->SetAt(wpOld);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700511 return pt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700512}
513
tsepez4cf55152016-11-02 14:37:54 -0700514bool CPWL_Edit::IsTextFull() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700515 return m_pEdit->IsTextFull();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700516}
517
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700518FX_FLOAT CPWL_Edit::GetCharArrayAutoFontSize(CPDF_Font* pFont,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800519 const CFX_FloatRect& rcPlate,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700520 int32_t nCharArray) {
521 if (pFont && !pFont->IsStandardFont()) {
522 FX_RECT rcBBox;
523 pFont->GetFontBBox(rcBBox);
524
Tom Sepez281a9ea2016-02-26 14:24:28 -0800525 CFX_FloatRect rcCell = rcPlate;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700526 FX_FLOAT xdiv = rcCell.Width() / nCharArray * 1000.0f / rcBBox.Width();
527 FX_FLOAT ydiv = -rcCell.Height() * 1000.0f / rcBBox.Height();
528
529 return xdiv < ydiv ? xdiv : ydiv;
530 }
531
532 return 0.0f;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700533}
534
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700535void CPWL_Edit::SetCharArray(int32_t nCharArray) {
536 if (HasFlag(PES_CHARARRAY) && nCharArray > 0) {
537 m_pEdit->SetCharArray(nCharArray);
tsepez4cf55152016-11-02 14:37:54 -0700538 m_pEdit->SetTextOverflow(true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700539
540 if (HasFlag(PWS_AUTOFONTSIZE)) {
dsinclairc7a73492016-04-05 12:01:42 -0700541 if (IPVT_FontMap* pFontMap = GetFontMap()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700542 FX_FLOAT fFontSize = GetCharArrayAutoFontSize(
543 pFontMap->GetPDFFont(0), GetClientRect(), nCharArray);
544 if (fFontSize > 0.0f) {
tsepez4cf55152016-11-02 14:37:54 -0700545 m_pEdit->SetAutoFontSize(false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700546 m_pEdit->SetFontSize(fFontSize);
547 }
548 }
549 }
550 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700551}
552
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700553void CPWL_Edit::SetLimitChar(int32_t nLimitChar) {
554 m_pEdit->SetLimitChar(nLimitChar);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700555}
556
tsepez067990c2016-09-13 06:46:40 -0700557void CPWL_Edit::ReplaceSel(const CFX_WideString& wsText) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700558 m_pEdit->Clear();
npmea3c3be2016-09-19 07:24:33 -0700559 m_pEdit->InsertText(wsText, FXFONT_DEFAULT_CHARSET);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700560}
561
Tom Sepez281a9ea2016-02-26 14:24:28 -0800562CFX_FloatRect CPWL_Edit::GetFocusRect() const {
563 return CFX_FloatRect();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700564}
565
tsepez4cf55152016-11-02 14:37:54 -0700566void CPWL_Edit::ShowVScrollBar(bool bShow) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700567 if (CPWL_ScrollBar* pScroll = GetVScrollBar()) {
568 if (bShow) {
569 if (!pScroll->IsVisible()) {
tsepez4cf55152016-11-02 14:37:54 -0700570 pScroll->SetVisible(true);
Tom Sepez281a9ea2016-02-26 14:24:28 -0800571 CFX_FloatRect rcWindow = GetWindowRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700572 m_rcOldWindow = rcWindow;
573 rcWindow.right += PWL_SCROLLBAR_WIDTH;
tsepez4cf55152016-11-02 14:37:54 -0700574 Move(rcWindow, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700575 }
576 } else {
577 if (pScroll->IsVisible()) {
tsepez4cf55152016-11-02 14:37:54 -0700578 pScroll->SetVisible(false);
579 Move(m_rcOldWindow, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700580 }
581 }
582 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700583}
584
tsepez4cf55152016-11-02 14:37:54 -0700585bool CPWL_Edit::IsVScrollBarVisible() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700586 if (CPWL_ScrollBar* pScroll = GetVScrollBar()) {
587 return pScroll->IsVisible();
588 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700589
tsepez4cf55152016-11-02 14:37:54 -0700590 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700591}
592
tsepez4cf55152016-11-02 14:37:54 -0700593bool CPWL_Edit::OnKeyDown(uint16_t nChar, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700594 if (m_bMouseDown)
tsepez4cf55152016-11-02 14:37:54 -0700595 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700596
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700597 if (nChar == FWL_VKEY_Delete) {
598 if (m_pFillerNotify) {
tsepez4cf55152016-11-02 14:37:54 -0700599 bool bRC = true;
600 bool bExit = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700601 CFX_WideString strChange;
602 CFX_WideString strChangeEx;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700603
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700604 int nSelStart = 0;
605 int nSelEnd = 0;
606 GetSel(nSelStart, nSelEnd);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700607
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700608 if (nSelStart == nSelEnd)
609 nSelEnd = nSelStart + 1;
Lei Zhanga5b47042015-10-19 14:32:16 -0700610 m_pFillerNotify->OnBeforeKeyStroke(GetAttachedData(), strChange,
tsepez4cf55152016-11-02 14:37:54 -0700611 strChangeEx, nSelStart, nSelEnd, true,
Lei Zhanga5b47042015-10-19 14:32:16 -0700612 bRC, bExit, nFlag);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700613 if (!bRC)
tsepez4cf55152016-11-02 14:37:54 -0700614 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700615 if (bExit)
tsepez4cf55152016-11-02 14:37:54 -0700616 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700617 }
618 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700619
tsepez4cf55152016-11-02 14:37:54 -0700620 bool bRet = CPWL_EditCtrl::OnKeyDown(nChar, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700621
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700622 // In case of implementation swallow the OnKeyDown event.
623 if (IsProceedtoOnChar(nChar, nFlag))
tsepez4cf55152016-11-02 14:37:54 -0700624 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700625
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700626 return bRet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700627}
628
629/**
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700630*In case of implementation swallow the OnKeyDown event.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700631*If the event is swallowed, implementation may do other unexpected things, which
632*is not the control means to do.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700633*/
tsepez4cf55152016-11-02 14:37:54 -0700634bool CPWL_Edit::IsProceedtoOnChar(uint16_t nKeyCode, uint32_t nFlag) {
635 bool bCtrl = IsCTRLpressed(nFlag);
636 bool bAlt = IsALTpressed(nFlag);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700637 if (bCtrl && !bAlt) {
638 // hot keys for edit control.
639 switch (nKeyCode) {
640 case 'C':
641 case 'V':
642 case 'X':
643 case 'A':
644 case 'Z':
tsepez4cf55152016-11-02 14:37:54 -0700645 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700646 default:
647 break;
648 }
649 }
650 // control characters.
651 switch (nKeyCode) {
652 case FWL_VKEY_Escape:
653 case FWL_VKEY_Back:
654 case FWL_VKEY_Return:
655 case FWL_VKEY_Space:
tsepez4cf55152016-11-02 14:37:54 -0700656 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700657 default:
tsepez4cf55152016-11-02 14:37:54 -0700658 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700659 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700660}
661
tsepez4cf55152016-11-02 14:37:54 -0700662bool CPWL_Edit::OnChar(uint16_t nChar, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700663 if (m_bMouseDown)
tsepez4cf55152016-11-02 14:37:54 -0700664 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700665
tsepez4cf55152016-11-02 14:37:54 -0700666 bool bRC = true;
667 bool bExit = false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700668
Lei Zhanga5b47042015-10-19 14:32:16 -0700669 if (!IsCTRLpressed(nFlag)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700670 if (m_pFillerNotify) {
671 CFX_WideString swChange;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700672
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700673 int nSelStart = 0;
674 int nSelEnd = 0;
675 GetSel(nSelStart, nSelEnd);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700676
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700677 switch (nChar) {
678 case FWL_VKEY_Back:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700679 if (nSelStart == nSelEnd)
680 nSelStart = nSelEnd - 1;
681 break;
682 case FWL_VKEY_Return:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700683 break;
684 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700685 swChange += nChar;
686 break;
687 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700688
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700689 CFX_WideString strChangeEx;
Lei Zhanga5b47042015-10-19 14:32:16 -0700690 m_pFillerNotify->OnBeforeKeyStroke(GetAttachedData(), swChange,
tsepez4cf55152016-11-02 14:37:54 -0700691 strChangeEx, nSelStart, nSelEnd, true,
Lei Zhanga5b47042015-10-19 14:32:16 -0700692 bRC, bExit, nFlag);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700693 }
694 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700695
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700696 if (!bRC)
tsepez4cf55152016-11-02 14:37:54 -0700697 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700698 if (bExit)
tsepez4cf55152016-11-02 14:37:54 -0700699 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700700
dsinclairc7a73492016-04-05 12:01:42 -0700701 if (IPVT_FontMap* pFontMap = GetFontMap()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700702 int32_t nOldCharSet = GetCharSet();
npmea3c3be2016-09-19 07:24:33 -0700703 int32_t nNewCharSet =
704 pFontMap->CharSetFromUnicode(nChar, FXFONT_DEFAULT_CHARSET);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700705 if (nOldCharSet != nNewCharSet) {
706 SetCharSet(nNewCharSet);
707 }
708 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700709
Lei Zhanga5b47042015-10-19 14:32:16 -0700710 return CPWL_EditCtrl::OnChar(nChar, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700711}
712
tsepez4cf55152016-11-02 14:37:54 -0700713bool CPWL_Edit::OnMouseWheel(short zDelta,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500714 const CFX_PointF& point,
tsepez4cf55152016-11-02 14:37:54 -0700715 uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700716 if (HasFlag(PES_MULTILINE)) {
Dan Sinclairf528eee2017-02-14 11:52:07 -0500717 CFX_PointF ptScroll = GetScrollPos();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700718
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700719 if (zDelta > 0) {
720 ptScroll.y += GetFontSize();
721 } else {
722 ptScroll.y -= GetFontSize();
723 }
724 SetScrollPos(ptScroll);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700725
tsepez4cf55152016-11-02 14:37:54 -0700726 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700727 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700728
tsepez4cf55152016-11-02 14:37:54 -0700729 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700730}
731
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700732void CPWL_Edit::OnInsertReturn(const CPVT_WordPlace& place,
733 const CPVT_WordPlace& oldplace) {
734 if (HasFlag(PES_SPELLCHECK)) {
735 m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace),
736 GetLatinWordsRange(place)));
737 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700738}
739
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700740void CPWL_Edit::OnBackSpace(const CPVT_WordPlace& place,
741 const CPVT_WordPlace& oldplace) {
742 if (HasFlag(PES_SPELLCHECK)) {
743 m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace),
744 GetLatinWordsRange(place)));
745 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700746}
747
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700748void CPWL_Edit::OnDelete(const CPVT_WordPlace& place,
749 const CPVT_WordPlace& oldplace) {
750 if (HasFlag(PES_SPELLCHECK)) {
751 m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace),
752 GetLatinWordsRange(place)));
753 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700754}
755
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700756void CPWL_Edit::OnClear(const CPVT_WordPlace& place,
757 const CPVT_WordPlace& oldplace) {
758 if (HasFlag(PES_SPELLCHECK)) {
759 m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace),
760 GetLatinWordsRange(place)));
761 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700762}
763
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700764void CPWL_Edit::OnInsertWord(const CPVT_WordPlace& place,
765 const CPVT_WordPlace& oldplace) {
766 if (HasFlag(PES_SPELLCHECK)) {
767 m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace),
768 GetLatinWordsRange(place)));
769 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700770}
771
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700772void CPWL_Edit::OnInsertText(const CPVT_WordPlace& place,
773 const CPVT_WordPlace& oldplace) {
774 if (HasFlag(PES_SPELLCHECK)) {
775 m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace),
776 GetLatinWordsRange(place)));
777 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700778}
779
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700780CPVT_WordRange CPWL_Edit::CombineWordRange(const CPVT_WordRange& wr1,
781 const CPVT_WordRange& wr2) {
782 CPVT_WordRange wrRet;
783
784 if (wr1.BeginPos.WordCmp(wr2.BeginPos) < 0) {
785 wrRet.BeginPos = wr1.BeginPos;
786 } else {
787 wrRet.BeginPos = wr2.BeginPos;
788 }
789
790 if (wr1.EndPos.WordCmp(wr2.EndPos) < 0) {
791 wrRet.EndPos = wr2.EndPos;
792 } else {
793 wrRet.EndPos = wr1.EndPos;
794 }
795
796 return wrRet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700797}
798
Dan Sinclairf528eee2017-02-14 11:52:07 -0500799CPVT_WordRange CPWL_Edit::GetLatinWordsRange(const CFX_PointF& point) const {
tsepez4cf55152016-11-02 14:37:54 -0700800 return GetSameWordsRange(m_pEdit->SearchWordPlace(point), true, false);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700801}
802
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700803CPVT_WordRange CPWL_Edit::GetLatinWordsRange(
804 const CPVT_WordPlace& place) const {
tsepez4cf55152016-11-02 14:37:54 -0700805 return GetSameWordsRange(place, true, false);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700806}
807
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700808CPVT_WordRange CPWL_Edit::GetArabicWordsRange(
809 const CPVT_WordPlace& place) const {
tsepez4cf55152016-11-02 14:37:54 -0700810 return GetSameWordsRange(place, false, true);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700811}
812
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700813#define PWL_ISARABICWORD(word) \
814 ((word >= 0x0600 && word <= 0x06FF) || (word >= 0xFB50 && word <= 0xFEFC))
815
816CPVT_WordRange CPWL_Edit::GetSameWordsRange(const CPVT_WordPlace& place,
tsepez4cf55152016-11-02 14:37:54 -0700817 bool bLatin,
818 bool bArabic) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700819 CPVT_WordRange range;
820
dsinclaire35af1e2016-07-13 11:26:20 -0700821 CFX_Edit_Iterator* pIterator = m_pEdit->GetIterator();
thestig821d59e2016-05-11 12:59:22 -0700822 CPVT_Word wordinfo;
823 CPVT_WordPlace wpStart(place), wpEnd(place);
824 pIterator->SetAt(place);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700825
thestig821d59e2016-05-11 12:59:22 -0700826 if (bLatin) {
827 while (pIterator->NextWord()) {
828 if (!pIterator->GetWord(wordinfo) ||
829 !FX_EDIT_ISLATINWORD(wordinfo.Word)) {
830 break;
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800831 }
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800832
thestig821d59e2016-05-11 12:59:22 -0700833 wpEnd = pIterator->GetAt();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700834 }
thestig821d59e2016-05-11 12:59:22 -0700835 } else if (bArabic) {
836 while (pIterator->NextWord()) {
837 if (!pIterator->GetWord(wordinfo) || !PWL_ISARABICWORD(wordinfo.Word))
838 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700839
thestig821d59e2016-05-11 12:59:22 -0700840 wpEnd = pIterator->GetAt();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700841 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700842 }
843
thestig821d59e2016-05-11 12:59:22 -0700844 pIterator->SetAt(place);
845
846 if (bLatin) {
847 do {
848 if (!pIterator->GetWord(wordinfo) ||
849 !FX_EDIT_ISLATINWORD(wordinfo.Word)) {
850 break;
851 }
852
853 wpStart = pIterator->GetAt();
854 } while (pIterator->PrevWord());
855 } else if (bArabic) {
856 do {
857 if (!pIterator->GetWord(wordinfo) || !PWL_ISARABICWORD(wordinfo.Word))
858 break;
859
860 wpStart = pIterator->GetAt();
861 } while (pIterator->PrevWord());
862 }
863
864 range.Set(wpStart, wpEnd);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700865 return range;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700866}