diff options
author | Tom Sepez <tsepez@chromium.org> | 2016-02-08 09:34:35 -0800 |
---|---|---|
committer | Tom Sepez <tsepez@chromium.org> | 2016-02-08 09:34:35 -0800 |
commit | ddf2f339f603246107451931d16245c8b7d1d7c4 (patch) | |
tree | 94350b986e9b31f6246616ca08a77e16c9cbc581 /xfa/src | |
parent | 22e659117f4302718e5bb82f7c74251bf032be4d (diff) | |
download | pdfium-ddf2f339f603246107451931d16245c8b7d1d7c4.tar.xz |
Remove CFX_PtrArray from xfa/include/fwl
Fix IWYU in stl_util.h
R=thestig@chromium.org
Review URL: https://codereview.chromium.org/1672283002 .
Diffstat (limited to 'xfa/src')
-rw-r--r-- | xfa/src/fwl/src/lightwidget/listbox.cpp | 74 | ||||
-rw-r--r-- | xfa/src/fwl/src/lightwidget/theme.cpp | 132 | ||||
-rw-r--r-- | xfa/src/fwl/src/theme/widgettp.cpp | 56 |
3 files changed, 117 insertions, 145 deletions
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; |