blob: de21dac1441b61a610ae65b0cf70ea9a669ef782 [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>
Henrique Nakashimaf1eae2c2017-06-29 11:18:49 -040011#include <sstream>
Dan Sinclair3ebd1212016-03-09 09:59:23 -050012#include <vector>
13
dsinclairbc5e6d22016-10-04 11:08:49 -070014#include "core/fpdfapi/font/cpdf_font.h"
dsinclair1727aee2016-09-29 13:12:56 -070015#include "core/fpdfdoc/cpvt_word.h"
dsinclaira52ab742016-09-29 13:59:29 -070016#include "core/fxcrt/fx_safe_types.h"
Tom Sepez8a6fdad2017-05-09 15:03:33 -070017#include "core/fxcrt/xml/cxml_content.h"
Dan Sinclair908c8482017-03-30 14:33:28 -040018#include "core/fxcrt/xml/cxml_element.h"
dsinclair74a34fc2016-09-29 16:41:42 -070019#include "core/fxge/cfx_graphstatedata.h"
20#include "core/fxge/cfx_pathdata.h"
21#include "core/fxge/cfx_renderdevice.h"
22#include "core/fxge/fx_font.h"
dsinclair0bb385b2016-09-29 17:03:59 -070023#include "fpdfsdk/fxedit/fxet_edit.h"
Lei Zhang633a3b72017-06-02 15:27:22 -070024#include "fpdfsdk/pdfwindow/cpwl_caret.h"
25#include "fpdfsdk/pdfwindow/cpwl_edit_ctrl.h"
26#include "fpdfsdk/pdfwindow/cpwl_font_map.h"
27#include "fpdfsdk/pdfwindow/cpwl_scroll_bar.h"
28#include "fpdfsdk/pdfwindow/cpwl_utils.h"
29#include "fpdfsdk/pdfwindow/cpwl_wnd.h"
Lei Zhangc2fb35f2016-01-05 16:46:58 -080030#include "public/fpdf_fwlevent.h"
Tom Sepezab277682016-02-17 10:07:21 -080031#include "third_party/base/stl_util.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070032
Lei Zhang12eea812017-06-02 14:22:41 -070033CPWL_Edit::CPWL_Edit() : m_bFocus(false) {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070034
Nico Weber9d8ec5a2015-08-04 13:00:21 -070035CPWL_Edit::~CPWL_Edit() {
Lei Zhangb45324b2017-05-22 17:05:40 -070036 ASSERT(!m_bFocus);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070037}
38
Nico Weber9d8ec5a2015-08-04 13:00:21 -070039CFX_ByteString CPWL_Edit::GetClassName() const {
40 return PWL_CLASSNAME_EDIT;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070041}
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 }
Lei Zhanga99de0e2017-02-27 14:45:56 -080057 swText.clear();
Nico Weber9d8ec5a2015-08-04 13:00:21 -070058
Tom Sepez8a6fdad2017-05-09 15:03:33 -070059 bool bFirst = true;
60 int32_t nCount = pXML->CountChildren();
Lei Zhanga99de0e2017-02-27 14:45:56 -080061 for (int32_t i = 0; i < nCount; i++) {
Tom Sepez8a6fdad2017-05-09 15:03:33 -070062 CXML_Element* pSubElement = ToElement(pXML->GetChild(i));
63 if (!pSubElement || !pSubElement->GetTagName().EqualNoCase("p"))
Lei Zhanga99de0e2017-02-27 14:45:56 -080064 continue;
65
Tom Sepez8a6fdad2017-05-09 15:03:33 -070066 CFX_WideString swSection;
67 int nSubChild = pSubElement->CountChildren();
68 for (int32_t j = 0; j < nSubChild; j++) {
69 CXML_Content* pSubContent = ToContent(pSubElement->GetChild(j));
70 if (pSubContent)
71 swSection += pSubContent->m_Content;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070072 }
Tom Sepez8a6fdad2017-05-09 15:03:33 -070073 if (bFirst)
74 bFirst = false;
75 else
76 swText += FWL_VKEY_Return;
77 swText += swSection;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070078 }
79
tsepez067990c2016-09-13 06:46:40 -070080 m_pEdit->SetText(swText);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070081}
82
Nico Weber9d8ec5a2015-08-04 13:00:21 -070083void CPWL_Edit::RePosChildWnd() {
84 if (CPWL_ScrollBar* pVSB = GetVScrollBar()) {
Tom Sepez281a9ea2016-02-26 14:24:28 -080085 CFX_FloatRect rcWindow = m_rcOldWindow;
86 CFX_FloatRect rcVScroll =
87 CFX_FloatRect(rcWindow.right, rcWindow.bottom,
88 rcWindow.right + PWL_SCROLLBAR_WIDTH, rcWindow.top);
tsepez4cf55152016-11-02 14:37:54 -070089 pVSB->Move(rcVScroll, true, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070090 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070091
Nico Weber9d8ec5a2015-08-04 13:00:21 -070092 if (m_pEditCaret && !HasFlag(PES_TEXTOVERFLOW))
93 m_pEditCaret->SetClipRect(CPWL_Utils::InflateRect(
Dan Sinclair50cce602016-02-24 09:51:16 -050094 GetClientRect(), 1.0f)); // +1 for caret beside border
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070095
Nico Weber9d8ec5a2015-08-04 13:00:21 -070096 CPWL_EditCtrl::RePosChildWnd();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070097}
98
Tom Sepez281a9ea2016-02-26 14:24:28 -080099CFX_FloatRect CPWL_Edit::GetClientRect() const {
100 CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(
Dan Sinclair05df0752017-03-14 14:43:42 -0400101 GetWindowRect(), (float)(GetBorderWidth() + GetInnerBorderWidth()));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700102
103 if (CPWL_ScrollBar* pVSB = GetVScrollBar()) {
104 if (pVSB->IsVisible()) {
105 rcClient.right -= PWL_SCROLLBAR_WIDTH;
106 }
107 }
108
109 return rcClient;
110}
111
tsepez4cf55152016-11-02 14:37:54 -0700112void CPWL_Edit::SetAlignFormatV(PWL_EDIT_ALIGNFORMAT_V nFormat, bool bPaint) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700113 m_pEdit->SetAlignmentV((int32_t)nFormat, bPaint);
114}
115
tsepez4cf55152016-11-02 14:37:54 -0700116bool CPWL_Edit::CanSelectAll() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700117 return GetSelectWordRange() != m_pEdit->GetWholeWordRange();
118}
119
tsepez4cf55152016-11-02 14:37:54 -0700120bool CPWL_Edit::CanClear() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700121 return !IsReadOnly() && m_pEdit->IsSelected();
122}
123
tsepez4cf55152016-11-02 14:37:54 -0700124bool CPWL_Edit::CanCopy() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700125 return !HasFlag(PES_PASSWORD) && !HasFlag(PES_NOREAD) &&
126 m_pEdit->IsSelected();
127}
128
tsepez4cf55152016-11-02 14:37:54 -0700129bool CPWL_Edit::CanCut() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700130 return CanCopy() && !IsReadOnly();
131}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700132void CPWL_Edit::CutText() {
133 if (!CanCut())
134 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700135 m_pEdit->Clear();
136}
137
138void CPWL_Edit::OnCreated() {
139 CPWL_EditCtrl::OnCreated();
140
141 if (CPWL_ScrollBar* pScroll = GetVScrollBar()) {
142 pScroll->RemoveFlag(PWS_AUTOTRANSPARENT);
143 pScroll->SetTransparency(255);
144 }
145
146 SetParamByFlag();
147
148 m_rcOldWindow = GetWindowRect();
149
150 m_pEdit->SetOprNotify(this);
tsepez4cf55152016-11-02 14:37:54 -0700151 m_pEdit->EnableOprNotify(true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700152}
153
154void CPWL_Edit::SetParamByFlag() {
155 if (HasFlag(PES_RIGHT)) {
tsepez4cf55152016-11-02 14:37:54 -0700156 m_pEdit->SetAlignmentH(2, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700157 } else if (HasFlag(PES_MIDDLE)) {
tsepez4cf55152016-11-02 14:37:54 -0700158 m_pEdit->SetAlignmentH(1, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700159 } else {
tsepez4cf55152016-11-02 14:37:54 -0700160 m_pEdit->SetAlignmentH(0, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700161 }
162
163 if (HasFlag(PES_BOTTOM)) {
tsepez4cf55152016-11-02 14:37:54 -0700164 m_pEdit->SetAlignmentV(2, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700165 } else if (HasFlag(PES_CENTER)) {
tsepez4cf55152016-11-02 14:37:54 -0700166 m_pEdit->SetAlignmentV(1, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700167 } else {
tsepez4cf55152016-11-02 14:37:54 -0700168 m_pEdit->SetAlignmentV(0, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700169 }
170
171 if (HasFlag(PES_PASSWORD)) {
tsepez4cf55152016-11-02 14:37:54 -0700172 m_pEdit->SetPasswordChar('*', false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700173 }
174
tsepez4cf55152016-11-02 14:37:54 -0700175 m_pEdit->SetMultiLine(HasFlag(PES_MULTILINE), false);
176 m_pEdit->SetAutoReturn(HasFlag(PES_AUTORETURN), false);
177 m_pEdit->SetAutoFontSize(HasFlag(PWS_AUTOFONTSIZE), false);
178 m_pEdit->SetAutoScroll(HasFlag(PES_AUTOSCROLL), false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700179 m_pEdit->EnableUndo(HasFlag(PES_UNDO));
180
181 if (HasFlag(PES_TEXTOVERFLOW)) {
Lei Zhangd24236a2017-06-29 18:28:58 -0700182 SetClipRect(CFX_FloatRect());
tsepez4cf55152016-11-02 14:37:54 -0700183 m_pEdit->SetTextOverflow(true, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700184 } else {
185 if (m_pEditCaret) {
186 m_pEditCaret->SetClipRect(CPWL_Utils::InflateRect(
Dan Sinclair50cce602016-02-24 09:51:16 -0500187 GetClientRect(), 1.0f)); // +1 for caret beside border
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700188 }
189 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700190}
191
Henrique Nakashimaf1eae2c2017-06-29 11:18:49 -0400192void CPWL_Edit::GetThisAppearanceStream(std::ostringstream* psAppStream) {
193 CPWL_Wnd::GetThisAppearanceStream(psAppStream);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700194
Tom Sepez281a9ea2016-02-26 14:24:28 -0800195 CFX_FloatRect rcClient = GetClientRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700196
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: {
Henrique Nakashimaf1eae2c2017-06-29 11:18:49 -0400202 *psAppStream << "q\n"
203 << GetBorderWidth() << " w\n"
204 << CPWL_Utils::GetColorAppStream(GetBorderColor(), false)
205 << " 2 J 0 j\n";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700206
207 for (int32_t i = 1; i < nCharArray; i++) {
Henrique Nakashimaf1eae2c2017-06-29 11:18:49 -0400208 *psAppStream << rcClient.left +
209 ((rcClient.right - rcClient.left) / nCharArray) *
210 i
211 << " " << rcClient.bottom << " m\n"
212 << rcClient.left +
213 ((rcClient.right - rcClient.left) / nCharArray) *
214 i
215 << " " << rcClient.top << " l S\n";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700216 }
217
Henrique Nakashimaf1eae2c2017-06-29 11:18:49 -0400218 *psAppStream << "Q\n";
dsinclair92cb5e52016-05-16 11:38:28 -0700219 break;
220 }
221 case BorderStyle::DASH: {
Henrique Nakashimaf1eae2c2017-06-29 11:18:49 -0400222 *psAppStream << "q\n"
223 << GetBorderWidth() << " w\n"
224 << CPWL_Utils::GetColorAppStream(GetBorderColor(), false)
225 << " 2 J 0 j\n"
226 << "[" << GetBorderDash().nDash << " "
227 << GetBorderDash().nGap << "] " << GetBorderDash().nPhase
228 << " d\n";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700229
230 for (int32_t i = 1; i < nCharArray; i++) {
Henrique Nakashimaf1eae2c2017-06-29 11:18:49 -0400231 *psAppStream << rcClient.left +
232 ((rcClient.right - rcClient.left) / nCharArray) *
233 i
234 << " " << rcClient.bottom << " m\n"
235 << rcClient.left +
236 ((rcClient.right - rcClient.left) / nCharArray) *
237 i
238 << " " << rcClient.top << " l S\n";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700239 }
240
Henrique Nakashimaf1eae2c2017-06-29 11:18:49 -0400241 *psAppStream << "Q\n";
dsinclair92cb5e52016-05-16 11:38:28 -0700242 break;
243 }
244 default:
245 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700246 }
247 }
248
Henrique Nakashimaf1eae2c2017-06-29 11:18:49 -0400249 std::ostringstream sText;
Dan Sinclairf528eee2017-02-14 11:52:07 -0500250 CFX_PointF ptOffset;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700251 CPVT_WordRange wrWhole = m_pEdit->GetWholeWordRange();
252 CPVT_WordRange wrSelect = GetSelectWordRange();
253 CPVT_WordRange wrVisible =
tsepez63f545c2016-09-13 16:08:49 -0700254 HasFlag(PES_TEXTOVERFLOW) ? wrWhole : m_pEdit->GetVisibleWordRange();
255
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700256 CPVT_WordRange wrSelBefore(wrWhole.BeginPos, wrSelect.BeginPos);
257 CPVT_WordRange wrSelAfter(wrSelect.EndPos, wrWhole.EndPos);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700258 CPVT_WordRange wrTemp =
259 CPWL_Utils::OverlapWordRange(GetSelectWordRange(), wrVisible);
260 CFX_ByteString sEditSel =
dsinclaire35af1e2016-07-13 11:26:20 -0700261 CPWL_Utils::GetEditSelAppStream(m_pEdit.get(), ptOffset, &wrTemp);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700262
263 if (sEditSel.GetLength() > 0)
Henrique Nakashimaf1eae2c2017-06-29 11:18:49 -0400264 sText << CPWL_Utils::GetColorAppStream(PWL_DEFAULT_SELBACKCOLOR)
265 << sEditSel;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700266
267 wrTemp = CPWL_Utils::OverlapWordRange(wrVisible, wrSelBefore);
268 CFX_ByteString sEditBefore = CPWL_Utils::GetEditAppStream(
dsinclaire35af1e2016-07-13 11:26:20 -0700269 m_pEdit.get(), ptOffset, &wrTemp, !HasFlag(PES_CHARARRAY),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700270 m_pEdit->GetPasswordChar());
271
272 if (sEditBefore.GetLength() > 0)
Dan Sinclaira0061af2017-02-23 09:25:17 -0500273 sText << "BT\n"
Henrique Nakashimaf1eae2c2017-06-29 11:18:49 -0400274 << CPWL_Utils::GetColorAppStream(GetTextColor()) << sEditBefore
275 << "ET\n";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700276
277 wrTemp = CPWL_Utils::OverlapWordRange(wrVisible, wrSelect);
278 CFX_ByteString sEditMid = CPWL_Utils::GetEditAppStream(
dsinclaire35af1e2016-07-13 11:26:20 -0700279 m_pEdit.get(), ptOffset, &wrTemp, !HasFlag(PES_CHARARRAY),
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700280 m_pEdit->GetPasswordChar());
281
282 if (sEditMid.GetLength() > 0)
283 sText << "BT\n"
284 << CPWL_Utils::GetColorAppStream(CPWL_Color(COLORTYPE_GRAY, 1))
Henrique Nakashimaf1eae2c2017-06-29 11:18:49 -0400285 << sEditMid << "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"
Henrique Nakashimaf1eae2c2017-06-29 11:18:49 -0400294 << CPWL_Utils::GetColorAppStream(GetTextColor()) << sEditAfter
295 << "ET\n";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700296
Henrique Nakashimaf1eae2c2017-06-29 11:18:49 -0400297 if (sText.tellp() > 0) {
weilidb444d22016-06-02 15:48:15 -0700298 CFX_FloatRect rect = GetClientRect();
Henrique Nakashimaf1eae2c2017-06-29 11:18:49 -0400299 *psAppStream << "q\n/Tx BMC\n";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700300
301 if (!HasFlag(PES_TEXTOVERFLOW))
Henrique Nakashimaf1eae2c2017-06-29 11:18:49 -0400302 *psAppStream << 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
Henrique Nakashimaf1eae2c2017-06-29 11:18:49 -0400306 *psAppStream << sText.str();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700307
Henrique Nakashimaf1eae2c2017-06-29 11:18:49 -0400308 *psAppStream << "EMC\nQ\n";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700309 }
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
318 int32_t nCharArray = m_pEdit->GetCharArray();
319 FX_SAFE_INT32 nCharArraySafe = nCharArray;
320 nCharArraySafe -= 1;
321 nCharArraySafe *= 2;
322
323 if (nCharArray > 0 && nCharArraySafe.IsValid()) {
324 switch (GetBorderStyle()) {
dsinclair92cb5e52016-05-16 11:38:28 -0700325 case BorderStyle::SOLID: {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700326 CFX_GraphStateData gsd;
Dan Sinclair05df0752017-03-14 14:43:42 -0400327 gsd.m_LineWidth = (float)GetBorderWidth();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700328
329 CFX_PathData path;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700330
331 for (int32_t i = 0; i < nCharArray - 1; i++) {
Dan Sinclaire4602322017-02-15 11:07:32 -0500332 path.AppendPoint(
dan sinclairb147e072017-02-22 19:56:15 -0500333 CFX_PointF(
334 rcClient.left +
335 ((rcClient.right - rcClient.left) / nCharArray) * (i + 1),
336 rcClient.bottom),
337 FXPT_TYPE::MoveTo, false);
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.top),
343 FXPT_TYPE::LineTo, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700344 }
Dan Sinclaire4602322017-02-15 11:07:32 -0500345 if (!path.GetPoints().empty()) {
Dan Sinclairfc54e052017-02-23 09:59:05 -0500346 pDevice->DrawPath(&path, pUser2Device, &gsd, 0,
347 GetBorderColor().ToFXColor(255), FXFILL_ALTERNATE);
dsinclair92cb5e52016-05-16 11:38:28 -0700348 }
349 break;
350 }
351 case BorderStyle::DASH: {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700352 CFX_GraphStateData gsd;
Dan Sinclair05df0752017-03-14 14:43:42 -0400353 gsd.m_LineWidth = (float)GetBorderWidth();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700354
355 gsd.SetDashCount(2);
Dan Sinclair05df0752017-03-14 14:43:42 -0400356 gsd.m_DashArray[0] = (float)GetBorderDash().nDash;
357 gsd.m_DashArray[1] = (float)GetBorderDash().nGap;
358 gsd.m_DashPhase = (float)GetBorderDash().nPhase;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700359
360 CFX_PathData path;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700361 for (int32_t i = 0; i < nCharArray - 1; i++) {
Dan Sinclaire4602322017-02-15 11:07:32 -0500362 path.AppendPoint(
dan sinclairb147e072017-02-22 19:56:15 -0500363 CFX_PointF(
364 rcClient.left +
365 ((rcClient.right - rcClient.left) / nCharArray) * (i + 1),
366 rcClient.bottom),
367 FXPT_TYPE::MoveTo, false);
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.top),
373 FXPT_TYPE::LineTo, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700374 }
Dan Sinclaire4602322017-02-15 11:07:32 -0500375 if (!path.GetPoints().empty()) {
Dan Sinclairfc54e052017-02-23 09:59:05 -0500376 pDevice->DrawPath(&path, pUser2Device, &gsd, 0,
377 GetBorderColor().ToFXColor(255), FXFILL_ALTERNATE);
dsinclair92cb5e52016-05-16 11:38:28 -0700378 }
379 break;
380 }
381 default:
382 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700383 }
384 }
385
Tom Sepez281a9ea2016-02-26 14:24:28 -0800386 CFX_FloatRect rcClip;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700387 CPVT_WordRange wrRange = m_pEdit->GetVisibleWordRange();
thestig1cd352e2016-06-07 17:53:06 -0700388 CPVT_WordRange* pRange = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700389 if (!HasFlag(PES_TEXTOVERFLOW)) {
390 rcClip = GetClientRect();
391 pRange = &wrRange;
392 }
tsepez63f545c2016-09-13 16:08:49 -0700393
dsinclairb9590102016-04-27 06:38:59 -0700394 CFX_SystemHandler* pSysHandler = GetSystemHandler();
Dan Sinclairfc54e052017-02-23 09:59:05 -0500395 CFX_Edit::DrawEdit(pDevice, pUser2Device, m_pEdit.get(),
396 GetTextColor().ToFXColor(GetTransparency()), rcClip,
Tom Sepezcc205132017-05-16 14:01:47 -0700397 CFX_PointF(), pRange, pSysHandler, m_pFormFiller.Get());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700398}
399
Dan Sinclairf528eee2017-02-14 11:52:07 -0500400bool CPWL_Edit::OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700401 CPWL_Wnd::OnLButtonDown(point, nFlag);
402
403 if (HasFlag(PES_TEXTOVERFLOW) || ClientHitTest(point)) {
404 if (m_bMouseDown)
405 InvalidateRect();
406
tsepez4cf55152016-11-02 14:37:54 -0700407 m_bMouseDown = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700408 SetCapture();
409
410 m_pEdit->OnMouseDown(point, IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
411 }
412
tsepez4cf55152016-11-02 14:37:54 -0700413 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700414}
415
Dan Sinclairf528eee2017-02-14 11:52:07 -0500416bool CPWL_Edit::OnLButtonDblClk(const CFX_PointF& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700417 CPWL_Wnd::OnLButtonDblClk(point, nFlag);
418
419 if (HasFlag(PES_TEXTOVERFLOW) || ClientHitTest(point)) {
420 m_pEdit->SelectAll();
421 }
422
tsepez4cf55152016-11-02 14:37:54 -0700423 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700424}
425
Dan Sinclairf528eee2017-02-14 11:52:07 -0500426bool CPWL_Edit::OnRButtonUp(const CFX_PointF& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700427 if (m_bMouseDown)
tsepez4cf55152016-11-02 14:37:54 -0700428 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700429
430 CPWL_Wnd::OnRButtonUp(point, nFlag);
431
432 if (!HasFlag(PES_TEXTOVERFLOW) && !ClientHitTest(point))
tsepez4cf55152016-11-02 14:37:54 -0700433 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700434
dsinclairb9590102016-04-27 06:38:59 -0700435 CFX_SystemHandler* pSH = GetSystemHandler();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700436 if (!pSH)
tsepez4cf55152016-11-02 14:37:54 -0700437 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700438
439 SetFocus();
440
tsepez4cf55152016-11-02 14:37:54 -0700441 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700442}
443
444void CPWL_Edit::OnSetFocus() {
tsepez4cf55152016-11-02 14:37:54 -0700445 SetEditCaret(true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700446 if (!IsReadOnly()) {
447 if (IPWL_FocusHandler* pFocusHandler = GetFocusHandler())
448 pFocusHandler->OnSetFocus(this);
449 }
tsepez4cf55152016-11-02 14:37:54 -0700450 m_bFocus = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700451}
452
453void CPWL_Edit::OnKillFocus() {
Dan Sinclair0fdd1ae2017-07-05 16:00:48 -0400454 CPWL_ScrollBar* pScroll = GetVScrollBar();
455 if (pScroll && pScroll->IsVisible()) {
456 pScroll->SetVisible(false);
457 Move(m_rcOldWindow, true, true);
458 }
459
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());
Dan Sinclairf51a02a2017-04-19 12:46:53 -0400462 SetCharSet(FX_CHARSET_ANSI);
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 {
Henrique Nakashimaf1eae2c2017-06-29 11:18:49 -0400494 std::ostringstream 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"
Henrique Nakashimaf1eae2c2017-06-29 11:18:49 -0400498 << CPWL_Utils::GetColorAppStream(GetTextColor()) << sEdit << "ET\n";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700499 }
Henrique Nakashimaf1eae2c2017-06-29 11:18:49 -0400500 return CFX_ByteString(sRet);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700501}
502
503CFX_ByteString CPWL_Edit::GetCaretAppearanceStream(
Dan Sinclairf528eee2017-02-14 11:52:07 -0500504 const CFX_PointF& ptOffset) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700505 if (m_pEditCaret)
506 return m_pEditCaret->GetCaretAppearanceStream(ptOffset);
507
508 return CFX_ByteString();
509}
510
Dan Sinclairf528eee2017-02-14 11:52:07 -0500511CFX_PointF CPWL_Edit::GetWordRightBottomPoint(const CPVT_WordPlace& wpWord) {
dsinclaire35af1e2016-07-13 11:26:20 -0700512 CFX_Edit_Iterator* pIterator = m_pEdit->GetIterator();
thestig821d59e2016-05-11 12:59:22 -0700513 CPVT_WordPlace wpOld = pIterator->GetAt();
514 pIterator->SetAt(wpWord);
tsepez63f545c2016-09-13 16:08:49 -0700515
Dan Sinclairf528eee2017-02-14 11:52:07 -0500516 CFX_PointF pt;
thestig821d59e2016-05-11 12:59:22 -0700517 CPVT_Word word;
518 if (pIterator->GetWord(word)) {
Dan Sinclairf528eee2017-02-14 11:52:07 -0500519 pt = CFX_PointF(word.ptWord.x + word.fWidth, word.ptWord.y + word.fDescent);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700520 }
thestig821d59e2016-05-11 12:59:22 -0700521 pIterator->SetAt(wpOld);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700522 return pt;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700523}
524
tsepez4cf55152016-11-02 14:37:54 -0700525bool CPWL_Edit::IsTextFull() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700526 return m_pEdit->IsTextFull();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700527}
528
Dan Sinclair05df0752017-03-14 14:43:42 -0400529float CPWL_Edit::GetCharArrayAutoFontSize(CPDF_Font* pFont,
530 const CFX_FloatRect& rcPlate,
531 int32_t nCharArray) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700532 if (pFont && !pFont->IsStandardFont()) {
533 FX_RECT rcBBox;
534 pFont->GetFontBBox(rcBBox);
535
Tom Sepez281a9ea2016-02-26 14:24:28 -0800536 CFX_FloatRect rcCell = rcPlate;
Dan Sinclair05df0752017-03-14 14:43:42 -0400537 float xdiv = rcCell.Width() / nCharArray * 1000.0f / rcBBox.Width();
538 float ydiv = -rcCell.Height() * 1000.0f / rcBBox.Height();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700539
540 return xdiv < ydiv ? xdiv : ydiv;
541 }
542
543 return 0.0f;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700544}
545
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700546void CPWL_Edit::SetCharArray(int32_t nCharArray) {
547 if (HasFlag(PES_CHARARRAY) && nCharArray > 0) {
548 m_pEdit->SetCharArray(nCharArray);
tsepez4cf55152016-11-02 14:37:54 -0700549 m_pEdit->SetTextOverflow(true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700550
551 if (HasFlag(PWS_AUTOFONTSIZE)) {
dsinclairc7a73492016-04-05 12:01:42 -0700552 if (IPVT_FontMap* pFontMap = GetFontMap()) {
Dan Sinclair05df0752017-03-14 14:43:42 -0400553 float fFontSize = GetCharArrayAutoFontSize(pFontMap->GetPDFFont(0),
554 GetClientRect(), nCharArray);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700555 if (fFontSize > 0.0f) {
tsepez4cf55152016-11-02 14:37:54 -0700556 m_pEdit->SetAutoFontSize(false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700557 m_pEdit->SetFontSize(fFontSize);
558 }
559 }
560 }
561 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700562}
563
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700564void CPWL_Edit::SetLimitChar(int32_t nLimitChar) {
565 m_pEdit->SetLimitChar(nLimitChar);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700566}
567
tsepez067990c2016-09-13 06:46:40 -0700568void CPWL_Edit::ReplaceSel(const CFX_WideString& wsText) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700569 m_pEdit->Clear();
Dan Sinclairf51a02a2017-04-19 12:46:53 -0400570 m_pEdit->InsertText(wsText, FX_CHARSET_Default);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700571}
572
Tom Sepez281a9ea2016-02-26 14:24:28 -0800573CFX_FloatRect CPWL_Edit::GetFocusRect() const {
574 return CFX_FloatRect();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700575}
576
tsepez4cf55152016-11-02 14:37:54 -0700577bool CPWL_Edit::IsVScrollBarVisible() const {
Dan Sinclair0fdd1ae2017-07-05 16:00:48 -0400578 if (CPWL_ScrollBar* pScroll = GetVScrollBar())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700579 return pScroll->IsVisible();
tsepez4cf55152016-11-02 14:37:54 -0700580 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700581}
582
tsepez4cf55152016-11-02 14:37:54 -0700583bool CPWL_Edit::OnKeyDown(uint16_t nChar, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700584 if (m_bMouseDown)
tsepez4cf55152016-11-02 14:37:54 -0700585 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700586
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700587 if (nChar == FWL_VKEY_Delete) {
588 if (m_pFillerNotify) {
tsepez4cf55152016-11-02 14:37:54 -0700589 bool bRC = true;
590 bool bExit = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700591 CFX_WideString strChange;
592 CFX_WideString strChangeEx;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700593
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700594 int nSelStart = 0;
595 int nSelEnd = 0;
596 GetSel(nSelStart, nSelEnd);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700597
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700598 if (nSelStart == nSelEnd)
599 nSelEnd = nSelStart + 1;
Lei Zhanga5b47042015-10-19 14:32:16 -0700600 m_pFillerNotify->OnBeforeKeyStroke(GetAttachedData(), strChange,
tsepez4cf55152016-11-02 14:37:54 -0700601 strChangeEx, nSelStart, nSelEnd, true,
Lei Zhanga5b47042015-10-19 14:32:16 -0700602 bRC, bExit, nFlag);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700603 if (!bRC)
tsepez4cf55152016-11-02 14:37:54 -0700604 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700605 if (bExit)
tsepez4cf55152016-11-02 14:37:54 -0700606 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700607 }
608 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700609
tsepez4cf55152016-11-02 14:37:54 -0700610 bool bRet = CPWL_EditCtrl::OnKeyDown(nChar, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700611
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700612 // In case of implementation swallow the OnKeyDown event.
613 if (IsProceedtoOnChar(nChar, nFlag))
tsepez4cf55152016-11-02 14:37:54 -0700614 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700615
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700616 return bRet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700617}
618
619/**
Lei Zhang633a3b72017-06-02 15:27:22 -0700620 *In case of implementation swallow the OnKeyDown event.
621 *If the event is swallowed, implementation may do other unexpected things,
622 *which is not the control means to do.
623 */
tsepez4cf55152016-11-02 14:37:54 -0700624bool CPWL_Edit::IsProceedtoOnChar(uint16_t nKeyCode, uint32_t nFlag) {
625 bool bCtrl = IsCTRLpressed(nFlag);
626 bool bAlt = IsALTpressed(nFlag);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700627 if (bCtrl && !bAlt) {
628 // hot keys for edit control.
629 switch (nKeyCode) {
630 case 'C':
631 case 'V':
632 case 'X':
633 case 'A':
634 case 'Z':
tsepez4cf55152016-11-02 14:37:54 -0700635 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700636 default:
637 break;
638 }
639 }
640 // control characters.
641 switch (nKeyCode) {
642 case FWL_VKEY_Escape:
643 case FWL_VKEY_Back:
644 case FWL_VKEY_Return:
645 case FWL_VKEY_Space:
tsepez4cf55152016-11-02 14:37:54 -0700646 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700647 default:
tsepez4cf55152016-11-02 14:37:54 -0700648 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700649 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700650}
651
tsepez4cf55152016-11-02 14:37:54 -0700652bool CPWL_Edit::OnChar(uint16_t nChar, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700653 if (m_bMouseDown)
tsepez4cf55152016-11-02 14:37:54 -0700654 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700655
tsepez4cf55152016-11-02 14:37:54 -0700656 bool bRC = true;
657 bool bExit = false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700658
Lei Zhanga5b47042015-10-19 14:32:16 -0700659 if (!IsCTRLpressed(nFlag)) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700660 if (m_pFillerNotify) {
661 CFX_WideString swChange;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700662
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700663 int nSelStart = 0;
664 int nSelEnd = 0;
665 GetSel(nSelStart, nSelEnd);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700666
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700667 switch (nChar) {
668 case FWL_VKEY_Back:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700669 if (nSelStart == nSelEnd)
670 nSelStart = nSelEnd - 1;
671 break;
672 case FWL_VKEY_Return:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700673 break;
674 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700675 swChange += nChar;
676 break;
677 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700678
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700679 CFX_WideString strChangeEx;
Lei Zhanga5b47042015-10-19 14:32:16 -0700680 m_pFillerNotify->OnBeforeKeyStroke(GetAttachedData(), swChange,
tsepez4cf55152016-11-02 14:37:54 -0700681 strChangeEx, nSelStart, nSelEnd, true,
Lei Zhanga5b47042015-10-19 14:32:16 -0700682 bRC, bExit, nFlag);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700683 }
684 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700685
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700686 if (!bRC)
tsepez4cf55152016-11-02 14:37:54 -0700687 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700688 if (bExit)
tsepez4cf55152016-11-02 14:37:54 -0700689 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700690
dsinclairc7a73492016-04-05 12:01:42 -0700691 if (IPVT_FontMap* pFontMap = GetFontMap()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700692 int32_t nOldCharSet = GetCharSet();
npmea3c3be2016-09-19 07:24:33 -0700693 int32_t nNewCharSet =
Dan Sinclairf51a02a2017-04-19 12:46:53 -0400694 pFontMap->CharSetFromUnicode(nChar, FX_CHARSET_Default);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700695 if (nOldCharSet != nNewCharSet) {
696 SetCharSet(nNewCharSet);
697 }
698 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700699
Lei Zhanga5b47042015-10-19 14:32:16 -0700700 return CPWL_EditCtrl::OnChar(nChar, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700701}
702
tsepez4cf55152016-11-02 14:37:54 -0700703bool CPWL_Edit::OnMouseWheel(short zDelta,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500704 const CFX_PointF& point,
tsepez4cf55152016-11-02 14:37:54 -0700705 uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700706 if (HasFlag(PES_MULTILINE)) {
Dan Sinclairf528eee2017-02-14 11:52:07 -0500707 CFX_PointF ptScroll = GetScrollPos();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700708
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700709 if (zDelta > 0) {
710 ptScroll.y += GetFontSize();
711 } else {
712 ptScroll.y -= GetFontSize();
713 }
714 SetScrollPos(ptScroll);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700715
tsepez4cf55152016-11-02 14:37:54 -0700716 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700717 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700718
tsepez4cf55152016-11-02 14:37:54 -0700719 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700720}
721
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700722void CPWL_Edit::OnInsertReturn(const CPVT_WordPlace& place,
723 const CPVT_WordPlace& oldplace) {
724 if (HasFlag(PES_SPELLCHECK)) {
725 m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace),
726 GetLatinWordsRange(place)));
727 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700728}
729
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700730void CPWL_Edit::OnBackSpace(const CPVT_WordPlace& place,
731 const CPVT_WordPlace& oldplace) {
732 if (HasFlag(PES_SPELLCHECK)) {
733 m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace),
734 GetLatinWordsRange(place)));
735 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700736}
737
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700738void CPWL_Edit::OnDelete(const CPVT_WordPlace& place,
739 const CPVT_WordPlace& oldplace) {
740 if (HasFlag(PES_SPELLCHECK)) {
741 m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace),
742 GetLatinWordsRange(place)));
743 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700744}
745
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700746void CPWL_Edit::OnClear(const CPVT_WordPlace& place,
747 const CPVT_WordPlace& oldplace) {
748 if (HasFlag(PES_SPELLCHECK)) {
749 m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace),
750 GetLatinWordsRange(place)));
751 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700752}
753
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700754void CPWL_Edit::OnInsertWord(const CPVT_WordPlace& place,
755 const CPVT_WordPlace& oldplace) {
756 if (HasFlag(PES_SPELLCHECK)) {
757 m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace),
758 GetLatinWordsRange(place)));
759 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700760}
761
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700762void CPWL_Edit::OnInsertText(const CPVT_WordPlace& place,
763 const CPVT_WordPlace& oldplace) {
764 if (HasFlag(PES_SPELLCHECK)) {
765 m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace),
766 GetLatinWordsRange(place)));
767 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700768}
769
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700770CPVT_WordRange CPWL_Edit::CombineWordRange(const CPVT_WordRange& wr1,
771 const CPVT_WordRange& wr2) {
Tom Sepez52f69b32017-03-21 13:42:38 -0700772 return CPVT_WordRange(std::min(wr1.BeginPos, wr2.BeginPos),
773 std::max(wr1.EndPos, wr2.EndPos));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700774}
775
Dan Sinclairf528eee2017-02-14 11:52:07 -0500776CPVT_WordRange CPWL_Edit::GetLatinWordsRange(const CFX_PointF& point) const {
tsepez4cf55152016-11-02 14:37:54 -0700777 return GetSameWordsRange(m_pEdit->SearchWordPlace(point), true, false);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700778}
779
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700780CPVT_WordRange CPWL_Edit::GetLatinWordsRange(
781 const CPVT_WordPlace& place) const {
tsepez4cf55152016-11-02 14:37:54 -0700782 return GetSameWordsRange(place, true, false);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700783}
784
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700785CPVT_WordRange CPWL_Edit::GetArabicWordsRange(
786 const CPVT_WordPlace& place) const {
tsepez4cf55152016-11-02 14:37:54 -0700787 return GetSameWordsRange(place, false, true);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700788}
789
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700790#define PWL_ISARABICWORD(word) \
791 ((word >= 0x0600 && word <= 0x06FF) || (word >= 0xFB50 && word <= 0xFEFC))
792
793CPVT_WordRange CPWL_Edit::GetSameWordsRange(const CPVT_WordPlace& place,
tsepez4cf55152016-11-02 14:37:54 -0700794 bool bLatin,
795 bool bArabic) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700796 CPVT_WordRange range;
797
dsinclaire35af1e2016-07-13 11:26:20 -0700798 CFX_Edit_Iterator* pIterator = m_pEdit->GetIterator();
thestig821d59e2016-05-11 12:59:22 -0700799 CPVT_Word wordinfo;
800 CPVT_WordPlace wpStart(place), wpEnd(place);
801 pIterator->SetAt(place);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700802
thestig821d59e2016-05-11 12:59:22 -0700803 if (bLatin) {
804 while (pIterator->NextWord()) {
805 if (!pIterator->GetWord(wordinfo) ||
806 !FX_EDIT_ISLATINWORD(wordinfo.Word)) {
807 break;
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800808 }
Lei Zhangc2fb35f2016-01-05 16:46:58 -0800809
thestig821d59e2016-05-11 12:59:22 -0700810 wpEnd = pIterator->GetAt();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700811 }
thestig821d59e2016-05-11 12:59:22 -0700812 } else if (bArabic) {
813 while (pIterator->NextWord()) {
814 if (!pIterator->GetWord(wordinfo) || !PWL_ISARABICWORD(wordinfo.Word))
815 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700816
thestig821d59e2016-05-11 12:59:22 -0700817 wpEnd = pIterator->GetAt();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700818 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700819 }
820
thestig821d59e2016-05-11 12:59:22 -0700821 pIterator->SetAt(place);
822
823 if (bLatin) {
824 do {
825 if (!pIterator->GetWord(wordinfo) ||
826 !FX_EDIT_ISLATINWORD(wordinfo.Word)) {
827 break;
828 }
829
830 wpStart = pIterator->GetAt();
831 } while (pIterator->PrevWord());
832 } else if (bArabic) {
833 do {
834 if (!pIterator->GetWord(wordinfo) || !PWL_ISARABICWORD(wordinfo.Word))
835 break;
836
837 wpStart = pIterator->GetAt();
838 } while (pIterator->PrevWord());
839 }
840
841 range.Set(wpStart, wpEnd);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700842 return range;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700843}