blob: e7371fd0e7e38d86261df1548b47198d48c721c1 [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 Sinclair1f403ce2017-02-21 12:56:24 -050043 return mt.Transform(CFX_PointF(1, 1)).y == mt.Transform(CFX_PointF(0, 1)).y;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070044}
45
Nico Weber9d8ec5a2015-08-04 13:00:21 -070046void CPWL_EditCtrl::SetCursor() {
47 if (IsValid()) {
dsinclairb9590102016-04-27 06:38:59 -070048 if (CFX_SystemHandler* pSH = GetSystemHandler()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070049 if (IsWndHorV())
50 pSH->SetCursor(FXCT_VBEAM);
51 else
52 pSH->SetCursor(FXCT_HBEAM);
Tom Sepez2f2ffec2015-07-23 14:42:09 -070053 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070054 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070055}
56
Nico Weber9d8ec5a2015-08-04 13:00:21 -070057void CPWL_EditCtrl::RePosChildWnd() {
58 m_pEdit->SetPlateRect(GetClientRect());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070059}
60
Nico Weber9d8ec5a2015-08-04 13:00:21 -070061void CPWL_EditCtrl::OnNotify(CPWL_Wnd* pWnd,
tsepezc3255f52016-03-25 14:52:27 -070062 uint32_t msg,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070063 intptr_t wParam,
64 intptr_t lParam) {
65 CPWL_Wnd::OnNotify(pWnd, msg, wParam, lParam);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070066
Nico Weber9d8ec5a2015-08-04 13:00:21 -070067 switch (msg) {
68 case PNM_SETSCROLLINFO:
69 switch (wParam) {
70 case SBT_VSCROLL:
71 if (CPWL_Wnd* pChild = GetVScrollBar()) {
72 pChild->OnNotify(pWnd, PNM_SETSCROLLINFO, wParam, lParam);
73 }
74 break;
75 }
76 break;
77 case PNM_SETSCROLLPOS:
78 switch (wParam) {
79 case SBT_VSCROLL:
80 if (CPWL_Wnd* pChild = GetVScrollBar()) {
81 pChild->OnNotify(pWnd, PNM_SETSCROLLPOS, wParam, lParam);
82 }
83 break;
84 }
85 break;
86 case PNM_SCROLLWINDOW: {
Dan Sinclair05df0752017-03-14 14:43:42 -040087 float fPos = *(float*)lParam;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070088 switch (wParam) {
89 case SBT_VSCROLL:
Dan Sinclairf528eee2017-02-14 11:52:07 -050090 m_pEdit->SetScrollPos(CFX_PointF(m_pEdit->GetScrollPos().x, fPos));
Nico Weber9d8ec5a2015-08-04 13:00:21 -070091 break;
92 }
93 } break;
94 case PNM_SETCARETINFO: {
95 if (PWL_CARET_INFO* pCaretInfo = (PWL_CARET_INFO*)wParam) {
96 SetCaret(pCaretInfo->bVisible, pCaretInfo->ptHead, pCaretInfo->ptFoot);
97 }
98 } break;
99 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700100}
101
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700102void CPWL_EditCtrl::CreateChildWnd(const PWL_CREATEPARAM& cp) {
103 if (!IsReadOnly())
104 CreateEditCaret(cp);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700105}
106
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700107void CPWL_EditCtrl::CreateEditCaret(const PWL_CREATEPARAM& cp) {
thestig732f6a02016-05-12 10:41:56 -0700108 if (m_pEditCaret)
109 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700110
thestig732f6a02016-05-12 10:41:56 -0700111 m_pEditCaret = new CPWL_Caret;
112 m_pEditCaret->SetInvalidRect(GetClientRect());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700113
thestig732f6a02016-05-12 10:41:56 -0700114 PWL_CREATEPARAM ecp = cp;
115 ecp.pParentWnd = this;
116 ecp.dwFlags = PWS_CHILD | PWS_NOREFRESHCLIP;
117 ecp.dwBorderWidth = 0;
dsinclair92cb5e52016-05-16 11:38:28 -0700118 ecp.nBorderStyle = BorderStyle::SOLID;
thestig732f6a02016-05-12 10:41:56 -0700119 ecp.rcRectWnd = CFX_FloatRect(0, 0, 0, 0);
120
121 m_pEditCaret->Create(ecp);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700122}
123
Dan Sinclair05df0752017-03-14 14:43:42 -0400124void CPWL_EditCtrl::SetFontSize(float fFontSize) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700125 m_pEdit->SetFontSize(fFontSize);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700126}
127
Dan Sinclair05df0752017-03-14 14:43:42 -0400128float CPWL_EditCtrl::GetFontSize() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700129 return m_pEdit->GetFontSize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700130}
131
tsepez4cf55152016-11-02 14:37:54 -0700132bool CPWL_EditCtrl::OnKeyDown(uint16_t nChar, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700133 if (m_bMouseDown)
tsepez4cf55152016-11-02 14:37:54 -0700134 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700135
tsepez4cf55152016-11-02 14:37:54 -0700136 bool bRet = CPWL_Wnd::OnKeyDown(nChar, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700137
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700138 // FILTER
139 switch (nChar) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700140 default:
tsepez4cf55152016-11-02 14:37:54 -0700141 return false;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700142 case FWL_VKEY_Delete:
143 case FWL_VKEY_Up:
144 case FWL_VKEY_Down:
145 case FWL_VKEY_Left:
146 case FWL_VKEY_Right:
147 case FWL_VKEY_Home:
148 case FWL_VKEY_End:
149 case FWL_VKEY_Insert:
150 case 'C':
151 case 'V':
152 case 'X':
153 case 'A':
154 case 'Z':
155 case 'c':
156 case 'v':
157 case 'x':
158 case 'a':
159 case 'z':
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700160 break;
161 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700162
thestig594b20b2016-05-12 21:56:43 -0700163 if (nChar == FWL_VKEY_Delete && m_pEdit->IsSelected())
164 nChar = FWL_VKEY_Unknown;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700165
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700166 switch (nChar) {
167 case FWL_VKEY_Delete:
168 Delete();
tsepez4cf55152016-11-02 14:37:54 -0700169 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700170 case FWL_VKEY_Insert:
171 if (IsSHIFTpressed(nFlag))
172 PasteText();
tsepez4cf55152016-11-02 14:37:54 -0700173 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700174 case FWL_VKEY_Up:
tsepez4cf55152016-11-02 14:37:54 -0700175 m_pEdit->OnVK_UP(IsSHIFTpressed(nFlag), false);
176 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700177 case FWL_VKEY_Down:
tsepez4cf55152016-11-02 14:37:54 -0700178 m_pEdit->OnVK_DOWN(IsSHIFTpressed(nFlag), false);
179 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700180 case FWL_VKEY_Left:
tsepez4cf55152016-11-02 14:37:54 -0700181 m_pEdit->OnVK_LEFT(IsSHIFTpressed(nFlag), false);
182 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700183 case FWL_VKEY_Right:
tsepez4cf55152016-11-02 14:37:54 -0700184 m_pEdit->OnVK_RIGHT(IsSHIFTpressed(nFlag), false);
185 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700186 case FWL_VKEY_Home:
187 m_pEdit->OnVK_HOME(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
tsepez4cf55152016-11-02 14:37:54 -0700188 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700189 case FWL_VKEY_End:
190 m_pEdit->OnVK_END(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
tsepez4cf55152016-11-02 14:37:54 -0700191 return true;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700192 case FWL_VKEY_Unknown:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700193 if (!IsSHIFTpressed(nFlag))
194 Clear();
195 else
196 CutText();
tsepez4cf55152016-11-02 14:37:54 -0700197 return true;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700198 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700199 break;
200 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700201
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700202 return bRet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700203}
204
tsepez4cf55152016-11-02 14:37:54 -0700205bool CPWL_EditCtrl::OnChar(uint16_t nChar, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700206 if (m_bMouseDown)
tsepez4cf55152016-11-02 14:37:54 -0700207 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700208
209 CPWL_Wnd::OnChar(nChar, nFlag);
210
211 // FILTER
212 switch (nChar) {
213 case 0x0A:
214 case 0x1B:
tsepez4cf55152016-11-02 14:37:54 -0700215 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700216 default:
217 break;
218 }
219
tsepez4cf55152016-11-02 14:37:54 -0700220 bool bCtrl = IsCTRLpressed(nFlag);
221 bool bAlt = IsALTpressed(nFlag);
222 bool bShift = IsSHIFTpressed(nFlag);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700223
Tom Sepez62a70f92016-03-21 15:00:20 -0700224 uint16_t word = nChar;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700225
226 if (bCtrl && !bAlt) {
227 switch (nChar) {
228 case 'C' - 'A' + 1:
229 CopyText();
tsepez4cf55152016-11-02 14:37:54 -0700230 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700231 case 'V' - 'A' + 1:
232 PasteText();
tsepez4cf55152016-11-02 14:37:54 -0700233 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700234 case 'X' - 'A' + 1:
235 CutText();
tsepez4cf55152016-11-02 14:37:54 -0700236 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700237 case 'A' - 'A' + 1:
238 SelectAll();
tsepez4cf55152016-11-02 14:37:54 -0700239 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700240 case 'Z' - 'A' + 1:
241 if (bShift)
242 Redo();
243 else
244 Undo();
tsepez4cf55152016-11-02 14:37:54 -0700245 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700246 default:
247 if (nChar < 32)
tsepez4cf55152016-11-02 14:37:54 -0700248 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700249 }
250 }
251
252 if (IsReadOnly())
tsepez4cf55152016-11-02 14:37:54 -0700253 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700254
255 if (m_pEdit->IsSelected() && word == FWL_VKEY_Back)
256 word = FWL_VKEY_Unknown;
257
258 Clear();
259
260 switch (word) {
261 case FWL_VKEY_Back:
262 Backspace();
263 break;
264 case FWL_VKEY_Return:
265 InsertReturn();
266 break;
267 case FWL_VKEY_Unknown:
268 break;
269 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700270 InsertWord(word, GetCharSet());
271 break;
272 }
273
tsepez4cf55152016-11-02 14:37:54 -0700274 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700275}
276
Dan Sinclairf528eee2017-02-14 11:52:07 -0500277bool CPWL_EditCtrl::OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700278 CPWL_Wnd::OnLButtonDown(point, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700279
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700280 if (ClientHitTest(point)) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700281 if (m_bMouseDown)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700282 InvalidateRect();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700283
tsepez4cf55152016-11-02 14:37:54 -0700284 m_bMouseDown = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700285 SetCapture();
286
287 m_pEdit->OnMouseDown(point, IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
288 }
289
tsepez4cf55152016-11-02 14:37:54 -0700290 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700291}
292
Dan Sinclairf528eee2017-02-14 11:52:07 -0500293bool CPWL_EditCtrl::OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700294 CPWL_Wnd::OnLButtonUp(point, nFlag);
295
296 if (m_bMouseDown) {
297 // can receive keybord message
298 if (ClientHitTest(point) && !IsFocused())
299 SetFocus();
300
301 ReleaseCapture();
tsepez4cf55152016-11-02 14:37:54 -0700302 m_bMouseDown = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700303 }
304
tsepez4cf55152016-11-02 14:37:54 -0700305 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700306}
307
Dan Sinclairf528eee2017-02-14 11:52:07 -0500308bool CPWL_EditCtrl::OnMouseMove(const CFX_PointF& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700309 CPWL_Wnd::OnMouseMove(point, nFlag);
310
311 if (m_bMouseDown)
tsepez4cf55152016-11-02 14:37:54 -0700312 m_pEdit->OnMouseMove(point, false, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700313
tsepez4cf55152016-11-02 14:37:54 -0700314 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700315}
316
Tom Sepez281a9ea2016-02-26 14:24:28 -0800317CFX_FloatRect CPWL_EditCtrl::GetContentRect() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700318 return m_pEdit->GetContentRect();
319}
320
tsepez4cf55152016-11-02 14:37:54 -0700321void CPWL_EditCtrl::SetEditCaret(bool bVisible) {
Dan Sinclairf528eee2017-02-14 11:52:07 -0500322 CFX_PointF ptHead;
323 CFX_PointF ptFoot;
tsepez63f545c2016-09-13 16:08:49 -0700324 if (bVisible)
Dan Sinclair1f403ce2017-02-21 12:56:24 -0500325 GetCaretInfo(&ptHead, &ptFoot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700326
327 CPVT_WordPlace wpTemp = m_pEdit->GetCaretWordPlace();
328 IOnSetCaret(bVisible, ptHead, ptFoot, wpTemp);
329}
330
Dan Sinclair1f403ce2017-02-21 12:56:24 -0500331void CPWL_EditCtrl::GetCaretInfo(CFX_PointF* ptHead, CFX_PointF* ptFoot) const {
dsinclaire35af1e2016-07-13 11:26:20 -0700332 CFX_Edit_Iterator* pIterator = m_pEdit->GetIterator();
thestig821d59e2016-05-11 12:59:22 -0700333 pIterator->SetAt(m_pEdit->GetCaret());
334 CPVT_Word word;
335 CPVT_Line line;
336 if (pIterator->GetWord(word)) {
Dan Sinclair1f403ce2017-02-21 12:56:24 -0500337 ptHead->x = word.ptWord.x + word.fWidth;
338 ptHead->y = word.ptWord.y + word.fAscent;
339 ptFoot->x = word.ptWord.x + word.fWidth;
340 ptFoot->y = word.ptWord.y + word.fDescent;
thestig821d59e2016-05-11 12:59:22 -0700341 } else if (pIterator->GetLine(line)) {
Dan Sinclair1f403ce2017-02-21 12:56:24 -0500342 ptHead->x = line.ptLine.x;
343 ptHead->y = line.ptLine.y + line.fLineAscent;
344 ptFoot->x = line.ptLine.x;
345 ptFoot->y = line.ptLine.y + line.fLineDescent;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700346 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700347}
348
tsepez4cf55152016-11-02 14:37:54 -0700349void CPWL_EditCtrl::SetCaret(bool bVisible,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500350 const CFX_PointF& ptHead,
351 const CFX_PointF& ptFoot) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700352 if (m_pEditCaret) {
353 if (!IsFocused() || m_pEdit->IsSelected())
tsepez4cf55152016-11-02 14:37:54 -0700354 bVisible = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700355
356 m_pEditCaret->SetCaret(bVisible, ptHead, ptFoot);
357 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700358}
359
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700360CFX_WideString CPWL_EditCtrl::GetText() const {
361 return m_pEdit->GetText();
362}
363
364void CPWL_EditCtrl::SetSel(int32_t nStartChar, int32_t nEndChar) {
365 m_pEdit->SetSel(nStartChar, nEndChar);
366}
367
368void CPWL_EditCtrl::GetSel(int32_t& nStartChar, int32_t& nEndChar) const {
369 m_pEdit->GetSel(nStartChar, nEndChar);
370}
371
372void CPWL_EditCtrl::Clear() {
373 if (!IsReadOnly())
374 m_pEdit->Clear();
375}
376
377void CPWL_EditCtrl::SelectAll() {
378 m_pEdit->SelectAll();
379}
380
381void CPWL_EditCtrl::Paint() {
thestig732f6a02016-05-12 10:41:56 -0700382 m_pEdit->Paint();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700383}
384
tsepez4cf55152016-11-02 14:37:54 -0700385void CPWL_EditCtrl::EnableRefresh(bool bRefresh) {
thestig732f6a02016-05-12 10:41:56 -0700386 m_pEdit->EnableRefresh(bRefresh);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700387}
388
389int32_t CPWL_EditCtrl::GetCaret() const {
thestig732f6a02016-05-12 10:41:56 -0700390 return m_pEdit->GetCaret();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700391}
392
393void CPWL_EditCtrl::SetCaret(int32_t nPos) {
thestig732f6a02016-05-12 10:41:56 -0700394 m_pEdit->SetCaret(nPos);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700395}
396
397int32_t CPWL_EditCtrl::GetTotalWords() const {
thestig732f6a02016-05-12 10:41:56 -0700398 return m_pEdit->GetTotalWords();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700399}
400
Dan Sinclairf528eee2017-02-14 11:52:07 -0500401void CPWL_EditCtrl::SetScrollPos(const CFX_PointF& point) {
thestig732f6a02016-05-12 10:41:56 -0700402 m_pEdit->SetScrollPos(point);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700403}
404
Dan Sinclairf528eee2017-02-14 11:52:07 -0500405CFX_PointF CPWL_EditCtrl::GetScrollPos() const {
thestig732f6a02016-05-12 10:41:56 -0700406 return m_pEdit->GetScrollPos();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700407}
408
409CPDF_Font* CPWL_EditCtrl::GetCaretFont() const {
410 int32_t nFontIndex = 0;
411
dsinclaire35af1e2016-07-13 11:26:20 -0700412 CFX_Edit_Iterator* pIterator = m_pEdit->GetIterator();
thestig821d59e2016-05-11 12:59:22 -0700413 pIterator->SetAt(m_pEdit->GetCaret());
414 CPVT_Word word;
415 CPVT_Section section;
416 if (pIterator->GetWord(word)) {
417 nFontIndex = word.nFontIndex;
418 } else if (HasFlag(PES_RICH)) {
419 if (pIterator->GetSection(section)) {
420 nFontIndex = section.WordProps.nFontIndex;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700421 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700422 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700423
dsinclairc7a73492016-04-05 12:01:42 -0700424 if (IPVT_FontMap* pFontMap = GetFontMap())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700425 return pFontMap->GetPDFFont(nFontIndex);
426
thestig1cd352e2016-06-07 17:53:06 -0700427 return nullptr;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700428}
429
Dan Sinclair05df0752017-03-14 14:43:42 -0400430float CPWL_EditCtrl::GetCaretFontSize() const {
431 float fFontSize = GetFontSize();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700432
dsinclaire35af1e2016-07-13 11:26:20 -0700433 CFX_Edit_Iterator* pIterator = m_pEdit->GetIterator();
thestig821d59e2016-05-11 12:59:22 -0700434 pIterator->SetAt(m_pEdit->GetCaret());
435 CPVT_Word word;
436 CPVT_Section section;
437 if (pIterator->GetWord(word)) {
438 fFontSize = word.fFontSize;
439 } else if (HasFlag(PES_RICH)) {
440 if (pIterator->GetSection(section)) {
441 fFontSize = section.WordProps.fFontSize;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700442 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700443 }
444
445 return fFontSize;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700446}
447
tsepez067990c2016-09-13 06:46:40 -0700448void CPWL_EditCtrl::SetText(const CFX_WideString& wsText) {
449 m_pEdit->SetText(wsText);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700450}
451
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700452void CPWL_EditCtrl::CopyText() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700453
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700454void CPWL_EditCtrl::PasteText() {}
455
456void CPWL_EditCtrl::CutText() {}
457
tsepez4cf55152016-11-02 14:37:54 -0700458void CPWL_EditCtrl::ShowVScrollBar(bool bShow) {}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700459
tsepez067990c2016-09-13 06:46:40 -0700460void CPWL_EditCtrl::InsertText(const CFX_WideString& wsText) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700461 if (!IsReadOnly())
npmea3c3be2016-09-19 07:24:33 -0700462 m_pEdit->InsertText(wsText, FXFONT_DEFAULT_CHARSET);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700463}
464
Tom Sepez62a70f92016-03-21 15:00:20 -0700465void CPWL_EditCtrl::InsertWord(uint16_t word, int32_t nCharset) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700466 if (!IsReadOnly())
467 m_pEdit->InsertWord(word, nCharset);
468}
469
470void CPWL_EditCtrl::InsertReturn() {
471 if (!IsReadOnly())
472 m_pEdit->InsertReturn();
473}
474
475void CPWL_EditCtrl::Delete() {
476 if (!IsReadOnly())
477 m_pEdit->Delete();
478}
479
480void CPWL_EditCtrl::Backspace() {
481 if (!IsReadOnly())
482 m_pEdit->Backspace();
483}
484
tsepez4cf55152016-11-02 14:37:54 -0700485bool CPWL_EditCtrl::CanUndo() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700486 return !IsReadOnly() && m_pEdit->CanUndo();
487}
488
tsepez4cf55152016-11-02 14:37:54 -0700489bool CPWL_EditCtrl::CanRedo() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700490 return !IsReadOnly() && m_pEdit->CanRedo();
491}
492
493void CPWL_EditCtrl::Redo() {
494 if (CanRedo())
495 m_pEdit->Redo();
496}
497
498void CPWL_EditCtrl::Undo() {
499 if (CanUndo())
500 m_pEdit->Undo();
501}
502
Dan Sinclair05df0752017-03-14 14:43:42 -0400503void CPWL_EditCtrl::IOnSetScrollInfoY(float fPlateMin,
504 float fPlateMax,
505 float fContentMin,
506 float fContentMax,
507 float fSmallStep,
508 float fBigStep) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700509 PWL_SCROLL_INFO Info;
510
511 Info.fPlateWidth = fPlateMax - fPlateMin;
512 Info.fContentMin = fContentMin;
513 Info.fContentMax = fContentMax;
514 Info.fSmallStep = fSmallStep;
515 Info.fBigStep = fBigStep;
516
517 OnNotify(this, PNM_SETSCROLLINFO, SBT_VSCROLL, (intptr_t)&Info);
518
519 if (IsFloatBigger(Info.fPlateWidth, Info.fContentMax - Info.fContentMin) ||
520 IsFloatEqual(Info.fPlateWidth, Info.fContentMax - Info.fContentMin)) {
tsepez4cf55152016-11-02 14:37:54 -0700521 ShowVScrollBar(false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700522 } else {
tsepez4cf55152016-11-02 14:37:54 -0700523 ShowVScrollBar(true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700524 }
525}
526
Dan Sinclair05df0752017-03-14 14:43:42 -0400527void CPWL_EditCtrl::IOnSetScrollPosY(float fy) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700528 OnNotify(this, PNM_SETSCROLLPOS, SBT_VSCROLL, (intptr_t)&fy);
529}
530
tsepez4cf55152016-11-02 14:37:54 -0700531void CPWL_EditCtrl::IOnSetCaret(bool bVisible,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500532 const CFX_PointF& ptHead,
533 const CFX_PointF& ptFoot,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700534 const CPVT_WordPlace& place) {
535 PWL_CARET_INFO cInfo;
536 cInfo.bVisible = bVisible;
537 cInfo.ptHead = ptHead;
538 cInfo.ptFoot = ptFoot;
539
thestig1cd352e2016-06-07 17:53:06 -0700540 OnNotify(this, PNM_SETCARETINFO, (intptr_t)&cInfo, (intptr_t) nullptr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700541}
542
dsinclairdbc77162016-07-13 11:34:23 -0700543void CPWL_EditCtrl::IOnCaretChange(const CPVT_SecProps& secProps,
544 const CPVT_WordProps& wordProps) {}
545
546void CPWL_EditCtrl::IOnContentChange(const CFX_FloatRect& rcContent) {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700547
Tom Sepez281a9ea2016-02-26 14:24:28 -0800548void CPWL_EditCtrl::IOnInvalidateRect(CFX_FloatRect* pRect) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700549 InvalidateRect(pRect);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700550}
551
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700552int32_t CPWL_EditCtrl::GetCharSet() const {
npmea3c3be2016-09-19 07:24:33 -0700553 return m_nCharSet < 0 ? FXFONT_DEFAULT_CHARSET : m_nCharSet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700554}
555
Tom Sepez281a9ea2016-02-26 14:24:28 -0800556void CPWL_EditCtrl::GetTextRange(const CFX_FloatRect& rect,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700557 int32_t& nStartChar,
558 int32_t& nEndChar) const {
559 nStartChar = m_pEdit->WordPlaceToWordIndex(
Dan Sinclairf528eee2017-02-14 11:52:07 -0500560 m_pEdit->SearchWordPlace(CFX_PointF(rect.left, rect.top)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700561 nEndChar = m_pEdit->WordPlaceToWordIndex(
Dan Sinclairf528eee2017-02-14 11:52:07 -0500562 m_pEdit->SearchWordPlace(CFX_PointF(rect.right, rect.bottom)));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700563}
564
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700565CFX_WideString CPWL_EditCtrl::GetText(int32_t& nStartChar,
566 int32_t& nEndChar) const {
567 CPVT_WordPlace wpStart = m_pEdit->WordIndexToWordPlace(nStartChar);
568 CPVT_WordPlace wpEnd = m_pEdit->WordIndexToWordPlace(nEndChar);
569 return m_pEdit->GetRangeText(CPVT_WordRange(wpStart, wpEnd));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700570}
571
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700572void CPWL_EditCtrl::SetReadyToInput() {
573 if (m_bMouseDown) {
574 ReleaseCapture();
tsepez4cf55152016-11-02 14:37:54 -0700575 m_bMouseDown = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700576 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700577}