Clean up CPDF_AnnotList.
[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   CPDF_Matrix GetCurMatrix();
107
108   CPDF_Rect FFLtoPWL(const CPDF_Rect& rect);
109   CPDF_Rect PWLtoFFL(const CPDF_Rect& rect);
110   CPDF_Point FFLtoPWL(const CPDF_Point& point);
111   CPDF_Point PWLtoFFL(const CPDF_Point& point);
112
113   CPDF_Point WndtoPWL(CPDFSDK_PageView* pPageView, const CPDF_Point& pt);
114   CPDF_Rect FFLtoWnd(CPDFSDK_PageView* pPageView, const CPDF_Rect& rect);
115
116   void SetWindowRect(CPDFSDK_PageView* pPageView, const CPDF_Rect& rcWindow);
117   CPDF_Rect GetWindowRect(CPDFSDK_PageView* pPageView);
118
119   FX_BOOL CommitData(CPDFSDK_PageView* pPageView, FX_UINT nFlag);
120   virtual FX_BOOL IsDataChanged(CPDFSDK_PageView* pPageView);
121   virtual void SaveData(CPDFSDK_PageView* pPageView);
122
123   CPWL_Wnd* GetPDFWindow(CPDFSDK_PageView* pPageView, FX_BOOL bNew);
124   void DestroyPDFWindow(CPDFSDK_PageView* pPageView);
125   void EscapeFiller(CPDFSDK_PageView* pPageView, FX_BOOL bDestroyPDFWindow);
126
127   virtual PWL_CREATEPARAM GetCreateParam();
128   virtual CPWL_Wnd* NewPDFWindow(const PWL_CREATEPARAM& cp,
129                                  CPDFSDK_PageView* pPageView) = 0;
130   virtual CPDF_Rect GetFocusBox(CPDFSDK_PageView* pPageView);
131
132   FX_BOOL IsValid() const;
133   CPDF_Rect GetPDFWindowRect() const;
134
135   CPDFSDK_PageView* GetCurPageView();
136   void SetChangeMark();
137
138   virtual void InvalidateRect(double left,
139                               double top,
140                               double right,
141                               double bottom);
142   CPDFDoc_Environment* GetApp() { return m_pApp; }
143   CPDFSDK_Annot* GetSDKAnnot() { return m_pAnnot; }
144
145  protected:
146   using CFFL_PageView2PDFWindow = std::map<CPDFSDK_PageView*, CPWL_Wnd*>;
147
148   CPDFDoc_Environment* m_pApp;
149   CPDFSDK_Widget* m_pWidget;
150   CPDFSDK_Annot* m_pAnnot;
151
152   FX_BOOL m_bValid;
153   CFFL_PageView2PDFWindow m_Maps;
154   CPDF_Point m_ptOldPos;
155 };
156
157 class CFFL_Button : public CFFL_FormFiller {
158  public:
159   CFFL_Button(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pWidget);
160   ~CFFL_Button() override;
161
162   // CFFL_FormFiller
163   void OnMouseEnter(CPDFSDK_PageView* pPageView,
164                     CPDFSDK_Annot* pAnnot) override;
165   void OnMouseExit(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot) override;
166   FX_BOOL OnLButtonDown(CPDFSDK_PageView* pPageView,
167                         CPDFSDK_Annot* pAnnot,
168                         FX_UINT nFlags,
169                         const CPDF_Point& point) override;
170   FX_BOOL OnLButtonUp(CPDFSDK_PageView* pPageView,
171                       CPDFSDK_Annot* pAnnot,
172                       FX_UINT nFlags,
173                       const CPDF_Point& point) override;
174   FX_BOOL OnMouseMove(CPDFSDK_PageView* pPageView,
175                       CPDFSDK_Annot* pAnnot,
176                       FX_UINT nFlags,
177                       const CPDF_Point& point) override;
178   void OnDraw(CPDFSDK_PageView* pPageView,
179               CPDFSDK_Annot* pAnnot,
180               CFX_RenderDevice* pDevice,
181               CPDF_Matrix* pUser2Device,
182               FX_DWORD dwFlags) override;
183   void OnDrawDeactive(CPDFSDK_PageView* pPageView,
184                       CPDFSDK_Annot* pAnnot,
185                       CFX_RenderDevice* pDevice,
186                       CPDF_Matrix* pUser2Device,
187                       FX_DWORD dwFlags) override;
188
189  protected:
190   FX_BOOL m_bMouseIn;
191   FX_BOOL m_bMouseDown;
192 };
193
194 #endif  // FPDFSDK_INCLUDE_FORMFILLER_FFL_FORMFILLER_H_