blob: d807f32c34014bb2d52b77299eb8abf53f6b8cd8 [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
Lei Zhang633a3b72017-06-02 15:27:22 -07007#include "fpdfsdk/pdfwindow/cpwl_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"
Tom Sepez8a6fdad2017-05-09 15:03:33 -070016#include "core/fxcrt/xml/cxml_content.h"
Dan Sinclair908c8482017-03-30 14:33:28 -040017#include "core/fxcrt/xml/cxml_element.h"
dsinclair74a34fc2016-09-29 16:41:42 -070018#include "core/fxge/cfx_graphstatedata.h"
19#include "core/fxge/cfx_pathdata.h"
20#include "core/fxge/cfx_renderdevice.h"
21#include "core/fxge/fx_font.h"
dsinclair0bb385b2016-09-29 17:03:59 -070022#include "fpdfsdk/fxedit/fxet_edit.h"
Lei Zhang633a3b72017-06-02 15:27:22 -070023#include "fpdfsdk/pdfwindow/cpwl_caret.h"
24#include "fpdfsdk/pdfwindow/cpwl_edit_ctrl.h"
25#include "fpdfsdk/pdfwindow/cpwl_font_map.h"
26#include "fpdfsdk/pdfwindow/cpwl_scroll_bar.h"
27#include "fpdfsdk/pdfwindow/cpwl_utils.h"
28#include "fpdfsdk/pdfwindow/cpwl_wnd.h"
Lei Zhangc2fb35f2016-01-05 16:46:58 -080029#include "public/fpdf_fwlevent.h"
Tom Sepezab277682016-02-17 10:07:21 -080030#include "third_party/base/stl_util.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070031
Lei Zhang12eea812017-06-02 14:22:41 -070032CPWL_Edit::CPWL_Edit() : m_bFocus(false) {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070033
Nico Weber9d8ec5a2015-08-04 13:00:21 -070034CPWL_Edit::~CPWL_Edit() {
Lei Zhangb45324b2017-05-22 17:05:40 -070035 ASSERT(!m_bFocus);
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
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;
Lei Zhanga99de0e2017-02-27 14:45:56 -080044 if (!HasFlag(PES_RICH)) {
45 m_pEdit->SetText(swText);
46 return;
47 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070048
Lei Zhanga99de0e2017-02-27 14:45:56 -080049 CFX_ByteString sValue = CFX_ByteString::FromUnicode(swText);
50 std::unique_ptr<CXML_Element> pXML(
51 CXML_Element::Parse(sValue.c_str(), sValue.GetLength()));
52 if (!pXML) {
53 m_pEdit->SetText(swText);
54 return;
55 }
Lei Zhanga99de0e2017-02-27 14:45:56 -080056 swText.clear();
Nico Weber9d8ec5a2015-08-04 13:00:21 -070057
Tom Sepez8a6fdad2017-05-09 15:03:33 -070058 bool bFirst = true;
59 int32_t nCount = pXML->CountChildren();
Lei Zhanga99de0e2017-02-27 14:45:56 -080060 for (int32_t i = 0; i < nCount; i++) {
Tom Sepez8a6fdad2017-05-09 15:03:33 -070061 CXML_Element* pSubElement = ToElement(pXML->GetChild(i));
62 if (!pSubElement || !pSubElement->GetTagName().EqualNoCase("p"))
Lei Zhanga99de0e2017-02-27 14:45:56 -080063 continue;
64
Tom Sepez8a6fdad2017-05-09 15:03:33 -070065 CFX_WideString swSection;
66 int nSubChild = pSubElement->CountChildren();
67 for (int32_t j = 0; j < nSubChild; j++) {
68 CXML_Content* pSubContent = ToContent(pSubElement->GetChild(j));
69 if (pSubContent)
70 swSection += pSubContent->m_Content;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070071 }
Tom Sepez8a6fdad2017-05-09 15:03:33 -070072 if (bFirst)
73 bFirst = false;
74 else
75 swText += FWL_VKEY_Return;
76 swText += swSection;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070077 }
78
tsepez067990c2016-09-13 06:46:40 -070079 m_pEdit->SetText(swText);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070080}
81
Nico Weber9d8ec5a2015-08-04 13:00:21 -070082void CPWL_Edit::RePosChildWnd() {
83 if (CPWL_ScrollBar* pVSB = GetVScrollBar()) {
Tom Sepez281a9ea2016-02-26 14:24:28 -080084 CFX_FloatRect rcWindow = m_rcOldWindow;
85 CFX_FloatRect rcVScroll =
86 CFX_FloatRect(rcWindow.right, rcWindow.bottom,
87 rcWindow.right + PWL_SCROLLBAR_WIDTH, rcWindow.top);
tsepez4cf55152016-11-02 14:37:54 -070088 pVSB->Move(rcVScroll, true, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070089 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070090
Nico Weber9d8ec5a2015-08-04 13:00:21 -070091 if (m_pEditCaret && !HasFlag(PES_TEXTOVERFLOW))
92 m_pEditCaret->SetClipRect(CPWL_Utils::InflateRect(
Dan Sinclair50cce602016-02-24 09:51:16 -050093 GetClientRect(), 1.0f)); // +1 for caret beside border
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070094
Nico Weber9d8ec5a2015-08-04 13:00:21 -070095 CPWL_EditCtrl::RePosChildWnd();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070096}
97
Tom Sepez281a9ea2016-02-26 14:24:28 -080098CFX_FloatRect CPWL_Edit::GetClientRect() const {
99 CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(
Dan Sinclair05df0752017-03-14 14:43:42 -0400100 GetWindowRect(), (float)(GetBorderWidth() + GetInnerBorderWidth()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700101
102 if (CPWL_ScrollBar* pVSB = GetVScrollBar()) {
103 if (pVSB->IsVisible()) {
104 rcClient.right -= PWL_SCROLLBAR_WIDTH;
105 }
106 }
107
108 return rcClient;
109}
110
tsepez4cf55152016-11-02 14:37:54 -0700111void CPWL_Edit::SetAlignFormatV(PWL_EDIT_ALIGNFORMAT_V nFormat, bool bPaint) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700112 m_pEdit->SetAlignmentV((int32_t)nFormat, bPaint);
113}
114
tsepez4cf55152016-11-02 14:37:54 -0700115bool CPWL_Edit::CanSelectAll() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700116 return GetSelectWordRange() != m_pEdit->GetWholeWordRange();
117}
118
tsepez4cf55152016-11-02 14:37:54 -0700119bool CPWL_Edit::CanClear() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700120 return !IsReadOnly() && m_pEdit->IsSelected();
121}
122
tsepez4cf55152016-11-02 14:37:54 -0700123bool CPWL_Edit::CanCopy() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700124 return !HasFlag(PES_PASSWORD) && !HasFlag(PES_NOREAD) &&
125 m_pEdit->IsSelected();
126}
127
tsepez4cf55152016-11-02 14:37:54 -0700128bool CPWL_Edit::CanCut() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700129 return CanCopy() && !IsReadOnly();
130}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700131void CPWL_Edit::CutText() {
132 if (!CanCut())
133 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700134 m_pEdit->Clear();
135}
136
137void CPWL_Edit::OnCreated() {
138 CPWL_EditCtrl::OnCreated();
139
140 if (CPWL_ScrollBar* pScroll = GetVScrollBar()) {
141 pScroll->RemoveFlag(PWS_AUTOTRANSPARENT);
142 pScroll->SetTransparency(255);
143 }
144
145 SetParamByFlag();
146
147 m_rcOldWindow = GetWindowRect();
148
149 m_pEdit->SetOprNotify(this);
tsepez4cf55152016-11-02 14:37:54 -0700150 m_pEdit->EnableOprNotify(true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700151}
152
153void CPWL_Edit::SetParamByFlag() {
154 if (HasFlag(PES_RIGHT)) {
tsepez4cf55152016-11-02 14:37:54 -0700155 m_pEdit->SetAlignmentH(2, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700156 } else if (HasFlag(PES_MIDDLE)) {
tsepez4cf55152016-11-02 14:37:54 -0700157 m_pEdit->SetAlignmentH(1, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700158 } else {
tsepez4cf55152016-11-02 14:37:54 -0700159 m_pEdit->SetAlignmentH(0, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700160 }
161
162 if (HasFlag(PES_BOTTOM)) {
tsepez4cf55152016-11-02 14:37:54 -0700163 m_pEdit->SetAlignmentV(2, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700164 } else if (HasFlag(PES_CENTER)) {
tsepez4cf55152016-11-02 14:37:54 -0700165 m_pEdit->SetAlignmentV(1, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700166 } else {
tsepez4cf55152016-11-02 14:37:54 -0700167 m_pEdit->SetAlignmentV(0, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700168 }
169
170 if (HasFlag(PES_PASSWORD)) {
tsepez4cf55152016-11-02 14:37:54 -0700171 m_pEdit->SetPasswordChar('*', false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700172 }
173
tsepez4cf55152016-11-02 14:37:54 -0700174 m_pEdit->SetMultiLine(HasFlag(PES_MULTILINE), false);
175 m_pEdit->SetAutoReturn(HasFlag(PES_AUTORETURN), false);
176 m_pEdit->SetAutoFontSize(HasFlag(PWS_AUTOFONTSIZE), false);
177 m_pEdit->SetAutoScroll(HasFlag(PES_AUTOSCROLL), false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700178 m_pEdit->EnableUndo(HasFlag(PES_UNDO));
179
180 if (HasFlag(PES_TEXTOVERFLOW)) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800181 SetClipRect(CFX_FloatRect(0.0f, 0.0f, 0.0f, 0.0f));
tsepez4cf55152016-11-02 14:37:54 -0700182 m_pEdit->SetTextOverflow(true, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700183 } else {
184 if (m_pEditCaret) {
185 m_pEditCaret->SetClipRect(CPWL_Utils::InflateRect(
Dan Sinclair50cce602016-02-24 09:51:16 -0500186 GetClientRect(), 1.0f)); // +1 for caret beside border
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700187 }
188 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700189}
190
191void CPWL_Edit::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) {
192 CPWL_Wnd::GetThisAppearanceStream(sAppStream);
193
Tom Sepez281a9ea2016-02-26 14:24:28 -0800194 CFX_FloatRect rcClient = GetClientRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700195 CFX_ByteTextBuf sLine;
196
197 int32_t nCharArray = m_pEdit->GetCharArray();
198
199 if (nCharArray > 0) {
200 switch (GetBorderStyle()) {
dsinclair92cb5e52016-05-16 11:38:28 -0700201 case BorderStyle::SOLID: {
tsepez4cf55152016-11-02 14:37:54 -0700202 sLine << "q\n"
203 << GetBorderWidth() << " w\n"
204 << CPWL_Utils::GetColorAppStream(GetBorderColor(), false)
tsepez4c3debb2016-04-08 12:20:38 -0700205 .AsStringC()
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700206 << " 2 J 0 j\n";
207
208 for (int32_t i = 1; i < nCharArray; i++) {
209 sLine << rcClient.left +
210 ((rcClient.right - rcClient.left) / nCharArray) * i
211 << " " << rcClient.bottom << " m\n"
212 << rcClient.left +
213 ((rcClient.right - rcClient.left) / nCharArray) * i
214 << " " << rcClient.top << " l S\n";
215 }
216
217 sLine << "Q\n";
dsinclair92cb5e52016-05-16 11:38:28 -0700218 break;
219 }
220 case BorderStyle::DASH: {
tsepez4cf55152016-11-02 14:37:54 -0700221 sLine << "q\n"
222 << GetBorderWidth() << " w\n"
223 << CPWL_Utils::GetColorAppStream(GetBorderColor(), false)
tsepez4c3debb2016-04-08 12:20:38 -0700224 .AsStringC()
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700225 << " 2 J 0 j\n"
226 << "[" << GetBorderDash().nDash << " " << GetBorderDash().nGap
227 << "] " << GetBorderDash().nPhase << " d\n";
228
229 for (int32_t i = 1; i < nCharArray; i++) {
230 sLine << rcClient.left +
231 ((rcClient.right - rcClient.left) / nCharArray) * i
232 << " " << rcClient.bottom << " m\n"
233 << rcClient.left +
234 ((rcClient.right - rcClient.left) / nCharArray) * i
235 << " " << rcClient.top << " l S\n";
236 }
237
238 sLine << "Q\n";
dsinclair92cb5e52016-05-16 11:38:28 -0700239 break;
240 }
241 default:
242 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700243 }
244 }
245
246 sAppStream << sLine;
247
248 CFX_ByteTextBuf sText;
Dan Sinclairf528eee2017-02-14 11:52:07 -0500249 CFX_PointF ptOffset;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700250 CPVT_WordRange wrWhole = m_pEdit->GetWholeWordRange();
251 CPVT_WordRange wrSelect = GetSelectWordRange();
252 CPVT_WordRange wrVisible =
tsepez63f545c2016-09-13 16:08:49 -0700253 HasFlag(PES_TEXTOVERFLOW) ? wrWhole : m_pEdit->GetVisibleWordRange();
254
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700255 CPVT_WordRange wrSelBefore(wrWhole.BeginPos, wrSelect.BeginPos);
256 CPVT_WordRange wrSelAfter(wrSelect.EndPos, wrWhole.EndPos);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700257 CPVT_WordRange wrTemp =
258 CPWL_Utils::OverlapWordRange(GetSelectWordRange(), wrVisible);
259 CFX_ByteString sEditSel =
dsinclaire35af1e2016-07-13 11:26:20 -0700260 CPWL_Utils::GetEditSelAppStream(m_pEdit.get(), ptOffset, &wrTemp);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700261
262 if (sEditSel.GetLength() > 0)
tsepez4c3debb2016-04-08 12:20:38 -0700263 sText << CPWL_Utils::GetColorAppStream(PWL_DEFAULT_SELBACKCOLOR).AsStringC()
264 << sEditSel.AsStringC();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700265
266 wrTemp = CPWL_Utils::OverlapWordRange(wrVisible, wrSelBefore);
267 CFX_ByteString sEditBefore = CPWL_Utils::GetEditAppStream(
dsinclaire35af1e2016-07-13 11:26:20 -0700268 m_pEdit.get(), ptOffset, &wrTemp, !HasFlag(PES_CHARARRAY),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700269 m_pEdit->GetPasswordChar());
270
271 if (sEditBefore.GetLength() > 0)
Dan Sinclaira0061af2017-02-23 09:25:17 -0500272 sText << "BT\n"
273 << CPWL_Utils::GetColorAppStream(GetTextColor()).AsStringC()
tsepez4c3debb2016-04-08 12:20:38 -0700274 << sEditBefore.AsStringC() << "ET\n";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700275
276 wrTemp = CPWL_Utils::OverlapWordRange(wrVisible, wrSelect);
277 CFX_ByteString sEditMid = CPWL_Utils::GetEditAppStream(
dsinclaire35af1e2016-07-13 11:26:20 -0700278 m_pEdit.get(), ptOffset, &wrTemp, !HasFlag(PES_CHARARRAY),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700279 m_pEdit->GetPasswordChar());
280
281 if (sEditMid.GetLength() > 0)
282 sText << "BT\n"
283 << CPWL_Utils::GetColorAppStream(CPWL_Color(COLORTYPE_GRAY, 1))
tsepez4c3debb2016-04-08 12:20:38 -0700284 .AsStringC()
285 << sEditMid.AsStringC() << "ET\n";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700286
287 wrTemp = CPWL_Utils::OverlapWordRange(wrVisible, wrSelAfter);
288 CFX_ByteString sEditAfter = CPWL_Utils::GetEditAppStream(
dsinclaire35af1e2016-07-13 11:26:20 -0700289 m_pEdit.get(), ptOffset, &wrTemp, !HasFlag(PES_CHARARRAY),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700290 m_pEdit->GetPasswordChar());
291
292 if (sEditAfter.GetLength() > 0)
Dan Sinclaira0061af2017-02-23 09:25:17 -0500293 sText << "BT\n"
294 << CPWL_Utils::GetColorAppStream(GetTextColor()).AsStringC()
tsepez4c3debb2016-04-08 12:20:38 -0700295 << sEditAfter.AsStringC() << "ET\n";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700296
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700297 if (sText.GetLength() > 0) {
weilidb444d22016-06-02 15:48:15 -0700298 CFX_FloatRect rect = GetClientRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700299 sAppStream << "q\n/Tx BMC\n";
300
301 if (!HasFlag(PES_TEXTOVERFLOW))
weilidb444d22016-06-02 15:48:15 -0700302 sAppStream << rect.left << " " << rect.bottom << " "
303 << rect.right - rect.left << " " << rect.top - rect.bottom
304 << " re W n\n";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700305
306 sAppStream << sText;
307
308 sAppStream << "EMC\nQ\n";
309 }
310}
311
312void CPWL_Edit::DrawThisAppearance(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800313 CFX_Matrix* pUser2Device) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700314 CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device);
315
Tom Sepez281a9ea2016-02-26 14:24:28 -0800316 CFX_FloatRect rcClient = GetClientRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700317 CFX_ByteTextBuf sLine;
318
319 int32_t nCharArray = m_pEdit->GetCharArray();
320 FX_SAFE_INT32 nCharArraySafe = nCharArray;
321 nCharArraySafe -= 1;
322 nCharArraySafe *= 2;
323
324 if (nCharArray > 0 && nCharArraySafe.IsValid()) {
325 switch (GetBorderStyle()) {
dsinclair92cb5e52016-05-16 11:38:28 -0700326 case BorderStyle::SOLID: {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700327 CFX_GraphStateData gsd;
Dan Sinclair05df0752017-03-14 14:43:42 -0400328 gsd.m_LineWidth = (float)GetBorderWidth();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700329
330 CFX_PathData path;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700331
332 for (int32_t i = 0; i < nCharArray - 1; i++) {
Dan Sinclaire4602322017-02-15 11:07:32 -0500333 path.AppendPoint(
dan sinclairb147e072017-02-22 19:56:15 -0500334 CFX_PointF(
335 rcClient.left +
336 ((rcClient.right - rcClient.left) / nCharArray) * (i + 1),
337 rcClient.bottom),
338 FXPT_TYPE::MoveTo, false);
Dan Sinclaire4602322017-02-15 11:07:32 -0500339 path.AppendPoint(
dan sinclairb147e072017-02-22 19:56:15 -0500340 CFX_PointF(
341 rcClient.left +
342 ((rcClient.right - rcClient.left) / nCharArray) * (i + 1),
343 rcClient.top),
344 FXPT_TYPE::LineTo, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700345 }
Dan Sinclaire4602322017-02-15 11:07:32 -0500346 if (!path.GetPoints().empty()) {
Dan Sinclairfc54e052017-02-23 09:59:05 -0500347 pDevice->DrawPath(&path, pUser2Device, &gsd, 0,
348 GetBorderColor().ToFXColor(255), FXFILL_ALTERNATE);
dsinclair92cb5e52016-05-16 11:38:28 -0700349 }
350 break;
351 }
352 case BorderStyle::DASH: {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700353 CFX_GraphStateData gsd;
Dan Sinclair05df0752017-03-14 14:43:42 -0400354 gsd.m_LineWidth = (float)GetBorderWidth();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700355
356 gsd.SetDashCount(2);
Dan Sinclair05df0752017-03-14 14:43:42 -0400357 gsd.m_DashArray[0] = (float)GetBorderDash().nDash;
358 gsd.m_DashArray[1] = (float)GetBorderDash().nGap;
359 gsd.m_DashPhase = (float)GetBorderDash().nPhase;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700360
361 CFX_PathData path;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700362 for (int32_t i = 0; i < nCharArray - 1; i++) {
Dan Sinclaire4602322017-02-15 11:07:32 -0500363 path.AppendPoint(
dan sinclairb147e072017-02-22 19:56:15 -0500364 CFX_PointF(
365 rcClient.left +
366 ((rcClient.right - rcClient.left) / nCharArray) * (i + 1),
367 rcClient.bottom),
368 FXPT_TYPE::MoveTo, false);
Dan Sinclaire4602322017-02-15 11:07:32 -0500369 path.AppendPoint(
dan sinclairb147e072017-02-22 19:56:15 -0500370 CFX_PointF(
371 rcClient.left +
372 ((rcClient.right - rcClient.left) / nCharArray) * (i + 1),
373 rcClient.top),
374 FXPT_TYPE::LineTo, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700375 }
Dan Sinclaire4602322017-02-15 11:07:32 -0500376 if (!path.GetPoints().empty()) {
Dan Sinclairfc54e052017-02-23 09:59:05 -0500377 pDevice->DrawPath(&path, pUser2Device, &gsd, 0,
378 GetBorderColor().ToFXColor(255), FXFILL_ALTERNATE);
dsinclair92cb5e52016-05-16 11:38:28 -0700379 }
380 break;
381 }
382 default:
383 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700384 }
385 }
386
Tom Sepez281a9ea2016-02-26 14:24:28 -0800387 CFX_FloatRect rcClip;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700388 CPVT_WordRange wrRange = m_pEdit->GetVisibleWordRange();
thestig1cd352e2016-06-07 17:53:06 -0700389 CPVT_WordRange* pRange = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700390 if (!HasFlag(PES_TEXTOVERFLOW)) {
391 rcClip = GetClientRect();
392 pRange = &wrRange;
393 }
tsepez63f545c2016-09-13 16:08:49 -0700394
dsinclairb9590102016-04-27 06:38:59 -0700395 CFX_SystemHandler* pSysHandler = GetSystemHandler();
Dan Sinclairfc54e052017-02-23 09:59:05 -0500396 CFX_Edit::DrawEdit(pDevice, pUser2Device, m_pEdit.get(),
397 GetTextColor().ToFXColor(GetTransparency()), rcClip,
Tom Sepezcc205132017-05-16 14:01:47 -0700398 CFX_PointF(), pRange, pSysHandler, m_pFormFiller.Get());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700399}
400
Dan Sinclairf528eee2017-02-14 11:52:07 -0500401bool CPWL_Edit::OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700402 CPWL_Wnd::OnLButtonDown(point, nFlag);
403
404 if (HasFlag(PES_TEXTOVERFLOW) || ClientHitTest(point)) {
405 if (m_bMouseDown)
406 InvalidateRect();
407
tsepez4cf55152016-11-02 14:37:54 -0700408 m_bMouseDown = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700409 SetCapture();
410
411 m_pEdit->OnMouseDown(point, IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
412 }
413
tsepez4cf55152016-11-02 14:37:54 -0700414 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700415}
416
Dan Sinclairf528eee2017-02-14 11:52:07 -0500417bool CPWL_Edit::OnLButtonDblClk(const CFX_PointF& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700418 CPWL_Wnd::OnLButtonDblClk(point, nFlag);
419
420 if (HasFlag(PES_TEXTOVERFLOW) || ClientHitTest(point)) {
421 m_pEdit->SelectAll();
422 }
423
tsepez4cf55152016-11-02 14:37:54 -0700424 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700425}
426
Dan Sinclairf528eee2017-02-14 11:52:07 -0500427bool CPWL_Edit::OnRButtonUp(const CFX_PointF& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700428 if (m_bMouseDown)
tsepez4cf55152016-11-02 14:37:54 -0700429 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700430
431 CPWL_Wnd::OnRButtonUp(point, nFlag);
432
433 if (!HasFlag(PES_TEXTOVERFLOW) && !ClientHitTest(point))
tsepez4cf55152016-11-02 14:37:54 -0700434 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700435
dsinclairb9590102016-04-27 06:38:59 -0700436 CFX_SystemHandler* pSH = GetSystemHandler();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700437 if (!pSH)
tsepez4cf55152016-11-02 14:37:54 -0700438 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700439
440 SetFocus();
441
tsepez4cf55152016-11-02 14:37:54 -0700442 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700443}
444
445void CPWL_Edit::OnSetFocus() {
tsepez4cf55152016-11-02 14:37:54 -0700446 SetEditCaret(true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700447 if (!IsReadOnly()) {
448 if (IPWL_FocusHandler* pFocusHandler = GetFocusHandler())
449 pFocusHandler->OnSetFocus(this);
450 }
tsepez4cf55152016-11-02 14:37:54 -0700451 m_bFocus = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700452}
453
454void CPWL_Edit::OnKillFocus() {
tsepez4cf55152016-11-02 14:37:54 -0700455 ShowVScrollBar(false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700456 m_pEdit->SelectNone();
Dan Sinclairf528eee2017-02-14 11:52:07 -0500457 SetCaret(false, CFX_PointF(), CFX_PointF());
Dan Sinclairf51a02a2017-04-19 12:46:53 -0400458 SetCharSet(FX_CHARSET_ANSI);
tsepez4cf55152016-11-02 14:37:54 -0700459 m_bFocus = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700460}
461
Dan Sinclair05df0752017-03-14 14:43:42 -0400462void CPWL_Edit::SetCharSpace(float fCharSpace) {
dsinclairefd5a992016-07-18 10:04:07 -0700463 m_pEdit->SetCharSpace(fCharSpace);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700464}
465
466CFX_ByteString CPWL_Edit::GetSelectAppearanceStream(
Dan Sinclairf528eee2017-02-14 11:52:07 -0500467 const CFX_PointF& ptOffset) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700468 CPVT_WordRange wr = GetSelectWordRange();
dsinclaire35af1e2016-07-13 11:26:20 -0700469 return CPWL_Utils::GetEditSelAppStream(m_pEdit.get(), ptOffset, &wr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700470}
471
472CPVT_WordRange CPWL_Edit::GetSelectWordRange() const {
473 if (m_pEdit->IsSelected()) {
474 int32_t nStart = -1;
475 int32_t nEnd = -1;
476
477 m_pEdit->GetSel(nStart, nEnd);
478
479 CPVT_WordPlace wpStart = m_pEdit->WordIndexToWordPlace(nStart);
480 CPVT_WordPlace wpEnd = m_pEdit->WordIndexToWordPlace(nEnd);
481
482 return CPVT_WordRange(wpStart, wpEnd);
483 }
484
485 return CPVT_WordRange();
486}
487
488CFX_ByteString CPWL_Edit::GetTextAppearanceStream(
Dan Sinclairf528eee2017-02-14 11:52:07 -0500489 const CFX_PointF& ptOffset) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700490 CFX_ByteTextBuf sRet;
dsinclaire35af1e2016-07-13 11:26:20 -0700491 CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream(m_pEdit.get(), ptOffset);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700492 if (sEdit.GetLength() > 0) {
Dan Sinclaira0061af2017-02-23 09:25:17 -0500493 sRet << "BT\n"
494 << CPWL_Utils::GetColorAppStream(GetTextColor()).AsStringC()
tsepez4c3debb2016-04-08 12:20:38 -0700495 << sEdit.AsStringC() << "ET\n";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700496 }
tsepez71a452f2016-05-13 17:51:27 -0700497 return sRet.MakeString();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700498}
499
500CFX_ByteString CPWL_Edit::GetCaretAppearanceStream(
Dan Sinclairf528eee2017-02-14 11:52:07 -0500501 const CFX_PointF& ptOffset) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700502 if (m_pEditCaret)
503 return m_pEditCaret->GetCaretAppearanceStream(ptOffset);
504
505 return CFX_ByteString();
506}
507
Dan Sinclairf528eee2017-02-14 11:52:07 -0500508CFX_PointF CPWL_Edit::GetWordRightBottomPoint(const CPVT_WordPlace& wpWord) {
dsinclaire35af1e2016-07-13 11:26:20 -0700509 CFX_Edit_Iterator* pIterator = m_pEdit->GetIterator();
thestig821d59e2016-05-11 12:59:22 -0700510 CPVT_WordPlace wpOld = pIterator->GetAt();
511 pIterator->SetAt(wpWord);
tsepez63f545c2016-09-13 16:08:49 -0700512
Dan Sinclairf528eee2017-02-14 11:52:07 -0500513 CFX_PointF pt;
thestig821d59e2016-05-11 12:59:22 -0700514 CPVT_Word word;
515 if (pIterator->GetWord(word)) {
Dan Sinclairf528eee2017-02-14 11:52:07 -0500516 pt = CFX_PointF(word.ptWord.x + word.fWidth, word.ptWord.y + word.fDescent);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700517 }
thestig821d59e2016-05-11 12:59:22 -0700518 pIterator->SetAt(wpOld);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700519 return pt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700520}
521
tsepez4cf55152016-11-02 14:37:54 -0700522bool CPWL_Edit::IsTextFull() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700523 return m_pEdit->IsTextFull();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700524}
525
Dan Sinclair05df0752017-03-14 14:43:42 -0400526float CPWL_Edit::GetCharArrayAutoFontSize(CPDF_Font* pFont,
527 const CFX_FloatRect& rcPlate,
528 int32_t nCharArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700529 if (pFont && !pFont->IsStandardFont()) {
530 FX_RECT rcBBox;
531 pFont->GetFontBBox(rcBBox);
532
Tom Sepez281a9ea2016-02-26 14:24:28 -0800533 CFX_FloatRect rcCell = rcPlate;
Dan Sinclair05df0752017-03-14 14:43:42 -0400534 float xdiv = rcCell.Width() / nCharArray * 1000.0f / rcBBox.Width();
535 float ydiv = -rcCell.Height() * 1000.0f / rcBBox.Height();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700536
537 return xdiv < ydiv ? xdiv : ydiv;
538 }
539
540 return 0.0f;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700541}
542
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700543void CPWL_Edit::SetCharArray(int32_t nCharArray) {
544 if (HasFlag(PES_CHARARRAY) && nCharArray > 0) {
545 m_pEdit->SetCharArray(nCharArray);
tsepez4cf55152016-11-02 14:37:54 -0700546 m_pEdit->SetTextOverflow(true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700547
548 if (HasFlag(PWS_AUTOFONTSIZE)) {
dsinclairc7a73492016-04-05 12:01:42 -0700549 if (IPVT_FontMap* pFontMap = GetFontMap()) {
Dan Sinclair05df0752017-03-14 14:43:42 -0400550 float fFontSize = GetCharArrayAutoFontSize(pFontMap->GetPDFFont(0),
551 GetClientRect(), nCharArray);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700552 if (fFontSize > 0.0f) {
tsepez4cf55152016-11-02 14:37:54 -0700553 m_pEdit->SetAutoFontSize(false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700554 m_pEdit->SetFontSize(fFontSize);
555 }
556 }
557 }
558 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700559}
560
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700561void CPWL_Edit::SetLimitChar(int32_t nLimitChar) {
562 m_pEdit->SetLimitChar(nLimitChar);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700563}
564
tsepez067990c2016-09-13 06:46:40 -0700565void CPWL_Edit::ReplaceSel(const CFX_WideString& wsText) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700566 m_pEdit->Clear();
Dan Sinclairf51a02a2017-04-19 12:46:53 -0400567 m_pEdit->InsertText(wsText, FX_CHARSET_Default);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700568}
569
Tom Sepez281a9ea2016-02-26 14:24:28 -0800570CFX_FloatRect CPWL_Edit::GetFocusRect() const {
571 return CFX_FloatRect();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700572}
573
tsepez4cf55152016-11-02 14:37:54 -0700574void CPWL_Edit::ShowVScrollBar(bool bShow) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700575 if (CPWL_ScrollBar* pScroll = GetVScrollBar()) {
576 if (bShow) {
577 if (!pScroll->IsVisible()) {
tsepez4cf55152016-11-02 14:37:54 -0700578 pScroll->SetVisible(true);
Tom Sepez281a9ea2016-02-26 14:24:28 -0800579 CFX_FloatRect rcWindow = GetWindowRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700580 m_rcOldWindow = rcWindow;
581 rcWindow.right += PWL_SCROLLBAR_WIDTH;
tsepez4cf55152016-11-02 14:37:54 -0700582 Move(rcWindow, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700583 }
584 } else {
585 if (pScroll->IsVisible()) {
tsepez4cf55152016-11-02 14:37:54 -0700586 pScroll->SetVisible(false);
587 Move(m_rcOldWindow, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700588 }
589 }
590 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700591}
592
tsepez4cf55152016-11-02 14:37:54 -0700593bool CPWL_Edit::IsVScrollBarVisible() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700594 if (CPWL_ScrollBar* pScroll = GetVScrollBar()) {
595 return pScroll->IsVisible();
596 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700597
tsepez4cf55152016-11-02 14:37:54 -0700598 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700599}
600
tsepez4cf55152016-11-02 14:37:54 -0700601bool CPWL_Edit::OnKeyDown(uint16_t nChar, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700602 if (m_bMouseDown)
tsepez4cf55152016-11-02 14:37:54 -0700603 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700604
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700605 if (nChar == FWL_VKEY_Delete) {
606 if (m_pFillerNotify) {
tsepez4cf55152016-11-02 14:37:54 -0700607 bool bRC = true;
608 bool bExit = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700609 CFX_WideString strChange;
610 CFX_WideString strChangeEx;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700611
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700612 int nSelStart = 0;
613 int nSelEnd = 0;
614 GetSel(nSelStart, nSelEnd);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700615
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700616 if (nSelStart == nSelEnd)
617 nSelEnd = nSelStart + 1;
Lei Zhanga5b47042015-10-19 14:32:16 -0700618 m_pFillerNotify->OnBeforeKeyStroke(GetAttachedData(), strChange,
tsepez4cf55152016-11-02 14:37:54 -0700619 strChangeEx, nSelStart, nSelEnd, true,
Lei Zhanga5b47042015-10-19 14:32:16 -0700620 bRC, bExit, nFlag);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700621 if (!bRC)
tsepez4cf55152016-11-02 14:37:54 -0700622 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700623 if (bExit)
tsepez4cf55152016-11-02 14:37:54 -0700624 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700625 }
626 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700627
tsepez4cf55152016-11-02 14:37:54 -0700628 bool bRet = CPWL_EditCtrl::OnKeyDown(nChar, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700629
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700630 // In case of implementation swallow the OnKeyDown event.
631 if (IsProceedtoOnChar(nChar, nFlag))
tsepez4cf55152016-11-02 14:37:54 -0700632 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700633
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700634 return bRet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700635}
636
637/**
Lei Zhang633a3b72017-06-02 15:27:22 -0700638 *In case of implementation swallow the OnKeyDown event.
639 *If the event is swallowed, implementation may do other unexpected things,
640 *which is not the control means to do.
641 */
tsepez4cf55152016-11-02 14:37:54 -0700642bool CPWL_Edit::IsProceedtoOnChar(uint16_t nKeyCode, uint32_t nFlag) {
643 bool bCtrl = IsCTRLpressed(nFlag);
644 bool bAlt = IsALTpressed(nFlag);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700645 if (bCtrl && !bAlt) {
646 // hot keys for edit control.
647 switch (nKeyCode) {
648 case 'C':
649 case 'V':
650 case 'X':
651 case 'A':
652 case 'Z':
tsepez4cf55152016-11-02 14:37:54 -0700653 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700654 default:
655 break;
656 }
657 }
658 // control characters.
659 switch (nKeyCode) {
660 case FWL_VKEY_Escape:
661 case FWL_VKEY_Back:
662 case FWL_VKEY_Return:
663 case FWL_VKEY_Space:
tsepez4cf55152016-11-02 14:37:54 -0700664 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700665 default:
tsepez4cf55152016-11-02 14:37:54 -0700666 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700667 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700668}
669
tsepez4cf55152016-11-02 14:37:54 -0700670bool CPWL_Edit::OnChar(uint16_t nChar, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700671 if (m_bMouseDown)
tsepez4cf55152016-11-02 14:37:54 -0700672 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700673
tsepez4cf55152016-11-02 14:37:54 -0700674 bool bRC = true;
675 bool bExit = false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700676
Lei Zhanga5b47042015-10-19 14:32:16 -0700677 if (!IsCTRLpressed(nFlag)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700678 if (m_pFillerNotify) {
679 CFX_WideString swChange;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700680
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700681 int nSelStart = 0;
682 int nSelEnd = 0;
683 GetSel(nSelStart, nSelEnd);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700684
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700685 switch (nChar) {
686 case FWL_VKEY_Back:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700687 if (nSelStart == nSelEnd)
688 nSelStart = nSelEnd - 1;
689 break;
690 case FWL_VKEY_Return:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700691 break;
692 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700693 swChange += nChar;
694 break;
695 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700696
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700697 CFX_WideString strChangeEx;
Lei Zhanga5b47042015-10-19 14:32:16 -0700698 m_pFillerNotify->OnBeforeKeyStroke(GetAttachedData(), swChange,
tsepez4cf55152016-11-02 14:37:54 -0700699 strChangeEx, nSelStart, nSelEnd, true,
Lei Zhanga5b47042015-10-19 14:32:16 -0700700 bRC, bExit, nFlag);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700701 }
702 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700703
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700704 if (!bRC)
tsepez4cf55152016-11-02 14:37:54 -0700705 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700706 if (bExit)
tsepez4cf55152016-11-02 14:37:54 -0700707 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700708
dsinclairc7a73492016-04-05 12:01:42 -0700709 if (IPVT_FontMap* pFontMap = GetFontMap()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700710 int32_t nOldCharSet = GetCharSet();
npmea3c3be2016-09-19 07:24:33 -0700711 int32_t nNewCharSet =
Dan Sinclairf51a02a2017-04-19 12:46:53 -0400712 pFontMap->CharSetFromUnicode(nChar, FX_CHARSET_Default);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700713 if (nOldCharSet != nNewCharSet) {
714 SetCharSet(nNewCharSet);
715 }
716 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700717
Lei Zhanga5b47042015-10-19 14:32:16 -0700718 return CPWL_EditCtrl::OnChar(nChar, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700719}
720
tsepez4cf55152016-11-02 14:37:54 -0700721bool CPWL_Edit::OnMouseWheel(short zDelta,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500722 const CFX_PointF& point,
tsepez4cf55152016-11-02 14:37:54 -0700723 uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700724 if (HasFlag(PES_MULTILINE)) {
Dan Sinclairf528eee2017-02-14 11:52:07 -0500725 CFX_PointF ptScroll = GetScrollPos();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700726
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700727 if (zDelta > 0) {
728 ptScroll.y += GetFontSize();
729 } else {
730 ptScroll.y -= GetFontSize();
731 }
732 SetScrollPos(ptScroll);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700733
tsepez4cf55152016-11-02 14:37:54 -0700734 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700735 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700736
tsepez4cf55152016-11-02 14:37:54 -0700737 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700738}
739
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700740void CPWL_Edit::OnInsertReturn(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::OnBackSpace(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::OnDelete(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::OnClear(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::OnInsertWord(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 -0700780void CPWL_Edit::OnInsertText(const CPVT_WordPlace& place,
781 const CPVT_WordPlace& oldplace) {
782 if (HasFlag(PES_SPELLCHECK)) {
783 m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace),
784 GetLatinWordsRange(place)));
785 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700786}
787
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700788CPVT_WordRange CPWL_Edit::CombineWordRange(const CPVT_WordRange& wr1,
789 const CPVT_WordRange& wr2) {
Tom Sepez52f69b32017-03-21 13:42:38 -0700790 return CPVT_WordRange(std::min(wr1.BeginPos, wr2.BeginPos),
791 std::max(wr1.EndPos, wr2.EndPos));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700792}
793
Dan Sinclairf528eee2017-02-14 11:52:07 -0500794CPVT_WordRange CPWL_Edit::GetLatinWordsRange(const CFX_PointF& point) const {
tsepez4cf55152016-11-02 14:37:54 -0700795 return GetSameWordsRange(m_pEdit->SearchWordPlace(point), true, false);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700796}
797
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700798CPVT_WordRange CPWL_Edit::GetLatinWordsRange(
799 const CPVT_WordPlace& place) const {
tsepez4cf55152016-11-02 14:37:54 -0700800 return GetSameWordsRange(place, true, false);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700801}
802
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700803CPVT_WordRange CPWL_Edit::GetArabicWordsRange(
804 const CPVT_WordPlace& place) const {
tsepez4cf55152016-11-02 14:37:54 -0700805 return GetSameWordsRange(place, false, true);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700806}
807
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700808#define PWL_ISARABICWORD(word) \
809 ((word >= 0x0600 && word <= 0x06FF) || (word >= 0xFB50 && word <= 0xFEFC))
810
811CPVT_WordRange CPWL_Edit::GetSameWordsRange(const CPVT_WordPlace& place,
tsepez4cf55152016-11-02 14:37:54 -0700812 bool bLatin,
813 bool bArabic) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700814 CPVT_WordRange range;
815
dsinclaire35af1e2016-07-13 11:26:20 -0700816 CFX_Edit_Iterator* pIterator = m_pEdit->GetIterator();
thestig821d59e2016-05-11 12:59:22 -0700817 CPVT_Word wordinfo;
818 CPVT_WordPlace wpStart(place), wpEnd(place);
819 pIterator->SetAt(place);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700820
thestig821d59e2016-05-11 12:59:22 -0700821 if (bLatin) {
822 while (pIterator->NextWord()) {
823 if (!pIterator->GetWord(wordinfo) ||
824 !FX_EDIT_ISLATINWORD(wordinfo.Word)) {
825 break;
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800826 }
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800827
thestig821d59e2016-05-11 12:59:22 -0700828 wpEnd = pIterator->GetAt();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700829 }
thestig821d59e2016-05-11 12:59:22 -0700830 } else if (bArabic) {
831 while (pIterator->NextWord()) {
832 if (!pIterator->GetWord(wordinfo) || !PWL_ISARABICWORD(wordinfo.Word))
833 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700834
thestig821d59e2016-05-11 12:59:22 -0700835 wpEnd = pIterator->GetAt();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700836 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700837 }
838
thestig821d59e2016-05-11 12:59:22 -0700839 pIterator->SetAt(place);
840
841 if (bLatin) {
842 do {
843 if (!pIterator->GetWord(wordinfo) ||
844 !FX_EDIT_ISLATINWORD(wordinfo.Word)) {
845 break;
846 }
847
848 wpStart = pIterator->GetAt();
849 } while (pIterator->PrevWord());
850 } else if (bArabic) {
851 do {
852 if (!pIterator->GetWord(wordinfo) || !PWL_ISARABICWORD(wordinfo.Word))
853 break;
854
855 wpStart = pIterator->GetAt();
856 } while (pIterator->PrevWord());
857 }
858
859 range.Set(wpStart, wpEnd);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700860 return range;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700861}