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/javascript/Field.h" | 7 #include "fpdfsdk/javascript/Field.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 IMPLEMENT_JS_CLASS(CJS_Field, Field) | 116 IMPLEMENT_JS_CLASS(CJS_Field, Field) |
117 | 117 |
118 CJS_DelayData::CJS_DelayData(FIELD_PROP prop, | 118 CJS_DelayData::CJS_DelayData(FIELD_PROP prop, |
119 int idx, | 119 int idx, |
120 const CFX_WideString& name) | 120 const CFX_WideString& name) |
121 : eProp(prop), nControlIndex(idx), sFieldName(name) {} | 121 : eProp(prop), nControlIndex(idx), sFieldName(name) {} |
122 | 122 |
123 CJS_DelayData::~CJS_DelayData() {} | 123 CJS_DelayData::~CJS_DelayData() {} |
124 | 124 |
125 void CJS_Field::InitInstance(IJS_Runtime* pIRuntime) { | 125 void CJS_Field::InitInstance(IJS_Runtime* pIRuntime) { |
126 CJS_Runtime* pRuntime = static_cast<CJS_Runtime*>(pIRuntime); | |
127 Field* pField = static_cast<Field*>(GetEmbedObject()); | |
128 pField->SetIsolate(pRuntime->GetIsolate()); | |
129 } | 126 } |
130 | 127 |
131 Field::Field(CJS_Object* pJSObject) | 128 Field::Field(CJS_Object* pJSObject) |
132 : CJS_EmbedObj(pJSObject), | 129 : CJS_EmbedObj(pJSObject), |
133 m_pJSDoc(nullptr), | 130 m_pJSDoc(nullptr), |
134 m_pDocument(nullptr), | 131 m_pDocument(nullptr), |
135 m_nFormControlIndex(-1), | 132 m_nFormControlIndex(-1), |
136 m_bCanSet(FALSE), | 133 m_bCanSet(FALSE), |
137 m_bDelay(FALSE), | 134 m_bDelay(FALSE) {} |
138 m_isolate(nullptr) {} | |
139 | 135 |
140 Field::~Field() {} | 136 Field::~Field() {} |
141 | 137 |
142 // note: iControlNo = -1, means not a widget. | 138 // note: iControlNo = -1, means not a widget. |
143 void Field::ParseFieldName(const std::wstring& strFieldNameParsed, | 139 void Field::ParseFieldName(const std::wstring& strFieldNameParsed, |
144 std::wstring& strFieldName, | 140 std::wstring& strFieldName, |
145 int& iControlNo) { | 141 int& iControlNo) { |
146 int iStart = strFieldNameParsed.find_last_of(L'.'); | 142 int iStart = strFieldNameParsed.find_last_of(L'.'); |
147 if (iStart == -1) { | 143 if (iStart == -1) { |
148 strFieldName = strFieldNameParsed; | 144 strFieldName = strFieldNameParsed; |
(...skipping 811 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
960 std::vector<uint32_t> array; | 956 std::vector<uint32_t> array; |
961 if (vp.GetJSValue()->GetType() == CJS_Value::VT_number) { | 957 if (vp.GetJSValue()->GetType() == CJS_Value::VT_number) { |
962 int iSelecting = 0; | 958 int iSelecting = 0; |
963 vp >> iSelecting; | 959 vp >> iSelecting; |
964 array.push_back(iSelecting); | 960 array.push_back(iSelecting); |
965 } else if (vp.GetJSValue()->IsArrayObject()) { | 961 } else if (vp.GetJSValue()->IsArrayObject()) { |
966 CJS_Array SelArray; | 962 CJS_Array SelArray; |
967 CJS_Value SelValue(pRuntime); | 963 CJS_Value SelValue(pRuntime); |
968 int iSelecting; | 964 int iSelecting; |
969 vp >> SelArray; | 965 vp >> SelArray; |
970 for (int i = 0, sz = SelArray.GetLength(); i < sz; i++) { | 966 for (int i = 0, sz = SelArray.GetLength(pRuntime); i < sz; i++) { |
971 SelArray.GetElement(pRuntime->GetIsolate(), i, SelValue); | 967 SelArray.GetElement(pRuntime, i, SelValue); |
972 iSelecting = SelValue.ToInt(pRuntime->GetIsolate()); | 968 iSelecting = SelValue.ToInt(pRuntime); |
973 array.push_back(iSelecting); | 969 array.push_back(iSelecting); |
974 } | 970 } |
975 } | 971 } |
976 | 972 |
977 if (m_bDelay) { | 973 if (m_bDelay) { |
978 AddDelay_WordArray(FP_CURRENTVALUEINDICES, array); | 974 AddDelay_WordArray(FP_CURRENTVALUEINDICES, array); |
979 } else { | 975 } else { |
980 Field::SetCurrentValueIndices(m_pDocument, m_FieldName, | 976 Field::SetCurrentValueIndices(m_pDocument, m_FieldName, |
981 m_nFormControlIndex, array); | 977 m_nFormControlIndex, array); |
982 } | 978 } |
983 } else { | 979 } else { |
984 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); | 980 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
985 if (FieldArray.empty()) | 981 if (FieldArray.empty()) |
986 return FALSE; | 982 return FALSE; |
987 | 983 |
988 CPDF_FormField* pFormField = FieldArray[0]; | 984 CPDF_FormField* pFormField = FieldArray[0]; |
989 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX && | 985 if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX && |
990 pFormField->GetFieldType() != FIELDTYPE_LISTBOX) { | 986 pFormField->GetFieldType() != FIELDTYPE_LISTBOX) { |
991 return FALSE; | 987 return FALSE; |
992 } | 988 } |
993 | 989 |
994 if (pFormField->CountSelectedItems() == 1) { | 990 if (pFormField->CountSelectedItems() == 1) { |
995 vp << pFormField->GetSelectedIndex(0); | 991 vp << pFormField->GetSelectedIndex(0); |
996 } else if (pFormField->CountSelectedItems() > 1) { | 992 } else if (pFormField->CountSelectedItems() > 1) { |
997 CJS_Array SelArray; | 993 CJS_Array SelArray; |
998 for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) { | 994 for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) { |
999 SelArray.SetElement( | 995 SelArray.SetElement( |
1000 pRuntime->GetIsolate(), i, | 996 pRuntime, i, CJS_Value(pRuntime, pFormField->GetSelectedIndex(i))); |
1001 CJS_Value(pRuntime, pFormField->GetSelectedIndex(i))); | |
1002 } | 997 } |
1003 vp << SelArray; | 998 vp << SelArray; |
1004 } else { | 999 } else { |
1005 vp << -1; | 1000 vp << -1; |
1006 } | 1001 } |
1007 } | 1002 } |
1008 | 1003 |
1009 return TRUE; | 1004 return TRUE; |
1010 } | 1005 } |
1011 | 1006 |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1382 | 1377 |
1383 if (!vp.GetJSValue()->IsArrayObject()) | 1378 if (!vp.GetJSValue()->IsArrayObject()) |
1384 return FALSE; | 1379 return FALSE; |
1385 } else { | 1380 } else { |
1386 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 1381 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
1387 CJS_Array ExportValusArray; | 1382 CJS_Array ExportValusArray; |
1388 if (m_nFormControlIndex < 0) { | 1383 if (m_nFormControlIndex < 0) { |
1389 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) { | 1384 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) { |
1390 CPDF_FormControl* pFormControl = pFormField->GetControl(i); | 1385 CPDF_FormControl* pFormControl = pFormField->GetControl(i); |
1391 ExportValusArray.SetElement( | 1386 ExportValusArray.SetElement( |
1392 pRuntime->GetIsolate(), i, | 1387 pRuntime, i, |
1393 CJS_Value(pRuntime, pFormControl->GetExportValue().c_str())); | 1388 CJS_Value(pRuntime, pFormControl->GetExportValue().c_str())); |
1394 } | 1389 } |
1395 } else { | 1390 } else { |
1396 if (m_nFormControlIndex >= pFormField->CountControls()) | 1391 if (m_nFormControlIndex >= pFormField->CountControls()) |
1397 return FALSE; | 1392 return FALSE; |
1398 | 1393 |
1399 CPDF_FormControl* pFormControl = | 1394 CPDF_FormControl* pFormControl = |
1400 pFormField->GetControl(m_nFormControlIndex); | 1395 pFormField->GetControl(m_nFormControlIndex); |
1401 if (!pFormControl) | 1396 if (!pFormControl) |
1402 return FALSE; | 1397 return FALSE; |
1403 | 1398 |
1404 ExportValusArray.SetElement( | 1399 ExportValusArray.SetElement( |
1405 pRuntime->GetIsolate(), 0, | 1400 pRuntime, 0, |
1406 CJS_Value(pRuntime, pFormControl->GetExportValue().c_str())); | 1401 CJS_Value(pRuntime, pFormControl->GetExportValue().c_str())); |
1407 } | 1402 } |
1408 vp << ExportValusArray; | 1403 vp << ExportValusArray; |
1409 } | 1404 } |
1410 return TRUE; | 1405 return TRUE; |
1411 } | 1406 } |
1412 | 1407 |
1413 FX_BOOL Field::fileSelect(IJS_Context* cc, | 1408 FX_BOOL Field::fileSelect(IJS_Context* cc, |
1414 CJS_PropValue& vp, | 1409 CJS_PropValue& vp, |
1415 CFX_WideString& sError) { | 1410 CFX_WideString& sError) { |
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1897 } | 1892 } |
1898 | 1893 |
1899 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 1894 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
1900 CJS_Array PageArray; | 1895 CJS_Array PageArray; |
1901 for (size_t i = 0; i < widgets.size(); ++i) { | 1896 for (size_t i = 0; i < widgets.size(); ++i) { |
1902 CPDFSDK_PageView* pPageView = widgets[i]->GetPageView(); | 1897 CPDFSDK_PageView* pPageView = widgets[i]->GetPageView(); |
1903 if (!pPageView) | 1898 if (!pPageView) |
1904 return FALSE; | 1899 return FALSE; |
1905 | 1900 |
1906 PageArray.SetElement( | 1901 PageArray.SetElement( |
1907 pRuntime->GetIsolate(), i, | 1902 pRuntime, i, CJS_Value(pRuntime, (int32_t)pPageView->GetPageIndex())); |
1908 CJS_Value(pRuntime, (int32_t)pPageView->GetPageIndex())); | |
1909 } | 1903 } |
1910 | 1904 |
1911 vp << PageArray; | 1905 vp << PageArray; |
1912 return TRUE; | 1906 return TRUE; |
1913 } | 1907 } |
1914 | 1908 |
1915 FX_BOOL Field::password(IJS_Context* cc, | 1909 FX_BOOL Field::password(IJS_Context* cc, |
1916 CJS_PropValue& vp, | 1910 CJS_PropValue& vp, |
1917 CFX_WideString& sError) { | 1911 CFX_WideString& sError) { |
1918 ASSERT(m_pDocument); | 1912 ASSERT(m_pDocument); |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2092 CJS_Value Lower_Righty(pRuntime); | 2086 CJS_Value Lower_Righty(pRuntime); |
2093 | 2087 |
2094 if (vp.IsSetting()) { | 2088 if (vp.IsSetting()) { |
2095 if (!m_bCanSet) | 2089 if (!m_bCanSet) |
2096 return FALSE; | 2090 return FALSE; |
2097 if (!vp.GetJSValue()->IsArrayObject()) | 2091 if (!vp.GetJSValue()->IsArrayObject()) |
2098 return FALSE; | 2092 return FALSE; |
2099 | 2093 |
2100 CJS_Array rcArray; | 2094 CJS_Array rcArray; |
2101 vp >> rcArray; | 2095 vp >> rcArray; |
2102 rcArray.GetElement(pRuntime->GetIsolate(), 0, Upper_Leftx); | 2096 rcArray.GetElement(pRuntime, 0, Upper_Leftx); |
2103 rcArray.GetElement(pRuntime->GetIsolate(), 1, Upper_Lefty); | 2097 rcArray.GetElement(pRuntime, 1, Upper_Lefty); |
2104 rcArray.GetElement(pRuntime->GetIsolate(), 2, Lower_Rightx); | 2098 rcArray.GetElement(pRuntime, 2, Lower_Rightx); |
2105 rcArray.GetElement(pRuntime->GetIsolate(), 3, Lower_Righty); | 2099 rcArray.GetElement(pRuntime, 3, Lower_Righty); |
2106 | 2100 |
2107 FX_FLOAT pArray[4] = {0.0f, 0.0f, 0.0f, 0.0f}; | 2101 FX_FLOAT pArray[4] = {0.0f, 0.0f, 0.0f, 0.0f}; |
2108 pArray[0] = | 2102 pArray[0] = static_cast<FX_FLOAT>(Upper_Leftx.ToInt(pRuntime)); |
2109 static_cast<FX_FLOAT>(Upper_Leftx.ToInt(pRuntime->GetIsolate())); | 2103 pArray[1] = static_cast<FX_FLOAT>(Lower_Righty.ToInt(pRuntime)); |
2110 pArray[1] = | 2104 pArray[2] = static_cast<FX_FLOAT>(Lower_Rightx.ToInt(pRuntime)); |
2111 static_cast<FX_FLOAT>(Lower_Righty.ToInt(pRuntime->GetIsolate())); | 2105 pArray[3] = static_cast<FX_FLOAT>(Upper_Lefty.ToInt(pRuntime)); |
2112 pArray[2] = | |
2113 static_cast<FX_FLOAT>(Lower_Rightx.ToInt(pRuntime->GetIsolate())); | |
2114 pArray[3] = | |
2115 static_cast<FX_FLOAT>(Upper_Lefty.ToInt(pRuntime->GetIsolate())); | |
2116 | 2106 |
2117 CFX_FloatRect crRect(pArray); | 2107 CFX_FloatRect crRect(pArray); |
2118 if (m_bDelay) { | 2108 if (m_bDelay) { |
2119 AddDelay_Rect(FP_RECT, crRect); | 2109 AddDelay_Rect(FP_RECT, crRect); |
2120 } else { | 2110 } else { |
2121 Field::SetRect(m_pDocument, m_FieldName, m_nFormControlIndex, crRect); | 2111 Field::SetRect(m_pDocument, m_FieldName, m_nFormControlIndex, crRect); |
2122 } | 2112 } |
2123 } else { | 2113 } else { |
2124 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); | 2114 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
2125 if (FieldArray.empty()) | 2115 if (FieldArray.empty()) |
2126 return FALSE; | 2116 return FALSE; |
2127 | 2117 |
2128 CPDF_FormField* pFormField = FieldArray[0]; | 2118 CPDF_FormField* pFormField = FieldArray[0]; |
2129 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); | 2119 CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); |
2130 CPDFSDK_Widget* pWidget = | 2120 CPDFSDK_Widget* pWidget = |
2131 pInterForm->GetWidget(GetSmartFieldControl(pFormField), true); | 2121 pInterForm->GetWidget(GetSmartFieldControl(pFormField), true); |
2132 if (!pWidget) | 2122 if (!pWidget) |
2133 return FALSE; | 2123 return FALSE; |
2134 | 2124 |
2135 CFX_FloatRect crRect = pWidget->GetRect(); | 2125 CFX_FloatRect crRect = pWidget->GetRect(); |
2136 Upper_Leftx = CJS_Value(pRuntime, static_cast<int32_t>(crRect.left)); | 2126 Upper_Leftx = CJS_Value(pRuntime, static_cast<int32_t>(crRect.left)); |
2137 Upper_Lefty = CJS_Value(pRuntime, static_cast<int32_t>(crRect.top)); | 2127 Upper_Lefty = CJS_Value(pRuntime, static_cast<int32_t>(crRect.top)); |
2138 Lower_Rightx = CJS_Value(pRuntime, static_cast<int32_t>(crRect.right)); | 2128 Lower_Rightx = CJS_Value(pRuntime, static_cast<int32_t>(crRect.right)); |
2139 Lower_Righty = CJS_Value(pRuntime, static_cast<int32_t>(crRect.bottom)); | 2129 Lower_Righty = CJS_Value(pRuntime, static_cast<int32_t>(crRect.bottom)); |
2140 | 2130 |
2141 CJS_Array rcArray; | 2131 CJS_Array rcArray; |
2142 rcArray.SetElement(pRuntime->GetIsolate(), 0, Upper_Leftx); | 2132 rcArray.SetElement(pRuntime, 0, Upper_Leftx); |
2143 rcArray.SetElement(pRuntime->GetIsolate(), 1, Upper_Lefty); | 2133 rcArray.SetElement(pRuntime, 1, Upper_Lefty); |
2144 rcArray.SetElement(pRuntime->GetIsolate(), 2, Lower_Rightx); | 2134 rcArray.SetElement(pRuntime, 2, Lower_Rightx); |
2145 rcArray.SetElement(pRuntime->GetIsolate(), 3, Lower_Righty); | 2135 rcArray.SetElement(pRuntime, 3, Lower_Righty); |
2146 vp << rcArray; | 2136 vp << rcArray; |
2147 } | 2137 } |
2148 return TRUE; | 2138 return TRUE; |
2149 } | 2139 } |
2150 | 2140 |
2151 void Field::SetRect(CPDFSDK_Document* pDocument, | 2141 void Field::SetRect(CPDFSDK_Document* pDocument, |
2152 const CFX_WideString& swFieldName, | 2142 const CFX_WideString& swFieldName, |
2153 int nControlIndex, | 2143 int nControlIndex, |
2154 const CFX_FloatRect& rect) { | 2144 const CFX_FloatRect& rect) { |
2155 CPDFSDK_InterForm* pInterForm = pDocument->GetInterForm(); | 2145 CPDFSDK_InterForm* pInterForm = pDocument->GetInterForm(); |
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2709 CFX_WideString& sError) { | 2699 CFX_WideString& sError) { |
2710 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 2700 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
2711 | 2701 |
2712 if (vp.IsSetting()) { | 2702 if (vp.IsSetting()) { |
2713 if (!m_bCanSet) | 2703 if (!m_bCanSet) |
2714 return FALSE; | 2704 return FALSE; |
2715 | 2705 |
2716 std::vector<CFX_WideString> strArray; | 2706 std::vector<CFX_WideString> strArray; |
2717 if (vp.GetJSValue()->IsArrayObject()) { | 2707 if (vp.GetJSValue()->IsArrayObject()) { |
2718 CJS_Array ValueArray; | 2708 CJS_Array ValueArray; |
2719 vp.GetJSValue()->ConvertToArray(pRuntime->GetIsolate(), ValueArray); | 2709 vp.GetJSValue()->ConvertToArray(pRuntime, ValueArray); |
2720 for (int i = 0, sz = ValueArray.GetLength(); i < sz; i++) { | 2710 for (int i = 0, sz = ValueArray.GetLength(pRuntime); i < sz; i++) { |
2721 CJS_Value ElementValue(pRuntime); | 2711 CJS_Value ElementValue(pRuntime); |
2722 ValueArray.GetElement(pRuntime->GetIsolate(), i, ElementValue); | 2712 ValueArray.GetElement(pRuntime, i, ElementValue); |
2723 strArray.push_back( | 2713 strArray.push_back(ElementValue.ToCFXWideString(pRuntime)); |
2724 ElementValue.ToCFXWideString(pRuntime->GetIsolate())); | |
2725 } | 2714 } |
2726 } else { | 2715 } else { |
2727 CFX_WideString swValue; | 2716 CFX_WideString swValue; |
2728 vp >> swValue; | 2717 vp >> swValue; |
2729 strArray.push_back(swValue); | 2718 strArray.push_back(swValue); |
2730 } | 2719 } |
2731 | 2720 |
2732 if (m_bDelay) { | 2721 if (m_bDelay) { |
2733 AddDelay_WideStringArray(FP_VALUE, strArray); | 2722 AddDelay_WideStringArray(FP_VALUE, strArray); |
2734 } else { | 2723 } else { |
(...skipping 14 matching lines...) Expand all Loading... |
2749 } break; | 2738 } break; |
2750 case FIELDTYPE_LISTBOX: { | 2739 case FIELDTYPE_LISTBOX: { |
2751 if (pFormField->CountSelectedItems() > 1) { | 2740 if (pFormField->CountSelectedItems() > 1) { |
2752 CJS_Array ValueArray; | 2741 CJS_Array ValueArray; |
2753 CJS_Value ElementValue(pRuntime); | 2742 CJS_Value ElementValue(pRuntime); |
2754 int iIndex; | 2743 int iIndex; |
2755 for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) { | 2744 for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) { |
2756 iIndex = pFormField->GetSelectedIndex(i); | 2745 iIndex = pFormField->GetSelectedIndex(i); |
2757 ElementValue = | 2746 ElementValue = |
2758 CJS_Value(pRuntime, pFormField->GetOptionValue(iIndex).c_str()); | 2747 CJS_Value(pRuntime, pFormField->GetOptionValue(iIndex).c_str()); |
2759 if (FXSYS_wcslen( | 2748 if (FXSYS_wcslen(ElementValue.ToCFXWideString(pRuntime).c_str()) == |
2760 ElementValue.ToCFXWideString(pRuntime->GetIsolate()) | 2749 0) { |
2761 .c_str()) == 0) { | |
2762 ElementValue = CJS_Value( | 2750 ElementValue = CJS_Value( |
2763 pRuntime, pFormField->GetOptionLabel(iIndex).c_str()); | 2751 pRuntime, pFormField->GetOptionLabel(iIndex).c_str()); |
2764 } | 2752 } |
2765 ValueArray.SetElement(pRuntime->GetIsolate(), i, ElementValue); | 2753 ValueArray.SetElement(pRuntime, i, ElementValue); |
2766 } | 2754 } |
2767 vp << ValueArray; | 2755 vp << ValueArray; |
2768 } else { | 2756 } else { |
2769 vp << pFormField->GetValue(); | 2757 vp << pFormField->GetValue(); |
2770 } | 2758 } |
2771 } break; | 2759 } break; |
2772 case FIELDTYPE_CHECKBOX: | 2760 case FIELDTYPE_CHECKBOX: |
2773 case FIELDTYPE_RADIOBUTTON: { | 2761 case FIELDTYPE_RADIOBUTTON: { |
2774 bool bFind = false; | 2762 bool bFind = false; |
2775 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) { | 2763 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) { |
2776 if (pFormField->GetControl(i)->IsChecked()) { | 2764 if (pFormField->GetControl(i)->IsChecked()) { |
2777 vp << pFormField->GetControl(i)->GetExportValue(); | 2765 vp << pFormField->GetControl(i)->GetExportValue(); |
2778 bFind = true; | 2766 bFind = true; |
2779 break; | 2767 break; |
2780 } | 2768 } |
2781 } | 2769 } |
2782 if (!bFind) | 2770 if (!bFind) |
2783 vp << L"Off"; | 2771 vp << L"Off"; |
2784 } break; | 2772 } break; |
2785 default: | 2773 default: |
2786 vp << pFormField->GetValue(); | 2774 vp << pFormField->GetValue(); |
2787 break; | 2775 break; |
2788 } | 2776 } |
2789 } | 2777 } |
2790 vp.GetJSValue()->MaybeCoerceToNumber(m_isolate); | 2778 vp.GetJSValue()->MaybeCoerceToNumber(pRuntime); |
2791 return TRUE; | 2779 return TRUE; |
2792 } | 2780 } |
2793 | 2781 |
2794 void Field::SetValue(CPDFSDK_Document* pDocument, | 2782 void Field::SetValue(CPDFSDK_Document* pDocument, |
2795 const CFX_WideString& swFieldName, | 2783 const CFX_WideString& swFieldName, |
2796 int nControlIndex, | 2784 int nControlIndex, |
2797 const std::vector<CFX_WideString>& strArray) { | 2785 const std::vector<CFX_WideString>& strArray) { |
2798 ASSERT(pDocument); | 2786 ASSERT(pDocument); |
2799 if (strArray.empty()) | 2787 if (strArray.empty()) |
2800 return; | 2788 return; |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2911 | 2899 |
2912 FX_BOOL Field::buttonGetCaption(IJS_Context* cc, | 2900 FX_BOOL Field::buttonGetCaption(IJS_Context* cc, |
2913 const std::vector<CJS_Value>& params, | 2901 const std::vector<CJS_Value>& params, |
2914 CJS_Value& vRet, | 2902 CJS_Value& vRet, |
2915 CFX_WideString& sError) { | 2903 CFX_WideString& sError) { |
2916 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 2904 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
2917 | 2905 |
2918 int nface = 0; | 2906 int nface = 0; |
2919 int iSize = params.size(); | 2907 int iSize = params.size(); |
2920 if (iSize >= 1) | 2908 if (iSize >= 1) |
2921 nface = params[0].ToInt(pRuntime->GetIsolate()); | 2909 nface = params[0].ToInt(pRuntime); |
2922 | 2910 |
2923 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); | 2911 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
2924 if (FieldArray.empty()) | 2912 if (FieldArray.empty()) |
2925 return FALSE; | 2913 return FALSE; |
2926 | 2914 |
2927 CPDF_FormField* pFormField = FieldArray[0]; | 2915 CPDF_FormField* pFormField = FieldArray[0]; |
2928 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON) | 2916 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON) |
2929 return FALSE; | 2917 return FALSE; |
2930 | 2918 |
2931 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); | 2919 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); |
(...skipping 15 matching lines...) Expand all Loading... |
2947 FX_BOOL Field::buttonGetIcon(IJS_Context* cc, | 2935 FX_BOOL Field::buttonGetIcon(IJS_Context* cc, |
2948 const std::vector<CJS_Value>& params, | 2936 const std::vector<CJS_Value>& params, |
2949 CJS_Value& vRet, | 2937 CJS_Value& vRet, |
2950 CFX_WideString& sError) { | 2938 CFX_WideString& sError) { |
2951 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 2939 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
2952 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 2940 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
2953 | 2941 |
2954 int nface = 0; | 2942 int nface = 0; |
2955 int iSize = params.size(); | 2943 int iSize = params.size(); |
2956 if (iSize >= 1) | 2944 if (iSize >= 1) |
2957 nface = params[0].ToInt(pRuntime->GetIsolate()); | 2945 nface = params[0].ToInt(pRuntime); |
2958 | 2946 |
2959 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); | 2947 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
2960 if (FieldArray.empty()) | 2948 if (FieldArray.empty()) |
2961 return FALSE; | 2949 return FALSE; |
2962 | 2950 |
2963 CPDF_FormField* pFormField = FieldArray[0]; | 2951 CPDF_FormField* pFormField = FieldArray[0]; |
2964 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON) | 2952 if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON) |
2965 return FALSE; | 2953 return FALSE; |
2966 | 2954 |
2967 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); | 2955 CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); |
2968 if (!pFormControl) | 2956 if (!pFormControl) |
2969 return FALSE; | 2957 return FALSE; |
2970 | 2958 |
2971 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj( | 2959 v8::Local<v8::Object> pObj = |
2972 pRuntime->GetIsolate(), pRuntime, CJS_Icon::g_nObjDefnID); | 2960 pRuntime->NewFxDynamicObj(CJS_Icon::g_nObjDefnID); |
2973 ASSERT(pObj.IsEmpty() == FALSE); | 2961 ASSERT(pObj.IsEmpty() == FALSE); |
2974 | 2962 |
2975 CJS_Icon* pJS_Icon = (CJS_Icon*)FXJS_GetPrivate(pRuntime->GetIsolate(), pObj); | 2963 CJS_Icon* pJS_Icon = static_cast<CJS_Icon*>(pRuntime->GetObjectPrivate(pObj)); |
2976 Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject(); | 2964 Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject(); |
2977 | 2965 |
2978 CPDF_Stream* pIconStream = nullptr; | 2966 CPDF_Stream* pIconStream = nullptr; |
2979 if (nface == 0) | 2967 if (nface == 0) |
2980 pIconStream = pFormControl->GetNormalIcon(); | 2968 pIconStream = pFormControl->GetNormalIcon(); |
2981 else if (nface == 1) | 2969 else if (nface == 1) |
2982 pIconStream = pFormControl->GetDownIcon(); | 2970 pIconStream = pFormControl->GetDownIcon(); |
2983 else if (nface == 2) | 2971 else if (nface == 2) |
2984 pIconStream = pFormControl->GetRolloverIcon(); | 2972 pIconStream = pFormControl->GetRolloverIcon(); |
2985 else | 2973 else |
(...skipping 30 matching lines...) Expand all Loading... |
3016 CJS_Value& vRet, | 3004 CJS_Value& vRet, |
3017 CFX_WideString& sError) { | 3005 CFX_WideString& sError) { |
3018 int iSize = params.size(); | 3006 int iSize = params.size(); |
3019 if (iSize < 1) | 3007 if (iSize < 1) |
3020 return FALSE; | 3008 return FALSE; |
3021 | 3009 |
3022 if (!m_bCanSet) | 3010 if (!m_bCanSet) |
3023 return FALSE; | 3011 return FALSE; |
3024 | 3012 |
3025 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 3013 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
3026 int nWidget = params[0].ToInt(pRuntime->GetIsolate()); | 3014 int nWidget = params[0].ToInt(pRuntime); |
3027 | 3015 |
3028 bool bCheckit = true; | 3016 bool bCheckit = true; |
3029 if (iSize >= 2) | 3017 if (iSize >= 2) |
3030 bCheckit = params[1].ToBool(pRuntime->GetIsolate()); | 3018 bCheckit = params[1].ToBool(pRuntime); |
3031 | 3019 |
3032 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); | 3020 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
3033 if (FieldArray.empty()) | 3021 if (FieldArray.empty()) |
3034 return FALSE; | 3022 return FALSE; |
3035 | 3023 |
3036 CPDF_FormField* pFormField = FieldArray[0]; | 3024 CPDF_FormField* pFormField = FieldArray[0]; |
3037 if (pFormField->GetFieldType() != FIELDTYPE_CHECKBOX && | 3025 if (pFormField->GetFieldType() != FIELDTYPE_CHECKBOX && |
3038 pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON) | 3026 pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON) |
3039 return FALSE; | 3027 return FALSE; |
3040 if (nWidget < 0 || nWidget >= pFormField->CountControls()) | 3028 if (nWidget < 0 || nWidget >= pFormField->CountControls()) |
(...skipping 21 matching lines...) Expand all Loading... |
3062 CJS_Value& vRet, | 3050 CJS_Value& vRet, |
3063 CFX_WideString& sError) { | 3051 CFX_WideString& sError) { |
3064 if (!m_bCanSet) | 3052 if (!m_bCanSet) |
3065 return FALSE; | 3053 return FALSE; |
3066 | 3054 |
3067 int iSize = params.size(); | 3055 int iSize = params.size(); |
3068 if (iSize < 1) | 3056 if (iSize < 1) |
3069 return FALSE; | 3057 return FALSE; |
3070 | 3058 |
3071 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 3059 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
3072 int nWidget = params[0].ToInt(pRuntime->GetIsolate()); | 3060 int nWidget = params[0].ToInt(pRuntime); |
3073 | 3061 |
3074 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); | 3062 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
3075 if (FieldArray.empty()) | 3063 if (FieldArray.empty()) |
3076 return FALSE; | 3064 return FALSE; |
3077 | 3065 |
3078 CPDF_FormField* pFormField = FieldArray[0]; | 3066 CPDF_FormField* pFormField = FieldArray[0]; |
3079 if (nWidget < 0 || nWidget >= pFormField->CountControls()) | 3067 if (nWidget < 0 || nWidget >= pFormField->CountControls()) |
3080 return FALSE; | 3068 return FALSE; |
3081 | 3069 |
3082 vRet = CJS_Value(pRuntime, | 3070 vRet = CJS_Value(pRuntime, |
(...skipping 28 matching lines...) Expand all Loading... |
3111 swSort.begin(), swSort.end(), | 3099 swSort.begin(), swSort.end(), |
3112 [](const std::unique_ptr<CFX_WideString>& p1, | 3100 [](const std::unique_ptr<CFX_WideString>& p1, |
3113 const std::unique_ptr<CFX_WideString>& p2) { return *p1 < *p2; }); | 3101 const std::unique_ptr<CFX_WideString>& p2) { return *p1 < *p2; }); |
3114 | 3102 |
3115 CJS_Context* pContext = (CJS_Context*)cc; | 3103 CJS_Context* pContext = (CJS_Context*)cc; |
3116 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 3104 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
3117 CJS_Array FormFieldArray; | 3105 CJS_Array FormFieldArray; |
3118 | 3106 |
3119 int j = 0; | 3107 int j = 0; |
3120 for (const auto& pStr : swSort) { | 3108 for (const auto& pStr : swSort) { |
3121 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj( | 3109 v8::Local<v8::Object> pObj = |
3122 pRuntime->GetIsolate(), pRuntime, CJS_Field::g_nObjDefnID); | 3110 pRuntime->NewFxDynamicObj(CJS_Field::g_nObjDefnID); |
3123 ASSERT(!pObj.IsEmpty()); | 3111 ASSERT(!pObj.IsEmpty()); |
3124 | 3112 |
3125 CJS_Field* pJSField = | 3113 CJS_Field* pJSField = |
3126 static_cast<CJS_Field*>(FXJS_GetPrivate(pRuntime->GetIsolate(), pObj)); | 3114 static_cast<CJS_Field*>(pRuntime->GetObjectPrivate(pObj)); |
3127 Field* pField = static_cast<Field*>(pJSField->GetEmbedObject()); | 3115 Field* pField = static_cast<Field*>(pJSField->GetEmbedObject()); |
3128 pField->AttachField(m_pJSDoc, *pStr); | 3116 pField->AttachField(m_pJSDoc, *pStr); |
3129 FormFieldArray.SetElement(pRuntime->GetIsolate(), j++, | 3117 FormFieldArray.SetElement(pRuntime, j++, CJS_Value(pRuntime, pJSField)); |
3130 CJS_Value(pRuntime, pJSField)); | |
3131 } | 3118 } |
3132 | 3119 |
3133 vRet = CJS_Value(pRuntime, FormFieldArray); | 3120 vRet = CJS_Value(pRuntime, FormFieldArray); |
3134 return TRUE; | 3121 return TRUE; |
3135 } | 3122 } |
3136 | 3123 |
3137 FX_BOOL Field::getItemAt(IJS_Context* cc, | 3124 FX_BOOL Field::getItemAt(IJS_Context* cc, |
3138 const std::vector<CJS_Value>& params, | 3125 const std::vector<CJS_Value>& params, |
3139 CJS_Value& vRet, | 3126 CJS_Value& vRet, |
3140 CFX_WideString& sError) { | 3127 CFX_WideString& sError) { |
3141 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 3128 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
3142 | 3129 |
3143 int iSize = params.size(); | 3130 int iSize = params.size(); |
3144 int nIdx = -1; | 3131 int nIdx = -1; |
3145 if (iSize >= 1) | 3132 if (iSize >= 1) |
3146 nIdx = params[0].ToInt(pRuntime->GetIsolate()); | 3133 nIdx = params[0].ToInt(pRuntime); |
3147 | 3134 |
3148 FX_BOOL bExport = TRUE; | 3135 FX_BOOL bExport = TRUE; |
3149 if (iSize >= 2) | 3136 if (iSize >= 2) |
3150 bExport = params[1].ToBool(pRuntime->GetIsolate()); | 3137 bExport = params[1].ToBool(pRuntime); |
3151 | 3138 |
3152 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); | 3139 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
3153 if (FieldArray.empty()) | 3140 if (FieldArray.empty()) |
3154 return FALSE; | 3141 return FALSE; |
3155 | 3142 |
3156 CPDF_FormField* pFormField = FieldArray[0]; | 3143 CPDF_FormField* pFormField = FieldArray[0]; |
3157 if ((pFormField->GetFieldType() == FIELDTYPE_LISTBOX) || | 3144 if ((pFormField->GetFieldType() == FIELDTYPE_LISTBOX) || |
3158 (pFormField->GetFieldType() == FIELDTYPE_COMBOBOX)) { | 3145 (pFormField->GetFieldType() == FIELDTYPE_COMBOBOX)) { |
3159 if (nIdx == -1 || nIdx > pFormField->CountOptions()) | 3146 if (nIdx == -1 || nIdx > pFormField->CountOptions()) |
3160 nIdx = pFormField->CountOptions() - 1; | 3147 nIdx = pFormField->CountOptions() - 1; |
(...skipping 28 matching lines...) Expand all Loading... |
3189 } | 3176 } |
3190 | 3177 |
3191 FX_BOOL Field::isBoxChecked(IJS_Context* cc, | 3178 FX_BOOL Field::isBoxChecked(IJS_Context* cc, |
3192 const std::vector<CJS_Value>& params, | 3179 const std::vector<CJS_Value>& params, |
3193 CJS_Value& vRet, | 3180 CJS_Value& vRet, |
3194 CFX_WideString& sError) { | 3181 CFX_WideString& sError) { |
3195 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 3182 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
3196 | 3183 |
3197 int nIndex = -1; | 3184 int nIndex = -1; |
3198 if (params.size() >= 1) | 3185 if (params.size() >= 1) |
3199 nIndex = params[0].ToInt(pRuntime->GetIsolate()); | 3186 nIndex = params[0].ToInt(pRuntime); |
3200 | 3187 |
3201 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); | 3188 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
3202 if (FieldArray.empty()) | 3189 if (FieldArray.empty()) |
3203 return FALSE; | 3190 return FALSE; |
3204 | 3191 |
3205 CPDF_FormField* pFormField = FieldArray[0]; | 3192 CPDF_FormField* pFormField = FieldArray[0]; |
3206 if (nIndex < 0 || nIndex >= pFormField->CountControls()) { | 3193 if (nIndex < 0 || nIndex >= pFormField->CountControls()) { |
3207 return FALSE; | 3194 return FALSE; |
3208 } | 3195 } |
3209 | 3196 |
3210 vRet = CJS_Value(pRuntime, | 3197 vRet = CJS_Value(pRuntime, |
3211 ((pFormField->GetFieldType() == FIELDTYPE_CHECKBOX || | 3198 ((pFormField->GetFieldType() == FIELDTYPE_CHECKBOX || |
3212 pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON) && | 3199 pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON) && |
3213 pFormField->GetControl(nIndex)->IsChecked() != 0)); | 3200 pFormField->GetControl(nIndex)->IsChecked() != 0)); |
3214 return TRUE; | 3201 return TRUE; |
3215 } | 3202 } |
3216 | 3203 |
3217 FX_BOOL Field::isDefaultChecked(IJS_Context* cc, | 3204 FX_BOOL Field::isDefaultChecked(IJS_Context* cc, |
3218 const std::vector<CJS_Value>& params, | 3205 const std::vector<CJS_Value>& params, |
3219 CJS_Value& vRet, | 3206 CJS_Value& vRet, |
3220 CFX_WideString& sError) { | 3207 CFX_WideString& sError) { |
3221 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 3208 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
3222 | 3209 |
3223 int nIndex = -1; | 3210 int nIndex = -1; |
3224 if (params.size() >= 1) | 3211 if (params.size() >= 1) |
3225 nIndex = params[0].ToInt(pRuntime->GetIsolate()); | 3212 nIndex = params[0].ToInt(pRuntime); |
3226 | 3213 |
3227 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); | 3214 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
3228 if (FieldArray.empty()) | 3215 if (FieldArray.empty()) |
3229 return FALSE; | 3216 return FALSE; |
3230 | 3217 |
3231 CPDF_FormField* pFormField = FieldArray[0]; | 3218 CPDF_FormField* pFormField = FieldArray[0]; |
3232 if (nIndex < 0 || nIndex >= pFormField->CountControls()) | 3219 if (nIndex < 0 || nIndex >= pFormField->CountControls()) |
3233 return FALSE; | 3220 return FALSE; |
3234 | 3221 |
3235 vRet = CJS_Value(pRuntime, | 3222 vRet = CJS_Value(pRuntime, |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3553 } | 3540 } |
3554 } | 3541 } |
3555 | 3542 |
3556 void Field::AddField(CPDFSDK_Document* pDocument, | 3543 void Field::AddField(CPDFSDK_Document* pDocument, |
3557 int nPageIndex, | 3544 int nPageIndex, |
3558 int nFieldType, | 3545 int nFieldType, |
3559 const CFX_WideString& sName, | 3546 const CFX_WideString& sName, |
3560 const CFX_FloatRect& rcCoords) { | 3547 const CFX_FloatRect& rcCoords) { |
3561 // Not supported. | 3548 // Not supported. |
3562 } | 3549 } |
OLD | NEW |