John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 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. |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 4 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
Dan Sinclair | edbb319 | 2016-03-21 09:08:24 -0400 | [diff] [blame] | 7 | #include "fpdfsdk/formfiller/cffl_combobox.h" |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 8 | |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame] | 9 | #include "fpdfsdk/cpdfsdk_formfillenvironment.h" |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 10 | #include "fpdfsdk/cpdfsdk_widget.h" |
Dan Sinclair | edbb319 | 2016-03-21 09:08:24 -0400 | [diff] [blame] | 11 | #include "fpdfsdk/formfiller/cba_fontmap.h" |
| 12 | #include "fpdfsdk/formfiller/cffl_formfiller.h" |
dsinclair | b94d7c9 | 2016-09-21 12:07:00 -0700 | [diff] [blame] | 13 | #include "fpdfsdk/formfiller/cffl_interactiveformfiller.h" |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 14 | #include "fpdfsdk/fsdk_common.h" |
dan sinclair | 89e904b | 2016-03-23 19:29:15 -0400 | [diff] [blame] | 15 | #include "fpdfsdk/pdfwindow/PWL_ComboBox.h" |
Tom Sepez | fe91c6c | 2017-05-16 15:33:20 -0700 | [diff] [blame] | 16 | #include "third_party/base/ptr_util.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 17 | |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame] | 18 | CFFL_ComboBox::CFFL_ComboBox(CPDFSDK_FormFillEnvironment* pApp, |
| 19 | CPDFSDK_Annot* pAnnot) |
Tom Sepez | fe91c6c | 2017-05-16 15:33:20 -0700 | [diff] [blame] | 20 | : CFFL_FormFiller(pApp, pAnnot) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 21 | m_State.nIndex = 0; |
| 22 | m_State.nStart = 0; |
| 23 | m_State.nEnd = 0; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 24 | } |
| 25 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 26 | CFFL_ComboBox::~CFFL_ComboBox() { |
Lei Zhang | ab5537d | 2016-01-06 14:58:14 -0800 | [diff] [blame] | 27 | for (const auto& it : m_Maps) |
| 28 | it.second->InvalidateFocusHandler(this); |
dsinclair | 28a4a24 | 2016-08-22 13:36:02 -0700 | [diff] [blame] | 29 | |
| 30 | // See comment in cffl_formfiller.h. |
| 31 | // The font map should be stored somewhere more appropriate so it will live |
| 32 | // until the PWL_Edit is done with it. pdfium:566 |
| 33 | DestroyWindows(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 34 | } |
| 35 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 36 | PWL_CREATEPARAM CFFL_ComboBox::GetCreateParam() { |
| 37 | PWL_CREATEPARAM cp = CFFL_FormFiller::GetCreateParam(); |
Tom Sepez | fe91c6c | 2017-05-16 15:33:20 -0700 | [diff] [blame] | 38 | if (m_pWidget->GetFieldFlags() & FIELDFLAG_EDIT) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 39 | cp.dwFlags |= PCBS_ALLOWCUSTOMTEXT; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 40 | |
Tom Sepez | d0409af | 2017-05-25 15:53:57 -0700 | [diff] [blame^] | 41 | if (!m_pFontMap) { |
| 42 | m_pFontMap = |
| 43 | pdfium::MakeUnique<CBA_FontMap>(m_pWidget.Get(), GetSystemHandler()); |
| 44 | } |
Tom Sepez | fe91c6c | 2017-05-16 15:33:20 -0700 | [diff] [blame] | 45 | cp.pFontMap = m_pFontMap.get(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 46 | cp.pFocusHandler = this; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 47 | return cp; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 48 | } |
| 49 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 50 | CPWL_Wnd* CFFL_ComboBox::NewPDFWindow(const PWL_CREATEPARAM& cp, |
| 51 | CPDFSDK_PageView* pPageView) { |
| 52 | CPWL_ComboBox* pWnd = new CPWL_ComboBox(); |
| 53 | pWnd->AttachFFLData(this); |
| 54 | pWnd->Create(cp); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 55 | |
dsinclair | 8779fa8 | 2016-10-12 12:05:44 -0700 | [diff] [blame] | 56 | CFFL_InteractiveFormFiller* pFormFiller = |
| 57 | m_pFormFillEnv->GetInteractiveFormFiller(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 58 | pWnd->SetFillerNotify(pFormFiller); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 59 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 60 | int32_t nCurSel = m_pWidget->GetSelectedIndex(0); |
| 61 | CFX_WideString swText; |
| 62 | if (nCurSel < 0) |
| 63 | swText = m_pWidget->GetValue(); |
| 64 | else |
| 65 | swText = m_pWidget->GetOptionLabel(nCurSel); |
Tom Sepez | 4f7bc04 | 2015-04-27 12:06:58 -0700 | [diff] [blame] | 66 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 67 | for (int32_t i = 0, sz = m_pWidget->CountOptions(); i < sz; i++) { |
tsepez | 067990c | 2016-09-13 06:46:40 -0700 | [diff] [blame] | 68 | pWnd->AddString(m_pWidget->GetOptionLabel(i)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 69 | } |
Tom Sepez | 4f7bc04 | 2015-04-27 12:06:58 -0700 | [diff] [blame] | 70 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 71 | pWnd->SetSelect(nCurSel); |
tsepez | 067990c | 2016-09-13 06:46:40 -0700 | [diff] [blame] | 72 | pWnd->SetText(swText); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 73 | return pWnd; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 74 | } |
| 75 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 76 | bool CFFL_ComboBox::OnChar(CPDFSDK_Annot* pAnnot, |
| 77 | uint32_t nChar, |
| 78 | uint32_t nFlags) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 79 | return CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 80 | } |
| 81 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 82 | bool CFFL_ComboBox::IsDataChanged(CPDFSDK_PageView* pPageView) { |
| 83 | CPWL_ComboBox* pWnd = (CPWL_ComboBox*)GetPDFWindow(pPageView, false); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 84 | if (!pWnd) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 85 | return false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 86 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 87 | int32_t nCurSel = pWnd->GetSelect(); |
| 88 | if (!(m_pWidget->GetFieldFlags() & FIELDFLAG_EDIT)) |
| 89 | return nCurSel != m_pWidget->GetSelectedIndex(0); |
| 90 | |
| 91 | if (nCurSel >= 0) |
| 92 | return nCurSel != m_pWidget->GetSelectedIndex(0); |
| 93 | |
| 94 | return pWnd->GetText() != m_pWidget->GetValue(); |
| 95 | } |
| 96 | |
| 97 | void CFFL_ComboBox::SaveData(CPDFSDK_PageView* pPageView) { |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 98 | CPWL_ComboBox* pWnd = |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 99 | static_cast<CPWL_ComboBox*>(GetPDFWindow(pPageView, false)); |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 100 | if (!pWnd) |
| 101 | return; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 102 | |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 103 | CFX_WideString swText = pWnd->GetText(); |
| 104 | int32_t nCurSel = pWnd->GetSelect(); |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 105 | |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 106 | bool bSetValue = false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 107 | |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 108 | if (m_pWidget->GetFieldFlags() & FIELDFLAG_EDIT) |
| 109 | bSetValue = (nCurSel < 0) || (swText != m_pWidget->GetOptionLabel(nCurSel)); |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 110 | |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 111 | if (bSetValue) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 112 | m_pWidget->SetValue(swText, false); |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 113 | } else { |
| 114 | m_pWidget->GetSelectedIndex(0); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 115 | m_pWidget->SetOptionSelection(nCurSel, true, false); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 116 | } |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 117 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 118 | m_pWidget->ResetFieldAppearance(true); |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 119 | m_pWidget->UpdateField(); |
| 120 | SetChangeMark(); |
| 121 | |
| 122 | m_pWidget->GetPDFPage(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 123 | } |
| 124 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 125 | void CFFL_ComboBox::GetActionData(CPDFSDK_PageView* pPageView, |
| 126 | CPDF_AAction::AActionType type, |
| 127 | PDFSDK_FieldAction& fa) { |
| 128 | switch (type) { |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 129 | case CPDF_AAction::KeyStroke: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 130 | if (CPWL_ComboBox* pComboBox = |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 131 | static_cast<CPWL_ComboBox*>(GetPDFWindow(pPageView, false))) { |
Tom Sepez | b4f0029 | 2015-11-23 09:13:33 -0800 | [diff] [blame] | 132 | if (CPWL_Edit* pEdit = pComboBox->GetEdit()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 133 | fa.bFieldFull = pEdit->IsTextFull(); |
| 134 | int nSelStart = 0; |
| 135 | int nSelEnd = 0; |
| 136 | pEdit->GetSel(nSelStart, nSelEnd); |
| 137 | fa.nSelEnd = nSelEnd; |
| 138 | fa.nSelStart = nSelStart; |
| 139 | fa.sValue = pEdit->GetText(); |
| 140 | fa.sChangeEx = GetSelectExportText(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 141 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 142 | if (fa.bFieldFull) { |
| 143 | fa.sChange = L""; |
| 144 | fa.sChangeEx = L""; |
| 145 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 146 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 147 | } |
| 148 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 149 | case CPDF_AAction::Validate: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 150 | if (CPWL_ComboBox* pComboBox = |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 151 | static_cast<CPWL_ComboBox*>(GetPDFWindow(pPageView, false))) { |
Tom Sepez | b4f0029 | 2015-11-23 09:13:33 -0800 | [diff] [blame] | 152 | if (CPWL_Edit* pEdit = pComboBox->GetEdit()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 153 | fa.sValue = pEdit->GetText(); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 154 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 155 | } |
| 156 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 157 | case CPDF_AAction::LoseFocus: |
| 158 | case CPDF_AAction::GetFocus: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 159 | fa.sValue = m_pWidget->GetValue(); |
| 160 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 161 | default: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 162 | break; |
| 163 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 164 | } |
| 165 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 166 | void CFFL_ComboBox::SetActionData(CPDFSDK_PageView* pPageView, |
| 167 | CPDF_AAction::AActionType type, |
| 168 | const PDFSDK_FieldAction& fa) { |
| 169 | switch (type) { |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 170 | case CPDF_AAction::KeyStroke: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 171 | if (CPWL_ComboBox* pComboBox = |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 172 | static_cast<CPWL_ComboBox*>(GetPDFWindow(pPageView, false))) { |
Tom Sepez | b4f0029 | 2015-11-23 09:13:33 -0800 | [diff] [blame] | 173 | if (CPWL_Edit* pEdit = pComboBox->GetEdit()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 174 | pEdit->SetSel(fa.nSelStart, fa.nSelEnd); |
tsepez | 067990c | 2016-09-13 06:46:40 -0700 | [diff] [blame] | 175 | pEdit->ReplaceSel(fa.sChange); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 176 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 177 | } |
| 178 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 179 | default: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 180 | break; |
| 181 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 182 | } |
| 183 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 184 | bool CFFL_ComboBox::IsActionDataChanged(CPDF_AAction::AActionType type, |
| 185 | const PDFSDK_FieldAction& faOld, |
| 186 | const PDFSDK_FieldAction& faNew) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 187 | switch (type) { |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 188 | case CPDF_AAction::KeyStroke: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 189 | return (!faOld.bFieldFull && faOld.nSelEnd != faNew.nSelEnd) || |
| 190 | faOld.nSelStart != faNew.nSelStart || |
| 191 | faOld.sChange != faNew.sChange; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 192 | default: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 193 | break; |
| 194 | } |
| 195 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 196 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | void CFFL_ComboBox::SaveState(CPDFSDK_PageView* pPageView) { |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 200 | ASSERT(pPageView); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 201 | |
| 202 | if (CPWL_ComboBox* pComboBox = |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 203 | static_cast<CPWL_ComboBox*>(GetPDFWindow(pPageView, false))) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 204 | m_State.nIndex = pComboBox->GetSelect(); |
| 205 | |
Tom Sepez | b4f0029 | 2015-11-23 09:13:33 -0800 | [diff] [blame] | 206 | if (CPWL_Edit* pEdit = pComboBox->GetEdit()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 207 | pEdit->GetSel(m_State.nStart, m_State.nEnd); |
| 208 | m_State.sValue = pEdit->GetText(); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 209 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 210 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 211 | } |
| 212 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 213 | void CFFL_ComboBox::RestoreState(CPDFSDK_PageView* pPageView) { |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 214 | ASSERT(pPageView); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 215 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 216 | if (CPWL_ComboBox* pComboBox = |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 217 | static_cast<CPWL_ComboBox*>(GetPDFWindow(pPageView, true))) { |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 218 | if (m_State.nIndex >= 0) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 219 | pComboBox->SetSelect(m_State.nIndex); |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 220 | } else { |
Tom Sepez | b4f0029 | 2015-11-23 09:13:33 -0800 | [diff] [blame] | 221 | if (CPWL_Edit* pEdit = pComboBox->GetEdit()) { |
tsepez | 067990c | 2016-09-13 06:46:40 -0700 | [diff] [blame] | 222 | pEdit->SetText(m_State.sValue); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 223 | pEdit->SetSel(m_State.nStart, m_State.nEnd); |
| 224 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 225 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 226 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 227 | } |
| 228 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 229 | CPWL_Wnd* CFFL_ComboBox::ResetPDFWindow(CPDFSDK_PageView* pPageView, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 230 | bool bRestoreValue) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 231 | if (bRestoreValue) |
| 232 | SaveState(pPageView); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 233 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 234 | DestroyPDFWindow(pPageView); |
| 235 | |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 236 | CPWL_Wnd* pRet = nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 237 | |
| 238 | if (bRestoreValue) { |
| 239 | RestoreState(pPageView); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 240 | pRet = GetPDFWindow(pPageView, false); |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 241 | } else { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 242 | pRet = GetPDFWindow(pPageView, true); |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 243 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 244 | |
| 245 | m_pWidget->UpdateField(); |
| 246 | |
| 247 | return pRet; |
| 248 | } |
| 249 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 250 | #ifdef PDF_ENABLE_XFA |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 251 | bool CFFL_ComboBox::IsFieldFull(CPDFSDK_PageView* pPageView) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 252 | if (CPWL_ComboBox* pComboBox = |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 253 | static_cast<CPWL_ComboBox*>(GetPDFWindow(pPageView, false))) { |
Tom Sepez | b4f0029 | 2015-11-23 09:13:33 -0800 | [diff] [blame] | 254 | if (CPWL_Edit* pEdit = pComboBox->GetEdit()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 255 | return pEdit->IsTextFull(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 256 | } |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 257 | return false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 258 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 259 | #endif // PDF_ENABLE_XFA |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 260 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 261 | void CFFL_ComboBox::OnSetFocus(CPWL_Wnd* pWnd) { |
dsinclair | 8779fa8 | 2016-10-12 12:05:44 -0700 | [diff] [blame] | 262 | ASSERT(m_pFormFillEnv); |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 263 | |
Lei Zhang | a8c2b91 | 2017-03-22 17:41:02 -0700 | [diff] [blame] | 264 | if (pWnd->GetClassName() != PWL_CLASSNAME_EDIT) |
| 265 | return; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 266 | |
Lei Zhang | a8c2b91 | 2017-03-22 17:41:02 -0700 | [diff] [blame] | 267 | CPWL_Edit* pEdit = (CPWL_Edit*)pWnd; |
Dan Sinclair | f51a02a | 2017-04-19 12:46:53 -0400 | [diff] [blame] | 268 | pEdit->SetCharSet(FX_CHARSET_ChineseSimplified); |
Lei Zhang | a8c2b91 | 2017-03-22 17:41:02 -0700 | [diff] [blame] | 269 | pEdit->SetReadyToInput(); |
| 270 | |
| 271 | CFX_WideString wsText = pEdit->GetText(); |
| 272 | int nCharacters = wsText.GetLength(); |
| 273 | CFX_ByteString bsUTFText = wsText.UTF16LE_Encode(); |
| 274 | auto* pBuffer = reinterpret_cast<const unsigned short*>(bsUTFText.c_str()); |
| 275 | m_pFormFillEnv->OnSetFieldInputFocus(pBuffer, nCharacters, true); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 276 | } |
| 277 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 278 | CFX_WideString CFFL_ComboBox::GetSelectExportText() { |
| 279 | CFX_WideString swRet; |
| 280 | |
| 281 | int nExport = -1; |
dsinclair | 461eeaf | 2016-07-27 07:40:05 -0700 | [diff] [blame] | 282 | CPDFSDK_PageView* pPageView = GetCurPageView(true); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 283 | if (CPWL_ComboBox* pComboBox = |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 284 | (CPWL_ComboBox*)GetPDFWindow(pPageView, false)) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 285 | nExport = pComboBox->GetSelect(); |
| 286 | } |
| 287 | |
| 288 | if (nExport >= 0) { |
| 289 | if (CPDF_FormField* pFormField = m_pWidget->GetFormField()) { |
| 290 | swRet = pFormField->GetOptionValue(nExport); |
| 291 | if (swRet.IsEmpty()) |
| 292 | swRet = pFormField->GetOptionLabel(nExport); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 293 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 294 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 295 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 296 | return swRet; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 297 | } |