blob: 07ac4af781a561dc83eb1fbf44f641eb96bcf3ce [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()
24 : m_pEdit(NULL),
25 m_pEditCaret(NULL),
26 m_bMouseDown(FALSE),
27 m_pEditNotify(NULL),
28 m_nCharSet(DEFAULT_CHARSET),
29 m_nCodePage(0) {
30 m_pEdit = IFX_Edit::NewEdit();
Lei Zhang96660d62015-12-14 18:27:25 -080031 ASSERT(m_pEdit);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070032}
33
Nico Weber9d8ec5a2015-08-04 13:00:21 -070034CPWL_EditCtrl::~CPWL_EditCtrl() {
35 IFX_Edit::DelEdit(m_pEdit);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070036}
37
Nico Weber9d8ec5a2015-08-04 13:00:21 -070038void CPWL_EditCtrl::OnCreate(PWL_CREATEPARAM& cp) {
39 cp.eCursorType = FXCT_VBEAM;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070040}
41
Nico Weber9d8ec5a2015-08-04 13:00:21 -070042void CPWL_EditCtrl::OnCreated() {
43 SetFontSize(GetCreationParam().fFontSize);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070044
Nico Weber9d8ec5a2015-08-04 13:00:21 -070045 m_pEdit->SetFontMap(GetFontMap());
46 m_pEdit->SetNotify(this);
47 m_pEdit->Initialize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070048}
49
Nico Weber9d8ec5a2015-08-04 13:00:21 -070050FX_BOOL CPWL_EditCtrl::IsWndHorV() {
Tom Sepez60d909e2015-12-10 15:34:55 -080051 CFX_Matrix mt = GetWindowMatrix();
Tom Sepez281a9ea2016-02-26 14:24:28 -080052 CFX_FloatPoint point1(0, 1);
53 CFX_FloatPoint point2(1, 1);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070054
Nico Weber9d8ec5a2015-08-04 13:00:21 -070055 mt.Transform(point1.x, point1.y);
56 mt.Transform(point2.x, point2.y);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070057
Nico Weber9d8ec5a2015-08-04 13:00:21 -070058 return point2.y == point1.y;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070059}
60
Nico Weber9d8ec5a2015-08-04 13:00:21 -070061void CPWL_EditCtrl::SetCursor() {
62 if (IsValid()) {
dsinclairb9590102016-04-27 06:38:59 -070063 if (CFX_SystemHandler* pSH = GetSystemHandler()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070064 if (IsWndHorV())
65 pSH->SetCursor(FXCT_VBEAM);
66 else
67 pSH->SetCursor(FXCT_HBEAM);
Tom Sepez2f2ffec2015-07-23 14:42:09 -070068 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070069 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070070}
71
Nico Weber9d8ec5a2015-08-04 13:00:21 -070072void CPWL_EditCtrl::RePosChildWnd() {
73 m_pEdit->SetPlateRect(GetClientRect());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070074}
75
Nico Weber9d8ec5a2015-08-04 13:00:21 -070076void CPWL_EditCtrl::OnNotify(CPWL_Wnd* pWnd,
tsepezc3255f52016-03-25 14:52:27 -070077 uint32_t msg,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070078 intptr_t wParam,
79 intptr_t lParam) {
80 CPWL_Wnd::OnNotify(pWnd, msg, wParam, lParam);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070081
Nico Weber9d8ec5a2015-08-04 13:00:21 -070082 switch (msg) {
83 case PNM_SETSCROLLINFO:
84 switch (wParam) {
85 case SBT_VSCROLL:
86 if (CPWL_Wnd* pChild = GetVScrollBar()) {
87 pChild->OnNotify(pWnd, PNM_SETSCROLLINFO, wParam, lParam);
88 }
89 break;
90 }
91 break;
92 case PNM_SETSCROLLPOS:
93 switch (wParam) {
94 case SBT_VSCROLL:
95 if (CPWL_Wnd* pChild = GetVScrollBar()) {
96 pChild->OnNotify(pWnd, PNM_SETSCROLLPOS, wParam, lParam);
97 }
98 break;
99 }
100 break;
101 case PNM_SCROLLWINDOW: {
102 FX_FLOAT fPos = *(FX_FLOAT*)lParam;
103 switch (wParam) {
104 case SBT_VSCROLL:
Tom Sepez281a9ea2016-02-26 14:24:28 -0800105 m_pEdit->SetScrollPos(
106 CFX_FloatPoint(m_pEdit->GetScrollPos().x, fPos));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700107 break;
108 }
109 } break;
110 case PNM_SETCARETINFO: {
111 if (PWL_CARET_INFO* pCaretInfo = (PWL_CARET_INFO*)wParam) {
112 SetCaret(pCaretInfo->bVisible, pCaretInfo->ptHead, pCaretInfo->ptFoot);
113 }
114 } break;
115 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700116}
117
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700118void CPWL_EditCtrl::CreateChildWnd(const PWL_CREATEPARAM& cp) {
119 if (!IsReadOnly())
120 CreateEditCaret(cp);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700121}
122
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700123void CPWL_EditCtrl::CreateEditCaret(const PWL_CREATEPARAM& cp) {
124 if (!m_pEditCaret) {
125 m_pEditCaret = new CPWL_Caret;
126 m_pEditCaret->SetInvalidRect(GetClientRect());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700127
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700128 PWL_CREATEPARAM ecp = cp;
129 ecp.pParentWnd = this;
130 ecp.dwFlags = PWS_CHILD | PWS_NOREFRESHCLIP;
131 ecp.dwBorderWidth = 0;
132 ecp.nBorderStyle = PBS_SOLID;
Tom Sepez281a9ea2016-02-26 14:24:28 -0800133 ecp.rcRectWnd = CFX_FloatRect(0, 0, 0, 0);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700134
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700135 m_pEditCaret->Create(ecp);
136 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700137}
138
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700139void CPWL_EditCtrl::SetFontSize(FX_FLOAT fFontSize) {
140 m_pEdit->SetFontSize(fFontSize);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700141}
142
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700143FX_FLOAT CPWL_EditCtrl::GetFontSize() const {
144 return m_pEdit->GetFontSize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700145}
146
tsepezc3255f52016-03-25 14:52:27 -0700147FX_BOOL CPWL_EditCtrl::OnKeyDown(uint16_t nChar, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700148 if (m_bMouseDown)
149 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700150
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700151 FX_BOOL bRet = CPWL_Wnd::OnKeyDown(nChar, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700152
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700153 // FILTER
154 switch (nChar) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700155 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700156 return FALSE;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700157 case FWL_VKEY_Delete:
158 case FWL_VKEY_Up:
159 case FWL_VKEY_Down:
160 case FWL_VKEY_Left:
161 case FWL_VKEY_Right:
162 case FWL_VKEY_Home:
163 case FWL_VKEY_End:
164 case FWL_VKEY_Insert:
165 case 'C':
166 case 'V':
167 case 'X':
168 case 'A':
169 case 'Z':
170 case 'c':
171 case 'v':
172 case 'x':
173 case 'a':
174 case 'z':
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700175 break;
176 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700177
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700178 if (nChar == FWL_VKEY_Delete) {
179 if (m_pEdit->IsSelected())
180 nChar = FWL_VKEY_Unknown;
181 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700182
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700183 switch (nChar) {
184 case FWL_VKEY_Delete:
185 Delete();
186 return TRUE;
187 case FWL_VKEY_Insert:
188 if (IsSHIFTpressed(nFlag))
189 PasteText();
190 return TRUE;
191 case FWL_VKEY_Up:
192 m_pEdit->OnVK_UP(IsSHIFTpressed(nFlag), FALSE);
193 return TRUE;
194 case FWL_VKEY_Down:
195 m_pEdit->OnVK_DOWN(IsSHIFTpressed(nFlag), FALSE);
196 return TRUE;
197 case FWL_VKEY_Left:
198 m_pEdit->OnVK_LEFT(IsSHIFTpressed(nFlag), FALSE);
199 return TRUE;
200 case FWL_VKEY_Right:
201 m_pEdit->OnVK_RIGHT(IsSHIFTpressed(nFlag), FALSE);
202 return TRUE;
203 case FWL_VKEY_Home:
204 m_pEdit->OnVK_HOME(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
205 return TRUE;
206 case FWL_VKEY_End:
207 m_pEdit->OnVK_END(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
208 return TRUE;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700209 case FWL_VKEY_Unknown:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700210 if (!IsSHIFTpressed(nFlag))
211 Clear();
212 else
213 CutText();
214 return TRUE;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700215 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700216 break;
217 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700218
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700219 return bRet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700220}
221
tsepezc3255f52016-03-25 14:52:27 -0700222FX_BOOL CPWL_EditCtrl::OnChar(uint16_t nChar, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700223 if (m_bMouseDown)
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700224 return TRUE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700225
226 CPWL_Wnd::OnChar(nChar, nFlag);
227
228 // FILTER
229 switch (nChar) {
230 case 0x0A:
231 case 0x1B:
232 return FALSE;
233 default:
234 break;
235 }
236
237 FX_BOOL bCtrl = IsCTRLpressed(nFlag);
238 FX_BOOL bAlt = IsALTpressed(nFlag);
239 FX_BOOL bShift = IsSHIFTpressed(nFlag);
240
Tom Sepez62a70f92016-03-21 15:00:20 -0700241 uint16_t word = nChar;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700242
243 if (bCtrl && !bAlt) {
244 switch (nChar) {
245 case 'C' - 'A' + 1:
246 CopyText();
247 return TRUE;
248 case 'V' - 'A' + 1:
249 PasteText();
250 return TRUE;
251 case 'X' - 'A' + 1:
252 CutText();
253 return TRUE;
254 case 'A' - 'A' + 1:
255 SelectAll();
256 return TRUE;
257 case 'Z' - 'A' + 1:
258 if (bShift)
259 Redo();
260 else
261 Undo();
262 return TRUE;
263 default:
264 if (nChar < 32)
265 return FALSE;
266 }
267 }
268
269 if (IsReadOnly())
270 return TRUE;
271
272 if (m_pEdit->IsSelected() && word == FWL_VKEY_Back)
273 word = FWL_VKEY_Unknown;
274
275 Clear();
276
277 switch (word) {
278 case FWL_VKEY_Back:
279 Backspace();
280 break;
281 case FWL_VKEY_Return:
282 InsertReturn();
283 break;
284 case FWL_VKEY_Unknown:
285 break;
286 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700287 InsertWord(word, GetCharSet());
288 break;
289 }
290
291 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700292}
293
Tom Sepez281a9ea2016-02-26 14:24:28 -0800294FX_BOOL CPWL_EditCtrl::OnLButtonDown(const CFX_FloatPoint& point,
tsepezc3255f52016-03-25 14:52:27 -0700295 uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700296 CPWL_Wnd::OnLButtonDown(point, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700297
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700298 if (ClientHitTest(point)) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700299 if (m_bMouseDown)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700300 InvalidateRect();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700301
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700302 m_bMouseDown = TRUE;
303 SetCapture();
304
305 m_pEdit->OnMouseDown(point, IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
306 }
307
308 return TRUE;
309}
310
Tom Sepez281a9ea2016-02-26 14:24:28 -0800311FX_BOOL CPWL_EditCtrl::OnLButtonUp(const CFX_FloatPoint& point,
tsepezc3255f52016-03-25 14:52:27 -0700312 uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700313 CPWL_Wnd::OnLButtonUp(point, nFlag);
314
315 if (m_bMouseDown) {
316 // can receive keybord message
317 if (ClientHitTest(point) && !IsFocused())
318 SetFocus();
319
320 ReleaseCapture();
321 m_bMouseDown = FALSE;
322 }
323
324 return TRUE;
325}
326
Tom Sepez281a9ea2016-02-26 14:24:28 -0800327FX_BOOL CPWL_EditCtrl::OnMouseMove(const CFX_FloatPoint& point,
tsepezc3255f52016-03-25 14:52:27 -0700328 uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700329 CPWL_Wnd::OnMouseMove(point, nFlag);
330
331 if (m_bMouseDown)
332 m_pEdit->OnMouseMove(point, FALSE, FALSE);
333
334 return TRUE;
335}
336
Tom Sepez281a9ea2016-02-26 14:24:28 -0800337CFX_FloatRect CPWL_EditCtrl::GetContentRect() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700338 return m_pEdit->GetContentRect();
339}
340
341void CPWL_EditCtrl::SetEditCaret(FX_BOOL bVisible) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800342 CFX_FloatPoint ptHead(0, 0), ptFoot(0, 0);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700343
344 if (bVisible) {
345 GetCaretInfo(ptHead, ptFoot);
346 }
347
348 CPVT_WordPlace wpTemp = m_pEdit->GetCaretWordPlace();
349 IOnSetCaret(bVisible, ptHead, ptFoot, wpTemp);
350}
351
Tom Sepez281a9ea2016-02-26 14:24:28 -0800352void CPWL_EditCtrl::GetCaretInfo(CFX_FloatPoint& ptHead,
353 CFX_FloatPoint& ptFoot) const {
thestig821d59e2016-05-11 12:59:22 -0700354 IFX_Edit_Iterator* pIterator = m_pEdit->GetIterator();
355 pIterator->SetAt(m_pEdit->GetCaret());
356 CPVT_Word word;
357 CPVT_Line line;
358 if (pIterator->GetWord(word)) {
359 ptHead.x = word.ptWord.x + word.fWidth;
360 ptHead.y = word.ptWord.y + word.fAscent;
361 ptFoot.x = word.ptWord.x + word.fWidth;
362 ptFoot.y = word.ptWord.y + word.fDescent;
363 } else if (pIterator->GetLine(line)) {
364 ptHead.x = line.ptLine.x;
365 ptHead.y = line.ptLine.y + line.fLineAscent;
366 ptFoot.x = line.ptLine.x;
367 ptFoot.y = line.ptLine.y + line.fLineDescent;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700368 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700369}
370
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700371void CPWL_EditCtrl::GetCaretPos(int32_t& x, int32_t& y) const {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800372 CFX_FloatPoint ptHead(0, 0), ptFoot(0, 0);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700373
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700374 GetCaretInfo(ptHead, ptFoot);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700375
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700376 PWLtoWnd(ptHead, x, y);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700377}
378
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700379void CPWL_EditCtrl::SetCaret(FX_BOOL bVisible,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800380 const CFX_FloatPoint& ptHead,
381 const CFX_FloatPoint& ptFoot) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700382 if (m_pEditCaret) {
383 if (!IsFocused() || m_pEdit->IsSelected())
384 bVisible = FALSE;
385
386 m_pEditCaret->SetCaret(bVisible, ptHead, ptFoot);
387 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700388}
389
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700390CFX_WideString CPWL_EditCtrl::GetText() const {
391 return m_pEdit->GetText();
392}
393
394void CPWL_EditCtrl::SetSel(int32_t nStartChar, int32_t nEndChar) {
395 m_pEdit->SetSel(nStartChar, nEndChar);
396}
397
398void CPWL_EditCtrl::GetSel(int32_t& nStartChar, int32_t& nEndChar) const {
399 m_pEdit->GetSel(nStartChar, nEndChar);
400}
401
402void CPWL_EditCtrl::Clear() {
403 if (!IsReadOnly())
404 m_pEdit->Clear();
405}
406
407void CPWL_EditCtrl::SelectAll() {
408 m_pEdit->SelectAll();
409}
410
411void CPWL_EditCtrl::Paint() {
412 if (m_pEdit)
413 m_pEdit->Paint();
414}
415
416void CPWL_EditCtrl::EnableRefresh(FX_BOOL bRefresh) {
417 if (m_pEdit)
418 m_pEdit->EnableRefresh(bRefresh);
419}
420
421int32_t CPWL_EditCtrl::GetCaret() const {
422 if (m_pEdit)
423 return m_pEdit->GetCaret();
424
425 return -1;
426}
427
428void CPWL_EditCtrl::SetCaret(int32_t nPos) {
429 if (m_pEdit)
430 m_pEdit->SetCaret(nPos);
431}
432
433int32_t CPWL_EditCtrl::GetTotalWords() const {
434 if (m_pEdit)
435 return m_pEdit->GetTotalWords();
436
437 return 0;
438}
439
Tom Sepez281a9ea2016-02-26 14:24:28 -0800440void CPWL_EditCtrl::SetScrollPos(const CFX_FloatPoint& point) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700441 if (m_pEdit)
442 m_pEdit->SetScrollPos(point);
443}
444
Tom Sepez281a9ea2016-02-26 14:24:28 -0800445CFX_FloatPoint CPWL_EditCtrl::GetScrollPos() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700446 if (m_pEdit)
447 return m_pEdit->GetScrollPos();
448
Tom Sepez281a9ea2016-02-26 14:24:28 -0800449 return CFX_FloatPoint(0.0f, 0.0f);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700450}
451
452CPDF_Font* CPWL_EditCtrl::GetCaretFont() const {
453 int32_t nFontIndex = 0;
454
thestig821d59e2016-05-11 12:59:22 -0700455 IFX_Edit_Iterator* pIterator = m_pEdit->GetIterator();
456 pIterator->SetAt(m_pEdit->GetCaret());
457 CPVT_Word word;
458 CPVT_Section section;
459 if (pIterator->GetWord(word)) {
460 nFontIndex = word.nFontIndex;
461 } else if (HasFlag(PES_RICH)) {
462 if (pIterator->GetSection(section)) {
463 nFontIndex = section.WordProps.nFontIndex;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700464 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700465 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700466
dsinclairc7a73492016-04-05 12:01:42 -0700467 if (IPVT_FontMap* pFontMap = GetFontMap())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700468 return pFontMap->GetPDFFont(nFontIndex);
469
470 return NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700471}
472
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700473FX_FLOAT CPWL_EditCtrl::GetCaretFontSize() const {
474 FX_FLOAT fFontSize = GetFontSize();
475
thestig821d59e2016-05-11 12:59:22 -0700476 IFX_Edit_Iterator* pIterator = m_pEdit->GetIterator();
477 pIterator->SetAt(m_pEdit->GetCaret());
478 CPVT_Word word;
479 CPVT_Section section;
480 if (pIterator->GetWord(word)) {
481 fFontSize = word.fFontSize;
482 } else if (HasFlag(PES_RICH)) {
483 if (pIterator->GetSection(section)) {
484 fFontSize = section.WordProps.fFontSize;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700485 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700486 }
487
488 return fFontSize;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700489}
490
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700491void CPWL_EditCtrl::SetText(const FX_WCHAR* csText) {
492 m_pEdit->SetText(csText);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700493}
494
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700495void CPWL_EditCtrl::CopyText() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700496
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700497void CPWL_EditCtrl::PasteText() {}
498
499void CPWL_EditCtrl::CutText() {}
500
501void CPWL_EditCtrl::ShowVScrollBar(FX_BOOL bShow) {}
502
503void CPWL_EditCtrl::InsertText(const FX_WCHAR* csText) {
504 if (!IsReadOnly())
505 m_pEdit->InsertText(csText);
506}
507
Tom Sepez62a70f92016-03-21 15:00:20 -0700508void CPWL_EditCtrl::InsertWord(uint16_t word, int32_t nCharset) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700509 if (!IsReadOnly())
510 m_pEdit->InsertWord(word, nCharset);
511}
512
513void CPWL_EditCtrl::InsertReturn() {
514 if (!IsReadOnly())
515 m_pEdit->InsertReturn();
516}
517
518void CPWL_EditCtrl::Delete() {
519 if (!IsReadOnly())
520 m_pEdit->Delete();
521}
522
523void CPWL_EditCtrl::Backspace() {
524 if (!IsReadOnly())
525 m_pEdit->Backspace();
526}
527
528FX_BOOL CPWL_EditCtrl::CanUndo() const {
529 return !IsReadOnly() && m_pEdit->CanUndo();
530}
531
532FX_BOOL CPWL_EditCtrl::CanRedo() const {
533 return !IsReadOnly() && m_pEdit->CanRedo();
534}
535
536void CPWL_EditCtrl::Redo() {
537 if (CanRedo())
538 m_pEdit->Redo();
539}
540
541void CPWL_EditCtrl::Undo() {
542 if (CanUndo())
543 m_pEdit->Undo();
544}
545
546void CPWL_EditCtrl::IOnSetScrollInfoY(FX_FLOAT fPlateMin,
547 FX_FLOAT fPlateMax,
548 FX_FLOAT fContentMin,
549 FX_FLOAT fContentMax,
550 FX_FLOAT fSmallStep,
551 FX_FLOAT fBigStep) {
552 PWL_SCROLL_INFO Info;
553
554 Info.fPlateWidth = fPlateMax - fPlateMin;
555 Info.fContentMin = fContentMin;
556 Info.fContentMax = fContentMax;
557 Info.fSmallStep = fSmallStep;
558 Info.fBigStep = fBigStep;
559
560 OnNotify(this, PNM_SETSCROLLINFO, SBT_VSCROLL, (intptr_t)&Info);
561
562 if (IsFloatBigger(Info.fPlateWidth, Info.fContentMax - Info.fContentMin) ||
563 IsFloatEqual(Info.fPlateWidth, Info.fContentMax - Info.fContentMin)) {
564 ShowVScrollBar(FALSE);
565 } else {
566 ShowVScrollBar(TRUE);
567 }
568}
569
570void CPWL_EditCtrl::IOnSetScrollPosY(FX_FLOAT fy) {
571 OnNotify(this, PNM_SETSCROLLPOS, SBT_VSCROLL, (intptr_t)&fy);
572}
573
574void CPWL_EditCtrl::IOnSetCaret(FX_BOOL bVisible,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800575 const CFX_FloatPoint& ptHead,
576 const CFX_FloatPoint& ptFoot,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700577 const CPVT_WordPlace& place) {
578 PWL_CARET_INFO cInfo;
579 cInfo.bVisible = bVisible;
580 cInfo.ptHead = ptHead;
581 cInfo.ptFoot = ptFoot;
582
583 OnNotify(this, PNM_SETCARETINFO, (intptr_t)&cInfo, (intptr_t)NULL);
584}
585
586void CPWL_EditCtrl::IOnCaretChange(const CPVT_SecProps& secProps,
587 const CPVT_WordProps& wordProps) {}
588
Tom Sepez281a9ea2016-02-26 14:24:28 -0800589void CPWL_EditCtrl::IOnContentChange(const CFX_FloatRect& rcContent) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700590 if (IsValid()) {
591 if (m_pEditNotify) {
592 m_pEditNotify->OnContentChange(rcContent);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700593 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700594 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700595}
596
Tom Sepez281a9ea2016-02-26 14:24:28 -0800597void CPWL_EditCtrl::IOnInvalidateRect(CFX_FloatRect* pRect) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700598 InvalidateRect(pRect);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700599}
600
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700601int32_t CPWL_EditCtrl::GetCharSet() const {
602 return m_nCharSet < 0 ? DEFAULT_CHARSET : m_nCharSet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700603}
604
Tom Sepez281a9ea2016-02-26 14:24:28 -0800605void CPWL_EditCtrl::GetTextRange(const CFX_FloatRect& rect,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700606 int32_t& nStartChar,
607 int32_t& nEndChar) const {
608 nStartChar = m_pEdit->WordPlaceToWordIndex(
Tom Sepez281a9ea2016-02-26 14:24:28 -0800609 m_pEdit->SearchWordPlace(CFX_FloatPoint(rect.left, rect.top)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700610 nEndChar = m_pEdit->WordPlaceToWordIndex(
Tom Sepez281a9ea2016-02-26 14:24:28 -0800611 m_pEdit->SearchWordPlace(CFX_FloatPoint(rect.right, rect.bottom)));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700612}
613
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700614CFX_WideString CPWL_EditCtrl::GetText(int32_t& nStartChar,
615 int32_t& nEndChar) const {
616 CPVT_WordPlace wpStart = m_pEdit->WordIndexToWordPlace(nStartChar);
617 CPVT_WordPlace wpEnd = m_pEdit->WordIndexToWordPlace(nEndChar);
618 return m_pEdit->GetRangeText(CPVT_WordRange(wpStart, wpEnd));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700619}
620
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700621void CPWL_EditCtrl::SetReadyToInput() {
622 if (m_bMouseDown) {
623 ReleaseCapture();
624 m_bMouseDown = FALSE;
625 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700626}