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_textfield.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [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" |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 12 | #include "fpdfsdk/fsdk_common.h" |
tsepez | 36eb4bd | 2016-10-03 15:24:27 -0700 | [diff] [blame] | 13 | #include "third_party/base/ptr_util.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 14 | |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame] | 15 | CFFL_TextField::CFFL_TextField(CPDFSDK_FormFillEnvironment* pApp, |
| 16 | CPDFSDK_Annot* pAnnot) |
weili | 2d5b020 | 2016-08-03 11:06:49 -0700 | [diff] [blame] | 17 | : CFFL_FormFiller(pApp, pAnnot) {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 18 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 19 | CFFL_TextField::~CFFL_TextField() { |
Lei Zhang | ab5537d | 2016-01-06 14:58:14 -0800 | [diff] [blame] | 20 | for (const auto& it : m_Maps) |
| 21 | it.second->InvalidateFocusHandler(this); |
dsinclair | 28a4a24 | 2016-08-22 13:36:02 -0700 | [diff] [blame] | 22 | |
| 23 | // See comment in cffl_formfiller.h. |
| 24 | // The font map should be stored somewhere more appropriate so it will live |
| 25 | // until the PWL_Edit is done with it. pdfium:566 |
| 26 | DestroyWindows(); |
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_TextField::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(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 33 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 34 | if (nFlags & FIELDFLAG_PASSWORD) { |
| 35 | cp.dwFlags |= PES_PASSWORD; |
| 36 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 37 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 38 | if (nFlags & FIELDFLAG_MULTILINE) { |
| 39 | cp.dwFlags |= PES_MULTILINE | PES_AUTORETURN | PES_TOP; |
| 40 | |
| 41 | if (!(nFlags & FIELDFLAG_DONOTSCROLL)) { |
| 42 | cp.dwFlags |= PWS_VSCROLL | PES_AUTOSCROLL; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 43 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 44 | } else { |
| 45 | cp.dwFlags |= PES_CENTER; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 46 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 47 | if (!(nFlags & FIELDFLAG_DONOTSCROLL)) { |
| 48 | cp.dwFlags |= PES_AUTOSCROLL; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 49 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 50 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 51 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 52 | if (nFlags & FIELDFLAG_COMB) { |
| 53 | cp.dwFlags |= PES_CHARARRAY; |
| 54 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 55 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 56 | if (nFlags & FIELDFLAG_RICHTEXT) { |
| 57 | cp.dwFlags |= PES_RICH; |
| 58 | } |
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 | cp.dwFlags |= PES_UNDO; |
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 | switch (m_pWidget->GetAlignment()) { |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 63 | default: |
| 64 | case BF_ALIGN_LEFT: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 65 | cp.dwFlags |= PES_LEFT; |
| 66 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 67 | case BF_ALIGN_MIDDLE: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 68 | cp.dwFlags |= PES_MIDDLE; |
| 69 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 70 | case BF_ALIGN_RIGHT: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 71 | cp.dwFlags |= PES_RIGHT; |
| 72 | break; |
| 73 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 74 | |
thestig | d4c34f2 | 2016-09-28 17:04:51 -0700 | [diff] [blame] | 75 | if (!m_pFontMap) { |
dsinclair | 8779fa8 | 2016-10-12 12:05:44 -0700 | [diff] [blame] | 76 | m_pFontMap = pdfium::MakeUnique<CBA_FontMap>( |
| 77 | m_pWidget, m_pFormFillEnv->GetSysHandler()); |
thestig | d4c34f2 | 2016-09-28 17:04:51 -0700 | [diff] [blame] | 78 | } |
weili | 2d5b020 | 2016-08-03 11:06:49 -0700 | [diff] [blame] | 79 | cp.pFontMap = m_pFontMap.get(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 80 | cp.pFocusHandler = this; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 81 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 82 | return cp; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 83 | } |
| 84 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 85 | CPWL_Wnd* CFFL_TextField::NewPDFWindow(const PWL_CREATEPARAM& cp, |
| 86 | CPDFSDK_PageView* pPageView) { |
| 87 | CPWL_Edit* pWnd = new CPWL_Edit(); |
| 88 | pWnd->AttachFFLData(this); |
| 89 | pWnd->Create(cp); |
dsinclair | 8779fa8 | 2016-10-12 12:05:44 -0700 | [diff] [blame] | 90 | pWnd->SetFillerNotify(m_pFormFillEnv->GetInteractiveFormFiller()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 91 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 92 | int32_t nMaxLen = m_pWidget->GetMaxLen(); |
| 93 | CFX_WideString swValue = m_pWidget->GetValue(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 94 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 95 | if (nMaxLen > 0) { |
| 96 | if (pWnd->HasFlag(PES_CHARARRAY)) { |
| 97 | pWnd->SetCharArray(nMaxLen); |
| 98 | pWnd->SetAlignFormatV(PEAV_CENTER); |
| 99 | } else { |
| 100 | pWnd->SetLimitChar(nMaxLen); |
| 101 | } |
| 102 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 103 | |
tsepez | 067990c | 2016-09-13 06:46:40 -0700 | [diff] [blame] | 104 | pWnd->SetText(swValue); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 105 | return pWnd; |
| 106 | } |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 107 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 108 | bool CFFL_TextField::OnChar(CPDFSDK_Annot* pAnnot, |
| 109 | uint32_t nChar, |
| 110 | uint32_t nFlags) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 111 | switch (nChar) { |
| 112 | case FWL_VKEY_Return: |
| 113 | if (!(m_pWidget->GetFieldFlags() & FIELDFLAG_MULTILINE)) { |
dsinclair | 461eeaf | 2016-07-27 07:40:05 -0700 | [diff] [blame] | 114 | CPDFSDK_PageView* pPageView = GetCurPageView(true); |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 115 | ASSERT(pPageView); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 116 | m_bValid = !m_bValid; |
Dan Sinclair | 6eec1c4 | 2017-02-21 17:20:43 -0500 | [diff] [blame] | 117 | m_pFormFillEnv->Invalidate(pAnnot->GetUnderlyingPage(), |
| 118 | pAnnot->GetRect().ToFxRect()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 119 | |
| 120 | if (m_bValid) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 121 | if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, true)) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 122 | pWnd->SetFocus(); |
| 123 | } else { |
| 124 | if (CommitData(pPageView, nFlags)) { |
| 125 | DestroyPDFWindow(pPageView); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 126 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 127 | } |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 128 | return false; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 129 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 130 | } |
| 131 | break; |
| 132 | case FWL_VKEY_Escape: { |
dsinclair | 461eeaf | 2016-07-27 07:40:05 -0700 | [diff] [blame] | 133 | CPDFSDK_PageView* pPageView = GetCurPageView(true); |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 134 | ASSERT(pPageView); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 135 | EscapeFiller(pPageView, true); |
| 136 | return true; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 137 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 138 | } |
Tom Sepez | 4f7bc04 | 2015-04-27 12:06:58 -0700 | [diff] [blame] | 139 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 140 | return CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 141 | } |
| 142 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 143 | bool CFFL_TextField::IsDataChanged(CPDFSDK_PageView* pPageView) { |
| 144 | if (CPWL_Edit* pEdit = (CPWL_Edit*)GetPDFWindow(pPageView, false)) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 145 | return pEdit->GetText() != m_pWidget->GetValue(); |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 146 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 147 | return false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 148 | } |
| 149 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 150 | void CFFL_TextField::SaveData(CPDFSDK_PageView* pPageView) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 151 | if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, false)) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 152 | CFX_WideString sOldValue = m_pWidget->GetValue(); |
| 153 | CFX_WideString sNewValue = pWnd->GetText(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 154 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 155 | m_pWidget->SetValue(sNewValue, false); |
| 156 | m_pWidget->ResetFieldAppearance(true); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 157 | m_pWidget->UpdateField(); |
| 158 | SetChangeMark(); |
| 159 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 160 | } |
| 161 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 162 | void CFFL_TextField::GetActionData(CPDFSDK_PageView* pPageView, |
| 163 | CPDF_AAction::AActionType type, |
| 164 | PDFSDK_FieldAction& fa) { |
| 165 | switch (type) { |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 166 | case CPDF_AAction::KeyStroke: |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 167 | if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, false)) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 168 | fa.bFieldFull = pWnd->IsTextFull(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 169 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 170 | fa.sValue = pWnd->GetText(); |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 171 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 172 | if (fa.bFieldFull) { |
| 173 | fa.sChange = L""; |
| 174 | fa.sChangeEx = L""; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 175 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 176 | } |
| 177 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 178 | case CPDF_AAction::Validate: |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 179 | if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, false)) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 180 | fa.sValue = pWnd->GetText(); |
| 181 | } |
| 182 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 183 | case CPDF_AAction::LoseFocus: |
| 184 | case CPDF_AAction::GetFocus: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 185 | fa.sValue = m_pWidget->GetValue(); |
| 186 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 187 | default: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 188 | break; |
| 189 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 190 | } |
| 191 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 192 | void CFFL_TextField::SetActionData(CPDFSDK_PageView* pPageView, |
| 193 | CPDF_AAction::AActionType type, |
| 194 | const PDFSDK_FieldAction& fa) { |
| 195 | switch (type) { |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 196 | case CPDF_AAction::KeyStroke: |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 197 | if (CPWL_Edit* pEdit = (CPWL_Edit*)GetPDFWindow(pPageView, false)) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 198 | pEdit->SetFocus(); |
| 199 | pEdit->SetSel(fa.nSelStart, fa.nSelEnd); |
tsepez | 067990c | 2016-09-13 06:46:40 -0700 | [diff] [blame] | 200 | pEdit->ReplaceSel(fa.sChange); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 201 | } |
| 202 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 203 | default: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 204 | break; |
| 205 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 206 | } |
| 207 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 208 | bool CFFL_TextField::IsActionDataChanged(CPDF_AAction::AActionType type, |
| 209 | const PDFSDK_FieldAction& faOld, |
| 210 | const PDFSDK_FieldAction& faNew) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 211 | switch (type) { |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 212 | case CPDF_AAction::KeyStroke: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 213 | return (!faOld.bFieldFull && faOld.nSelEnd != faNew.nSelEnd) || |
| 214 | faOld.nSelStart != faNew.nSelStart || |
| 215 | faOld.sChange != faNew.sChange; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 216 | default: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 217 | break; |
| 218 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 219 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 220 | return false; |
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 | void CFFL_TextField::SaveState(CPDFSDK_PageView* pPageView) { |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 224 | ASSERT(pPageView); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 225 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 226 | if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, false)) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 227 | pWnd->GetSel(m_State.nStart, m_State.nEnd); |
| 228 | m_State.sValue = pWnd->GetText(); |
| 229 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 230 | } |
| 231 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 232 | void CFFL_TextField::RestoreState(CPDFSDK_PageView* pPageView) { |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 233 | ASSERT(pPageView); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 234 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 235 | if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, true)) { |
tsepez | 067990c | 2016-09-13 06:46:40 -0700 | [diff] [blame] | 236 | pWnd->SetText(m_State.sValue); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 237 | pWnd->SetSel(m_State.nStart, m_State.nEnd); |
| 238 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 239 | } |
| 240 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 241 | CPWL_Wnd* CFFL_TextField::ResetPDFWindow(CPDFSDK_PageView* pPageView, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 242 | bool bRestoreValue) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 243 | if (bRestoreValue) |
| 244 | SaveState(pPageView); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 245 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 246 | DestroyPDFWindow(pPageView); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 247 | |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 248 | CPWL_Wnd* pRet = nullptr; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 249 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 250 | if (bRestoreValue) { |
| 251 | RestoreState(pPageView); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 252 | pRet = GetPDFWindow(pPageView, false); |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 253 | } else { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 254 | pRet = GetPDFWindow(pPageView, true); |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 255 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 256 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 257 | m_pWidget->UpdateField(); |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 258 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 259 | return pRet; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 260 | } |
| 261 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 262 | #ifdef PDF_ENABLE_XFA |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 263 | bool CFFL_TextField::IsFieldFull(CPDFSDK_PageView* pPageView) { |
| 264 | if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, false)) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 265 | return pWnd->IsTextFull(); |
| 266 | } |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 267 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 268 | return false; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 269 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 270 | #endif // PDF_ENABLE_XFA |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 271 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 272 | void CFFL_TextField::OnSetFocus(CPWL_Wnd* pWnd) { |
dsinclair | 8779fa8 | 2016-10-12 12:05:44 -0700 | [diff] [blame] | 273 | ASSERT(m_pFormFillEnv); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 274 | if (pWnd->GetClassName() == PWL_CLASSNAME_EDIT) { |
| 275 | CPWL_Edit* pEdit = (CPWL_Edit*)pWnd; |
thestig | 907a522 | 2016-06-21 14:38:27 -0700 | [diff] [blame] | 276 | pEdit->SetCharSet(FXFONT_GB2312_CHARSET); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 277 | pEdit->SetCodePage(936); |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 278 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 279 | pEdit->SetReadyToInput(); |
| 280 | CFX_WideString wsText = pEdit->GetText(); |
| 281 | int nCharacters = wsText.GetLength(); |
| 282 | CFX_ByteString bsUTFText = wsText.UTF16LE_Encode(); |
| 283 | unsigned short* pBuffer = (unsigned short*)bsUTFText.c_str(); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 284 | m_pFormFillEnv->OnSetFieldInputFocus(pBuffer, nCharacters, true); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 285 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 286 | } |