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