blob: f84c38e23b428b2f7dea80b5f361d08fd7a59b3e [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
Lei Zhanga99de0e2017-02-27 14:45:56 -08009#include <memory>
Dan Sinclair3ebd1212016-03-09 09:59:23 -050010#include <vector>
11
dsinclairbc5e6d22016-10-04 11:08:49 -070012#include "core/fpdfapi/font/cpdf_font.h"
dsinclair1727aee2016-09-29 13:12:56 -070013#include "core/fpdfdoc/cpvt_word.h"
dsinclaira52ab742016-09-29 13:59:29 -070014#include "core/fxcrt/fx_safe_types.h"
15#include "core/fxcrt/fx_xml.h"
dsinclair74a34fc2016-09-29 16:41:42 -070016#include "core/fxge/cfx_graphstatedata.h"
17#include "core/fxge/cfx_pathdata.h"
18#include "core/fxge/cfx_renderdevice.h"
19#include "core/fxge/fx_font.h"
dsinclair0bb385b2016-09-29 17:03:59 -070020#include "fpdfsdk/fxedit/fxet_edit.h"
dan sinclair89e904b2016-03-23 19:29:15 -040021#include "fpdfsdk/pdfwindow/PWL_Caret.h"
22#include "fpdfsdk/pdfwindow/PWL_EditCtrl.h"
23#include "fpdfsdk/pdfwindow/PWL_FontMap.h"
24#include "fpdfsdk/pdfwindow/PWL_ScrollBar.h"
25#include "fpdfsdk/pdfwindow/PWL_Utils.h"
26#include "fpdfsdk/pdfwindow/PWL_Wnd.h"
Lei Zhangc2fb35f2016-01-05 16:46:58 -080027#include "public/fpdf_fwlevent.h"
Tom Sepezab277682016-02-17 10:07:21 -080028#include "third_party/base/stl_util.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070029
Nico Weber9d8ec5a2015-08-04 13:00:21 -070030CPWL_Edit::CPWL_Edit()
tsepez4cf55152016-11-02 14:37:54 -070031 : m_pFillerNotify(nullptr), m_bFocus(false), m_pFormFiller(nullptr) {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070032
Nico Weber9d8ec5a2015-08-04 13:00:21 -070033CPWL_Edit::~CPWL_Edit() {
tsepez4cf55152016-11-02 14:37:54 -070034 ASSERT(m_bFocus == false);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070035}
36
Nico Weber9d8ec5a2015-08-04 13:00:21 -070037CFX_ByteString CPWL_Edit::GetClassName() const {
38 return PWL_CLASSNAME_EDIT;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070039}
40
Nico Weber9d8ec5a2015-08-04 13:00:21 -070041void CPWL_Edit::OnDestroy() {}
42
tsepez067990c2016-09-13 06:46:40 -070043void CPWL_Edit::SetText(const CFX_WideString& csText) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070044 CFX_WideString swText = csText;
Lei Zhanga99de0e2017-02-27 14:45:56 -080045 if (!HasFlag(PES_RICH)) {
46 m_pEdit->SetText(swText);
47 return;
48 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070049
Lei Zhanga99de0e2017-02-27 14:45:56 -080050 CFX_ByteString sValue = CFX_ByteString::FromUnicode(swText);
51 std::unique_ptr<CXML_Element> pXML(
52 CXML_Element::Parse(sValue.c_str(), sValue.GetLength()));
53 if (!pXML) {
54 m_pEdit->SetText(swText);
55 return;
56 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070057
Lei Zhanga99de0e2017-02-27 14:45:56 -080058 int32_t nCount = pXML->CountChildren();
59 bool bFirst = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070060
Lei Zhanga99de0e2017-02-27 14:45:56 -080061 swText.clear();
Nico Weber9d8ec5a2015-08-04 13:00:21 -070062
Lei Zhanga99de0e2017-02-27 14:45:56 -080063 for (int32_t i = 0; i < nCount; i++) {
64 CXML_Element* pSubElement = pXML->GetElement(i);
65 if (!pSubElement)
66 continue;
67
68 CFX_ByteString tag = pSubElement->GetTagName();
69 if (tag.EqualNoCase("p")) {
70 int nChild = pSubElement->CountChildren();
71 CFX_WideString swSection;
72 for (int32_t j = 0; j < nChild; j++)
73 swSection += pSubElement->GetContent(j);
74
75 if (bFirst)
76 bFirst = false;
77 else
78 swText += FWL_VKEY_Return;
79 swText += swSection;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070080 }
81 }
82
tsepez067990c2016-09-13 06:46:40 -070083 m_pEdit->SetText(swText);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070084}
85
Nico Weber9d8ec5a2015-08-04 13:00:21 -070086void CPWL_Edit::RePosChildWnd() {
87 if (CPWL_ScrollBar* pVSB = GetVScrollBar()) {
Tom Sepez281a9ea2016-02-26 14:24:28 -080088 CFX_FloatRect rcWindow = m_rcOldWindow;
89 CFX_FloatRect rcVScroll =
90 CFX_FloatRect(rcWindow.right, rcWindow.bottom,
91 rcWindow.right + PWL_SCROLLBAR_WIDTH, rcWindow.top);
tsepez4cf55152016-11-02 14:37:54 -070092 pVSB->Move(rcVScroll, true, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070093 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070094
Nico Weber9d8ec5a2015-08-04 13:00:21 -070095 if (m_pEditCaret && !HasFlag(PES_TEXTOVERFLOW))
96 m_pEditCaret->SetClipRect(CPWL_Utils::InflateRect(
Dan Sinclair50cce602016-02-24 09:51:16 -050097 GetClientRect(), 1.0f)); // +1 for caret beside border
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070098
Nico Weber9d8ec5a2015-08-04 13:00:21 -070099 CPWL_EditCtrl::RePosChildWnd();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700100}
101
Tom Sepez281a9ea2016-02-26 14:24:28 -0800102CFX_FloatRect CPWL_Edit::GetClientRect() const {
103 CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(
Dan Sinclair05df0752017-03-14 14:43:42 -0400104 GetWindowRect(), (float)(GetBorderWidth() + GetInnerBorderWidth()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700105
106 if (CPWL_ScrollBar* pVSB = GetVScrollBar()) {
107 if (pVSB->IsVisible()) {
108 rcClient.right -= PWL_SCROLLBAR_WIDTH;
109 }
110 }
111
112 return rcClient;
113}
114
tsepez4cf55152016-11-02 14:37:54 -0700115void CPWL_Edit::SetAlignFormatV(PWL_EDIT_ALIGNFORMAT_V nFormat, bool bPaint) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700116 m_pEdit->SetAlignmentV((int32_t)nFormat, bPaint);
117}
118
tsepez4cf55152016-11-02 14:37:54 -0700119bool CPWL_Edit::CanSelectAll() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700120 return GetSelectWordRange() != m_pEdit->GetWholeWordRange();
121}
122
tsepez4cf55152016-11-02 14:37:54 -0700123bool CPWL_Edit::CanClear() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700124 return !IsReadOnly() && m_pEdit->IsSelected();
125}
126
tsepez4cf55152016-11-02 14:37:54 -0700127bool CPWL_Edit::CanCopy() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700128 return !HasFlag(PES_PASSWORD) && !HasFlag(PES_NOREAD) &&
129 m_pEdit->IsSelected();
130}
131
tsepez4cf55152016-11-02 14:37:54 -0700132bool CPWL_Edit::CanCut() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700133 return CanCopy() && !IsReadOnly();
134}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700135void CPWL_Edit::CutText() {
136 if (!CanCut())
137 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700138 m_pEdit->Clear();
139}
140
141void CPWL_Edit::OnCreated() {
142 CPWL_EditCtrl::OnCreated();
143
144 if (CPWL_ScrollBar* pScroll = GetVScrollBar()) {
145 pScroll->RemoveFlag(PWS_AUTOTRANSPARENT);
146 pScroll->SetTransparency(255);
147 }
148
149 SetParamByFlag();
150
151 m_rcOldWindow = GetWindowRect();
152
153 m_pEdit->SetOprNotify(this);
tsepez4cf55152016-11-02 14:37:54 -0700154 m_pEdit->EnableOprNotify(true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700155}
156
157void CPWL_Edit::SetParamByFlag() {
158 if (HasFlag(PES_RIGHT)) {
tsepez4cf55152016-11-02 14:37:54 -0700159 m_pEdit->SetAlignmentH(2, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700160 } else if (HasFlag(PES_MIDDLE)) {
tsepez4cf55152016-11-02 14:37:54 -0700161 m_pEdit->SetAlignmentH(1, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700162 } else {
tsepez4cf55152016-11-02 14:37:54 -0700163 m_pEdit->SetAlignmentH(0, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700164 }
165
166 if (HasFlag(PES_BOTTOM)) {
tsepez4cf55152016-11-02 14:37:54 -0700167 m_pEdit->SetAlignmentV(2, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700168 } else if (HasFlag(PES_CENTER)) {
tsepez4cf55152016-11-02 14:37:54 -0700169 m_pEdit->SetAlignmentV(1, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700170 } else {
tsepez4cf55152016-11-02 14:37:54 -0700171 m_pEdit->SetAlignmentV(0, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700172 }
173
174 if (HasFlag(PES_PASSWORD)) {
tsepez4cf55152016-11-02 14:37:54 -0700175 m_pEdit->SetPasswordChar('*', false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700176 }
177
tsepez4cf55152016-11-02 14:37:54 -0700178 m_pEdit->SetMultiLine(HasFlag(PES_MULTILINE), false);
179 m_pEdit->SetAutoReturn(HasFlag(PES_AUTORETURN), false);
180 m_pEdit->SetAutoFontSize(HasFlag(PWS_AUTOFONTSIZE), false);
181 m_pEdit->SetAutoScroll(HasFlag(PES_AUTOSCROLL), false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700182 m_pEdit->EnableUndo(HasFlag(PES_UNDO));
183
184 if (HasFlag(PES_TEXTOVERFLOW)) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800185 SetClipRect(CFX_FloatRect(0.0f, 0.0f, 0.0f, 0.0f));
tsepez4cf55152016-11-02 14:37:54 -0700186 m_pEdit->SetTextOverflow(true, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700187 } else {
188 if (m_pEditCaret) {
189 m_pEditCaret->SetClipRect(CPWL_Utils::InflateRect(
Dan Sinclair50cce602016-02-24 09:51:16 -0500190 GetClientRect(), 1.0f)); // +1 for caret beside border
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700191 }
192 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700193}
194
195void CPWL_Edit::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) {
196 CPWL_Wnd::GetThisAppearanceStream(sAppStream);
197
Tom Sepez281a9ea2016-02-26 14:24:28 -0800198 CFX_FloatRect rcClient = GetClientRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700199 CFX_ByteTextBuf sLine;
200
201 int32_t nCharArray = m_pEdit->GetCharArray();
202
203 if (nCharArray > 0) {
204 switch (GetBorderStyle()) {
dsinclair92cb5e52016-05-16 11:38:28 -0700205 case BorderStyle::SOLID: {
tsepez4cf55152016-11-02 14:37:54 -0700206 sLine << "q\n"
207 << GetBorderWidth() << " w\n"
208 << CPWL_Utils::GetColorAppStream(GetBorderColor(), false)
tsepez4c3debb2016-04-08 12:20:38 -0700209 .AsStringC()
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700210 << " 2 J 0 j\n";
211
212 for (int32_t i = 1; i < nCharArray; i++) {
213 sLine << rcClient.left +
214 ((rcClient.right - rcClient.left) / nCharArray) * i
215 << " " << rcClient.bottom << " m\n"
216 << rcClient.left +
217 ((rcClient.right - rcClient.left) / nCharArray) * i
218 << " " << rcClient.top << " l S\n";
219 }
220
221 sLine << "Q\n";
dsinclair92cb5e52016-05-16 11:38:28 -0700222 break;
223 }
224 case BorderStyle::DASH: {
tsepez4cf55152016-11-02 14:37:54 -0700225 sLine << "q\n"
226 << GetBorderWidth() << " w\n"
227 << CPWL_Utils::GetColorAppStream(GetBorderColor(), false)
tsepez4c3debb2016-04-08 12:20:38 -0700228 .AsStringC()
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700229 << " 2 J 0 j\n"
230 << "[" << GetBorderDash().nDash << " " << GetBorderDash().nGap
231 << "] " << GetBorderDash().nPhase << " d\n";
232
233 for (int32_t i = 1; i < nCharArray; i++) {
234 sLine << rcClient.left +
235 ((rcClient.right - rcClient.left) / nCharArray) * i
236 << " " << rcClient.bottom << " m\n"
237 << rcClient.left +
238 ((rcClient.right - rcClient.left) / nCharArray) * i
239 << " " << rcClient.top << " l S\n";
240 }
241
242 sLine << "Q\n";
dsinclair92cb5e52016-05-16 11:38:28 -0700243 break;
244 }
245 default:
246 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700247 }
248 }
249
250 sAppStream << sLine;
251
252 CFX_ByteTextBuf sText;
Dan Sinclairf528eee2017-02-14 11:52:07 -0500253 CFX_PointF ptOffset;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700254 CPVT_WordRange wrWhole = m_pEdit->GetWholeWordRange();
255 CPVT_WordRange wrSelect = GetSelectWordRange();
256 CPVT_WordRange wrVisible =
tsepez63f545c2016-09-13 16:08:49 -0700257 HasFlag(PES_TEXTOVERFLOW) ? wrWhole : m_pEdit->GetVisibleWordRange();
258
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700259 CPVT_WordRange wrSelBefore(wrWhole.BeginPos, wrSelect.BeginPos);
260 CPVT_WordRange wrSelAfter(wrSelect.EndPos, wrWhole.EndPos);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700261 CPVT_WordRange wrTemp =
262 CPWL_Utils::OverlapWordRange(GetSelectWordRange(), wrVisible);
263 CFX_ByteString sEditSel =
dsinclaire35af1e2016-07-13 11:26:20 -0700264 CPWL_Utils::GetEditSelAppStream(m_pEdit.get(), ptOffset, &wrTemp);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700265
266 if (sEditSel.GetLength() > 0)
tsepez4c3debb2016-04-08 12:20:38 -0700267 sText << CPWL_Utils::GetColorAppStream(PWL_DEFAULT_SELBACKCOLOR).AsStringC()
268 << sEditSel.AsStringC();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700269
270 wrTemp = CPWL_Utils::OverlapWordRange(wrVisible, wrSelBefore);
271 CFX_ByteString sEditBefore = CPWL_Utils::GetEditAppStream(
dsinclaire35af1e2016-07-13 11:26:20 -0700272 m_pEdit.get(), ptOffset, &wrTemp, !HasFlag(PES_CHARARRAY),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700273 m_pEdit->GetPasswordChar());
274
275 if (sEditBefore.GetLength() > 0)
Dan Sinclaira0061af2017-02-23 09:25:17 -0500276 sText << "BT\n"
277 << CPWL_Utils::GetColorAppStream(GetTextColor()).AsStringC()
tsepez4c3debb2016-04-08 12:20:38 -0700278 << sEditBefore.AsStringC() << "ET\n";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700279
280 wrTemp = CPWL_Utils::OverlapWordRange(wrVisible, wrSelect);
281 CFX_ByteString sEditMid = CPWL_Utils::GetEditAppStream(
dsinclaire35af1e2016-07-13 11:26:20 -0700282 m_pEdit.get(), ptOffset, &wrTemp, !HasFlag(PES_CHARARRAY),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700283 m_pEdit->GetPasswordChar());
284
285 if (sEditMid.GetLength() > 0)
286 sText << "BT\n"
287 << CPWL_Utils::GetColorAppStream(CPWL_Color(COLORTYPE_GRAY, 1))
tsepez4c3debb2016-04-08 12:20:38 -0700288 .AsStringC()
289 << sEditMid.AsStringC() << "ET\n";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700290
291 wrTemp = CPWL_Utils::OverlapWordRange(wrVisible, wrSelAfter);
292 CFX_ByteString sEditAfter = CPWL_Utils::GetEditAppStream(
dsinclaire35af1e2016-07-13 11:26:20 -0700293 m_pEdit.get(), ptOffset, &wrTemp, !HasFlag(PES_CHARARRAY),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700294 m_pEdit->GetPasswordChar());
295
296 if (sEditAfter.GetLength() > 0)
Dan Sinclaira0061af2017-02-23 09:25:17 -0500297 sText << "BT\n"
298 << CPWL_Utils::GetColorAppStream(GetTextColor()).AsStringC()
tsepez4c3debb2016-04-08 12:20:38 -0700299 << sEditAfter.AsStringC() << "ET\n";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700300
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700301 if (sText.GetLength() > 0) {
weilidb444d22016-06-02 15:48:15 -0700302 CFX_FloatRect rect = GetClientRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700303 sAppStream << "q\n/Tx BMC\n";
304
305 if (!HasFlag(PES_TEXTOVERFLOW))
weilidb444d22016-06-02 15:48:15 -0700306 sAppStream << rect.left << " " << rect.bottom << " "
307 << rect.right - rect.left << " " << rect.top - rect.bottom
308 << " re W n\n";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700309
310 sAppStream << sText;
311
312 sAppStream << "EMC\nQ\n";
313 }
314}
315
316void CPWL_Edit::DrawThisAppearance(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800317 CFX_Matrix* pUser2Device) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700318 CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device);
319
Tom Sepez281a9ea2016-02-26 14:24:28 -0800320 CFX_FloatRect rcClient = GetClientRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700321 CFX_ByteTextBuf sLine;
322
323 int32_t nCharArray = m_pEdit->GetCharArray();
324 FX_SAFE_INT32 nCharArraySafe = nCharArray;
325 nCharArraySafe -= 1;
326 nCharArraySafe *= 2;
327
328 if (nCharArray > 0 && nCharArraySafe.IsValid()) {
329 switch (GetBorderStyle()) {
dsinclair92cb5e52016-05-16 11:38:28 -0700330 case BorderStyle::SOLID: {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700331 CFX_GraphStateData gsd;
Dan Sinclair05df0752017-03-14 14:43:42 -0400332 gsd.m_LineWidth = (float)GetBorderWidth();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700333
334 CFX_PathData path;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700335
336 for (int32_t i = 0; i < nCharArray - 1; i++) {
Dan Sinclaire4602322017-02-15 11:07:32 -0500337 path.AppendPoint(
dan sinclairb147e072017-02-22 19:56:15 -0500338 CFX_PointF(
339 rcClient.left +
340 ((rcClient.right - rcClient.left) / nCharArray) * (i + 1),
341 rcClient.bottom),
342 FXPT_TYPE::MoveTo, false);
Dan Sinclaire4602322017-02-15 11:07:32 -0500343 path.AppendPoint(
dan sinclairb147e072017-02-22 19:56:15 -0500344 CFX_PointF(
345 rcClient.left +
346 ((rcClient.right - rcClient.left) / nCharArray) * (i + 1),
347 rcClient.top),
348 FXPT_TYPE::LineTo, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700349 }
Dan Sinclaire4602322017-02-15 11:07:32 -0500350 if (!path.GetPoints().empty()) {
Dan Sinclairfc54e052017-02-23 09:59:05 -0500351 pDevice->DrawPath(&path, pUser2Device, &gsd, 0,
352 GetBorderColor().ToFXColor(255), FXFILL_ALTERNATE);
dsinclair92cb5e52016-05-16 11:38:28 -0700353 }
354 break;
355 }
356 case BorderStyle::DASH: {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700357 CFX_GraphStateData gsd;
Dan Sinclair05df0752017-03-14 14:43:42 -0400358 gsd.m_LineWidth = (float)GetBorderWidth();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700359
360 gsd.SetDashCount(2);
Dan Sinclair05df0752017-03-14 14:43:42 -0400361 gsd.m_DashArray[0] = (float)GetBorderDash().nDash;
362 gsd.m_DashArray[1] = (float)GetBorderDash().nGap;
363 gsd.m_DashPhase = (float)GetBorderDash().nPhase;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700364
365 CFX_PathData path;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700366 for (int32_t i = 0; i < nCharArray - 1; i++) {
Dan Sinclaire4602322017-02-15 11:07:32 -0500367 path.AppendPoint(
dan sinclairb147e072017-02-22 19:56:15 -0500368 CFX_PointF(
369 rcClient.left +
370 ((rcClient.right - rcClient.left) / nCharArray) * (i + 1),
371 rcClient.bottom),
372 FXPT_TYPE::MoveTo, false);
Dan Sinclaire4602322017-02-15 11:07:32 -0500373 path.AppendPoint(
dan sinclairb147e072017-02-22 19:56:15 -0500374 CFX_PointF(
375 rcClient.left +
376 ((rcClient.right - rcClient.left) / nCharArray) * (i + 1),
377 rcClient.top),
378 FXPT_TYPE::LineTo, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700379 }
Dan Sinclaire4602322017-02-15 11:07:32 -0500380 if (!path.GetPoints().empty()) {
Dan Sinclairfc54e052017-02-23 09:59:05 -0500381 pDevice->DrawPath(&path, pUser2Device, &gsd, 0,
382 GetBorderColor().ToFXColor(255), FXFILL_ALTERNATE);
dsinclair92cb5e52016-05-16 11:38:28 -0700383 }
384 break;
385 }
386 default:
387 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700388 }
389 }
390
Tom Sepez281a9ea2016-02-26 14:24:28 -0800391 CFX_FloatRect rcClip;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700392 CPVT_WordRange wrRange = m_pEdit->GetVisibleWordRange();
thestig1cd352e2016-06-07 17:53:06 -0700393 CPVT_WordRange* pRange = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700394 if (!HasFlag(PES_TEXTOVERFLOW)) {
395 rcClip = GetClientRect();
396 pRange = &wrRange;
397 }
tsepez63f545c2016-09-13 16:08:49 -0700398
dsinclairb9590102016-04-27 06:38:59 -0700399 CFX_SystemHandler* pSysHandler = GetSystemHandler();
Dan Sinclairfc54e052017-02-23 09:59:05 -0500400 CFX_Edit::DrawEdit(pDevice, pUser2Device, m_pEdit.get(),
401 GetTextColor().ToFXColor(GetTransparency()), rcClip,
402 CFX_PointF(), pRange, pSysHandler, m_pFormFiller);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700403}
404
Dan Sinclairf528eee2017-02-14 11:52:07 -0500405bool CPWL_Edit::OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700406 CPWL_Wnd::OnLButtonDown(point, nFlag);
407
408 if (HasFlag(PES_TEXTOVERFLOW) || ClientHitTest(point)) {
409 if (m_bMouseDown)
410 InvalidateRect();
411
tsepez4cf55152016-11-02 14:37:54 -0700412 m_bMouseDown = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700413 SetCapture();
414
415 m_pEdit->OnMouseDown(point, IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
416 }
417
tsepez4cf55152016-11-02 14:37:54 -0700418 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700419}
420
Dan Sinclairf528eee2017-02-14 11:52:07 -0500421bool CPWL_Edit::OnLButtonDblClk(const CFX_PointF& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700422 CPWL_Wnd::OnLButtonDblClk(point, nFlag);
423
424 if (HasFlag(PES_TEXTOVERFLOW) || ClientHitTest(point)) {
425 m_pEdit->SelectAll();
426 }
427
tsepez4cf55152016-11-02 14:37:54 -0700428 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700429}
430
Dan Sinclairf528eee2017-02-14 11:52:07 -0500431bool CPWL_Edit::OnRButtonUp(const CFX_PointF& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700432 if (m_bMouseDown)
tsepez4cf55152016-11-02 14:37:54 -0700433 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700434
435 CPWL_Wnd::OnRButtonUp(point, nFlag);
436
437 if (!HasFlag(PES_TEXTOVERFLOW) && !ClientHitTest(point))
tsepez4cf55152016-11-02 14:37:54 -0700438 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700439
dsinclairb9590102016-04-27 06:38:59 -0700440 CFX_SystemHandler* pSH = GetSystemHandler();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700441 if (!pSH)
tsepez4cf55152016-11-02 14:37:54 -0700442 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700443
444 SetFocus();
445
tsepez4cf55152016-11-02 14:37:54 -0700446 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700447}
448
449void CPWL_Edit::OnSetFocus() {
tsepez4cf55152016-11-02 14:37:54 -0700450 SetEditCaret(true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700451 if (!IsReadOnly()) {
452 if (IPWL_FocusHandler* pFocusHandler = GetFocusHandler())
453 pFocusHandler->OnSetFocus(this);
454 }
tsepez4cf55152016-11-02 14:37:54 -0700455 m_bFocus = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700456}
457
458void CPWL_Edit::OnKillFocus() {
tsepez4cf55152016-11-02 14:37:54 -0700459 ShowVScrollBar(false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700460 m_pEdit->SelectNone();
Dan Sinclairf528eee2017-02-14 11:52:07 -0500461 SetCaret(false, CFX_PointF(), CFX_PointF());
thestig907a5222016-06-21 14:38:27 -0700462 SetCharSet(FXFONT_ANSI_CHARSET);
tsepez4cf55152016-11-02 14:37:54 -0700463 m_bFocus = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700464}
465
Dan Sinclair05df0752017-03-14 14:43:42 -0400466void CPWL_Edit::SetCharSpace(float fCharSpace) {
dsinclairefd5a992016-07-18 10:04:07 -0700467 m_pEdit->SetCharSpace(fCharSpace);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700468}
469
470CFX_ByteString CPWL_Edit::GetSelectAppearanceStream(
Dan Sinclairf528eee2017-02-14 11:52:07 -0500471 const CFX_PointF& ptOffset) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700472 CPVT_WordRange wr = GetSelectWordRange();
dsinclaire35af1e2016-07-13 11:26:20 -0700473 return CPWL_Utils::GetEditSelAppStream(m_pEdit.get(), ptOffset, &wr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700474}
475
476CPVT_WordRange CPWL_Edit::GetSelectWordRange() const {
477 if (m_pEdit->IsSelected()) {
478 int32_t nStart = -1;
479 int32_t nEnd = -1;
480
481 m_pEdit->GetSel(nStart, nEnd);
482
483 CPVT_WordPlace wpStart = m_pEdit->WordIndexToWordPlace(nStart);
484 CPVT_WordPlace wpEnd = m_pEdit->WordIndexToWordPlace(nEnd);
485
486 return CPVT_WordRange(wpStart, wpEnd);
487 }
488
489 return CPVT_WordRange();
490}
491
492CFX_ByteString CPWL_Edit::GetTextAppearanceStream(
Dan Sinclairf528eee2017-02-14 11:52:07 -0500493 const CFX_PointF& ptOffset) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700494 CFX_ByteTextBuf sRet;
dsinclaire35af1e2016-07-13 11:26:20 -0700495 CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream(m_pEdit.get(), ptOffset);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700496 if (sEdit.GetLength() > 0) {
Dan Sinclaira0061af2017-02-23 09:25:17 -0500497 sRet << "BT\n"
498 << CPWL_Utils::GetColorAppStream(GetTextColor()).AsStringC()
tsepez4c3debb2016-04-08 12:20:38 -0700499 << sEdit.AsStringC() << "ET\n";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700500 }
tsepez71a452f2016-05-13 17:51:27 -0700501 return sRet.MakeString();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700502}
503
504CFX_ByteString CPWL_Edit::GetCaretAppearanceStream(
Dan Sinclairf528eee2017-02-14 11:52:07 -0500505 const CFX_PointF& ptOffset) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700506 if (m_pEditCaret)
507 return m_pEditCaret->GetCaretAppearanceStream(ptOffset);
508
509 return CFX_ByteString();
510}
511
Dan Sinclairf528eee2017-02-14 11:52:07 -0500512CFX_PointF CPWL_Edit::GetWordRightBottomPoint(const CPVT_WordPlace& wpWord) {
dsinclaire35af1e2016-07-13 11:26:20 -0700513 CFX_Edit_Iterator* pIterator = m_pEdit->GetIterator();
thestig821d59e2016-05-11 12:59:22 -0700514 CPVT_WordPlace wpOld = pIterator->GetAt();
515 pIterator->SetAt(wpWord);
tsepez63f545c2016-09-13 16:08:49 -0700516
Dan Sinclairf528eee2017-02-14 11:52:07 -0500517 CFX_PointF pt;
thestig821d59e2016-05-11 12:59:22 -0700518 CPVT_Word word;
519 if (pIterator->GetWord(word)) {
Dan Sinclairf528eee2017-02-14 11:52:07 -0500520 pt = CFX_PointF(word.ptWord.x + word.fWidth, word.ptWord.y + word.fDescent);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700521 }
thestig821d59e2016-05-11 12:59:22 -0700522 pIterator->SetAt(wpOld);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700523 return pt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700524}
525
tsepez4cf55152016-11-02 14:37:54 -0700526bool CPWL_Edit::IsTextFull() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700527 return m_pEdit->IsTextFull();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700528}
529
Dan Sinclair05df0752017-03-14 14:43:42 -0400530float CPWL_Edit::GetCharArrayAutoFontSize(CPDF_Font* pFont,
531 const CFX_FloatRect& rcPlate,
532 int32_t nCharArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700533 if (pFont && !pFont->IsStandardFont()) {
534 FX_RECT rcBBox;
535 pFont->GetFontBBox(rcBBox);
536
Tom Sepez281a9ea2016-02-26 14:24:28 -0800537 CFX_FloatRect rcCell = rcPlate;
Dan Sinclair05df0752017-03-14 14:43:42 -0400538 float xdiv = rcCell.Width() / nCharArray * 1000.0f / rcBBox.Width();
539 float ydiv = -rcCell.Height() * 1000.0f / rcBBox.Height();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700540
541 return xdiv < ydiv ? xdiv : ydiv;
542 }
543
544 return 0.0f;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700545}
546
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700547void CPWL_Edit::SetCharArray(int32_t nCharArray) {
548 if (HasFlag(PES_CHARARRAY) && nCharArray > 0) {
549 m_pEdit->SetCharArray(nCharArray);
tsepez4cf55152016-11-02 14:37:54 -0700550 m_pEdit->SetTextOverflow(true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700551
552 if (HasFlag(PWS_AUTOFONTSIZE)) {
dsinclairc7a73492016-04-05 12:01:42 -0700553 if (IPVT_FontMap* pFontMap = GetFontMap()) {
Dan Sinclair05df0752017-03-14 14:43:42 -0400554 float fFontSize = GetCharArrayAutoFontSize(pFontMap->GetPDFFont(0),
555 GetClientRect(), nCharArray);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700556 if (fFontSize > 0.0f) {
tsepez4cf55152016-11-02 14:37:54 -0700557 m_pEdit->SetAutoFontSize(false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700558 m_pEdit->SetFontSize(fFontSize);
559 }
560 }
561 }
562 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700563}
564
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700565void CPWL_Edit::SetLimitChar(int32_t nLimitChar) {
566 m_pEdit->SetLimitChar(nLimitChar);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700567}
568
tsepez067990c2016-09-13 06:46:40 -0700569void CPWL_Edit::ReplaceSel(const CFX_WideString& wsText) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700570 m_pEdit->Clear();
npmea3c3be2016-09-19 07:24:33 -0700571 m_pEdit->InsertText(wsText, FXFONT_DEFAULT_CHARSET);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700572}
573
Tom Sepez281a9ea2016-02-26 14:24:28 -0800574CFX_FloatRect CPWL_Edit::GetFocusRect() const {
575 return CFX_FloatRect();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700576}
577
tsepez4cf55152016-11-02 14:37:54 -0700578void CPWL_Edit::ShowVScrollBar(bool bShow) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700579 if (CPWL_ScrollBar* pScroll = GetVScrollBar()) {
580 if (bShow) {
581 if (!pScroll->IsVisible()) {
tsepez4cf55152016-11-02 14:37:54 -0700582 pScroll->SetVisible(true);
Tom Sepez281a9ea2016-02-26 14:24:28 -0800583 CFX_FloatRect rcWindow = GetWindowRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700584 m_rcOldWindow = rcWindow;
585 rcWindow.right += PWL_SCROLLBAR_WIDTH;
tsepez4cf55152016-11-02 14:37:54 -0700586 Move(rcWindow, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700587 }
588 } else {
589 if (pScroll->IsVisible()) {
tsepez4cf55152016-11-02 14:37:54 -0700590 pScroll->SetVisible(false);
591 Move(m_rcOldWindow, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700592 }
593 }
594 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700595}
596
tsepez4cf55152016-11-02 14:37:54 -0700597bool CPWL_Edit::IsVScrollBarVisible() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700598 if (CPWL_ScrollBar* pScroll = GetVScrollBar()) {
599 return pScroll->IsVisible();
600 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700601
tsepez4cf55152016-11-02 14:37:54 -0700602 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700603}
604
tsepez4cf55152016-11-02 14:37:54 -0700605bool CPWL_Edit::OnKeyDown(uint16_t nChar, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700606 if (m_bMouseDown)
tsepez4cf55152016-11-02 14:37:54 -0700607 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700608
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700609 if (nChar == FWL_VKEY_Delete) {
610 if (m_pFillerNotify) {
tsepez4cf55152016-11-02 14:37:54 -0700611 bool bRC = true;
612 bool bExit = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700613 CFX_WideString strChange;
614 CFX_WideString strChangeEx;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700615
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700616 int nSelStart = 0;
617 int nSelEnd = 0;
618 GetSel(nSelStart, nSelEnd);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700619
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700620 if (nSelStart == nSelEnd)
621 nSelEnd = nSelStart + 1;
Lei Zhanga5b47042015-10-19 14:32:16 -0700622 m_pFillerNotify->OnBeforeKeyStroke(GetAttachedData(), strChange,
tsepez4cf55152016-11-02 14:37:54 -0700623 strChangeEx, nSelStart, nSelEnd, true,
Lei Zhanga5b47042015-10-19 14:32:16 -0700624 bRC, bExit, nFlag);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700625 if (!bRC)
tsepez4cf55152016-11-02 14:37:54 -0700626 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700627 if (bExit)
tsepez4cf55152016-11-02 14:37:54 -0700628 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700629 }
630 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700631
tsepez4cf55152016-11-02 14:37:54 -0700632 bool bRet = CPWL_EditCtrl::OnKeyDown(nChar, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700633
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700634 // In case of implementation swallow the OnKeyDown event.
635 if (IsProceedtoOnChar(nChar, nFlag))
tsepez4cf55152016-11-02 14:37:54 -0700636 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700637
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700638 return bRet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700639}
640
641/**
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700642*In case of implementation swallow the OnKeyDown event.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700643*If the event is swallowed, implementation may do other unexpected things, which
644*is not the control means to do.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700645*/
tsepez4cf55152016-11-02 14:37:54 -0700646bool CPWL_Edit::IsProceedtoOnChar(uint16_t nKeyCode, uint32_t nFlag) {
647 bool bCtrl = IsCTRLpressed(nFlag);
648 bool bAlt = IsALTpressed(nFlag);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700649 if (bCtrl && !bAlt) {
650 // hot keys for edit control.
651 switch (nKeyCode) {
652 case 'C':
653 case 'V':
654 case 'X':
655 case 'A':
656 case 'Z':
tsepez4cf55152016-11-02 14:37:54 -0700657 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700658 default:
659 break;
660 }
661 }
662 // control characters.
663 switch (nKeyCode) {
664 case FWL_VKEY_Escape:
665 case FWL_VKEY_Back:
666 case FWL_VKEY_Return:
667 case FWL_VKEY_Space:
tsepez4cf55152016-11-02 14:37:54 -0700668 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700669 default:
tsepez4cf55152016-11-02 14:37:54 -0700670 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700671 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700672}
673
tsepez4cf55152016-11-02 14:37:54 -0700674bool CPWL_Edit::OnChar(uint16_t nChar, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700675 if (m_bMouseDown)
tsepez4cf55152016-11-02 14:37:54 -0700676 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700677
tsepez4cf55152016-11-02 14:37:54 -0700678 bool bRC = true;
679 bool bExit = false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700680
Lei Zhanga5b47042015-10-19 14:32:16 -0700681 if (!IsCTRLpressed(nFlag)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700682 if (m_pFillerNotify) {
683 CFX_WideString swChange;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700684
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700685 int nSelStart = 0;
686 int nSelEnd = 0;
687 GetSel(nSelStart, nSelEnd);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700688
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700689 switch (nChar) {
690 case FWL_VKEY_Back:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700691 if (nSelStart == nSelEnd)
692 nSelStart = nSelEnd - 1;
693 break;
694 case FWL_VKEY_Return:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700695 break;
696 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700697 swChange += nChar;
698 break;
699 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700700
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700701 CFX_WideString strChangeEx;
Lei Zhanga5b47042015-10-19 14:32:16 -0700702 m_pFillerNotify->OnBeforeKeyStroke(GetAttachedData(), swChange,
tsepez4cf55152016-11-02 14:37:54 -0700703 strChangeEx, nSelStart, nSelEnd, true,
Lei Zhanga5b47042015-10-19 14:32:16 -0700704 bRC, bExit, nFlag);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700705 }
706 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700707
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700708 if (!bRC)
tsepez4cf55152016-11-02 14:37:54 -0700709 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700710 if (bExit)
tsepez4cf55152016-11-02 14:37:54 -0700711 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700712
dsinclairc7a73492016-04-05 12:01:42 -0700713 if (IPVT_FontMap* pFontMap = GetFontMap()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700714 int32_t nOldCharSet = GetCharSet();
npmea3c3be2016-09-19 07:24:33 -0700715 int32_t nNewCharSet =
716 pFontMap->CharSetFromUnicode(nChar, FXFONT_DEFAULT_CHARSET);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700717 if (nOldCharSet != nNewCharSet) {
718 SetCharSet(nNewCharSet);
719 }
720 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700721
Lei Zhanga5b47042015-10-19 14:32:16 -0700722 return CPWL_EditCtrl::OnChar(nChar, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700723}
724
tsepez4cf55152016-11-02 14:37:54 -0700725bool CPWL_Edit::OnMouseWheel(short zDelta,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500726 const CFX_PointF& point,
tsepez4cf55152016-11-02 14:37:54 -0700727 uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700728 if (HasFlag(PES_MULTILINE)) {
Dan Sinclairf528eee2017-02-14 11:52:07 -0500729 CFX_PointF ptScroll = GetScrollPos();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700730
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700731 if (zDelta > 0) {
732 ptScroll.y += GetFontSize();
733 } else {
734 ptScroll.y -= GetFontSize();
735 }
736 SetScrollPos(ptScroll);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700737
tsepez4cf55152016-11-02 14:37:54 -0700738 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700739 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700740
tsepez4cf55152016-11-02 14:37:54 -0700741 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700742}
743
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700744void CPWL_Edit::OnInsertReturn(const CPVT_WordPlace& place,
745 const CPVT_WordPlace& oldplace) {
746 if (HasFlag(PES_SPELLCHECK)) {
747 m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace),
748 GetLatinWordsRange(place)));
749 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700750}
751
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700752void CPWL_Edit::OnBackSpace(const CPVT_WordPlace& place,
753 const CPVT_WordPlace& oldplace) {
754 if (HasFlag(PES_SPELLCHECK)) {
755 m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace),
756 GetLatinWordsRange(place)));
757 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700758}
759
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700760void CPWL_Edit::OnDelete(const CPVT_WordPlace& place,
761 const CPVT_WordPlace& oldplace) {
762 if (HasFlag(PES_SPELLCHECK)) {
763 m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace),
764 GetLatinWordsRange(place)));
765 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700766}
767
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700768void CPWL_Edit::OnClear(const CPVT_WordPlace& place,
769 const CPVT_WordPlace& oldplace) {
770 if (HasFlag(PES_SPELLCHECK)) {
771 m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace),
772 GetLatinWordsRange(place)));
773 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700774}
775
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700776void CPWL_Edit::OnInsertWord(const CPVT_WordPlace& place,
777 const CPVT_WordPlace& oldplace) {
778 if (HasFlag(PES_SPELLCHECK)) {
779 m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace),
780 GetLatinWordsRange(place)));
781 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700782}
783
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700784void CPWL_Edit::OnInsertText(const CPVT_WordPlace& place,
785 const CPVT_WordPlace& oldplace) {
786 if (HasFlag(PES_SPELLCHECK)) {
787 m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace),
788 GetLatinWordsRange(place)));
789 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700790}
791
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700792CPVT_WordRange CPWL_Edit::CombineWordRange(const CPVT_WordRange& wr1,
793 const CPVT_WordRange& wr2) {
794 CPVT_WordRange wrRet;
795
796 if (wr1.BeginPos.WordCmp(wr2.BeginPos) < 0) {
797 wrRet.BeginPos = wr1.BeginPos;
798 } else {
799 wrRet.BeginPos = wr2.BeginPos;
800 }
801
802 if (wr1.EndPos.WordCmp(wr2.EndPos) < 0) {
803 wrRet.EndPos = wr2.EndPos;
804 } else {
805 wrRet.EndPos = wr1.EndPos;
806 }
807
808 return wrRet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700809}
810
Dan Sinclairf528eee2017-02-14 11:52:07 -0500811CPVT_WordRange CPWL_Edit::GetLatinWordsRange(const CFX_PointF& point) const {
tsepez4cf55152016-11-02 14:37:54 -0700812 return GetSameWordsRange(m_pEdit->SearchWordPlace(point), true, false);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700813}
814
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700815CPVT_WordRange CPWL_Edit::GetLatinWordsRange(
816 const CPVT_WordPlace& place) const {
tsepez4cf55152016-11-02 14:37:54 -0700817 return GetSameWordsRange(place, true, false);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700818}
819
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700820CPVT_WordRange CPWL_Edit::GetArabicWordsRange(
821 const CPVT_WordPlace& place) const {
tsepez4cf55152016-11-02 14:37:54 -0700822 return GetSameWordsRange(place, false, true);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700823}
824
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700825#define PWL_ISARABICWORD(word) \
826 ((word >= 0x0600 && word <= 0x06FF) || (word >= 0xFB50 && word <= 0xFEFC))
827
828CPVT_WordRange CPWL_Edit::GetSameWordsRange(const CPVT_WordPlace& place,
tsepez4cf55152016-11-02 14:37:54 -0700829 bool bLatin,
830 bool bArabic) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700831 CPVT_WordRange range;
832
dsinclaire35af1e2016-07-13 11:26:20 -0700833 CFX_Edit_Iterator* pIterator = m_pEdit->GetIterator();
thestig821d59e2016-05-11 12:59:22 -0700834 CPVT_Word wordinfo;
835 CPVT_WordPlace wpStart(place), wpEnd(place);
836 pIterator->SetAt(place);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700837
thestig821d59e2016-05-11 12:59:22 -0700838 if (bLatin) {
839 while (pIterator->NextWord()) {
840 if (!pIterator->GetWord(wordinfo) ||
841 !FX_EDIT_ISLATINWORD(wordinfo.Word)) {
842 break;
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800843 }
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800844
thestig821d59e2016-05-11 12:59:22 -0700845 wpEnd = pIterator->GetAt();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700846 }
thestig821d59e2016-05-11 12:59:22 -0700847 } else if (bArabic) {
848 while (pIterator->NextWord()) {
849 if (!pIterator->GetWord(wordinfo) || !PWL_ISARABICWORD(wordinfo.Word))
850 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700851
thestig821d59e2016-05-11 12:59:22 -0700852 wpEnd = pIterator->GetAt();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700853 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700854 }
855
thestig821d59e2016-05-11 12:59:22 -0700856 pIterator->SetAt(place);
857
858 if (bLatin) {
859 do {
860 if (!pIterator->GetWord(wordinfo) ||
861 !FX_EDIT_ISLATINWORD(wordinfo.Word)) {
862 break;
863 }
864
865 wpStart = pIterator->GetAt();
866 } while (pIterator->PrevWord());
867 } else if (bArabic) {
868 do {
869 if (!pIterator->GetWord(wordinfo) || !PWL_ISARABICWORD(wordinfo.Word))
870 break;
871
872 wpStart = pIterator->GetAt();
873 } while (pIterator->PrevWord());
874 }
875
876 range.Set(wpStart, wpEnd);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700877 return range;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700878}