OLD | NEW |
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/fxfa/app/xfa_ffchoicelist.h" | 7 #include "xfa/fxfa/app/xfa_ffchoicelist.h" |
8 | 8 |
| 9 #include "third_party/base/ptr_util.h" |
9 #include "xfa/fwl/core/cfwl_combobox.h" | 10 #include "xfa/fwl/core/cfwl_combobox.h" |
10 #include "xfa/fwl/core/cfwl_listbox.h" | 11 #include "xfa/fwl/core/cfwl_listbox.h" |
11 #include "xfa/fwl/core/fwl_noteimp.h" | 12 #include "xfa/fwl/core/fwl_noteimp.h" |
12 #include "xfa/fwl/core/ifwl_app.h" | 13 #include "xfa/fwl/core/ifwl_app.h" |
13 #include "xfa/fwl/core/ifwl_edit.h" | 14 #include "xfa/fwl/core/ifwl_edit.h" |
| 15 #include "xfa/fxfa/app/cxfa_ffcomboboxdelegate.h" |
| 16 #include "xfa/fxfa/app/cxfa_fflistboxdelegate.h" |
14 #include "xfa/fxfa/app/xfa_fffield.h" | 17 #include "xfa/fxfa/app/xfa_fffield.h" |
15 #include "xfa/fxfa/app/xfa_fwladapter.h" | 18 #include "xfa/fxfa/app/xfa_fwladapter.h" |
16 #include "xfa/fxfa/cxfa_eventparam.h" | 19 #include "xfa/fxfa/cxfa_eventparam.h" |
17 #include "xfa/fxfa/xfa_ffdoc.h" | 20 #include "xfa/fxfa/xfa_ffdoc.h" |
18 #include "xfa/fxfa/xfa_ffdocview.h" | 21 #include "xfa/fxfa/xfa_ffdocview.h" |
19 #include "xfa/fxfa/xfa_ffpageview.h" | 22 #include "xfa/fxfa/xfa_ffpageview.h" |
20 #include "xfa/fxfa/xfa_ffwidget.h" | 23 #include "xfa/fxfa/xfa_ffwidget.h" |
21 | 24 |
22 CXFA_FFListBox::CXFA_FFListBox(CXFA_FFPageView* pPageView, | 25 CXFA_FFListBox::CXFA_FFListBox(CXFA_FFPageView* pPageView, |
23 CXFA_WidgetAcc* pDataAcc) | 26 CXFA_WidgetAcc* pDataAcc) |
24 : CXFA_FFField(pPageView, pDataAcc), m_pOldDelegate(nullptr) {} | 27 : CXFA_FFField(pPageView, pDataAcc) {} |
25 | 28 |
26 CXFA_FFListBox::~CXFA_FFListBox() { | 29 CXFA_FFListBox::~CXFA_FFListBox() { |
27 if (m_pNormalWidget) { | 30 if (m_pNormalWidget) { |
28 IFWL_Widget* pWidget = m_pNormalWidget->GetWidget(); | 31 IFWL_Widget* pWidget = m_pNormalWidget->GetWidget(); |
29 CFWL_NoteDriver* pNoteDriver = pWidget->GetOwnerApp()->GetNoteDriver(); | 32 CFWL_NoteDriver* pNoteDriver = pWidget->GetOwnerApp()->GetNoteDriver(); |
30 pNoteDriver->UnregisterEventTarget(pWidget); | 33 pNoteDriver->UnregisterEventTarget(pWidget); |
31 } | 34 } |
32 } | 35 } |
33 | 36 |
34 FX_BOOL CXFA_FFListBox::LoadWidget() { | 37 FX_BOOL CXFA_FFListBox::LoadWidget() { |
35 CFWL_ListBox* pListBox = new CFWL_ListBox(GetFWLApp()); | 38 CFWL_ListBox* pListBox = new CFWL_ListBox(GetFWLApp()); |
36 pListBox->Initialize(); | 39 pListBox->Initialize(); |
37 pListBox->ModifyStyles(FWL_WGTSTYLE_VScroll | FWL_WGTSTYLE_NoBackground, | 40 pListBox->ModifyStyles(FWL_WGTSTYLE_VScroll | FWL_WGTSTYLE_NoBackground, |
38 0xFFFFFFFF); | 41 0xFFFFFFFF); |
39 m_pNormalWidget = (CFWL_Widget*)pListBox; | 42 m_pNormalWidget = (CFWL_Widget*)pListBox; |
40 m_pNormalWidget->SetLayoutItem(this); | 43 m_pNormalWidget->SetLayoutItem(this); |
41 | 44 |
42 IFWL_Widget* pWidget = m_pNormalWidget->GetWidget(); | 45 IFWL_Widget* pWidget = m_pNormalWidget->GetWidget(); |
43 CFWL_NoteDriver* pNoteDriver = pWidget->GetOwnerApp()->GetNoteDriver(); | 46 CFWL_NoteDriver* pNoteDriver = pWidget->GetOwnerApp()->GetNoteDriver(); |
44 pNoteDriver->RegisterEventTarget(pWidget, pWidget); | 47 pNoteDriver->RegisterEventTarget(pWidget, pWidget); |
45 | 48 |
46 m_pOldDelegate = m_pNormalWidget->GetCurrentDelegate(); | 49 m_pNormalWidget->SetDelegate(pdfium::MakeUnique<CXFA_FFListBoxDelegate>( |
47 m_pNormalWidget->SetCurrentDelegate(this); | 50 m_pNormalWidget->ReleaseDelegate(), this)); |
48 m_pNormalWidget->LockUpdate(); | 51 m_pNormalWidget->LockUpdate(); |
49 | 52 |
50 CFX_WideStringArray wsLabelArray; | 53 CFX_WideStringArray wsLabelArray; |
51 m_pDataAcc->GetChoiceListItems(wsLabelArray, FALSE); | 54 m_pDataAcc->GetChoiceListItems(wsLabelArray, FALSE); |
52 int32_t iItems = wsLabelArray.GetSize(); | 55 int32_t iItems = wsLabelArray.GetSize(); |
53 for (int32_t i = 0; i < iItems; i++) { | 56 for (int32_t i = 0; i < iItems; i++) { |
54 pListBox->AddString(wsLabelArray[i].AsStringC()); | 57 pListBox->AddString(wsLabelArray[i].AsStringC()); |
55 } | 58 } |
56 uint32_t dwExtendedStyle = FWL_STYLEEXT_LTB_ShowScrollBarFocus; | 59 uint32_t dwExtendedStyle = FWL_STYLEEXT_LTB_ShowScrollBarFocus; |
57 if (m_pDataAcc->GetChoiceListOpen() == XFA_ATTRIBUTEENUM_MultiSelect) { | 60 if (m_pDataAcc->GetChoiceListOpen() == XFA_ATTRIBUTEENUM_MultiSelect) { |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 if (nIndex < 0) { | 181 if (nIndex < 0) { |
179 ((CFWL_ListBox*)m_pNormalWidget)->DeleteAll(); | 182 ((CFWL_ListBox*)m_pNormalWidget)->DeleteAll(); |
180 } else { | 183 } else { |
181 ((CFWL_ListBox*)m_pNormalWidget) | 184 ((CFWL_ListBox*)m_pNormalWidget) |
182 ->DeleteString(((CFWL_ListBox*)m_pNormalWidget)->GetItem(nIndex)); | 185 ->DeleteString(((CFWL_ListBox*)m_pNormalWidget)->GetItem(nIndex)); |
183 } | 186 } |
184 m_pNormalWidget->Update(); | 187 m_pNormalWidget->Update(); |
185 AddInvalidateRect(); | 188 AddInvalidateRect(); |
186 } | 189 } |
187 | 190 |
188 void CXFA_FFListBox::OnProcessMessage(CFWL_Message* pMessage) { | |
189 m_pOldDelegate->OnProcessMessage(pMessage); | |
190 } | |
191 | |
192 void CXFA_FFListBox::OnProcessEvent(CFWL_Event* pEvent) { | |
193 CXFA_FFField::OnProcessEvent(pEvent); | |
194 switch (pEvent->GetClassID()) { | |
195 case CFWL_EventType::SelectChanged: { | |
196 CFX_Int32Array arrSels; | |
197 OnSelectChanged(m_pNormalWidget->GetWidget(), arrSels); | |
198 break; | |
199 } | |
200 default: | |
201 break; | |
202 } | |
203 m_pOldDelegate->OnProcessEvent(pEvent); | |
204 } | |
205 void CXFA_FFListBox::OnDrawWidget(CFX_Graphics* pGraphics, | |
206 const CFX_Matrix* pMatrix) { | |
207 m_pOldDelegate->OnDrawWidget(pGraphics, pMatrix); | |
208 } | |
209 | |
210 CXFA_FFComboBox::CXFA_FFComboBox(CXFA_FFPageView* pPageView, | 191 CXFA_FFComboBox::CXFA_FFComboBox(CXFA_FFPageView* pPageView, |
211 CXFA_WidgetAcc* pDataAcc) | 192 CXFA_WidgetAcc* pDataAcc) |
212 : CXFA_FFField(pPageView, pDataAcc), m_pOldDelegate(nullptr) {} | 193 : CXFA_FFField(pPageView, pDataAcc) {} |
213 | 194 |
214 CXFA_FFComboBox::~CXFA_FFComboBox() {} | 195 CXFA_FFComboBox::~CXFA_FFComboBox() {} |
215 | 196 |
216 FX_BOOL CXFA_FFComboBox::GetBBox(CFX_RectF& rtBox, | 197 FX_BOOL CXFA_FFComboBox::GetBBox(CFX_RectF& rtBox, |
217 uint32_t dwStatus, | 198 uint32_t dwStatus, |
218 FX_BOOL bDrawFocus) { | 199 FX_BOOL bDrawFocus) { |
219 if (bDrawFocus) | 200 if (bDrawFocus) |
220 return FALSE; | 201 return FALSE; |
221 return CXFA_FFWidget::GetBBox(rtBox, dwStatus); | 202 return CXFA_FFWidget::GetBBox(rtBox, dwStatus); |
222 } | 203 } |
(...skipping 12 matching lines...) Expand all Loading... |
235 FX_BOOL CXFA_FFComboBox::LoadWidget() { | 216 FX_BOOL CXFA_FFComboBox::LoadWidget() { |
236 CFWL_ComboBox* pComboBox = new CFWL_ComboBox(GetFWLApp()); | 217 CFWL_ComboBox* pComboBox = new CFWL_ComboBox(GetFWLApp()); |
237 pComboBox->Initialize(); | 218 pComboBox->Initialize(); |
238 m_pNormalWidget = (CFWL_Widget*)pComboBox; | 219 m_pNormalWidget = (CFWL_Widget*)pComboBox; |
239 m_pNormalWidget->SetLayoutItem(this); | 220 m_pNormalWidget->SetLayoutItem(this); |
240 | 221 |
241 IFWL_Widget* pWidget = m_pNormalWidget->GetWidget(); | 222 IFWL_Widget* pWidget = m_pNormalWidget->GetWidget(); |
242 CFWL_NoteDriver* pNoteDriver = pWidget->GetOwnerApp()->GetNoteDriver(); | 223 CFWL_NoteDriver* pNoteDriver = pWidget->GetOwnerApp()->GetNoteDriver(); |
243 pNoteDriver->RegisterEventTarget(pWidget, pWidget); | 224 pNoteDriver->RegisterEventTarget(pWidget, pWidget); |
244 | 225 |
245 m_pOldDelegate = m_pNormalWidget->GetCurrentDelegate(); | 226 m_pNormalWidget->SetDelegate(pdfium::MakeUnique<CXFA_FFComboBoxDelegate>( |
246 m_pNormalWidget->SetCurrentDelegate(this); | 227 m_pNormalWidget->ReleaseDelegate(), this)); |
247 m_pNormalWidget->LockUpdate(); | 228 m_pNormalWidget->LockUpdate(); |
248 | 229 |
249 CFX_WideStringArray wsLabelArray; | 230 CFX_WideStringArray wsLabelArray; |
250 m_pDataAcc->GetChoiceListItems(wsLabelArray, FALSE); | 231 m_pDataAcc->GetChoiceListItems(wsLabelArray, FALSE); |
251 int32_t iItems = wsLabelArray.GetSize(); | 232 int32_t iItems = wsLabelArray.GetSize(); |
252 for (int32_t i = 0; i < iItems; i++) { | 233 for (int32_t i = 0; i < iItems; i++) { |
253 pComboBox->AddString(wsLabelArray[i].AsStringC()); | 234 pComboBox->AddString(wsLabelArray[i].AsStringC()); |
254 } | 235 } |
255 CFX_Int32Array iSelArray; | 236 CFX_Int32Array iSelArray; |
256 m_pDataAcc->GetSelectedItems(iSelArray); | 237 m_pDataAcc->GetSelectedItems(iSelArray); |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 eParam.m_eType = XFA_EVENT_PreOpen; | 478 eParam.m_eType = XFA_EVENT_PreOpen; |
498 eParam.m_pTarget = m_pDataAcc; | 479 eParam.m_pTarget = m_pDataAcc; |
499 m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_PreOpen, &eParam); | 480 m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_PreOpen, &eParam); |
500 } | 481 } |
501 void CXFA_FFComboBox::OnPostOpen(IFWL_Widget* pWidget) { | 482 void CXFA_FFComboBox::OnPostOpen(IFWL_Widget* pWidget) { |
502 CXFA_EventParam eParam; | 483 CXFA_EventParam eParam; |
503 eParam.m_eType = XFA_EVENT_PostOpen; | 484 eParam.m_eType = XFA_EVENT_PostOpen; |
504 eParam.m_pTarget = m_pDataAcc; | 485 eParam.m_pTarget = m_pDataAcc; |
505 m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_PostOpen, &eParam); | 486 m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_PostOpen, &eParam); |
506 } | 487 } |
507 | |
508 void CXFA_FFComboBox::OnProcessMessage(CFWL_Message* pMessage) { | |
509 m_pOldDelegate->OnProcessMessage(pMessage); | |
510 } | |
511 | |
512 void CXFA_FFComboBox::OnProcessEvent(CFWL_Event* pEvent) { | |
513 CXFA_FFField::OnProcessEvent(pEvent); | |
514 switch (pEvent->GetClassID()) { | |
515 case CFWL_EventType::SelectChanged: { | |
516 CFWL_EvtCmbSelChanged* postEvent = (CFWL_EvtCmbSelChanged*)pEvent; | |
517 OnSelectChanged(m_pNormalWidget->GetWidget(), postEvent->iArraySels, | |
518 postEvent->bLButtonUp); | |
519 break; | |
520 } | |
521 case CFWL_EventType::EditChanged: { | |
522 CFX_WideString wsChanged; | |
523 OnTextChanged(m_pNormalWidget->GetWidget(), wsChanged); | |
524 break; | |
525 } | |
526 case CFWL_EventType::PreDropDown: { | |
527 OnPreOpen(m_pNormalWidget->GetWidget()); | |
528 break; | |
529 } | |
530 case CFWL_EventType::PostDropDown: { | |
531 OnPostOpen(m_pNormalWidget->GetWidget()); | |
532 break; | |
533 } | |
534 default: | |
535 break; | |
536 } | |
537 m_pOldDelegate->OnProcessEvent(pEvent); | |
538 } | |
539 | |
540 void CXFA_FFComboBox::OnDrawWidget(CFX_Graphics* pGraphics, | |
541 const CFX_Matrix* pMatrix) { | |
542 m_pOldDelegate->OnDrawWidget(pGraphics, pMatrix); | |
543 } | |
OLD | NEW |