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 XFA_FXFA_CXFA_FFWIDGETHANDLER_H_
8 #define XFA_FXFA_CXFA_FFWIDGETHANDLER_H_
9 
10 #include <vector>
11 
12 #include "xfa/fxfa/cxfa_eventparam.h"
13 #include "xfa/fxfa/fxfa.h"
14 #include "xfa/fxfa/parser/cxfa_document.h"
15 
16 class CXFA_FFDocView;
17 class CXFA_Graphics;
18 enum class FWL_WidgetHit;
19 
20 class CXFA_FFWidgetHandler {
21  public:
22   explicit CXFA_FFWidgetHandler(CXFA_FFDocView* pDocView);
23   ~CXFA_FFWidgetHandler();
24 
25   CXFA_FFWidget* CreateWidget(CXFA_FFWidget* hParent,
26                               XFA_WIDGETTYPE eType,
27                               CXFA_FFWidget* hBefore = nullptr);
28 
29   bool OnMouseEnter(CXFA_FFWidget* hWidget);
30   bool OnMouseExit(CXFA_FFWidget* hWidget);
31   bool OnLButtonDown(CXFA_FFWidget* hWidget,
32                      uint32_t dwFlags,
33                      const CFX_PointF& point);
34   bool OnLButtonUp(CXFA_FFWidget* hWidget,
35                    uint32_t dwFlags,
36                    const CFX_PointF& point);
37   bool OnLButtonDblClk(CXFA_FFWidget* hWidget,
38                        uint32_t dwFlags,
39                        const CFX_PointF& point);
40   bool OnMouseMove(CXFA_FFWidget* hWidget,
41                    uint32_t dwFlags,
42                    const CFX_PointF& point);
43   bool OnMouseWheel(CXFA_FFWidget* hWidget,
44                     uint32_t dwFlags,
45                     int16_t zDelta,
46                     const CFX_PointF& point);
47   bool OnRButtonDown(CXFA_FFWidget* hWidget,
48                      uint32_t dwFlags,
49                      const CFX_PointF& point);
50   bool OnRButtonUp(CXFA_FFWidget* hWidget,
51                    uint32_t dwFlags,
52                    const CFX_PointF& point);
53   bool OnRButtonDblClk(CXFA_FFWidget* hWidget,
54                        uint32_t dwFlags,
55                        const CFX_PointF& point);
56 
57   WideString GetSelectedText(CXFA_FFWidget* widget);
58   void PasteText(CXFA_FFWidget* widget, const WideString& text);
59 
60   bool OnKeyDown(CXFA_FFWidget* hWidget, uint32_t dwKeyCode, uint32_t dwFlags);
61   bool OnKeyUp(CXFA_FFWidget* hWidget, uint32_t dwKeyCode, uint32_t dwFlags);
62   bool OnChar(CXFA_FFWidget* hWidget, uint32_t dwChar, uint32_t dwFlags);
63   FWL_WidgetHit OnHitTest(CXFA_FFWidget* hWidget, const CFX_PointF& point);
64   bool OnSetCursor(CXFA_FFWidget* hWidget, const CFX_PointF& point);
65   void RenderWidget(CXFA_FFWidget* hWidget,
66                     CXFA_Graphics* pGS,
67                     const CFX_Matrix& matrix,
68                     bool bHighlight);
69   bool HasEvent(CXFA_WidgetAcc* pWidgetAcc, XFA_EVENTTYPE eEventType);
70   int32_t ProcessEvent(CXFA_WidgetAcc* pWidgetAcc, CXFA_EventParam* pParam);
71 
72  private:
73   CXFA_Node* CreateWidgetFormItem(XFA_WIDGETTYPE eType,
74                                   CXFA_Node* pParent,
75                                   CXFA_Node* pBefore) const;
76 
77   CXFA_Node* CreatePushButton(CXFA_Node* pParent, CXFA_Node* pBefore) const;
78   CXFA_Node* CreateCheckButton(CXFA_Node* pParent, CXFA_Node* pBefore) const;
79   CXFA_Node* CreateExclGroup(CXFA_Node* pParent, CXFA_Node* pBefore) const;
80   CXFA_Node* CreateRadioButton(CXFA_Node* pParent, CXFA_Node* pBefore) const;
81   CXFA_Node* CreateDatetimeEdit(CXFA_Node* pParent, CXFA_Node* pBefore) const;
82   CXFA_Node* CreateDecimalField(CXFA_Node* pParent, CXFA_Node* pBefore) const;
83   CXFA_Node* CreateNumericField(CXFA_Node* pParent, CXFA_Node* pBefore) const;
84   CXFA_Node* CreateSignature(CXFA_Node* pParent, CXFA_Node* pBefore) const;
85   CXFA_Node* CreateTextEdit(CXFA_Node* pParent, CXFA_Node* pBefore) const;
86   CXFA_Node* CreateDropdownList(CXFA_Node* pParent, CXFA_Node* pBefore) const;
87   CXFA_Node* CreateListBox(CXFA_Node* pParent, CXFA_Node* pBefore) const;
88   CXFA_Node* CreateImageField(CXFA_Node* pParent, CXFA_Node* pBefore) const;
89   CXFA_Node* CreatePasswordEdit(CXFA_Node* pParent, CXFA_Node* pBefore) const;
90   CXFA_Node* CreateField(XFA_Element eElement,
91                          CXFA_Node* pParent,
92                          CXFA_Node* pBefore) const;
93   CXFA_Node* CreateArc(CXFA_Node* pParent, CXFA_Node* pBefore) const;
94   CXFA_Node* CreateRectangle(CXFA_Node* pParent, CXFA_Node* pBefore) const;
95   CXFA_Node* CreateImage(CXFA_Node* pParent, CXFA_Node* pBefore) const;
96   CXFA_Node* CreateLine(CXFA_Node* pParent, CXFA_Node* pBefore) const;
97   CXFA_Node* CreateText(CXFA_Node* pParent, CXFA_Node* pBefore) const;
98   CXFA_Node* CreateDraw(XFA_Element eElement,
99                         CXFA_Node* pParent,
100                         CXFA_Node* pBefore) const;
101 
102   CXFA_Node* CreateSubform(CXFA_Node* pParent, CXFA_Node* pBefore) const;
103   CXFA_Node* CreateFormItem(XFA_Element eElement,
104                             CXFA_Node* pParent,
105                             CXFA_Node* pBefore) const;
106   CXFA_Node* CreateCopyNode(XFA_Element eElement,
107                             CXFA_Node* pParent,
108                             CXFA_Node* pBefore = nullptr) const;
109   CXFA_Node* CreateTemplateNode(XFA_Element eElement,
110                                 CXFA_Node* pParent,
111                                 CXFA_Node* pBefore) const;
112   CXFA_Node* CreateFontNode(CXFA_Node* pParent) const;
113   CXFA_Node* CreateMarginNode(CXFA_Node* pParent,
114                               uint32_t dwFlags,
115                               float fInsets[4]) const;
116   CXFA_Node* CreateValueNode(XFA_Element eValue, CXFA_Node* pParent) const;
117   CXFA_Document* GetObjFactory() const;
118   CXFA_Document* GetXFADoc() const;
119 
120   CXFA_FFDocView* m_pDocView;
121 };
122 
123 #endif  //  XFA_FXFA_CXFA_FFWIDGETHANDLER_H_
124