blob: bde247fab482bf036c831a60b783d99c50b44a00 [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"
dsinclair0b851ff2016-07-21 12:03:01 -070015#include "xfa/fxfa/parser/cxfa_contentlayoutitem.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:
weili47bcd4c2016-06-16 08:00:06 -070036 CXFA_CalcData();
37 ~CXFA_CalcData();
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
tsepez7fa55132016-05-25 16:57:11 -070043class CXFA_FFWidget : public CXFA_ContentLayoutItem {
Dan Sinclair1770c022016-03-14 14:14:16 -040044 public:
45 CXFA_FFWidget(CXFA_FFPageView* pPageView, CXFA_WidgetAcc* pDataAcc);
weili47bcd4c2016-06-16 08:00:06 -070046 ~CXFA_FFWidget() override;
47
Dan Sinclair1770c022016-03-14 14:14:16 -040048 virtual FX_BOOL GetBBox(CFX_RectF& rtBox,
tsepezdeee3d22016-03-25 14:38:58 -070049 uint32_t dwStatus,
Dan Sinclair1770c022016-03-14 14:14:16 -040050 FX_BOOL bDrawFocus = FALSE);
Dan Sinclair1770c022016-03-14 14:14:16 -040051 virtual void RenderWidget(CFX_Graphics* pGS,
dsinclair9d6ca992016-06-16 10:51:56 -070052 CFX_Matrix* pMatrix,
53 uint32_t dwStatus);
Dan Sinclair1770c022016-03-14 14:14:16 -040054 virtual FX_BOOL IsLoaded();
55 virtual FX_BOOL LoadWidget();
56 virtual void UnloadWidget();
57 virtual FX_BOOL PerformLayout();
58 virtual FX_BOOL UpdateFWLData();
59 virtual void UpdateWidgetProperty();
60 virtual FX_BOOL OnMouseEnter();
61 virtual FX_BOOL OnMouseExit();
tsepezdeee3d22016-03-25 14:38:58 -070062 virtual FX_BOOL OnLButtonDown(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy);
63 virtual FX_BOOL OnLButtonUp(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy);
64 virtual FX_BOOL OnLButtonDblClk(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy);
65 virtual FX_BOOL OnMouseMove(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy);
66 virtual FX_BOOL OnMouseWheel(uint32_t dwFlags,
Dan Sinclair1770c022016-03-14 14:14:16 -040067 int16_t zDelta,
68 FX_FLOAT fx,
69 FX_FLOAT fy);
tsepezdeee3d22016-03-25 14:38:58 -070070 virtual FX_BOOL OnRButtonDown(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy);
71 virtual FX_BOOL OnRButtonUp(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy);
72 virtual FX_BOOL OnRButtonDblClk(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy);
Dan Sinclair1770c022016-03-14 14:14:16 -040073
74 virtual FX_BOOL OnSetFocus(CXFA_FFWidget* pOldWidget);
75 virtual FX_BOOL OnKillFocus(CXFA_FFWidget* pNewWidget);
tsepezdeee3d22016-03-25 14:38:58 -070076 virtual FX_BOOL OnKeyDown(uint32_t dwKeyCode, uint32_t dwFlags);
77 virtual FX_BOOL OnKeyUp(uint32_t dwKeyCode, uint32_t dwFlags);
78 virtual FX_BOOL OnChar(uint32_t dwChar, uint32_t dwFlags);
dsinclair89fcde82016-05-03 13:00:25 -070079 virtual FWL_WidgetHit OnHitTest(FX_FLOAT fx, FX_FLOAT fy);
Dan Sinclair1770c022016-03-14 14:14:16 -040080 virtual FX_BOOL OnSetCursor(FX_FLOAT fx, FX_FLOAT fy);
weili47bcd4c2016-06-16 08:00:06 -070081 virtual FX_BOOL CanUndo();
82 virtual FX_BOOL CanRedo();
83 virtual FX_BOOL Undo();
84 virtual FX_BOOL Redo();
85 virtual FX_BOOL CanCopy();
86 virtual FX_BOOL CanCut();
87 virtual FX_BOOL CanPaste();
88 virtual FX_BOOL CanSelectAll();
89 virtual FX_BOOL CanDelete();
90 virtual FX_BOOL CanDeSelect();
91 virtual FX_BOOL Copy(CFX_WideString& wsCopy);
92 virtual FX_BOOL Cut(CFX_WideString& wsCut);
93 virtual FX_BOOL Paste(const CFX_WideString& wsPaste);
94 virtual FX_BOOL SelectAll();
95 virtual FX_BOOL Delete();
96 virtual FX_BOOL DeSelect();
Dan Sinclair1770c022016-03-14 14:14:16 -040097 virtual FX_BOOL GetSuggestWords(CFX_PointF pointf,
weili47bcd4c2016-06-16 08:00:06 -070098 std::vector<CFX_ByteString>& sSuggest);
Dan Sinclair1770c022016-03-14 14:14:16 -040099 virtual FX_BOOL ReplaceSpellCheckWord(CFX_PointF pointf,
weili47bcd4c2016-06-16 08:00:06 -0700100 const CFX_ByteStringC& bsReplace);
101
102 CXFA_FFPageView* GetPageView();
103 void SetPageView(CXFA_FFPageView* pPageView);
104 void GetWidgetRect(CFX_RectF& rtWidget);
105 CFX_RectF ReCacheWidgetRect();
106 uint32_t GetStatus();
107 void ModifyStatus(uint32_t dwAdded, uint32_t dwRemoved);
108
109 CXFA_WidgetAcc* GetDataAcc();
110 FX_BOOL GetToolTip(CFX_WideString& wsToolTip);
111
Dan Sinclair1770c022016-03-14 14:14:16 -0400112 CXFA_FFDocView* GetDocView();
weili47bcd4c2016-06-16 08:00:06 -0700113 void SetDocView(CXFA_FFDocView* pDocView);
Dan Sinclair1770c022016-03-14 14:14:16 -0400114 CXFA_FFDoc* GetDoc();
115 CXFA_FFApp* GetApp();
116 IXFA_AppProvider* GetAppProvider();
dsinclair85d1f2c2016-06-23 12:40:16 -0700117 void InvalidateWidget(const CFX_RectF* pRect = nullptr);
118 void AddInvalidateRect(const CFX_RectF* pRect = nullptr);
Dan Sinclair1770c022016-03-14 14:14:16 -0400119 FX_BOOL GetCaptionText(CFX_WideString& wsCap);
tsepez7d89e722016-05-04 13:38:11 -0700120 bool IsFocused();
Dan Sinclair1770c022016-03-14 14:14:16 -0400121 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);
weili47bcd4c2016-06-16 08:00:06 -0700129
Dan Sinclair1770c022016-03-14 14:14:16 -0400130 void DrawBorder(CFX_Graphics* pGS,
131 CXFA_Box box,
132 const CFX_RectF& rtBorder,
133 CFX_Matrix* pMatrix,
tsepezdeee3d22016-03-25 14:38:58 -0700134 uint32_t dwFlags = 0);
Dan Sinclair1770c022016-03-14 14:14:16 -0400135 void GetMinMaxWidth(FX_FLOAT fMinWidth, FX_FLOAT fMaxWidth);
136 void GetMinMaxHeight(FX_FLOAT fMinHeight, FX_FLOAT fMaxHeight);
137 void GetRectWithoutRotate(CFX_RectF& rtWidget);
tsepez7d89e722016-05-04 13:38:11 -0700138 bool IsMatchVisibleStatus(uint32_t dwStatus);
Dan Sinclair1770c022016-03-14 14:14:16 -0400139 void EventKillFocus();
140 FX_BOOL IsButtonDown();
141 void SetButtonDown(FX_BOOL bSet);
weili47bcd4c2016-06-16 08:00:06 -0700142
Dan Sinclair1770c022016-03-14 14:14:16 -0400143 CXFA_FFDocView* m_pDocView;
144 CXFA_FFPageView* m_pPageView;
145 CXFA_WidgetAcc* m_pDataAcc;
146 CFX_RectF m_rtWidget;
147};
weili47bcd4c2016-06-16 08:00:06 -0700148
Dan Sinclair1770c022016-03-14 14:14:16 -0400149int32_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);
dsinclair56a8b192016-06-21 14:15:25 -0700177FX_BOOL XFA_IsCreateWidget(XFA_Element iType);
Dan Sinclair1770c022016-03-14 14:14:16 -0400178#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_