blob: 8a0dea198053fdb4695c360d481a6861fca77e1e [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"
dan sinclair89e904b2016-03-23 19:29:15 -040011#include "fpdfsdk/pdfwindow/PWL_Caret.h"
12#include "fpdfsdk/pdfwindow/PWL_FontMap.h"
13#include "fpdfsdk/pdfwindow/PWL_ScrollBar.h"
14#include "fpdfsdk/pdfwindow/PWL_Utils.h"
15#include "fpdfsdk/pdfwindow/PWL_Wnd.h"
Lei Zhangc2fb35f2016-01-05 16:46:58 -080016#include "public/fpdf_fwlevent.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070017
Nico Weber9d8ec5a2015-08-04 13:00:21 -070018#define IsFloatZero(f) ((f) < 0.0001 && (f) > -0.0001)
19#define IsFloatBigger(fa, fb) ((fa) > (fb) && !IsFloatZero((fa) - (fb)))
20#define IsFloatSmaller(fa, fb) ((fa) < (fb) && !IsFloatZero((fa) - (fb)))
21#define IsFloatEqual(fa, fb) IsFloatZero((fa) - (fb))
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070022
Nico Weber9d8ec5a2015-08-04 13:00:21 -070023CPWL_EditCtrl::CPWL_EditCtrl()
thestig732f6a02016-05-12 10:41:56 -070024 : m_pEdit(IFX_Edit::NewEdit()),
Nico Weber9d8ec5a2015-08-04 13:00:21 -070025 m_pEditCaret(NULL),
26 m_bMouseDown(FALSE),
27 m_pEditNotify(NULL),
28 m_nCharSet(DEFAULT_CHARSET),
thestig732f6a02016-05-12 10:41:56 -070029 m_nCodePage(0) {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070030
Nico Weber9d8ec5a2015-08-04 13:00:21 -070031CPWL_EditCtrl::~CPWL_EditCtrl() {
32 IFX_Edit::DelEdit(m_pEdit);
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;
131 ecp.nBorderStyle = PBS_SOLID;
132 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
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700176 if (nChar == FWL_VKEY_Delete) {
177 if (m_pEdit->IsSelected())
178 nChar = FWL_VKEY_Unknown;
179 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700180
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700181 switch (nChar) {
182 case FWL_VKEY_Delete:
183 Delete();
184 return TRUE;
185 case FWL_VKEY_Insert:
186 if (IsSHIFTpressed(nFlag))
187 PasteText();
188 return TRUE;
189 case FWL_VKEY_Up:
190 m_pEdit->OnVK_UP(IsSHIFTpressed(nFlag), FALSE);
191 return TRUE;
192 case FWL_VKEY_Down:
193 m_pEdit->OnVK_DOWN(IsSHIFTpressed(nFlag), FALSE);
194 return TRUE;
195 case FWL_VKEY_Left:
196 m_pEdit->OnVK_LEFT(IsSHIFTpressed(nFlag), FALSE);
197 return TRUE;
198 case FWL_VKEY_Right:
199 m_pEdit->OnVK_RIGHT(IsSHIFTpressed(nFlag), FALSE);
200 return TRUE;
201 case FWL_VKEY_Home:
202 m_pEdit->OnVK_HOME(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
203 return TRUE;
204 case FWL_VKEY_End:
205 m_pEdit->OnVK_END(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
206 return TRUE;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700207 case FWL_VKEY_Unknown:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700208 if (!IsSHIFTpressed(nFlag))
209 Clear();
210 else
211 CutText();
212 return TRUE;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700213 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700214 break;
215 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700216
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700217 return bRet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700218}
219
tsepezc3255f52016-03-25 14:52:27 -0700220FX_BOOL CPWL_EditCtrl::OnChar(uint16_t nChar, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700221 if (m_bMouseDown)
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700222 return TRUE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700223
224 CPWL_Wnd::OnChar(nChar, nFlag);
225
226 // FILTER
227 switch (nChar) {
228 case 0x0A:
229 case 0x1B:
230 return FALSE;
231 default:
232 break;
233 }
234
235 FX_BOOL bCtrl = IsCTRLpressed(nFlag);
236 FX_BOOL bAlt = IsALTpressed(nFlag);
237 FX_BOOL bShift = IsSHIFTpressed(nFlag);
238
Tom Sepez62a70f92016-03-21 15:00:20 -0700239 uint16_t word = nChar;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700240
241 if (bCtrl && !bAlt) {
242 switch (nChar) {
243 case 'C' - 'A' + 1:
244 CopyText();
245 return TRUE;
246 case 'V' - 'A' + 1:
247 PasteText();
248 return TRUE;
249 case 'X' - 'A' + 1:
250 CutText();
251 return TRUE;
252 case 'A' - 'A' + 1:
253 SelectAll();
254 return TRUE;
255 case 'Z' - 'A' + 1:
256 if (bShift)
257 Redo();
258 else
259 Undo();
260 return TRUE;
261 default:
262 if (nChar < 32)
263 return FALSE;
264 }
265 }
266
267 if (IsReadOnly())
268 return TRUE;
269
270 if (m_pEdit->IsSelected() && word == FWL_VKEY_Back)
271 word = FWL_VKEY_Unknown;
272
273 Clear();
274
275 switch (word) {
276 case FWL_VKEY_Back:
277 Backspace();
278 break;
279 case FWL_VKEY_Return:
280 InsertReturn();
281 break;
282 case FWL_VKEY_Unknown:
283 break;
284 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700285 InsertWord(word, GetCharSet());
286 break;
287 }
288
289 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700290}
291
Tom Sepez281a9ea2016-02-26 14:24:28 -0800292FX_BOOL CPWL_EditCtrl::OnLButtonDown(const CFX_FloatPoint& point,
tsepezc3255f52016-03-25 14:52:27 -0700293 uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700294 CPWL_Wnd::OnLButtonDown(point, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700295
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700296 if (ClientHitTest(point)) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700297 if (m_bMouseDown)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700298 InvalidateRect();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700299
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700300 m_bMouseDown = TRUE;
301 SetCapture();
302
303 m_pEdit->OnMouseDown(point, IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
304 }
305
306 return TRUE;
307}
308
Tom Sepez281a9ea2016-02-26 14:24:28 -0800309FX_BOOL CPWL_EditCtrl::OnLButtonUp(const CFX_FloatPoint& point,
tsepezc3255f52016-03-25 14:52:27 -0700310 uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700311 CPWL_Wnd::OnLButtonUp(point, nFlag);
312
313 if (m_bMouseDown) {
314 // can receive keybord message
315 if (ClientHitTest(point) && !IsFocused())
316 SetFocus();
317
318 ReleaseCapture();
319 m_bMouseDown = FALSE;
320 }
321
322 return TRUE;
323}
324
Tom Sepez281a9ea2016-02-26 14:24:28 -0800325FX_BOOL CPWL_EditCtrl::OnMouseMove(const CFX_FloatPoint& point,
tsepezc3255f52016-03-25 14:52:27 -0700326 uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700327 CPWL_Wnd::OnMouseMove(point, nFlag);
328
329 if (m_bMouseDown)
330 m_pEdit->OnMouseMove(point, FALSE, FALSE);
331
332 return TRUE;
333}
334
Tom Sepez281a9ea2016-02-26 14:24:28 -0800335CFX_FloatRect CPWL_EditCtrl::GetContentRect() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700336 return m_pEdit->GetContentRect();
337}
338
339void CPWL_EditCtrl::SetEditCaret(FX_BOOL bVisible) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800340 CFX_FloatPoint ptHead(0, 0), ptFoot(0, 0);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700341
342 if (bVisible) {
343 GetCaretInfo(ptHead, ptFoot);
344 }
345
346 CPVT_WordPlace wpTemp = m_pEdit->GetCaretWordPlace();
347 IOnSetCaret(bVisible, ptHead, ptFoot, wpTemp);
348}
349
Tom Sepez281a9ea2016-02-26 14:24:28 -0800350void CPWL_EditCtrl::GetCaretInfo(CFX_FloatPoint& ptHead,
351 CFX_FloatPoint& ptFoot) const {
thestig821d59e2016-05-11 12:59:22 -0700352 IFX_Edit_Iterator* pIterator = m_pEdit->GetIterator();
353 pIterator->SetAt(m_pEdit->GetCaret());
354 CPVT_Word word;
355 CPVT_Line line;
356 if (pIterator->GetWord(word)) {
357 ptHead.x = word.ptWord.x + word.fWidth;
358 ptHead.y = word.ptWord.y + word.fAscent;
359 ptFoot.x = word.ptWord.x + word.fWidth;
360 ptFoot.y = word.ptWord.y + word.fDescent;
361 } else if (pIterator->GetLine(line)) {
362 ptHead.x = line.ptLine.x;
363 ptHead.y = line.ptLine.y + line.fLineAscent;
364 ptFoot.x = line.ptLine.x;
365 ptFoot.y = line.ptLine.y + line.fLineDescent;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700366 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700367}
368
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700369void CPWL_EditCtrl::GetCaretPos(int32_t& x, int32_t& y) const {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800370 CFX_FloatPoint ptHead(0, 0), ptFoot(0, 0);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700371
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700372 GetCaretInfo(ptHead, ptFoot);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700373
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700374 PWLtoWnd(ptHead, x, y);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700375}
376
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700377void CPWL_EditCtrl::SetCaret(FX_BOOL bVisible,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800378 const CFX_FloatPoint& ptHead,
379 const CFX_FloatPoint& ptFoot) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700380 if (m_pEditCaret) {
381 if (!IsFocused() || m_pEdit->IsSelected())
382 bVisible = FALSE;
383
384 m_pEditCaret->SetCaret(bVisible, ptHead, ptFoot);
385 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700386}
387
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700388CFX_WideString CPWL_EditCtrl::GetText() const {
389 return m_pEdit->GetText();
390}
391
392void CPWL_EditCtrl::SetSel(int32_t nStartChar, int32_t nEndChar) {
393 m_pEdit->SetSel(nStartChar, nEndChar);
394}
395
396void CPWL_EditCtrl::GetSel(int32_t& nStartChar, int32_t& nEndChar) const {
397 m_pEdit->GetSel(nStartChar, nEndChar);
398}
399
400void CPWL_EditCtrl::Clear() {
401 if (!IsReadOnly())
402 m_pEdit->Clear();
403}
404
405void CPWL_EditCtrl::SelectAll() {
406 m_pEdit->SelectAll();
407}
408
409void CPWL_EditCtrl::Paint() {
thestig732f6a02016-05-12 10:41:56 -0700410 m_pEdit->Paint();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700411}
412
413void CPWL_EditCtrl::EnableRefresh(FX_BOOL bRefresh) {
thestig732f6a02016-05-12 10:41:56 -0700414 m_pEdit->EnableRefresh(bRefresh);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700415}
416
417int32_t CPWL_EditCtrl::GetCaret() const {
thestig732f6a02016-05-12 10:41:56 -0700418 return m_pEdit->GetCaret();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700419}
420
421void CPWL_EditCtrl::SetCaret(int32_t nPos) {
thestig732f6a02016-05-12 10:41:56 -0700422 m_pEdit->SetCaret(nPos);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700423}
424
425int32_t CPWL_EditCtrl::GetTotalWords() const {
thestig732f6a02016-05-12 10:41:56 -0700426 return m_pEdit->GetTotalWords();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700427}
428
Tom Sepez281a9ea2016-02-26 14:24:28 -0800429void CPWL_EditCtrl::SetScrollPos(const CFX_FloatPoint& point) {
thestig732f6a02016-05-12 10:41:56 -0700430 m_pEdit->SetScrollPos(point);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700431}
432
Tom Sepez281a9ea2016-02-26 14:24:28 -0800433CFX_FloatPoint CPWL_EditCtrl::GetScrollPos() const {
thestig732f6a02016-05-12 10:41:56 -0700434 return m_pEdit->GetScrollPos();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700435}
436
437CPDF_Font* CPWL_EditCtrl::GetCaretFont() const {
438 int32_t nFontIndex = 0;
439
thestig821d59e2016-05-11 12:59:22 -0700440 IFX_Edit_Iterator* pIterator = m_pEdit->GetIterator();
441 pIterator->SetAt(m_pEdit->GetCaret());
442 CPVT_Word word;
443 CPVT_Section section;
444 if (pIterator->GetWord(word)) {
445 nFontIndex = word.nFontIndex;
446 } else if (HasFlag(PES_RICH)) {
447 if (pIterator->GetSection(section)) {
448 nFontIndex = section.WordProps.nFontIndex;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700449 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700450 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700451
dsinclairc7a73492016-04-05 12:01:42 -0700452 if (IPVT_FontMap* pFontMap = GetFontMap())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700453 return pFontMap->GetPDFFont(nFontIndex);
454
455 return NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700456}
457
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700458FX_FLOAT CPWL_EditCtrl::GetCaretFontSize() const {
459 FX_FLOAT fFontSize = GetFontSize();
460
thestig821d59e2016-05-11 12:59:22 -0700461 IFX_Edit_Iterator* pIterator = m_pEdit->GetIterator();
462 pIterator->SetAt(m_pEdit->GetCaret());
463 CPVT_Word word;
464 CPVT_Section section;
465 if (pIterator->GetWord(word)) {
466 fFontSize = word.fFontSize;
467 } else if (HasFlag(PES_RICH)) {
468 if (pIterator->GetSection(section)) {
469 fFontSize = section.WordProps.fFontSize;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700470 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700471 }
472
473 return fFontSize;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700474}
475
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700476void CPWL_EditCtrl::SetText(const FX_WCHAR* csText) {
477 m_pEdit->SetText(csText);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700478}
479
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700480void CPWL_EditCtrl::CopyText() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700481
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700482void CPWL_EditCtrl::PasteText() {}
483
484void CPWL_EditCtrl::CutText() {}
485
486void CPWL_EditCtrl::ShowVScrollBar(FX_BOOL bShow) {}
487
488void CPWL_EditCtrl::InsertText(const FX_WCHAR* csText) {
489 if (!IsReadOnly())
490 m_pEdit->InsertText(csText);
491}
492
Tom Sepez62a70f92016-03-21 15:00:20 -0700493void CPWL_EditCtrl::InsertWord(uint16_t word, int32_t nCharset) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700494 if (!IsReadOnly())
495 m_pEdit->InsertWord(word, nCharset);
496}
497
498void CPWL_EditCtrl::InsertReturn() {
499 if (!IsReadOnly())
500 m_pEdit->InsertReturn();
501}
502
503void CPWL_EditCtrl::Delete() {
504 if (!IsReadOnly())
505 m_pEdit->Delete();
506}
507
508void CPWL_EditCtrl::Backspace() {
509 if (!IsReadOnly())
510 m_pEdit->Backspace();
511}
512
513FX_BOOL CPWL_EditCtrl::CanUndo() const {
514 return !IsReadOnly() && m_pEdit->CanUndo();
515}
516
517FX_BOOL CPWL_EditCtrl::CanRedo() const {
518 return !IsReadOnly() && m_pEdit->CanRedo();
519}
520
521void CPWL_EditCtrl::Redo() {
522 if (CanRedo())
523 m_pEdit->Redo();
524}
525
526void CPWL_EditCtrl::Undo() {
527 if (CanUndo())
528 m_pEdit->Undo();
529}
530
531void CPWL_EditCtrl::IOnSetScrollInfoY(FX_FLOAT fPlateMin,
532 FX_FLOAT fPlateMax,
533 FX_FLOAT fContentMin,
534 FX_FLOAT fContentMax,
535 FX_FLOAT fSmallStep,
536 FX_FLOAT fBigStep) {
537 PWL_SCROLL_INFO Info;
538
539 Info.fPlateWidth = fPlateMax - fPlateMin;
540 Info.fContentMin = fContentMin;
541 Info.fContentMax = fContentMax;
542 Info.fSmallStep = fSmallStep;
543 Info.fBigStep = fBigStep;
544
545 OnNotify(this, PNM_SETSCROLLINFO, SBT_VSCROLL, (intptr_t)&Info);
546
547 if (IsFloatBigger(Info.fPlateWidth, Info.fContentMax - Info.fContentMin) ||
548 IsFloatEqual(Info.fPlateWidth, Info.fContentMax - Info.fContentMin)) {
549 ShowVScrollBar(FALSE);
550 } else {
551 ShowVScrollBar(TRUE);
552 }
553}
554
555void CPWL_EditCtrl::IOnSetScrollPosY(FX_FLOAT fy) {
556 OnNotify(this, PNM_SETSCROLLPOS, SBT_VSCROLL, (intptr_t)&fy);
557}
558
559void CPWL_EditCtrl::IOnSetCaret(FX_BOOL bVisible,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800560 const CFX_FloatPoint& ptHead,
561 const CFX_FloatPoint& ptFoot,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700562 const CPVT_WordPlace& place) {
563 PWL_CARET_INFO cInfo;
564 cInfo.bVisible = bVisible;
565 cInfo.ptHead = ptHead;
566 cInfo.ptFoot = ptFoot;
567
568 OnNotify(this, PNM_SETCARETINFO, (intptr_t)&cInfo, (intptr_t)NULL);
569}
570
571void CPWL_EditCtrl::IOnCaretChange(const CPVT_SecProps& secProps,
572 const CPVT_WordProps& wordProps) {}
573
Tom Sepez281a9ea2016-02-26 14:24:28 -0800574void CPWL_EditCtrl::IOnContentChange(const CFX_FloatRect& rcContent) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700575 if (IsValid()) {
576 if (m_pEditNotify) {
577 m_pEditNotify->OnContentChange(rcContent);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700578 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700579 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700580}
581
Tom Sepez281a9ea2016-02-26 14:24:28 -0800582void CPWL_EditCtrl::IOnInvalidateRect(CFX_FloatRect* pRect) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700583 InvalidateRect(pRect);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700584}
585
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700586int32_t CPWL_EditCtrl::GetCharSet() const {
587 return m_nCharSet < 0 ? DEFAULT_CHARSET : m_nCharSet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700588}
589
Tom Sepez281a9ea2016-02-26 14:24:28 -0800590void CPWL_EditCtrl::GetTextRange(const CFX_FloatRect& rect,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700591 int32_t& nStartChar,
592 int32_t& nEndChar) const {
593 nStartChar = m_pEdit->WordPlaceToWordIndex(
Tom Sepez281a9ea2016-02-26 14:24:28 -0800594 m_pEdit->SearchWordPlace(CFX_FloatPoint(rect.left, rect.top)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700595 nEndChar = m_pEdit->WordPlaceToWordIndex(
Tom Sepez281a9ea2016-02-26 14:24:28 -0800596 m_pEdit->SearchWordPlace(CFX_FloatPoint(rect.right, rect.bottom)));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700597}
598
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700599CFX_WideString CPWL_EditCtrl::GetText(int32_t& nStartChar,
600 int32_t& nEndChar) const {
601 CPVT_WordPlace wpStart = m_pEdit->WordIndexToWordPlace(nStartChar);
602 CPVT_WordPlace wpEnd = m_pEdit->WordIndexToWordPlace(nEndChar);
603 return m_pEdit->GetRangeText(CPVT_WordRange(wpStart, wpEnd));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700604}
605
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700606void CPWL_EditCtrl::SetReadyToInput() {
607 if (m_bMouseDown) {
608 ReleaseCapture();
609 m_bMouseDown = FALSE;
610 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700611}