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