blob: 9d8b16a53c11618394a31f7f00faf27f61db282c [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 -070019CPWL_EditCtrl::CPWL_EditCtrl()
dsinclaire35af1e2016-07-13 11:26:20 -070020 : m_pEdit(new CFX_Edit),
thestig1cd352e2016-06-07 17:53:06 -070021 m_pEditCaret(nullptr),
Nico Weber9d8ec5a2015-08-04 13:00:21 -070022 m_bMouseDown(FALSE),
Nico Weber9d8ec5a2015-08-04 13:00:21 -070023 m_nCharSet(DEFAULT_CHARSET),
thestig732f6a02016-05-12 10:41:56 -070024 m_nCodePage(0) {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070025
dsinclairdbc77162016-07-13 11:34:23 -070026CPWL_EditCtrl::~CPWL_EditCtrl() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070027
Nico Weber9d8ec5a2015-08-04 13:00:21 -070028void CPWL_EditCtrl::OnCreate(PWL_CREATEPARAM& cp) {
29 cp.eCursorType = FXCT_VBEAM;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070030}
31
Nico Weber9d8ec5a2015-08-04 13:00:21 -070032void CPWL_EditCtrl::OnCreated() {
33 SetFontSize(GetCreationParam().fFontSize);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070034
Nico Weber9d8ec5a2015-08-04 13:00:21 -070035 m_pEdit->SetFontMap(GetFontMap());
36 m_pEdit->SetNotify(this);
37 m_pEdit->Initialize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070038}
39
Nico Weber9d8ec5a2015-08-04 13:00:21 -070040FX_BOOL CPWL_EditCtrl::IsWndHorV() {
Tom Sepez60d909e2015-12-10 15:34:55 -080041 CFX_Matrix mt = GetWindowMatrix();
Tom Sepez281a9ea2016-02-26 14:24:28 -080042 CFX_FloatPoint point1(0, 1);
43 CFX_FloatPoint point2(1, 1);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070044
Nico Weber9d8ec5a2015-08-04 13:00:21 -070045 mt.Transform(point1.x, point1.y);
46 mt.Transform(point2.x, point2.y);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070047
Nico Weber9d8ec5a2015-08-04 13:00:21 -070048 return point2.y == point1.y;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070049}
50
Nico Weber9d8ec5a2015-08-04 13:00:21 -070051void CPWL_EditCtrl::SetCursor() {
52 if (IsValid()) {
dsinclairb9590102016-04-27 06:38:59 -070053 if (CFX_SystemHandler* pSH = GetSystemHandler()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070054 if (IsWndHorV())
55 pSH->SetCursor(FXCT_VBEAM);
56 else
57 pSH->SetCursor(FXCT_HBEAM);
Tom Sepez2f2ffec2015-07-23 14:42:09 -070058 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070059 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070060}
61
Nico Weber9d8ec5a2015-08-04 13:00:21 -070062void CPWL_EditCtrl::RePosChildWnd() {
63 m_pEdit->SetPlateRect(GetClientRect());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070064}
65
Nico Weber9d8ec5a2015-08-04 13:00:21 -070066void CPWL_EditCtrl::OnNotify(CPWL_Wnd* pWnd,
tsepezc3255f52016-03-25 14:52:27 -070067 uint32_t msg,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070068 intptr_t wParam,
69 intptr_t lParam) {
70 CPWL_Wnd::OnNotify(pWnd, msg, wParam, lParam);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070071
Nico Weber9d8ec5a2015-08-04 13:00:21 -070072 switch (msg) {
73 case PNM_SETSCROLLINFO:
74 switch (wParam) {
75 case SBT_VSCROLL:
76 if (CPWL_Wnd* pChild = GetVScrollBar()) {
77 pChild->OnNotify(pWnd, PNM_SETSCROLLINFO, wParam, lParam);
78 }
79 break;
80 }
81 break;
82 case PNM_SETSCROLLPOS:
83 switch (wParam) {
84 case SBT_VSCROLL:
85 if (CPWL_Wnd* pChild = GetVScrollBar()) {
86 pChild->OnNotify(pWnd, PNM_SETSCROLLPOS, wParam, lParam);
87 }
88 break;
89 }
90 break;
91 case PNM_SCROLLWINDOW: {
92 FX_FLOAT fPos = *(FX_FLOAT*)lParam;
93 switch (wParam) {
94 case SBT_VSCROLL:
Tom Sepez281a9ea2016-02-26 14:24:28 -080095 m_pEdit->SetScrollPos(
96 CFX_FloatPoint(m_pEdit->GetScrollPos().x, fPos));
Nico Weber9d8ec5a2015-08-04 13:00:21 -070097 break;
98 }
99 } break;
100 case PNM_SETCARETINFO: {
101 if (PWL_CARET_INFO* pCaretInfo = (PWL_CARET_INFO*)wParam) {
102 SetCaret(pCaretInfo->bVisible, pCaretInfo->ptHead, pCaretInfo->ptFoot);
103 }
104 } break;
105 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700106}
107
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700108void CPWL_EditCtrl::CreateChildWnd(const PWL_CREATEPARAM& cp) {
109 if (!IsReadOnly())
110 CreateEditCaret(cp);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700111}
112
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700113void CPWL_EditCtrl::CreateEditCaret(const PWL_CREATEPARAM& cp) {
thestig732f6a02016-05-12 10:41:56 -0700114 if (m_pEditCaret)
115 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700116
thestig732f6a02016-05-12 10:41:56 -0700117 m_pEditCaret = new CPWL_Caret;
118 m_pEditCaret->SetInvalidRect(GetClientRect());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700119
thestig732f6a02016-05-12 10:41:56 -0700120 PWL_CREATEPARAM ecp = cp;
121 ecp.pParentWnd = this;
122 ecp.dwFlags = PWS_CHILD | PWS_NOREFRESHCLIP;
123 ecp.dwBorderWidth = 0;
dsinclair92cb5e52016-05-16 11:38:28 -0700124 ecp.nBorderStyle = BorderStyle::SOLID;
thestig732f6a02016-05-12 10:41:56 -0700125 ecp.rcRectWnd = CFX_FloatRect(0, 0, 0, 0);
126
127 m_pEditCaret->Create(ecp);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700128}
129
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700130void CPWL_EditCtrl::SetFontSize(FX_FLOAT fFontSize) {
131 m_pEdit->SetFontSize(fFontSize);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700132}
133
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700134FX_FLOAT CPWL_EditCtrl::GetFontSize() const {
135 return m_pEdit->GetFontSize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700136}
137
tsepezc3255f52016-03-25 14:52:27 -0700138FX_BOOL CPWL_EditCtrl::OnKeyDown(uint16_t nChar, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700139 if (m_bMouseDown)
140 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700141
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700142 FX_BOOL bRet = CPWL_Wnd::OnKeyDown(nChar, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700143
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700144 // FILTER
145 switch (nChar) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700146 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700147 return FALSE;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700148 case FWL_VKEY_Delete:
149 case FWL_VKEY_Up:
150 case FWL_VKEY_Down:
151 case FWL_VKEY_Left:
152 case FWL_VKEY_Right:
153 case FWL_VKEY_Home:
154 case FWL_VKEY_End:
155 case FWL_VKEY_Insert:
156 case 'C':
157 case 'V':
158 case 'X':
159 case 'A':
160 case 'Z':
161 case 'c':
162 case 'v':
163 case 'x':
164 case 'a':
165 case 'z':
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700166 break;
167 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700168
thestig594b20b2016-05-12 21:56:43 -0700169 if (nChar == FWL_VKEY_Delete && m_pEdit->IsSelected())
170 nChar = FWL_VKEY_Unknown;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700171
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700172 switch (nChar) {
173 case FWL_VKEY_Delete:
174 Delete();
175 return TRUE;
176 case FWL_VKEY_Insert:
177 if (IsSHIFTpressed(nFlag))
178 PasteText();
179 return TRUE;
180 case FWL_VKEY_Up:
181 m_pEdit->OnVK_UP(IsSHIFTpressed(nFlag), FALSE);
182 return TRUE;
183 case FWL_VKEY_Down:
184 m_pEdit->OnVK_DOWN(IsSHIFTpressed(nFlag), FALSE);
185 return TRUE;
186 case FWL_VKEY_Left:
187 m_pEdit->OnVK_LEFT(IsSHIFTpressed(nFlag), FALSE);
188 return TRUE;
189 case FWL_VKEY_Right:
190 m_pEdit->OnVK_RIGHT(IsSHIFTpressed(nFlag), FALSE);
191 return TRUE;
192 case FWL_VKEY_Home:
193 m_pEdit->OnVK_HOME(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
194 return TRUE;
195 case FWL_VKEY_End:
196 m_pEdit->OnVK_END(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
197 return TRUE;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700198 case FWL_VKEY_Unknown:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700199 if (!IsSHIFTpressed(nFlag))
200 Clear();
201 else
202 CutText();
203 return TRUE;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700204 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700205 break;
206 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700207
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700208 return bRet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700209}
210
tsepezc3255f52016-03-25 14:52:27 -0700211FX_BOOL CPWL_EditCtrl::OnChar(uint16_t nChar, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700212 if (m_bMouseDown)
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700213 return TRUE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700214
215 CPWL_Wnd::OnChar(nChar, nFlag);
216
217 // FILTER
218 switch (nChar) {
219 case 0x0A:
220 case 0x1B:
221 return FALSE;
222 default:
223 break;
224 }
225
226 FX_BOOL bCtrl = IsCTRLpressed(nFlag);
227 FX_BOOL bAlt = IsALTpressed(nFlag);
228 FX_BOOL bShift = IsSHIFTpressed(nFlag);
229
Tom Sepez62a70f92016-03-21 15:00:20 -0700230 uint16_t word = nChar;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700231
232 if (bCtrl && !bAlt) {
233 switch (nChar) {
234 case 'C' - 'A' + 1:
235 CopyText();
236 return TRUE;
237 case 'V' - 'A' + 1:
238 PasteText();
239 return TRUE;
240 case 'X' - 'A' + 1:
241 CutText();
242 return TRUE;
243 case 'A' - 'A' + 1:
244 SelectAll();
245 return TRUE;
246 case 'Z' - 'A' + 1:
247 if (bShift)
248 Redo();
249 else
250 Undo();
251 return TRUE;
252 default:
253 if (nChar < 32)
254 return FALSE;
255 }
256 }
257
258 if (IsReadOnly())
259 return TRUE;
260
261 if (m_pEdit->IsSelected() && word == FWL_VKEY_Back)
262 word = FWL_VKEY_Unknown;
263
264 Clear();
265
266 switch (word) {
267 case FWL_VKEY_Back:
268 Backspace();
269 break;
270 case FWL_VKEY_Return:
271 InsertReturn();
272 break;
273 case FWL_VKEY_Unknown:
274 break;
275 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700276 InsertWord(word, GetCharSet());
277 break;
278 }
279
280 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700281}
282
Tom Sepez281a9ea2016-02-26 14:24:28 -0800283FX_BOOL CPWL_EditCtrl::OnLButtonDown(const CFX_FloatPoint& point,
tsepezc3255f52016-03-25 14:52:27 -0700284 uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700285 CPWL_Wnd::OnLButtonDown(point, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700286
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700287 if (ClientHitTest(point)) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700288 if (m_bMouseDown)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700289 InvalidateRect();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700290
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700291 m_bMouseDown = TRUE;
292 SetCapture();
293
294 m_pEdit->OnMouseDown(point, IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
295 }
296
297 return TRUE;
298}
299
Tom Sepez281a9ea2016-02-26 14:24:28 -0800300FX_BOOL CPWL_EditCtrl::OnLButtonUp(const CFX_FloatPoint& point,
tsepezc3255f52016-03-25 14:52:27 -0700301 uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700302 CPWL_Wnd::OnLButtonUp(point, nFlag);
303
304 if (m_bMouseDown) {
305 // can receive keybord message
306 if (ClientHitTest(point) && !IsFocused())
307 SetFocus();
308
309 ReleaseCapture();
310 m_bMouseDown = FALSE;
311 }
312
313 return TRUE;
314}
315
Tom Sepez281a9ea2016-02-26 14:24:28 -0800316FX_BOOL CPWL_EditCtrl::OnMouseMove(const CFX_FloatPoint& point,
tsepezc3255f52016-03-25 14:52:27 -0700317 uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700318 CPWL_Wnd::OnMouseMove(point, nFlag);
319
320 if (m_bMouseDown)
321 m_pEdit->OnMouseMove(point, FALSE, FALSE);
322
323 return TRUE;
324}
325
Tom Sepez281a9ea2016-02-26 14:24:28 -0800326CFX_FloatRect CPWL_EditCtrl::GetContentRect() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700327 return m_pEdit->GetContentRect();
328}
329
330void CPWL_EditCtrl::SetEditCaret(FX_BOOL bVisible) {
tsepez63f545c2016-09-13 16:08:49 -0700331 CFX_FloatPoint ptHead;
332 CFX_FloatPoint ptFoot;
333 if (bVisible)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700334 GetCaretInfo(ptHead, ptFoot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700335
336 CPVT_WordPlace wpTemp = m_pEdit->GetCaretWordPlace();
337 IOnSetCaret(bVisible, ptHead, ptFoot, wpTemp);
338}
339
Tom Sepez281a9ea2016-02-26 14:24:28 -0800340void CPWL_EditCtrl::GetCaretInfo(CFX_FloatPoint& ptHead,
341 CFX_FloatPoint& ptFoot) const {
dsinclaire35af1e2016-07-13 11:26:20 -0700342 CFX_Edit_Iterator* pIterator = m_pEdit->GetIterator();
thestig821d59e2016-05-11 12:59:22 -0700343 pIterator->SetAt(m_pEdit->GetCaret());
344 CPVT_Word word;
345 CPVT_Line line;
346 if (pIterator->GetWord(word)) {
347 ptHead.x = word.ptWord.x + word.fWidth;
348 ptHead.y = word.ptWord.y + word.fAscent;
349 ptFoot.x = word.ptWord.x + word.fWidth;
350 ptFoot.y = word.ptWord.y + word.fDescent;
351 } else if (pIterator->GetLine(line)) {
352 ptHead.x = line.ptLine.x;
353 ptHead.y = line.ptLine.y + line.fLineAscent;
354 ptFoot.x = line.ptLine.x;
355 ptFoot.y = line.ptLine.y + line.fLineDescent;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700356 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700357}
358
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700359void CPWL_EditCtrl::GetCaretPos(int32_t& x, int32_t& y) const {
tsepez63f545c2016-09-13 16:08:49 -0700360 CFX_FloatPoint ptHead;
361 CFX_FloatPoint ptFoot;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700362 GetCaretInfo(ptHead, ptFoot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700363 PWLtoWnd(ptHead, x, y);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700364}
365
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700366void CPWL_EditCtrl::SetCaret(FX_BOOL bVisible,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800367 const CFX_FloatPoint& ptHead,
368 const CFX_FloatPoint& ptFoot) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700369 if (m_pEditCaret) {
370 if (!IsFocused() || m_pEdit->IsSelected())
371 bVisible = FALSE;
372
373 m_pEditCaret->SetCaret(bVisible, ptHead, ptFoot);
374 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700375}
376
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700377CFX_WideString CPWL_EditCtrl::GetText() const {
378 return m_pEdit->GetText();
379}
380
381void CPWL_EditCtrl::SetSel(int32_t nStartChar, int32_t nEndChar) {
382 m_pEdit->SetSel(nStartChar, nEndChar);
383}
384
385void CPWL_EditCtrl::GetSel(int32_t& nStartChar, int32_t& nEndChar) const {
386 m_pEdit->GetSel(nStartChar, nEndChar);
387}
388
389void CPWL_EditCtrl::Clear() {
390 if (!IsReadOnly())
391 m_pEdit->Clear();
392}
393
394void CPWL_EditCtrl::SelectAll() {
395 m_pEdit->SelectAll();
396}
397
398void CPWL_EditCtrl::Paint() {
thestig732f6a02016-05-12 10:41:56 -0700399 m_pEdit->Paint();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700400}
401
402void CPWL_EditCtrl::EnableRefresh(FX_BOOL bRefresh) {
thestig732f6a02016-05-12 10:41:56 -0700403 m_pEdit->EnableRefresh(bRefresh);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700404}
405
406int32_t CPWL_EditCtrl::GetCaret() const {
thestig732f6a02016-05-12 10:41:56 -0700407 return m_pEdit->GetCaret();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700408}
409
410void CPWL_EditCtrl::SetCaret(int32_t nPos) {
thestig732f6a02016-05-12 10:41:56 -0700411 m_pEdit->SetCaret(nPos);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700412}
413
414int32_t CPWL_EditCtrl::GetTotalWords() const {
thestig732f6a02016-05-12 10:41:56 -0700415 return m_pEdit->GetTotalWords();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700416}
417
Tom Sepez281a9ea2016-02-26 14:24:28 -0800418void CPWL_EditCtrl::SetScrollPos(const CFX_FloatPoint& point) {
thestig732f6a02016-05-12 10:41:56 -0700419 m_pEdit->SetScrollPos(point);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700420}
421
Tom Sepez281a9ea2016-02-26 14:24:28 -0800422CFX_FloatPoint CPWL_EditCtrl::GetScrollPos() const {
thestig732f6a02016-05-12 10:41:56 -0700423 return m_pEdit->GetScrollPos();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700424}
425
426CPDF_Font* CPWL_EditCtrl::GetCaretFont() const {
427 int32_t nFontIndex = 0;
428
dsinclaire35af1e2016-07-13 11:26:20 -0700429 CFX_Edit_Iterator* pIterator = m_pEdit->GetIterator();
thestig821d59e2016-05-11 12:59:22 -0700430 pIterator->SetAt(m_pEdit->GetCaret());
431 CPVT_Word word;
432 CPVT_Section section;
433 if (pIterator->GetWord(word)) {
434 nFontIndex = word.nFontIndex;
435 } else if (HasFlag(PES_RICH)) {
436 if (pIterator->GetSection(section)) {
437 nFontIndex = section.WordProps.nFontIndex;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700438 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700439 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700440
dsinclairc7a73492016-04-05 12:01:42 -0700441 if (IPVT_FontMap* pFontMap = GetFontMap())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700442 return pFontMap->GetPDFFont(nFontIndex);
443
thestig1cd352e2016-06-07 17:53:06 -0700444 return nullptr;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700445}
446
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700447FX_FLOAT CPWL_EditCtrl::GetCaretFontSize() const {
448 FX_FLOAT fFontSize = GetFontSize();
449
dsinclaire35af1e2016-07-13 11:26:20 -0700450 CFX_Edit_Iterator* pIterator = m_pEdit->GetIterator();
thestig821d59e2016-05-11 12:59:22 -0700451 pIterator->SetAt(m_pEdit->GetCaret());
452 CPVT_Word word;
453 CPVT_Section section;
454 if (pIterator->GetWord(word)) {
455 fFontSize = word.fFontSize;
456 } else if (HasFlag(PES_RICH)) {
457 if (pIterator->GetSection(section)) {
458 fFontSize = section.WordProps.fFontSize;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700459 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700460 }
461
462 return fFontSize;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700463}
464
tsepez067990c2016-09-13 06:46:40 -0700465void CPWL_EditCtrl::SetText(const CFX_WideString& wsText) {
466 m_pEdit->SetText(wsText);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700467}
468
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700469void CPWL_EditCtrl::CopyText() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700470
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700471void CPWL_EditCtrl::PasteText() {}
472
473void CPWL_EditCtrl::CutText() {}
474
475void CPWL_EditCtrl::ShowVScrollBar(FX_BOOL bShow) {}
476
tsepez067990c2016-09-13 06:46:40 -0700477void CPWL_EditCtrl::InsertText(const CFX_WideString& wsText) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700478 if (!IsReadOnly())
tsepez067990c2016-09-13 06:46:40 -0700479 m_pEdit->InsertText(wsText, DEFAULT_CHARSET);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700480}
481
Tom Sepez62a70f92016-03-21 15:00:20 -0700482void CPWL_EditCtrl::InsertWord(uint16_t word, int32_t nCharset) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700483 if (!IsReadOnly())
484 m_pEdit->InsertWord(word, nCharset);
485}
486
487void CPWL_EditCtrl::InsertReturn() {
488 if (!IsReadOnly())
489 m_pEdit->InsertReturn();
490}
491
492void CPWL_EditCtrl::Delete() {
493 if (!IsReadOnly())
494 m_pEdit->Delete();
495}
496
497void CPWL_EditCtrl::Backspace() {
498 if (!IsReadOnly())
499 m_pEdit->Backspace();
500}
501
502FX_BOOL CPWL_EditCtrl::CanUndo() const {
503 return !IsReadOnly() && m_pEdit->CanUndo();
504}
505
506FX_BOOL CPWL_EditCtrl::CanRedo() const {
507 return !IsReadOnly() && m_pEdit->CanRedo();
508}
509
510void CPWL_EditCtrl::Redo() {
511 if (CanRedo())
512 m_pEdit->Redo();
513}
514
515void CPWL_EditCtrl::Undo() {
516 if (CanUndo())
517 m_pEdit->Undo();
518}
519
520void CPWL_EditCtrl::IOnSetScrollInfoY(FX_FLOAT fPlateMin,
521 FX_FLOAT fPlateMax,
522 FX_FLOAT fContentMin,
523 FX_FLOAT fContentMax,
524 FX_FLOAT fSmallStep,
525 FX_FLOAT fBigStep) {
526 PWL_SCROLL_INFO Info;
527
528 Info.fPlateWidth = fPlateMax - fPlateMin;
529 Info.fContentMin = fContentMin;
530 Info.fContentMax = fContentMax;
531 Info.fSmallStep = fSmallStep;
532 Info.fBigStep = fBigStep;
533
534 OnNotify(this, PNM_SETSCROLLINFO, SBT_VSCROLL, (intptr_t)&Info);
535
536 if (IsFloatBigger(Info.fPlateWidth, Info.fContentMax - Info.fContentMin) ||
537 IsFloatEqual(Info.fPlateWidth, Info.fContentMax - Info.fContentMin)) {
538 ShowVScrollBar(FALSE);
539 } else {
540 ShowVScrollBar(TRUE);
541 }
542}
543
544void CPWL_EditCtrl::IOnSetScrollPosY(FX_FLOAT fy) {
545 OnNotify(this, PNM_SETSCROLLPOS, SBT_VSCROLL, (intptr_t)&fy);
546}
547
548void CPWL_EditCtrl::IOnSetCaret(FX_BOOL bVisible,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800549 const CFX_FloatPoint& ptHead,
550 const CFX_FloatPoint& ptFoot,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700551 const CPVT_WordPlace& place) {
552 PWL_CARET_INFO cInfo;
553 cInfo.bVisible = bVisible;
554 cInfo.ptHead = ptHead;
555 cInfo.ptFoot = ptFoot;
556
thestig1cd352e2016-06-07 17:53:06 -0700557 OnNotify(this, PNM_SETCARETINFO, (intptr_t)&cInfo, (intptr_t) nullptr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700558}
559
dsinclairdbc77162016-07-13 11:34:23 -0700560void CPWL_EditCtrl::IOnCaretChange(const CPVT_SecProps& secProps,
561 const CPVT_WordProps& wordProps) {}
562
563void CPWL_EditCtrl::IOnContentChange(const CFX_FloatRect& rcContent) {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700564
Tom Sepez281a9ea2016-02-26 14:24:28 -0800565void CPWL_EditCtrl::IOnInvalidateRect(CFX_FloatRect* pRect) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700566 InvalidateRect(pRect);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700567}
568
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700569int32_t CPWL_EditCtrl::GetCharSet() const {
570 return m_nCharSet < 0 ? DEFAULT_CHARSET : m_nCharSet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700571}
572
Tom Sepez281a9ea2016-02-26 14:24:28 -0800573void CPWL_EditCtrl::GetTextRange(const CFX_FloatRect& rect,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700574 int32_t& nStartChar,
575 int32_t& nEndChar) const {
576 nStartChar = m_pEdit->WordPlaceToWordIndex(
Tom Sepez281a9ea2016-02-26 14:24:28 -0800577 m_pEdit->SearchWordPlace(CFX_FloatPoint(rect.left, rect.top)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700578 nEndChar = m_pEdit->WordPlaceToWordIndex(
Tom Sepez281a9ea2016-02-26 14:24:28 -0800579 m_pEdit->SearchWordPlace(CFX_FloatPoint(rect.right, rect.bottom)));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700580}
581
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700582CFX_WideString CPWL_EditCtrl::GetText(int32_t& nStartChar,
583 int32_t& nEndChar) const {
584 CPVT_WordPlace wpStart = m_pEdit->WordIndexToWordPlace(nStartChar);
585 CPVT_WordPlace wpEnd = m_pEdit->WordIndexToWordPlace(nEndChar);
586 return m_pEdit->GetRangeText(CPVT_WordRange(wpStart, wpEnd));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700587}
588
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700589void CPWL_EditCtrl::SetReadyToInput() {
590 if (m_bMouseDown) {
591 ReleaseCapture();
592 m_bMouseDown = FALSE;
593 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700594}