blob: 1357594e9c2a09dec2c18935ea8ee239c7c79729 [file] [log] [blame]
K. Moon832a6942022-10-31 20:11:31 +00001// Copyright 2016 The PDFium Authors
jaepark27362762016-08-11 13:10:39 -07002// 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
dsinclair114e46a2016-09-29 17:18:21 -07007#ifndef FPDFSDK_CPDFSDK_ANNOT_H_
8#define FPDFSDK_CPDFSDK_ANNOT_H_
jaepark27362762016-08-11 13:10:39 -07009
dsinclair1727aee2016-09-29 13:12:56 -070010#include "core/fpdfdoc/cpdf_annot.h"
Lei Zhang5f852812020-02-13 20:13:17 +000011#include "core/fxcrt/fx_coordinates.h"
Lei Zhang76ef4c92022-04-08 19:03:51 +000012#include "core/fxcrt/mask.h"
Tom Sepez27c350f2019-06-11 23:52:35 +000013#include "core/fxcrt/observed_ptr.h"
Dan Sinclairaee0db02017-09-21 16:53:58 -040014#include "core/fxcrt/unowned_ptr.h"
Lei Zhang889fce72022-04-08 21:13:51 +000015#include "core/fxcrt/widestring.h"
Lei Zhang76ef4c92022-04-08 19:03:51 +000016#include "public/fpdf_fwlevent.h"
jaepark27362762016-08-11 13:10:39 -070017
jaepark27362762016-08-11 13:10:39 -070018class CPDF_Page;
Tom Sepez522d77d2018-07-28 00:00:25 +000019class CPDFSDK_BAAnnot;
jaepark27362762016-08-11 13:10:39 -070020class CPDFSDK_PageView;
Tom Sepez451ed2d2019-08-19 22:55:31 +000021class CPDFXFA_Widget;
Tom Sepez8e94c182019-06-11 23:57:25 +000022class IPDF_Page;
jaepark27362762016-08-11 13:10:39 -070023
Tom Sepezd8ae8f82019-06-12 17:58:33 +000024class CPDFSDK_Annot : public Observable {
jaepark27362762016-08-11 13:10:39 -070025 public:
Lei Zhang76ef4c92022-04-08 19:03:51 +000026 // 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 Zhang2ea512b2022-04-08 21:10:01 +000047 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 Zhang76ef4c92022-04-08 19:03:51 +000052 };
53
jaepark27362762016-08-11 13:10:39 -070054 virtual ~CPDFSDK_Annot();
55
Tom Sepez522d77d2018-07-28 00:00:25 +000056 virtual CPDFSDK_BAAnnot* AsBAAnnot();
Tom Sepez451ed2d2019-08-19 22:55:31 +000057 virtual CPDFXFA_Widget* AsXFAWidget();
jaepark27362762016-08-11 13:10:39 -070058
Lei Zhang76ef4c92022-04-08 19:03:51 +000059 // Never returns nullptr.
60 virtual UnsafeInputHandlers* GetUnsafeInputHandlers() = 0;
61
Lei Zhang5214eeb2022-04-04 23:37:28 +000062 virtual void OnLoad() {}
jaepark27362762016-08-11 13:10:39 -070063 virtual int GetLayoutOrder() const;
64 virtual CPDF_Annot* GetPDFAnnot() const;
Tom Sepezc1415542021-09-21 21:48:59 +000065 virtual CPDF_Annot::Subtype GetAnnotSubtype() const = 0;
66 virtual CFX_FloatRect GetRect() const = 0;
Lei Zhang2ea512b2022-04-08 21:10:01 +000067 virtual void OnDraw(CFX_RenderDevice* pDevice,
68 const CFX_Matrix& mtUser2Device,
69 bool bDrawAnnots) = 0;
Lei Zhang37cef932022-04-05 18:23:29 +000070 virtual bool DoHitTest(const CFX_PointF& point) = 0;
Lei Zhang23a042f2022-04-05 23:45:19 +000071 virtual CFX_FloatRect GetViewBBox() = 0;
Lei Zhangf342da72022-04-06 23:54:50 +000072 virtual bool CanUndo() = 0;
73 virtual bool CanRedo() = 0;
74 virtual bool Undo() = 0;
75 virtual bool Redo() = 0;
Lei Zhang889fce72022-04-08 21:13:51 +000076 virtual WideString GetText() = 0;
77 virtual WideString GetSelectedText() = 0;
Keren Zhu74e7eb72023-01-19 19:21:41 +000078 virtual void ReplaceAndKeepSelection(const WideString& text) = 0;
Lei Zhang889fce72022-04-08 21:13:51 +000079 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;
jaepark27362762016-08-11 13:10:39 -070083
Lei Zhang76ef4c92022-04-08 19:03:51 +000084 // 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 Zhang2ea512b2022-04-08 21:10:01 +0000112 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 Zhang76ef4c92022-04-08 19:03:51 +0000122
Tom Sepez9bf01812019-08-19 18:59:27 +0000123 // 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.
jaepark27362762016-08-11 13:10:39 -0700127
Lei Zhangc2ad6282020-02-13 20:50:57 +0000128 // Never returns nullptr.
Tom Sepezc4acde52022-10-28 00:47:46 +0000129 CPDFSDK_PageView* GetPageView() const { return m_pPageView; }
jaepark27362762016-08-11 13:10:39 -0700130
jaepark27362762016-08-11 13:10:39 -0700131 protected:
Tom Sepezc1415542021-09-21 21:48:59 +0000132 explicit CPDFSDK_Annot(CPDFSDK_PageView* pPageView);
133
Tom Sepeza5af7872022-08-16 19:26:42 +0000134 private:
Dan Sinclairaee0db02017-09-21 16:53:58 -0400135 UnownedPtr<CPDFSDK_PageView> const m_pPageView;
jaepark27362762016-08-11 13:10:39 -0700136};
137
Tom Sepez451ed2d2019-08-19 22:55:31 +0000138inline CPDFXFA_Widget* ToXFAWidget(CPDFSDK_Annot* pAnnot) {
139 return pAnnot ? pAnnot->AsXFAWidget() : nullptr;
140}
141
dsinclair114e46a2016-09-29 17:18:21 -0700142#endif // FPDFSDK_CPDFSDK_ANNOT_H_