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