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 "fpdfsdk/include/formfiller/FFL_CBA_Fontmap.h" | 7 #include "fpdfsdk/include/formfiller/FFL_CBA_Fontmap.h" |
8 #include "fpdfsdk/include/formfiller/FFL_TextField.h" | 8 #include "fpdfsdk/include/formfiller/FFL_TextField.h" |
9 | 9 |
10 /* ------------------------------- CFFL_TextField | 10 /* ------------------------------- CFFL_TextField |
11 * ------------------------------- */ | 11 * ------------------------------- */ |
12 | 12 |
13 CFFL_TextField::CFFL_TextField(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pAnnot) | 13 CFFL_TextField::CFFL_TextField(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pAnnot) |
14 : CFFL_FormFiller(pApp, pAnnot), | 14 : CFFL_FormFiller(pApp, pAnnot), m_pFontMap(NULL) { |
15 m_pFontMap(NULL) //, | |
16 // m_pSpellCheck(NULL) | |
17 { | |
18 m_State.nStart = m_State.nEnd = 0; | 15 m_State.nStart = m_State.nEnd = 0; |
19 } | 16 } |
20 | 17 |
21 CFFL_TextField::~CFFL_TextField() { | 18 CFFL_TextField::~CFFL_TextField() { |
22 delete m_pFontMap; | 19 delete m_pFontMap; |
23 } | 20 } |
24 | 21 |
25 PWL_CREATEPARAM CFFL_TextField::GetCreateParam() { | 22 PWL_CREATEPARAM CFFL_TextField::GetCreateParam() { |
26 PWL_CREATEPARAM cp = CFFL_FormFiller::GetCreateParam(); | 23 PWL_CREATEPARAM cp = CFFL_FormFiller::GetCreateParam(); |
27 | 24 |
28 ASSERT(m_pWidget != NULL); | |
29 int nFlags = m_pWidget->GetFieldFlags(); | 25 int nFlags = m_pWidget->GetFieldFlags(); |
30 | 26 |
31 if (nFlags & FIELDFLAG_PASSWORD) { | 27 if (nFlags & FIELDFLAG_PASSWORD) { |
32 cp.dwFlags |= PES_PASSWORD; | 28 cp.dwFlags |= PES_PASSWORD; |
33 } | 29 } |
34 | 30 |
35 if (!(nFlags & FIELDFLAG_DONOTSPELLCHECK)) { | 31 if (!(nFlags & FIELDFLAG_DONOTSPELLCHECK)) { |
36 } | 32 } |
37 | 33 |
38 if (nFlags & FIELDFLAG_MULTILINE) { | 34 if (nFlags & FIELDFLAG_MULTILINE) { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 | 77 |
82 return cp; | 78 return cp; |
83 } | 79 } |
84 | 80 |
85 CPWL_Wnd* CFFL_TextField::NewPDFWindow(const PWL_CREATEPARAM& cp, | 81 CPWL_Wnd* CFFL_TextField::NewPDFWindow(const PWL_CREATEPARAM& cp, |
86 CPDFSDK_PageView* pPageView) { | 82 CPDFSDK_PageView* pPageView) { |
87 CPWL_Edit* pWnd = new CPWL_Edit(); | 83 CPWL_Edit* pWnd = new CPWL_Edit(); |
88 pWnd->AttachFFLData(this); | 84 pWnd->AttachFFLData(this); |
89 pWnd->Create(cp); | 85 pWnd->Create(cp); |
90 | 86 |
91 ASSERT(m_pApp != NULL); | |
92 CFFL_IFormFiller* pIFormFiller = m_pApp->GetIFormFiller(); | 87 CFFL_IFormFiller* pIFormFiller = m_pApp->GetIFormFiller(); |
93 pWnd->SetFillerNotify(pIFormFiller); | 88 pWnd->SetFillerNotify(pIFormFiller); |
94 | 89 |
95 ASSERT(m_pWidget != NULL); | |
96 int32_t nMaxLen = m_pWidget->GetMaxLen(); | 90 int32_t nMaxLen = m_pWidget->GetMaxLen(); |
97 CFX_WideString swValue = m_pWidget->GetValue(); | 91 CFX_WideString swValue = m_pWidget->GetValue(); |
98 | 92 |
99 if (nMaxLen > 0) { | 93 if (nMaxLen > 0) { |
100 if (pWnd->HasFlag(PES_CHARARRAY)) { | 94 if (pWnd->HasFlag(PES_CHARARRAY)) { |
101 pWnd->SetCharArray(nMaxLen); | 95 pWnd->SetCharArray(nMaxLen); |
102 pWnd->SetAlignFormatV(PEAV_CENTER); | 96 pWnd->SetAlignFormatV(PEAV_CENTER); |
103 } else { | 97 } else { |
104 pWnd->SetLimitChar(nMaxLen); | 98 pWnd->SetLimitChar(nMaxLen); |
105 } | 99 } |
106 } | 100 } |
107 | 101 |
108 pWnd->SetText(swValue.c_str()); | 102 pWnd->SetText(swValue.c_str()); |
109 return pWnd; | 103 return pWnd; |
110 } | 104 } |
111 | 105 |
112 FX_BOOL CFFL_TextField::OnChar(CPDFSDK_Annot* pAnnot, | 106 FX_BOOL CFFL_TextField::OnChar(CPDFSDK_Annot* pAnnot, |
113 FX_UINT nChar, | 107 FX_UINT nChar, |
114 FX_UINT nFlags) { | 108 FX_UINT nFlags) { |
115 switch (nChar) { | 109 switch (nChar) { |
116 case FWL_VKEY_Return: | 110 case FWL_VKEY_Return: |
117 if (!(m_pWidget->GetFieldFlags() & FIELDFLAG_MULTILINE)) { | 111 if (!(m_pWidget->GetFieldFlags() & FIELDFLAG_MULTILINE)) { |
118 CPDFSDK_PageView* pPageView = GetCurPageView(); | 112 CPDFSDK_PageView* pPageView = GetCurPageView(); |
119 ASSERT(pPageView != NULL); | 113 ASSERT(pPageView); |
120 m_bValid = !m_bValid; | 114 m_bValid = !m_bValid; |
121 CPDF_Rect rcAnnot = pAnnot->GetRect(); | 115 CPDF_Rect rcAnnot = pAnnot->GetRect(); |
122 m_pApp->FFI_Invalidate(pAnnot->GetUnderlyingPage(), rcAnnot.left, | 116 m_pApp->FFI_Invalidate(pAnnot->GetUnderlyingPage(), rcAnnot.left, |
123 rcAnnot.top, rcAnnot.right, rcAnnot.bottom); | 117 rcAnnot.top, rcAnnot.right, rcAnnot.bottom); |
124 | 118 |
125 if (m_bValid) { | 119 if (m_bValid) { |
126 if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, TRUE)) | 120 if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, TRUE)) |
127 pWnd->SetFocus(); | 121 pWnd->SetFocus(); |
128 } else { | 122 } else { |
129 if (CommitData(pPageView, nFlags)) { | 123 if (CommitData(pPageView, nFlags)) { |
130 DestroyPDFWindow(pPageView); | 124 DestroyPDFWindow(pPageView); |
131 return TRUE; | 125 return TRUE; |
132 } | 126 } |
133 return FALSE; | 127 return FALSE; |
134 } | 128 } |
135 } | 129 } |
136 break; | 130 break; |
137 case FWL_VKEY_Escape: { | 131 case FWL_VKEY_Escape: { |
138 CPDFSDK_PageView* pPageView = GetCurPageView(); | 132 CPDFSDK_PageView* pPageView = GetCurPageView(); |
139 ASSERT(pPageView != NULL); | 133 ASSERT(pPageView); |
140 EscapeFiller(pPageView, TRUE); | 134 EscapeFiller(pPageView, TRUE); |
141 return TRUE; | 135 return TRUE; |
142 } | 136 } |
143 } | 137 } |
144 | 138 |
145 return CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags); | 139 return CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags); |
146 } | 140 } |
147 | 141 |
148 FX_BOOL CFFL_TextField::IsDataChanged(CPDFSDK_PageView* pPageView) { | 142 FX_BOOL CFFL_TextField::IsDataChanged(CPDFSDK_PageView* pPageView) { |
149 ASSERT(m_pWidget != NULL); | |
150 | |
151 if (CPWL_Edit* pEdit = (CPWL_Edit*)GetPDFWindow(pPageView, FALSE)) | 143 if (CPWL_Edit* pEdit = (CPWL_Edit*)GetPDFWindow(pPageView, FALSE)) |
152 return pEdit->GetText() != m_pWidget->GetValue(); | 144 return pEdit->GetText() != m_pWidget->GetValue(); |
153 | 145 |
154 return FALSE; | 146 return FALSE; |
155 } | 147 } |
156 | 148 |
157 void CFFL_TextField::SaveData(CPDFSDK_PageView* pPageView) { | 149 void CFFL_TextField::SaveData(CPDFSDK_PageView* pPageView) { |
158 ASSERT(m_pWidget != NULL); | |
159 | |
160 if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, FALSE)) { | 150 if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, FALSE)) { |
161 CFX_WideString sOldValue = m_pWidget->GetValue(); | 151 CFX_WideString sOldValue = m_pWidget->GetValue(); |
162 CFX_WideString sNewValue = pWnd->GetText(); | 152 CFX_WideString sNewValue = pWnd->GetText(); |
163 | 153 |
164 m_pWidget->SetValue(sNewValue, FALSE); | 154 m_pWidget->SetValue(sNewValue, FALSE); |
165 m_pWidget->ResetFieldAppearance(TRUE); | 155 m_pWidget->ResetFieldAppearance(TRUE); |
166 m_pWidget->UpdateField(); | 156 m_pWidget->UpdateField(); |
167 SetChangeMark(); | 157 SetChangeMark(); |
168 } | 158 } |
169 } | 159 } |
(...skipping 14 matching lines...) Expand all Loading... |
184 } | 174 } |
185 } | 175 } |
186 break; | 176 break; |
187 case CPDF_AAction::Validate: | 177 case CPDF_AAction::Validate: |
188 if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, FALSE)) { | 178 if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, FALSE)) { |
189 fa.sValue = pWnd->GetText(); | 179 fa.sValue = pWnd->GetText(); |
190 } | 180 } |
191 break; | 181 break; |
192 case CPDF_AAction::LoseFocus: | 182 case CPDF_AAction::LoseFocus: |
193 case CPDF_AAction::GetFocus: | 183 case CPDF_AAction::GetFocus: |
194 ASSERT(m_pWidget != NULL); | |
195 fa.sValue = m_pWidget->GetValue(); | 184 fa.sValue = m_pWidget->GetValue(); |
196 break; | 185 break; |
197 default: | 186 default: |
198 break; | 187 break; |
199 } | 188 } |
200 } | 189 } |
201 | 190 |
202 void CFFL_TextField::SetActionData(CPDFSDK_PageView* pPageView, | 191 void CFFL_TextField::SetActionData(CPDFSDK_PageView* pPageView, |
203 CPDF_AAction::AActionType type, | 192 CPDF_AAction::AActionType type, |
204 const PDFSDK_FieldAction& fa) { | 193 const PDFSDK_FieldAction& fa) { |
(...skipping 19 matching lines...) Expand all Loading... |
224 faOld.nSelStart != faNew.nSelStart || | 213 faOld.nSelStart != faNew.nSelStart || |
225 faOld.sChange != faNew.sChange; | 214 faOld.sChange != faNew.sChange; |
226 default: | 215 default: |
227 break; | 216 break; |
228 } | 217 } |
229 | 218 |
230 return FALSE; | 219 return FALSE; |
231 } | 220 } |
232 | 221 |
233 void CFFL_TextField::SaveState(CPDFSDK_PageView* pPageView) { | 222 void CFFL_TextField::SaveState(CPDFSDK_PageView* pPageView) { |
234 ASSERT(pPageView != NULL); | 223 ASSERT(pPageView); |
235 | 224 |
236 if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, FALSE)) { | 225 if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, FALSE)) { |
237 pWnd->GetSel(m_State.nStart, m_State.nEnd); | 226 pWnd->GetSel(m_State.nStart, m_State.nEnd); |
238 m_State.sValue = pWnd->GetText(); | 227 m_State.sValue = pWnd->GetText(); |
239 } | 228 } |
240 } | 229 } |
241 | 230 |
242 void CFFL_TextField::RestoreState(CPDFSDK_PageView* pPageView) { | 231 void CFFL_TextField::RestoreState(CPDFSDK_PageView* pPageView) { |
243 ASSERT(pPageView != NULL); | 232 ASSERT(pPageView); |
244 | 233 |
245 if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, TRUE)) { | 234 if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, TRUE)) { |
246 pWnd->SetText(m_State.sValue.c_str()); | 235 pWnd->SetText(m_State.sValue.c_str()); |
247 pWnd->SetSel(m_State.nStart, m_State.nEnd); | 236 pWnd->SetSel(m_State.nStart, m_State.nEnd); |
248 } | 237 } |
249 } | 238 } |
250 | 239 |
251 CPWL_Wnd* CFFL_TextField::ResetPDFWindow(CPDFSDK_PageView* pPageView, | 240 CPWL_Wnd* CFFL_TextField::ResetPDFWindow(CPDFSDK_PageView* pPageView, |
252 FX_BOOL bRestoreValue) { | 241 FX_BOOL bRestoreValue) { |
253 if (bRestoreValue) | 242 if (bRestoreValue) |
(...skipping 18 matching lines...) Expand all Loading... |
272 FX_BOOL CFFL_TextField::IsFieldFull(CPDFSDK_PageView* pPageView) { | 261 FX_BOOL CFFL_TextField::IsFieldFull(CPDFSDK_PageView* pPageView) { |
273 if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, FALSE)) { | 262 if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, FALSE)) { |
274 return pWnd->IsTextFull(); | 263 return pWnd->IsTextFull(); |
275 } | 264 } |
276 | 265 |
277 return FALSE; | 266 return FALSE; |
278 } | 267 } |
279 #endif // PDF_ENABLE_XFA | 268 #endif // PDF_ENABLE_XFA |
280 | 269 |
281 void CFFL_TextField::OnSetFocus(CPWL_Wnd* pWnd) { | 270 void CFFL_TextField::OnSetFocus(CPWL_Wnd* pWnd) { |
282 ASSERT(m_pApp != NULL); | 271 ASSERT(m_pApp); |
283 | |
284 ASSERT(pWnd != NULL); | |
285 | |
286 if (pWnd->GetClassName() == PWL_CLASSNAME_EDIT) { | 272 if (pWnd->GetClassName() == PWL_CLASSNAME_EDIT) { |
287 CPWL_Edit* pEdit = (CPWL_Edit*)pWnd; | 273 CPWL_Edit* pEdit = (CPWL_Edit*)pWnd; |
288 pEdit->SetCharSet(134); | 274 pEdit->SetCharSet(134); |
289 pEdit->SetCodePage(936); | 275 pEdit->SetCodePage(936); |
290 | 276 |
291 pEdit->SetReadyToInput(); | 277 pEdit->SetReadyToInput(); |
292 CFX_WideString wsText = pEdit->GetText(); | 278 CFX_WideString wsText = pEdit->GetText(); |
293 int nCharacters = wsText.GetLength(); | 279 int nCharacters = wsText.GetLength(); |
294 CFX_ByteString bsUTFText = wsText.UTF16LE_Encode(); | 280 CFX_ByteString bsUTFText = wsText.UTF16LE_Encode(); |
295 unsigned short* pBuffer = (unsigned short*)bsUTFText.c_str(); | 281 unsigned short* pBuffer = (unsigned short*)bsUTFText.c_str(); |
296 m_pApp->FFI_OnSetFieldInputFocus(m_pWidget->GetFormField(), pBuffer, | 282 m_pApp->FFI_OnSetFieldInputFocus(m_pWidget->GetFormField(), pBuffer, |
297 nCharacters, TRUE); | 283 nCharacters, TRUE); |
298 | 284 |
299 pEdit->SetEditNotify(this); | 285 pEdit->SetEditNotify(this); |
300 } | 286 } |
301 } | 287 } |
302 | 288 |
303 void CFFL_TextField::OnKillFocus(CPWL_Wnd* pWnd) {} | 289 void CFFL_TextField::OnKillFocus(CPWL_Wnd* pWnd) {} |
304 | 290 |
305 void CFFL_TextField::OnAddUndo(CPWL_Edit* pEdit) {} | 291 void CFFL_TextField::OnAddUndo(CPWL_Edit* pEdit) {} |
OLD | NEW |