blob: 13b06a9b49ab744ee5551e2fc07efdf1e2c5f224 [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;
Ryan Harrison275e2602017-09-18 14:23:18 -040056 virtual bool IsInstance(const WideStringView& wsClass) 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
81 CFWL_Widget* GetOwner() { return m_pWidgetMgr->GetOwnerWidget(this); }
82 CFWL_Widget* GetOuter() const { return m_pOuter; }
83
84 uint32_t GetStyles() const;
dsinclair98329fe2016-11-10 09:40:14 -080085 void ModifyStyles(uint32_t dwStylesAdded, uint32_t dwStylesRemoved);
dsinclair2c489cc2016-11-23 16:17:20 -080086 uint32_t GetStylesEx() const;
87 uint32_t GetStates() const;
dsinclair73895de2016-10-20 07:19:43 -070088
dsinclair2c489cc2016-11-23 16:17:20 -080089 void LockUpdate() { m_iLock++; }
90 void UnlockUpdate() {
91 if (IsLocked())
92 m_iLock--;
93 }
tsepez54ab2342016-05-26 17:35:54 -070094
Dan Sinclair1f403ce2017-02-21 12:56:24 -050095 CFX_PointF TransformTo(CFWL_Widget* pWidget, const CFX_PointF& point);
Tom Sepezbcdbeae2018-08-21 23:07:21 +000096 CFX_Matrix GetMatrix() const;
97 IFWL_ThemeProvider* GetThemeProvider() const {
98 return m_pProperties->m_pThemeProvider.Get();
99 }
dsinclair73895de2016-10-20 07:19:43 -0700100
dsinclair2c489cc2016-11-23 16:17:20 -0800101 void SetDelegate(IFWL_WidgetDelegate* delegate) { m_pDelegate = delegate; }
102 IFWL_WidgetDelegate* GetDelegate() {
Tom Sepezcc205132017-05-16 14:01:47 -0700103 return m_pDelegate ? m_pDelegate.Get() : this;
dsinclair2c489cc2016-11-23 16:17:20 -0800104 }
105 const IFWL_WidgetDelegate* GetDelegate() const {
Tom Sepezcc205132017-05-16 14:01:47 -0700106 return m_pDelegate ? m_pDelegate.Get() : this;
dsinclair2c489cc2016-11-23 16:17:20 -0800107 }
Tom Sepez99ffdb02016-01-26 14:51:21 -0800108
Tom Sepez797ca5c2017-05-25 12:03:18 -0700109 const CFWL_App* GetOwnerApp() const { return m_pOwnerApp.Get(); }
dsinclair2c489cc2016-11-23 16:17:20 -0800110 uint32_t GetEventKey() const { return m_nEventKey; }
111 void SetEventKey(uint32_t key) { m_nEventKey = key; }
112
dsinclair89ab4992016-12-08 14:06:10 -0800113 CXFA_FFWidget* GetLayoutItem() const { return m_pLayoutItem; }
114 void SetLayoutItem(CXFA_FFWidget* pItem) { m_pLayoutItem = pItem; }
dsinclair2c489cc2016-11-23 16:17:20 -0800115
dsinclair43ac44c2016-12-08 14:05:14 -0800116 void RepaintRect(const CFX_RectF& pRect);
117 void Repaint();
dsinclair7f432a12016-03-29 12:38:01 -0700118
119 protected:
dsinclair2c489cc2016-11-23 16:17:20 -0800120 CFWL_Widget(const CFWL_App* app,
121 std::unique_ptr<CFWL_WidgetProperties> properties,
122 CFWL_Widget* pOuter);
weili5d8e5aa2016-08-08 17:30:37 -0700123
dsinclair2c489cc2016-11-23 16:17:20 -0800124 bool IsEnabled() const;
dsinclair2c489cc2016-11-23 16:17:20 -0800125 bool IsLocked() const { return m_iLock > 0; }
126 bool HasBorder() const;
dsinclair43ac44c2016-12-08 14:05:14 -0800127 CFX_RectF GetEdgeRect();
Dan Sinclair05df0752017-03-14 14:43:42 -0400128 float GetBorderSize(bool bCX);
dsinclair43ac44c2016-12-08 14:05:14 -0800129 CFX_RectF GetRelativeRect();
dsinclair2c489cc2016-11-23 16:17:20 -0800130 IFWL_ThemeProvider* GetAvailableTheme();
Ryan Harrison275e2602017-09-18 14:23:18 -0400131 CFX_SizeF CalcTextSize(const WideString& wsText,
dsinclair2c489cc2016-11-23 16:17:20 -0800132 IFWL_ThemeProvider* pTheme,
dsinclair442997c2016-12-07 17:58:41 -0800133 bool bMultiLine);
Ryan Harrison275e2602017-09-18 14:23:18 -0400134 void CalcTextRect(const WideString& wsText,
dsinclair2c489cc2016-11-23 16:17:20 -0800135 IFWL_ThemeProvider* pTheme,
Dan Sinclairdff02ce2017-08-14 10:26:59 -0400136 const FDE_TextStyle& dwTTOStyles,
137 FDE_TextAlignment iTTOAlign,
Henrique Nakashima0b0b0b32018-05-01 21:00:44 +0000138 CFX_RectF* pRect);
dsinclair2c489cc2016-11-23 16:17:20 -0800139 void SetGrab(bool bSet);
dsinclair2c489cc2016-11-23 16:17:20 -0800140 void RegisterEventTarget(CFWL_Widget* pEventSource);
141 void UnregisterEventTarget();
dsinclair2c489cc2016-11-23 16:17:20 -0800142 void DispatchEvent(CFWL_Event* pEvent);
Dan Sinclair2b918c82017-07-13 14:47:10 -0400143 void DrawBorder(CXFA_Graphics* pGraphics,
dsinclair2c489cc2016-11-23 16:17:20 -0800144 CFWL_Part iPartBorder,
145 IFWL_ThemeProvider* pTheme,
Lei Zhang4b472142017-08-17 14:30:08 -0700146 const CFX_Matrix& pMatrix);
dsinclair2c489cc2016-11-23 16:17:20 -0800147
Dan Sinclairaee0db02017-09-21 16:53:58 -0400148 UnownedPtr<const CFWL_App> const m_pOwnerApp;
149 UnownedPtr<CFWL_WidgetMgr> const m_pWidgetMgr;
dsinclair2c489cc2016-11-23 16:17:20 -0800150 std::unique_ptr<CFWL_WidgetProperties> m_pProperties;
151 CFWL_Widget* m_pOuter;
152 int32_t m_iLock;
153
154 private:
Tom Sepezbcdbeae2018-08-21 23:07:21 +0000155 CFWL_Widget* GetParent() const { return m_pWidgetMgr->GetParentWidget(this); }
dsinclair2c489cc2016-11-23 16:17:20 -0800156 CFX_SizeF GetOffsetFromParent(CFWL_Widget* pParent);
157
158 bool IsVisible() const;
159 bool IsOverLapper() const;
160 bool IsPopup() const;
161 bool IsChild() const;
dsinclair2c489cc2016-11-23 16:17:20 -0800162 CFWL_Widget* GetRootOuter();
Dan Sinclair2b918c82017-07-13 14:47:10 -0400163 void DrawBackground(CXFA_Graphics* pGraphics,
dsinclair2c489cc2016-11-23 16:17:20 -0800164 CFWL_Part iPartBk,
165 IFWL_ThemeProvider* pTheme,
dsinclair442997c2016-12-07 17:58:41 -0800166 const CFX_Matrix* pMatrix);
dsinclair2c489cc2016-11-23 16:17:20 -0800167 void NotifyDriver();
168 bool IsParent(CFWL_Widget* pParent);
169
dsinclair89ab4992016-12-08 14:06:10 -0800170 CXFA_FFWidget* m_pLayoutItem;
dsinclair2c489cc2016-11-23 16:17:20 -0800171 uint32_t m_nEventKey;
Dan Sinclairaee0db02017-09-21 16:53:58 -0400172 UnownedPtr<IFWL_WidgetDelegate> m_pDelegate;
Tom Sepez99ffdb02016-01-26 14:51:21 -0800173};
Dan Sinclairc7cd8092016-02-18 15:02:55 -0500174
dsinclair447b1f32016-12-08 10:06:32 -0800175#endif // XFA_FWL_CFWL_WIDGET_H_