Tom Sepez | 99ffdb0 | 2016-01-26 14:51:21 -0800 | [diff] [blame] | 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 | |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 7 | #ifndef XFA_FWL_CFWL_WIDGET_H_ |
| 8 | #define XFA_FWL_CFWL_WIDGET_H_ |
Tom Sepez | cc20513 | 2017-05-16 14:01:47 -0700 | [diff] [blame] | 9 | |
weili | 5d8e5aa | 2016-08-08 17:30:37 -0700 | [diff] [blame] | 10 | #include <memory> |
| 11 | |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 12 | #include "core/fxcrt/fx_coordinates.h" |
| 13 | #include "core/fxcrt/fx_system.h" |
Dan Sinclair | aee0db0 | 2017-09-21 16:53:58 -0400 | [diff] [blame] | 14 | #include "core/fxcrt/unowned_ptr.h" |
Lei Zhang | 6e59fb5 | 2018-01-18 19:03:58 +0000 | [diff] [blame] | 15 | #include "xfa/fde/cfde_data.h" |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 16 | #include "xfa/fwl/cfwl_event.h" |
| 17 | #include "xfa/fwl/cfwl_themepart.h" |
| 18 | #include "xfa/fwl/cfwl_widgetmgr.h" |
Tom Sepez | bcdbeae | 2018-08-21 23:07:21 +0000 | [diff] [blame^] | 19 | #include "xfa/fwl/cfwl_widgetproperties.h" |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 20 | #include "xfa/fwl/fwl_widgethit.h" |
| 21 | #include "xfa/fwl/ifwl_widgetdelegate.h" |
Tom Sepez | 99ffdb0 | 2016-01-26 14:51:21 -0800 | [diff] [blame] | 22 | |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 23 | enum class FWL_Type { |
| 24 | Unknown = 0, |
| 25 | |
| 26 | Barcode, |
| 27 | Caret, |
| 28 | CheckBox, |
| 29 | ComboBox, |
| 30 | DateTimePicker, |
| 31 | Edit, |
| 32 | Form, |
| 33 | FormProxy, |
| 34 | ListBox, |
| 35 | MonthCalendar, |
| 36 | PictureBox, |
| 37 | PushButton, |
| 38 | ScrollBar, |
| 39 | SpinButton, |
| 40 | ToolTip |
| 41 | }; |
| 42 | |
| 43 | class CFWL_App; |
| 44 | class CFWL_AppImp; |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 45 | class CFWL_MessageKey; |
Tom Sepez | 99ffdb0 | 2016-01-26 14:51:21 -0800 | [diff] [blame] | 46 | class CFWL_Widget; |
Tom Sepez | 99ffdb0 | 2016-01-26 14:51:21 -0800 | [diff] [blame] | 47 | class CFWL_WidgetMgr; |
dsinclair | 89ab499 | 2016-12-08 14:06:10 -0800 | [diff] [blame] | 48 | class CXFA_FFWidget; |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 49 | class IFWL_ThemeProvider; |
Tom Sepez | 99ffdb0 | 2016-01-26 14:51:21 -0800 | [diff] [blame] | 50 | |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 51 | class CFWL_Widget : public IFWL_WidgetDelegate { |
Tom Sepez | 99ffdb0 | 2016-01-26 14:51:21 -0800 | [diff] [blame] | 52 | public: |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 53 | ~CFWL_Widget() override; |
dsinclair | b4d40ff | 2016-05-05 10:28:02 -0700 | [diff] [blame] | 54 | |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 55 | virtual FWL_Type GetClassID() const = 0; |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 56 | virtual bool IsInstance(const WideStringView& wsClass) const; |
dsinclair | da911bc | 2016-12-07 18:47:00 -0800 | [diff] [blame] | 57 | virtual CFX_RectF GetAutosizedWidgetRect(); |
| 58 | virtual CFX_RectF GetWidgetRect(); |
dsinclair | 43ac44c | 2016-12-08 14:05:14 -0800 | [diff] [blame] | 59 | virtual CFX_RectF GetClientRect(); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 60 | virtual void ModifyStylesEx(uint32_t dwStylesExAdded, |
| 61 | uint32_t dwStylesExRemoved); |
dsinclair | 7fa190d | 2016-12-07 17:23:28 -0800 | [diff] [blame] | 62 | virtual void SetStates(uint32_t dwStates); |
| 63 | virtual void RemoveStates(uint32_t dwStates); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 64 | virtual void Update() = 0; |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 65 | virtual FWL_WidgetHit HitTest(const CFX_PointF& point); |
Dan Sinclair | 2b918c8 | 2017-07-13 14:47:10 -0400 | [diff] [blame] | 66 | virtual void DrawWidget(CXFA_Graphics* pGraphics, |
Lei Zhang | 4b47214 | 2017-08-17 14:30:08 -0700 | [diff] [blame] | 67 | const CFX_Matrix& matrix) = 0; |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 68 | virtual void SetThemeProvider(IFWL_ThemeProvider* pThemeProvider); |
weili | 5d8e5aa | 2016-08-08 17:30:37 -0700 | [diff] [blame] | 69 | |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 70 | // IFWL_WidgetDelegate. |
| 71 | void OnProcessMessage(CFWL_Message* pMessage) override; |
| 72 | void OnProcessEvent(CFWL_Event* pEvent) override; |
Dan Sinclair | 2b918c8 | 2017-07-13 14:47:10 -0400 | [diff] [blame] | 73 | void OnDrawWidget(CXFA_Graphics* pGraphics, |
Lei Zhang | 4b47214 | 2017-08-17 14:30:08 -0700 | [diff] [blame] | 74 | const CFX_Matrix& matrix) override; |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 75 | |
dsinclair | 67c6ca3 | 2016-12-07 18:24:00 -0800 | [diff] [blame] | 76 | void InflateWidgetRect(CFX_RectF& rect); |
dsinclair | 98329fe | 2016-11-10 09:40:14 -0800 | [diff] [blame] | 77 | void SetWidgetRect(const CFX_RectF& rect); |
dsinclair | 73895de | 2016-10-20 07:19:43 -0700 | [diff] [blame] | 78 | |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 79 | void SetParent(CFWL_Widget* pParent); |
| 80 | |
| 81 | CFWL_Widget* GetOwner() { return m_pWidgetMgr->GetOwnerWidget(this); } |
| 82 | CFWL_Widget* GetOuter() const { return m_pOuter; } |
| 83 | |
| 84 | uint32_t GetStyles() const; |
dsinclair | 98329fe | 2016-11-10 09:40:14 -0800 | [diff] [blame] | 85 | void ModifyStyles(uint32_t dwStylesAdded, uint32_t dwStylesRemoved); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 86 | uint32_t GetStylesEx() const; |
| 87 | uint32_t GetStates() const; |
dsinclair | 73895de | 2016-10-20 07:19:43 -0700 | [diff] [blame] | 88 | |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 89 | void LockUpdate() { m_iLock++; } |
| 90 | void UnlockUpdate() { |
| 91 | if (IsLocked()) |
| 92 | m_iLock--; |
| 93 | } |
tsepez | 54ab234 | 2016-05-26 17:35:54 -0700 | [diff] [blame] | 94 | |
Dan Sinclair | 1f403ce | 2017-02-21 12:56:24 -0500 | [diff] [blame] | 95 | CFX_PointF TransformTo(CFWL_Widget* pWidget, const CFX_PointF& point); |
Tom Sepez | bcdbeae | 2018-08-21 23:07:21 +0000 | [diff] [blame^] | 96 | CFX_Matrix GetMatrix() const; |
| 97 | IFWL_ThemeProvider* GetThemeProvider() const { |
| 98 | return m_pProperties->m_pThemeProvider.Get(); |
| 99 | } |
dsinclair | 73895de | 2016-10-20 07:19:43 -0700 | [diff] [blame] | 100 | |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 101 | void SetDelegate(IFWL_WidgetDelegate* delegate) { m_pDelegate = delegate; } |
| 102 | IFWL_WidgetDelegate* GetDelegate() { |
Tom Sepez | cc20513 | 2017-05-16 14:01:47 -0700 | [diff] [blame] | 103 | return m_pDelegate ? m_pDelegate.Get() : this; |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 104 | } |
| 105 | const IFWL_WidgetDelegate* GetDelegate() const { |
Tom Sepez | cc20513 | 2017-05-16 14:01:47 -0700 | [diff] [blame] | 106 | return m_pDelegate ? m_pDelegate.Get() : this; |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 107 | } |
Tom Sepez | 99ffdb0 | 2016-01-26 14:51:21 -0800 | [diff] [blame] | 108 | |
Tom Sepez | 797ca5c | 2017-05-25 12:03:18 -0700 | [diff] [blame] | 109 | const CFWL_App* GetOwnerApp() const { return m_pOwnerApp.Get(); } |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 110 | uint32_t GetEventKey() const { return m_nEventKey; } |
| 111 | void SetEventKey(uint32_t key) { m_nEventKey = key; } |
| 112 | |
dsinclair | 89ab499 | 2016-12-08 14:06:10 -0800 | [diff] [blame] | 113 | CXFA_FFWidget* GetLayoutItem() const { return m_pLayoutItem; } |
| 114 | void SetLayoutItem(CXFA_FFWidget* pItem) { m_pLayoutItem = pItem; } |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 115 | |
dsinclair | 43ac44c | 2016-12-08 14:05:14 -0800 | [diff] [blame] | 116 | void RepaintRect(const CFX_RectF& pRect); |
| 117 | void Repaint(); |
dsinclair | 7f432a1 | 2016-03-29 12:38:01 -0700 | [diff] [blame] | 118 | |
| 119 | protected: |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 120 | CFWL_Widget(const CFWL_App* app, |
| 121 | std::unique_ptr<CFWL_WidgetProperties> properties, |
| 122 | CFWL_Widget* pOuter); |
weili | 5d8e5aa | 2016-08-08 17:30:37 -0700 | [diff] [blame] | 123 | |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 124 | bool IsEnabled() const; |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 125 | bool IsLocked() const { return m_iLock > 0; } |
| 126 | bool HasBorder() const; |
dsinclair | 43ac44c | 2016-12-08 14:05:14 -0800 | [diff] [blame] | 127 | CFX_RectF GetEdgeRect(); |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 128 | float GetBorderSize(bool bCX); |
dsinclair | 43ac44c | 2016-12-08 14:05:14 -0800 | [diff] [blame] | 129 | CFX_RectF GetRelativeRect(); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 130 | IFWL_ThemeProvider* GetAvailableTheme(); |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 131 | CFX_SizeF CalcTextSize(const WideString& wsText, |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 132 | IFWL_ThemeProvider* pTheme, |
dsinclair | 442997c | 2016-12-07 17:58:41 -0800 | [diff] [blame] | 133 | bool bMultiLine); |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 134 | void CalcTextRect(const WideString& wsText, |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 135 | IFWL_ThemeProvider* pTheme, |
Dan Sinclair | dff02ce | 2017-08-14 10:26:59 -0400 | [diff] [blame] | 136 | const FDE_TextStyle& dwTTOStyles, |
| 137 | FDE_TextAlignment iTTOAlign, |
Henrique Nakashima | 0b0b0b3 | 2018-05-01 21:00:44 +0000 | [diff] [blame] | 138 | CFX_RectF* pRect); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 139 | void SetGrab(bool bSet); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 140 | void RegisterEventTarget(CFWL_Widget* pEventSource); |
| 141 | void UnregisterEventTarget(); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 142 | void DispatchEvent(CFWL_Event* pEvent); |
Dan Sinclair | 2b918c8 | 2017-07-13 14:47:10 -0400 | [diff] [blame] | 143 | void DrawBorder(CXFA_Graphics* pGraphics, |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 144 | CFWL_Part iPartBorder, |
| 145 | IFWL_ThemeProvider* pTheme, |
Lei Zhang | 4b47214 | 2017-08-17 14:30:08 -0700 | [diff] [blame] | 146 | const CFX_Matrix& pMatrix); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 147 | |
Dan Sinclair | aee0db0 | 2017-09-21 16:53:58 -0400 | [diff] [blame] | 148 | UnownedPtr<const CFWL_App> const m_pOwnerApp; |
| 149 | UnownedPtr<CFWL_WidgetMgr> const m_pWidgetMgr; |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 150 | std::unique_ptr<CFWL_WidgetProperties> m_pProperties; |
| 151 | CFWL_Widget* m_pOuter; |
| 152 | int32_t m_iLock; |
| 153 | |
| 154 | private: |
Tom Sepez | bcdbeae | 2018-08-21 23:07:21 +0000 | [diff] [blame^] | 155 | CFWL_Widget* GetParent() const { return m_pWidgetMgr->GetParentWidget(this); } |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 156 | CFX_SizeF GetOffsetFromParent(CFWL_Widget* pParent); |
| 157 | |
| 158 | bool IsVisible() const; |
| 159 | bool IsOverLapper() const; |
| 160 | bool IsPopup() const; |
| 161 | bool IsChild() const; |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 162 | CFWL_Widget* GetRootOuter(); |
Dan Sinclair | 2b918c8 | 2017-07-13 14:47:10 -0400 | [diff] [blame] | 163 | void DrawBackground(CXFA_Graphics* pGraphics, |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 164 | CFWL_Part iPartBk, |
| 165 | IFWL_ThemeProvider* pTheme, |
dsinclair | 442997c | 2016-12-07 17:58:41 -0800 | [diff] [blame] | 166 | const CFX_Matrix* pMatrix); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 167 | void NotifyDriver(); |
| 168 | bool IsParent(CFWL_Widget* pParent); |
| 169 | |
dsinclair | 89ab499 | 2016-12-08 14:06:10 -0800 | [diff] [blame] | 170 | CXFA_FFWidget* m_pLayoutItem; |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 171 | uint32_t m_nEventKey; |
Dan Sinclair | aee0db0 | 2017-09-21 16:53:58 -0400 | [diff] [blame] | 172 | UnownedPtr<IFWL_WidgetDelegate> m_pDelegate; |
Tom Sepez | 99ffdb0 | 2016-01-26 14:51:21 -0800 | [diff] [blame] | 173 | }; |
Dan Sinclair | c7cd809 | 2016-02-18 15:02:55 -0500 | [diff] [blame] | 174 | |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 175 | #endif // XFA_FWL_CFWL_WIDGET_H_ |