blob: 59879bb2748e88dca62eb522b349dde8a23c9f71 [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
Dan Sinclair63fbd8d2017-07-05 14:10:36 -040077void CPWL_EditCtrl::ScrollWindowVertically(float pos) {
78 m_pEdit->SetScrollPos(CFX_PointF(m_pEdit->GetScrollPos().x, pos));
79}
80
Nico Weber9d8ec5a2015-08-04 13:00:21 -070081void CPWL_EditCtrl::CreateChildWnd(const PWL_CREATEPARAM& cp) {
82 if (!IsReadOnly())
83 CreateEditCaret(cp);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070084}
85
Nico Weber9d8ec5a2015-08-04 13:00:21 -070086void CPWL_EditCtrl::CreateEditCaret(const PWL_CREATEPARAM& cp) {
thestig732f6a02016-05-12 10:41:56 -070087 if (m_pEditCaret)
88 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070089
thestig732f6a02016-05-12 10:41:56 -070090 m_pEditCaret = new CPWL_Caret;
91 m_pEditCaret->SetInvalidRect(GetClientRect());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070092
thestig732f6a02016-05-12 10:41:56 -070093 PWL_CREATEPARAM ecp = cp;
94 ecp.pParentWnd = this;
95 ecp.dwFlags = PWS_CHILD | PWS_NOREFRESHCLIP;
96 ecp.dwBorderWidth = 0;
dsinclair92cb5e52016-05-16 11:38:28 -070097 ecp.nBorderStyle = BorderStyle::SOLID;
Lei Zhangd24236a2017-06-29 18:28:58 -070098 ecp.rcRectWnd = CFX_FloatRect();
thestig732f6a02016-05-12 10:41:56 -070099
100 m_pEditCaret->Create(ecp);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700101}
102
Dan Sinclair05df0752017-03-14 14:43:42 -0400103void CPWL_EditCtrl::SetFontSize(float fFontSize) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700104 m_pEdit->SetFontSize(fFontSize);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700105}
106
Dan Sinclair05df0752017-03-14 14:43:42 -0400107float CPWL_EditCtrl::GetFontSize() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700108 return m_pEdit->GetFontSize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700109}
110
tsepez4cf55152016-11-02 14:37:54 -0700111bool CPWL_EditCtrl::OnKeyDown(uint16_t nChar, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700112 if (m_bMouseDown)
tsepez4cf55152016-11-02 14:37:54 -0700113 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700114
tsepez4cf55152016-11-02 14:37:54 -0700115 bool bRet = CPWL_Wnd::OnKeyDown(nChar, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700116
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700117 // FILTER
118 switch (nChar) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700119 default:
tsepez4cf55152016-11-02 14:37:54 -0700120 return false;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700121 case FWL_VKEY_Delete:
122 case FWL_VKEY_Up:
123 case FWL_VKEY_Down:
124 case FWL_VKEY_Left:
125 case FWL_VKEY_Right:
126 case FWL_VKEY_Home:
127 case FWL_VKEY_End:
128 case FWL_VKEY_Insert:
129 case 'C':
130 case 'V':
131 case 'X':
132 case 'A':
133 case 'Z':
134 case 'c':
135 case 'v':
136 case 'x':
137 case 'a':
138 case 'z':
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700139 break;
140 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700141
thestig594b20b2016-05-12 21:56:43 -0700142 if (nChar == FWL_VKEY_Delete && m_pEdit->IsSelected())
143 nChar = FWL_VKEY_Unknown;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700144
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700145 switch (nChar) {
146 case FWL_VKEY_Delete:
147 Delete();
tsepez4cf55152016-11-02 14:37:54 -0700148 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700149 case FWL_VKEY_Insert:
150 if (IsSHIFTpressed(nFlag))
151 PasteText();
tsepez4cf55152016-11-02 14:37:54 -0700152 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700153 case FWL_VKEY_Up:
tsepez4cf55152016-11-02 14:37:54 -0700154 m_pEdit->OnVK_UP(IsSHIFTpressed(nFlag), false);
155 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700156 case FWL_VKEY_Down:
tsepez4cf55152016-11-02 14:37:54 -0700157 m_pEdit->OnVK_DOWN(IsSHIFTpressed(nFlag), false);
158 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700159 case FWL_VKEY_Left:
tsepez4cf55152016-11-02 14:37:54 -0700160 m_pEdit->OnVK_LEFT(IsSHIFTpressed(nFlag), false);
161 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700162 case FWL_VKEY_Right:
tsepez4cf55152016-11-02 14:37:54 -0700163 m_pEdit->OnVK_RIGHT(IsSHIFTpressed(nFlag), false);
164 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700165 case FWL_VKEY_Home:
166 m_pEdit->OnVK_HOME(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
tsepez4cf55152016-11-02 14:37:54 -0700167 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700168 case FWL_VKEY_End:
169 m_pEdit->OnVK_END(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
tsepez4cf55152016-11-02 14:37:54 -0700170 return true;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700171 case FWL_VKEY_Unknown:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700172 if (!IsSHIFTpressed(nFlag))
173 Clear();
174 else
175 CutText();
tsepez4cf55152016-11-02 14:37:54 -0700176 return true;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700177 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700178 break;
179 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700180
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700181 return bRet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700182}
183
tsepez4cf55152016-11-02 14:37:54 -0700184bool CPWL_EditCtrl::OnChar(uint16_t nChar, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700185 if (m_bMouseDown)
tsepez4cf55152016-11-02 14:37:54 -0700186 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700187
188 CPWL_Wnd::OnChar(nChar, nFlag);
189
190 // FILTER
191 switch (nChar) {
192 case 0x0A:
193 case 0x1B:
tsepez4cf55152016-11-02 14:37:54 -0700194 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700195 default:
196 break;
197 }
198
tsepez4cf55152016-11-02 14:37:54 -0700199 bool bCtrl = IsCTRLpressed(nFlag);
200 bool bAlt = IsALTpressed(nFlag);
201 bool bShift = IsSHIFTpressed(nFlag);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700202
Tom Sepez62a70f92016-03-21 15:00:20 -0700203 uint16_t word = nChar;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700204
205 if (bCtrl && !bAlt) {
206 switch (nChar) {
207 case 'C' - 'A' + 1:
208 CopyText();
tsepez4cf55152016-11-02 14:37:54 -0700209 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700210 case 'V' - 'A' + 1:
211 PasteText();
tsepez4cf55152016-11-02 14:37:54 -0700212 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700213 case 'X' - 'A' + 1:
214 CutText();
tsepez4cf55152016-11-02 14:37:54 -0700215 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700216 case 'A' - 'A' + 1:
217 SelectAll();
tsepez4cf55152016-11-02 14:37:54 -0700218 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700219 case 'Z' - 'A' + 1:
220 if (bShift)
221 Redo();
222 else
223 Undo();
tsepez4cf55152016-11-02 14:37:54 -0700224 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700225 default:
226 if (nChar < 32)
tsepez4cf55152016-11-02 14:37:54 -0700227 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700228 }
229 }
230
231 if (IsReadOnly())
tsepez4cf55152016-11-02 14:37:54 -0700232 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700233
234 if (m_pEdit->IsSelected() && word == FWL_VKEY_Back)
235 word = FWL_VKEY_Unknown;
236
237 Clear();
238
239 switch (word) {
240 case FWL_VKEY_Back:
241 Backspace();
242 break;
243 case FWL_VKEY_Return:
244 InsertReturn();
245 break;
246 case FWL_VKEY_Unknown:
247 break;
248 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700249 InsertWord(word, GetCharSet());
250 break;
251 }
252
tsepez4cf55152016-11-02 14:37:54 -0700253 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700254}
255
Dan Sinclairf528eee2017-02-14 11:52:07 -0500256bool CPWL_EditCtrl::OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700257 CPWL_Wnd::OnLButtonDown(point, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700258
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700259 if (ClientHitTest(point)) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700260 if (m_bMouseDown)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700261 InvalidateRect();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700262
tsepez4cf55152016-11-02 14:37:54 -0700263 m_bMouseDown = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700264 SetCapture();
265
266 m_pEdit->OnMouseDown(point, IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
267 }
268
tsepez4cf55152016-11-02 14:37:54 -0700269 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700270}
271
Dan Sinclairf528eee2017-02-14 11:52:07 -0500272bool CPWL_EditCtrl::OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700273 CPWL_Wnd::OnLButtonUp(point, nFlag);
274
275 if (m_bMouseDown) {
276 // can receive keybord message
277 if (ClientHitTest(point) && !IsFocused())
278 SetFocus();
279
280 ReleaseCapture();
tsepez4cf55152016-11-02 14:37:54 -0700281 m_bMouseDown = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700282 }
283
tsepez4cf55152016-11-02 14:37:54 -0700284 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700285}
286
Dan Sinclairf528eee2017-02-14 11:52:07 -0500287bool CPWL_EditCtrl::OnMouseMove(const CFX_PointF& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700288 CPWL_Wnd::OnMouseMove(point, nFlag);
289
290 if (m_bMouseDown)
tsepez4cf55152016-11-02 14:37:54 -0700291 m_pEdit->OnMouseMove(point, false, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700292
tsepez4cf55152016-11-02 14:37:54 -0700293 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700294}
295
tsepez4cf55152016-11-02 14:37:54 -0700296void CPWL_EditCtrl::SetEditCaret(bool bVisible) {
Dan Sinclairf528eee2017-02-14 11:52:07 -0500297 CFX_PointF ptHead;
298 CFX_PointF ptFoot;
tsepez63f545c2016-09-13 16:08:49 -0700299 if (bVisible)
Dan Sinclair1f403ce2017-02-21 12:56:24 -0500300 GetCaretInfo(&ptHead, &ptFoot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700301
302 CPVT_WordPlace wpTemp = m_pEdit->GetCaretWordPlace();
303 IOnSetCaret(bVisible, ptHead, ptFoot, wpTemp);
304}
305
Dan Sinclair1f403ce2017-02-21 12:56:24 -0500306void CPWL_EditCtrl::GetCaretInfo(CFX_PointF* ptHead, CFX_PointF* ptFoot) const {
dsinclaire35af1e2016-07-13 11:26:20 -0700307 CFX_Edit_Iterator* pIterator = m_pEdit->GetIterator();
thestig821d59e2016-05-11 12:59:22 -0700308 pIterator->SetAt(m_pEdit->GetCaret());
309 CPVT_Word word;
310 CPVT_Line line;
311 if (pIterator->GetWord(word)) {
Dan Sinclair1f403ce2017-02-21 12:56:24 -0500312 ptHead->x = word.ptWord.x + word.fWidth;
313 ptHead->y = word.ptWord.y + word.fAscent;
314 ptFoot->x = word.ptWord.x + word.fWidth;
315 ptFoot->y = word.ptWord.y + word.fDescent;
thestig821d59e2016-05-11 12:59:22 -0700316 } else if (pIterator->GetLine(line)) {
Dan Sinclair1f403ce2017-02-21 12:56:24 -0500317 ptHead->x = line.ptLine.x;
318 ptHead->y = line.ptLine.y + line.fLineAscent;
319 ptFoot->x = line.ptLine.x;
320 ptFoot->y = line.ptLine.y + line.fLineDescent;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700321 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700322}
323
tsepez4cf55152016-11-02 14:37:54 -0700324void CPWL_EditCtrl::SetCaret(bool bVisible,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500325 const CFX_PointF& ptHead,
326 const CFX_PointF& ptFoot) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700327 if (m_pEditCaret) {
328 if (!IsFocused() || m_pEdit->IsSelected())
tsepez4cf55152016-11-02 14:37:54 -0700329 bVisible = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700330
331 m_pEditCaret->SetCaret(bVisible, ptHead, ptFoot);
332 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700333}
334
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700335CFX_WideString CPWL_EditCtrl::GetText() const {
336 return m_pEdit->GetText();
337}
338
339void CPWL_EditCtrl::SetSel(int32_t nStartChar, int32_t nEndChar) {
340 m_pEdit->SetSel(nStartChar, nEndChar);
341}
342
343void CPWL_EditCtrl::GetSel(int32_t& nStartChar, int32_t& nEndChar) const {
344 m_pEdit->GetSel(nStartChar, nEndChar);
345}
346
347void CPWL_EditCtrl::Clear() {
348 if (!IsReadOnly())
349 m_pEdit->Clear();
350}
351
352void CPWL_EditCtrl::SelectAll() {
353 m_pEdit->SelectAll();
354}
355
Dan Sinclairf528eee2017-02-14 11:52:07 -0500356void CPWL_EditCtrl::SetScrollPos(const CFX_PointF& point) {
thestig732f6a02016-05-12 10:41:56 -0700357 m_pEdit->SetScrollPos(point);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700358}
359
Dan Sinclairf528eee2017-02-14 11:52:07 -0500360CFX_PointF CPWL_EditCtrl::GetScrollPos() const {
thestig732f6a02016-05-12 10:41:56 -0700361 return m_pEdit->GetScrollPos();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700362}
363
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700364void CPWL_EditCtrl::CopyText() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700365
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700366void CPWL_EditCtrl::PasteText() {}
367
368void CPWL_EditCtrl::CutText() {}
369
tsepez4cf55152016-11-02 14:37:54 -0700370void CPWL_EditCtrl::ShowVScrollBar(bool bShow) {}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700371
Tom Sepez62a70f92016-03-21 15:00:20 -0700372void CPWL_EditCtrl::InsertWord(uint16_t word, int32_t nCharset) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700373 if (!IsReadOnly())
374 m_pEdit->InsertWord(word, nCharset);
375}
376
377void CPWL_EditCtrl::InsertReturn() {
378 if (!IsReadOnly())
379 m_pEdit->InsertReturn();
380}
381
382void CPWL_EditCtrl::Delete() {
383 if (!IsReadOnly())
384 m_pEdit->Delete();
385}
386
387void CPWL_EditCtrl::Backspace() {
388 if (!IsReadOnly())
389 m_pEdit->Backspace();
390}
391
tsepez4cf55152016-11-02 14:37:54 -0700392bool CPWL_EditCtrl::CanUndo() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700393 return !IsReadOnly() && m_pEdit->CanUndo();
394}
395
tsepez4cf55152016-11-02 14:37:54 -0700396bool CPWL_EditCtrl::CanRedo() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700397 return !IsReadOnly() && m_pEdit->CanRedo();
398}
399
400void CPWL_EditCtrl::Redo() {
401 if (CanRedo())
402 m_pEdit->Redo();
403}
404
405void CPWL_EditCtrl::Undo() {
406 if (CanUndo())
407 m_pEdit->Undo();
408}
409
Dan Sinclair05df0752017-03-14 14:43:42 -0400410void CPWL_EditCtrl::IOnSetScrollInfoY(float fPlateMin,
411 float fPlateMax,
412 float fContentMin,
413 float fContentMax,
414 float fSmallStep,
415 float fBigStep) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700416 PWL_SCROLL_INFO Info;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700417 Info.fPlateWidth = fPlateMax - fPlateMin;
418 Info.fContentMin = fContentMin;
419 Info.fContentMax = fContentMax;
420 Info.fSmallStep = fSmallStep;
421 Info.fBigStep = fBigStep;
Dan Sinclairfb00ec22017-07-05 09:28:15 -0400422 SetScrollInfo(Info);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700423
424 if (IsFloatBigger(Info.fPlateWidth, Info.fContentMax - Info.fContentMin) ||
425 IsFloatEqual(Info.fPlateWidth, Info.fContentMax - Info.fContentMin)) {
tsepez4cf55152016-11-02 14:37:54 -0700426 ShowVScrollBar(false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700427 } else {
tsepez4cf55152016-11-02 14:37:54 -0700428 ShowVScrollBar(true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700429 }
430}
431
Dan Sinclair05df0752017-03-14 14:43:42 -0400432void CPWL_EditCtrl::IOnSetScrollPosY(float fy) {
Dan Sinclair7e0336e2017-07-05 09:39:50 -0400433 SetScrollPosition(fy);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700434}
435
tsepez4cf55152016-11-02 14:37:54 -0700436void CPWL_EditCtrl::IOnSetCaret(bool bVisible,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500437 const CFX_PointF& ptHead,
438 const CFX_PointF& ptFoot,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700439 const CPVT_WordPlace& place) {
Dan Sinclair1b4670c2017-07-05 14:11:23 -0400440 SetCaret(bVisible, ptHead, ptFoot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700441}
442
Tom Sepez281a9ea2016-02-26 14:24:28 -0800443void CPWL_EditCtrl::IOnInvalidateRect(CFX_FloatRect* pRect) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700444 InvalidateRect(pRect);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700445}
446
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700447int32_t CPWL_EditCtrl::GetCharSet() const {
Dan Sinclairf51a02a2017-04-19 12:46:53 -0400448 return m_nCharSet < 0 ? FX_CHARSET_Default : m_nCharSet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700449}
450
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700451void CPWL_EditCtrl::SetReadyToInput() {
452 if (m_bMouseDown) {
453 ReleaseCapture();
tsepez4cf55152016-11-02 14:37:54 -0700454 m_bMouseDown = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700455 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700456}