blob: 009cd44dc03157982b299875e75ccd0d9e494466 [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
dsinclair5b493092016-09-29 20:20:24 -07007#ifndef XFA_FXFA_XFA_FFWIDGET_H_
8#define XFA_FXFA_XFA_FFWIDGET_H_
Dan Sinclair1770c022016-03-14 14:14:16 -04009
10#include <vector>
11
dsinclair8a4e2862016-09-29 13:43:30 -070012#include "core/fxcodec/fx_codec_def.h"
dsinclair74a34fc2016-09-29 16:41:42 -070013#include "core/fxge/cfx_graphstatedata.h"
dsinclair447b1f32016-12-08 10:06:32 -080014#include "xfa/fwl/cfwl_app.h"
dsinclair5b493092016-09-29 20:20:24 -070015#include "xfa/fxfa/fxfa.h"
dsinclair0b851ff2016-07-21 12:03:01 -070016#include "xfa/fxfa/parser/cxfa_contentlayoutitem.h"
Dan Sinclair1770c022016-03-14 14:14:16 -040017
18class CXFA_FFPageView;
19class CXFA_FFDocView;
20class CXFA_FFDoc;
21class CXFA_FFApp;
dsinclair89fcde82016-05-03 13:00:25 -070022enum class FWL_WidgetHit;
Dan Sinclair1770c022016-03-14 14:14:16 -040023
24inline FX_FLOAT XFA_UnitPx2Pt(FX_FLOAT fPx, FX_FLOAT fDpi) {
25 return fPx * 72.0f / fDpi;
26}
27#define XFA_FLOAT_PERCISION 0.001f
28enum XFA_WIDGETITEM {
29 XFA_WIDGETITEM_Parent,
30 XFA_WIDGETITEM_FirstChild,
31 XFA_WIDGETITEM_NextSibling,
32 XFA_WIDGETITEM_PrevSibling,
33};
tsepezbb0d4462016-04-27 16:59:30 -070034
Dan Sinclair1770c022016-03-14 14:14:16 -040035class CXFA_CalcData {
36 public:
weili47bcd4c2016-06-16 08:00:06 -070037 CXFA_CalcData();
38 ~CXFA_CalcData();
tsepezbb0d4462016-04-27 16:59:30 -070039
Tom Sepez51d02b32017-01-30 14:49:24 -080040 std::vector<CXFA_WidgetAcc*> m_Globals;
Dan Sinclair1770c022016-03-14 14:14:16 -040041 int32_t m_iRefCount;
42};
tsepezbb0d4462016-04-27 16:59:30 -070043
tsepez7fa55132016-05-25 16:57:11 -070044class CXFA_FFWidget : public CXFA_ContentLayoutItem {
Dan Sinclair1770c022016-03-14 14:14:16 -040045 public:
46 CXFA_FFWidget(CXFA_FFPageView* pPageView, CXFA_WidgetAcc* pDataAcc);
weili47bcd4c2016-06-16 08:00:06 -070047 ~CXFA_FFWidget() override;
48
tsepezd19e9122016-11-02 15:43:18 -070049 virtual bool GetBBox(CFX_RectF& rtBox,
50 uint32_t dwStatus,
51 bool bDrawFocus = false);
Dan Sinclair1770c022016-03-14 14:14:16 -040052 virtual void RenderWidget(CFX_Graphics* pGS,
dsinclair9d6ca992016-06-16 10:51:56 -070053 CFX_Matrix* pMatrix,
54 uint32_t dwStatus);
tsepezd19e9122016-11-02 15:43:18 -070055 virtual bool IsLoaded();
56 virtual bool LoadWidget();
Dan Sinclair1770c022016-03-14 14:14:16 -040057 virtual void UnloadWidget();
tsepezd19e9122016-11-02 15:43:18 -070058 virtual bool PerformLayout();
59 virtual bool UpdateFWLData();
Dan Sinclair1770c022016-03-14 14:14:16 -040060 virtual void UpdateWidgetProperty();
tsepezd19e9122016-11-02 15:43:18 -070061 virtual bool OnMouseEnter();
62 virtual bool OnMouseExit();
63 virtual bool OnLButtonDown(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy);
64 virtual bool OnLButtonUp(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy);
65 virtual bool OnLButtonDblClk(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy);
66 virtual bool OnMouseMove(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy);
67 virtual bool OnMouseWheel(uint32_t dwFlags,
68 int16_t zDelta,
69 FX_FLOAT fx,
70 FX_FLOAT fy);
71 virtual bool OnRButtonDown(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy);
72 virtual bool OnRButtonUp(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy);
73 virtual bool OnRButtonDblClk(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy);
Dan Sinclair1770c022016-03-14 14:14:16 -040074
tsepezd19e9122016-11-02 15:43:18 -070075 virtual bool OnSetFocus(CXFA_FFWidget* pOldWidget);
76 virtual bool OnKillFocus(CXFA_FFWidget* pNewWidget);
77 virtual bool OnKeyDown(uint32_t dwKeyCode, uint32_t dwFlags);
78 virtual bool OnKeyUp(uint32_t dwKeyCode, uint32_t dwFlags);
79 virtual bool OnChar(uint32_t dwChar, uint32_t dwFlags);
dsinclair89fcde82016-05-03 13:00:25 -070080 virtual FWL_WidgetHit OnHitTest(FX_FLOAT fx, FX_FLOAT fy);
tsepezd19e9122016-11-02 15:43:18 -070081 virtual bool OnSetCursor(FX_FLOAT fx, FX_FLOAT fy);
82 virtual bool CanUndo();
83 virtual bool CanRedo();
84 virtual bool Undo();
85 virtual bool Redo();
86 virtual bool CanCopy();
87 virtual bool CanCut();
88 virtual bool CanPaste();
89 virtual bool CanSelectAll();
90 virtual bool CanDelete();
91 virtual bool CanDeSelect();
92 virtual bool Copy(CFX_WideString& wsCopy);
93 virtual bool Cut(CFX_WideString& wsCut);
94 virtual bool Paste(const CFX_WideString& wsPaste);
dsinclair14a60c52016-11-16 12:15:27 -080095 virtual void SelectAll();
96 virtual void Delete();
97 virtual void DeSelect();
tsepezd19e9122016-11-02 15:43:18 -070098 virtual bool GetSuggestWords(CFX_PointF pointf,
99 std::vector<CFX_ByteString>& sSuggest);
100 virtual bool ReplaceSpellCheckWord(CFX_PointF pointf,
101 const CFX_ByteStringC& bsReplace);
weili47bcd4c2016-06-16 08:00:06 -0700102
103 CXFA_FFPageView* GetPageView();
104 void SetPageView(CXFA_FFPageView* pPageView);
105 void GetWidgetRect(CFX_RectF& rtWidget);
106 CFX_RectF ReCacheWidgetRect();
107 uint32_t GetStatus();
108 void ModifyStatus(uint32_t dwAdded, uint32_t dwRemoved);
109
110 CXFA_WidgetAcc* GetDataAcc();
tsepezd19e9122016-11-02 15:43:18 -0700111 bool GetToolTip(CFX_WideString& wsToolTip);
weili47bcd4c2016-06-16 08:00:06 -0700112
Dan Sinclair1770c022016-03-14 14:14:16 -0400113 CXFA_FFDocView* GetDocView();
weili47bcd4c2016-06-16 08:00:06 -0700114 void SetDocView(CXFA_FFDocView* pDocView);
Dan Sinclair1770c022016-03-14 14:14:16 -0400115 CXFA_FFDoc* GetDoc();
116 CXFA_FFApp* GetApp();
117 IXFA_AppProvider* GetAppProvider();
dsinclair85d1f2c2016-06-23 12:40:16 -0700118 void InvalidateWidget(const CFX_RectF* pRect = nullptr);
119 void AddInvalidateRect(const CFX_RectF* pRect = nullptr);
tsepezd19e9122016-11-02 15:43:18 -0700120 bool GetCaptionText(CFX_WideString& wsCap);
tsepez7d89e722016-05-04 13:38:11 -0700121 bool IsFocused();
Dan Sinclair1770c022016-03-14 14:14:16 -0400122 void Rotate2Normal(FX_FLOAT& fx, FX_FLOAT& fy);
123 void GetRotateMatrix(CFX_Matrix& mt);
tsepezd19e9122016-11-02 15:43:18 -0700124 bool IsLayoutRectEmpty();
Dan Sinclair1770c022016-03-14 14:14:16 -0400125 CXFA_FFWidget* GetParent();
tsepezd19e9122016-11-02 15:43:18 -0700126 bool IsAncestorOf(CXFA_FFWidget* pWidget);
dsinclair1a7534a2016-11-22 15:56:11 -0800127 const CFWL_App* GetFWLApp();
Dan Sinclair1770c022016-03-14 14:14:16 -0400128
129 protected:
tsepezd19e9122016-11-02 15:43:18 -0700130 virtual bool PtInActiveRect(FX_FLOAT fx, FX_FLOAT fy);
weili47bcd4c2016-06-16 08:00:06 -0700131
Dan Sinclair1770c022016-03-14 14:14:16 -0400132 void DrawBorder(CFX_Graphics* pGS,
133 CXFA_Box box,
134 const CFX_RectF& rtBorder,
135 CFX_Matrix* pMatrix,
tsepezdeee3d22016-03-25 14:38:58 -0700136 uint32_t dwFlags = 0);
Dan Sinclair1770c022016-03-14 14:14:16 -0400137 void GetMinMaxWidth(FX_FLOAT fMinWidth, FX_FLOAT fMaxWidth);
138 void GetMinMaxHeight(FX_FLOAT fMinHeight, FX_FLOAT fMaxHeight);
139 void GetRectWithoutRotate(CFX_RectF& rtWidget);
tsepez7d89e722016-05-04 13:38:11 -0700140 bool IsMatchVisibleStatus(uint32_t dwStatus);
Dan Sinclair1770c022016-03-14 14:14:16 -0400141 void EventKillFocus();
tsepezd19e9122016-11-02 15:43:18 -0700142 bool IsButtonDown();
143 void SetButtonDown(bool bSet);
weili47bcd4c2016-06-16 08:00:06 -0700144
Dan Sinclair1770c022016-03-14 14:14:16 -0400145 CXFA_FFDocView* m_pDocView;
146 CXFA_FFPageView* m_pPageView;
147 CXFA_WidgetAcc* m_pDataAcc;
148 CFX_RectF m_rtWidget;
149};
weili47bcd4c2016-06-16 08:00:06 -0700150
Dan Sinclair1770c022016-03-14 14:14:16 -0400151int32_t XFA_StrokeTypeSetLineDash(CFX_Graphics* pGraphics,
152 int32_t iStrokeType,
153 int32_t iCapType);
154CFX_GraphStateData::LineCap XFA_LineCapToFXGE(int32_t iLineCap);
155void XFA_DrawImage(CFX_Graphics* pGS,
156 const CFX_RectF& rtImage,
157 CFX_Matrix* pMatrix,
158 CFX_DIBitmap* pDIBitmap,
159 int32_t iAspect,
160 int32_t iImageXDpi,
161 int32_t iImageYDpi,
162 int32_t iHorzAlign = XFA_ATTRIBUTEENUM_Left,
163 int32_t iVertAlign = XFA_ATTRIBUTEENUM_Top);
tsepez833619b2016-12-07 09:21:17 -0800164
Dan Sinclair1770c022016-03-14 14:14:16 -0400165CFX_DIBitmap* XFA_LoadImageData(CXFA_FFDoc* pDoc,
166 CXFA_Image* pImage,
tsepezd19e9122016-11-02 15:43:18 -0700167 bool& bNameImage,
Dan Sinclair1770c022016-03-14 14:14:16 -0400168 int32_t& iImageXDpi,
169 int32_t& iImageYDpi);
tsepez833619b2016-12-07 09:21:17 -0800170
171CFX_DIBitmap* XFA_LoadImageFromBuffer(
172 const CFX_RetainPtr<IFX_SeekableReadStream>& pImageFileRead,
173 FXCODEC_IMAGE_TYPE type,
174 int32_t& iImageXDpi,
175 int32_t& iImageYDpi);
176
tsepezfc58ad12016-04-05 12:22:15 -0700177FXCODEC_IMAGE_TYPE XFA_GetImageType(const CFX_WideString& wsType);
Dan Sinclair1770c022016-03-14 14:14:16 -0400178FX_CHAR* XFA_Base64Encode(const uint8_t* buf, int32_t buf_len);
179void XFA_RectWidthoutMargin(CFX_RectF& rt,
180 const CXFA_Margin& mg,
tsepezd19e9122016-11-02 15:43:18 -0700181 bool bUI = false);
Dan Sinclair1770c022016-03-14 14:14:16 -0400182CXFA_FFWidget* XFA_GetWidgetFromLayoutItem(CXFA_LayoutItem* pLayoutItem);
tsepezd19e9122016-11-02 15:43:18 -0700183bool XFA_IsCreateWidget(XFA_Element iType);
Dan Sinclair1770c022016-03-14 14:14:16 -0400184#define XFA_DRAWBOX_ForceRound 1
185#define XFA_DRAWBOX_Lowered3D 2
186void XFA_DrawBox(CXFA_Box box,
187 CFX_Graphics* pGS,
188 const CFX_RectF& rtWidget,
189 CFX_Matrix* pMatrix,
tsepezdeee3d22016-03-25 14:38:58 -0700190 uint32_t dwFlags = 0);
Dan Sinclair1770c022016-03-14 14:14:16 -0400191
dsinclair5b493092016-09-29 20:20:24 -0700192#endif // XFA_FXFA_XFA_FFWIDGET_H_