blob: 575fd39089dc0793a155c0a47e72539444f9f769 [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) {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800331 CFX_FloatPoint ptHead(0, 0), ptFoot(0, 0);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700332
333 if (bVisible) {
334 GetCaretInfo(ptHead, ptFoot);
335 }
336
337 CPVT_WordPlace wpTemp = m_pEdit->GetCaretWordPlace();
338 IOnSetCaret(bVisible, ptHead, ptFoot, wpTemp);
339}
340
Tom Sepez281a9ea2016-02-26 14:24:28 -0800341void CPWL_EditCtrl::GetCaretInfo(CFX_FloatPoint& ptHead,
342 CFX_FloatPoint& ptFoot) const {
dsinclaire35af1e2016-07-13 11:26:20 -0700343 CFX_Edit_Iterator* pIterator = m_pEdit->GetIterator();
thestig821d59e2016-05-11 12:59:22 -0700344 pIterator->SetAt(m_pEdit->GetCaret());
345 CPVT_Word word;
346 CPVT_Line line;
347 if (pIterator->GetWord(word)) {
348 ptHead.x = word.ptWord.x + word.fWidth;
349 ptHead.y = word.ptWord.y + word.fAscent;
350 ptFoot.x = word.ptWord.x + word.fWidth;
351 ptFoot.y = word.ptWord.y + word.fDescent;
352 } else if (pIterator->GetLine(line)) {
353 ptHead.x = line.ptLine.x;
354 ptHead.y = line.ptLine.y + line.fLineAscent;
355 ptFoot.x = line.ptLine.x;
356 ptFoot.y = line.ptLine.y + line.fLineDescent;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700357 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700358}
359
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700360void CPWL_EditCtrl::GetCaretPos(int32_t& x, int32_t& y) const {
Tom Sepez281a9ea2016-02-26 14:24:28 -0800361 CFX_FloatPoint ptHead(0, 0), ptFoot(0, 0);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700362
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700363 GetCaretInfo(ptHead, ptFoot);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700364
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700365 PWLtoWnd(ptHead, x, y);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700366}
367
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700368void CPWL_EditCtrl::SetCaret(FX_BOOL bVisible,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800369 const CFX_FloatPoint& ptHead,
370 const CFX_FloatPoint& ptFoot) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700371 if (m_pEditCaret) {
372 if (!IsFocused() || m_pEdit->IsSelected())
373 bVisible = FALSE;
374
375 m_pEditCaret->SetCaret(bVisible, ptHead, ptFoot);
376 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700377}
378
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700379CFX_WideString CPWL_EditCtrl::GetText() const {
380 return m_pEdit->GetText();
381}
382
383void CPWL_EditCtrl::SetSel(int32_t nStartChar, int32_t nEndChar) {
384 m_pEdit->SetSel(nStartChar, nEndChar);
385}
386
387void CPWL_EditCtrl::GetSel(int32_t& nStartChar, int32_t& nEndChar) const {
388 m_pEdit->GetSel(nStartChar, nEndChar);
389}
390
391void CPWL_EditCtrl::Clear() {
392 if (!IsReadOnly())
393 m_pEdit->Clear();
394}
395
396void CPWL_EditCtrl::SelectAll() {
397 m_pEdit->SelectAll();
398}
399
400void CPWL_EditCtrl::Paint() {
thestig732f6a02016-05-12 10:41:56 -0700401 m_pEdit->Paint();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700402}
403
404void CPWL_EditCtrl::EnableRefresh(FX_BOOL bRefresh) {
thestig732f6a02016-05-12 10:41:56 -0700405 m_pEdit->EnableRefresh(bRefresh);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700406}
407
408int32_t CPWL_EditCtrl::GetCaret() const {
thestig732f6a02016-05-12 10:41:56 -0700409 return m_pEdit->GetCaret();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700410}
411
412void CPWL_EditCtrl::SetCaret(int32_t nPos) {
thestig732f6a02016-05-12 10:41:56 -0700413 m_pEdit->SetCaret(nPos);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700414}
415
416int32_t CPWL_EditCtrl::GetTotalWords() const {
thestig732f6a02016-05-12 10:41:56 -0700417 return m_pEdit->GetTotalWords();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700418}
419
Tom Sepez281a9ea2016-02-26 14:24:28 -0800420void CPWL_EditCtrl::SetScrollPos(const CFX_FloatPoint& point) {
thestig732f6a02016-05-12 10:41:56 -0700421 m_pEdit->SetScrollPos(point);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700422}
423
Tom Sepez281a9ea2016-02-26 14:24:28 -0800424CFX_FloatPoint CPWL_EditCtrl::GetScrollPos() const {
thestig732f6a02016-05-12 10:41:56 -0700425 return m_pEdit->GetScrollPos();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700426}
427
428CPDF_Font* CPWL_EditCtrl::GetCaretFont() const {
429 int32_t nFontIndex = 0;
430
dsinclaire35af1e2016-07-13 11:26:20 -0700431 CFX_Edit_Iterator* pIterator = m_pEdit->GetIterator();
thestig821d59e2016-05-11 12:59:22 -0700432 pIterator->SetAt(m_pEdit->GetCaret());
433 CPVT_Word word;
434 CPVT_Section section;
435 if (pIterator->GetWord(word)) {
436 nFontIndex = word.nFontIndex;
437 } else if (HasFlag(PES_RICH)) {
438 if (pIterator->GetSection(section)) {
439 nFontIndex = section.WordProps.nFontIndex;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700440 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700441 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700442
dsinclairc7a73492016-04-05 12:01:42 -0700443 if (IPVT_FontMap* pFontMap = GetFontMap())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700444 return pFontMap->GetPDFFont(nFontIndex);
445
thestig1cd352e2016-06-07 17:53:06 -0700446 return nullptr;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700447}
448
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700449FX_FLOAT CPWL_EditCtrl::GetCaretFontSize() const {
450 FX_FLOAT fFontSize = GetFontSize();
451
dsinclaire35af1e2016-07-13 11:26:20 -0700452 CFX_Edit_Iterator* pIterator = m_pEdit->GetIterator();
thestig821d59e2016-05-11 12:59:22 -0700453 pIterator->SetAt(m_pEdit->GetCaret());
454 CPVT_Word word;
455 CPVT_Section section;
456 if (pIterator->GetWord(word)) {
457 fFontSize = word.fFontSize;
458 } else if (HasFlag(PES_RICH)) {
459 if (pIterator->GetSection(section)) {
460 fFontSize = section.WordProps.fFontSize;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700461 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700462 }
463
464 return fFontSize;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700465}
466
tsepez067990c2016-09-13 06:46:40 -0700467void CPWL_EditCtrl::SetText(const CFX_WideString& wsText) {
468 m_pEdit->SetText(wsText);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700469}
470
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700471void CPWL_EditCtrl::CopyText() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700472
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700473void CPWL_EditCtrl::PasteText() {}
474
475void CPWL_EditCtrl::CutText() {}
476
477void CPWL_EditCtrl::ShowVScrollBar(FX_BOOL bShow) {}
478
tsepez067990c2016-09-13 06:46:40 -0700479void CPWL_EditCtrl::InsertText(const CFX_WideString& wsText) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700480 if (!IsReadOnly())
tsepez067990c2016-09-13 06:46:40 -0700481 m_pEdit->InsertText(wsText, DEFAULT_CHARSET);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700482}
483
Tom Sepez62a70f92016-03-21 15:00:20 -0700484void CPWL_EditCtrl::InsertWord(uint16_t word, int32_t nCharset) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700485 if (!IsReadOnly())
486 m_pEdit->InsertWord(word, nCharset);
487}
488
489void CPWL_EditCtrl::InsertReturn() {
490 if (!IsReadOnly())
491 m_pEdit->InsertReturn();
492}
493
494void CPWL_EditCtrl::Delete() {
495 if (!IsReadOnly())
496 m_pEdit->Delete();
497}
498
499void CPWL_EditCtrl::Backspace() {
500 if (!IsReadOnly())
501 m_pEdit->Backspace();
502}
503
504FX_BOOL CPWL_EditCtrl::CanUndo() const {
505 return !IsReadOnly() && m_pEdit->CanUndo();
506}
507
508FX_BOOL CPWL_EditCtrl::CanRedo() const {
509 return !IsReadOnly() && m_pEdit->CanRedo();
510}
511
512void CPWL_EditCtrl::Redo() {
513 if (CanRedo())
514 m_pEdit->Redo();
515}
516
517void CPWL_EditCtrl::Undo() {
518 if (CanUndo())
519 m_pEdit->Undo();
520}
521
522void CPWL_EditCtrl::IOnSetScrollInfoY(FX_FLOAT fPlateMin,
523 FX_FLOAT fPlateMax,
524 FX_FLOAT fContentMin,
525 FX_FLOAT fContentMax,
526 FX_FLOAT fSmallStep,
527 FX_FLOAT fBigStep) {
528 PWL_SCROLL_INFO Info;
529
530 Info.fPlateWidth = fPlateMax - fPlateMin;
531 Info.fContentMin = fContentMin;
532 Info.fContentMax = fContentMax;
533 Info.fSmallStep = fSmallStep;
534 Info.fBigStep = fBigStep;
535
536 OnNotify(this, PNM_SETSCROLLINFO, SBT_VSCROLL, (intptr_t)&Info);
537
538 if (IsFloatBigger(Info.fPlateWidth, Info.fContentMax - Info.fContentMin) ||
539 IsFloatEqual(Info.fPlateWidth, Info.fContentMax - Info.fContentMin)) {
540 ShowVScrollBar(FALSE);
541 } else {
542 ShowVScrollBar(TRUE);
543 }
544}
545
546void CPWL_EditCtrl::IOnSetScrollPosY(FX_FLOAT fy) {
547 OnNotify(this, PNM_SETSCROLLPOS, SBT_VSCROLL, (intptr_t)&fy);
548}
549
550void CPWL_EditCtrl::IOnSetCaret(FX_BOOL bVisible,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800551 const CFX_FloatPoint& ptHead,
552 const CFX_FloatPoint& ptFoot,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700553 const CPVT_WordPlace& place) {
554 PWL_CARET_INFO cInfo;
555 cInfo.bVisible = bVisible;
556 cInfo.ptHead = ptHead;
557 cInfo.ptFoot = ptFoot;
558
thestig1cd352e2016-06-07 17:53:06 -0700559 OnNotify(this, PNM_SETCARETINFO, (intptr_t)&cInfo, (intptr_t) nullptr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700560}
561
dsinclairdbc77162016-07-13 11:34:23 -0700562void CPWL_EditCtrl::IOnCaretChange(const CPVT_SecProps& secProps,
563 const CPVT_WordProps& wordProps) {}
564
565void CPWL_EditCtrl::IOnContentChange(const CFX_FloatRect& rcContent) {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700566
Tom Sepez281a9ea2016-02-26 14:24:28 -0800567void CPWL_EditCtrl::IOnInvalidateRect(CFX_FloatRect* pRect) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700568 InvalidateRect(pRect);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700569}
570
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700571int32_t CPWL_EditCtrl::GetCharSet() const {
572 return m_nCharSet < 0 ? DEFAULT_CHARSET : m_nCharSet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700573}
574
Tom Sepez281a9ea2016-02-26 14:24:28 -0800575void CPWL_EditCtrl::GetTextRange(const CFX_FloatRect& rect,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700576 int32_t& nStartChar,
577 int32_t& nEndChar) const {
578 nStartChar = m_pEdit->WordPlaceToWordIndex(
Tom Sepez281a9ea2016-02-26 14:24:28 -0800579 m_pEdit->SearchWordPlace(CFX_FloatPoint(rect.left, rect.top)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700580 nEndChar = m_pEdit->WordPlaceToWordIndex(
Tom Sepez281a9ea2016-02-26 14:24:28 -0800581 m_pEdit->SearchWordPlace(CFX_FloatPoint(rect.right, rect.bottom)));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700582}
583
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700584CFX_WideString CPWL_EditCtrl::GetText(int32_t& nStartChar,
585 int32_t& nEndChar) const {
586 CPVT_WordPlace wpStart = m_pEdit->WordIndexToWordPlace(nStartChar);
587 CPVT_WordPlace wpEnd = m_pEdit->WordIndexToWordPlace(nEndChar);
588 return m_pEdit->GetRangeText(CPVT_WordRange(wpStart, wpEnd));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700589}
590
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700591void CPWL_EditCtrl::SetReadyToInput() {
592 if (m_bMouseDown) {
593 ReleaseCapture();
594 m_bMouseDown = FALSE;
595 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700596}