blob: 9c22cead583f867da589123d47d5f1b829c57e55 [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
Nico Weber9d8ec5a2015-08-04 13:00:21 -070056void CPWL_EditCtrl::RePosChildWnd() {
57 m_pEdit->SetPlateRect(GetClientRect());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070058}
59
Nico Weber9d8ec5a2015-08-04 13:00:21 -070060void CPWL_EditCtrl::OnNotify(CPWL_Wnd* pWnd,
tsepezc3255f52016-03-25 14:52:27 -070061 uint32_t msg,
Nico Weber9d8ec5a2015-08-04 13:00:21 -070062 intptr_t wParam,
63 intptr_t lParam) {
64 CPWL_Wnd::OnNotify(pWnd, msg, wParam, lParam);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070065
Nico Weber9d8ec5a2015-08-04 13:00:21 -070066 switch (msg) {
67 case PNM_SETSCROLLINFO:
68 switch (wParam) {
69 case SBT_VSCROLL:
70 if (CPWL_Wnd* pChild = GetVScrollBar()) {
71 pChild->OnNotify(pWnd, PNM_SETSCROLLINFO, wParam, lParam);
72 }
73 break;
74 }
75 break;
76 case PNM_SETSCROLLPOS:
77 switch (wParam) {
78 case SBT_VSCROLL:
79 if (CPWL_Wnd* pChild = GetVScrollBar()) {
80 pChild->OnNotify(pWnd, PNM_SETSCROLLPOS, wParam, lParam);
81 }
82 break;
83 }
84 break;
85 case PNM_SCROLLWINDOW: {
Dan Sinclair05df0752017-03-14 14:43:42 -040086 float fPos = *(float*)lParam;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070087 switch (wParam) {
88 case SBT_VSCROLL:
Dan Sinclairf528eee2017-02-14 11:52:07 -050089 m_pEdit->SetScrollPos(CFX_PointF(m_pEdit->GetScrollPos().x, fPos));
Nico Weber9d8ec5a2015-08-04 13:00:21 -070090 break;
91 }
92 } break;
93 case PNM_SETCARETINFO: {
94 if (PWL_CARET_INFO* pCaretInfo = (PWL_CARET_INFO*)wParam) {
95 SetCaret(pCaretInfo->bVisible, pCaretInfo->ptHead, pCaretInfo->ptFoot);
96 }
97 } break;
98 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070099}
100
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700101void CPWL_EditCtrl::CreateChildWnd(const PWL_CREATEPARAM& cp) {
102 if (!IsReadOnly())
103 CreateEditCaret(cp);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700104}
105
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700106void CPWL_EditCtrl::CreateEditCaret(const PWL_CREATEPARAM& cp) {
thestig732f6a02016-05-12 10:41:56 -0700107 if (m_pEditCaret)
108 return;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700109
thestig732f6a02016-05-12 10:41:56 -0700110 m_pEditCaret = new CPWL_Caret;
111 m_pEditCaret->SetInvalidRect(GetClientRect());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700112
thestig732f6a02016-05-12 10:41:56 -0700113 PWL_CREATEPARAM ecp = cp;
114 ecp.pParentWnd = this;
115 ecp.dwFlags = PWS_CHILD | PWS_NOREFRESHCLIP;
116 ecp.dwBorderWidth = 0;
dsinclair92cb5e52016-05-16 11:38:28 -0700117 ecp.nBorderStyle = BorderStyle::SOLID;
thestig732f6a02016-05-12 10:41:56 -0700118 ecp.rcRectWnd = CFX_FloatRect(0, 0, 0, 0);
119
120 m_pEditCaret->Create(ecp);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700121}
122
Dan Sinclair05df0752017-03-14 14:43:42 -0400123void CPWL_EditCtrl::SetFontSize(float fFontSize) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700124 m_pEdit->SetFontSize(fFontSize);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700125}
126
Dan Sinclair05df0752017-03-14 14:43:42 -0400127float CPWL_EditCtrl::GetFontSize() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700128 return m_pEdit->GetFontSize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700129}
130
tsepez4cf55152016-11-02 14:37:54 -0700131bool CPWL_EditCtrl::OnKeyDown(uint16_t nChar, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700132 if (m_bMouseDown)
tsepez4cf55152016-11-02 14:37:54 -0700133 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700134
tsepez4cf55152016-11-02 14:37:54 -0700135 bool bRet = CPWL_Wnd::OnKeyDown(nChar, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700136
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700137 // FILTER
138 switch (nChar) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700139 default:
tsepez4cf55152016-11-02 14:37:54 -0700140 return false;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700141 case FWL_VKEY_Delete:
142 case FWL_VKEY_Up:
143 case FWL_VKEY_Down:
144 case FWL_VKEY_Left:
145 case FWL_VKEY_Right:
146 case FWL_VKEY_Home:
147 case FWL_VKEY_End:
148 case FWL_VKEY_Insert:
149 case 'C':
150 case 'V':
151 case 'X':
152 case 'A':
153 case 'Z':
154 case 'c':
155 case 'v':
156 case 'x':
157 case 'a':
158 case 'z':
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700159 break;
160 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700161
thestig594b20b2016-05-12 21:56:43 -0700162 if (nChar == FWL_VKEY_Delete && m_pEdit->IsSelected())
163 nChar = FWL_VKEY_Unknown;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700164
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700165 switch (nChar) {
166 case FWL_VKEY_Delete:
167 Delete();
tsepez4cf55152016-11-02 14:37:54 -0700168 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700169 case FWL_VKEY_Insert:
170 if (IsSHIFTpressed(nFlag))
171 PasteText();
tsepez4cf55152016-11-02 14:37:54 -0700172 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700173 case FWL_VKEY_Up:
tsepez4cf55152016-11-02 14:37:54 -0700174 m_pEdit->OnVK_UP(IsSHIFTpressed(nFlag), false);
175 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700176 case FWL_VKEY_Down:
tsepez4cf55152016-11-02 14:37:54 -0700177 m_pEdit->OnVK_DOWN(IsSHIFTpressed(nFlag), false);
178 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700179 case FWL_VKEY_Left:
tsepez4cf55152016-11-02 14:37:54 -0700180 m_pEdit->OnVK_LEFT(IsSHIFTpressed(nFlag), false);
181 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700182 case FWL_VKEY_Right:
tsepez4cf55152016-11-02 14:37:54 -0700183 m_pEdit->OnVK_RIGHT(IsSHIFTpressed(nFlag), false);
184 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700185 case FWL_VKEY_Home:
186 m_pEdit->OnVK_HOME(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
tsepez4cf55152016-11-02 14:37:54 -0700187 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700188 case FWL_VKEY_End:
189 m_pEdit->OnVK_END(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
tsepez4cf55152016-11-02 14:37:54 -0700190 return true;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700191 case FWL_VKEY_Unknown:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700192 if (!IsSHIFTpressed(nFlag))
193 Clear();
194 else
195 CutText();
tsepez4cf55152016-11-02 14:37:54 -0700196 return true;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700197 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700198 break;
199 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700200
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700201 return bRet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700202}
203
tsepez4cf55152016-11-02 14:37:54 -0700204bool CPWL_EditCtrl::OnChar(uint16_t nChar, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700205 if (m_bMouseDown)
tsepez4cf55152016-11-02 14:37:54 -0700206 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700207
208 CPWL_Wnd::OnChar(nChar, nFlag);
209
210 // FILTER
211 switch (nChar) {
212 case 0x0A:
213 case 0x1B:
tsepez4cf55152016-11-02 14:37:54 -0700214 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700215 default:
216 break;
217 }
218
tsepez4cf55152016-11-02 14:37:54 -0700219 bool bCtrl = IsCTRLpressed(nFlag);
220 bool bAlt = IsALTpressed(nFlag);
221 bool bShift = IsSHIFTpressed(nFlag);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700222
Tom Sepez62a70f92016-03-21 15:00:20 -0700223 uint16_t word = nChar;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700224
225 if (bCtrl && !bAlt) {
226 switch (nChar) {
227 case 'C' - 'A' + 1:
228 CopyText();
tsepez4cf55152016-11-02 14:37:54 -0700229 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700230 case 'V' - 'A' + 1:
231 PasteText();
tsepez4cf55152016-11-02 14:37:54 -0700232 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700233 case 'X' - 'A' + 1:
234 CutText();
tsepez4cf55152016-11-02 14:37:54 -0700235 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700236 case 'A' - 'A' + 1:
237 SelectAll();
tsepez4cf55152016-11-02 14:37:54 -0700238 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700239 case 'Z' - 'A' + 1:
240 if (bShift)
241 Redo();
242 else
243 Undo();
tsepez4cf55152016-11-02 14:37:54 -0700244 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700245 default:
246 if (nChar < 32)
tsepez4cf55152016-11-02 14:37:54 -0700247 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700248 }
249 }
250
251 if (IsReadOnly())
tsepez4cf55152016-11-02 14:37:54 -0700252 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700253
254 if (m_pEdit->IsSelected() && word == FWL_VKEY_Back)
255 word = FWL_VKEY_Unknown;
256
257 Clear();
258
259 switch (word) {
260 case FWL_VKEY_Back:
261 Backspace();
262 break;
263 case FWL_VKEY_Return:
264 InsertReturn();
265 break;
266 case FWL_VKEY_Unknown:
267 break;
268 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700269 InsertWord(word, GetCharSet());
270 break;
271 }
272
tsepez4cf55152016-11-02 14:37:54 -0700273 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700274}
275
Dan Sinclairf528eee2017-02-14 11:52:07 -0500276bool CPWL_EditCtrl::OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700277 CPWL_Wnd::OnLButtonDown(point, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700278
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700279 if (ClientHitTest(point)) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700280 if (m_bMouseDown)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700281 InvalidateRect();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700282
tsepez4cf55152016-11-02 14:37:54 -0700283 m_bMouseDown = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700284 SetCapture();
285
286 m_pEdit->OnMouseDown(point, IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
287 }
288
tsepez4cf55152016-11-02 14:37:54 -0700289 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700290}
291
Dan Sinclairf528eee2017-02-14 11:52:07 -0500292bool CPWL_EditCtrl::OnLButtonUp(const CFX_PointF& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700293 CPWL_Wnd::OnLButtonUp(point, nFlag);
294
295 if (m_bMouseDown) {
296 // can receive keybord message
297 if (ClientHitTest(point) && !IsFocused())
298 SetFocus();
299
300 ReleaseCapture();
tsepez4cf55152016-11-02 14:37:54 -0700301 m_bMouseDown = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700302 }
303
tsepez4cf55152016-11-02 14:37:54 -0700304 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700305}
306
Dan Sinclairf528eee2017-02-14 11:52:07 -0500307bool CPWL_EditCtrl::OnMouseMove(const CFX_PointF& point, uint32_t nFlag) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700308 CPWL_Wnd::OnMouseMove(point, nFlag);
309
310 if (m_bMouseDown)
tsepez4cf55152016-11-02 14:37:54 -0700311 m_pEdit->OnMouseMove(point, false, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700312
tsepez4cf55152016-11-02 14:37:54 -0700313 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700314}
315
tsepez4cf55152016-11-02 14:37:54 -0700316void CPWL_EditCtrl::SetEditCaret(bool bVisible) {
Dan Sinclairf528eee2017-02-14 11:52:07 -0500317 CFX_PointF ptHead;
318 CFX_PointF ptFoot;
tsepez63f545c2016-09-13 16:08:49 -0700319 if (bVisible)
Dan Sinclair1f403ce2017-02-21 12:56:24 -0500320 GetCaretInfo(&ptHead, &ptFoot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700321
322 CPVT_WordPlace wpTemp = m_pEdit->GetCaretWordPlace();
323 IOnSetCaret(bVisible, ptHead, ptFoot, wpTemp);
324}
325
Dan Sinclair1f403ce2017-02-21 12:56:24 -0500326void CPWL_EditCtrl::GetCaretInfo(CFX_PointF* ptHead, CFX_PointF* ptFoot) const {
dsinclaire35af1e2016-07-13 11:26:20 -0700327 CFX_Edit_Iterator* pIterator = m_pEdit->GetIterator();
thestig821d59e2016-05-11 12:59:22 -0700328 pIterator->SetAt(m_pEdit->GetCaret());
329 CPVT_Word word;
330 CPVT_Line line;
331 if (pIterator->GetWord(word)) {
Dan Sinclair1f403ce2017-02-21 12:56:24 -0500332 ptHead->x = word.ptWord.x + word.fWidth;
333 ptHead->y = word.ptWord.y + word.fAscent;
334 ptFoot->x = word.ptWord.x + word.fWidth;
335 ptFoot->y = word.ptWord.y + word.fDescent;
thestig821d59e2016-05-11 12:59:22 -0700336 } else if (pIterator->GetLine(line)) {
Dan Sinclair1f403ce2017-02-21 12:56:24 -0500337 ptHead->x = line.ptLine.x;
338 ptHead->y = line.ptLine.y + line.fLineAscent;
339 ptFoot->x = line.ptLine.x;
340 ptFoot->y = line.ptLine.y + line.fLineDescent;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700341 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700342}
343
tsepez4cf55152016-11-02 14:37:54 -0700344void CPWL_EditCtrl::SetCaret(bool bVisible,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500345 const CFX_PointF& ptHead,
346 const CFX_PointF& ptFoot) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700347 if (m_pEditCaret) {
348 if (!IsFocused() || m_pEdit->IsSelected())
tsepez4cf55152016-11-02 14:37:54 -0700349 bVisible = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700350
351 m_pEditCaret->SetCaret(bVisible, ptHead, ptFoot);
352 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700353}
354
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700355CFX_WideString CPWL_EditCtrl::GetText() const {
356 return m_pEdit->GetText();
357}
358
359void CPWL_EditCtrl::SetSel(int32_t nStartChar, int32_t nEndChar) {
360 m_pEdit->SetSel(nStartChar, nEndChar);
361}
362
363void CPWL_EditCtrl::GetSel(int32_t& nStartChar, int32_t& nEndChar) const {
364 m_pEdit->GetSel(nStartChar, nEndChar);
365}
366
367void CPWL_EditCtrl::Clear() {
368 if (!IsReadOnly())
369 m_pEdit->Clear();
370}
371
372void CPWL_EditCtrl::SelectAll() {
373 m_pEdit->SelectAll();
374}
375
Dan Sinclairf528eee2017-02-14 11:52:07 -0500376void CPWL_EditCtrl::SetScrollPos(const CFX_PointF& point) {
thestig732f6a02016-05-12 10:41:56 -0700377 m_pEdit->SetScrollPos(point);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700378}
379
Dan Sinclairf528eee2017-02-14 11:52:07 -0500380CFX_PointF CPWL_EditCtrl::GetScrollPos() const {
thestig732f6a02016-05-12 10:41:56 -0700381 return m_pEdit->GetScrollPos();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700382}
383
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700384void CPWL_EditCtrl::CopyText() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700385
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700386void CPWL_EditCtrl::PasteText() {}
387
388void CPWL_EditCtrl::CutText() {}
389
tsepez4cf55152016-11-02 14:37:54 -0700390void CPWL_EditCtrl::ShowVScrollBar(bool bShow) {}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700391
Tom Sepez62a70f92016-03-21 15:00:20 -0700392void CPWL_EditCtrl::InsertWord(uint16_t word, int32_t nCharset) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700393 if (!IsReadOnly())
394 m_pEdit->InsertWord(word, nCharset);
395}
396
397void CPWL_EditCtrl::InsertReturn() {
398 if (!IsReadOnly())
399 m_pEdit->InsertReturn();
400}
401
402void CPWL_EditCtrl::Delete() {
403 if (!IsReadOnly())
404 m_pEdit->Delete();
405}
406
407void CPWL_EditCtrl::Backspace() {
408 if (!IsReadOnly())
409 m_pEdit->Backspace();
410}
411
tsepez4cf55152016-11-02 14:37:54 -0700412bool CPWL_EditCtrl::CanUndo() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700413 return !IsReadOnly() && m_pEdit->CanUndo();
414}
415
tsepez4cf55152016-11-02 14:37:54 -0700416bool CPWL_EditCtrl::CanRedo() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700417 return !IsReadOnly() && m_pEdit->CanRedo();
418}
419
420void CPWL_EditCtrl::Redo() {
421 if (CanRedo())
422 m_pEdit->Redo();
423}
424
425void CPWL_EditCtrl::Undo() {
426 if (CanUndo())
427 m_pEdit->Undo();
428}
429
Dan Sinclair05df0752017-03-14 14:43:42 -0400430void CPWL_EditCtrl::IOnSetScrollInfoY(float fPlateMin,
431 float fPlateMax,
432 float fContentMin,
433 float fContentMax,
434 float fSmallStep,
435 float fBigStep) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700436 PWL_SCROLL_INFO Info;
437
438 Info.fPlateWidth = fPlateMax - fPlateMin;
439 Info.fContentMin = fContentMin;
440 Info.fContentMax = fContentMax;
441 Info.fSmallStep = fSmallStep;
442 Info.fBigStep = fBigStep;
443
444 OnNotify(this, PNM_SETSCROLLINFO, SBT_VSCROLL, (intptr_t)&Info);
445
446 if (IsFloatBigger(Info.fPlateWidth, Info.fContentMax - Info.fContentMin) ||
447 IsFloatEqual(Info.fPlateWidth, Info.fContentMax - Info.fContentMin)) {
tsepez4cf55152016-11-02 14:37:54 -0700448 ShowVScrollBar(false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700449 } else {
tsepez4cf55152016-11-02 14:37:54 -0700450 ShowVScrollBar(true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700451 }
452}
453
Dan Sinclair05df0752017-03-14 14:43:42 -0400454void CPWL_EditCtrl::IOnSetScrollPosY(float fy) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700455 OnNotify(this, PNM_SETSCROLLPOS, SBT_VSCROLL, (intptr_t)&fy);
456}
457
tsepez4cf55152016-11-02 14:37:54 -0700458void CPWL_EditCtrl::IOnSetCaret(bool bVisible,
Dan Sinclairf528eee2017-02-14 11:52:07 -0500459 const CFX_PointF& ptHead,
460 const CFX_PointF& ptFoot,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700461 const CPVT_WordPlace& place) {
462 PWL_CARET_INFO cInfo;
463 cInfo.bVisible = bVisible;
464 cInfo.ptHead = ptHead;
465 cInfo.ptFoot = ptFoot;
466
thestig1cd352e2016-06-07 17:53:06 -0700467 OnNotify(this, PNM_SETCARETINFO, (intptr_t)&cInfo, (intptr_t) nullptr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700468}
469
Tom Sepez281a9ea2016-02-26 14:24:28 -0800470void CPWL_EditCtrl::IOnInvalidateRect(CFX_FloatRect* pRect) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700471 InvalidateRect(pRect);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700472}
473
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700474int32_t CPWL_EditCtrl::GetCharSet() const {
Dan Sinclairf51a02a2017-04-19 12:46:53 -0400475 return m_nCharSet < 0 ? FX_CHARSET_Default : m_nCharSet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700476}
477
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700478void CPWL_EditCtrl::SetReadyToInput() {
479 if (m_bMouseDown) {
480 ReleaseCapture();
tsepez4cf55152016-11-02 14:37:54 -0700481 m_bMouseDown = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700482 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700483}