1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
|
// Copyright 2014 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#include "xfa/fxfa/app/xfa_fwltheme.h"
#include "xfa/fde/tto/fde_textout.h"
#include "xfa/fgas/crt/fgas_codepage.h"
#include "xfa/fwl/basewidget/ifwl_barcode.h"
#include "xfa/fwl/basewidget/ifwl_caret.h"
#include "xfa/fwl/basewidget/ifwl_checkbox.h"
#include "xfa/fwl/basewidget/ifwl_combobox.h"
#include "xfa/fwl/basewidget/ifwl_datetimepicker.h"
#include "xfa/fwl/basewidget/ifwl_edit.h"
#include "xfa/fwl/basewidget/ifwl_listbox.h"
#include "xfa/fwl/basewidget/ifwl_monthcalendar.h"
#include "xfa/fwl/basewidget/ifwl_picturebox.h"
#include "xfa/fwl/basewidget/ifwl_pushbutton.h"
#include "xfa/fwl/basewidget/ifwl_scrollbar.h"
#include "xfa/fwl/core/cfwl_themebackground.h"
#include "xfa/fwl/core/cfwl_themetext.h"
#include "xfa/fxfa/app/xfa_ffwidget.h"
#include "xfa/fxgraphics/cfx_color.h"
#include "xfa/include/fxfa/xfa_ffapp.h"
namespace {
const FX_WCHAR* const g_FWLTheme_CalFonts[] = {
L"Arial", L"Courier New", L"DejaVu Sans",
};
} // namespace
CXFA_FFWidget* XFA_ThemeGetOuterWidget(IFWL_Widget* pWidget) {
IFWL_Widget* pOuter = pWidget;
while (pOuter->GetOuter()) {
pOuter = pOuter->GetOuter();
}
if (pOuter) {
return (CXFA_FFWidget*)pOuter->GetPrivateData(pOuter);
}
return NULL;
}
CXFA_FWLTheme::CXFA_FWLTheme(CXFA_FFApp* pApp) : m_pApp(pApp) {
m_pTextOut = NULL;
m_dwCapacity = 0;
m_fCapacity = 0;
m_pCalendarFont = NULL;
m_Rect.Set(0, 0, 0, 0);
m_pCheckBoxTP = new CXFA_FWLCheckBoxTP;
m_pListBoxTP = new CFWL_ListBoxTP;
m_pPictureBoxTP = new CFWL_PictureBoxTP;
m_pSrollBarTP = new CFWL_ScrollBarTP;
m_pEditTP = new CXFA_FWLEditTP;
m_pComboBoxTP = new CFWL_ComboBoxTP;
m_pMonthCalendarTP = new CFWL_MonthCalendarTP;
m_pDateTimePickerTP = new CFWL_DateTimePickerTP;
m_pPushButtonTP = new CFWL_PushButtonTP;
m_pCaretTP = new CFWL_CaretTP;
m_pBarcodeTP = new CFWL_BarcodeTP;
Initialize();
}
CXFA_FWLTheme::~CXFA_FWLTheme() {
Finalize();
delete m_pCheckBoxTP;
delete m_pListBoxTP;
delete m_pPictureBoxTP;
delete m_pSrollBarTP;
delete m_pEditTP;
delete m_pComboBoxTP;
delete m_pMonthCalendarTP;
delete m_pDateTimePickerTP;
delete m_pPushButtonTP;
delete m_pCaretTP;
delete m_pBarcodeTP;
}
FWL_ERR CXFA_FWLTheme::Initialize() {
m_pTextOut = IFDE_TextOut::Create();
for (size_t i = 0; !m_pCalendarFont && i < FX_ArraySize(g_FWLTheme_CalFonts);
++i) {
m_pCalendarFont = IFX_Font::LoadFont(g_FWLTheme_CalFonts[i], 0, 0,
m_pApp->GetFDEFontMgr());
}
if (!m_pCalendarFont) {
#if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
m_pCalendarFont = m_pApp->GetFDEFontMgr()->GetDefFontByCodePage(
FX_CODEPAGE_MSWin_WesternEuropean, 0, NULL);
#else
m_pCalendarFont = m_pApp->GetFDEFontMgr()->GetFontByCodePage(
FX_CODEPAGE_MSWin_WesternEuropean, 0, NULL);
#endif
}
FXSYS_assert(NULL != m_pCalendarFont);
FWLTHEME_Init();
return FWL_ERR_Succeeded;
}
FWL_ERR CXFA_FWLTheme::Finalize() {
if (m_pTextOut) {
m_pTextOut->Release();
m_pTextOut = NULL;
}
if (m_pCalendarFont) {
m_pCalendarFont->Release();
m_pCalendarFont = NULL;
}
FWLTHEME_Release();
return FWL_ERR_Succeeded;
}
FX_BOOL CXFA_FWLTheme::IsValidWidget(IFWL_Widget* pWidget) {
return TRUE;
}
uint32_t CXFA_FWLTheme::GetThemeID(IFWL_Widget* pWidget) {
return 0;
}
uint32_t CXFA_FWLTheme::SetThemeID(IFWL_Widget* pWidget,
uint32_t dwThemeID,
FX_BOOL bChildren) {
return 0;
}
FX_BOOL CXFA_FWLTheme::DrawBackground(CFWL_ThemeBackground* pParams) {
return GetTheme(pParams->m_pWidget)->DrawBackground(pParams);
}
FX_BOOL CXFA_FWLTheme::DrawText(CFWL_ThemeText* pParams) {
if (pParams->m_wsText.IsEmpty()) {
return FWL_ERR_Indefinite;
}
if (pParams->m_pWidget->GetClassID() == FWL_CLASSHASH_MonthCalendar) {
CXFA_FFWidget* pWidget = XFA_ThemeGetOuterWidget(pParams->m_pWidget);
if (!pWidget) {
return FWL_ERR_Indefinite;
}
m_pTextOut->SetStyles(pParams->m_dwTTOStyles);
m_pTextOut->SetAlignment(pParams->m_iTTOAlign);
m_pTextOut->SetFont(m_pCalendarFont);
m_pTextOut->SetFontSize(FWLTHEME_CAPACITY_FontSize);
m_pTextOut->SetTextColor(FWLTHEME_CAPACITY_TextColor);
if ((pParams->m_iPart == FWL_PART_MCD_DatesIn) &&
!(pParams->m_dwStates & FWL_ITEMSTATE_MCD_Flag) &&
(pParams->m_dwStates &
(FWL_PARTSTATE_MCD_Hovered | FWL_PARTSTATE_MCD_Selected))) {
m_pTextOut->SetTextColor(0xFFFFFFFF);
}
if (pParams->m_iPart == FWL_PART_MCD_Caption) {
if (m_pMonthCalendarTP->GetThemeID(pParams->m_pWidget) == 0) {
m_pTextOut->SetTextColor(ArgbEncode(0xff, 0, 153, 255));
} else {
m_pTextOut->SetTextColor(ArgbEncode(0xff, 128, 128, 0));
}
}
CFX_Graphics* pGraphics = pParams->m_pGraphics;
CFX_RenderDevice* pRenderDevice = pGraphics->GetRenderDevice();
if (!pRenderDevice)
return FALSE;
m_pTextOut->SetRenderDevice(pRenderDevice);
CFX_Matrix mtPart = pParams->m_matrix;
CFX_Matrix* pMatrix = pGraphics->GetMatrix();
if (pMatrix) {
mtPart.Concat(*pMatrix);
}
m_pTextOut->SetMatrix(mtPart);
m_pTextOut->DrawLogicText(pParams->m_wsText, pParams->m_wsText.GetLength(),
pParams->m_rtPart);
return TRUE;
}
CXFA_FFWidget* pWidget = XFA_ThemeGetOuterWidget(pParams->m_pWidget);
if (!pWidget) {
return FWL_ERR_Indefinite;
}
CXFA_WidgetAcc* pAcc = pWidget->GetDataAcc();
CFX_Graphics* pGraphics = pParams->m_pGraphics;
CFX_RenderDevice* pRenderDevice = pGraphics->GetRenderDevice();
if (!pRenderDevice)
return FALSE;
m_pTextOut->SetRenderDevice(pRenderDevice);
m_pTextOut->SetStyles(pParams->m_dwTTOStyles);
m_pTextOut->SetAlignment(pParams->m_iTTOAlign);
m_pTextOut->SetFont(pAcc->GetFDEFont());
m_pTextOut->SetFontSize(pAcc->GetFontSize());
m_pTextOut->SetTextColor(pAcc->GetTextColor());
CFX_Matrix mtPart = pParams->m_matrix;
CFX_Matrix* pMatrix = pGraphics->GetMatrix();
if (pMatrix) {
mtPart.Concat(*pMatrix);
}
m_pTextOut->SetMatrix(mtPart);
m_pTextOut->DrawLogicText(pParams->m_wsText, pParams->m_wsText.GetLength(),
pParams->m_rtPart);
return TRUE;
}
void* CXFA_FWLTheme::GetCapacity(CFWL_ThemePart* pThemePart,
uint32_t dwCapacity) {
switch (dwCapacity) {
case FWL_WGTCAPACITY_Font: {
if (CXFA_FFWidget* pWidget =
XFA_ThemeGetOuterWidget(pThemePart->m_pWidget)) {
return pWidget->GetDataAcc()->GetFDEFont();
}
} break;
case FWL_WGTCAPACITY_FontSize: {
if (CXFA_FFWidget* pWidget =
XFA_ThemeGetOuterWidget(pThemePart->m_pWidget)) {
m_fCapacity = pWidget->GetDataAcc()->GetFontSize();
return &m_fCapacity;
}
} break;
case FWL_WGTCAPACITY_TextColor: {
if (CXFA_FFWidget* pWidget =
XFA_ThemeGetOuterWidget(pThemePart->m_pWidget)) {
m_dwCapacity = pWidget->GetDataAcc()->GetTextColor();
return &m_dwCapacity;
}
} break;
case FWL_WGTCAPACITY_LineHeight: {
if (CXFA_FFWidget* pWidget =
XFA_ThemeGetOuterWidget(pThemePart->m_pWidget)) {
m_fCapacity = pWidget->GetDataAcc()->GetLineHeight();
return &m_fCapacity;
}
} break;
case FWL_WGTCAPACITY_ScrollBarWidth: {
m_fCapacity = 9;
return &m_fCapacity;
} break;
case FWL_WGTCAPACITY_UIMargin: {
CXFA_FFWidget* pWidget = XFA_ThemeGetOuterWidget(pThemePart->m_pWidget);
if (pWidget) {
CXFA_LayoutItem* pItem = pWidget;
CXFA_WidgetAcc* pWidgetAcc = pWidget->GetDataAcc();
pWidgetAcc->GetUIMargin(m_Rect);
if (CXFA_Para para = pWidgetAcc->GetPara()) {
m_Rect.left += para.GetMarginLeft();
if (pWidgetAcc->IsMultiLine()) {
m_Rect.width += para.GetMarginRight();
}
}
if (pItem->GetPrev() == NULL) {
if (pItem->GetNext()) {
m_Rect.height = 0;
}
} else if (pItem->GetNext() == NULL) {
m_Rect.top = 0;
} else {
m_Rect.top = 0;
m_Rect.height = 0;
}
}
return &m_Rect;
} break;
case FWL_WGTCAPACITY_SpaceAboveBelow: {
CXFA_FFWidget* pWidget = XFA_ThemeGetOuterWidget(pThemePart->m_pWidget);
if (pWidget) {
CXFA_WidgetAcc* pWidgetAcc = pWidget->GetDataAcc();
if (CXFA_Para para = pWidgetAcc->GetPara()) {
m_SizeAboveBelow.x = para.GetSpaceAbove();
m_SizeAboveBelow.y = para.GetSpaceBelow();
}
}
return &m_SizeAboveBelow;
} break;
default:
break;
}
if (pThemePart->m_pWidget->GetClassID() == FWL_CLASSHASH_MonthCalendar &&
dwCapacity >= FWL_MCCAPACITY_Sun && dwCapacity <= FWL_MCCAPACITY_Today) {
if (CXFA_FFWidget* pWidget =
XFA_ThemeGetOuterWidget(pThemePart->m_pWidget)) {
IXFA_AppProvider* pAppProvider = pWidget->GetAppProvider();
m_wsResource.Empty();
pAppProvider->LoadString(
XFA_IDS_StringWeekDay_Sun + dwCapacity - FWL_WGTCAPACITY_MAX - 5,
m_wsResource);
if (!m_wsResource.IsEmpty()) {
return &m_wsResource;
}
}
}
return GetTheme(pThemePart->m_pWidget)->GetCapacity(pThemePart, dwCapacity);
}
FX_BOOL CXFA_FWLTheme::IsCustomizedLayout(IFWL_Widget* pWidget) {
return GetTheme(pWidget)->IsCustomizedLayout(pWidget);
}
FWL_ERR CXFA_FWLTheme::GetPartRect(CFWL_ThemePart* pThemePart) {
CFX_RectF rect;
return GetTheme(pThemePart->m_pWidget)->GetPartRect(pThemePart, rect);
}
FX_BOOL CXFA_FWLTheme::IsInPart(CFWL_ThemePart* pThemePart,
FX_FLOAT fx,
FX_FLOAT fy) {
return GetTheme(pThemePart->m_pWidget)->IsInPart(pThemePart, fx, fy);
}
FX_BOOL CXFA_FWLTheme::CalcTextRect(CFWL_ThemeText* pParams, CFX_RectF& rect) {
if (pParams->m_pWidget->GetClassID() == FWL_CLASSHASH_MonthCalendar) {
CXFA_FFWidget* pWidget = XFA_ThemeGetOuterWidget(pParams->m_pWidget);
if (!pWidget) {
return FWL_ERR_Indefinite;
}
if (!pParams)
return FALSE;
if (!m_pTextOut)
return FALSE;
m_pTextOut->SetFont(m_pCalendarFont);
m_pTextOut->SetFontSize(FWLTHEME_CAPACITY_FontSize);
m_pTextOut->SetTextColor(FWLTHEME_CAPACITY_TextColor);
m_pTextOut->SetAlignment(pParams->m_iTTOAlign);
m_pTextOut->SetStyles(pParams->m_dwTTOStyles);
m_pTextOut->CalcLogicSize(pParams->m_wsText, pParams->m_wsText.GetLength(),
rect);
return TRUE;
}
CXFA_FFWidget* pWidget = XFA_ThemeGetOuterWidget(pParams->m_pWidget);
if (!pWidget) {
return FWL_ERR_Indefinite;
}
CXFA_WidgetAcc* pAcc = pWidget->GetDataAcc();
m_pTextOut->SetFont(pAcc->GetFDEFont());
m_pTextOut->SetFontSize(pAcc->GetFontSize());
m_pTextOut->SetTextColor(pAcc->GetTextColor());
if (!pParams)
return FALSE;
if (!m_pTextOut)
return FALSE;
m_pTextOut->SetAlignment(pParams->m_iTTOAlign);
m_pTextOut->SetStyles(pParams->m_dwTTOStyles);
m_pTextOut->CalcLogicSize(pParams->m_wsText, pParams->m_wsText.GetLength(),
rect);
return TRUE;
}
CFWL_WidgetTP* CXFA_FWLTheme::GetTheme(IFWL_Widget* pWidget) {
switch (pWidget->GetClassID()) {
case FWL_CLASSHASH_CheckBox:
return m_pCheckBoxTP;
case FWL_CLASSHASH_ListBox:
return m_pListBoxTP;
case FWL_CLASSHASH_PictureBox:
return m_pPictureBoxTP;
case FWL_CLASSHASH_ScrollBar:
return m_pSrollBarTP;
case FWL_CLASSHASH_Edit:
return m_pEditTP;
case FWL_CLASSHASH_ComboBox:
return m_pComboBoxTP;
case FWL_CLASSHASH_MonthCalendar:
return m_pMonthCalendarTP;
case FWL_CLASSHASH_DateTimePicker:
return m_pDateTimePickerTP;
case FWL_CLASSHASH_PushButton:
return m_pPushButtonTP;
case FWL_CLASSHASH_Caret:
return m_pCaretTP;
case FWL_CLASSHASH_Barcode:
return m_pBarcodeTP;
default:
break;
}
return NULL;
}
CXFA_FWLCheckBoxTP::CXFA_FWLCheckBoxTP() {}
FX_BOOL CXFA_FWLCheckBoxTP::DrawBackground(CFWL_ThemeBackground* pParams) {
if (pParams->m_iPart != FWL_PART_CKB_CheckBox) {
return TRUE;
}
if (((pParams->m_dwStates & FWL_PARTSTATE_CKB_Mask2) ==
FWL_PARTSTATE_CKB_Checked) ||
((pParams->m_dwStates & FWL_PARTSTATE_CKB_Mask2) ==
FWL_PARTSTATE_CKB_Neutral)) {
DrawCheckSign(pParams->m_pWidget, pParams->m_pGraphics, &pParams->m_rtPart,
pParams->m_dwStates, &pParams->m_matrix);
}
return TRUE;
}
void CXFA_FWLCheckBoxTP::DrawCheckSign(IFWL_Widget* pWidget,
CFX_Graphics* pGraphics,
const CFX_RectF* pRtBox,
int32_t iState,
CFX_Matrix* pMatrix) {
CFX_RectF rtSign(*pRtBox);
uint32_t dwColor = 0xFF000000;
if ((iState & FWL_PARTSTATE_CKB_Mask2) == FWL_PARTSTATE_CKB_Neutral) {
dwColor = 0xFFA9A9A9;
}
{
uint32_t dwStyle = pWidget->GetStylesEx();
rtSign.Deflate(rtSign.width / 4, rtSign.height / 4);
switch (dwStyle & FWL_STYLEEXT_CKB_SignShapeMask) {
case FWL_STYLEEXT_CKB_SignShapeCheck:
DrawSignCheck(pGraphics, &rtSign, dwColor, pMatrix);
break;
case FWL_STYLEEXT_CKB_SignShapeCircle:
DrawSignCircle(pGraphics, &rtSign, dwColor, pMatrix);
break;
case FWL_STYLEEXT_CKB_SignShapeCross:
DrawSignCross(pGraphics, &rtSign, dwColor, pMatrix);
break;
case FWL_STYLEEXT_CKB_SignShapeDiamond:
DrawSignDiamond(pGraphics, &rtSign, dwColor, pMatrix);
break;
case FWL_STYLEEXT_CKB_SignShapeSquare:
DrawSignSquare(pGraphics, &rtSign, dwColor, pMatrix);
break;
case FWL_STYLEEXT_CKB_SignShapeStar:
DrawSignStar(pGraphics, &rtSign, dwColor, pMatrix);
break;
default:
break;
}
}
}
CXFA_FWLEditTP::CXFA_FWLEditTP() {}
CXFA_FWLEditTP::~CXFA_FWLEditTP() {}
FX_BOOL CXFA_FWLEditTP::DrawBackground(CFWL_ThemeBackground* pParams) {
if (FWL_PART_EDT_CombTextLine == pParams->m_iPart) {
CXFA_FFWidget* pWidget = XFA_ThemeGetOuterWidget(pParams->m_pWidget);
FX_ARGB cr = 0xFF000000;
FX_FLOAT fWidth = 1.0f;
if (CXFA_Border borderUI = pWidget->GetDataAcc()->GetUIBorder()) {
CXFA_Edge edge = borderUI.GetEdge(0);
if (edge) {
cr = edge.GetColor();
fWidth = edge.GetThickness();
}
}
CFX_Color crLine(cr);
pParams->m_pGraphics->SetStrokeColor(&crLine);
pParams->m_pGraphics->SetLineWidth(fWidth);
pParams->m_pGraphics->StrokePath(pParams->m_pPath, &pParams->m_matrix);
return TRUE;
}
return CFWL_EditTP::DrawBackground(pParams);
}
|