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