Fix a leak with g_DefaultGlobalObjectTemplate.
[pdfium.git] / fpdfsdk / include / formfiller / FFL_IFormFiller.h
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 "FormFiller.h"
13
14 class CFFL_FormFiller;
15 class CFFL_PrivateData;
16
17 class CFFL_IFormFiller : public IPWL_Filler_Notify {
18  public:
19   explicit CFFL_IFormFiller(CPDFDoc_Environment* pApp);
20   ~CFFL_IFormFiller() override;
21
22   virtual FX_BOOL Annot_HitTest(CPDFSDK_PageView* pPageView,
23                                 CPDFSDK_Annot* pAnnot,
24                                 CPDF_Point point);
25   virtual FX_RECT GetViewBBox(CPDFSDK_PageView* pPageView,
26                               CPDFSDK_Annot* pAnnot);
27   virtual void OnDraw(CPDFSDK_PageView* pPageView,
28                       CPDFSDK_Annot* pAnnot,
29                       CFX_RenderDevice* pDevice,
30                       CPDF_Matrix* pUser2Device,
31                       FX_DWORD dwFlags);
32
33   virtual void OnCreate(CPDFSDK_Annot* pAnnot);
34   virtual void OnLoad(CPDFSDK_Annot* pAnnot);
35   virtual void OnDelete(CPDFSDK_Annot* pAnnot);
36
37   virtual void OnMouseEnter(CPDFSDK_PageView* pPageView,
38                             CPDFSDK_Annot* pAnnot,
39                             FX_UINT nFlag);
40   virtual void OnMouseExit(CPDFSDK_PageView* pPageView,
41                            CPDFSDK_Annot* pAnnot,
42                            FX_UINT nFlag);
43
44   virtual FX_BOOL OnLButtonDown(CPDFSDK_PageView* pPageView,
45                                 CPDFSDK_Annot* pAnnot,
46                                 FX_UINT nFlags,
47                                 const CPDF_Point& point);
48   virtual FX_BOOL OnLButtonUp(CPDFSDK_PageView* pPageView,
49                               CPDFSDK_Annot* pAnnot,
50                               FX_UINT nFlags,
51                               const CPDF_Point& point);
52   virtual FX_BOOL OnLButtonDblClk(CPDFSDK_PageView* pPageView,
53                                   CPDFSDK_Annot* pAnnot,
54                                   FX_UINT nFlags,
55                                   const CPDF_Point& point);
56   virtual FX_BOOL OnMouseMove(CPDFSDK_PageView* pPageView,
57                               CPDFSDK_Annot* pAnnot,
58                               FX_UINT nFlags,
59                               const CPDF_Point& point);
60   virtual FX_BOOL OnMouseWheel(CPDFSDK_PageView* pPageView,
61                                CPDFSDK_Annot* pAnnot,
62                                FX_UINT nFlags,
63                                short zDelta,
64                                const CPDF_Point& point);
65   virtual FX_BOOL OnRButtonDown(CPDFSDK_PageView* pPageView,
66                                 CPDFSDK_Annot* pAnnot,
67                                 FX_UINT nFlags,
68                                 const CPDF_Point& point);
69   virtual FX_BOOL OnRButtonUp(CPDFSDK_PageView* pPageView,
70                               CPDFSDK_Annot* pAnnot,
71                               FX_UINT nFlags,
72                               const CPDF_Point& point);
73
74   virtual FX_BOOL OnKeyDown(CPDFSDK_Annot* pAnnot,
75                             FX_UINT nKeyCode,
76                             FX_UINT nFlags);
77   virtual FX_BOOL OnChar(CPDFSDK_Annot* pAnnot, FX_UINT nChar, FX_UINT nFlags);
78
79   virtual FX_BOOL OnSetFocus(CPDFSDK_Annot* pAnnot, FX_UINT nFlag);
80   virtual FX_BOOL OnKillFocus(CPDFSDK_Annot* pAnnot, FX_UINT nFlag);
81
82   CFFL_FormFiller* GetFormFiller(CPDFSDK_Annot* pAnnot, FX_BOOL bRegister);
83   void RemoveFormFiller(CPDFSDK_Annot* pAnnot);
84
85   static FX_BOOL IsVisible(CPDFSDK_Widget* pWidget);
86   static FX_BOOL IsReadOnly(CPDFSDK_Widget* pWidget);
87   static FX_BOOL IsFillingAllowed(CPDFSDK_Widget* pWidget);
88   static FX_BOOL IsValidAnnot(CPDFSDK_PageView* pPageView,
89                               CPDFSDK_Annot* pAnnot);
90
91   void OnKeyStrokeCommit(CPDFSDK_Widget* pWidget,
92                          CPDFSDK_PageView* pPageView,
93                          FX_BOOL& bRC,
94                          FX_BOOL& bExit,
95                          FX_DWORD nFlag);
96   void OnValidate(CPDFSDK_Widget* pWidget,
97                   CPDFSDK_PageView* pPageView,
98                   FX_BOOL& bRC,
99                   FX_BOOL& bExit,
100                   FX_DWORD nFlag);
101
102   void OnCalculate(CPDFSDK_Widget* pWidget,
103                    CPDFSDK_PageView* pPageView,
104                    FX_BOOL& bExit,
105                    FX_DWORD nFlag);
106   void OnFormat(CPDFSDK_Widget* pWidget,
107                 CPDFSDK_PageView* pPageView,
108                 FX_BOOL& bExit,
109                 FX_DWORD nFlag);
110   void OnButtonUp(CPDFSDK_Widget* pWidget,
111                   CPDFSDK_PageView* pPageView,
112                   FX_BOOL& bReset,
113                   FX_BOOL& bExit,
114                   FX_UINT nFlag);
115
116  private:
117   using CFFL_Widget2Filler = std::map<CPDFSDK_Annot*, CFFL_FormFiller*>;
118
119   // IPWL_Filler_Notify:
120   void QueryWherePopup(void* pPrivateData,
121                        FX_FLOAT fPopupMin,
122                        FX_FLOAT fPopupMax,
123                        int32_t& nRet,
124                        FX_FLOAT& fPopupRet) override;
125   void OnBeforeKeyStroke(FX_BOOL bEditOrList,
126                          void* pPrivateData,
127                          int32_t nKeyCode,
128                          CFX_WideString& strChange,
129                          const CFX_WideString& strChangeEx,
130                          int nSelStart,
131                          int nSelEnd,
132                          FX_BOOL bKeyDown,
133                          FX_BOOL& bRC,
134                          FX_BOOL& bExit,
135                          FX_DWORD nFlag) override;
136   void OnAfterKeyStroke(FX_BOOL bEditOrList,
137                         void* pPrivateData,
138                         FX_BOOL& bExit,
139                         FX_DWORD nFlag) override;
140
141   void UnRegisterFormFiller(CPDFSDK_Annot* pAnnot);
142
143   CPDFDoc_Environment* m_pApp;
144   CFFL_Widget2Filler m_Maps;
145   FX_BOOL m_bNotifying;
146 };
147
148 class CFFL_PrivateData {
149  public:
150   CPDFSDK_Widget* pWidget;
151   CPDFSDK_PageView* pPageView;
152   int nWidgetAge;
153   int nValueAge;
154 };
155
156 #endif  // FPDFSDK_INCLUDE_FORMFILLER_FFL_IFORMFILLER_H_