| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "xfa/fwl/core/cfwl_listbox.h" | 7 #include "xfa/fwl/core/cfwl_listbox.h" |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| 11 #include "third_party/base/stl_util.h" | 11 #include "third_party/base/stl_util.h" |
| 12 | 12 |
| 13 namespace { |
| 14 |
| 15 IFWL_ListBox* ToListBox(IFWL_Widget* widget) { |
| 16 return static_cast<IFWL_ListBox*>(widget); |
| 17 } |
| 18 |
| 19 } // namespace |
| 20 |
| 13 CFWL_ListBox::CFWL_ListBox(const IFWL_App* app) : CFWL_Widget(app) {} | 21 CFWL_ListBox::CFWL_ListBox(const IFWL_App* app) : CFWL_Widget(app) {} |
| 14 | 22 |
| 15 CFWL_ListBox::~CFWL_ListBox() {} | 23 CFWL_ListBox::~CFWL_ListBox() {} |
| 16 | 24 |
| 17 void CFWL_ListBox::Initialize() { | 25 void CFWL_ListBox::Initialize() { |
| 18 ASSERT(!m_pIface); | 26 ASSERT(!m_pIface); |
| 19 | 27 |
| 20 std::unique_ptr<IFWL_ListBox> pListBox(new IFWL_ListBox( | 28 std::unique_ptr<IFWL_ListBox> pListBox(new IFWL_ListBox( |
| 21 m_pApp, m_pProperties->MakeWidgetImpProperties(&m_ListBoxDP), nullptr)); | 29 m_pApp, m_pProperties->MakeWidgetImpProperties(&m_ListBoxDP), nullptr)); |
| 22 pListBox->Initialize(); | 30 pListBox->Initialize(); |
| 23 | 31 |
| 24 m_pIface = std::move(pListBox); | 32 m_pIface = std::move(pListBox); |
| 25 CFWL_Widget::Initialize(); | 33 CFWL_Widget::Initialize(); |
| 26 } | 34 } |
| 27 | 35 |
| 28 IFWL_ListBox* CFWL_ListBox::GetWidget() { | |
| 29 return static_cast<IFWL_ListBox*>(m_pIface.get()); | |
| 30 } | |
| 31 | |
| 32 const IFWL_ListBox* CFWL_ListBox::GetWidget() const { | |
| 33 return static_cast<IFWL_ListBox*>(m_pIface.get()); | |
| 34 } | |
| 35 | |
| 36 FWL_Error CFWL_ListBox::AddDIBitmap(CFX_DIBitmap* pDIB, IFWL_ListItem* pItem) { | 36 FWL_Error CFWL_ListBox::AddDIBitmap(CFX_DIBitmap* pDIB, IFWL_ListItem* pItem) { |
| 37 static_cast<CFWL_ListItem*>(pItem)->m_pDIB = pDIB; | 37 static_cast<CFWL_ListItem*>(pItem)->m_pDIB = pDIB; |
| 38 return FWL_Error::Succeeded; | 38 return FWL_Error::Succeeded; |
| 39 } | 39 } |
| 40 | 40 |
| 41 IFWL_ListItem* CFWL_ListBox::AddString(const CFX_WideStringC& wsAdd, | 41 IFWL_ListItem* CFWL_ListBox::AddString(const CFX_WideStringC& wsAdd, |
| 42 FX_BOOL bSelect) { | 42 FX_BOOL bSelect) { |
| 43 std::unique_ptr<CFWL_ListItem> pItem(new CFWL_ListItem); | 43 std::unique_ptr<CFWL_ListItem> pItem(new CFWL_ListItem); |
| 44 pItem->m_dwStates = 0; | 44 pItem->m_dwStates = 0; |
| 45 pItem->m_wsText = wsAdd; | 45 pItem->m_wsText = wsAdd; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 71 return TRUE; | 71 return TRUE; |
| 72 } | 72 } |
| 73 | 73 |
| 74 void CFWL_ListBox::DeleteAll() { | 74 void CFWL_ListBox::DeleteAll() { |
| 75 m_ListBoxDP.m_ItemArray.clear(); | 75 m_ListBoxDP.m_ItemArray.clear(); |
| 76 } | 76 } |
| 77 | 77 |
| 78 int32_t CFWL_ListBox::CountSelItems() { | 78 int32_t CFWL_ListBox::CountSelItems() { |
| 79 if (!GetWidget()) | 79 if (!GetWidget()) |
| 80 return 0; | 80 return 0; |
| 81 return GetWidget()->CountSelItems(); | 81 return ToListBox(GetWidget())->CountSelItems(); |
| 82 } | 82 } |
| 83 | 83 |
| 84 IFWL_ListItem* CFWL_ListBox::GetSelItem(int32_t nIndexSel) { | 84 IFWL_ListItem* CFWL_ListBox::GetSelItem(int32_t nIndexSel) { |
| 85 if (!GetWidget()) | 85 if (!GetWidget()) |
| 86 return nullptr; | 86 return nullptr; |
| 87 return GetWidget()->GetSelItem(nIndexSel); | 87 return ToListBox(GetWidget())->GetSelItem(nIndexSel); |
| 88 } | 88 } |
| 89 | 89 |
| 90 int32_t CFWL_ListBox::GetSelIndex(int32_t nIndex) { | 90 int32_t CFWL_ListBox::GetSelIndex(int32_t nIndex) { |
| 91 if (!GetWidget()) | 91 if (!GetWidget()) |
| 92 return 0; | 92 return 0; |
| 93 return GetWidget()->GetSelIndex(nIndex); | 93 return ToListBox(GetWidget())->GetSelIndex(nIndex); |
| 94 } | 94 } |
| 95 | 95 |
| 96 FWL_Error CFWL_ListBox::SetSelItem(IFWL_ListItem* pItem, FX_BOOL bSelect) { | 96 FWL_Error CFWL_ListBox::SetSelItem(IFWL_ListItem* pItem, FX_BOOL bSelect) { |
| 97 if (!GetWidget()) | 97 if (!GetWidget()) |
| 98 return FWL_Error::Indefinite; | 98 return FWL_Error::Indefinite; |
| 99 return GetWidget()->SetSelItem(pItem, bSelect); | 99 return ToListBox(GetWidget())->SetSelItem(pItem, bSelect); |
| 100 } | 100 } |
| 101 | 101 |
| 102 FWL_Error CFWL_ListBox::GetItemText(IFWL_ListItem* pItem, | 102 FWL_Error CFWL_ListBox::GetItemText(IFWL_ListItem* pItem, |
| 103 CFX_WideString& wsText) { | 103 CFX_WideString& wsText) { |
| 104 if (!GetWidget()) | 104 if (!GetWidget()) |
| 105 return FWL_Error::Indefinite; | 105 return FWL_Error::Indefinite; |
| 106 return GetWidget()->GetItemText(pItem, wsText); | 106 return ToListBox(GetWidget())->GetItemText(pItem, wsText); |
| 107 } | 107 } |
| 108 | 108 |
| 109 FWL_Error CFWL_ListBox::GetScrollPos(FX_FLOAT& fPos, FX_BOOL bVert) { | 109 FWL_Error CFWL_ListBox::GetScrollPos(FX_FLOAT& fPos, FX_BOOL bVert) { |
| 110 if (!GetWidget()) | 110 if (!GetWidget()) |
| 111 return FWL_Error::Indefinite; | 111 return FWL_Error::Indefinite; |
| 112 return GetWidget()->GetScrollPos(fPos, bVert); | 112 return ToListBox(GetWidget())->GetScrollPos(fPos, bVert); |
| 113 } | 113 } |
| 114 | 114 |
| 115 FWL_Error CFWL_ListBox::SetItemHeight(FX_FLOAT fItemHeight) { | 115 FWL_Error CFWL_ListBox::SetItemHeight(FX_FLOAT fItemHeight) { |
| 116 m_ListBoxDP.m_fItemHeight = fItemHeight; | 116 m_ListBoxDP.m_fItemHeight = fItemHeight; |
| 117 return FWL_Error::Succeeded; | 117 return FWL_Error::Succeeded; |
| 118 } | 118 } |
| 119 | 119 |
| 120 IFWL_ListItem* CFWL_ListBox::GetFocusItem() { | 120 IFWL_ListItem* CFWL_ListBox::GetFocusItem() { |
| 121 for (const auto& pItem : m_ListBoxDP.m_ItemArray) { | 121 for (const auto& pItem : m_ListBoxDP.m_ItemArray) { |
| 122 if (pItem->m_dwStates & FWL_ITEMSTATE_LTB_Focused) | 122 if (pItem->m_dwStates & FWL_ITEMSTATE_LTB_Focused) |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 return pItem ? static_cast<CFWL_ListItem*>(pItem)->m_pData : nullptr; | 169 return pItem ? static_cast<CFWL_ListItem*>(pItem)->m_pData : nullptr; |
| 170 } | 170 } |
| 171 | 171 |
| 172 IFWL_ListItem* CFWL_ListBox::GetItemAtPoint(FX_FLOAT fx, FX_FLOAT fy) { | 172 IFWL_ListItem* CFWL_ListBox::GetItemAtPoint(FX_FLOAT fx, FX_FLOAT fy) { |
| 173 CFX_RectF rtClient; | 173 CFX_RectF rtClient; |
| 174 GetWidget()->GetClientRect(rtClient); | 174 GetWidget()->GetClientRect(rtClient); |
| 175 fx -= rtClient.left; | 175 fx -= rtClient.left; |
| 176 fy -= rtClient.top; | 176 fy -= rtClient.top; |
| 177 FX_FLOAT fPosX = 0; | 177 FX_FLOAT fPosX = 0; |
| 178 FX_FLOAT fPosY = 0; | 178 FX_FLOAT fPosY = 0; |
| 179 GetWidget()->GetScrollPos(fx); | 179 ToListBox(GetWidget())->GetScrollPos(fx); |
| 180 GetWidget()->GetScrollPos(fy, FALSE); | 180 ToListBox(GetWidget())->GetScrollPos(fy, FALSE); |
| 181 int32_t nCount = m_ListBoxDP.CountItems(nullptr); | 181 int32_t nCount = m_ListBoxDP.CountItems(nullptr); |
| 182 for (int32_t i = 0; i < nCount; i++) { | 182 for (int32_t i = 0; i < nCount; i++) { |
| 183 IFWL_ListItem* pItem = m_ListBoxDP.GetItem(nullptr, i); | 183 IFWL_ListItem* pItem = m_ListBoxDP.GetItem(nullptr, i); |
| 184 if (!pItem) { | 184 if (!pItem) { |
| 185 continue; | 185 continue; |
| 186 } | 186 } |
| 187 CFX_RectF rtItem; | 187 CFX_RectF rtItem; |
| 188 m_ListBoxDP.GetItemRect(nullptr, pItem, rtItem); | 188 m_ListBoxDP.GetItemRect(nullptr, pItem, rtItem); |
| 189 rtItem.Offset(-fPosX, -fPosY); | 189 rtItem.Offset(-fPosX, -fPosY); |
| 190 if (rtItem.Contains(fx, fy)) { | 190 if (rtItem.Contains(fx, fy)) { |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 m_rtItem.Reset(); | 340 m_rtItem.Reset(); |
| 341 m_dwStates = 0; | 341 m_dwStates = 0; |
| 342 m_wsText = L""; | 342 m_wsText = L""; |
| 343 m_pDIB = nullptr; | 343 m_pDIB = nullptr; |
| 344 m_pData = nullptr; | 344 m_pData = nullptr; |
| 345 m_dwCheckState = 0; | 345 m_dwCheckState = 0; |
| 346 m_rtCheckBox.Reset(); | 346 m_rtCheckBox.Reset(); |
| 347 } | 347 } |
| 348 | 348 |
| 349 CFWL_ListItem::~CFWL_ListItem() {} | 349 CFWL_ListItem::~CFWL_ListItem() {} |
| OLD | NEW |