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
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
|
// 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/include/xfa_ffapp.h"
#include "xfa/fxfa/include/xfa_ffwidget.h"
#include "xfa/fxgraphics/cfx_color.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 && pOuter->GetOuter())
pOuter = pOuter->GetOuter();
return pOuter ? static_cast<CXFA_FFWidget*>(pOuter->GetLayoutItem())
: nullptr;
}
CXFA_FWLTheme::CXFA_FWLTheme(CXFA_FFApp* pApp) : m_pApp(pApp) {
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_Error CXFA_FWLTheme::Initialize() {
m_pTextOut.reset(new CFDE_TextOut);
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
}
ASSERT(NULL != m_pCalendarFont);
FWLTHEME_Init();
return FWL_Error::Succeeded;
}
FWL_Error CXFA_FWLTheme::Finalize() {
m_pTextOut.reset();
if (m_pCalendarFont) {
m_pCalendarFont->Release();
m_pCalendarFont = nullptr;
}
FWLTHEME_Release();
return FWL_Error::Succeeded;
}
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 FALSE;
if (pParams->m_pWidget->GetClassID() == FWL_Type::MonthCalendar) {
CXFA_FFWidget* pWidget = XFA_ThemeGetOuterWidget(pParams->m_pWidget);
if (!pWidget)
return FALSE;
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 == CFWL_Part::DatesIn) &&
!(pParams->m_dwStates & FWL_ITEMSTATE_MCD_Flag) &&
(pParams->m_dwStates &
(CFWL_PartState_Hovered | CFWL_PartState_Selected))) {
m_pTextOut->SetTextColor(0xFFFFFFFF);
}
if (pParams->m_iPart == CFWL_Part::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.c_str(),
pParams->m_wsText.GetLength(), pParams->m_rtPart);
return TRUE;
}
CXFA_FFWidget* pWidget = XFA_ThemeGetOuterWidget(pParams->m_pWidget);
if (!pWidget)
return FALSE;
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.c_str(),
pParams->m_wsText.GetLength(), pParams->m_rtPart);
return TRUE;
}
void* CXFA_FWLTheme::GetCapacity(CFWL_ThemePart* pThemePart,
CFWL_WidgetCapacity dwCapacity) {
switch (dwCapacity) {
case CFWL_WidgetCapacity::Font: {
if (CXFA_FFWidget* pWidget =
XFA_ThemeGetOuterWidget(pThemePart->m_pWidget)) {
return pWidget->GetDataAcc()->GetFDEFont();
}
} break;
case CFWL_WidgetCapacity::FontSize: {
if (CXFA_FFWidget* pWidget =
XFA_ThemeGetOuterWidget(pThemePart->m_pWidget)) {
m_fCapacity = pWidget->GetDataAcc()->GetFontSize();
return &m_fCapacity;
}
} break;
case CFWL_WidgetCapacity::TextColor: {
if (CXFA_FFWidget* pWidget =
XFA_ThemeGetOuterWidget(pThemePart->m_pWidget)) {
m_dwCapacity = pWidget->GetDataAcc()->GetTextColor();
return &m_dwCapacity;
}
} break;
case CFWL_WidgetCapacity::LineHeight: {
if (CXFA_FFWidget* pWidget =
XFA_ThemeGetOuterWidget(pThemePart->m_pWidget)) {
m_fCapacity = pWidget->GetDataAcc()->GetLineHeight();
return &m_fCapacity;
}
} break;
case CFWL_WidgetCapacity::ScrollBarWidth: {
m_fCapacity = 9;
return &m_fCapacity;
} break;
case CFWL_WidgetCapacity::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 CFWL_WidgetCapacity::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;
}
int dwCapValue = static_cast<int>(dwCapacity);
if (pThemePart->m_pWidget->GetClassID() == FWL_Type::MonthCalendar &&
dwCapValue >= static_cast<int>(CFWL_WidgetCapacity::Today) &&
dwCapValue <= static_cast<int>(CFWL_WidgetCapacity::December)) {
if (CXFA_FFWidget* pWidget =
XFA_ThemeGetOuterWidget(pThemePart->m_pWidget)) {
IXFA_AppProvider* pAppProvider = pWidget->GetAppProvider();
m_wsResource.clear();
switch (dwCapacity) {
case CFWL_WidgetCapacity::Sun:
pAppProvider->LoadString(XFA_IDS_StringWeekDay_Sun, m_wsResource);
break;
case CFWL_WidgetCapacity::Mon:
pAppProvider->LoadString(XFA_IDS_StringWeekDay_Mon, m_wsResource);
break;
case CFWL_WidgetCapacity::Tue:
pAppProvider->LoadString(XFA_IDS_StringWeekDay_Tue, m_wsResource);
break;
case CFWL_WidgetCapacity::Wed:
pAppProvider->LoadString(XFA_IDS_StringWeekDay_Wed, m_wsResource);
break;
case CFWL_WidgetCapacity::Thu:
pAppProvider->LoadString(XFA_IDS_StringWeekDay_Thu, m_wsResource);
break;
case CFWL_WidgetCapacity::Fri:
pAppProvider->LoadString(XFA_IDS_StringWeekDay_Fri, m_wsResource);
break;
case CFWL_WidgetCapacity::Sat:
pAppProvider->LoadString(XFA_IDS_StringWeekDay_Sat, m_wsResource);
break;
case CFWL_WidgetCapacity::January:
pAppProvider->LoadString(XFA_IDS_StringMonth_Jan, m_wsResource);
break;
case CFWL_WidgetCapacity::February:
pAppProvider->LoadString(XFA_IDS_StringMonth_Feb, m_wsResource);
break;
case CFWL_WidgetCapacity::March:
pAppProvider->LoadString(XFA_IDS_StringMonth_March, m_wsResource);
break;
case CFWL_WidgetCapacity::April:
pAppProvider->LoadString(XFA_IDS_StringMonth_April, m_wsResource);
break;
case CFWL_WidgetCapacity::May:
pAppProvider->LoadString(XFA_IDS_StringMonth_May, m_wsResource);
break;
case CFWL_WidgetCapacity::June:
pAppProvider->LoadString(XFA_IDS_StringMonth_June, m_wsResource);
break;
case CFWL_WidgetCapacity::July:
pAppProvider->LoadString(XFA_IDS_StringMonth_July, m_wsResource);
break;
case CFWL_WidgetCapacity::August:
pAppProvider->LoadString(XFA_IDS_StringMonth_Aug, m_wsResource);
break;
case CFWL_WidgetCapacity::September:
pAppProvider->LoadString(XFA_IDS_StringMonth_Sept, m_wsResource);
break;
case CFWL_WidgetCapacity::October:
pAppProvider->LoadString(XFA_IDS_StringMonth_Oct, m_wsResource);
break;
case CFWL_WidgetCapacity::November:
pAppProvider->LoadString(XFA_IDS_StringMonth_Nov, m_wsResource);
break;
case CFWL_WidgetCapacity::December:
pAppProvider->LoadString(XFA_IDS_StringMonth_Dec, m_wsResource);
break;
case CFWL_WidgetCapacity::Today:
pAppProvider->LoadString(XFA_IDS_String_Today, m_wsResource);
break;
default:
break;
}
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_Error 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_Type::MonthCalendar) {
CXFA_FFWidget* pWidget = XFA_ThemeGetOuterWidget(pParams->m_pWidget);
if (!pWidget)
return FALSE;
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.c_str(),
pParams->m_wsText.GetLength(), rect);
return TRUE;
}
CXFA_FFWidget* pWidget = XFA_ThemeGetOuterWidget(pParams->m_pWidget);
if (!pWidget)
return FALSE;
CXFA_WidgetAcc* pAcc = pWidget->GetDataAcc();
m_pTextOut->SetFont(pAcc->GetFDEFont());
m_pTextOut->SetFontSize(pAcc->GetFontSize());
m_pTextOut->SetTextColor(pAcc->GetTextColor());
if (!pParams)
return FALSE;
m_pTextOut->SetAlignment(pParams->m_iTTOAlign);
m_pTextOut->SetStyles(pParams->m_dwTTOStyles);
m_pTextOut->CalcLogicSize(pParams->m_wsText.c_str(),
pParams->m_wsText.GetLength(), rect);
return TRUE;
}
CFWL_WidgetTP* CXFA_FWLTheme::GetTheme(IFWL_Widget* pWidget) {
switch (pWidget->GetClassID()) {
case FWL_Type::CheckBox:
return m_pCheckBoxTP;
case FWL_Type::ListBox:
return m_pListBoxTP;
case FWL_Type::PictureBox:
return m_pPictureBoxTP;
case FWL_Type::ScrollBar:
return m_pSrollBarTP;
case FWL_Type::Edit:
return m_pEditTP;
case FWL_Type::ComboBox:
return m_pComboBoxTP;
case FWL_Type::MonthCalendar:
return m_pMonthCalendarTP;
case FWL_Type::DateTimePicker:
return m_pDateTimePickerTP;
case FWL_Type::PushButton:
return m_pPushButtonTP;
case FWL_Type::Caret:
return m_pCaretTP;
case FWL_Type::Barcode:
return m_pBarcodeTP;
default:
return nullptr;
}
}
CXFA_FWLCheckBoxTP::CXFA_FWLCheckBoxTP() {}
FX_BOOL CXFA_FWLCheckBoxTP::DrawBackground(CFWL_ThemeBackground* pParams) {
if (pParams->m_iPart != CFWL_Part::CheckBox) {
return TRUE;
}
if ((pParams->m_dwStates & CFWL_PartState_Checked) ||
(pParams->m_dwStates & CFWL_PartState_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 & CFWL_PartState_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 (CFWL_Part::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);
}
|