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_XFA_FFWIDGET_H_
8 #define XFA_FXFA_XFA_FFWIDGET_H_
9
10 #include <vector>
11
12 #include "core/fxcodec/fx_codec_def.h"
13 #include "core/fxge/cfx_graphstatedata.h"
14 #include "xfa/fwl/cfwl_app.h"
15 #include "xfa/fxfa/fxfa.h"
16 #include "xfa/fxfa/parser/cxfa_contentlayoutitem.h"
17
18 class CXFA_FFPageView;
19 class CXFA_FFDocView;
20 class CXFA_FFDoc;
21 class CXFA_FFApp;
22 enum class FWL_WidgetHit;
23
XFA_UnitPx2Pt(FX_FLOAT fPx,FX_FLOAT fDpi)24 inline FX_FLOAT XFA_UnitPx2Pt(FX_FLOAT fPx, FX_FLOAT fDpi) {
25 return fPx * 72.0f / fDpi;
26 }
27
28 #define XFA_FLOAT_PERCISION 0.001f
29
30 enum XFA_WIDGETITEM {
31 XFA_WIDGETITEM_Parent,
32 XFA_WIDGETITEM_FirstChild,
33 XFA_WIDGETITEM_NextSibling,
34 XFA_WIDGETITEM_PrevSibling,
35 };
36
37 class CXFA_CalcData {
38 public:
39 CXFA_CalcData();
40 ~CXFA_CalcData();
41
42 std::vector<CXFA_WidgetAcc*> m_Globals;
43 int32_t m_iRefCount;
44 };
45
46 class CXFA_FFWidget : public CXFA_ContentLayoutItem {
47 public:
48 explicit CXFA_FFWidget(CXFA_WidgetAcc* pDataAcc);
49 ~CXFA_FFWidget() override;
50
51 virtual CFX_RectF GetBBox(uint32_t dwStatus, bool bDrawFocus = false);
52 virtual void RenderWidget(CFX_Graphics* pGS,
53 CFX_Matrix* pMatrix,
54 uint32_t dwStatus);
55 virtual bool IsLoaded();
56 virtual bool LoadWidget();
57 virtual void UnloadWidget();
58 virtual bool PerformLayout();
59 virtual bool UpdateFWLData();
60 virtual void UpdateWidgetProperty();
61 virtual bool OnMouseEnter();
62 virtual bool OnMouseExit();
63 virtual bool OnLButtonDown(uint32_t dwFlags, const CFX_PointF& point);
64 virtual bool OnLButtonUp(uint32_t dwFlags, const CFX_PointF& point);
65 virtual bool OnLButtonDblClk(uint32_t dwFlags, const CFX_PointF& point);
66 virtual bool OnMouseMove(uint32_t dwFlags, const CFX_PointF& point);
67 virtual bool OnMouseWheel(uint32_t dwFlags,
68 int16_t zDelta,
69 const CFX_PointF& point);
70 virtual bool OnRButtonDown(uint32_t dwFlags, const CFX_PointF& point);
71 virtual bool OnRButtonUp(uint32_t dwFlags, const CFX_PointF& point);
72 virtual bool OnRButtonDblClk(uint32_t dwFlags, const CFX_PointF& point);
73
74 virtual bool OnSetFocus(CXFA_FFWidget* pOldWidget);
75 virtual bool OnKillFocus(CXFA_FFWidget* pNewWidget);
76 virtual bool OnKeyDown(uint32_t dwKeyCode, uint32_t dwFlags);
77 virtual bool OnKeyUp(uint32_t dwKeyCode, uint32_t dwFlags);
78 virtual bool OnChar(uint32_t dwChar, uint32_t dwFlags);
79 virtual FWL_WidgetHit OnHitTest(const CFX_PointF& point);
80 virtual bool OnSetCursor(const CFX_PointF& point);
81 virtual bool CanUndo();
82 virtual bool CanRedo();
83 virtual bool Undo();
84 virtual bool Redo();
85 virtual bool CanCopy();
86 virtual bool CanCut();
87 virtual bool CanPaste();
88 virtual bool CanSelectAll();
89 virtual bool CanDelete();
90 virtual bool CanDeSelect();
91 virtual bool Copy(CFX_WideString& wsCopy);
92 virtual bool Cut(CFX_WideString& wsCut);
93 virtual bool Paste(const CFX_WideString& wsPaste);
94 virtual void SelectAll();
95 virtual void Delete();
96 virtual void DeSelect();
97 virtual bool GetSuggestWords(CFX_PointF pointf,
98 std::vector<CFX_ByteString>& sSuggest);
99 virtual bool ReplaceSpellCheckWord(CFX_PointF pointf,
100 const CFX_ByteStringC& bsReplace);
101
GetPageView()102 CXFA_FFPageView* GetPageView() const { return m_pPageView; }
SetPageView(CXFA_FFPageView * pPageView)103 void SetPageView(CXFA_FFPageView* pPageView) { m_pPageView = pPageView; }
104 CFX_RectF GetWidgetRect();
105 CFX_RectF RecacheWidgetRect();
106 uint32_t GetStatus();
107 void ModifyStatus(uint32_t dwAdded, uint32_t dwRemoved);
108
109 CXFA_WidgetAcc* GetDataAcc();
110 bool GetToolTip(CFX_WideString& wsToolTip);
111
112 CXFA_FFDocView* GetDocView();
113 void SetDocView(CXFA_FFDocView* pDocView);
114 CXFA_FFDoc* GetDoc();
115 CXFA_FFApp* GetApp();
116 IXFA_AppProvider* GetAppProvider();
117 void InvalidateWidget(const CFX_RectF* pRect = nullptr);
118 void AddInvalidateRect(const CFX_RectF* pRect = nullptr);
119 bool GetCaptionText(CFX_WideString& wsCap);
120 bool IsFocused();
121 CFX_PointF Rotate2Normal(const CFX_PointF& point);
122 CFX_Matrix GetRotateMatrix();
123 bool IsLayoutRectEmpty();
124 CXFA_FFWidget* GetParent();
125 bool IsAncestorOf(CXFA_FFWidget* pWidget);
126 const CFWL_App* GetFWLApp();
127
128 protected:
129 virtual bool PtInActiveRect(const CFX_PointF& point);
130
131 void DrawBorder(CFX_Graphics* pGS,
132 CXFA_Box box,
133 const CFX_RectF& rtBorder,
134 CFX_Matrix* pMatrix,
135 uint32_t dwFlags = 0);
136
137 CFX_RectF GetRectWithoutRotate();
138 bool IsMatchVisibleStatus(uint32_t dwStatus);
139 void EventKillFocus();
140 bool IsButtonDown();
141 void SetButtonDown(bool bSet);
142
143 CXFA_FFDocView* m_pDocView;
144 CXFA_FFPageView* m_pPageView;
145 CXFA_WidgetAcc* m_pDataAcc;
146 CFX_RectF m_rtWidget;
147 };
148
149 int32_t XFA_StrokeTypeSetLineDash(CFX_Graphics* pGraphics,
150 int32_t iStrokeType,
151 int32_t iCapType);
152 CFX_GraphStateData::LineCap XFA_LineCapToFXGE(int32_t iLineCap);
153 void XFA_DrawImage(CFX_Graphics* pGS,
154 const CFX_RectF& rtImage,
155 CFX_Matrix* pMatrix,
156 CFX_DIBitmap* pDIBitmap,
157 int32_t iAspect,
158 int32_t iImageXDpi,
159 int32_t iImageYDpi,
160 int32_t iHorzAlign = XFA_ATTRIBUTEENUM_Left,
161 int32_t iVertAlign = XFA_ATTRIBUTEENUM_Top);
162
163 CFX_DIBitmap* XFA_LoadImageData(CXFA_FFDoc* pDoc,
164 CXFA_Image* pImage,
165 bool& bNameImage,
166 int32_t& iImageXDpi,
167 int32_t& iImageYDpi);
168
169 CFX_DIBitmap* XFA_LoadImageFromBuffer(
170 const CFX_RetainPtr<IFX_SeekableReadStream>& pImageFileRead,
171 FXCODEC_IMAGE_TYPE type,
172 int32_t& iImageXDpi,
173 int32_t& iImageYDpi);
174
175 FXCODEC_IMAGE_TYPE XFA_GetImageType(const CFX_WideString& wsType);
176 FX_CHAR* XFA_Base64Encode(const uint8_t* buf, int32_t buf_len);
177 void XFA_RectWidthoutMargin(CFX_RectF& rt,
178 const CXFA_Margin& mg,
179 bool bUI = false);
180 CXFA_FFWidget* XFA_GetWidgetFromLayoutItem(CXFA_LayoutItem* pLayoutItem);
181 bool XFA_IsCreateWidget(XFA_Element iType);
182 #define XFA_DRAWBOX_ForceRound 1
183 #define XFA_DRAWBOX_Lowered3D 2
184 void XFA_DrawBox(CXFA_Box box,
185 CFX_Graphics* pGS,
186 const CFX_RectF& rtWidget,
187 CFX_Matrix* pMatrix,
188 uint32_t dwFlags = 0);
189
190 #endif // XFA_FXFA_XFA_FFWIDGET_H_
191