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/fwl/core/ifwl_combobox.h" | 7 #include "xfa/fwl/core/ifwl_combobox.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
11 #include <utility> | 11 #include <utility> |
12 | 12 |
13 #include "third_party/base/ptr_util.h" | 13 #include "third_party/base/ptr_util.h" |
14 #include "xfa/fde/cfde_txtedtengine.h" | 14 #include "xfa/fde/cfde_txtedtengine.h" |
15 #include "xfa/fde/tto/fde_textout.h" | 15 #include "xfa/fde/tto/fde_textout.h" |
16 #include "xfa/fwl/core/cfwl_app.h" | 16 #include "xfa/fwl/core/cfwl_app.h" |
17 #include "xfa/fwl/core/cfwl_evteditchanged.h" | 17 #include "xfa/fwl/core/cfwl_evteditchanged.h" |
18 #include "xfa/fwl/core/cfwl_evtpostdropdown.h" | 18 #include "xfa/fwl/core/cfwl_evtpostdropdown.h" |
19 #include "xfa/fwl/core/cfwl_evtpredropdown.h" | 19 #include "xfa/fwl/core/cfwl_evtpredropdown.h" |
20 #include "xfa/fwl/core/cfwl_evtselectchanged.h" | 20 #include "xfa/fwl/core/cfwl_evtselectchanged.h" |
21 #include "xfa/fwl/core/cfwl_evttextchanged.h" | 21 #include "xfa/fwl/core/cfwl_evttextchanged.h" |
| 22 #include "xfa/fwl/core/cfwl_formproxy.h" |
22 #include "xfa/fwl/core/cfwl_msgkey.h" | 23 #include "xfa/fwl/core/cfwl_msgkey.h" |
23 #include "xfa/fwl/core/cfwl_msgkillfocus.h" | 24 #include "xfa/fwl/core/cfwl_msgkillfocus.h" |
24 #include "xfa/fwl/core/cfwl_msgmouse.h" | 25 #include "xfa/fwl/core/cfwl_msgmouse.h" |
25 #include "xfa/fwl/core/cfwl_msgsetfocus.h" | 26 #include "xfa/fwl/core/cfwl_msgsetfocus.h" |
26 #include "xfa/fwl/core/cfwl_notedriver.h" | 27 #include "xfa/fwl/core/cfwl_notedriver.h" |
27 #include "xfa/fwl/core/cfwl_themebackground.h" | 28 #include "xfa/fwl/core/cfwl_themebackground.h" |
28 #include "xfa/fwl/core/cfwl_themepart.h" | 29 #include "xfa/fwl/core/cfwl_themepart.h" |
29 #include "xfa/fwl/core/cfwl_themetext.h" | 30 #include "xfa/fwl/core/cfwl_themetext.h" |
30 #include "xfa/fwl/core/cfwl_widgetmgr.h" | 31 #include "xfa/fwl/core/cfwl_widgetmgr.h" |
31 #include "xfa/fwl/core/ifwl_formproxy.h" | |
32 #include "xfa/fwl/core/ifwl_listbox.h" | 32 #include "xfa/fwl/core/ifwl_listbox.h" |
33 #include "xfa/fwl/core/ifwl_themeprovider.h" | 33 #include "xfa/fwl/core/ifwl_themeprovider.h" |
34 | 34 |
35 IFWL_ComboBox::IFWL_ComboBox(const CFWL_App* app, | 35 IFWL_ComboBox::IFWL_ComboBox(const CFWL_App* app, |
36 std::unique_ptr<CFWL_WidgetProperties> properties) | 36 std::unique_ptr<CFWL_WidgetProperties> properties) |
37 : IFWL_Widget(app, std::move(properties), nullptr), | 37 : IFWL_Widget(app, std::move(properties), nullptr), |
38 m_pComboBoxProxy(nullptr), | 38 m_pComboBoxProxy(nullptr), |
39 m_bLButtonDown(false), | 39 m_bLButtonDown(false), |
40 m_iCurSel(-1), | 40 m_iCurSel(-1), |
41 m_iBtnState(CFWL_PartState_Normal), | 41 m_iBtnState(CFWL_PartState_Normal), |
42 m_fComboFormHandler(0) { | 42 m_fComboFormHandler(0) { |
43 m_rtClient.Reset(); | 43 m_rtClient.Reset(); |
44 m_rtBtn.Reset(); | 44 m_rtBtn.Reset(); |
45 m_rtHandler.Reset(); | 45 m_rtHandler.Reset(); |
46 | 46 |
47 if (m_pWidgetMgr->IsFormDisabled()) { | 47 if (m_pWidgetMgr->IsFormDisabled()) { |
48 DisForm_InitComboList(); | 48 DisForm_InitComboList(); |
49 DisForm_InitComboEdit(); | 49 DisForm_InitComboEdit(); |
50 return; | 50 return; |
51 } | 51 } |
52 | 52 |
53 auto prop = pdfium::MakeUnique<CFWL_WidgetProperties>(); | 53 auto prop = pdfium::MakeUnique<CFWL_WidgetProperties>(); |
54 prop->m_pThemeProvider = m_pProperties->m_pThemeProvider; | 54 prop->m_pThemeProvider = m_pProperties->m_pThemeProvider; |
55 prop->m_dwStyles |= FWL_WGTSTYLE_Border | FWL_WGTSTYLE_VScroll; | 55 prop->m_dwStyles |= FWL_WGTSTYLE_Border | FWL_WGTSTYLE_VScroll; |
56 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_ListItemIconText) | 56 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_ListItemIconText) |
57 prop->m_dwStyleExes |= FWL_STYLEEXT_LTB_Icon; | 57 prop->m_dwStyleExes |= FWL_STYLEEXT_LTB_Icon; |
58 m_pListBox = | 58 m_pListBox = |
59 pdfium::MakeUnique<IFWL_ComboList>(m_pOwnerApp, std::move(prop), this); | 59 pdfium::MakeUnique<CFWL_ComboList>(m_pOwnerApp, std::move(prop), this); |
60 | 60 |
61 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_DropDown) && !m_pEdit) { | 61 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_DropDown) && !m_pEdit) { |
62 m_pEdit.reset(new IFWL_ComboEdit( | 62 m_pEdit.reset(new CFWL_ComboEdit( |
63 m_pOwnerApp, pdfium::MakeUnique<CFWL_WidgetProperties>(), this)); | 63 m_pOwnerApp, pdfium::MakeUnique<CFWL_WidgetProperties>(), this)); |
64 m_pEdit->SetOuter(this); | 64 m_pEdit->SetOuter(this); |
65 } | 65 } |
66 if (m_pEdit) | 66 if (m_pEdit) |
67 m_pEdit->SetParent(this); | 67 m_pEdit->SetParent(this); |
68 | 68 |
69 SetStates(m_pProperties->m_dwStates); | 69 SetStates(m_pProperties->m_dwStates); |
70 } | 70 } |
71 | 71 |
72 IFWL_ComboBox::~IFWL_ComboBox() {} | 72 IFWL_ComboBox::~IFWL_ComboBox() {} |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 void IFWL_ComboBox::ModifyStylesEx(uint32_t dwStylesExAdded, | 115 void IFWL_ComboBox::ModifyStylesEx(uint32_t dwStylesExAdded, |
116 uint32_t dwStylesExRemoved) { | 116 uint32_t dwStylesExRemoved) { |
117 if (m_pWidgetMgr->IsFormDisabled()) { | 117 if (m_pWidgetMgr->IsFormDisabled()) { |
118 DisForm_ModifyStylesEx(dwStylesExAdded, dwStylesExRemoved); | 118 DisForm_ModifyStylesEx(dwStylesExAdded, dwStylesExRemoved); |
119 return; | 119 return; |
120 } | 120 } |
121 | 121 |
122 bool bAddDropDown = !!(dwStylesExAdded & FWL_STYLEEXT_CMB_DropDown); | 122 bool bAddDropDown = !!(dwStylesExAdded & FWL_STYLEEXT_CMB_DropDown); |
123 bool bRemoveDropDown = !!(dwStylesExRemoved & FWL_STYLEEXT_CMB_DropDown); | 123 bool bRemoveDropDown = !!(dwStylesExRemoved & FWL_STYLEEXT_CMB_DropDown); |
124 if (bAddDropDown && !m_pEdit) { | 124 if (bAddDropDown && !m_pEdit) { |
125 m_pEdit = pdfium::MakeUnique<IFWL_ComboEdit>( | 125 m_pEdit = pdfium::MakeUnique<CFWL_ComboEdit>( |
126 m_pOwnerApp, pdfium::MakeUnique<CFWL_WidgetProperties>(), nullptr); | 126 m_pOwnerApp, pdfium::MakeUnique<CFWL_WidgetProperties>(), nullptr); |
127 m_pEdit->SetOuter(this); | 127 m_pEdit->SetOuter(this); |
128 m_pEdit->SetParent(this); | 128 m_pEdit->SetParent(this); |
129 } else if (bRemoveDropDown && m_pEdit) { | 129 } else if (bRemoveDropDown && m_pEdit) { |
130 m_pEdit->SetStates(FWL_WGTSTATE_Invisible, true); | 130 m_pEdit->SetStates(FWL_WGTSTATE_Invisible, true); |
131 } | 131 } |
132 IFWL_Widget::ModifyStylesEx(dwStylesExAdded, dwStylesExRemoved); | 132 IFWL_Widget::ModifyStylesEx(dwStylesExAdded, dwStylesExRemoved); |
133 } | 133 } |
134 | 134 |
135 void IFWL_ComboBox::Update() { | 135 void IFWL_ComboBox::Update() { |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 if (!m_pListBox) | 574 if (!m_pListBox) |
575 return; | 575 return; |
576 | 576 |
577 auto prop = pdfium::MakeUnique<CFWL_WidgetProperties>(); | 577 auto prop = pdfium::MakeUnique<CFWL_WidgetProperties>(); |
578 prop->m_pOwner = this; | 578 prop->m_pOwner = this; |
579 prop->m_dwStyles = FWL_WGTSTYLE_Popup; | 579 prop->m_dwStyles = FWL_WGTSTYLE_Popup; |
580 prop->m_dwStates = FWL_WGTSTATE_Invisible; | 580 prop->m_dwStates = FWL_WGTSTATE_Invisible; |
581 | 581 |
582 // TODO(dsinclair): Does this leak? I don't see a delete, but I'm not sure | 582 // TODO(dsinclair): Does this leak? I don't see a delete, but I'm not sure |
583 // if the SetParent call is going to transfer ownership. | 583 // if the SetParent call is going to transfer ownership. |
584 m_pComboBoxProxy = new IFWL_ComboBoxProxy(this, m_pOwnerApp, std::move(prop), | 584 m_pComboBoxProxy = new CFWL_ComboBoxProxy(this, m_pOwnerApp, std::move(prop), |
585 m_pListBox.get()); | 585 m_pListBox.get()); |
586 m_pListBox->SetParent(m_pComboBoxProxy); | 586 m_pListBox->SetParent(m_pComboBoxProxy); |
587 } | 587 } |
588 | 588 |
589 void IFWL_ComboBox::DisForm_InitComboList() { | 589 void IFWL_ComboBox::DisForm_InitComboList() { |
590 if (m_pListBox) | 590 if (m_pListBox) |
591 return; | 591 return; |
592 | 592 |
593 auto prop = pdfium::MakeUnique<CFWL_WidgetProperties>(); | 593 auto prop = pdfium::MakeUnique<CFWL_WidgetProperties>(); |
594 prop->m_pParent = this; | 594 prop->m_pParent = this; |
595 prop->m_dwStyles = FWL_WGTSTYLE_Border | FWL_WGTSTYLE_VScroll; | 595 prop->m_dwStyles = FWL_WGTSTYLE_Border | FWL_WGTSTYLE_VScroll; |
596 prop->m_dwStates = FWL_WGTSTATE_Invisible; | 596 prop->m_dwStates = FWL_WGTSTATE_Invisible; |
597 prop->m_pThemeProvider = m_pProperties->m_pThemeProvider; | 597 prop->m_pThemeProvider = m_pProperties->m_pThemeProvider; |
598 m_pListBox = | 598 m_pListBox = |
599 pdfium::MakeUnique<IFWL_ComboList>(m_pOwnerApp, std::move(prop), this); | 599 pdfium::MakeUnique<CFWL_ComboList>(m_pOwnerApp, std::move(prop), this); |
600 } | 600 } |
601 | 601 |
602 void IFWL_ComboBox::DisForm_InitComboEdit() { | 602 void IFWL_ComboBox::DisForm_InitComboEdit() { |
603 if (m_pEdit) | 603 if (m_pEdit) |
604 return; | 604 return; |
605 | 605 |
606 auto prop = pdfium::MakeUnique<CFWL_WidgetProperties>(); | 606 auto prop = pdfium::MakeUnique<CFWL_WidgetProperties>(); |
607 prop->m_pParent = this; | 607 prop->m_pParent = this; |
608 prop->m_pThemeProvider = m_pProperties->m_pThemeProvider; | 608 prop->m_pThemeProvider = m_pProperties->m_pThemeProvider; |
609 | 609 |
610 m_pEdit = | 610 m_pEdit = |
611 pdfium::MakeUnique<IFWL_ComboEdit>(m_pOwnerApp, std::move(prop), this); | 611 pdfium::MakeUnique<CFWL_ComboEdit>(m_pOwnerApp, std::move(prop), this); |
612 m_pEdit->SetOuter(this); | 612 m_pEdit->SetOuter(this); |
613 } | 613 } |
614 | 614 |
615 void IFWL_ComboBox::DisForm_ShowDropList(bool bActivate) { | 615 void IFWL_ComboBox::DisForm_ShowDropList(bool bActivate) { |
616 if (DisForm_IsDropListVisible() == bActivate) | 616 if (DisForm_IsDropListVisible() == bActivate) |
617 return; | 617 return; |
618 | 618 |
619 if (bActivate) { | 619 if (bActivate) { |
620 CFWL_EvtPreDropDown preEvent; | 620 CFWL_EvtPreDropDown preEvent; |
621 preEvent.m_pSrcTarget = this; | 621 preEvent.m_pSrcTarget = this; |
622 DispatchEvent(&preEvent); | 622 DispatchEvent(&preEvent); |
623 | 623 |
624 IFWL_ComboList* pComboList = m_pListBox.get(); | 624 CFWL_ComboList* pComboList = m_pListBox.get(); |
625 int32_t iItems = pComboList->CountItems(nullptr); | 625 int32_t iItems = pComboList->CountItems(nullptr); |
626 if (iItems < 1) | 626 if (iItems < 1) |
627 return; | 627 return; |
628 | 628 |
629 ResetListItemAlignment(); | 629 ResetListItemAlignment(); |
630 pComboList->ChangeSelected(m_iCurSel); | 630 pComboList->ChangeSelected(m_iCurSel); |
631 | 631 |
632 FX_FLOAT fItemHeight = pComboList->CalcItemHeight(); | 632 FX_FLOAT fItemHeight = pComboList->CalcItemHeight(); |
633 FX_FLOAT fBorder = GetBorderSize(); | 633 FX_FLOAT fBorder = GetBorderSize(); |
634 FX_FLOAT fPopupMin = 0.0f; | 634 FX_FLOAT fPopupMin = 0.0f; |
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1086 msg.m_pSrcTarget = m_pEdit.get(); | 1086 msg.m_pSrcTarget = m_pEdit.get(); |
1087 m_pEdit->GetDelegate()->OnProcessMessage(&msg); | 1087 m_pEdit->GetDelegate()->OnProcessMessage(&msg); |
1088 } | 1088 } |
1089 } | 1089 } |
1090 | 1090 |
1091 void IFWL_ComboBox::DisForm_OnKey(CFWL_MsgKey* pMsg) { | 1091 void IFWL_ComboBox::DisForm_OnKey(CFWL_MsgKey* pMsg) { |
1092 uint32_t dwKeyCode = pMsg->m_dwKeyCode; | 1092 uint32_t dwKeyCode = pMsg->m_dwKeyCode; |
1093 const bool bUp = dwKeyCode == FWL_VKEY_Up; | 1093 const bool bUp = dwKeyCode == FWL_VKEY_Up; |
1094 const bool bDown = dwKeyCode == FWL_VKEY_Down; | 1094 const bool bDown = dwKeyCode == FWL_VKEY_Down; |
1095 if (bUp || bDown) { | 1095 if (bUp || bDown) { |
1096 IFWL_ComboList* pComboList = m_pListBox.get(); | 1096 CFWL_ComboList* pComboList = m_pListBox.get(); |
1097 int32_t iCount = pComboList->CountItems(nullptr); | 1097 int32_t iCount = pComboList->CountItems(nullptr); |
1098 if (iCount < 1) | 1098 if (iCount < 1) |
1099 return; | 1099 return; |
1100 | 1100 |
1101 bool bMatchEqual = false; | 1101 bool bMatchEqual = false; |
1102 int32_t iCurSel = m_iCurSel; | 1102 int32_t iCurSel = m_iCurSel; |
1103 if (m_pEdit) { | 1103 if (m_pEdit) { |
1104 CFX_WideString wsText; | 1104 CFX_WideString wsText; |
1105 m_pEdit->GetText(wsText); | 1105 m_pEdit->GetText(wsText); |
1106 iCurSel = pComboList->MatchItem(wsText); | 1106 iCurSel = pComboList->MatchItem(wsText); |
(...skipping 14 matching lines...) Expand all Loading... |
1121 else | 1121 else |
1122 iCurSel++; | 1122 iCurSel++; |
1123 } | 1123 } |
1124 m_iCurSel = iCurSel; | 1124 m_iCurSel = iCurSel; |
1125 SyncEditText(m_iCurSel); | 1125 SyncEditText(m_iCurSel); |
1126 return; | 1126 return; |
1127 } | 1127 } |
1128 if (m_pEdit) | 1128 if (m_pEdit) |
1129 m_pEdit->GetDelegate()->OnProcessMessage(pMsg); | 1129 m_pEdit->GetDelegate()->OnProcessMessage(pMsg); |
1130 } | 1130 } |
OLD | NEW |