1 // Copyright 2014 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_FORMFILLER_CFFL_FORMFILLER_H_ 8 #define FPDFSDK_FORMFILLER_CFFL_FORMFILLER_H_ 9 10 #include <map> 11 #include <memory> 12 13 #include "core/fxcrt/cfx_timer.h" 14 #include "core/fxcrt/unowned_ptr.h" 15 #include "fpdfsdk/cpdfsdk_fieldaction.h" 16 #include "fpdfsdk/cpdfsdk_widget.h" 17 #include "fpdfsdk/formfiller/cffl_interactiveformfiller.h" 18 #include "fpdfsdk/pwl/cpwl_wnd.h" 19 #include "fpdfsdk/pwl/ipwl_systemhandler.h" 20 21 class CPDFSDK_Annot; 22 class CPDFSDK_FormFillEnvironment; 23 class CPDFSDK_PageView; 24 25 class CFFL_FormFiller : public CPWL_Wnd::ProviderIface, 26 public CFX_Timer::CallbackIface { 27 public: 28 CFFL_FormFiller(CPDFSDK_FormFillEnvironment* pFormFillEnv, 29 CPDFSDK_Widget* pWidget); 30 ~CFFL_FormFiller() override; 31 32 virtual void OnDraw(CPDFSDK_PageView* pPageView, 33 CPDFSDK_Annot* pAnnot, 34 CFX_RenderDevice* pDevice, 35 const CFX_Matrix& mtUser2Device); 36 virtual void OnDrawDeactive(CPDFSDK_PageView* pPageView, 37 CPDFSDK_Annot* pAnnot, 38 CFX_RenderDevice* pDevice, 39 const CFX_Matrix& mtUser2Device); 40 41 virtual void OnMouseEnter(CPDFSDK_PageView* pPageView); 42 virtual void OnMouseExit(CPDFSDK_PageView* pPageView); 43 44 virtual bool OnLButtonDown(CPDFSDK_PageView* pPageView, 45 CPDFSDK_Annot* pAnnot, 46 uint32_t nFlags, 47 const CFX_PointF& point); 48 virtual bool OnLButtonUp(CPDFSDK_PageView* pPageView, 49 CPDFSDK_Annot* pAnnot, 50 uint32_t nFlags, 51 const CFX_PointF& point); 52 virtual bool OnLButtonDblClk(CPDFSDK_PageView* pPageView, 53 uint32_t nFlags, 54 const CFX_PointF& point); 55 virtual bool OnMouseMove(CPDFSDK_PageView* pPageView, 56 uint32_t nFlags, 57 const CFX_PointF& point); 58 virtual bool OnMouseWheel(CPDFSDK_PageView* pPageView, 59 uint32_t nFlags, 60 short zDelta, 61 const CFX_PointF& point); 62 virtual bool OnRButtonDown(CPDFSDK_PageView* pPageView, 63 uint32_t nFlags, 64 const CFX_PointF& point); 65 virtual bool OnRButtonUp(CPDFSDK_PageView* pPageView, 66 uint32_t nFlags, 67 const CFX_PointF& point); 68 69 virtual bool OnKeyDown(uint32_t nKeyCode, uint32_t nFlags); 70 virtual bool OnChar(CPDFSDK_Annot* pAnnot, uint32_t nChar, uint32_t nFlags); 71 virtual bool SetIndexSelected(int index, bool selected); 72 virtual bool IsIndexSelected(int index); 73 74 FX_RECT GetViewBBox(CPDFSDK_PageView* pPageView); 75 76 WideString GetText(); 77 WideString GetSelectedText(); 78 void ReplaceSelection(const WideString& text); 79 80 bool CanUndo(); 81 bool CanRedo(); 82 bool Undo(); 83 bool Redo(); 84 85 void SetFocusForAnnot(CPDFSDK_Annot* pAnnot, uint32_t nFlag); 86 void KillFocusForAnnot(uint32_t nFlag); 87 88 // CFX_Timer::CallbackIface: 89 void OnTimerFired() override; 90 91 // CPWL_Wnd::ProviderIface: 92 CFX_Matrix GetWindowMatrix( 93 const IPWL_SystemHandler::PerWindowData* pAttached) override; 94 95 virtual void GetActionData(CPDFSDK_PageView* pPageView, 96 CPDF_AAction::AActionType type, 97 CPDFSDK_FieldAction& fa); 98 virtual void SetActionData(CPDFSDK_PageView* pPageView, 99 CPDF_AAction::AActionType type, 100 const CPDFSDK_FieldAction& fa); 101 virtual CPWL_Wnd::CreateParams GetCreateParam(); 102 virtual std::unique_ptr<CPWL_Wnd> NewPWLWindow( 103 const CPWL_Wnd::CreateParams& cp, 104 std::unique_ptr<IPWL_SystemHandler::PerWindowData> pAttachedData) = 0; 105 virtual CPWL_Wnd* ResetPWLWindow(CPDFSDK_PageView* pPageView, 106 bool bRestoreValue); 107 virtual void SaveState(CPDFSDK_PageView* pPageView); 108 virtual void RestoreState(CPDFSDK_PageView* pPageView); 109 110 CFX_Matrix GetCurMatrix(); 111 CFX_FloatRect GetFocusBox(CPDFSDK_PageView* pPageView); 112 CFX_FloatRect FFLtoPWL(const CFX_FloatRect& rect); 113 CFX_FloatRect PWLtoFFL(const CFX_FloatRect& rect); 114 CFX_PointF FFLtoPWL(const CFX_PointF& point); 115 CFX_PointF PWLtoFFL(const CFX_PointF& point); 116 CFX_PointF WndtoPWL(const CFX_PointF& pt); 117 CFX_FloatRect FFLtoWnd(const CFX_FloatRect& rect); 118 119 bool CommitData(CPDFSDK_PageView* pPageView, uint32_t nFlag); 120 virtual bool IsDataChanged(CPDFSDK_PageView* pPageView); 121 virtual void SaveData(CPDFSDK_PageView* pPageView); 122 123 #ifdef PDF_ENABLE_XFA 124 virtual bool IsFieldFull(CPDFSDK_PageView* pPageView); 125 #endif // PDF_ENABLE_XFA 126 127 CPWL_Wnd* GetPWLWindow(CPDFSDK_PageView* pPageView, bool bNew); 128 void DestroyPWLWindow(CPDFSDK_PageView* pPageView); 129 void EscapeFiller(CPDFSDK_PageView* pPageView, bool bDestroyPWLWindow); 130 131 bool IsValid() const; 132 CFX_FloatRect GetPDFAnnotRect() const; 133 134 CPDFSDK_PageView* GetCurPageView(bool renew); 135 void SetChangeMark(); 136 GetSDKAnnot()137 CPDFSDK_Annot* GetSDKAnnot() const { return m_pWidget.Get(); } 138 139 protected: 140 // If the inheriting widget has its own fontmap and a PWL_Edit widget that 141 // access that fontmap then you have to call DestroyWindows before destroying 142 // the font map in order to not get a use-after-free. 143 // 144 // The font map should be stored somewhere more appropriate so it will live 145 // until the PWL_Edit is done with it. pdfium:566 146 void DestroyWindows(); 147 148 void InvalidateRect(const FX_RECT& rect); 149 150 bool m_bValid = false; 151 UnownedPtr<CPDFSDK_FormFillEnvironment> const m_pFormFillEnv; 152 UnownedPtr<CPDFSDK_Widget> m_pWidget; 153 std::unique_ptr<CFX_Timer> m_pTimer; 154 std::map<CPDFSDK_PageView*, std::unique_ptr<CPWL_Wnd>> m_Maps; 155 }; 156 157 #endif // FPDFSDK_FORMFILLER_CFFL_FORMFILLER_H_ 158