blob: b95f8442a14a3205708841ff457525bbcb5246d0 [file] [log] [blame]
K. Moon832a6942022-10-31 20:11:31 +00001// Copyright 2016 The PDFium Authors
dsinclairf34518b2016-09-13 12:03:48 -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_PAGEVIEW_H_
8#define FPDFSDK_CPDFSDK_PAGEVIEW_H_
dsinclairf34518b2016-09-13 12:03:48 -07009
Tom Sepez1e7fd162021-07-27 20:44:31 +000010#include <stdint.h>
11
dsinclairf34518b2016-09-13 12:03:48 -070012#include <memory>
13#include <vector>
14
dsinclair41872fa2016-10-04 11:29:35 -070015#include "core/fpdfapi/page/cpdf_page.h"
Tom Sepez6f9e9f62021-08-11 17:01:53 +000016#include "core/fxcrt/mask.h"
Dan Sinclairaee0db02017-09-21 16:53:58 -040017#include "core/fxcrt/unowned_ptr.h"
dsinclair114e46a2016-09-29 17:18:21 -070018#include "fpdfsdk/cpdfsdk_annot.h"
dsinclairf34518b2016-09-13 12:03:48 -070019
20class CFX_RenderDevice;
21class CPDF_AnnotList;
22class CPDF_RenderOptions;
Tom Sepez49357702019-08-19 17:17:18 +000023class CPDFSDK_FormFillEnvironment;
Tom Sepezd5ba1692021-09-13 20:36:19 +000024class CPDFSDK_InteractiveForm;
dsinclairf34518b2016-09-13 12:03:48 -070025
Tom Sepezba47d302021-09-16 01:36:04 +000026#ifdef PDF_ENABLE_XFA
27class CPDFXFA_Page;
28class CXFA_FFWidget;
29#endif // PDF_ENABLE_XFA
30
dsinclairf34518b2016-09-13 12:03:48 -070031class CPDFSDK_PageView final : public CPDF_Page::View {
32 public:
Tom Sepez101535f2018-06-12 13:36:05 +000033 CPDFSDK_PageView(CPDFSDK_FormFillEnvironment* pFormFillEnv, IPDF_Page* page);
dsinclairf34518b2016-09-13 12:03:48 -070034 ~CPDFSDK_PageView();
35
Tom Sepeze1b54ce2022-08-11 20:28:40 +000036 // CPDF_Page::View:
37 void ClearPage(CPDF_Page* pPage) override;
38
dsinclairf34518b2016-09-13 12:03:48 -070039 void PageView_OnDraw(CFX_RenderDevice* pDevice,
Lei Zhang09ee0872018-10-09 19:13:55 +000040 const CFX_Matrix& mtUser2Device,
dsinclairf34518b2016-09-13 12:03:48 -070041 CPDF_RenderOptions* pOptions,
42 const FX_RECT& pClip);
dsinclairf34518b2016-09-13 12:03:48 -070043
dsinclair8afe15a2016-10-05 12:00:34 -070044 void LoadFXAnnots();
dsinclairf34518b2016-09-13 12:03:48 -070045 CPDFSDK_Annot* GetFocusAnnot();
Tom Sepezba47d302021-09-16 01:36:04 +000046 CPDFSDK_Annot* GetNextAnnot(CPDFSDK_Annot* pAnnot);
47 CPDFSDK_Annot* GetPrevAnnot(CPDFSDK_Annot* pAnnot);
48 CPDFSDK_Annot* GetFirstFocusableAnnot();
49 CPDFSDK_Annot* GetLastFocusableAnnot();
dsinclair8afe15a2016-10-05 12:00:34 -070050 bool IsValidAnnot(const CPDF_Annot* p) const;
51 bool IsValidSDKAnnot(const CPDFSDK_Annot* p) const;
dsinclairf34518b2016-09-13 12:03:48 -070052
Lei Zhangf2a636f2022-04-04 19:01:14 +000053 std::vector<CPDFSDK_Annot*> GetAnnotList() const;
Tom Sepezb5649d92022-07-19 00:45:22 +000054 CPDFSDK_Annot* GetAnnotByDict(const CPDF_Dictionary* pDict);
dsinclairf34518b2016-09-13 12:03:48 -070055
56#ifdef PDF_ENABLE_XFA
Lei Zhang584ed122022-04-04 20:12:08 +000057 CPDFSDK_Annot* AddAnnotForFFWidget(CXFA_FFWidget* pWidget);
58 void DeleteAnnotForFFWidget(CXFA_FFWidget* pWidget);
59 CPDFSDK_Annot* GetAnnotForFFWidget(CXFA_FFWidget* pWidget);
Tom Sepez9bf01812019-08-19 18:59:27 +000060 IPDF_Page* GetXFAPage();
dsinclairf34518b2016-09-13 12:03:48 -070061#endif // PDF_ENABLE_XFA
62
63 CPDF_Page* GetPDFPage() const;
64 CPDF_Document* GetPDFDocument();
Tom Sepezc4acde52022-10-28 00:47:46 +000065 CPDFSDK_FormFillEnvironment* GetFormFillEnv() const { return m_pFormFillEnv; }
Tom Sepezcc205132017-05-16 14:01:47 -070066
Lei Zhanga4c7ac42018-04-17 15:12:58 +000067 WideString GetFocusedFormText();
Ryan Harrison275e2602017-09-18 14:23:18 -040068 WideString GetSelectedText();
Keren Zhu74e7eb72023-01-19 19:21:41 +000069 void ReplaceAndKeepSelection(const WideString& text);
Ryan Harrison275e2602017-09-18 14:23:18 -040070 void ReplaceSelection(const WideString& text);
Lei Zhanga6105362020-06-22 20:09:56 +000071 bool SelectAllText();
Diana Gagedce2d722017-06-20 11:17:11 -070072
Lei Zhangee967722018-04-19 20:55:54 +000073 bool CanUndo();
74 bool CanRedo();
75 bool Undo();
76 bool Redo();
77
Lei Zhang2ea512b2022-04-08 21:10:01 +000078 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 Sinclairf528eee2017-02-14 11:52:07 -050088 const CFX_PointF& point,
Lei Zhangbe912092020-04-17 18:03:33 +000089 const CFX_Vector& delta);
dsinclair8afe15a2016-10-05 12:00:34 -070090
rycsmitha5230e22019-02-21 17:33:03 +000091 bool SetIndexSelected(int index, bool selected);
92 bool IsIndexSelected(int index);
93
Lei Zhang831fa112018-12-19 20:30:14 +000094 const CFX_Matrix& GetCurrentMatrix() const { return m_curMatrix; }
dsinclairf34518b2016-09-13 12:03:48 -070095 void UpdateRects(const std::vector<CFX_FloatRect>& rects);
96 void UpdateView(CPDFSDK_Annot* pAnnot);
dsinclairf34518b2016-09-13 12:03:48 -070097
98 int GetPageIndex() const;
dsinclaire5393582016-10-03 11:25:00 -070099
tsepez4cf55152016-11-02 14:37:54 -0700100 void SetValid(bool bValid) { m_bValid = bValid; }
Lei Zhang09ee0872018-10-09 19:13:55 +0000101 bool IsValid() const { return m_bValid; }
102 bool IsLocked() const { return m_bLocked; }
dsinclairbcf46232016-10-03 13:02:27 -0700103 void SetBeingDestroyed() { m_bBeingDestroyed = true; }
104 bool IsBeingDestroyed() const { return m_bBeingDestroyed; }
dsinclairf34518b2016-09-13 12:03:48 -0700105
106 private:
Tom Sepezba47d302021-09-16 01:36:04 +0000107#ifdef PDF_ENABLE_XFA
108 CPDFXFA_Page* XFAPageIfNotBackedByPDFPage();
109#endif
110
Lei Zhang20143282022-04-08 21:16:52 +0000111 std::unique_ptr<CPDFSDK_Annot> NewAnnot(CPDF_Annot* annot);
112
Tom Sepezc44513e2022-10-24 23:23:03 +0000113 CPDFSDK_InteractiveForm* GetInteractiveForm() const;
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500114 CPDFSDK_Annot* GetFXAnnotAtPoint(const CFX_PointF& point);
115 CPDFSDK_Annot* GetFXWidgetAtPoint(const CFX_PointF& point);
116
dsinclairf34518b2016-09-13 12:03:48 -0700117 int GetPageIndexForStaticPDF() const;
118
Lei Zhang76ef4c92022-04-08 19:03:51 +0000119 void EnterWidget(ObservedPtr<CPDFSDK_Annot>& pAnnot,
Lei Zhang2ea512b2022-04-08 21:10:01 +0000120 Mask<FWL_EVENTFLAG> nFlags);
121 void ExitWidget(bool callExitCallback, Mask<FWL_EVENTFLAG> nFlags);
Henrique Nakashima4a652542017-08-22 10:59:49 -0400122
dsinclairf34518b2016-09-13 12:03:48 -0700123 CFX_Matrix m_curMatrix;
Tom Sepez76f17892021-03-30 20:25:14 +0000124 UnownedPtr<IPDF_Page> const m_page;
dsinclairf34518b2016-09-13 12:03:48 -0700125 std::unique_ptr<CPDF_AnnotList> m_pAnnotList;
Lei Zhangf2a636f2022-04-04 19:01:14 +0000126 std::vector<std::unique_ptr<CPDFSDK_Annot>> m_SDKAnnotArray;
Dan Sinclairaee0db02017-09-21 16:53:58 -0400127 UnownedPtr<CPDFSDK_FormFillEnvironment> const m_pFormFillEnv;
Tom Sepezd8ae8f82019-06-12 17:58:33 +0000128 ObservedPtr<CPDFSDK_Annot> m_pCaptureWidget;
Tom Sepez2aa4b2f2018-05-25 22:38:49 +0000129 bool m_bOnWidget = false;
130 bool m_bValid = false;
131 bool m_bLocked = false;
132 bool m_bBeingDestroyed = false;
dsinclairf34518b2016-09-13 12:03:48 -0700133};
134
dsinclair114e46a2016-09-29 17:18:21 -0700135#endif // FPDFSDK_CPDFSDK_PAGEVIEW_H_