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 | |
Dan Sinclair | 80c4878 | 2017-03-23 12:11:20 -0400 | [diff] [blame] | 7 | #ifndef XFA_FXFA_CXFA_FFWIDGET_H_ |
| 8 | #define XFA_FXFA_CXFA_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 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 24 | inline float XFA_UnitPx2Pt(float fPx, float fDpi) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 25 | return fPx * 72.0f / fDpi; |
| 26 | } |
dan sinclair | aaf0bdc | 2017-02-04 10:16:21 -0500 | [diff] [blame] | 27 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 28 | #define XFA_FLOAT_PERCISION 0.001f |
dan sinclair | aaf0bdc | 2017-02-04 10:16:21 -0500 | [diff] [blame] | 29 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 30 | enum XFA_WIDGETITEM { |
| 31 | XFA_WIDGETITEM_Parent, |
| 32 | XFA_WIDGETITEM_FirstChild, |
| 33 | XFA_WIDGETITEM_NextSibling, |
| 34 | XFA_WIDGETITEM_PrevSibling, |
| 35 | }; |
tsepez | bb0d446 | 2016-04-27 16:59:30 -0700 | [diff] [blame] | 36 | |
Dan Sinclair | 80c4878 | 2017-03-23 12:11:20 -0400 | [diff] [blame] | 37 | int32_t XFA_StrokeTypeSetLineDash(CFX_Graphics* pGraphics, |
| 38 | int32_t iStrokeType, |
| 39 | int32_t iCapType); |
| 40 | CFX_GraphStateData::LineCap XFA_LineCapToFXGE(int32_t iLineCap); |
| 41 | void XFA_DrawImage(CFX_Graphics* pGS, |
| 42 | const CFX_RectF& rtImage, |
| 43 | CFX_Matrix* pMatrix, |
Tom Sepez | f0799fe | 2017-03-28 09:31:32 -0700 | [diff] [blame] | 44 | const CFX_RetainPtr<CFX_DIBitmap>& pDIBitmap, |
Dan Sinclair | 80c4878 | 2017-03-23 12:11:20 -0400 | [diff] [blame] | 45 | 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 Sepez | f0799fe | 2017-03-28 09:31:32 -0700 | [diff] [blame] | 51 | CFX_RetainPtr<CFX_DIBitmap> XFA_LoadImageData(CXFA_FFDoc* pDoc, |
| 52 | CXFA_Image* pImage, |
| 53 | bool& bNameImage, |
| 54 | int32_t& iImageXDpi, |
| 55 | int32_t& iImageYDpi); |
Dan Sinclair | 80c4878 | 2017-03-23 12:11:20 -0400 | [diff] [blame] | 56 | |
Tom Sepez | f0799fe | 2017-03-28 09:31:32 -0700 | [diff] [blame] | 57 | CFX_RetainPtr<CFX_DIBitmap> XFA_LoadImageFromBuffer( |
Dan Sinclair | 80c4878 | 2017-03-23 12:11:20 -0400 | [diff] [blame] | 58 | const CFX_RetainPtr<IFX_SeekableReadStream>& pImageFileRead, |
| 59 | FXCODEC_IMAGE_TYPE type, |
| 60 | int32_t& iImageXDpi, |
| 61 | int32_t& iImageYDpi); |
| 62 | |
| 63 | FXCODEC_IMAGE_TYPE XFA_GetImageType(const CFX_WideString& wsType); |
| 64 | char* XFA_Base64Encode(const uint8_t* buf, int32_t buf_len); |
| 65 | void XFA_RectWidthoutMargin(CFX_RectF& rt, |
| 66 | const CXFA_Margin& mg, |
| 67 | bool bUI = false); |
| 68 | CXFA_FFWidget* XFA_GetWidgetFromLayoutItem(CXFA_LayoutItem* pLayoutItem); |
| 69 | bool XFA_IsCreateWidget(XFA_Element iType); |
| 70 | #define XFA_DRAWBOX_ForceRound 1 |
| 71 | #define XFA_DRAWBOX_Lowered3D 2 |
| 72 | void 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 Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 78 | class CXFA_CalcData { |
| 79 | public: |
weili | 47bcd4c | 2016-06-16 08:00:06 -0700 | [diff] [blame] | 80 | CXFA_CalcData(); |
| 81 | ~CXFA_CalcData(); |
tsepez | bb0d446 | 2016-04-27 16:59:30 -0700 | [diff] [blame] | 82 | |
Tom Sepez | 51d02b3 | 2017-01-30 14:49:24 -0800 | [diff] [blame] | 83 | std::vector<CXFA_WidgetAcc*> m_Globals; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 84 | int32_t m_iRefCount; |
| 85 | }; |
tsepez | bb0d446 | 2016-04-27 16:59:30 -0700 | [diff] [blame] | 86 | |
tsepez | 7fa5513 | 2016-05-25 16:57:11 -0700 | [diff] [blame] | 87 | class CXFA_FFWidget : public CXFA_ContentLayoutItem { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 88 | public: |
dan sinclair | aaf0bdc | 2017-02-04 10:16:21 -0500 | [diff] [blame] | 89 | explicit CXFA_FFWidget(CXFA_WidgetAcc* pDataAcc); |
weili | 47bcd4c | 2016-06-16 08:00:06 -0700 | [diff] [blame] | 90 | ~CXFA_FFWidget() override; |
| 91 | |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 92 | virtual CFX_RectF GetBBox(uint32_t dwStatus, bool bDrawFocus = false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 93 | virtual void RenderWidget(CFX_Graphics* pGS, |
dsinclair | 9d6ca99 | 2016-06-16 10:51:56 -0700 | [diff] [blame] | 94 | CFX_Matrix* pMatrix, |
| 95 | uint32_t dwStatus); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 96 | virtual bool IsLoaded(); |
| 97 | virtual bool LoadWidget(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 98 | virtual void UnloadWidget(); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 99 | virtual bool PerformLayout(); |
| 100 | virtual bool UpdateFWLData(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 101 | virtual void UpdateWidgetProperty(); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 102 | virtual bool OnMouseEnter(); |
| 103 | virtual bool OnMouseExit(); |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 104 | 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); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 108 | virtual bool OnMouseWheel(uint32_t dwFlags, |
| 109 | int16_t zDelta, |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 110 | 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 Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 114 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 115 | 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 Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 120 | virtual FWL_WidgetHit OnHitTest(const CFX_PointF& point); |
| 121 | virtual bool OnSetCursor(const CFX_PointF& point); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 122 | 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); |
dsinclair | 14a60c5 | 2016-11-16 12:15:27 -0800 | [diff] [blame] | 135 | virtual void SelectAll(); |
| 136 | virtual void Delete(); |
| 137 | virtual void DeSelect(); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 138 | virtual bool GetSuggestWords(CFX_PointF pointf, |
| 139 | std::vector<CFX_ByteString>& sSuggest); |
| 140 | virtual bool ReplaceSpellCheckWord(CFX_PointF pointf, |
| 141 | const CFX_ByteStringC& bsReplace); |
weili | 47bcd4c | 2016-06-16 08:00:06 -0700 | [diff] [blame] | 142 | |
dan sinclair | aaf0bdc | 2017-02-04 10:16:21 -0500 | [diff] [blame] | 143 | CXFA_FFPageView* GetPageView() const { return m_pPageView; } |
| 144 | void SetPageView(CXFA_FFPageView* pPageView) { m_pPageView = pPageView; } |
Lei Zhang | afc8eb3 | 2017-03-28 14:32:13 -0700 | [diff] [blame^] | 145 | const CFX_RectF& GetWidgetRect() const; |
| 146 | const CFX_RectF& RecacheWidgetRect() const; |
weili | 47bcd4c | 2016-06-16 08:00:06 -0700 | [diff] [blame] | 147 | uint32_t GetStatus(); |
| 148 | void ModifyStatus(uint32_t dwAdded, uint32_t dwRemoved); |
| 149 | |
| 150 | CXFA_WidgetAcc* GetDataAcc(); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 151 | bool GetToolTip(CFX_WideString& wsToolTip); |
weili | 47bcd4c | 2016-06-16 08:00:06 -0700 | [diff] [blame] | 152 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 153 | CXFA_FFDocView* GetDocView(); |
weili | 47bcd4c | 2016-06-16 08:00:06 -0700 | [diff] [blame] | 154 | void SetDocView(CXFA_FFDocView* pDocView); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 155 | CXFA_FFDoc* GetDoc(); |
| 156 | CXFA_FFApp* GetApp(); |
| 157 | IXFA_AppProvider* GetAppProvider(); |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 158 | void InvalidateWidget(const CFX_RectF* pRect = nullptr); |
| 159 | void AddInvalidateRect(const CFX_RectF* pRect = nullptr); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 160 | bool GetCaptionText(CFX_WideString& wsCap); |
tsepez | 7d89e72 | 2016-05-04 13:38:11 -0700 | [diff] [blame] | 161 | bool IsFocused(); |
Dan Sinclair | 1f403ce | 2017-02-21 12:56:24 -0500 | [diff] [blame] | 162 | CFX_PointF Rotate2Normal(const CFX_PointF& point); |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 163 | CFX_Matrix GetRotateMatrix(); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 164 | bool IsLayoutRectEmpty(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 165 | CXFA_FFWidget* GetParent(); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 166 | bool IsAncestorOf(CXFA_FFWidget* pWidget); |
dsinclair | 1a7534a | 2016-11-22 15:56:11 -0800 | [diff] [blame] | 167 | const CFWL_App* GetFWLApp(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 168 | |
| 169 | protected: |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 170 | virtual bool PtInActiveRect(const CFX_PointF& point); |
weili | 47bcd4c | 2016-06-16 08:00:06 -0700 | [diff] [blame] | 171 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 172 | void DrawBorder(CFX_Graphics* pGS, |
| 173 | CXFA_Box box, |
| 174 | const CFX_RectF& rtBorder, |
| 175 | CFX_Matrix* pMatrix, |
tsepez | deee3d2 | 2016-03-25 14:38:58 -0700 | [diff] [blame] | 176 | uint32_t dwFlags = 0); |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 177 | |
| 178 | CFX_RectF GetRectWithoutRotate(); |
tsepez | 7d89e72 | 2016-05-04 13:38:11 -0700 | [diff] [blame] | 179 | bool IsMatchVisibleStatus(uint32_t dwStatus); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 180 | void EventKillFocus(); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 181 | bool IsButtonDown(); |
| 182 | void SetButtonDown(bool bSet); |
weili | 47bcd4c | 2016-06-16 08:00:06 -0700 | [diff] [blame] | 183 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 184 | CXFA_FFDocView* m_pDocView; |
| 185 | CXFA_FFPageView* m_pPageView; |
Lei Zhang | afc8eb3 | 2017-03-28 14:32:13 -0700 | [diff] [blame^] | 186 | CXFA_WidgetAcc* const m_pDataAcc; |
| 187 | mutable CFX_RectF m_rtWidget; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 188 | }; |
weili | 47bcd4c | 2016-06-16 08:00:06 -0700 | [diff] [blame] | 189 | |
Dan Sinclair | 80c4878 | 2017-03-23 12:11:20 -0400 | [diff] [blame] | 190 | #endif // XFA_FXFA_CXFA_FFWIDGET_H_ |