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/include/fx_basic.h" 13 #include "core/fxcrt/include/fx_coordinates.h" 14 #include "core/fxcrt/include/fx_system.h" 15 #include "xfa/fwl/core/fwl_error.h" 16 #include "xfa/fwl/core/fwl_widgetimp.h" 17 18 // FWL contains three parallel inheritance hierarchies, which reference each 19 // other via pointers as follows: 20 // 21 // m_pAssociate 22 // <---------------------------------- 23 // CFWL_Widget ----------> IFWL_Widget ----------> CFWL_WidgetImp 24 // | m_pIface | m_pImpl | 25 // A A A 26 // | | | 27 // CFWL_... IFWL_... CFWL_...Imp 28 // 29 // TODO(tsepez): Collapse these into a single hierarchy. 30 // 31 32 enum class FWL_Type { 33 Unknown = 0, 34 35 Barcode, 36 Caret, 37 CheckBox, 38 ComboBox, 39 DateTimePicker, 40 Edit, 41 Form, 42 FormProxy, 43 ListBox, 44 MonthCalendar, 45 PictureBox, 46 PushButton, 47 ScrollBar, 48 SpinButton, 49 ToolTip 50 }; 51 52 class CFWL_WidgetImp; 53 class CFX_Graphics; 54 class IFWL_App; 55 class IFWL_DataProvider; 56 class IFWL_Form; 57 class IFWL_ThemeProvider; 58 class IFWL_WidgetDelegate; 59 60 class IFWL_Widget { 61 public: 62 IFWL_Widget(); 63 virtual ~IFWL_Widget(); 64 65 FWL_Error GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize = FALSE); 66 FWL_Error GetGlobalRect(CFX_RectF& rect); 67 FWL_Error SetWidgetRect(const CFX_RectF& rect); 68 FWL_Error GetClientRect(CFX_RectF& rect); 69 IFWL_Widget* GetParent(); 70 FWL_Error SetParent(IFWL_Widget* pParent); 71 IFWL_Widget* GetOwner(); 72 FWL_Error SetOwner(IFWL_Widget* pOwner); 73 IFWL_Widget* GetOuter(); 74 uint32_t GetStyles(); 75 FWL_Error ModifyStyles(uint32_t dwStylesAdded, uint32_t dwStylesRemoved); 76 uint32_t GetStylesEx(); 77 FWL_Error ModifyStylesEx(uint32_t dwStylesExAdded, 78 uint32_t dwStylesExRemoved); 79 uint32_t GetStates(); 80 void SetStates(uint32_t dwStates, FX_BOOL bSet = TRUE); 81 uint32_t GetEventKey() const; 82 void SetEventKey(uint32_t key); 83 void* GetLayoutItem() const; 84 void SetLayoutItem(void* pItem); 85 void* GetAssociateWidget() const; 86 void SetAssociateWidget(void* pAssociate); 87 FWL_Error Update(); 88 FWL_Error LockUpdate(); 89 FWL_Error UnlockUpdate(); 90 FWL_WidgetHit HitTest(FX_FLOAT fx, FX_FLOAT fy); 91 FWL_Error TransformTo(IFWL_Widget* pWidget, FX_FLOAT& fx, FX_FLOAT& fy); 92 FWL_Error TransformTo(IFWL_Widget* pWidget, CFX_RectF& rt); 93 FWL_Error GetMatrix(CFX_Matrix& matrix, FX_BOOL bGlobal = FALSE); 94 FWL_Error SetMatrix(const CFX_Matrix& matrix); 95 FWL_Error DrawWidget(CFX_Graphics* pGraphics, 96 const CFX_Matrix* pMatrix = nullptr); 97 IFWL_ThemeProvider* GetThemeProvider(); 98 FWL_Error SetThemeProvider(IFWL_ThemeProvider* pThemeProvider); 99 FWL_Error SetDataProvider(IFWL_DataProvider* pDataProvider); 100 IFWL_WidgetDelegate* SetDelegate(IFWL_WidgetDelegate* pDelegate); 101 IFWL_App* GetOwnerApp() const; 102 CFX_SizeF GetOffsetFromParent(IFWL_Widget* pParent); 103 104 // These call into equivalent polymorphic methods of m_pImpl. There 105 // should be no need to override these in subclasses. 106 FWL_Error GetClassName(CFX_WideString& wsClass) const; 107 FWL_Type GetClassID() const; 108 FX_BOOL IsInstance(const CFX_WideStringC& wsClass) const; 109 FWL_Error Initialize(); 110 FWL_Error Finalize(); 111 GetImpl()112 CFWL_WidgetImp* GetImpl() const { return m_pImpl.get(); } 113 114 protected: 115 // Takes ownership of |pImpl|. SetImpl(CFWL_WidgetImp * pImpl)116 void SetImpl(CFWL_WidgetImp* pImpl) { m_pImpl.reset(pImpl); } 117 118 private: 119 std::unique_ptr<CFWL_WidgetImp> m_pImpl; 120 }; 121 122 #endif // XFA_FWL_CORE_IFWL_WIDGET_H_ 123