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 #include "xfa/src/foxitlib.h"
IsValidWidget(IFWL_Widget * pWidget)8 FX_BOOL CFWL_Theme::IsValidWidget(IFWL_Widget* pWidget) {
9 return !!GetTheme(pWidget);
10 }
GetThemeID(IFWL_Widget * pWidget)11 FX_DWORD CFWL_Theme::GetThemeID(IFWL_Widget* pWidget) {
12 return GetTheme(pWidget)->GetThemeID(pWidget);
13 }
SetThemeID(IFWL_Widget * pWidget,FX_DWORD dwThemeID,FX_BOOL bChildren)14 FX_DWORD CFWL_Theme::SetThemeID(IFWL_Widget* pWidget,
15 FX_DWORD dwThemeID,
16 FX_BOOL bChildren) {
17 int32_t iCount = m_arrThemes.GetSize();
18 FX_DWORD dwID;
19 for (int32_t i = 0; i < iCount; i++) {
20 CFWL_WidgetTP* pTheme = static_cast<CFWL_WidgetTP*>(m_arrThemes[i]);
21 dwID = pTheme->GetThemeID(pWidget);
22 pTheme->SetThemeID(pWidget, dwThemeID, FALSE);
23 }
24 return dwID;
25 }
GetThemeMatrix(IFWL_Widget * pWidget,CFX_Matrix & matrix)26 FWL_ERR CFWL_Theme::GetThemeMatrix(IFWL_Widget* pWidget, CFX_Matrix& matrix) {
27 return FWL_ERR_Succeeded;
28 }
SetThemeMatrix(IFWL_Widget * pWidget,const CFX_Matrix & matrix)29 FWL_ERR CFWL_Theme::SetThemeMatrix(IFWL_Widget* pWidget,
30 const CFX_Matrix& matrix) {
31 return FWL_ERR_Succeeded;
32 }
DrawBackground(CFWL_ThemeBackground * pParams)33 FX_BOOL CFWL_Theme::DrawBackground(CFWL_ThemeBackground* pParams) {
34 CFWL_WidgetTP* pTheme = GetTheme(pParams->m_pWidget);
35 FXSYS_assert(pTheme);
36 return pTheme->DrawBackground(pParams);
37 }
DrawText(CFWL_ThemeText * pParams)38 FX_BOOL CFWL_Theme::DrawText(CFWL_ThemeText* pParams) {
39 CFWL_WidgetTP* pTheme = GetTheme(pParams->m_pWidget);
40 FXSYS_assert(pTheme);
41 return pTheme->DrawText(pParams);
42 }
GetCapacity(CFWL_ThemePart * pThemePart,FX_DWORD dwCapacity)43 void* CFWL_Theme::GetCapacity(CFWL_ThemePart* pThemePart, FX_DWORD dwCapacity) {
44 CFWL_WidgetTP* pTheme = GetTheme(pThemePart->m_pWidget);
45 FXSYS_assert(pTheme);
46 return pTheme->GetCapacity(pThemePart, dwCapacity);
47 }
IsCustomizedLayout(IFWL_Widget * pWidget)48 FX_BOOL CFWL_Theme::IsCustomizedLayout(IFWL_Widget* pWidget) {
49 CFWL_WidgetTP* pTheme = GetTheme(pWidget);
50 FXSYS_assert(pTheme);
51 return pTheme->IsCustomizedLayout(pWidget);
52 }
GetPartRect(CFWL_ThemePart * pThemePart,CFX_RectF & rtPart)53 FWL_ERR CFWL_Theme::GetPartRect(CFWL_ThemePart* pThemePart, CFX_RectF& rtPart) {
54 CFWL_WidgetTP* pTheme = GetTheme(pThemePart->m_pWidget);
55 FXSYS_assert(pTheme);
56 return pTheme->GetPartRect(pThemePart, rtPart);
57 }
IsInPart(CFWL_ThemePart * pThemePart,FX_FLOAT fx,FX_FLOAT fy)58 FX_BOOL CFWL_Theme::IsInPart(CFWL_ThemePart* pThemePart,
59 FX_FLOAT fx,
60 FX_FLOAT fy) {
61 CFWL_WidgetTP* pTheme = GetTheme(pThemePart->m_pWidget);
62 FXSYS_assert(pTheme);
63 return pTheme->IsInPart(pThemePart, fx, fy);
64 }
CalcTextRect(CFWL_ThemeText * pParams,CFX_RectF & rect)65 FX_BOOL CFWL_Theme::CalcTextRect(CFWL_ThemeText* pParams, CFX_RectF& rect) {
66 CFWL_WidgetTP* pTheme = GetTheme(pParams->m_pWidget);
67 FXSYS_assert(pTheme);
68 return pTheme->CalcTextRect(pParams, rect);
69 }
Initialize()70 FWL_ERR CFWL_Theme::Initialize() {
71 int32_t iCount = m_arrThemes.GetSize();
72 for (int32_t i = 0; i < iCount; i++) {
73 CFWL_WidgetTP* pTheme = static_cast<CFWL_WidgetTP*>(m_arrThemes[i]);
74 pTheme->Initialize();
75 }
76 FWLTHEME_Init();
77 return FWL_ERR_Succeeded;
78 }
Finalize()79 FWL_ERR CFWL_Theme::Finalize() {
80 int32_t iCount = m_arrThemes.GetSize();
81 for (int32_t i = 0; i < iCount; i++) {
82 CFWL_WidgetTP* pTheme = static_cast<CFWL_WidgetTP*>(m_arrThemes[i]);
83 pTheme->Finalize();
84 }
85 FWLTHEME_Release();
86 return FWL_ERR_Succeeded;
87 }
CFWL_Theme()88 CFWL_Theme::CFWL_Theme() {
89 CFWL_FormTP* pFormTP = new CFWL_FormTP;
90 CFWL_PushButtonTP* pPushButtonTP = new CFWL_PushButtonTP;
91 CFWL_CheckBoxTP* pCheckBoxTP = new CFWL_CheckBoxTP;
92 CFWL_ListBoxTP* pListBoxTP = new CFWL_ListBoxTP;
93 CFWL_PictureBoxTP* pPictureBoxTP = new CFWL_PictureBoxTP;
94 CFWL_ScrollBarTP* pSrollBarTP = new CFWL_ScrollBarTP;
95 CFWL_EditTP* pEditTP = new CFWL_EditTP;
96 CFWL_ComboBoxTP* pComboBoxTP = new CFWL_ComboBoxTP;
97 CFWL_BarcodeTP* pBarcodeTP = new CFWL_BarcodeTP;
98 CFWL_DateTimePickerTP* pDateTimePickerTP = new CFWL_DateTimePickerTP;
99 CFWL_MonthCalendarTP* pMonthCalendarTP = new CFWL_MonthCalendarTP;
100 CFWL_CaretTP* pCaretTP = new CFWL_CaretTP;
101 m_arrThemes.Add(pFormTP);
102 m_arrThemes.Add(pPushButtonTP);
103 m_arrThemes.Add(pCheckBoxTP);
104 m_arrThemes.Add(pListBoxTP);
105 m_arrThemes.Add(pPictureBoxTP);
106 m_arrThemes.Add(pSrollBarTP);
107 m_arrThemes.Add(pEditTP);
108 m_arrThemes.Add(pComboBoxTP);
109 m_arrThemes.Add(pBarcodeTP);
110 m_arrThemes.Add(pDateTimePickerTP);
111 m_arrThemes.Add(pMonthCalendarTP);
112 m_arrThemes.Add(pCaretTP);
113 }
~CFWL_Theme()114 CFWL_Theme::~CFWL_Theme() {
115 for (int32_t i = 0; i < m_arrThemes.GetSize(); i++) {
116 delete static_cast<CFWL_WidgetTP*>(m_arrThemes[i]);
117 }
118 m_arrThemes.RemoveAll();
119 }
SetFont(IFWL_Widget * pWidget,const FX_WCHAR * strFont,FX_FLOAT fFontSize,FX_ARGB rgbFont)120 FWL_ERR CFWL_Theme::SetFont(IFWL_Widget* pWidget,
121 const FX_WCHAR* strFont,
122 FX_FLOAT fFontSize,
123 FX_ARGB rgbFont) {
124 int32_t iCount = m_arrThemes.GetSize();
125 for (int32_t i = 0; i < iCount; i++) {
126 CFWL_WidgetTP* pTheme = static_cast<CFWL_WidgetTP*>(m_arrThemes[i]);
127 pTheme->SetFont(pWidget, strFont, fFontSize, rgbFont);
128 }
129 return FWL_ERR_Succeeded;
130 }
GetTheme(IFWL_Widget * pWidget)131 CFWL_WidgetTP* CFWL_Theme::GetTheme(IFWL_Widget* pWidget) {
132 int32_t iCount = m_arrThemes.GetSize();
133 for (int32_t i = 0; i < iCount; i++) {
134 CFWL_WidgetTP* pTheme = static_cast<CFWL_WidgetTP*>(m_arrThemes[i]);
135 if (pTheme->IsValidWidget(pWidget)) {
136 return pTheme;
137 }
138 }
139 return NULL;
140 }
141