blob: f18aaaa13094338b62c953daa0b230d30c6b2ceb [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 Zhang633a3b72017-06-02 15:27:22 -07007#include "fpdfsdk/pdfwindow/cpwl_edit_ctrl.h"
Lei Zhangc2fb35f2016-01-05 16:46:58 -08008
dsinclair1727aee2016-09-29 13:12:56 -07009#include "core/fpdfdoc/cpvt_section.h"
10#include "core/fpdfdoc/cpvt_word.h"
dsinclair74a34fc2016-09-29 16:41:42 -070011#include "core/fxge/fx_font.h"
dsinclair0bb385b2016-09-29 17:03:59 -070012#include "fpdfsdk/fxedit/fxet_edit.h"
Lei Zhang633a3b72017-06-02 15:27:22 -070013#include "fpdfsdk/pdfwindow/cpwl_caret.h"
14#include "fpdfsdk/pdfwindow/cpwl_font_map.h"
15#include "fpdfsdk/pdfwindow/cpwl_scroll_bar.h"
16#include "fpdfsdk/pdfwindow/cpwl_utils.h"
17#include "fpdfsdk/pdfwindow/cpwl_wnd.h"
Lei Zhangc2fb35f2016-01-05 16:46:58 -080018#include "public/fpdf_fwlevent.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070019
Nico Weber9d8ec5a2015-08-04 13:00:21 -070020CPWL_EditCtrl::CPWL_EditCtrl()
dsinclaire35af1e2016-07-13 11:26:20 -070021 : m_pEdit(new CFX_Edit),
thestig1cd352e2016-06-07 17:53:06 -070022 m_pEditCaret(nullptr),
tsepez4cf55152016-11-02 14:37:54 -070023 m_bMouseDown(false),
Dan Sinclairf51a02a2017-04-19 12:46:53 -040024 m_nCharSet(FX_CHARSET_Default) {}
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
tsepez4cf55152016-11-02 14:37:54 -070040bool CPWL_EditCtrl::IsWndHorV() {
Tom Sepez60d909e2015-12-10 15:34:55 -080041 CFX_Matrix mt = GetWindowMatrix();
Dan Sinclair1f403ce2017-02-21 12:56:24 -050042 return mt.Transform(CFX_PointF(1, 1)).y == mt.Transform(CFX_PointF(0, 1)).y;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070043}
44
Nico Weber9d8ec5a2015-08-04 13:00:21 -070045void CPWL_EditCtrl::SetCursor() {
46 if (IsValid()) {
dsinclairb9590102016-04-27 06:38:59 -070047 if (CFX_SystemHandler* pSH = GetSystemHandler()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070048 if (IsWndHorV())
49 pSH->SetCursor(FXCT_VBEAM);
50 else
51 pSH->SetCursor(FXCT_HBEAM);
Tom Sepez2f2ffec2015-07-23 14:42:09 -070052 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070053 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070054}
55
Diana Gagedce2d722017-06-20 11:17:11 -070056CFX_WideString CPWL_EditCtrl::GetSelectedText() {
57 if (m_pEdit)
58 return m_pEdit->GetSelText();
59
60 return CFX_WideString();
61}
62
Nico Weber9d8ec5a2015-08-04 13:00:21 -070063void CPWL_EditCtrl::RePosChildWnd() {
64 m_pEdit->SetPlateRect(GetClientRect());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070065}
66
Dan Sinclairfb00ec22017-07-05 09:28:15 -040067void CPWL_EditCtrl::SetScrollInfo(const PWL_SCROLL_INFO& info) {
68 if (CPWL_Wnd* pChild = GetVScrollBar())
69 pChild->SetScrollInfo(info);
70}
71
Dan Sinclair7e0336e2017-07-05 09:39:50 -040072void CPWL_EditCtrl::SetScrollPosition(float pos) {
73 if (CPWL_Wnd* pChild = GetVScrollBar())
74 pChild->SetScrollPosition(pos);
75}
76
Nico Weber9d8ec5a2015-08-04 13:00:21 -070077void CPWL_EditCtrl::OnNotify(CPWL_Wnd* pWnd,
tsepezc3255f52016-03-25 14:52:27 -070078 uint32_t msg,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070079 intptr_t wParam,
80 intptr_t lParam) {
81 CPWL_Wnd::OnNotify(pWnd, msg, wParam, lParam);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070082
Nico Weber9d8ec5a2015-08-04 13:00:21 -070083 switch (msg) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070084 case PNM_SCROLLWINDOW: {
Dan Sinclair05df0752017-03-14 14:43:42 -040085 float fPos = *(float*)lParam;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070086 switch (wParam) {
87 case SBT_VSCROLL:
Dan Sinclairf528eee2017-02-14 11:52:07 -050088 m_pEdit->SetScrollPos(CFX_PointF(m_pEdit->GetScrollPos().x, fPos));
Nico Weber9d8ec5a2015-08-04 13:00:21 -070089 break;
90 }
91 } break;
92 case PNM_SETCARETINFO: {
93 if (PWL_CARET_INFO* pCaretInfo = (PWL_CARET_INFO*)wParam) {
94 SetCaret(pCaretInfo->bVisible, pCaretInfo->ptHead, pCaretInfo->ptFoot);
95 }
96 } break;
97 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070098}
99
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700100void CPWL_EditCtrl::CreateChildWnd(const PWL_CREATEPARAM& cp) {
101 if (!IsReadOnly())
102 CreateEditCaret(cp);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700103}
104
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700105void CPWL_EditCtrl::CreateEditCaret(const PWL_CREATEPARAM& cp) {
thestig732f6a02016-05-12 10:41:56 -0700106 if (m_pEditCaret)
107 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700108
thestig732f6a02016-05-12 10:41:56 -0700109 m_pEditCaret = new CPWL_Caret;
110 m_pEditCaret->SetInvalidRect(GetClientRect());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700111
thestig732f6a02016-05-12 10:41:56 -0700112 PWL_CREATEPARAM ecp = cp;
113 ecp.pParentWnd = this;
114 ecp.dwFlags = PWS_CHILD | PWS_NOREFRESHCLIP;
115 ecp.dwBorderWidth = 0;
dsinclair92cb5e52016-05-16 11:38:28 -0700116 ecp.nBorderStyle = BorderStyle::SOLID;
Lei Zhangd24236a2017-06-29 18:28:58 -0700117 ecp.rcRectWnd = CFX_FloatRect();
thestig732f6a02016-05-12 10:41:56 -0700118
119 m_pEditCaret->Create(ecp);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700120}
121
Dan Sinclair05df0752017-03-14 14:43:42 -0400122void CPWL_EditCtrl::SetFontSize(float fFontSize) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700123 m_pEdit->SetFontSize(fFontSize);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700124}
125
Dan Sinclair05df0752017-03-14 14:43:42 -0400126float CPWL_EditCtrl::GetFontSize() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700127 return m_pEdit->GetFontSize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700128}
129
tsepez4cf55152016-11-02 14:37:54 -0700130bool CPWL_EditCtrl::OnKeyDown(uint16_t nChar, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700131 if (m_bMouseDown)
tsepez4cf55152016-11-02 14:37:54 -0700132 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700133
tsepez4cf55152016-11-02 14:37:54 -0700134 bool bRet = CPWL_Wnd::OnKeyDown(nChar, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700135
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700136 // FILTER
137 switch (nChar) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700138 default:
tsepez4cf55152016-11-02 14:37:54 -0700139 return false;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700140 case FWL_VKEY_Delete:
141 case FWL_VKEY_Up:
142 case FWL_VKEY_Down:
143 case FWL_VKEY_Left:
144 case FWL_VKEY_Right:
145 case FWL_VKEY_Home:
146 case FWL_VKEY_End:
147 case FWL_VKEY_Insert:
148 case 'C':
149 case 'V':
150 case 'X':
151 case 'A':
152 case 'Z':
153 case 'c':
154 case 'v':
155 case 'x':
156 case 'a':
157 case 'z':
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700158 break;
159 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700160
thestig594b20b2016-05-12 21:56:43 -0700161 if (nChar == FWL_VKEY_Delete && m_pEdit->IsSelected())
162 nChar = FWL_VKEY_Unknown;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700163
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700164 switch (nChar) {
165 case FWL_VKEY_Delete:
166 Delete();
tsepez4cf55152016-11-02 14:37:54 -0700167 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700168 case FWL_VKEY_Insert:
169 if (IsSHIFTpressed(nFlag))
170 PasteText();
tsepez4cf55152016-11-02 14:37:54 -0700171 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700172 case FWL_VKEY_Up:
tsepez4cf55152016-11-02 14:37:54 -0700173 m_pEdit->OnVK_UP(IsSHIFTpressed(nFlag), false);
174 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700175 case FWL_VKEY_Down:
tsepez4cf55152016-11-02 14:37:54 -0700176 m_pEdit->OnVK_DOWN(IsSHIFTpressed(nFlag), false);
177 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700178 case FWL_VKEY_Left:
tsepez4cf55152016-11-02 14:37:54 -0700179 m_pEdit->OnVK_LEFT(IsSHIFTpressed(nFlag), false);
180 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700181 case FWL_VKEY_Right:
tsepez4cf55152016-11-02 14:37:54 -0700182 m_pEdit->OnVK_RIGHT(IsSHIFTpressed(nFlag), false);
183 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700184 case FWL_VKEY_Home:
185 m_pEdit->OnVK_HOME(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
tsepez4cf55152016-11-02 14:37:54 -0700186 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700187 case FWL_VKEY_End:
188 m_pEdit->OnVK_END(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
tsepez4cf55152016-11-02 14:37:54 -0700189 return true;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700190 case FWL_VKEY_Unknown:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700191 if (!IsSHIFTpressed(nFlag))
192 Clear();
193 else
194 CutText();
tsepez4cf55152016-11-02 14:37:54 -0700195 return true;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700196 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700197 break;
198 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700199
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700200 return bRet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700201}
202
tsepez4cf55152016-11-02 14:37:54 -0700203bool CPWL_EditCtrl::OnChar(uint16_t nChar, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700204 if (m_bMouseDown)
tsepez4cf55152016-11-02 14:37:54 -0700205 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700206
207 CPWL_Wnd::OnChar(nChar, nFlag);
208
209 // FILTER
210 switch (nChar) {
211 case 0x0A:
212 case 0x1B:
tsepez4cf55152016-11-02 14:37:54 -0700213 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700214 default:
215 break;
216 }
217
tsepez4cf55152016-11-02 14:37:54 -0700218 bool bCtrl = IsCTRLpressed(nFlag);
219 bool bAlt = IsALTpressed(nFlag);
220 bool bShift = IsSHIFTpressed(nFlag);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700221
Tom Sepez62a70f92016-03-21 15:00:20 -0700222 uint16_t word = nChar;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700223
224 if (bCtrl && !bAlt) {
225 switch (nChar) {
226 case 'C' - 'A' + 1:
227 CopyText();
tsepez4cf55152016-11-02 14:37:54 -0700228 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700229 case 'V' - 'A' + 1:
230 PasteText();
tsepez4cf55152016-11-02 14:37:54 -0700231 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700232 case 'X' - 'A' + 1:
233 CutText();
tsepez4cf55152016-11-02 14:37:54 -0700234 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700235 case 'A' - 'A' + 1:
236 SelectAll();
tsepez4cf55152016-11-02 14:37:54 -0700237 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700238 case 'Z' - 'A' + 1:
239 if (bShift)
240 Redo();
241 else
242 Undo();
tsepez4cf55152016-11-02 14:37:54 -0700243 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700244 default:
245 if (nChar < 32)
tsepez4cf55152016-11-02 14:37:54 -0700246 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700247 }
248 }
249
250 if (IsReadOnly())
tsepez4cf55152016-11-02 14:37:54 -0700251 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700252
253 if (m_pEdit->IsSelected() && word == FWL_VKEY_Back)
254 word = FWL_VKEY_Unknown;
255
256 Clear();
257
258 switch (word) {
259 case FWL_VKEY_Back:
260 Backspace();
261 break;
262 case FWL_VKEY_Return:
263 InsertReturn();
264 break;
265 case FWL_VKEY_Unknown:
266 break;
267 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700268 InsertWord(word, GetCharSet());
269 break;
270 }
271
tsepez4cf55152016-11-02 14:37:54 -0700272 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700273}
274
Dan Sinclairf528eee2017-02-14 11:52:07 -0500275bool CPWL_EditCtrl::OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700276 CPWL_Wnd::OnLButtonDown(point, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700277
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700278 if (ClientHitTest(point)) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700279 if (m_bMouseDown)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700280 InvalidateRect();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700281
tsepez4cf55152016-11-02 14:37:54 -0700282 m_bMouseDown = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700283 SetCapture();
284
285 m_pEdit->OnMouseDown(point, IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
286 }
287
tsepez4cf55152016-11-02 14:37:54 -0700288 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700289}
290
Dan Sinclairf528eee2017-02-14 11:52:07 -0500291bool CPWL_EditCtrl::OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700292 CPWL_Wnd::OnLButtonUp(point, nFlag);
293
294 if (m_bMouseDown) {
295 // can receive keybord message
296 if (ClientHitTest(point) && !IsFocused())
297 SetFocus();
298
299 ReleaseCapture();
tsepez4cf55152016-11-02 14:37:54 -0700300 m_bMouseDown = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700301 }
302
tsepez4cf55152016-11-02 14:37:54 -0700303 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700304}
305
Dan Sinclairf528eee2017-02-14 11:52:07 -0500306bool CPWL_EditCtrl::OnMouseMove(const CFX_PointF& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700307 CPWL_Wnd::OnMouseMove(point, nFlag);
308
309 if (m_bMouseDown)
tsepez4cf55152016-11-02 14:37:54 -0700310 m_pEdit->OnMouseMove(point, false, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700311
tsepez4cf55152016-11-02 14:37:54 -0700312 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700313}
314
tsepez4cf55152016-11-02 14:37:54 -0700315void CPWL_EditCtrl::SetEditCaret(bool bVisible) {
Dan Sinclairf528eee2017-02-14 11:52:07 -0500316 CFX_PointF ptHead;
317 CFX_PointF ptFoot;
tsepez63f545c2016-09-13 16:08:49 -0700318 if (bVisible)
Dan Sinclair1f403ce2017-02-21 12:56:24 -0500319 GetCaretInfo(&ptHead, &ptFoot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700320
321 CPVT_WordPlace wpTemp = m_pEdit->GetCaretWordPlace();
322 IOnSetCaret(bVisible, ptHead, ptFoot, wpTemp);
323}
324
Dan Sinclair1f403ce2017-02-21 12:56:24 -0500325void CPWL_EditCtrl::GetCaretInfo(CFX_PointF* ptHead, CFX_PointF* ptFoot) const {
dsinclaire35af1e2016-07-13 11:26:20 -0700326 CFX_Edit_Iterator* pIterator = m_pEdit->GetIterator();
thestig821d59e2016-05-11 12:59:22 -0700327 pIterator->SetAt(m_pEdit->GetCaret());
328 CPVT_Word word;
329 CPVT_Line line;
330 if (pIterator->GetWord(word)) {
Dan Sinclair1f403ce2017-02-21 12:56:24 -0500331 ptHead->x = word.ptWord.x + word.fWidth;
332 ptHead->y = word.ptWord.y + word.fAscent;
333 ptFoot->x = word.ptWord.x + word.fWidth;
334 ptFoot->y = word.ptWord.y + word.fDescent;
thestig821d59e2016-05-11 12:59:22 -0700335 } else if (pIterator->GetLine(line)) {
Dan Sinclair1f403ce2017-02-21 12:56:24 -0500336 ptHead->x = line.ptLine.x;
337 ptHead->y = line.ptLine.y + line.fLineAscent;
338 ptFoot->x = line.ptLine.x;
339 ptFoot->y = line.ptLine.y + line.fLineDescent;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700340 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700341}
342
tsepez4cf55152016-11-02 14:37:54 -0700343void CPWL_EditCtrl::SetCaret(bool bVisible,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500344 const CFX_PointF& ptHead,
345 const CFX_PointF& ptFoot) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700346 if (m_pEditCaret) {
347 if (!IsFocused() || m_pEdit->IsSelected())
tsepez4cf55152016-11-02 14:37:54 -0700348 bVisible = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700349
350 m_pEditCaret->SetCaret(bVisible, ptHead, ptFoot);
351 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700352}
353
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700354CFX_WideString CPWL_EditCtrl::GetText() const {
355 return m_pEdit->GetText();
356}
357
358void CPWL_EditCtrl::SetSel(int32_t nStartChar, int32_t nEndChar) {
359 m_pEdit->SetSel(nStartChar, nEndChar);
360}
361
362void CPWL_EditCtrl::GetSel(int32_t& nStartChar, int32_t& nEndChar) const {
363 m_pEdit->GetSel(nStartChar, nEndChar);
364}
365
366void CPWL_EditCtrl::Clear() {
367 if (!IsReadOnly())
368 m_pEdit->Clear();
369}
370
371void CPWL_EditCtrl::SelectAll() {
372 m_pEdit->SelectAll();
373}
374
Dan Sinclairf528eee2017-02-14 11:52:07 -0500375void CPWL_EditCtrl::SetScrollPos(const CFX_PointF& point) {
thestig732f6a02016-05-12 10:41:56 -0700376 m_pEdit->SetScrollPos(point);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700377}
378
Dan Sinclairf528eee2017-02-14 11:52:07 -0500379CFX_PointF CPWL_EditCtrl::GetScrollPos() const {
thestig732f6a02016-05-12 10:41:56 -0700380 return m_pEdit->GetScrollPos();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700381}
382
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700383void CPWL_EditCtrl::CopyText() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700384
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700385void CPWL_EditCtrl::PasteText() {}
386
387void CPWL_EditCtrl::CutText() {}
388
tsepez4cf55152016-11-02 14:37:54 -0700389void CPWL_EditCtrl::ShowVScrollBar(bool bShow) {}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700390
Tom Sepez62a70f92016-03-21 15:00:20 -0700391void CPWL_EditCtrl::InsertWord(uint16_t word, int32_t nCharset) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700392 if (!IsReadOnly())
393 m_pEdit->InsertWord(word, nCharset);
394}
395
396void CPWL_EditCtrl::InsertReturn() {
397 if (!IsReadOnly())
398 m_pEdit->InsertReturn();
399}
400
401void CPWL_EditCtrl::Delete() {
402 if (!IsReadOnly())
403 m_pEdit->Delete();
404}
405
406void CPWL_EditCtrl::Backspace() {
407 if (!IsReadOnly())
408 m_pEdit->Backspace();
409}
410
tsepez4cf55152016-11-02 14:37:54 -0700411bool CPWL_EditCtrl::CanUndo() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700412 return !IsReadOnly() && m_pEdit->CanUndo();
413}
414
tsepez4cf55152016-11-02 14:37:54 -0700415bool CPWL_EditCtrl::CanRedo() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700416 return !IsReadOnly() && m_pEdit->CanRedo();
417}
418
419void CPWL_EditCtrl::Redo() {
420 if (CanRedo())
421 m_pEdit->Redo();
422}
423
424void CPWL_EditCtrl::Undo() {
425 if (CanUndo())
426 m_pEdit->Undo();
427}
428
Dan Sinclair05df0752017-03-14 14:43:42 -0400429void CPWL_EditCtrl::IOnSetScrollInfoY(float fPlateMin,
430 float fPlateMax,
431 float fContentMin,
432 float fContentMax,
433 float fSmallStep,
434 float fBigStep) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700435 PWL_SCROLL_INFO Info;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700436 Info.fPlateWidth = fPlateMax - fPlateMin;
437 Info.fContentMin = fContentMin;
438 Info.fContentMax = fContentMax;
439 Info.fSmallStep = fSmallStep;
440 Info.fBigStep = fBigStep;
Dan Sinclairfb00ec22017-07-05 09:28:15 -0400441 SetScrollInfo(Info);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700442
443 if (IsFloatBigger(Info.fPlateWidth, Info.fContentMax - Info.fContentMin) ||
444 IsFloatEqual(Info.fPlateWidth, Info.fContentMax - Info.fContentMin)) {
tsepez4cf55152016-11-02 14:37:54 -0700445 ShowVScrollBar(false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700446 } else {
tsepez4cf55152016-11-02 14:37:54 -0700447 ShowVScrollBar(true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700448 }
449}
450
Dan Sinclair05df0752017-03-14 14:43:42 -0400451void CPWL_EditCtrl::IOnSetScrollPosY(float fy) {
Dan Sinclair7e0336e2017-07-05 09:39:50 -0400452 SetScrollPosition(fy);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700453}
454
tsepez4cf55152016-11-02 14:37:54 -0700455void CPWL_EditCtrl::IOnSetCaret(bool bVisible,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500456 const CFX_PointF& ptHead,
457 const CFX_PointF& ptFoot,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700458 const CPVT_WordPlace& place) {
459 PWL_CARET_INFO cInfo;
460 cInfo.bVisible = bVisible;
461 cInfo.ptHead = ptHead;
462 cInfo.ptFoot = ptFoot;
463
thestig1cd352e2016-06-07 17:53:06 -0700464 OnNotify(this, PNM_SETCARETINFO, (intptr_t)&cInfo, (intptr_t) nullptr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700465}
466
Tom Sepez281a9ea2016-02-26 14:24:28 -0800467void CPWL_EditCtrl::IOnInvalidateRect(CFX_FloatRect* pRect) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700468 InvalidateRect(pRect);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700469}
470
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700471int32_t CPWL_EditCtrl::GetCharSet() const {
Dan Sinclairf51a02a2017-04-19 12:46:53 -0400472 return m_nCharSet < 0 ? FX_CHARSET_Default : m_nCharSet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700473}
474
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700475void CPWL_EditCtrl::SetReadyToInput() {
476 if (m_bMouseDown) {
477 ReleaseCapture();
tsepez4cf55152016-11-02 14:37:54 -0700478 m_bMouseDown = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700479 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700480}