blob: dd1094a868704494025c0db71ec2ba5e2f9aae39 [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
dsinclairc7a73492016-04-05 12:01:42 -07009#include "core/fpdfdoc/include/cpvt_section.h"
10#include "core/fpdfdoc/include/cpvt_word.h"
dsinclaire35af1e2016-07-13 11:26:20 -070011#include "fpdfsdk/fxedit/include/fxet_edit.h"
dan sinclair89e904b2016-03-23 19:29:15 -040012#include "fpdfsdk/pdfwindow/PWL_Caret.h"
13#include "fpdfsdk/pdfwindow/PWL_FontMap.h"
14#include "fpdfsdk/pdfwindow/PWL_ScrollBar.h"
15#include "fpdfsdk/pdfwindow/PWL_Utils.h"
16#include "fpdfsdk/pdfwindow/PWL_Wnd.h"
Lei Zhangc2fb35f2016-01-05 16:46:58 -080017#include "public/fpdf_fwlevent.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070018
Nico Weber9d8ec5a2015-08-04 13:00:21 -070019#define IsFloatZero(f) ((f) < 0.0001 && (f) > -0.0001)
20#define IsFloatBigger(fa, fb) ((fa) > (fb) && !IsFloatZero((fa) - (fb)))
21#define IsFloatSmaller(fa, fb) ((fa) < (fb) && !IsFloatZero((fa) - (fb)))
22#define IsFloatEqual(fa, fb) IsFloatZero((fa) - (fb))
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070023
Nico Weber9d8ec5a2015-08-04 13:00:21 -070024CPWL_EditCtrl::CPWL_EditCtrl()
dsinclaire35af1e2016-07-13 11:26:20 -070025 : m_pEdit(new CFX_Edit),
thestig1cd352e2016-06-07 17:53:06 -070026 m_pEditCaret(nullptr),
Nico Weber9d8ec5a2015-08-04 13:00:21 -070027 m_bMouseDown(FALSE),
thestig1cd352e2016-06-07 17:53:06 -070028 m_pEditNotify(nullptr),
Nico Weber9d8ec5a2015-08-04 13:00:21 -070029 m_nCharSet(DEFAULT_CHARSET),
thestig732f6a02016-05-12 10:41:56 -070030 m_nCodePage(0) {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070031
Nico Weber9d8ec5a2015-08-04 13:00:21 -070032CPWL_EditCtrl::~CPWL_EditCtrl() {
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070033}
34
Nico Weber9d8ec5a2015-08-04 13:00:21 -070035void CPWL_EditCtrl::OnCreate(PWL_CREATEPARAM& cp) {
36 cp.eCursorType = FXCT_VBEAM;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070037}
38
Nico Weber9d8ec5a2015-08-04 13:00:21 -070039void CPWL_EditCtrl::OnCreated() {
40 SetFontSize(GetCreationParam().fFontSize);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070041
Nico Weber9d8ec5a2015-08-04 13:00:21 -070042 m_pEdit->SetFontMap(GetFontMap());
43 m_pEdit->SetNotify(this);
44 m_pEdit->Initialize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070045}
46
Nico Weber9d8ec5a2015-08-04 13:00:21 -070047FX_BOOL CPWL_EditCtrl::IsWndHorV() {
Tom Sepez60d909e2015-12-10 15:34:55 -080048 CFX_Matrix mt = GetWindowMatrix();
Tom Sepez281a9ea2016-02-26 14:24:28 -080049 CFX_FloatPoint point1(0, 1);
50 CFX_FloatPoint point2(1, 1);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070051
Nico Weber9d8ec5a2015-08-04 13:00:21 -070052 mt.Transform(point1.x, point1.y);
53 mt.Transform(point2.x, point2.y);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070054
Nico Weber9d8ec5a2015-08-04 13:00:21 -070055 return point2.y == point1.y;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070056}
57
Nico Weber9d8ec5a2015-08-04 13:00:21 -070058void CPWL_EditCtrl::SetCursor() {
59 if (IsValid()) {
dsinclairb9590102016-04-27 06:38:59 -070060 if (CFX_SystemHandler* pSH = GetSystemHandler()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070061 if (IsWndHorV())
62 pSH->SetCursor(FXCT_VBEAM);
63 else
64 pSH->SetCursor(FXCT_HBEAM);
Tom Sepez2f2ffec2015-07-23 14:42:09 -070065 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070066 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070067}
68
Nico Weber9d8ec5a2015-08-04 13:00:21 -070069void CPWL_EditCtrl::RePosChildWnd() {
70 m_pEdit->SetPlateRect(GetClientRect());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070071}
72
Nico Weber9d8ec5a2015-08-04 13:00:21 -070073void CPWL_EditCtrl::OnNotify(CPWL_Wnd* pWnd,
tsepezc3255f52016-03-25 14:52:27 -070074 uint32_t msg,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070075 intptr_t wParam,
76 intptr_t lParam) {
77 CPWL_Wnd::OnNotify(pWnd, msg, wParam, lParam);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070078
Nico Weber9d8ec5a2015-08-04 13:00:21 -070079 switch (msg) {
80 case PNM_SETSCROLLINFO:
81 switch (wParam) {
82 case SBT_VSCROLL:
83 if (CPWL_Wnd* pChild = GetVScrollBar()) {
84 pChild->OnNotify(pWnd, PNM_SETSCROLLINFO, wParam, lParam);
85 }
86 break;
87 }
88 break;
89 case PNM_SETSCROLLPOS:
90 switch (wParam) {
91 case SBT_VSCROLL:
92 if (CPWL_Wnd* pChild = GetVScrollBar()) {
93 pChild->OnNotify(pWnd, PNM_SETSCROLLPOS, wParam, lParam);
94 }
95 break;
96 }
97 break;
98 case PNM_SCROLLWINDOW: {
99 FX_FLOAT fPos = *(FX_FLOAT*)lParam;
100 switch (wParam) {
101 case SBT_VSCROLL:
Tom Sepez281a9ea2016-02-26 14:24:28 -0800102 m_pEdit->SetScrollPos(
103 CFX_FloatPoint(m_pEdit->GetScrollPos().x, fPos));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700104 break;
105 }
106 } break;
107 case PNM_SETCARETINFO: {
108 if (PWL_CARET_INFO* pCaretInfo = (PWL_CARET_INFO*)wParam) {
109 SetCaret(pCaretInfo->bVisible, pCaretInfo->ptHead, pCaretInfo->ptFoot);
110 }
111 } break;
112 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700113}
114
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700115void CPWL_EditCtrl::CreateChildWnd(const PWL_CREATEPARAM& cp) {
116 if (!IsReadOnly())
117 CreateEditCaret(cp);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700118}
119
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700120void CPWL_EditCtrl::CreateEditCaret(const PWL_CREATEPARAM& cp) {
thestig732f6a02016-05-12 10:41:56 -0700121 if (m_pEditCaret)
122 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700123
thestig732f6a02016-05-12 10:41:56 -0700124 m_pEditCaret = new CPWL_Caret;
125 m_pEditCaret->SetInvalidRect(GetClientRect());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700126
thestig732f6a02016-05-12 10:41:56 -0700127 PWL_CREATEPARAM ecp = cp;
128 ecp.pParentWnd = this;
129 ecp.dwFlags = PWS_CHILD | PWS_NOREFRESHCLIP;
130 ecp.dwBorderWidth = 0;
dsinclair92cb5e52016-05-16 11:38:28 -0700131 ecp.nBorderStyle = BorderStyle::SOLID;
thestig732f6a02016-05-12 10:41:56 -0700132 ecp.rcRectWnd = CFX_FloatRect(0, 0, 0, 0);
133
134 m_pEditCaret->Create(ecp);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700135}
136
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700137void CPWL_EditCtrl::SetFontSize(FX_FLOAT fFontSize) {
138 m_pEdit->SetFontSize(fFontSize);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700139}
140
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700141FX_FLOAT CPWL_EditCtrl::GetFontSize() const {
142 return m_pEdit->GetFontSize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700143}
144
tsepezc3255f52016-03-25 14:52:27 -0700145FX_BOOL CPWL_EditCtrl::OnKeyDown(uint16_t nChar, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700146 if (m_bMouseDown)
147 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700148
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700149 FX_BOOL bRet = CPWL_Wnd::OnKeyDown(nChar, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700150
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700151 // FILTER
152 switch (nChar) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700153 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700154 return FALSE;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700155 case FWL_VKEY_Delete:
156 case FWL_VKEY_Up:
157 case FWL_VKEY_Down:
158 case FWL_VKEY_Left:
159 case FWL_VKEY_Right:
160 case FWL_VKEY_Home:
161 case FWL_VKEY_End:
162 case FWL_VKEY_Insert:
163 case 'C':
164 case 'V':
165 case 'X':
166 case 'A':
167 case 'Z':
168 case 'c':
169 case 'v':
170 case 'x':
171 case 'a':
172 case 'z':
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700173 break;
174 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700175
thestig594b20b2016-05-12 21:56:43 -0700176 if (nChar == FWL_VKEY_Delete && m_pEdit->IsSelected())
177 nChar = FWL_VKEY_Unknown;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700178
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700179 switch (nChar) {
180 case FWL_VKEY_Delete:
181 Delete();
182 return TRUE;
183 case FWL_VKEY_Insert:
184 if (IsSHIFTpressed(nFlag))
185 PasteText();
186 return TRUE;
187 case FWL_VKEY_Up:
188 m_pEdit->OnVK_UP(IsSHIFTpressed(nFlag), FALSE);
189 return TRUE;
190 case FWL_VKEY_Down:
191 m_pEdit->OnVK_DOWN(IsSHIFTpressed(nFlag), FALSE);
192 return TRUE;
193 case FWL_VKEY_Left:
194 m_pEdit->OnVK_LEFT(IsSHIFTpressed(nFlag), FALSE);
195 return TRUE;
196 case FWL_VKEY_Right:
197 m_pEdit->OnVK_RIGHT(IsSHIFTpressed(nFlag), FALSE);
198 return TRUE;
199 case FWL_VKEY_Home:
200 m_pEdit->OnVK_HOME(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
201 return TRUE;
202 case FWL_VKEY_End:
203 m_pEdit->OnVK_END(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
204 return TRUE;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700205 case FWL_VKEY_Unknown:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700206 if (!IsSHIFTpressed(nFlag))
207 Clear();
208 else
209 CutText();
210 return TRUE;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700211 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700212 break;
213 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700214
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700215 return bRet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700216}
217
tsepezc3255f52016-03-25 14:52:27 -0700218FX_BOOL CPWL_EditCtrl::OnChar(uint16_t nChar, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700219 if (m_bMouseDown)
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700220 return TRUE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700221
222 CPWL_Wnd::OnChar(nChar, nFlag);
223
224 // FILTER
225 switch (nChar) {
226 case 0x0A:
227 case 0x1B:
228 return FALSE;
229 default:
230 break;
231 }
232
233 FX_BOOL bCtrl = IsCTRLpressed(nFlag);
234 FX_BOOL bAlt = IsALTpressed(nFlag);
235 FX_BOOL bShift = IsSHIFTpressed(nFlag);
236
Tom Sepez62a70f92016-03-21 15:00:20 -0700237 uint16_t word = nChar;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700238
239 if (bCtrl && !bAlt) {
240 switch (nChar) {
241 case 'C' - 'A' + 1:
242 CopyText();
243 return TRUE;
244 case 'V' - 'A' + 1:
245 PasteText();
246 return TRUE;
247 case 'X' - 'A' + 1:
248 CutText();
249 return TRUE;
250 case 'A' - 'A' + 1:
251 SelectAll();
252 return TRUE;
253 case 'Z' - 'A' + 1:
254 if (bShift)
255 Redo();
256 else
257 Undo();
258 return TRUE;
259 default:
260 if (nChar < 32)
261 return FALSE;
262 }
263 }
264
265 if (IsReadOnly())
266 return TRUE;
267
268 if (m_pEdit->IsSelected() && word == FWL_VKEY_Back)
269 word = FWL_VKEY_Unknown;
270
271 Clear();
272
273 switch (word) {
274 case FWL_VKEY_Back:
275 Backspace();
276 break;
277 case FWL_VKEY_Return:
278 InsertReturn();
279 break;
280 case FWL_VKEY_Unknown:
281 break;
282 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700283 InsertWord(word, GetCharSet());
284 break;
285 }
286
287 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700288}
289
Tom Sepez281a9ea2016-02-26 14:24:28 -0800290FX_BOOL CPWL_EditCtrl::OnLButtonDown(const CFX_FloatPoint& point,
tsepezc3255f52016-03-25 14:52:27 -0700291 uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700292 CPWL_Wnd::OnLButtonDown(point, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700293
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700294 if (ClientHitTest(point)) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700295 if (m_bMouseDown)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700296 InvalidateRect();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700297
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700298 m_bMouseDown = TRUE;
299 SetCapture();
300
301 m_pEdit->OnMouseDown(point, IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
302 }
303
304 return TRUE;
305}
306
Tom Sepez281a9ea2016-02-26 14:24:28 -0800307FX_BOOL CPWL_EditCtrl::OnLButtonUp(const CFX_FloatPoint& point,
tsepezc3255f52016-03-25 14:52:27 -0700308 uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700309 CPWL_Wnd::OnLButtonUp(point, nFlag);
310
311 if (m_bMouseDown) {
312 // can receive keybord message
313 if (ClientHitTest(point) && !IsFocused())
314 SetFocus();
315
316 ReleaseCapture();
317 m_bMouseDown = FALSE;
318 }
319
320 return TRUE;
321}
322
Tom Sepez281a9ea2016-02-26 14:24:28 -0800323FX_BOOL CPWL_EditCtrl::OnMouseMove(const CFX_FloatPoint& point,
tsepezc3255f52016-03-25 14:52:27 -0700324 uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700325 CPWL_Wnd::OnMouseMove(point, nFlag);
326
327 if (m_bMouseDown)
328 m_pEdit->OnMouseMove(point, FALSE, FALSE);
329
330 return TRUE;
331}
332
Tom Sepez281a9ea2016-02-26 14:24:28 -0800333CFX_FloatRect CPWL_EditCtrl::GetContentRect() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700334 return m_pEdit->GetContentRect();
335}
336
337void CPWL_EditCtrl::SetEditCaret(FX_BOOL bVisible) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800338 CFX_FloatPoint ptHead(0, 0), ptFoot(0, 0);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700339
340 if (bVisible) {
341 GetCaretInfo(ptHead, ptFoot);
342 }
343
344 CPVT_WordPlace wpTemp = m_pEdit->GetCaretWordPlace();
345 IOnSetCaret(bVisible, ptHead, ptFoot, wpTemp);
346}
347
Tom Sepez281a9ea2016-02-26 14:24:28 -0800348void CPWL_EditCtrl::GetCaretInfo(CFX_FloatPoint& ptHead,
349 CFX_FloatPoint& ptFoot) const {
dsinclaire35af1e2016-07-13 11:26:20 -0700350 CFX_Edit_Iterator* pIterator = m_pEdit->GetIterator();
thestig821d59e2016-05-11 12:59:22 -0700351 pIterator->SetAt(m_pEdit->GetCaret());
352 CPVT_Word word;
353 CPVT_Line line;
354 if (pIterator->GetWord(word)) {
355 ptHead.x = word.ptWord.x + word.fWidth;
356 ptHead.y = word.ptWord.y + word.fAscent;
357 ptFoot.x = word.ptWord.x + word.fWidth;
358 ptFoot.y = word.ptWord.y + word.fDescent;
359 } else if (pIterator->GetLine(line)) {
360 ptHead.x = line.ptLine.x;
361 ptHead.y = line.ptLine.y + line.fLineAscent;
362 ptFoot.x = line.ptLine.x;
363 ptFoot.y = line.ptLine.y + line.fLineDescent;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700364 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700365}
366
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700367void CPWL_EditCtrl::GetCaretPos(int32_t& x, int32_t& y) const {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800368 CFX_FloatPoint ptHead(0, 0), ptFoot(0, 0);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700369
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700370 GetCaretInfo(ptHead, ptFoot);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700371
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700372 PWLtoWnd(ptHead, x, y);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700373}
374
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700375void CPWL_EditCtrl::SetCaret(FX_BOOL bVisible,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800376 const CFX_FloatPoint& ptHead,
377 const CFX_FloatPoint& ptFoot) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700378 if (m_pEditCaret) {
379 if (!IsFocused() || m_pEdit->IsSelected())
380 bVisible = FALSE;
381
382 m_pEditCaret->SetCaret(bVisible, ptHead, ptFoot);
383 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700384}
385
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700386CFX_WideString CPWL_EditCtrl::GetText() const {
387 return m_pEdit->GetText();
388}
389
390void CPWL_EditCtrl::SetSel(int32_t nStartChar, int32_t nEndChar) {
391 m_pEdit->SetSel(nStartChar, nEndChar);
392}
393
394void CPWL_EditCtrl::GetSel(int32_t& nStartChar, int32_t& nEndChar) const {
395 m_pEdit->GetSel(nStartChar, nEndChar);
396}
397
398void CPWL_EditCtrl::Clear() {
399 if (!IsReadOnly())
400 m_pEdit->Clear();
401}
402
403void CPWL_EditCtrl::SelectAll() {
404 m_pEdit->SelectAll();
405}
406
407void CPWL_EditCtrl::Paint() {
thestig732f6a02016-05-12 10:41:56 -0700408 m_pEdit->Paint();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700409}
410
411void CPWL_EditCtrl::EnableRefresh(FX_BOOL bRefresh) {
thestig732f6a02016-05-12 10:41:56 -0700412 m_pEdit->EnableRefresh(bRefresh);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700413}
414
415int32_t CPWL_EditCtrl::GetCaret() const {
thestig732f6a02016-05-12 10:41:56 -0700416 return m_pEdit->GetCaret();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700417}
418
419void CPWL_EditCtrl::SetCaret(int32_t nPos) {
thestig732f6a02016-05-12 10:41:56 -0700420 m_pEdit->SetCaret(nPos);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700421}
422
423int32_t CPWL_EditCtrl::GetTotalWords() const {
thestig732f6a02016-05-12 10:41:56 -0700424 return m_pEdit->GetTotalWords();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700425}
426
Tom Sepez281a9ea2016-02-26 14:24:28 -0800427void CPWL_EditCtrl::SetScrollPos(const CFX_FloatPoint& point) {
thestig732f6a02016-05-12 10:41:56 -0700428 m_pEdit->SetScrollPos(point);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700429}
430
Tom Sepez281a9ea2016-02-26 14:24:28 -0800431CFX_FloatPoint CPWL_EditCtrl::GetScrollPos() const {
thestig732f6a02016-05-12 10:41:56 -0700432 return m_pEdit->GetScrollPos();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700433}
434
435CPDF_Font* CPWL_EditCtrl::GetCaretFont() const {
436 int32_t nFontIndex = 0;
437
dsinclaire35af1e2016-07-13 11:26:20 -0700438 CFX_Edit_Iterator* pIterator = m_pEdit->GetIterator();
thestig821d59e2016-05-11 12:59:22 -0700439 pIterator->SetAt(m_pEdit->GetCaret());
440 CPVT_Word word;
441 CPVT_Section section;
442 if (pIterator->GetWord(word)) {
443 nFontIndex = word.nFontIndex;
444 } else if (HasFlag(PES_RICH)) {
445 if (pIterator->GetSection(section)) {
446 nFontIndex = section.WordProps.nFontIndex;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700447 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700448 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700449
dsinclairc7a73492016-04-05 12:01:42 -0700450 if (IPVT_FontMap* pFontMap = GetFontMap())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700451 return pFontMap->GetPDFFont(nFontIndex);
452
thestig1cd352e2016-06-07 17:53:06 -0700453 return nullptr;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700454}
455
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700456FX_FLOAT CPWL_EditCtrl::GetCaretFontSize() const {
457 FX_FLOAT fFontSize = GetFontSize();
458
dsinclaire35af1e2016-07-13 11:26:20 -0700459 CFX_Edit_Iterator* pIterator = m_pEdit->GetIterator();
thestig821d59e2016-05-11 12:59:22 -0700460 pIterator->SetAt(m_pEdit->GetCaret());
461 CPVT_Word word;
462 CPVT_Section section;
463 if (pIterator->GetWord(word)) {
464 fFontSize = word.fFontSize;
465 } else if (HasFlag(PES_RICH)) {
466 if (pIterator->GetSection(section)) {
467 fFontSize = section.WordProps.fFontSize;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700468 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700469 }
470
471 return fFontSize;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700472}
473
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700474void CPWL_EditCtrl::SetText(const FX_WCHAR* csText) {
475 m_pEdit->SetText(csText);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700476}
477
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700478void CPWL_EditCtrl::CopyText() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700479
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700480void CPWL_EditCtrl::PasteText() {}
481
482void CPWL_EditCtrl::CutText() {}
483
484void CPWL_EditCtrl::ShowVScrollBar(FX_BOOL bShow) {}
485
486void CPWL_EditCtrl::InsertText(const FX_WCHAR* csText) {
487 if (!IsReadOnly())
488 m_pEdit->InsertText(csText);
489}
490
Tom Sepez62a70f92016-03-21 15:00:20 -0700491void CPWL_EditCtrl::InsertWord(uint16_t word, int32_t nCharset) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700492 if (!IsReadOnly())
493 m_pEdit->InsertWord(word, nCharset);
494}
495
496void CPWL_EditCtrl::InsertReturn() {
497 if (!IsReadOnly())
498 m_pEdit->InsertReturn();
499}
500
501void CPWL_EditCtrl::Delete() {
502 if (!IsReadOnly())
503 m_pEdit->Delete();
504}
505
506void CPWL_EditCtrl::Backspace() {
507 if (!IsReadOnly())
508 m_pEdit->Backspace();
509}
510
511FX_BOOL CPWL_EditCtrl::CanUndo() const {
512 return !IsReadOnly() && m_pEdit->CanUndo();
513}
514
515FX_BOOL CPWL_EditCtrl::CanRedo() const {
516 return !IsReadOnly() && m_pEdit->CanRedo();
517}
518
519void CPWL_EditCtrl::Redo() {
520 if (CanRedo())
521 m_pEdit->Redo();
522}
523
524void CPWL_EditCtrl::Undo() {
525 if (CanUndo())
526 m_pEdit->Undo();
527}
528
529void CPWL_EditCtrl::IOnSetScrollInfoY(FX_FLOAT fPlateMin,
530 FX_FLOAT fPlateMax,
531 FX_FLOAT fContentMin,
532 FX_FLOAT fContentMax,
533 FX_FLOAT fSmallStep,
534 FX_FLOAT fBigStep) {
535 PWL_SCROLL_INFO Info;
536
537 Info.fPlateWidth = fPlateMax - fPlateMin;
538 Info.fContentMin = fContentMin;
539 Info.fContentMax = fContentMax;
540 Info.fSmallStep = fSmallStep;
541 Info.fBigStep = fBigStep;
542
543 OnNotify(this, PNM_SETSCROLLINFO, SBT_VSCROLL, (intptr_t)&Info);
544
545 if (IsFloatBigger(Info.fPlateWidth, Info.fContentMax - Info.fContentMin) ||
546 IsFloatEqual(Info.fPlateWidth, Info.fContentMax - Info.fContentMin)) {
547 ShowVScrollBar(FALSE);
548 } else {
549 ShowVScrollBar(TRUE);
550 }
551}
552
553void CPWL_EditCtrl::IOnSetScrollPosY(FX_FLOAT fy) {
554 OnNotify(this, PNM_SETSCROLLPOS, SBT_VSCROLL, (intptr_t)&fy);
555}
556
557void CPWL_EditCtrl::IOnSetCaret(FX_BOOL bVisible,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800558 const CFX_FloatPoint& ptHead,
559 const CFX_FloatPoint& ptFoot,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700560 const CPVT_WordPlace& place) {
561 PWL_CARET_INFO cInfo;
562 cInfo.bVisible = bVisible;
563 cInfo.ptHead = ptHead;
564 cInfo.ptFoot = ptFoot;
565
thestig1cd352e2016-06-07 17:53:06 -0700566 OnNotify(this, PNM_SETCARETINFO, (intptr_t)&cInfo, (intptr_t) nullptr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700567}
568
Tom Sepez281a9ea2016-02-26 14:24:28 -0800569void CPWL_EditCtrl::IOnContentChange(const CFX_FloatRect& rcContent) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700570 if (IsValid()) {
571 if (m_pEditNotify) {
572 m_pEditNotify->OnContentChange(rcContent);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700573 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700574 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700575}
576
Tom Sepez281a9ea2016-02-26 14:24:28 -0800577void CPWL_EditCtrl::IOnInvalidateRect(CFX_FloatRect* pRect) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700578 InvalidateRect(pRect);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700579}
580
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700581int32_t CPWL_EditCtrl::GetCharSet() const {
582 return m_nCharSet < 0 ? DEFAULT_CHARSET : m_nCharSet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700583}
584
Tom Sepez281a9ea2016-02-26 14:24:28 -0800585void CPWL_EditCtrl::GetTextRange(const CFX_FloatRect& rect,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700586 int32_t& nStartChar,
587 int32_t& nEndChar) const {
588 nStartChar = m_pEdit->WordPlaceToWordIndex(
Tom Sepez281a9ea2016-02-26 14:24:28 -0800589 m_pEdit->SearchWordPlace(CFX_FloatPoint(rect.left, rect.top)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700590 nEndChar = m_pEdit->WordPlaceToWordIndex(
Tom Sepez281a9ea2016-02-26 14:24:28 -0800591 m_pEdit->SearchWordPlace(CFX_FloatPoint(rect.right, rect.bottom)));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700592}
593
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700594CFX_WideString CPWL_EditCtrl::GetText(int32_t& nStartChar,
595 int32_t& nEndChar) const {
596 CPVT_WordPlace wpStart = m_pEdit->WordIndexToWordPlace(nStartChar);
597 CPVT_WordPlace wpEnd = m_pEdit->WordIndexToWordPlace(nEndChar);
598 return m_pEdit->GetRangeText(CPVT_WordRange(wpStart, wpEnd));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700599}
600
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700601void CPWL_EditCtrl::SetReadyToInput() {
602 if (m_bMouseDown) {
603 ReleaseCapture();
604 m_bMouseDown = FALSE;
605 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700606}