blob: 9f846cf2a40d4bbfcb909dd684463fa8b00af8b8 [file] [log] [blame]
dsinclairf34518b2016-09-13 12:03:48 -07001// Copyright 2016 PDFium Authors. All rights reserved.
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
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
10#include <memory>
11#include <vector>
12
dsinclair41872fa2016-10-04 11:29:35 -070013#include "core/fpdfapi/page/cpdf_page.h"
dsinclaira52ab742016-09-29 13:59:29 -070014#include "core/fxcrt/fx_system.h"
Dan Sinclairaee0db02017-09-21 16:53:58 -040015#include "core/fxcrt/unowned_ptr.h"
dsinclair114e46a2016-09-29 17:18:21 -070016#include "fpdfsdk/cpdfsdk_annot.h"
Henrique Nakashima4a652542017-08-22 10:59:49 -040017#include "fpdfsdk/cpdfsdk_annothandlermgr.h"
dsinclairf34518b2016-09-13 12:03:48 -070018
19class CFX_RenderDevice;
20class CPDF_AnnotList;
21class CPDF_RenderOptions;
22
23class CPDFSDK_PageView final : public CPDF_Page::View {
24 public:
dsinclairb402b172016-10-11 09:26:32 -070025 CPDFSDK_PageView(CPDFSDK_FormFillEnvironment* pFormFillEnv,
26 UnderlyingPageType* page);
dsinclairf34518b2016-09-13 12:03:48 -070027 ~CPDFSDK_PageView();
28
29#ifdef PDF_ENABLE_XFA
30 void PageView_OnDraw(CFX_RenderDevice* pDevice,
31 CFX_Matrix* pUser2Device,
32 CPDF_RenderOptions* pOptions,
33 const FX_RECT& pClip);
34#else // PDF_ENABLE_XFA
35 void PageView_OnDraw(CFX_RenderDevice* pDevice,
36 CFX_Matrix* pUser2Device,
37 CPDF_RenderOptions* pOptions);
38#endif // PDF_ENABLE_XFA
39
dsinclair8afe15a2016-10-05 12:00:34 -070040 void LoadFXAnnots();
dsinclairf34518b2016-09-13 12:03:48 -070041 CPDFSDK_Annot* GetFocusAnnot();
dsinclair8afe15a2016-10-05 12:00:34 -070042 bool IsValidAnnot(const CPDF_Annot* p) const;
43 bool IsValidSDKAnnot(const CPDFSDK_Annot* p) const;
dsinclairf34518b2016-09-13 12:03:48 -070044
dsinclair8afe15a2016-10-05 12:00:34 -070045 const std::vector<CPDFSDK_Annot*>& GetAnnotList() const {
46 return m_SDKAnnotArray;
47 }
dsinclairf34518b2016-09-13 12:03:48 -070048 CPDFSDK_Annot* GetAnnotByDict(CPDF_Dictionary* pDict);
49
50#ifdef PDF_ENABLE_XFA
tsepez4cf55152016-11-02 14:37:54 -070051 bool DeleteAnnot(CPDFSDK_Annot* pAnnot);
dsinclairf34518b2016-09-13 12:03:48 -070052 CPDFSDK_Annot* AddAnnot(CXFA_FFWidget* pPDFAnnot);
53 CPDFSDK_Annot* GetAnnotByXFAWidget(CXFA_FFWidget* hWidget);
dsinclair8afe15a2016-10-05 12:00:34 -070054
dsinclairf34518b2016-09-13 12:03:48 -070055 CPDFXFA_Page* GetPDFXFAPage() { return m_page; }
56#endif // PDF_ENABLE_XFA
57
58 CPDF_Page* GetPDFPage() const;
59 CPDF_Document* GetPDFDocument();
Tom Sepezcc205132017-05-16 14:01:47 -070060 CPDFSDK_FormFillEnvironment* GetFormFillEnv() const {
61 return m_pFormFillEnv.Get();
62 }
63
Lei Zhanga4c7ac42018-04-17 15:12:58 +000064 WideString GetFocusedFormText();
Ryan Harrison275e2602017-09-18 14:23:18 -040065 WideString GetSelectedText();
66 void ReplaceSelection(const WideString& text);
Diana Gagedce2d722017-06-20 11:17:11 -070067
Lei Zhang63b01262017-08-31 08:54:46 -070068 bool OnFocus(const CFX_PointF& point, uint32_t nFlag);
Dan Sinclairf528eee2017-02-14 11:52:07 -050069 bool OnLButtonDown(const CFX_PointF& point, uint32_t nFlag);
70 bool OnLButtonUp(const CFX_PointF& point, uint32_t nFlag);
dsinclairf34518b2016-09-13 12:03:48 -070071#ifdef PDF_ENABLE_XFA
Dan Sinclairf528eee2017-02-14 11:52:07 -050072 bool OnRButtonDown(const CFX_PointF& point, uint32_t nFlag);
73 bool OnRButtonUp(const CFX_PointF& point, uint32_t nFlag);
dsinclairf34518b2016-09-13 12:03:48 -070074#endif // PDF_ENABLE_XFA
tsepez4cf55152016-11-02 14:37:54 -070075 bool OnChar(int nChar, uint32_t nFlag);
76 bool OnKeyDown(int nKeyCode, int nFlag);
77 bool OnKeyUp(int nKeyCode, int nFlag);
dsinclairf34518b2016-09-13 12:03:48 -070078
Dan Sinclairf528eee2017-02-14 11:52:07 -050079 bool OnMouseMove(const CFX_PointF& point, int nFlag);
tsepez4cf55152016-11-02 14:37:54 -070080 bool OnMouseWheel(double deltaX,
81 double deltaY,
Dan Sinclairf528eee2017-02-14 11:52:07 -050082 const CFX_PointF& point,
tsepez4cf55152016-11-02 14:37:54 -070083 int nFlag);
dsinclair8afe15a2016-10-05 12:00:34 -070084
dsinclairf34518b2016-09-13 12:03:48 -070085 void GetCurrentMatrix(CFX_Matrix& matrix) { matrix = m_curMatrix; }
86 void UpdateRects(const std::vector<CFX_FloatRect>& rects);
87 void UpdateView(CPDFSDK_Annot* pAnnot);
dsinclairf34518b2016-09-13 12:03:48 -070088
89 int GetPageIndex() const;
dsinclaire5393582016-10-03 11:25:00 -070090
tsepez4cf55152016-11-02 14:37:54 -070091 void SetValid(bool bValid) { m_bValid = bValid; }
92 bool IsValid() { return m_bValid; }
dsinclaire5393582016-10-03 11:25:00 -070093
tsepez4cf55152016-11-02 14:37:54 -070094 bool IsLocked() { return m_bLocked; }
dsinclairbcf46232016-10-03 13:02:27 -070095
96 void SetBeingDestroyed() { m_bBeingDestroyed = true; }
97 bool IsBeingDestroyed() const { return m_bBeingDestroyed; }
98
dsinclairf34518b2016-09-13 12:03:48 -070099#ifndef PDF_ENABLE_XFA
100 bool OwnsPage() const { return m_bOwnsPage; }
101 void TakePageOwnership() { m_bOwnsPage = true; }
102#endif // PDF_ENABLE_XFA
103
104 private:
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500105 CPDFSDK_Annot* GetFXAnnotAtPoint(const CFX_PointF& point);
106 CPDFSDK_Annot* GetFXWidgetAtPoint(const CFX_PointF& point);
107
dsinclairf34518b2016-09-13 12:03:48 -0700108 int GetPageIndexForStaticPDF() const;
109
Henrique Nakashima4a652542017-08-22 10:59:49 -0400110 void EnterWidget(CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr,
111 CPDFSDK_Annot::ObservedPtr* pAnnot,
112 uint32_t nFlag);
113 void ExitWidget(CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr,
114 bool callExitCallback,
115 uint32_t nFlag);
116
dsinclairf34518b2016-09-13 12:03:48 -0700117 CFX_Matrix m_curMatrix;
118 UnderlyingPageType* const m_page;
119 std::unique_ptr<CPDF_AnnotList> m_pAnnotList;
dsinclair8afe15a2016-10-05 12:00:34 -0700120 std::vector<CPDFSDK_Annot*> m_SDKAnnotArray;
Dan Sinclairaee0db02017-09-21 16:53:58 -0400121 UnownedPtr<CPDFSDK_FormFillEnvironment> const m_pFormFillEnv;
tsepezf8074ce2016-09-27 14:29:57 -0700122 CPDFSDK_Annot::ObservedPtr m_pCaptureWidget;
dsinclairf34518b2016-09-13 12:03:48 -0700123#ifndef PDF_ENABLE_XFA
124 bool m_bOwnsPage;
125#endif // PDF_ENABLE_XFA
tsepez4cf55152016-11-02 14:37:54 -0700126 bool m_bOnWidget;
127 bool m_bValid;
128 bool m_bLocked;
dsinclairbcf46232016-10-03 13:02:27 -0700129 bool m_bBeingDestroyed;
dsinclairf34518b2016-09-13 12:03:48 -0700130};
131
dsinclair114e46a2016-09-29 17:18:21 -0700132#endif // FPDFSDK_CPDFSDK_PAGEVIEW_H_