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 "core/fxcrt/unowned_ptr.h" 16 #include "fpdfsdk/cpdfsdk_annot.h" 17 #include "fpdfsdk/cpdfsdk_annothandlermgr.h" 18 19 class CFX_RenderDevice; 20 class CPDF_AnnotList; 21 class CPDF_RenderOptions; 22 23 class CPDFSDK_PageView final : public CPDF_Page::View { 24 public: 25 CPDFSDK_PageView(CPDFSDK_FormFillEnvironment* pFormFillEnv, 26 UnderlyingPageType* page); 27 ~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 40 void LoadFXAnnots(); 41 CPDFSDK_Annot* GetFocusAnnot(); 42 bool IsValidAnnot(const CPDF_Annot* p) const; 43 bool IsValidSDKAnnot(const CPDFSDK_Annot* p) const; 44 GetAnnotList()45 const std::vector<CPDFSDK_Annot*>& GetAnnotList() const { 46 return m_SDKAnnotArray; 47 } 48 CPDFSDK_Annot* GetAnnotByDict(CPDF_Dictionary* pDict); 49 50 #ifdef PDF_ENABLE_XFA 51 bool DeleteAnnot(CPDFSDK_Annot* pAnnot); 52 CPDFSDK_Annot* AddAnnot(CXFA_FFWidget* pPDFAnnot); 53 CPDFSDK_Annot* GetAnnotByXFAWidget(CXFA_FFWidget* hWidget); 54 GetPDFXFAPage()55 CPDFXFA_Page* GetPDFXFAPage() { return m_page; } 56 #endif // PDF_ENABLE_XFA 57 58 CPDF_Page* GetPDFPage() const; 59 CPDF_Document* GetPDFDocument(); GetFormFillEnv()60 CPDFSDK_FormFillEnvironment* GetFormFillEnv() const { 61 return m_pFormFillEnv.Get(); 62 } 63 64 WideString GetSelectedText(); 65 void ReplaceSelection(const WideString& text); 66 67 bool OnFocus(const CFX_PointF& point, uint32_t nFlag); 68 bool OnLButtonDown(const CFX_PointF& point, uint32_t nFlag); 69 bool OnLButtonUp(const CFX_PointF& point, uint32_t nFlag); 70 #ifdef PDF_ENABLE_XFA 71 bool OnRButtonDown(const CFX_PointF& point, uint32_t nFlag); 72 bool OnRButtonUp(const CFX_PointF& point, uint32_t nFlag); 73 #endif // PDF_ENABLE_XFA 74 bool OnChar(int nChar, uint32_t nFlag); 75 bool OnKeyDown(int nKeyCode, int nFlag); 76 bool OnKeyUp(int nKeyCode, int nFlag); 77 78 bool OnMouseMove(const CFX_PointF& point, int nFlag); 79 bool OnMouseWheel(double deltaX, 80 double deltaY, 81 const CFX_PointF& point, 82 int nFlag); 83 GetCurrentMatrix(CFX_Matrix & matrix)84 void GetCurrentMatrix(CFX_Matrix& matrix) { matrix = m_curMatrix; } 85 void UpdateRects(const std::vector<CFX_FloatRect>& rects); 86 void UpdateView(CPDFSDK_Annot* pAnnot); 87 88 int GetPageIndex() const; 89 SetValid(bool bValid)90 void SetValid(bool bValid) { m_bValid = bValid; } IsValid()91 bool IsValid() { return m_bValid; } 92 IsLocked()93 bool IsLocked() { return m_bLocked; } 94 SetBeingDestroyed()95 void SetBeingDestroyed() { m_bBeingDestroyed = true; } IsBeingDestroyed()96 bool IsBeingDestroyed() const { return m_bBeingDestroyed; } 97 98 #ifndef PDF_ENABLE_XFA OwnsPage()99 bool OwnsPage() const { return m_bOwnsPage; } TakePageOwnership()100 void TakePageOwnership() { m_bOwnsPage = true; } 101 #endif // PDF_ENABLE_XFA 102 103 private: 104 CPDFSDK_Annot* GetFXAnnotAtPoint(const CFX_PointF& point); 105 CPDFSDK_Annot* GetFXWidgetAtPoint(const CFX_PointF& point); 106 107 int GetPageIndexForStaticPDF() const; 108 109 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 116 CFX_Matrix m_curMatrix; 117 UnderlyingPageType* const m_page; 118 std::unique_ptr<CPDF_AnnotList> m_pAnnotList; 119 std::vector<CPDFSDK_Annot*> m_SDKAnnotArray; 120 UnownedPtr<CPDFSDK_FormFillEnvironment> const m_pFormFillEnv; 121 CPDFSDK_Annot::ObservedPtr m_pCaptureWidget; 122 #ifndef PDF_ENABLE_XFA 123 bool m_bOwnsPage; 124 #endif // PDF_ENABLE_XFA 125 bool m_bOnWidget; 126 bool m_bValid; 127 bool m_bLocked; 128 bool m_bBeingDestroyed; 129 }; 130 131 #endif // FPDFSDK_CPDFSDK_PAGEVIEW_H_ 132