blob: 85f9b768d3ae764d9d92f76306a7a637b88c0958 [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"
19#include "xfa/fwl/fwl_widgethit.h"
20#include "xfa/fwl/ifwl_widgetdelegate.h"
Tom Sepez99ffdb02016-01-26 14:51:21 -080021
dsinclair2c489cc2016-11-23 16:17:20 -080022enum 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
42class CFWL_App;
43class CFWL_AppImp;
dsinclair447b1f32016-12-08 10:06:32 -080044class CFWL_MessageKey;
Tom Sepez99ffdb02016-01-26 14:51:21 -080045class CFWL_Widget;
Tom Sepez99ffdb02016-01-26 14:51:21 -080046class CFWL_WidgetMgr;
dsinclair2c489cc2016-11-23 16:17:20 -080047class CFWL_WidgetProperties;
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);
dsinclair1babeee2016-12-08 19:45:00 -080096 CFX_Matrix GetMatrix();
dsinclair2c489cc2016-11-23 16:17:20 -080097 IFWL_ThemeProvider* GetThemeProvider() const;
dsinclair73895de2016-10-20 07:19:43 -070098
dsinclair2c489cc2016-11-23 16:17:20 -080099 void SetDelegate(IFWL_WidgetDelegate* delegate) { m_pDelegate = delegate; }
100 IFWL_WidgetDelegate* GetDelegate() {
Tom Sepezcc205132017-05-16 14:01:47 -0700101 return m_pDelegate ? m_pDelegate.Get() : this;
dsinclair2c489cc2016-11-23 16:17:20 -0800102 }
103 const IFWL_WidgetDelegate* GetDelegate() const {
Tom Sepezcc205132017-05-16 14:01:47 -0700104 return m_pDelegate ? m_pDelegate.Get() : this;
dsinclair2c489cc2016-11-23 16:17:20 -0800105 }
Tom Sepez99ffdb02016-01-26 14:51:21 -0800106
Tom Sepez797ca5c2017-05-25 12:03:18 -0700107 const CFWL_App* GetOwnerApp() const { return m_pOwnerApp.Get(); }
dsinclair2c489cc2016-11-23 16:17:20 -0800108 uint32_t GetEventKey() const { return m_nEventKey; }
109 void SetEventKey(uint32_t key) { m_nEventKey = key; }
110
dsinclair89ab4992016-12-08 14:06:10 -0800111 CXFA_FFWidget* GetLayoutItem() const { return m_pLayoutItem; }
112 void SetLayoutItem(CXFA_FFWidget* pItem) { m_pLayoutItem = pItem; }
dsinclair2c489cc2016-11-23 16:17:20 -0800113
114 void SetFocus(bool bFocus);
dsinclair43ac44c2016-12-08 14:05:14 -0800115 void RepaintRect(const CFX_RectF& pRect);
116 void Repaint();
dsinclair7f432a12016-03-29 12:38:01 -0700117
118 protected:
dsinclair2c489cc2016-11-23 16:17:20 -0800119 CFWL_Widget(const CFWL_App* app,
120 std::unique_ptr<CFWL_WidgetProperties> properties,
121 CFWL_Widget* pOuter);
weili5d8e5aa2016-08-08 17:30:37 -0700122
dsinclair2c489cc2016-11-23 16:17:20 -0800123 bool IsEnabled() const;
dsinclair2c489cc2016-11-23 16:17:20 -0800124 bool IsLocked() const { return m_iLock > 0; }
125 bool HasBorder() const;
dsinclair43ac44c2016-12-08 14:05:14 -0800126 CFX_RectF GetEdgeRect();
Dan Sinclair05df0752017-03-14 14:43:42 -0400127 float GetBorderSize(bool bCX);
dsinclair43ac44c2016-12-08 14:05:14 -0800128 CFX_RectF GetRelativeRect();
dsinclair2c489cc2016-11-23 16:17:20 -0800129 IFWL_ThemeProvider* GetAvailableTheme();
Ryan Harrison275e2602017-09-18 14:23:18 -0400130 CFX_SizeF CalcTextSize(const WideString& wsText,
dsinclair2c489cc2016-11-23 16:17:20 -0800131 IFWL_ThemeProvider* pTheme,
dsinclair442997c2016-12-07 17:58:41 -0800132 bool bMultiLine);
Ryan Harrison275e2602017-09-18 14:23:18 -0400133 void CalcTextRect(const WideString& wsText,
dsinclair2c489cc2016-11-23 16:17:20 -0800134 IFWL_ThemeProvider* pTheme,
Dan Sinclairdff02ce2017-08-14 10:26:59 -0400135 const FDE_TextStyle& dwTTOStyles,
136 FDE_TextAlignment iTTOAlign,
Henrique Nakashima0b0b0b32018-05-01 21:00:44 +0000137 CFX_RectF* pRect);
dsinclair2c489cc2016-11-23 16:17:20 -0800138 void SetGrab(bool bSet);
dsinclair2c489cc2016-11-23 16:17:20 -0800139 void RegisterEventTarget(CFWL_Widget* pEventSource);
140 void UnregisterEventTarget();
dsinclair2c489cc2016-11-23 16:17:20 -0800141 void DispatchEvent(CFWL_Event* pEvent);
Dan Sinclair2b918c82017-07-13 14:47:10 -0400142 void DrawBorder(CXFA_Graphics* pGraphics,
dsinclair2c489cc2016-11-23 16:17:20 -0800143 CFWL_Part iPartBorder,
144 IFWL_ThemeProvider* pTheme,
Lei Zhang4b472142017-08-17 14:30:08 -0700145 const CFX_Matrix& pMatrix);
dsinclair2c489cc2016-11-23 16:17:20 -0800146
Dan Sinclairaee0db02017-09-21 16:53:58 -0400147 UnownedPtr<const CFWL_App> const m_pOwnerApp;
148 UnownedPtr<CFWL_WidgetMgr> const m_pWidgetMgr;
dsinclair2c489cc2016-11-23 16:17:20 -0800149 std::unique_ptr<CFWL_WidgetProperties> m_pProperties;
150 CFWL_Widget* m_pOuter;
151 int32_t m_iLock;
152
153 private:
154 CFWL_Widget* GetParent() { return m_pWidgetMgr->GetParentWidget(this); }
155 CFX_SizeF GetOffsetFromParent(CFWL_Widget* pParent);
156
157 bool IsVisible() const;
158 bool IsOverLapper() const;
159 bool IsPopup() const;
160 bool IsChild() const;
dsinclair2c489cc2016-11-23 16:17:20 -0800161 CFWL_Widget* GetRootOuter();
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
dsinclair89ab4992016-12-08 14:06:10 -0800169 CXFA_FFWidget* m_pLayoutItem;
dsinclair2c489cc2016-11-23 16:17:20 -0800170 uint32_t m_nEventKey;
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_