blob: 64272e34c511af9af6951deed759e8d7c87d7e2e [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();
Dan Sinclairf528eee2017-02-14 11:52:07 -050043 CFX_PointF point1(0, 1);
44 CFX_PointF 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:
Dan Sinclairf528eee2017-02-14 11:52:07 -050096 m_pEdit->SetScrollPos(CFX_PointF(m_pEdit->GetScrollPos().x, fPos));
Nico Weber9d8ec5a2015-08-04 13:00:21 -070097 break;
98 }
99 } break;
100 case PNM_SETCARETINFO: {
101 if (PWL_CARET_INFO* pCaretInfo = (PWL_CARET_INFO*)wParam) {
102 SetCaret(pCaretInfo->bVisible, pCaretInfo->ptHead, pCaretInfo->ptFoot);
103 }
104 } break;
105 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700106}
107
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700108void CPWL_EditCtrl::CreateChildWnd(const PWL_CREATEPARAM& cp) {
109 if (!IsReadOnly())
110 CreateEditCaret(cp);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700111}
112
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700113void CPWL_EditCtrl::CreateEditCaret(const PWL_CREATEPARAM& cp) {
thestig732f6a02016-05-12 10:41:56 -0700114 if (m_pEditCaret)
115 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700116
thestig732f6a02016-05-12 10:41:56 -0700117 m_pEditCaret = new CPWL_Caret;
118 m_pEditCaret->SetInvalidRect(GetClientRect());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700119
thestig732f6a02016-05-12 10:41:56 -0700120 PWL_CREATEPARAM ecp = cp;
121 ecp.pParentWnd = this;
122 ecp.dwFlags = PWS_CHILD | PWS_NOREFRESHCLIP;
123 ecp.dwBorderWidth = 0;
dsinclair92cb5e52016-05-16 11:38:28 -0700124 ecp.nBorderStyle = BorderStyle::SOLID;
thestig732f6a02016-05-12 10:41:56 -0700125 ecp.rcRectWnd = CFX_FloatRect(0, 0, 0, 0);
126
127 m_pEditCaret->Create(ecp);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700128}
129
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700130void CPWL_EditCtrl::SetFontSize(FX_FLOAT fFontSize) {
131 m_pEdit->SetFontSize(fFontSize);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700132}
133
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700134FX_FLOAT CPWL_EditCtrl::GetFontSize() const {
135 return m_pEdit->GetFontSize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700136}
137
tsepez4cf55152016-11-02 14:37:54 -0700138bool CPWL_EditCtrl::OnKeyDown(uint16_t nChar, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700139 if (m_bMouseDown)
tsepez4cf55152016-11-02 14:37:54 -0700140 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700141
tsepez4cf55152016-11-02 14:37:54 -0700142 bool bRet = CPWL_Wnd::OnKeyDown(nChar, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700143
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700144 // FILTER
145 switch (nChar) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700146 default:
tsepez4cf55152016-11-02 14:37:54 -0700147 return false;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700148 case FWL_VKEY_Delete:
149 case FWL_VKEY_Up:
150 case FWL_VKEY_Down:
151 case FWL_VKEY_Left:
152 case FWL_VKEY_Right:
153 case FWL_VKEY_Home:
154 case FWL_VKEY_End:
155 case FWL_VKEY_Insert:
156 case 'C':
157 case 'V':
158 case 'X':
159 case 'A':
160 case 'Z':
161 case 'c':
162 case 'v':
163 case 'x':
164 case 'a':
165 case 'z':
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700166 break;
167 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700168
thestig594b20b2016-05-12 21:56:43 -0700169 if (nChar == FWL_VKEY_Delete && m_pEdit->IsSelected())
170 nChar = FWL_VKEY_Unknown;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700171
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700172 switch (nChar) {
173 case FWL_VKEY_Delete:
174 Delete();
tsepez4cf55152016-11-02 14:37:54 -0700175 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700176 case FWL_VKEY_Insert:
177 if (IsSHIFTpressed(nFlag))
178 PasteText();
tsepez4cf55152016-11-02 14:37:54 -0700179 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700180 case FWL_VKEY_Up:
tsepez4cf55152016-11-02 14:37:54 -0700181 m_pEdit->OnVK_UP(IsSHIFTpressed(nFlag), false);
182 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700183 case FWL_VKEY_Down:
tsepez4cf55152016-11-02 14:37:54 -0700184 m_pEdit->OnVK_DOWN(IsSHIFTpressed(nFlag), false);
185 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700186 case FWL_VKEY_Left:
tsepez4cf55152016-11-02 14:37:54 -0700187 m_pEdit->OnVK_LEFT(IsSHIFTpressed(nFlag), false);
188 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700189 case FWL_VKEY_Right:
tsepez4cf55152016-11-02 14:37:54 -0700190 m_pEdit->OnVK_RIGHT(IsSHIFTpressed(nFlag), false);
191 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700192 case FWL_VKEY_Home:
193 m_pEdit->OnVK_HOME(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
tsepez4cf55152016-11-02 14:37:54 -0700194 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700195 case FWL_VKEY_End:
196 m_pEdit->OnVK_END(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
tsepez4cf55152016-11-02 14:37:54 -0700197 return true;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700198 case FWL_VKEY_Unknown:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700199 if (!IsSHIFTpressed(nFlag))
200 Clear();
201 else
202 CutText();
tsepez4cf55152016-11-02 14:37:54 -0700203 return true;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700204 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700205 break;
206 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700207
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700208 return bRet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700209}
210
tsepez4cf55152016-11-02 14:37:54 -0700211bool CPWL_EditCtrl::OnChar(uint16_t nChar, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700212 if (m_bMouseDown)
tsepez4cf55152016-11-02 14:37:54 -0700213 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700214
215 CPWL_Wnd::OnChar(nChar, nFlag);
216
217 // FILTER
218 switch (nChar) {
219 case 0x0A:
220 case 0x1B:
tsepez4cf55152016-11-02 14:37:54 -0700221 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700222 default:
223 break;
224 }
225
tsepez4cf55152016-11-02 14:37:54 -0700226 bool bCtrl = IsCTRLpressed(nFlag);
227 bool bAlt = IsALTpressed(nFlag);
228 bool bShift = IsSHIFTpressed(nFlag);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700229
Tom Sepez62a70f92016-03-21 15:00:20 -0700230 uint16_t word = nChar;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700231
232 if (bCtrl && !bAlt) {
233 switch (nChar) {
234 case 'C' - 'A' + 1:
235 CopyText();
tsepez4cf55152016-11-02 14:37:54 -0700236 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700237 case 'V' - 'A' + 1:
238 PasteText();
tsepez4cf55152016-11-02 14:37:54 -0700239 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700240 case 'X' - 'A' + 1:
241 CutText();
tsepez4cf55152016-11-02 14:37:54 -0700242 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700243 case 'A' - 'A' + 1:
244 SelectAll();
tsepez4cf55152016-11-02 14:37:54 -0700245 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700246 case 'Z' - 'A' + 1:
247 if (bShift)
248 Redo();
249 else
250 Undo();
tsepez4cf55152016-11-02 14:37:54 -0700251 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700252 default:
253 if (nChar < 32)
tsepez4cf55152016-11-02 14:37:54 -0700254 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700255 }
256 }
257
258 if (IsReadOnly())
tsepez4cf55152016-11-02 14:37:54 -0700259 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700260
261 if (m_pEdit->IsSelected() && word == FWL_VKEY_Back)
262 word = FWL_VKEY_Unknown;
263
264 Clear();
265
266 switch (word) {
267 case FWL_VKEY_Back:
268 Backspace();
269 break;
270 case FWL_VKEY_Return:
271 InsertReturn();
272 break;
273 case FWL_VKEY_Unknown:
274 break;
275 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700276 InsertWord(word, GetCharSet());
277 break;
278 }
279
tsepez4cf55152016-11-02 14:37:54 -0700280 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700281}
282
Dan Sinclairf528eee2017-02-14 11:52:07 -0500283bool CPWL_EditCtrl::OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700284 CPWL_Wnd::OnLButtonDown(point, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700285
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700286 if (ClientHitTest(point)) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700287 if (m_bMouseDown)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700288 InvalidateRect();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700289
tsepez4cf55152016-11-02 14:37:54 -0700290 m_bMouseDown = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700291 SetCapture();
292
293 m_pEdit->OnMouseDown(point, IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
294 }
295
tsepez4cf55152016-11-02 14:37:54 -0700296 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700297}
298
Dan Sinclairf528eee2017-02-14 11:52:07 -0500299bool CPWL_EditCtrl::OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700300 CPWL_Wnd::OnLButtonUp(point, nFlag);
301
302 if (m_bMouseDown) {
303 // can receive keybord message
304 if (ClientHitTest(point) && !IsFocused())
305 SetFocus();
306
307 ReleaseCapture();
tsepez4cf55152016-11-02 14:37:54 -0700308 m_bMouseDown = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700309 }
310
tsepez4cf55152016-11-02 14:37:54 -0700311 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700312}
313
Dan Sinclairf528eee2017-02-14 11:52:07 -0500314bool CPWL_EditCtrl::OnMouseMove(const CFX_PointF& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700315 CPWL_Wnd::OnMouseMove(point, nFlag);
316
317 if (m_bMouseDown)
tsepez4cf55152016-11-02 14:37:54 -0700318 m_pEdit->OnMouseMove(point, false, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700319
tsepez4cf55152016-11-02 14:37:54 -0700320 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700321}
322
Tom Sepez281a9ea2016-02-26 14:24:28 -0800323CFX_FloatRect CPWL_EditCtrl::GetContentRect() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700324 return m_pEdit->GetContentRect();
325}
326
tsepez4cf55152016-11-02 14:37:54 -0700327void CPWL_EditCtrl::SetEditCaret(bool bVisible) {
Dan Sinclairf528eee2017-02-14 11:52:07 -0500328 CFX_PointF ptHead;
329 CFX_PointF ptFoot;
tsepez63f545c2016-09-13 16:08:49 -0700330 if (bVisible)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700331 GetCaretInfo(ptHead, ptFoot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700332
333 CPVT_WordPlace wpTemp = m_pEdit->GetCaretWordPlace();
334 IOnSetCaret(bVisible, ptHead, ptFoot, wpTemp);
335}
336
Dan Sinclairf528eee2017-02-14 11:52:07 -0500337void CPWL_EditCtrl::GetCaretInfo(CFX_PointF& ptHead, CFX_PointF& ptFoot) const {
dsinclaire35af1e2016-07-13 11:26:20 -0700338 CFX_Edit_Iterator* pIterator = m_pEdit->GetIterator();
thestig821d59e2016-05-11 12:59:22 -0700339 pIterator->SetAt(m_pEdit->GetCaret());
340 CPVT_Word word;
341 CPVT_Line line;
342 if (pIterator->GetWord(word)) {
343 ptHead.x = word.ptWord.x + word.fWidth;
344 ptHead.y = word.ptWord.y + word.fAscent;
345 ptFoot.x = word.ptWord.x + word.fWidth;
346 ptFoot.y = word.ptWord.y + word.fDescent;
347 } else if (pIterator->GetLine(line)) {
348 ptHead.x = line.ptLine.x;
349 ptHead.y = line.ptLine.y + line.fLineAscent;
350 ptFoot.x = line.ptLine.x;
351 ptFoot.y = line.ptLine.y + line.fLineDescent;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700352 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700353}
354
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700355void CPWL_EditCtrl::GetCaretPos(int32_t& x, int32_t& y) const {
Dan Sinclairf528eee2017-02-14 11:52:07 -0500356 CFX_PointF ptHead;
357 CFX_PointF ptFoot;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700358 GetCaretInfo(ptHead, ptFoot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700359 PWLtoWnd(ptHead, x, y);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700360}
361
tsepez4cf55152016-11-02 14:37:54 -0700362void CPWL_EditCtrl::SetCaret(bool bVisible,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500363 const CFX_PointF& ptHead,
364 const CFX_PointF& ptFoot) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700365 if (m_pEditCaret) {
366 if (!IsFocused() || m_pEdit->IsSelected())
tsepez4cf55152016-11-02 14:37:54 -0700367 bVisible = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700368
369 m_pEditCaret->SetCaret(bVisible, ptHead, ptFoot);
370 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700371}
372
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700373CFX_WideString CPWL_EditCtrl::GetText() const {
374 return m_pEdit->GetText();
375}
376
377void CPWL_EditCtrl::SetSel(int32_t nStartChar, int32_t nEndChar) {
378 m_pEdit->SetSel(nStartChar, nEndChar);
379}
380
381void CPWL_EditCtrl::GetSel(int32_t& nStartChar, int32_t& nEndChar) const {
382 m_pEdit->GetSel(nStartChar, nEndChar);
383}
384
385void CPWL_EditCtrl::Clear() {
386 if (!IsReadOnly())
387 m_pEdit->Clear();
388}
389
390void CPWL_EditCtrl::SelectAll() {
391 m_pEdit->SelectAll();
392}
393
394void CPWL_EditCtrl::Paint() {
thestig732f6a02016-05-12 10:41:56 -0700395 m_pEdit->Paint();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700396}
397
tsepez4cf55152016-11-02 14:37:54 -0700398void CPWL_EditCtrl::EnableRefresh(bool bRefresh) {
thestig732f6a02016-05-12 10:41:56 -0700399 m_pEdit->EnableRefresh(bRefresh);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700400}
401
402int32_t CPWL_EditCtrl::GetCaret() const {
thestig732f6a02016-05-12 10:41:56 -0700403 return m_pEdit->GetCaret();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700404}
405
406void CPWL_EditCtrl::SetCaret(int32_t nPos) {
thestig732f6a02016-05-12 10:41:56 -0700407 m_pEdit->SetCaret(nPos);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700408}
409
410int32_t CPWL_EditCtrl::GetTotalWords() const {
thestig732f6a02016-05-12 10:41:56 -0700411 return m_pEdit->GetTotalWords();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700412}
413
Dan Sinclairf528eee2017-02-14 11:52:07 -0500414void CPWL_EditCtrl::SetScrollPos(const CFX_PointF& point) {
thestig732f6a02016-05-12 10:41:56 -0700415 m_pEdit->SetScrollPos(point);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700416}
417
Dan Sinclairf528eee2017-02-14 11:52:07 -0500418CFX_PointF CPWL_EditCtrl::GetScrollPos() const {
thestig732f6a02016-05-12 10:41:56 -0700419 return m_pEdit->GetScrollPos();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700420}
421
422CPDF_Font* CPWL_EditCtrl::GetCaretFont() const {
423 int32_t nFontIndex = 0;
424
dsinclaire35af1e2016-07-13 11:26:20 -0700425 CFX_Edit_Iterator* pIterator = m_pEdit->GetIterator();
thestig821d59e2016-05-11 12:59:22 -0700426 pIterator->SetAt(m_pEdit->GetCaret());
427 CPVT_Word word;
428 CPVT_Section section;
429 if (pIterator->GetWord(word)) {
430 nFontIndex = word.nFontIndex;
431 } else if (HasFlag(PES_RICH)) {
432 if (pIterator->GetSection(section)) {
433 nFontIndex = section.WordProps.nFontIndex;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700434 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700435 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700436
dsinclairc7a73492016-04-05 12:01:42 -0700437 if (IPVT_FontMap* pFontMap = GetFontMap())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700438 return pFontMap->GetPDFFont(nFontIndex);
439
thestig1cd352e2016-06-07 17:53:06 -0700440 return nullptr;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700441}
442
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700443FX_FLOAT CPWL_EditCtrl::GetCaretFontSize() const {
444 FX_FLOAT fFontSize = GetFontSize();
445
dsinclaire35af1e2016-07-13 11:26:20 -0700446 CFX_Edit_Iterator* pIterator = m_pEdit->GetIterator();
thestig821d59e2016-05-11 12:59:22 -0700447 pIterator->SetAt(m_pEdit->GetCaret());
448 CPVT_Word word;
449 CPVT_Section section;
450 if (pIterator->GetWord(word)) {
451 fFontSize = word.fFontSize;
452 } else if (HasFlag(PES_RICH)) {
453 if (pIterator->GetSection(section)) {
454 fFontSize = section.WordProps.fFontSize;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700455 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700456 }
457
458 return fFontSize;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700459}
460
tsepez067990c2016-09-13 06:46:40 -0700461void CPWL_EditCtrl::SetText(const CFX_WideString& wsText) {
462 m_pEdit->SetText(wsText);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700463}
464
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700465void CPWL_EditCtrl::CopyText() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700466
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700467void CPWL_EditCtrl::PasteText() {}
468
469void CPWL_EditCtrl::CutText() {}
470
tsepez4cf55152016-11-02 14:37:54 -0700471void CPWL_EditCtrl::ShowVScrollBar(bool bShow) {}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700472
tsepez067990c2016-09-13 06:46:40 -0700473void CPWL_EditCtrl::InsertText(const CFX_WideString& wsText) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700474 if (!IsReadOnly())
npmea3c3be2016-09-19 07:24:33 -0700475 m_pEdit->InsertText(wsText, FXFONT_DEFAULT_CHARSET);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700476}
477
Tom Sepez62a70f92016-03-21 15:00:20 -0700478void CPWL_EditCtrl::InsertWord(uint16_t word, int32_t nCharset) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700479 if (!IsReadOnly())
480 m_pEdit->InsertWord(word, nCharset);
481}
482
483void CPWL_EditCtrl::InsertReturn() {
484 if (!IsReadOnly())
485 m_pEdit->InsertReturn();
486}
487
488void CPWL_EditCtrl::Delete() {
489 if (!IsReadOnly())
490 m_pEdit->Delete();
491}
492
493void CPWL_EditCtrl::Backspace() {
494 if (!IsReadOnly())
495 m_pEdit->Backspace();
496}
497
tsepez4cf55152016-11-02 14:37:54 -0700498bool CPWL_EditCtrl::CanUndo() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700499 return !IsReadOnly() && m_pEdit->CanUndo();
500}
501
tsepez4cf55152016-11-02 14:37:54 -0700502bool CPWL_EditCtrl::CanRedo() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700503 return !IsReadOnly() && m_pEdit->CanRedo();
504}
505
506void CPWL_EditCtrl::Redo() {
507 if (CanRedo())
508 m_pEdit->Redo();
509}
510
511void CPWL_EditCtrl::Undo() {
512 if (CanUndo())
513 m_pEdit->Undo();
514}
515
516void CPWL_EditCtrl::IOnSetScrollInfoY(FX_FLOAT fPlateMin,
517 FX_FLOAT fPlateMax,
518 FX_FLOAT fContentMin,
519 FX_FLOAT fContentMax,
520 FX_FLOAT fSmallStep,
521 FX_FLOAT fBigStep) {
522 PWL_SCROLL_INFO Info;
523
524 Info.fPlateWidth = fPlateMax - fPlateMin;
525 Info.fContentMin = fContentMin;
526 Info.fContentMax = fContentMax;
527 Info.fSmallStep = fSmallStep;
528 Info.fBigStep = fBigStep;
529
530 OnNotify(this, PNM_SETSCROLLINFO, SBT_VSCROLL, (intptr_t)&Info);
531
532 if (IsFloatBigger(Info.fPlateWidth, Info.fContentMax - Info.fContentMin) ||
533 IsFloatEqual(Info.fPlateWidth, Info.fContentMax - Info.fContentMin)) {
tsepez4cf55152016-11-02 14:37:54 -0700534 ShowVScrollBar(false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700535 } else {
tsepez4cf55152016-11-02 14:37:54 -0700536 ShowVScrollBar(true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700537 }
538}
539
540void CPWL_EditCtrl::IOnSetScrollPosY(FX_FLOAT fy) {
541 OnNotify(this, PNM_SETSCROLLPOS, SBT_VSCROLL, (intptr_t)&fy);
542}
543
tsepez4cf55152016-11-02 14:37:54 -0700544void CPWL_EditCtrl::IOnSetCaret(bool bVisible,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500545 const CFX_PointF& ptHead,
546 const CFX_PointF& ptFoot,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700547 const CPVT_WordPlace& place) {
548 PWL_CARET_INFO cInfo;
549 cInfo.bVisible = bVisible;
550 cInfo.ptHead = ptHead;
551 cInfo.ptFoot = ptFoot;
552
thestig1cd352e2016-06-07 17:53:06 -0700553 OnNotify(this, PNM_SETCARETINFO, (intptr_t)&cInfo, (intptr_t) nullptr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700554}
555
dsinclairdbc77162016-07-13 11:34:23 -0700556void CPWL_EditCtrl::IOnCaretChange(const CPVT_SecProps& secProps,
557 const CPVT_WordProps& wordProps) {}
558
559void CPWL_EditCtrl::IOnContentChange(const CFX_FloatRect& rcContent) {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700560
Tom Sepez281a9ea2016-02-26 14:24:28 -0800561void CPWL_EditCtrl::IOnInvalidateRect(CFX_FloatRect* pRect) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700562 InvalidateRect(pRect);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700563}
564
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700565int32_t CPWL_EditCtrl::GetCharSet() const {
npmea3c3be2016-09-19 07:24:33 -0700566 return m_nCharSet < 0 ? FXFONT_DEFAULT_CHARSET : m_nCharSet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700567}
568
Tom Sepez281a9ea2016-02-26 14:24:28 -0800569void CPWL_EditCtrl::GetTextRange(const CFX_FloatRect& rect,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700570 int32_t& nStartChar,
571 int32_t& nEndChar) const {
572 nStartChar = m_pEdit->WordPlaceToWordIndex(
Dan Sinclairf528eee2017-02-14 11:52:07 -0500573 m_pEdit->SearchWordPlace(CFX_PointF(rect.left, rect.top)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700574 nEndChar = m_pEdit->WordPlaceToWordIndex(
Dan Sinclairf528eee2017-02-14 11:52:07 -0500575 m_pEdit->SearchWordPlace(CFX_PointF(rect.right, rect.bottom)));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700576}
577
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700578CFX_WideString CPWL_EditCtrl::GetText(int32_t& nStartChar,
579 int32_t& nEndChar) const {
580 CPVT_WordPlace wpStart = m_pEdit->WordIndexToWordPlace(nStartChar);
581 CPVT_WordPlace wpEnd = m_pEdit->WordIndexToWordPlace(nEndChar);
582 return m_pEdit->GetRangeText(CPVT_WordRange(wpStart, wpEnd));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700583}
584
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700585void CPWL_EditCtrl::SetReadyToInput() {
586 if (m_bMouseDown) {
587 ReleaseCapture();
tsepez4cf55152016-11-02 14:37:54 -0700588 m_bMouseDown = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700589 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700590}