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 7 #ifndef XFA_FWL_CORE_FWL_WIDGETIMP_H_ 8 #define XFA_FWL_CORE_FWL_WIDGETIMP_H_ 9 10 #include "core/fxcrt/include/fx_coordinates.h" 11 #include "core/fxcrt/include/fx_system.h" 12 #include "xfa/fwl/core/cfwl_event.h" 13 #include "xfa/fwl/core/cfwl_themepart.h" 14 #include "xfa/fwl/core/ifwl_widgetdelegate.h" 15 #include "xfa/fwl/core/include/fwl_widgethit.h" 16 #include "xfa/fwl/theme/cfwl_widgettp.h" 17 18 class CFWL_AppImp; 19 class CFWL_MsgKey; 20 class CFWL_WidgetImpProperties; 21 class CFWL_WidgetMgr; 22 class IFWL_App; 23 class IFWL_DataProvider; 24 class IFWL_ThemeProvider; 25 class IFWL_Widget; 26 enum class FWL_Type; 27 28 class CFWL_WidgetImp { 29 public: 30 virtual ~CFWL_WidgetImp(); 31 32 virtual FWL_Error Initialize(); 33 virtual FWL_Error Finalize(); 34 virtual FWL_Error GetClassName(CFX_WideString& wsClass) const; 35 virtual FWL_Type GetClassID() const = 0; 36 virtual FX_BOOL IsInstance(const CFX_WideStringC& wsClass) const; 37 38 virtual FWL_Error GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize = FALSE); 39 virtual FWL_Error GetGlobalRect(CFX_RectF& rect); 40 virtual FWL_Error SetWidgetRect(const CFX_RectF& rect); 41 virtual FWL_Error GetClientRect(CFX_RectF& rect); 42 virtual IFWL_Widget* GetParent(); 43 virtual FWL_Error SetParent(IFWL_Widget* pParent); 44 virtual IFWL_Widget* GetOwner(); 45 virtual FWL_Error SetOwner(IFWL_Widget* pOwner); 46 virtual IFWL_Widget* GetOuter(); 47 virtual uint32_t GetStyles(); 48 virtual FWL_Error ModifyStyles(uint32_t dwStylesAdded, 49 uint32_t dwStylesRemoved); 50 virtual uint32_t GetStylesEx(); 51 virtual FWL_Error ModifyStylesEx(uint32_t dwStylesExAdded, 52 uint32_t dwStylesExRemoved); 53 virtual uint32_t GetStates(); 54 virtual void SetStates(uint32_t dwStates, FX_BOOL bSet = TRUE); 55 virtual FWL_Error Update(); 56 virtual FWL_Error LockUpdate(); 57 virtual FWL_Error UnlockUpdate(); 58 virtual FWL_WidgetHit HitTest(FX_FLOAT fx, FX_FLOAT fy); 59 virtual FWL_Error TransformTo(IFWL_Widget* pWidget, 60 FX_FLOAT& fx, 61 FX_FLOAT& fy); 62 virtual FWL_Error TransformTo(IFWL_Widget* pWidget, CFX_RectF& rt); 63 virtual FWL_Error GetMatrix(CFX_Matrix& matrix, FX_BOOL bGlobal = FALSE); 64 virtual FWL_Error SetMatrix(const CFX_Matrix& matrix); 65 virtual FWL_Error DrawWidget(CFX_Graphics* pGraphics, 66 const CFX_Matrix* pMatrix = nullptr); 67 virtual IFWL_ThemeProvider* GetThemeProvider(); 68 virtual FWL_Error SetThemeProvider(IFWL_ThemeProvider* pThemeProvider); 69 virtual FWL_Error SetDataProvider(IFWL_DataProvider* pDataProvider); 70 virtual IFWL_WidgetDelegate* SetDelegate(IFWL_WidgetDelegate* pDelegate); 71 virtual IFWL_App* GetOwnerApp() const; 72 73 FWL_Error SetOwnerApp(CFWL_AppImp* pOwnerApp); 74 IFWL_Widget* GetInterface() const; 75 void SetInterface(IFWL_Widget* pInterface); 76 CFX_SizeF GetOffsetFromParent(IFWL_Widget* pParent); 77 uint32_t GetEventKey() const; 78 void SetEventKey(uint32_t key); 79 void* GetLayoutItem() const; 80 void SetLayoutItem(void* pItem); 81 void* GetAssociateWidget() const; 82 void SetAssociateWidget(void* pAssociate); 83 84 protected: 85 friend class CFWL_WidgetImpDelegate; 86 87 CFWL_WidgetImp(const CFWL_WidgetImpProperties& properties, 88 IFWL_Widget* pOuter); 89 90 FX_BOOL IsEnabled() const; 91 FX_BOOL IsVisible() const; 92 FX_BOOL IsActive() const; 93 FX_BOOL IsOverLapper() const; 94 FX_BOOL IsPopup() const; 95 FX_BOOL IsChild() const; 96 FX_BOOL IsLocked() const; 97 FX_BOOL IsOffscreen() const; 98 FX_BOOL HasBorder() const; 99 FX_BOOL HasEdge() const; 100 void GetEdgeRect(CFX_RectF& rtEdge); 101 FX_FLOAT GetBorderSize(FX_BOOL bCX = TRUE); 102 FX_FLOAT GetEdgeWidth(); 103 void GetRelativeRect(CFX_RectF& rect); 104 void* GetThemeCapacity(CFWL_WidgetCapacity dwCapacity); 105 IFWL_ThemeProvider* GetAvailableTheme(); 106 CFWL_WidgetImp* GetRootOuter(); 107 CFX_SizeF CalcTextSize(const CFX_WideString& wsText, 108 IFWL_ThemeProvider* pTheme, 109 FX_BOOL bMultiLine = FALSE, 110 int32_t iLineWidth = -1); 111 void CalcTextRect(const CFX_WideString& wsText, 112 IFWL_ThemeProvider* pTheme, 113 uint32_t dwTTOStyles, 114 int32_t iTTOAlign, 115 CFX_RectF& rect); 116 void SetFocus(FX_BOOL bFocus); 117 void SetGrab(FX_BOOL bSet); 118 FX_BOOL GetPopupPos(FX_FLOAT fMinHeight, 119 FX_FLOAT fMaxHeight, 120 const CFX_RectF& rtAnchor, 121 CFX_RectF& rtPopup); 122 FX_BOOL GetPopupPosMenu(FX_FLOAT fMinHeight, 123 FX_FLOAT fMaxHeight, 124 const CFX_RectF& rtAnchor, 125 CFX_RectF& rtPopup); 126 FX_BOOL GetPopupPosComboBox(FX_FLOAT fMinHeight, 127 FX_FLOAT fMaxHeight, 128 const CFX_RectF& rtAnchor, 129 CFX_RectF& rtPopup); 130 FX_BOOL GetPopupPosGeneral(FX_FLOAT fMinHeight, 131 FX_FLOAT fMaxHeight, 132 const CFX_RectF& rtAnchor, 133 CFX_RectF& rtPopup); 134 FX_BOOL GetScreenSize(FX_FLOAT& fx, FX_FLOAT& fy); 135 void RegisterEventTarget(IFWL_Widget* pEventSource = nullptr, 136 uint32_t dwFilter = FWL_EVENT_ALL_MASK); 137 void UnregisterEventTarget(); 138 void DispatchKeyEvent(CFWL_MsgKey* pNote); 139 void DispatchEvent(CFWL_Event* pEvent); 140 void Repaint(const CFX_RectF* pRect = nullptr); 141 void DrawBackground(CFX_Graphics* pGraphics, 142 CFWL_Part iPartBk, 143 IFWL_ThemeProvider* pTheme, 144 const CFX_Matrix* pMatrix = nullptr); 145 void DrawBorder(CFX_Graphics* pGraphics, 146 CFWL_Part iPartBorder, 147 IFWL_ThemeProvider* pTheme, 148 const CFX_Matrix* pMatrix = nullptr); 149 void DrawEdge(CFX_Graphics* pGraphics, 150 CFWL_Part iPartEdge, 151 IFWL_ThemeProvider* pTheme, 152 const CFX_Matrix* pMatrix = nullptr); 153 void NotifyDriver(); 154 155 FX_BOOL IsParent(IFWL_Widget* pParent); 156 157 CFWL_WidgetMgr* m_pWidgetMgr; 158 CFWL_AppImp* m_pOwnerApp; 159 CFWL_WidgetImpProperties* m_pProperties; 160 IFWL_WidgetDelegate* m_pDelegate; 161 IFWL_WidgetDelegate* m_pCurDelegate; 162 IFWL_Widget* m_pOuter; 163 IFWL_Widget* m_pInterface; 164 void* m_pLayoutItem; 165 void* m_pAssociate; 166 int32_t m_iLock; 167 uint32_t m_nEventKey; 168 }; 169 170 class CFWL_WidgetImpDelegate : public IFWL_WidgetDelegate { 171 public: 172 CFWL_WidgetImpDelegate(); ~CFWL_WidgetImpDelegate()173 ~CFWL_WidgetImpDelegate() override {} 174 void OnProcessMessage(CFWL_Message* pMessage) override; 175 void OnProcessEvent(CFWL_Event* pEvent) override; 176 void OnDrawWidget(CFX_Graphics* pGraphics, 177 const CFX_Matrix* pMatrix = nullptr) override; 178 }; 179 180 #endif // XFA_FWL_CORE_FWL_WIDGETIMP_H_ 181