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

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

Issue 1803723002: Move xfa/src up to xfa/. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Rebase to master Created 4 years, 9 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/src/fwl/lightwidget/edit.cpp ('k') | xfa/src/fwl/lightwidget/picturebox.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7 #include "xfa/include/fwl/lightwidget/listbox.h"
8
9 #include <memory>
10
11 #include "third_party/base/stl_util.h"
12
13 CFWL_ListBox* CFWL_ListBox::Create() {
14 return new CFWL_ListBox;
15 }
16 FWL_ERR CFWL_ListBox::Initialize(const CFWL_WidgetProperties* pProperties) {
17 if (m_pIface)
18 return FWL_ERR_Indefinite;
19 if (pProperties) {
20 *m_pProperties = *pProperties;
21 }
22 std::unique_ptr<IFWL_ListBox> pListBox(IFWL_ListBox::Create(
23 m_pProperties->MakeWidgetImpProperties(&m_ListBoxDP), nullptr));
24 FWL_ERR ret = pListBox->Initialize();
25 if (ret != FWL_ERR_Succeeded) {
26 return ret;
27 }
28 m_pIface = pListBox.release();
29 CFWL_Widget::Initialize();
30 return FWL_ERR_Succeeded;
31 }
32 FWL_ERR CFWL_ListBox::AddDIBitmap(CFX_DIBitmap* pDIB, FWL_HLISTITEM hItem) {
33 reinterpret_cast<CFWL_ListItem*>(hItem)->m_pDIB = pDIB;
34 return FWL_ERR_Succeeded;
35 }
36 FWL_HLISTITEM CFWL_ListBox::AddString(const CFX_WideStringC& wsAdd,
37 FX_BOOL bSelect) {
38 std::unique_ptr<CFWL_ListItem> pItem(new CFWL_ListItem);
39 pItem->m_dwStates = 0;
40 pItem->m_wsText = wsAdd;
41 pItem->m_dwStates = bSelect ? FWL_ITEMSTATE_LTB_Selected : 0;
42 m_ListBoxDP.m_ItemArray.push_back(std::move(pItem));
43 return (FWL_HLISTITEM)m_ListBoxDP.m_ItemArray.back().get();
44 }
45 FX_BOOL CFWL_ListBox::DeleteString(FWL_HLISTITEM hItem) {
46 int32_t nIndex = m_ListBoxDP.GetItemIndex(GetWidget(), hItem);
47 if (nIndex < 0 ||
48 static_cast<size_t>(nIndex) >= m_ListBoxDP.m_ItemArray.size()) {
49 return FALSE;
50 }
51 int32_t iCount = m_ListBoxDP.CountItems(m_pIface);
52 int32_t iSel = nIndex + 1;
53 if (iSel >= iCount) {
54 iSel = nIndex - 1;
55 if (iSel < 0) {
56 iSel = -1;
57 }
58 }
59 if (iSel >= 0) {
60 CFWL_ListItem* pSel =
61 reinterpret_cast<CFWL_ListItem*>(m_ListBoxDP.GetItem(m_pIface, iSel));
62 pSel->m_dwStates |= FWL_ITEMSTATE_LTB_Selected;
63 }
64 m_ListBoxDP.m_ItemArray.erase(m_ListBoxDP.m_ItemArray.begin() + nIndex);
65 return TRUE;
66 }
67 void CFWL_ListBox::DeleteAll() {
68 m_ListBoxDP.m_ItemArray.clear();
69 }
70 int32_t CFWL_ListBox::CountSelItems() {
71 if (!m_pIface)
72 return 0;
73 return static_cast<IFWL_ListBox*>(m_pIface)->CountSelItems();
74 }
75 FWL_HLISTITEM CFWL_ListBox::GetSelItem(int32_t nIndexSel) {
76 if (!m_pIface)
77 return NULL;
78 return static_cast<IFWL_ListBox*>(m_pIface)->GetSelItem(nIndexSel);
79 }
80 int32_t CFWL_ListBox::GetSelIndex(int32_t nIndex) {
81 if (!m_pIface)
82 return 0;
83 return static_cast<IFWL_ListBox*>(m_pIface)->GetSelIndex(nIndex);
84 }
85 FWL_ERR CFWL_ListBox::SetSelItem(FWL_HLISTITEM hItem, FX_BOOL bSelect) {
86 if (!m_pIface)
87 return FWL_ERR_Indefinite;
88 return static_cast<IFWL_ListBox*>(m_pIface)->SetSelItem(hItem, bSelect);
89 }
90 FWL_ERR CFWL_ListBox::GetItemText(FWL_HLISTITEM hItem, CFX_WideString& wsText) {
91 if (!m_pIface)
92 return FWL_ERR_Indefinite;
93 return static_cast<IFWL_ListBox*>(m_pIface)->GetItemText(hItem, wsText);
94 }
95 FWL_ERR CFWL_ListBox::GetScrollPos(FX_FLOAT& fPos, FX_BOOL bVert) {
96 if (!m_pIface)
97 return FWL_ERR_Indefinite;
98 return static_cast<IFWL_ListBox*>(m_pIface)->GetScrollPos(fPos, bVert);
99 }
100 FWL_ERR CFWL_ListBox::SetItemHeight(FX_FLOAT fItemHeight) {
101 m_ListBoxDP.m_fItemHeight = fItemHeight;
102 return FWL_ERR_Succeeded;
103 }
104 FWL_HLISTITEM CFWL_ListBox::GetFocusItem() {
105 for (const auto& hItem : m_ListBoxDP.m_ItemArray) {
106 if (hItem->m_dwStates & FWL_ITEMSTATE_LTB_Focused)
107 return (FWL_HLISTITEM)hItem.get();
108 }
109 return nullptr;
110 }
111 FWL_ERR CFWL_ListBox::SetFocusItem(FWL_HLISTITEM hItem) {
112 int32_t nIndex = m_ListBoxDP.GetItemIndex(GetWidget(), hItem);
113 m_ListBoxDP.m_ItemArray[nIndex]->m_dwStates |= FWL_ITEMSTATE_LTB_Focused;
114 return FWL_ERR_Succeeded;
115 }
116 FWL_ERR* CFWL_ListBox::Sort(IFWL_ListBoxCompare* pCom) {
117 return static_cast<IFWL_ListBox*>(m_pIface)->Sort(pCom);
118 }
119 int32_t CFWL_ListBox::CountItems() {
120 return pdfium::CollectionSize<int32_t>(m_ListBoxDP.m_ItemArray);
121 }
122 FWL_HLISTITEM CFWL_ListBox::GetItem(int32_t nIndex) {
123 if (nIndex < 0 || nIndex >= CountItems())
124 return nullptr;
125
126 return (FWL_HLISTITEM)m_ListBoxDP.m_ItemArray[nIndex].get();
127 }
128 FWL_ERR CFWL_ListBox::SetItemString(FWL_HLISTITEM hItem,
129 const CFX_WideStringC& wsText) {
130 if (!hItem)
131 return FWL_ERR_Indefinite;
132 reinterpret_cast<CFWL_ListItem*>(hItem)->m_wsText = wsText;
133 return FWL_ERR_Succeeded;
134 }
135 FWL_ERR CFWL_ListBox::GetItemString(FWL_HLISTITEM hItem,
136 CFX_WideString& wsText) {
137 if (!hItem)
138 return FWL_ERR_Indefinite;
139 wsText = reinterpret_cast<CFWL_ListItem*>(hItem)->m_wsText;
140 return FWL_ERR_Succeeded;
141 }
142 FWL_ERR CFWL_ListBox::SetItemData(FWL_HLISTITEM hItem, void* pData) {
143 if (!hItem)
144 return FWL_ERR_Indefinite;
145 reinterpret_cast<CFWL_ListItem*>(hItem)->m_pData = pData;
146 return FWL_ERR_Succeeded;
147 }
148 void* CFWL_ListBox::GetItemData(FWL_HLISTITEM hItem) {
149 if (!hItem)
150 return NULL;
151 return reinterpret_cast<CFWL_ListItem*>(hItem)->m_pData;
152 }
153 FWL_HLISTITEM CFWL_ListBox::GetItemAtPoint(FX_FLOAT fx, FX_FLOAT fy) {
154 CFX_RectF rtClient;
155 m_pIface->GetClientRect(rtClient);
156 fx -= rtClient.left;
157 fy -= rtClient.top;
158 FX_FLOAT fPosX = 0;
159 FX_FLOAT fPosY = 0;
160 static_cast<IFWL_ListBox*>(m_pIface)->GetScrollPos(fx);
161 static_cast<IFWL_ListBox*>(m_pIface)->GetScrollPos(fy, FALSE);
162 int32_t nCount = m_ListBoxDP.CountItems(NULL);
163 for (int32_t i = 0; i < nCount; i++) {
164 FWL_HLISTITEM hItem = m_ListBoxDP.GetItem(NULL, i);
165 if (!hItem) {
166 continue;
167 }
168 CFX_RectF rtItem;
169 m_ListBoxDP.GetItemRect(NULL, hItem, rtItem);
170 rtItem.Offset(-fPosX, -fPosY);
171 if (rtItem.Contains(fx, fy)) {
172 return hItem;
173 }
174 }
175 return NULL;
176 }
177 FX_DWORD CFWL_ListBox::GetItemStates(FWL_HLISTITEM hItem) {
178 if (!hItem)
179 return 0;
180 CFWL_ListItem* pItem = reinterpret_cast<CFWL_ListItem*>(hItem);
181 return pItem->m_dwStates | pItem->m_dwCheckState;
182 }
183 CFWL_ListBox::CFWL_ListBox() {}
184 CFWL_ListBox::~CFWL_ListBox() {}
185 CFWL_ListBox::CFWL_ListBoxDP::CFWL_ListBoxDP() {}
186 CFWL_ListBox::CFWL_ListBoxDP::~CFWL_ListBoxDP() {}
187 FWL_ERR CFWL_ListBox::CFWL_ListBoxDP::GetCaption(IFWL_Widget* pWidget,
188 CFX_WideString& wsCaption) {
189 wsCaption = m_wsData;
190 return FWL_ERR_Succeeded;
191 }
192 int32_t CFWL_ListBox::CFWL_ListBoxDP::CountItems(IFWL_Widget* pWidget) {
193 return pdfium::CollectionSize<int32_t>(m_ItemArray);
194 }
195 FWL_HLISTITEM CFWL_ListBox::CFWL_ListBoxDP::GetItem(IFWL_Widget* pWidget,
196 int32_t nIndex) {
197 if (nIndex < 0 || nIndex >= CountItems(pWidget))
198 return nullptr;
199
200 return (FWL_HLISTITEM)m_ItemArray[nIndex].get();
201 }
202 int32_t CFWL_ListBox::CFWL_ListBoxDP::GetItemIndex(IFWL_Widget* pWidget,
203 FWL_HLISTITEM hItem) {
204 auto it = std::find_if(
205 m_ItemArray.begin(), m_ItemArray.end(),
206 [hItem](const std::unique_ptr<CFWL_ListItem>& candidate) {
207 return candidate.get() == reinterpret_cast<CFWL_ListItem*>(hItem);
208 });
209 return it != m_ItemArray.end() ? it - m_ItemArray.begin() : -1;
210 }
211 FX_BOOL CFWL_ListBox::CFWL_ListBoxDP::SetItemIndex(IFWL_Widget* pWidget,
212 FWL_HLISTITEM hItem,
213 int32_t nIndex) {
214 if (nIndex < 0 || nIndex >= CountItems(pWidget))
215 return FALSE;
216 m_ItemArray[nIndex].reset(reinterpret_cast<CFWL_ListItem*>(hItem));
217 return TRUE;
218 }
219 FX_DWORD CFWL_ListBox::CFWL_ListBoxDP::GetItemStyles(IFWL_Widget* pWidget,
220 FWL_HLISTITEM hItem) {
221 if (!hItem)
222 return -1;
223 return reinterpret_cast<CFWL_ListItem*>(hItem)->m_dwStates;
224 }
225 FWL_ERR CFWL_ListBox::CFWL_ListBoxDP::GetItemText(IFWL_Widget* pWidget,
226 FWL_HLISTITEM hItem,
227 CFX_WideString& wsText) {
228 if (!hItem)
229 return FWL_ERR_Indefinite;
230 wsText = reinterpret_cast<CFWL_ListItem*>(hItem)->m_wsText;
231 return FWL_ERR_Succeeded;
232 }
233 FWL_ERR CFWL_ListBox::CFWL_ListBoxDP::GetItemRect(IFWL_Widget* pWidget,
234 FWL_HLISTITEM hItem,
235 CFX_RectF& rtItem) {
236 if (!hItem)
237 return FWL_ERR_Indefinite;
238 CFWL_ListItem* pItem = reinterpret_cast<CFWL_ListItem*>(hItem);
239 rtItem = pItem->m_rtItem;
240 return FWL_ERR_Succeeded;
241 }
242 void* CFWL_ListBox::CFWL_ListBoxDP::GetItemData(IFWL_Widget* pWidget,
243 FWL_HLISTITEM hItem) {
244 if (!hItem)
245 return NULL;
246 CFWL_ListItem* pItem = reinterpret_cast<CFWL_ListItem*>(hItem);
247 return pItem->m_pData;
248 }
249 FWL_ERR CFWL_ListBox::CFWL_ListBoxDP::SetItemStyles(IFWL_Widget* pWidget,
250 FWL_HLISTITEM hItem,
251 FX_DWORD dwStyle) {
252 if (!hItem)
253 return FWL_ERR_Indefinite;
254 reinterpret_cast<CFWL_ListItem*>(hItem)->m_dwStates = dwStyle;
255 return FWL_ERR_Succeeded;
256 }
257 FWL_ERR CFWL_ListBox::CFWL_ListBoxDP::SetItemText(IFWL_Widget* pWidget,
258 FWL_HLISTITEM hItem,
259 const FX_WCHAR* pszText) {
260 if (!hItem)
261 return FWL_ERR_Indefinite;
262 reinterpret_cast<CFWL_ListItem*>(hItem)->m_wsText = pszText;
263 return FWL_ERR_Succeeded;
264 }
265 FWL_ERR CFWL_ListBox::CFWL_ListBoxDP::SetItemRect(IFWL_Widget* pWidget,
266 FWL_HLISTITEM hItem,
267 const CFX_RectF& rtItem) {
268 if (!hItem)
269 return FWL_ERR_Indefinite;
270 reinterpret_cast<CFWL_ListItem*>(hItem)->m_rtItem = rtItem;
271 return FWL_ERR_Succeeded;
272 }
273 FX_FLOAT CFWL_ListBox::CFWL_ListBoxDP::GetItemHeight(IFWL_Widget* pWidget) {
274 return m_fItemHeight;
275 }
276 CFX_DIBitmap* CFWL_ListBox::CFWL_ListBoxDP::GetItemIcon(IFWL_Widget* pWidget,
277 FWL_HLISTITEM hItem) {
278 return reinterpret_cast<CFWL_ListItem*>(hItem)->m_pDIB;
279 }
280 FWL_ERR CFWL_ListBox::CFWL_ListBoxDP::GetItemCheckRect(IFWL_Widget* pWidget,
281 FWL_HLISTITEM hItem,
282 CFX_RectF& rtCheck) {
283 rtCheck = reinterpret_cast<CFWL_ListItem*>(hItem)->m_rtCheckBox;
284 return FWL_ERR_Succeeded;
285 }
286 FWL_ERR CFWL_ListBox::CFWL_ListBoxDP::SetItemCheckRect(
287 IFWL_Widget* pWidget,
288 FWL_HLISTITEM hItem,
289 const CFX_RectF& rtCheck) {
290 reinterpret_cast<CFWL_ListItem*>(hItem)->m_rtCheckBox = rtCheck;
291 return FWL_ERR_Succeeded;
292 }
293 FX_DWORD CFWL_ListBox::CFWL_ListBoxDP::GetItemCheckState(IFWL_Widget* pWidget,
294 FWL_HLISTITEM hItem) {
295 return reinterpret_cast<CFWL_ListItem*>(hItem)->m_dwCheckState;
296 }
297 FWL_ERR CFWL_ListBox::CFWL_ListBoxDP::SetItemCheckState(IFWL_Widget* pWidget,
298 FWL_HLISTITEM hItem,
299 FX_DWORD dwCheckState) {
300 reinterpret_cast<CFWL_ListItem*>(hItem)->m_dwCheckState = dwCheckState;
301 return FWL_ERR_Succeeded;
302 }
OLDNEW
« no previous file with comments | « xfa/src/fwl/lightwidget/edit.cpp ('k') | xfa/src/fwl/lightwidget/picturebox.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698