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_FFWIDGET_H_
8 #define XFA_FXFA_CXFA_FFWIDGET_H_
9
10 #include <vector>
11
12 #include "core/fpdfdoc/cpdf_formfield.h"
13 #include "core/fxcodec/fx_codec_def.h"
14 #include "core/fxge/cfx_graphstatedata.h"
15 #include "xfa/fwl/cfwl_app.h"
16 #include "xfa/fxfa/fxfa.h"
17 #include "xfa/fxfa/parser/cxfa_contentlayoutitem.h"
18
19 class CXFA_Box;
20 class CXFA_FFPageView;
21 class CXFA_FFDocView;
22 class CXFA_FFDoc;
23 class CXFA_FFApp;
24 class CXFA_Graphics;
25 class CXFA_Image;
26 enum class FWL_WidgetHit;
27
XFA_UnitPx2Pt(float fPx,float fDpi)28 inline float XFA_UnitPx2Pt(float fPx, float fDpi) {
29 return fPx * 72.0f / fDpi;
30 }
31
32 #define XFA_FLOAT_PERCISION 0.001f
33
34 void XFA_DrawImage(CXFA_Graphics* pGS,
35 const CFX_RectF& rtImage,
36 const CFX_Matrix& matrix,
37 const RetainPtr<CFX_DIBitmap>& pDIBitmap,
38 XFA_AttributeEnum iAspect,
39 int32_t iImageXDpi,
40 int32_t iImageYDpi,
41 XFA_AttributeEnum iHorzAlign = XFA_AttributeEnum::Left,
42 XFA_AttributeEnum iVertAlign = XFA_AttributeEnum::Top);
43
44 RetainPtr<CFX_DIBitmap> XFA_LoadImageFromBuffer(
45 const RetainPtr<IFX_SeekableReadStream>& pImageFileRead,
46 FXCODEC_IMAGE_TYPE type,
47 int32_t& iImageXDpi,
48 int32_t& iImageYDpi);
49
50 void XFA_RectWithoutMargin(CFX_RectF& rt,
51 const CXFA_Margin* margin,
52 bool bUI = false);
53 CXFA_FFWidget* XFA_GetWidgetFromLayoutItem(CXFA_LayoutItem* pLayoutItem);
54
55 class CXFA_CalcData {
56 public:
57 CXFA_CalcData();
58 ~CXFA_CalcData();
59
60 std::vector<CXFA_Node*> m_Globals;
61 int32_t m_iRefCount;
62 };
63
64 class CXFA_FFWidget : public CXFA_ContentLayoutItem {
65 public:
66 explicit CXFA_FFWidget(CXFA_Node* pNode);
67 ~CXFA_FFWidget() override;
68
69 virtual CFX_RectF GetBBox(uint32_t dwStatus, bool bDrawFocus = false);
70 virtual void RenderWidget(CXFA_Graphics* pGS,
71 const CFX_Matrix& matrix,
72 uint32_t dwStatus);
73 virtual bool IsLoaded();
74 virtual bool LoadWidget();
75 virtual void UnloadWidget();
76 virtual bool PerformLayout();
77 virtual bool UpdateFWLData();
78 virtual void UpdateWidgetProperty();
79 virtual bool OnMouseEnter();
80 virtual bool OnMouseExit();
81 virtual bool OnLButtonDown(uint32_t dwFlags, const CFX_PointF& point);
82 virtual bool OnLButtonUp(uint32_t dwFlags, const CFX_PointF& point);
83 virtual bool OnLButtonDblClk(uint32_t dwFlags, const CFX_PointF& point);
84 virtual bool OnMouseMove(uint32_t dwFlags, const CFX_PointF& point);
85 virtual bool OnMouseWheel(uint32_t dwFlags,
86 int16_t zDelta,
87 const CFX_PointF& point);
88 virtual bool OnRButtonDown(uint32_t dwFlags, const CFX_PointF& point);
89 virtual bool OnRButtonUp(uint32_t dwFlags, const CFX_PointF& point);
90 virtual bool OnRButtonDblClk(uint32_t dwFlags, const CFX_PointF& point);
91
92 virtual bool OnSetFocus(CXFA_FFWidget* pOldWidget);
93 virtual bool OnKillFocus(CXFA_FFWidget* pNewWidget);
94 virtual bool OnKeyDown(uint32_t dwKeyCode, uint32_t dwFlags);
95 virtual bool OnKeyUp(uint32_t dwKeyCode, uint32_t dwFlags);
96 virtual bool OnChar(uint32_t dwChar, uint32_t dwFlags);
97 virtual FWL_WidgetHit OnHitTest(const CFX_PointF& point);
98 virtual bool OnSetCursor(const CFX_PointF& point);
99 virtual bool CanUndo();
100 virtual bool CanRedo();
101 virtual bool Undo();
102 virtual bool Redo();
103 virtual bool CanCopy();
104 virtual bool CanCut();
105 virtual bool CanPaste();
106 virtual bool CanSelectAll();
107 virtual bool CanDelete();
108 virtual bool CanDeSelect();
109 virtual Optional<WideString> Copy();
110 virtual Optional<WideString> Cut();
111 virtual bool Paste(const WideString& wsPaste);
112 virtual void SelectAll();
113 virtual void Delete();
114 virtual void DeSelect();
115
116 virtual FormFieldType GetFormFieldType();
117
118 // TODO(tsepez): Implement or remove.
119 void GetSuggestWords(CFX_PointF pointf, std::vector<ByteString>* pWords);
120 bool ReplaceSpellCheckWord(CFX_PointF pointf,
121 const ByteStringView& bsReplace);
122
GetPageView()123 CXFA_FFPageView* GetPageView() const { return m_pPageView; }
SetPageView(CXFA_FFPageView * pPageView)124 void SetPageView(CXFA_FFPageView* pPageView) { m_pPageView = pPageView; }
125 const CFX_RectF& GetWidgetRect() const;
126 const CFX_RectF& RecacheWidgetRect() const;
127 uint32_t GetStatus();
128 void ModifyStatus(uint32_t dwAdded, uint32_t dwRemoved);
129
GetNode()130 CXFA_Node* GetNode() { return m_pNode.Get(); }
131
132 CXFA_FFDocView* GetDocView();
133 void SetDocView(CXFA_FFDocView* pDocView);
134 CXFA_FFDoc* GetDoc();
135 CXFA_FFApp* GetApp();
136 IXFA_AppProvider* GetAppProvider();
137 void AddInvalidateRect();
IsFocused()138 bool IsFocused() const { return !!(m_dwStatus & XFA_WidgetStatus_Focused); }
139 CFX_PointF Rotate2Normal(const CFX_PointF& point);
140 CFX_Matrix GetRotateMatrix();
141 bool IsLayoutRectEmpty();
142 CXFA_FFWidget* GetParent();
143 bool IsAncestorOf(CXFA_FFWidget* pWidget);
144 const CFWL_App* GetFWLApp();
145
146 protected:
147 virtual bool PtInActiveRect(const CFX_PointF& point);
148
149 void DrawBorder(CXFA_Graphics* pGS,
150 CXFA_Box* box,
151 const CFX_RectF& rtBorder,
152 const CFX_Matrix& matrix);
153 void DrawBorderWithFlag(CXFA_Graphics* pGS,
154 CXFA_Box* box,
155 const CFX_RectF& rtBorder,
156 const CFX_Matrix& matrix,
157 bool forceRound);
158
159 CFX_RectF GetRectWithoutRotate();
160 bool IsMatchVisibleStatus(uint32_t dwStatus);
161 void EventKillFocus();
162 bool IsButtonDown();
163 void SetButtonDown(bool bSet);
164
165 CXFA_FFDocView* m_pDocView = nullptr;
166 CXFA_FFPageView* m_pPageView = nullptr;
167 UnownedPtr<CXFA_Node> const m_pNode;
168 mutable CFX_RectF m_rtWidget;
169 };
170
171 #endif // XFA_FXFA_CXFA_FFWIDGET_H_
172