blob: 03f3ab6318a4f92c531c4eee17f6ab2708e591ea [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
Ryan Harrison275e2602017-09-18 14:23:18 -040064 WideString GetSelectedText();
65 void ReplaceSelection(const WideString& text);
Diana Gagedce2d722017-06-20 11:17:11 -070066
Lei Zhang63b01262017-08-31 08:54:46 -070067 bool OnFocus(const CFX_PointF& point, uint32_t nFlag);
Dan Sinclairf528eee2017-02-14 11:52:07 -050068 bool OnLButtonDown(const CFX_PointF& point, uint32_t nFlag);
69 bool OnLButtonUp(const CFX_PointF& point, uint32_t nFlag);
dsinclairf34518b2016-09-13 12:03:48 -070070#ifdef PDF_ENABLE_XFA
Dan Sinclairf528eee2017-02-14 11:52:07 -050071 bool OnRButtonDown(const CFX_PointF& point, uint32_t nFlag);
72 bool OnRButtonUp(const CFX_PointF& point, uint32_t nFlag);
dsinclairf34518b2016-09-13 12:03:48 -070073#endif // PDF_ENABLE_XFA
tsepez4cf55152016-11-02 14:37:54 -070074 bool OnChar(int nChar, uint32_t nFlag);
75 bool OnKeyDown(int nKeyCode, int nFlag);
76 bool OnKeyUp(int nKeyCode, int nFlag);
dsinclairf34518b2016-09-13 12:03:48 -070077
Dan Sinclairf528eee2017-02-14 11:52:07 -050078 bool OnMouseMove(const CFX_PointF& point, int nFlag);
tsepez4cf55152016-11-02 14:37:54 -070079 bool OnMouseWheel(double deltaX,
80 double deltaY,
Dan Sinclairf528eee2017-02-14 11:52:07 -050081 const CFX_PointF& point,
tsepez4cf55152016-11-02 14:37:54 -070082 int nFlag);
dsinclair8afe15a2016-10-05 12:00:34 -070083
dsinclairf34518b2016-09-13 12:03:48 -070084 void GetCurrentMatrix(CFX_Matrix& matrix) { matrix = m_curMatrix; }
85 void UpdateRects(const std::vector<CFX_FloatRect>& rects);
86 void UpdateView(CPDFSDK_Annot* pAnnot);
dsinclairf34518b2016-09-13 12:03:48 -070087
88 int GetPageIndex() const;
dsinclaire5393582016-10-03 11:25:00 -070089
tsepez4cf55152016-11-02 14:37:54 -070090 void SetValid(bool bValid) { m_bValid = bValid; }
91 bool IsValid() { return m_bValid; }
dsinclaire5393582016-10-03 11:25:00 -070092
tsepez4cf55152016-11-02 14:37:54 -070093 bool IsLocked() { return m_bLocked; }
dsinclairbcf46232016-10-03 13:02:27 -070094
95 void SetBeingDestroyed() { m_bBeingDestroyed = true; }
96 bool IsBeingDestroyed() const { return m_bBeingDestroyed; }
97
dsinclairf34518b2016-09-13 12:03:48 -070098#ifndef PDF_ENABLE_XFA
99 bool OwnsPage() const { return m_bOwnsPage; }
100 void TakePageOwnership() { m_bOwnsPage = true; }
101#endif // PDF_ENABLE_XFA
102
103 private:
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500104 CPDFSDK_Annot* GetFXAnnotAtPoint(const CFX_PointF& point);
105 CPDFSDK_Annot* GetFXWidgetAtPoint(const CFX_PointF& point);
106
dsinclairf34518b2016-09-13 12:03:48 -0700107 int GetPageIndexForStaticPDF() const;
108
Henrique Nakashima4a652542017-08-22 10:59:49 -0400109 void EnterWidget(CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr,
110 CPDFSDK_Annot::ObservedPtr* pAnnot,
111 uint32_t nFlag);
112 void ExitWidget(CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr,
113 bool callExitCallback,
114 uint32_t nFlag);
115
dsinclairf34518b2016-09-13 12:03:48 -0700116 CFX_Matrix m_curMatrix;
117 UnderlyingPageType* const m_page;
118 std::unique_ptr<CPDF_AnnotList> m_pAnnotList;
dsinclair8afe15a2016-10-05 12:00:34 -0700119 std::vector<CPDFSDK_Annot*> m_SDKAnnotArray;
Dan Sinclairaee0db02017-09-21 16:53:58 -0400120 UnownedPtr<CPDFSDK_FormFillEnvironment> const m_pFormFillEnv;
tsepezf8074ce2016-09-27 14:29:57 -0700121 CPDFSDK_Annot::ObservedPtr m_pCaptureWidget;
dsinclairf34518b2016-09-13 12:03:48 -0700122#ifndef PDF_ENABLE_XFA
123 bool m_bOwnsPage;
124#endif // PDF_ENABLE_XFA
tsepez4cf55152016-11-02 14:37:54 -0700125 bool m_bOnWidget;
126 bool m_bValid;
127 bool m_bLocked;
dsinclairbcf46232016-10-03 13:02:27 -0700128 bool m_bBeingDestroyed;
dsinclairf34518b2016-09-13 12:03:48 -0700129};
130
dsinclair114e46a2016-09-29 17:18:21 -0700131#endif // FPDFSDK_CPDFSDK_PAGEVIEW_H_