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