| 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 <algorithm> |
| 10 #include <memory> |
| 11 #include <vector> |
| 12 |
| 9 #include "Document.h" | 13 #include "Document.h" |
| 10 #include "Icon.h" | 14 #include "Icon.h" |
| 11 #include "JS_Context.h" | 15 #include "JS_Context.h" |
| 12 #include "JS_Define.h" | 16 #include "JS_Define.h" |
| 13 #include "JS_EventHandler.h" | 17 #include "JS_EventHandler.h" |
| 14 #include "JS_Object.h" | 18 #include "JS_Object.h" |
| 15 #include "JS_Runtime.h" | 19 #include "JS_Runtime.h" |
| 16 #include "JS_Value.h" | 20 #include "JS_Value.h" |
| 17 #include "PublicMethods.h" | 21 #include "PublicMethods.h" |
| 18 #include "color.h" | 22 #include "color.h" |
| (...skipping 3057 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3076 return TRUE; | 3080 return TRUE; |
| 3077 } | 3081 } |
| 3078 | 3082 |
| 3079 FX_BOOL Field::deleteItemAt(IJS_Context* cc, | 3083 FX_BOOL Field::deleteItemAt(IJS_Context* cc, |
| 3080 const std::vector<CJS_Value>& params, | 3084 const std::vector<CJS_Value>& params, |
| 3081 CJS_Value& vRet, | 3085 CJS_Value& vRet, |
| 3082 CFX_WideString& sError) { | 3086 CFX_WideString& sError) { |
| 3083 return TRUE; | 3087 return TRUE; |
| 3084 } | 3088 } |
| 3085 | 3089 |
| 3086 int JS_COMPARESTRING(CFX_WideString* ps1, CFX_WideString* ps2) { | |
| 3087 return ps1->Compare(*ps2); | |
| 3088 } | |
| 3089 | |
| 3090 FX_BOOL Field::getArray(IJS_Context* cc, | 3090 FX_BOOL Field::getArray(IJS_Context* cc, |
| 3091 const std::vector<CJS_Value>& params, | 3091 const std::vector<CJS_Value>& params, |
| 3092 CJS_Value& vRet, | 3092 CJS_Value& vRet, |
| 3093 CFX_WideString& sError) { | 3093 CFX_WideString& sError) { |
| 3094 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); | 3094 std::vector<CPDF_FormField*> FieldArray = GetFormFields(m_FieldName); |
| 3095 if (FieldArray.empty()) | 3095 if (FieldArray.empty()) |
| 3096 return FALSE; | 3096 return FALSE; |
| 3097 | 3097 |
| 3098 CGW_ArrayTemplate<CFX_WideString*> swSort; | 3098 std::vector<std::unique_ptr<CFX_WideString>> swSort; |
| 3099 for (CPDF_FormField* pFormField : FieldArray) { |
| 3100 swSort.push_back(std::unique_ptr<CFX_WideString>( |
| 3101 new CFX_WideString(pFormField->GetFullName()))); |
| 3102 } |
| 3099 | 3103 |
| 3100 for (CPDF_FormField* pFormField : FieldArray) | 3104 std::sort( |
| 3101 swSort.Add(new CFX_WideString(pFormField->GetFullName())); | 3105 swSort.begin(), swSort.end(), |
| 3102 swSort.Sort(JS_COMPARESTRING); | 3106 [](const std::unique_ptr<CFX_WideString>& p1, |
| 3107 const std::unique_ptr<CFX_WideString>& p2) { return *p1 < *p2; }); |
| 3103 | 3108 |
| 3104 CJS_Context* pContext = (CJS_Context*)cc; | 3109 CJS_Context* pContext = (CJS_Context*)cc; |
| 3105 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 3110 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
| 3106 ASSERT(pRuntime); | 3111 CJS_Array FormFieldArray(pRuntime); |
| 3107 | 3112 |
| 3108 CJS_Array FormFieldArray(pRuntime); | 3113 int j = 0; |
| 3109 for (int j = 0, jsz = swSort.GetSize(); j < jsz; j++) { | 3114 for (const auto& pStr : swSort) { |
| 3110 std::unique_ptr<CFX_WideString> pStr(swSort.GetAt(j)); | |
| 3111 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj( | 3115 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj( |
| 3112 pRuntime->GetIsolate(), pRuntime, CJS_Field::g_nObjDefnID); | 3116 pRuntime->GetIsolate(), pRuntime, CJS_Field::g_nObjDefnID); |
| 3113 ASSERT(!pObj.IsEmpty()); | 3117 ASSERT(!pObj.IsEmpty()); |
| 3114 | 3118 |
| 3115 CJS_Field* pJSField = | 3119 CJS_Field* pJSField = |
| 3116 (CJS_Field*)FXJS_GetPrivate(pRuntime->GetIsolate(), pObj); | 3120 static_cast<CJS_Field*>(FXJS_GetPrivate(pRuntime->GetIsolate(), pObj)); |
| 3117 Field* pField = (Field*)pJSField->GetEmbedObject(); | 3121 Field* pField = static_cast<Field*>(pJSField->GetEmbedObject()); |
| 3118 pField->AttachField(m_pJSDoc, *pStr); | 3122 pField->AttachField(m_pJSDoc, *pStr); |
| 3119 | 3123 |
| 3120 CJS_Value FormFieldValue(pRuntime); | 3124 CJS_Value FormFieldValue(pRuntime); |
| 3121 FormFieldValue = pJSField; | 3125 FormFieldValue = pJSField; |
| 3122 FormFieldArray.SetElement(j, FormFieldValue); | 3126 FormFieldArray.SetElement(j++, FormFieldValue); |
| 3123 } | 3127 } |
| 3124 | 3128 |
| 3125 vRet = FormFieldArray; | 3129 vRet = FormFieldArray; |
| 3126 swSort.RemoveAll(); | |
| 3127 return TRUE; | 3130 return TRUE; |
| 3128 } | 3131 } |
| 3129 | 3132 |
| 3130 FX_BOOL Field::getItemAt(IJS_Context* cc, | 3133 FX_BOOL Field::getItemAt(IJS_Context* cc, |
| 3131 const std::vector<CJS_Value>& params, | 3134 const std::vector<CJS_Value>& params, |
| 3132 CJS_Value& vRet, | 3135 CJS_Value& vRet, |
| 3133 CFX_WideString& sError) { | 3136 CFX_WideString& sError) { |
| 3134 int iSize = params.size(); | 3137 int iSize = params.size(); |
| 3135 | 3138 |
| 3136 int nIdx = -1; | 3139 int nIdx = -1; |
| (...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3586 } | 3589 } |
| 3587 } | 3590 } |
| 3588 | 3591 |
| 3589 void Field::AddField(CPDFSDK_Document* pDocument, | 3592 void Field::AddField(CPDFSDK_Document* pDocument, |
| 3590 int nPageIndex, | 3593 int nPageIndex, |
| 3591 int nFieldType, | 3594 int nFieldType, |
| 3592 const CFX_WideString& sName, | 3595 const CFX_WideString& sName, |
| 3593 const CPDF_Rect& rcCoords) { | 3596 const CPDF_Rect& rcCoords) { |
| 3594 // Not supported. | 3597 // Not supported. |
| 3595 } | 3598 } |
| OLD | NEW |