summaryrefslogtreecommitdiff
path: root/xfa/src/fwl/src/lightwidget/theme.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'xfa/src/fwl/src/lightwidget/theme.cpp')
-rw-r--r--xfa/src/fwl/src/lightwidget/theme.cpp132
1 files changed, 57 insertions, 75 deletions
diff --git a/xfa/src/fwl/src/lightwidget/theme.cpp b/xfa/src/fwl/src/lightwidget/theme.cpp
index b9acbec1a4..8352ad807d 100644
--- a/xfa/src/fwl/src/lightwidget/theme.cpp
+++ b/xfa/src/fwl/src/lightwidget/theme.cpp
@@ -4,137 +4,119 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+#include <algorithm>
+
#include "xfa/src/foxitlib.h"
+
+CFWL_Theme::CFWL_Theme() {
+ m_ThemesArray.push_back(std::unique_ptr<CFWL_WidgetTP>(new CFWL_FormTP));
+ m_ThemesArray.push_back(
+ std::unique_ptr<CFWL_WidgetTP>(new CFWL_PushButtonTP));
+ m_ThemesArray.push_back(std::unique_ptr<CFWL_WidgetTP>(new CFWL_CheckBoxTP));
+ m_ThemesArray.push_back(std::unique_ptr<CFWL_WidgetTP>(new CFWL_ListBoxTP));
+ m_ThemesArray.push_back(
+ std::unique_ptr<CFWL_WidgetTP>(new CFWL_PictureBoxTP));
+ m_ThemesArray.push_back(std::unique_ptr<CFWL_WidgetTP>(new CFWL_ScrollBarTP));
+ m_ThemesArray.push_back(std::unique_ptr<CFWL_WidgetTP>(new CFWL_EditTP));
+ m_ThemesArray.push_back(std::unique_ptr<CFWL_WidgetTP>(new CFWL_ComboBoxTP));
+ m_ThemesArray.push_back(std::unique_ptr<CFWL_WidgetTP>(new CFWL_BarcodeTP));
+ m_ThemesArray.push_back(
+ std::unique_ptr<CFWL_WidgetTP>(new CFWL_DateTimePickerTP));
+ m_ThemesArray.push_back(
+ std::unique_ptr<CFWL_WidgetTP>(new CFWL_MonthCalendarTP));
+ m_ThemesArray.push_back(std::unique_ptr<CFWL_WidgetTP>(new CFWL_CaretTP));
+}
+
+CFWL_Theme::~CFWL_Theme() {}
+
FX_BOOL CFWL_Theme::IsValidWidget(IFWL_Widget* pWidget) {
return !!GetTheme(pWidget);
}
+
FX_DWORD CFWL_Theme::GetThemeID(IFWL_Widget* pWidget) {
return GetTheme(pWidget)->GetThemeID(pWidget);
}
+
FX_DWORD CFWL_Theme::SetThemeID(IFWL_Widget* pWidget,
FX_DWORD dwThemeID,
FX_BOOL bChildren) {
- int32_t iCount = m_arrThemes.GetSize();
FX_DWORD dwID;
- for (int32_t i = 0; i < iCount; i++) {
- CFWL_WidgetTP* pTheme = static_cast<CFWL_WidgetTP*>(m_arrThemes[i]);
+ for (const auto& pTheme : m_ThemesArray) {
dwID = pTheme->GetThemeID(pWidget);
pTheme->SetThemeID(pWidget, dwThemeID, FALSE);
}
return dwID;
}
+
FWL_ERR CFWL_Theme::GetThemeMatrix(IFWL_Widget* pWidget, CFX_Matrix& matrix) {
return FWL_ERR_Succeeded;
}
+
FWL_ERR CFWL_Theme::SetThemeMatrix(IFWL_Widget* pWidget,
const CFX_Matrix& matrix) {
return FWL_ERR_Succeeded;
}
+
FX_BOOL CFWL_Theme::DrawBackground(CFWL_ThemeBackground* pParams) {
- CFWL_WidgetTP* pTheme = GetTheme(pParams->m_pWidget);
- FXSYS_assert(pTheme);
- return pTheme->DrawBackground(pParams);
+ return GetTheme(pParams->m_pWidget)->DrawBackground(pParams);
}
+
FX_BOOL CFWL_Theme::DrawText(CFWL_ThemeText* pParams) {
- CFWL_WidgetTP* pTheme = GetTheme(pParams->m_pWidget);
- FXSYS_assert(pTheme);
- return pTheme->DrawText(pParams);
+ return GetTheme(pParams->m_pWidget)->DrawText(pParams);
}
+
void* CFWL_Theme::GetCapacity(CFWL_ThemePart* pThemePart, FX_DWORD dwCapacity) {
- CFWL_WidgetTP* pTheme = GetTheme(pThemePart->m_pWidget);
- FXSYS_assert(pTheme);
- return pTheme->GetCapacity(pThemePart, dwCapacity);
+ return GetTheme(pThemePart->m_pWidget)->GetCapacity(pThemePart, dwCapacity);
}
+
FX_BOOL CFWL_Theme::IsCustomizedLayout(IFWL_Widget* pWidget) {
- CFWL_WidgetTP* pTheme = GetTheme(pWidget);
- FXSYS_assert(pTheme);
- return pTheme->IsCustomizedLayout(pWidget);
+ return GetTheme(pWidget)->IsCustomizedLayout(pWidget);
}
+
FWL_ERR CFWL_Theme::GetPartRect(CFWL_ThemePart* pThemePart, CFX_RectF& rtPart) {
- CFWL_WidgetTP* pTheme = GetTheme(pThemePart->m_pWidget);
- FXSYS_assert(pTheme);
- return pTheme->GetPartRect(pThemePart, rtPart);
+ return GetTheme(pThemePart->m_pWidget)->GetPartRect(pThemePart, rtPart);
}
+
FX_BOOL CFWL_Theme::IsInPart(CFWL_ThemePart* pThemePart,
FX_FLOAT fx,
FX_FLOAT fy) {
- CFWL_WidgetTP* pTheme = GetTheme(pThemePart->m_pWidget);
- FXSYS_assert(pTheme);
- return pTheme->IsInPart(pThemePart, fx, fy);
+ return GetTheme(pThemePart->m_pWidget)->IsInPart(pThemePart, fx, fy);
}
+
FX_BOOL CFWL_Theme::CalcTextRect(CFWL_ThemeText* pParams, CFX_RectF& rect) {
- CFWL_WidgetTP* pTheme = GetTheme(pParams->m_pWidget);
- FXSYS_assert(pTheme);
- return pTheme->CalcTextRect(pParams, rect);
+ return GetTheme(pParams->m_pWidget)->CalcTextRect(pParams, rect);
}
+
FWL_ERR CFWL_Theme::Initialize() {
- int32_t iCount = m_arrThemes.GetSize();
- for (int32_t i = 0; i < iCount; i++) {
- CFWL_WidgetTP* pTheme = static_cast<CFWL_WidgetTP*>(m_arrThemes[i]);
+ for (const auto& pTheme : m_ThemesArray)
pTheme->Initialize();
- }
+
FWLTHEME_Init();
return FWL_ERR_Succeeded;
}
+
FWL_ERR CFWL_Theme::Finalize() {
- int32_t iCount = m_arrThemes.GetSize();
- for (int32_t i = 0; i < iCount; i++) {
- CFWL_WidgetTP* pTheme = static_cast<CFWL_WidgetTP*>(m_arrThemes[i]);
+ for (const auto& pTheme : m_ThemesArray)
pTheme->Finalize();
- }
+
FWLTHEME_Release();
return FWL_ERR_Succeeded;
}
-CFWL_Theme::CFWL_Theme() {
- CFWL_FormTP* pFormTP = new CFWL_FormTP;
- CFWL_PushButtonTP* pPushButtonTP = new CFWL_PushButtonTP;
- CFWL_CheckBoxTP* pCheckBoxTP = new CFWL_CheckBoxTP;
- CFWL_ListBoxTP* pListBoxTP = new CFWL_ListBoxTP;
- CFWL_PictureBoxTP* pPictureBoxTP = new CFWL_PictureBoxTP;
- CFWL_ScrollBarTP* pSrollBarTP = new CFWL_ScrollBarTP;
- CFWL_EditTP* pEditTP = new CFWL_EditTP;
- CFWL_ComboBoxTP* pComboBoxTP = new CFWL_ComboBoxTP;
- CFWL_BarcodeTP* pBarcodeTP = new CFWL_BarcodeTP;
- CFWL_DateTimePickerTP* pDateTimePickerTP = new CFWL_DateTimePickerTP;
- CFWL_MonthCalendarTP* pMonthCalendarTP = new CFWL_MonthCalendarTP;
- CFWL_CaretTP* pCaretTP = new CFWL_CaretTP;
- m_arrThemes.Add(pFormTP);
- m_arrThemes.Add(pPushButtonTP);
- m_arrThemes.Add(pCheckBoxTP);
- m_arrThemes.Add(pListBoxTP);
- m_arrThemes.Add(pPictureBoxTP);
- m_arrThemes.Add(pSrollBarTP);
- m_arrThemes.Add(pEditTP);
- m_arrThemes.Add(pComboBoxTP);
- m_arrThemes.Add(pBarcodeTP);
- m_arrThemes.Add(pDateTimePickerTP);
- m_arrThemes.Add(pMonthCalendarTP);
- m_arrThemes.Add(pCaretTP);
-}
-CFWL_Theme::~CFWL_Theme() {
- for (int32_t i = 0; i < m_arrThemes.GetSize(); i++) {
- delete static_cast<CFWL_WidgetTP*>(m_arrThemes[i]);
- }
- m_arrThemes.RemoveAll();
-}
+
FWL_ERR CFWL_Theme::SetFont(IFWL_Widget* pWidget,
const FX_WCHAR* strFont,
FX_FLOAT fFontSize,
FX_ARGB rgbFont) {
- int32_t iCount = m_arrThemes.GetSize();
- for (int32_t i = 0; i < iCount; i++) {
- CFWL_WidgetTP* pTheme = static_cast<CFWL_WidgetTP*>(m_arrThemes[i]);
+ for (const auto& pTheme : m_ThemesArray)
pTheme->SetFont(pWidget, strFont, fFontSize, rgbFont);
- }
+
return FWL_ERR_Succeeded;
}
+
CFWL_WidgetTP* CFWL_Theme::GetTheme(IFWL_Widget* pWidget) {
- int32_t iCount = m_arrThemes.GetSize();
- for (int32_t i = 0; i < iCount; i++) {
- CFWL_WidgetTP* pTheme = static_cast<CFWL_WidgetTP*>(m_arrThemes[i]);
- if (pTheme->IsValidWidget(pWidget)) {
- return pTheme;
- }
+ for (const auto& pTheme : m_ThemesArray) {
+ if (pTheme->IsValidWidget(pWidget))
+ return pTheme.get();
}
- return NULL;
+ return nullptr;
}