K. Moon | 832a694 | 2022-10-31 20:11:31 +0000 | [diff] [blame] | 1 | // Copyright 2016 The PDFium Authors |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 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 | |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 7 | #ifndef FPDFSDK_CPDFSDK_PAGEVIEW_H_ |
| 8 | #define FPDFSDK_CPDFSDK_PAGEVIEW_H_ |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 9 | |
Tom Sepez | 1e7fd16 | 2021-07-27 20:44:31 +0000 | [diff] [blame] | 10 | #include <stdint.h> |
| 11 | |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 12 | #include <memory> |
| 13 | #include <vector> |
| 14 | |
dsinclair | 41872fa | 2016-10-04 11:29:35 -0700 | [diff] [blame] | 15 | #include "core/fpdfapi/page/cpdf_page.h" |
Tom Sepez | 6f9e9f6 | 2021-08-11 17:01:53 +0000 | [diff] [blame] | 16 | #include "core/fxcrt/mask.h" |
Dan Sinclair | aee0db0 | 2017-09-21 16:53:58 -0400 | [diff] [blame] | 17 | #include "core/fxcrt/unowned_ptr.h" |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 18 | #include "fpdfsdk/cpdfsdk_annot.h" |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 19 | |
| 20 | class CFX_RenderDevice; |
| 21 | class CPDF_AnnotList; |
| 22 | class CPDF_RenderOptions; |
Tom Sepez | 4935770 | 2019-08-19 17:17:18 +0000 | [diff] [blame] | 23 | class CPDFSDK_FormFillEnvironment; |
Tom Sepez | d5ba169 | 2021-09-13 20:36:19 +0000 | [diff] [blame] | 24 | class CPDFSDK_InteractiveForm; |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 25 | |
Tom Sepez | ba47d30 | 2021-09-16 01:36:04 +0000 | [diff] [blame] | 26 | #ifdef PDF_ENABLE_XFA |
| 27 | class CPDFXFA_Page; |
| 28 | class CXFA_FFWidget; |
| 29 | #endif // PDF_ENABLE_XFA |
| 30 | |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 31 | class CPDFSDK_PageView final : public CPDF_Page::View { |
| 32 | public: |
Tom Sepez | 101535f | 2018-06-12 13:36:05 +0000 | [diff] [blame] | 33 | CPDFSDK_PageView(CPDFSDK_FormFillEnvironment* pFormFillEnv, IPDF_Page* page); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 34 | ~CPDFSDK_PageView(); |
| 35 | |
Tom Sepez | e1b54ce | 2022-08-11 20:28:40 +0000 | [diff] [blame] | 36 | // CPDF_Page::View: |
| 37 | void ClearPage(CPDF_Page* pPage) override; |
| 38 | |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 39 | void PageView_OnDraw(CFX_RenderDevice* pDevice, |
Lei Zhang | 09ee087 | 2018-10-09 19:13:55 +0000 | [diff] [blame] | 40 | const CFX_Matrix& mtUser2Device, |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 41 | CPDF_RenderOptions* pOptions, |
| 42 | const FX_RECT& pClip); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 43 | |
dsinclair | 8afe15a | 2016-10-05 12:00:34 -0700 | [diff] [blame] | 44 | void LoadFXAnnots(); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 45 | CPDFSDK_Annot* GetFocusAnnot(); |
Tom Sepez | ba47d30 | 2021-09-16 01:36:04 +0000 | [diff] [blame] | 46 | CPDFSDK_Annot* GetNextAnnot(CPDFSDK_Annot* pAnnot); |
| 47 | CPDFSDK_Annot* GetPrevAnnot(CPDFSDK_Annot* pAnnot); |
| 48 | CPDFSDK_Annot* GetFirstFocusableAnnot(); |
| 49 | CPDFSDK_Annot* GetLastFocusableAnnot(); |
dsinclair | 8afe15a | 2016-10-05 12:00:34 -0700 | [diff] [blame] | 50 | bool IsValidAnnot(const CPDF_Annot* p) const; |
| 51 | bool IsValidSDKAnnot(const CPDFSDK_Annot* p) const; |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 52 | |
Lei Zhang | f2a636f | 2022-04-04 19:01:14 +0000 | [diff] [blame] | 53 | std::vector<CPDFSDK_Annot*> GetAnnotList() const; |
Tom Sepez | b5649d9 | 2022-07-19 00:45:22 +0000 | [diff] [blame] | 54 | CPDFSDK_Annot* GetAnnotByDict(const CPDF_Dictionary* pDict); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 55 | |
| 56 | #ifdef PDF_ENABLE_XFA |
Lei Zhang | 584ed12 | 2022-04-04 20:12:08 +0000 | [diff] [blame] | 57 | CPDFSDK_Annot* AddAnnotForFFWidget(CXFA_FFWidget* pWidget); |
| 58 | void DeleteAnnotForFFWidget(CXFA_FFWidget* pWidget); |
| 59 | CPDFSDK_Annot* GetAnnotForFFWidget(CXFA_FFWidget* pWidget); |
Tom Sepez | 9bf0181 | 2019-08-19 18:59:27 +0000 | [diff] [blame] | 60 | IPDF_Page* GetXFAPage(); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 61 | #endif // PDF_ENABLE_XFA |
| 62 | |
| 63 | CPDF_Page* GetPDFPage() const; |
| 64 | CPDF_Document* GetPDFDocument(); |
Tom Sepez | c4acde5 | 2022-10-28 00:47:46 +0000 | [diff] [blame] | 65 | CPDFSDK_FormFillEnvironment* GetFormFillEnv() const { return m_pFormFillEnv; } |
Tom Sepez | cc20513 | 2017-05-16 14:01:47 -0700 | [diff] [blame] | 66 | |
Lei Zhang | a4c7ac4 | 2018-04-17 15:12:58 +0000 | [diff] [blame] | 67 | WideString GetFocusedFormText(); |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 68 | WideString GetSelectedText(); |
Keren Zhu | 74e7eb7 | 2023-01-19 19:21:41 +0000 | [diff] [blame] | 69 | void ReplaceAndKeepSelection(const WideString& text); |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 70 | void ReplaceSelection(const WideString& text); |
Lei Zhang | a610536 | 2020-06-22 20:09:56 +0000 | [diff] [blame] | 71 | bool SelectAllText(); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 72 | |
Lei Zhang | ee96772 | 2018-04-19 20:55:54 +0000 | [diff] [blame] | 73 | bool CanUndo(); |
| 74 | bool CanRedo(); |
| 75 | bool Undo(); |
| 76 | bool Redo(); |
| 77 | |
Lei Zhang | 2ea512b | 2022-04-08 21:10:01 +0000 | [diff] [blame] | 78 | bool OnFocus(Mask<FWL_EVENTFLAG> nFlags, const CFX_PointF& point); |
| 79 | bool OnLButtonDown(Mask<FWL_EVENTFLAG> nFlags, const CFX_PointF& point); |
| 80 | bool OnLButtonUp(Mask<FWL_EVENTFLAG> nFlags, const CFX_PointF& point); |
| 81 | bool OnLButtonDblClk(Mask<FWL_EVENTFLAG> nFlags, const CFX_PointF& point); |
| 82 | bool OnRButtonDown(Mask<FWL_EVENTFLAG> nFlags, const CFX_PointF& point); |
| 83 | bool OnRButtonUp(Mask<FWL_EVENTFLAG> nFlags, const CFX_PointF& point); |
| 84 | bool OnChar(uint32_t nChar, Mask<FWL_EVENTFLAG> nFlags); |
| 85 | bool OnKeyDown(FWL_VKEYCODE nKeyCode, Mask<FWL_EVENTFLAG> nFlags); |
| 86 | bool OnMouseMove(Mask<FWL_EVENTFLAG> nFlags, const CFX_PointF& point); |
| 87 | bool OnMouseWheel(Mask<FWL_EVENTFLAG> nFlags, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 88 | const CFX_PointF& point, |
Lei Zhang | be91209 | 2020-04-17 18:03:33 +0000 | [diff] [blame] | 89 | const CFX_Vector& delta); |
dsinclair | 8afe15a | 2016-10-05 12:00:34 -0700 | [diff] [blame] | 90 | |
rycsmith | a5230e2 | 2019-02-21 17:33:03 +0000 | [diff] [blame] | 91 | bool SetIndexSelected(int index, bool selected); |
| 92 | bool IsIndexSelected(int index); |
| 93 | |
Lei Zhang | 831fa11 | 2018-12-19 20:30:14 +0000 | [diff] [blame] | 94 | const CFX_Matrix& GetCurrentMatrix() const { return m_curMatrix; } |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 95 | void UpdateRects(const std::vector<CFX_FloatRect>& rects); |
| 96 | void UpdateView(CPDFSDK_Annot* pAnnot); |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 97 | |
| 98 | int GetPageIndex() const; |
dsinclair | e539358 | 2016-10-03 11:25:00 -0700 | [diff] [blame] | 99 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 100 | void SetValid(bool bValid) { m_bValid = bValid; } |
Lei Zhang | 09ee087 | 2018-10-09 19:13:55 +0000 | [diff] [blame] | 101 | bool IsValid() const { return m_bValid; } |
| 102 | bool IsLocked() const { return m_bLocked; } |
dsinclair | bcf4623 | 2016-10-03 13:02:27 -0700 | [diff] [blame] | 103 | void SetBeingDestroyed() { m_bBeingDestroyed = true; } |
| 104 | bool IsBeingDestroyed() const { return m_bBeingDestroyed; } |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 105 | |
| 106 | private: |
Tom Sepez | ba47d30 | 2021-09-16 01:36:04 +0000 | [diff] [blame] | 107 | #ifdef PDF_ENABLE_XFA |
| 108 | CPDFXFA_Page* XFAPageIfNotBackedByPDFPage(); |
| 109 | #endif |
| 110 | |
Lei Zhang | 2014328 | 2022-04-08 21:16:52 +0000 | [diff] [blame] | 111 | std::unique_ptr<CPDFSDK_Annot> NewAnnot(CPDF_Annot* annot); |
| 112 | |
Tom Sepez | c44513e | 2022-10-24 23:23:03 +0000 | [diff] [blame] | 113 | CPDFSDK_InteractiveForm* GetInteractiveForm() const; |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 114 | CPDFSDK_Annot* GetFXAnnotAtPoint(const CFX_PointF& point); |
| 115 | CPDFSDK_Annot* GetFXWidgetAtPoint(const CFX_PointF& point); |
| 116 | |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 117 | int GetPageIndexForStaticPDF() const; |
| 118 | |
Lei Zhang | 76ef4c9 | 2022-04-08 19:03:51 +0000 | [diff] [blame] | 119 | void EnterWidget(ObservedPtr<CPDFSDK_Annot>& pAnnot, |
Lei Zhang | 2ea512b | 2022-04-08 21:10:01 +0000 | [diff] [blame] | 120 | Mask<FWL_EVENTFLAG> nFlags); |
| 121 | void ExitWidget(bool callExitCallback, Mask<FWL_EVENTFLAG> nFlags); |
Henrique Nakashima | 4a65254 | 2017-08-22 10:59:49 -0400 | [diff] [blame] | 122 | |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 123 | CFX_Matrix m_curMatrix; |
Tom Sepez | 76f1789 | 2021-03-30 20:25:14 +0000 | [diff] [blame] | 124 | UnownedPtr<IPDF_Page> const m_page; |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 125 | std::unique_ptr<CPDF_AnnotList> m_pAnnotList; |
Lei Zhang | f2a636f | 2022-04-04 19:01:14 +0000 | [diff] [blame] | 126 | std::vector<std::unique_ptr<CPDFSDK_Annot>> m_SDKAnnotArray; |
Dan Sinclair | aee0db0 | 2017-09-21 16:53:58 -0400 | [diff] [blame] | 127 | UnownedPtr<CPDFSDK_FormFillEnvironment> const m_pFormFillEnv; |
Tom Sepez | d8ae8f8 | 2019-06-12 17:58:33 +0000 | [diff] [blame] | 128 | ObservedPtr<CPDFSDK_Annot> m_pCaptureWidget; |
Tom Sepez | 2aa4b2f | 2018-05-25 22:38:49 +0000 | [diff] [blame] | 129 | bool m_bOnWidget = false; |
| 130 | bool m_bValid = false; |
| 131 | bool m_bLocked = false; |
| 132 | bool m_bBeingDestroyed = false; |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 133 | }; |
| 134 | |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 135 | #endif // FPDFSDK_CPDFSDK_PAGEVIEW_H_ |