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_widgettp.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/theme/cfwl_widgettp.h"
8
9#include <algorithm>
10#include <utility>
11
12#include "xfa/fde/cfde_textout.h"
13#include "xfa/fgas/font/cfgas_gefont.h"
14#include "xfa/fgas/graphics/cfgas_gecolor.h"
15#include "xfa/fgas/graphics/cfgas_gegraphics.h"
16#include "xfa/fgas/graphics/cfgas_gepath.h"
17#include "xfa/fwl/cfwl_themebackground.h"
18#include "xfa/fwl/cfwl_themepart.h"
19#include "xfa/fwl/cfwl_themetext.h"
20#include "xfa/fwl/cfwl_widget.h"
21#include "xfa/fwl/cfwl_widgetmgr.h"
22#include "xfa/fwl/ifwl_themeprovider.h"
23
24namespace pdfium {
25
26CFWL_WidgetTP::CFWL_WidgetTP() = default;
27
28CFWL_WidgetTP::~CFWL_WidgetTP() = default;
29
30void CFWL_WidgetTP::Trace(cppgc::Visitor* visitor) const {}
31
32void CFWL_WidgetTP::DrawBackground(const CFWL_ThemeBackground& pParams) {}
33
34void CFWL_WidgetTP::DrawText(const CFWL_ThemeText& pParams) {
35 EnsureTTOInitialized(pParams.GetWidget()->GetThemeProvider());
36 if (pParams.m_wsText.IsEmpty())
37 return;
38
39 CFGAS_GEGraphics* pGraphics = pParams.GetGraphics();
40 m_pTextOut->SetStyles(pParams.m_dwTTOStyles);
41 m_pTextOut->SetAlignment(pParams.m_iTTOAlign);
42
43 CFX_Matrix matrix = pParams.m_matrix;
44 matrix.Concat(*pGraphics->GetMatrix());
45 m_pTextOut->SetMatrix(matrix);
46 m_pTextOut->DrawLogicText(pGraphics->GetRenderDevice(), pParams.m_wsText,
47 pParams.m_PartRect);
48}
49
51 if (m_pColorData)
52 return;
53
54 m_pColorData = std::make_unique<CColorData>();
55 m_pColorData->clrBorder[0] = ArgbEncode(255, 202, 216, 249);
56 m_pColorData->clrBorder[1] = ArgbEncode(255, 171, 190, 233);
57 m_pColorData->clrBorder[2] = ArgbEncode(255, 135, 147, 219);
58 m_pColorData->clrBorder[3] = ArgbEncode(255, 172, 168, 153);
59 m_pColorData->clrStart[0] = ArgbEncode(255, 225, 234, 254);
60 m_pColorData->clrStart[1] = ArgbEncode(255, 253, 255, 255);
61 m_pColorData->clrStart[2] = ArgbEncode(255, 110, 142, 241);
62 m_pColorData->clrStart[3] = ArgbEncode(255, 254, 254, 251);
63 m_pColorData->clrEnd[0] = ArgbEncode(255, 175, 204, 251);
64 m_pColorData->clrEnd[1] = ArgbEncode(255, 185, 218, 251);
65 m_pColorData->clrEnd[2] = ArgbEncode(255, 210, 222, 235);
66 m_pColorData->clrEnd[3] = ArgbEncode(255, 243, 241, 236);
67 m_pColorData->clrSign[0] = ArgbEncode(255, 77, 97, 133);
68 m_pColorData->clrSign[1] = ArgbEncode(255, 77, 97, 133);
69 m_pColorData->clrSign[2] = ArgbEncode(255, 77, 97, 133);
70 m_pColorData->clrSign[3] = ArgbEncode(255, 128, 128, 128);
71}
72
74 if (m_pTextOut)
75 return;
76
77 m_pTextOut = std::make_unique<CFDE_TextOut>();
78 m_pTextOut->SetFont(pProvider->GetFWLFont());
79 m_pTextOut->SetFontSize(FWLTHEME_CAPACITY_FontSize);
80 m_pTextOut->SetTextColor(FWLTHEME_CAPACITY_TextColor);
81}
82
84 const CFX_RectF& rect,
85 const CFX_Matrix& matrix) {
86 if (!pGraphics)
87 return;
88
89 CFGAS_GEPath path;
90 path.AddRectangle(rect.left, rect.top, rect.width, rect.height);
91 path.AddRectangle(rect.left + 1, rect.top + 1, rect.width - 2,
92 rect.height - 2);
93
94 CFGAS_GEGraphics::StateRestorer restorer(pGraphics);
97}
98
100 const CFX_RectF& rect,
101 const CFX_Matrix& matrix) {
103}
104
106 FX_ARGB fillColor,
107 const CFX_RectF& rect,
108 const CFX_Matrix& matrix) {
109 if (!pGraphics)
110 return;
111
112 CFGAS_GEPath path;
113 path.AddRectangle(rect.left, rect.top, rect.width, rect.height);
114
115 CFGAS_GEGraphics::StateRestorer restorer(pGraphics);
116 pGraphics->SetFillColor(CFGAS_GEColor(fillColor));
118}
119
121 const CFX_RectF& rect,
122 const CFX_Matrix& matrix) {
123 if (!pGraphics)
124 return;
125
126 CFGAS_GEPath path;
127 path.AddRectangle(rect.left, rect.top, rect.width, rect.height);
128
129 CFGAS_GEGraphics::StateRestorer restorer(pGraphics);
130 pGraphics->SetStrokeColor(CFGAS_GEColor(0xFF000000));
131 static constexpr float kDashPattern[2] = {1, 1};
132 pGraphics->SetLineDash(0.0f, kDashPattern);
133 pGraphics->StrokePath(path, matrix);
134}
135
137 const CFX_RectF& rect,
138 FWLTHEME_DIRECTION eDict,
139 FX_ARGB argSign,
140 const CFX_Matrix& matrix) {
141 bool bVert =
143 float fLeft = ((rect.width - (bVert ? 9 : 6)) / 2 + rect.left) + 0.5f;
144 float fTop = ((rect.height - (bVert ? 6 : 9)) / 2 + rect.top) + 0.5f;
145 CFGAS_GEPath path;
146 switch (eDict) {
148 path.MoveTo(CFX_PointF(fLeft, fTop + 1));
149 path.LineTo(CFX_PointF(fLeft + 4, fTop + 5));
150 path.LineTo(CFX_PointF(fLeft + 8, fTop + 1));
151 path.LineTo(CFX_PointF(fLeft + 7, fTop));
152 path.LineTo(CFX_PointF(fLeft + 4, fTop + 3));
153 path.LineTo(CFX_PointF(fLeft + 1, fTop));
154 break;
156 path.MoveTo(CFX_PointF(fLeft, fTop + 4));
157 path.LineTo(CFX_PointF(fLeft + 4, fTop));
158 path.LineTo(CFX_PointF(fLeft + 8, fTop + 4));
159 path.LineTo(CFX_PointF(fLeft + 7, fTop + 5));
160 path.LineTo(CFX_PointF(fLeft + 4, fTop + 2));
161 path.LineTo(CFX_PointF(fLeft + 1, fTop + 5));
162 break;
164 path.MoveTo(CFX_PointF(fLeft + 1, fTop));
165 path.LineTo(CFX_PointF(fLeft + 5, fTop + 4));
166 path.LineTo(CFX_PointF(fLeft + 1, fTop + 8));
167 path.LineTo(CFX_PointF(fLeft, fTop + 7));
168 path.LineTo(CFX_PointF(fLeft + 3, fTop + 4));
169 path.LineTo(CFX_PointF(fLeft, fTop + 1));
170 break;
172 path.MoveTo(CFX_PointF(fLeft, fTop + 4));
173 path.LineTo(CFX_PointF(fLeft + 4, fTop));
174 path.LineTo(CFX_PointF(fLeft + 5, fTop + 1));
175 path.LineTo(CFX_PointF(fLeft + 2, fTop + 4));
176 path.LineTo(CFX_PointF(fLeft + 5, fTop + 7));
177 path.LineTo(CFX_PointF(fLeft + 4, fTop + 8));
178 break;
179 }
180 pGraphics->SetFillColor(CFGAS_GEColor(argSign));
182}
183
185 const CFX_RectF& rect,
186 FWLTHEME_STATE eState,
187 const CFX_Matrix& matrix) {
189 FillSolidRect(pGraphics,
190 m_pColorData->clrEnd[static_cast<size_t>(eState) - 1], rect,
191 matrix);
192
193 CFGAS_GEPath path;
194 path.AddRectangle(rect.left, rect.top, rect.width, rect.height);
195 pGraphics->SetStrokeColor(
196 CFGAS_GEColor(m_pColorData->clrBorder[static_cast<size_t>(eState) - 1]));
197 pGraphics->StrokePath(path, matrix);
198}
199
201 const CFX_RectF& rect,
202 FWLTHEME_DIRECTION eDict,
203 FWLTHEME_STATE eState,
204 const CFX_Matrix& matrix) {
205 DrawBtn(pGraphics, rect, eState, matrix);
207 DrawArrow(pGraphics, rect, eDict,
208 m_pColorData->clrSign[static_cast<size_t>(eState) - 1], matrix);
209}
210
211} // namespace pdfium
#define FWLTHEME_CAPACITY_TextColor
Definition cfwl_utils.h:26
#define FWLTHEME_CAPACITY_FontSize
Definition cfwl_utils.h:25
#define FWLTHEME_COLOR_Background
Definition cfwl_utils.h:22
CFGAS_GEColor(FX_ARGB argb)
StateRestorer(CFGAS_GEGraphics *graphics)
void FillPath(const CFGAS_GEPath &path, CFX_FillRenderOptions::FillType fill_type, const CFX_Matrix &matrix)
void SetStrokeColor(const CFGAS_GEColor &color)
const CFX_Matrix * GetMatrix() const
void SetFillColor(const CFGAS_GEColor &color)
void StrokePath(const CFGAS_GEPath &path, const CFX_Matrix &matrix)
void MoveTo(const CFX_PointF &point)
void AddRectangle(float left, float top, float width, float height)
void LineTo(const CFX_PointF &point)
void Concat(const CFX_Matrix &right)
CFWL_Widget * GetWidget() const
CFGAS_GEGraphics * GetGraphics() const
void FillBackground(CFGAS_GEGraphics *pGraphics, const CFX_RectF &rect, const CFX_Matrix &matrix)
virtual void DrawBackground(const CFWL_ThemeBackground &pParams)
void DrawFocus(CFGAS_GEGraphics *pGraphics, const CFX_RectF &rect, const CFX_Matrix &matrix)
void EnsureTTOInitialized(IFWL_ThemeProvider *pProvider)
void DrawBtn(CFGAS_GEGraphics *pGraphics, const CFX_RectF &rect, FWLTHEME_STATE eState, const CFX_Matrix &matrix)
virtual void DrawText(const CFWL_ThemeText &pParams)
void DrawBorder(CFGAS_GEGraphics *pGraphics, const CFX_RectF &rect, const CFX_Matrix &matrix)
void Trace(cppgc::Visitor *visitor) const
void DrawArrowBtn(CFGAS_GEGraphics *pGraphics, const CFX_RectF &rect, FWLTHEME_DIRECTION eDict, FWLTHEME_STATE eState, const CFX_Matrix &matrix)
void FillSolidRect(CFGAS_GEGraphics *pGraphics, FX_ARGB fillColor, const CFX_RectF &rect, const CFX_Matrix &matrix)
void DrawArrow(CFGAS_GEGraphics *pGraphics, const CFX_RectF &rect, FWLTHEME_DIRECTION eDict, FX_ARGB argSign, const CFX_Matrix &matrix)
uint32_t FX_ARGB
Definition fx_dib.h:36
constexpr FX_ARGB ArgbEncode(uint32_t a, uint32_t r, uint32_t g, uint32_t b)
Definition fx_dib.h:188
FWLTHEME_DIRECTION
Definition cfwl_utils.h:19
FWLTHEME_STATE
Definition cfwl_utils.h:17