blob: 1bb17db6de0fcea2a4802a06a09d4ea292c1a68e [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),
Nico Weber9d8ec5a2015-08-04 13:00:21 -070028 m_nCharSet(DEFAULT_CHARSET),
thestig732f6a02016-05-12 10:41:56 -070029 m_nCodePage(0) {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070030
dsinclairdbc77162016-07-13 11:34:23 -070031CPWL_EditCtrl::~CPWL_EditCtrl() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070032
Nico Weber9d8ec5a2015-08-04 13:00:21 -070033void CPWL_EditCtrl::OnCreate(PWL_CREATEPARAM& cp) {
34 cp.eCursorType = FXCT_VBEAM;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070035}
36
Nico Weber9d8ec5a2015-08-04 13:00:21 -070037void CPWL_EditCtrl::OnCreated() {
38 SetFontSize(GetCreationParam().fFontSize);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070039
Nico Weber9d8ec5a2015-08-04 13:00:21 -070040 m_pEdit->SetFontMap(GetFontMap());
41 m_pEdit->SetNotify(this);
42 m_pEdit->Initialize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070043}
44
Nico Weber9d8ec5a2015-08-04 13:00:21 -070045FX_BOOL CPWL_EditCtrl::IsWndHorV() {
Tom Sepez60d909e2015-12-10 15:34:55 -080046 CFX_Matrix mt = GetWindowMatrix();
Tom Sepez281a9ea2016-02-26 14:24:28 -080047 CFX_FloatPoint point1(0, 1);
48 CFX_FloatPoint point2(1, 1);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070049
Nico Weber9d8ec5a2015-08-04 13:00:21 -070050 mt.Transform(point1.x, point1.y);
51 mt.Transform(point2.x, point2.y);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070052
Nico Weber9d8ec5a2015-08-04 13:00:21 -070053 return point2.y == point1.y;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070054}
55
Nico Weber9d8ec5a2015-08-04 13:00:21 -070056void CPWL_EditCtrl::SetCursor() {
57 if (IsValid()) {
dsinclairb9590102016-04-27 06:38:59 -070058 if (CFX_SystemHandler* pSH = GetSystemHandler()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070059 if (IsWndHorV())
60 pSH->SetCursor(FXCT_VBEAM);
61 else
62 pSH->SetCursor(FXCT_HBEAM);
Tom Sepez2f2ffec2015-07-23 14:42:09 -070063 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070064 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070065}
66
Nico Weber9d8ec5a2015-08-04 13:00:21 -070067void CPWL_EditCtrl::RePosChildWnd() {
68 m_pEdit->SetPlateRect(GetClientRect());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070069}
70
Nico Weber9d8ec5a2015-08-04 13:00:21 -070071void CPWL_EditCtrl::OnNotify(CPWL_Wnd* pWnd,
tsepezc3255f52016-03-25 14:52:27 -070072 uint32_t msg,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070073 intptr_t wParam,
74 intptr_t lParam) {
75 CPWL_Wnd::OnNotify(pWnd, msg, wParam, lParam);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070076
Nico Weber9d8ec5a2015-08-04 13:00:21 -070077 switch (msg) {
78 case PNM_SETSCROLLINFO:
79 switch (wParam) {
80 case SBT_VSCROLL:
81 if (CPWL_Wnd* pChild = GetVScrollBar()) {
82 pChild->OnNotify(pWnd, PNM_SETSCROLLINFO, wParam, lParam);
83 }
84 break;
85 }
86 break;
87 case PNM_SETSCROLLPOS:
88 switch (wParam) {
89 case SBT_VSCROLL:
90 if (CPWL_Wnd* pChild = GetVScrollBar()) {
91 pChild->OnNotify(pWnd, PNM_SETSCROLLPOS, wParam, lParam);
92 }
93 break;
94 }
95 break;
96 case PNM_SCROLLWINDOW: {
97 FX_FLOAT fPos = *(FX_FLOAT*)lParam;
98 switch (wParam) {
99 case SBT_VSCROLL:
Tom Sepez281a9ea2016-02-26 14:24:28 -0800100 m_pEdit->SetScrollPos(
101 CFX_FloatPoint(m_pEdit->GetScrollPos().x, fPos));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700102 break;
103 }
104 } break;
105 case PNM_SETCARETINFO: {
106 if (PWL_CARET_INFO* pCaretInfo = (PWL_CARET_INFO*)wParam) {
107 SetCaret(pCaretInfo->bVisible, pCaretInfo->ptHead, pCaretInfo->ptFoot);
108 }
109 } break;
110 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700111}
112
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700113void CPWL_EditCtrl::CreateChildWnd(const PWL_CREATEPARAM& cp) {
114 if (!IsReadOnly())
115 CreateEditCaret(cp);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700116}
117
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700118void CPWL_EditCtrl::CreateEditCaret(const PWL_CREATEPARAM& cp) {
thestig732f6a02016-05-12 10:41:56 -0700119 if (m_pEditCaret)
120 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700121
thestig732f6a02016-05-12 10:41:56 -0700122 m_pEditCaret = new CPWL_Caret;
123 m_pEditCaret->SetInvalidRect(GetClientRect());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700124
thestig732f6a02016-05-12 10:41:56 -0700125 PWL_CREATEPARAM ecp = cp;
126 ecp.pParentWnd = this;
127 ecp.dwFlags = PWS_CHILD | PWS_NOREFRESHCLIP;
128 ecp.dwBorderWidth = 0;
dsinclair92cb5e52016-05-16 11:38:28 -0700129 ecp.nBorderStyle = BorderStyle::SOLID;
thestig732f6a02016-05-12 10:41:56 -0700130 ecp.rcRectWnd = CFX_FloatRect(0, 0, 0, 0);
131
132 m_pEditCaret->Create(ecp);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700133}
134
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700135void CPWL_EditCtrl::SetFontSize(FX_FLOAT fFontSize) {
136 m_pEdit->SetFontSize(fFontSize);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700137}
138
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700139FX_FLOAT CPWL_EditCtrl::GetFontSize() const {
140 return m_pEdit->GetFontSize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700141}
142
tsepezc3255f52016-03-25 14:52:27 -0700143FX_BOOL CPWL_EditCtrl::OnKeyDown(uint16_t nChar, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700144 if (m_bMouseDown)
145 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700146
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700147 FX_BOOL bRet = CPWL_Wnd::OnKeyDown(nChar, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700148
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700149 // FILTER
150 switch (nChar) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700151 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700152 return FALSE;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700153 case FWL_VKEY_Delete:
154 case FWL_VKEY_Up:
155 case FWL_VKEY_Down:
156 case FWL_VKEY_Left:
157 case FWL_VKEY_Right:
158 case FWL_VKEY_Home:
159 case FWL_VKEY_End:
160 case FWL_VKEY_Insert:
161 case 'C':
162 case 'V':
163 case 'X':
164 case 'A':
165 case 'Z':
166 case 'c':
167 case 'v':
168 case 'x':
169 case 'a':
170 case 'z':
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700171 break;
172 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700173
thestig594b20b2016-05-12 21:56:43 -0700174 if (nChar == FWL_VKEY_Delete && m_pEdit->IsSelected())
175 nChar = FWL_VKEY_Unknown;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700176
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700177 switch (nChar) {
178 case FWL_VKEY_Delete:
179 Delete();
180 return TRUE;
181 case FWL_VKEY_Insert:
182 if (IsSHIFTpressed(nFlag))
183 PasteText();
184 return TRUE;
185 case FWL_VKEY_Up:
186 m_pEdit->OnVK_UP(IsSHIFTpressed(nFlag), FALSE);
187 return TRUE;
188 case FWL_VKEY_Down:
189 m_pEdit->OnVK_DOWN(IsSHIFTpressed(nFlag), FALSE);
190 return TRUE;
191 case FWL_VKEY_Left:
192 m_pEdit->OnVK_LEFT(IsSHIFTpressed(nFlag), FALSE);
193 return TRUE;
194 case FWL_VKEY_Right:
195 m_pEdit->OnVK_RIGHT(IsSHIFTpressed(nFlag), FALSE);
196 return TRUE;
197 case FWL_VKEY_Home:
198 m_pEdit->OnVK_HOME(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
199 return TRUE;
200 case FWL_VKEY_End:
201 m_pEdit->OnVK_END(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
202 return TRUE;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700203 case FWL_VKEY_Unknown:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700204 if (!IsSHIFTpressed(nFlag))
205 Clear();
206 else
207 CutText();
208 return TRUE;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700209 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700210 break;
211 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700212
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700213 return bRet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700214}
215
tsepezc3255f52016-03-25 14:52:27 -0700216FX_BOOL CPWL_EditCtrl::OnChar(uint16_t nChar, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700217 if (m_bMouseDown)
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700218 return TRUE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700219
220 CPWL_Wnd::OnChar(nChar, nFlag);
221
222 // FILTER
223 switch (nChar) {
224 case 0x0A:
225 case 0x1B:
226 return FALSE;
227 default:
228 break;
229 }
230
231 FX_BOOL bCtrl = IsCTRLpressed(nFlag);
232 FX_BOOL bAlt = IsALTpressed(nFlag);
233 FX_BOOL bShift = IsSHIFTpressed(nFlag);
234
Tom Sepez62a70f92016-03-21 15:00:20 -0700235 uint16_t word = nChar;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700236
237 if (bCtrl && !bAlt) {
238 switch (nChar) {
239 case 'C' - 'A' + 1:
240 CopyText();
241 return TRUE;
242 case 'V' - 'A' + 1:
243 PasteText();
244 return TRUE;
245 case 'X' - 'A' + 1:
246 CutText();
247 return TRUE;
248 case 'A' - 'A' + 1:
249 SelectAll();
250 return TRUE;
251 case 'Z' - 'A' + 1:
252 if (bShift)
253 Redo();
254 else
255 Undo();
256 return TRUE;
257 default:
258 if (nChar < 32)
259 return FALSE;
260 }
261 }
262
263 if (IsReadOnly())
264 return TRUE;
265
266 if (m_pEdit->IsSelected() && word == FWL_VKEY_Back)
267 word = FWL_VKEY_Unknown;
268
269 Clear();
270
271 switch (word) {
272 case FWL_VKEY_Back:
273 Backspace();
274 break;
275 case FWL_VKEY_Return:
276 InsertReturn();
277 break;
278 case FWL_VKEY_Unknown:
279 break;
280 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700281 InsertWord(word, GetCharSet());
282 break;
283 }
284
285 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700286}
287
Tom Sepez281a9ea2016-02-26 14:24:28 -0800288FX_BOOL CPWL_EditCtrl::OnLButtonDown(const CFX_FloatPoint& point,
tsepezc3255f52016-03-25 14:52:27 -0700289 uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700290 CPWL_Wnd::OnLButtonDown(point, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700291
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700292 if (ClientHitTest(point)) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700293 if (m_bMouseDown)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700294 InvalidateRect();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700295
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700296 m_bMouseDown = TRUE;
297 SetCapture();
298
299 m_pEdit->OnMouseDown(point, IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
300 }
301
302 return TRUE;
303}
304
Tom Sepez281a9ea2016-02-26 14:24:28 -0800305FX_BOOL CPWL_EditCtrl::OnLButtonUp(const CFX_FloatPoint& point,
tsepezc3255f52016-03-25 14:52:27 -0700306 uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700307 CPWL_Wnd::OnLButtonUp(point, nFlag);
308
309 if (m_bMouseDown) {
310 // can receive keybord message
311 if (ClientHitTest(point) && !IsFocused())
312 SetFocus();
313
314 ReleaseCapture();
315 m_bMouseDown = FALSE;
316 }
317
318 return TRUE;
319}
320
Tom Sepez281a9ea2016-02-26 14:24:28 -0800321FX_BOOL CPWL_EditCtrl::OnMouseMove(const CFX_FloatPoint& point,
tsepezc3255f52016-03-25 14:52:27 -0700322 uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700323 CPWL_Wnd::OnMouseMove(point, nFlag);
324
325 if (m_bMouseDown)
326 m_pEdit->OnMouseMove(point, FALSE, FALSE);
327
328 return TRUE;
329}
330
Tom Sepez281a9ea2016-02-26 14:24:28 -0800331CFX_FloatRect CPWL_EditCtrl::GetContentRect() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700332 return m_pEdit->GetContentRect();
333}
334
335void CPWL_EditCtrl::SetEditCaret(FX_BOOL bVisible) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800336 CFX_FloatPoint ptHead(0, 0), ptFoot(0, 0);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700337
338 if (bVisible) {
339 GetCaretInfo(ptHead, ptFoot);
340 }
341
342 CPVT_WordPlace wpTemp = m_pEdit->GetCaretWordPlace();
343 IOnSetCaret(bVisible, ptHead, ptFoot, wpTemp);
344}
345
Tom Sepez281a9ea2016-02-26 14:24:28 -0800346void CPWL_EditCtrl::GetCaretInfo(CFX_FloatPoint& ptHead,
347 CFX_FloatPoint& ptFoot) const {
dsinclaire35af1e2016-07-13 11:26:20 -0700348 CFX_Edit_Iterator* pIterator = m_pEdit->GetIterator();
thestig821d59e2016-05-11 12:59:22 -0700349 pIterator->SetAt(m_pEdit->GetCaret());
350 CPVT_Word word;
351 CPVT_Line line;
352 if (pIterator->GetWord(word)) {
353 ptHead.x = word.ptWord.x + word.fWidth;
354 ptHead.y = word.ptWord.y + word.fAscent;
355 ptFoot.x = word.ptWord.x + word.fWidth;
356 ptFoot.y = word.ptWord.y + word.fDescent;
357 } else if (pIterator->GetLine(line)) {
358 ptHead.x = line.ptLine.x;
359 ptHead.y = line.ptLine.y + line.fLineAscent;
360 ptFoot.x = line.ptLine.x;
361 ptFoot.y = line.ptLine.y + line.fLineDescent;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700362 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700363}
364
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700365void CPWL_EditCtrl::GetCaretPos(int32_t& x, int32_t& y) const {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800366 CFX_FloatPoint ptHead(0, 0), ptFoot(0, 0);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700367
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700368 GetCaretInfo(ptHead, ptFoot);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700369
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700370 PWLtoWnd(ptHead, x, y);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700371}
372
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700373void CPWL_EditCtrl::SetCaret(FX_BOOL bVisible,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800374 const CFX_FloatPoint& ptHead,
375 const CFX_FloatPoint& ptFoot) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700376 if (m_pEditCaret) {
377 if (!IsFocused() || m_pEdit->IsSelected())
378 bVisible = FALSE;
379
380 m_pEditCaret->SetCaret(bVisible, ptHead, ptFoot);
381 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700382}
383
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700384CFX_WideString CPWL_EditCtrl::GetText() const {
385 return m_pEdit->GetText();
386}
387
388void CPWL_EditCtrl::SetSel(int32_t nStartChar, int32_t nEndChar) {
389 m_pEdit->SetSel(nStartChar, nEndChar);
390}
391
392void CPWL_EditCtrl::GetSel(int32_t& nStartChar, int32_t& nEndChar) const {
393 m_pEdit->GetSel(nStartChar, nEndChar);
394}
395
396void CPWL_EditCtrl::Clear() {
397 if (!IsReadOnly())
398 m_pEdit->Clear();
399}
400
401void CPWL_EditCtrl::SelectAll() {
402 m_pEdit->SelectAll();
403}
404
405void CPWL_EditCtrl::Paint() {
thestig732f6a02016-05-12 10:41:56 -0700406 m_pEdit->Paint();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700407}
408
409void CPWL_EditCtrl::EnableRefresh(FX_BOOL bRefresh) {
thestig732f6a02016-05-12 10:41:56 -0700410 m_pEdit->EnableRefresh(bRefresh);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700411}
412
413int32_t CPWL_EditCtrl::GetCaret() const {
thestig732f6a02016-05-12 10:41:56 -0700414 return m_pEdit->GetCaret();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700415}
416
417void CPWL_EditCtrl::SetCaret(int32_t nPos) {
thestig732f6a02016-05-12 10:41:56 -0700418 m_pEdit->SetCaret(nPos);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700419}
420
421int32_t CPWL_EditCtrl::GetTotalWords() const {
thestig732f6a02016-05-12 10:41:56 -0700422 return m_pEdit->GetTotalWords();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700423}
424
Tom Sepez281a9ea2016-02-26 14:24:28 -0800425void CPWL_EditCtrl::SetScrollPos(const CFX_FloatPoint& point) {
thestig732f6a02016-05-12 10:41:56 -0700426 m_pEdit->SetScrollPos(point);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700427}
428
Tom Sepez281a9ea2016-02-26 14:24:28 -0800429CFX_FloatPoint CPWL_EditCtrl::GetScrollPos() const {
thestig732f6a02016-05-12 10:41:56 -0700430 return m_pEdit->GetScrollPos();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700431}
432
433CPDF_Font* CPWL_EditCtrl::GetCaretFont() const {
434 int32_t nFontIndex = 0;
435
dsinclaire35af1e2016-07-13 11:26:20 -0700436 CFX_Edit_Iterator* pIterator = m_pEdit->GetIterator();
thestig821d59e2016-05-11 12:59:22 -0700437 pIterator->SetAt(m_pEdit->GetCaret());
438 CPVT_Word word;
439 CPVT_Section section;
440 if (pIterator->GetWord(word)) {
441 nFontIndex = word.nFontIndex;
442 } else if (HasFlag(PES_RICH)) {
443 if (pIterator->GetSection(section)) {
444 nFontIndex = section.WordProps.nFontIndex;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700445 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700446 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700447
dsinclairc7a73492016-04-05 12:01:42 -0700448 if (IPVT_FontMap* pFontMap = GetFontMap())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700449 return pFontMap->GetPDFFont(nFontIndex);
450
thestig1cd352e2016-06-07 17:53:06 -0700451 return nullptr;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700452}
453
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700454FX_FLOAT CPWL_EditCtrl::GetCaretFontSize() const {
455 FX_FLOAT fFontSize = GetFontSize();
456
dsinclaire35af1e2016-07-13 11:26:20 -0700457 CFX_Edit_Iterator* pIterator = m_pEdit->GetIterator();
thestig821d59e2016-05-11 12:59:22 -0700458 pIterator->SetAt(m_pEdit->GetCaret());
459 CPVT_Word word;
460 CPVT_Section section;
461 if (pIterator->GetWord(word)) {
462 fFontSize = word.fFontSize;
463 } else if (HasFlag(PES_RICH)) {
464 if (pIterator->GetSection(section)) {
465 fFontSize = section.WordProps.fFontSize;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700466 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700467 }
468
469 return fFontSize;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700470}
471
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700472void CPWL_EditCtrl::SetText(const FX_WCHAR* csText) {
473 m_pEdit->SetText(csText);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700474}
475
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700476void CPWL_EditCtrl::CopyText() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700477
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700478void CPWL_EditCtrl::PasteText() {}
479
480void CPWL_EditCtrl::CutText() {}
481
482void CPWL_EditCtrl::ShowVScrollBar(FX_BOOL bShow) {}
483
484void CPWL_EditCtrl::InsertText(const FX_WCHAR* csText) {
485 if (!IsReadOnly())
486 m_pEdit->InsertText(csText);
487}
488
Tom Sepez62a70f92016-03-21 15:00:20 -0700489void CPWL_EditCtrl::InsertWord(uint16_t word, int32_t nCharset) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700490 if (!IsReadOnly())
491 m_pEdit->InsertWord(word, nCharset);
492}
493
494void CPWL_EditCtrl::InsertReturn() {
495 if (!IsReadOnly())
496 m_pEdit->InsertReturn();
497}
498
499void CPWL_EditCtrl::Delete() {
500 if (!IsReadOnly())
501 m_pEdit->Delete();
502}
503
504void CPWL_EditCtrl::Backspace() {
505 if (!IsReadOnly())
506 m_pEdit->Backspace();
507}
508
509FX_BOOL CPWL_EditCtrl::CanUndo() const {
510 return !IsReadOnly() && m_pEdit->CanUndo();
511}
512
513FX_BOOL CPWL_EditCtrl::CanRedo() const {
514 return !IsReadOnly() && m_pEdit->CanRedo();
515}
516
517void CPWL_EditCtrl::Redo() {
518 if (CanRedo())
519 m_pEdit->Redo();
520}
521
522void CPWL_EditCtrl::Undo() {
523 if (CanUndo())
524 m_pEdit->Undo();
525}
526
527void CPWL_EditCtrl::IOnSetScrollInfoY(FX_FLOAT fPlateMin,
528 FX_FLOAT fPlateMax,
529 FX_FLOAT fContentMin,
530 FX_FLOAT fContentMax,
531 FX_FLOAT fSmallStep,
532 FX_FLOAT fBigStep) {
533 PWL_SCROLL_INFO Info;
534
535 Info.fPlateWidth = fPlateMax - fPlateMin;
536 Info.fContentMin = fContentMin;
537 Info.fContentMax = fContentMax;
538 Info.fSmallStep = fSmallStep;
539 Info.fBigStep = fBigStep;
540
541 OnNotify(this, PNM_SETSCROLLINFO, SBT_VSCROLL, (intptr_t)&Info);
542
543 if (IsFloatBigger(Info.fPlateWidth, Info.fContentMax - Info.fContentMin) ||
544 IsFloatEqual(Info.fPlateWidth, Info.fContentMax - Info.fContentMin)) {
545 ShowVScrollBar(FALSE);
546 } else {
547 ShowVScrollBar(TRUE);
548 }
549}
550
551void CPWL_EditCtrl::IOnSetScrollPosY(FX_FLOAT fy) {
552 OnNotify(this, PNM_SETSCROLLPOS, SBT_VSCROLL, (intptr_t)&fy);
553}
554
555void CPWL_EditCtrl::IOnSetCaret(FX_BOOL bVisible,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800556 const CFX_FloatPoint& ptHead,
557 const CFX_FloatPoint& ptFoot,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700558 const CPVT_WordPlace& place) {
559 PWL_CARET_INFO cInfo;
560 cInfo.bVisible = bVisible;
561 cInfo.ptHead = ptHead;
562 cInfo.ptFoot = ptFoot;
563
thestig1cd352e2016-06-07 17:53:06 -0700564 OnNotify(this, PNM_SETCARETINFO, (intptr_t)&cInfo, (intptr_t) nullptr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700565}
566
dsinclairdbc77162016-07-13 11:34:23 -0700567void CPWL_EditCtrl::IOnCaretChange(const CPVT_SecProps& secProps,
568 const CPVT_WordProps& wordProps) {}
569
570void CPWL_EditCtrl::IOnContentChange(const CFX_FloatRect& rcContent) {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700571
Tom Sepez281a9ea2016-02-26 14:24:28 -0800572void CPWL_EditCtrl::IOnInvalidateRect(CFX_FloatRect* pRect) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700573 InvalidateRect(pRect);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700574}
575
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700576int32_t CPWL_EditCtrl::GetCharSet() const {
577 return m_nCharSet < 0 ? DEFAULT_CHARSET : m_nCharSet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700578}
579
Tom Sepez281a9ea2016-02-26 14:24:28 -0800580void CPWL_EditCtrl::GetTextRange(const CFX_FloatRect& rect,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700581 int32_t& nStartChar,
582 int32_t& nEndChar) const {
583 nStartChar = m_pEdit->WordPlaceToWordIndex(
Tom Sepez281a9ea2016-02-26 14:24:28 -0800584 m_pEdit->SearchWordPlace(CFX_FloatPoint(rect.left, rect.top)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700585 nEndChar = m_pEdit->WordPlaceToWordIndex(
Tom Sepez281a9ea2016-02-26 14:24:28 -0800586 m_pEdit->SearchWordPlace(CFX_FloatPoint(rect.right, rect.bottom)));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700587}
588
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700589CFX_WideString CPWL_EditCtrl::GetText(int32_t& nStartChar,
590 int32_t& nEndChar) const {
591 CPVT_WordPlace wpStart = m_pEdit->WordIndexToWordPlace(nStartChar);
592 CPVT_WordPlace wpEnd = m_pEdit->WordIndexToWordPlace(nEndChar);
593 return m_pEdit->GetRangeText(CPVT_WordRange(wpStart, wpEnd));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700594}
595
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700596void CPWL_EditCtrl::SetReadyToInput() {
597 if (m_bMouseDown) {
598 ReleaseCapture();
599 m_bMouseDown = FALSE;
600 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700601}