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_INCLUDE_FORMFILLER_FFL_IFORMFILLER_H_
8 #define FPDFSDK_INCLUDE_FORMFILLER_FFL_IFORMFILLER_H_
9 
10 #include <map>
11 
12 #include "fpdfsdk/include/fsdk_define.h"
13 #include "fpdfsdk/include/pdfwindow/PWL_Edit.h"
14 
15 class CFFL_FormFiller;
16 class CFFL_PrivateData;
17 class CPDFDoc_Environment;
18 class CPDFSDK_Annot;
19 class CPDFSDK_PageView;
20 class CPDFSDK_Widget;
21 
22 class CFFL_IFormFiller : public IPWL_Filler_Notify {
23  public:
24   explicit CFFL_IFormFiller(CPDFDoc_Environment* pApp);
25   ~CFFL_IFormFiller() override;
26 
27   virtual FX_BOOL Annot_HitTest(CPDFSDK_PageView* pPageView,
28                                 CPDFSDK_Annot* pAnnot,
29                                 CPDF_Point point);
30   virtual FX_RECT GetViewBBox(CPDFSDK_PageView* pPageView,
31                               CPDFSDK_Annot* pAnnot);
32   virtual void OnDraw(CPDFSDK_PageView* pPageView,
33                       CPDFSDK_Annot* pAnnot,
34                       CFX_RenderDevice* pDevice,
35                       CFX_Matrix* pUser2Device,
36                       FX_DWORD dwFlags);
37 
38   virtual void OnCreate(CPDFSDK_Annot* pAnnot);
39   virtual void OnLoad(CPDFSDK_Annot* pAnnot);
40   virtual void OnDelete(CPDFSDK_Annot* pAnnot);
41 
42   virtual void OnMouseEnter(CPDFSDK_PageView* pPageView,
43                             CPDFSDK_Annot* pAnnot,
44                             FX_UINT nFlag);
45   virtual void OnMouseExit(CPDFSDK_PageView* pPageView,
46                            CPDFSDK_Annot* pAnnot,
47                            FX_UINT nFlag);
48 
49   virtual FX_BOOL OnLButtonDown(CPDFSDK_PageView* pPageView,
50                                 CPDFSDK_Annot* pAnnot,
51                                 FX_UINT nFlags,
52                                 const CPDF_Point& point);
53   virtual FX_BOOL OnLButtonUp(CPDFSDK_PageView* pPageView,
54                               CPDFSDK_Annot* pAnnot,
55                               FX_UINT nFlags,
56                               const CPDF_Point& point);
57   virtual FX_BOOL OnLButtonDblClk(CPDFSDK_PageView* pPageView,
58                                   CPDFSDK_Annot* pAnnot,
59                                   FX_UINT nFlags,
60                                   const CPDF_Point& point);
61   virtual FX_BOOL OnMouseMove(CPDFSDK_PageView* pPageView,
62                               CPDFSDK_Annot* pAnnot,
63                               FX_UINT nFlags,
64                               const CPDF_Point& point);
65   virtual FX_BOOL OnMouseWheel(CPDFSDK_PageView* pPageView,
66                                CPDFSDK_Annot* pAnnot,
67                                FX_UINT nFlags,
68                                short zDelta,
69                                const CPDF_Point& point);
70   virtual FX_BOOL OnRButtonDown(CPDFSDK_PageView* pPageView,
71                                 CPDFSDK_Annot* pAnnot,
72                                 FX_UINT nFlags,
73                                 const CPDF_Point& point);
74   virtual FX_BOOL OnRButtonUp(CPDFSDK_PageView* pPageView,
75                               CPDFSDK_Annot* pAnnot,
76                               FX_UINT nFlags,
77                               const CPDF_Point& point);
78 
79   virtual FX_BOOL OnKeyDown(CPDFSDK_Annot* pAnnot,
80                             FX_UINT nKeyCode,
81                             FX_UINT nFlags);
82   virtual FX_BOOL OnChar(CPDFSDK_Annot* pAnnot, FX_UINT nChar, FX_UINT nFlags);
83 
84   virtual FX_BOOL OnSetFocus(CPDFSDK_Annot* pAnnot, FX_UINT nFlag);
85   virtual FX_BOOL OnKillFocus(CPDFSDK_Annot* pAnnot, FX_UINT nFlag);
86 
87   CFFL_FormFiller* GetFormFiller(CPDFSDK_Annot* pAnnot, FX_BOOL bRegister);
88   void RemoveFormFiller(CPDFSDK_Annot* pAnnot);
89 
90   static FX_BOOL IsVisible(CPDFSDK_Widget* pWidget);
91   static FX_BOOL IsReadOnly(CPDFSDK_Widget* pWidget);
92   static FX_BOOL IsFillingAllowed(CPDFSDK_Widget* pWidget);
93   static FX_BOOL IsValidAnnot(CPDFSDK_PageView* pPageView,
94                               CPDFSDK_Annot* pAnnot);
95 
96   void OnKeyStrokeCommit(CPDFSDK_Widget* pWidget,
97                          CPDFSDK_PageView* pPageView,
98                          FX_BOOL& bRC,
99                          FX_BOOL& bExit,
100                          FX_DWORD nFlag);
101   void OnValidate(CPDFSDK_Widget* pWidget,
102                   CPDFSDK_PageView* pPageView,
103                   FX_BOOL& bRC,
104                   FX_BOOL& bExit,
105                   FX_DWORD nFlag);
106 
107   void OnCalculate(CPDFSDK_Widget* pWidget,
108                    CPDFSDK_PageView* pPageView,
109                    FX_BOOL& bExit,
110                    FX_DWORD nFlag);
111   void OnFormat(CPDFSDK_Widget* pWidget,
112                 CPDFSDK_PageView* pPageView,
113                 FX_BOOL& bExit,
114                 FX_DWORD nFlag);
115   void OnButtonUp(CPDFSDK_Widget* pWidget,
116                   CPDFSDK_PageView* pPageView,
117                   FX_BOOL& bReset,
118                   FX_BOOL& bExit,
119                   FX_UINT nFlag);
120 #ifdef PDF_ENABLE_XFA
121   void OnClick(CPDFSDK_Widget* pWidget,
122                CPDFSDK_PageView* pPageView,
123                FX_BOOL& bReset,
124                FX_BOOL& bExit,
125                FX_UINT nFlag);
126   void OnFull(CPDFSDK_Widget* pWidget,
127               CPDFSDK_PageView* pPageView,
128               FX_BOOL& bReset,
129               FX_BOOL& bExit,
130               FX_UINT nFlag);
131   void OnPreOpen(CPDFSDK_Widget* pWidget,
132                  CPDFSDK_PageView* pPageView,
133                  FX_BOOL& bReset,
134                  FX_BOOL& bExit,
135                  FX_UINT nFlag);
136   void OnPostOpen(CPDFSDK_Widget* pWidget,
137                   CPDFSDK_PageView* pPageView,
138                   FX_BOOL& bReset,
139                   FX_BOOL& bExit,
140                   FX_UINT nFlag);
141 #endif  // PDF_ENABLE_XFA
142 
143  private:
144   using CFFL_Widget2Filler = std::map<CPDFSDK_Annot*, CFFL_FormFiller*>;
145 
146   // IPWL_Filler_Notify:
147   void QueryWherePopup(void* pPrivateData,
148                        FX_FLOAT fPopupMin,
149                        FX_FLOAT fPopupMax,
150                        int32_t& nRet,
151                        FX_FLOAT& fPopupRet) override;
152   void OnBeforeKeyStroke(void* pPrivateData,
153                          CFX_WideString& strChange,
154                          const CFX_WideString& strChangeEx,
155                          int nSelStart,
156                          int nSelEnd,
157                          FX_BOOL bKeyDown,
158                          FX_BOOL& bRC,
159                          FX_BOOL& bExit,
160                          FX_DWORD nFlag) override;
161 #ifdef PDF_ENABLE_XFA
162   void OnPopupPreOpen(void* pPrivateData,
163                       FX_BOOL& bExit,
164                       FX_DWORD nFlag) override;
165   void OnPopupPostOpen(void* pPrivateData,
166                        FX_BOOL& bExit,
167                        FX_DWORD nFlag) override;
168   void SetFocusAnnotTab(CPDFSDK_Annot* pWidget,
169                         FX_BOOL bSameField,
170                         FX_BOOL bNext);
171 #endif  // PDF_ENABLE_XFA
172   void UnRegisterFormFiller(CPDFSDK_Annot* pAnnot);
173 
174   CPDFDoc_Environment* m_pApp;
175   CFFL_Widget2Filler m_Maps;
176   FX_BOOL m_bNotifying;
177 };
178 
179 class CFFL_PrivateData {
180  public:
181   CPDFSDK_Widget* pWidget;
182   CPDFSDK_PageView* pPageView;
183   int nWidgetAge;
184   int nValueAge;
185 };
186 
187 #endif  // FPDFSDK_INCLUDE_FORMFILLER_FFL_IFORMFILLER_H_
188