From ad700c2c1fc3c3843dae71e5982f462e42efc987 Mon Sep 17 00:00:00 2001 From: tsepez Date: Thu, 2 Jun 2016 14:17:40 -0700 Subject: Replace FWL_HLISTITEM with class IFWL_ListItem {} Make CFWL_ classes inherit from IFWL_ListItem. Replace reinterpret_casts with static_casts. Review-Url: https://codereview.chromium.org/2029923002 --- xfa/fwl/lightwidget/cfwl_combobox.cpp | 104 ++++++++++++++++------------------ 1 file changed, 50 insertions(+), 54 deletions(-) (limited to 'xfa/fwl/lightwidget/cfwl_combobox.cpp') diff --git a/xfa/fwl/lightwidget/cfwl_combobox.cpp b/xfa/fwl/lightwidget/cfwl_combobox.cpp index d70113b18a..934b0d856e 100644 --- a/xfa/fwl/lightwidget/cfwl_combobox.cpp +++ b/xfa/fwl/lightwidget/cfwl_combobox.cpp @@ -69,8 +69,8 @@ int32_t CFWL_ComboBox::CountItems() { FWL_Error CFWL_ComboBox::GetTextByIndex(int32_t iIndex, CFX_WideString& wsText) { - CFWL_ComboBoxItem* pItem = reinterpret_cast( - m_comboBoxData.GetItem(m_pIface, iIndex)); + CFWL_ComboBoxItem* pItem = + static_cast(m_comboBoxData.GetItem(m_pIface, iIndex)); if (!pItem) return FWL_Error::Indefinite; wsText = pItem->m_wsText; @@ -158,8 +158,8 @@ FWL_Error CFWL_ComboBox::SetMaxListHeight(FX_FLOAT fMaxHeight) { } FWL_Error CFWL_ComboBox::SetItemData(int32_t iIndex, void* pData) { - CFWL_ComboBoxItem* pItem = reinterpret_cast( - m_comboBoxData.GetItem(m_pIface, iIndex)); + CFWL_ComboBoxItem* pItem = + static_cast(m_comboBoxData.GetItem(m_pIface, iIndex)); if (!pItem) return FWL_Error::Indefinite; pItem->m_pData = pData; @@ -167,8 +167,8 @@ FWL_Error CFWL_ComboBox::SetItemData(int32_t iIndex, void* pData) { } void* CFWL_ComboBox::GetItemData(int32_t iIndex) { - CFWL_ComboBoxItem* pItem = reinterpret_cast( - m_comboBoxData.GetItem(m_pIface, iIndex)); + CFWL_ComboBoxItem* pItem = + static_cast(m_comboBoxData.GetItem(m_pIface, iIndex)); if (!pItem) return NULL; return pItem->m_pData; @@ -294,93 +294,92 @@ int32_t CFWL_ComboBox::CFWL_ComboBoxDP::CountItems(IFWL_Widget* pWidget) { return m_ItemArray.size(); } -FWL_HLISTITEM CFWL_ComboBox::CFWL_ComboBoxDP::GetItem(IFWL_Widget* pWidget, - int32_t nIndex) { +IFWL_ListItem* CFWL_ComboBox::CFWL_ComboBoxDP::GetItem(IFWL_Widget* pWidget, + int32_t nIndex) { if (nIndex < 0 || static_cast(nIndex) >= m_ItemArray.size()) return nullptr; - return reinterpret_cast(m_ItemArray[nIndex].get()); + return m_ItemArray[nIndex].get(); } int32_t CFWL_ComboBox::CFWL_ComboBoxDP::GetItemIndex(IFWL_Widget* pWidget, - FWL_HLISTITEM hItem) { + IFWL_ListItem* pItem) { auto it = std::find_if( m_ItemArray.begin(), m_ItemArray.end(), - [hItem](const std::unique_ptr& candidate) { - return candidate.get() == reinterpret_cast(hItem); + [pItem](const std::unique_ptr& candidate) { + return candidate.get() == static_cast(pItem); }); return it != m_ItemArray.end() ? it - m_ItemArray.begin() : -1; } FX_BOOL CFWL_ComboBox::CFWL_ComboBoxDP::SetItemIndex(IFWL_Widget* pWidget, - FWL_HLISTITEM hItem, + IFWL_ListItem* pItem, int32_t nIndex) { if (nIndex < 0 || static_cast(nIndex) >= m_ItemArray.size()) return FALSE; - m_ItemArray[nIndex].reset(reinterpret_cast(hItem)); + m_ItemArray[nIndex].reset(static_cast(pItem)); return TRUE; } uint32_t CFWL_ComboBox::CFWL_ComboBoxDP::GetItemStyles(IFWL_Widget* pWidget, - FWL_HLISTITEM hItem) { - if (!hItem) + IFWL_ListItem* pItem) { + if (!pItem) return 0; - return reinterpret_cast(hItem)->m_dwStyles; + return static_cast(pItem)->m_dwStyles; } FWL_Error CFWL_ComboBox::CFWL_ComboBoxDP::GetItemText(IFWL_Widget* pWidget, - FWL_HLISTITEM hItem, + IFWL_ListItem* pItem, CFX_WideString& wsText) { - if (!hItem) + if (!pItem) return FWL_Error::Indefinite; - wsText = reinterpret_cast(hItem)->m_wsText; + wsText = static_cast(pItem)->m_wsText; return FWL_Error::Succeeded; } FWL_Error CFWL_ComboBox::CFWL_ComboBoxDP::GetItemRect(IFWL_Widget* pWidget, - FWL_HLISTITEM hItem, + IFWL_ListItem* pItem, CFX_RectF& rtItem) { - if (!hItem) + if (!pItem) return FWL_Error::Indefinite; - CFWL_ComboBoxItem* pItem = reinterpret_cast(hItem); - rtItem.Set(pItem->m_rtItem.left, pItem->m_rtItem.top, pItem->m_rtItem.width, - pItem->m_rtItem.height); + CFWL_ComboBoxItem* pComboItem = static_cast(pItem); + rtItem.Set(pComboItem->m_rtItem.left, pComboItem->m_rtItem.top, + pComboItem->m_rtItem.width, pComboItem->m_rtItem.height); return FWL_Error::Succeeded; } void* CFWL_ComboBox::CFWL_ComboBoxDP::GetItemData(IFWL_Widget* pWidget, - FWL_HLISTITEM hItem) { - if (!hItem) + IFWL_ListItem* pItem) { + if (!pItem) return NULL; - CFWL_ComboBoxItem* pItem = reinterpret_cast(hItem); - return pItem->m_pData; + return static_cast(pItem)->m_pData; } FWL_Error CFWL_ComboBox::CFWL_ComboBoxDP::SetItemStyles(IFWL_Widget* pWidget, - FWL_HLISTITEM hItem, + IFWL_ListItem* pItem, uint32_t dwStyle) { - if (!hItem) + if (!pItem) return FWL_Error::Indefinite; - reinterpret_cast(hItem)->m_dwStyles = dwStyle; + static_cast(pItem)->m_dwStyles = dwStyle; return FWL_Error::Succeeded; } FWL_Error CFWL_ComboBox::CFWL_ComboBoxDP::SetItemText(IFWL_Widget* pWidget, - FWL_HLISTITEM hItem, + IFWL_ListItem* pItem, const FX_WCHAR* pszText) { - if (!hItem) + if (!pItem) return FWL_Error::Indefinite; - reinterpret_cast(hItem)->m_wsText = pszText; + static_cast(pItem)->m_wsText = pszText; return FWL_Error::Succeeded; } FWL_Error CFWL_ComboBox::CFWL_ComboBoxDP::SetItemRect(IFWL_Widget* pWidget, - FWL_HLISTITEM hItem, + IFWL_ListItem* pItem, const CFX_RectF& rtItem) { - if (!hItem) + if (!pItem) return FWL_Error::Indefinite; - reinterpret_cast(hItem)->m_rtItem = rtItem; + static_cast(pItem)->m_rtItem = rtItem; return FWL_Error::Succeeded; } @@ -388,43 +387,40 @@ FX_FLOAT CFWL_ComboBox::CFWL_ComboBoxDP::GetItemHeight(IFWL_Widget* pWidget) { return m_fItemHeight; } -CFX_DIBitmap* CFWL_ComboBox::CFWL_ComboBoxDP::GetItemIcon(IFWL_Widget* pWidget, - FWL_HLISTITEM hItem) { - if (!hItem) +CFX_DIBitmap* CFWL_ComboBox::CFWL_ComboBoxDP::GetItemIcon( + IFWL_Widget* pWidget, + IFWL_ListItem* pItem) { + if (!pItem) return NULL; - return reinterpret_cast(hItem)->m_pDIB; + return static_cast(pItem)->m_pDIB; } FWL_Error CFWL_ComboBox::CFWL_ComboBoxDP::GetItemCheckRect(IFWL_Widget* pWidget, - FWL_HLISTITEM hItem, + IFWL_ListItem* pItem, CFX_RectF& rtCheck) { - CFWL_ComboBoxItem* pItem = reinterpret_cast(hItem); - rtCheck = pItem->m_rtCheckBox; + rtCheck = static_cast(pItem)->m_rtCheckBox; return FWL_Error::Succeeded; } FWL_Error CFWL_ComboBox::CFWL_ComboBoxDP::SetItemCheckRect( IFWL_Widget* pWidget, - FWL_HLISTITEM hItem, + IFWL_ListItem* pItem, const CFX_RectF& rtCheck) { - CFWL_ComboBoxItem* pItem = reinterpret_cast(hItem); - pItem->m_rtCheckBox = rtCheck; + static_cast(pItem)->m_rtCheckBox = rtCheck; return FWL_Error::Succeeded; } uint32_t CFWL_ComboBox::CFWL_ComboBoxDP::GetItemCheckState( IFWL_Widget* pWidget, - FWL_HLISTITEM hItem) { - CFWL_ComboBoxItem* pItem = reinterpret_cast(hItem); - return pItem->m_dwCheckState; + IFWL_ListItem* pItem) { + return static_cast(pItem)->m_dwCheckState; } FWL_Error CFWL_ComboBox::CFWL_ComboBoxDP::SetItemCheckState( IFWL_Widget* pWidget, - FWL_HLISTITEM hItem, + IFWL_ListItem* pItem, uint32_t dwCheckState) { - CFWL_ComboBoxItem* pItem = reinterpret_cast(hItem); - pItem->m_dwCheckState = dwCheckState; + static_cast(pItem)->m_dwCheckState = dwCheckState; return FWL_Error::Succeeded; } -- cgit v1.2.3