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

Side by Side Diff: xfa/fwl/core/cfwl_listbox.cpp

Issue 2505703003: Cleaning up nits in fwl/core files. (Closed)
Patch Set: Created 4 years, 1 month 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
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 "xfa/fwl/core/cfwl_listbox.h" 7 #include "xfa/fwl/core/cfwl_listbox.h"
8 8
9 #include <memory> 9 #include <memory>
10 10
(...skipping 26 matching lines...) Expand all
37 std::unique_ptr<CFWL_ListItem> pItem(new CFWL_ListItem); 37 std::unique_ptr<CFWL_ListItem> pItem(new CFWL_ListItem);
38 pItem->m_dwStates = 0; 38 pItem->m_dwStates = 0;
39 pItem->m_wsText = wsAdd; 39 pItem->m_wsText = wsAdd;
40 pItem->m_dwStates = bSelect ? FWL_ITEMSTATE_LTB_Selected : 0; 40 pItem->m_dwStates = bSelect ? FWL_ITEMSTATE_LTB_Selected : 0;
41 m_ItemArray.push_back(std::move(pItem)); 41 m_ItemArray.push_back(std::move(pItem));
42 return m_ItemArray.back().get(); 42 return m_ItemArray.back().get();
43 } 43 }
44 44
45 bool CFWL_ListBox::DeleteString(CFWL_ListItem* pItem) { 45 bool CFWL_ListBox::DeleteString(CFWL_ListItem* pItem) {
46 int32_t nIndex = GetItemIndex(GetWidget(), pItem); 46 int32_t nIndex = GetItemIndex(GetWidget(), pItem);
47 if (nIndex < 0 || static_cast<size_t>(nIndex) >= m_ItemArray.size()) { 47 if (nIndex < 0 || static_cast<size_t>(nIndex) >= m_ItemArray.size())
48 return false; 48 return false;
49 } 49
50 int32_t iCount = CountItems(m_pIface.get()); 50 int32_t iCount = CountItems(m_pIface.get());
51 int32_t iSel = nIndex + 1; 51 int32_t iSel = nIndex + 1;
52 if (iSel >= iCount) { 52 if (iSel >= iCount) {
npm 2016/11/15 21:38:30 nit: remove iCount, directly call CountItems(m_pIf
dsinclair 2016/11/15 21:44:06 Followup.
53 iSel = nIndex - 1; 53 iSel = nIndex - 1;
54 if (iSel < 0) { 54 if (iSel < 0)
55 iSel = -1; 55 iSel = -1;
56 }
57 } 56 }
58 if (iSel >= 0) { 57 if (iSel >= 0) {
59 CFWL_ListItem* pSel = 58 CFWL_ListItem* pSel =
60 static_cast<CFWL_ListItem*>(GetItem(m_pIface.get(), iSel)); 59 static_cast<CFWL_ListItem*>(GetItem(m_pIface.get(), iSel));
61 pSel->m_dwStates |= FWL_ITEMSTATE_LTB_Selected; 60 pSel->m_dwStates |= FWL_ITEMSTATE_LTB_Selected;
62 } 61 }
63 m_ItemArray.erase(m_ItemArray.begin() + nIndex); 62 m_ItemArray.erase(m_ItemArray.begin() + nIndex);
64 return true; 63 return true;
65 } 64 }
66 65
67 void CFWL_ListBox::DeleteAll() { 66 void CFWL_ListBox::DeleteAll() {
68 m_ItemArray.clear(); 67 m_ItemArray.clear();
69 } 68 }
70 69
71 int32_t CFWL_ListBox::CountSelItems() { 70 int32_t CFWL_ListBox::CountSelItems() {
72 return GetWidget() ? ToListBox(GetWidget())->CountSelItems() : 0; 71 return GetWidget() ? ToListBox(GetWidget())->CountSelItems() : 0;
73 } 72 }
74 73
75 CFWL_ListItem* CFWL_ListBox::GetSelItem(int32_t nIndexSel) { 74 CFWL_ListItem* CFWL_ListBox::GetSelItem(int32_t nIndexSel) {
76 return GetWidget() ? ToListBox(GetWidget())->GetSelItem(nIndexSel) : nullptr; 75 return GetWidget() ? ToListBox(GetWidget())->GetSelItem(nIndexSel) : nullptr;
77 } 76 }
78 77
79 int32_t CFWL_ListBox::GetSelIndex(int32_t nIndex) { 78 int32_t CFWL_ListBox::GetSelIndex(int32_t nIndex) {
80 if (!GetWidget()) 79 return GetWidget() ? ToListBox(GetWidget())->GetSelIndex(nIndex) : 0;
81 return 0;
82 return ToListBox(GetWidget())->GetSelIndex(nIndex);
83 } 80 }
84 81
85 void CFWL_ListBox::SetSelItem(CFWL_ListItem* pItem, bool bSelect) { 82 void CFWL_ListBox::SetSelItem(CFWL_ListItem* pItem, bool bSelect) {
86 if (GetWidget()) 83 if (GetWidget())
87 ToListBox(GetWidget())->SetSelItem(pItem, bSelect); 84 ToListBox(GetWidget())->SetSelItem(pItem, bSelect);
88 } 85 }
89 86
90 void CFWL_ListBox::GetItemText(CFWL_ListItem* pItem, CFX_WideString& wsText) { 87 void CFWL_ListBox::GetItemText(CFWL_ListItem* pItem, CFX_WideString& wsText) {
91 if (GetWidget()) 88 if (GetWidget())
92 ToListBox(GetWidget())->GetItemText(pItem, wsText); 89 ToListBox(GetWidget())->GetItemText(pItem, wsText);
93 } 90 }
94 91
95 CFWL_ListItem* CFWL_ListBox::GetItem(int32_t nIndex) { 92 CFWL_ListItem* CFWL_ListBox::GetItem(int32_t nIndex) {
96 if (nIndex < 0 || nIndex >= CountItems(nullptr)) 93 if (nIndex < 0 || nIndex >= CountItems(nullptr))
97 return nullptr; 94 return nullptr;
98
99 return m_ItemArray[nIndex].get(); 95 return m_ItemArray[nIndex].get();
100 } 96 }
101 97
102 uint32_t CFWL_ListBox::GetItemStates(CFWL_ListItem* pItem) { 98 uint32_t CFWL_ListBox::GetItemStates(CFWL_ListItem* pItem) {
103 if (!pItem) 99 if (!pItem)
104 return 0; 100 return 0;
105 CFWL_ListItem* pListItem = static_cast<CFWL_ListItem*>(pItem); 101 return pItem->m_dwStates | pItem->m_dwCheckState;
106 return pListItem->m_dwStates | pListItem->m_dwCheckState;
107 } 102 }
108 103
109 void CFWL_ListBox::GetCaption(IFWL_Widget* pWidget, CFX_WideString& wsCaption) { 104 void CFWL_ListBox::GetCaption(IFWL_Widget* pWidget, CFX_WideString& wsCaption) {
npm 2016/11/15 21:38:30 Similarly here, pWidget is not used in most of the
dsinclair 2016/11/15 21:44:06 Acknowledged.
110 wsCaption = L""; 105 wsCaption = L"";
111 } 106 }
112 107
113 int32_t CFWL_ListBox::CountItems(const IFWL_Widget* pWidget) const { 108 int32_t CFWL_ListBox::CountItems(const IFWL_Widget* pWidget) const {
114 return pdfium::CollectionSize<int32_t>(m_ItemArray); 109 return pdfium::CollectionSize<int32_t>(m_ItemArray);
115 } 110 }
116 111
117 CFWL_ListItem* CFWL_ListBox::GetItem(const IFWL_Widget* pWidget, 112 CFWL_ListItem* CFWL_ListBox::GetItem(const IFWL_Widget* pWidget,
118 int32_t nIndex) const { 113 int32_t nIndex) const {
119 if (nIndex < 0 || nIndex >= CountItems(pWidget)) 114 if (nIndex < 0 || nIndex >= CountItems(pWidget))
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 uint32_t CFWL_ListBox::GetItemCheckState(IFWL_Widget* pWidget, 182 uint32_t CFWL_ListBox::GetItemCheckState(IFWL_Widget* pWidget,
188 CFWL_ListItem* pItem) { 183 CFWL_ListItem* pItem) {
189 return static_cast<CFWL_ListItem*>(pItem)->m_dwCheckState; 184 return static_cast<CFWL_ListItem*>(pItem)->m_dwCheckState;
190 } 185 }
191 186
192 void CFWL_ListBox::SetItemCheckState(IFWL_Widget* pWidget, 187 void CFWL_ListBox::SetItemCheckState(IFWL_Widget* pWidget,
193 CFWL_ListItem* pItem, 188 CFWL_ListItem* pItem,
194 uint32_t dwCheckState) { 189 uint32_t dwCheckState) {
195 static_cast<CFWL_ListItem*>(pItem)->m_dwCheckState = dwCheckState; 190 static_cast<CFWL_ListItem*>(pItem)->m_dwCheckState = dwCheckState;
196 } 191 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698