blob: 0794be653c1fb680e3012e81fbdfddca1b5dfb5a [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 Zhangbde53d22015-11-12 22:21:30 -08007#include "fpdfsdk/include/pdfwindow/PDFWindow.h"
8#include "fpdfsdk/include/pdfwindow/PWL_Caret.h"
9#include "fpdfsdk/include/pdfwindow/PWL_EditCtrl.h"
10#include "fpdfsdk/include/pdfwindow/PWL_FontMap.h"
11#include "fpdfsdk/include/pdfwindow/PWL_ScrollBar.h"
12#include "fpdfsdk/include/pdfwindow/PWL_Utils.h"
13#include "fpdfsdk/include/pdfwindow/PWL_Wnd.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070014
Nico Weber9d8ec5a2015-08-04 13:00:21 -070015#define IsFloatZero(f) ((f) < 0.0001 && (f) > -0.0001)
16#define IsFloatBigger(fa, fb) ((fa) > (fb) && !IsFloatZero((fa) - (fb)))
17#define IsFloatSmaller(fa, fb) ((fa) < (fb) && !IsFloatZero((fa) - (fb)))
18#define IsFloatEqual(fa, fb) IsFloatZero((fa) - (fb))
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070019
20/* ---------------------------- CPWL_EditCtrl ------------------------------ */
21
Nico Weber9d8ec5a2015-08-04 13:00:21 -070022CPWL_EditCtrl::CPWL_EditCtrl()
23 : m_pEdit(NULL),
24 m_pEditCaret(NULL),
25 m_bMouseDown(FALSE),
26 m_pEditNotify(NULL),
27 m_nCharSet(DEFAULT_CHARSET),
28 m_nCodePage(0) {
29 m_pEdit = IFX_Edit::NewEdit();
30 ASSERT(m_pEdit != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070031}
32
Nico Weber9d8ec5a2015-08-04 13:00:21 -070033CPWL_EditCtrl::~CPWL_EditCtrl() {
34 IFX_Edit::DelEdit(m_pEdit);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070035}
36
Nico Weber9d8ec5a2015-08-04 13:00:21 -070037void CPWL_EditCtrl::OnCreate(PWL_CREATEPARAM& cp) {
38 cp.eCursorType = FXCT_VBEAM;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070039}
40
Nico Weber9d8ec5a2015-08-04 13:00:21 -070041void CPWL_EditCtrl::OnCreated() {
42 SetFontSize(GetCreationParam().fFontSize);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070043
Nico Weber9d8ec5a2015-08-04 13:00:21 -070044 m_pEdit->SetFontMap(GetFontMap());
45 m_pEdit->SetNotify(this);
46 m_pEdit->Initialize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070047}
48
Nico Weber9d8ec5a2015-08-04 13:00:21 -070049FX_BOOL CPWL_EditCtrl::IsWndHorV() {
50 CPDF_Matrix mt = GetWindowMatrix();
51 CPDF_Point point1(0, 1);
52 CPDF_Point point2(1, 1);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070053
Nico Weber9d8ec5a2015-08-04 13:00:21 -070054 mt.Transform(point1.x, point1.y);
55 mt.Transform(point2.x, point2.y);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070056
Nico Weber9d8ec5a2015-08-04 13:00:21 -070057 return point2.y == point1.y;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070058}
59
Nico Weber9d8ec5a2015-08-04 13:00:21 -070060void CPWL_EditCtrl::SetCursor() {
61 if (IsValid()) {
62 if (IFX_SystemHandler* pSH = GetSystemHandler()) {
63 if (IsWndHorV())
64 pSH->SetCursor(FXCT_VBEAM);
65 else
66 pSH->SetCursor(FXCT_HBEAM);
Tom Sepez2f2ffec2015-07-23 14:42:09 -070067 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070068 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070069}
70
Nico Weber9d8ec5a2015-08-04 13:00:21 -070071void CPWL_EditCtrl::RePosChildWnd() {
72 m_pEdit->SetPlateRect(GetClientRect());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070073}
74
Nico Weber9d8ec5a2015-08-04 13:00:21 -070075void CPWL_EditCtrl::OnNotify(CPWL_Wnd* pWnd,
76 FX_DWORD msg,
77 intptr_t wParam,
78 intptr_t lParam) {
79 CPWL_Wnd::OnNotify(pWnd, msg, wParam, lParam);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070080
Nico Weber9d8ec5a2015-08-04 13:00:21 -070081 switch (msg) {
82 case PNM_SETSCROLLINFO:
83 switch (wParam) {
84 case SBT_VSCROLL:
85 if (CPWL_Wnd* pChild = GetVScrollBar()) {
86 pChild->OnNotify(pWnd, PNM_SETSCROLLINFO, wParam, lParam);
87 }
88 break;
89 }
90 break;
91 case PNM_SETSCROLLPOS:
92 switch (wParam) {
93 case SBT_VSCROLL:
94 if (CPWL_Wnd* pChild = GetVScrollBar()) {
95 pChild->OnNotify(pWnd, PNM_SETSCROLLPOS, wParam, lParam);
96 }
97 break;
98 }
99 break;
100 case PNM_SCROLLWINDOW: {
101 FX_FLOAT fPos = *(FX_FLOAT*)lParam;
102 switch (wParam) {
103 case SBT_VSCROLL:
104 m_pEdit->SetScrollPos(CPDF_Point(m_pEdit->GetScrollPos().x, fPos));
105 break;
106 }
107 } break;
108 case PNM_SETCARETINFO: {
109 if (PWL_CARET_INFO* pCaretInfo = (PWL_CARET_INFO*)wParam) {
110 SetCaret(pCaretInfo->bVisible, pCaretInfo->ptHead, pCaretInfo->ptFoot);
111 }
112 } break;
113 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700114}
115
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700116void CPWL_EditCtrl::CreateChildWnd(const PWL_CREATEPARAM& cp) {
117 if (!IsReadOnly())
118 CreateEditCaret(cp);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700119}
120
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700121void CPWL_EditCtrl::CreateEditCaret(const PWL_CREATEPARAM& cp) {
122 if (!m_pEditCaret) {
123 m_pEditCaret = new CPWL_Caret;
124 m_pEditCaret->SetInvalidRect(GetClientRect());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700125
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700126 PWL_CREATEPARAM ecp = cp;
127 ecp.pParentWnd = this;
128 ecp.dwFlags = PWS_CHILD | PWS_NOREFRESHCLIP;
129 ecp.dwBorderWidth = 0;
130 ecp.nBorderStyle = PBS_SOLID;
131 ecp.rcRectWnd = CPDF_Rect(0, 0, 0, 0);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700132
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700133 m_pEditCaret->Create(ecp);
134 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700135}
136
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700137void CPWL_EditCtrl::SetFontSize(FX_FLOAT fFontSize) {
138 m_pEdit->SetFontSize(fFontSize);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700139}
140
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700141FX_FLOAT CPWL_EditCtrl::GetFontSize() const {
142 return m_pEdit->GetFontSize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700143}
144
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700145FX_BOOL CPWL_EditCtrl::OnKeyDown(FX_WORD nChar, FX_DWORD nFlag) {
146 if (m_bMouseDown)
147 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700148
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700149 FX_BOOL bRet = CPWL_Wnd::OnKeyDown(nChar, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700150
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700151 // FILTER
152 switch (nChar) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700153 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700154 return FALSE;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700155 case FWL_VKEY_Delete:
156 case FWL_VKEY_Up:
157 case FWL_VKEY_Down:
158 case FWL_VKEY_Left:
159 case FWL_VKEY_Right:
160 case FWL_VKEY_Home:
161 case FWL_VKEY_End:
162 case FWL_VKEY_Insert:
163 case 'C':
164 case 'V':
165 case 'X':
166 case 'A':
167 case 'Z':
168 case 'c':
169 case 'v':
170 case 'x':
171 case 'a':
172 case 'z':
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700173 break;
174 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700175
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700176 if (nChar == FWL_VKEY_Delete) {
177 if (m_pEdit->IsSelected())
178 nChar = FWL_VKEY_Unknown;
179 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700180
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700181 switch (nChar) {
182 case FWL_VKEY_Delete:
183 Delete();
184 return TRUE;
185 case FWL_VKEY_Insert:
186 if (IsSHIFTpressed(nFlag))
187 PasteText();
188 return TRUE;
189 case FWL_VKEY_Up:
190 m_pEdit->OnVK_UP(IsSHIFTpressed(nFlag), FALSE);
191 return TRUE;
192 case FWL_VKEY_Down:
193 m_pEdit->OnVK_DOWN(IsSHIFTpressed(nFlag), FALSE);
194 return TRUE;
195 case FWL_VKEY_Left:
196 m_pEdit->OnVK_LEFT(IsSHIFTpressed(nFlag), FALSE);
197 return TRUE;
198 case FWL_VKEY_Right:
199 m_pEdit->OnVK_RIGHT(IsSHIFTpressed(nFlag), FALSE);
200 return TRUE;
201 case FWL_VKEY_Home:
202 m_pEdit->OnVK_HOME(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
203 return TRUE;
204 case FWL_VKEY_End:
205 m_pEdit->OnVK_END(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
206 return TRUE;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700207 case FWL_VKEY_Unknown:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700208 if (!IsSHIFTpressed(nFlag))
209 Clear();
210 else
211 CutText();
212 return TRUE;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700213 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700214 break;
215 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700216
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700217 return bRet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700218}
219
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700220FX_BOOL CPWL_EditCtrl::OnChar(FX_WORD nChar, FX_DWORD nFlag) {
221 if (m_bMouseDown)
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700222 return TRUE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700223
224 CPWL_Wnd::OnChar(nChar, nFlag);
225
226 // FILTER
227 switch (nChar) {
228 case 0x0A:
229 case 0x1B:
230 return FALSE;
231 default:
232 break;
233 }
234
235 FX_BOOL bCtrl = IsCTRLpressed(nFlag);
236 FX_BOOL bAlt = IsALTpressed(nFlag);
237 FX_BOOL bShift = IsSHIFTpressed(nFlag);
238
239 FX_WORD word = nChar;
240
241 if (bCtrl && !bAlt) {
242 switch (nChar) {
243 case 'C' - 'A' + 1:
244 CopyText();
245 return TRUE;
246 case 'V' - 'A' + 1:
247 PasteText();
248 return TRUE;
249 case 'X' - 'A' + 1:
250 CutText();
251 return TRUE;
252 case 'A' - 'A' + 1:
253 SelectAll();
254 return TRUE;
255 case 'Z' - 'A' + 1:
256 if (bShift)
257 Redo();
258 else
259 Undo();
260 return TRUE;
261 default:
262 if (nChar < 32)
263 return FALSE;
264 }
265 }
266
267 if (IsReadOnly())
268 return TRUE;
269
270 if (m_pEdit->IsSelected() && word == FWL_VKEY_Back)
271 word = FWL_VKEY_Unknown;
272
273 Clear();
274
275 switch (word) {
276 case FWL_VKEY_Back:
277 Backspace();
278 break;
279 case FWL_VKEY_Return:
280 InsertReturn();
281 break;
282 case FWL_VKEY_Unknown:
283 break;
284 default:
285 if (IsINSERTpressed(nFlag))
286 Delete();
287 InsertWord(word, GetCharSet());
288 break;
289 }
290
291 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700292}
293
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700294FX_BOOL CPWL_EditCtrl::OnLButtonDown(const CPDF_Point& point, FX_DWORD nFlag) {
295 CPWL_Wnd::OnLButtonDown(point, nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700296
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700297 if (ClientHitTest(point)) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700298 if (m_bMouseDown)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700299 InvalidateRect();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700300
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700301 m_bMouseDown = TRUE;
302 SetCapture();
303
304 m_pEdit->OnMouseDown(point, IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
305 }
306
307 return TRUE;
308}
309
310FX_BOOL CPWL_EditCtrl::OnLButtonUp(const CPDF_Point& point, FX_DWORD nFlag) {
311 CPWL_Wnd::OnLButtonUp(point, nFlag);
312
313 if (m_bMouseDown) {
314 // can receive keybord message
315 if (ClientHitTest(point) && !IsFocused())
316 SetFocus();
317
318 ReleaseCapture();
319 m_bMouseDown = FALSE;
320 }
321
322 return TRUE;
323}
324
325FX_BOOL CPWL_EditCtrl::OnMouseMove(const CPDF_Point& point, FX_DWORD nFlag) {
326 CPWL_Wnd::OnMouseMove(point, nFlag);
327
328 if (m_bMouseDown)
329 m_pEdit->OnMouseMove(point, FALSE, FALSE);
330
331 return TRUE;
332}
333
334CPDF_Rect CPWL_EditCtrl::GetContentRect() const {
335 return m_pEdit->GetContentRect();
336}
337
338void CPWL_EditCtrl::SetEditCaret(FX_BOOL bVisible) {
339 CPDF_Point ptHead(0, 0), ptFoot(0, 0);
340
341 if (bVisible) {
342 GetCaretInfo(ptHead, ptFoot);
343 }
344
345 CPVT_WordPlace wpTemp = m_pEdit->GetCaretWordPlace();
346 IOnSetCaret(bVisible, ptHead, ptFoot, wpTemp);
347}
348
349void CPWL_EditCtrl::GetCaretInfo(CPDF_Point& ptHead, CPDF_Point& ptFoot) const {
350 if (IFX_Edit_Iterator* pIterator = m_pEdit->GetIterator()) {
351 pIterator->SetAt(m_pEdit->GetCaret());
352 CPVT_Word word;
353 CPVT_Line line;
354 if (pIterator->GetWord(word)) {
355 ptHead.x = word.ptWord.x + word.fWidth;
356 ptHead.y = word.ptWord.y + word.fAscent;
357 ptFoot.x = word.ptWord.x + word.fWidth;
358 ptFoot.y = word.ptWord.y + word.fDescent;
359 } else if (pIterator->GetLine(line)) {
360 ptHead.x = line.ptLine.x;
361 ptHead.y = line.ptLine.y + line.fLineAscent;
362 ptFoot.x = line.ptLine.x;
363 ptFoot.y = line.ptLine.y + line.fLineDescent;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700364 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700365 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700366}
367
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700368void CPWL_EditCtrl::GetCaretPos(int32_t& x, int32_t& y) const {
369 CPDF_Point ptHead(0, 0), ptFoot(0, 0);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700370
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700371 GetCaretInfo(ptHead, ptFoot);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700372
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700373 PWLtoWnd(ptHead, x, y);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700374}
375
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700376void CPWL_EditCtrl::SetCaret(FX_BOOL bVisible,
377 const CPDF_Point& ptHead,
378 const CPDF_Point& ptFoot) {
379 if (m_pEditCaret) {
380 if (!IsFocused() || m_pEdit->IsSelected())
381 bVisible = FALSE;
382
383 m_pEditCaret->SetCaret(bVisible, ptHead, ptFoot);
384 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700385}
386
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700387FX_BOOL CPWL_EditCtrl::IsModified() const {
388 return m_pEdit->IsModified();
389}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700390
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700391CFX_WideString CPWL_EditCtrl::GetText() const {
392 return m_pEdit->GetText();
393}
394
395void CPWL_EditCtrl::SetSel(int32_t nStartChar, int32_t nEndChar) {
396 m_pEdit->SetSel(nStartChar, nEndChar);
397}
398
399void CPWL_EditCtrl::GetSel(int32_t& nStartChar, int32_t& nEndChar) const {
400 m_pEdit->GetSel(nStartChar, nEndChar);
401}
402
403void CPWL_EditCtrl::Clear() {
404 if (!IsReadOnly())
405 m_pEdit->Clear();
406}
407
408void CPWL_EditCtrl::SelectAll() {
409 m_pEdit->SelectAll();
410}
411
412void CPWL_EditCtrl::Paint() {
413 if (m_pEdit)
414 m_pEdit->Paint();
415}
416
417void CPWL_EditCtrl::EnableRefresh(FX_BOOL bRefresh) {
418 if (m_pEdit)
419 m_pEdit->EnableRefresh(bRefresh);
420}
421
422int32_t CPWL_EditCtrl::GetCaret() const {
423 if (m_pEdit)
424 return m_pEdit->GetCaret();
425
426 return -1;
427}
428
429void CPWL_EditCtrl::SetCaret(int32_t nPos) {
430 if (m_pEdit)
431 m_pEdit->SetCaret(nPos);
432}
433
434int32_t CPWL_EditCtrl::GetTotalWords() const {
435 if (m_pEdit)
436 return m_pEdit->GetTotalWords();
437
438 return 0;
439}
440
441void CPWL_EditCtrl::SetScrollPos(const CPDF_Point& point) {
442 if (m_pEdit)
443 m_pEdit->SetScrollPos(point);
444}
445
446CPDF_Point CPWL_EditCtrl::GetScrollPos() const {
447 if (m_pEdit)
448 return m_pEdit->GetScrollPos();
449
450 return CPDF_Point(0.0f, 0.0f);
451}
452
453CPDF_Font* CPWL_EditCtrl::GetCaretFont() const {
454 int32_t nFontIndex = 0;
455
456 if (IFX_Edit_Iterator* pIterator = m_pEdit->GetIterator()) {
457 pIterator->SetAt(m_pEdit->GetCaret());
458 CPVT_Word word;
459 CPVT_Section section;
460 if (pIterator->GetWord(word)) {
461 nFontIndex = word.nFontIndex;
462 } else if (HasFlag(PES_RICH)) {
463 if (pIterator->GetSection(section)) {
464 nFontIndex = section.WordProps.nFontIndex;
465 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700466 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700467 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700468
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700469 if (IFX_Edit_FontMap* pFontMap = GetFontMap())
470 return pFontMap->GetPDFFont(nFontIndex);
471
472 return NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700473}
474
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700475FX_FLOAT CPWL_EditCtrl::GetCaretFontSize() const {
476 FX_FLOAT fFontSize = GetFontSize();
477
478 if (IFX_Edit_Iterator* pIterator = m_pEdit->GetIterator()) {
479 pIterator->SetAt(m_pEdit->GetCaret());
480 CPVT_Word word;
481 CPVT_Section section;
482 if (pIterator->GetWord(word)) {
483 fFontSize = word.fFontSize;
484 } else if (HasFlag(PES_RICH)) {
485 if (pIterator->GetSection(section)) {
486 fFontSize = section.WordProps.fFontSize;
487 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700488 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700489 }
490
491 return fFontSize;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700492}
493
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700494void CPWL_EditCtrl::SetText(const FX_WCHAR* csText) {
495 m_pEdit->SetText(csText);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700496}
497
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700498void CPWL_EditCtrl::CopyText() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700499
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700500void CPWL_EditCtrl::PasteText() {}
501
502void CPWL_EditCtrl::CutText() {}
503
504void CPWL_EditCtrl::ShowVScrollBar(FX_BOOL bShow) {}
505
506void CPWL_EditCtrl::InsertText(const FX_WCHAR* csText) {
507 if (!IsReadOnly())
508 m_pEdit->InsertText(csText);
509}
510
511void CPWL_EditCtrl::InsertWord(FX_WORD word, int32_t nCharset) {
512 if (!IsReadOnly())
513 m_pEdit->InsertWord(word, nCharset);
514}
515
516void CPWL_EditCtrl::InsertReturn() {
517 if (!IsReadOnly())
518 m_pEdit->InsertReturn();
519}
520
521void CPWL_EditCtrl::Delete() {
522 if (!IsReadOnly())
523 m_pEdit->Delete();
524}
525
526void CPWL_EditCtrl::Backspace() {
527 if (!IsReadOnly())
528 m_pEdit->Backspace();
529}
530
531FX_BOOL CPWL_EditCtrl::CanUndo() const {
532 return !IsReadOnly() && m_pEdit->CanUndo();
533}
534
535FX_BOOL CPWL_EditCtrl::CanRedo() const {
536 return !IsReadOnly() && m_pEdit->CanRedo();
537}
538
539void CPWL_EditCtrl::Redo() {
540 if (CanRedo())
541 m_pEdit->Redo();
542}
543
544void CPWL_EditCtrl::Undo() {
545 if (CanUndo())
546 m_pEdit->Undo();
547}
548
549void CPWL_EditCtrl::IOnSetScrollInfoY(FX_FLOAT fPlateMin,
550 FX_FLOAT fPlateMax,
551 FX_FLOAT fContentMin,
552 FX_FLOAT fContentMax,
553 FX_FLOAT fSmallStep,
554 FX_FLOAT fBigStep) {
555 PWL_SCROLL_INFO Info;
556
557 Info.fPlateWidth = fPlateMax - fPlateMin;
558 Info.fContentMin = fContentMin;
559 Info.fContentMax = fContentMax;
560 Info.fSmallStep = fSmallStep;
561 Info.fBigStep = fBigStep;
562
563 OnNotify(this, PNM_SETSCROLLINFO, SBT_VSCROLL, (intptr_t)&Info);
564
565 if (IsFloatBigger(Info.fPlateWidth, Info.fContentMax - Info.fContentMin) ||
566 IsFloatEqual(Info.fPlateWidth, Info.fContentMax - Info.fContentMin)) {
567 ShowVScrollBar(FALSE);
568 } else {
569 ShowVScrollBar(TRUE);
570 }
571}
572
573void CPWL_EditCtrl::IOnSetScrollPosY(FX_FLOAT fy) {
574 OnNotify(this, PNM_SETSCROLLPOS, SBT_VSCROLL, (intptr_t)&fy);
575}
576
577void CPWL_EditCtrl::IOnSetCaret(FX_BOOL bVisible,
578 const CPDF_Point& ptHead,
579 const CPDF_Point& ptFoot,
580 const CPVT_WordPlace& place) {
581 PWL_CARET_INFO cInfo;
582 cInfo.bVisible = bVisible;
583 cInfo.ptHead = ptHead;
584 cInfo.ptFoot = ptFoot;
585
586 OnNotify(this, PNM_SETCARETINFO, (intptr_t)&cInfo, (intptr_t)NULL);
587}
588
589void CPWL_EditCtrl::IOnCaretChange(const CPVT_SecProps& secProps,
590 const CPVT_WordProps& wordProps) {}
591
592void CPWL_EditCtrl::IOnContentChange(const CPDF_Rect& rcContent) {
593 if (IsValid()) {
594 if (m_pEditNotify) {
595 m_pEditNotify->OnContentChange(rcContent);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700596 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700597 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700598}
599
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700600void CPWL_EditCtrl::IOnInvalidateRect(CPDF_Rect* pRect) {
601 InvalidateRect(pRect);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700602}
603
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700604int32_t CPWL_EditCtrl::GetCharSet() const {
605 return m_nCharSet < 0 ? DEFAULT_CHARSET : m_nCharSet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700606}
607
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700608void CPWL_EditCtrl::GetTextRange(const CPDF_Rect& rect,
609 int32_t& nStartChar,
610 int32_t& nEndChar) const {
611 nStartChar = m_pEdit->WordPlaceToWordIndex(
612 m_pEdit->SearchWordPlace(CPDF_Point(rect.left, rect.top)));
613 nEndChar = m_pEdit->WordPlaceToWordIndex(
614 m_pEdit->SearchWordPlace(CPDF_Point(rect.right, rect.bottom)));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700615}
616
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700617CFX_WideString CPWL_EditCtrl::GetText(int32_t& nStartChar,
618 int32_t& nEndChar) const {
619 CPVT_WordPlace wpStart = m_pEdit->WordIndexToWordPlace(nStartChar);
620 CPVT_WordPlace wpEnd = m_pEdit->WordIndexToWordPlace(nEndChar);
621 return m_pEdit->GetRangeText(CPVT_WordRange(wpStart, wpEnd));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700622}
623
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700624void CPWL_EditCtrl::SetReadyToInput() {
625 if (m_bMouseDown) {
626 ReleaseCapture();
627 m_bMouseDown = FALSE;
628 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700629}