1 // Copyright 2014 The PDFium Authors 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_BAANNOT_H_ 8 #define FPDFSDK_CPDFSDK_BAANNOT_H_ 9 10 #include "core/fpdfdoc/cpdf_aaction.h" 11 #include "core/fpdfdoc/cpdf_action.h" 12 #include "core/fpdfdoc/cpdf_annot.h" 13 #include "core/fxcrt/fx_coordinates.h" 14 #include "core/fxcrt/fx_string.h" 15 #include "core/fxcrt/unowned_ptr.h" 16 #include "core/fxge/cfx_renderdevice.h" 17 #include "fpdfsdk/cpdfsdk_annot.h" 18 19 class CFX_Matrix; 20 class CPDF_Dictionary; 21 class CPDFSDK_PageView; 22 23 class CPDFSDK_BAAnnot : public CPDFSDK_Annot, 24 CPDFSDK_Annot::UnsafeInputHandlers { 25 public: 26 CPDFSDK_BAAnnot(CPDF_Annot* pAnnot, CPDFSDK_PageView* pPageView); 27 ~CPDFSDK_BAAnnot() override; 28 29 // CPDFSDK_Annot: 30 CPDFSDK_BAAnnot* AsBAAnnot() override; 31 CPDFSDK_Annot::UnsafeInputHandlers* GetUnsafeInputHandlers() override; 32 CPDF_Annot::Subtype GetAnnotSubtype() const override; 33 CFX_FloatRect GetRect() const override; 34 CPDF_Annot* GetPDFAnnot() const override; 35 int GetLayoutOrder() const override; 36 void OnDraw(CFX_RenderDevice* pDevice, 37 const CFX_Matrix& mtUser2Device, 38 bool bDrawAnnots) override; 39 bool DoHitTest(const CFX_PointF& point) override; 40 CFX_FloatRect GetViewBBox() override; 41 bool CanUndo() override; 42 bool CanRedo() override; 43 bool Undo() override; 44 bool Redo() override; 45 WideString GetText() override; 46 WideString GetSelectedText() override; 47 void ReplaceAndKeepSelection(const WideString& text) override; 48 void ReplaceSelection(const WideString& text) override; 49 bool SelectAllText() override; 50 bool SetIndexSelected(int index, bool selected) override; 51 bool IsIndexSelected(int index) override; 52 53 virtual CPDF_Action GetAAction(CPDF_AAction::AActionType eAAT); 54 virtual bool IsAppearanceValid(); 55 virtual void DrawAppearance(CFX_RenderDevice* pDevice, 56 const CFX_Matrix& mtUser2Device, 57 CPDF_Annot::AppearanceMode mode); 58 59 void SetAnnotName(const WideString& sName); 60 WideString GetAnnotName() const; 61 62 void SetFlags(uint32_t nFlags); 63 uint32_t GetFlags() const; 64 65 void SetAppStateOff(); 66 ByteString GetAppState() const; 67 68 void SetBorderWidth(int nWidth); 69 int GetBorderWidth() const; 70 71 void SetBorderStyle(BorderStyle nStyle); 72 BorderStyle GetBorderStyle() const; 73 74 bool IsVisible() const; 75 76 CPDF_Action GetAction() const; 77 CPDF_AAction GetAAction() const; 78 CPDF_Dest GetDestination() const; 79 80 protected: 81 const CPDF_Dictionary* GetAnnotDict() const; 82 RetainPtr<CPDF_Dictionary> GetMutableAnnotDict(); 83 RetainPtr<CPDF_Dictionary> GetAPDict(); 84 void ClearCachedAnnotAP(); 85 bool IsFocusableAnnot(const CPDF_Annot::Subtype& annot_type) const; 86 87 private: 88 // CPDFSDK_Annot::UnsafeInputHandlers: 89 void OnMouseEnter(Mask<FWL_EVENTFLAG> nFlags) override; 90 void OnMouseExit(Mask<FWL_EVENTFLAG> nFlags) override; 91 bool OnLButtonDown(Mask<FWL_EVENTFLAG> nFlags, 92 const CFX_PointF& point) override; 93 bool OnLButtonUp(Mask<FWL_EVENTFLAG> nFlags, 94 const CFX_PointF& point) override; 95 bool OnLButtonDblClk(Mask<FWL_EVENTFLAG> nFlags, 96 const CFX_PointF& point) override; 97 bool OnMouseMove(Mask<FWL_EVENTFLAG> nFlags, 98 const CFX_PointF& point) override; 99 bool OnMouseWheel(Mask<FWL_EVENTFLAG> nFlags, 100 const CFX_PointF& point, 101 const CFX_Vector& delta) override; 102 bool OnRButtonDown(Mask<FWL_EVENTFLAG> nFlags, 103 const CFX_PointF& point) override; 104 bool OnRButtonUp(Mask<FWL_EVENTFLAG> nFlags, 105 const CFX_PointF& point) override; 106 bool OnChar(uint32_t nChar, Mask<FWL_EVENTFLAG> nFlags) override; 107 bool OnKeyDown(FWL_VKEYCODE nKeyCode, Mask<FWL_EVENTFLAG> nFlags) override; 108 bool OnSetFocus(Mask<FWL_EVENTFLAG> nFlags) override; 109 bool OnKillFocus(Mask<FWL_EVENTFLAG> nFlags) override; 110 111 void SetOpenState(bool bOpenState); 112 void UpdateAnnotRects(); 113 void InvalidateRect(); 114 115 bool is_focused_ = false; 116 UnownedPtr<CPDF_Annot> const m_pAnnot; 117 }; 118 119 #endif // FPDFSDK_CPDFSDK_BAANNOT_H_ 120