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_CFWL_WIDGET_H_ 8 #define XFA_FWL_CFWL_WIDGET_H_ 9 10 #include <memory> 11 12 #include "core/fxcrt/fx_coordinates.h" 13 #include "core/fxcrt/fx_system.h" 14 #include "core/fxcrt/unowned_ptr.h" 15 #include "xfa/fde/cfde_data.h" 16 #include "xfa/fwl/cfwl_event.h" 17 #include "xfa/fwl/cfwl_themepart.h" 18 #include "xfa/fwl/cfwl_widgetmgr.h" 19 #include "xfa/fwl/fwl_widgethit.h" 20 #include "xfa/fwl/ifwl_widgetdelegate.h" 21 22 enum class FWL_Type { 23 Unknown = 0, 24 25 Barcode, 26 Caret, 27 CheckBox, 28 ComboBox, 29 DateTimePicker, 30 Edit, 31 Form, 32 FormProxy, 33 ListBox, 34 MonthCalendar, 35 PictureBox, 36 PushButton, 37 ScrollBar, 38 SpinButton, 39 ToolTip 40 }; 41 42 class CFWL_App; 43 class CFWL_AppImp; 44 class CFWL_MessageKey; 45 class CFWL_Widget; 46 class CFWL_WidgetMgr; 47 class CFWL_WidgetProperties; 48 class CXFA_FFWidget; 49 class IFWL_ThemeProvider; 50 51 class CFWL_Widget : public IFWL_WidgetDelegate { 52 public: 53 ~CFWL_Widget() override; 54 55 virtual FWL_Type GetClassID() const = 0; 56 virtual bool IsInstance(const WideStringView& wsClass) const; 57 virtual CFX_RectF GetAutosizedWidgetRect(); 58 virtual CFX_RectF GetWidgetRect(); 59 virtual CFX_RectF GetClientRect(); 60 virtual void ModifyStylesEx(uint32_t dwStylesExAdded, 61 uint32_t dwStylesExRemoved); 62 virtual void SetStates(uint32_t dwStates); 63 virtual void RemoveStates(uint32_t dwStates); 64 virtual void Update() = 0; 65 virtual FWL_WidgetHit HitTest(const CFX_PointF& point); 66 virtual void DrawWidget(CXFA_Graphics* pGraphics, 67 const CFX_Matrix& matrix) = 0; 68 virtual void SetThemeProvider(IFWL_ThemeProvider* pThemeProvider); 69 70 // IFWL_WidgetDelegate. 71 void OnProcessMessage(CFWL_Message* pMessage) override; 72 void OnProcessEvent(CFWL_Event* pEvent) override; 73 void OnDrawWidget(CXFA_Graphics* pGraphics, 74 const CFX_Matrix& matrix) override; 75 76 void InflateWidgetRect(CFX_RectF& rect); 77 void SetWidgetRect(const CFX_RectF& rect); 78 79 void SetParent(CFWL_Widget* pParent); 80 GetOwner()81 CFWL_Widget* GetOwner() { return m_pWidgetMgr->GetOwnerWidget(this); } GetOuter()82 CFWL_Widget* GetOuter() const { return m_pOuter; } 83 84 uint32_t GetStyles() const; 85 void ModifyStyles(uint32_t dwStylesAdded, uint32_t dwStylesRemoved); 86 uint32_t GetStylesEx() const; 87 uint32_t GetStates() const; 88 LockUpdate()89 void LockUpdate() { m_iLock++; } UnlockUpdate()90 void UnlockUpdate() { 91 if (IsLocked()) 92 m_iLock--; 93 } 94 95 CFX_PointF TransformTo(CFWL_Widget* pWidget, const CFX_PointF& point); 96 CFX_Matrix GetMatrix(); 97 IFWL_ThemeProvider* GetThemeProvider() const; 98 SetDelegate(IFWL_WidgetDelegate * delegate)99 void SetDelegate(IFWL_WidgetDelegate* delegate) { m_pDelegate = delegate; } GetDelegate()100 IFWL_WidgetDelegate* GetDelegate() { 101 return m_pDelegate ? m_pDelegate.Get() : this; 102 } GetDelegate()103 const IFWL_WidgetDelegate* GetDelegate() const { 104 return m_pDelegate ? m_pDelegate.Get() : this; 105 } 106 GetOwnerApp()107 const CFWL_App* GetOwnerApp() const { return m_pOwnerApp.Get(); } GetEventKey()108 uint32_t GetEventKey() const { return m_nEventKey; } SetEventKey(uint32_t key)109 void SetEventKey(uint32_t key) { m_nEventKey = key; } 110 GetLayoutItem()111 CXFA_FFWidget* GetLayoutItem() const { return m_pLayoutItem; } SetLayoutItem(CXFA_FFWidget * pItem)112 void SetLayoutItem(CXFA_FFWidget* pItem) { m_pLayoutItem = pItem; } 113 114 void SetFocus(bool bFocus); 115 void RepaintRect(const CFX_RectF& pRect); 116 void Repaint(); 117 118 protected: 119 CFWL_Widget(const CFWL_App* app, 120 std::unique_ptr<CFWL_WidgetProperties> properties, 121 CFWL_Widget* pOuter); 122 123 bool IsEnabled() const; IsLocked()124 bool IsLocked() const { return m_iLock > 0; } 125 bool HasBorder() const; 126 CFX_RectF GetEdgeRect(); 127 float GetBorderSize(bool bCX); 128 CFX_RectF GetRelativeRect(); 129 IFWL_ThemeProvider* GetAvailableTheme(); 130 CFX_SizeF CalcTextSize(const WideString& wsText, 131 IFWL_ThemeProvider* pTheme, 132 bool bMultiLine); 133 void CalcTextRect(const WideString& wsText, 134 IFWL_ThemeProvider* pTheme, 135 const FDE_TextStyle& dwTTOStyles, 136 FDE_TextAlignment iTTOAlign, 137 CFX_RectF& rect); 138 void SetGrab(bool bSet); 139 void GetPopupPos(float fMinHeight, 140 float fMaxHeight, 141 const CFX_RectF& rtAnchor, 142 CFX_RectF& rtPopup); 143 void RegisterEventTarget(CFWL_Widget* pEventSource); 144 void UnregisterEventTarget(); 145 void DispatchEvent(CFWL_Event* pEvent); 146 void DrawBorder(CXFA_Graphics* pGraphics, 147 CFWL_Part iPartBorder, 148 IFWL_ThemeProvider* pTheme, 149 const CFX_Matrix& pMatrix); 150 151 UnownedPtr<const CFWL_App> const m_pOwnerApp; 152 UnownedPtr<CFWL_WidgetMgr> const m_pWidgetMgr; 153 std::unique_ptr<CFWL_WidgetProperties> m_pProperties; 154 CFWL_Widget* m_pOuter; 155 int32_t m_iLock; 156 157 private: GetParent()158 CFWL_Widget* GetParent() { return m_pWidgetMgr->GetParentWidget(this); } 159 CFX_SizeF GetOffsetFromParent(CFWL_Widget* pParent); 160 161 bool IsVisible() const; 162 bool IsOverLapper() const; 163 bool IsPopup() const; 164 bool IsChild() const; 165 CFWL_Widget* GetRootOuter(); 166 bool GetPopupPosMenu(float fMinHeight, 167 float fMaxHeight, 168 const CFX_RectF& rtAnchor, 169 CFX_RectF& rtPopup); 170 bool GetPopupPosComboBox(float fMinHeight, 171 float fMaxHeight, 172 const CFX_RectF& rtAnchor, 173 CFX_RectF& rtPopup); 174 bool GetPopupPosGeneral(float fMinHeight, 175 float fMaxHeight, 176 const CFX_RectF& rtAnchor, 177 CFX_RectF& rtPopup); 178 void DrawBackground(CXFA_Graphics* pGraphics, 179 CFWL_Part iPartBk, 180 IFWL_ThemeProvider* pTheme, 181 const CFX_Matrix* pMatrix); 182 void NotifyDriver(); 183 bool IsParent(CFWL_Widget* pParent); 184 185 CXFA_FFWidget* m_pLayoutItem; 186 uint32_t m_nEventKey; 187 UnownedPtr<IFWL_WidgetDelegate> m_pDelegate; 188 }; 189 190 #endif // XFA_FWL_CFWL_WIDGET_H_ 191