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