Merge XFA to PDFium master at 4dc95e7 on 10/28/2014
[pdfium.git] / xfa / src / fwl / src / lightwidget / combobox.cpp
1 // Copyright 2014 PDFium Authors. All rights reserved.\r
2 // Use of this source code is governed by a BSD-style license that can be\r
3 // found in the LICENSE file.\r
4 \r
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com\r
6 \r
7 #include "../../../foxitlib.h"\r
8 CFWL_ComboBox* CFWL_ComboBox::Create()\r
9 {\r
10     return FX_NEW CFWL_ComboBox;\r
11 }\r
12 FWL_ERR CFWL_ComboBox::Initialize(const CFWL_WidgetProperties *pProperties )\r
13 {\r
14     _FWL_RETURN_VALUE_IF_FAIL(!m_pImp, FWL_ERR_Indefinite);\r
15     if (pProperties) {\r
16         *m_pProperties = *pProperties;\r
17     }\r
18     CFWL_WidgetImpProperties prop;\r
19     prop.m_ctmOnParent = m_pProperties->m_ctmOnParent;\r
20     prop.m_rtWidget = m_pProperties->m_rtWidget;\r
21     prop.m_dwStyles = m_pProperties->m_dwStyles;\r
22     prop.m_dwStyleExes = m_pProperties->m_dwStyleExes;\r
23     prop.m_dwStates = m_pProperties->m_dwStates;\r
24     prop.m_pDataProvider = &m_comboBoxData;\r
25     if (m_pProperties->m_pParent) {\r
26         prop.m_pParent = m_pProperties->m_pParent->GetWidget();\r
27     }\r
28     if (m_pProperties->m_pOwner) {\r
29         prop.m_pOwner = m_pProperties->m_pOwner->GetWidget();\r
30     }\r
31     m_pImp = IFWL_ComboBox::Create();\r
32     FWL_ERR ret = ((IFWL_ComboBox*)m_pImp)->Initialize(prop);\r
33     if (ret == FWL_ERR_Succeeded) {\r
34         CFWL_Widget::Initialize();\r
35     }\r
36     return ret;\r
37 }\r
38 FX_INT32 CFWL_ComboBox::AddString(FX_WSTR wsText)\r
39 {\r
40     CFWL_ComboBoxItem *pItem = FX_NEW CFWL_ComboBoxItem;\r
41     pItem->m_wsText = wsText;\r
42     pItem->m_dwStyles = 0;\r
43     return m_comboBoxData.m_arrItem.Add(pItem);\r
44 }\r
45 FX_INT32 CFWL_ComboBox::AddString(FX_WSTR wsText, CFX_DIBitmap *pIcon)\r
46 {\r
47     CFWL_ComboBoxItem *pItem = FX_NEW CFWL_ComboBoxItem;\r
48     pItem->m_wsText = wsText;\r
49     pItem->m_dwStyles = 0;\r
50     pItem->m_pDIB = pIcon;\r
51     return m_comboBoxData.m_arrItem.Add(pItem);\r
52 }\r
53 FX_INT32 CFWL_ComboBox::RemoveAt(FX_INT32 iIndex)\r
54 {\r
55     return m_comboBoxData.m_arrItem.RemoveAt(iIndex);\r
56 }\r
57 FX_INT32 CFWL_ComboBox::RemoveAll()\r
58 {\r
59     m_comboBoxData.m_arrItem.RemoveAll();\r
60     return 0;\r
61 }\r
62 FX_INT32 CFWL_ComboBox::CountItems()\r
63 {\r
64     return m_comboBoxData.CountItems(GetWidget());\r
65 }\r
66 FWL_ERR CFWL_ComboBox::GetTextByIndex(FX_INT32 iIndex, CFX_WideString &wsText)\r
67 {\r
68     CFWL_ComboBoxItem *pItem = (CFWL_ComboBoxItem*)(m_comboBoxData.GetItem((IFWL_Widget *)this, iIndex));\r
69     _FWL_RETURN_VALUE_IF_FAIL(pItem, FWL_ERR_Indefinite);\r
70     wsText = pItem->m_wsText;\r
71     return FWL_ERR_Succeeded;\r
72 }\r
73 FX_INT32 CFWL_ComboBox::GetCurSel()\r
74 {\r
75     _FWL_RETURN_VALUE_IF_FAIL(m_pImp, -1);\r
76     return ((IFWL_ComboBox*)m_pImp)->GetCurSel();\r
77 }\r
78 FWL_ERR CFWL_ComboBox::SetCurSel(FX_INT32 iSel)\r
79 {\r
80     _FWL_RETURN_VALUE_IF_FAIL(m_pImp, FWL_ERR_Indefinite);\r
81     return ((IFWL_ComboBox*)m_pImp)->SetCurSel(iSel);\r
82 }\r
83 FWL_ERR CFWL_ComboBox::SetEditText(FX_WSTR wsText)\r
84 {\r
85     _FWL_RETURN_VALUE_IF_FAIL(m_pImp, FWL_ERR_Indefinite);\r
86     return ((IFWL_ComboBox*)m_pImp)->SetEditText(wsText);\r
87 }\r
88 FX_INT32 CFWL_ComboBox::GetEditTextLength() const\r
89 {\r
90     _FWL_RETURN_VALUE_IF_FAIL(m_pImp, 0);\r
91     return ((IFWL_ComboBox*)m_pImp)->GetEditTextLength();\r
92 }\r
93 FWL_ERR CFWL_ComboBox::GetEditText(CFX_WideString &wsText, FX_INT32 nStart, FX_INT32 nCount) const\r
94 {\r
95     _FWL_RETURN_VALUE_IF_FAIL(m_pImp, FWL_ERR_Indefinite);\r
96     return ((IFWL_ComboBox*)m_pImp)->GetEditText(wsText, nStart, nCount);\r
97 }\r
98 FWL_ERR CFWL_ComboBox::SetEditSelRange(FX_INT32 nStart, FX_INT32 nCount)\r
99 {\r
100     _FWL_RETURN_VALUE_IF_FAIL(m_pImp, FWL_ERR_Indefinite);\r
101     return ((IFWL_ComboBox*)m_pImp)->SetEditSelRange(nStart, nCount);\r
102 }\r
103 FX_INT32 CFWL_ComboBox::GetEditSelRange(FX_INT32 nIndex, FX_INT32 &nStart)\r
104 {\r
105     _FWL_RETURN_VALUE_IF_FAIL(m_pImp, 0);\r
106     return ((IFWL_ComboBox*)m_pImp)->GetEditSelRange(nIndex, nStart);\r
107 }\r
108 FX_INT32 CFWL_ComboBox::GetEditLimit()\r
109 {\r
110     _FWL_RETURN_VALUE_IF_FAIL(m_pImp, 0);\r
111     return ((IFWL_ComboBox*)m_pImp)->GetEditLimit();\r
112 }\r
113 FWL_ERR CFWL_ComboBox::SetEditLimit(FX_INT32 nLimit)\r
114 {\r
115     _FWL_RETURN_VALUE_IF_FAIL(m_pImp, FWL_ERR_Indefinite);\r
116     return ((IFWL_ComboBox*)m_pImp)->SetEditLimit(nLimit);\r
117 }\r
118 FWL_ERR CFWL_ComboBox::EditDoClipboard(FX_INT32 iCmd)\r
119 {\r
120     _FWL_RETURN_VALUE_IF_FAIL(m_pImp, FWL_ERR_Indefinite);\r
121     return ((IFWL_ComboBox*)m_pImp)->EditDoClipboard(iCmd);\r
122 }\r
123 FX_BOOL CFWL_ComboBox::EditRedo(FX_BSTR bsRecord)\r
124 {\r
125     _FWL_RETURN_VALUE_IF_FAIL(m_pImp, FALSE);\r
126     return ((IFWL_ComboBox*)m_pImp)->EditRedo(bsRecord);\r
127 }\r
128 FX_BOOL CFWL_ComboBox::EditUndo(FX_BSTR bsRecord)\r
129 {\r
130     _FWL_RETURN_VALUE_IF_FAIL(m_pImp, FALSE);\r
131     return ((IFWL_ComboBox*)m_pImp)->EditUndo(bsRecord);\r
132 }\r
133 FWL_ERR CFWL_ComboBox::SetMaxListHeight(FX_FLOAT fMaxHeight)\r
134 {\r
135     m_comboBoxData.m_fMaxListHeight = fMaxHeight;\r
136     return FWL_ERR_Succeeded;\r
137 }\r
138 FWL_ERR CFWL_ComboBox::SetItemData(FX_INT32 iIndex, FX_LPVOID pData)\r
139 {\r
140     CFWL_ComboBoxItem *pItem = (CFWL_ComboBoxItem*)(m_comboBoxData.GetItem((IFWL_Widget *)this, iIndex));\r
141     _FWL_RETURN_VALUE_IF_FAIL(pItem, FWL_ERR_Indefinite);\r
142     pItem->m_pData = pData;\r
143     return FWL_ERR_Succeeded;\r
144 }\r
145 FX_LPVOID CFWL_ComboBox::GetItemData(FX_INT32 iIndex)\r
146 {\r
147     CFWL_ComboBoxItem *pItem = (CFWL_ComboBoxItem*)(m_comboBoxData.GetItem((IFWL_Widget *)this, iIndex));\r
148     _FWL_RETURN_VALUE_IF_FAIL(pItem, NULL);\r
149     return pItem->m_pData;\r
150 }\r
151 FWL_ERR CFWL_ComboBox::SetListTheme(IFWL_ThemeProvider *pTheme)\r
152 {\r
153     return ((IFWL_ComboBox*)m_pImp)->GetListBoxt()->SetThemeProvider(pTheme);\r
154 }\r
155 FX_BOOL CFWL_ComboBox::AfterFocusShowDropList()\r
156 {\r
157     return ((IFWL_ComboBox*)m_pImp)->AfterFocusShowDropList();\r
158 }\r
159 FWL_ERR CFWL_ComboBox::OpenDropDownList(FX_BOOL bActivate)\r
160 {\r
161     return ((IFWL_ComboBox*)m_pImp)->OpenDropDownList(bActivate);\r
162 }\r
163 FX_BOOL CFWL_ComboBox::EditCanUndo()\r
164 {\r
165     _FWL_RETURN_VALUE_IF_FAIL(m_pImp, FALSE);\r
166     return ((IFWL_ComboBox*)m_pImp)->EditCanUndo();\r
167 }\r
168 FX_BOOL CFWL_ComboBox::EditCanRedo()\r
169 {\r
170     _FWL_RETURN_VALUE_IF_FAIL(m_pImp, FALSE);\r
171     return ((IFWL_ComboBox*)m_pImp)->EditCanRedo();\r
172 }\r
173 FX_BOOL CFWL_ComboBox::EditUndo()\r
174 {\r
175     _FWL_RETURN_VALUE_IF_FAIL(m_pImp, FALSE);\r
176     return ((IFWL_ComboBox*)m_pImp)->EditUndo();\r
177 }\r
178 FX_BOOL CFWL_ComboBox::EditRedo()\r
179 {\r
180     _FWL_RETURN_VALUE_IF_FAIL(m_pImp, FALSE);\r
181     return ((IFWL_ComboBox*)m_pImp)->EditRedo();\r
182 }\r
183 FX_BOOL CFWL_ComboBox::EditCanCopy()\r
184 {\r
185     _FWL_RETURN_VALUE_IF_FAIL(m_pImp, FALSE);\r
186     return ((IFWL_ComboBox*)m_pImp)->EditCanCopy();\r
187 }\r
188 FX_BOOL CFWL_ComboBox::EditCanCut()\r
189 {\r
190     _FWL_RETURN_VALUE_IF_FAIL(m_pImp, FALSE);\r
191     return ((IFWL_ComboBox*)m_pImp)->EditCanCut();\r
192 }\r
193 FX_BOOL CFWL_ComboBox::EditCanSelectAll()\r
194 {\r
195     _FWL_RETURN_VALUE_IF_FAIL(m_pImp, FALSE);\r
196     return ((IFWL_ComboBox*)m_pImp)->EditCanSelectAll();\r
197 }\r
198 FX_BOOL CFWL_ComboBox::EditCopy(CFX_WideString &wsCopy)\r
199 {\r
200     _FWL_RETURN_VALUE_IF_FAIL(m_pImp, FALSE);\r
201     return ((IFWL_ComboBox*)m_pImp)->EditCopy(wsCopy);\r
202 }\r
203 FX_BOOL CFWL_ComboBox::EditCut(CFX_WideString &wsCut)\r
204 {\r
205     _FWL_RETURN_VALUE_IF_FAIL(m_pImp, FALSE);\r
206     return ((IFWL_ComboBox*)m_pImp)->EditCut(wsCut);\r
207 }\r
208 FX_BOOL CFWL_ComboBox::EditPaste(const CFX_WideString &wsPaste)\r
209 {\r
210     _FWL_RETURN_VALUE_IF_FAIL(m_pImp, FALSE);\r
211     return ((IFWL_ComboBox*)m_pImp)->EditPaste(wsPaste);\r
212 }\r
213 FX_BOOL CFWL_ComboBox::EditSelectAll()\r
214 {\r
215     _FWL_RETURN_VALUE_IF_FAIL(m_pImp, FALSE);\r
216     return ((IFWL_ComboBox*)m_pImp)->EditSelectAll();\r
217 }\r
218 FX_BOOL CFWL_ComboBox::EditDelete()\r
219 {\r
220     _FWL_RETURN_VALUE_IF_FAIL(m_pImp, FALSE);\r
221     return ((IFWL_ComboBox*)m_pImp)->EditDelete();\r
222 }\r
223 FX_BOOL CFWL_ComboBox::EditDeSelect()\r
224 {\r
225     _FWL_RETURN_VALUE_IF_FAIL(m_pImp, FALSE);\r
226     return ((IFWL_ComboBox*)m_pImp)->EditDeSelect();\r
227 }\r
228 FWL_ERR CFWL_ComboBox::GetBBox(CFX_RectF &rect)\r
229 {\r
230     _FWL_RETURN_VALUE_IF_FAIL(m_pImp, FALSE);\r
231     return ((IFWL_ComboBox*)m_pImp)->GetBBox(rect);\r
232 }\r
233 FWL_ERR         CFWL_ComboBox::EditModifyStylesEx(FX_DWORD dwStylesExAdded,\r
234         FX_DWORD dwStylesExRemoved)\r
235 {\r
236     _FWL_RETURN_VALUE_IF_FAIL(m_pImp, FALSE);\r
237     return ((IFWL_ComboBox*)m_pImp)->EditModifyStylesEx(dwStylesExAdded, dwStylesExRemoved);\r
238 }\r
239 CFWL_ComboBox::CFWL_ComboBox()\r
240 {\r
241 }\r
242 CFWL_ComboBox::~CFWL_ComboBox()\r
243 {\r
244 }\r
245 CFWL_ComboBox::CFWL_ComboBoxDP::CFWL_ComboBoxDP()\r
246 {\r
247     m_fItemHeight = 0;\r
248     m_fMaxListHeight = 0;\r
249 }\r
250 CFWL_ComboBox::CFWL_ComboBoxDP::~CFWL_ComboBoxDP()\r
251 {\r
252     FX_INT32 nCount = m_arrItem.GetSize();\r
253     for (FX_INT32 i = 0; i < nCount; i ++) {\r
254         CFWL_ComboBoxItem *pItem = (CFWL_ComboBoxItem*)m_arrItem[i];\r
255         if (pItem) {\r
256             delete pItem;\r
257         }\r
258     }\r
259     m_arrItem.RemoveAll();\r
260 }\r
261 FX_INT32 CFWL_ComboBox::CFWL_ComboBoxDP::CountItems(IFWL_Widget *pWidget)\r
262 {\r
263     return m_arrItem.GetSize();\r
264 }\r
265 FWL_HLISTITEM CFWL_ComboBox::CFWL_ComboBoxDP::GetItem(IFWL_Widget *pWidget, FX_INT32 nIndex)\r
266 {\r
267     FX_INT32 iCount = m_arrItem.GetSize();\r
268     if (nIndex >= iCount || nIndex < 0) {\r
269         return NULL;\r
270     }\r
271     return (FWL_HLISTITEM)m_arrItem[nIndex];\r
272 }\r
273 FX_INT32 CFWL_ComboBox::CFWL_ComboBoxDP::GetItemIndex(IFWL_Widget *pWidget, FWL_HLISTITEM hItem)\r
274 {\r
275     return m_arrItem.Find(hItem);\r
276 }\r
277 FX_BOOL CFWL_ComboBox::CFWL_ComboBoxDP::SetItemIndex(IFWL_Widget *pWidget, FWL_HLISTITEM hItem, FX_INT32 nIndex)\r
278 {\r
279     return m_arrItem.SetAt(nIndex, hItem);\r
280 }\r
281 FX_DWORD CFWL_ComboBox::CFWL_ComboBoxDP::GetItemStyles(IFWL_Widget *pWidget, FWL_HLISTITEM hItem)\r
282 {\r
283     _FWL_RETURN_VALUE_IF_FAIL(hItem, 0);\r
284     return ((CFWL_ComboBoxItem*)hItem)->m_dwStyles;\r
285 }\r
286 FWL_ERR CFWL_ComboBox::CFWL_ComboBoxDP::GetItemText(IFWL_Widget *pWidget, FWL_HLISTITEM hItem, CFX_WideString &wsText)\r
287 {\r
288     _FWL_RETURN_VALUE_IF_FAIL(hItem, FWL_ERR_Indefinite);\r
289     wsText = ((CFWL_ComboBoxItem*)hItem)->m_wsText;\r
290     return FWL_ERR_Succeeded;\r
291 }\r
292 FWL_ERR CFWL_ComboBox::CFWL_ComboBoxDP::GetItemRect(IFWL_Widget *pWidget, FWL_HLISTITEM hItem, CFX_RectF& rtItem)\r
293 {\r
294     _FWL_RETURN_VALUE_IF_FAIL(hItem, FWL_ERR_Indefinite);\r
295     CFWL_ComboBoxItem *pItem = (CFWL_ComboBoxItem*)hItem;\r
296     rtItem.Set(pItem->m_rtItem.left,\r
297                pItem->m_rtItem.top,\r
298                pItem->m_rtItem.width,\r
299                pItem->m_rtItem.height);\r
300     return FWL_ERR_Succeeded;\r
301 }\r
302 FX_LPVOID CFWL_ComboBox::CFWL_ComboBoxDP::GetItemData(IFWL_Widget *pWidget, FWL_HLISTITEM hItem)\r
303 {\r
304     _FWL_RETURN_VALUE_IF_FAIL(hItem, NULL);\r
305     CFWL_ComboBoxItem *pItem = (CFWL_ComboBoxItem*)hItem;\r
306     return pItem->m_pData;\r
307 }\r
308 FWL_ERR CFWL_ComboBox::CFWL_ComboBoxDP::SetItemStyles(IFWL_Widget *pWidget, FWL_HLISTITEM hItem, FX_DWORD dwStyle)\r
309 {\r
310     _FWL_RETURN_VALUE_IF_FAIL(hItem, FWL_ERR_Indefinite);\r
311     ((CFWL_ComboBoxItem*)hItem)->m_dwStyles = dwStyle;\r
312     return FWL_ERR_Succeeded;\r
313 }\r
314 FWL_ERR CFWL_ComboBox::CFWL_ComboBoxDP::SetItemText(IFWL_Widget *pWidget, FWL_HLISTITEM hItem, FX_LPCWSTR pszText)\r
315 {\r
316     _FWL_RETURN_VALUE_IF_FAIL(hItem, FWL_ERR_Indefinite);\r
317     ((CFWL_ComboBoxItem*)hItem)->m_wsText = pszText;\r
318     return FWL_ERR_Succeeded;\r
319 }\r
320 FWL_ERR CFWL_ComboBox::CFWL_ComboBoxDP::SetItemRect(IFWL_Widget *pWidget, FWL_HLISTITEM hItem, const CFX_RectF& rtItem)\r
321 {\r
322     _FWL_RETURN_VALUE_IF_FAIL(hItem, FWL_ERR_Indefinite);\r
323     ((CFWL_ComboBoxItem*)hItem)->m_rtItem = rtItem;\r
324     return FWL_ERR_Succeeded;\r
325 }\r
326 FX_FLOAT CFWL_ComboBox::CFWL_ComboBoxDP::GetItemHeight(IFWL_Widget *pWidget)\r
327 {\r
328     return m_fItemHeight;\r
329 }\r
330 CFX_DIBitmap* CFWL_ComboBox::CFWL_ComboBoxDP::GetItemIcon(IFWL_Widget *pWidget, FWL_HLISTITEM hItem)\r
331 {\r
332     _FWL_RETURN_VALUE_IF_FAIL(hItem, NULL);\r
333     return ((CFWL_ComboBoxItem*)hItem)->m_pDIB;\r
334 }\r
335 FWL_ERR CFWL_ComboBox::CFWL_ComboBoxDP::GetItemCheckRect(IFWL_Widget *pWidget, FWL_HLISTITEM hItem, CFX_RectF& rtCheck)\r
336 {\r
337     CFWL_ComboBoxItem *pItem = (CFWL_ComboBoxItem*)hItem;\r
338     rtCheck = pItem->m_rtCheckBox;\r
339     return FWL_ERR_Succeeded;\r
340 }\r
341 FWL_ERR CFWL_ComboBox::CFWL_ComboBoxDP::SetItemCheckRect(IFWL_Widget *pWidget, FWL_HLISTITEM hItem, const CFX_RectF& rtCheck)\r
342 {\r
343     CFWL_ComboBoxItem *pItem = (CFWL_ComboBoxItem*)hItem;\r
344     pItem->m_rtCheckBox = rtCheck;\r
345     return FWL_ERR_Succeeded;\r
346 }\r
347 FX_DWORD CFWL_ComboBox::CFWL_ComboBoxDP::GetItemCheckState(IFWL_Widget *pWidget, FWL_HLISTITEM hItem)\r
348 {\r
349     CFWL_ComboBoxItem *pItem = (CFWL_ComboBoxItem*)hItem;\r
350     return pItem->m_dwCheckState;\r
351 }\r
352 FWL_ERR CFWL_ComboBox::CFWL_ComboBoxDP::SetItemCheckState(IFWL_Widget *pWidget, FWL_HLISTITEM hItem, FX_DWORD dwCheckState)\r
353 {\r
354     CFWL_ComboBoxItem *pItem = (CFWL_ComboBoxItem*)hItem;\r
355     pItem->m_dwCheckState = dwCheckState;\r
356     return FWL_ERR_Succeeded;\r
357 }\r
358 FX_FLOAT CFWL_ComboBox::CFWL_ComboBoxDP::GetListHeight(IFWL_Widget *pWidget)\r
359 {\r
360     return m_fMaxListHeight;\r
361 }\r