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 | 7222ea6 | 2016-04-06 14:33:07 -0700 | [diff] [blame] | 7 | #ifndef XFA_FXFA_INCLUDE_XFA_FFWIDGET_H_ |
| 8 | #define XFA_FXFA_INCLUDE_XFA_FFWIDGET_H_ |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 9 | |
| 10 | #include <vector> |
| 11 | |
dsinclair | 86e5474 | 2016-04-06 12:30:31 -0700 | [diff] [blame] | 12 | #include "core/fxcodec/include/fx_codec_def.h" |
dsinclair | 48baa5f | 2016-04-06 10:00:40 -0700 | [diff] [blame] | 13 | #include "core/fxge/include/fx_ge.h" |
dsinclair | 7222ea6 | 2016-04-06 14:33:07 -0700 | [diff] [blame] | 14 | #include "xfa/fxfa/include/fxfa.h" |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 15 | #include "xfa/fxfa/parser/xfa_doclayout.h" |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 16 | |
| 17 | class CXFA_FFPageView; |
| 18 | class CXFA_FFDocView; |
| 19 | class CXFA_FFDoc; |
| 20 | class CXFA_FFApp; |
dsinclair | 89fcde8 | 2016-05-03 13:00:25 -0700 | [diff] [blame^] | 21 | enum class FWL_WidgetHit; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 22 | |
| 23 | inline FX_FLOAT XFA_UnitPx2Pt(FX_FLOAT fPx, FX_FLOAT fDpi) { |
| 24 | return fPx * 72.0f / fDpi; |
| 25 | } |
| 26 | #define XFA_FLOAT_PERCISION 0.001f |
| 27 | enum XFA_WIDGETITEM { |
| 28 | XFA_WIDGETITEM_Parent, |
| 29 | XFA_WIDGETITEM_FirstChild, |
| 30 | XFA_WIDGETITEM_NextSibling, |
| 31 | XFA_WIDGETITEM_PrevSibling, |
| 32 | }; |
tsepez | bb0d446 | 2016-04-27 16:59:30 -0700 | [diff] [blame] | 33 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 34 | class CXFA_CalcData { |
| 35 | public: |
| 36 | CXFA_CalcData() : m_iRefCount(0) {} |
| 37 | ~CXFA_CalcData() { m_Globals.RemoveAll(); } |
tsepez | bb0d446 | 2016-04-27 16:59:30 -0700 | [diff] [blame] | 38 | |
| 39 | CFX_ArrayTemplate<CXFA_WidgetAcc*> m_Globals; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 40 | int32_t m_iRefCount; |
| 41 | }; |
tsepez | bb0d446 | 2016-04-27 16:59:30 -0700 | [diff] [blame] | 42 | |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 43 | class CXFA_FFWidget : public CFX_PrivateData, public CXFA_ContentLayoutItem { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 44 | public: |
| 45 | CXFA_FFWidget(CXFA_FFPageView* pPageView, CXFA_WidgetAcc* pDataAcc); |
| 46 | virtual ~CXFA_FFWidget(); |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 47 | CXFA_FFPageView* GetPageView(); |
| 48 | void SetPageView(CXFA_FFPageView* pPageView); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 49 | void GetWidgetRect(CFX_RectF& rtWidget); |
| 50 | CFX_RectF ReCacheWidgetRect(); |
tsepez | deee3d2 | 2016-03-25 14:38:58 -0700 | [diff] [blame] | 51 | uint32_t GetStatus(); |
| 52 | void ModifyStatus(uint32_t dwAdded, uint32_t dwRemoved); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 53 | virtual FX_BOOL GetBBox(CFX_RectF& rtBox, |
tsepez | deee3d2 | 2016-03-25 14:38:58 -0700 | [diff] [blame] | 54 | uint32_t dwStatus, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 55 | FX_BOOL bDrawFocus = FALSE); |
| 56 | CXFA_WidgetAcc* GetDataAcc(); |
| 57 | FX_BOOL GetToolTip(CFX_WideString& wsToolTip); |
| 58 | virtual void RenderWidget(CFX_Graphics* pGS, |
| 59 | CFX_Matrix* pMatrix = NULL, |
tsepez | deee3d2 | 2016-03-25 14:38:58 -0700 | [diff] [blame] | 60 | uint32_t dwStatus = 0, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 61 | int32_t iRotate = 0); |
| 62 | |
| 63 | virtual FX_BOOL IsLoaded(); |
| 64 | virtual FX_BOOL LoadWidget(); |
| 65 | virtual void UnloadWidget(); |
| 66 | virtual FX_BOOL PerformLayout(); |
| 67 | virtual FX_BOOL UpdateFWLData(); |
| 68 | virtual void UpdateWidgetProperty(); |
| 69 | virtual FX_BOOL OnMouseEnter(); |
| 70 | virtual FX_BOOL OnMouseExit(); |
tsepez | deee3d2 | 2016-03-25 14:38:58 -0700 | [diff] [blame] | 71 | virtual FX_BOOL OnLButtonDown(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy); |
| 72 | virtual FX_BOOL OnLButtonUp(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy); |
| 73 | virtual FX_BOOL OnLButtonDblClk(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy); |
| 74 | virtual FX_BOOL OnMouseMove(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy); |
| 75 | virtual FX_BOOL OnMouseWheel(uint32_t dwFlags, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 76 | int16_t zDelta, |
| 77 | FX_FLOAT fx, |
| 78 | FX_FLOAT fy); |
tsepez | deee3d2 | 2016-03-25 14:38:58 -0700 | [diff] [blame] | 79 | virtual FX_BOOL OnRButtonDown(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy); |
| 80 | virtual FX_BOOL OnRButtonUp(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy); |
| 81 | virtual FX_BOOL OnRButtonDblClk(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 82 | |
| 83 | virtual FX_BOOL OnSetFocus(CXFA_FFWidget* pOldWidget); |
| 84 | virtual FX_BOOL OnKillFocus(CXFA_FFWidget* pNewWidget); |
tsepez | deee3d2 | 2016-03-25 14:38:58 -0700 | [diff] [blame] | 85 | virtual FX_BOOL OnKeyDown(uint32_t dwKeyCode, uint32_t dwFlags); |
| 86 | virtual FX_BOOL OnKeyUp(uint32_t dwKeyCode, uint32_t dwFlags); |
| 87 | virtual FX_BOOL OnChar(uint32_t dwChar, uint32_t dwFlags); |
dsinclair | 89fcde8 | 2016-05-03 13:00:25 -0700 | [diff] [blame^] | 88 | virtual FWL_WidgetHit OnHitTest(FX_FLOAT fx, FX_FLOAT fy); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 89 | virtual FX_BOOL OnSetCursor(FX_FLOAT fx, FX_FLOAT fy); |
| 90 | virtual FX_BOOL CanUndo() { return FALSE; } |
| 91 | virtual FX_BOOL CanRedo() { return FALSE; } |
| 92 | virtual FX_BOOL Undo() { return FALSE; } |
| 93 | virtual FX_BOOL Redo() { return FALSE; } |
| 94 | virtual FX_BOOL CanCopy() { return FALSE; } |
| 95 | virtual FX_BOOL CanCut() { return FALSE; } |
| 96 | virtual FX_BOOL CanPaste() { return FALSE; } |
| 97 | virtual FX_BOOL CanSelectAll() { return FALSE; } |
| 98 | virtual FX_BOOL CanDelete() { return CanCut(); } |
| 99 | virtual FX_BOOL CanDeSelect() { return CanCopy(); } |
| 100 | virtual FX_BOOL Copy(CFX_WideString& wsCopy) { return FALSE; } |
| 101 | virtual FX_BOOL Cut(CFX_WideString& wsCut) { return FALSE; } |
| 102 | virtual FX_BOOL Paste(const CFX_WideString& wsPaste) { return FALSE; } |
| 103 | virtual FX_BOOL SelectAll() { return FALSE; } |
| 104 | virtual FX_BOOL Delete() { return FALSE; } |
| 105 | virtual FX_BOOL DeSelect() { return FALSE; } |
| 106 | virtual FX_BOOL GetSuggestWords(CFX_PointF pointf, |
| 107 | std::vector<CFX_ByteString>& sSuggest) { |
| 108 | return FALSE; |
| 109 | } |
| 110 | virtual FX_BOOL ReplaceSpellCheckWord(CFX_PointF pointf, |
| 111 | const CFX_ByteStringC& bsReplace) { |
| 112 | return FALSE; |
| 113 | } |
| 114 | CXFA_FFDocView* GetDocView(); |
| 115 | void SetDocView(CXFA_FFDocView* pDocView) { m_pDocView = pDocView; } |
| 116 | CXFA_FFDoc* GetDoc(); |
| 117 | CXFA_FFApp* GetApp(); |
| 118 | IXFA_AppProvider* GetAppProvider(); |
| 119 | void InvalidateWidget(const CFX_RectF* pRect = NULL); |
| 120 | void AddInvalidateRect(const CFX_RectF* pRect = NULL); |
| 121 | FX_BOOL GetCaptionText(CFX_WideString& wsCap); |
| 122 | FX_BOOL IsFocused(); |
| 123 | void Rotate2Normal(FX_FLOAT& fx, FX_FLOAT& fy); |
| 124 | void GetRotateMatrix(CFX_Matrix& mt); |
| 125 | FX_BOOL IsLayoutRectEmpty(); |
| 126 | CXFA_FFWidget* GetParent(); |
| 127 | FX_BOOL IsAncestorOf(CXFA_FFWidget* pWidget); |
| 128 | |
| 129 | protected: |
| 130 | virtual FX_BOOL PtInActiveRect(FX_FLOAT fx, FX_FLOAT fy); |
| 131 | void DrawBorder(CFX_Graphics* pGS, |
| 132 | CXFA_Box box, |
| 133 | const CFX_RectF& rtBorder, |
| 134 | CFX_Matrix* pMatrix, |
tsepez | deee3d2 | 2016-03-25 14:38:58 -0700 | [diff] [blame] | 135 | uint32_t dwFlags = 0); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 136 | void GetMinMaxWidth(FX_FLOAT fMinWidth, FX_FLOAT fMaxWidth); |
| 137 | void GetMinMaxHeight(FX_FLOAT fMinHeight, FX_FLOAT fMaxHeight); |
| 138 | void GetRectWithoutRotate(CFX_RectF& rtWidget); |
tsepez | deee3d2 | 2016-03-25 14:38:58 -0700 | [diff] [blame] | 139 | FX_BOOL IsMatchVisibleStatus(uint32_t dwStatus); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 140 | |
| 141 | void EventKillFocus(); |
| 142 | FX_BOOL IsButtonDown(); |
| 143 | void SetButtonDown(FX_BOOL bSet); |
| 144 | CXFA_FFDocView* m_pDocView; |
| 145 | CXFA_FFPageView* m_pPageView; |
| 146 | CXFA_WidgetAcc* m_pDataAcc; |
| 147 | CFX_RectF m_rtWidget; |
| 148 | }; |
| 149 | int32_t XFA_StrokeTypeSetLineDash(CFX_Graphics* pGraphics, |
| 150 | int32_t iStrokeType, |
| 151 | int32_t iCapType); |
| 152 | CFX_GraphStateData::LineCap XFA_LineCapToFXGE(int32_t iLineCap); |
| 153 | void 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); |
| 162 | CFX_DIBitmap* XFA_LoadImageData(CXFA_FFDoc* pDoc, |
| 163 | CXFA_Image* pImage, |
| 164 | FX_BOOL& bNameImage, |
| 165 | int32_t& iImageXDpi, |
| 166 | int32_t& iImageYDpi); |
| 167 | CFX_DIBitmap* XFA_LoadImageFromBuffer(IFX_FileRead* pImageFileRead, |
| 168 | FXCODEC_IMAGE_TYPE type, |
| 169 | int32_t& iImageXDpi, |
| 170 | int32_t& iImageYDpi); |
tsepez | fc58ad1 | 2016-04-05 12:22:15 -0700 | [diff] [blame] | 171 | FXCODEC_IMAGE_TYPE XFA_GetImageType(const CFX_WideString& wsType); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 172 | FX_CHAR* XFA_Base64Encode(const uint8_t* buf, int32_t buf_len); |
| 173 | void XFA_RectWidthoutMargin(CFX_RectF& rt, |
| 174 | const CXFA_Margin& mg, |
| 175 | FX_BOOL bUI = FALSE); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 176 | CXFA_FFWidget* XFA_GetWidgetFromLayoutItem(CXFA_LayoutItem* pLayoutItem); |
| 177 | FX_BOOL XFA_IsCreateWidget(XFA_ELEMENT iType); |
| 178 | #define XFA_DRAWBOX_ForceRound 1 |
| 179 | #define XFA_DRAWBOX_Lowered3D 2 |
| 180 | void XFA_DrawBox(CXFA_Box box, |
| 181 | CFX_Graphics* pGS, |
| 182 | const CFX_RectF& rtWidget, |
| 183 | CFX_Matrix* pMatrix, |
tsepez | deee3d2 | 2016-03-25 14:38:58 -0700 | [diff] [blame] | 184 | uint32_t dwFlags = 0); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 185 | |
dsinclair | 7222ea6 | 2016-04-06 14:33:07 -0700 | [diff] [blame] | 186 | #endif // XFA_FXFA_INCLUDE_XFA_FFWIDGET_H_ |