OLD | NEW |
| (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/fwl/lightwidget/cfwl_combobox.h" | |
8 | |
9 #include <utility> | |
10 | |
11 #include "xfa/fwl/core/fwl_error.h" | |
12 #include "xfa/fwl/core/ifwl_widget.h" | |
13 | |
14 IFWL_ComboBox* CFWL_ComboBox::GetWidget() { | |
15 return static_cast<IFWL_ComboBox*>(m_pIface.get()); | |
16 } | |
17 | |
18 const IFWL_ComboBox* CFWL_ComboBox::GetWidget() const { | |
19 return static_cast<IFWL_ComboBox*>(m_pIface.get()); | |
20 } | |
21 | |
22 FWL_Error CFWL_ComboBox::Initialize(const CFWL_WidgetProperties* pProperties) { | |
23 if (m_pIface) | |
24 return FWL_Error::Indefinite; | |
25 if (pProperties) { | |
26 *m_pProperties = *pProperties; | |
27 } | |
28 std::unique_ptr<IFWL_ComboBox> pComboBox(new IFWL_ComboBox( | |
29 m_pProperties->MakeWidgetImpProperties(&m_comboBoxData))); | |
30 FWL_Error ret = pComboBox->Initialize(); | |
31 if (ret != FWL_Error::Succeeded) { | |
32 return ret; | |
33 } | |
34 m_pIface = std::move(pComboBox); | |
35 CFWL_Widget::Initialize(); | |
36 return FWL_Error::Succeeded; | |
37 } | |
38 | |
39 int32_t CFWL_ComboBox::AddString(const CFX_WideStringC& wsText) { | |
40 std::unique_ptr<CFWL_ComboBoxItem> pItem(new CFWL_ComboBoxItem); | |
41 pItem->m_wsText = wsText; | |
42 pItem->m_dwStyles = 0; | |
43 m_comboBoxData.m_ItemArray.push_back(std::move(pItem)); | |
44 return m_comboBoxData.m_ItemArray.size() - 1; | |
45 } | |
46 | |
47 int32_t CFWL_ComboBox::AddString(const CFX_WideStringC& wsText, | |
48 CFX_DIBitmap* pIcon) { | |
49 std::unique_ptr<CFWL_ComboBoxItem> pItem(new CFWL_ComboBoxItem); | |
50 pItem->m_wsText = wsText; | |
51 pItem->m_dwStyles = 0; | |
52 pItem->m_pDIB = pIcon; | |
53 m_comboBoxData.m_ItemArray.push_back(std::move(pItem)); | |
54 return m_comboBoxData.m_ItemArray.size() - 1; | |
55 } | |
56 | |
57 bool CFWL_ComboBox::RemoveAt(int32_t iIndex) { | |
58 if (iIndex < 0 || | |
59 static_cast<size_t>(iIndex) >= m_comboBoxData.m_ItemArray.size()) { | |
60 return false; | |
61 } | |
62 m_comboBoxData.m_ItemArray.erase(m_comboBoxData.m_ItemArray.begin() + iIndex); | |
63 return true; | |
64 } | |
65 | |
66 void CFWL_ComboBox::RemoveAll() { | |
67 m_comboBoxData.m_ItemArray.clear(); | |
68 } | |
69 | |
70 int32_t CFWL_ComboBox::CountItems() { | |
71 return m_comboBoxData.CountItems(GetWidget()); | |
72 } | |
73 | |
74 FWL_Error CFWL_ComboBox::GetTextByIndex(int32_t iIndex, | |
75 CFX_WideString& wsText) { | |
76 CFWL_ComboBoxItem* pItem = static_cast<CFWL_ComboBoxItem*>( | |
77 m_comboBoxData.GetItem(m_pIface.get(), iIndex)); | |
78 if (!pItem) | |
79 return FWL_Error::Indefinite; | |
80 wsText = pItem->m_wsText; | |
81 return FWL_Error::Succeeded; | |
82 } | |
83 | |
84 int32_t CFWL_ComboBox::GetCurSel() { | |
85 return GetWidget() ? GetWidget()->GetCurSel() : -1; | |
86 } | |
87 | |
88 FWL_Error CFWL_ComboBox::SetCurSel(int32_t iSel) { | |
89 return GetWidget() ? GetWidget()->SetCurSel(iSel) : FWL_Error::Indefinite; | |
90 } | |
91 | |
92 FWL_Error CFWL_ComboBox::SetEditText(const CFX_WideString& wsText) { | |
93 return GetWidget() ? GetWidget()->SetEditText(wsText) : FWL_Error::Indefinite; | |
94 } | |
95 | |
96 int32_t CFWL_ComboBox::GetEditTextLength() const { | |
97 return GetWidget() ? GetWidget()->GetEditTextLength() : 0; | |
98 } | |
99 | |
100 FWL_Error CFWL_ComboBox::GetEditText(CFX_WideString& wsText, | |
101 int32_t nStart, | |
102 int32_t nCount) const { | |
103 return GetWidget() ? GetWidget()->GetEditText(wsText, nStart, nCount) | |
104 : FWL_Error::Indefinite; | |
105 } | |
106 | |
107 FWL_Error CFWL_ComboBox::SetEditSelRange(int32_t nStart, int32_t nCount) { | |
108 return GetWidget() ? GetWidget()->SetEditSelRange(nStart, nCount) | |
109 : FWL_Error::Indefinite; | |
110 } | |
111 | |
112 int32_t CFWL_ComboBox::GetEditSelRange(int32_t nIndex, int32_t& nStart) { | |
113 return GetWidget() ? GetWidget()->GetEditSelRange(nIndex, nStart) : 0; | |
114 } | |
115 | |
116 int32_t CFWL_ComboBox::GetEditLimit() { | |
117 return GetWidget() ? GetWidget()->GetEditLimit() : 0; | |
118 } | |
119 | |
120 FWL_Error CFWL_ComboBox::SetEditLimit(int32_t nLimit) { | |
121 return GetWidget() ? GetWidget()->SetEditLimit(nLimit) | |
122 : FWL_Error::Indefinite; | |
123 } | |
124 | |
125 FWL_Error CFWL_ComboBox::EditDoClipboard(int32_t iCmd) { | |
126 return GetWidget() ? GetWidget()->EditDoClipboard(iCmd) | |
127 : FWL_Error::Indefinite; | |
128 } | |
129 | |
130 FX_BOOL CFWL_ComboBox::EditRedo(const IFDE_TxtEdtDoRecord* pRecord) { | |
131 return GetWidget() ? GetWidget()->EditRedo(pRecord) : FALSE; | |
132 } | |
133 | |
134 FX_BOOL CFWL_ComboBox::EditUndo(const IFDE_TxtEdtDoRecord* pRecord) { | |
135 return GetWidget() ? GetWidget()->EditUndo(pRecord) : FALSE; | |
136 } | |
137 | |
138 FWL_Error CFWL_ComboBox::SetMaxListHeight(FX_FLOAT fMaxHeight) { | |
139 m_comboBoxData.m_fMaxListHeight = fMaxHeight; | |
140 return FWL_Error::Succeeded; | |
141 } | |
142 | |
143 FWL_Error CFWL_ComboBox::SetItemData(int32_t iIndex, void* pData) { | |
144 CFWL_ComboBoxItem* pItem = static_cast<CFWL_ComboBoxItem*>( | |
145 m_comboBoxData.GetItem(m_pIface.get(), iIndex)); | |
146 if (!pItem) | |
147 return FWL_Error::Indefinite; | |
148 pItem->m_pData = pData; | |
149 return FWL_Error::Succeeded; | |
150 } | |
151 | |
152 void* CFWL_ComboBox::GetItemData(int32_t iIndex) { | |
153 CFWL_ComboBoxItem* pItem = static_cast<CFWL_ComboBoxItem*>( | |
154 m_comboBoxData.GetItem(m_pIface.get(), iIndex)); | |
155 return pItem ? pItem->m_pData : nullptr; | |
156 } | |
157 | |
158 FWL_Error CFWL_ComboBox::SetListTheme(IFWL_ThemeProvider* pTheme) { | |
159 return GetWidget()->GetListBoxt()->SetThemeProvider(pTheme); | |
160 } | |
161 | |
162 FX_BOOL CFWL_ComboBox::AfterFocusShowDropList() { | |
163 return GetWidget()->AfterFocusShowDropList(); | |
164 } | |
165 | |
166 FWL_Error CFWL_ComboBox::OpenDropDownList(FX_BOOL bActivate) { | |
167 return GetWidget()->OpenDropDownList(bActivate); | |
168 } | |
169 | |
170 FX_BOOL CFWL_ComboBox::EditCanUndo() { | |
171 return GetWidget() ? GetWidget()->EditCanUndo() : FALSE; | |
172 } | |
173 | |
174 FX_BOOL CFWL_ComboBox::EditCanRedo() { | |
175 return GetWidget() ? GetWidget()->EditCanRedo() : FALSE; | |
176 } | |
177 | |
178 FX_BOOL CFWL_ComboBox::EditUndo() { | |
179 return GetWidget() ? GetWidget()->EditUndo() : FALSE; | |
180 } | |
181 | |
182 FX_BOOL CFWL_ComboBox::EditRedo() { | |
183 return GetWidget() ? GetWidget()->EditRedo() : FALSE; | |
184 } | |
185 | |
186 FX_BOOL CFWL_ComboBox::EditCanCopy() { | |
187 return GetWidget() ? GetWidget()->EditCanCopy() : FALSE; | |
188 } | |
189 | |
190 FX_BOOL CFWL_ComboBox::EditCanCut() { | |
191 return GetWidget() ? GetWidget()->EditCanCut() : FALSE; | |
192 } | |
193 | |
194 FX_BOOL CFWL_ComboBox::EditCanSelectAll() { | |
195 return GetWidget() ? GetWidget()->EditCanSelectAll() : FALSE; | |
196 } | |
197 | |
198 FX_BOOL CFWL_ComboBox::EditCopy(CFX_WideString& wsCopy) { | |
199 return GetWidget() ? GetWidget()->EditCopy(wsCopy) : FALSE; | |
200 } | |
201 | |
202 FX_BOOL CFWL_ComboBox::EditCut(CFX_WideString& wsCut) { | |
203 return GetWidget() ? GetWidget()->EditCut(wsCut) : FALSE; | |
204 } | |
205 | |
206 FX_BOOL CFWL_ComboBox::EditPaste(const CFX_WideString& wsPaste) { | |
207 return GetWidget() ? GetWidget()->EditPaste(wsPaste) : FALSE; | |
208 } | |
209 | |
210 FX_BOOL CFWL_ComboBox::EditSelectAll() { | |
211 return GetWidget() ? GetWidget()->EditSelectAll() : FALSE; | |
212 } | |
213 | |
214 FX_BOOL CFWL_ComboBox::EditDelete() { | |
215 return GetWidget() ? GetWidget()->EditDelete() : FALSE; | |
216 } | |
217 | |
218 FX_BOOL CFWL_ComboBox::EditDeSelect() { | |
219 return GetWidget() ? GetWidget()->EditDeSelect() : FALSE; | |
220 } | |
221 | |
222 FWL_Error CFWL_ComboBox::GetBBox(CFX_RectF& rect) { | |
223 return GetWidget() ? GetWidget()->GetBBox(rect) : FWL_Error::Indefinite; | |
224 } | |
225 | |
226 FWL_Error CFWL_ComboBox::EditModifyStylesEx(uint32_t dwStylesExAdded, | |
227 uint32_t dwStylesExRemoved) { | |
228 return GetWidget() | |
229 ? GetWidget()->EditModifyStylesEx(dwStylesExAdded, | |
230 dwStylesExRemoved) | |
231 : FWL_Error::Indefinite; | |
232 } | |
233 | |
234 CFWL_ComboBox::CFWL_ComboBox() {} | |
235 | |
236 CFWL_ComboBox::~CFWL_ComboBox() {} | |
237 | |
238 CFWL_ComboBox::CFWL_ComboBoxDP::CFWL_ComboBoxDP() { | |
239 m_fItemHeight = 0; | |
240 m_fMaxListHeight = 0; | |
241 } | |
242 | |
243 CFWL_ComboBox::CFWL_ComboBoxDP::~CFWL_ComboBoxDP() {} | |
244 | |
245 FWL_Error CFWL_ComboBox::CFWL_ComboBoxDP::GetCaption( | |
246 IFWL_Widget* pWidget, | |
247 CFX_WideString& wsCaption) { | |
248 return FWL_Error::Succeeded; | |
249 } | |
250 | |
251 int32_t CFWL_ComboBox::CFWL_ComboBoxDP::CountItems(const IFWL_Widget* pWidget) { | |
252 return m_ItemArray.size(); | |
253 } | |
254 | |
255 IFWL_ListItem* CFWL_ComboBox::CFWL_ComboBoxDP::GetItem( | |
256 const IFWL_Widget* pWidget, | |
257 int32_t nIndex) { | |
258 if (nIndex < 0 || static_cast<size_t>(nIndex) >= m_ItemArray.size()) | |
259 return nullptr; | |
260 | |
261 return m_ItemArray[nIndex].get(); | |
262 } | |
263 | |
264 int32_t CFWL_ComboBox::CFWL_ComboBoxDP::GetItemIndex(IFWL_Widget* pWidget, | |
265 IFWL_ListItem* pItem) { | |
266 auto it = std::find_if( | |
267 m_ItemArray.begin(), m_ItemArray.end(), | |
268 [pItem](const std::unique_ptr<CFWL_ComboBoxItem>& candidate) { | |
269 return candidate.get() == static_cast<CFWL_ComboBoxItem*>(pItem); | |
270 }); | |
271 return it != m_ItemArray.end() ? it - m_ItemArray.begin() : -1; | |
272 } | |
273 | |
274 FX_BOOL CFWL_ComboBox::CFWL_ComboBoxDP::SetItemIndex(IFWL_Widget* pWidget, | |
275 IFWL_ListItem* pItem, | |
276 int32_t nIndex) { | |
277 if (nIndex < 0 || static_cast<size_t>(nIndex) >= m_ItemArray.size()) | |
278 return FALSE; | |
279 | |
280 m_ItemArray[nIndex].reset(static_cast<CFWL_ComboBoxItem*>(pItem)); | |
281 return TRUE; | |
282 } | |
283 | |
284 uint32_t CFWL_ComboBox::CFWL_ComboBoxDP::GetItemStyles(IFWL_Widget* pWidget, | |
285 IFWL_ListItem* pItem) { | |
286 if (!pItem) | |
287 return 0; | |
288 return static_cast<CFWL_ComboBoxItem*>(pItem)->m_dwStyles; | |
289 } | |
290 | |
291 FWL_Error CFWL_ComboBox::CFWL_ComboBoxDP::GetItemText(IFWL_Widget* pWidget, | |
292 IFWL_ListItem* pItem, | |
293 CFX_WideString& wsText) { | |
294 if (!pItem) | |
295 return FWL_Error::Indefinite; | |
296 wsText = static_cast<CFWL_ComboBoxItem*>(pItem)->m_wsText; | |
297 return FWL_Error::Succeeded; | |
298 } | |
299 | |
300 FWL_Error CFWL_ComboBox::CFWL_ComboBoxDP::GetItemRect(IFWL_Widget* pWidget, | |
301 IFWL_ListItem* pItem, | |
302 CFX_RectF& rtItem) { | |
303 if (!pItem) | |
304 return FWL_Error::Indefinite; | |
305 CFWL_ComboBoxItem* pComboItem = static_cast<CFWL_ComboBoxItem*>(pItem); | |
306 rtItem.Set(pComboItem->m_rtItem.left, pComboItem->m_rtItem.top, | |
307 pComboItem->m_rtItem.width, pComboItem->m_rtItem.height); | |
308 return FWL_Error::Succeeded; | |
309 } | |
310 | |
311 void* CFWL_ComboBox::CFWL_ComboBoxDP::GetItemData(IFWL_Widget* pWidget, | |
312 IFWL_ListItem* pItem) { | |
313 return pItem ? static_cast<CFWL_ComboBoxItem*>(pItem)->m_pData : nullptr; | |
314 } | |
315 | |
316 FWL_Error CFWL_ComboBox::CFWL_ComboBoxDP::SetItemStyles(IFWL_Widget* pWidget, | |
317 IFWL_ListItem* pItem, | |
318 uint32_t dwStyle) { | |
319 if (!pItem) | |
320 return FWL_Error::Indefinite; | |
321 static_cast<CFWL_ComboBoxItem*>(pItem)->m_dwStyles = dwStyle; | |
322 return FWL_Error::Succeeded; | |
323 } | |
324 | |
325 FWL_Error CFWL_ComboBox::CFWL_ComboBoxDP::SetItemText(IFWL_Widget* pWidget, | |
326 IFWL_ListItem* pItem, | |
327 const FX_WCHAR* pszText) { | |
328 if (!pItem) | |
329 return FWL_Error::Indefinite; | |
330 static_cast<CFWL_ComboBoxItem*>(pItem)->m_wsText = pszText; | |
331 return FWL_Error::Succeeded; | |
332 } | |
333 | |
334 FWL_Error CFWL_ComboBox::CFWL_ComboBoxDP::SetItemRect(IFWL_Widget* pWidget, | |
335 IFWL_ListItem* pItem, | |
336 const CFX_RectF& rtItem) { | |
337 if (!pItem) | |
338 return FWL_Error::Indefinite; | |
339 static_cast<CFWL_ComboBoxItem*>(pItem)->m_rtItem = rtItem; | |
340 return FWL_Error::Succeeded; | |
341 } | |
342 | |
343 FX_FLOAT CFWL_ComboBox::CFWL_ComboBoxDP::GetItemHeight(IFWL_Widget* pWidget) { | |
344 return m_fItemHeight; | |
345 } | |
346 | |
347 CFX_DIBitmap* CFWL_ComboBox::CFWL_ComboBoxDP::GetItemIcon( | |
348 IFWL_Widget* pWidget, | |
349 IFWL_ListItem* pItem) { | |
350 return pItem ? static_cast<CFWL_ComboBoxItem*>(pItem)->m_pDIB : nullptr; | |
351 } | |
352 | |
353 FWL_Error CFWL_ComboBox::CFWL_ComboBoxDP::GetItemCheckRect(IFWL_Widget* pWidget, | |
354 IFWL_ListItem* pItem, | |
355 CFX_RectF& rtCheck) { | |
356 rtCheck = static_cast<CFWL_ComboBoxItem*>(pItem)->m_rtCheckBox; | |
357 return FWL_Error::Succeeded; | |
358 } | |
359 | |
360 FWL_Error CFWL_ComboBox::CFWL_ComboBoxDP::SetItemCheckRect( | |
361 IFWL_Widget* pWidget, | |
362 IFWL_ListItem* pItem, | |
363 const CFX_RectF& rtCheck) { | |
364 static_cast<CFWL_ComboBoxItem*>(pItem)->m_rtCheckBox = rtCheck; | |
365 return FWL_Error::Succeeded; | |
366 } | |
367 | |
368 uint32_t CFWL_ComboBox::CFWL_ComboBoxDP::GetItemCheckState( | |
369 IFWL_Widget* pWidget, | |
370 IFWL_ListItem* pItem) { | |
371 return static_cast<CFWL_ComboBoxItem*>(pItem)->m_dwCheckState; | |
372 } | |
373 | |
374 FWL_Error CFWL_ComboBox::CFWL_ComboBoxDP::SetItemCheckState( | |
375 IFWL_Widget* pWidget, | |
376 IFWL_ListItem* pItem, | |
377 uint32_t dwCheckState) { | |
378 static_cast<CFWL_ComboBoxItem*>(pItem)->m_dwCheckState = dwCheckState; | |
379 return FWL_Error::Succeeded; | |
380 } | |
381 | |
382 FX_FLOAT CFWL_ComboBox::CFWL_ComboBoxDP::GetListHeight(IFWL_Widget* pWidget) { | |
383 return m_fMaxListHeight; | |
384 } | |
385 | |
386 CFWL_ComboBoxItem::CFWL_ComboBoxItem() : m_pDIB(nullptr), m_pData(nullptr) {} | |
387 | |
388 CFWL_ComboBoxItem::~CFWL_ComboBoxItem() {} | |
OLD | NEW |