Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Side by Side Diff: xfa/src/fwl/src/lightwidget/listbox.cpp

Issue 1672283002: Remove CFX_PtrArray from xfa/include/fwl (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « xfa/include/fwl/theme/widgettp.h ('k') | xfa/src/fwl/src/lightwidget/theme.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <memory> 7 #include <memory>
8 8
9 #include "third_party/base/stl_util.h"
9 #include "xfa/src/foxitlib.h" 10 #include "xfa/src/foxitlib.h"
10 11
11 CFWL_ListBox* CFWL_ListBox::Create() { 12 CFWL_ListBox* CFWL_ListBox::Create() {
12 return new CFWL_ListBox; 13 return new CFWL_ListBox;
13 } 14 }
14 FWL_ERR CFWL_ListBox::Initialize(const CFWL_WidgetProperties* pProperties) { 15 FWL_ERR CFWL_ListBox::Initialize(const CFWL_WidgetProperties* pProperties) {
15 if (m_pIface) 16 if (m_pIface)
16 return FWL_ERR_Indefinite; 17 return FWL_ERR_Indefinite;
17 if (pProperties) { 18 if (pProperties) {
18 *m_pProperties = *pProperties; 19 *m_pProperties = *pProperties;
19 } 20 }
20 std::unique_ptr<IFWL_ListBox> pListBox(IFWL_ListBox::Create( 21 std::unique_ptr<IFWL_ListBox> pListBox(IFWL_ListBox::Create(
21 m_pProperties->MakeWidgetImpProperties(&m_ListBoxDP), nullptr)); 22 m_pProperties->MakeWidgetImpProperties(&m_ListBoxDP), nullptr));
22 FWL_ERR ret = pListBox->Initialize(); 23 FWL_ERR ret = pListBox->Initialize();
23 if (ret != FWL_ERR_Succeeded) { 24 if (ret != FWL_ERR_Succeeded) {
24 return ret; 25 return ret;
25 } 26 }
26 m_pIface = pListBox.release(); 27 m_pIface = pListBox.release();
27 CFWL_Widget::Initialize(); 28 CFWL_Widget::Initialize();
28 return FWL_ERR_Succeeded; 29 return FWL_ERR_Succeeded;
29 } 30 }
30 FWL_ERR CFWL_ListBox::AddDIBitmap(CFX_DIBitmap* pDIB, FWL_HLISTITEM hItem) { 31 FWL_ERR CFWL_ListBox::AddDIBitmap(CFX_DIBitmap* pDIB, FWL_HLISTITEM hItem) {
31 reinterpret_cast<CFWL_ListItem*>(hItem)->m_pDIB = pDIB; 32 reinterpret_cast<CFWL_ListItem*>(hItem)->m_pDIB = pDIB;
32 return FWL_ERR_Succeeded; 33 return FWL_ERR_Succeeded;
33 } 34 }
34 FWL_HLISTITEM CFWL_ListBox::AddString(const CFX_WideStringC& wsAdd, 35 FWL_HLISTITEM CFWL_ListBox::AddString(const CFX_WideStringC& wsAdd,
35 FX_BOOL bSelect) { 36 FX_BOOL bSelect) {
36 CFWL_ListItem* pItem = new CFWL_ListItem; 37 std::unique_ptr<CFWL_ListItem> pItem(new CFWL_ListItem);
37 pItem->m_dwStates = 0; 38 pItem->m_dwStates = 0;
38 pItem->m_wsText = wsAdd; 39 pItem->m_wsText = wsAdd;
39 pItem->m_dwStates = bSelect ? FWL_ITEMSTATE_LTB_Selected : 0; 40 pItem->m_dwStates = bSelect ? FWL_ITEMSTATE_LTB_Selected : 0;
40 m_ListBoxDP.m_arrItem.Add(pItem); 41 m_ListBoxDP.m_ItemArray.push_back(std::move(pItem));
41 return (FWL_HLISTITEM)pItem; 42 return (FWL_HLISTITEM)m_ListBoxDP.m_ItemArray.back().get();
42 } 43 }
43 FX_BOOL CFWL_ListBox::DeleteString(FWL_HLISTITEM hItem) { 44 FX_BOOL CFWL_ListBox::DeleteString(FWL_HLISTITEM hItem) {
44 int32_t nIndex = m_ListBoxDP.GetItemIndex(GetWidget(), hItem); 45 int32_t nIndex = m_ListBoxDP.GetItemIndex(GetWidget(), hItem);
45 if (nIndex < 0 || nIndex >= m_ListBoxDP.m_arrItem.GetSize()) { 46 if (nIndex < 0 ||
47 static_cast<size_t>(nIndex) >= m_ListBoxDP.m_ItemArray.size()) {
46 return FALSE; 48 return FALSE;
47 } 49 }
48 CFWL_ListItem* pDelItem = 50 CFWL_ListItem* pDelItem =
49 reinterpret_cast<CFWL_ListItem*>(m_ListBoxDP.GetItem(m_pIface, nIndex)); 51 reinterpret_cast<CFWL_ListItem*>(m_ListBoxDP.GetItem(m_pIface, nIndex));
50 int32_t iCount = m_ListBoxDP.CountItems(m_pIface); 52 int32_t iCount = m_ListBoxDP.CountItems(m_pIface);
51 int32_t iSel = nIndex + 1; 53 int32_t iSel = nIndex + 1;
52 if (iSel >= iCount) { 54 if (iSel >= iCount) {
53 iSel = nIndex - 1; 55 iSel = nIndex - 1;
54 if (iSel < 0) { 56 if (iSel < 0) {
55 iSel = -1; 57 iSel = -1;
56 } 58 }
57 } 59 }
58 if (iSel >= 0) { 60 if (iSel >= 0) {
59 CFWL_ListItem* pSel = 61 CFWL_ListItem* pSel =
60 reinterpret_cast<CFWL_ListItem*>(m_ListBoxDP.GetItem(m_pIface, iSel)); 62 reinterpret_cast<CFWL_ListItem*>(m_ListBoxDP.GetItem(m_pIface, iSel));
61 pSel->m_dwStates |= FWL_ITEMSTATE_LTB_Selected; 63 pSel->m_dwStates |= FWL_ITEMSTATE_LTB_Selected;
62 } 64 }
63 m_ListBoxDP.m_arrItem.RemoveAt(nIndex); 65 m_ListBoxDP.m_ItemArray.erase(m_ListBoxDP.m_ItemArray.begin() + nIndex);
64 delete pDelItem; 66 delete pDelItem;
65 return TRUE; 67 return TRUE;
66 } 68 }
67 FX_BOOL CFWL_ListBox::DeleteAll() { 69 FX_BOOL CFWL_ListBox::DeleteAll() {
68 int32_t iCount = m_ListBoxDP.CountItems(m_pIface); 70 size_t iCount = m_ListBoxDP.CountItems(m_pIface);
69 for (int32_t i = 0; i < iCount; i++) { 71 for (size_t i = 0; i < iCount; ++i) {
70 CFWL_ListItem* pItem = 72 CFWL_ListItem* pItem =
71 reinterpret_cast<CFWL_ListItem*>(m_ListBoxDP.GetItem(m_pIface, i)); 73 reinterpret_cast<CFWL_ListItem*>(m_ListBoxDP.GetItem(m_pIface, i));
72 delete pItem; 74 delete pItem;
73 } 75 }
74 m_ListBoxDP.m_arrItem.RemoveAll(); 76 m_ListBoxDP.m_ItemArray.clear();
75 return TRUE; 77 return TRUE;
76 } 78 }
77 int32_t CFWL_ListBox::CountSelItems() { 79 int32_t CFWL_ListBox::CountSelItems() {
78 if (!m_pIface) 80 if (!m_pIface)
79 return 0; 81 return 0;
80 return static_cast<IFWL_ListBox*>(m_pIface)->CountSelItems(); 82 return static_cast<IFWL_ListBox*>(m_pIface)->CountSelItems();
81 } 83 }
82 FWL_HLISTITEM CFWL_ListBox::GetSelItem(int32_t nIndexSel) { 84 FWL_HLISTITEM CFWL_ListBox::GetSelItem(int32_t nIndexSel) {
83 if (!m_pIface) 85 if (!m_pIface)
84 return NULL; 86 return NULL;
(...skipping 17 matching lines...) Expand all
102 FWL_ERR CFWL_ListBox::GetScrollPos(FX_FLOAT& fPos, FX_BOOL bVert) { 104 FWL_ERR CFWL_ListBox::GetScrollPos(FX_FLOAT& fPos, FX_BOOL bVert) {
103 if (!m_pIface) 105 if (!m_pIface)
104 return FWL_ERR_Indefinite; 106 return FWL_ERR_Indefinite;
105 return static_cast<IFWL_ListBox*>(m_pIface)->GetScrollPos(fPos, bVert); 107 return static_cast<IFWL_ListBox*>(m_pIface)->GetScrollPos(fPos, bVert);
106 } 108 }
107 FWL_ERR CFWL_ListBox::SetItemHeight(FX_FLOAT fItemHeight) { 109 FWL_ERR CFWL_ListBox::SetItemHeight(FX_FLOAT fItemHeight) {
108 m_ListBoxDP.m_fItemHeight = fItemHeight; 110 m_ListBoxDP.m_fItemHeight = fItemHeight;
109 return FWL_ERR_Succeeded; 111 return FWL_ERR_Succeeded;
110 } 112 }
111 FWL_HLISTITEM CFWL_ListBox::GetFocusItem() { 113 FWL_HLISTITEM CFWL_ListBox::GetFocusItem() {
112 for (int32_t i = 0; i < m_ListBoxDP.m_arrItem.GetSize(); i++) { 114 for (const auto& hItem : m_ListBoxDP.m_ItemArray) {
113 CFWL_ListItem* hItem = 115 if (hItem->m_dwStates & FWL_ITEMSTATE_LTB_Focused)
114 static_cast<CFWL_ListItem*>(m_ListBoxDP.m_arrItem[i]); 116 return (FWL_HLISTITEM)hItem.get();
115 if (hItem->m_dwStates & FWL_ITEMSTATE_LTB_Focused) {
116 return (FWL_HLISTITEM)hItem;
117 }
118 } 117 }
119 return NULL; 118 return nullptr;
120 } 119 }
121 FWL_ERR CFWL_ListBox::SetFocusItem(FWL_HLISTITEM hItem) { 120 FWL_ERR CFWL_ListBox::SetFocusItem(FWL_HLISTITEM hItem) {
122 int32_t nIndex = m_ListBoxDP.GetItemIndex(GetWidget(), hItem); 121 int32_t nIndex = m_ListBoxDP.GetItemIndex(GetWidget(), hItem);
123 static_cast<CFWL_ListItem*>(m_ListBoxDP.m_arrItem[nIndex])->m_dwStates |= 122 m_ListBoxDP.m_ItemArray[nIndex]->m_dwStates |= FWL_ITEMSTATE_LTB_Focused;
124 FWL_ITEMSTATE_LTB_Focused;
125 return FWL_ERR_Succeeded; 123 return FWL_ERR_Succeeded;
126 } 124 }
127 FWL_ERR* CFWL_ListBox::Sort(IFWL_ListBoxCompare* pCom) { 125 FWL_ERR* CFWL_ListBox::Sort(IFWL_ListBoxCompare* pCom) {
128 return static_cast<IFWL_ListBox*>(m_pIface)->Sort(pCom); 126 return static_cast<IFWL_ListBox*>(m_pIface)->Sort(pCom);
129 } 127 }
130 int32_t CFWL_ListBox::CountItems() { 128 int32_t CFWL_ListBox::CountItems() {
131 return m_ListBoxDP.m_arrItem.GetSize(); 129 return pdfium::CollectionSize<int32_t>(m_ListBoxDP.m_ItemArray);
132 } 130 }
133 FWL_HLISTITEM CFWL_ListBox::GetItem(int32_t nIndex) { 131 FWL_HLISTITEM CFWL_ListBox::GetItem(int32_t nIndex) {
134 int32_t nCount = m_ListBoxDP.m_arrItem.GetSize(); 132 if (nIndex < 0 || nIndex >= CountItems())
135 if (nIndex > nCount - 1 && nIndex < 0) { 133 return nullptr;
136 return NULL; 134
137 } 135 return (FWL_HLISTITEM)m_ListBoxDP.m_ItemArray[nIndex].get();
138 return (FWL_HLISTITEM)m_ListBoxDP.m_arrItem[nIndex];
139 } 136 }
140 FWL_ERR CFWL_ListBox::SetItemString(FWL_HLISTITEM hItem, 137 FWL_ERR CFWL_ListBox::SetItemString(FWL_HLISTITEM hItem,
141 const CFX_WideStringC& wsText) { 138 const CFX_WideStringC& wsText) {
142 if (!hItem) 139 if (!hItem)
143 return FWL_ERR_Indefinite; 140 return FWL_ERR_Indefinite;
144 reinterpret_cast<CFWL_ListItem*>(hItem)->m_wsText = wsText; 141 reinterpret_cast<CFWL_ListItem*>(hItem)->m_wsText = wsText;
145 return FWL_ERR_Succeeded; 142 return FWL_ERR_Succeeded;
146 } 143 }
147 FWL_ERR CFWL_ListBox::GetItemString(FWL_HLISTITEM hItem, 144 FWL_ERR CFWL_ListBox::GetItemString(FWL_HLISTITEM hItem,
148 CFX_WideString& wsText) { 145 CFX_WideString& wsText) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 } 185 }
189 FX_DWORD CFWL_ListBox::GetItemStates(FWL_HLISTITEM hItem) { 186 FX_DWORD CFWL_ListBox::GetItemStates(FWL_HLISTITEM hItem) {
190 if (!hItem) 187 if (!hItem)
191 return 0; 188 return 0;
192 CFWL_ListItem* pItem = reinterpret_cast<CFWL_ListItem*>(hItem); 189 CFWL_ListItem* pItem = reinterpret_cast<CFWL_ListItem*>(hItem);
193 return pItem->m_dwStates | pItem->m_dwCheckState; 190 return pItem->m_dwStates | pItem->m_dwCheckState;
194 } 191 }
195 CFWL_ListBox::CFWL_ListBox() {} 192 CFWL_ListBox::CFWL_ListBox() {}
196 CFWL_ListBox::~CFWL_ListBox() {} 193 CFWL_ListBox::~CFWL_ListBox() {}
197 CFWL_ListBox::CFWL_ListBoxDP::CFWL_ListBoxDP() {} 194 CFWL_ListBox::CFWL_ListBoxDP::CFWL_ListBoxDP() {}
198 CFWL_ListBox::CFWL_ListBoxDP::~CFWL_ListBoxDP() { 195 CFWL_ListBox::CFWL_ListBoxDP::~CFWL_ListBoxDP() {}
199 int32_t nCount = m_arrItem.GetSize();
200 for (int32_t i = 0; i < nCount; i++) {
201 delete static_cast<CFWL_ListItem*>(m_arrItem[i]);
202 }
203 m_arrItem.RemoveAll();
204 }
205 FWL_ERR CFWL_ListBox::CFWL_ListBoxDP::GetCaption(IFWL_Widget* pWidget, 196 FWL_ERR CFWL_ListBox::CFWL_ListBoxDP::GetCaption(IFWL_Widget* pWidget,
206 CFX_WideString& wsCaption) { 197 CFX_WideString& wsCaption) {
207 wsCaption = m_wsData; 198 wsCaption = m_wsData;
208 return FWL_ERR_Succeeded; 199 return FWL_ERR_Succeeded;
209 } 200 }
210 int32_t CFWL_ListBox::CFWL_ListBoxDP::CountItems(IFWL_Widget* pWidget) { 201 int32_t CFWL_ListBox::CFWL_ListBoxDP::CountItems(IFWL_Widget* pWidget) {
211 return m_arrItem.GetSize(); 202 return pdfium::CollectionSize<int32_t>(m_ItemArray);
212 } 203 }
213 FWL_HLISTITEM CFWL_ListBox::CFWL_ListBoxDP::GetItem(IFWL_Widget* pWidget, 204 FWL_HLISTITEM CFWL_ListBox::CFWL_ListBoxDP::GetItem(IFWL_Widget* pWidget,
214 int32_t nIndex) { 205 int32_t nIndex) {
215 if (nIndex >= m_arrItem.GetSize() || nIndex < 0) { 206 if (nIndex < 0 || nIndex >= CountItems(pWidget))
216 return NULL; 207 return nullptr;
217 } else { 208
218 return (FWL_HLISTITEM)m_arrItem[nIndex]; 209 return (FWL_HLISTITEM)m_ItemArray[nIndex].get();
219 }
220 } 210 }
221 int32_t CFWL_ListBox::CFWL_ListBoxDP::GetItemIndex(IFWL_Widget* pWidget, 211 int32_t CFWL_ListBox::CFWL_ListBoxDP::GetItemIndex(IFWL_Widget* pWidget,
222 FWL_HLISTITEM hItem) { 212 FWL_HLISTITEM hItem) {
223 return m_arrItem.Find(hItem); 213 auto it = std::find_if(
214 m_ItemArray.begin(), m_ItemArray.end(),
215 [hItem](const std::unique_ptr<CFWL_ListItem>& candidate) {
216 return candidate.get() == reinterpret_cast<CFWL_ListItem*>(hItem);
217 });
218 return it != m_ItemArray.end() ? it - m_ItemArray.begin() : -1;
224 } 219 }
225 FX_BOOL CFWL_ListBox::CFWL_ListBoxDP::SetItemIndex(IFWL_Widget* pWidget, 220 FX_BOOL CFWL_ListBox::CFWL_ListBoxDP::SetItemIndex(IFWL_Widget* pWidget,
226 FWL_HLISTITEM hItem, 221 FWL_HLISTITEM hItem,
227 int32_t nIndex) { 222 int32_t nIndex) {
228 return m_arrItem.SetAt(nIndex, hItem); 223 if (nIndex < 0 || nIndex >= CountItems(pWidget))
224 return FALSE;
225 m_ItemArray[nIndex].reset(reinterpret_cast<CFWL_ListItem*>(hItem));
226 return TRUE;
229 } 227 }
230 FX_DWORD CFWL_ListBox::CFWL_ListBoxDP::GetItemStyles(IFWL_Widget* pWidget, 228 FX_DWORD CFWL_ListBox::CFWL_ListBoxDP::GetItemStyles(IFWL_Widget* pWidget,
231 FWL_HLISTITEM hItem) { 229 FWL_HLISTITEM hItem) {
232 if (!hItem) 230 if (!hItem)
233 return -1; 231 return -1;
234 return reinterpret_cast<CFWL_ListItem*>(hItem)->m_dwStates; 232 return reinterpret_cast<CFWL_ListItem*>(hItem)->m_dwStates;
235 } 233 }
236 FWL_ERR CFWL_ListBox::CFWL_ListBoxDP::GetItemText(IFWL_Widget* pWidget, 234 FWL_ERR CFWL_ListBox::CFWL_ListBoxDP::GetItemText(IFWL_Widget* pWidget,
237 FWL_HLISTITEM hItem, 235 FWL_HLISTITEM hItem,
238 CFX_WideString& wsText) { 236 CFX_WideString& wsText) {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 FX_DWORD CFWL_ListBox::CFWL_ListBoxDP::GetItemCheckState(IFWL_Widget* pWidget, 302 FX_DWORD CFWL_ListBox::CFWL_ListBoxDP::GetItemCheckState(IFWL_Widget* pWidget,
305 FWL_HLISTITEM hItem) { 303 FWL_HLISTITEM hItem) {
306 return reinterpret_cast<CFWL_ListItem*>(hItem)->m_dwCheckState; 304 return reinterpret_cast<CFWL_ListItem*>(hItem)->m_dwCheckState;
307 } 305 }
308 FWL_ERR CFWL_ListBox::CFWL_ListBoxDP::SetItemCheckState(IFWL_Widget* pWidget, 306 FWL_ERR CFWL_ListBox::CFWL_ListBoxDP::SetItemCheckState(IFWL_Widget* pWidget,
309 FWL_HLISTITEM hItem, 307 FWL_HLISTITEM hItem,
310 FX_DWORD dwCheckState) { 308 FX_DWORD dwCheckState) {
311 reinterpret_cast<CFWL_ListItem*>(hItem)->m_dwCheckState = dwCheckState; 309 reinterpret_cast<CFWL_ListItem*>(hItem)->m_dwCheckState = dwCheckState;
312 return FWL_ERR_Succeeded; 310 return FWL_ERR_Succeeded;
313 } 311 }
OLDNEW
« no previous file with comments | « xfa/include/fwl/theme/widgettp.h ('k') | xfa/src/fwl/src/lightwidget/theme.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698