| 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/PublicMethods.h" | 7 #include "fpdfsdk/javascript/PublicMethods.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 if (FXSYS_wcsicmp(sFuction, L"MAX") == 0) { | 156 if (FXSYS_wcsicmp(sFuction, L"MAX") == 0) { |
| 157 return std::max(dValue1, dValue2); | 157 return std::max(dValue1, dValue2); |
| 158 } | 158 } |
| 159 return dValue1; | 159 return dValue1; |
| 160 } | 160 } |
| 161 | 161 |
| 162 CJS_Array CJS_PublicMethods::AF_MakeArrayFromList(CJS_Runtime* pRuntime, | 162 CJS_Array CJS_PublicMethods::AF_MakeArrayFromList(CJS_Runtime* pRuntime, |
| 163 CJS_Value val) { | 163 CJS_Value val) { |
| 164 CJS_Array StrArray; | 164 CJS_Array StrArray; |
| 165 if (val.IsArrayObject()) { | 165 if (val.IsArrayObject()) { |
| 166 val.ConvertToArray(pRuntime->GetIsolate(), StrArray); | 166 val.ConvertToArray(pRuntime, StrArray); |
| 167 return StrArray; | 167 return StrArray; |
| 168 } | 168 } |
| 169 CFX_WideString wsStr = val.ToCFXWideString(pRuntime->GetIsolate()); | 169 CFX_WideString wsStr = val.ToCFXWideString(pRuntime); |
| 170 CFX_ByteString t = CFX_ByteString::FromUnicode(wsStr); | 170 CFX_ByteString t = CFX_ByteString::FromUnicode(wsStr); |
| 171 const char* p = t.c_str(); | 171 const char* p = t.c_str(); |
| 172 | 172 |
| 173 int ch = ','; | 173 int ch = ','; |
| 174 int nIndex = 0; | 174 int nIndex = 0; |
| 175 | 175 |
| 176 while (*p) { | 176 while (*p) { |
| 177 const char* pTemp = strchr(p, ch); | 177 const char* pTemp = strchr(p, ch); |
| 178 if (!pTemp) { | 178 if (!pTemp) { |
| 179 StrArray.SetElement( | 179 StrArray.SetElement( |
| 180 pRuntime->GetIsolate(), nIndex, | 180 pRuntime, nIndex, |
| 181 CJS_Value(pRuntime, StrTrim(CFX_ByteString(p)).c_str())); | 181 CJS_Value(pRuntime, StrTrim(CFX_ByteString(p)).c_str())); |
| 182 break; | 182 break; |
| 183 } | 183 } |
| 184 | 184 |
| 185 char* pSub = new char[pTemp - p + 1]; | 185 char* pSub = new char[pTemp - p + 1]; |
| 186 strncpy(pSub, p, pTemp - p); | 186 strncpy(pSub, p, pTemp - p); |
| 187 *(pSub + (pTemp - p)) = '\0'; | 187 *(pSub + (pTemp - p)) = '\0'; |
| 188 | 188 |
| 189 StrArray.SetElement( | 189 StrArray.SetElement( |
| 190 pRuntime->GetIsolate(), nIndex, | 190 pRuntime, nIndex, |
| 191 CJS_Value(pRuntime, StrTrim(CFX_ByteString(pSub)).c_str())); | 191 CJS_Value(pRuntime, StrTrim(CFX_ByteString(pSub)).c_str())); |
| 192 delete[] pSub; | 192 delete[] pSub; |
| 193 | 193 |
| 194 nIndex++; | 194 nIndex++; |
| 195 p = ++pTemp; | 195 p = ++pTemp; |
| 196 } | 196 } |
| 197 return StrArray; | 197 return StrArray; |
| 198 } | 198 } |
| 199 | 199 |
| 200 int CJS_PublicMethods::ParseStringInteger(const CFX_WideString& str, | 200 int CJS_PublicMethods::ParseStringInteger(const CFX_WideString& str, |
| (...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 736 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 736 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 737 CJS_EventHandler* pEvent = pContext->GetEventHandler(); | 737 CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
| 738 if (!pEvent->m_pValue) | 738 if (!pEvent->m_pValue) |
| 739 return FALSE; | 739 return FALSE; |
| 740 | 740 |
| 741 CFX_WideString& Value = pEvent->Value(); | 741 CFX_WideString& Value = pEvent->Value(); |
| 742 CFX_ByteString strValue = StrTrim(CFX_ByteString::FromUnicode(Value)); | 742 CFX_ByteString strValue = StrTrim(CFX_ByteString::FromUnicode(Value)); |
| 743 if (strValue.IsEmpty()) | 743 if (strValue.IsEmpty()) |
| 744 return TRUE; | 744 return TRUE; |
| 745 | 745 |
| 746 int iDec = params[0].ToInt(pRuntime->GetIsolate()); | 746 int iDec = params[0].ToInt(pRuntime); |
| 747 int iSepStyle = params[1].ToInt(pRuntime->GetIsolate()); | 747 int iSepStyle = params[1].ToInt(pRuntime); |
| 748 int iNegStyle = params[2].ToInt(pRuntime->GetIsolate()); | 748 int iNegStyle = params[2].ToInt(pRuntime); |
| 749 // params[3] is iCurrStyle, it's not used. | 749 // params[3] is iCurrStyle, it's not used. |
| 750 CFX_WideString wstrCurrency = | 750 CFX_WideString wstrCurrency = params[4].ToCFXWideString(pRuntime); |
| 751 params[4].ToCFXWideString(pRuntime->GetIsolate()); | 751 FX_BOOL bCurrencyPrepend = params[5].ToBool(pRuntime); |
| 752 FX_BOOL bCurrencyPrepend = params[5].ToBool(pRuntime->GetIsolate()); | |
| 753 | 752 |
| 754 if (iDec < 0) | 753 if (iDec < 0) |
| 755 iDec = -iDec; | 754 iDec = -iDec; |
| 756 | 755 |
| 757 if (iSepStyle < 0 || iSepStyle > 3) | 756 if (iSepStyle < 0 || iSepStyle > 3) |
| 758 iSepStyle = 0; | 757 iSepStyle = 0; |
| 759 | 758 |
| 760 if (iNegStyle < 0 || iNegStyle > 3) | 759 if (iNegStyle < 0 || iNegStyle > 3) |
| 761 iNegStyle = 0; | 760 iNegStyle = 0; |
| 762 | 761 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 832 if (iNegStyle == 0) { | 831 if (iNegStyle == 0) { |
| 833 Value = L"-" + Value; | 832 Value = L"-" + Value; |
| 834 } else if (iNegStyle == 2 || iNegStyle == 3) { | 833 } else if (iNegStyle == 2 || iNegStyle == 3) { |
| 835 Value = L"(" + Value + L")"; | 834 Value = L"(" + Value + L")"; |
| 836 } | 835 } |
| 837 if (iNegStyle == 1 || iNegStyle == 3) { | 836 if (iNegStyle == 1 || iNegStyle == 3) { |
| 838 if (Field* fTarget = pEvent->Target_Field()) { | 837 if (Field* fTarget = pEvent->Target_Field()) { |
| 839 CJS_Array arColor; | 838 CJS_Array arColor; |
| 840 CJS_Value vColElm(pRuntime); | 839 CJS_Value vColElm(pRuntime); |
| 841 vColElm = CJS_Value(pRuntime, L"RGB"); | 840 vColElm = CJS_Value(pRuntime, L"RGB"); |
| 842 arColor.SetElement(pRuntime->GetIsolate(), 0, vColElm); | 841 arColor.SetElement(pRuntime, 0, vColElm); |
| 843 vColElm = CJS_Value(pRuntime, 1); | 842 vColElm = CJS_Value(pRuntime, 1); |
| 844 arColor.SetElement(pRuntime->GetIsolate(), 1, vColElm); | 843 arColor.SetElement(pRuntime, 1, vColElm); |
| 845 vColElm = CJS_Value(pRuntime, 0); | 844 vColElm = CJS_Value(pRuntime, 0); |
| 846 arColor.SetElement(pRuntime->GetIsolate(), 2, vColElm); | 845 arColor.SetElement(pRuntime, 2, vColElm); |
| 847 arColor.SetElement(pRuntime->GetIsolate(), 3, vColElm); | 846 arColor.SetElement(pRuntime, 3, vColElm); |
| 848 | 847 |
| 849 CJS_PropValue vProp(pRuntime); | 848 CJS_PropValue vProp(pRuntime); |
| 850 vProp.StartGetting(); | 849 vProp.StartGetting(); |
| 851 vProp << arColor; | 850 vProp << arColor; |
| 852 vProp.StartSetting(); | 851 vProp.StartSetting(); |
| 853 fTarget->textColor(cc, vProp, sError); // red | 852 fTarget->textColor(cc, vProp, sError); // red |
| 854 } | 853 } |
| 855 } | 854 } |
| 856 } else { | 855 } else { |
| 857 if (iNegStyle == 1 || iNegStyle == 3) { | 856 if (iNegStyle == 1 || iNegStyle == 3) { |
| 858 if (Field* fTarget = pEvent->Target_Field()) { | 857 if (Field* fTarget = pEvent->Target_Field()) { |
| 859 CJS_Array arColor; | 858 CJS_Array arColor; |
| 860 CJS_Value vColElm(pRuntime); | 859 CJS_Value vColElm(pRuntime); |
| 861 vColElm = CJS_Value(pRuntime, L"RGB"); | 860 vColElm = CJS_Value(pRuntime, L"RGB"); |
| 862 arColor.SetElement(pRuntime->GetIsolate(), 0, vColElm); | 861 arColor.SetElement(pRuntime, 0, vColElm); |
| 863 vColElm = CJS_Value(pRuntime, 0); | 862 vColElm = CJS_Value(pRuntime, 0); |
| 864 arColor.SetElement(pRuntime->GetIsolate(), 1, vColElm); | 863 arColor.SetElement(pRuntime, 1, vColElm); |
| 865 arColor.SetElement(pRuntime->GetIsolate(), 2, vColElm); | 864 arColor.SetElement(pRuntime, 2, vColElm); |
| 866 arColor.SetElement(pRuntime->GetIsolate(), 3, vColElm); | 865 arColor.SetElement(pRuntime, 3, vColElm); |
| 867 | 866 |
| 868 CJS_PropValue vProp(pRuntime); | 867 CJS_PropValue vProp(pRuntime); |
| 869 vProp.StartGetting(); | 868 vProp.StartGetting(); |
| 870 fTarget->textColor(cc, vProp, sError); | 869 fTarget->textColor(cc, vProp, sError); |
| 871 | 870 |
| 872 CJS_Array aProp; | 871 CJS_Array aProp; |
| 873 vProp.GetJSValue()->ConvertToArray(pRuntime->GetIsolate(), aProp); | 872 vProp.GetJSValue()->ConvertToArray(pRuntime, aProp); |
| 874 | 873 |
| 875 CPWL_Color crProp; | 874 CPWL_Color crProp; |
| 876 CPWL_Color crColor; | 875 CPWL_Color crColor; |
| 877 color::ConvertArrayToPWLColor(pRuntime, aProp, &crProp); | 876 color::ConvertArrayToPWLColor(pRuntime, aProp, &crProp); |
| 878 color::ConvertArrayToPWLColor(pRuntime, arColor, &crColor); | 877 color::ConvertArrayToPWLColor(pRuntime, arColor, &crColor); |
| 879 | 878 |
| 880 if (crColor != crProp) { | 879 if (crColor != crProp) { |
| 881 CJS_PropValue vProp2(pRuntime); | 880 CJS_PropValue vProp2(pRuntime); |
| 882 vProp2.StartGetting(); | 881 vProp2.StartGetting(); |
| 883 vProp2 << arColor; | 882 vProp2 << arColor; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 935 if (bHasSign) { | 934 if (bHasSign) { |
| 936 // can't insert "change" in front to sign postion. | 935 // can't insert "change" in front to sign postion. |
| 937 if (pEvent->SelStart() == 0) { | 936 if (pEvent->SelStart() == 0) { |
| 938 FX_BOOL& bRc = pEvent->Rc(); | 937 FX_BOOL& bRc = pEvent->Rc(); |
| 939 bRc = FALSE; | 938 bRc = FALSE; |
| 940 return TRUE; | 939 return TRUE; |
| 941 } | 940 } |
| 942 } | 941 } |
| 943 | 942 |
| 944 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 943 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 945 int iSepStyle = params[1].ToInt(pRuntime->GetIsolate()); | 944 int iSepStyle = params[1].ToInt(pRuntime); |
| 946 if (iSepStyle < 0 || iSepStyle > 3) | 945 if (iSepStyle < 0 || iSepStyle > 3) |
| 947 iSepStyle = 0; | 946 iSepStyle = 0; |
| 948 const FX_WCHAR cSep = iSepStyle < 2 ? L'.' : L','; | 947 const FX_WCHAR cSep = iSepStyle < 2 ? L'.' : L','; |
| 949 | 948 |
| 950 bool bHasSep = wstrValue.Find(cSep) != -1; | 949 bool bHasSep = wstrValue.Find(cSep) != -1; |
| 951 for (FX_STRSIZE i = 0; i < wstrChange.GetLength(); ++i) { | 950 for (FX_STRSIZE i = 0; i < wstrChange.GetLength(); ++i) { |
| 952 if (wstrChange[i] == cSep) { | 951 if (wstrChange[i] == cSep) { |
| 953 if (bHasSep) { | 952 if (bHasSep) { |
| 954 FX_BOOL& bRc = pEvent->Rc(); | 953 FX_BOOL& bRc = pEvent->Rc(); |
| 955 bRc = FALSE; | 954 bRc = FALSE; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1010 return FALSE; | 1009 return FALSE; |
| 1011 } | 1010 } |
| 1012 if (!pEvent->m_pValue) | 1011 if (!pEvent->m_pValue) |
| 1013 return FALSE; | 1012 return FALSE; |
| 1014 | 1013 |
| 1015 CFX_WideString& Value = pEvent->Value(); | 1014 CFX_WideString& Value = pEvent->Value(); |
| 1016 CFX_ByteString strValue = StrTrim(CFX_ByteString::FromUnicode(Value)); | 1015 CFX_ByteString strValue = StrTrim(CFX_ByteString::FromUnicode(Value)); |
| 1017 if (strValue.IsEmpty()) | 1016 if (strValue.IsEmpty()) |
| 1018 return TRUE; | 1017 return TRUE; |
| 1019 | 1018 |
| 1020 int iDec = params[0].ToInt(pRuntime->GetIsolate()); | 1019 int iDec = params[0].ToInt(pRuntime); |
| 1021 if (iDec < 0) | 1020 if (iDec < 0) |
| 1022 iDec = -iDec; | 1021 iDec = -iDec; |
| 1023 | 1022 |
| 1024 int iSepStyle = params[1].ToInt(pRuntime->GetIsolate()); | 1023 int iSepStyle = params[1].ToInt(pRuntime); |
| 1025 if (iSepStyle < 0 || iSepStyle > 3) | 1024 if (iSepStyle < 0 || iSepStyle > 3) |
| 1026 iSepStyle = 0; | 1025 iSepStyle = 0; |
| 1027 | 1026 |
| 1028 // for processing decimal places | 1027 // for processing decimal places |
| 1029 double dValue = atof(strValue.c_str()); | 1028 double dValue = atof(strValue.c_str()); |
| 1030 dValue *= 100; | 1029 dValue *= 100; |
| 1031 if (iDec > 0) | 1030 if (iDec > 0) |
| 1032 dValue += DOUBLE_CORRECT; | 1031 dValue += DOUBLE_CORRECT; |
| 1033 | 1032 |
| 1034 int iDec2; | 1033 int iDec2; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1110 return FALSE; | 1109 return FALSE; |
| 1111 } | 1110 } |
| 1112 if (!pEvent->m_pValue) | 1111 if (!pEvent->m_pValue) |
| 1113 return FALSE; | 1112 return FALSE; |
| 1114 | 1113 |
| 1115 CFX_WideString& val = pEvent->Value(); | 1114 CFX_WideString& val = pEvent->Value(); |
| 1116 CFX_WideString strValue = val; | 1115 CFX_WideString strValue = val; |
| 1117 if (strValue.IsEmpty()) | 1116 if (strValue.IsEmpty()) |
| 1118 return TRUE; | 1117 return TRUE; |
| 1119 | 1118 |
| 1120 CFX_WideString sFormat = params[0].ToCFXWideString(pRuntime->GetIsolate()); | 1119 CFX_WideString sFormat = params[0].ToCFXWideString(pRuntime); |
| 1121 double dDate = 0.0f; | 1120 double dDate = 0.0f; |
| 1122 | 1121 |
| 1123 if (strValue.Find(L"GMT") != -1) { | 1122 if (strValue.Find(L"GMT") != -1) { |
| 1124 // for GMT format time | 1123 // for GMT format time |
| 1125 // such as "Tue Aug 11 14:24:16 GMT+08002009" | 1124 // such as "Tue Aug 11 14:24:16 GMT+08002009" |
| 1126 dDate = MakeInterDate(strValue); | 1125 dDate = MakeInterDate(strValue); |
| 1127 } else { | 1126 } else { |
| 1128 dDate = MakeRegularDate(strValue, sFormat, nullptr); | 1127 dDate = MakeRegularDate(strValue, sFormat, nullptr); |
| 1129 } | 1128 } |
| 1130 | 1129 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1211 return FALSE; | 1210 return FALSE; |
| 1212 } | 1211 } |
| 1213 | 1212 |
| 1214 if (pEvent->WillCommit()) { | 1213 if (pEvent->WillCommit()) { |
| 1215 if (!pEvent->m_pValue) | 1214 if (!pEvent->m_pValue) |
| 1216 return FALSE; | 1215 return FALSE; |
| 1217 CFX_WideString strValue = pEvent->Value(); | 1216 CFX_WideString strValue = pEvent->Value(); |
| 1218 if (strValue.IsEmpty()) | 1217 if (strValue.IsEmpty()) |
| 1219 return TRUE; | 1218 return TRUE; |
| 1220 | 1219 |
| 1221 CFX_WideString sFormat = params[0].ToCFXWideString(pRuntime->GetIsolate()); | 1220 CFX_WideString sFormat = params[0].ToCFXWideString(pRuntime); |
| 1222 bool bWrongFormat = FALSE; | 1221 bool bWrongFormat = FALSE; |
| 1223 double dRet = MakeRegularDate(strValue, sFormat, &bWrongFormat); | 1222 double dRet = MakeRegularDate(strValue, sFormat, &bWrongFormat); |
| 1224 if (bWrongFormat || JS_PortIsNan(dRet)) { | 1223 if (bWrongFormat || JS_PortIsNan(dRet)) { |
| 1225 CFX_WideString swMsg; | 1224 CFX_WideString swMsg; |
| 1226 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE).c_str(), | 1225 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE).c_str(), |
| 1227 sFormat.c_str()); | 1226 sFormat.c_str()); |
| 1228 AlertIfPossible(pContext, swMsg.c_str()); | 1227 AlertIfPossible(pContext, swMsg.c_str()); |
| 1229 pEvent->Rc() = FALSE; | 1228 pEvent->Rc() = FALSE; |
| 1230 return TRUE; | 1229 return TRUE; |
| 1231 } | 1230 } |
| 1232 } | 1231 } |
| 1233 return TRUE; | 1232 return TRUE; |
| 1234 } | 1233 } |
| 1235 | 1234 |
| 1236 FX_BOOL CJS_PublicMethods::AFDate_Format(IJS_Context* cc, | 1235 FX_BOOL CJS_PublicMethods::AFDate_Format(IJS_Context* cc, |
| 1237 const std::vector<CJS_Value>& params, | 1236 const std::vector<CJS_Value>& params, |
| 1238 CJS_Value& vRet, | 1237 CJS_Value& vRet, |
| 1239 CFX_WideString& sError) { | 1238 CFX_WideString& sError) { |
| 1240 CJS_Context* pContext = (CJS_Context*)cc; | 1239 CJS_Context* pContext = (CJS_Context*)cc; |
| 1241 if (params.size() != 1) { | 1240 if (params.size() != 1) { |
| 1242 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1241 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 1243 return FALSE; | 1242 return FALSE; |
| 1244 } | 1243 } |
| 1245 | 1244 |
| 1246 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 1245 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 1247 int iIndex = params[0].ToInt(pRuntime->GetIsolate()); | 1246 int iIndex = params[0].ToInt(pRuntime); |
| 1248 const FX_WCHAR* cFormats[] = {L"m/d", | 1247 const FX_WCHAR* cFormats[] = {L"m/d", |
| 1249 L"m/d/yy", | 1248 L"m/d/yy", |
| 1250 L"mm/dd/yy", | 1249 L"mm/dd/yy", |
| 1251 L"mm/yy", | 1250 L"mm/yy", |
| 1252 L"d-mmm", | 1251 L"d-mmm", |
| 1253 L"d-mmm-yy", | 1252 L"d-mmm-yy", |
| 1254 L"dd-mmm-yy", | 1253 L"dd-mmm-yy", |
| 1255 L"yy-mm-dd", | 1254 L"yy-mm-dd", |
| 1256 L"mmm-yy", | 1255 L"mmm-yy", |
| 1257 L"mmmm-yy", | 1256 L"mmmm-yy", |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1275 const std::vector<CJS_Value>& params, | 1274 const std::vector<CJS_Value>& params, |
| 1276 CJS_Value& vRet, | 1275 CJS_Value& vRet, |
| 1277 CFX_WideString& sError) { | 1276 CFX_WideString& sError) { |
| 1278 CJS_Context* pContext = (CJS_Context*)cc; | 1277 CJS_Context* pContext = (CJS_Context*)cc; |
| 1279 if (params.size() != 1) { | 1278 if (params.size() != 1) { |
| 1280 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1279 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 1281 return FALSE; | 1280 return FALSE; |
| 1282 } | 1281 } |
| 1283 | 1282 |
| 1284 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 1283 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 1285 int iIndex = params[0].ToInt(pRuntime->GetIsolate()); | 1284 int iIndex = params[0].ToInt(pRuntime); |
| 1286 const FX_WCHAR* cFormats[] = {L"m/d", | 1285 const FX_WCHAR* cFormats[] = {L"m/d", |
| 1287 L"m/d/yy", | 1286 L"m/d/yy", |
| 1288 L"mm/dd/yy", | 1287 L"mm/dd/yy", |
| 1289 L"mm/yy", | 1288 L"mm/yy", |
| 1290 L"d-mmm", | 1289 L"d-mmm", |
| 1291 L"d-mmm-yy", | 1290 L"d-mmm-yy", |
| 1292 L"dd-mmm-yy", | 1291 L"dd-mmm-yy", |
| 1293 L"yy-mm-dd", | 1292 L"yy-mm-dd", |
| 1294 L"mmm-yy", | 1293 L"mmm-yy", |
| 1295 L"mmmm-yy", | 1294 L"mmmm-yy", |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1312 const std::vector<CJS_Value>& params, | 1311 const std::vector<CJS_Value>& params, |
| 1313 CJS_Value& vRet, | 1312 CJS_Value& vRet, |
| 1314 CFX_WideString& sError) { | 1313 CFX_WideString& sError) { |
| 1315 CJS_Context* pContext = (CJS_Context*)cc; | 1314 CJS_Context* pContext = (CJS_Context*)cc; |
| 1316 if (params.size() != 1) { | 1315 if (params.size() != 1) { |
| 1317 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1316 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 1318 return FALSE; | 1317 return FALSE; |
| 1319 } | 1318 } |
| 1320 | 1319 |
| 1321 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 1320 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 1322 int iIndex = params[0].ToInt(pRuntime->GetIsolate()); | 1321 int iIndex = params[0].ToInt(pRuntime); |
| 1323 const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss", | 1322 const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss", |
| 1324 L"h:MM:ss tt"}; | 1323 L"h:MM:ss tt"}; |
| 1325 | 1324 |
| 1326 if (iIndex < 0 || (static_cast<size_t>(iIndex) >= FX_ArraySize(cFormats))) | 1325 if (iIndex < 0 || (static_cast<size_t>(iIndex) >= FX_ArraySize(cFormats))) |
| 1327 iIndex = 0; | 1326 iIndex = 0; |
| 1328 | 1327 |
| 1329 std::vector<CJS_Value> newParams; | 1328 std::vector<CJS_Value> newParams; |
| 1330 newParams.push_back( | 1329 newParams.push_back( |
| 1331 CJS_Value(CJS_Runtime::FromContext(cc), cFormats[iIndex])); | 1330 CJS_Value(CJS_Runtime::FromContext(cc), cFormats[iIndex])); |
| 1332 return AFDate_FormatEx(cc, newParams, vRet, sError); | 1331 return AFDate_FormatEx(cc, newParams, vRet, sError); |
| 1333 } | 1332 } |
| 1334 | 1333 |
| 1335 FX_BOOL CJS_PublicMethods::AFTime_Keystroke( | 1334 FX_BOOL CJS_PublicMethods::AFTime_Keystroke( |
| 1336 IJS_Context* cc, | 1335 IJS_Context* cc, |
| 1337 const std::vector<CJS_Value>& params, | 1336 const std::vector<CJS_Value>& params, |
| 1338 CJS_Value& vRet, | 1337 CJS_Value& vRet, |
| 1339 CFX_WideString& sError) { | 1338 CFX_WideString& sError) { |
| 1340 CJS_Context* pContext = (CJS_Context*)cc; | 1339 CJS_Context* pContext = (CJS_Context*)cc; |
| 1341 if (params.size() != 1) { | 1340 if (params.size() != 1) { |
| 1342 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1341 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 1343 return FALSE; | 1342 return FALSE; |
| 1344 } | 1343 } |
| 1345 | 1344 |
| 1346 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 1345 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 1347 int iIndex = params[0].ToInt(pRuntime->GetIsolate()); | 1346 int iIndex = params[0].ToInt(pRuntime); |
| 1348 const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss", | 1347 const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss", |
| 1349 L"h:MM:ss tt"}; | 1348 L"h:MM:ss tt"}; |
| 1350 | 1349 |
| 1351 if (iIndex < 0 || (static_cast<size_t>(iIndex) >= FX_ArraySize(cFormats))) | 1350 if (iIndex < 0 || (static_cast<size_t>(iIndex) >= FX_ArraySize(cFormats))) |
| 1352 iIndex = 0; | 1351 iIndex = 0; |
| 1353 | 1352 |
| 1354 std::vector<CJS_Value> newParams; | 1353 std::vector<CJS_Value> newParams; |
| 1355 newParams.push_back( | 1354 newParams.push_back( |
| 1356 CJS_Value(CJS_Runtime::FromContext(cc), cFormats[iIndex])); | 1355 CJS_Value(CJS_Runtime::FromContext(cc), cFormats[iIndex])); |
| 1357 return AFDate_KeystrokeEx(cc, newParams, vRet, sError); | 1356 return AFDate_KeystrokeEx(cc, newParams, vRet, sError); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1384 return FALSE; | 1383 return FALSE; |
| 1385 } | 1384 } |
| 1386 | 1385 |
| 1387 CJS_EventHandler* pEvent = pContext->GetEventHandler(); | 1386 CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
| 1388 if (!pEvent->m_pValue) | 1387 if (!pEvent->m_pValue) |
| 1389 return FALSE; | 1388 return FALSE; |
| 1390 | 1389 |
| 1391 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 1390 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 1392 CFX_WideString wsSource = pEvent->Value(); | 1391 CFX_WideString wsSource = pEvent->Value(); |
| 1393 CFX_WideString wsFormat; | 1392 CFX_WideString wsFormat; |
| 1394 switch (params[0].ToInt(pRuntime->GetIsolate())) { | 1393 switch (params[0].ToInt(pRuntime)) { |
| 1395 case 0: | 1394 case 0: |
| 1396 wsFormat = L"99999"; | 1395 wsFormat = L"99999"; |
| 1397 break; | 1396 break; |
| 1398 case 1: | 1397 case 1: |
| 1399 wsFormat = L"99999-9999"; | 1398 wsFormat = L"99999-9999"; |
| 1400 break; | 1399 break; |
| 1401 case 2: | 1400 case 2: |
| 1402 if (util::printx(L"9999999999", wsSource).GetLength() >= 10) | 1401 if (util::printx(L"9999999999", wsSource).GetLength() >= 10) |
| 1403 wsFormat = L"(999) 999-9999"; | 1402 wsFormat = L"(999) 999-9999"; |
| 1404 else | 1403 else |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1425 | 1424 |
| 1426 if (params.size() < 1) { | 1425 if (params.size() < 1) { |
| 1427 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1426 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 1428 return FALSE; | 1427 return FALSE; |
| 1429 } | 1428 } |
| 1430 | 1429 |
| 1431 if (!pEvent->m_pValue) | 1430 if (!pEvent->m_pValue) |
| 1432 return FALSE; | 1431 return FALSE; |
| 1433 CFX_WideString& valEvent = pEvent->Value(); | 1432 CFX_WideString& valEvent = pEvent->Value(); |
| 1434 | 1433 |
| 1435 CFX_WideString wstrMask = params[0].ToCFXWideString(pRuntime->GetIsolate()); | 1434 CFX_WideString wstrMask = params[0].ToCFXWideString(pRuntime); |
| 1436 if (wstrMask.IsEmpty()) | 1435 if (wstrMask.IsEmpty()) |
| 1437 return TRUE; | 1436 return TRUE; |
| 1438 | 1437 |
| 1439 if (pEvent->WillCommit()) { | 1438 if (pEvent->WillCommit()) { |
| 1440 if (valEvent.IsEmpty()) | 1439 if (valEvent.IsEmpty()) |
| 1441 return TRUE; | 1440 return TRUE; |
| 1442 | 1441 |
| 1443 FX_STRSIZE iIndexMask = 0; | 1442 FX_STRSIZE iIndexMask = 0; |
| 1444 for (; iIndexMask < valEvent.GetLength(); ++iIndexMask) { | 1443 for (; iIndexMask < valEvent.GetLength(); ++iIndexMask) { |
| 1445 if (!maskSatisfied(valEvent[iIndexMask], wstrMask[iIndexMask])) | 1444 if (!maskSatisfied(valEvent[iIndexMask], wstrMask[iIndexMask])) |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1513 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1512 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 1514 return FALSE; | 1513 return FALSE; |
| 1515 } | 1514 } |
| 1516 | 1515 |
| 1517 CJS_EventHandler* pEvent = pContext->GetEventHandler(); | 1516 CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
| 1518 if (!pEvent->m_pValue) | 1517 if (!pEvent->m_pValue) |
| 1519 return FALSE; | 1518 return FALSE; |
| 1520 | 1519 |
| 1521 const char* cFormat = ""; | 1520 const char* cFormat = ""; |
| 1522 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 1521 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 1523 switch (params[0].ToInt(pRuntime->GetIsolate())) { | 1522 switch (params[0].ToInt(pRuntime)) { |
| 1524 case 0: | 1523 case 0: |
| 1525 cFormat = "99999"; | 1524 cFormat = "99999"; |
| 1526 break; | 1525 break; |
| 1527 case 1: | 1526 case 1: |
| 1528 cFormat = "999999999"; | 1527 cFormat = "999999999"; |
| 1529 break; | 1528 break; |
| 1530 case 2: | 1529 case 2: |
| 1531 if (pEvent->Value().GetLength() + pEvent->Change().GetLength() > 7) | 1530 if (pEvent->Value().GetLength() + pEvent->Change().GetLength() > 7) |
| 1532 cFormat = "9999999999"; | 1531 cFormat = "9999999999"; |
| 1533 else | 1532 else |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1589 CJS_Value& vRet, | 1588 CJS_Value& vRet, |
| 1590 CFX_WideString& sError) { | 1589 CFX_WideString& sError) { |
| 1591 CJS_Context* pContext = (CJS_Context*)cc; | 1590 CJS_Context* pContext = (CJS_Context*)cc; |
| 1592 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 1591 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 1593 | 1592 |
| 1594 if (params.size() != 2) { | 1593 if (params.size() != 2) { |
| 1595 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1594 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 1596 return FALSE; | 1595 return FALSE; |
| 1597 } | 1596 } |
| 1598 | 1597 |
| 1599 CFX_WideString sValue = params[0].ToCFXWideString(pRuntime->GetIsolate()); | 1598 CFX_WideString sValue = params[0].ToCFXWideString(pRuntime); |
| 1600 CFX_WideString sFormat = params[1].ToCFXWideString(pRuntime->GetIsolate()); | 1599 CFX_WideString sFormat = params[1].ToCFXWideString(pRuntime); |
| 1601 | 1600 |
| 1602 double dDate = MakeRegularDate(sValue, sFormat, nullptr); | 1601 double dDate = MakeRegularDate(sValue, sFormat, nullptr); |
| 1603 | 1602 |
| 1604 if (JS_PortIsNan(dDate)) { | 1603 if (JS_PortIsNan(dDate)) { |
| 1605 CFX_WideString swMsg; | 1604 CFX_WideString swMsg; |
| 1606 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE).c_str(), | 1605 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE).c_str(), |
| 1607 sFormat.c_str()); | 1606 sFormat.c_str()); |
| 1608 AlertIfPossible((CJS_Context*)cc, swMsg.c_str()); | 1607 AlertIfPossible((CJS_Context*)cc, swMsg.c_str()); |
| 1609 return FALSE; | 1608 return FALSE; |
| 1610 } | 1609 } |
| 1611 | 1610 |
| 1612 vRet = CJS_Value(pRuntime, dDate); | 1611 vRet = CJS_Value(pRuntime, dDate); |
| 1613 return TRUE; | 1612 return TRUE; |
| 1614 } | 1613 } |
| 1615 | 1614 |
| 1616 FX_BOOL CJS_PublicMethods::AFSimple(IJS_Context* cc, | 1615 FX_BOOL CJS_PublicMethods::AFSimple(IJS_Context* cc, |
| 1617 const std::vector<CJS_Value>& params, | 1616 const std::vector<CJS_Value>& params, |
| 1618 CJS_Value& vRet, | 1617 CJS_Value& vRet, |
| 1619 CFX_WideString& sError) { | 1618 CFX_WideString& sError) { |
| 1620 CJS_Context* pContext = (CJS_Context*)cc; | 1619 CJS_Context* pContext = (CJS_Context*)cc; |
| 1621 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 1620 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 1622 | 1621 |
| 1623 if (params.size() != 3) { | 1622 if (params.size() != 3) { |
| 1624 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1623 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 1625 return FALSE; | 1624 return FALSE; |
| 1626 } | 1625 } |
| 1627 | 1626 |
| 1628 vRet = CJS_Value( | 1627 vRet = CJS_Value(pRuntime, static_cast<double>(AF_Simple( |
| 1629 pRuntime, static_cast<double>(AF_Simple( | 1628 params[0].ToCFXWideString(pRuntime).c_str(), |
| 1630 params[0].ToCFXWideString(pRuntime->GetIsolate()).c_str(), | 1629 params[1].ToDouble(pRuntime), |
| 1631 params[1].ToDouble(pRuntime->GetIsolate()), | 1630 params[2].ToDouble(pRuntime)))); |
| 1632 params[2].ToDouble(pRuntime->GetIsolate())))); | |
| 1633 | 1631 |
| 1634 return TRUE; | 1632 return TRUE; |
| 1635 } | 1633 } |
| 1636 | 1634 |
| 1637 FX_BOOL CJS_PublicMethods::AFMakeNumber(IJS_Context* cc, | 1635 FX_BOOL CJS_PublicMethods::AFMakeNumber(IJS_Context* cc, |
| 1638 const std::vector<CJS_Value>& params, | 1636 const std::vector<CJS_Value>& params, |
| 1639 CJS_Value& vRet, | 1637 CJS_Value& vRet, |
| 1640 CFX_WideString& sError) { | 1638 CFX_WideString& sError) { |
| 1641 CJS_Context* pContext = (CJS_Context*)cc; | 1639 CJS_Context* pContext = (CJS_Context*)cc; |
| 1642 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 1640 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 1643 | 1641 |
| 1644 if (params.size() != 1) { | 1642 if (params.size() != 1) { |
| 1645 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1643 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 1646 return FALSE; | 1644 return FALSE; |
| 1647 } | 1645 } |
| 1648 | 1646 |
| 1649 CFX_WideString ws = params[0].ToCFXWideString(pRuntime->GetIsolate()); | 1647 CFX_WideString ws = params[0].ToCFXWideString(pRuntime); |
| 1650 ws.Replace(L",", L"."); | 1648 ws.Replace(L",", L"."); |
| 1651 vRet = CJS_Value(pRuntime, ws.c_str()); | 1649 vRet = CJS_Value(pRuntime, ws.c_str()); |
| 1652 vRet.MaybeCoerceToNumber(pRuntime->GetIsolate()); | 1650 vRet.MaybeCoerceToNumber(pRuntime); |
| 1653 if (vRet.GetType() != CJS_Value::VT_number) | 1651 if (vRet.GetType() != CJS_Value::VT_number) |
| 1654 vRet = CJS_Value(pRuntime, 0); | 1652 vRet = CJS_Value(pRuntime, 0); |
| 1655 return TRUE; | 1653 return TRUE; |
| 1656 } | 1654 } |
| 1657 | 1655 |
| 1658 FX_BOOL CJS_PublicMethods::AFSimple_Calculate( | 1656 FX_BOOL CJS_PublicMethods::AFSimple_Calculate( |
| 1659 IJS_Context* cc, | 1657 IJS_Context* cc, |
| 1660 const std::vector<CJS_Value>& params, | 1658 const std::vector<CJS_Value>& params, |
| 1661 CJS_Value& vRet, | 1659 CJS_Value& vRet, |
| 1662 CFX_WideString& sError) { | 1660 CFX_WideString& sError) { |
| 1663 CJS_Context* pContext = (CJS_Context*)cc; | 1661 CJS_Context* pContext = (CJS_Context*)cc; |
| 1664 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 1662 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 1665 | 1663 |
| 1666 if (params.size() != 2) { | 1664 if (params.size() != 2) { |
| 1667 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1665 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 1668 return FALSE; | 1666 return FALSE; |
| 1669 } | 1667 } |
| 1670 | 1668 |
| 1671 CJS_Value params1 = params[1]; | 1669 CJS_Value params1 = params[1]; |
| 1672 if (!params1.IsArrayObject() && params1.GetType() != CJS_Value::VT_string) { | 1670 if (!params1.IsArrayObject() && params1.GetType() != CJS_Value::VT_string) { |
| 1673 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1671 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 1674 return FALSE; | 1672 return FALSE; |
| 1675 } | 1673 } |
| 1676 | 1674 |
| 1677 CPDFSDK_Document* pReaderDoc = pContext->GetReaderDocument(); | 1675 CPDFSDK_Document* pReaderDoc = pContext->GetReaderDocument(); |
| 1678 CPDFSDK_InterForm* pReaderInterForm = pReaderDoc->GetInterForm(); | 1676 CPDFSDK_InterForm* pReaderInterForm = pReaderDoc->GetInterForm(); |
| 1679 CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm(); | 1677 CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm(); |
| 1680 | 1678 |
| 1681 CFX_WideString sFunction = params[0].ToCFXWideString(pRuntime->GetIsolate()); | 1679 CFX_WideString sFunction = params[0].ToCFXWideString(pRuntime); |
| 1682 double dValue = wcscmp(sFunction.c_str(), L"PRD") == 0 ? 1.0 : 0.0; | 1680 double dValue = wcscmp(sFunction.c_str(), L"PRD") == 0 ? 1.0 : 0.0; |
| 1683 | 1681 |
| 1684 CJS_Array FieldNameArray = AF_MakeArrayFromList(pRuntime, params1); | 1682 CJS_Array FieldNameArray = AF_MakeArrayFromList(pRuntime, params1); |
| 1685 int nFieldsCount = 0; | 1683 int nFieldsCount = 0; |
| 1686 | 1684 |
| 1687 for (int i = 0, isz = FieldNameArray.GetLength(); i < isz; i++) { | 1685 for (int i = 0, isz = FieldNameArray.GetLength(pRuntime); i < isz; i++) { |
| 1688 CJS_Value jsValue(pRuntime); | 1686 CJS_Value jsValue(pRuntime); |
| 1689 FieldNameArray.GetElement(pRuntime->GetIsolate(), i, jsValue); | 1687 FieldNameArray.GetElement(pRuntime, i, jsValue); |
| 1690 CFX_WideString wsFieldName = | 1688 CFX_WideString wsFieldName = jsValue.ToCFXWideString(pRuntime); |
| 1691 jsValue.ToCFXWideString(pRuntime->GetIsolate()); | |
| 1692 | 1689 |
| 1693 for (int j = 0, jsz = pInterForm->CountFields(wsFieldName); j < jsz; j++) { | 1690 for (int j = 0, jsz = pInterForm->CountFields(wsFieldName); j < jsz; j++) { |
| 1694 if (CPDF_FormField* pFormField = pInterForm->GetField(j, wsFieldName)) { | 1691 if (CPDF_FormField* pFormField = pInterForm->GetField(j, wsFieldName)) { |
| 1695 double dTemp = 0.0; | 1692 double dTemp = 0.0; |
| 1696 switch (pFormField->GetFieldType()) { | 1693 switch (pFormField->GetFieldType()) { |
| 1697 case FIELDTYPE_TEXTFIELD: | 1694 case FIELDTYPE_TEXTFIELD: |
| 1698 case FIELDTYPE_COMBOBOX: { | 1695 case FIELDTYPE_COMBOBOX: { |
| 1699 CFX_WideString trimmed = pFormField->GetValue(); | 1696 CFX_WideString trimmed = pFormField->GetValue(); |
| 1700 trimmed.TrimRight(); | 1697 trimmed.TrimRight(); |
| 1701 trimmed.TrimLeft(); | 1698 trimmed.TrimLeft(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1742 } | 1739 } |
| 1743 } | 1740 } |
| 1744 | 1741 |
| 1745 if (wcscmp(sFunction.c_str(), L"AVG") == 0 && nFieldsCount > 0) | 1742 if (wcscmp(sFunction.c_str(), L"AVG") == 0 && nFieldsCount > 0) |
| 1746 dValue /= nFieldsCount; | 1743 dValue /= nFieldsCount; |
| 1747 | 1744 |
| 1748 dValue = (double)floor(dValue * FXSYS_pow((double)10, (double)6) + 0.49) / | 1745 dValue = (double)floor(dValue * FXSYS_pow((double)10, (double)6) + 0.49) / |
| 1749 FXSYS_pow((double)10, (double)6); | 1746 FXSYS_pow((double)10, (double)6); |
| 1750 CJS_Value jsValue(pRuntime, dValue); | 1747 CJS_Value jsValue(pRuntime, dValue); |
| 1751 if (pContext->GetEventHandler()->m_pValue) | 1748 if (pContext->GetEventHandler()->m_pValue) |
| 1752 pContext->GetEventHandler()->Value() = | 1749 pContext->GetEventHandler()->Value() = jsValue.ToCFXWideString(pRuntime); |
| 1753 jsValue.ToCFXWideString(pRuntime->GetIsolate()); | |
| 1754 | 1750 |
| 1755 return TRUE; | 1751 return TRUE; |
| 1756 } | 1752 } |
| 1757 | 1753 |
| 1758 /* This function validates the current event to ensure that its value is | 1754 /* This function validates the current event to ensure that its value is |
| 1759 ** within the specified range. */ | 1755 ** within the specified range. */ |
| 1760 | 1756 |
| 1761 FX_BOOL CJS_PublicMethods::AFRange_Validate( | 1757 FX_BOOL CJS_PublicMethods::AFRange_Validate( |
| 1762 IJS_Context* cc, | 1758 IJS_Context* cc, |
| 1763 const std::vector<CJS_Value>& params, | 1759 const std::vector<CJS_Value>& params, |
| 1764 CJS_Value& vRet, | 1760 CJS_Value& vRet, |
| 1765 CFX_WideString& sError) { | 1761 CFX_WideString& sError) { |
| 1766 CJS_Context* pContext = (CJS_Context*)cc; | 1762 CJS_Context* pContext = (CJS_Context*)cc; |
| 1767 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 1763 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 1768 CJS_EventHandler* pEvent = pContext->GetEventHandler(); | 1764 CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
| 1769 | 1765 |
| 1770 if (params.size() != 4) { | 1766 if (params.size() != 4) { |
| 1771 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1767 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 1772 return FALSE; | 1768 return FALSE; |
| 1773 } | 1769 } |
| 1774 | 1770 |
| 1775 if (!pEvent->m_pValue) | 1771 if (!pEvent->m_pValue) |
| 1776 return FALSE; | 1772 return FALSE; |
| 1777 if (pEvent->Value().IsEmpty()) | 1773 if (pEvent->Value().IsEmpty()) |
| 1778 return TRUE; | 1774 return TRUE; |
| 1779 double dEentValue = | 1775 double dEentValue = |
| 1780 atof(CFX_ByteString::FromUnicode(pEvent->Value()).c_str()); | 1776 atof(CFX_ByteString::FromUnicode(pEvent->Value()).c_str()); |
| 1781 FX_BOOL bGreaterThan = params[0].ToBool(pRuntime->GetIsolate()); | 1777 FX_BOOL bGreaterThan = params[0].ToBool(pRuntime); |
| 1782 double dGreaterThan = params[1].ToDouble(pRuntime->GetIsolate()); | 1778 double dGreaterThan = params[1].ToDouble(pRuntime); |
| 1783 FX_BOOL bLessThan = params[2].ToBool(pRuntime->GetIsolate()); | 1779 FX_BOOL bLessThan = params[2].ToBool(pRuntime); |
| 1784 double dLessThan = params[3].ToDouble(pRuntime->GetIsolate()); | 1780 double dLessThan = params[3].ToDouble(pRuntime); |
| 1785 CFX_WideString swMsg; | 1781 CFX_WideString swMsg; |
| 1786 | 1782 |
| 1787 if (bGreaterThan && bLessThan) { | 1783 if (bGreaterThan && bLessThan) { |
| 1788 if (dEentValue < dGreaterThan || dEentValue > dLessThan) | 1784 if (dEentValue < dGreaterThan || dEentValue > dLessThan) |
| 1789 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE1).c_str(), | 1785 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE1).c_str(), |
| 1790 params[1].ToCFXWideString(pRuntime->GetIsolate()).c_str(), | 1786 params[1].ToCFXWideString(pRuntime).c_str(), |
| 1791 params[3].ToCFXWideString(pRuntime->GetIsolate()).c_str()); | 1787 params[3].ToCFXWideString(pRuntime).c_str()); |
| 1792 } else if (bGreaterThan) { | 1788 } else if (bGreaterThan) { |
| 1793 if (dEentValue < dGreaterThan) | 1789 if (dEentValue < dGreaterThan) |
| 1794 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE2).c_str(), | 1790 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE2).c_str(), |
| 1795 params[1].ToCFXWideString(pRuntime->GetIsolate()).c_str()); | 1791 params[1].ToCFXWideString(pRuntime).c_str()); |
| 1796 } else if (bLessThan) { | 1792 } else if (bLessThan) { |
| 1797 if (dEentValue > dLessThan) | 1793 if (dEentValue > dLessThan) |
| 1798 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE3).c_str(), | 1794 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE3).c_str(), |
| 1799 params[3].ToCFXWideString(pRuntime->GetIsolate()).c_str()); | 1795 params[3].ToCFXWideString(pRuntime).c_str()); |
| 1800 } | 1796 } |
| 1801 | 1797 |
| 1802 if (!swMsg.IsEmpty()) { | 1798 if (!swMsg.IsEmpty()) { |
| 1803 AlertIfPossible(pContext, swMsg.c_str()); | 1799 AlertIfPossible(pContext, swMsg.c_str()); |
| 1804 pEvent->Rc() = FALSE; | 1800 pEvent->Rc() = FALSE; |
| 1805 } | 1801 } |
| 1806 return TRUE; | 1802 return TRUE; |
| 1807 } | 1803 } |
| 1808 | 1804 |
| 1809 FX_BOOL CJS_PublicMethods::AFExtractNums(IJS_Context* cc, | 1805 FX_BOOL CJS_PublicMethods::AFExtractNums(IJS_Context* cc, |
| 1810 const std::vector<CJS_Value>& params, | 1806 const std::vector<CJS_Value>& params, |
| 1811 CJS_Value& vRet, | 1807 CJS_Value& vRet, |
| 1812 CFX_WideString& sError) { | 1808 CFX_WideString& sError) { |
| 1813 CJS_Context* pContext = (CJS_Context*)cc; | 1809 CJS_Context* pContext = (CJS_Context*)cc; |
| 1814 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 1810 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 1815 | 1811 |
| 1816 if (params.size() != 1) { | 1812 if (params.size() != 1) { |
| 1817 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1813 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); |
| 1818 return FALSE; | 1814 return FALSE; |
| 1819 } | 1815 } |
| 1820 | 1816 |
| 1821 CJS_Array nums; | 1817 CJS_Array nums; |
| 1822 CFX_WideString str = params[0].ToCFXWideString(pRuntime->GetIsolate()); | 1818 CFX_WideString str = params[0].ToCFXWideString(pRuntime); |
| 1823 CFX_WideString sPart; | 1819 CFX_WideString sPart; |
| 1824 | 1820 |
| 1825 if (str.GetAt(0) == L'.' || str.GetAt(0) == L',') | 1821 if (str.GetAt(0) == L'.' || str.GetAt(0) == L',') |
| 1826 str = L"0" + str; | 1822 str = L"0" + str; |
| 1827 | 1823 |
| 1828 int nIndex = 0; | 1824 int nIndex = 0; |
| 1829 for (int i = 0, sz = str.GetLength(); i < sz; i++) { | 1825 for (int i = 0, sz = str.GetLength(); i < sz; i++) { |
| 1830 FX_WCHAR wc = str.GetAt(i); | 1826 FX_WCHAR wc = str.GetAt(i); |
| 1831 if (FXSYS_iswdigit(wc)) { | 1827 if (FXSYS_iswdigit(wc)) { |
| 1832 sPart += wc; | 1828 sPart += wc; |
| 1833 } else { | 1829 } else { |
| 1834 if (sPart.GetLength() > 0) { | 1830 if (sPart.GetLength() > 0) { |
| 1835 nums.SetElement(pRuntime->GetIsolate(), nIndex, | 1831 nums.SetElement(pRuntime, nIndex, CJS_Value(pRuntime, sPart.c_str())); |
| 1836 CJS_Value(pRuntime, sPart.c_str())); | |
| 1837 sPart = L""; | 1832 sPart = L""; |
| 1838 nIndex++; | 1833 nIndex++; |
| 1839 } | 1834 } |
| 1840 } | 1835 } |
| 1841 } | 1836 } |
| 1842 | 1837 |
| 1843 if (sPart.GetLength() > 0) { | 1838 if (sPart.GetLength() > 0) { |
| 1844 nums.SetElement(pRuntime->GetIsolate(), nIndex, | 1839 nums.SetElement(pRuntime, nIndex, CJS_Value(pRuntime, sPart.c_str())); |
| 1845 CJS_Value(pRuntime, sPart.c_str())); | |
| 1846 } | 1840 } |
| 1847 | 1841 |
| 1848 if (nums.GetLength() > 0) | 1842 if (nums.GetLength(pRuntime) > 0) |
| 1849 vRet = CJS_Value(pRuntime, nums); | 1843 vRet = CJS_Value(pRuntime, nums); |
| 1850 else | 1844 else |
| 1851 vRet.SetNull(pRuntime); | 1845 vRet.SetNull(pRuntime); |
| 1852 | 1846 |
| 1853 return TRUE; | 1847 return TRUE; |
| 1854 } | 1848 } |
| OLD | NEW |