Merge XFA to PDFium master at 4dc95e7 on 10/28/2014
[pdfium.git] / xfa / src / fxfa / src / app / xfa_ffchoicelist.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 #include "../common/xfa_common.h"\r
9 #include "xfa_fwladapter.h"\r
10 #include "xfa_ffwidget.h"\r
11 #include "xfa_fffield.h"\r
12 #include "xfa_ffpageview.h"\r
13 #include "xfa_ffdocview.h"\r
14 #include "xfa_ffchoicelist.h"\r
15 #include "xfa_ffdoc.h"\r
16 CXFA_FFListBox::CXFA_FFListBox(CXFA_FFPageView* pPageView, CXFA_WidgetAcc* pDataAcc)\r
17     : CXFA_FFField(pPageView, pDataAcc)\r
18     , m_pOldDelegate(NULL)\r
19 {\r
20 }\r
21 CXFA_FFListBox::~CXFA_FFListBox()\r
22 {\r
23     if (m_pNormalWidget) {\r
24         IFWL_Widget* pWidget = m_pNormalWidget->GetWidget();\r
25         IFWL_NoteDriver *pNoteDriver = FWL_GetApp()->GetNoteDriver();\r
26         pNoteDriver->UnregisterEventTarget(pWidget);\r
27     }\r
28 }\r
29 FX_BOOL CXFA_FFListBox::LoadWidget()\r
30 {\r
31     CFWL_ListBox* pListBox = CFWL_ListBox::Create();\r
32     pListBox->Initialize();\r
33     pListBox->ModifyStyles(FWL_WGTSTYLE_VScroll | FWL_WGTSTYLE_NoBackground, 0xFFFFFFFF);\r
34     m_pNormalWidget = (CFWL_Widget*)pListBox;\r
35     IFWL_Widget* pWidget = m_pNormalWidget->GetWidget();\r
36     m_pNormalWidget->SetPrivateData(pWidget, this, NULL);\r
37     IFWL_NoteDriver *pNoteDriver = FWL_GetApp()->GetNoteDriver();\r
38     pNoteDriver->RegisterEventTarget(pWidget, pWidget);\r
39     m_pOldDelegate = m_pNormalWidget->SetDelegate(this);\r
40     m_pNormalWidget->LockUpdate();\r
41     CFX_WideStringArray wsLabelArray;\r
42     m_pDataAcc->GetChoiceListItems(wsLabelArray, FALSE);\r
43     FX_INT32 iItems = wsLabelArray.GetSize();\r
44     for (FX_INT32 i = 0; i < iItems; i++) {\r
45         pListBox->AddString(wsLabelArray[i]);\r
46     }\r
47     FX_DWORD dwExtendedStyle = FWL_STYLEEXT_LTB_ShowScrollBarFocus;\r
48     if (m_pDataAcc->GetChoiceListOpen() == XFA_ATTRIBUTEENUM_MultiSelect) {\r
49         dwExtendedStyle |= FWL_STYLEEXT_LTB_MultiSelection;\r
50     }\r
51     dwExtendedStyle |= GetAlignment();\r
52     m_pNormalWidget->ModifyStylesEx(dwExtendedStyle, 0xFFFFFFFF);\r
53     CFX_Int32Array iSelArray;\r
54     m_pDataAcc->GetSelectedItems(iSelArray);\r
55     FX_INT32 iSelCount = iSelArray.GetSize();\r
56     for (FX_INT32 j = 0; j < iSelCount; j++) {\r
57         FWL_HLISTITEM item = pListBox->GetItem(iSelArray[j]);\r
58         pListBox->SetSelItem(item, TRUE);\r
59     }\r
60     m_pNormalWidget->UnlockUpdate();\r
61     return CXFA_FFField::LoadWidget();\r
62 }\r
63 FX_BOOL CXFA_FFListBox::OnKillFocus(CXFA_FFWidget* pNewFocus)\r
64 {\r
65     FX_BOOL flag = ProcessCommittedData();\r
66     if (!flag) {\r
67         UpdateFWLData();\r
68     }\r
69     CXFA_FFField::OnKillFocus(pNewFocus);\r
70     return TRUE;\r
71 }\r
72 FX_BOOL CXFA_FFListBox::CommitData()\r
73 {\r
74     FXSYS_assert(m_pNormalWidget != NULL);\r
75     CFWL_ListBox* pListBox = (CFWL_ListBox*)m_pNormalWidget;\r
76     FX_INT32 iSels = pListBox->CountSelItems();\r
77     CFX_Int32Array iSelArray;\r
78     for (FX_INT32 i = 0; i < iSels; i++) {\r
79         iSelArray.Add(pListBox->GetSelIndex(i));\r
80     }\r
81     m_pDataAcc->SetSelectdItems(iSelArray, TRUE);\r
82     return TRUE;\r
83 }\r
84 FX_BOOL CXFA_FFListBox::IsDataChanged()\r
85 {\r
86     CFX_Int32Array iSelArray;\r
87     m_pDataAcc->GetSelectedItems(iSelArray);\r
88     FX_INT32 iOldSels = iSelArray.GetSize();\r
89     CFWL_ListBox* pListBox = (CFWL_ListBox*)m_pNormalWidget;\r
90     FX_INT32 iSels = pListBox->CountSelItems();\r
91     if (iOldSels == iSels) {\r
92         FX_INT32 iIndex = 0;\r
93         for (; iIndex < iSels; iIndex++) {\r
94             FWL_HLISTITEM hlistItem = pListBox->GetItem(iSelArray[iIndex]);\r
95             if(!(pListBox->GetItemStates(hlistItem) && FWL_ITEMSTATE_LTB_Selected)) {\r
96                 break;\r
97             }\r
98         }\r
99         if (iIndex == iSels) {\r
100             return FALSE;\r
101         }\r
102     }\r
103     return TRUE;\r
104 }\r
105 FX_DWORD CXFA_FFListBox::GetAlignment()\r
106 {\r
107     FX_DWORD dwExtendedStyle = 0;\r
108     if (CXFA_Para para = m_pDataAcc->GetPara()) {\r
109         FX_INT32 iHorz = para.GetHorizontalAlign();\r
110         switch(iHorz) {\r
111             case XFA_ATTRIBUTEENUM_Center:\r
112                 dwExtendedStyle |= FWL_STYLEEXT_LTB_CenterAlign;\r
113                 break;\r
114             case XFA_ATTRIBUTEENUM_Justify:\r
115                 break;\r
116             case XFA_ATTRIBUTEENUM_JustifyAll:\r
117                 break;\r
118             case XFA_ATTRIBUTEENUM_Radix:\r
119                 break;\r
120             case XFA_ATTRIBUTEENUM_Right:\r
121                 dwExtendedStyle |= FWL_STYLEEXT_LTB_RightAlign;\r
122                 break;\r
123             default:\r
124                 dwExtendedStyle |= FWL_STYLEEXT_LTB_LeftAlign;\r
125                 break;\r
126         }\r
127     }\r
128     return dwExtendedStyle;\r
129 }\r
130 FX_BOOL CXFA_FFListBox::UpdateFWLData()\r
131 {\r
132     if (!m_pNormalWidget) {\r
133         return FALSE;\r
134     }\r
135     CFWL_ListBox* pListBox = ((CFWL_ListBox*)m_pNormalWidget);\r
136     CFX_ArrayTemplate<FWL_HLISTITEM> selItemArray;\r
137     CFX_Int32Array iSelArray;\r
138     m_pDataAcc->GetSelectedItems(iSelArray);\r
139     FX_INT32 iSelCount = iSelArray.GetSize();\r
140     for (FX_INT32 j = 0; j < iSelCount; j++) {\r
141         FWL_HLISTITEM lpItemSel = pListBox->GetSelItem(iSelArray[j]);\r
142         selItemArray.Add(lpItemSel);\r
143     }\r
144     pListBox->SetSelItem(pListBox->GetSelItem(-1), FALSE);\r
145     for(FX_INT32 i = 0; i < iSelCount; i++) {\r
146         ((CFWL_ListBox*)m_pNormalWidget)->SetSelItem(selItemArray[i], TRUE);\r
147     }\r
148     m_pNormalWidget->Update();\r
149     return TRUE;\r
150 }\r
151 void CXFA_FFListBox::OnSelectChanged(IFWL_Widget *pWidget, const CFX_Int32Array &arrSels)\r
152 {\r
153     CXFA_EventParam eParam;\r
154     eParam.m_eType = XFA_EVENT_Change;\r
155     eParam.m_pTarget = m_pDataAcc;\r
156     m_pDataAcc->GetValue(eParam.m_wsPrevText, XFA_VALUEPICTURE_Raw);\r
157     CFWL_ListBox* pListBox = (CFWL_ListBox*)m_pNormalWidget;\r
158     FX_INT32 iSels = pListBox->CountSelItems();\r
159     if (iSels > 0) {\r
160         pListBox->GetItemText(pListBox->GetSelItem(0), eParam.m_wsNewText);\r
161     }\r
162     m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_Change, &eParam);\r
163 }\r
164 void CXFA_FFListBox::SetItemState(FX_INT32 nIndex, FX_BOOL bSelected)\r
165 {\r
166     FWL_HLISTITEM item = ((CFWL_ListBox*)m_pNormalWidget)->GetSelItem(nIndex);\r
167     ((CFWL_ListBox*)m_pNormalWidget)->SetSelItem(item, bSelected);\r
168     m_pNormalWidget->Update();\r
169     AddInvalidateRect();\r
170 }\r
171 void CXFA_FFListBox::InsertItem(FX_WSTR wsLabel, FX_INT32 nIndex )\r
172 {\r
173     CFX_WideString wsTemp(wsLabel);\r
174     ((CFWL_ListBox*)m_pNormalWidget)->AddString(wsTemp);\r
175     m_pNormalWidget->Update();\r
176     AddInvalidateRect();\r
177 }\r
178 void CXFA_FFListBox::DeleteItem(FX_INT32 nIndex)\r
179 {\r
180     if (nIndex < 0) {\r
181         ((CFWL_ListBox*)m_pNormalWidget)->DeleteAll();\r
182     } else {\r
183         ((CFWL_ListBox*)m_pNormalWidget)->DeleteString(((CFWL_ListBox*)m_pNormalWidget)->GetItem(nIndex));\r
184     }\r
185     m_pNormalWidget->Update();\r
186     AddInvalidateRect();\r
187 }\r
188 FX_INT32 CXFA_FFListBox::OnProcessMessage(CFWL_Message *pMessage)\r
189 {\r
190     return m_pOldDelegate->OnProcessMessage(pMessage);\r
191 }\r
192 FWL_ERR CXFA_FFListBox::OnProcessEvent(CFWL_Event *pEvent)\r
193 {\r
194     CXFA_FFField::OnProcessEvent(pEvent);\r
195     FX_DWORD dwEventID = pEvent->GetClassID();\r
196     switch (dwEventID) {\r
197         case FWL_EVTHASH_LTB_SelChanged: {\r
198                 CFX_Int32Array arrSels;\r
199                 OnSelectChanged(m_pNormalWidget->GetWidget(), arrSels);\r
200                 break;\r
201             }\r
202         default: {\r
203             }\r
204     }\r
205     return m_pOldDelegate->OnProcessEvent(pEvent);\r
206 }\r
207 FWL_ERR CXFA_FFListBox::OnDrawWidget(CFX_Graphics *pGraphics, const CFX_Matrix *pMatrix )\r
208 {\r
209     return m_pOldDelegate->OnDrawWidget(pGraphics, pMatrix);\r
210 }\r
211 CXFA_FFComboBox::CXFA_FFComboBox(CXFA_FFPageView* pPageView, CXFA_WidgetAcc* pDataAcc)\r
212     : CXFA_FFField(pPageView, pDataAcc)\r
213     , m_pOldDelegate(NULL)\r
214 {\r
215 }\r
216 CXFA_FFComboBox::~CXFA_FFComboBox()\r
217 {\r
218 }\r
219 FX_BOOL CXFA_FFComboBox::GetBBox(CFX_RectF &rtBox, FX_DWORD dwStatus, FX_BOOL bDrawFocus)\r
220 {\r
221     if (bDrawFocus) {\r
222         return FALSE;\r
223     }\r
224 #ifndef _XFA_EMB\r
225     return CXFA_FFWidget::GetBBox(rtBox, dwStatus);\r
226 #endif\r
227     GetRectWithoutRotate(rtBox);\r
228     if (m_pNormalWidget) {\r
229         CFX_RectF rtWidget;\r
230         ((CFWL_ComboBox*)m_pNormalWidget)->GetBBox(rtWidget);\r
231         rtBox.Union(rtWidget);\r
232     }\r
233     CFX_Matrix mt;\r
234     GetRotateMatrix(mt);\r
235     mt.TransformRect(rtBox);\r
236     return TRUE;\r
237 }\r
238 FX_BOOL CXFA_FFComboBox::PtInActiveRect(FX_FLOAT fx, FX_FLOAT fy)\r
239 {\r
240     if (!m_pNormalWidget) {\r
241         return FALSE;\r
242     }\r
243     CFX_RectF rtWidget;\r
244     ((CFWL_ComboBox*)m_pNormalWidget)->GetBBox(rtWidget);\r
245     if (rtWidget.Contains(fx, fy)) {\r
246         return TRUE;\r
247     }\r
248     return FALSE;\r
249 }\r
250 FX_BOOL CXFA_FFComboBox::LoadWidget()\r
251 {\r
252     CFWL_ComboBox* pComboBox = CFWL_ComboBox::Create();\r
253     pComboBox->Initialize();\r
254     m_pNormalWidget = (CFWL_Widget*)pComboBox;\r
255     IFWL_Widget* pWidget = m_pNormalWidget->GetWidget();\r
256     m_pNormalWidget->SetPrivateData(pWidget, this, NULL);\r
257     IFWL_NoteDriver *pNoteDriver = FWL_GetApp()->GetNoteDriver();\r
258     pNoteDriver->RegisterEventTarget(pWidget, pWidget);\r
259     m_pOldDelegate = m_pNormalWidget->SetDelegate(this);\r
260     m_pNormalWidget->LockUpdate();\r
261     CFX_WideStringArray wsLabelArray;\r
262     m_pDataAcc->GetChoiceListItems(wsLabelArray, FALSE);\r
263     FX_INT32 iItems = wsLabelArray.GetSize();\r
264     for (FX_INT32 i = 0; i < iItems; i++) {\r
265         pComboBox->AddString(wsLabelArray[i]);\r
266     }\r
267     CFX_Int32Array iSelArray;\r
268     m_pDataAcc->GetSelectedItems(iSelArray);\r
269     FX_INT32 iSelCount = iSelArray.GetSize();\r
270     if (iSelCount > 0) {\r
271         pComboBox->SetCurSel(iSelArray[0]);\r
272     } else {\r
273         CFX_WideString wsText;\r
274         m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Raw);\r
275         pComboBox->SetEditText(wsText);\r
276     }\r
277     UpdateWidgetProperty();\r
278     m_pNormalWidget->UnlockUpdate();\r
279     return CXFA_FFField::LoadWidget();\r
280 }\r
281 void CXFA_FFComboBox::UpdateWidgetProperty()\r
282 {\r
283     CFWL_ComboBox* pComboBox = (CFWL_ComboBox*)m_pNormalWidget;\r
284     if (!pComboBox) {\r
285         return;\r
286     }\r
287     FX_DWORD dwExtendedStyle = 0;\r
288     FX_DWORD dwEditStyles = FWL_STYLEEXT_EDT_ReadOnly | FWL_STYLEEXT_EDT_LastLineHeight;\r
289     dwExtendedStyle |= UpdateUIProperty();\r
290     if (m_pDataAcc->IsChoiceListAllowTextEntry()) {\r
291         dwEditStyles &= ~FWL_STYLEEXT_EDT_ReadOnly;\r
292         dwExtendedStyle |= FWL_STYLEEXT_CMB_DropDown;\r
293     }\r
294     if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open || !m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) {\r
295         dwEditStyles |= FWL_STYLEEXT_EDT_ReadOnly;\r
296         dwExtendedStyle |= FWL_STYLEEXT_CMB_ReadOnly;\r
297     }\r
298     dwExtendedStyle |= GetAlignment();\r
299     m_pNormalWidget->ModifyStylesEx(dwExtendedStyle, 0xFFFFFFFF);\r
300     if (m_pDataAcc->GetHorizontalScrollPolicy() != XFA_ATTRIBUTEENUM_Off) {\r
301         dwEditStyles |= FWL_STYLEEXT_EDT_AutoHScroll;\r
302     }\r
303     pComboBox->EditModifyStylesEx(dwEditStyles, 0xFFFFFFFF);\r
304 }\r
305 FX_BOOL CXFA_FFComboBox::OnRButtonUp(FX_DWORD dwFlags, FX_FLOAT fx, FX_FLOAT fy)\r
306 {\r
307     if (!CXFA_FFField::OnRButtonUp(dwFlags, fx, fy)) {\r
308         return FALSE;\r
309     }\r
310     CFX_PointF pt;\r
311     pt.Set(fx, fy);\r
312     GetDoc()->GetDocProvider()->PopupMenu((XFA_HWIDGET)this, pt, NULL);\r
313     return TRUE;\r
314 }\r
315 FX_BOOL CXFA_FFComboBox::OnKillFocus(CXFA_FFWidget* pNewWidget)\r
316 {\r
317     FX_BOOL flag = ProcessCommittedData();\r
318     if (!flag) {\r
319         UpdateFWLData();\r
320     }\r
321     CXFA_FFField::OnKillFocus(pNewWidget);\r
322     return TRUE;\r
323 }\r
324 void CXFA_FFComboBox::OpenDropDownList()\r
325 {\r
326     ((CFWL_ComboBox*)m_pNormalWidget)->OpenDropDownList(TRUE);\r
327 }\r
328 FX_BOOL CXFA_FFComboBox::CommitData()\r
329 {\r
330     return m_pDataAcc->SetValue(m_wsNewValue, XFA_VALUEPICTURE_Raw);\r
331 }\r
332 FX_BOOL CXFA_FFComboBox::IsDataChanged()\r
333 {\r
334     CFWL_ComboBox* pFWLcombobox = ((CFWL_ComboBox*)m_pNormalWidget);\r
335     CFX_WideString wsText;\r
336     pFWLcombobox->GetEditText(wsText);\r
337     FX_INT32 iCursel = pFWLcombobox->GetCurSel();\r
338     if (iCursel >= 0) {\r
339         CFX_WideString wsSel;\r
340         pFWLcombobox->GetTextByIndex(iCursel, wsSel);\r
341         if (wsSel == wsText) {\r
342             m_pDataAcc->GetChoiceListItem(wsText, iCursel, TRUE);\r
343         }\r
344     }\r
345     CFX_WideString wsOldValue;\r
346     m_pDataAcc->GetValue(wsOldValue, XFA_VALUEPICTURE_Raw);\r
347     if (wsOldValue != wsText) {\r
348         m_wsNewValue = wsText;\r
349         return TRUE;\r
350     }\r
351     return FALSE;\r
352 }\r
353 void CXFA_FFComboBox::FWLEventSelChange(CXFA_EventParam* pParam)\r
354 {\r
355     pParam->m_eType = XFA_EVENT_Change;\r
356     pParam->m_pTarget = m_pDataAcc;\r
357     CFWL_ComboBox* pFWLcombobox = ((CFWL_ComboBox*)m_pNormalWidget);\r
358     pFWLcombobox->GetEditText(pParam->m_wsNewText);\r
359     m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_Change, pParam);\r
360 }\r
361 FX_DWORD CXFA_FFComboBox::GetAlignment()\r
362 {\r
363     FX_DWORD dwExtendedStyle = 0;\r
364     if (CXFA_Para para = m_pDataAcc->GetPara()) {\r
365         FX_INT32 iHorz = para.GetHorizontalAlign();\r
366         switch(iHorz) {\r
367             case XFA_ATTRIBUTEENUM_Center:\r
368                 dwExtendedStyle |= FWL_STYLEEXT_CMB_EditHCenter | FWL_STYLEEXT_CMB_ListItemCenterAlign;\r
369                 break;\r
370             case XFA_ATTRIBUTEENUM_Justify:\r
371                 dwExtendedStyle |= FWL_STYLEEXT_CMB_EditJustified;\r
372                 break;\r
373             case XFA_ATTRIBUTEENUM_JustifyAll:\r
374                 break;\r
375             case XFA_ATTRIBUTEENUM_Radix:\r
376                 break;\r
377             case XFA_ATTRIBUTEENUM_Right:\r
378                 break;\r
379             default:\r
380                 dwExtendedStyle |= FWL_STYLEEXT_CMB_EditHNear | FWL_STYLEEXT_CMB_ListItemLeftAlign;\r
381                 break;\r
382         }\r
383         FX_INT32 iVert = para.GetVerticalAlign();\r
384         switch(iVert) {\r
385             case XFA_ATTRIBUTEENUM_Middle:\r
386                 dwExtendedStyle |= FWL_STYLEEXT_CMB_EditVCenter;\r
387                 break;\r
388             case XFA_ATTRIBUTEENUM_Bottom:\r
389                 dwExtendedStyle |= FWL_STYLEEXT_CMB_EditVFar;\r
390                 break;\r
391             default:\r
392                 dwExtendedStyle |= FWL_STYLEEXT_CMB_EditVNear;\r
393                 break;\r
394         }\r
395     }\r
396     return dwExtendedStyle;\r
397 }\r
398 FX_BOOL CXFA_FFComboBox::UpdateFWLData()\r
399 {\r
400     if (!m_pNormalWidget) {\r
401         return FALSE;\r
402     }\r
403     CFX_Int32Array iSelArray;\r
404     m_pDataAcc->GetSelectedItems(iSelArray);\r
405     FX_INT32 iSelCount = iSelArray.GetSize();\r
406     if (iSelCount > 0) {\r
407         ((CFWL_ComboBox*)m_pNormalWidget)->SetCurSel(iSelArray[0]);\r
408     } else {\r
409         CFX_WideString wsText;\r
410         ((CFWL_ComboBox*)m_pNormalWidget)->SetCurSel(-1);\r
411         m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Raw);\r
412         ((CFWL_ComboBox*)m_pNormalWidget)->SetEditText(wsText);\r
413     }\r
414     m_pNormalWidget->Update();\r
415     return TRUE;\r
416 }\r
417 FX_BOOL CXFA_FFComboBox::CanUndo()\r
418 {\r
419     return m_pDataAcc->IsChoiceListAllowTextEntry() && ((CFWL_ComboBox*)m_pNormalWidget)->EditCanUndo();\r
420 }\r
421 FX_BOOL CXFA_FFComboBox::CanRedo()\r
422 {\r
423     return m_pDataAcc->IsChoiceListAllowTextEntry() && ((CFWL_ComboBox*)m_pNormalWidget)->EditCanRedo();\r
424 }\r
425 FX_BOOL CXFA_FFComboBox::Undo()\r
426 {\r
427     return m_pDataAcc->IsChoiceListAllowTextEntry() && ((CFWL_ComboBox*)m_pNormalWidget)->EditUndo();\r
428 }\r
429 FX_BOOL CXFA_FFComboBox::Redo()\r
430 {\r
431     return m_pDataAcc->IsChoiceListAllowTextEntry() && ((CFWL_ComboBox*)m_pNormalWidget)->EditRedo();\r
432 }\r
433 FX_BOOL CXFA_FFComboBox::CanCopy()\r
434 {\r
435     return ((CFWL_ComboBox*)m_pNormalWidget)->EditCanCopy();\r
436 }\r
437 FX_BOOL CXFA_FFComboBox::CanCut()\r
438 {\r
439     if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open) {\r
440         return FALSE;\r
441     }\r
442     return m_pDataAcc->IsChoiceListAllowTextEntry() && ((CFWL_ComboBox*)m_pNormalWidget)->EditCanCut();\r
443 }\r
444 FX_BOOL CXFA_FFComboBox::CanPaste()\r
445 {\r
446     return m_pDataAcc->IsChoiceListAllowTextEntry() && (m_pDataAcc->GetAccess() == XFA_ATTRIBUTEENUM_Open);\r
447 }\r
448 FX_BOOL CXFA_FFComboBox::CanSelectAll()\r
449 {\r
450     return ((CFWL_ComboBox*)m_pNormalWidget)->EditCanSelectAll();\r
451 }\r
452 FX_BOOL CXFA_FFComboBox::Copy(CFX_WideString &wsCopy)\r
453 {\r
454     return ((CFWL_ComboBox*)m_pNormalWidget)->EditCopy(wsCopy);\r
455 }\r
456 FX_BOOL CXFA_FFComboBox::Cut(CFX_WideString &wsCut)\r
457 {\r
458     return m_pDataAcc->IsChoiceListAllowTextEntry() && ((CFWL_ComboBox*)m_pNormalWidget)->EditCut(wsCut);\r
459 }\r
460 FX_BOOL CXFA_FFComboBox::Paste(const CFX_WideString &wsPaste)\r
461 {\r
462     return m_pDataAcc->IsChoiceListAllowTextEntry() && ((CFWL_ComboBox*)m_pNormalWidget)->EditPaste(wsPaste);\r
463 }\r
464 FX_BOOL CXFA_FFComboBox::SelectAll()\r
465 {\r
466     return ((CFWL_ComboBox*)m_pNormalWidget)->EditSelectAll();\r
467 }\r
468 FX_BOOL CXFA_FFComboBox::Delete()\r
469 {\r
470     return ((CFWL_ComboBox*)m_pNormalWidget)->EditDelete();\r
471 }\r
472 FX_BOOL CXFA_FFComboBox::DeSelect()\r
473 {\r
474     return ((CFWL_ComboBox*)m_pNormalWidget)->EditDeSelect();\r
475 }\r
476 void CXFA_FFComboBox::SetItemState(FX_INT32 nIndex, FX_BOOL bSelected)\r
477 {\r
478     if (bSelected) {\r
479         ((CFWL_ComboBox*)m_pNormalWidget)->SetCurSel(nIndex);\r
480     } else {\r
481         ((CFWL_ComboBox*)m_pNormalWidget)->SetCurSel(-1);\r
482     }\r
483     m_pNormalWidget->Update();\r
484     AddInvalidateRect();\r
485 }\r
486 void CXFA_FFComboBox::InsertItem(FX_WSTR wsLabel, FX_INT32 nIndex )\r
487 {\r
488     ((CFWL_ComboBox*)m_pNormalWidget)->AddString(wsLabel);\r
489     m_pNormalWidget->Update();\r
490     AddInvalidateRect();\r
491 }\r
492 void CXFA_FFComboBox::DeleteItem(FX_INT32 nIndex)\r
493 {\r
494     if (nIndex < 0) {\r
495         ((CFWL_ComboBox*)m_pNormalWidget)->RemoveAll();\r
496     } else {\r
497         ((CFWL_ComboBox*)m_pNormalWidget)->RemoveAt(nIndex);\r
498     }\r
499     m_pNormalWidget->Update();\r
500     AddInvalidateRect();\r
501 }\r
502 void CXFA_FFComboBox::OnTextChanged(IFWL_Widget *pWidget, const CFX_WideString &wsChanged)\r
503 {\r
504     CXFA_EventParam eParam;\r
505     m_pDataAcc->GetValue(eParam.m_wsPrevText, XFA_VALUEPICTURE_Raw);\r
506     eParam.m_wsChange = wsChanged;\r
507     FWLEventSelChange(&eParam);\r
508 }\r
509 void CXFA_FFComboBox::OnSelectChanged(IFWL_Widget *pWidget, const CFX_Int32Array &arrSels, FX_BOOL bLButtonUp)\r
510 {\r
511     CXFA_EventParam eParam;\r
512     m_pDataAcc->GetValue(eParam.m_wsPrevText, XFA_VALUEPICTURE_Raw);\r
513     FWLEventSelChange(&eParam);\r
514     if (m_pDataAcc->GetChoiceListCommitOn() == XFA_ATTRIBUTEENUM_Select && bLButtonUp) {\r
515         m_pDocView->SetFocusWidgetAcc(NULL);\r
516     }\r
517 }\r
518 void CXFA_FFComboBox::OnPreOpen(IFWL_Widget *pWidget)\r
519 {\r
520     CXFA_EventParam eParam;\r
521     eParam.m_eType = XFA_EVENT_PreOpen;\r
522     eParam.m_pTarget = m_pDataAcc;\r
523     m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_PreOpen, &eParam);\r
524 }\r
525 void CXFA_FFComboBox::OnPostOpen(IFWL_Widget *pWidget)\r
526 {\r
527     CXFA_EventParam eParam;\r
528     eParam.m_eType = XFA_EVENT_PostOpen;\r
529     eParam.m_pTarget = m_pDataAcc;\r
530     m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_PostOpen, &eParam);\r
531 }\r
532 void CXFA_FFComboBox::OnAddDoRecord(IFWL_Widget *pWidget)\r
533 {\r
534     GetDoc()->GetDocProvider()->AddDoRecord((XFA_HWIDGET)this);\r
535 }\r
536 FX_INT32 CXFA_FFComboBox::OnProcessMessage(CFWL_Message *pMessage)\r
537 {\r
538     return m_pOldDelegate->OnProcessMessage(pMessage);\r
539 }\r
540 FWL_ERR CXFA_FFComboBox::OnProcessEvent(CFWL_Event *pEvent)\r
541 {\r
542     CXFA_FFField::OnProcessEvent(pEvent);\r
543     FX_DWORD dwEventID = pEvent->GetClassID();\r
544     switch (dwEventID) {\r
545         case FWL_EVTHASH_CMB_SelChanged: {\r
546                 CFWL_EvtCmbSelChanged *postEvent = (CFWL_EvtCmbSelChanged*)pEvent;\r
547                 OnSelectChanged(m_pNormalWidget->GetWidget(), postEvent->iArraySels, postEvent->bLButtonUp);\r
548                 break;\r
549             }\r
550         case FWL_EVTHASH_CMB_EditChanged: {\r
551                 CFX_WideString wsChanged;\r
552                 OnTextChanged(m_pNormalWidget->GetWidget(), wsChanged);\r
553                 break;\r
554             }\r
555         case FWL_EVTHASH_CMB_PreDropDown: {\r
556                 OnPreOpen(m_pNormalWidget->GetWidget());\r
557                 break;\r
558             }\r
559         case FWL_EVTHASH_CMB_PostDropDown: {\r
560                 OnPostOpen(m_pNormalWidget->GetWidget());\r
561                 break;\r
562             }\r
563         default: {\r
564             }\r
565     }\r
566     return m_pOldDelegate->OnProcessEvent(pEvent);\r
567 }\r
568 FWL_ERR CXFA_FFComboBox::OnDrawWidget(CFX_Graphics *pGraphics, const CFX_Matrix *pMatrix )\r
569 {\r
570     return m_pOldDelegate->OnDrawWidget(pGraphics, pMatrix);\r
571 }\r