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" |
Dan Sinclair | dff02ce | 2017-08-14 10:26:59 -0400 | [diff] [blame] | 15 | #include "xfa/fde/cfde_textout.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" |
| 19 | #include "xfa/fwl/fwl_widgethit.h" |
| 20 | #include "xfa/fwl/ifwl_widgetdelegate.h" |
Tom Sepez | 99ffdb0 | 2016-01-26 14:51:21 -0800 | [diff] [blame] | 21 | |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 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; |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 44 | class CFWL_MessageKey; |
Tom Sepez | 99ffdb0 | 2016-01-26 14:51:21 -0800 | [diff] [blame] | 45 | class CFWL_Widget; |
Tom Sepez | 99ffdb0 | 2016-01-26 14:51:21 -0800 | [diff] [blame] | 46 | class CFWL_WidgetMgr; |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 47 | class CFWL_WidgetProperties; |
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); |
dsinclair | 1babeee | 2016-12-08 19:45:00 -0800 | [diff] [blame] | 96 | CFX_Matrix GetMatrix(); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 97 | IFWL_ThemeProvider* GetThemeProvider() const; |
dsinclair | 73895de | 2016-10-20 07:19:43 -0700 | [diff] [blame] | 98 | |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 99 | void SetDelegate(IFWL_WidgetDelegate* delegate) { m_pDelegate = delegate; } |
| 100 | IFWL_WidgetDelegate* GetDelegate() { |
Tom Sepez | cc20513 | 2017-05-16 14:01:47 -0700 | [diff] [blame] | 101 | return m_pDelegate ? m_pDelegate.Get() : this; |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 102 | } |
| 103 | const IFWL_WidgetDelegate* GetDelegate() const { |
Tom Sepez | cc20513 | 2017-05-16 14:01:47 -0700 | [diff] [blame] | 104 | return m_pDelegate ? m_pDelegate.Get() : this; |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 105 | } |
Tom Sepez | 99ffdb0 | 2016-01-26 14:51:21 -0800 | [diff] [blame] | 106 | |
Tom Sepez | 797ca5c | 2017-05-25 12:03:18 -0700 | [diff] [blame] | 107 | const CFWL_App* GetOwnerApp() const { return m_pOwnerApp.Get(); } |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 108 | uint32_t GetEventKey() const { return m_nEventKey; } |
| 109 | void SetEventKey(uint32_t key) { m_nEventKey = key; } |
| 110 | |
dsinclair | 89ab499 | 2016-12-08 14:06:10 -0800 | [diff] [blame] | 111 | CXFA_FFWidget* GetLayoutItem() const { return m_pLayoutItem; } |
| 112 | void SetLayoutItem(CXFA_FFWidget* pItem) { m_pLayoutItem = pItem; } |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 113 | |
| 114 | void SetFocus(bool bFocus); |
dsinclair | 43ac44c | 2016-12-08 14:05:14 -0800 | [diff] [blame] | 115 | void RepaintRect(const CFX_RectF& pRect); |
| 116 | void Repaint(); |
dsinclair | 7f432a1 | 2016-03-29 12:38:01 -0700 | [diff] [blame] | 117 | |
| 118 | protected: |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 119 | CFWL_Widget(const CFWL_App* app, |
| 120 | std::unique_ptr<CFWL_WidgetProperties> properties, |
| 121 | CFWL_Widget* pOuter); |
weili | 5d8e5aa | 2016-08-08 17:30:37 -0700 | [diff] [blame] | 122 | |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 123 | bool IsEnabled() const; |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 124 | bool IsLocked() const { return m_iLock > 0; } |
| 125 | bool HasBorder() const; |
dsinclair | 43ac44c | 2016-12-08 14:05:14 -0800 | [diff] [blame] | 126 | CFX_RectF GetEdgeRect(); |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 127 | float GetBorderSize(bool bCX); |
dsinclair | 43ac44c | 2016-12-08 14:05:14 -0800 | [diff] [blame] | 128 | CFX_RectF GetRelativeRect(); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 129 | IFWL_ThemeProvider* GetAvailableTheme(); |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 130 | CFX_SizeF CalcTextSize(const WideString& wsText, |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 131 | IFWL_ThemeProvider* pTheme, |
dsinclair | 442997c | 2016-12-07 17:58:41 -0800 | [diff] [blame] | 132 | bool bMultiLine); |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 133 | void CalcTextRect(const WideString& wsText, |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 134 | IFWL_ThemeProvider* pTheme, |
Dan Sinclair | dff02ce | 2017-08-14 10:26:59 -0400 | [diff] [blame] | 135 | const FDE_TextStyle& dwTTOStyles, |
| 136 | FDE_TextAlignment iTTOAlign, |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 137 | CFX_RectF& rect); |
| 138 | void SetGrab(bool bSet); |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 139 | void GetPopupPos(float fMinHeight, |
| 140 | float fMaxHeight, |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 141 | const CFX_RectF& rtAnchor, |
| 142 | CFX_RectF& rtPopup); |
| 143 | void RegisterEventTarget(CFWL_Widget* pEventSource); |
| 144 | void UnregisterEventTarget(); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 145 | void DispatchEvent(CFWL_Event* pEvent); |
Dan Sinclair | 2b918c8 | 2017-07-13 14:47:10 -0400 | [diff] [blame] | 146 | void DrawBorder(CXFA_Graphics* pGraphics, |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 147 | CFWL_Part iPartBorder, |
| 148 | IFWL_ThemeProvider* pTheme, |
Lei Zhang | 4b47214 | 2017-08-17 14:30:08 -0700 | [diff] [blame] | 149 | const CFX_Matrix& pMatrix); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 150 | |
Dan Sinclair | aee0db0 | 2017-09-21 16:53:58 -0400 | [diff] [blame] | 151 | UnownedPtr<const CFWL_App> const m_pOwnerApp; |
| 152 | UnownedPtr<CFWL_WidgetMgr> const m_pWidgetMgr; |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 153 | std::unique_ptr<CFWL_WidgetProperties> m_pProperties; |
| 154 | CFWL_Widget* m_pOuter; |
| 155 | int32_t m_iLock; |
| 156 | |
| 157 | private: |
| 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; |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 165 | CFWL_Widget* GetRootOuter(); |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 166 | bool GetPopupPosMenu(float fMinHeight, |
| 167 | float fMaxHeight, |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 168 | const CFX_RectF& rtAnchor, |
| 169 | CFX_RectF& rtPopup); |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 170 | bool GetPopupPosComboBox(float fMinHeight, |
| 171 | float fMaxHeight, |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 172 | const CFX_RectF& rtAnchor, |
| 173 | CFX_RectF& rtPopup); |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 174 | bool GetPopupPosGeneral(float fMinHeight, |
| 175 | float fMaxHeight, |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 176 | const CFX_RectF& rtAnchor, |
| 177 | CFX_RectF& rtPopup); |
Dan Sinclair | 2b918c8 | 2017-07-13 14:47:10 -0400 | [diff] [blame] | 178 | void DrawBackground(CXFA_Graphics* pGraphics, |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 179 | CFWL_Part iPartBk, |
| 180 | IFWL_ThemeProvider* pTheme, |
dsinclair | 442997c | 2016-12-07 17:58:41 -0800 | [diff] [blame] | 181 | const CFX_Matrix* pMatrix); |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 182 | void NotifyDriver(); |
| 183 | bool IsParent(CFWL_Widget* pParent); |
| 184 | |
dsinclair | 89ab499 | 2016-12-08 14:06:10 -0800 | [diff] [blame] | 185 | CXFA_FFWidget* m_pLayoutItem; |
dsinclair | 2c489cc | 2016-11-23 16:17:20 -0800 | [diff] [blame] | 186 | uint32_t m_nEventKey; |
Dan Sinclair | aee0db0 | 2017-09-21 16:53:58 -0400 | [diff] [blame] | 187 | UnownedPtr<IFWL_WidgetDelegate> m_pDelegate; |
Tom Sepez | 99ffdb0 | 2016-01-26 14:51:21 -0800 | [diff] [blame] | 188 | }; |
Dan Sinclair | c7cd809 | 2016-02-18 15:02:55 -0500 | [diff] [blame] | 189 | |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 190 | #endif // XFA_FWL_CFWL_WIDGET_H_ |