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 "../../include/formfiller/FFL_TextField.h" | 7 #include "../../include/formfiller/FFL_TextField.h" |
8 #include "../../include/formfiller/FFL_CBA_Fontmap.h" | 8 #include "../../include/formfiller/FFL_CBA_Fontmap.h" |
9 | 9 |
10 /* ------------------------------- CFFL_TextField ------------------------------
- */ | 10 /* ------------------------------- CFFL_TextField ------------------------------
- */ |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 { | 122 { |
123 pWnd->SetLimitChar(nMaxLen); | 123 pWnd->SetLimitChar(nMaxLen); |
124 } | 124 } |
125 } | 125 } |
126 | 126 |
127 pWnd->SetText(swValue.c_str()); | 127 pWnd->SetText(swValue.c_str()); |
128 return pWnd; | 128 return pWnd; |
129 } | 129 } |
130 | 130 |
131 | 131 |
132 FX_BOOL»CFFL_TextField::OnChar(CPDFSDK_Annot* pAnnot, FX_UINT nChar, FX_UINT nFl
ags) | 132 bool» CFFL_TextField::OnChar(CPDFSDK_Annot* pAnnot, FX_UINT nChar, FX_UINT nFl
ags) |
133 { | 133 { |
134 switch (nChar) | 134 switch (nChar) |
135 { | 135 { |
136 case FWL_VKEY_Return: | 136 case FWL_VKEY_Return: |
137 if (!(m_pWidget->GetFieldFlags() & FIELDFLAG_MULTILINE)) | 137 if (!(m_pWidget->GetFieldFlags() & FIELDFLAG_MULTILINE)) |
138 { | 138 { |
139 CPDFSDK_PageView* pPageView = GetCurPageView(); | 139 CPDFSDK_PageView* pPageView = GetCurPageView(); |
140 ASSERT(pPageView != NULL); | 140 ASSERT(pPageView != NULL); |
141 m_bValid = !m_bValid; | 141 m_bValid = !m_bValid; |
142 CPDF_Rect rcAnnot = pAnnot->GetRect(); | 142 CPDF_Rect rcAnnot = pAnnot->GetRect(); |
143 m_pApp->FFI_Invalidate(pAnnot->GetPDFPage(), rcAnnot.lef
t, rcAnnot.top, rcAnnot.right, rcAnnot.bottom); | 143 m_pApp->FFI_Invalidate(pAnnot->GetPDFPage(), rcAnnot.lef
t, rcAnnot.top, rcAnnot.right, rcAnnot.bottom); |
144 | 144 |
145 if (m_bValid) | 145 if (m_bValid) |
146 { | 146 { |
147 » » » » if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, TRU
E)) | 147 » » » » if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, tru
e)) |
148 pWnd->SetFocus(); | 148 pWnd->SetFocus(); |
149 } | 149 } |
150 else | 150 else |
151 { | 151 { |
152 if (CommitData(pPageView, nFlags)) | 152 if (CommitData(pPageView, nFlags)) |
153 { | 153 { |
154 DestroyPDFWindow(pPageView); | 154 DestroyPDFWindow(pPageView); |
155 » » » » » return TRUE; | 155 » » » » » return true; |
156 } | 156 } |
157 else | 157 else |
158 { | 158 { |
159 » » » » » return FALSE; | 159 » » » » » return false; |
160 } | 160 } |
161 } | 161 } |
162 } | 162 } |
163 break; | 163 break; |
164 case FWL_VKEY_Escape: | 164 case FWL_VKEY_Escape: |
165 { | 165 { |
166 CPDFSDK_PageView* pPageView = GetCurPageView(); | 166 CPDFSDK_PageView* pPageView = GetCurPageView(); |
167 ASSERT(pPageView != NULL); | 167 ASSERT(pPageView != NULL); |
168 » » » EscapeFiller(pPageView,TRUE); | 168 » » » EscapeFiller(pPageView,true); |
169 » » » return TRUE; | 169 » » » return true; |
170 } | 170 } |
171 } | 171 } |
172 | 172 |
173 return CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags); | 173 return CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags); |
174 } | 174 } |
175 | 175 |
176 FX_BOOL»CFFL_TextField::IsDataChanged(CPDFSDK_PageView* pPageView) | 176 bool» CFFL_TextField::IsDataChanged(CPDFSDK_PageView* pPageView) |
177 { | 177 { |
178 ASSERT(m_pWidget != NULL); | 178 ASSERT(m_pWidget != NULL); |
179 | 179 |
180 » if (CPWL_Edit * pEdit = (CPWL_Edit*)GetPDFWindow(pPageView, FALSE)) | 180 » if (CPWL_Edit * pEdit = (CPWL_Edit*)GetPDFWindow(pPageView, false)) |
181 return pEdit->GetText() != m_pWidget->GetValue(); | 181 return pEdit->GetText() != m_pWidget->GetValue(); |
182 | 182 |
183 » return FALSE; | 183 » return false; |
184 } | 184 } |
185 | 185 |
186 void CFFL_TextField::SaveData(CPDFSDK_PageView* pPageView) | 186 void CFFL_TextField::SaveData(CPDFSDK_PageView* pPageView) |
187 { | 187 { |
188 ASSERT(m_pWidget != NULL); | 188 ASSERT(m_pWidget != NULL); |
189 | 189 |
190 » if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, FALSE)) | 190 » if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, false)) |
191 { | 191 { |
192 CFX_WideString sOldValue = m_pWidget->GetValue(); | 192 CFX_WideString sOldValue = m_pWidget->GetValue(); |
193 CFX_WideString sNewValue = pWnd->GetText(); | 193 CFX_WideString sNewValue = pWnd->GetText(); |
194 | 194 |
195 » » m_pWidget->SetValue(sNewValue, FALSE); | 195 » » m_pWidget->SetValue(sNewValue, false); |
196 » » m_pWidget->ResetFieldAppearance(TRUE); | 196 » » m_pWidget->ResetFieldAppearance(true); |
197 m_pWidget->UpdateField(); | 197 m_pWidget->UpdateField(); |
198 SetChangeMark(); | 198 SetChangeMark(); |
199 } | 199 } |
200 } | 200 } |
201 | 201 |
202 void CFFL_TextField::GetActionData(CPDFSDK_PageView* pPageView, CPDF_AAction::AA
ctionType type, | 202 void CFFL_TextField::GetActionData(CPDFSDK_PageView* pPageView, CPDF_AAction::AA
ctionType type, |
203 PDFSDK_F
ieldAction& fa) | 203 PDFSDK_F
ieldAction& fa) |
204 { | 204 { |
205 switch (type) | 205 switch (type) |
206 { | 206 { |
207 case CPDF_AAction::KeyStroke: | 207 case CPDF_AAction::KeyStroke: |
208 » » if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, FALSE)
) | 208 » » if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, false)
) |
209 { | 209 { |
210 fa.bFieldFull = pWnd->IsTextFull(); | 210 fa.bFieldFull = pWnd->IsTextFull(); |
211 | 211 |
212 fa.sValue = pWnd->GetText(); | 212 fa.sValue = pWnd->GetText(); |
213 | 213 |
214 if (fa.bFieldFull) | 214 if (fa.bFieldFull) |
215 { | 215 { |
216 fa.sChange = L""; | 216 fa.sChange = L""; |
217 fa.sChangeEx = L""; | 217 fa.sChangeEx = L""; |
218 } | 218 } |
219 } | 219 } |
220 break; | 220 break; |
221 case CPDF_AAction::Validate: | 221 case CPDF_AAction::Validate: |
222 » » if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, FALSE)
) | 222 » » if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, false)
) |
223 { | 223 { |
224 fa.sValue = pWnd->GetText(); | 224 fa.sValue = pWnd->GetText(); |
225 } | 225 } |
226 break; | 226 break; |
227 case CPDF_AAction::LoseFocus: | 227 case CPDF_AAction::LoseFocus: |
228 case CPDF_AAction::GetFocus: | 228 case CPDF_AAction::GetFocus: |
229 ASSERT(m_pWidget != NULL); | 229 ASSERT(m_pWidget != NULL); |
230 fa.sValue = m_pWidget->GetValue(); | 230 fa.sValue = m_pWidget->GetValue(); |
231 break; | 231 break; |
232 default: | 232 default: |
233 break; | 233 break; |
234 } | 234 } |
235 } | 235 } |
236 | 236 |
237 void CFFL_TextField::SetActionData(CPDFSDK_PageView* pPageView, CPDF_AAction::AA
ctionType type, | 237 void CFFL_TextField::SetActionData(CPDFSDK_PageView* pPageView, CPDF_AAction::AA
ctionType type, |
238 const PD
FSDK_FieldAction& fa) | 238 const PD
FSDK_FieldAction& fa) |
239 { | 239 { |
240 switch (type) | 240 switch (type) |
241 { | 241 { |
242 case CPDF_AAction::KeyStroke: | 242 case CPDF_AAction::KeyStroke: |
243 » » if (CPWL_Edit * pEdit = (CPWL_Edit*)GetPDFWindow(pPageView, FALS
E)) | 243 » » if (CPWL_Edit * pEdit = (CPWL_Edit*)GetPDFWindow(pPageView, fals
e)) |
244 { | 244 { |
245 pEdit->SetFocus(); | 245 pEdit->SetFocus(); |
246 pEdit->SetSel(fa.nSelStart, fa.nSelEnd); | 246 pEdit->SetSel(fa.nSelStart, fa.nSelEnd); |
247 pEdit->ReplaceSel(fa.sChange.c_str()); | 247 pEdit->ReplaceSel(fa.sChange.c_str()); |
248 } | 248 } |
249 break; | 249 break; |
250 default: | 250 default: |
251 break; | 251 break; |
252 } | 252 } |
253 } | 253 } |
254 | 254 |
255 | 255 |
256 FX_BOOL»CFFL_TextField::IsActionDataChanged(CPDF_AAction::AActionType type, cons
t PDFSDK_FieldAction& faOld, | 256 bool» CFFL_TextField::IsActionDataChanged(CPDF_AAction::AActionType type, cons
t PDFSDK_FieldAction& faOld, |
257 const PD
FSDK_FieldAction& faNew) | 257 const PD
FSDK_FieldAction& faNew) |
258 { | 258 { |
259 switch (type) | 259 switch (type) |
260 { | 260 { |
261 case CPDF_AAction::KeyStroke: | 261 case CPDF_AAction::KeyStroke: |
262 return (!faOld.bFieldFull && faOld.nSelEnd != faNew.nSelEnd) ||
faOld.nSelStart != faNew.nSelStart || | 262 return (!faOld.bFieldFull && faOld.nSelEnd != faNew.nSelEnd) ||
faOld.nSelStart != faNew.nSelStart || |
263 faOld.sChange != faNew.sChange; | 263 faOld.sChange != faNew.sChange; |
264 default: | 264 default: |
265 break; | 265 break; |
266 } | 266 } |
267 | 267 |
268 » return FALSE; | 268 » return false; |
269 } | 269 } |
270 | 270 |
271 void CFFL_TextField::SaveState(CPDFSDK_PageView* pPageView) | 271 void CFFL_TextField::SaveState(CPDFSDK_PageView* pPageView) |
272 { | 272 { |
273 ASSERT(pPageView != NULL); | 273 ASSERT(pPageView != NULL); |
274 | 274 |
275 » if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, FALSE)) | 275 » if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, false)) |
276 { | 276 { |
277 pWnd->GetSel(m_State.nStart, m_State.nEnd); | 277 pWnd->GetSel(m_State.nStart, m_State.nEnd); |
278 m_State.sValue = pWnd->GetText(); | 278 m_State.sValue = pWnd->GetText(); |
279 } | 279 } |
280 } | 280 } |
281 | 281 |
282 void CFFL_TextField::RestoreState(CPDFSDK_PageView* pPageView) | 282 void CFFL_TextField::RestoreState(CPDFSDK_PageView* pPageView) |
283 { | 283 { |
284 ASSERT(pPageView != NULL); | 284 ASSERT(pPageView != NULL); |
285 | 285 |
286 » if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, TRUE)) | 286 » if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, true)) |
287 { | 287 { |
288 pWnd->SetText(m_State.sValue.c_str()); | 288 pWnd->SetText(m_State.sValue.c_str()); |
289 pWnd->SetSel(m_State.nStart, m_State.nEnd); | 289 pWnd->SetSel(m_State.nStart, m_State.nEnd); |
290 } | 290 } |
291 } | 291 } |
292 | 292 |
293 CPWL_Wnd* CFFL_TextField::ResetPDFWindow(CPDFSDK_PageView* pPageView, FX_BOOL bR
estoreValue) | 293 CPWL_Wnd* CFFL_TextField::ResetPDFWindow(CPDFSDK_PageView* pPageView, bool bRest
oreValue) |
294 { | 294 { |
295 if (bRestoreValue) | 295 if (bRestoreValue) |
296 SaveState(pPageView); | 296 SaveState(pPageView); |
297 | 297 |
298 DestroyPDFWindow(pPageView); | 298 DestroyPDFWindow(pPageView); |
299 | 299 |
300 CPWL_Wnd* pRet = NULL; | 300 CPWL_Wnd* pRet = NULL; |
301 | 301 |
302 if (bRestoreValue) | 302 if (bRestoreValue) |
303 { | 303 { |
304 RestoreState(pPageView); | 304 RestoreState(pPageView); |
305 » » pRet = GetPDFWindow(pPageView, FALSE); | 305 » » pRet = GetPDFWindow(pPageView, false); |
306 } | 306 } |
307 else | 307 else |
308 » » pRet = GetPDFWindow(pPageView, TRUE); | 308 » » pRet = GetPDFWindow(pPageView, true); |
309 | 309 |
310 m_pWidget->UpdateField(); | 310 m_pWidget->UpdateField(); |
311 | 311 |
312 return pRet; | 312 return pRet; |
313 } | 313 } |
314 | 314 |
315 void CFFL_TextField::OnSetFocus(CPWL_Wnd* pWnd) | 315 void CFFL_TextField::OnSetFocus(CPWL_Wnd* pWnd) |
316 { | 316 { |
317 ASSERT(m_pApp != NULL); | 317 ASSERT(m_pApp != NULL); |
318 | 318 |
319 ASSERT(pWnd != NULL); | 319 ASSERT(pWnd != NULL); |
320 | 320 |
321 if (pWnd->GetClassName() == PWL_CLASSNAME_EDIT) | 321 if (pWnd->GetClassName() == PWL_CLASSNAME_EDIT) |
322 { | 322 { |
323 CPWL_Edit* pEdit = (CPWL_Edit*)pWnd; | 323 CPWL_Edit* pEdit = (CPWL_Edit*)pWnd; |
324 pEdit->SetCharSet(134); | 324 pEdit->SetCharSet(134); |
325 pEdit->SetCodePage(936); | 325 pEdit->SetCodePage(936); |
326 | 326 |
327 pEdit->SetReadyToInput(); | 327 pEdit->SetReadyToInput(); |
328 CFX_WideString wsText = pEdit->GetText(); | 328 CFX_WideString wsText = pEdit->GetText(); |
329 int nCharacters = wsText.GetLength(); | 329 int nCharacters = wsText.GetLength(); |
330 CFX_ByteString bsUTFText = wsText.UTF16LE_Encode(); | 330 CFX_ByteString bsUTFText = wsText.UTF16LE_Encode(); |
331 unsigned short* pBuffer = (unsigned short*)bsUTFText.c_str(); | 331 unsigned short* pBuffer = (unsigned short*)bsUTFText.c_str(); |
332 » » m_pApp->FFI_OnSetFieldInputFocus(m_pWidget->GetFormField(), pBuf
fer, nCharacters, TRUE); | 332 » » m_pApp->FFI_OnSetFieldInputFocus(m_pWidget->GetFormField(), pBuf
fer, nCharacters, true); |
333 | 333 |
334 pEdit->SetEditNotify(this); | 334 pEdit->SetEditNotify(this); |
335 //pUndo->BeginEdit(pDocument); | 335 //pUndo->BeginEdit(pDocument); |
336 } | 336 } |
337 } | 337 } |
338 | 338 |
339 void CFFL_TextField::OnKillFocus(CPWL_Wnd* pWnd) | 339 void CFFL_TextField::OnKillFocus(CPWL_Wnd* pWnd) |
340 { | 340 { |
341 | 341 |
342 } | 342 } |
343 | 343 |
344 FX_BOOL»CFFL_TextField::CanCopy(CPDFSDK_Document* pDocument) | 344 bool» CFFL_TextField::CanCopy(CPDFSDK_Document* pDocument) |
345 { | 345 { |
346 » return FALSE; | 346 » return false; |
347 } | 347 } |
348 | 348 |
349 FX_BOOL CFFL_TextField::CanCut(CPDFSDK_Document* pDocument) | 349 bool CFFL_TextField::CanCut(CPDFSDK_Document* pDocument) |
350 { | 350 { |
351 » return FALSE; | 351 » return false; |
352 } | 352 } |
353 | 353 |
354 FX_BOOL»CFFL_TextField::CanPaste(CPDFSDK_Document* pDocument) | 354 bool» CFFL_TextField::CanPaste(CPDFSDK_Document* pDocument) |
355 { | 355 { |
356 » return FALSE; | 356 » return false; |
357 } | 357 } |
358 | 358 |
359 void CFFL_TextField::OnAddUndo(CPWL_Edit* pEdit) | 359 void CFFL_TextField::OnAddUndo(CPWL_Edit* pEdit) |
360 { | 360 { |
361 } | 361 } |
362 | 362 |
OLD | NEW |