blob: 90b7a3c7c078e54de1ef698542e6cda2a2b15178 [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 Zhang60f507b2015-06-13 00:41:00 -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_EditCtrl.h"
Lei Zhangc2fb35f2016-01-05 16:46:58 -08008
dsinclair1727aee2016-09-29 13:12:56 -07009#include "core/fpdfdoc/cpvt_section.h"
10#include "core/fpdfdoc/cpvt_word.h"
dsinclair74a34fc2016-09-29 16:41:42 -070011#include "core/fxge/fx_font.h"
dsinclair0bb385b2016-09-29 17:03:59 -070012#include "fpdfsdk/fxedit/fxet_edit.h"
dan sinclair89e904b2016-03-23 19:29:15 -040013#include "fpdfsdk/pdfwindow/PWL_Caret.h"
14#include "fpdfsdk/pdfwindow/PWL_FontMap.h"
15#include "fpdfsdk/pdfwindow/PWL_ScrollBar.h"
16#include "fpdfsdk/pdfwindow/PWL_Utils.h"
17#include "fpdfsdk/pdfwindow/PWL_Wnd.h"
Lei Zhangc2fb35f2016-01-05 16:46:58 -080018#include "public/fpdf_fwlevent.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070019
Nico Weber9d8ec5a2015-08-04 13:00:21 -070020CPWL_EditCtrl::CPWL_EditCtrl()
dsinclaire35af1e2016-07-13 11:26:20 -070021 : m_pEdit(new CFX_Edit),
thestig1cd352e2016-06-07 17:53:06 -070022 m_pEditCaret(nullptr),
tsepez4cf55152016-11-02 14:37:54 -070023 m_bMouseDown(false),
npmea3c3be2016-09-19 07:24:33 -070024 m_nCharSet(FXFONT_DEFAULT_CHARSET),
thestig732f6a02016-05-12 10:41:56 -070025 m_nCodePage(0) {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070026
dsinclairdbc77162016-07-13 11:34:23 -070027CPWL_EditCtrl::~CPWL_EditCtrl() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070028
Nico Weber9d8ec5a2015-08-04 13:00:21 -070029void CPWL_EditCtrl::OnCreate(PWL_CREATEPARAM& cp) {
30 cp.eCursorType = FXCT_VBEAM;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070031}
32
Nico Weber9d8ec5a2015-08-04 13:00:21 -070033void CPWL_EditCtrl::OnCreated() {
34 SetFontSize(GetCreationParam().fFontSize);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070035
Nico Weber9d8ec5a2015-08-04 13:00:21 -070036 m_pEdit->SetFontMap(GetFontMap());
37 m_pEdit->SetNotify(this);
38 m_pEdit->Initialize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070039}
40
tsepez4cf55152016-11-02 14:37:54 -070041bool CPWL_EditCtrl::IsWndHorV() {
Tom Sepez60d909e2015-12-10 15:34:55 -080042 CFX_Matrix mt = GetWindowMatrix();
Tom Sepez281a9ea2016-02-26 14:24:28 -080043 CFX_FloatPoint point1(0, 1);
44 CFX_FloatPoint point2(1, 1);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070045
Dan Sinclairafb44562017-02-09 13:07:43 -050046 mt.TransformPoint(point1.x, point1.y);
47 mt.TransformPoint(point2.x, point2.y);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070048
Nico Weber9d8ec5a2015-08-04 13:00:21 -070049 return point2.y == point1.y;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070050}
51
Nico Weber9d8ec5a2015-08-04 13:00:21 -070052void CPWL_EditCtrl::SetCursor() {
53 if (IsValid()) {
dsinclairb9590102016-04-27 06:38:59 -070054 if (CFX_SystemHandler* pSH = GetSystemHandler()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070055 if (IsWndHorV())
56 pSH->SetCursor(FXCT_VBEAM);
57 else
58 pSH->SetCursor(FXCT_HBEAM);
Tom Sepez2f2ffec2015-07-23 14:42:09 -070059 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070060 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070061}
62
Nico Weber9d8ec5a2015-08-04 13:00:21 -070063void CPWL_EditCtrl::RePosChildWnd() {
64 m_pEdit->SetPlateRect(GetClientRect());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070065}
66
Nico Weber9d8ec5a2015-08-04 13:00:21 -070067void CPWL_EditCtrl::OnNotify(CPWL_Wnd* pWnd,
tsepezc3255f52016-03-25 14:52:27 -070068 uint32_t msg,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070069 intptr_t wParam,
70 intptr_t lParam) {
71 CPWL_Wnd::OnNotify(pWnd, msg, wParam, lParam);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070072
Nico Weber9d8ec5a2015-08-04 13:00:21 -070073 switch (msg) {
74 case PNM_SETSCROLLINFO:
75 switch (wParam) {
76 case SBT_VSCROLL:
77 if (CPWL_Wnd* pChild = GetVScrollBar()) {
78 pChild->OnNotify(pWnd, PNM_SETSCROLLINFO, wParam, lParam);
79 }
80 break;
81 }
82 break;
83 case PNM_SETSCROLLPOS:
84 switch (wParam) {
85 case SBT_VSCROLL:
86 if (CPWL_Wnd* pChild = GetVScrollBar()) {
87 pChild->OnNotify(pWnd, PNM_SETSCROLLPOS, wParam, lParam);
88 }
89 break;
90 }
91 break;
92 case PNM_SCROLLWINDOW: {
93 FX_FLOAT fPos = *(FX_FLOAT*)lParam;
94 switch (wParam) {
95 case SBT_VSCROLL:
Tom Sepez281a9ea2016-02-26 14:24:28 -080096 m_pEdit->SetScrollPos(
97 CFX_FloatPoint(m_pEdit->GetScrollPos().x, fPos));
Nico Weber9d8ec5a2015-08-04 13:00:21 -070098 break;
99 }
100 } break;
101 case PNM_SETCARETINFO: {
102 if (PWL_CARET_INFO* pCaretInfo = (PWL_CARET_INFO*)wParam) {
103 SetCaret(pCaretInfo->bVisible, pCaretInfo->ptHead, pCaretInfo->ptFoot);
104 }
105 } break;
106 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700107}
108
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700109void CPWL_EditCtrl::CreateChildWnd(const PWL_CREATEPARAM& cp) {
110 if (!IsReadOnly())
111 CreateEditCaret(cp);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700112}
113
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700114void CPWL_EditCtrl::CreateEditCaret(const PWL_CREATEPARAM& cp) {
thestig732f6a02016-05-12 10:41:56 -0700115 if (m_pEditCaret)
116 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700117
thestig732f6a02016-05-12 10:41:56 -0700118 m_pEditCaret = new CPWL_Caret;
119 m_pEditCaret->SetInvalidRect(GetClientRect());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700120
thestig732f6a02016-05-12 10:41:56 -0700121 PWL_CREATEPARAM ecp = cp;
122 ecp.pParentWnd = this;
123 ecp.dwFlags = PWS_CHILD | PWS_NOREFRESHCLIP;
124 ecp.dwBorderWidth = 0;
dsinclair92cb5e52016-05-16 11:38:28 -0700125 ecp.nBorderStyle = BorderStyle::SOLID;
thestig732f6a02016-05-12 10:41:56 -0700126 ecp.rcRectWnd = CFX_FloatRect(0, 0, 0, 0);
127
128 m_pEditCaret->Create(ecp);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700129}
130
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700131void CPWL_EditCtrl::SetFontSize(FX_FLOAT fFontSize) {
132 m_pEdit->SetFontSize(fFontSize);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700133}
134
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700135FX_FLOAT CPWL_EditCtrl::GetFontSize() const {
136 return m_pEdit->GetFontSize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700137}
138
tsepez4cf55152016-11-02 14:37:54 -0700139bool CPWL_EditCtrl::OnKeyDown(uint16_t nChar, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700140 if (m_bMouseDown)
tsepez4cf55152016-11-02 14:37:54 -0700141 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700142
tsepez4cf55152016-11-02 14:37:54 -0700143 bool bRet = CPWL_Wnd::OnKeyDown(nChar, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700144
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700145 // FILTER
146 switch (nChar) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700147 default:
tsepez4cf55152016-11-02 14:37:54 -0700148 return false;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700149 case FWL_VKEY_Delete:
150 case FWL_VKEY_Up:
151 case FWL_VKEY_Down:
152 case FWL_VKEY_Left:
153 case FWL_VKEY_Right:
154 case FWL_VKEY_Home:
155 case FWL_VKEY_End:
156 case FWL_VKEY_Insert:
157 case 'C':
158 case 'V':
159 case 'X':
160 case 'A':
161 case 'Z':
162 case 'c':
163 case 'v':
164 case 'x':
165 case 'a':
166 case 'z':
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700167 break;
168 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700169
thestig594b20b2016-05-12 21:56:43 -0700170 if (nChar == FWL_VKEY_Delete && m_pEdit->IsSelected())
171 nChar = FWL_VKEY_Unknown;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700172
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700173 switch (nChar) {
174 case FWL_VKEY_Delete:
175 Delete();
tsepez4cf55152016-11-02 14:37:54 -0700176 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700177 case FWL_VKEY_Insert:
178 if (IsSHIFTpressed(nFlag))
179 PasteText();
tsepez4cf55152016-11-02 14:37:54 -0700180 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700181 case FWL_VKEY_Up:
tsepez4cf55152016-11-02 14:37:54 -0700182 m_pEdit->OnVK_UP(IsSHIFTpressed(nFlag), false);
183 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700184 case FWL_VKEY_Down:
tsepez4cf55152016-11-02 14:37:54 -0700185 m_pEdit->OnVK_DOWN(IsSHIFTpressed(nFlag), false);
186 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700187 case FWL_VKEY_Left:
tsepez4cf55152016-11-02 14:37:54 -0700188 m_pEdit->OnVK_LEFT(IsSHIFTpressed(nFlag), false);
189 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700190 case FWL_VKEY_Right:
tsepez4cf55152016-11-02 14:37:54 -0700191 m_pEdit->OnVK_RIGHT(IsSHIFTpressed(nFlag), false);
192 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700193 case FWL_VKEY_Home:
194 m_pEdit->OnVK_HOME(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
tsepez4cf55152016-11-02 14:37:54 -0700195 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700196 case FWL_VKEY_End:
197 m_pEdit->OnVK_END(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
tsepez4cf55152016-11-02 14:37:54 -0700198 return true;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700199 case FWL_VKEY_Unknown:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700200 if (!IsSHIFTpressed(nFlag))
201 Clear();
202 else
203 CutText();
tsepez4cf55152016-11-02 14:37:54 -0700204 return true;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700205 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700206 break;
207 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700208
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700209 return bRet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700210}
211
tsepez4cf55152016-11-02 14:37:54 -0700212bool CPWL_EditCtrl::OnChar(uint16_t nChar, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700213 if (m_bMouseDown)
tsepez4cf55152016-11-02 14:37:54 -0700214 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700215
216 CPWL_Wnd::OnChar(nChar, nFlag);
217
218 // FILTER
219 switch (nChar) {
220 case 0x0A:
221 case 0x1B:
tsepez4cf55152016-11-02 14:37:54 -0700222 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700223 default:
224 break;
225 }
226
tsepez4cf55152016-11-02 14:37:54 -0700227 bool bCtrl = IsCTRLpressed(nFlag);
228 bool bAlt = IsALTpressed(nFlag);
229 bool bShift = IsSHIFTpressed(nFlag);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700230
Tom Sepez62a70f92016-03-21 15:00:20 -0700231 uint16_t word = nChar;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700232
233 if (bCtrl && !bAlt) {
234 switch (nChar) {
235 case 'C' - 'A' + 1:
236 CopyText();
tsepez4cf55152016-11-02 14:37:54 -0700237 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700238 case 'V' - 'A' + 1:
239 PasteText();
tsepez4cf55152016-11-02 14:37:54 -0700240 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700241 case 'X' - 'A' + 1:
242 CutText();
tsepez4cf55152016-11-02 14:37:54 -0700243 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700244 case 'A' - 'A' + 1:
245 SelectAll();
tsepez4cf55152016-11-02 14:37:54 -0700246 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700247 case 'Z' - 'A' + 1:
248 if (bShift)
249 Redo();
250 else
251 Undo();
tsepez4cf55152016-11-02 14:37:54 -0700252 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700253 default:
254 if (nChar < 32)
tsepez4cf55152016-11-02 14:37:54 -0700255 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700256 }
257 }
258
259 if (IsReadOnly())
tsepez4cf55152016-11-02 14:37:54 -0700260 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700261
262 if (m_pEdit->IsSelected() && word == FWL_VKEY_Back)
263 word = FWL_VKEY_Unknown;
264
265 Clear();
266
267 switch (word) {
268 case FWL_VKEY_Back:
269 Backspace();
270 break;
271 case FWL_VKEY_Return:
272 InsertReturn();
273 break;
274 case FWL_VKEY_Unknown:
275 break;
276 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700277 InsertWord(word, GetCharSet());
278 break;
279 }
280
tsepez4cf55152016-11-02 14:37:54 -0700281 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700282}
283
tsepez4cf55152016-11-02 14:37:54 -0700284bool CPWL_EditCtrl::OnLButtonDown(const CFX_FloatPoint& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700285 CPWL_Wnd::OnLButtonDown(point, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700286
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700287 if (ClientHitTest(point)) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700288 if (m_bMouseDown)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700289 InvalidateRect();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700290
tsepez4cf55152016-11-02 14:37:54 -0700291 m_bMouseDown = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700292 SetCapture();
293
294 m_pEdit->OnMouseDown(point, IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
295 }
296
tsepez4cf55152016-11-02 14:37:54 -0700297 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700298}
299
tsepez4cf55152016-11-02 14:37:54 -0700300bool CPWL_EditCtrl::OnLButtonUp(const CFX_FloatPoint& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700301 CPWL_Wnd::OnLButtonUp(point, nFlag);
302
303 if (m_bMouseDown) {
304 // can receive keybord message
305 if (ClientHitTest(point) && !IsFocused())
306 SetFocus();
307
308 ReleaseCapture();
tsepez4cf55152016-11-02 14:37:54 -0700309 m_bMouseDown = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700310 }
311
tsepez4cf55152016-11-02 14:37:54 -0700312 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700313}
314
tsepez4cf55152016-11-02 14:37:54 -0700315bool CPWL_EditCtrl::OnMouseMove(const CFX_FloatPoint& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700316 CPWL_Wnd::OnMouseMove(point, nFlag);
317
318 if (m_bMouseDown)
tsepez4cf55152016-11-02 14:37:54 -0700319 m_pEdit->OnMouseMove(point, false, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700320
tsepez4cf55152016-11-02 14:37:54 -0700321 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700322}
323
Tom Sepez281a9ea2016-02-26 14:24:28 -0800324CFX_FloatRect CPWL_EditCtrl::GetContentRect() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700325 return m_pEdit->GetContentRect();
326}
327
tsepez4cf55152016-11-02 14:37:54 -0700328void CPWL_EditCtrl::SetEditCaret(bool bVisible) {
tsepez63f545c2016-09-13 16:08:49 -0700329 CFX_FloatPoint ptHead;
330 CFX_FloatPoint ptFoot;
331 if (bVisible)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700332 GetCaretInfo(ptHead, ptFoot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700333
334 CPVT_WordPlace wpTemp = m_pEdit->GetCaretWordPlace();
335 IOnSetCaret(bVisible, ptHead, ptFoot, wpTemp);
336}
337
Tom Sepez281a9ea2016-02-26 14:24:28 -0800338void CPWL_EditCtrl::GetCaretInfo(CFX_FloatPoint& ptHead,
339 CFX_FloatPoint& ptFoot) const {
dsinclaire35af1e2016-07-13 11:26:20 -0700340 CFX_Edit_Iterator* pIterator = m_pEdit->GetIterator();
thestig821d59e2016-05-11 12:59:22 -0700341 pIterator->SetAt(m_pEdit->GetCaret());
342 CPVT_Word word;
343 CPVT_Line line;
344 if (pIterator->GetWord(word)) {
345 ptHead.x = word.ptWord.x + word.fWidth;
346 ptHead.y = word.ptWord.y + word.fAscent;
347 ptFoot.x = word.ptWord.x + word.fWidth;
348 ptFoot.y = word.ptWord.y + word.fDescent;
349 } else if (pIterator->GetLine(line)) {
350 ptHead.x = line.ptLine.x;
351 ptHead.y = line.ptLine.y + line.fLineAscent;
352 ptFoot.x = line.ptLine.x;
353 ptFoot.y = line.ptLine.y + line.fLineDescent;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700354 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700355}
356
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700357void CPWL_EditCtrl::GetCaretPos(int32_t& x, int32_t& y) const {
tsepez63f545c2016-09-13 16:08:49 -0700358 CFX_FloatPoint ptHead;
359 CFX_FloatPoint ptFoot;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700360 GetCaretInfo(ptHead, ptFoot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700361 PWLtoWnd(ptHead, x, y);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700362}
363
tsepez4cf55152016-11-02 14:37:54 -0700364void CPWL_EditCtrl::SetCaret(bool bVisible,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800365 const CFX_FloatPoint& ptHead,
366 const CFX_FloatPoint& ptFoot) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700367 if (m_pEditCaret) {
368 if (!IsFocused() || m_pEdit->IsSelected())
tsepez4cf55152016-11-02 14:37:54 -0700369 bVisible = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700370
371 m_pEditCaret->SetCaret(bVisible, ptHead, ptFoot);
372 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700373}
374
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700375CFX_WideString CPWL_EditCtrl::GetText() const {
376 return m_pEdit->GetText();
377}
378
379void CPWL_EditCtrl::SetSel(int32_t nStartChar, int32_t nEndChar) {
380 m_pEdit->SetSel(nStartChar, nEndChar);
381}
382
383void CPWL_EditCtrl::GetSel(int32_t& nStartChar, int32_t& nEndChar) const {
384 m_pEdit->GetSel(nStartChar, nEndChar);
385}
386
387void CPWL_EditCtrl::Clear() {
388 if (!IsReadOnly())
389 m_pEdit->Clear();
390}
391
392void CPWL_EditCtrl::SelectAll() {
393 m_pEdit->SelectAll();
394}
395
396void CPWL_EditCtrl::Paint() {
thestig732f6a02016-05-12 10:41:56 -0700397 m_pEdit->Paint();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700398}
399
tsepez4cf55152016-11-02 14:37:54 -0700400void CPWL_EditCtrl::EnableRefresh(bool bRefresh) {
thestig732f6a02016-05-12 10:41:56 -0700401 m_pEdit->EnableRefresh(bRefresh);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700402}
403
404int32_t CPWL_EditCtrl::GetCaret() const {
thestig732f6a02016-05-12 10:41:56 -0700405 return m_pEdit->GetCaret();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700406}
407
408void CPWL_EditCtrl::SetCaret(int32_t nPos) {
thestig732f6a02016-05-12 10:41:56 -0700409 m_pEdit->SetCaret(nPos);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700410}
411
412int32_t CPWL_EditCtrl::GetTotalWords() const {
thestig732f6a02016-05-12 10:41:56 -0700413 return m_pEdit->GetTotalWords();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700414}
415
Tom Sepez281a9ea2016-02-26 14:24:28 -0800416void CPWL_EditCtrl::SetScrollPos(const CFX_FloatPoint& point) {
thestig732f6a02016-05-12 10:41:56 -0700417 m_pEdit->SetScrollPos(point);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700418}
419
Tom Sepez281a9ea2016-02-26 14:24:28 -0800420CFX_FloatPoint CPWL_EditCtrl::GetScrollPos() const {
thestig732f6a02016-05-12 10:41:56 -0700421 return m_pEdit->GetScrollPos();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700422}
423
424CPDF_Font* CPWL_EditCtrl::GetCaretFont() const {
425 int32_t nFontIndex = 0;
426
dsinclaire35af1e2016-07-13 11:26:20 -0700427 CFX_Edit_Iterator* pIterator = m_pEdit->GetIterator();
thestig821d59e2016-05-11 12:59:22 -0700428 pIterator->SetAt(m_pEdit->GetCaret());
429 CPVT_Word word;
430 CPVT_Section section;
431 if (pIterator->GetWord(word)) {
432 nFontIndex = word.nFontIndex;
433 } else if (HasFlag(PES_RICH)) {
434 if (pIterator->GetSection(section)) {
435 nFontIndex = section.WordProps.nFontIndex;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700436 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700437 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700438
dsinclairc7a73492016-04-05 12:01:42 -0700439 if (IPVT_FontMap* pFontMap = GetFontMap())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700440 return pFontMap->GetPDFFont(nFontIndex);
441
thestig1cd352e2016-06-07 17:53:06 -0700442 return nullptr;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700443}
444
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700445FX_FLOAT CPWL_EditCtrl::GetCaretFontSize() const {
446 FX_FLOAT fFontSize = GetFontSize();
447
dsinclaire35af1e2016-07-13 11:26:20 -0700448 CFX_Edit_Iterator* pIterator = m_pEdit->GetIterator();
thestig821d59e2016-05-11 12:59:22 -0700449 pIterator->SetAt(m_pEdit->GetCaret());
450 CPVT_Word word;
451 CPVT_Section section;
452 if (pIterator->GetWord(word)) {
453 fFontSize = word.fFontSize;
454 } else if (HasFlag(PES_RICH)) {
455 if (pIterator->GetSection(section)) {
456 fFontSize = section.WordProps.fFontSize;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700457 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700458 }
459
460 return fFontSize;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700461}
462
tsepez067990c2016-09-13 06:46:40 -0700463void CPWL_EditCtrl::SetText(const CFX_WideString& wsText) {
464 m_pEdit->SetText(wsText);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700465}
466
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700467void CPWL_EditCtrl::CopyText() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700468
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700469void CPWL_EditCtrl::PasteText() {}
470
471void CPWL_EditCtrl::CutText() {}
472
tsepez4cf55152016-11-02 14:37:54 -0700473void CPWL_EditCtrl::ShowVScrollBar(bool bShow) {}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700474
tsepez067990c2016-09-13 06:46:40 -0700475void CPWL_EditCtrl::InsertText(const CFX_WideString& wsText) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700476 if (!IsReadOnly())
npmea3c3be2016-09-19 07:24:33 -0700477 m_pEdit->InsertText(wsText, FXFONT_DEFAULT_CHARSET);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700478}
479
Tom Sepez62a70f92016-03-21 15:00:20 -0700480void CPWL_EditCtrl::InsertWord(uint16_t word, int32_t nCharset) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700481 if (!IsReadOnly())
482 m_pEdit->InsertWord(word, nCharset);
483}
484
485void CPWL_EditCtrl::InsertReturn() {
486 if (!IsReadOnly())
487 m_pEdit->InsertReturn();
488}
489
490void CPWL_EditCtrl::Delete() {
491 if (!IsReadOnly())
492 m_pEdit->Delete();
493}
494
495void CPWL_EditCtrl::Backspace() {
496 if (!IsReadOnly())
497 m_pEdit->Backspace();
498}
499
tsepez4cf55152016-11-02 14:37:54 -0700500bool CPWL_EditCtrl::CanUndo() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700501 return !IsReadOnly() && m_pEdit->CanUndo();
502}
503
tsepez4cf55152016-11-02 14:37:54 -0700504bool CPWL_EditCtrl::CanRedo() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700505 return !IsReadOnly() && m_pEdit->CanRedo();
506}
507
508void CPWL_EditCtrl::Redo() {
509 if (CanRedo())
510 m_pEdit->Redo();
511}
512
513void CPWL_EditCtrl::Undo() {
514 if (CanUndo())
515 m_pEdit->Undo();
516}
517
518void CPWL_EditCtrl::IOnSetScrollInfoY(FX_FLOAT fPlateMin,
519 FX_FLOAT fPlateMax,
520 FX_FLOAT fContentMin,
521 FX_FLOAT fContentMax,
522 FX_FLOAT fSmallStep,
523 FX_FLOAT fBigStep) {
524 PWL_SCROLL_INFO Info;
525
526 Info.fPlateWidth = fPlateMax - fPlateMin;
527 Info.fContentMin = fContentMin;
528 Info.fContentMax = fContentMax;
529 Info.fSmallStep = fSmallStep;
530 Info.fBigStep = fBigStep;
531
532 OnNotify(this, PNM_SETSCROLLINFO, SBT_VSCROLL, (intptr_t)&Info);
533
534 if (IsFloatBigger(Info.fPlateWidth, Info.fContentMax - Info.fContentMin) ||
535 IsFloatEqual(Info.fPlateWidth, Info.fContentMax - Info.fContentMin)) {
tsepez4cf55152016-11-02 14:37:54 -0700536 ShowVScrollBar(false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700537 } else {
tsepez4cf55152016-11-02 14:37:54 -0700538 ShowVScrollBar(true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700539 }
540}
541
542void CPWL_EditCtrl::IOnSetScrollPosY(FX_FLOAT fy) {
543 OnNotify(this, PNM_SETSCROLLPOS, SBT_VSCROLL, (intptr_t)&fy);
544}
545
tsepez4cf55152016-11-02 14:37:54 -0700546void CPWL_EditCtrl::IOnSetCaret(bool bVisible,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800547 const CFX_FloatPoint& ptHead,
548 const CFX_FloatPoint& ptFoot,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700549 const CPVT_WordPlace& place) {
550 PWL_CARET_INFO cInfo;
551 cInfo.bVisible = bVisible;
552 cInfo.ptHead = ptHead;
553 cInfo.ptFoot = ptFoot;
554
thestig1cd352e2016-06-07 17:53:06 -0700555 OnNotify(this, PNM_SETCARETINFO, (intptr_t)&cInfo, (intptr_t) nullptr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700556}
557
dsinclairdbc77162016-07-13 11:34:23 -0700558void CPWL_EditCtrl::IOnCaretChange(const CPVT_SecProps& secProps,
559 const CPVT_WordProps& wordProps) {}
560
561void CPWL_EditCtrl::IOnContentChange(const CFX_FloatRect& rcContent) {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700562
Tom Sepez281a9ea2016-02-26 14:24:28 -0800563void CPWL_EditCtrl::IOnInvalidateRect(CFX_FloatRect* pRect) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700564 InvalidateRect(pRect);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700565}
566
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700567int32_t CPWL_EditCtrl::GetCharSet() const {
npmea3c3be2016-09-19 07:24:33 -0700568 return m_nCharSet < 0 ? FXFONT_DEFAULT_CHARSET : m_nCharSet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700569}
570
Tom Sepez281a9ea2016-02-26 14:24:28 -0800571void CPWL_EditCtrl::GetTextRange(const CFX_FloatRect& rect,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700572 int32_t& nStartChar,
573 int32_t& nEndChar) const {
574 nStartChar = m_pEdit->WordPlaceToWordIndex(
Tom Sepez281a9ea2016-02-26 14:24:28 -0800575 m_pEdit->SearchWordPlace(CFX_FloatPoint(rect.left, rect.top)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700576 nEndChar = m_pEdit->WordPlaceToWordIndex(
Tom Sepez281a9ea2016-02-26 14:24:28 -0800577 m_pEdit->SearchWordPlace(CFX_FloatPoint(rect.right, rect.bottom)));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700578}
579
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700580CFX_WideString CPWL_EditCtrl::GetText(int32_t& nStartChar,
581 int32_t& nEndChar) const {
582 CPVT_WordPlace wpStart = m_pEdit->WordIndexToWordPlace(nStartChar);
583 CPVT_WordPlace wpEnd = m_pEdit->WordIndexToWordPlace(nEndChar);
584 return m_pEdit->GetRangeText(CPVT_WordRange(wpStart, wpEnd));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700585}
586
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700587void CPWL_EditCtrl::SetReadyToInput() {
588 if (m_bMouseDown) {
589 ReleaseCapture();
tsepez4cf55152016-11-02 14:37:54 -0700590 m_bMouseDown = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700591 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700592}