Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
cpwl_edit.cpp
Go to the documentation of this file.
1// Copyright 2014 The PDFium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7#include "fpdfsdk/pwl/cpwl_edit.h"
8
9#include <algorithm>
10#include <memory>
11#include <sstream>
12#include <utility>
13
14#include "constants/ascii.h"
15#include "core/fpdfapi/font/cpdf_font.h"
16#include "core/fpdfdoc/cpvt_word.h"
17#include "core/fpdfdoc/ipvt_fontmap.h"
18#include "core/fxcrt/fx_safe_types.h"
19#include "core/fxge/cfx_fillrenderoptions.h"
20#include "core/fxge/cfx_graphstatedata.h"
21#include "core/fxge/cfx_path.h"
22#include "core/fxge/cfx_renderdevice.h"
23#include "core/fxge/fx_font.h"
24#include "fpdfsdk/pwl/cpwl_caret.h"
25#include "fpdfsdk/pwl/cpwl_edit_impl.h"
26#include "fpdfsdk/pwl/cpwl_scroll_bar.h"
27#include "fpdfsdk/pwl/cpwl_wnd.h"
28#include "fpdfsdk/pwl/ipwl_fillernotify.h"
29#include "public/fpdf_fwlevent.h"
30#include "third_party/base/check.h"
31
32CPWL_Edit::CPWL_Edit(
33 const CreateParams& cp,
34 std::unique_ptr<IPWL_FillerNotify::PerWindowData> pAttachedData)
35 : CPWL_Wnd(cp, std::move(pAttachedData)),
38}
39
40CPWL_Edit::~CPWL_Edit() {
41 DCHECK(!m_bFocus);
42}
43
44void CPWL_Edit::SetText(const WideString& csText) {
45 m_pEditImpl->SetText(csText);
46 m_pEditImpl->Paint();
47}
48
49bool CPWL_Edit::RepositionChildWnd() {
50 if (CPWL_ScrollBar* pVSB = GetVScrollBar()) {
51 CFX_FloatRect rcWindow = m_rcOldWindow;
52 CFX_FloatRect rcVScroll =
53 CFX_FloatRect(rcWindow.right, rcWindow.bottom,
54 rcWindow.right + CPWL_ScrollBar::kWidth, rcWindow.top);
55
56 ObservedPtr<CPWL_Edit> this_observed(this);
57 pVSB->Move(rcVScroll, true, false);
58 if (!this_observed) {
59 return false;
60 }
61 }
62
63 if (m_pCaret && !HasFlag(PES_TEXTOVERFLOW)) {
65 if (!rect.IsEmpty()) {
66 // +1 for caret beside border
67 rect.Inflate(1.0f, 1.0f);
68 rect.Normalize();
69 }
70 m_pCaret->SetClipRect(rect);
71 }
72
73 m_pEditImpl->SetPlateRect(GetClientRect());
74 m_pEditImpl->Paint();
75 return true;
76}
77
78CFX_FloatRect CPWL_Edit::GetClientRect() const {
79 float width = static_cast<float>(GetBorderWidth() + GetInnerBorderWidth());
80 CFX_FloatRect rcClient = GetWindowRect().GetDeflated(width, width);
81 CPWL_ScrollBar* pVSB = GetVScrollBar();
82 if (pVSB && pVSB->IsVisible())
83 rcClient.right -= CPWL_ScrollBar::kWidth;
84 return rcClient;
85}
86
88 m_pEditImpl->SetAlignmentV(static_cast<int32_t>(PEAV_CENTER));
89 m_pEditImpl->Paint();
90}
91
92bool CPWL_Edit::CanSelectAll() const {
93 return GetSelectWordRange() != m_pEditImpl->GetWholeWordRange();
94}
95
96bool CPWL_Edit::CanCopy() const {
97 return !HasFlag(PES_PASSWORD) && m_pEditImpl->IsSelected();
98}
99
100bool CPWL_Edit::CanCut() const {
101 return CanCopy() && !IsReadOnly();
102}
103
104void CPWL_Edit::CutText() {
105 if (!CanCut())
106 return;
107 m_pEditImpl->ClearSelection();
108}
109
110void CPWL_Edit::OnCreated() {
112 m_pEditImpl->SetFontMap(GetFontMap());
113 m_pEditImpl->SetNotify(this);
114 m_pEditImpl->Initialize();
115
116 if (CPWL_ScrollBar* pScroll = GetVScrollBar()) {
118 pScroll->SetTransparency(255);
119 }
120
121 SetParamByFlag();
122 m_rcOldWindow = GetWindowRect();
123}
124
125void CPWL_Edit::SetParamByFlag() {
126 if (HasFlag(PES_RIGHT)) {
127 m_pEditImpl->SetAlignmentH(2);
128 } else if (HasFlag(PES_MIDDLE)) {
129 m_pEditImpl->SetAlignmentH(1);
130 } else {
131 m_pEditImpl->SetAlignmentH(0);
132 }
133
134 if (HasFlag(PES_CENTER)) {
135 m_pEditImpl->SetAlignmentV(1);
136 } else {
137 m_pEditImpl->SetAlignmentV(0);
138 }
139
140 if (HasFlag(PES_PASSWORD)) {
141 m_pEditImpl->SetPasswordChar('*');
142 }
143
144 m_pEditImpl->SetMultiLine(HasFlag(PES_MULTILINE));
145 m_pEditImpl->SetAutoReturn(HasFlag(PES_AUTORETURN));
146 m_pEditImpl->SetAutoFontSize(HasFlag(PWS_AUTOFONTSIZE));
147 m_pEditImpl->SetAutoScroll(HasFlag(PES_AUTOSCROLL));
148 m_pEditImpl->EnableUndo(HasFlag(PES_UNDO));
149
152 m_pEditImpl->SetTextOverflow(true);
153 } else {
154 if (m_pCaret) {
156 if (!rect.IsEmpty()) {
157 // +1 for caret beside border
158 rect.Inflate(1.0f, 1.0f);
159 rect.Normalize();
160 }
161 m_pCaret->SetClipRect(rect);
162 }
163 }
164}
165
166void CPWL_Edit::DrawThisAppearance(CFX_RenderDevice* pDevice,
167 const CFX_Matrix& mtUser2Device) {
168 CPWL_Wnd::DrawThisAppearance(pDevice, mtUser2Device);
169
170 const CFX_FloatRect rcClient = GetClientRect();
171 const BorderStyle border_style = GetBorderStyle();
172 const int32_t nCharArray = m_pEditImpl->GetCharArray();
173 bool draw_border = nCharArray > 0 && (border_style == BorderStyle::kSolid ||
174 border_style == BorderStyle::kDash);
175 if (draw_border) {
176 FX_SAFE_INT32 nCharArraySafe = nCharArray;
177 nCharArraySafe -= 1;
178 nCharArraySafe *= 2;
179 draw_border = nCharArraySafe.IsValid();
180 }
181
182 if (draw_border) {
185 if (border_style == BorderStyle::kDash) {
186 gsd.m_DashArray = {static_cast<float>(GetBorderDash().nDash),
187 static_cast<float>(GetBorderDash().nGap)};
188 gsd.m_DashPhase = GetBorderDash().nPhase;
189 }
190
191 const float width = (rcClient.right - rcClient.left) / nCharArray;
192 CFX_Path path;
193 CFX_PointF bottom(0, rcClient.bottom);
194 CFX_PointF top(0, rcClient.top);
195 for (int32_t i = 0; i < nCharArray - 1; ++i) {
196 bottom.x = rcClient.left + width * (i + 1);
197 top.x = bottom.x;
200 }
201 if (!path.GetPoints().empty()) {
202 pDevice->DrawPath(path, &mtUser2Device, &gsd, 0,
203 GetBorderColor().ToFXColor(255),
205 }
206 }
207
208 CFX_FloatRect rcClip;
209 CPVT_WordRange wrRange = m_pEditImpl->GetVisibleWordRange();
210 CPVT_WordRange* pRange = nullptr;
212 rcClip = GetClientRect();
213 pRange = &wrRange;
214 }
215 m_pEditImpl->DrawEdit(
216 pDevice, mtUser2Device, GetTextColor().ToFXColor(GetTransparency()),
217 rcClip, CFX_PointF(), pRange, GetFillerNotify(), GetAttachedData());
218}
219
220void CPWL_Edit::OnSetFocus() {
221 ObservedPtr<CPWL_Edit> observed_ptr(this);
222 SetEditCaret(true);
223 if (!observed_ptr)
224 return;
225
226 if (!IsReadOnly()) {
227 CPWL_Wnd::ProviderIface* pProvider = GetProvider();
228 if (pProvider) {
229 pProvider->OnSetFocusForEdit(this);
230 if (!observed_ptr)
231 return;
232 }
233 }
234 m_bFocus = true;
235}
236
237void CPWL_Edit::OnKillFocus() {
238 ObservedPtr<CPWL_Edit> observed_ptr(this);
239 CPWL_ScrollBar* pScroll = GetVScrollBar();
240 if (pScroll && pScroll->IsVisible()) {
241 if (!pScroll->SetVisible(false)) {
242 return;
243 }
244 if (!observed_ptr) {
245 return;
246 }
247 if (!Move(m_rcOldWindow, true, true)) {
248 return;
249 }
250 }
251
252 m_pEditImpl->SelectNone();
253 if (!observed_ptr)
254 return;
255
256 if (!SetCaret(false, CFX_PointF(), CFX_PointF()))
257 return;
258
260 m_bFocus = false;
261}
262
263CPVT_WordRange CPWL_Edit::GetSelectWordRange() const {
264 if (!m_pEditImpl->IsSelected())
265 return CPVT_WordRange();
266
267 int32_t nStart;
268 int32_t nEnd;
269 std::tie(nStart, nEnd) = m_pEditImpl->GetSelection();
270
271 CPVT_WordPlace wpStart = m_pEditImpl->WordIndexToWordPlace(nStart);
272 CPVT_WordPlace wpEnd = m_pEditImpl->WordIndexToWordPlace(nEnd);
273 return CPVT_WordRange(wpStart, wpEnd);
274}
275
276bool CPWL_Edit::IsTextFull() const {
277 return m_pEditImpl->IsTextFull();
278}
279
280float CPWL_Edit::GetCharArrayAutoFontSize(const CPDF_Font* pFont,
281 const CFX_FloatRect& rcPlate,
282 int32_t nCharArray) {
283 if (!pFont || pFont->IsStandardFont())
284 return 0.0f;
285
286 const FX_RECT& rcBBox = pFont->GetFontBBox();
287
288 CFX_FloatRect rcCell = rcPlate;
289 float xdiv = rcCell.Width() / nCharArray * 1000.0f / rcBBox.Width();
290 float ydiv = -rcCell.Height() * 1000.0f / rcBBox.Height();
291
292 return xdiv < ydiv ? xdiv : ydiv;
293}
294
295void CPWL_Edit::SetCharArray(int32_t nCharArray) {
296 if (!HasFlag(PES_CHARARRAY) || nCharArray <= 0)
297 return;
298
299 m_pEditImpl->SetCharArray(nCharArray);
300 m_pEditImpl->SetTextOverflow(true);
301 m_pEditImpl->Paint();
302
304 return;
305
306 IPVT_FontMap* pFontMap = GetFontMap();
307 if (!pFontMap)
308 return;
309
310 float fFontSize = GetCharArrayAutoFontSize(pFontMap->GetPDFFont(0).Get(),
311 GetClientRect(), nCharArray);
312 if (fFontSize <= 0.0f)
313 return;
314
315 m_pEditImpl->SetAutoFontSize(false);
316 m_pEditImpl->SetFontSize(fFontSize);
317 m_pEditImpl->Paint();
318}
319
320void CPWL_Edit::SetLimitChar(int32_t nLimitChar) {
321 m_pEditImpl->SetLimitChar(nLimitChar);
322 m_pEditImpl->Paint();
323}
324
325CFX_FloatRect CPWL_Edit::GetFocusRect() const {
326 return CFX_FloatRect();
327}
328
329bool CPWL_Edit::IsVScrollBarVisible() const {
330 CPWL_ScrollBar* pScroll = GetVScrollBar();
331 return pScroll && pScroll->IsVisible();
332}
333
334bool CPWL_Edit::OnKeyDown(FWL_VKEYCODE nKeyCode, Mask<FWL_EVENTFLAG> nFlag) {
335 if (m_bMouseDown)
336 return true;
337
338 if (nKeyCode == FWL_VKEY_Delete) {
339 WideString strChange;
340 WideString strChangeEx;
341
342 int nSelStart;
343 int nSelEnd;
344 std::tie(nSelStart, nSelEnd) = GetSelection();
345
346 if (nSelStart == nSelEnd)
347 nSelEnd = nSelStart + 1;
348
349 ObservedPtr<CPWL_Wnd> this_observed(this);
350
352 GetFillerNotify()->OnBeforeKeyStroke(GetAttachedData(), strChange,
353 strChangeEx, nSelStart, nSelEnd,
354 true, nFlag);
355
356 if (!this_observed) {
357 return false;
358 }
359 if (!result.rc) {
360 return false;
361 }
362 if (result.exit) {
363 return false;
364 }
365 }
366
367 bool bRet = OnKeyDownInternal(nKeyCode, nFlag);
368
369 // In case of implementation swallow the OnKeyDown event.
370 if (IsProceedtoOnChar(nKeyCode, nFlag))
371 return true;
372
373 return bRet;
374}
375
376// static
377bool CPWL_Edit::IsProceedtoOnChar(FWL_VKEYCODE nKeyCode,
378 Mask<FWL_EVENTFLAG> nFlag) {
379 bool bCtrl = IsPlatformShortcutKey(nFlag);
380 bool bAlt = IsALTKeyDown(nFlag);
381 if (bCtrl && !bAlt) {
382 // hot keys for edit control.
383 switch (nKeyCode) {
384 case FWL_VKEY_A:
385 case FWL_VKEY_C:
386 case FWL_VKEY_V:
387 case FWL_VKEY_X:
388 case FWL_VKEY_Z:
389 return true;
390 default:
391 break;
392 }
393 }
394 // control characters.
395 switch (nKeyCode) {
396 case FWL_VKEY_Escape:
397 case FWL_VKEY_Back:
398 case FWL_VKEY_Return:
399 case FWL_VKEY_Space:
400 return true;
401 default:
402 return false;
403 }
404}
405
406bool CPWL_Edit::OnChar(uint16_t nChar, Mask<FWL_EVENTFLAG> nFlag) {
407 if (m_bMouseDown)
408 return true;
409
410 if (!IsCTRLKeyDown(nFlag)) {
411 WideString swChange;
412 int nSelStart;
413 int nSelEnd;
414 std::tie(nSelStart, nSelEnd) = GetSelection();
415
416 switch (nChar) {
417 case pdfium::ascii::kBackspace:
418 if (nSelStart == nSelEnd)
419 nSelStart = nSelEnd - 1;
420 break;
421 case pdfium::ascii::kReturn:
422 break;
423 default:
424 swChange += nChar;
425 break;
426 }
427
428 ObservedPtr<CPWL_Wnd> this_observed(this);
429
430 WideString strChangeEx;
432 GetFillerNotify()->OnBeforeKeyStroke(GetAttachedData(), swChange,
433 strChangeEx, nSelStart, nSelEnd,
434 true, nFlag);
435
436 if (!this_observed) {
437 return false;
438 }
439 if (!result.rc) {
440 return true;
441 }
442 if (result.exit) {
443 return false;
444 }
445 }
446
447 if (IPVT_FontMap* pFontMap = GetFontMap()) {
448 FX_Charset nOldCharSet = GetCharSet();
449 FX_Charset nNewCharSet =
451 if (nOldCharSet != nNewCharSet) {
452 SetCharSet(nNewCharSet);
453 }
454 }
455
456 return OnCharInternal(nChar, nFlag);
457}
458
459bool CPWL_Edit::OnMouseWheel(Mask<FWL_EVENTFLAG> nFlag,
460 const CFX_PointF& point,
461 const CFX_Vector& delta) {
463 return false;
464
465 CFX_PointF ptScroll = GetScrollPos();
466 if (delta.y > 0)
467 ptScroll.y += GetFontSize();
468 else
469 ptScroll.y -= GetFontSize();
470 SetScrollPos(ptScroll);
471 return true;
472}
473
474void CPWL_Edit::OnDestroy() {
475 m_pCaret.ExtractAsDangling();
476}
477
478bool CPWL_Edit::IsWndHorV() const {
480 return mt.Transform(CFX_PointF(1, 1)).y == mt.Transform(CFX_PointF(0, 1)).y;
481}
482
483void CPWL_Edit::SetCursor() {
484 if (IsValid()) {
485 GetFillerNotify()->SetCursor(IsWndHorV()
488 }
489}
490
491WideString CPWL_Edit::GetSelectedText() {
492 return m_pEditImpl->GetSelectedText();
493}
494
495void CPWL_Edit::ReplaceAndKeepSelection(const WideString& text) {
496 m_pEditImpl->ReplaceAndKeepSelection(text);
497}
498
499void CPWL_Edit::ReplaceSelection(const WideString& text) {
500 m_pEditImpl->ReplaceSelection(text);
501}
502
503bool CPWL_Edit::SelectAllText() {
504 m_pEditImpl->SelectAll();
505 return true;
506}
507
508void CPWL_Edit::SetScrollInfo(const PWL_SCROLL_INFO& info) {
509 if (CPWL_Wnd* pChild = GetVScrollBar())
510 pChild->SetScrollInfo(info);
511}
512
513void CPWL_Edit::SetScrollPosition(float pos) {
514 if (CPWL_Wnd* pChild = GetVScrollBar())
515 pChild->SetScrollPosition(pos);
516}
517
518void CPWL_Edit::ScrollWindowVertically(float pos) {
519 m_pEditImpl->SetScrollPos(CFX_PointF(m_pEditImpl->GetScrollPos().x, pos));
520}
521
522void CPWL_Edit::CreateChildWnd(const CreateParams& cp) {
523 if (!IsReadOnly())
524 CreateEditCaret(cp);
525}
526
527void CPWL_Edit::CreateEditCaret(const CreateParams& cp) {
528 if (m_pCaret)
529 return;
530
531 CreateParams ecp = cp;
533 ecp.dwBorderWidth = 0;
536
537 auto pCaret = std::make_unique<CPWL_Caret>(ecp, CloneAttachedData());
538 m_pCaret = pCaret.get();
539 m_pCaret->SetInvalidRect(GetClientRect());
540 AddChild(std::move(pCaret));
541 m_pCaret->Realize();
542}
543
544void CPWL_Edit::SetFontSize(float fFontSize) {
545 m_pEditImpl->SetFontSize(fFontSize);
546 m_pEditImpl->Paint();
547}
548
549float CPWL_Edit::GetFontSize() const {
550 return m_pEditImpl->GetFontSize();
551}
552
553bool CPWL_Edit::OnKeyDownInternal(FWL_VKEYCODE nKeyCode,
554 Mask<FWL_EVENTFLAG> nFlag) {
555 if (m_bMouseDown)
556 return true;
557
558 bool bRet = CPWL_Wnd::OnKeyDown(nKeyCode, nFlag);
559
560 // FILTER
561 switch (nKeyCode) {
562 default:
563 return false;
564 case FWL_VKEY_Delete:
565 case FWL_VKEY_Up:
566 case FWL_VKEY_Down:
567 case FWL_VKEY_Left:
568 case FWL_VKEY_Right:
569 case FWL_VKEY_Home:
570 case FWL_VKEY_End:
571 case FWL_VKEY_Insert:
572 case FWL_VKEY_A:
573 case FWL_VKEY_C:
574 case FWL_VKEY_V:
575 case FWL_VKEY_X:
576 case FWL_VKEY_Z:
577 break;
578 }
579
580 if (nKeyCode == FWL_VKEY_Delete && m_pEditImpl->IsSelected())
581 nKeyCode = FWL_VKEY_Unknown;
582
583 switch (nKeyCode) {
584 case FWL_VKEY_Delete:
585 Delete();
586 return true;
587 case FWL_VKEY_Insert:
588 if (IsSHIFTKeyDown(nFlag))
589 PasteText();
590 return true;
591 case FWL_VKEY_Up:
592 m_pEditImpl->OnVK_UP(IsSHIFTKeyDown(nFlag));
593 return true;
594 case FWL_VKEY_Down:
595 m_pEditImpl->OnVK_DOWN(IsSHIFTKeyDown(nFlag));
596 return true;
597 case FWL_VKEY_Left:
598 m_pEditImpl->OnVK_LEFT(IsSHIFTKeyDown(nFlag));
599 return true;
600 case FWL_VKEY_Right:
601 m_pEditImpl->OnVK_RIGHT(IsSHIFTKeyDown(nFlag));
602 return true;
603 case FWL_VKEY_Home:
604 m_pEditImpl->OnVK_HOME(IsSHIFTKeyDown(nFlag), IsCTRLKeyDown(nFlag));
605 return true;
606 case FWL_VKEY_End:
607 m_pEditImpl->OnVK_END(IsSHIFTKeyDown(nFlag), IsCTRLKeyDown(nFlag));
608 return true;
609 case FWL_VKEY_Unknown:
610 if (!IsSHIFTKeyDown(nFlag))
612 else
613 CutText();
614 return true;
615 default:
616 break;
617 }
618
619 return bRet;
620}
621
622bool CPWL_Edit::OnCharInternal(uint16_t nChar, Mask<FWL_EVENTFLAG> nFlag) {
623 if (m_bMouseDown)
624 return true;
625
626 CPWL_Wnd::OnChar(nChar, nFlag);
627
628 // FILTER
629 switch (nChar) {
630 case pdfium::ascii::kNewline:
631 case pdfium::ascii::kEscape:
632 return false;
633 default:
634 break;
635 }
636
637 bool bCtrl = IsPlatformShortcutKey(nFlag);
638 bool bAlt = IsALTKeyDown(nFlag);
639 bool bShift = IsSHIFTKeyDown(nFlag);
640
641 uint16_t word = nChar;
642
643 if (bCtrl && !bAlt) {
644 switch (nChar) {
645 case pdfium::ascii::kControlC:
646 CopyText();
647 return true;
648 case pdfium::ascii::kControlV:
649 PasteText();
650 return true;
651 case pdfium::ascii::kControlX:
652 CutText();
653 return true;
654 case pdfium::ascii::kControlA:
656 return true;
657 case pdfium::ascii::kControlZ:
658 if (bShift)
659 Redo();
660 else
661 Undo();
662 return true;
663 default:
664 if (nChar < 32)
665 return false;
666 }
667 }
668
669 if (IsReadOnly())
670 return true;
671
672 if (m_pEditImpl->IsSelected() && word == pdfium::ascii::kBackspace)
673 word = pdfium::ascii::kNul;
674
676
677 switch (word) {
678 case pdfium::ascii::kBackspace:
679 Backspace();
680 break;
681 case pdfium::ascii::kReturn:
682 InsertReturn();
683 break;
684 case pdfium::ascii::kNul:
685 break;
686 default:
687 InsertWord(word, GetCharSet());
688 break;
689 }
690
691 return true;
692}
693
694bool CPWL_Edit::OnLButtonDown(Mask<FWL_EVENTFLAG> nFlag,
695 const CFX_PointF& point) {
697 if (HasFlag(PES_TEXTOVERFLOW) || ClientHitTest(point)) {
698 if (m_bMouseDown && !InvalidateRect(nullptr))
699 return true;
700
701 m_bMouseDown = true;
702 SetCapture();
703 m_pEditImpl->OnMouseDown(point, IsSHIFTKeyDown(nFlag),
704 IsCTRLKeyDown(nFlag));
705 }
706 return true;
707}
708
709bool CPWL_Edit::OnLButtonUp(Mask<FWL_EVENTFLAG> nFlag,
710 const CFX_PointF& point) {
711 CPWL_Wnd::OnLButtonUp(nFlag, point);
712 if (m_bMouseDown) {
713 // can receive keybord message
714 if (ClientHitTest(point) && !IsFocused())
715 SetFocus();
716
718 m_bMouseDown = false;
719 }
720 return true;
721}
722
723bool CPWL_Edit::OnLButtonDblClk(Mask<FWL_EVENTFLAG> nFlag,
724 const CFX_PointF& point) {
726 if (HasFlag(PES_TEXTOVERFLOW) || ClientHitTest(point))
727 m_pEditImpl->SelectAll();
728
729 return true;
730}
731
732bool CPWL_Edit::OnRButtonUp(Mask<FWL_EVENTFLAG> nFlag,
733 const CFX_PointF& point) {
734 if (m_bMouseDown)
735 return false;
736
737 CPWL_Wnd::OnRButtonUp(nFlag, point);
738 if (!HasFlag(PES_TEXTOVERFLOW) && !ClientHitTest(point))
739 return true;
740
741 SetFocus();
742 return false;
743}
744
745bool CPWL_Edit::OnMouseMove(Mask<FWL_EVENTFLAG> nFlag,
746 const CFX_PointF& point) {
747 CPWL_Wnd::OnMouseMove(nFlag, point);
748
749 if (m_bMouseDown)
750 m_pEditImpl->OnMouseMove(point, false, false);
751
752 return true;
753}
754
755void CPWL_Edit::SetEditCaret(bool bVisible) {
756 CFX_PointF ptHead;
757 CFX_PointF ptFoot;
758 if (bVisible)
759 GetCaretInfo(&ptHead, &ptFoot);
760
761 SetCaret(bVisible, ptHead, ptFoot);
762 // Note, |this| may no longer be viable at this point. If more work needs to
763 // be done, check the return value of SetCaret().
764}
765
766void CPWL_Edit::GetCaretInfo(CFX_PointF* ptHead, CFX_PointF* ptFoot) const {
767 CPWL_EditImpl::Iterator* pIterator = m_pEditImpl->GetIterator();
768 pIterator->SetAt(m_pEditImpl->GetCaret());
769 CPVT_Word word;
770 CPVT_Line line;
771 if (pIterator->GetWord(word)) {
772 ptHead->x = word.ptWord.x + word.fWidth;
773 ptHead->y = word.ptWord.y + word.fAscent;
774 ptFoot->x = word.ptWord.x + word.fWidth;
775 ptFoot->y = word.ptWord.y + word.fDescent;
776 } else if (pIterator->GetLine(line)) {
777 ptHead->x = line.ptLine.x;
778 ptHead->y = line.ptLine.y + line.fLineAscent;
779 ptFoot->x = line.ptLine.x;
780 ptFoot->y = line.ptLine.y + line.fLineDescent;
781 }
782}
783
784bool CPWL_Edit::SetCaret(bool bVisible,
785 const CFX_PointF& ptHead,
786 const CFX_PointF& ptFoot) {
787 if (!m_pCaret)
788 return true;
789
790 if (!IsFocused() || m_pEditImpl->IsSelected())
791 bVisible = false;
792
793 ObservedPtr<CPWL_Edit> this_observed(this);
794 m_pCaret->SetCaret(bVisible, ptHead, ptFoot);
795 if (!this_observed) {
796 return false;
797 }
798
799 return true;
800}
801
802WideString CPWL_Edit::GetText() {
803 return m_pEditImpl->GetText();
804}
805
806void CPWL_Edit::SetSelection(int32_t nStartChar, int32_t nEndChar) {
807 m_pEditImpl->SetSelection(nStartChar, nEndChar);
808}
809
810std::pair<int32_t, int32_t> CPWL_Edit::GetSelection() const {
811 return m_pEditImpl->GetSelection();
812}
813
814void CPWL_Edit::ClearSelection() {
815 if (!IsReadOnly())
816 m_pEditImpl->ClearSelection();
817}
818
819void CPWL_Edit::SetScrollPos(const CFX_PointF& point) {
820 m_pEditImpl->SetScrollPos(point);
821}
822
823CFX_PointF CPWL_Edit::GetScrollPos() const {
824 return m_pEditImpl->GetScrollPos();
825}
826
827void CPWL_Edit::CopyText() {}
828
829void CPWL_Edit::PasteText() {}
830
831void CPWL_Edit::InsertWord(uint16_t word, FX_Charset nCharset) {
832 if (!IsReadOnly())
833 m_pEditImpl->InsertWord(word, nCharset);
834}
835
836void CPWL_Edit::InsertReturn() {
837 if (!IsReadOnly())
838 m_pEditImpl->InsertReturn();
839}
840
841void CPWL_Edit::Delete() {
842 if (!IsReadOnly())
843 m_pEditImpl->Delete();
844}
845
846void CPWL_Edit::Backspace() {
847 if (!IsReadOnly())
848 m_pEditImpl->Backspace();
849}
850
851bool CPWL_Edit::CanUndo() {
852 return !IsReadOnly() && m_pEditImpl->CanUndo();
853}
854
855bool CPWL_Edit::CanRedo() {
856 return !IsReadOnly() && m_pEditImpl->CanRedo();
857}
858
859bool CPWL_Edit::Undo() {
860 return CanUndo() && m_pEditImpl->Undo();
861}
862
863bool CPWL_Edit::Redo() {
864 return CanRedo() && m_pEditImpl->Redo();
865}
866
867void CPWL_Edit::SetReadyToInput() {
868 if (m_bMouseDown) {
870 m_bMouseDown = false;
871 }
872}
BorderStyle
constexpr CFX_FloatRect(float l, float b, float r, float t)
constexpr CFX_FloatRect()=default
float Width() const
bool IsEmpty() const
void Inflate(float x, float y)
CFX_FloatRect & operator=(const CFX_FloatRect &that)=default
float Height() const
CFX_PointF Transform(const CFX_PointF &point) const
void AppendPoint(const CFX_PointF &point, Point::Type type)
Definition cfx_path.cpp:289
bool DrawPath(const CFX_Path &path, const CFX_Matrix *pObject2Device, const CFX_GraphStateData *pGraphState, uint32_t fill_color, uint32_t stroke_color, const CFX_FillRenderOptions &fill_options)
const FX_RECT & GetFontBBox() const
Definition cpdf_font.h:113
bool IsStandardFont() const
float fLineAscent
Definition cpvt_line.h:21
float fLineDescent
Definition cpvt_line.h:22
float fAscent
Definition cpvt_word.h:23
float fDescent
Definition cpvt_word.h:24
float fWidth
Definition cpvt_word.h:25
bool GetWord(CPVT_Word &word) const
bool GetLine(CPVT_Line &line) const
bool CanCopy() const
Definition cpwl_edit.cpp:96
static float GetCharArrayAutoFontSize(const CPDF_Font *pFont, const CFX_FloatRect &rcPlate, int32_t nCharArray)
bool IsTextFull() const
void SetScrollInfo(const PWL_SCROLL_INFO &info) override
bool CanRedo() override
void SetFontSize(float fFontSize) override
bool SetCaret(bool bVisible, const CFX_PointF &ptHead, const CFX_PointF &ptFoot)
bool SelectAllText() override
bool OnLButtonUp(Mask< FWL_EVENTFLAG > nFlag, const CFX_PointF &point) override
bool CanUndo() override
bool OnKeyDown(FWL_VKEYCODE nKeyCode, Mask< FWL_EVENTFLAG > nFlag) override
CPWL_Edit(const CreateParams &cp, std::unique_ptr< IPWL_FillerNotify::PerWindowData > pAttachedData)
Definition cpwl_edit.cpp:32
void CutText()
bool Undo() override
bool Redo() override
CFX_FloatRect GetFocusRect() const override
bool RepositionChildWnd() override
Definition cpwl_edit.cpp:49
void SetScrollPosition(float pos) override
void SetAlignFormatVerticalCenter()
Definition cpwl_edit.cpp:87
void SetCursor() override
WideString GetText() override
void SetCharSet(FX_Charset nCharSet)
Definition cpwl_edit.h:81
bool CanCut() const
bool OnLButtonDblClk(Mask< FWL_EVENTFLAG > nFlag, const CFX_PointF &point) override
void OnSetFocus() override
void ReplaceAndKeepSelection(const WideString &text) override
void ScrollWindowVertically(float pos) override
void SetCharArray(int32_t nCharArray)
void SetSelection(int32_t nStartChar, int32_t nEndChar)
std::pair< int32_t, int32_t > GetSelection() const
void OnKillFocus() override
void SetScrollPos(const CFX_PointF &point)
void ClearSelection()
void SetText(const WideString &csText)
Definition cpwl_edit.cpp:44
bool OnMouseMove(Mask< FWL_EVENTFLAG > nFlag, const CFX_PointF &point) override
void ReplaceSelection(const WideString &text) override
CFX_FloatRect GetClientRect() const override
Definition cpwl_edit.cpp:78
bool OnMouseWheel(Mask< FWL_EVENTFLAG > nFlag, const CFX_PointF &point, const CFX_Vector &delta) override
void DrawThisAppearance(CFX_RenderDevice *pDevice, const CFX_Matrix &mtUser2Device) override
~CPWL_Edit() override
Definition cpwl_edit.cpp:40
void SetReadyToInput()
bool OnChar(uint16_t nChar, Mask< FWL_EVENTFLAG > nFlag) override
void OnCreated() override
WideString GetSelectedText() override
float GetFontSize() const override
void SetLimitChar(int32_t nLimitChar)
FX_Charset GetCharSet() const
Definition cpwl_edit.h:82
bool OnLButtonDown(Mask< FWL_EVENTFLAG > nFlag, const CFX_PointF &point) override
CFX_PointF GetScrollPos() const
bool OnRButtonUp(Mask< FWL_EVENTFLAG > nFlag, const CFX_PointF &point) override
void CreateChildWnd(const CreateParams &cp) override
void OnDestroy() override
bool CanSelectAll() const
Definition cpwl_edit.cpp:92
static constexpr float kWidth
CFX_FloatRect rcRectWnd
Definition cpwl_wnd.h:105
BorderStyle nBorderStyle
Definition cpwl_wnd.h:114
virtual void OnSetFocusForEdit(CPWL_Edit *pEdit)=0
CFX_Matrix GetWindowMatrix() const
Definition cpwl_wnd.cpp:739
static bool IsPlatformShortcutKey(Mask< FWL_EVENTFLAG > nFlag)
Definition cpwl_wnd.cpp:143
static bool IsCTRLKeyDown(Mask< FWL_EVENTFLAG > nFlag)
Definition cpwl_wnd.cpp:128
bool ClientHitTest(const CFX_PointF &point) const
Definition cpwl_wnd.cpp:571
void SetCapture()
Definition cpwl_wnd.cpp:518
static bool IsALTKeyDown(Mask< FWL_EVENTFLAG > nFlag)
Definition cpwl_wnd.cpp:133
CFX_Color GetBorderColor() const
Definition cpwl_wnd.cpp:490
BorderStyle GetBorderStyle() const
Definition cpwl_wnd.cpp:478
virtual bool OnChar(uint16_t nChar, Mask< FWL_EVENTFLAG > nFlag)
Definition cpwl_wnd.cpp:309
void RemoveFlag(uint32_t dwFlags)
Definition cpwl_wnd.cpp:466
IPWL_FillerNotify * GetFillerNotify() const
Definition cpwl_wnd.h:245
bool HasFlag(uint32_t dwFlags) const
Definition cpwl_wnd.cpp:462
CFX_FloatRect GetWindowRect() const
Definition cpwl_wnd.cpp:440
void ReleaseCapture()
Definition cpwl_wnd.cpp:524
bool IsFocused() const
Definition cpwl_wnd.cpp:684
IPVT_FontMap * GetFontMap() const
Definition cpwl_wnd.h:274
void SetTransparency(int32_t nTransparency)
Definition cpwl_wnd.cpp:732
virtual bool OnLButtonUp(Mask< FWL_EVENTFLAG > nFlag, const CFX_PointF &point)
virtual bool OnMouseMove(Mask< FWL_EVENTFLAG > nFlag, const CFX_PointF &point)
static bool IsSHIFTKeyDown(Mask< FWL_EVENTFLAG > nFlag)
Definition cpwl_wnd.cpp:123
virtual bool OnRButtonUp(Mask< FWL_EVENTFLAG > nFlag, const CFX_PointF &point)
Definition cpwl_wnd.cpp:357
virtual bool OnKeyDown(FWL_VKEYCODE nKeyCode, Mask< FWL_EVENTFLAG > nFlag)
Definition cpwl_wnd.cpp:297
int32_t GetBorderWidth() const
Definition cpwl_wnd.cpp:482
CreateParams * GetCreationParams()
Definition cpwl_wnd.h:238
virtual void SetScrollInfo(const PWL_SCROLL_INFO &info)
Definition cpwl_wnd.cpp:428
virtual bool InvalidateRect(const CFX_FloatRect *pRect)
Definition cpwl_wnd.cpp:278
virtual void SetFocus()
Definition cpwl_wnd.cpp:533
bool IsVisible() const
Definition cpwl_wnd.h:204
virtual bool SetVisible(bool bVisible)
Definition cpwl_wnd.cpp:575
IPWL_FillerNotify::PerWindowData * GetAttachedData() const
Definition cpwl_wnd.h:209
const CPWL_Dash & GetBorderDash() const
Definition cpwl_wnd.cpp:494
int32_t GetInnerBorderWidth() const
Definition cpwl_wnd.cpp:486
virtual void SetScrollPosition(float pos)
Definition cpwl_wnd.cpp:430
virtual void DrawThisAppearance(CFX_RenderDevice *pDevice, const CFX_Matrix &mtUser2Device)
Definition cpwl_wnd.cpp:250
ProviderIface * GetProvider() const
Definition cpwl_wnd.h:239
bool Move(const CFX_FloatRect &rcNew, bool bReset, bool bRefresh)
Definition cpwl_wnd.cpp:211
void SetClipRect(const CFX_FloatRect &rect)
Definition cpwl_wnd.cpp:601
virtual bool OnLButtonDblClk(Mask< FWL_EVENTFLAG > nFlag, const CFX_PointF &point)
CPWL_ScrollBar * GetVScrollBar() const
Definition cpwl_wnd.cpp:498
bool IsValid() const
Definition cpwl_wnd.h:237
virtual bool OnLButtonDown(Mask< FWL_EVENTFLAG > nFlag, const CFX_PointF &point)
bool IsReadOnly() const
Definition cpwl_wnd.cpp:610
virtual RetainPtr< CPDF_Font > GetPDFFont(int32_t nFontIndex)=0
virtual FX_Charset CharSetFromUnicode(uint16_t word, FX_Charset nOldCharset)=0
WideString & operator+=(wchar_t ch)
#define PES_AUTOSCROLL
Definition cpwl_wnd.h:48
#define PES_UNDO
Definition cpwl_wnd.h:50
#define PES_MULTILINE
Definition cpwl_wnd.h:40
#define PES_CHARARRAY
Definition cpwl_wnd.h:47
#define PWS_AUTOTRANSPARENT
Definition cpwl_wnd.h:36
#define PWS_AUTOFONTSIZE
Definition cpwl_wnd.h:35
#define PES_CENTER
Definition cpwl_wnd.h:46
#define PES_TEXTOVERFLOW
Definition cpwl_wnd.h:52
#define PES_MIDDLE
Definition cpwl_wnd.h:44
#define PES_PASSWORD
Definition cpwl_wnd.h:41
#define PWS_NOREFRESHCLIP
Definition cpwl_wnd.h:37
#define PES_RIGHT
Definition cpwl_wnd.h:43
#define PES_AUTORETURN
Definition cpwl_wnd.h:49
@ FWL_VKEY_End
@ FWL_VKEY_Z
@ FWL_VKEY_Right
@ FWL_VKEY_Up
@ FWL_VKEY_Home
@ FWL_VKEY_Down
@ FWL_VKEY_Unknown
@ FWL_VKEY_A
@ FWL_VKEY_Space
@ FWL_VKEY_X
@ FWL_VKEY_Insert
@ FWL_VKEY_C
@ FWL_VKEY_Back
@ FWL_VKEY_V
@ FWL_VKEY_Left
@ FWL_VKEY_Escape
@ FWL_VKEY_Return
@ FWL_VKEY_Delete
FX_Charset
Definition fx_codepage.h:70
constexpr uint8_t kEscape
Definition ascii.h:24
constexpr uint8_t kReturn
Definition ascii.h:20
constexpr uint8_t kControlC
Definition ascii.h:16
constexpr uint8_t kNul
Definition ascii.h:13
constexpr uint8_t kControlZ
Definition ascii.h:23
constexpr uint8_t kBackspace
Definition ascii.h:17
constexpr uint8_t kControlX
Definition ascii.h:22
constexpr uint8_t kNewline
Definition ascii.h:19
constexpr uint8_t kControlV
Definition ascii.h:21
constexpr uint8_t kControlA
Definition ascii.h:14
static constexpr CFX_FillRenderOptions EvenOddOptions()
CPVT_WordRange(const CPVT_WordPlace &begin, const CPVT_WordPlace &end)
CPVT_WordRange()=default
int Height() const
int Width() const