Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 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 | |
dsinclair | 5b49309 | 2016-09-29 20:20:24 -0700 | [diff] [blame] | 7 | #ifndef XFA_FXFA_XFA_FFWIDGET_H_ |
| 8 | #define XFA_FXFA_XFA_FFWIDGET_H_ |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 9 | |
| 10 | #include <vector> |
| 11 | |
dsinclair | 8a4e286 | 2016-09-29 13:43:30 -0700 | [diff] [blame] | 12 | #include "core/fxcodec/fx_codec_def.h" |
dsinclair | 74a34fc | 2016-09-29 16:41:42 -0700 | [diff] [blame] | 13 | #include "core/fxge/cfx_graphstatedata.h" |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 14 | #include "xfa/fwl/cfwl_app.h" |
dsinclair | 5b49309 | 2016-09-29 20:20:24 -0700 | [diff] [blame] | 15 | #include "xfa/fxfa/fxfa.h" |
dsinclair | 0b851ff | 2016-07-21 12:03:01 -0700 | [diff] [blame] | 16 | #include "xfa/fxfa/parser/cxfa_contentlayoutitem.h" |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 17 | |
| 18 | class CXFA_FFPageView; |
| 19 | class CXFA_FFDocView; |
| 20 | class CXFA_FFDoc; |
| 21 | class CXFA_FFApp; |
dsinclair | 89fcde8 | 2016-05-03 13:00:25 -0700 | [diff] [blame] | 22 | enum class FWL_WidgetHit; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 23 | |
| 24 | inline FX_FLOAT XFA_UnitPx2Pt(FX_FLOAT fPx, FX_FLOAT fDpi) { |
| 25 | return fPx * 72.0f / fDpi; |
| 26 | } |
| 27 | #define XFA_FLOAT_PERCISION 0.001f |
| 28 | enum XFA_WIDGETITEM { |
| 29 | XFA_WIDGETITEM_Parent, |
| 30 | XFA_WIDGETITEM_FirstChild, |
| 31 | XFA_WIDGETITEM_NextSibling, |
| 32 | XFA_WIDGETITEM_PrevSibling, |
| 33 | }; |
tsepez | bb0d446 | 2016-04-27 16:59:30 -0700 | [diff] [blame] | 34 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 35 | class CXFA_CalcData { |
| 36 | public: |
weili | 47bcd4c | 2016-06-16 08:00:06 -0700 | [diff] [blame] | 37 | CXFA_CalcData(); |
| 38 | ~CXFA_CalcData(); |
tsepez | bb0d446 | 2016-04-27 16:59:30 -0700 | [diff] [blame] | 39 | |
Tom Sepez | 51d02b3 | 2017-01-30 14:49:24 -0800 | [diff] [blame^] | 40 | std::vector<CXFA_WidgetAcc*> m_Globals; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 41 | int32_t m_iRefCount; |
| 42 | }; |
tsepez | bb0d446 | 2016-04-27 16:59:30 -0700 | [diff] [blame] | 43 | |
tsepez | 7fa5513 | 2016-05-25 16:57:11 -0700 | [diff] [blame] | 44 | class CXFA_FFWidget : public CXFA_ContentLayoutItem { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 45 | public: |
| 46 | CXFA_FFWidget(CXFA_FFPageView* pPageView, CXFA_WidgetAcc* pDataAcc); |
weili | 47bcd4c | 2016-06-16 08:00:06 -0700 | [diff] [blame] | 47 | ~CXFA_FFWidget() override; |
| 48 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 49 | virtual bool GetBBox(CFX_RectF& rtBox, |
| 50 | uint32_t dwStatus, |
| 51 | bool bDrawFocus = false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 52 | virtual void RenderWidget(CFX_Graphics* pGS, |
dsinclair | 9d6ca99 | 2016-06-16 10:51:56 -0700 | [diff] [blame] | 53 | CFX_Matrix* pMatrix, |
| 54 | uint32_t dwStatus); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 55 | virtual bool IsLoaded(); |
| 56 | virtual bool LoadWidget(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 57 | virtual void UnloadWidget(); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 58 | virtual bool PerformLayout(); |
| 59 | virtual bool UpdateFWLData(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 60 | virtual void UpdateWidgetProperty(); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 61 | 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 Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 74 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 75 | 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); |
dsinclair | 89fcde8 | 2016-05-03 13:00:25 -0700 | [diff] [blame] | 80 | virtual FWL_WidgetHit OnHitTest(FX_FLOAT fx, FX_FLOAT fy); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 81 | 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); |
dsinclair | 14a60c5 | 2016-11-16 12:15:27 -0800 | [diff] [blame] | 95 | virtual void SelectAll(); |
| 96 | virtual void Delete(); |
| 97 | virtual void DeSelect(); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 98 | virtual bool GetSuggestWords(CFX_PointF pointf, |
| 99 | std::vector<CFX_ByteString>& sSuggest); |
| 100 | virtual bool ReplaceSpellCheckWord(CFX_PointF pointf, |
| 101 | const CFX_ByteStringC& bsReplace); |
weili | 47bcd4c | 2016-06-16 08:00:06 -0700 | [diff] [blame] | 102 | |
| 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(); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 111 | bool GetToolTip(CFX_WideString& wsToolTip); |
weili | 47bcd4c | 2016-06-16 08:00:06 -0700 | [diff] [blame] | 112 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 113 | CXFA_FFDocView* GetDocView(); |
weili | 47bcd4c | 2016-06-16 08:00:06 -0700 | [diff] [blame] | 114 | void SetDocView(CXFA_FFDocView* pDocView); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 115 | CXFA_FFDoc* GetDoc(); |
| 116 | CXFA_FFApp* GetApp(); |
| 117 | IXFA_AppProvider* GetAppProvider(); |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 118 | void InvalidateWidget(const CFX_RectF* pRect = nullptr); |
| 119 | void AddInvalidateRect(const CFX_RectF* pRect = nullptr); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 120 | bool GetCaptionText(CFX_WideString& wsCap); |
tsepez | 7d89e72 | 2016-05-04 13:38:11 -0700 | [diff] [blame] | 121 | bool IsFocused(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 122 | void Rotate2Normal(FX_FLOAT& fx, FX_FLOAT& fy); |
| 123 | void GetRotateMatrix(CFX_Matrix& mt); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 124 | bool IsLayoutRectEmpty(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 125 | CXFA_FFWidget* GetParent(); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 126 | bool IsAncestorOf(CXFA_FFWidget* pWidget); |
dsinclair | 1a7534a | 2016-11-22 15:56:11 -0800 | [diff] [blame] | 127 | const CFWL_App* GetFWLApp(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 128 | |
| 129 | protected: |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 130 | virtual bool PtInActiveRect(FX_FLOAT fx, FX_FLOAT fy); |
weili | 47bcd4c | 2016-06-16 08:00:06 -0700 | [diff] [blame] | 131 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 132 | void DrawBorder(CFX_Graphics* pGS, |
| 133 | CXFA_Box box, |
| 134 | const CFX_RectF& rtBorder, |
| 135 | CFX_Matrix* pMatrix, |
tsepez | deee3d2 | 2016-03-25 14:38:58 -0700 | [diff] [blame] | 136 | uint32_t dwFlags = 0); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 137 | void GetMinMaxWidth(FX_FLOAT fMinWidth, FX_FLOAT fMaxWidth); |
| 138 | void GetMinMaxHeight(FX_FLOAT fMinHeight, FX_FLOAT fMaxHeight); |
| 139 | void GetRectWithoutRotate(CFX_RectF& rtWidget); |
tsepez | 7d89e72 | 2016-05-04 13:38:11 -0700 | [diff] [blame] | 140 | bool IsMatchVisibleStatus(uint32_t dwStatus); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 141 | void EventKillFocus(); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 142 | bool IsButtonDown(); |
| 143 | void SetButtonDown(bool bSet); |
weili | 47bcd4c | 2016-06-16 08:00:06 -0700 | [diff] [blame] | 144 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 145 | CXFA_FFDocView* m_pDocView; |
| 146 | CXFA_FFPageView* m_pPageView; |
| 147 | CXFA_WidgetAcc* m_pDataAcc; |
| 148 | CFX_RectF m_rtWidget; |
| 149 | }; |
weili | 47bcd4c | 2016-06-16 08:00:06 -0700 | [diff] [blame] | 150 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 151 | int32_t XFA_StrokeTypeSetLineDash(CFX_Graphics* pGraphics, |
| 152 | int32_t iStrokeType, |
| 153 | int32_t iCapType); |
| 154 | CFX_GraphStateData::LineCap XFA_LineCapToFXGE(int32_t iLineCap); |
| 155 | void 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); |
tsepez | 833619b | 2016-12-07 09:21:17 -0800 | [diff] [blame] | 164 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 165 | CFX_DIBitmap* XFA_LoadImageData(CXFA_FFDoc* pDoc, |
| 166 | CXFA_Image* pImage, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 167 | bool& bNameImage, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 168 | int32_t& iImageXDpi, |
| 169 | int32_t& iImageYDpi); |
tsepez | 833619b | 2016-12-07 09:21:17 -0800 | [diff] [blame] | 170 | |
| 171 | CFX_DIBitmap* XFA_LoadImageFromBuffer( |
| 172 | const CFX_RetainPtr<IFX_SeekableReadStream>& pImageFileRead, |
| 173 | FXCODEC_IMAGE_TYPE type, |
| 174 | int32_t& iImageXDpi, |
| 175 | int32_t& iImageYDpi); |
| 176 | |
tsepez | fc58ad1 | 2016-04-05 12:22:15 -0700 | [diff] [blame] | 177 | FXCODEC_IMAGE_TYPE XFA_GetImageType(const CFX_WideString& wsType); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 178 | FX_CHAR* XFA_Base64Encode(const uint8_t* buf, int32_t buf_len); |
| 179 | void XFA_RectWidthoutMargin(CFX_RectF& rt, |
| 180 | const CXFA_Margin& mg, |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 181 | bool bUI = false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 182 | CXFA_FFWidget* XFA_GetWidgetFromLayoutItem(CXFA_LayoutItem* pLayoutItem); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 183 | bool XFA_IsCreateWidget(XFA_Element iType); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 184 | #define XFA_DRAWBOX_ForceRound 1 |
| 185 | #define XFA_DRAWBOX_Lowered3D 2 |
| 186 | void XFA_DrawBox(CXFA_Box box, |
| 187 | CFX_Graphics* pGS, |
| 188 | const CFX_RectF& rtWidget, |
| 189 | CFX_Matrix* pMatrix, |
tsepez | deee3d2 | 2016-03-25 14:38:58 -0700 | [diff] [blame] | 190 | uint32_t dwFlags = 0); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 191 | |
dsinclair | 5b49309 | 2016-09-29 20:20:24 -0700 | [diff] [blame] | 192 | #endif // XFA_FXFA_XFA_FFWIDGET_H_ |