Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
cfwl_widget.cpp
Go to the documentation of this file.
1// Copyright 2014 The PDFium Authors
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#include "xfa/fwl/cfwl_widget.h"
8
9#include <algorithm>
10#include <utility>
11#include <vector>
12
13#include "core/fxcrt/check.h"
14#include "v8/include/cppgc/visitor.h"
15#include "xfa/fde/cfde_textout.h"
16#include "xfa/fwl/cfwl_app.h"
17#include "xfa/fwl/cfwl_combobox.h"
18#include "xfa/fwl/cfwl_event.h"
19#include "xfa/fwl/cfwl_eventmouse.h"
20#include "xfa/fwl/cfwl_messagekey.h"
21#include "xfa/fwl/cfwl_messagekillfocus.h"
22#include "xfa/fwl/cfwl_messagemouse.h"
23#include "xfa/fwl/cfwl_messagemousewheel.h"
24#include "xfa/fwl/cfwl_messagesetfocus.h"
25#include "xfa/fwl/cfwl_notedriver.h"
26#include "xfa/fwl/cfwl_themebackground.h"
27#include "xfa/fwl/cfwl_themepart.h"
28#include "xfa/fwl/cfwl_themetext.h"
29#include "xfa/fwl/cfwl_widgetmgr.h"
30#include "xfa/fwl/ifwl_themeprovider.h"
31
32namespace pdfium {
33
34namespace {
35
36constexpr float kCalcHeight = 2048.0f;
37constexpr float kCalcWidth = 2048.0f;
38constexpr float kCalcMultiLineDefWidth = 120.0f;
39
40} // namespace
41
42CFWL_Widget::CFWL_Widget(CFWL_App* app,
43 const Properties& properties,
44 CFWL_Widget* pOuter)
45 : m_Properties(properties),
49 m_pWidgetMgr->InsertWidget(m_pOuter, this);
50}
51
52CFWL_Widget::~CFWL_Widget() = default;
53
55 CHECK(!IsLocked()); // Prefer hard stop to UaF.
56 NotifyDriver();
57 m_pWidgetMgr->RemoveWidget(this);
58}
59
60void CFWL_Widget::Trace(cppgc::Visitor* visitor) const {
61 visitor->Trace(m_pAdapterIface);
62 visitor->Trace(m_pFWLApp);
63 visitor->Trace(m_pWidgetMgr);
64 visitor->Trace(m_pDelegate);
65 visitor->Trace(m_pOuter);
66}
67
68bool CFWL_Widget::IsForm() const {
69 return false;
70}
71
75
79
81 if (!HasBorder())
82 return;
83
84 float fBorder = GetCXBorderSize();
85 rect.Inflate(fBorder, fBorder);
86}
87
89 m_WidgetRect = rect;
90}
91
95
96void CFWL_Widget::ModifyStyles(uint32_t dwStylesAdded,
97 uint32_t dwStylesRemoved) {
98 m_Properties.m_dwStyles &= ~dwStylesRemoved;
99 m_Properties.m_dwStyles |= dwStylesAdded;
100}
101
102void CFWL_Widget::ModifyStyleExts(uint32_t dwStyleExtsAdded,
103 uint32_t dwStyleExtsRemoved) {
104 m_Properties.m_dwStyleExts &= ~dwStyleExtsRemoved;
105 m_Properties.m_dwStyleExts |= dwStyleExtsAdded;
106}
107
108static void NotifyHideChildWidget(CFWL_WidgetMgr* widgetMgr,
109 CFWL_Widget* widget,
110 CFWL_NoteDriver* noteDriver) {
111 CFWL_Widget* child = widgetMgr->GetFirstChildWidget(widget);
112 while (child) {
113 noteDriver->NotifyTargetHide(child);
114 NotifyHideChildWidget(widgetMgr, child, noteDriver);
115 child = widgetMgr->GetNextSiblingWidget(child);
116 }
117}
118
119void CFWL_Widget::SetStates(uint32_t dwStates) {
120 m_Properties.m_dwStates |= dwStates;
121 if (IsVisible())
122 return;
123
124 CFWL_NoteDriver* noteDriver = GetFWLApp()->GetNoteDriver();
125 noteDriver->NotifyTargetHide(this);
126
127 CFWL_WidgetMgr* widgetMgr = GetFWLApp()->GetWidgetMgr();
128 CFWL_Widget* child = widgetMgr->GetFirstChildWidget(this);
129 while (child) {
130 noteDriver->NotifyTargetHide(child);
131 NotifyHideChildWidget(widgetMgr, child, noteDriver);
132 child = widgetMgr->GetNextSiblingWidget(child);
133 }
134}
135
136void CFWL_Widget::RemoveStates(uint32_t dwStates) {
137 m_Properties.m_dwStates &= ~dwStates;
138}
139
147
149 const CFX_PointF& point) {
150 CFX_SizeF szOffset;
151 if (IsParent(pWidget)) {
152 szOffset = GetOffsetFromParent(pWidget);
153 } else {
154 szOffset = pWidget->GetOffsetFromParent(this);
155 szOffset.width = -szOffset.width;
156 szOffset.height = -szOffset.height;
157 }
158 return point + CFX_PointF(szOffset.width, szOffset.height);
159}
160
162 CFWL_Widget* parent = GetParent();
163 std::vector<CFWL_Widget*> parents;
164 while (parent) {
165 parents.push_back(parent);
166 parent = parent->GetParent();
167 }
168
169 CFX_Matrix matrix;
170 for (size_t i = parents.size(); i >= 2; i--) {
171 CFX_RectF rect = parents[i - 2]->GetWidgetRect();
172 matrix.TranslatePrepend(rect.left, rect.top);
173 }
174 return matrix;
175}
176
180
181bool CFWL_Widget::IsEnabled() const {
183}
184
188
192
197
198bool CFWL_Widget::IsPopup() const {
200}
201
202bool CFWL_Widget::IsChild() const {
204}
205
207 CFWL_Widget* pOuter = const_cast<CFWL_Widget*>(this);
208 while (pOuter->GetOuter())
209 pOuter = pOuter->GetOuter();
210 return pOuter;
211}
212
219
223
227
231
232CFX_SizeF CFWL_Widget::CalcTextSize(const WideString& wsText, bool bMultiLine) {
233 CFWL_ThemeText calPart(CFWL_ThemePart::Part::kNone, this, nullptr);
234 calPart.m_wsText = wsText;
235 if (bMultiLine)
236 calPart.m_dwTTOStyles.line_wrap_ = true;
237 else
238 calPart.m_dwTTOStyles.single_line_ = true;
239
241 float fWidth = bMultiLine ? kCalcMultiLineDefWidth : kCalcWidth;
242 CFX_RectF rect(0, 0, fWidth, kCalcHeight);
244 return CFX_SizeF(rect.width, rect.height);
245}
246
248 const FDE_TextStyle& dwTTOStyles,
249 FDE_TextAlignment iTTOAlign,
250 CFX_RectF* pRect) {
251 CFWL_ThemeText calPart(CFWL_ThemePart::Part::kNone, this, nullptr);
252 calPart.m_wsText = wsText;
253 calPart.m_dwTTOStyles = dwTTOStyles;
254 calPart.m_iTTOAlign = iTTOAlign;
256}
257
258void CFWL_Widget::SetGrab(bool bSet) {
259 CFWL_NoteDriver* pDriver = GetFWLApp()->GetNoteDriver();
260 pDriver->SetGrab(bSet ? this : nullptr);
261}
262
264 CFWL_NoteDriver* pNoteDriver = GetFWLApp()->GetNoteDriver();
265 pNoteDriver->UnregisterEventTarget(this);
266}
267
269 if (m_pOuter) {
270 m_pOuter->GetDelegate()->OnProcessEvent(pEvent);
271 return;
272 }
273 CFWL_NoteDriver* pNoteDriver = GetFWLApp()->GetNoteDriver();
274 pNoteDriver->SendEvent(pEvent);
275}
276
277void CFWL_Widget::RepaintRect(const CFX_RectF& pRect) {
278 m_pWidgetMgr->RepaintWidget(this, pRect);
279}
280
281void CFWL_Widget::DrawBackground(CFGAS_GEGraphics* pGraphics,
282 CFWL_ThemePart::Part iPartBk,
283 const CFX_Matrix& mtMatrix) {
284 CFWL_ThemeBackground param(iPartBk, this, pGraphics);
285 param.m_matrix = mtMatrix;
288}
289
291 CFWL_ThemePart::Part iPartBorder,
292 const CFX_Matrix& matrix) {
293 CFWL_ThemeBackground param(iPartBorder, this, pGraphics);
294 param.m_matrix = matrix;
297}
298
299void CFWL_Widget::NotifyDriver() {
300 CFWL_NoteDriver* pDriver = GetFWLApp()->GetNoteDriver();
301 pDriver->NotifyTargetDestroy(this);
302}
303
304CFX_SizeF CFWL_Widget::GetOffsetFromParent(CFWL_Widget* pParent) {
305 if (pParent == this)
306 return CFX_SizeF();
307
308 CFX_SizeF szRet(m_WidgetRect.left, m_WidgetRect.top);
309 CFWL_WidgetMgr* pWidgetMgr = GetFWLApp()->GetWidgetMgr();
310 CFWL_Widget* pDstWidget = GetParent();
311 while (pDstWidget && pDstWidget != pParent) {
312 CFX_RectF rtDst = pDstWidget->GetWidgetRect();
313 szRet += CFX_SizeF(rtDst.left, rtDst.top);
314 pDstWidget = pWidgetMgr->GetParentWidget(pDstWidget);
315 }
316 return szRet;
317}
318
319bool CFWL_Widget::IsParent(CFWL_Widget* pParent) {
320 CFWL_Widget* pUpWidget = GetParent();
321 while (pUpWidget) {
322 if (pUpWidget == pParent)
323 return true;
324 pUpWidget = pUpWidget->GetParent();
325 }
326 return false;
327}
328
330 CFWL_Widget* pWidget = pMessage->GetDstTarget();
331 if (!pWidget)
332 return;
333
334 switch (pMessage->GetType()) {
336 CFWL_MessageMouse* pMsgMouse = static_cast<CFWL_MessageMouse*>(pMessage);
337 CFWL_EventMouse evt(pWidget, pWidget, pMsgMouse->m_dwCmd);
338 pWidget->DispatchEvent(&evt);
339 break;
340 }
341 default:
342 break;
343 }
344}
345
347
349 : widget_(widget) {
350 widget_->LockUpdate();
351}
352
354 widget_->UnlockUpdate();
355}
356
357} // namespace pdfium
#define FWL_STYLE_WGT_Child
Definition cfwl_widget.h:36
#define FWL_STYLE_WGT_Popup
Definition cfwl_widget.h:35
#define FWL_STATE_WGT_Invisible
Definition cfwl_widget.h:45
#define FWL_STYLE_WGT_OverLapper
Definition cfwl_widget.h:34
#define FWL_STATE_WGT_Disabled
Definition cfwl_widget.h:43
#define FWL_STYLE_WGT_Border
Definition cfwl_widget.h:38
#define FWL_STYLE_WGT_WindowTypeMask
Definition cfwl_widget.h:37
CFX_Matrix & operator=(const CFX_Matrix &other)=default
void TranslatePrepend(float x, float y)
constexpr CFX_RectF()=default
void Inflate(float x, float y)
CFX_RectF & operator=(const CFX_RectF &other)=default
bool Contains(const PointType &p) const
constexpr CFX_RectF(float dst_left, float dst_top, float dst_width, float dst_height)
void Deflate(float x, float y)
CFWL_NoteDriver * GetNoteDriver() const
Definition cfwl_app.h:49
IFWL_ThemeProvider * GetThemeProvider() const
Definition cfwl_app.h:44
CFWL_WidgetMgr * GetWidgetMgr() const
Definition cfwl_app.h:48
CFWL_EventMouse(CFWL_Widget *pSrcTarget, CFWL_Widget *pDstTarget, CFWL_MessageMouse::MouseCommand cmd)
Type GetType() const
CFWL_Widget * GetDstTarget() const
void SendEvent(CFWL_Event *pNote)
void NotifyTargetDestroy(CFWL_Widget *pNoteTarget)
void UnregisterEventTarget(CFWL_Widget *pListener)
void NotifyTargetHide(CFWL_Widget *pNoteTarget)
void SetGrab(CFWL_Widget *pGrab)
CFWL_ThemeBackground(Part iPart, CFWL_Widget *pWidget, CFGAS_GEGraphics *pGraphics)
FDE_TextStyle m_dwTTOStyles
CFWL_ThemeText(Part iPart, CFWL_Widget *pWidget, CFGAS_GEGraphics *pGraphics)
FDE_TextAlignment m_iTTOAlign
CFWL_Widget * GetFirstChildWidget(CFWL_Widget *pWidget) const
CFWL_Widget * GetNextSiblingWidget(CFWL_Widget *pWidget) const
CFWL_Widget * GetParentWidget(const CFWL_Widget *pWidget) const
void OnProcessMessage(CFWL_Message *pMessage) override
virtual CFX_RectF GetWidgetRect()
void RepaintRect(const CFX_RectF &pRect)
virtual void RemoveStates(uint32_t dwStates)
bool HasBorder() const
CFWL_Widget * GetOutmost() const
void DispatchEvent(CFWL_Event *pEvent)
CFWL_Widget * GetOuter() const
CFX_PointF TransformTo(CFWL_Widget *pWidget, const CFX_PointF &point)
void ModifyStyles(uint32_t dwStylesAdded, uint32_t dwStylesRemoved)
bool IsOverLapper() const
void SetGrab(bool bSet)
float GetCYBorderSize() const
virtual CFX_RectF GetAutosizedWidgetRect()
CFWL_Widget(CFWL_App *app, const Properties &properties, CFWL_Widget *pOuter)
float GetCXBorderSize() const
void DrawBorder(CFGAS_GEGraphics *pGraphics, CFWL_ThemePart::Part iPartBorder, const CFX_Matrix &pMatrix)
virtual bool IsForm() const
virtual void PreFinalize()
virtual void ModifyStyleExts(uint32_t dwStyleExtsAdded, uint32_t dwStyleExtsRemoved)
void OnProcessEvent(CFWL_Event *pEvent) override
virtual FWL_WidgetHit HitTest(const CFX_PointF &point)
virtual CFX_RectF GetClientRect()
void SetWidgetRect(const CFX_RectF &rect)
CFX_Matrix GetMatrix() const
CFWL_App * GetFWLApp() const
IFWL_ThemeProvider * GetThemeProvider() const
~CFWL_Widget() override
bool IsLocked() const
CFX_RectF GetRelativeRect() const
bool IsVisible() const
void InflateWidgetRect(CFX_RectF &rect)
void CalcTextRect(const WideString &wsText, const FDE_TextStyle &dwTTOStyles, FDE_TextAlignment iTTOAlign, CFX_RectF *pRect)
Properties m_Properties
bool IsEnabled() const
virtual void SetStates(uint32_t dwStates)
CFX_RectF GetEdgeRect() const
CFX_SizeF CalcTextSize(const WideString &wsText, bool bMultiLine)
virtual float GetCYBorderSize() const =0
virtual void CalcTextRect(const CFWL_ThemeText &pParams, CFX_RectF *pRect)=0
virtual void DrawBackground(const CFWL_ThemeBackground &pParams)=0
virtual float GetCXBorderSize() const =0
CFX_PTemplate< float > CFX_PointF
CFX_STemplate< float > CFX_SizeF
static void NotifyHideChildWidget(CFWL_WidgetMgr *widgetMgr, CFWL_Widget *widget, CFWL_NoteDriver *noteDriver)
FDE_TextAlignment
Definition cfde_data.h:14
#define CHECK(cvref)
fxcrt::WideString WideString
Definition widestring.h:207