cpdfsdk_pageview.h revision 4d3acf4ec42bf6e838f9060103aff98fbf170794
1// 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
7#ifndef FPDFSDK_CPDFSDK_PAGEVIEW_H_
8#define FPDFSDK_CPDFSDK_PAGEVIEW_H_
9
10#include <memory>
11#include <vector>
12
13#include "core/fpdfapi/page/cpdf_page.h"
14#include "core/fxcrt/fx_system.h"
15#include "fpdfsdk/cpdfsdk_annot.h"
16
17class CFX_RenderDevice;
18class CPDF_AnnotList;
19class CPDF_RenderOptions;
20
21class CPDFSDK_PageView final : public CPDF_Page::View {
22 public:
23  CPDFSDK_PageView(CPDFSDK_FormFillEnvironment* pFormFillEnv,
24                   UnderlyingPageType* page);
25  ~CPDFSDK_PageView();
26
27#ifdef PDF_ENABLE_XFA
28  void PageView_OnDraw(CFX_RenderDevice* pDevice,
29                       CFX_Matrix* pUser2Device,
30                       CPDF_RenderOptions* pOptions,
31                       const FX_RECT& pClip);
32#else   // PDF_ENABLE_XFA
33  void PageView_OnDraw(CFX_RenderDevice* pDevice,
34                       CFX_Matrix* pUser2Device,
35                       CPDF_RenderOptions* pOptions);
36#endif  // PDF_ENABLE_XFA
37
38  CPDFSDK_Annot* GetFXAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
39  CPDFSDK_Annot* GetFXWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
40
41  void LoadFXAnnots();
42  CPDFSDK_Annot* GetFocusAnnot();
43  bool IsValidAnnot(const CPDF_Annot* p) const;
44  bool IsValidSDKAnnot(const CPDFSDK_Annot* p) const;
45
46  const std::vector<CPDFSDK_Annot*>& GetAnnotList() const {
47    return m_SDKAnnotArray;
48  }
49  CPDFSDK_Annot* GetAnnotByDict(CPDF_Dictionary* pDict);
50
51#ifdef PDF_ENABLE_XFA
52  bool DeleteAnnot(CPDFSDK_Annot* pAnnot);
53  CPDFSDK_Annot* AddAnnot(CXFA_FFWidget* pPDFAnnot);
54  CPDFSDK_Annot* GetAnnotByXFAWidget(CXFA_FFWidget* hWidget);
55
56  CPDFXFA_Page* GetPDFXFAPage() { return m_page; }
57#endif  // PDF_ENABLE_XFA
58
59  CPDF_Page* GetPDFPage() const;
60  CPDF_Document* GetPDFDocument();
61  CPDFSDK_FormFillEnvironment* GetFormFillEnv() const { return m_pFormFillEnv; }
62  bool OnLButtonDown(const CFX_FloatPoint& point, uint32_t nFlag);
63  bool OnLButtonUp(const CFX_FloatPoint& point, uint32_t nFlag);
64#ifdef PDF_ENABLE_XFA
65  bool OnRButtonDown(const CFX_FloatPoint& point, uint32_t nFlag);
66  bool OnRButtonUp(const CFX_FloatPoint& point, uint32_t nFlag);
67#endif  // PDF_ENABLE_XFA
68  bool OnChar(int nChar, uint32_t nFlag);
69  bool OnKeyDown(int nKeyCode, int nFlag);
70  bool OnKeyUp(int nKeyCode, int nFlag);
71
72  bool OnMouseMove(const CFX_FloatPoint& point, int nFlag);
73  bool OnMouseWheel(double deltaX,
74                    double deltaY,
75                    const CFX_FloatPoint& point,
76                    int nFlag);
77
78  void GetCurrentMatrix(CFX_Matrix& matrix) { matrix = m_curMatrix; }
79  void UpdateRects(const std::vector<CFX_FloatRect>& rects);
80  void UpdateView(CPDFSDK_Annot* pAnnot);
81
82  int GetPageIndex() const;
83
84  void SetValid(bool bValid) { m_bValid = bValid; }
85  bool IsValid() { return m_bValid; }
86
87  void SetLock(bool bLocked) { m_bLocked = bLocked; }
88  bool IsLocked() { return m_bLocked; }
89
90  void SetBeingDestroyed() { m_bBeingDestroyed = true; }
91  bool IsBeingDestroyed() const { return m_bBeingDestroyed; }
92
93#ifndef PDF_ENABLE_XFA
94  bool OwnsPage() const { return m_bOwnsPage; }
95  void TakePageOwnership() { m_bOwnsPage = true; }
96#endif  // PDF_ENABLE_XFA
97
98 private:
99  int GetPageIndexForStaticPDF() const;
100
101  CFX_Matrix m_curMatrix;
102  UnderlyingPageType* const m_page;
103  std::unique_ptr<CPDF_AnnotList> m_pAnnotList;
104  std::vector<CPDFSDK_Annot*> m_SDKAnnotArray;
105  CPDFSDK_FormFillEnvironment* const m_pFormFillEnv;  // Not owned.
106  CPDFSDK_Annot::ObservedPtr m_pCaptureWidget;
107#ifndef PDF_ENABLE_XFA
108  bool m_bOwnsPage;
109#endif  // PDF_ENABLE_XFA
110  bool m_bEnterWidget;
111  bool m_bExitWidget;
112  bool m_bOnWidget;
113  bool m_bValid;
114  bool m_bLocked;
115  bool m_bBeingDestroyed;
116};
117
118#endif  // FPDFSDK_CPDFSDK_PAGEVIEW_H_
119