OLD | NEW |
1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 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/cpdfsdk_interform.h" | 7 #include "fpdfsdk/include/cpdfsdk_interform.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 pRuntime->ReleaseContext(pContext); | 269 pRuntime->ReleaseContext(pContext); |
270 | 270 |
271 if (bRet && bRC && sValue.Compare(sOldValue) != 0) | 271 if (bRet && bRC && sValue.Compare(sOldValue) != 0) |
272 pField->SetValue(sValue, TRUE); | 272 pField->SetValue(sValue, TRUE); |
273 } | 273 } |
274 | 274 |
275 m_bBusy = FALSE; | 275 m_bBusy = FALSE; |
276 } | 276 } |
277 | 277 |
278 CFX_WideString CPDFSDK_InterForm::OnFormat(CPDF_FormField* pFormField, | 278 CFX_WideString CPDFSDK_InterForm::OnFormat(CPDF_FormField* pFormField, |
279 FX_BOOL& bFormated) { | 279 FX_BOOL& bFormatted) { |
280 CFX_WideString sValue = pFormField->GetValue(); | 280 CFX_WideString sValue = pFormField->GetValue(); |
281 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); | 281 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); |
282 ASSERT(pEnv); | 282 ASSERT(pEnv); |
283 if (!pEnv->IsJSInitiated()) { | 283 if (!pEnv->IsJSInitiated()) { |
284 bFormated = FALSE; | 284 bFormatted = FALSE; |
285 return sValue; | 285 return sValue; |
286 } | 286 } |
287 | 287 |
288 IJS_Runtime* pRuntime = m_pDocument->GetJsRuntime(); | 288 IJS_Runtime* pRuntime = m_pDocument->GetJsRuntime(); |
289 pRuntime->SetReaderDocument(m_pDocument); | 289 pRuntime->SetReaderDocument(m_pDocument); |
290 | 290 |
291 if (pFormField->GetFieldType() == FIELDTYPE_COMBOBOX && | 291 if (pFormField->GetFieldType() == FIELDTYPE_COMBOBOX && |
292 pFormField->CountSelectedItems() > 0) { | 292 pFormField->CountSelectedItems() > 0) { |
293 int index = pFormField->GetSelectedIndex(0); | 293 int index = pFormField->GetSelectedIndex(0); |
294 if (index >= 0) | 294 if (index >= 0) |
295 sValue = pFormField->GetOptionLabel(index); | 295 sValue = pFormField->GetOptionLabel(index); |
296 } | 296 } |
297 | 297 |
298 bFormated = FALSE; | 298 bFormatted = FALSE; |
299 | 299 |
300 CPDF_AAction aAction = pFormField->GetAdditionalAction(); | 300 CPDF_AAction aAction = pFormField->GetAdditionalAction(); |
301 if (aAction.GetDict() && aAction.ActionExist(CPDF_AAction::Format)) { | 301 if (aAction.GetDict() && aAction.ActionExist(CPDF_AAction::Format)) { |
302 CPDF_Action action = aAction.GetAction(CPDF_AAction::Format); | 302 CPDF_Action action = aAction.GetAction(CPDF_AAction::Format); |
303 if (action.GetDict()) { | 303 if (action.GetDict()) { |
304 CFX_WideString script = action.GetJavaScript(); | 304 CFX_WideString script = action.GetJavaScript(); |
305 if (!script.IsEmpty()) { | 305 if (!script.IsEmpty()) { |
306 CFX_WideString Value = sValue; | 306 CFX_WideString Value = sValue; |
307 | 307 |
308 IJS_Context* pContext = pRuntime->NewContext(); | 308 IJS_Context* pContext = pRuntime->NewContext(); |
309 pContext->OnField_Format(pFormField, Value, TRUE); | 309 pContext->OnField_Format(pFormField, Value, TRUE); |
310 CFX_WideString sInfo; | 310 CFX_WideString sInfo; |
311 FX_BOOL bRet = pContext->RunScript(script, &sInfo); | 311 FX_BOOL bRet = pContext->RunScript(script, &sInfo); |
312 pRuntime->ReleaseContext(pContext); | 312 pRuntime->ReleaseContext(pContext); |
313 | 313 |
314 if (bRet) { | 314 if (bRet) { |
315 sValue = Value; | 315 sValue = Value; |
316 bFormated = TRUE; | 316 bFormatted = TRUE; |
317 } | 317 } |
318 } | 318 } |
319 } | 319 } |
320 } | 320 } |
321 | 321 |
322 return sValue; | 322 return sValue; |
323 } | 323 } |
324 | 324 |
325 void CPDFSDK_InterForm::ResetFieldAppearance(CPDF_FormField* pFormField, | 325 void CPDFSDK_InterForm::ResetFieldAppearance(CPDF_FormField* pFormField, |
326 const FX_WCHAR* sValue, | 326 const FX_WCHAR* sValue, |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
625 return 1; | 625 return 1; |
626 } | 626 } |
627 | 627 |
628 void CPDFSDK_InterForm::AfterValueChange(CPDF_FormField* pField) { | 628 void CPDFSDK_InterForm::AfterValueChange(CPDF_FormField* pField) { |
629 #ifdef PDF_ENABLE_XFA | 629 #ifdef PDF_ENABLE_XFA |
630 SynchronizeField(pField, FALSE); | 630 SynchronizeField(pField, FALSE); |
631 #endif // PDF_ENABLE_XFA | 631 #endif // PDF_ENABLE_XFA |
632 int nType = pField->GetFieldType(); | 632 int nType = pField->GetFieldType(); |
633 if (nType == FIELDTYPE_COMBOBOX || nType == FIELDTYPE_TEXTFIELD) { | 633 if (nType == FIELDTYPE_COMBOBOX || nType == FIELDTYPE_TEXTFIELD) { |
634 OnCalculate(pField); | 634 OnCalculate(pField); |
635 FX_BOOL bFormated = FALSE; | 635 FX_BOOL bFormatted = FALSE; |
636 CFX_WideString sValue = OnFormat(pField, bFormated); | 636 CFX_WideString sValue = OnFormat(pField, bFormatted); |
637 ResetFieldAppearance(pField, bFormated ? sValue.c_str() : nullptr, TRUE); | 637 ResetFieldAppearance(pField, bFormatted ? sValue.c_str() : nullptr, TRUE); |
638 UpdateField(pField); | 638 UpdateField(pField); |
639 } | 639 } |
640 } | 640 } |
641 | 641 |
642 int CPDFSDK_InterForm::BeforeSelectionChange(CPDF_FormField* pField, | 642 int CPDFSDK_InterForm::BeforeSelectionChange(CPDF_FormField* pField, |
643 const CFX_WideString& csValue) { | 643 const CFX_WideString& csValue) { |
644 if (pField->GetFieldType() != FIELDTYPE_LISTBOX) | 644 if (pField->GetFieldType() != FIELDTYPE_LISTBOX) |
645 return 0; | 645 return 0; |
646 | 646 |
647 if (!OnKeyStrokeCommit(pField, csValue)) | 647 if (!OnKeyStrokeCommit(pField, csValue)) |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
717 } | 717 } |
718 } | 718 } |
719 | 719 |
720 FX_COLORREF CPDFSDK_InterForm::GetHighlightColor(int nFieldType) { | 720 FX_COLORREF CPDFSDK_InterForm::GetHighlightColor(int nFieldType) { |
721 if (nFieldType < 0 || nFieldType > kNumFieldTypes) | 721 if (nFieldType < 0 || nFieldType > kNumFieldTypes) |
722 return FXSYS_RGB(255, 255, 255); | 722 return FXSYS_RGB(255, 255, 255); |
723 if (nFieldType == 0) | 723 if (nFieldType == 0) |
724 return m_aHighlightColor[0]; | 724 return m_aHighlightColor[0]; |
725 return m_aHighlightColor[nFieldType - 1]; | 725 return m_aHighlightColor[nFieldType - 1]; |
726 } | 726 } |
OLD | NEW |