Fix a leak with g_DefaultGlobalObjectTemplate.
[pdfium.git] / fpdfsdk / include / formfiller / FFL_FormFiller.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_FORMFILLER_H_
8 #define FPDFSDK_INCLUDE_FORMFILLER_FFL_FORMFILLER_H_
9
10 #include "FFL_IFormFiller.h"
11 #include "FFL_CBA_Fontmap.h"
12
13 class CPDFDoc_Environment;
14 class CPDFSDK_Annot;
15 class CPDFSDK_Document;
16 class CPDFSDK_PageView;
17 class CPDFSDK_Widget;
18
19 class CFFL_FormFiller : public IPWL_Provider, public CPWL_TimerHandler {
20  public:
21   CFFL_FormFiller(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pAnnot);
22   ~CFFL_FormFiller() override;
23
24   virtual FX_RECT GetViewBBox(CPDFSDK_PageView* pPageView,
25                               CPDFSDK_Annot* pAnnot);
26   virtual void OnDraw(CPDFSDK_PageView* pPageView,
27                       CPDFSDK_Annot* pAnnot,
28                       CFX_RenderDevice* pDevice,
29                       CPDF_Matrix* pUser2Device,
30                       FX_DWORD dwFlags);
31   virtual void OnDrawDeactive(CPDFSDK_PageView* pPageView,
32                               CPDFSDK_Annot* pAnnot,
33                               CFX_RenderDevice* pDevice,
34                               CPDF_Matrix* pUser2Device,
35                               FX_DWORD dwFlags);
36
37   virtual void OnCreate(CPDFSDK_Annot* pAnnot);
38   virtual void OnLoad(CPDFSDK_Annot* pAnnot);
39   virtual void OnDelete(CPDFSDK_Annot* pAnnot);
40
41   virtual void OnMouseEnter(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot);
42   virtual void OnMouseExit(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot);
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   void SetFocusForAnnot(CPDFSDK_Annot* pAnnot, FX_UINT nFlag);
80   void KillFocusForAnnot(CPDFSDK_Annot* pAnnot, FX_UINT nFlag);
81
82   // CPWL_TimerHandler
83   void TimerProc() override;
84   IFX_SystemHandler* GetSystemHandler() const override;
85
86   // IPWL_Provider
87   CPDF_Matrix GetWindowMatrix(void* pAttachedData) override;
88   CFX_WideString LoadPopupMenuString(int nIndex) override;
89
90   virtual void GetActionData(CPDFSDK_PageView* pPageView,
91                              CPDF_AAction::AActionType type,
92                              PDFSDK_FieldAction& fa);
93   virtual void SetActionData(CPDFSDK_PageView* pPageView,
94                              CPDF_AAction::AActionType type,
95                              const PDFSDK_FieldAction& fa);
96   virtual FX_BOOL IsActionDataChanged(CPDF_AAction::AActionType type,
97                                       const PDFSDK_FieldAction& faOld,
98                                       const PDFSDK_FieldAction& faNew);
99
100   virtual void SaveState(CPDFSDK_PageView* pPageView);
101   virtual void RestoreState(CPDFSDK_PageView* pPageView);
102
103   virtual CPWL_Wnd* ResetPDFWindow(CPDFSDK_PageView* pPageView,
104                                    FX_BOOL bRestoreValue);
105
106   virtual void OnKeyStroke(FX_BOOL bKeyDown, FX_DWORD nFlag);
107
108   CPDF_Matrix GetCurMatrix();
109
110   CPDF_Rect FFLtoPWL(const CPDF_Rect& rect);
111   CPDF_Rect PWLtoFFL(const CPDF_Rect& rect);
112   CPDF_Point FFLtoPWL(const CPDF_Point& point);
113   CPDF_Point PWLtoFFL(const CPDF_Point& point);
114
115   CPDF_Point WndtoPWL(CPDFSDK_PageView* pPageView, const CPDF_Point& pt);
116   CPDF_Rect FFLtoWnd(CPDFSDK_PageView* pPageView, const CPDF_Rect& rect);
117
118   void SetWindowRect(CPDFSDK_PageView* pPageView, const CPDF_Rect& rcWindow);
119   CPDF_Rect GetWindowRect(CPDFSDK_PageView* pPageView);
120
121   FX_BOOL CommitData(CPDFSDK_PageView* pPageView, FX_UINT nFlag);
122   virtual FX_BOOL IsDataChanged(CPDFSDK_PageView* pPageView);
123   virtual void SaveData(CPDFSDK_PageView* pPageView);
124
125   CPWL_Wnd* GetPDFWindow(CPDFSDK_PageView* pPageView, FX_BOOL bNew);
126   void DestroyPDFWindow(CPDFSDK_PageView* pPageView);
127   void EscapeFiller(CPDFSDK_PageView* pPageView, FX_BOOL bDestroyPDFWindow);
128
129   virtual PWL_CREATEPARAM GetCreateParam();
130   virtual CPWL_Wnd* NewPDFWindow(const PWL_CREATEPARAM& cp,
131                                  CPDFSDK_PageView* pPageView) = 0;
132   virtual CPDF_Rect GetFocusBox(CPDFSDK_PageView* pPageView);
133
134   FX_BOOL IsValid() const;
135   CPDF_Rect GetPDFWindowRect() const;
136
137   CPDFSDK_PageView* GetCurPageView();
138   void SetChangeMark();
139
140   virtual void InvalidateRect(double left,
141                               double top,
142                               double right,
143                               double bottom);
144   CPDFDoc_Environment* GetApp() { return m_pApp; }
145   CPDFSDK_Annot* GetSDKAnnot() { return m_pAnnot; }
146
147  protected:
148   using CFFL_PageView2PDFWindow = std::map<CPDFSDK_PageView*, CPWL_Wnd*>;
149
150   CPDFDoc_Environment* m_pApp;
151   CPDFSDK_Widget* m_pWidget;
152   CPDFSDK_Annot* m_pAnnot;
153
154   FX_BOOL m_bValid;
155   CFFL_PageView2PDFWindow m_Maps;
156   CPDF_Point m_ptOldPos;
157 };
158
159 class CFFL_Button : public CFFL_FormFiller {
160  public:
161   CFFL_Button(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pWidget);
162   ~CFFL_Button() override;
163
164   // CFFL_FormFiller
165   void OnMouseEnter(CPDFSDK_PageView* pPageView,
166                     CPDFSDK_Annot* pAnnot) override;
167   void OnMouseExit(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot) override;
168   FX_BOOL OnLButtonDown(CPDFSDK_PageView* pPageView,
169                         CPDFSDK_Annot* pAnnot,
170                         FX_UINT nFlags,
171                         const CPDF_Point& point) override;
172   FX_BOOL OnLButtonUp(CPDFSDK_PageView* pPageView,
173                       CPDFSDK_Annot* pAnnot,
174                       FX_UINT nFlags,
175                       const CPDF_Point& point) override;
176   FX_BOOL OnMouseMove(CPDFSDK_PageView* pPageView,
177                       CPDFSDK_Annot* pAnnot,
178                       FX_UINT nFlags,
179                       const CPDF_Point& point) override;
180   void OnDraw(CPDFSDK_PageView* pPageView,
181               CPDFSDK_Annot* pAnnot,
182               CFX_RenderDevice* pDevice,
183               CPDF_Matrix* pUser2Device,
184               FX_DWORD dwFlags) override;
185   void OnDrawDeactive(CPDFSDK_PageView* pPageView,
186                       CPDFSDK_Annot* pAnnot,
187                       CFX_RenderDevice* pDevice,
188                       CPDF_Matrix* pUser2Device,
189                       FX_DWORD dwFlags) override;
190
191  protected:
192   FX_BOOL m_bMouseIn;
193   FX_BOOL m_bMouseDown;
194 };
195
196 #endif  // FPDFSDK_INCLUDE_FORMFILLER_FFL_FORMFILLER_H_