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 12 #include "fpdfsdk/formfiller/cba_fontmap.h" 13 #include "fpdfsdk/formfiller/cffl_interactiveformfiller.h" 14 #include "fpdfsdk/pdfsdk_fieldaction.h" 15 16 class CPDFSDK_Annot; 17 class CPDFSDK_FormFillEnvironment; 18 class CPDFSDK_PageView; 19 class CPDFSDK_Widget; 20 21 class CFFL_FormFiller : public IPWL_Provider, public CPWL_TimerHandler { 22 public: 23 CFFL_FormFiller(CPDFSDK_FormFillEnvironment* pFormFillEnv, 24 CPDFSDK_Annot* pAnnot); 25 ~CFFL_FormFiller() override; 26 27 virtual FX_RECT GetViewBBox(CPDFSDK_PageView* pPageView, 28 CPDFSDK_Annot* pAnnot); 29 virtual void OnDraw(CPDFSDK_PageView* pPageView, 30 CPDFSDK_Annot* pAnnot, 31 CFX_RenderDevice* pDevice, 32 CFX_Matrix* pUser2Device); 33 virtual void OnDrawDeactive(CPDFSDK_PageView* pPageView, 34 CPDFSDK_Annot* pAnnot, 35 CFX_RenderDevice* pDevice, 36 CFX_Matrix* pUser2Device); 37 38 virtual void OnMouseEnter(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot); 39 virtual void OnMouseExit(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot); 40 41 virtual bool OnLButtonDown(CPDFSDK_PageView* pPageView, 42 CPDFSDK_Annot* pAnnot, 43 uint32_t nFlags, 44 const CFX_PointF& point); 45 virtual bool OnLButtonUp(CPDFSDK_PageView* pPageView, 46 CPDFSDK_Annot* pAnnot, 47 uint32_t nFlags, 48 const CFX_PointF& point); 49 virtual bool OnLButtonDblClk(CPDFSDK_PageView* pPageView, 50 CPDFSDK_Annot* pAnnot, 51 uint32_t nFlags, 52 const CFX_PointF& point); 53 virtual bool OnMouseMove(CPDFSDK_PageView* pPageView, 54 CPDFSDK_Annot* pAnnot, 55 uint32_t nFlags, 56 const CFX_PointF& point); 57 virtual bool OnMouseWheel(CPDFSDK_PageView* pPageView, 58 CPDFSDK_Annot* pAnnot, 59 uint32_t nFlags, 60 short zDelta, 61 const CFX_PointF& point); 62 virtual bool OnRButtonDown(CPDFSDK_PageView* pPageView, 63 CPDFSDK_Annot* pAnnot, 64 uint32_t nFlags, 65 const CFX_PointF& point); 66 virtual bool OnRButtonUp(CPDFSDK_PageView* pPageView, 67 CPDFSDK_Annot* pAnnot, 68 uint32_t nFlags, 69 const CFX_PointF& point); 70 71 virtual bool OnKeyDown(CPDFSDK_Annot* pAnnot, 72 uint32_t nKeyCode, 73 uint32_t nFlags); 74 virtual bool OnChar(CPDFSDK_Annot* pAnnot, uint32_t nChar, uint32_t nFlags); 75 76 void SetFocusForAnnot(CPDFSDK_Annot* pAnnot, uint32_t nFlag); 77 void KillFocusForAnnot(CPDFSDK_Annot* pAnnot, uint32_t nFlag); 78 79 // CPWL_TimerHandler 80 void TimerProc() override; 81 CFX_SystemHandler* GetSystemHandler() const override; 82 83 // IPWL_Provider 84 CFX_Matrix GetWindowMatrix(void* pAttachedData) override; 85 CFX_WideString LoadPopupMenuString(int nIndex) override; 86 87 virtual void GetActionData(CPDFSDK_PageView* pPageView, 88 CPDF_AAction::AActionType type, 89 PDFSDK_FieldAction& fa); 90 virtual void SetActionData(CPDFSDK_PageView* pPageView, 91 CPDF_AAction::AActionType type, 92 const PDFSDK_FieldAction& fa); 93 virtual bool IsActionDataChanged(CPDF_AAction::AActionType type, 94 const PDFSDK_FieldAction& faOld, 95 const PDFSDK_FieldAction& faNew); 96 97 virtual void SaveState(CPDFSDK_PageView* pPageView); 98 virtual void RestoreState(CPDFSDK_PageView* pPageView); 99 100 virtual CPWL_Wnd* ResetPDFWindow(CPDFSDK_PageView* pPageView, 101 bool bRestoreValue); 102 103 CFX_Matrix GetCurMatrix(); 104 105 CFX_FloatRect FFLtoPWL(const CFX_FloatRect& rect); 106 CFX_FloatRect PWLtoFFL(const CFX_FloatRect& rect); 107 CFX_PointF FFLtoPWL(const CFX_PointF& point); 108 CFX_PointF PWLtoFFL(const CFX_PointF& point); 109 110 CFX_PointF WndtoPWL(CPDFSDK_PageView* pPageView, const CFX_PointF& pt); 111 CFX_FloatRect FFLtoWnd(CPDFSDK_PageView* pPageView, 112 const CFX_FloatRect& rect); 113 114 void SetWindowRect(CPDFSDK_PageView* pPageView, 115 const CFX_FloatRect& rcWindow); 116 CFX_FloatRect GetWindowRect(CPDFSDK_PageView* pPageView); 117 118 bool CommitData(CPDFSDK_PageView* pPageView, uint32_t nFlag); 119 virtual bool IsDataChanged(CPDFSDK_PageView* pPageView); 120 virtual void SaveData(CPDFSDK_PageView* pPageView); 121 122 #ifdef PDF_ENABLE_XFA 123 virtual bool IsFieldFull(CPDFSDK_PageView* pPageView); 124 #endif // PDF_ENABLE_XFA 125 126 CPWL_Wnd* GetPDFWindow(CPDFSDK_PageView* pPageView, bool bNew); 127 void DestroyPDFWindow(CPDFSDK_PageView* pPageView); 128 void EscapeFiller(CPDFSDK_PageView* pPageView, bool bDestroyPDFWindow); 129 130 virtual PWL_CREATEPARAM GetCreateParam(); 131 virtual CPWL_Wnd* NewPDFWindow(const PWL_CREATEPARAM& cp, 132 CPDFSDK_PageView* pPageView) = 0; 133 virtual CFX_FloatRect GetFocusBox(CPDFSDK_PageView* pPageView); 134 135 bool IsValid() const; 136 CFX_FloatRect GetPDFWindowRect() const; 137 138 CPDFSDK_PageView* GetCurPageView(bool renew); 139 void SetChangeMark(); 140 141 virtual void InvalidateRect(const FX_RECT& rect); GetSDKAnnot()142 CPDFSDK_Annot* GetSDKAnnot() { return m_pAnnot; } 143 144 protected: 145 using CFFL_PageView2PDFWindow = std::map<CPDFSDK_PageView*, CPWL_Wnd*>; 146 147 // If the inheriting widget has its own fontmap and a PWL_Edit widget that 148 // access that fontmap then you have to call DestroyWindows before destroying 149 // the font map in order to not get a use-after-free. 150 // 151 // The font map should be stored somewhere more appropriate so it will live 152 // until the PWL_Edit is done with it. pdfium:566 153 void DestroyWindows(); 154 155 CPDFSDK_FormFillEnvironment* m_pFormFillEnv; 156 CPDFSDK_Widget* m_pWidget; 157 CPDFSDK_Annot* m_pAnnot; 158 bool m_bValid; 159 CFFL_PageView2PDFWindow m_Maps; 160 CFX_PointF m_ptOldPos; 161 }; 162 163 class CFFL_Button : public CFFL_FormFiller { 164 public: 165 CFFL_Button(CPDFSDK_FormFillEnvironment* pFormFillEnv, 166 CPDFSDK_Annot* pWidget); 167 ~CFFL_Button() override; 168 169 // CFFL_FormFiller 170 void OnMouseEnter(CPDFSDK_PageView* pPageView, 171 CPDFSDK_Annot* pAnnot) override; 172 void OnMouseExit(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot) override; 173 bool OnLButtonDown(CPDFSDK_PageView* pPageView, 174 CPDFSDK_Annot* pAnnot, 175 uint32_t nFlags, 176 const CFX_PointF& point) override; 177 bool OnLButtonUp(CPDFSDK_PageView* pPageView, 178 CPDFSDK_Annot* pAnnot, 179 uint32_t nFlags, 180 const CFX_PointF& point) override; 181 bool OnMouseMove(CPDFSDK_PageView* pPageView, 182 CPDFSDK_Annot* pAnnot, 183 uint32_t nFlags, 184 const CFX_PointF& point) override; 185 void OnDraw(CPDFSDK_PageView* pPageView, 186 CPDFSDK_Annot* pAnnot, 187 CFX_RenderDevice* pDevice, 188 CFX_Matrix* pUser2Device) override; 189 void OnDrawDeactive(CPDFSDK_PageView* pPageView, 190 CPDFSDK_Annot* pAnnot, 191 CFX_RenderDevice* pDevice, 192 CFX_Matrix* pUser2Device) override; 193 194 protected: 195 bool m_bMouseIn; 196 bool m_bMouseDown; 197 }; 198 199 #endif // FPDFSDK_FORMFILLER_CFFL_FORMFILLER_H_ 200