blob: ef3d908221ab40b1987989edc052ccc1e41025b1 [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
Dan Sinclair80c48782017-03-23 12:11:20 -04007#ifndef XFA_FXFA_CXFA_FFWIDGET_H_
8#define XFA_FXFA_CXFA_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
Dan Sinclair05df0752017-03-14 14:43:42 -040024inline float XFA_UnitPx2Pt(float fPx, float fDpi) {
Dan Sinclair1770c022016-03-14 14:14:16 -040025 return fPx * 72.0f / fDpi;
26}
dan sinclairaaf0bdc2017-02-04 10:16:21 -050027
Dan Sinclair1770c022016-03-14 14:14:16 -040028#define XFA_FLOAT_PERCISION 0.001f
dan sinclairaaf0bdc2017-02-04 10:16:21 -050029
Dan Sinclair1770c022016-03-14 14:14:16 -040030enum XFA_WIDGETITEM {
31 XFA_WIDGETITEM_Parent,
32 XFA_WIDGETITEM_FirstChild,
33 XFA_WIDGETITEM_NextSibling,
34 XFA_WIDGETITEM_PrevSibling,
35};
tsepezbb0d4462016-04-27 16:59:30 -070036
Dan Sinclair80c48782017-03-23 12:11:20 -040037int32_t XFA_StrokeTypeSetLineDash(CFX_Graphics* pGraphics,
38 int32_t iStrokeType,
39 int32_t iCapType);
40CFX_GraphStateData::LineCap XFA_LineCapToFXGE(int32_t iLineCap);
41void XFA_DrawImage(CFX_Graphics* pGS,
42 const CFX_RectF& rtImage,
43 CFX_Matrix* pMatrix,
Tom Sepezf0799fe2017-03-28 09:31:32 -070044 const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap,
Dan Sinclair80c48782017-03-23 12:11:20 -040045 int32_t iAspect,
46 int32_t iImageXDpi,
47 int32_t iImageYDpi,
48 int32_t iHorzAlign = XFA_ATTRIBUTEENUM_Left,
49 int32_t iVertAlign = XFA_ATTRIBUTEENUM_Top);
50
Tom Sepezf0799fe2017-03-28 09:31:32 -070051CFX_RetainPtr<CFX_DIBitmap> XFA_LoadImageData(CXFA_FFDoc* pDoc,
52 CXFA_Image* pImage,
53 bool& bNameImage,
54 int32_t& iImageXDpi,
55 int32_t& iImageYDpi);
Dan Sinclair80c48782017-03-23 12:11:20 -040056
Tom Sepezf0799fe2017-03-28 09:31:32 -070057CFX_RetainPtr<CFX_DIBitmap> XFA_LoadImageFromBuffer(
Dan Sinclair80c48782017-03-23 12:11:20 -040058 const CFX_RetainPtr<IFX_SeekableReadStream>& pImageFileRead,
59 FXCODEC_IMAGE_TYPE type,
60 int32_t& iImageXDpi,
61 int32_t& iImageYDpi);
62
63FXCODEC_IMAGE_TYPE XFA_GetImageType(const CFX_WideString& wsType);
64char* XFA_Base64Encode(const uint8_t* buf, int32_t buf_len);
65void XFA_RectWidthoutMargin(CFX_RectF& rt,
66 const CXFA_Margin& mg,
67 bool bUI = false);
68CXFA_FFWidget* XFA_GetWidgetFromLayoutItem(CXFA_LayoutItem* pLayoutItem);
69bool XFA_IsCreateWidget(XFA_Element iType);
70#define XFA_DRAWBOX_ForceRound 1
71#define XFA_DRAWBOX_Lowered3D 2
72void XFA_DrawBox(CXFA_Box box,
73 CFX_Graphics* pGS,
74 const CFX_RectF& rtWidget,
75 CFX_Matrix* pMatrix,
76 uint32_t dwFlags = 0);
77
Dan Sinclair1770c022016-03-14 14:14:16 -040078class CXFA_CalcData {
79 public:
weili47bcd4c2016-06-16 08:00:06 -070080 CXFA_CalcData();
81 ~CXFA_CalcData();
tsepezbb0d4462016-04-27 16:59:30 -070082
Tom Sepez51d02b32017-01-30 14:49:24 -080083 std::vector<CXFA_WidgetAcc*> m_Globals;
Dan Sinclair1770c022016-03-14 14:14:16 -040084 int32_t m_iRefCount;
85};
tsepezbb0d4462016-04-27 16:59:30 -070086
tsepez7fa55132016-05-25 16:57:11 -070087class CXFA_FFWidget : public CXFA_ContentLayoutItem {
Dan Sinclair1770c022016-03-14 14:14:16 -040088 public:
dan sinclairaaf0bdc2017-02-04 10:16:21 -050089 explicit CXFA_FFWidget(CXFA_WidgetAcc* pDataAcc);
weili47bcd4c2016-06-16 08:00:06 -070090 ~CXFA_FFWidget() override;
91
Dan Sinclair1b08df12017-02-09 09:17:20 -050092 virtual CFX_RectF GetBBox(uint32_t dwStatus, bool bDrawFocus = false);
Dan Sinclair1770c022016-03-14 14:14:16 -040093 virtual void RenderWidget(CFX_Graphics* pGS,
dsinclair9d6ca992016-06-16 10:51:56 -070094 CFX_Matrix* pMatrix,
95 uint32_t dwStatus);
tsepezd19e9122016-11-02 15:43:18 -070096 virtual bool IsLoaded();
97 virtual bool LoadWidget();
Dan Sinclair1770c022016-03-14 14:14:16 -040098 virtual void UnloadWidget();
tsepezd19e9122016-11-02 15:43:18 -070099 virtual bool PerformLayout();
100 virtual bool UpdateFWLData();
Dan Sinclair1770c022016-03-14 14:14:16 -0400101 virtual void UpdateWidgetProperty();
tsepezd19e9122016-11-02 15:43:18 -0700102 virtual bool OnMouseEnter();
103 virtual bool OnMouseExit();
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500104 virtual bool OnLButtonDown(uint32_t dwFlags, const CFX_PointF& point);
105 virtual bool OnLButtonUp(uint32_t dwFlags, const CFX_PointF& point);
106 virtual bool OnLButtonDblClk(uint32_t dwFlags, const CFX_PointF& point);
107 virtual bool OnMouseMove(uint32_t dwFlags, const CFX_PointF& point);
tsepezd19e9122016-11-02 15:43:18 -0700108 virtual bool OnMouseWheel(uint32_t dwFlags,
109 int16_t zDelta,
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500110 const CFX_PointF& point);
111 virtual bool OnRButtonDown(uint32_t dwFlags, const CFX_PointF& point);
112 virtual bool OnRButtonUp(uint32_t dwFlags, const CFX_PointF& point);
113 virtual bool OnRButtonDblClk(uint32_t dwFlags, const CFX_PointF& point);
Dan Sinclair1770c022016-03-14 14:14:16 -0400114
tsepezd19e9122016-11-02 15:43:18 -0700115 virtual bool OnSetFocus(CXFA_FFWidget* pOldWidget);
116 virtual bool OnKillFocus(CXFA_FFWidget* pNewWidget);
117 virtual bool OnKeyDown(uint32_t dwKeyCode, uint32_t dwFlags);
118 virtual bool OnKeyUp(uint32_t dwKeyCode, uint32_t dwFlags);
119 virtual bool OnChar(uint32_t dwChar, uint32_t dwFlags);
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500120 virtual FWL_WidgetHit OnHitTest(const CFX_PointF& point);
121 virtual bool OnSetCursor(const CFX_PointF& point);
tsepezd19e9122016-11-02 15:43:18 -0700122 virtual bool CanUndo();
123 virtual bool CanRedo();
124 virtual bool Undo();
125 virtual bool Redo();
126 virtual bool CanCopy();
127 virtual bool CanCut();
128 virtual bool CanPaste();
129 virtual bool CanSelectAll();
130 virtual bool CanDelete();
131 virtual bool CanDeSelect();
132 virtual bool Copy(CFX_WideString& wsCopy);
133 virtual bool Cut(CFX_WideString& wsCut);
134 virtual bool Paste(const CFX_WideString& wsPaste);
dsinclair14a60c52016-11-16 12:15:27 -0800135 virtual void SelectAll();
136 virtual void Delete();
137 virtual void DeSelect();
tsepezd19e9122016-11-02 15:43:18 -0700138 virtual bool GetSuggestWords(CFX_PointF pointf,
139 std::vector<CFX_ByteString>& sSuggest);
140 virtual bool ReplaceSpellCheckWord(CFX_PointF pointf,
141 const CFX_ByteStringC& bsReplace);
weili47bcd4c2016-06-16 08:00:06 -0700142
dan sinclairaaf0bdc2017-02-04 10:16:21 -0500143 CXFA_FFPageView* GetPageView() const { return m_pPageView; }
144 void SetPageView(CXFA_FFPageView* pPageView) { m_pPageView = pPageView; }
Lei Zhangafc8eb32017-03-28 14:32:13 -0700145 const CFX_RectF& GetWidgetRect() const;
146 const CFX_RectF& RecacheWidgetRect() const;
weili47bcd4c2016-06-16 08:00:06 -0700147 uint32_t GetStatus();
148 void ModifyStatus(uint32_t dwAdded, uint32_t dwRemoved);
149
150 CXFA_WidgetAcc* GetDataAcc();
tsepezd19e9122016-11-02 15:43:18 -0700151 bool GetToolTip(CFX_WideString& wsToolTip);
weili47bcd4c2016-06-16 08:00:06 -0700152
Dan Sinclair1770c022016-03-14 14:14:16 -0400153 CXFA_FFDocView* GetDocView();
weili47bcd4c2016-06-16 08:00:06 -0700154 void SetDocView(CXFA_FFDocView* pDocView);
Dan Sinclair1770c022016-03-14 14:14:16 -0400155 CXFA_FFDoc* GetDoc();
156 CXFA_FFApp* GetApp();
157 IXFA_AppProvider* GetAppProvider();
dsinclair85d1f2c2016-06-23 12:40:16 -0700158 void InvalidateWidget(const CFX_RectF* pRect = nullptr);
159 void AddInvalidateRect(const CFX_RectF* pRect = nullptr);
tsepezd19e9122016-11-02 15:43:18 -0700160 bool GetCaptionText(CFX_WideString& wsCap);
tsepez7d89e722016-05-04 13:38:11 -0700161 bool IsFocused();
Dan Sinclair1f403ce2017-02-21 12:56:24 -0500162 CFX_PointF Rotate2Normal(const CFX_PointF& point);
Dan Sinclair1b08df12017-02-09 09:17:20 -0500163 CFX_Matrix GetRotateMatrix();
tsepezd19e9122016-11-02 15:43:18 -0700164 bool IsLayoutRectEmpty();
Dan Sinclair1770c022016-03-14 14:14:16 -0400165 CXFA_FFWidget* GetParent();
tsepezd19e9122016-11-02 15:43:18 -0700166 bool IsAncestorOf(CXFA_FFWidget* pWidget);
dsinclair1a7534a2016-11-22 15:56:11 -0800167 const CFWL_App* GetFWLApp();
Dan Sinclair1770c022016-03-14 14:14:16 -0400168
169 protected:
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500170 virtual bool PtInActiveRect(const CFX_PointF& point);
weili47bcd4c2016-06-16 08:00:06 -0700171
Dan Sinclair1770c022016-03-14 14:14:16 -0400172 void DrawBorder(CFX_Graphics* pGS,
173 CXFA_Box box,
174 const CFX_RectF& rtBorder,
175 CFX_Matrix* pMatrix,
tsepezdeee3d22016-03-25 14:38:58 -0700176 uint32_t dwFlags = 0);
Dan Sinclair1b08df12017-02-09 09:17:20 -0500177
178 CFX_RectF GetRectWithoutRotate();
tsepez7d89e722016-05-04 13:38:11 -0700179 bool IsMatchVisibleStatus(uint32_t dwStatus);
Dan Sinclair1770c022016-03-14 14:14:16 -0400180 void EventKillFocus();
tsepezd19e9122016-11-02 15:43:18 -0700181 bool IsButtonDown();
182 void SetButtonDown(bool bSet);
weili47bcd4c2016-06-16 08:00:06 -0700183
Dan Sinclair1770c022016-03-14 14:14:16 -0400184 CXFA_FFDocView* m_pDocView;
185 CXFA_FFPageView* m_pPageView;
Lei Zhangafc8eb32017-03-28 14:32:13 -0700186 CXFA_WidgetAcc* const m_pDataAcc;
187 mutable CFX_RectF m_rtWidget;
Dan Sinclair1770c022016-03-14 14:14:16 -0400188};
weili47bcd4c2016-06-16 08:00:06 -0700189
Dan Sinclair80c48782017-03-23 12:11:20 -0400190#endif // XFA_FXFA_CXFA_FFWIDGET_H_