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

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

Issue 1669313002: Remove CFX_PtrArray from xfa's combobox.h. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Meh, map and memory are both m-words. 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/lightwidget/combobox.h ('k') | no next file » | 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 <utility>
8 8
9 #include "xfa/src/foxitlib.h" 9 #include "xfa/src/foxitlib.h"
10 10
11 CFWL_ComboBox* CFWL_ComboBox::Create() { 11 CFWL_ComboBox* CFWL_ComboBox::Create() {
12 return new CFWL_ComboBox; 12 return new CFWL_ComboBox;
13 } 13 }
14 FWL_ERR CFWL_ComboBox::Initialize(const CFWL_WidgetProperties* pProperties) { 14 FWL_ERR CFWL_ComboBox::Initialize(const CFWL_WidgetProperties* pProperties) {
15 if (m_pIface) 15 if (m_pIface)
16 return FWL_ERR_Indefinite; 16 return FWL_ERR_Indefinite;
17 if (pProperties) { 17 if (pProperties) {
18 *m_pProperties = *pProperties; 18 *m_pProperties = *pProperties;
19 } 19 }
20 std::unique_ptr<IFWL_ComboBox> pComboBox(IFWL_ComboBox::Create( 20 std::unique_ptr<IFWL_ComboBox> pComboBox(IFWL_ComboBox::Create(
21 m_pProperties->MakeWidgetImpProperties(&m_comboBoxData))); 21 m_pProperties->MakeWidgetImpProperties(&m_comboBoxData)));
22 FWL_ERR ret = pComboBox->Initialize(); 22 FWL_ERR ret = pComboBox->Initialize();
23 if (ret != FWL_ERR_Succeeded) { 23 if (ret != FWL_ERR_Succeeded) {
24 return ret; 24 return ret;
25 } 25 }
26 m_pIface = pComboBox.release(); 26 m_pIface = pComboBox.release();
27 CFWL_Widget::Initialize(); 27 CFWL_Widget::Initialize();
28 return FWL_ERR_Succeeded; 28 return FWL_ERR_Succeeded;
29 } 29 }
30 int32_t CFWL_ComboBox::AddString(const CFX_WideStringC& wsText) { 30 int32_t CFWL_ComboBox::AddString(const CFX_WideStringC& wsText) {
31 CFWL_ComboBoxItem* pItem = new CFWL_ComboBoxItem; 31 std::unique_ptr<CFWL_ComboBoxItem> pItem(new CFWL_ComboBoxItem);
32 pItem->m_wsText = wsText; 32 pItem->m_wsText = wsText;
33 pItem->m_dwStyles = 0; 33 pItem->m_dwStyles = 0;
34 return m_comboBoxData.m_arrItem.Add(pItem); 34 m_comboBoxData.m_ItemArray.push_back(std::move(pItem));
35 return m_comboBoxData.m_ItemArray.size() - 1;
35 } 36 }
36 int32_t CFWL_ComboBox::AddString(const CFX_WideStringC& wsText, 37 int32_t CFWL_ComboBox::AddString(const CFX_WideStringC& wsText,
37 CFX_DIBitmap* pIcon) { 38 CFX_DIBitmap* pIcon) {
38 CFWL_ComboBoxItem* pItem = new CFWL_ComboBoxItem; 39 std::unique_ptr<CFWL_ComboBoxItem> pItem(new CFWL_ComboBoxItem);
39 pItem->m_wsText = wsText; 40 pItem->m_wsText = wsText;
40 pItem->m_dwStyles = 0; 41 pItem->m_dwStyles = 0;
41 pItem->m_pDIB = pIcon; 42 pItem->m_pDIB = pIcon;
42 return m_comboBoxData.m_arrItem.Add(pItem); 43 m_comboBoxData.m_ItemArray.push_back(std::move(pItem));
44 return m_comboBoxData.m_ItemArray.size() - 1;
43 } 45 }
44 int32_t CFWL_ComboBox::RemoveAt(int32_t iIndex) { 46 bool CFWL_ComboBox::RemoveAt(int32_t iIndex) {
45 return m_comboBoxData.m_arrItem.RemoveAt(iIndex); 47 if (iIndex < 0 || iIndex >= m_comboBoxData.m_ItemArray.size())
48 return false;
49
50 m_comboBoxData.m_ItemArray.erase(m_comboBoxData.m_ItemArray.begin() + iIndex);
51 return true;
46 } 52 }
47 int32_t CFWL_ComboBox::RemoveAll() { 53 void CFWL_ComboBox::RemoveAll() {
48 m_comboBoxData.m_arrItem.RemoveAll(); 54 m_comboBoxData.m_ItemArray.clear();
49 return 0;
50 } 55 }
51 int32_t CFWL_ComboBox::CountItems() { 56 int32_t CFWL_ComboBox::CountItems() {
52 return m_comboBoxData.CountItems(GetWidget()); 57 return m_comboBoxData.CountItems(GetWidget());
53 } 58 }
54 FWL_ERR CFWL_ComboBox::GetTextByIndex(int32_t iIndex, CFX_WideString& wsText) { 59 FWL_ERR CFWL_ComboBox::GetTextByIndex(int32_t iIndex, CFX_WideString& wsText) {
55 CFWL_ComboBoxItem* pItem = reinterpret_cast<CFWL_ComboBoxItem*>( 60 CFWL_ComboBoxItem* pItem = reinterpret_cast<CFWL_ComboBoxItem*>(
56 m_comboBoxData.GetItem(m_pIface, iIndex)); 61 m_comboBoxData.GetItem(m_pIface, iIndex));
57 if (!pItem) 62 if (!pItem)
58 return FWL_ERR_Indefinite; 63 return FWL_ERR_Indefinite;
59 wsText = pItem->m_wsText; 64 wsText = pItem->m_wsText;
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 return FALSE; 232 return FALSE;
228 return static_cast<IFWL_ComboBox*>(m_pIface) 233 return static_cast<IFWL_ComboBox*>(m_pIface)
229 ->EditModifyStylesEx(dwStylesExAdded, dwStylesExRemoved); 234 ->EditModifyStylesEx(dwStylesExAdded, dwStylesExRemoved);
230 } 235 }
231 CFWL_ComboBox::CFWL_ComboBox() {} 236 CFWL_ComboBox::CFWL_ComboBox() {}
232 CFWL_ComboBox::~CFWL_ComboBox() {} 237 CFWL_ComboBox::~CFWL_ComboBox() {}
233 CFWL_ComboBox::CFWL_ComboBoxDP::CFWL_ComboBoxDP() { 238 CFWL_ComboBox::CFWL_ComboBoxDP::CFWL_ComboBoxDP() {
234 m_fItemHeight = 0; 239 m_fItemHeight = 0;
235 m_fMaxListHeight = 0; 240 m_fMaxListHeight = 0;
236 } 241 }
237 CFWL_ComboBox::CFWL_ComboBoxDP::~CFWL_ComboBoxDP() { 242 CFWL_ComboBox::CFWL_ComboBoxDP::~CFWL_ComboBoxDP() {}
238 int32_t nCount = m_arrItem.GetSize();
239 for (int32_t i = 0; i < nCount; i++) {
240 delete static_cast<CFWL_ComboBoxItem*>(m_arrItem[i]);
241 }
242 m_arrItem.RemoveAll();
243 }
244 int32_t CFWL_ComboBox::CFWL_ComboBoxDP::CountItems(IFWL_Widget* pWidget) { 243 int32_t CFWL_ComboBox::CFWL_ComboBoxDP::CountItems(IFWL_Widget* pWidget) {
245 return m_arrItem.GetSize(); 244 return m_ItemArray.size();
246 } 245 }
247 FWL_HLISTITEM CFWL_ComboBox::CFWL_ComboBoxDP::GetItem(IFWL_Widget* pWidget, 246 FWL_HLISTITEM CFWL_ComboBox::CFWL_ComboBoxDP::GetItem(IFWL_Widget* pWidget,
248 int32_t nIndex) { 247 int32_t nIndex) {
249 int32_t iCount = m_arrItem.GetSize(); 248 return nIndex >= 0 && nIndex < m_ItemArray.size()
250 if (nIndex >= iCount || nIndex < 0) { 249 ? reinterpret_cast<FWL_HLISTITEM>(m_ItemArray[nIndex].get())
251 return NULL; 250 : nullptr;
252 }
253 return (FWL_HLISTITEM)m_arrItem[nIndex];
254 } 251 }
255 int32_t CFWL_ComboBox::CFWL_ComboBoxDP::GetItemIndex(IFWL_Widget* pWidget, 252 int32_t CFWL_ComboBox::CFWL_ComboBoxDP::GetItemIndex(IFWL_Widget* pWidget,
256 FWL_HLISTITEM hItem) { 253 FWL_HLISTITEM hItem) {
257 return m_arrItem.Find(hItem); 254 auto it = std::find_if(
255 m_ItemArray.begin(), m_ItemArray.end(),
256 [hItem](const std::unique_ptr<CFWL_ComboBoxItem>& candidate) {
257 return candidate.get() == reinterpret_cast<CFWL_ComboBoxItem*>(hItem);
258 });
259 return it != m_ItemArray.end() ? it - m_ItemArray.begin() : -1;
258 } 260 }
259 FX_BOOL CFWL_ComboBox::CFWL_ComboBoxDP::SetItemIndex(IFWL_Widget* pWidget, 261 FX_BOOL CFWL_ComboBox::CFWL_ComboBoxDP::SetItemIndex(IFWL_Widget* pWidget,
260 FWL_HLISTITEM hItem, 262 FWL_HLISTITEM hItem,
261 int32_t nIndex) { 263 int32_t nIndex) {
262 return m_arrItem.SetAt(nIndex, hItem); 264 if (nIndex < 0 || nIndex >= m_ItemArray.size())
265 return FALSE;
266
267 m_ItemArray[nIndex].reset(reinterpret_cast<CFWL_ComboBoxItem*>(hItem));
268 return TRUE;
263 } 269 }
264 FX_DWORD CFWL_ComboBox::CFWL_ComboBoxDP::GetItemStyles(IFWL_Widget* pWidget, 270 FX_DWORD CFWL_ComboBox::CFWL_ComboBoxDP::GetItemStyles(IFWL_Widget* pWidget,
265 FWL_HLISTITEM hItem) { 271 FWL_HLISTITEM hItem) {
266 if (!hItem) 272 if (!hItem)
267 return 0; 273 return 0;
268 return reinterpret_cast<CFWL_ComboBoxItem*>(hItem)->m_dwStyles; 274 return reinterpret_cast<CFWL_ComboBoxItem*>(hItem)->m_dwStyles;
269 } 275 }
270 FWL_ERR CFWL_ComboBox::CFWL_ComboBoxDP::GetItemText(IFWL_Widget* pWidget, 276 FWL_ERR CFWL_ComboBox::CFWL_ComboBoxDP::GetItemText(IFWL_Widget* pWidget,
271 FWL_HLISTITEM hItem, 277 FWL_HLISTITEM hItem,
272 CFX_WideString& wsText) { 278 CFX_WideString& wsText) {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 IFWL_Widget* pWidget, 356 IFWL_Widget* pWidget,
351 FWL_HLISTITEM hItem, 357 FWL_HLISTITEM hItem,
352 FX_DWORD dwCheckState) { 358 FX_DWORD dwCheckState) {
353 CFWL_ComboBoxItem* pItem = reinterpret_cast<CFWL_ComboBoxItem*>(hItem); 359 CFWL_ComboBoxItem* pItem = reinterpret_cast<CFWL_ComboBoxItem*>(hItem);
354 pItem->m_dwCheckState = dwCheckState; 360 pItem->m_dwCheckState = dwCheckState;
355 return FWL_ERR_Succeeded; 361 return FWL_ERR_Succeeded;
356 } 362 }
357 FX_FLOAT CFWL_ComboBox::CFWL_ComboBoxDP::GetListHeight(IFWL_Widget* pWidget) { 363 FX_FLOAT CFWL_ComboBox::CFWL_ComboBoxDP::GetListHeight(IFWL_Widget* pWidget) {
358 return m_fMaxListHeight; 364 return m_fMaxListHeight;
359 } 365 }
OLDNEW
« no previous file with comments | « xfa/include/fwl/lightwidget/combobox.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698