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