blob: 10b5d6c04f007d8a82b5d3a4e21916de1c67e0d9 [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
Lei Zhangbde53d22015-11-12 22:21:30 -08007#include "fpdfsdk/include/pdfwindow/PWL_EditCtrl.h"
Lei Zhangc2fb35f2016-01-05 16:46:58 -08008
9#include "fpdfsdk/include/pdfwindow/PWL_Caret.h"
Lei Zhangbde53d22015-11-12 22:21:30 -080010#include "fpdfsdk/include/pdfwindow/PWL_FontMap.h"
11#include "fpdfsdk/include/pdfwindow/PWL_ScrollBar.h"
12#include "fpdfsdk/include/pdfwindow/PWL_Utils.h"
13#include "fpdfsdk/include/pdfwindow/PWL_Wnd.h"
Lei Zhangc2fb35f2016-01-05 16:46:58 -080014#include "public/fpdf_fwlevent.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070015
Nico Weber9d8ec5a2015-08-04 13:00:21 -070016#define IsFloatZero(f) ((f) < 0.0001 && (f) > -0.0001)
17#define IsFloatBigger(fa, fb) ((fa) > (fb) && !IsFloatZero((fa) - (fb)))
18#define IsFloatSmaller(fa, fb) ((fa) < (fb) && !IsFloatZero((fa) - (fb)))
19#define IsFloatEqual(fa, fb) IsFloatZero((fa) - (fb))
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070020
Nico Weber9d8ec5a2015-08-04 13:00:21 -070021CPWL_EditCtrl::CPWL_EditCtrl()
22 : m_pEdit(NULL),
23 m_pEditCaret(NULL),
24 m_bMouseDown(FALSE),
25 m_pEditNotify(NULL),
26 m_nCharSet(DEFAULT_CHARSET),
27 m_nCodePage(0) {
28 m_pEdit = IFX_Edit::NewEdit();
Lei Zhang96660d62015-12-14 18:27:25 -080029 ASSERT(m_pEdit);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070030}
31
Nico Weber9d8ec5a2015-08-04 13:00:21 -070032CPWL_EditCtrl::~CPWL_EditCtrl() {
33 IFX_Edit::DelEdit(m_pEdit);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070034}
35
Nico Weber9d8ec5a2015-08-04 13:00:21 -070036void CPWL_EditCtrl::OnCreate(PWL_CREATEPARAM& cp) {
37 cp.eCursorType = FXCT_VBEAM;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070038}
39
Nico Weber9d8ec5a2015-08-04 13:00:21 -070040void CPWL_EditCtrl::OnCreated() {
41 SetFontSize(GetCreationParam().fFontSize);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070042
Nico Weber9d8ec5a2015-08-04 13:00:21 -070043 m_pEdit->SetFontMap(GetFontMap());
44 m_pEdit->SetNotify(this);
45 m_pEdit->Initialize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070046}
47
Nico Weber9d8ec5a2015-08-04 13:00:21 -070048FX_BOOL CPWL_EditCtrl::IsWndHorV() {
Tom Sepez60d909e2015-12-10 15:34:55 -080049 CFX_Matrix mt = GetWindowMatrix();
Tom Sepez281a9ea2016-02-26 14:24:28 -080050 CFX_FloatPoint point1(0, 1);
51 CFX_FloatPoint point2(1, 1);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070052
Nico Weber9d8ec5a2015-08-04 13:00:21 -070053 mt.Transform(point1.x, point1.y);
54 mt.Transform(point2.x, point2.y);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070055
Nico Weber9d8ec5a2015-08-04 13:00:21 -070056 return point2.y == point1.y;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070057}
58
Nico Weber9d8ec5a2015-08-04 13:00:21 -070059void CPWL_EditCtrl::SetCursor() {
60 if (IsValid()) {
61 if (IFX_SystemHandler* pSH = GetSystemHandler()) {
62 if (IsWndHorV())
63 pSH->SetCursor(FXCT_VBEAM);
64 else
65 pSH->SetCursor(FXCT_HBEAM);
Tom Sepez2f2ffec2015-07-23 14:42:09 -070066 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070067 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070068}
69
Nico Weber9d8ec5a2015-08-04 13:00:21 -070070void CPWL_EditCtrl::RePosChildWnd() {
71 m_pEdit->SetPlateRect(GetClientRect());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070072}
73
Nico Weber9d8ec5a2015-08-04 13:00:21 -070074void CPWL_EditCtrl::OnNotify(CPWL_Wnd* pWnd,
75 FX_DWORD msg,
76 intptr_t wParam,
77 intptr_t lParam) {
78 CPWL_Wnd::OnNotify(pWnd, msg, wParam, lParam);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070079
Nico Weber9d8ec5a2015-08-04 13:00:21 -070080 switch (msg) {
81 case PNM_SETSCROLLINFO:
82 switch (wParam) {
83 case SBT_VSCROLL:
84 if (CPWL_Wnd* pChild = GetVScrollBar()) {
85 pChild->OnNotify(pWnd, PNM_SETSCROLLINFO, wParam, lParam);
86 }
87 break;
88 }
89 break;
90 case PNM_SETSCROLLPOS:
91 switch (wParam) {
92 case SBT_VSCROLL:
93 if (CPWL_Wnd* pChild = GetVScrollBar()) {
94 pChild->OnNotify(pWnd, PNM_SETSCROLLPOS, wParam, lParam);
95 }
96 break;
97 }
98 break;
99 case PNM_SCROLLWINDOW: {
100 FX_FLOAT fPos = *(FX_FLOAT*)lParam;
101 switch (wParam) {
102 case SBT_VSCROLL:
Tom Sepez281a9ea2016-02-26 14:24:28 -0800103 m_pEdit->SetScrollPos(
104 CFX_FloatPoint(m_pEdit->GetScrollPos().x, fPos));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700105 break;
106 }
107 } break;
108 case PNM_SETCARETINFO: {
109 if (PWL_CARET_INFO* pCaretInfo = (PWL_CARET_INFO*)wParam) {
110 SetCaret(pCaretInfo->bVisible, pCaretInfo->ptHead, pCaretInfo->ptFoot);
111 }
112 } break;
113 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700114}
115
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700116void CPWL_EditCtrl::CreateChildWnd(const PWL_CREATEPARAM& cp) {
117 if (!IsReadOnly())
118 CreateEditCaret(cp);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700119}
120
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700121void CPWL_EditCtrl::CreateEditCaret(const PWL_CREATEPARAM& cp) {
122 if (!m_pEditCaret) {
123 m_pEditCaret = new CPWL_Caret;
124 m_pEditCaret->SetInvalidRect(GetClientRect());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700125
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700126 PWL_CREATEPARAM ecp = cp;
127 ecp.pParentWnd = this;
128 ecp.dwFlags = PWS_CHILD | PWS_NOREFRESHCLIP;
129 ecp.dwBorderWidth = 0;
130 ecp.nBorderStyle = PBS_SOLID;
Tom Sepez281a9ea2016-02-26 14:24:28 -0800131 ecp.rcRectWnd = CFX_FloatRect(0, 0, 0, 0);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700132
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700133 m_pEditCaret->Create(ecp);
134 }
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
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700145FX_BOOL CPWL_EditCtrl::OnKeyDown(FX_WORD nChar, FX_DWORD nFlag) {
146 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
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700220FX_BOOL CPWL_EditCtrl::OnChar(FX_WORD nChar, FX_DWORD nFlag) {
221 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
239 FX_WORD word = nChar;
240
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:
285 if (IsINSERTpressed(nFlag))
286 Delete();
287 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,
295 FX_DWORD 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,
312 FX_DWORD 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,
328 FX_DWORD 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 {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700354 if (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;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700368 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700369 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700370}
371
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700372void CPWL_EditCtrl::GetCaretPos(int32_t& x, int32_t& y) const {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800373 CFX_FloatPoint ptHead(0, 0), ptFoot(0, 0);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700374
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700375 GetCaretInfo(ptHead, ptFoot);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700376
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700377 PWLtoWnd(ptHead, x, y);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700378}
379
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700380void CPWL_EditCtrl::SetCaret(FX_BOOL bVisible,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800381 const CFX_FloatPoint& ptHead,
382 const CFX_FloatPoint& ptFoot) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700383 if (m_pEditCaret) {
384 if (!IsFocused() || m_pEdit->IsSelected())
385 bVisible = FALSE;
386
387 m_pEditCaret->SetCaret(bVisible, ptHead, ptFoot);
388 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700389}
390
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700391CFX_WideString CPWL_EditCtrl::GetText() const {
392 return m_pEdit->GetText();
393}
394
395void CPWL_EditCtrl::SetSel(int32_t nStartChar, int32_t nEndChar) {
396 m_pEdit->SetSel(nStartChar, nEndChar);
397}
398
399void CPWL_EditCtrl::GetSel(int32_t& nStartChar, int32_t& nEndChar) const {
400 m_pEdit->GetSel(nStartChar, nEndChar);
401}
402
403void CPWL_EditCtrl::Clear() {
404 if (!IsReadOnly())
405 m_pEdit->Clear();
406}
407
408void CPWL_EditCtrl::SelectAll() {
409 m_pEdit->SelectAll();
410}
411
412void CPWL_EditCtrl::Paint() {
413 if (m_pEdit)
414 m_pEdit->Paint();
415}
416
417void CPWL_EditCtrl::EnableRefresh(FX_BOOL bRefresh) {
418 if (m_pEdit)
419 m_pEdit->EnableRefresh(bRefresh);
420}
421
422int32_t CPWL_EditCtrl::GetCaret() const {
423 if (m_pEdit)
424 return m_pEdit->GetCaret();
425
426 return -1;
427}
428
429void CPWL_EditCtrl::SetCaret(int32_t nPos) {
430 if (m_pEdit)
431 m_pEdit->SetCaret(nPos);
432}
433
434int32_t CPWL_EditCtrl::GetTotalWords() const {
435 if (m_pEdit)
436 return m_pEdit->GetTotalWords();
437
438 return 0;
439}
440
Tom Sepez281a9ea2016-02-26 14:24:28 -0800441void CPWL_EditCtrl::SetScrollPos(const CFX_FloatPoint& point) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700442 if (m_pEdit)
443 m_pEdit->SetScrollPos(point);
444}
445
Tom Sepez281a9ea2016-02-26 14:24:28 -0800446CFX_FloatPoint CPWL_EditCtrl::GetScrollPos() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700447 if (m_pEdit)
448 return m_pEdit->GetScrollPos();
449
Tom Sepez281a9ea2016-02-26 14:24:28 -0800450 return CFX_FloatPoint(0.0f, 0.0f);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700451}
452
453CPDF_Font* CPWL_EditCtrl::GetCaretFont() const {
454 int32_t nFontIndex = 0;
455
456 if (IFX_Edit_Iterator* pIterator = m_pEdit->GetIterator()) {
457 pIterator->SetAt(m_pEdit->GetCaret());
458 CPVT_Word word;
459 CPVT_Section section;
460 if (pIterator->GetWord(word)) {
461 nFontIndex = word.nFontIndex;
462 } else if (HasFlag(PES_RICH)) {
463 if (pIterator->GetSection(section)) {
464 nFontIndex = section.WordProps.nFontIndex;
465 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700466 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700467 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700468
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700469 if (IFX_Edit_FontMap* pFontMap = GetFontMap())
470 return pFontMap->GetPDFFont(nFontIndex);
471
472 return NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700473}
474
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700475FX_FLOAT CPWL_EditCtrl::GetCaretFontSize() const {
476 FX_FLOAT fFontSize = GetFontSize();
477
478 if (IFX_Edit_Iterator* pIterator = m_pEdit->GetIterator()) {
479 pIterator->SetAt(m_pEdit->GetCaret());
480 CPVT_Word word;
481 CPVT_Section section;
482 if (pIterator->GetWord(word)) {
483 fFontSize = word.fFontSize;
484 } else if (HasFlag(PES_RICH)) {
485 if (pIterator->GetSection(section)) {
486 fFontSize = section.WordProps.fFontSize;
487 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700488 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700489 }
490
491 return fFontSize;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700492}
493
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700494void CPWL_EditCtrl::SetText(const FX_WCHAR* csText) {
495 m_pEdit->SetText(csText);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700496}
497
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700498void CPWL_EditCtrl::CopyText() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700499
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700500void CPWL_EditCtrl::PasteText() {}
501
502void CPWL_EditCtrl::CutText() {}
503
504void CPWL_EditCtrl::ShowVScrollBar(FX_BOOL bShow) {}
505
506void CPWL_EditCtrl::InsertText(const FX_WCHAR* csText) {
507 if (!IsReadOnly())
508 m_pEdit->InsertText(csText);
509}
510
511void CPWL_EditCtrl::InsertWord(FX_WORD word, int32_t nCharset) {
512 if (!IsReadOnly())
513 m_pEdit->InsertWord(word, nCharset);
514}
515
516void CPWL_EditCtrl::InsertReturn() {
517 if (!IsReadOnly())
518 m_pEdit->InsertReturn();
519}
520
521void CPWL_EditCtrl::Delete() {
522 if (!IsReadOnly())
523 m_pEdit->Delete();
524}
525
526void CPWL_EditCtrl::Backspace() {
527 if (!IsReadOnly())
528 m_pEdit->Backspace();
529}
530
531FX_BOOL CPWL_EditCtrl::CanUndo() const {
532 return !IsReadOnly() && m_pEdit->CanUndo();
533}
534
535FX_BOOL CPWL_EditCtrl::CanRedo() const {
536 return !IsReadOnly() && m_pEdit->CanRedo();
537}
538
539void CPWL_EditCtrl::Redo() {
540 if (CanRedo())
541 m_pEdit->Redo();
542}
543
544void CPWL_EditCtrl::Undo() {
545 if (CanUndo())
546 m_pEdit->Undo();
547}
548
549void CPWL_EditCtrl::IOnSetScrollInfoY(FX_FLOAT fPlateMin,
550 FX_FLOAT fPlateMax,
551 FX_FLOAT fContentMin,
552 FX_FLOAT fContentMax,
553 FX_FLOAT fSmallStep,
554 FX_FLOAT fBigStep) {
555 PWL_SCROLL_INFO Info;
556
557 Info.fPlateWidth = fPlateMax - fPlateMin;
558 Info.fContentMin = fContentMin;
559 Info.fContentMax = fContentMax;
560 Info.fSmallStep = fSmallStep;
561 Info.fBigStep = fBigStep;
562
563 OnNotify(this, PNM_SETSCROLLINFO, SBT_VSCROLL, (intptr_t)&Info);
564
565 if (IsFloatBigger(Info.fPlateWidth, Info.fContentMax - Info.fContentMin) ||
566 IsFloatEqual(Info.fPlateWidth, Info.fContentMax - Info.fContentMin)) {
567 ShowVScrollBar(FALSE);
568 } else {
569 ShowVScrollBar(TRUE);
570 }
571}
572
573void CPWL_EditCtrl::IOnSetScrollPosY(FX_FLOAT fy) {
574 OnNotify(this, PNM_SETSCROLLPOS, SBT_VSCROLL, (intptr_t)&fy);
575}
576
577void CPWL_EditCtrl::IOnSetCaret(FX_BOOL bVisible,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800578 const CFX_FloatPoint& ptHead,
579 const CFX_FloatPoint& ptFoot,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700580 const CPVT_WordPlace& place) {
581 PWL_CARET_INFO cInfo;
582 cInfo.bVisible = bVisible;
583 cInfo.ptHead = ptHead;
584 cInfo.ptFoot = ptFoot;
585
586 OnNotify(this, PNM_SETCARETINFO, (intptr_t)&cInfo, (intptr_t)NULL);
587}
588
589void CPWL_EditCtrl::IOnCaretChange(const CPVT_SecProps& secProps,
590 const CPVT_WordProps& wordProps) {}
591
Tom Sepez281a9ea2016-02-26 14:24:28 -0800592void CPWL_EditCtrl::IOnContentChange(const CFX_FloatRect& rcContent) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700593 if (IsValid()) {
594 if (m_pEditNotify) {
595 m_pEditNotify->OnContentChange(rcContent);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700596 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700597 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700598}
599
Tom Sepez281a9ea2016-02-26 14:24:28 -0800600void CPWL_EditCtrl::IOnInvalidateRect(CFX_FloatRect* pRect) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700601 InvalidateRect(pRect);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700602}
603
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700604int32_t CPWL_EditCtrl::GetCharSet() const {
605 return m_nCharSet < 0 ? DEFAULT_CHARSET : m_nCharSet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700606}
607
Tom Sepez281a9ea2016-02-26 14:24:28 -0800608void CPWL_EditCtrl::GetTextRange(const CFX_FloatRect& rect,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700609 int32_t& nStartChar,
610 int32_t& nEndChar) const {
611 nStartChar = m_pEdit->WordPlaceToWordIndex(
Tom Sepez281a9ea2016-02-26 14:24:28 -0800612 m_pEdit->SearchWordPlace(CFX_FloatPoint(rect.left, rect.top)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700613 nEndChar = m_pEdit->WordPlaceToWordIndex(
Tom Sepez281a9ea2016-02-26 14:24:28 -0800614 m_pEdit->SearchWordPlace(CFX_FloatPoint(rect.right, rect.bottom)));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700615}
616
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700617CFX_WideString CPWL_EditCtrl::GetText(int32_t& nStartChar,
618 int32_t& nEndChar) const {
619 CPVT_WordPlace wpStart = m_pEdit->WordIndexToWordPlace(nStartChar);
620 CPVT_WordPlace wpEnd = m_pEdit->WordIndexToWordPlace(nEndChar);
621 return m_pEdit->GetRangeText(CPVT_WordRange(wpStart, wpEnd));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700622}
623
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700624void CPWL_EditCtrl::SetReadyToInput() {
625 if (m_bMouseDown) {
626 ReleaseCapture();
627 m_bMouseDown = FALSE;
628 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700629}