OLD | NEW |
| (Empty) |
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 | |
7 #ifndef XFA_FWL_CORE_CFWL_WIDGET_H_ | |
8 #define XFA_FWL_CORE_CFWL_WIDGET_H_ | |
9 #include <memory> | |
10 | |
11 #include "core/fxcrt/fx_coordinates.h" | |
12 #include "core/fxcrt/fx_system.h" | |
13 #include "xfa/fwl/core/cfwl_event.h" | |
14 #include "xfa/fwl/core/cfwl_themepart.h" | |
15 #include "xfa/fwl/core/cfwl_widgetmgr.h" | |
16 #include "xfa/fwl/core/fwl_widgethit.h" | |
17 #include "xfa/fwl/core/ifwl_widgetdelegate.h" | |
18 #include "xfa/fwl/theme/cfwl_widgettp.h" | |
19 | |
20 enum class FWL_Type { | |
21 Unknown = 0, | |
22 | |
23 Barcode, | |
24 Caret, | |
25 CheckBox, | |
26 ComboBox, | |
27 DateTimePicker, | |
28 Edit, | |
29 Form, | |
30 FormProxy, | |
31 ListBox, | |
32 MonthCalendar, | |
33 PictureBox, | |
34 PushButton, | |
35 ScrollBar, | |
36 SpinButton, | |
37 ToolTip | |
38 }; | |
39 | |
40 class CFWL_App; | |
41 class CFWL_AppImp; | |
42 class CFWL_MsgKey; | |
43 class CFWL_Widget; | |
44 class CFWL_WidgetMgr; | |
45 class CFWL_WidgetProperties; | |
46 class IFWL_ThemeProvider; | |
47 | |
48 class CFWL_Widget : public IFWL_WidgetDelegate { | |
49 public: | |
50 ~CFWL_Widget() override; | |
51 | |
52 virtual FWL_Type GetClassID() const = 0; | |
53 virtual bool IsInstance(const CFX_WideStringC& wsClass) const; | |
54 virtual CFX_RectF GetAutosizedWidgetRect(); | |
55 virtual CFX_RectF GetWidgetRect(); | |
56 virtual void GetClientRect(CFX_RectF& rect); | |
57 virtual void ModifyStylesEx(uint32_t dwStylesExAdded, | |
58 uint32_t dwStylesExRemoved); | |
59 virtual void SetStates(uint32_t dwStates); | |
60 virtual void RemoveStates(uint32_t dwStates); | |
61 virtual void Update() = 0; | |
62 virtual FWL_WidgetHit HitTest(FX_FLOAT fx, FX_FLOAT fy); | |
63 virtual void DrawWidget(CFX_Graphics* pGraphics, | |
64 const CFX_Matrix* pMatrix) = 0; | |
65 virtual void SetThemeProvider(IFWL_ThemeProvider* pThemeProvider); | |
66 | |
67 // IFWL_WidgetDelegate. | |
68 void OnProcessMessage(CFWL_Message* pMessage) override; | |
69 void OnProcessEvent(CFWL_Event* pEvent) override; | |
70 void OnDrawWidget(CFX_Graphics* pGraphics, | |
71 const CFX_Matrix* pMatrix) override; | |
72 | |
73 void InflateWidgetRect(CFX_RectF& rect); | |
74 void SetWidgetRect(const CFX_RectF& rect); | |
75 | |
76 void SetParent(CFWL_Widget* pParent); | |
77 | |
78 CFWL_Widget* GetOwner() { return m_pWidgetMgr->GetOwnerWidget(this); } | |
79 CFWL_Widget* GetOuter() const { return m_pOuter; } | |
80 | |
81 uint32_t GetStyles() const; | |
82 void ModifyStyles(uint32_t dwStylesAdded, uint32_t dwStylesRemoved); | |
83 uint32_t GetStylesEx() const; | |
84 uint32_t GetStates() const; | |
85 | |
86 void LockUpdate() { m_iLock++; } | |
87 void UnlockUpdate() { | |
88 if (IsLocked()) | |
89 m_iLock--; | |
90 } | |
91 | |
92 void TransformTo(CFWL_Widget* pWidget, FX_FLOAT& fx, FX_FLOAT& fy); | |
93 void GetMatrix(CFX_Matrix& matrix, bool bGlobal); | |
94 IFWL_ThemeProvider* GetThemeProvider() const; | |
95 | |
96 void SetDelegate(IFWL_WidgetDelegate* delegate) { m_pDelegate = delegate; } | |
97 IFWL_WidgetDelegate* GetDelegate() { | |
98 return m_pDelegate ? m_pDelegate : this; | |
99 } | |
100 const IFWL_WidgetDelegate* GetDelegate() const { | |
101 return m_pDelegate ? m_pDelegate : this; | |
102 } | |
103 | |
104 const CFWL_App* GetOwnerApp() const { return m_pOwnerApp; } | |
105 uint32_t GetEventKey() const { return m_nEventKey; } | |
106 void SetEventKey(uint32_t key) { m_nEventKey = key; } | |
107 | |
108 void* GetLayoutItem() const { return m_pLayoutItem; } | |
109 void SetLayoutItem(void* pItem) { m_pLayoutItem = pItem; } | |
110 | |
111 void SetFocus(bool bFocus); | |
112 void Repaint(const CFX_RectF* pRect); | |
113 | |
114 protected: | |
115 CFWL_Widget(const CFWL_App* app, | |
116 std::unique_ptr<CFWL_WidgetProperties> properties, | |
117 CFWL_Widget* pOuter); | |
118 | |
119 bool IsEnabled() const; | |
120 bool IsActive() const; | |
121 bool IsLocked() const { return m_iLock > 0; } | |
122 bool HasBorder() const; | |
123 bool HasEdge() const; | |
124 void GetEdgeRect(CFX_RectF& rtEdge); | |
125 FX_FLOAT GetBorderSize(bool bCX); | |
126 FX_FLOAT GetEdgeWidth(); | |
127 void GetRelativeRect(CFX_RectF& rect); | |
128 void* GetThemeCapacity(CFWL_WidgetCapacity dwCapacity); | |
129 IFWL_ThemeProvider* GetAvailableTheme(); | |
130 CFX_SizeF CalcTextSize(const CFX_WideString& wsText, | |
131 IFWL_ThemeProvider* pTheme, | |
132 bool bMultiLine); | |
133 void CalcTextRect(const CFX_WideString& wsText, | |
134 IFWL_ThemeProvider* pTheme, | |
135 uint32_t dwTTOStyles, | |
136 int32_t iTTOAlign, | |
137 CFX_RectF& rect); | |
138 void SetGrab(bool bSet); | |
139 void GetPopupPos(FX_FLOAT fMinHeight, | |
140 FX_FLOAT fMaxHeight, | |
141 const CFX_RectF& rtAnchor, | |
142 CFX_RectF& rtPopup); | |
143 void RegisterEventTarget(CFWL_Widget* pEventSource); | |
144 void UnregisterEventTarget(); | |
145 void DispatchEvent(CFWL_Event* pEvent); | |
146 void DrawBorder(CFX_Graphics* pGraphics, | |
147 CFWL_Part iPartBorder, | |
148 IFWL_ThemeProvider* pTheme, | |
149 const CFX_Matrix* pMatrix); | |
150 void DrawEdge(CFX_Graphics* pGraphics, | |
151 CFWL_Part iPartEdge, | |
152 IFWL_ThemeProvider* pTheme, | |
153 const CFX_Matrix* pMatrix); | |
154 | |
155 const CFWL_App* const m_pOwnerApp; | |
156 CFWL_WidgetMgr* const m_pWidgetMgr; | |
157 std::unique_ptr<CFWL_WidgetProperties> m_pProperties; | |
158 CFWL_Widget* m_pOuter; | |
159 int32_t m_iLock; | |
160 | |
161 private: | |
162 CFWL_Widget* GetParent() { return m_pWidgetMgr->GetParentWidget(this); } | |
163 CFX_SizeF GetOffsetFromParent(CFWL_Widget* pParent); | |
164 | |
165 bool IsVisible() const; | |
166 bool IsOverLapper() const; | |
167 bool IsPopup() const; | |
168 bool IsChild() const; | |
169 bool IsOffscreen() const; | |
170 CFWL_Widget* GetRootOuter(); | |
171 bool GetPopupPosMenu(FX_FLOAT fMinHeight, | |
172 FX_FLOAT fMaxHeight, | |
173 const CFX_RectF& rtAnchor, | |
174 CFX_RectF& rtPopup); | |
175 bool GetPopupPosComboBox(FX_FLOAT fMinHeight, | |
176 FX_FLOAT fMaxHeight, | |
177 const CFX_RectF& rtAnchor, | |
178 CFX_RectF& rtPopup); | |
179 bool GetPopupPosGeneral(FX_FLOAT fMinHeight, | |
180 FX_FLOAT fMaxHeight, | |
181 const CFX_RectF& rtAnchor, | |
182 CFX_RectF& rtPopup); | |
183 bool GetScreenSize(FX_FLOAT& fx, FX_FLOAT& fy); | |
184 void DrawBackground(CFX_Graphics* pGraphics, | |
185 CFWL_Part iPartBk, | |
186 IFWL_ThemeProvider* pTheme, | |
187 const CFX_Matrix* pMatrix); | |
188 void NotifyDriver(); | |
189 bool IsParent(CFWL_Widget* pParent); | |
190 | |
191 void* m_pLayoutItem; | |
192 uint32_t m_nEventKey; | |
193 IFWL_WidgetDelegate* m_pDelegate; // Not owned. | |
194 }; | |
195 | |
196 #endif // XFA_FWL_CORE_CFWL_WIDGET_H_ | |
OLD | NEW |