| OLD | NEW |
| (Empty) |
| 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_IFWL_WIDGET_H_ | |
| 8 #define XFA_FWL_CORE_IFWL_WIDGET_H_ | |
| 9 | |
| 10 #include <memory> | |
| 11 | |
| 12 #include "core/fxcrt/fx_coordinates.h" | |
| 13 #include "core/fxcrt/fx_system.h" | |
| 14 #include "xfa/fwl/core/cfwl_event.h" | |
| 15 #include "xfa/fwl/core/cfwl_themepart.h" | |
| 16 #include "xfa/fwl/core/cfwl_widgetmgr.h" | |
| 17 #include "xfa/fwl/core/fwl_widgethit.h" | |
| 18 #include "xfa/fwl/core/ifwl_widgetdelegate.h" | |
| 19 #include "xfa/fwl/theme/cfwl_widgettp.h" | |
| 20 | |
| 21 // FWL contains two parallel inheritance hierarchies, which reference each | |
| 22 // other via pointers as follows: | |
| 23 // | |
| 24 // m_pAssociate | |
| 25 // <---------- | |
| 26 // CFWL_Widget ----------> IFWL_Widget | |
| 27 // | m_pIface | | |
| 28 // A A | |
| 29 // | | | |
| 30 // CFWL_... IFWL_... | |
| 31 // | |
| 32 // TODO(tsepez): Collapse these into a single hierarchy. | |
| 33 // | |
| 34 | |
| 35 enum class FWL_Type { | |
| 36 Unknown = 0, | |
| 37 | |
| 38 Barcode, | |
| 39 Caret, | |
| 40 CheckBox, | |
| 41 ComboBox, | |
| 42 DateTimePicker, | |
| 43 Edit, | |
| 44 Form, | |
| 45 FormProxy, | |
| 46 ListBox, | |
| 47 MonthCalendar, | |
| 48 PictureBox, | |
| 49 PushButton, | |
| 50 ScrollBar, | |
| 51 SpinButton, | |
| 52 ToolTip | |
| 53 }; | |
| 54 | |
| 55 class CFWL_AppImp; | |
| 56 class CFWL_MsgKey; | |
| 57 class CFWL_Widget; | |
| 58 class CFWL_WidgetProperties; | |
| 59 class CFWL_WidgetMgr; | |
| 60 class CFWL_App; | |
| 61 class IFWL_ThemeProvider; | |
| 62 class IFWL_Widget; | |
| 63 enum class FWL_Type; | |
| 64 | |
| 65 class IFWL_Widget : public IFWL_WidgetDelegate { | |
| 66 public: | |
| 67 ~IFWL_Widget() override; | |
| 68 | |
| 69 virtual FWL_Type GetClassID() const = 0; | |
| 70 virtual bool IsInstance(const CFX_WideStringC& wsClass) const; | |
| 71 virtual void GetWidgetRect(CFX_RectF& rect, bool bAutoSize = false); | |
| 72 virtual void GetClientRect(CFX_RectF& rect); | |
| 73 virtual void ModifyStylesEx(uint32_t dwStylesExAdded, | |
| 74 uint32_t dwStylesExRemoved); | |
| 75 virtual void SetStates(uint32_t dwStates, bool bSet = true); | |
| 76 virtual void Update() = 0; | |
| 77 virtual FWL_WidgetHit HitTest(FX_FLOAT fx, FX_FLOAT fy); | |
| 78 virtual void DrawWidget(CFX_Graphics* pGraphics, | |
| 79 const CFX_Matrix* pMatrix = nullptr) = 0; | |
| 80 virtual void SetThemeProvider(IFWL_ThemeProvider* pThemeProvider); | |
| 81 | |
| 82 // IFWL_WidgetDelegate. | |
| 83 void OnProcessMessage(CFWL_Message* pMessage) override; | |
| 84 void OnProcessEvent(CFWL_Event* pEvent) override; | |
| 85 void OnDrawWidget(CFX_Graphics* pGraphics, | |
| 86 const CFX_Matrix* pMatrix = nullptr) override; | |
| 87 | |
| 88 void SetWidgetRect(const CFX_RectF& rect); | |
| 89 | |
| 90 void SetParent(IFWL_Widget* pParent); | |
| 91 | |
| 92 IFWL_Widget* GetOwner() { return m_pWidgetMgr->GetOwnerWidget(this); } | |
| 93 IFWL_Widget* GetOuter() const { return m_pOuter; } | |
| 94 | |
| 95 uint32_t GetStyles() const; | |
| 96 void ModifyStyles(uint32_t dwStylesAdded, uint32_t dwStylesRemoved); | |
| 97 uint32_t GetStylesEx() const; | |
| 98 uint32_t GetStates() const; | |
| 99 | |
| 100 void LockUpdate() { m_iLock++; } | |
| 101 void UnlockUpdate() { | |
| 102 if (IsLocked()) | |
| 103 m_iLock--; | |
| 104 } | |
| 105 | |
| 106 void TransformTo(IFWL_Widget* pWidget, FX_FLOAT& fx, FX_FLOAT& fy); | |
| 107 void GetMatrix(CFX_Matrix& matrix, bool bGlobal = false); | |
| 108 IFWL_ThemeProvider* GetThemeProvider() const; | |
| 109 | |
| 110 void SetDelegate(IFWL_WidgetDelegate* delegate) { m_pDelegate = delegate; } | |
| 111 IFWL_WidgetDelegate* GetDelegate() { | |
| 112 return m_pDelegate ? m_pDelegate : this; | |
| 113 } | |
| 114 const IFWL_WidgetDelegate* GetDelegate() const { | |
| 115 return m_pDelegate ? m_pDelegate : this; | |
| 116 } | |
| 117 | |
| 118 const CFWL_App* GetOwnerApp() const { return m_pOwnerApp; } | |
| 119 uint32_t GetEventKey() const { return m_nEventKey; } | |
| 120 void SetEventKey(uint32_t key) { m_nEventKey = key; } | |
| 121 | |
| 122 void* GetLayoutItem() const { return m_pLayoutItem; } | |
| 123 void SetLayoutItem(void* pItem) { m_pLayoutItem = pItem; } | |
| 124 | |
| 125 void SetAssociateWidget(CFWL_Widget* pAssociate) { | |
| 126 m_pAssociate = pAssociate; | |
| 127 } | |
| 128 | |
| 129 void SetFocus(bool bFocus); | |
| 130 void Repaint(const CFX_RectF* pRect = nullptr); | |
| 131 | |
| 132 protected: | |
| 133 IFWL_Widget(const CFWL_App* app, | |
| 134 std::unique_ptr<CFWL_WidgetProperties> properties, | |
| 135 IFWL_Widget* pOuter); | |
| 136 | |
| 137 bool IsEnabled() const; | |
| 138 bool IsActive() const; | |
| 139 bool IsLocked() const { return m_iLock > 0; } | |
| 140 bool HasBorder() const; | |
| 141 bool HasEdge() const; | |
| 142 void GetEdgeRect(CFX_RectF& rtEdge); | |
| 143 FX_FLOAT GetBorderSize(bool bCX = true); | |
| 144 FX_FLOAT GetEdgeWidth(); | |
| 145 void GetRelativeRect(CFX_RectF& rect); | |
| 146 void* GetThemeCapacity(CFWL_WidgetCapacity dwCapacity); | |
| 147 IFWL_ThemeProvider* GetAvailableTheme(); | |
| 148 CFX_SizeF CalcTextSize(const CFX_WideString& wsText, | |
| 149 IFWL_ThemeProvider* pTheme, | |
| 150 bool bMultiLine = false, | |
| 151 int32_t iLineWidth = -1); | |
| 152 void CalcTextRect(const CFX_WideString& wsText, | |
| 153 IFWL_ThemeProvider* pTheme, | |
| 154 uint32_t dwTTOStyles, | |
| 155 int32_t iTTOAlign, | |
| 156 CFX_RectF& rect); | |
| 157 void SetGrab(bool bSet); | |
| 158 void GetPopupPos(FX_FLOAT fMinHeight, | |
| 159 FX_FLOAT fMaxHeight, | |
| 160 const CFX_RectF& rtAnchor, | |
| 161 CFX_RectF& rtPopup); | |
| 162 void RegisterEventTarget(IFWL_Widget* pEventSource); | |
| 163 void UnregisterEventTarget(); | |
| 164 void DispatchKeyEvent(CFWL_MsgKey* pNote); | |
| 165 void DispatchEvent(CFWL_Event* pEvent); | |
| 166 void DrawBorder(CFX_Graphics* pGraphics, | |
| 167 CFWL_Part iPartBorder, | |
| 168 IFWL_ThemeProvider* pTheme, | |
| 169 const CFX_Matrix* pMatrix = nullptr); | |
| 170 void DrawEdge(CFX_Graphics* pGraphics, | |
| 171 CFWL_Part iPartEdge, | |
| 172 IFWL_ThemeProvider* pTheme, | |
| 173 const CFX_Matrix* pMatrix = nullptr); | |
| 174 | |
| 175 const CFWL_App* const m_pOwnerApp; | |
| 176 CFWL_WidgetMgr* const m_pWidgetMgr; | |
| 177 std::unique_ptr<CFWL_WidgetProperties> m_pProperties; | |
| 178 IFWL_Widget* m_pOuter; | |
| 179 int32_t m_iLock; | |
| 180 | |
| 181 private: | |
| 182 IFWL_Widget* GetParent() { return m_pWidgetMgr->GetParentWidget(this); } | |
| 183 CFX_SizeF GetOffsetFromParent(IFWL_Widget* pParent); | |
| 184 | |
| 185 bool IsVisible() const; | |
| 186 bool IsOverLapper() const; | |
| 187 bool IsPopup() const; | |
| 188 bool IsChild() const; | |
| 189 bool IsOffscreen() const; | |
| 190 IFWL_Widget* GetRootOuter(); | |
| 191 bool GetPopupPosMenu(FX_FLOAT fMinHeight, | |
| 192 FX_FLOAT fMaxHeight, | |
| 193 const CFX_RectF& rtAnchor, | |
| 194 CFX_RectF& rtPopup); | |
| 195 bool GetPopupPosComboBox(FX_FLOAT fMinHeight, | |
| 196 FX_FLOAT fMaxHeight, | |
| 197 const CFX_RectF& rtAnchor, | |
| 198 CFX_RectF& rtPopup); | |
| 199 bool GetPopupPosGeneral(FX_FLOAT fMinHeight, | |
| 200 FX_FLOAT fMaxHeight, | |
| 201 const CFX_RectF& rtAnchor, | |
| 202 CFX_RectF& rtPopup); | |
| 203 bool GetScreenSize(FX_FLOAT& fx, FX_FLOAT& fy); | |
| 204 void DrawBackground(CFX_Graphics* pGraphics, | |
| 205 CFWL_Part iPartBk, | |
| 206 IFWL_ThemeProvider* pTheme, | |
| 207 const CFX_Matrix* pMatrix = nullptr); | |
| 208 void NotifyDriver(); | |
| 209 bool IsParent(IFWL_Widget* pParent); | |
| 210 | |
| 211 void* m_pLayoutItem; | |
| 212 CFWL_Widget* m_pAssociate; | |
| 213 uint32_t m_nEventKey; | |
| 214 IFWL_WidgetDelegate* m_pDelegate; // Not owned. | |
| 215 }; | |
| 216 | |
| 217 #endif // XFA_FWL_CORE_IFWL_WIDGET_H_ | |
| OLD | NEW |