blob: 92491a06f3577ecc5afdabad53931b68036ebe3d [file] [log] [blame]
Tom Sepez99ffdb02016-01-26 14:51:21 -08001// 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
dsinclair447b1f32016-12-08 10:06:32 -08007#ifndef XFA_FWL_CFWL_WIDGET_H_
8#define XFA_FWL_CFWL_WIDGET_H_
Tom Sepezcc205132017-05-16 14:01:47 -07009
weili5d8e5aa2016-08-08 17:30:37 -070010#include <memory>
11
dsinclair2c489cc2016-11-23 16:17:20 -080012#include "core/fxcrt/fx_coordinates.h"
13#include "core/fxcrt/fx_system.h"
Dan Sinclairaee0db02017-09-21 16:53:58 -040014#include "core/fxcrt/unowned_ptr.h"
Lei Zhang6e59fb52018-01-18 19:03:58 +000015#include "xfa/fde/cfde_data.h"
dsinclair447b1f32016-12-08 10:06:32 -080016#include "xfa/fwl/cfwl_event.h"
17#include "xfa/fwl/cfwl_themepart.h"
18#include "xfa/fwl/cfwl_widgetmgr.h"
Tom Sepezbcdbeae2018-08-21 23:07:21 +000019#include "xfa/fwl/cfwl_widgetproperties.h"
dsinclair447b1f32016-12-08 10:06:32 -080020#include "xfa/fwl/fwl_widgethit.h"
21#include "xfa/fwl/ifwl_widgetdelegate.h"
Tom Sepez99ffdb02016-01-26 14:51:21 -080022
dsinclair2c489cc2016-11-23 16:17:20 -080023enum 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
43class CFWL_App;
44class CFWL_AppImp;
dsinclair447b1f32016-12-08 10:06:32 -080045class CFWL_MessageKey;
Tom Sepez99ffdb02016-01-26 14:51:21 -080046class CFWL_Widget;
Tom Sepez99ffdb02016-01-26 14:51:21 -080047class CFWL_WidgetMgr;
dsinclair89ab4992016-12-08 14:06:10 -080048class CXFA_FFWidget;
dsinclair2c489cc2016-11-23 16:17:20 -080049class IFWL_ThemeProvider;
Tom Sepez99ffdb02016-01-26 14:51:21 -080050
dsinclair2c489cc2016-11-23 16:17:20 -080051class CFWL_Widget : public IFWL_WidgetDelegate {
Tom Sepez99ffdb02016-01-26 14:51:21 -080052 public:
dsinclair2c489cc2016-11-23 16:17:20 -080053 ~CFWL_Widget() override;
dsinclairb4d40ff2016-05-05 10:28:02 -070054
dsinclair2c489cc2016-11-23 16:17:20 -080055 virtual FWL_Type GetClassID() const = 0;
Tom Sepez13653742018-11-28 23:13:53 +000056 virtual bool IsForm() const;
dsinclairda911bc2016-12-07 18:47:00 -080057 virtual CFX_RectF GetAutosizedWidgetRect();
58 virtual CFX_RectF GetWidgetRect();
dsinclair43ac44c2016-12-08 14:05:14 -080059 virtual CFX_RectF GetClientRect();
dsinclair2c489cc2016-11-23 16:17:20 -080060 virtual void ModifyStylesEx(uint32_t dwStylesExAdded,
61 uint32_t dwStylesExRemoved);
dsinclair7fa190d2016-12-07 17:23:28 -080062 virtual void SetStates(uint32_t dwStates);
63 virtual void RemoveStates(uint32_t dwStates);
dsinclair2c489cc2016-11-23 16:17:20 -080064 virtual void Update() = 0;
Dan Sinclairb45ea1f2017-02-21 14:27:59 -050065 virtual FWL_WidgetHit HitTest(const CFX_PointF& point);
Dan Sinclair2b918c82017-07-13 14:47:10 -040066 virtual void DrawWidget(CXFA_Graphics* pGraphics,
Lei Zhang4b472142017-08-17 14:30:08 -070067 const CFX_Matrix& matrix) = 0;
dsinclair2c489cc2016-11-23 16:17:20 -080068 virtual void SetThemeProvider(IFWL_ThemeProvider* pThemeProvider);
weili5d8e5aa2016-08-08 17:30:37 -070069
dsinclair2c489cc2016-11-23 16:17:20 -080070 // IFWL_WidgetDelegate.
71 void OnProcessMessage(CFWL_Message* pMessage) override;
72 void OnProcessEvent(CFWL_Event* pEvent) override;
Dan Sinclair2b918c82017-07-13 14:47:10 -040073 void OnDrawWidget(CXFA_Graphics* pGraphics,
Lei Zhang4b472142017-08-17 14:30:08 -070074 const CFX_Matrix& matrix) override;
dsinclair2c489cc2016-11-23 16:17:20 -080075
dsinclair67c6ca32016-12-07 18:24:00 -080076 void InflateWidgetRect(CFX_RectF& rect);
dsinclair98329fe2016-11-10 09:40:14 -080077 void SetWidgetRect(const CFX_RectF& rect);
dsinclair73895de2016-10-20 07:19:43 -070078
dsinclair2c489cc2016-11-23 16:17:20 -080079 void SetParent(CFWL_Widget* pParent);
80
Tom Sepez7c8f33a2018-11-29 00:19:45 +000081 bool IsVisible() const;
82 bool IsOverLapper() const;
83 bool IsPopup() const;
84 bool IsChild() const;
85
dsinclair2c489cc2016-11-23 16:17:20 -080086 CFWL_Widget* GetOwner() { return m_pWidgetMgr->GetOwnerWidget(this); }
87 CFWL_Widget* GetOuter() const { return m_pOuter; }
88
89 uint32_t GetStyles() const;
dsinclair98329fe2016-11-10 09:40:14 -080090 void ModifyStyles(uint32_t dwStylesAdded, uint32_t dwStylesRemoved);
dsinclair2c489cc2016-11-23 16:17:20 -080091 uint32_t GetStylesEx() const;
92 uint32_t GetStates() const;
dsinclair73895de2016-10-20 07:19:43 -070093
dsinclair2c489cc2016-11-23 16:17:20 -080094 void LockUpdate() { m_iLock++; }
95 void UnlockUpdate() {
96 if (IsLocked())
97 m_iLock--;
98 }
tsepez54ab2342016-05-26 17:35:54 -070099
Dan Sinclair1f403ce2017-02-21 12:56:24 -0500100 CFX_PointF TransformTo(CFWL_Widget* pWidget, const CFX_PointF& point);
Tom Sepezbcdbeae2018-08-21 23:07:21 +0000101 CFX_Matrix GetMatrix() const;
102 IFWL_ThemeProvider* GetThemeProvider() const {
103 return m_pProperties->m_pThemeProvider.Get();
104 }
dsinclair73895de2016-10-20 07:19:43 -0700105
dsinclair2c489cc2016-11-23 16:17:20 -0800106 void SetDelegate(IFWL_WidgetDelegate* delegate) { m_pDelegate = delegate; }
107 IFWL_WidgetDelegate* GetDelegate() {
Tom Sepezcc205132017-05-16 14:01:47 -0700108 return m_pDelegate ? m_pDelegate.Get() : this;
dsinclair2c489cc2016-11-23 16:17:20 -0800109 }
110 const IFWL_WidgetDelegate* GetDelegate() const {
Tom Sepezcc205132017-05-16 14:01:47 -0700111 return m_pDelegate ? m_pDelegate.Get() : this;
dsinclair2c489cc2016-11-23 16:17:20 -0800112 }
Tom Sepez99ffdb02016-01-26 14:51:21 -0800113
Tom Sepez797ca5c2017-05-25 12:03:18 -0700114 const CFWL_App* GetOwnerApp() const { return m_pOwnerApp.Get(); }
dsinclair2c489cc2016-11-23 16:17:20 -0800115 uint32_t GetEventKey() const { return m_nEventKey; }
116 void SetEventKey(uint32_t key) { m_nEventKey = key; }
117
dsinclair89ab4992016-12-08 14:06:10 -0800118 CXFA_FFWidget* GetLayoutItem() const { return m_pLayoutItem; }
119 void SetLayoutItem(CXFA_FFWidget* pItem) { m_pLayoutItem = pItem; }
dsinclair2c489cc2016-11-23 16:17:20 -0800120
dsinclair43ac44c2016-12-08 14:05:14 -0800121 void RepaintRect(const CFX_RectF& pRect);
dsinclair7f432a12016-03-29 12:38:01 -0700122
123 protected:
dsinclair2c489cc2016-11-23 16:17:20 -0800124 CFWL_Widget(const CFWL_App* app,
125 std::unique_ptr<CFWL_WidgetProperties> properties,
126 CFWL_Widget* pOuter);
weili5d8e5aa2016-08-08 17:30:37 -0700127
dsinclair2c489cc2016-11-23 16:17:20 -0800128 bool IsEnabled() const;
dsinclair2c489cc2016-11-23 16:17:20 -0800129 bool IsLocked() const { return m_iLock > 0; }
130 bool HasBorder() const;
Tom Sepezb4f27442018-08-23 20:13:46 +0000131 CFX_RectF GetEdgeRect() const;
132 float GetCXBorderSize() const;
133 float GetCYBorderSize() const;
134 CFX_RectF GetRelativeRect() const;
135 IFWL_ThemeProvider* GetAvailableTheme() const;
Ryan Harrison275e2602017-09-18 14:23:18 -0400136 CFX_SizeF CalcTextSize(const WideString& wsText,
dsinclair2c489cc2016-11-23 16:17:20 -0800137 IFWL_ThemeProvider* pTheme,
dsinclair442997c2016-12-07 17:58:41 -0800138 bool bMultiLine);
Ryan Harrison275e2602017-09-18 14:23:18 -0400139 void CalcTextRect(const WideString& wsText,
dsinclair2c489cc2016-11-23 16:17:20 -0800140 IFWL_ThemeProvider* pTheme,
Dan Sinclairdff02ce2017-08-14 10:26:59 -0400141 const FDE_TextStyle& dwTTOStyles,
142 FDE_TextAlignment iTTOAlign,
Henrique Nakashima0b0b0b32018-05-01 21:00:44 +0000143 CFX_RectF* pRect);
dsinclair2c489cc2016-11-23 16:17:20 -0800144 void SetGrab(bool bSet);
dsinclair2c489cc2016-11-23 16:17:20 -0800145 void RegisterEventTarget(CFWL_Widget* pEventSource);
146 void UnregisterEventTarget();
dsinclair2c489cc2016-11-23 16:17:20 -0800147 void DispatchEvent(CFWL_Event* pEvent);
Dan Sinclair2b918c82017-07-13 14:47:10 -0400148 void DrawBorder(CXFA_Graphics* pGraphics,
dsinclair2c489cc2016-11-23 16:17:20 -0800149 CFWL_Part iPartBorder,
150 IFWL_ThemeProvider* pTheme,
Lei Zhang4b472142017-08-17 14:30:08 -0700151 const CFX_Matrix& pMatrix);
dsinclair2c489cc2016-11-23 16:17:20 -0800152
Dan Sinclairaee0db02017-09-21 16:53:58 -0400153 UnownedPtr<const CFWL_App> const m_pOwnerApp;
154 UnownedPtr<CFWL_WidgetMgr> const m_pWidgetMgr;
dsinclair2c489cc2016-11-23 16:17:20 -0800155 std::unique_ptr<CFWL_WidgetProperties> m_pProperties;
156 CFWL_Widget* m_pOuter;
Tom Sepezaff84602019-01-29 22:23:53 +0000157 int32_t m_iLock = 0;
dsinclair2c489cc2016-11-23 16:17:20 -0800158
159 private:
Tom Sepezbcdbeae2018-08-21 23:07:21 +0000160 CFWL_Widget* GetParent() const { return m_pWidgetMgr->GetParentWidget(this); }
dsinclair2c489cc2016-11-23 16:17:20 -0800161 CFX_SizeF GetOffsetFromParent(CFWL_Widget* pParent);
Dan Sinclair2b918c82017-07-13 14:47:10 -0400162 void DrawBackground(CXFA_Graphics* pGraphics,
dsinclair2c489cc2016-11-23 16:17:20 -0800163 CFWL_Part iPartBk,
164 IFWL_ThemeProvider* pTheme,
dsinclair442997c2016-12-07 17:58:41 -0800165 const CFX_Matrix* pMatrix);
dsinclair2c489cc2016-11-23 16:17:20 -0800166 void NotifyDriver();
167 bool IsParent(CFWL_Widget* pParent);
168
Tom Sepezaff84602019-01-29 22:23:53 +0000169 uint32_t m_nEventKey = 0;
170 CXFA_FFWidget* m_pLayoutItem = nullptr;
Dan Sinclairaee0db02017-09-21 16:53:58 -0400171 UnownedPtr<IFWL_WidgetDelegate> m_pDelegate;
Tom Sepez99ffdb02016-01-26 14:51:21 -0800172};
Dan Sinclairc7cd8092016-02-18 15:02:55 -0500173
dsinclair447b1f32016-12-08 10:06:32 -0800174#endif // XFA_FWL_CFWL_WIDGET_H_