From 0ced827f257344a1f5804aa96df538f3e783bd10 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Wed, 23 Nov 2016 12:20:47 -0500 Subject: Remove listbox providers and build into listbox This CL removes the IFWL_ListBox::DataProvider and builds the data storage for the list directly into IFWL_ListBox. This removes the need for the provider in CFWL_ComboBox and CFWL_ListBox. Change-Id: I74c2286757a0b73083908f1cc630a88e7d730fd9 Reviewed-on: https://pdfium-review.googlesource.com/2050 Commit-Queue: dan sinclair Reviewed-by: Tom Sepez --- xfa/fwl/core/cfwl_listbox.cpp | 136 ++++++++---------------------------------- 1 file changed, 24 insertions(+), 112 deletions(-) (limited to 'xfa/fwl/core/cfwl_listbox.cpp') diff --git a/xfa/fwl/core/cfwl_listbox.cpp b/xfa/fwl/core/cfwl_listbox.cpp index cefee8ca87..bf7798978a 100644 --- a/xfa/fwl/core/cfwl_listbox.cpp +++ b/xfa/fwl/core/cfwl_listbox.cpp @@ -34,35 +34,38 @@ void CFWL_ListBox::Initialize() { CFWL_Widget::Initialize(); } +CFWL_ListItem* CFWL_ListBox::GetItem(const IFWL_Widget* pWidget, + int32_t nIndex) const { + return GetWidget() ? ToListBox(GetWidget())->GetItem(pWidget, nIndex) + : nullptr; +} + +void CFWL_ListBox::GetItemText(IFWL_Widget* pWidget, + CFWL_ListItem* pItem, + CFX_WideString& wsText) { + if (GetWidget()) + ToListBox(GetWidget())->GetItemText(pWidget, pItem, wsText); +} + CFWL_ListItem* CFWL_ListBox::AddString(const CFX_WideStringC& wsAdd, bool bSelect) { - std::unique_ptr pItem(new CFWL_ListItem); - pItem->m_dwStates = 0; - pItem->m_wsText = wsAdd; - pItem->m_dwStates = bSelect ? FWL_ITEMSTATE_LTB_Selected : 0; - m_ItemArray.push_back(std::move(pItem)); - return m_ItemArray.back().get(); + return GetWidget() ? ToListBox(GetWidget())->AddString(wsAdd, bSelect) + : nullptr; } bool CFWL_ListBox::DeleteString(CFWL_ListItem* pItem) { - int32_t nIndex = GetItemIndex(GetWidget(), pItem); - if (nIndex < 0 || static_cast(nIndex) >= m_ItemArray.size()) - return false; - - int32_t iSel = nIndex + 1; - if (iSel >= CountItems(m_pIface.get())) - iSel = nIndex - 1; - if (iSel >= 0) { - CFWL_ListItem* pSel = - static_cast(GetItem(m_pIface.get(), iSel)); - pSel->m_dwStates |= FWL_ITEMSTATE_LTB_Selected; - } - m_ItemArray.erase(m_ItemArray.begin() + nIndex); - return true; + return GetWidget() && ToListBox(GetWidget())->DeleteString(pItem); } void CFWL_ListBox::DeleteAll() { - m_ItemArray.clear(); + if (GetWidget()) + ToListBox(GetWidget())->DeleteAll(); +} + +uint32_t CFWL_ListBox::GetItemStates(CFWL_ListItem* pItem) { + if (!pItem) + return 0; + return pItem->m_dwStates | pItem->m_dwCheckState; } int32_t CFWL_ListBox::CountSelItems() { @@ -81,94 +84,3 @@ void CFWL_ListBox::SetSelItem(CFWL_ListItem* pItem, bool bSelect) { if (GetWidget()) ToListBox(GetWidget())->SetSelItem(pItem, bSelect); } - -void CFWL_ListBox::GetItemText(IFWL_Widget* pWidget, - CFWL_ListItem* pItem, - CFX_WideString& wsText) { - if (pItem) - wsText = static_cast(pItem)->m_wsText; -} - -uint32_t CFWL_ListBox::GetItemStates(CFWL_ListItem* pItem) { - if (!pItem) - return 0; - return pItem->m_dwStates | pItem->m_dwCheckState; -} - -int32_t CFWL_ListBox::CountItems(const IFWL_Widget* pWidget) const { - return pdfium::CollectionSize(m_ItemArray); -} - -CFWL_ListItem* CFWL_ListBox::GetItem(const IFWL_Widget* pWidget, - int32_t nIndex) const { - if (nIndex < 0 || nIndex >= CountItems(pWidget)) - return nullptr; - return m_ItemArray[nIndex].get(); -} - -int32_t CFWL_ListBox::GetItemIndex(IFWL_Widget* pWidget, CFWL_ListItem* pItem) { - auto it = std::find_if( - m_ItemArray.begin(), m_ItemArray.end(), - [pItem](const std::unique_ptr& candidate) { - return candidate.get() == static_cast(pItem); - }); - return it != m_ItemArray.end() ? it - m_ItemArray.begin() : -1; -} - -uint32_t CFWL_ListBox::GetItemStyles(IFWL_Widget* pWidget, - CFWL_ListItem* pItem) { - return pItem ? static_cast(pItem)->m_dwStates : 0; -} - -void CFWL_ListBox::GetItemRect(IFWL_Widget* pWidget, - CFWL_ListItem* pItem, - CFX_RectF& rtItem) { - if (pItem) - rtItem = static_cast(pItem)->m_rtItem; -} - -void* CFWL_ListBox::GetItemData(IFWL_Widget* pWidget, CFWL_ListItem* pItem) { - return pItem ? static_cast(pItem)->m_pData : nullptr; -} - -void CFWL_ListBox::SetItemStyles(IFWL_Widget* pWidget, - CFWL_ListItem* pItem, - uint32_t dwStyle) { - if (pItem) - static_cast(pItem)->m_dwStates = dwStyle; -} - -void CFWL_ListBox::SetItemRect(IFWL_Widget* pWidget, - CFWL_ListItem* pItem, - const CFX_RectF& rtItem) { - if (pItem) - static_cast(pItem)->m_rtItem = rtItem; -} - -CFX_DIBitmap* CFWL_ListBox::GetItemIcon(IFWL_Widget* pWidget, - CFWL_ListItem* pItem) { - return static_cast(pItem)->m_pDIB; -} - -void CFWL_ListBox::GetItemCheckRect(IFWL_Widget* pWidget, - CFWL_ListItem* pItem, - CFX_RectF& rtCheck) { - rtCheck = static_cast(pItem)->m_rtCheckBox; -} - -void CFWL_ListBox::SetItemCheckRect(IFWL_Widget* pWidget, - CFWL_ListItem* pItem, - const CFX_RectF& rtCheck) { - static_cast(pItem)->m_rtCheckBox = rtCheck; -} - -uint32_t CFWL_ListBox::GetItemCheckState(IFWL_Widget* pWidget, - CFWL_ListItem* pItem) { - return static_cast(pItem)->m_dwCheckState; -} - -void CFWL_ListBox::SetItemCheckState(IFWL_Widget* pWidget, - CFWL_ListItem* pItem, - uint32_t dwCheckState) { - static_cast(pItem)->m_dwCheckState = dwCheckState; -} -- cgit v1.2.3