blob: 8452febb97d75017766832ec04e043d6726e73a2 [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"
dsinclaire35af1e2016-07-13 11:26:20 -070012#include "fpdfsdk/fxedit/include/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),
Nico Weber9d8ec5a2015-08-04 13:00:21 -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
Nico Weber9d8ec5a2015-08-04 13:00:21 -070041FX_BOOL 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
Nico Weber9d8ec5a2015-08-04 13:00:21 -070046 mt.Transform(point1.x, point1.y);
47 mt.Transform(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
tsepezc3255f52016-03-25 14:52:27 -0700139FX_BOOL CPWL_EditCtrl::OnKeyDown(uint16_t nChar, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700140 if (m_bMouseDown)
141 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700142
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700143 FX_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:
Nico Weber9d8ec5a2015-08-04 13:00:21 -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();
176 return TRUE;
177 case FWL_VKEY_Insert:
178 if (IsSHIFTpressed(nFlag))
179 PasteText();
180 return TRUE;
181 case FWL_VKEY_Up:
182 m_pEdit->OnVK_UP(IsSHIFTpressed(nFlag), FALSE);
183 return TRUE;
184 case FWL_VKEY_Down:
185 m_pEdit->OnVK_DOWN(IsSHIFTpressed(nFlag), FALSE);
186 return TRUE;
187 case FWL_VKEY_Left:
188 m_pEdit->OnVK_LEFT(IsSHIFTpressed(nFlag), FALSE);
189 return TRUE;
190 case FWL_VKEY_Right:
191 m_pEdit->OnVK_RIGHT(IsSHIFTpressed(nFlag), FALSE);
192 return TRUE;
193 case FWL_VKEY_Home:
194 m_pEdit->OnVK_HOME(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
195 return TRUE;
196 case FWL_VKEY_End:
197 m_pEdit->OnVK_END(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
198 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();
204 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
tsepezc3255f52016-03-25 14:52:27 -0700212FX_BOOL CPWL_EditCtrl::OnChar(uint16_t nChar, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700213 if (m_bMouseDown)
Tom Sepez2f2ffec2015-07-23 14:42:09 -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:
222 return FALSE;
223 default:
224 break;
225 }
226
227 FX_BOOL bCtrl = IsCTRLpressed(nFlag);
228 FX_BOOL bAlt = IsALTpressed(nFlag);
229 FX_BOOL bShift = IsSHIFTpressed(nFlag);
230
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();
237 return TRUE;
238 case 'V' - 'A' + 1:
239 PasteText();
240 return TRUE;
241 case 'X' - 'A' + 1:
242 CutText();
243 return TRUE;
244 case 'A' - 'A' + 1:
245 SelectAll();
246 return TRUE;
247 case 'Z' - 'A' + 1:
248 if (bShift)
249 Redo();
250 else
251 Undo();
252 return TRUE;
253 default:
254 if (nChar < 32)
255 return FALSE;
256 }
257 }
258
259 if (IsReadOnly())
260 return TRUE;
261
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
281 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700282}
283
Tom Sepez281a9ea2016-02-26 14:24:28 -0800284FX_BOOL CPWL_EditCtrl::OnLButtonDown(const CFX_FloatPoint& point,
tsepezc3255f52016-03-25 14:52:27 -0700285 uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700286 CPWL_Wnd::OnLButtonDown(point, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700287
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700288 if (ClientHitTest(point)) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700289 if (m_bMouseDown)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700290 InvalidateRect();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700291
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700292 m_bMouseDown = TRUE;
293 SetCapture();
294
295 m_pEdit->OnMouseDown(point, IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
296 }
297
298 return TRUE;
299}
300
Tom Sepez281a9ea2016-02-26 14:24:28 -0800301FX_BOOL CPWL_EditCtrl::OnLButtonUp(const CFX_FloatPoint& point,
tsepezc3255f52016-03-25 14:52:27 -0700302 uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700303 CPWL_Wnd::OnLButtonUp(point, nFlag);
304
305 if (m_bMouseDown) {
306 // can receive keybord message
307 if (ClientHitTest(point) && !IsFocused())
308 SetFocus();
309
310 ReleaseCapture();
311 m_bMouseDown = FALSE;
312 }
313
314 return TRUE;
315}
316
Tom Sepez281a9ea2016-02-26 14:24:28 -0800317FX_BOOL CPWL_EditCtrl::OnMouseMove(const CFX_FloatPoint& point,
tsepezc3255f52016-03-25 14:52:27 -0700318 uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700319 CPWL_Wnd::OnMouseMove(point, nFlag);
320
321 if (m_bMouseDown)
322 m_pEdit->OnMouseMove(point, FALSE, FALSE);
323
324 return TRUE;
325}
326
Tom Sepez281a9ea2016-02-26 14:24:28 -0800327CFX_FloatRect CPWL_EditCtrl::GetContentRect() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700328 return m_pEdit->GetContentRect();
329}
330
331void CPWL_EditCtrl::SetEditCaret(FX_BOOL bVisible) {
tsepez63f545c2016-09-13 16:08:49 -0700332 CFX_FloatPoint ptHead;
333 CFX_FloatPoint ptFoot;
334 if (bVisible)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700335 GetCaretInfo(ptHead, ptFoot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700336
337 CPVT_WordPlace wpTemp = m_pEdit->GetCaretWordPlace();
338 IOnSetCaret(bVisible, ptHead, ptFoot, wpTemp);
339}
340
Tom Sepez281a9ea2016-02-26 14:24:28 -0800341void CPWL_EditCtrl::GetCaretInfo(CFX_FloatPoint& ptHead,
342 CFX_FloatPoint& ptFoot) const {
dsinclaire35af1e2016-07-13 11:26:20 -0700343 CFX_Edit_Iterator* pIterator = m_pEdit->GetIterator();
thestig821d59e2016-05-11 12:59:22 -0700344 pIterator->SetAt(m_pEdit->GetCaret());
345 CPVT_Word word;
346 CPVT_Line line;
347 if (pIterator->GetWord(word)) {
348 ptHead.x = word.ptWord.x + word.fWidth;
349 ptHead.y = word.ptWord.y + word.fAscent;
350 ptFoot.x = word.ptWord.x + word.fWidth;
351 ptFoot.y = word.ptWord.y + word.fDescent;
352 } else if (pIterator->GetLine(line)) {
353 ptHead.x = line.ptLine.x;
354 ptHead.y = line.ptLine.y + line.fLineAscent;
355 ptFoot.x = line.ptLine.x;
356 ptFoot.y = line.ptLine.y + line.fLineDescent;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700357 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700358}
359
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700360void CPWL_EditCtrl::GetCaretPos(int32_t& x, int32_t& y) const {
tsepez63f545c2016-09-13 16:08:49 -0700361 CFX_FloatPoint ptHead;
362 CFX_FloatPoint ptFoot;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700363 GetCaretInfo(ptHead, ptFoot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700364 PWLtoWnd(ptHead, x, y);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700365}
366
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700367void CPWL_EditCtrl::SetCaret(FX_BOOL bVisible,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800368 const CFX_FloatPoint& ptHead,
369 const CFX_FloatPoint& ptFoot) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700370 if (m_pEditCaret) {
371 if (!IsFocused() || m_pEdit->IsSelected())
372 bVisible = FALSE;
373
374 m_pEditCaret->SetCaret(bVisible, ptHead, ptFoot);
375 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700376}
377
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700378CFX_WideString CPWL_EditCtrl::GetText() const {
379 return m_pEdit->GetText();
380}
381
382void CPWL_EditCtrl::SetSel(int32_t nStartChar, int32_t nEndChar) {
383 m_pEdit->SetSel(nStartChar, nEndChar);
384}
385
386void CPWL_EditCtrl::GetSel(int32_t& nStartChar, int32_t& nEndChar) const {
387 m_pEdit->GetSel(nStartChar, nEndChar);
388}
389
390void CPWL_EditCtrl::Clear() {
391 if (!IsReadOnly())
392 m_pEdit->Clear();
393}
394
395void CPWL_EditCtrl::SelectAll() {
396 m_pEdit->SelectAll();
397}
398
399void CPWL_EditCtrl::Paint() {
thestig732f6a02016-05-12 10:41:56 -0700400 m_pEdit->Paint();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700401}
402
403void CPWL_EditCtrl::EnableRefresh(FX_BOOL bRefresh) {
thestig732f6a02016-05-12 10:41:56 -0700404 m_pEdit->EnableRefresh(bRefresh);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700405}
406
407int32_t CPWL_EditCtrl::GetCaret() const {
thestig732f6a02016-05-12 10:41:56 -0700408 return m_pEdit->GetCaret();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700409}
410
411void CPWL_EditCtrl::SetCaret(int32_t nPos) {
thestig732f6a02016-05-12 10:41:56 -0700412 m_pEdit->SetCaret(nPos);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700413}
414
415int32_t CPWL_EditCtrl::GetTotalWords() const {
thestig732f6a02016-05-12 10:41:56 -0700416 return m_pEdit->GetTotalWords();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700417}
418
Tom Sepez281a9ea2016-02-26 14:24:28 -0800419void CPWL_EditCtrl::SetScrollPos(const CFX_FloatPoint& point) {
thestig732f6a02016-05-12 10:41:56 -0700420 m_pEdit->SetScrollPos(point);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700421}
422
Tom Sepez281a9ea2016-02-26 14:24:28 -0800423CFX_FloatPoint CPWL_EditCtrl::GetScrollPos() const {
thestig732f6a02016-05-12 10:41:56 -0700424 return m_pEdit->GetScrollPos();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700425}
426
427CPDF_Font* CPWL_EditCtrl::GetCaretFont() const {
428 int32_t nFontIndex = 0;
429
dsinclaire35af1e2016-07-13 11:26:20 -0700430 CFX_Edit_Iterator* pIterator = m_pEdit->GetIterator();
thestig821d59e2016-05-11 12:59:22 -0700431 pIterator->SetAt(m_pEdit->GetCaret());
432 CPVT_Word word;
433 CPVT_Section section;
434 if (pIterator->GetWord(word)) {
435 nFontIndex = word.nFontIndex;
436 } else if (HasFlag(PES_RICH)) {
437 if (pIterator->GetSection(section)) {
438 nFontIndex = section.WordProps.nFontIndex;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700439 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700440 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700441
dsinclairc7a73492016-04-05 12:01:42 -0700442 if (IPVT_FontMap* pFontMap = GetFontMap())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700443 return pFontMap->GetPDFFont(nFontIndex);
444
thestig1cd352e2016-06-07 17:53:06 -0700445 return nullptr;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700446}
447
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700448FX_FLOAT CPWL_EditCtrl::GetCaretFontSize() const {
449 FX_FLOAT fFontSize = GetFontSize();
450
dsinclaire35af1e2016-07-13 11:26:20 -0700451 CFX_Edit_Iterator* pIterator = m_pEdit->GetIterator();
thestig821d59e2016-05-11 12:59:22 -0700452 pIterator->SetAt(m_pEdit->GetCaret());
453 CPVT_Word word;
454 CPVT_Section section;
455 if (pIterator->GetWord(word)) {
456 fFontSize = word.fFontSize;
457 } else if (HasFlag(PES_RICH)) {
458 if (pIterator->GetSection(section)) {
459 fFontSize = section.WordProps.fFontSize;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700460 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700461 }
462
463 return fFontSize;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700464}
465
tsepez067990c2016-09-13 06:46:40 -0700466void CPWL_EditCtrl::SetText(const CFX_WideString& wsText) {
467 m_pEdit->SetText(wsText);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700468}
469
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700470void CPWL_EditCtrl::CopyText() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700471
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700472void CPWL_EditCtrl::PasteText() {}
473
474void CPWL_EditCtrl::CutText() {}
475
476void CPWL_EditCtrl::ShowVScrollBar(FX_BOOL bShow) {}
477
tsepez067990c2016-09-13 06:46:40 -0700478void CPWL_EditCtrl::InsertText(const CFX_WideString& wsText) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700479 if (!IsReadOnly())
npmea3c3be2016-09-19 07:24:33 -0700480 m_pEdit->InsertText(wsText, FXFONT_DEFAULT_CHARSET);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700481}
482
Tom Sepez62a70f92016-03-21 15:00:20 -0700483void CPWL_EditCtrl::InsertWord(uint16_t word, int32_t nCharset) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700484 if (!IsReadOnly())
485 m_pEdit->InsertWord(word, nCharset);
486}
487
488void CPWL_EditCtrl::InsertReturn() {
489 if (!IsReadOnly())
490 m_pEdit->InsertReturn();
491}
492
493void CPWL_EditCtrl::Delete() {
494 if (!IsReadOnly())
495 m_pEdit->Delete();
496}
497
498void CPWL_EditCtrl::Backspace() {
499 if (!IsReadOnly())
500 m_pEdit->Backspace();
501}
502
503FX_BOOL CPWL_EditCtrl::CanUndo() const {
504 return !IsReadOnly() && m_pEdit->CanUndo();
505}
506
507FX_BOOL CPWL_EditCtrl::CanRedo() const {
508 return !IsReadOnly() && m_pEdit->CanRedo();
509}
510
511void CPWL_EditCtrl::Redo() {
512 if (CanRedo())
513 m_pEdit->Redo();
514}
515
516void CPWL_EditCtrl::Undo() {
517 if (CanUndo())
518 m_pEdit->Undo();
519}
520
521void CPWL_EditCtrl::IOnSetScrollInfoY(FX_FLOAT fPlateMin,
522 FX_FLOAT fPlateMax,
523 FX_FLOAT fContentMin,
524 FX_FLOAT fContentMax,
525 FX_FLOAT fSmallStep,
526 FX_FLOAT fBigStep) {
527 PWL_SCROLL_INFO Info;
528
529 Info.fPlateWidth = fPlateMax - fPlateMin;
530 Info.fContentMin = fContentMin;
531 Info.fContentMax = fContentMax;
532 Info.fSmallStep = fSmallStep;
533 Info.fBigStep = fBigStep;
534
535 OnNotify(this, PNM_SETSCROLLINFO, SBT_VSCROLL, (intptr_t)&Info);
536
537 if (IsFloatBigger(Info.fPlateWidth, Info.fContentMax - Info.fContentMin) ||
538 IsFloatEqual(Info.fPlateWidth, Info.fContentMax - Info.fContentMin)) {
539 ShowVScrollBar(FALSE);
540 } else {
541 ShowVScrollBar(TRUE);
542 }
543}
544
545void CPWL_EditCtrl::IOnSetScrollPosY(FX_FLOAT fy) {
546 OnNotify(this, PNM_SETSCROLLPOS, SBT_VSCROLL, (intptr_t)&fy);
547}
548
549void CPWL_EditCtrl::IOnSetCaret(FX_BOOL bVisible,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800550 const CFX_FloatPoint& ptHead,
551 const CFX_FloatPoint& ptFoot,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700552 const CPVT_WordPlace& place) {
553 PWL_CARET_INFO cInfo;
554 cInfo.bVisible = bVisible;
555 cInfo.ptHead = ptHead;
556 cInfo.ptFoot = ptFoot;
557
thestig1cd352e2016-06-07 17:53:06 -0700558 OnNotify(this, PNM_SETCARETINFO, (intptr_t)&cInfo, (intptr_t) nullptr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700559}
560
dsinclairdbc77162016-07-13 11:34:23 -0700561void CPWL_EditCtrl::IOnCaretChange(const CPVT_SecProps& secProps,
562 const CPVT_WordProps& wordProps) {}
563
564void CPWL_EditCtrl::IOnContentChange(const CFX_FloatRect& rcContent) {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700565
Tom Sepez281a9ea2016-02-26 14:24:28 -0800566void CPWL_EditCtrl::IOnInvalidateRect(CFX_FloatRect* pRect) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700567 InvalidateRect(pRect);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700568}
569
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700570int32_t CPWL_EditCtrl::GetCharSet() const {
npmea3c3be2016-09-19 07:24:33 -0700571 return m_nCharSet < 0 ? FXFONT_DEFAULT_CHARSET : m_nCharSet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700572}
573
Tom Sepez281a9ea2016-02-26 14:24:28 -0800574void CPWL_EditCtrl::GetTextRange(const CFX_FloatRect& rect,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700575 int32_t& nStartChar,
576 int32_t& nEndChar) const {
577 nStartChar = m_pEdit->WordPlaceToWordIndex(
Tom Sepez281a9ea2016-02-26 14:24:28 -0800578 m_pEdit->SearchWordPlace(CFX_FloatPoint(rect.left, rect.top)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700579 nEndChar = m_pEdit->WordPlaceToWordIndex(
Tom Sepez281a9ea2016-02-26 14:24:28 -0800580 m_pEdit->SearchWordPlace(CFX_FloatPoint(rect.right, rect.bottom)));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700581}
582
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700583CFX_WideString CPWL_EditCtrl::GetText(int32_t& nStartChar,
584 int32_t& nEndChar) const {
585 CPVT_WordPlace wpStart = m_pEdit->WordIndexToWordPlace(nStartChar);
586 CPVT_WordPlace wpEnd = m_pEdit->WordIndexToWordPlace(nEndChar);
587 return m_pEdit->GetRangeText(CPVT_WordRange(wpStart, wpEnd));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700588}
589
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700590void CPWL_EditCtrl::SetReadyToInput() {
591 if (m_bMouseDown) {
592 ReleaseCapture();
593 m_bMouseDown = FALSE;
594 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700595}