| 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 "Field.h" | 7 #include "Field.h" |
| 8 | 8 |
| 9 #include "Document.h" | 9 #include "Document.h" |
| 10 #include "Icon.h" | 10 #include "Icon.h" |
| (...skipping 2720 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2731 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); | 2731 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 2732 if (FieldArray.empty()) | 2732 if (FieldArray.empty()) |
| 2733 return FALSE; | 2733 return FALSE; |
| 2734 | 2734 |
| 2735 CPDF_FormField* pFormField = FieldArray[0]; | 2735 CPDF_FormField* pFormField = FieldArray[0]; |
| 2736 switch (pFormField->GetFieldType()) { | 2736 switch (pFormField->GetFieldType()) { |
| 2737 case FIELDTYPE_PUSHBUTTON: | 2737 case FIELDTYPE_PUSHBUTTON: |
| 2738 return FALSE; | 2738 return FALSE; |
| 2739 case FIELDTYPE_COMBOBOX: | 2739 case FIELDTYPE_COMBOBOX: |
| 2740 case FIELDTYPE_TEXTFIELD: { | 2740 case FIELDTYPE_TEXTFIELD: { |
| 2741 CFX_WideString swValue = pFormField->GetValue(); | 2741 vp << pFormField->GetValue(); |
| 2742 | |
| 2743 double dRet; | |
| 2744 FX_BOOL bDot; | |
| 2745 if (CJS_PublicMethods::ConvertStringToNumber(swValue.c_str(), dRet, | |
| 2746 bDot)) { | |
| 2747 if (bDot) | |
| 2748 vp << dRet; | |
| 2749 else | |
| 2750 vp << dRet; | |
| 2751 } else { | |
| 2752 vp << swValue; | |
| 2753 } | |
| 2754 } break; | 2742 } break; |
| 2755 case FIELDTYPE_LISTBOX: { | 2743 case FIELDTYPE_LISTBOX: { |
| 2756 if (pFormField->CountSelectedItems() > 1) { | 2744 if (pFormField->CountSelectedItems() > 1) { |
| 2757 CJS_Array ValueArray(pRuntime); | 2745 CJS_Array ValueArray(pRuntime); |
| 2758 CJS_Value ElementValue(pRuntime); | 2746 CJS_Value ElementValue(pRuntime); |
| 2759 int iIndex; | 2747 int iIndex; |
| 2760 for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) { | 2748 for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) { |
| 2761 iIndex = pFormField->GetSelectedIndex(i); | 2749 iIndex = pFormField->GetSelectedIndex(i); |
| 2762 ElementValue = pFormField->GetOptionValue(iIndex).c_str(); | 2750 ElementValue = pFormField->GetOptionValue(iIndex).c_str(); |
| 2763 if (FXSYS_wcslen(ElementValue.ToCFXWideString().c_str()) == 0) | 2751 if (FXSYS_wcslen(ElementValue.ToCFXWideString().c_str()) == 0) |
| 2764 ElementValue = pFormField->GetOptionLabel(iIndex).c_str(); | 2752 ElementValue = pFormField->GetOptionLabel(iIndex).c_str(); |
| 2765 ValueArray.SetElement(i, ElementValue); | 2753 ValueArray.SetElement(i, ElementValue); |
| 2766 } | 2754 } |
| 2767 vp << ValueArray; | 2755 vp << ValueArray; |
| 2768 } else { | 2756 } else { |
| 2769 CFX_WideString swValue = pFormField->GetValue(); | 2757 vp << pFormField->GetValue(); |
| 2770 | |
| 2771 double dRet; | |
| 2772 FX_BOOL bDot; | |
| 2773 if (CJS_PublicMethods::ConvertStringToNumber(swValue.c_str(), dRet, | |
| 2774 bDot)) { | |
| 2775 if (bDot) | |
| 2776 vp << dRet; | |
| 2777 else | |
| 2778 vp << dRet; | |
| 2779 } else { | |
| 2780 vp << swValue; | |
| 2781 } | |
| 2782 } | 2758 } |
| 2783 } break; | 2759 } break; |
| 2784 case FIELDTYPE_CHECKBOX: | 2760 case FIELDTYPE_CHECKBOX: |
| 2785 case FIELDTYPE_RADIOBUTTON: { | 2761 case FIELDTYPE_RADIOBUTTON: { |
| 2786 FX_BOOL bFind = FALSE; | 2762 bool bFind = false; |
| 2787 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) { | 2763 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) { |
| 2788 if (!pFormField->GetControl(i)->IsChecked()) | 2764 if (pFormField->GetControl(i)->IsChecked()) { |
| 2789 continue; | 2765 vp << pFormField->GetControl(i)->GetExportValue(); |
| 2790 | 2766 bFind = true; |
| 2791 CFX_WideString swValue = pFormField->GetControl(i)->GetExportValue(); | 2767 break; |
| 2792 double dRet; | |
| 2793 FX_BOOL bDotDummy; | |
| 2794 if (CJS_PublicMethods::ConvertStringToNumber(swValue.c_str(), dRet, | |
| 2795 bDotDummy)) { | |
| 2796 vp << dRet; | |
| 2797 } else { | |
| 2798 vp << swValue; | |
| 2799 } | 2768 } |
| 2800 | |
| 2801 bFind = TRUE; | |
| 2802 break; | |
| 2803 } | 2769 } |
| 2804 if (!bFind) | 2770 if (!bFind) |
| 2805 vp << L"Off"; | 2771 vp << L"Off"; |
| 2806 } break; | 2772 } break; |
| 2807 default: | 2773 default: |
| 2808 vp << pFormField->GetValue(); | 2774 vp << pFormField->GetValue(); |
| 2809 break; | 2775 break; |
| 2810 } | 2776 } |
| 2811 } | 2777 } |
| 2812 | 2778 vp.MaybeCoerceToNumber(); |
| 2813 return TRUE; | 2779 return TRUE; |
| 2814 } | 2780 } |
| 2815 | 2781 |
| 2816 void Field::SetValue(CPDFSDK_Document* pDocument, | 2782 void Field::SetValue(CPDFSDK_Document* pDocument, |
| 2817 const CFX_WideString& swFieldName, | 2783 const CFX_WideString& swFieldName, |
| 2818 int nControlIndex, | 2784 int nControlIndex, |
| 2819 const CJS_WideStringArray& strArray) { | 2785 const CJS_WideStringArray& strArray) { |
| 2820 ASSERT(pDocument); | 2786 ASSERT(pDocument); |
| 2821 | 2787 |
| 2822 if (strArray.GetSize() < 1) | 2788 if (strArray.GetSize() < 1) |
| (...skipping 797 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3620 } | 3586 } |
| 3621 } | 3587 } |
| 3622 | 3588 |
| 3623 void Field::AddField(CPDFSDK_Document* pDocument, | 3589 void Field::AddField(CPDFSDK_Document* pDocument, |
| 3624 int nPageIndex, | 3590 int nPageIndex, |
| 3625 int nFieldType, | 3591 int nFieldType, |
| 3626 const CFX_WideString& sName, | 3592 const CFX_WideString& sName, |
| 3627 const CPDF_Rect& rcCoords) { | 3593 const CPDF_Rect& rcCoords) { |
| 3628 // Not supported. | 3594 // Not supported. |
| 3629 } | 3595 } |
| OLD | NEW |