K. Moon | 832a694 | 2022-10-31 20:11:31 +0000 | [diff] [blame] | 1 | // Copyright 2016 The PDFium Authors |
jaepark | 2736276 | 2016-08-11 13:10:39 -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_ANNOT_H_ |
| 8 | #define FPDFSDK_CPDFSDK_ANNOT_H_ |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 9 | |
dsinclair | 1727aee | 2016-09-29 13:12:56 -0700 | [diff] [blame] | 10 | #include "core/fpdfdoc/cpdf_annot.h" |
Lei Zhang | 5f85281 | 2020-02-13 20:13:17 +0000 | [diff] [blame] | 11 | #include "core/fxcrt/fx_coordinates.h" |
Lei Zhang | 76ef4c9 | 2022-04-08 19:03:51 +0000 | [diff] [blame] | 12 | #include "core/fxcrt/mask.h" |
Tom Sepez | 27c350f | 2019-06-11 23:52:35 +0000 | [diff] [blame] | 13 | #include "core/fxcrt/observed_ptr.h" |
Dan Sinclair | aee0db0 | 2017-09-21 16:53:58 -0400 | [diff] [blame] | 14 | #include "core/fxcrt/unowned_ptr.h" |
Lei Zhang | 889fce7 | 2022-04-08 21:13:51 +0000 | [diff] [blame] | 15 | #include "core/fxcrt/widestring.h" |
Lei Zhang | 76ef4c9 | 2022-04-08 19:03:51 +0000 | [diff] [blame] | 16 | #include "public/fpdf_fwlevent.h" |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 17 | |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 18 | class CPDF_Page; |
Tom Sepez | 522d77d | 2018-07-28 00:00:25 +0000 | [diff] [blame] | 19 | class CPDFSDK_BAAnnot; |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 20 | class CPDFSDK_PageView; |
Tom Sepez | 451ed2d | 2019-08-19 22:55:31 +0000 | [diff] [blame] | 21 | class CPDFXFA_Widget; |
Tom Sepez | 8e94c18 | 2019-06-11 23:57:25 +0000 | [diff] [blame] | 22 | class IPDF_Page; |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 23 | |
Tom Sepez | d8ae8f8 | 2019-06-12 17:58:33 +0000 | [diff] [blame] | 24 | class CPDFSDK_Annot : public Observable { |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 25 | public: |
Lei Zhang | 76ef4c9 | 2022-04-08 19:03:51 +0000 | [diff] [blame] | 26 | // These methods may destroy the class that implements them when called. |
| 27 | // Access through the static methods below of the same name. |
| 28 | class UnsafeInputHandlers { |
| 29 | public: |
| 30 | virtual void OnMouseEnter(Mask<FWL_EVENTFLAG> nFlags) = 0; |
| 31 | virtual void OnMouseExit(Mask<FWL_EVENTFLAG> nFlags) = 0; |
| 32 | virtual bool OnLButtonDown(Mask<FWL_EVENTFLAG> nFlags, |
| 33 | const CFX_PointF& point) = 0; |
| 34 | virtual bool OnLButtonUp(Mask<FWL_EVENTFLAG> nFlags, |
| 35 | const CFX_PointF& point) = 0; |
| 36 | virtual bool OnLButtonDblClk(Mask<FWL_EVENTFLAG> nFlags, |
| 37 | const CFX_PointF& point) = 0; |
| 38 | virtual bool OnMouseMove(Mask<FWL_EVENTFLAG> nFlags, |
| 39 | const CFX_PointF& point) = 0; |
| 40 | virtual bool OnMouseWheel(Mask<FWL_EVENTFLAG> nFlags, |
| 41 | const CFX_PointF& point, |
| 42 | const CFX_Vector& delta) = 0; |
| 43 | virtual bool OnRButtonDown(Mask<FWL_EVENTFLAG> nFlags, |
| 44 | const CFX_PointF& point) = 0; |
| 45 | virtual bool OnRButtonUp(Mask<FWL_EVENTFLAG> nFlags, |
| 46 | const CFX_PointF& point) = 0; |
Lei Zhang | 2ea512b | 2022-04-08 21:10:01 +0000 | [diff] [blame] | 47 | virtual bool OnChar(uint32_t nChar, Mask<FWL_EVENTFLAG> nFlags) = 0; |
| 48 | virtual bool OnKeyDown(FWL_VKEYCODE nKeyCode, |
| 49 | Mask<FWL_EVENTFLAG> nFlags) = 0; |
| 50 | virtual bool OnSetFocus(Mask<FWL_EVENTFLAG> nFlags) = 0; |
| 51 | virtual bool OnKillFocus(Mask<FWL_EVENTFLAG> nFlags) = 0; |
Lei Zhang | 76ef4c9 | 2022-04-08 19:03:51 +0000 | [diff] [blame] | 52 | }; |
| 53 | |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 54 | virtual ~CPDFSDK_Annot(); |
| 55 | |
Tom Sepez | 522d77d | 2018-07-28 00:00:25 +0000 | [diff] [blame] | 56 | virtual CPDFSDK_BAAnnot* AsBAAnnot(); |
Tom Sepez | 451ed2d | 2019-08-19 22:55:31 +0000 | [diff] [blame] | 57 | virtual CPDFXFA_Widget* AsXFAWidget(); |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 58 | |
Lei Zhang | 76ef4c9 | 2022-04-08 19:03:51 +0000 | [diff] [blame] | 59 | // Never returns nullptr. |
| 60 | virtual UnsafeInputHandlers* GetUnsafeInputHandlers() = 0; |
| 61 | |
Lei Zhang | 5214eeb | 2022-04-04 23:37:28 +0000 | [diff] [blame] | 62 | virtual void OnLoad() {} |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 63 | virtual int GetLayoutOrder() const; |
| 64 | virtual CPDF_Annot* GetPDFAnnot() const; |
Tom Sepez | c141554 | 2021-09-21 21:48:59 +0000 | [diff] [blame] | 65 | virtual CPDF_Annot::Subtype GetAnnotSubtype() const = 0; |
| 66 | virtual CFX_FloatRect GetRect() const = 0; |
Lei Zhang | 2ea512b | 2022-04-08 21:10:01 +0000 | [diff] [blame] | 67 | virtual void OnDraw(CFX_RenderDevice* pDevice, |
| 68 | const CFX_Matrix& mtUser2Device, |
| 69 | bool bDrawAnnots) = 0; |
Lei Zhang | 37cef93 | 2022-04-05 18:23:29 +0000 | [diff] [blame] | 70 | virtual bool DoHitTest(const CFX_PointF& point) = 0; |
Lei Zhang | 23a042f | 2022-04-05 23:45:19 +0000 | [diff] [blame] | 71 | virtual CFX_FloatRect GetViewBBox() = 0; |
Lei Zhang | f342da7 | 2022-04-06 23:54:50 +0000 | [diff] [blame] | 72 | virtual bool CanUndo() = 0; |
| 73 | virtual bool CanRedo() = 0; |
| 74 | virtual bool Undo() = 0; |
| 75 | virtual bool Redo() = 0; |
Lei Zhang | 889fce7 | 2022-04-08 21:13:51 +0000 | [diff] [blame] | 76 | virtual WideString GetText() = 0; |
| 77 | virtual WideString GetSelectedText() = 0; |
Keren Zhu | 74e7eb7 | 2023-01-19 19:21:41 +0000 | [diff] [blame] | 78 | virtual void ReplaceAndKeepSelection(const WideString& text) = 0; |
Lei Zhang | 889fce7 | 2022-04-08 21:13:51 +0000 | [diff] [blame] | 79 | virtual void ReplaceSelection(const WideString& text) = 0; |
| 80 | virtual bool SelectAllText() = 0; |
| 81 | virtual bool SetIndexSelected(int index, bool selected) = 0; |
| 82 | virtual bool IsIndexSelected(int index) = 0; |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 83 | |
Lei Zhang | 76ef4c9 | 2022-04-08 19:03:51 +0000 | [diff] [blame] | 84 | // Callers must check if `pAnnot` is still valid after calling these methods, |
| 85 | // before accessing them again. |
| 86 | static void OnMouseEnter(ObservedPtr<CPDFSDK_Annot>& pAnnot, |
| 87 | Mask<FWL_EVENTFLAG> nFlags); |
| 88 | static void OnMouseExit(ObservedPtr<CPDFSDK_Annot>& pAnnot, |
| 89 | Mask<FWL_EVENTFLAG> nFlags); |
| 90 | static bool OnLButtonDown(ObservedPtr<CPDFSDK_Annot>& pAnnot, |
| 91 | Mask<FWL_EVENTFLAG> nFlags, |
| 92 | const CFX_PointF& point); |
| 93 | static bool OnLButtonUp(ObservedPtr<CPDFSDK_Annot>& pAnnot, |
| 94 | Mask<FWL_EVENTFLAG> nFlags, |
| 95 | const CFX_PointF& point); |
| 96 | static bool OnLButtonDblClk(ObservedPtr<CPDFSDK_Annot>& pAnnot, |
| 97 | Mask<FWL_EVENTFLAG> nFlags, |
| 98 | const CFX_PointF& point); |
| 99 | static bool OnMouseMove(ObservedPtr<CPDFSDK_Annot>& pAnnot, |
| 100 | Mask<FWL_EVENTFLAG> nFlags, |
| 101 | const CFX_PointF& point); |
| 102 | static bool OnMouseWheel(ObservedPtr<CPDFSDK_Annot>& pAnnot, |
| 103 | Mask<FWL_EVENTFLAG> nFlags, |
| 104 | const CFX_PointF& point, |
| 105 | const CFX_Vector& delta); |
| 106 | static bool OnRButtonDown(ObservedPtr<CPDFSDK_Annot>& pAnnot, |
| 107 | Mask<FWL_EVENTFLAG> nFlags, |
| 108 | const CFX_PointF& point); |
| 109 | static bool OnRButtonUp(ObservedPtr<CPDFSDK_Annot>& pAnnot, |
| 110 | Mask<FWL_EVENTFLAG> nFlags, |
| 111 | const CFX_PointF& point); |
Lei Zhang | 2ea512b | 2022-04-08 21:10:01 +0000 | [diff] [blame] | 112 | static bool OnChar(ObservedPtr<CPDFSDK_Annot>& pAnnot, |
| 113 | uint32_t nChar, |
| 114 | Mask<FWL_EVENTFLAG> nFlags); |
| 115 | static bool OnKeyDown(ObservedPtr<CPDFSDK_Annot>& pAnnot, |
| 116 | FWL_VKEYCODE nKeyCode, |
| 117 | Mask<FWL_EVENTFLAG> nFlags); |
| 118 | static bool OnSetFocus(ObservedPtr<CPDFSDK_Annot>& pAnnot, |
| 119 | Mask<FWL_EVENTFLAG> nFlags); |
| 120 | static bool OnKillFocus(ObservedPtr<CPDFSDK_Annot>& pAnnot, |
| 121 | Mask<FWL_EVENTFLAG> nFlags); |
Lei Zhang | 76ef4c9 | 2022-04-08 19:03:51 +0000 | [diff] [blame] | 122 | |
Tom Sepez | 9bf0181 | 2019-08-19 18:59:27 +0000 | [diff] [blame] | 123 | // Three cases: PDF page only, XFA page only, or XFA page backed by PDF page. |
| 124 | IPDF_Page* GetPage(); // Returns XFA Page if possible, else PDF page. |
| 125 | CPDF_Page* GetPDFPage(); // Returns PDF page or nullptr. |
| 126 | IPDF_Page* GetXFAPage(); // Returns XFA page or nullptr. |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 127 | |
Lei Zhang | c2ad628 | 2020-02-13 20:50:57 +0000 | [diff] [blame] | 128 | // Never returns nullptr. |
Tom Sepez | c4acde5 | 2022-10-28 00:47:46 +0000 | [diff] [blame] | 129 | CPDFSDK_PageView* GetPageView() const { return m_pPageView; } |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 130 | |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 131 | protected: |
Tom Sepez | c141554 | 2021-09-21 21:48:59 +0000 | [diff] [blame] | 132 | explicit CPDFSDK_Annot(CPDFSDK_PageView* pPageView); |
| 133 | |
Tom Sepez | a5af787 | 2022-08-16 19:26:42 +0000 | [diff] [blame] | 134 | private: |
Dan Sinclair | aee0db0 | 2017-09-21 16:53:58 -0400 | [diff] [blame] | 135 | UnownedPtr<CPDFSDK_PageView> const m_pPageView; |
jaepark | 2736276 | 2016-08-11 13:10:39 -0700 | [diff] [blame] | 136 | }; |
| 137 | |
Tom Sepez | 451ed2d | 2019-08-19 22:55:31 +0000 | [diff] [blame] | 138 | inline CPDFXFA_Widget* ToXFAWidget(CPDFSDK_Annot* pAnnot) { |
| 139 | return pAnnot ? pAnnot->AsXFAWidget() : nullptr; |
| 140 | } |
| 141 | |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 142 | #endif // FPDFSDK_CPDFSDK_ANNOT_H_ |