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