blob: 2c005a4335f47394205ded6a0c922d137fb1680d [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::OnNotify(CPWL_Wnd* pWnd,
tsepezc3255f52016-03-25 14:52:27 -070082 uint32_t msg,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070083 intptr_t wParam,
84 intptr_t lParam) {
85 CPWL_Wnd::OnNotify(pWnd, msg, wParam, lParam);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070086
Nico Weber9d8ec5a2015-08-04 13:00:21 -070087 switch (msg) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070088 case PNM_SETCARETINFO: {
89 if (PWL_CARET_INFO* pCaretInfo = (PWL_CARET_INFO*)wParam) {
90 SetCaret(pCaretInfo->bVisible, pCaretInfo->ptHead, pCaretInfo->ptFoot);
91 }
92 } break;
93 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070094}
95
Nico Weber9d8ec5a2015-08-04 13:00:21 -070096void CPWL_EditCtrl::CreateChildWnd(const PWL_CREATEPARAM& cp) {
97 if (!IsReadOnly())
98 CreateEditCaret(cp);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070099}
100
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700101void CPWL_EditCtrl::CreateEditCaret(const PWL_CREATEPARAM& cp) {
thestig732f6a02016-05-12 10:41:56 -0700102 if (m_pEditCaret)
103 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700104
thestig732f6a02016-05-12 10:41:56 -0700105 m_pEditCaret = new CPWL_Caret;
106 m_pEditCaret->SetInvalidRect(GetClientRect());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700107
thestig732f6a02016-05-12 10:41:56 -0700108 PWL_CREATEPARAM ecp = cp;
109 ecp.pParentWnd = this;
110 ecp.dwFlags = PWS_CHILD | PWS_NOREFRESHCLIP;
111 ecp.dwBorderWidth = 0;
dsinclair92cb5e52016-05-16 11:38:28 -0700112 ecp.nBorderStyle = BorderStyle::SOLID;
Lei Zhangd24236a2017-06-29 18:28:58 -0700113 ecp.rcRectWnd = CFX_FloatRect();
thestig732f6a02016-05-12 10:41:56 -0700114
115 m_pEditCaret->Create(ecp);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700116}
117
Dan Sinclair05df0752017-03-14 14:43:42 -0400118void CPWL_EditCtrl::SetFontSize(float fFontSize) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700119 m_pEdit->SetFontSize(fFontSize);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700120}
121
Dan Sinclair05df0752017-03-14 14:43:42 -0400122float CPWL_EditCtrl::GetFontSize() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700123 return m_pEdit->GetFontSize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700124}
125
tsepez4cf55152016-11-02 14:37:54 -0700126bool CPWL_EditCtrl::OnKeyDown(uint16_t nChar, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700127 if (m_bMouseDown)
tsepez4cf55152016-11-02 14:37:54 -0700128 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700129
tsepez4cf55152016-11-02 14:37:54 -0700130 bool bRet = CPWL_Wnd::OnKeyDown(nChar, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700131
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700132 // FILTER
133 switch (nChar) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700134 default:
tsepez4cf55152016-11-02 14:37:54 -0700135 return false;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700136 case FWL_VKEY_Delete:
137 case FWL_VKEY_Up:
138 case FWL_VKEY_Down:
139 case FWL_VKEY_Left:
140 case FWL_VKEY_Right:
141 case FWL_VKEY_Home:
142 case FWL_VKEY_End:
143 case FWL_VKEY_Insert:
144 case 'C':
145 case 'V':
146 case 'X':
147 case 'A':
148 case 'Z':
149 case 'c':
150 case 'v':
151 case 'x':
152 case 'a':
153 case 'z':
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700154 break;
155 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700156
thestig594b20b2016-05-12 21:56:43 -0700157 if (nChar == FWL_VKEY_Delete && m_pEdit->IsSelected())
158 nChar = FWL_VKEY_Unknown;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700159
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700160 switch (nChar) {
161 case FWL_VKEY_Delete:
162 Delete();
tsepez4cf55152016-11-02 14:37:54 -0700163 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700164 case FWL_VKEY_Insert:
165 if (IsSHIFTpressed(nFlag))
166 PasteText();
tsepez4cf55152016-11-02 14:37:54 -0700167 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700168 case FWL_VKEY_Up:
tsepez4cf55152016-11-02 14:37:54 -0700169 m_pEdit->OnVK_UP(IsSHIFTpressed(nFlag), false);
170 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700171 case FWL_VKEY_Down:
tsepez4cf55152016-11-02 14:37:54 -0700172 m_pEdit->OnVK_DOWN(IsSHIFTpressed(nFlag), false);
173 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700174 case FWL_VKEY_Left:
tsepez4cf55152016-11-02 14:37:54 -0700175 m_pEdit->OnVK_LEFT(IsSHIFTpressed(nFlag), false);
176 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700177 case FWL_VKEY_Right:
tsepez4cf55152016-11-02 14:37:54 -0700178 m_pEdit->OnVK_RIGHT(IsSHIFTpressed(nFlag), false);
179 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700180 case FWL_VKEY_Home:
181 m_pEdit->OnVK_HOME(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
tsepez4cf55152016-11-02 14:37:54 -0700182 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700183 case FWL_VKEY_End:
184 m_pEdit->OnVK_END(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
tsepez4cf55152016-11-02 14:37:54 -0700185 return true;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700186 case FWL_VKEY_Unknown:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700187 if (!IsSHIFTpressed(nFlag))
188 Clear();
189 else
190 CutText();
tsepez4cf55152016-11-02 14:37:54 -0700191 return true;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700192 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700193 break;
194 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700195
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700196 return bRet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700197}
198
tsepez4cf55152016-11-02 14:37:54 -0700199bool CPWL_EditCtrl::OnChar(uint16_t nChar, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700200 if (m_bMouseDown)
tsepez4cf55152016-11-02 14:37:54 -0700201 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700202
203 CPWL_Wnd::OnChar(nChar, nFlag);
204
205 // FILTER
206 switch (nChar) {
207 case 0x0A:
208 case 0x1B:
tsepez4cf55152016-11-02 14:37:54 -0700209 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700210 default:
211 break;
212 }
213
tsepez4cf55152016-11-02 14:37:54 -0700214 bool bCtrl = IsCTRLpressed(nFlag);
215 bool bAlt = IsALTpressed(nFlag);
216 bool bShift = IsSHIFTpressed(nFlag);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700217
Tom Sepez62a70f92016-03-21 15:00:20 -0700218 uint16_t word = nChar;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700219
220 if (bCtrl && !bAlt) {
221 switch (nChar) {
222 case 'C' - 'A' + 1:
223 CopyText();
tsepez4cf55152016-11-02 14:37:54 -0700224 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700225 case 'V' - 'A' + 1:
226 PasteText();
tsepez4cf55152016-11-02 14:37:54 -0700227 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700228 case 'X' - 'A' + 1:
229 CutText();
tsepez4cf55152016-11-02 14:37:54 -0700230 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700231 case 'A' - 'A' + 1:
232 SelectAll();
tsepez4cf55152016-11-02 14:37:54 -0700233 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700234 case 'Z' - 'A' + 1:
235 if (bShift)
236 Redo();
237 else
238 Undo();
tsepez4cf55152016-11-02 14:37:54 -0700239 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700240 default:
241 if (nChar < 32)
tsepez4cf55152016-11-02 14:37:54 -0700242 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700243 }
244 }
245
246 if (IsReadOnly())
tsepez4cf55152016-11-02 14:37:54 -0700247 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700248
249 if (m_pEdit->IsSelected() && word == FWL_VKEY_Back)
250 word = FWL_VKEY_Unknown;
251
252 Clear();
253
254 switch (word) {
255 case FWL_VKEY_Back:
256 Backspace();
257 break;
258 case FWL_VKEY_Return:
259 InsertReturn();
260 break;
261 case FWL_VKEY_Unknown:
262 break;
263 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700264 InsertWord(word, GetCharSet());
265 break;
266 }
267
tsepez4cf55152016-11-02 14:37:54 -0700268 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700269}
270
Dan Sinclairf528eee2017-02-14 11:52:07 -0500271bool CPWL_EditCtrl::OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700272 CPWL_Wnd::OnLButtonDown(point, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700273
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700274 if (ClientHitTest(point)) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700275 if (m_bMouseDown)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700276 InvalidateRect();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700277
tsepez4cf55152016-11-02 14:37:54 -0700278 m_bMouseDown = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700279 SetCapture();
280
281 m_pEdit->OnMouseDown(point, IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
282 }
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::OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700288 CPWL_Wnd::OnLButtonUp(point, nFlag);
289
290 if (m_bMouseDown) {
291 // can receive keybord message
292 if (ClientHitTest(point) && !IsFocused())
293 SetFocus();
294
295 ReleaseCapture();
tsepez4cf55152016-11-02 14:37:54 -0700296 m_bMouseDown = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700297 }
298
tsepez4cf55152016-11-02 14:37:54 -0700299 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700300}
301
Dan Sinclairf528eee2017-02-14 11:52:07 -0500302bool CPWL_EditCtrl::OnMouseMove(const CFX_PointF& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700303 CPWL_Wnd::OnMouseMove(point, nFlag);
304
305 if (m_bMouseDown)
tsepez4cf55152016-11-02 14:37:54 -0700306 m_pEdit->OnMouseMove(point, false, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700307
tsepez4cf55152016-11-02 14:37:54 -0700308 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700309}
310
tsepez4cf55152016-11-02 14:37:54 -0700311void CPWL_EditCtrl::SetEditCaret(bool bVisible) {
Dan Sinclairf528eee2017-02-14 11:52:07 -0500312 CFX_PointF ptHead;
313 CFX_PointF ptFoot;
tsepez63f545c2016-09-13 16:08:49 -0700314 if (bVisible)
Dan Sinclair1f403ce2017-02-21 12:56:24 -0500315 GetCaretInfo(&ptHead, &ptFoot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700316
317 CPVT_WordPlace wpTemp = m_pEdit->GetCaretWordPlace();
318 IOnSetCaret(bVisible, ptHead, ptFoot, wpTemp);
319}
320
Dan Sinclair1f403ce2017-02-21 12:56:24 -0500321void CPWL_EditCtrl::GetCaretInfo(CFX_PointF* ptHead, CFX_PointF* ptFoot) const {
dsinclaire35af1e2016-07-13 11:26:20 -0700322 CFX_Edit_Iterator* pIterator = m_pEdit->GetIterator();
thestig821d59e2016-05-11 12:59:22 -0700323 pIterator->SetAt(m_pEdit->GetCaret());
324 CPVT_Word word;
325 CPVT_Line line;
326 if (pIterator->GetWord(word)) {
Dan Sinclair1f403ce2017-02-21 12:56:24 -0500327 ptHead->x = word.ptWord.x + word.fWidth;
328 ptHead->y = word.ptWord.y + word.fAscent;
329 ptFoot->x = word.ptWord.x + word.fWidth;
330 ptFoot->y = word.ptWord.y + word.fDescent;
thestig821d59e2016-05-11 12:59:22 -0700331 } else if (pIterator->GetLine(line)) {
Dan Sinclair1f403ce2017-02-21 12:56:24 -0500332 ptHead->x = line.ptLine.x;
333 ptHead->y = line.ptLine.y + line.fLineAscent;
334 ptFoot->x = line.ptLine.x;
335 ptFoot->y = line.ptLine.y + line.fLineDescent;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700336 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700337}
338
tsepez4cf55152016-11-02 14:37:54 -0700339void CPWL_EditCtrl::SetCaret(bool bVisible,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500340 const CFX_PointF& ptHead,
341 const CFX_PointF& ptFoot) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700342 if (m_pEditCaret) {
343 if (!IsFocused() || m_pEdit->IsSelected())
tsepez4cf55152016-11-02 14:37:54 -0700344 bVisible = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700345
346 m_pEditCaret->SetCaret(bVisible, ptHead, ptFoot);
347 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700348}
349
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700350CFX_WideString CPWL_EditCtrl::GetText() const {
351 return m_pEdit->GetText();
352}
353
354void CPWL_EditCtrl::SetSel(int32_t nStartChar, int32_t nEndChar) {
355 m_pEdit->SetSel(nStartChar, nEndChar);
356}
357
358void CPWL_EditCtrl::GetSel(int32_t& nStartChar, int32_t& nEndChar) const {
359 m_pEdit->GetSel(nStartChar, nEndChar);
360}
361
362void CPWL_EditCtrl::Clear() {
363 if (!IsReadOnly())
364 m_pEdit->Clear();
365}
366
367void CPWL_EditCtrl::SelectAll() {
368 m_pEdit->SelectAll();
369}
370
Dan Sinclairf528eee2017-02-14 11:52:07 -0500371void CPWL_EditCtrl::SetScrollPos(const CFX_PointF& point) {
thestig732f6a02016-05-12 10:41:56 -0700372 m_pEdit->SetScrollPos(point);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700373}
374
Dan Sinclairf528eee2017-02-14 11:52:07 -0500375CFX_PointF CPWL_EditCtrl::GetScrollPos() const {
thestig732f6a02016-05-12 10:41:56 -0700376 return m_pEdit->GetScrollPos();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700377}
378
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700379void CPWL_EditCtrl::CopyText() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700380
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700381void CPWL_EditCtrl::PasteText() {}
382
383void CPWL_EditCtrl::CutText() {}
384
tsepez4cf55152016-11-02 14:37:54 -0700385void CPWL_EditCtrl::ShowVScrollBar(bool bShow) {}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700386
Tom Sepez62a70f92016-03-21 15:00:20 -0700387void CPWL_EditCtrl::InsertWord(uint16_t word, int32_t nCharset) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700388 if (!IsReadOnly())
389 m_pEdit->InsertWord(word, nCharset);
390}
391
392void CPWL_EditCtrl::InsertReturn() {
393 if (!IsReadOnly())
394 m_pEdit->InsertReturn();
395}
396
397void CPWL_EditCtrl::Delete() {
398 if (!IsReadOnly())
399 m_pEdit->Delete();
400}
401
402void CPWL_EditCtrl::Backspace() {
403 if (!IsReadOnly())
404 m_pEdit->Backspace();
405}
406
tsepez4cf55152016-11-02 14:37:54 -0700407bool CPWL_EditCtrl::CanUndo() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700408 return !IsReadOnly() && m_pEdit->CanUndo();
409}
410
tsepez4cf55152016-11-02 14:37:54 -0700411bool CPWL_EditCtrl::CanRedo() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700412 return !IsReadOnly() && m_pEdit->CanRedo();
413}
414
415void CPWL_EditCtrl::Redo() {
416 if (CanRedo())
417 m_pEdit->Redo();
418}
419
420void CPWL_EditCtrl::Undo() {
421 if (CanUndo())
422 m_pEdit->Undo();
423}
424
Dan Sinclair05df0752017-03-14 14:43:42 -0400425void CPWL_EditCtrl::IOnSetScrollInfoY(float fPlateMin,
426 float fPlateMax,
427 float fContentMin,
428 float fContentMax,
429 float fSmallStep,
430 float fBigStep) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700431 PWL_SCROLL_INFO Info;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700432 Info.fPlateWidth = fPlateMax - fPlateMin;
433 Info.fContentMin = fContentMin;
434 Info.fContentMax = fContentMax;
435 Info.fSmallStep = fSmallStep;
436 Info.fBigStep = fBigStep;
Dan Sinclairfb00ec22017-07-05 09:28:15 -0400437 SetScrollInfo(Info);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700438
439 if (IsFloatBigger(Info.fPlateWidth, Info.fContentMax - Info.fContentMin) ||
440 IsFloatEqual(Info.fPlateWidth, Info.fContentMax - Info.fContentMin)) {
tsepez4cf55152016-11-02 14:37:54 -0700441 ShowVScrollBar(false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700442 } else {
tsepez4cf55152016-11-02 14:37:54 -0700443 ShowVScrollBar(true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700444 }
445}
446
Dan Sinclair05df0752017-03-14 14:43:42 -0400447void CPWL_EditCtrl::IOnSetScrollPosY(float fy) {
Dan Sinclair7e0336e2017-07-05 09:39:50 -0400448 SetScrollPosition(fy);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700449}
450
tsepez4cf55152016-11-02 14:37:54 -0700451void CPWL_EditCtrl::IOnSetCaret(bool bVisible,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500452 const CFX_PointF& ptHead,
453 const CFX_PointF& ptFoot,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700454 const CPVT_WordPlace& place) {
455 PWL_CARET_INFO cInfo;
456 cInfo.bVisible = bVisible;
457 cInfo.ptHead = ptHead;
458 cInfo.ptFoot = ptFoot;
459
thestig1cd352e2016-06-07 17:53:06 -0700460 OnNotify(this, PNM_SETCARETINFO, (intptr_t)&cInfo, (intptr_t) nullptr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700461}
462
Tom Sepez281a9ea2016-02-26 14:24:28 -0800463void CPWL_EditCtrl::IOnInvalidateRect(CFX_FloatRect* pRect) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700464 InvalidateRect(pRect);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700465}
466
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700467int32_t CPWL_EditCtrl::GetCharSet() const {
Dan Sinclairf51a02a2017-04-19 12:46:53 -0400468 return m_nCharSet < 0 ? FX_CHARSET_Default : m_nCharSet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700469}
470
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700471void CPWL_EditCtrl::SetReadyToInput() {
472 if (m_bMouseDown) {
473 ReleaseCapture();
tsepez4cf55152016-11-02 14:37:54 -0700474 m_bMouseDown = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700475 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700476}