blob: 3390696e01de38d91f2302a36ec621f474ee5a3d [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
Nico Weber9d8ec5a2015-08-04 13:00:21 -070067void CPWL_EditCtrl::OnNotify(CPWL_Wnd* pWnd,
tsepezc3255f52016-03-25 14:52:27 -070068 uint32_t msg,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070069 intptr_t wParam,
70 intptr_t lParam) {
71 CPWL_Wnd::OnNotify(pWnd, msg, wParam, lParam);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070072
Nico Weber9d8ec5a2015-08-04 13:00:21 -070073 switch (msg) {
74 case PNM_SETSCROLLINFO:
75 switch (wParam) {
76 case SBT_VSCROLL:
77 if (CPWL_Wnd* pChild = GetVScrollBar()) {
78 pChild->OnNotify(pWnd, PNM_SETSCROLLINFO, wParam, lParam);
79 }
80 break;
81 }
82 break;
83 case PNM_SETSCROLLPOS:
84 switch (wParam) {
85 case SBT_VSCROLL:
86 if (CPWL_Wnd* pChild = GetVScrollBar()) {
87 pChild->OnNotify(pWnd, PNM_SETSCROLLPOS, wParam, lParam);
88 }
89 break;
90 }
91 break;
92 case PNM_SCROLLWINDOW: {
Dan Sinclair05df0752017-03-14 14:43:42 -040093 float fPos = *(float*)lParam;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070094 switch (wParam) {
95 case SBT_VSCROLL:
Dan Sinclairf528eee2017-02-14 11:52:07 -050096 m_pEdit->SetScrollPos(CFX_PointF(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
Dan Sinclair05df0752017-03-14 14:43:42 -0400130void CPWL_EditCtrl::SetFontSize(float fFontSize) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700131 m_pEdit->SetFontSize(fFontSize);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700132}
133
Dan Sinclair05df0752017-03-14 14:43:42 -0400134float CPWL_EditCtrl::GetFontSize() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700135 return m_pEdit->GetFontSize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700136}
137
tsepez4cf55152016-11-02 14:37:54 -0700138bool CPWL_EditCtrl::OnKeyDown(uint16_t nChar, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700139 if (m_bMouseDown)
tsepez4cf55152016-11-02 14:37:54 -0700140 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700141
tsepez4cf55152016-11-02 14:37:54 -0700142 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:
tsepez4cf55152016-11-02 14:37:54 -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();
tsepez4cf55152016-11-02 14:37:54 -0700175 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700176 case FWL_VKEY_Insert:
177 if (IsSHIFTpressed(nFlag))
178 PasteText();
tsepez4cf55152016-11-02 14:37:54 -0700179 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700180 case FWL_VKEY_Up:
tsepez4cf55152016-11-02 14:37:54 -0700181 m_pEdit->OnVK_UP(IsSHIFTpressed(nFlag), false);
182 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700183 case FWL_VKEY_Down:
tsepez4cf55152016-11-02 14:37:54 -0700184 m_pEdit->OnVK_DOWN(IsSHIFTpressed(nFlag), false);
185 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700186 case FWL_VKEY_Left:
tsepez4cf55152016-11-02 14:37:54 -0700187 m_pEdit->OnVK_LEFT(IsSHIFTpressed(nFlag), false);
188 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700189 case FWL_VKEY_Right:
tsepez4cf55152016-11-02 14:37:54 -0700190 m_pEdit->OnVK_RIGHT(IsSHIFTpressed(nFlag), false);
191 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700192 case FWL_VKEY_Home:
193 m_pEdit->OnVK_HOME(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
tsepez4cf55152016-11-02 14:37:54 -0700194 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700195 case FWL_VKEY_End:
196 m_pEdit->OnVK_END(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
tsepez4cf55152016-11-02 14:37:54 -0700197 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();
tsepez4cf55152016-11-02 14:37:54 -0700203 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
tsepez4cf55152016-11-02 14:37:54 -0700211bool CPWL_EditCtrl::OnChar(uint16_t nChar, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700212 if (m_bMouseDown)
tsepez4cf55152016-11-02 14:37:54 -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:
tsepez4cf55152016-11-02 14:37:54 -0700221 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700222 default:
223 break;
224 }
225
tsepez4cf55152016-11-02 14:37:54 -0700226 bool bCtrl = IsCTRLpressed(nFlag);
227 bool bAlt = IsALTpressed(nFlag);
228 bool bShift = IsSHIFTpressed(nFlag);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700229
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();
tsepez4cf55152016-11-02 14:37:54 -0700236 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700237 case 'V' - 'A' + 1:
238 PasteText();
tsepez4cf55152016-11-02 14:37:54 -0700239 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700240 case 'X' - 'A' + 1:
241 CutText();
tsepez4cf55152016-11-02 14:37:54 -0700242 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700243 case 'A' - 'A' + 1:
244 SelectAll();
tsepez4cf55152016-11-02 14:37:54 -0700245 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700246 case 'Z' - 'A' + 1:
247 if (bShift)
248 Redo();
249 else
250 Undo();
tsepez4cf55152016-11-02 14:37:54 -0700251 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700252 default:
253 if (nChar < 32)
tsepez4cf55152016-11-02 14:37:54 -0700254 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700255 }
256 }
257
258 if (IsReadOnly())
tsepez4cf55152016-11-02 14:37:54 -0700259 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700260
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
tsepez4cf55152016-11-02 14:37:54 -0700280 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700281}
282
Dan Sinclairf528eee2017-02-14 11:52:07 -0500283bool CPWL_EditCtrl::OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700284 CPWL_Wnd::OnLButtonDown(point, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700285
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700286 if (ClientHitTest(point)) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700287 if (m_bMouseDown)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700288 InvalidateRect();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700289
tsepez4cf55152016-11-02 14:37:54 -0700290 m_bMouseDown = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700291 SetCapture();
292
293 m_pEdit->OnMouseDown(point, IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
294 }
295
tsepez4cf55152016-11-02 14:37:54 -0700296 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700297}
298
Dan Sinclairf528eee2017-02-14 11:52:07 -0500299bool CPWL_EditCtrl::OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700300 CPWL_Wnd::OnLButtonUp(point, nFlag);
301
302 if (m_bMouseDown) {
303 // can receive keybord message
304 if (ClientHitTest(point) && !IsFocused())
305 SetFocus();
306
307 ReleaseCapture();
tsepez4cf55152016-11-02 14:37:54 -0700308 m_bMouseDown = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700309 }
310
tsepez4cf55152016-11-02 14:37:54 -0700311 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700312}
313
Dan Sinclairf528eee2017-02-14 11:52:07 -0500314bool CPWL_EditCtrl::OnMouseMove(const CFX_PointF& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700315 CPWL_Wnd::OnMouseMove(point, nFlag);
316
317 if (m_bMouseDown)
tsepez4cf55152016-11-02 14:37:54 -0700318 m_pEdit->OnMouseMove(point, false, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700319
tsepez4cf55152016-11-02 14:37:54 -0700320 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700321}
322
tsepez4cf55152016-11-02 14:37:54 -0700323void CPWL_EditCtrl::SetEditCaret(bool bVisible) {
Dan Sinclairf528eee2017-02-14 11:52:07 -0500324 CFX_PointF ptHead;
325 CFX_PointF ptFoot;
tsepez63f545c2016-09-13 16:08:49 -0700326 if (bVisible)
Dan Sinclair1f403ce2017-02-21 12:56:24 -0500327 GetCaretInfo(&ptHead, &ptFoot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700328
329 CPVT_WordPlace wpTemp = m_pEdit->GetCaretWordPlace();
330 IOnSetCaret(bVisible, ptHead, ptFoot, wpTemp);
331}
332
Dan Sinclair1f403ce2017-02-21 12:56:24 -0500333void CPWL_EditCtrl::GetCaretInfo(CFX_PointF* ptHead, CFX_PointF* ptFoot) const {
dsinclaire35af1e2016-07-13 11:26:20 -0700334 CFX_Edit_Iterator* pIterator = m_pEdit->GetIterator();
thestig821d59e2016-05-11 12:59:22 -0700335 pIterator->SetAt(m_pEdit->GetCaret());
336 CPVT_Word word;
337 CPVT_Line line;
338 if (pIterator->GetWord(word)) {
Dan Sinclair1f403ce2017-02-21 12:56:24 -0500339 ptHead->x = word.ptWord.x + word.fWidth;
340 ptHead->y = word.ptWord.y + word.fAscent;
341 ptFoot->x = word.ptWord.x + word.fWidth;
342 ptFoot->y = word.ptWord.y + word.fDescent;
thestig821d59e2016-05-11 12:59:22 -0700343 } else if (pIterator->GetLine(line)) {
Dan Sinclair1f403ce2017-02-21 12:56:24 -0500344 ptHead->x = line.ptLine.x;
345 ptHead->y = line.ptLine.y + line.fLineAscent;
346 ptFoot->x = line.ptLine.x;
347 ptFoot->y = line.ptLine.y + line.fLineDescent;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700348 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700349}
350
tsepez4cf55152016-11-02 14:37:54 -0700351void CPWL_EditCtrl::SetCaret(bool bVisible,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500352 const CFX_PointF& ptHead,
353 const CFX_PointF& ptFoot) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700354 if (m_pEditCaret) {
355 if (!IsFocused() || m_pEdit->IsSelected())
tsepez4cf55152016-11-02 14:37:54 -0700356 bVisible = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700357
358 m_pEditCaret->SetCaret(bVisible, ptHead, ptFoot);
359 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700360}
361
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700362CFX_WideString CPWL_EditCtrl::GetText() const {
363 return m_pEdit->GetText();
364}
365
366void CPWL_EditCtrl::SetSel(int32_t nStartChar, int32_t nEndChar) {
367 m_pEdit->SetSel(nStartChar, nEndChar);
368}
369
370void CPWL_EditCtrl::GetSel(int32_t& nStartChar, int32_t& nEndChar) const {
371 m_pEdit->GetSel(nStartChar, nEndChar);
372}
373
374void CPWL_EditCtrl::Clear() {
375 if (!IsReadOnly())
376 m_pEdit->Clear();
377}
378
379void CPWL_EditCtrl::SelectAll() {
380 m_pEdit->SelectAll();
381}
382
Dan Sinclairf528eee2017-02-14 11:52:07 -0500383void CPWL_EditCtrl::SetScrollPos(const CFX_PointF& point) {
thestig732f6a02016-05-12 10:41:56 -0700384 m_pEdit->SetScrollPos(point);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700385}
386
Dan Sinclairf528eee2017-02-14 11:52:07 -0500387CFX_PointF CPWL_EditCtrl::GetScrollPos() const {
thestig732f6a02016-05-12 10:41:56 -0700388 return m_pEdit->GetScrollPos();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700389}
390
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700391void CPWL_EditCtrl::CopyText() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700392
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700393void CPWL_EditCtrl::PasteText() {}
394
395void CPWL_EditCtrl::CutText() {}
396
tsepez4cf55152016-11-02 14:37:54 -0700397void CPWL_EditCtrl::ShowVScrollBar(bool bShow) {}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700398
Tom Sepez62a70f92016-03-21 15:00:20 -0700399void CPWL_EditCtrl::InsertWord(uint16_t word, int32_t nCharset) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700400 if (!IsReadOnly())
401 m_pEdit->InsertWord(word, nCharset);
402}
403
404void CPWL_EditCtrl::InsertReturn() {
405 if (!IsReadOnly())
406 m_pEdit->InsertReturn();
407}
408
409void CPWL_EditCtrl::Delete() {
410 if (!IsReadOnly())
411 m_pEdit->Delete();
412}
413
414void CPWL_EditCtrl::Backspace() {
415 if (!IsReadOnly())
416 m_pEdit->Backspace();
417}
418
tsepez4cf55152016-11-02 14:37:54 -0700419bool CPWL_EditCtrl::CanUndo() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700420 return !IsReadOnly() && m_pEdit->CanUndo();
421}
422
tsepez4cf55152016-11-02 14:37:54 -0700423bool CPWL_EditCtrl::CanRedo() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700424 return !IsReadOnly() && m_pEdit->CanRedo();
425}
426
427void CPWL_EditCtrl::Redo() {
428 if (CanRedo())
429 m_pEdit->Redo();
430}
431
432void CPWL_EditCtrl::Undo() {
433 if (CanUndo())
434 m_pEdit->Undo();
435}
436
Dan Sinclair05df0752017-03-14 14:43:42 -0400437void CPWL_EditCtrl::IOnSetScrollInfoY(float fPlateMin,
438 float fPlateMax,
439 float fContentMin,
440 float fContentMax,
441 float fSmallStep,
442 float fBigStep) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700443 PWL_SCROLL_INFO Info;
444
445 Info.fPlateWidth = fPlateMax - fPlateMin;
446 Info.fContentMin = fContentMin;
447 Info.fContentMax = fContentMax;
448 Info.fSmallStep = fSmallStep;
449 Info.fBigStep = fBigStep;
450
451 OnNotify(this, PNM_SETSCROLLINFO, SBT_VSCROLL, (intptr_t)&Info);
452
453 if (IsFloatBigger(Info.fPlateWidth, Info.fContentMax - Info.fContentMin) ||
454 IsFloatEqual(Info.fPlateWidth, Info.fContentMax - Info.fContentMin)) {
tsepez4cf55152016-11-02 14:37:54 -0700455 ShowVScrollBar(false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700456 } else {
tsepez4cf55152016-11-02 14:37:54 -0700457 ShowVScrollBar(true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700458 }
459}
460
Dan Sinclair05df0752017-03-14 14:43:42 -0400461void CPWL_EditCtrl::IOnSetScrollPosY(float fy) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700462 OnNotify(this, PNM_SETSCROLLPOS, SBT_VSCROLL, (intptr_t)&fy);
463}
464
tsepez4cf55152016-11-02 14:37:54 -0700465void CPWL_EditCtrl::IOnSetCaret(bool bVisible,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500466 const CFX_PointF& ptHead,
467 const CFX_PointF& ptFoot,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700468 const CPVT_WordPlace& place) {
469 PWL_CARET_INFO cInfo;
470 cInfo.bVisible = bVisible;
471 cInfo.ptHead = ptHead;
472 cInfo.ptFoot = ptFoot;
473
thestig1cd352e2016-06-07 17:53:06 -0700474 OnNotify(this, PNM_SETCARETINFO, (intptr_t)&cInfo, (intptr_t) nullptr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700475}
476
Tom Sepez281a9ea2016-02-26 14:24:28 -0800477void CPWL_EditCtrl::IOnInvalidateRect(CFX_FloatRect* pRect) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700478 InvalidateRect(pRect);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700479}
480
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700481int32_t CPWL_EditCtrl::GetCharSet() const {
Dan Sinclairf51a02a2017-04-19 12:46:53 -0400482 return m_nCharSet < 0 ? FX_CHARSET_Default : m_nCharSet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700483}
484
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700485void CPWL_EditCtrl::SetReadyToInput() {
486 if (m_bMouseDown) {
487 ReleaseCapture();
tsepez4cf55152016-11-02 14:37:54 -0700488 m_bMouseDown = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700489 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700490}