blob: 74e4c84c4de4e72f57a925505411adfb89e18e10 [file] [log] [blame]
Dan Sinclair1770c022016-03-14 14:14:16 -04001// 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
dsinclair7222ea62016-04-06 14:33:07 -07007#ifndef XFA_FXFA_INCLUDE_XFA_FFWIDGET_H_
8#define XFA_FXFA_INCLUDE_XFA_FFWIDGET_H_
Dan Sinclair1770c022016-03-14 14:14:16 -04009
10#include <vector>
11
dsinclair86e54742016-04-06 12:30:31 -070012#include "core/fxcodec/include/fx_codec_def.h"
dsinclair48baa5f2016-04-06 10:00:40 -070013#include "core/fxge/include/fx_ge.h"
dsinclair7222ea62016-04-06 14:33:07 -070014#include "xfa/fxfa/include/fxfa.h"
Dan Sinclair1770c022016-03-14 14:14:16 -040015#include "xfa/fxfa/parser/xfa_doclayout.h"
Dan Sinclair1770c022016-03-14 14:14:16 -040016
17class CXFA_FFPageView;
18class CXFA_FFDocView;
19class CXFA_FFDoc;
20class CXFA_FFApp;
dsinclair89fcde82016-05-03 13:00:25 -070021enum class FWL_WidgetHit;
Dan Sinclair1770c022016-03-14 14:14:16 -040022
23inline FX_FLOAT XFA_UnitPx2Pt(FX_FLOAT fPx, FX_FLOAT fDpi) {
24 return fPx * 72.0f / fDpi;
25}
26#define XFA_FLOAT_PERCISION 0.001f
27enum XFA_WIDGETITEM {
28 XFA_WIDGETITEM_Parent,
29 XFA_WIDGETITEM_FirstChild,
30 XFA_WIDGETITEM_NextSibling,
31 XFA_WIDGETITEM_PrevSibling,
32};
tsepezbb0d4462016-04-27 16:59:30 -070033
Dan Sinclair1770c022016-03-14 14:14:16 -040034class CXFA_CalcData {
35 public:
36 CXFA_CalcData() : m_iRefCount(0) {}
37 ~CXFA_CalcData() { m_Globals.RemoveAll(); }
tsepezbb0d4462016-04-27 16:59:30 -070038
39 CFX_ArrayTemplate<CXFA_WidgetAcc*> m_Globals;
Dan Sinclair1770c022016-03-14 14:14:16 -040040 int32_t m_iRefCount;
41};
tsepezbb0d4462016-04-27 16:59:30 -070042
dsinclairdf4bc592016-03-31 20:34:43 -070043class CXFA_FFWidget : public CFX_PrivateData, public CXFA_ContentLayoutItem {
Dan Sinclair1770c022016-03-14 14:14:16 -040044 public:
45 CXFA_FFWidget(CXFA_FFPageView* pPageView, CXFA_WidgetAcc* pDataAcc);
46 virtual ~CXFA_FFWidget();
dsinclairdf4bc592016-03-31 20:34:43 -070047 CXFA_FFPageView* GetPageView();
48 void SetPageView(CXFA_FFPageView* pPageView);
Dan Sinclair1770c022016-03-14 14:14:16 -040049 void GetWidgetRect(CFX_RectF& rtWidget);
50 CFX_RectF ReCacheWidgetRect();
tsepezdeee3d22016-03-25 14:38:58 -070051 uint32_t GetStatus();
52 void ModifyStatus(uint32_t dwAdded, uint32_t dwRemoved);
Dan Sinclair1770c022016-03-14 14:14:16 -040053 virtual FX_BOOL GetBBox(CFX_RectF& rtBox,
tsepezdeee3d22016-03-25 14:38:58 -070054 uint32_t dwStatus,
Dan Sinclair1770c022016-03-14 14:14:16 -040055 FX_BOOL bDrawFocus = FALSE);
56 CXFA_WidgetAcc* GetDataAcc();
57 FX_BOOL GetToolTip(CFX_WideString& wsToolTip);
58 virtual void RenderWidget(CFX_Graphics* pGS,
59 CFX_Matrix* pMatrix = NULL,
tsepezdeee3d22016-03-25 14:38:58 -070060 uint32_t dwStatus = 0,
Dan Sinclair1770c022016-03-14 14:14:16 -040061 int32_t iRotate = 0);
62
63 virtual FX_BOOL IsLoaded();
64 virtual FX_BOOL LoadWidget();
65 virtual void UnloadWidget();
66 virtual FX_BOOL PerformLayout();
67 virtual FX_BOOL UpdateFWLData();
68 virtual void UpdateWidgetProperty();
69 virtual FX_BOOL OnMouseEnter();
70 virtual FX_BOOL OnMouseExit();
tsepezdeee3d22016-03-25 14:38:58 -070071 virtual FX_BOOL OnLButtonDown(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy);
72 virtual FX_BOOL OnLButtonUp(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy);
73 virtual FX_BOOL OnLButtonDblClk(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy);
74 virtual FX_BOOL OnMouseMove(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy);
75 virtual FX_BOOL OnMouseWheel(uint32_t dwFlags,
Dan Sinclair1770c022016-03-14 14:14:16 -040076 int16_t zDelta,
77 FX_FLOAT fx,
78 FX_FLOAT fy);
tsepezdeee3d22016-03-25 14:38:58 -070079 virtual FX_BOOL OnRButtonDown(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy);
80 virtual FX_BOOL OnRButtonUp(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy);
81 virtual FX_BOOL OnRButtonDblClk(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy);
Dan Sinclair1770c022016-03-14 14:14:16 -040082
83 virtual FX_BOOL OnSetFocus(CXFA_FFWidget* pOldWidget);
84 virtual FX_BOOL OnKillFocus(CXFA_FFWidget* pNewWidget);
tsepezdeee3d22016-03-25 14:38:58 -070085 virtual FX_BOOL OnKeyDown(uint32_t dwKeyCode, uint32_t dwFlags);
86 virtual FX_BOOL OnKeyUp(uint32_t dwKeyCode, uint32_t dwFlags);
87 virtual FX_BOOL OnChar(uint32_t dwChar, uint32_t dwFlags);
dsinclair89fcde82016-05-03 13:00:25 -070088 virtual FWL_WidgetHit OnHitTest(FX_FLOAT fx, FX_FLOAT fy);
Dan Sinclair1770c022016-03-14 14:14:16 -040089 virtual FX_BOOL OnSetCursor(FX_FLOAT fx, FX_FLOAT fy);
90 virtual FX_BOOL CanUndo() { return FALSE; }
91 virtual FX_BOOL CanRedo() { return FALSE; }
92 virtual FX_BOOL Undo() { return FALSE; }
93 virtual FX_BOOL Redo() { return FALSE; }
94 virtual FX_BOOL CanCopy() { return FALSE; }
95 virtual FX_BOOL CanCut() { return FALSE; }
96 virtual FX_BOOL CanPaste() { return FALSE; }
97 virtual FX_BOOL CanSelectAll() { return FALSE; }
98 virtual FX_BOOL CanDelete() { return CanCut(); }
99 virtual FX_BOOL CanDeSelect() { return CanCopy(); }
100 virtual FX_BOOL Copy(CFX_WideString& wsCopy) { return FALSE; }
101 virtual FX_BOOL Cut(CFX_WideString& wsCut) { return FALSE; }
102 virtual FX_BOOL Paste(const CFX_WideString& wsPaste) { return FALSE; }
103 virtual FX_BOOL SelectAll() { return FALSE; }
104 virtual FX_BOOL Delete() { return FALSE; }
105 virtual FX_BOOL DeSelect() { return FALSE; }
106 virtual FX_BOOL GetSuggestWords(CFX_PointF pointf,
107 std::vector<CFX_ByteString>& sSuggest) {
108 return FALSE;
109 }
110 virtual FX_BOOL ReplaceSpellCheckWord(CFX_PointF pointf,
111 const CFX_ByteStringC& bsReplace) {
112 return FALSE;
113 }
114 CXFA_FFDocView* GetDocView();
115 void SetDocView(CXFA_FFDocView* pDocView) { m_pDocView = pDocView; }
116 CXFA_FFDoc* GetDoc();
117 CXFA_FFApp* GetApp();
118 IXFA_AppProvider* GetAppProvider();
119 void InvalidateWidget(const CFX_RectF* pRect = NULL);
120 void AddInvalidateRect(const CFX_RectF* pRect = NULL);
121 FX_BOOL GetCaptionText(CFX_WideString& wsCap);
122 FX_BOOL IsFocused();
123 void Rotate2Normal(FX_FLOAT& fx, FX_FLOAT& fy);
124 void GetRotateMatrix(CFX_Matrix& mt);
125 FX_BOOL IsLayoutRectEmpty();
126 CXFA_FFWidget* GetParent();
127 FX_BOOL IsAncestorOf(CXFA_FFWidget* pWidget);
128
129 protected:
130 virtual FX_BOOL PtInActiveRect(FX_FLOAT fx, FX_FLOAT fy);
131 void DrawBorder(CFX_Graphics* pGS,
132 CXFA_Box box,
133 const CFX_RectF& rtBorder,
134 CFX_Matrix* pMatrix,
tsepezdeee3d22016-03-25 14:38:58 -0700135 uint32_t dwFlags = 0);
Dan Sinclair1770c022016-03-14 14:14:16 -0400136 void GetMinMaxWidth(FX_FLOAT fMinWidth, FX_FLOAT fMaxWidth);
137 void GetMinMaxHeight(FX_FLOAT fMinHeight, FX_FLOAT fMaxHeight);
138 void GetRectWithoutRotate(CFX_RectF& rtWidget);
tsepezdeee3d22016-03-25 14:38:58 -0700139 FX_BOOL IsMatchVisibleStatus(uint32_t dwStatus);
Dan Sinclair1770c022016-03-14 14:14:16 -0400140
141 void EventKillFocus();
142 FX_BOOL IsButtonDown();
143 void SetButtonDown(FX_BOOL bSet);
144 CXFA_FFDocView* m_pDocView;
145 CXFA_FFPageView* m_pPageView;
146 CXFA_WidgetAcc* m_pDataAcc;
147 CFX_RectF m_rtWidget;
148};
149int32_t XFA_StrokeTypeSetLineDash(CFX_Graphics* pGraphics,
150 int32_t iStrokeType,
151 int32_t iCapType);
152CFX_GraphStateData::LineCap XFA_LineCapToFXGE(int32_t iLineCap);
153void 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);
162CFX_DIBitmap* XFA_LoadImageData(CXFA_FFDoc* pDoc,
163 CXFA_Image* pImage,
164 FX_BOOL& bNameImage,
165 int32_t& iImageXDpi,
166 int32_t& iImageYDpi);
167CFX_DIBitmap* XFA_LoadImageFromBuffer(IFX_FileRead* pImageFileRead,
168 FXCODEC_IMAGE_TYPE type,
169 int32_t& iImageXDpi,
170 int32_t& iImageYDpi);
tsepezfc58ad12016-04-05 12:22:15 -0700171FXCODEC_IMAGE_TYPE XFA_GetImageType(const CFX_WideString& wsType);
Dan Sinclair1770c022016-03-14 14:14:16 -0400172FX_CHAR* XFA_Base64Encode(const uint8_t* buf, int32_t buf_len);
173void XFA_RectWidthoutMargin(CFX_RectF& rt,
174 const CXFA_Margin& mg,
175 FX_BOOL bUI = FALSE);
Dan Sinclair1770c022016-03-14 14:14:16 -0400176CXFA_FFWidget* XFA_GetWidgetFromLayoutItem(CXFA_LayoutItem* pLayoutItem);
177FX_BOOL XFA_IsCreateWidget(XFA_ELEMENT iType);
178#define XFA_DRAWBOX_ForceRound 1
179#define XFA_DRAWBOX_Lowered3D 2
180void XFA_DrawBox(CXFA_Box box,
181 CFX_Graphics* pGS,
182 const CFX_RectF& rtWidget,
183 CFX_Matrix* pMatrix,
tsepezdeee3d22016-03-25 14:38:58 -0700184 uint32_t dwFlags = 0);
Dan Sinclair1770c022016-03-14 14:14:16 -0400185
dsinclair7222ea62016-04-06 14:33:07 -0700186#endif // XFA_FXFA_INCLUDE_XFA_FFWIDGET_H_