summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--third_party/base/stl_util.h2
-rw-r--r--xfa/include/fwl/lightwidget/listbox.h98
-rw-r--r--xfa/include/fwl/lightwidget/theme.h12
-rw-r--r--xfa/include/fwl/theme/widgettp.h27
-rw-r--r--xfa/src/fwl/src/lightwidget/listbox.cpp74
-rw-r--r--xfa/src/fwl/src/lightwidget/theme.cpp132
-rw-r--r--xfa/src/fwl/src/theme/widgettp.cpp56
7 files changed, 202 insertions, 199 deletions
diff --git a/third_party/base/stl_util.h b/third_party/base/stl_util.h
index 7f1d38bf40..353d3a68c3 100644
--- a/third_party/base/stl_util.h
+++ b/third_party/base/stl_util.h
@@ -5,6 +5,8 @@
#ifndef PDFIUM_THIRD_PARTY_BASE_STL_UTIL_H_
#define PDFIUM_THIRD_PARTY_BASE_STL_UTIL_H_
+#include <algorithm>
+
#include "third_party/base/numerics/safe_conversions.h"
namespace pdfium {
diff --git a/xfa/include/fwl/lightwidget/listbox.h b/xfa/include/fwl/lightwidget/listbox.h
index 70888f6007..09bc018a63 100644
--- a/xfa/include/fwl/lightwidget/listbox.h
+++ b/xfa/include/fwl/lightwidget/listbox.h
@@ -4,13 +4,20 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-#ifndef _FWL_LISTBOX_LIGHT_H
-#define _FWL_LISTBOX_LIGHT_H
+#ifndef XFA_INCLUDE_FWL_LIGHTWIDGET_LISTBOX_H_
+#define XFA_INCLUDE_FWL_LIGHTWIDGET_LISTBOX_H_
+
+#include <memory>
+#include <vector>
+
+#include "xfa/include/fwl/lightwidget/widget.h"
+
class CFWL_Widget;
class CFWL_WidgetProperties;
class IFWL_ListBoxDP;
class CFWL_ListBox;
class CFWL_ListItem;
+
class CFWL_ListBox : public CFWL_Widget {
public:
static CFWL_ListBox* Create();
@@ -46,54 +53,58 @@ class CFWL_ListBox : public CFWL_Widget {
public:
CFWL_ListBoxDP();
~CFWL_ListBoxDP();
- virtual FWL_ERR GetCaption(IFWL_Widget* pWidget, CFX_WideString& wsCaption);
- virtual int32_t CountItems(IFWL_Widget* pWidget);
- virtual FWL_HLISTITEM GetItem(IFWL_Widget* pWidget, int32_t nIndex);
- virtual int32_t GetItemIndex(IFWL_Widget* pWidget, FWL_HLISTITEM hItem);
- virtual FX_BOOL SetItemIndex(IFWL_Widget* pWidget,
- FWL_HLISTITEM hItem,
- int32_t nIndex);
+ // IFWL_DataProvider:
+ FWL_ERR GetCaption(IFWL_Widget* pWidget,
+ CFX_WideString& wsCaption) override;
- virtual FX_DWORD GetItemStyles(IFWL_Widget* pWidget, FWL_HLISTITEM hItem);
- virtual FWL_ERR GetItemText(IFWL_Widget* pWidget,
- FWL_HLISTITEM hItem,
- CFX_WideString& wsText);
- virtual FWL_ERR GetItemRect(IFWL_Widget* pWidget,
- FWL_HLISTITEM hItem,
- CFX_RectF& rtItem);
- virtual void* GetItemData(IFWL_Widget* pWidget, FWL_HLISTITEM hItem);
+ // IFWL_ListBoxDP:
+ int32_t CountItems(IFWL_Widget* pWidget) override;
+ FWL_HLISTITEM GetItem(IFWL_Widget* pWidget, int32_t nIndex) override;
+ int32_t GetItemIndex(IFWL_Widget* pWidget, FWL_HLISTITEM hItem) override;
+ FX_BOOL SetItemIndex(IFWL_Widget* pWidget,
+ FWL_HLISTITEM hItem,
+ int32_t nIndex) override;
+ FX_DWORD GetItemStyles(IFWL_Widget* pWidget, FWL_HLISTITEM hItem) override;
+ FWL_ERR GetItemText(IFWL_Widget* pWidget,
+ FWL_HLISTITEM hItem,
+ CFX_WideString& wsText) override;
+ FWL_ERR GetItemRect(IFWL_Widget* pWidget,
+ FWL_HLISTITEM hItem,
+ CFX_RectF& rtItem) override;
+ void* GetItemData(IFWL_Widget* pWidget, FWL_HLISTITEM hItem) override;
+ FWL_ERR SetItemStyles(IFWL_Widget* pWidget,
+ FWL_HLISTITEM hItem,
+ FX_DWORD dwStyle) override;
+ FWL_ERR SetItemText(IFWL_Widget* pWidget,
+ FWL_HLISTITEM hItem,
+ const FX_WCHAR* pszText) override;
+ FWL_ERR SetItemRect(IFWL_Widget* pWidget,
+ FWL_HLISTITEM hItem,
+ const CFX_RectF& rtItem) override;
+ FX_FLOAT GetItemHeight(IFWL_Widget* pWidget) override;
+ CFX_DIBitmap* GetItemIcon(IFWL_Widget* pWidget,
+ FWL_HLISTITEM hItem) override;
+ FWL_ERR GetItemCheckRect(IFWL_Widget* pWidget,
+ FWL_HLISTITEM hItem,
+ CFX_RectF& rtCheck) override;
+ FWL_ERR SetItemCheckRect(IFWL_Widget* pWidget,
+ FWL_HLISTITEM hItem,
+ const CFX_RectF& rtCheck) override;
+ FX_DWORD GetItemCheckState(IFWL_Widget* pWidget,
+ FWL_HLISTITEM hItem) override;
+ FWL_ERR SetItemCheckState(IFWL_Widget* pWidget,
+ FWL_HLISTITEM hItem,
+ FX_DWORD dwCheckState) override;
- virtual FWL_ERR SetItemStyles(IFWL_Widget* pWidget,
- FWL_HLISTITEM hItem,
- FX_DWORD dwStyle);
- virtual FWL_ERR SetItemText(IFWL_Widget* pWidget,
- FWL_HLISTITEM hItem,
- const FX_WCHAR* pszText);
- virtual FWL_ERR SetItemRect(IFWL_Widget* pWidget,
- FWL_HLISTITEM hItem,
- const CFX_RectF& rtItem);
- virtual FX_FLOAT GetItemHeight(IFWL_Widget* pWidget);
- virtual CFX_DIBitmap* GetItemIcon(IFWL_Widget* pWidget,
- FWL_HLISTITEM hItem);
- virtual FWL_ERR GetItemCheckRect(IFWL_Widget* pWidget,
- FWL_HLISTITEM hItem,
- CFX_RectF& rtCheck);
- virtual FWL_ERR SetItemCheckRect(IFWL_Widget* pWidget,
- FWL_HLISTITEM hItem,
- const CFX_RectF& rtCheck);
- virtual FX_DWORD GetItemCheckState(IFWL_Widget* pWidget,
- FWL_HLISTITEM hItem);
- virtual FWL_ERR SetItemCheckState(IFWL_Widget* pWidget,
- FWL_HLISTITEM hItem,
- FX_DWORD dwCheckState);
-
- CFX_PtrArray m_arrItem;
+ std::vector<std::unique_ptr<CFWL_ListItem>> m_ItemArray;
CFX_WideString m_wsData;
FX_FLOAT m_fItemHeight;
};
+
CFWL_ListBoxDP m_ListBoxDP;
};
+
class CFWL_ListItem {
public:
CFWL_ListItem() {
@@ -113,4 +124,5 @@ class CFWL_ListItem {
FX_DWORD m_dwCheckState;
CFX_RectF m_rtCheckBox;
};
-#endif
+
+#endif // XFA_INCLUDE_FWL_LIGHTWIDGET_LISTBOX_H_
diff --git a/xfa/include/fwl/lightwidget/theme.h b/xfa/include/fwl/lightwidget/theme.h
index 75a60dc9fe..824cacebc7 100644
--- a/xfa/include/fwl/lightwidget/theme.h
+++ b/xfa/include/fwl/lightwidget/theme.h
@@ -4,8 +4,11 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-#ifndef _FWL_THEME_LIGHT_H
-#define _FWL_THEME_LIGHT_H
+#ifndef XFA_INCLUDE_FWL_LIGHTWIDGET_THEME_H_
+#define XFA_INCLUDE_FWL_LIGHTWIDGET_THEME_H_
+
+#include <memory>
+#include <vector>
#include "xfa/include/fwl/core/fwl_theme.h"
@@ -45,6 +48,7 @@ class CFWL_Theme : public IFWL_ThemeProvider {
CFWL_WidgetTP* GetTheme(IFWL_Widget* pWidget);
protected:
- CFX_PtrArray m_arrThemes;
+ std::vector<std::unique_ptr<CFWL_WidgetTP>> m_ThemesArray;
};
-#endif
+
+#endif // XFA_INCLUDE_FWL_LIGHTWIDGET_THEME_H_
diff --git a/xfa/include/fwl/theme/widgettp.h b/xfa/include/fwl/theme/widgettp.h
index adeeb42d6c..404ca51547 100644
--- a/xfa/include/fwl/theme/widgettp.h
+++ b/xfa/include/fwl/theme/widgettp.h
@@ -4,8 +4,12 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-#ifndef _FWL_WIDGETTP_H
-#define _FWL_WIDGETTP_H
+#ifndef XFA_INCLUDE_FWL_THEME_WIDGETTP_H_
+#define XFA_INCLUDE_FWL_THEME_WIDGETTP_H_
+
+#include <memory>
+#include <vector>
+
class IFWL_ThemeProvider;
class IFWL_Widget;
class IFDE_TextOut;
@@ -16,6 +20,7 @@ class IFX_FontSourceEnum;
#endif
class CFWL_WidgetTP;
class CFWL_ArrowData;
+
class CFWL_WidgetTP {
public:
virtual FX_BOOL IsValidWidget(IFWL_Widget* pWidget);
@@ -142,6 +147,7 @@ void FWLTHEME_Release();
FX_DWORD FWL_GetThemeLayout(FX_DWORD dwThemeID);
FX_DWORD FWL_GetThemeColor(FX_DWORD dwThemeID);
FX_DWORD FWL_MakeThemeID(FX_DWORD dwLayout, FX_DWORD dwColor);
+
class CFWL_ArrowData {
public:
static CFWL_ArrowData* GetInstance();
@@ -162,6 +168,7 @@ class CFWL_ArrowData {
CFWL_ArrowData();
static CFWL_ArrowData* m_pInstance;
};
+
class CFWL_FontData {
public:
CFWL_FontData();
@@ -184,16 +191,22 @@ class CFWL_FontData {
IFX_FontSourceEnum* m_pFontSource;
#endif
};
+
class CFWL_FontManager {
public:
- CFWL_FontManager();
- virtual ~CFWL_FontManager();
+ static CFWL_FontManager* GetInstance();
+ static void DestroyInstance();
+
IFX_Font* FindFont(const CFX_WideStringC& wsFontFamily,
FX_DWORD dwFontStyles,
FX_WORD dwCodePage);
protected:
- CFX_PtrArray m_arrFonts;
+ CFWL_FontManager();
+ virtual ~CFWL_FontManager();
+
+ static CFWL_FontManager* s_FontManager;
+ std::vector<std::unique_ptr<CFWL_FontData>> m_FontsArray;
};
-CFWL_FontManager* FWL_GetFontManager();
-#endif
+
+#endif // XFA_INCLUDE_FWL_THEME_WIDGETTP_H_
diff --git a/xfa/src/fwl/src/lightwidget/listbox.cpp b/xfa/src/fwl/src/lightwidget/listbox.cpp
index c1eb6728e8..62e25cc36d 100644
--- a/xfa/src/fwl/src/lightwidget/listbox.cpp
+++ b/xfa/src/fwl/src/lightwidget/listbox.cpp
@@ -6,6 +6,7 @@
#include <memory>
+#include "third_party/base/stl_util.h"
#include "xfa/src/foxitlib.h"
CFWL_ListBox* CFWL_ListBox::Create() {
@@ -33,16 +34,17 @@ FWL_ERR CFWL_ListBox::AddDIBitmap(CFX_DIBitmap* pDIB, FWL_HLISTITEM hItem) {
}
FWL_HLISTITEM CFWL_ListBox::AddString(const CFX_WideStringC& wsAdd,
FX_BOOL bSelect) {
- CFWL_ListItem* pItem = new CFWL_ListItem;
+ std::unique_ptr<CFWL_ListItem> pItem(new CFWL_ListItem);
pItem->m_dwStates = 0;
pItem->m_wsText = wsAdd;
pItem->m_dwStates = bSelect ? FWL_ITEMSTATE_LTB_Selected : 0;
- m_ListBoxDP.m_arrItem.Add(pItem);
- return (FWL_HLISTITEM)pItem;
+ m_ListBoxDP.m_ItemArray.push_back(std::move(pItem));
+ return (FWL_HLISTITEM)m_ListBoxDP.m_ItemArray.back().get();
}
FX_BOOL CFWL_ListBox::DeleteString(FWL_HLISTITEM hItem) {
int32_t nIndex = m_ListBoxDP.GetItemIndex(GetWidget(), hItem);
- if (nIndex < 0 || nIndex >= m_ListBoxDP.m_arrItem.GetSize()) {
+ if (nIndex < 0 ||
+ static_cast<size_t>(nIndex) >= m_ListBoxDP.m_ItemArray.size()) {
return FALSE;
}
CFWL_ListItem* pDelItem =
@@ -60,18 +62,18 @@ FX_BOOL CFWL_ListBox::DeleteString(FWL_HLISTITEM hItem) {
reinterpret_cast<CFWL_ListItem*>(m_ListBoxDP.GetItem(m_pIface, iSel));
pSel->m_dwStates |= FWL_ITEMSTATE_LTB_Selected;
}
- m_ListBoxDP.m_arrItem.RemoveAt(nIndex);
+ m_ListBoxDP.m_ItemArray.erase(m_ListBoxDP.m_ItemArray.begin() + nIndex);
delete pDelItem;
return TRUE;
}
FX_BOOL CFWL_ListBox::DeleteAll() {
- int32_t iCount = m_ListBoxDP.CountItems(m_pIface);
- for (int32_t i = 0; i < iCount; i++) {
+ size_t iCount = m_ListBoxDP.CountItems(m_pIface);
+ for (size_t i = 0; i < iCount; ++i) {
CFWL_ListItem* pItem =
reinterpret_cast<CFWL_ListItem*>(m_ListBoxDP.GetItem(m_pIface, i));
delete pItem;
}
- m_ListBoxDP.m_arrItem.RemoveAll();
+ m_ListBoxDP.m_ItemArray.clear();
return TRUE;
}
int32_t CFWL_ListBox::CountSelItems() {
@@ -109,33 +111,28 @@ FWL_ERR CFWL_ListBox::SetItemHeight(FX_FLOAT fItemHeight) {
return FWL_ERR_Succeeded;
}
FWL_HLISTITEM CFWL_ListBox::GetFocusItem() {
- for (int32_t i = 0; i < m_ListBoxDP.m_arrItem.GetSize(); i++) {
- CFWL_ListItem* hItem =
- static_cast<CFWL_ListItem*>(m_ListBoxDP.m_arrItem[i]);
- if (hItem->m_dwStates & FWL_ITEMSTATE_LTB_Focused) {
- return (FWL_HLISTITEM)hItem;
- }
+ for (const auto& hItem : m_ListBoxDP.m_ItemArray) {
+ if (hItem->m_dwStates & FWL_ITEMSTATE_LTB_Focused)
+ return (FWL_HLISTITEM)hItem.get();
}
- return NULL;
+ return nullptr;
}
FWL_ERR CFWL_ListBox::SetFocusItem(FWL_HLISTITEM hItem) {
int32_t nIndex = m_ListBoxDP.GetItemIndex(GetWidget(), hItem);
- static_cast<CFWL_ListItem*>(m_ListBoxDP.m_arrItem[nIndex])->m_dwStates |=
- FWL_ITEMSTATE_LTB_Focused;
+ m_ListBoxDP.m_ItemArray[nIndex]->m_dwStates |= FWL_ITEMSTATE_LTB_Focused;
return FWL_ERR_Succeeded;
}
FWL_ERR* CFWL_ListBox::Sort(IFWL_ListBoxCompare* pCom) {
return static_cast<IFWL_ListBox*>(m_pIface)->Sort(pCom);
}
int32_t CFWL_ListBox::CountItems() {
- return m_ListBoxDP.m_arrItem.GetSize();
+ return pdfium::CollectionSize<int32_t>(m_ListBoxDP.m_ItemArray);
}
FWL_HLISTITEM CFWL_ListBox::GetItem(int32_t nIndex) {
- int32_t nCount = m_ListBoxDP.m_arrItem.GetSize();
- if (nIndex > nCount - 1 && nIndex < 0) {
- return NULL;
- }
- return (FWL_HLISTITEM)m_ListBoxDP.m_arrItem[nIndex];
+ if (nIndex < 0 || nIndex >= CountItems())
+ return nullptr;
+
+ return (FWL_HLISTITEM)m_ListBoxDP.m_ItemArray[nIndex].get();
}
FWL_ERR CFWL_ListBox::SetItemString(FWL_HLISTITEM hItem,
const CFX_WideStringC& wsText) {
@@ -195,37 +192,38 @@ FX_DWORD CFWL_ListBox::GetItemStates(FWL_HLISTITEM hItem) {
CFWL_ListBox::CFWL_ListBox() {}
CFWL_ListBox::~CFWL_ListBox() {}
CFWL_ListBox::CFWL_ListBoxDP::CFWL_ListBoxDP() {}
-CFWL_ListBox::CFWL_ListBoxDP::~CFWL_ListBoxDP() {
- int32_t nCount = m_arrItem.GetSize();
- for (int32_t i = 0; i < nCount; i++) {
- delete static_cast<CFWL_ListItem*>(m_arrItem[i]);
- }
- m_arrItem.RemoveAll();
-}
+CFWL_ListBox::CFWL_ListBoxDP::~CFWL_ListBoxDP() {}
FWL_ERR CFWL_ListBox::CFWL_ListBoxDP::GetCaption(IFWL_Widget* pWidget,
CFX_WideString& wsCaption) {
wsCaption = m_wsData;
return FWL_ERR_Succeeded;
}
int32_t CFWL_ListBox::CFWL_ListBoxDP::CountItems(IFWL_Widget* pWidget) {
- return m_arrItem.GetSize();
+ return pdfium::CollectionSize<int32_t>(m_ItemArray);
}
FWL_HLISTITEM CFWL_ListBox::CFWL_ListBoxDP::GetItem(IFWL_Widget* pWidget,
int32_t nIndex) {
- if (nIndex >= m_arrItem.GetSize() || nIndex < 0) {
- return NULL;
- } else {
- return (FWL_HLISTITEM)m_arrItem[nIndex];
- }
+ if (nIndex < 0 || nIndex >= CountItems(pWidget))
+ return nullptr;
+
+ return (FWL_HLISTITEM)m_ItemArray[nIndex].get();
}
int32_t CFWL_ListBox::CFWL_ListBoxDP::GetItemIndex(IFWL_Widget* pWidget,
FWL_HLISTITEM hItem) {
- return m_arrItem.Find(hItem);
+ auto it = std::find_if(
+ m_ItemArray.begin(), m_ItemArray.end(),
+ [hItem](const std::unique_ptr<CFWL_ListItem>& candidate) {
+ return candidate.get() == reinterpret_cast<CFWL_ListItem*>(hItem);
+ });
+ return it != m_ItemArray.end() ? it - m_ItemArray.begin() : -1;
}
FX_BOOL CFWL_ListBox::CFWL_ListBoxDP::SetItemIndex(IFWL_Widget* pWidget,
FWL_HLISTITEM hItem,
int32_t nIndex) {
- return m_arrItem.SetAt(nIndex, hItem);
+ if (nIndex < 0 || nIndex >= CountItems(pWidget))
+ return FALSE;
+ m_ItemArray[nIndex].reset(reinterpret_cast<CFWL_ListItem*>(hItem));
+ return TRUE;
}
FX_DWORD CFWL_ListBox::CFWL_ListBoxDP::GetItemStyles(IFWL_Widget* pWidget,
FWL_HLISTITEM hItem) {
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;
}
diff --git a/xfa/src/fwl/src/theme/widgettp.cpp b/xfa/src/fwl/src/theme/widgettp.cpp
index 1941694557..ef69ec0334 100644
--- a/xfa/src/fwl/src/theme/widgettp.cpp
+++ b/xfa/src/fwl/src/theme/widgettp.cpp
@@ -166,7 +166,7 @@ FWL_ERR CFWL_WidgetTP::SetFont(IFWL_Widget* pWidget,
if (!m_pTextOut) {
return FWL_ERR_Succeeded;
}
- m_pFDEFont = FWL_GetFontManager()->FindFont(strFont, 0, 0);
+ m_pFDEFont = CFWL_FontManager::GetInstance()->FindFont(strFont, 0, 0);
m_pTextOut->SetFont(m_pFDEFont);
m_pTextOut->SetFontSize(fFontSize);
m_pTextOut->SetTextColor(rgbFont);
@@ -193,7 +193,8 @@ FX_ERR CFWL_WidgetTP::InitTTO() {
if (m_pTextOut) {
return FWL_ERR_Succeeded;
}
- m_pFDEFont = FWL_GetFontManager()->FindFont(FX_WSTRC(L"Helvetica"), 0, 0);
+ m_pFDEFont =
+ CFWL_FontManager::GetInstance()->FindFont(FX_WSTRC(L"Helvetica"), 0, 0);
m_pTextOut = IFDE_TextOut::Create();
m_pTextOut->SetFont(m_pFDEFont);
m_pTextOut->SetFontSize(FWLTHEME_CAPACITY_FontSize);
@@ -683,17 +684,6 @@ FWLCOLOR CFWL_WidgetTP::BlendColor(FWLCOLOR srcColor,
CFWL_ArrowData::CFWL_ArrowData() : m_pColorData(NULL) {
SetColorData(0);
}
-CFWL_FontManager* FWL_GetFontManager() {
- static CFWL_FontManager* _fontManager = NULL;
- if (_fontManager == NULL) {
- _fontManager = new CFWL_FontManager;
- }
- return _fontManager;
-}
-void FWL_ReleaseFontManager() {
- CFWL_FontManager* fontManager = FWL_GetFontManager();
- delete fontManager;
-}
CFWL_FontData::CFWL_FontData()
: m_dwStyles(0),
m_dwCodePage(0),
@@ -742,36 +732,38 @@ FX_BOOL CFWL_FontData::LoadFont(const CFX_WideStringC& wsFontFamily,
m_pFontMgr);
return m_pFont != NULL;
}
-CFWL_FontManager::CFWL_FontManager() {}
-CFWL_FontManager::~CFWL_FontManager() {
- for (int32_t i = 0; i < m_arrFonts.GetSize(); i++) {
- delete static_cast<CFWL_FontData*>(m_arrFonts[i]);
- }
- m_arrFonts.RemoveAll();
+
+CFWL_FontManager* CFWL_FontManager::s_FontManager = nullptr;
+CFWL_FontManager* CFWL_FontManager::GetInstance() {
+ if (!s_FontManager)
+ s_FontManager = new CFWL_FontManager;
+ return s_FontManager;
+}
+void CFWL_FontManager::DestroyInstance() {
+ delete s_FontManager;
+ s_FontManager = nullptr;
}
+CFWL_FontManager::CFWL_FontManager() {}
+CFWL_FontManager::~CFWL_FontManager() {}
IFX_Font* CFWL_FontManager::FindFont(const CFX_WideStringC& wsFontFamily,
FX_DWORD dwFontStyles,
FX_WORD wCodePage) {
- for (int32_t i = 0; i < m_arrFonts.GetSize(); i++) {
- CFWL_FontData* data = static_cast<CFWL_FontData*>(m_arrFonts[i]);
- if (data->Equal(wsFontFamily, dwFontStyles, wCodePage)) {
- return data->GetFont();
- }
- }
- CFWL_FontData* fontData = new CFWL_FontData;
- if (!fontData->LoadFont(wsFontFamily, dwFontStyles, wCodePage)) {
- delete fontData;
- return NULL;
+ for (const auto& pData : m_FontsArray) {
+ if (pData->Equal(wsFontFamily, dwFontStyles, wCodePage))
+ return pData->GetFont();
}
- m_arrFonts.Add(fontData);
- return fontData->GetFont();
+ std::unique_ptr<CFWL_FontData> pFontData(new CFWL_FontData);
+ if (!pFontData->LoadFont(wsFontFamily, dwFontStyles, wCodePage))
+ return nullptr;
+ m_FontsArray.push_back(std::move(pFontData));
+ return m_FontsArray.back()->GetFont();
}
FX_BOOL FWLTHEME_Init() {
return TRUE;
}
void FWLTHEME_Release() {
CFWL_ArrowData::DestroyInstance();
- FWL_ReleaseFontManager();
+ CFWL_FontManager::DestroyInstance();
}
FX_DWORD FWL_GetThemeLayout(FX_DWORD dwThemeID) {
return 0xffff0000 & dwThemeID;