blob: b1285a84289ea47cf26168e1a7f2081201588cee [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
Tom Sepez52f69b32017-03-21 13:42:38 -07009#include <algorithm>
Lei Zhanga99de0e2017-02-27 14:45:56 -080010#include <memory>
Dan Sinclair3ebd1212016-03-09 09:59:23 -050011#include <vector>
12
dsinclairbc5e6d22016-10-04 11:08:49 -070013#include "core/fpdfapi/font/cpdf_font.h"
dsinclair1727aee2016-09-29 13:12:56 -070014#include "core/fpdfdoc/cpvt_word.h"
dsinclaira52ab742016-09-29 13:59:29 -070015#include "core/fxcrt/fx_safe_types.h"
Dan Sinclair908c8482017-03-30 14:33:28 -040016#include "core/fxcrt/xml/cxml_element.h"
dsinclair74a34fc2016-09-29 16:41:42 -070017#include "core/fxge/cfx_graphstatedata.h"
18#include "core/fxge/cfx_pathdata.h"
19#include "core/fxge/cfx_renderdevice.h"
20#include "core/fxge/fx_font.h"
dsinclair0bb385b2016-09-29 17:03:59 -070021#include "fpdfsdk/fxedit/fxet_edit.h"
dan sinclair89e904b2016-03-23 19:29:15 -040022#include "fpdfsdk/pdfwindow/PWL_Caret.h"
23#include "fpdfsdk/pdfwindow/PWL_EditCtrl.h"
24#include "fpdfsdk/pdfwindow/PWL_FontMap.h"
25#include "fpdfsdk/pdfwindow/PWL_ScrollBar.h"
26#include "fpdfsdk/pdfwindow/PWL_Utils.h"
27#include "fpdfsdk/pdfwindow/PWL_Wnd.h"
Lei Zhangc2fb35f2016-01-05 16:46:58 -080028#include "public/fpdf_fwlevent.h"
Tom Sepezab277682016-02-17 10:07:21 -080029#include "third_party/base/stl_util.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070030
Nico Weber9d8ec5a2015-08-04 13:00:21 -070031CPWL_Edit::CPWL_Edit()
tsepez4cf55152016-11-02 14:37:54 -070032 : m_pFillerNotify(nullptr), m_bFocus(false), m_pFormFiller(nullptr) {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070033
Nico Weber9d8ec5a2015-08-04 13:00:21 -070034CPWL_Edit::~CPWL_Edit() {
tsepez4cf55152016-11-02 14:37:54 -070035 ASSERT(m_bFocus == false);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070036}
37
Nico Weber9d8ec5a2015-08-04 13:00:21 -070038CFX_ByteString CPWL_Edit::GetClassName() const {
39 return PWL_CLASSNAME_EDIT;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070040}
41
Nico Weber9d8ec5a2015-08-04 13:00:21 -070042void CPWL_Edit::OnDestroy() {}
43
tsepez067990c2016-09-13 06:46:40 -070044void CPWL_Edit::SetText(const CFX_WideString& csText) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070045 CFX_WideString swText = csText;
Lei Zhanga99de0e2017-02-27 14:45:56 -080046 if (!HasFlag(PES_RICH)) {
47 m_pEdit->SetText(swText);
48 return;
49 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070050
Lei Zhanga99de0e2017-02-27 14:45:56 -080051 CFX_ByteString sValue = CFX_ByteString::FromUnicode(swText);
52 std::unique_ptr<CXML_Element> pXML(
53 CXML_Element::Parse(sValue.c_str(), sValue.GetLength()));
54 if (!pXML) {
55 m_pEdit->SetText(swText);
56 return;
57 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070058
Lei Zhanga99de0e2017-02-27 14:45:56 -080059 int32_t nCount = pXML->CountChildren();
60 bool bFirst = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070061
Lei Zhanga99de0e2017-02-27 14:45:56 -080062 swText.clear();
Nico Weber9d8ec5a2015-08-04 13:00:21 -070063
Lei Zhanga99de0e2017-02-27 14:45:56 -080064 for (int32_t i = 0; i < nCount; i++) {
65 CXML_Element* pSubElement = pXML->GetElement(i);
66 if (!pSubElement)
67 continue;
68
69 CFX_ByteString tag = pSubElement->GetTagName();
70 if (tag.EqualNoCase("p")) {
71 int nChild = pSubElement->CountChildren();
72 CFX_WideString swSection;
73 for (int32_t j = 0; j < nChild; j++)
74 swSection += pSubElement->GetContent(j);
75
76 if (bFirst)
77 bFirst = false;
78 else
79 swText += FWL_VKEY_Return;
80 swText += swSection;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070081 }
82 }
83
tsepez067990c2016-09-13 06:46:40 -070084 m_pEdit->SetText(swText);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070085}
86
Nico Weber9d8ec5a2015-08-04 13:00:21 -070087void CPWL_Edit::RePosChildWnd() {
88 if (CPWL_ScrollBar* pVSB = GetVScrollBar()) {
Tom Sepez281a9ea2016-02-26 14:24:28 -080089 CFX_FloatRect rcWindow = m_rcOldWindow;
90 CFX_FloatRect rcVScroll =
91 CFX_FloatRect(rcWindow.right, rcWindow.bottom,
92 rcWindow.right + PWL_SCROLLBAR_WIDTH, rcWindow.top);
tsepez4cf55152016-11-02 14:37:54 -070093 pVSB->Move(rcVScroll, true, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070094 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070095
Nico Weber9d8ec5a2015-08-04 13:00:21 -070096 if (m_pEditCaret && !HasFlag(PES_TEXTOVERFLOW))
97 m_pEditCaret->SetClipRect(CPWL_Utils::InflateRect(
Dan Sinclair50cce602016-02-24 09:51:16 -050098 GetClientRect(), 1.0f)); // +1 for caret beside border
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070099
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700100 CPWL_EditCtrl::RePosChildWnd();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700101}
102
Tom Sepez281a9ea2016-02-26 14:24:28 -0800103CFX_FloatRect CPWL_Edit::GetClientRect() const {
104 CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(
Dan Sinclair05df0752017-03-14 14:43:42 -0400105 GetWindowRect(), (float)(GetBorderWidth() + GetInnerBorderWidth()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700106
107 if (CPWL_ScrollBar* pVSB = GetVScrollBar()) {
108 if (pVSB->IsVisible()) {
109 rcClient.right -= PWL_SCROLLBAR_WIDTH;
110 }
111 }
112
113 return rcClient;
114}
115
tsepez4cf55152016-11-02 14:37:54 -0700116void CPWL_Edit::SetAlignFormatV(PWL_EDIT_ALIGNFORMAT_V nFormat, bool bPaint) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700117 m_pEdit->SetAlignmentV((int32_t)nFormat, bPaint);
118}
119
tsepez4cf55152016-11-02 14:37:54 -0700120bool CPWL_Edit::CanSelectAll() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700121 return GetSelectWordRange() != m_pEdit->GetWholeWordRange();
122}
123
tsepez4cf55152016-11-02 14:37:54 -0700124bool CPWL_Edit::CanClear() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700125 return !IsReadOnly() && m_pEdit->IsSelected();
126}
127
tsepez4cf55152016-11-02 14:37:54 -0700128bool CPWL_Edit::CanCopy() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700129 return !HasFlag(PES_PASSWORD) && !HasFlag(PES_NOREAD) &&
130 m_pEdit->IsSelected();
131}
132
tsepez4cf55152016-11-02 14:37:54 -0700133bool CPWL_Edit::CanCut() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700134 return CanCopy() && !IsReadOnly();
135}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700136void CPWL_Edit::CutText() {
137 if (!CanCut())
138 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700139 m_pEdit->Clear();
140}
141
142void CPWL_Edit::OnCreated() {
143 CPWL_EditCtrl::OnCreated();
144
145 if (CPWL_ScrollBar* pScroll = GetVScrollBar()) {
146 pScroll->RemoveFlag(PWS_AUTOTRANSPARENT);
147 pScroll->SetTransparency(255);
148 }
149
150 SetParamByFlag();
151
152 m_rcOldWindow = GetWindowRect();
153
154 m_pEdit->SetOprNotify(this);
tsepez4cf55152016-11-02 14:37:54 -0700155 m_pEdit->EnableOprNotify(true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700156}
157
158void CPWL_Edit::SetParamByFlag() {
159 if (HasFlag(PES_RIGHT)) {
tsepez4cf55152016-11-02 14:37:54 -0700160 m_pEdit->SetAlignmentH(2, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700161 } else if (HasFlag(PES_MIDDLE)) {
tsepez4cf55152016-11-02 14:37:54 -0700162 m_pEdit->SetAlignmentH(1, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700163 } else {
tsepez4cf55152016-11-02 14:37:54 -0700164 m_pEdit->SetAlignmentH(0, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700165 }
166
167 if (HasFlag(PES_BOTTOM)) {
tsepez4cf55152016-11-02 14:37:54 -0700168 m_pEdit->SetAlignmentV(2, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700169 } else if (HasFlag(PES_CENTER)) {
tsepez4cf55152016-11-02 14:37:54 -0700170 m_pEdit->SetAlignmentV(1, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700171 } else {
tsepez4cf55152016-11-02 14:37:54 -0700172 m_pEdit->SetAlignmentV(0, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700173 }
174
175 if (HasFlag(PES_PASSWORD)) {
tsepez4cf55152016-11-02 14:37:54 -0700176 m_pEdit->SetPasswordChar('*', false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700177 }
178
tsepez4cf55152016-11-02 14:37:54 -0700179 m_pEdit->SetMultiLine(HasFlag(PES_MULTILINE), false);
180 m_pEdit->SetAutoReturn(HasFlag(PES_AUTORETURN), false);
181 m_pEdit->SetAutoFontSize(HasFlag(PWS_AUTOFONTSIZE), false);
182 m_pEdit->SetAutoScroll(HasFlag(PES_AUTOSCROLL), false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700183 m_pEdit->EnableUndo(HasFlag(PES_UNDO));
184
185 if (HasFlag(PES_TEXTOVERFLOW)) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800186 SetClipRect(CFX_FloatRect(0.0f, 0.0f, 0.0f, 0.0f));
tsepez4cf55152016-11-02 14:37:54 -0700187 m_pEdit->SetTextOverflow(true, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700188 } else {
189 if (m_pEditCaret) {
190 m_pEditCaret->SetClipRect(CPWL_Utils::InflateRect(
Dan Sinclair50cce602016-02-24 09:51:16 -0500191 GetClientRect(), 1.0f)); // +1 for caret beside border
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700192 }
193 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700194}
195
196void CPWL_Edit::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) {
197 CPWL_Wnd::GetThisAppearanceStream(sAppStream);
198
Tom Sepez281a9ea2016-02-26 14:24:28 -0800199 CFX_FloatRect rcClient = GetClientRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700200 CFX_ByteTextBuf sLine;
201
202 int32_t nCharArray = m_pEdit->GetCharArray();
203
204 if (nCharArray > 0) {
205 switch (GetBorderStyle()) {
dsinclair92cb5e52016-05-16 11:38:28 -0700206 case BorderStyle::SOLID: {
tsepez4cf55152016-11-02 14:37:54 -0700207 sLine << "q\n"
208 << GetBorderWidth() << " w\n"
209 << CPWL_Utils::GetColorAppStream(GetBorderColor(), false)
tsepez4c3debb2016-04-08 12:20:38 -0700210 .AsStringC()
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700211 << " 2 J 0 j\n";
212
213 for (int32_t i = 1; i < nCharArray; i++) {
214 sLine << rcClient.left +
215 ((rcClient.right - rcClient.left) / nCharArray) * i
216 << " " << rcClient.bottom << " m\n"
217 << rcClient.left +
218 ((rcClient.right - rcClient.left) / nCharArray) * i
219 << " " << rcClient.top << " l S\n";
220 }
221
222 sLine << "Q\n";
dsinclair92cb5e52016-05-16 11:38:28 -0700223 break;
224 }
225 case BorderStyle::DASH: {
tsepez4cf55152016-11-02 14:37:54 -0700226 sLine << "q\n"
227 << GetBorderWidth() << " w\n"
228 << CPWL_Utils::GetColorAppStream(GetBorderColor(), false)
tsepez4c3debb2016-04-08 12:20:38 -0700229 .AsStringC()
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700230 << " 2 J 0 j\n"
231 << "[" << GetBorderDash().nDash << " " << GetBorderDash().nGap
232 << "] " << GetBorderDash().nPhase << " d\n";
233
234 for (int32_t i = 1; i < nCharArray; i++) {
235 sLine << rcClient.left +
236 ((rcClient.right - rcClient.left) / nCharArray) * i
237 << " " << rcClient.bottom << " m\n"
238 << rcClient.left +
239 ((rcClient.right - rcClient.left) / nCharArray) * i
240 << " " << rcClient.top << " l S\n";
241 }
242
243 sLine << "Q\n";
dsinclair92cb5e52016-05-16 11:38:28 -0700244 break;
245 }
246 default:
247 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700248 }
249 }
250
251 sAppStream << sLine;
252
253 CFX_ByteTextBuf sText;
Dan Sinclairf528eee2017-02-14 11:52:07 -0500254 CFX_PointF ptOffset;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700255 CPVT_WordRange wrWhole = m_pEdit->GetWholeWordRange();
256 CPVT_WordRange wrSelect = GetSelectWordRange();
257 CPVT_WordRange wrVisible =
tsepez63f545c2016-09-13 16:08:49 -0700258 HasFlag(PES_TEXTOVERFLOW) ? wrWhole : m_pEdit->GetVisibleWordRange();
259
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700260 CPVT_WordRange wrSelBefore(wrWhole.BeginPos, wrSelect.BeginPos);
261 CPVT_WordRange wrSelAfter(wrSelect.EndPos, wrWhole.EndPos);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700262 CPVT_WordRange wrTemp =
263 CPWL_Utils::OverlapWordRange(GetSelectWordRange(), wrVisible);
264 CFX_ByteString sEditSel =
dsinclaire35af1e2016-07-13 11:26:20 -0700265 CPWL_Utils::GetEditSelAppStream(m_pEdit.get(), ptOffset, &wrTemp);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700266
267 if (sEditSel.GetLength() > 0)
tsepez4c3debb2016-04-08 12:20:38 -0700268 sText << CPWL_Utils::GetColorAppStream(PWL_DEFAULT_SELBACKCOLOR).AsStringC()
269 << sEditSel.AsStringC();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700270
271 wrTemp = CPWL_Utils::OverlapWordRange(wrVisible, wrSelBefore);
272 CFX_ByteString sEditBefore = CPWL_Utils::GetEditAppStream(
dsinclaire35af1e2016-07-13 11:26:20 -0700273 m_pEdit.get(), ptOffset, &wrTemp, !HasFlag(PES_CHARARRAY),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700274 m_pEdit->GetPasswordChar());
275
276 if (sEditBefore.GetLength() > 0)
Dan Sinclaira0061af2017-02-23 09:25:17 -0500277 sText << "BT\n"
278 << CPWL_Utils::GetColorAppStream(GetTextColor()).AsStringC()
tsepez4c3debb2016-04-08 12:20:38 -0700279 << sEditBefore.AsStringC() << "ET\n";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700280
281 wrTemp = CPWL_Utils::OverlapWordRange(wrVisible, wrSelect);
282 CFX_ByteString sEditMid = CPWL_Utils::GetEditAppStream(
dsinclaire35af1e2016-07-13 11:26:20 -0700283 m_pEdit.get(), ptOffset, &wrTemp, !HasFlag(PES_CHARARRAY),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700284 m_pEdit->GetPasswordChar());
285
286 if (sEditMid.GetLength() > 0)
287 sText << "BT\n"
288 << CPWL_Utils::GetColorAppStream(CPWL_Color(COLORTYPE_GRAY, 1))
tsepez4c3debb2016-04-08 12:20:38 -0700289 .AsStringC()
290 << sEditMid.AsStringC() << "ET\n";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700291
292 wrTemp = CPWL_Utils::OverlapWordRange(wrVisible, wrSelAfter);
293 CFX_ByteString sEditAfter = CPWL_Utils::GetEditAppStream(
dsinclaire35af1e2016-07-13 11:26:20 -0700294 m_pEdit.get(), ptOffset, &wrTemp, !HasFlag(PES_CHARARRAY),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700295 m_pEdit->GetPasswordChar());
296
297 if (sEditAfter.GetLength() > 0)
Dan Sinclaira0061af2017-02-23 09:25:17 -0500298 sText << "BT\n"
299 << CPWL_Utils::GetColorAppStream(GetTextColor()).AsStringC()
tsepez4c3debb2016-04-08 12:20:38 -0700300 << sEditAfter.AsStringC() << "ET\n";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700301
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700302 if (sText.GetLength() > 0) {
weilidb444d22016-06-02 15:48:15 -0700303 CFX_FloatRect rect = GetClientRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700304 sAppStream << "q\n/Tx BMC\n";
305
306 if (!HasFlag(PES_TEXTOVERFLOW))
weilidb444d22016-06-02 15:48:15 -0700307 sAppStream << rect.left << " " << rect.bottom << " "
308 << rect.right - rect.left << " " << rect.top - rect.bottom
309 << " re W n\n";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700310
311 sAppStream << sText;
312
313 sAppStream << "EMC\nQ\n";
314 }
315}
316
317void CPWL_Edit::DrawThisAppearance(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800318 CFX_Matrix* pUser2Device) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700319 CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device);
320
Tom Sepez281a9ea2016-02-26 14:24:28 -0800321 CFX_FloatRect rcClient = GetClientRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700322 CFX_ByteTextBuf sLine;
323
324 int32_t nCharArray = m_pEdit->GetCharArray();
325 FX_SAFE_INT32 nCharArraySafe = nCharArray;
326 nCharArraySafe -= 1;
327 nCharArraySafe *= 2;
328
329 if (nCharArray > 0 && nCharArraySafe.IsValid()) {
330 switch (GetBorderStyle()) {
dsinclair92cb5e52016-05-16 11:38:28 -0700331 case BorderStyle::SOLID: {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700332 CFX_GraphStateData gsd;
Dan Sinclair05df0752017-03-14 14:43:42 -0400333 gsd.m_LineWidth = (float)GetBorderWidth();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700334
335 CFX_PathData path;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700336
337 for (int32_t i = 0; i < nCharArray - 1; i++) {
Dan Sinclaire4602322017-02-15 11:07:32 -0500338 path.AppendPoint(
dan sinclairb147e072017-02-22 19:56:15 -0500339 CFX_PointF(
340 rcClient.left +
341 ((rcClient.right - rcClient.left) / nCharArray) * (i + 1),
342 rcClient.bottom),
343 FXPT_TYPE::MoveTo, false);
Dan Sinclaire4602322017-02-15 11:07:32 -0500344 path.AppendPoint(
dan sinclairb147e072017-02-22 19:56:15 -0500345 CFX_PointF(
346 rcClient.left +
347 ((rcClient.right - rcClient.left) / nCharArray) * (i + 1),
348 rcClient.top),
349 FXPT_TYPE::LineTo, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700350 }
Dan Sinclaire4602322017-02-15 11:07:32 -0500351 if (!path.GetPoints().empty()) {
Dan Sinclairfc54e052017-02-23 09:59:05 -0500352 pDevice->DrawPath(&path, pUser2Device, &gsd, 0,
353 GetBorderColor().ToFXColor(255), FXFILL_ALTERNATE);
dsinclair92cb5e52016-05-16 11:38:28 -0700354 }
355 break;
356 }
357 case BorderStyle::DASH: {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700358 CFX_GraphStateData gsd;
Dan Sinclair05df0752017-03-14 14:43:42 -0400359 gsd.m_LineWidth = (float)GetBorderWidth();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700360
361 gsd.SetDashCount(2);
Dan Sinclair05df0752017-03-14 14:43:42 -0400362 gsd.m_DashArray[0] = (float)GetBorderDash().nDash;
363 gsd.m_DashArray[1] = (float)GetBorderDash().nGap;
364 gsd.m_DashPhase = (float)GetBorderDash().nPhase;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700365
366 CFX_PathData path;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700367 for (int32_t i = 0; i < nCharArray - 1; i++) {
Dan Sinclaire4602322017-02-15 11:07:32 -0500368 path.AppendPoint(
dan sinclairb147e072017-02-22 19:56:15 -0500369 CFX_PointF(
370 rcClient.left +
371 ((rcClient.right - rcClient.left) / nCharArray) * (i + 1),
372 rcClient.bottom),
373 FXPT_TYPE::MoveTo, false);
Dan Sinclaire4602322017-02-15 11:07:32 -0500374 path.AppendPoint(
dan sinclairb147e072017-02-22 19:56:15 -0500375 CFX_PointF(
376 rcClient.left +
377 ((rcClient.right - rcClient.left) / nCharArray) * (i + 1),
378 rcClient.top),
379 FXPT_TYPE::LineTo, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700380 }
Dan Sinclaire4602322017-02-15 11:07:32 -0500381 if (!path.GetPoints().empty()) {
Dan Sinclairfc54e052017-02-23 09:59:05 -0500382 pDevice->DrawPath(&path, pUser2Device, &gsd, 0,
383 GetBorderColor().ToFXColor(255), FXFILL_ALTERNATE);
dsinclair92cb5e52016-05-16 11:38:28 -0700384 }
385 break;
386 }
387 default:
388 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700389 }
390 }
391
Tom Sepez281a9ea2016-02-26 14:24:28 -0800392 CFX_FloatRect rcClip;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700393 CPVT_WordRange wrRange = m_pEdit->GetVisibleWordRange();
thestig1cd352e2016-06-07 17:53:06 -0700394 CPVT_WordRange* pRange = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700395 if (!HasFlag(PES_TEXTOVERFLOW)) {
396 rcClip = GetClientRect();
397 pRange = &wrRange;
398 }
tsepez63f545c2016-09-13 16:08:49 -0700399
dsinclairb9590102016-04-27 06:38:59 -0700400 CFX_SystemHandler* pSysHandler = GetSystemHandler();
Dan Sinclairfc54e052017-02-23 09:59:05 -0500401 CFX_Edit::DrawEdit(pDevice, pUser2Device, m_pEdit.get(),
402 GetTextColor().ToFXColor(GetTransparency()), rcClip,
403 CFX_PointF(), pRange, pSysHandler, m_pFormFiller);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700404}
405
Dan Sinclairf528eee2017-02-14 11:52:07 -0500406bool CPWL_Edit::OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700407 CPWL_Wnd::OnLButtonDown(point, nFlag);
408
409 if (HasFlag(PES_TEXTOVERFLOW) || ClientHitTest(point)) {
410 if (m_bMouseDown)
411 InvalidateRect();
412
tsepez4cf55152016-11-02 14:37:54 -0700413 m_bMouseDown = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700414 SetCapture();
415
416 m_pEdit->OnMouseDown(point, IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
417 }
418
tsepez4cf55152016-11-02 14:37:54 -0700419 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700420}
421
Dan Sinclairf528eee2017-02-14 11:52:07 -0500422bool CPWL_Edit::OnLButtonDblClk(const CFX_PointF& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700423 CPWL_Wnd::OnLButtonDblClk(point, nFlag);
424
425 if (HasFlag(PES_TEXTOVERFLOW) || ClientHitTest(point)) {
426 m_pEdit->SelectAll();
427 }
428
tsepez4cf55152016-11-02 14:37:54 -0700429 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700430}
431
Dan Sinclairf528eee2017-02-14 11:52:07 -0500432bool CPWL_Edit::OnRButtonUp(const CFX_PointF& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700433 if (m_bMouseDown)
tsepez4cf55152016-11-02 14:37:54 -0700434 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700435
436 CPWL_Wnd::OnRButtonUp(point, nFlag);
437
438 if (!HasFlag(PES_TEXTOVERFLOW) && !ClientHitTest(point))
tsepez4cf55152016-11-02 14:37:54 -0700439 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700440
dsinclairb9590102016-04-27 06:38:59 -0700441 CFX_SystemHandler* pSH = GetSystemHandler();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700442 if (!pSH)
tsepez4cf55152016-11-02 14:37:54 -0700443 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700444
445 SetFocus();
446
tsepez4cf55152016-11-02 14:37:54 -0700447 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700448}
449
450void CPWL_Edit::OnSetFocus() {
tsepez4cf55152016-11-02 14:37:54 -0700451 SetEditCaret(true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700452 if (!IsReadOnly()) {
453 if (IPWL_FocusHandler* pFocusHandler = GetFocusHandler())
454 pFocusHandler->OnSetFocus(this);
455 }
tsepez4cf55152016-11-02 14:37:54 -0700456 m_bFocus = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700457}
458
459void CPWL_Edit::OnKillFocus() {
tsepez4cf55152016-11-02 14:37:54 -0700460 ShowVScrollBar(false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700461 m_pEdit->SelectNone();
Dan Sinclairf528eee2017-02-14 11:52:07 -0500462 SetCaret(false, CFX_PointF(), CFX_PointF());
Dan Sinclairf51a02a2017-04-19 12:46:53 -0400463 SetCharSet(FX_CHARSET_ANSI);
tsepez4cf55152016-11-02 14:37:54 -0700464 m_bFocus = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700465}
466
Dan Sinclair05df0752017-03-14 14:43:42 -0400467void CPWL_Edit::SetCharSpace(float fCharSpace) {
dsinclairefd5a992016-07-18 10:04:07 -0700468 m_pEdit->SetCharSpace(fCharSpace);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700469}
470
471CFX_ByteString CPWL_Edit::GetSelectAppearanceStream(
Dan Sinclairf528eee2017-02-14 11:52:07 -0500472 const CFX_PointF& ptOffset) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700473 CPVT_WordRange wr = GetSelectWordRange();
dsinclaire35af1e2016-07-13 11:26:20 -0700474 return CPWL_Utils::GetEditSelAppStream(m_pEdit.get(), ptOffset, &wr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700475}
476
477CPVT_WordRange CPWL_Edit::GetSelectWordRange() const {
478 if (m_pEdit->IsSelected()) {
479 int32_t nStart = -1;
480 int32_t nEnd = -1;
481
482 m_pEdit->GetSel(nStart, nEnd);
483
484 CPVT_WordPlace wpStart = m_pEdit->WordIndexToWordPlace(nStart);
485 CPVT_WordPlace wpEnd = m_pEdit->WordIndexToWordPlace(nEnd);
486
487 return CPVT_WordRange(wpStart, wpEnd);
488 }
489
490 return CPVT_WordRange();
491}
492
493CFX_ByteString CPWL_Edit::GetTextAppearanceStream(
Dan Sinclairf528eee2017-02-14 11:52:07 -0500494 const CFX_PointF& ptOffset) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700495 CFX_ByteTextBuf sRet;
dsinclaire35af1e2016-07-13 11:26:20 -0700496 CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream(m_pEdit.get(), ptOffset);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700497 if (sEdit.GetLength() > 0) {
Dan Sinclaira0061af2017-02-23 09:25:17 -0500498 sRet << "BT\n"
499 << CPWL_Utils::GetColorAppStream(GetTextColor()).AsStringC()
tsepez4c3debb2016-04-08 12:20:38 -0700500 << sEdit.AsStringC() << "ET\n";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700501 }
tsepez71a452f2016-05-13 17:51:27 -0700502 return sRet.MakeString();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700503}
504
505CFX_ByteString CPWL_Edit::GetCaretAppearanceStream(
Dan Sinclairf528eee2017-02-14 11:52:07 -0500506 const CFX_PointF& ptOffset) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700507 if (m_pEditCaret)
508 return m_pEditCaret->GetCaretAppearanceStream(ptOffset);
509
510 return CFX_ByteString();
511}
512
Dan Sinclairf528eee2017-02-14 11:52:07 -0500513CFX_PointF CPWL_Edit::GetWordRightBottomPoint(const CPVT_WordPlace& wpWord) {
dsinclaire35af1e2016-07-13 11:26:20 -0700514 CFX_Edit_Iterator* pIterator = m_pEdit->GetIterator();
thestig821d59e2016-05-11 12:59:22 -0700515 CPVT_WordPlace wpOld = pIterator->GetAt();
516 pIterator->SetAt(wpWord);
tsepez63f545c2016-09-13 16:08:49 -0700517
Dan Sinclairf528eee2017-02-14 11:52:07 -0500518 CFX_PointF pt;
thestig821d59e2016-05-11 12:59:22 -0700519 CPVT_Word word;
520 if (pIterator->GetWord(word)) {
Dan Sinclairf528eee2017-02-14 11:52:07 -0500521 pt = CFX_PointF(word.ptWord.x + word.fWidth, word.ptWord.y + word.fDescent);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700522 }
thestig821d59e2016-05-11 12:59:22 -0700523 pIterator->SetAt(wpOld);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700524 return pt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700525}
526
tsepez4cf55152016-11-02 14:37:54 -0700527bool CPWL_Edit::IsTextFull() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700528 return m_pEdit->IsTextFull();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700529}
530
Dan Sinclair05df0752017-03-14 14:43:42 -0400531float CPWL_Edit::GetCharArrayAutoFontSize(CPDF_Font* pFont,
532 const CFX_FloatRect& rcPlate,
533 int32_t nCharArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700534 if (pFont && !pFont->IsStandardFont()) {
535 FX_RECT rcBBox;
536 pFont->GetFontBBox(rcBBox);
537
Tom Sepez281a9ea2016-02-26 14:24:28 -0800538 CFX_FloatRect rcCell = rcPlate;
Dan Sinclair05df0752017-03-14 14:43:42 -0400539 float xdiv = rcCell.Width() / nCharArray * 1000.0f / rcBBox.Width();
540 float ydiv = -rcCell.Height() * 1000.0f / rcBBox.Height();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700541
542 return xdiv < ydiv ? xdiv : ydiv;
543 }
544
545 return 0.0f;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700546}
547
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700548void CPWL_Edit::SetCharArray(int32_t nCharArray) {
549 if (HasFlag(PES_CHARARRAY) && nCharArray > 0) {
550 m_pEdit->SetCharArray(nCharArray);
tsepez4cf55152016-11-02 14:37:54 -0700551 m_pEdit->SetTextOverflow(true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700552
553 if (HasFlag(PWS_AUTOFONTSIZE)) {
dsinclairc7a73492016-04-05 12:01:42 -0700554 if (IPVT_FontMap* pFontMap = GetFontMap()) {
Dan Sinclair05df0752017-03-14 14:43:42 -0400555 float fFontSize = GetCharArrayAutoFontSize(pFontMap->GetPDFFont(0),
556 GetClientRect(), nCharArray);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700557 if (fFontSize > 0.0f) {
tsepez4cf55152016-11-02 14:37:54 -0700558 m_pEdit->SetAutoFontSize(false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700559 m_pEdit->SetFontSize(fFontSize);
560 }
561 }
562 }
563 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700564}
565
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700566void CPWL_Edit::SetLimitChar(int32_t nLimitChar) {
567 m_pEdit->SetLimitChar(nLimitChar);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700568}
569
tsepez067990c2016-09-13 06:46:40 -0700570void CPWL_Edit::ReplaceSel(const CFX_WideString& wsText) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700571 m_pEdit->Clear();
Dan Sinclairf51a02a2017-04-19 12:46:53 -0400572 m_pEdit->InsertText(wsText, FX_CHARSET_Default);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700573}
574
Tom Sepez281a9ea2016-02-26 14:24:28 -0800575CFX_FloatRect CPWL_Edit::GetFocusRect() const {
576 return CFX_FloatRect();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700577}
578
tsepez4cf55152016-11-02 14:37:54 -0700579void CPWL_Edit::ShowVScrollBar(bool bShow) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700580 if (CPWL_ScrollBar* pScroll = GetVScrollBar()) {
581 if (bShow) {
582 if (!pScroll->IsVisible()) {
tsepez4cf55152016-11-02 14:37:54 -0700583 pScroll->SetVisible(true);
Tom Sepez281a9ea2016-02-26 14:24:28 -0800584 CFX_FloatRect rcWindow = GetWindowRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700585 m_rcOldWindow = rcWindow;
586 rcWindow.right += PWL_SCROLLBAR_WIDTH;
tsepez4cf55152016-11-02 14:37:54 -0700587 Move(rcWindow, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700588 }
589 } else {
590 if (pScroll->IsVisible()) {
tsepez4cf55152016-11-02 14:37:54 -0700591 pScroll->SetVisible(false);
592 Move(m_rcOldWindow, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700593 }
594 }
595 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700596}
597
tsepez4cf55152016-11-02 14:37:54 -0700598bool CPWL_Edit::IsVScrollBarVisible() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700599 if (CPWL_ScrollBar* pScroll = GetVScrollBar()) {
600 return pScroll->IsVisible();
601 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700602
tsepez4cf55152016-11-02 14:37:54 -0700603 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700604}
605
tsepez4cf55152016-11-02 14:37:54 -0700606bool CPWL_Edit::OnKeyDown(uint16_t nChar, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700607 if (m_bMouseDown)
tsepez4cf55152016-11-02 14:37:54 -0700608 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700609
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700610 if (nChar == FWL_VKEY_Delete) {
611 if (m_pFillerNotify) {
tsepez4cf55152016-11-02 14:37:54 -0700612 bool bRC = true;
613 bool bExit = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700614 CFX_WideString strChange;
615 CFX_WideString strChangeEx;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700616
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700617 int nSelStart = 0;
618 int nSelEnd = 0;
619 GetSel(nSelStart, nSelEnd);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700620
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700621 if (nSelStart == nSelEnd)
622 nSelEnd = nSelStart + 1;
Lei Zhanga5b47042015-10-19 14:32:16 -0700623 m_pFillerNotify->OnBeforeKeyStroke(GetAttachedData(), strChange,
tsepez4cf55152016-11-02 14:37:54 -0700624 strChangeEx, nSelStart, nSelEnd, true,
Lei Zhanga5b47042015-10-19 14:32:16 -0700625 bRC, bExit, nFlag);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700626 if (!bRC)
tsepez4cf55152016-11-02 14:37:54 -0700627 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700628 if (bExit)
tsepez4cf55152016-11-02 14:37:54 -0700629 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700630 }
631 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700632
tsepez4cf55152016-11-02 14:37:54 -0700633 bool bRet = CPWL_EditCtrl::OnKeyDown(nChar, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700634
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700635 // In case of implementation swallow the OnKeyDown event.
636 if (IsProceedtoOnChar(nChar, nFlag))
tsepez4cf55152016-11-02 14:37:54 -0700637 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700638
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700639 return bRet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700640}
641
642/**
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700643*In case of implementation swallow the OnKeyDown event.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700644*If the event is swallowed, implementation may do other unexpected things, which
645*is not the control means to do.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700646*/
tsepez4cf55152016-11-02 14:37:54 -0700647bool CPWL_Edit::IsProceedtoOnChar(uint16_t nKeyCode, uint32_t nFlag) {
648 bool bCtrl = IsCTRLpressed(nFlag);
649 bool bAlt = IsALTpressed(nFlag);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700650 if (bCtrl && !bAlt) {
651 // hot keys for edit control.
652 switch (nKeyCode) {
653 case 'C':
654 case 'V':
655 case 'X':
656 case 'A':
657 case 'Z':
tsepez4cf55152016-11-02 14:37:54 -0700658 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700659 default:
660 break;
661 }
662 }
663 // control characters.
664 switch (nKeyCode) {
665 case FWL_VKEY_Escape:
666 case FWL_VKEY_Back:
667 case FWL_VKEY_Return:
668 case FWL_VKEY_Space:
tsepez4cf55152016-11-02 14:37:54 -0700669 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700670 default:
tsepez4cf55152016-11-02 14:37:54 -0700671 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700672 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700673}
674
tsepez4cf55152016-11-02 14:37:54 -0700675bool CPWL_Edit::OnChar(uint16_t nChar, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700676 if (m_bMouseDown)
tsepez4cf55152016-11-02 14:37:54 -0700677 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700678
tsepez4cf55152016-11-02 14:37:54 -0700679 bool bRC = true;
680 bool bExit = false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700681
Lei Zhanga5b47042015-10-19 14:32:16 -0700682 if (!IsCTRLpressed(nFlag)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700683 if (m_pFillerNotify) {
684 CFX_WideString swChange;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700685
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700686 int nSelStart = 0;
687 int nSelEnd = 0;
688 GetSel(nSelStart, nSelEnd);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700689
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700690 switch (nChar) {
691 case FWL_VKEY_Back:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700692 if (nSelStart == nSelEnd)
693 nSelStart = nSelEnd - 1;
694 break;
695 case FWL_VKEY_Return:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700696 break;
697 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700698 swChange += nChar;
699 break;
700 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700701
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700702 CFX_WideString strChangeEx;
Lei Zhanga5b47042015-10-19 14:32:16 -0700703 m_pFillerNotify->OnBeforeKeyStroke(GetAttachedData(), swChange,
tsepez4cf55152016-11-02 14:37:54 -0700704 strChangeEx, nSelStart, nSelEnd, true,
Lei Zhanga5b47042015-10-19 14:32:16 -0700705 bRC, bExit, nFlag);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700706 }
707 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700708
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700709 if (!bRC)
tsepez4cf55152016-11-02 14:37:54 -0700710 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700711 if (bExit)
tsepez4cf55152016-11-02 14:37:54 -0700712 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700713
dsinclairc7a73492016-04-05 12:01:42 -0700714 if (IPVT_FontMap* pFontMap = GetFontMap()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700715 int32_t nOldCharSet = GetCharSet();
npmea3c3be2016-09-19 07:24:33 -0700716 int32_t nNewCharSet =
Dan Sinclairf51a02a2017-04-19 12:46:53 -0400717 pFontMap->CharSetFromUnicode(nChar, FX_CHARSET_Default);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700718 if (nOldCharSet != nNewCharSet) {
719 SetCharSet(nNewCharSet);
720 }
721 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700722
Lei Zhanga5b47042015-10-19 14:32:16 -0700723 return CPWL_EditCtrl::OnChar(nChar, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700724}
725
tsepez4cf55152016-11-02 14:37:54 -0700726bool CPWL_Edit::OnMouseWheel(short zDelta,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500727 const CFX_PointF& point,
tsepez4cf55152016-11-02 14:37:54 -0700728 uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700729 if (HasFlag(PES_MULTILINE)) {
Dan Sinclairf528eee2017-02-14 11:52:07 -0500730 CFX_PointF ptScroll = GetScrollPos();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700731
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700732 if (zDelta > 0) {
733 ptScroll.y += GetFontSize();
734 } else {
735 ptScroll.y -= GetFontSize();
736 }
737 SetScrollPos(ptScroll);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700738
tsepez4cf55152016-11-02 14:37:54 -0700739 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700740 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700741
tsepez4cf55152016-11-02 14:37:54 -0700742 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700743}
744
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700745void CPWL_Edit::OnInsertReturn(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::OnBackSpace(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::OnDelete(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::OnClear(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::OnInsertWord(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 -0700785void CPWL_Edit::OnInsertText(const CPVT_WordPlace& place,
786 const CPVT_WordPlace& oldplace) {
787 if (HasFlag(PES_SPELLCHECK)) {
788 m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace),
789 GetLatinWordsRange(place)));
790 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700791}
792
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700793CPVT_WordRange CPWL_Edit::CombineWordRange(const CPVT_WordRange& wr1,
794 const CPVT_WordRange& wr2) {
Tom Sepez52f69b32017-03-21 13:42:38 -0700795 return CPVT_WordRange(std::min(wr1.BeginPos, wr2.BeginPos),
796 std::max(wr1.EndPos, wr2.EndPos));
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}