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