| 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 710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 721 return sRet; | 721 return sRet; |
| 722 } | 722 } |
| 723 | 723 |
| 724 // function AFNumber_Format(nDec, sepStyle, negStyle, currStyle, strCurrency, | 724 // function AFNumber_Format(nDec, sepStyle, negStyle, currStyle, strCurrency, |
| 725 // bCurrencyPrepend) | 725 // bCurrencyPrepend) |
| 726 FX_BOOL CJS_PublicMethods::AFNumber_Format(IJS_Context* cc, | 726 FX_BOOL CJS_PublicMethods::AFNumber_Format(IJS_Context* cc, |
| 727 const std::vector<CJS_Value>& params, | 727 const std::vector<CJS_Value>& params, |
| 728 CJS_Value& vRet, | 728 CJS_Value& vRet, |
| 729 CFX_WideString& sError) { | 729 CFX_WideString& sError) { |
| 730 #if _FX_OS_ != _FX_ANDROID_ | 730 #if _FX_OS_ != _FX_ANDROID_ |
| 731 CJS_Context* pContext = (CJS_Context*)cc; | |
| 732 if (params.size() != 6) { | 731 if (params.size() != 6) { |
| 733 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 732 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
| 734 return FALSE; | 733 return FALSE; |
| 735 } | 734 } |
| 736 | 735 |
| 737 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 736 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 737 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
| 738 CJS_EventHandler* pEvent = pContext->GetEventHandler(); | 738 CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
| 739 if (!pEvent->m_pValue) | 739 if (!pEvent->m_pValue) |
| 740 return FALSE; | 740 return FALSE; |
| 741 | 741 |
| 742 CFX_WideString& Value = pEvent->Value(); | 742 CFX_WideString& Value = pEvent->Value(); |
| 743 CFX_ByteString strValue = StrTrim(CFX_ByteString::FromUnicode(Value)); | 743 CFX_ByteString strValue = StrTrim(CFX_ByteString::FromUnicode(Value)); |
| 744 if (strValue.IsEmpty()) | 744 if (strValue.IsEmpty()) |
| 745 return TRUE; | 745 return TRUE; |
| 746 | 746 |
| 747 int iDec = params[0].ToInt(pRuntime); | 747 int iDec = params[0].ToInt(pRuntime); |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 891 return TRUE; | 891 return TRUE; |
| 892 } | 892 } |
| 893 | 893 |
| 894 // function AFNumber_Keystroke(nDec, sepStyle, negStyle, currStyle, strCurrency, | 894 // function AFNumber_Keystroke(nDec, sepStyle, negStyle, currStyle, strCurrency, |
| 895 // bCurrencyPrepend) | 895 // bCurrencyPrepend) |
| 896 FX_BOOL CJS_PublicMethods::AFNumber_Keystroke( | 896 FX_BOOL CJS_PublicMethods::AFNumber_Keystroke( |
| 897 IJS_Context* cc, | 897 IJS_Context* cc, |
| 898 const std::vector<CJS_Value>& params, | 898 const std::vector<CJS_Value>& params, |
| 899 CJS_Value& vRet, | 899 CJS_Value& vRet, |
| 900 CFX_WideString& sError) { | 900 CFX_WideString& sError) { |
| 901 CJS_Context* pContext = (CJS_Context*)cc; | 901 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 902 CJS_EventHandler* pEvent = pContext->GetEventHandler(); | 902 CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
| 903 | 903 |
| 904 if (params.size() < 2) | 904 if (params.size() < 2) |
| 905 return FALSE; | 905 return FALSE; |
| 906 | 906 |
| 907 if (!pEvent->m_pValue) | 907 if (!pEvent->m_pValue) |
| 908 return FALSE; | 908 return FALSE; |
| 909 | 909 |
| 910 CFX_WideString& val = pEvent->Value(); | 910 CFX_WideString& val = pEvent->Value(); |
| 911 CFX_WideString& wstrChange = pEvent->Change(); | 911 CFX_WideString& wstrChange = pEvent->Change(); |
| 912 CFX_WideString wstrValue = val; | 912 CFX_WideString wstrValue = val; |
| 913 | 913 |
| 914 if (pEvent->WillCommit()) { | 914 if (pEvent->WillCommit()) { |
| 915 CFX_WideString swTemp = StrTrim(wstrValue); | 915 CFX_WideString swTemp = StrTrim(wstrValue); |
| 916 if (swTemp.IsEmpty()) | 916 if (swTemp.IsEmpty()) |
| 917 return TRUE; | 917 return TRUE; |
| 918 | 918 |
| 919 swTemp.Replace(L",", L"."); | 919 swTemp.Replace(L",", L"."); |
| 920 if (!IsNumber(swTemp.c_str())) { | 920 if (!IsNumber(swTemp.c_str())) { |
| 921 pEvent->Rc() = FALSE; | 921 pEvent->Rc() = FALSE; |
| 922 sError = JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYSTROKE); | 922 sError = JSGetStringFromID(IDS_STRING_JSAFNUMBER_KEYSTROKE); |
| 923 AlertIfPossible(pContext, sError.c_str()); | 923 AlertIfPossible(pContext, sError.c_str()); |
| 924 } | 924 } |
| 925 return TRUE; // it happens after the last keystroke and before validating, | 925 return TRUE; // it happens after the last keystroke and before validating, |
| 926 } | 926 } |
| 927 | 927 |
| 928 CFX_WideString wstrSelected; | 928 CFX_WideString wstrSelected; |
| 929 if (pEvent->SelStart() != -1) { | 929 if (pEvent->SelStart() != -1) { |
| 930 wstrSelected = wstrValue.Mid(pEvent->SelStart(), | 930 wstrSelected = wstrValue.Mid(pEvent->SelStart(), |
| 931 pEvent->SelEnd() - pEvent->SelStart()); | 931 pEvent->SelEnd() - pEvent->SelStart()); |
| 932 } | 932 } |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 994 return TRUE; | 994 return TRUE; |
| 995 } | 995 } |
| 996 | 996 |
| 997 // function AFPercent_Format(nDec, sepStyle) | 997 // function AFPercent_Format(nDec, sepStyle) |
| 998 FX_BOOL CJS_PublicMethods::AFPercent_Format( | 998 FX_BOOL CJS_PublicMethods::AFPercent_Format( |
| 999 IJS_Context* cc, | 999 IJS_Context* cc, |
| 1000 const std::vector<CJS_Value>& params, | 1000 const std::vector<CJS_Value>& params, |
| 1001 CJS_Value& vRet, | 1001 CJS_Value& vRet, |
| 1002 CFX_WideString& sError) { | 1002 CFX_WideString& sError) { |
| 1003 #if _FX_OS_ != _FX_ANDROID_ | 1003 #if _FX_OS_ != _FX_ANDROID_ |
| 1004 CJS_Context* pContext = (CJS_Context*)cc; | 1004 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 1005 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 1005 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 1006 CJS_EventHandler* pEvent = pContext->GetEventHandler(); | 1006 CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
| 1007 | 1007 |
| 1008 if (params.size() != 2) { | 1008 if (params.size() != 2) { |
| 1009 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1009 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
| 1010 return FALSE; | 1010 return FALSE; |
| 1011 } | 1011 } |
| 1012 if (!pEvent->m_pValue) | 1012 if (!pEvent->m_pValue) |
| 1013 return FALSE; | 1013 return FALSE; |
| 1014 | 1014 |
| 1015 CFX_WideString& Value = pEvent->Value(); | 1015 CFX_WideString& Value = pEvent->Value(); |
| 1016 CFX_ByteString strValue = StrTrim(CFX_ByteString::FromUnicode(Value)); | 1016 CFX_ByteString strValue = StrTrim(CFX_ByteString::FromUnicode(Value)); |
| 1017 if (strValue.IsEmpty()) | 1017 if (strValue.IsEmpty()) |
| 1018 return TRUE; | 1018 return TRUE; |
| 1019 | 1019 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1094 CJS_Value& vRet, | 1094 CJS_Value& vRet, |
| 1095 CFX_WideString& sError) { | 1095 CFX_WideString& sError) { |
| 1096 return AFNumber_Keystroke(cc, params, vRet, sError); | 1096 return AFNumber_Keystroke(cc, params, vRet, sError); |
| 1097 } | 1097 } |
| 1098 | 1098 |
| 1099 // function AFDate_FormatEx(cFormat) | 1099 // function AFDate_FormatEx(cFormat) |
| 1100 FX_BOOL CJS_PublicMethods::AFDate_FormatEx(IJS_Context* cc, | 1100 FX_BOOL CJS_PublicMethods::AFDate_FormatEx(IJS_Context* cc, |
| 1101 const std::vector<CJS_Value>& params, | 1101 const std::vector<CJS_Value>& params, |
| 1102 CJS_Value& vRet, | 1102 CJS_Value& vRet, |
| 1103 CFX_WideString& sError) { | 1103 CFX_WideString& sError) { |
| 1104 CJS_Context* pContext = (CJS_Context*)cc; | 1104 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 1105 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 1105 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 1106 CJS_EventHandler* pEvent = pContext->GetEventHandler(); | 1106 CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
| 1107 | 1107 |
| 1108 if (params.size() != 1) { | 1108 if (params.size() != 1) { |
| 1109 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1109 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
| 1110 return FALSE; | 1110 return FALSE; |
| 1111 } | 1111 } |
| 1112 if (!pEvent->m_pValue) | 1112 if (!pEvent->m_pValue) |
| 1113 return FALSE; | 1113 return FALSE; |
| 1114 | 1114 |
| 1115 CFX_WideString& val = pEvent->Value(); | 1115 CFX_WideString& val = pEvent->Value(); |
| 1116 CFX_WideString strValue = val; | 1116 CFX_WideString strValue = val; |
| 1117 if (strValue.IsEmpty()) | 1117 if (strValue.IsEmpty()) |
| 1118 return TRUE; | 1118 return TRUE; |
| 1119 | 1119 |
| 1120 CFX_WideString sFormat = params[0].ToCFXWideString(pRuntime); | 1120 CFX_WideString sFormat = params[0].ToCFXWideString(pRuntime); |
| 1121 double dDate = 0.0f; | 1121 double dDate = 0.0f; |
| 1122 | 1122 |
| 1123 if (strValue.Find(L"GMT") != -1) { | 1123 if (strValue.Find(L"GMT") != -1) { |
| 1124 // for GMT format time | 1124 // for GMT format time |
| 1125 // such as "Tue Aug 11 14:24:16 GMT+08002009" | 1125 // such as "Tue Aug 11 14:24:16 GMT+08002009" |
| 1126 dDate = MakeInterDate(strValue); | 1126 dDate = MakeInterDate(strValue); |
| 1127 } else { | 1127 } else { |
| 1128 dDate = MakeRegularDate(strValue, sFormat, nullptr); | 1128 dDate = MakeRegularDate(strValue, sFormat, nullptr); |
| 1129 } | 1129 } |
| 1130 | 1130 |
| 1131 if (JS_PortIsNan(dDate)) { | 1131 if (JS_PortIsNan(dDate)) { |
| 1132 CFX_WideString swMsg; | 1132 CFX_WideString swMsg; |
| 1133 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE).c_str(), | 1133 swMsg.Format(JSGetStringFromID(IDS_STRING_JSPARSEDATE).c_str(), |
| 1134 sFormat.c_str()); | 1134 sFormat.c_str()); |
| 1135 AlertIfPossible(pContext, swMsg.c_str()); | 1135 AlertIfPossible(pContext, swMsg.c_str()); |
| 1136 return FALSE; | 1136 return FALSE; |
| 1137 } | 1137 } |
| 1138 | 1138 |
| 1139 val = MakeFormatDate(dDate, sFormat); | 1139 val = MakeFormatDate(dDate, sFormat); |
| 1140 return TRUE; | 1140 return TRUE; |
| 1141 } | 1141 } |
| 1142 | 1142 |
| 1143 double CJS_PublicMethods::MakeInterDate(const CFX_WideString& strValue) { | 1143 double CJS_PublicMethods::MakeInterDate(const CFX_WideString& strValue) { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1216 return FALSE; | 1216 return FALSE; |
| 1217 CFX_WideString strValue = pEvent->Value(); | 1217 CFX_WideString strValue = pEvent->Value(); |
| 1218 if (strValue.IsEmpty()) | 1218 if (strValue.IsEmpty()) |
| 1219 return TRUE; | 1219 return TRUE; |
| 1220 | 1220 |
| 1221 CFX_WideString sFormat = params[0].ToCFXWideString(pRuntime); | 1221 CFX_WideString sFormat = params[0].ToCFXWideString(pRuntime); |
| 1222 bool bWrongFormat = FALSE; | 1222 bool bWrongFormat = FALSE; |
| 1223 double dRet = MakeRegularDate(strValue, sFormat, &bWrongFormat); | 1223 double dRet = MakeRegularDate(strValue, sFormat, &bWrongFormat); |
| 1224 if (bWrongFormat || JS_PortIsNan(dRet)) { | 1224 if (bWrongFormat || JS_PortIsNan(dRet)) { |
| 1225 CFX_WideString swMsg; | 1225 CFX_WideString swMsg; |
| 1226 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE).c_str(), | 1226 swMsg.Format(JSGetStringFromID(IDS_STRING_JSPARSEDATE).c_str(), |
| 1227 sFormat.c_str()); | 1227 sFormat.c_str()); |
| 1228 AlertIfPossible(pContext, swMsg.c_str()); | 1228 AlertIfPossible(pContext, swMsg.c_str()); |
| 1229 pEvent->Rc() = FALSE; | 1229 pEvent->Rc() = FALSE; |
| 1230 return TRUE; | 1230 return TRUE; |
| 1231 } | 1231 } |
| 1232 } | 1232 } |
| 1233 return TRUE; | 1233 return TRUE; |
| 1234 } | 1234 } |
| 1235 | 1235 |
| 1236 FX_BOOL CJS_PublicMethods::AFDate_Format(IJS_Context* cc, | 1236 FX_BOOL CJS_PublicMethods::AFDate_Format(IJS_Context* cc, |
| 1237 const std::vector<CJS_Value>& params, | 1237 const std::vector<CJS_Value>& params, |
| 1238 CJS_Value& vRet, | 1238 CJS_Value& vRet, |
| 1239 CFX_WideString& sError) { | 1239 CFX_WideString& sError) { |
| 1240 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(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); | 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", |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1268 CJS_Value(CJS_Runtime::FromContext(cc), cFormats[iIndex])); | 1267 CJS_Value(CJS_Runtime::FromContext(cc), cFormats[iIndex])); |
| 1269 return AFDate_FormatEx(cc, newParams, vRet, sError); | 1268 return AFDate_FormatEx(cc, newParams, vRet, sError); |
| 1270 } | 1269 } |
| 1271 | 1270 |
| 1272 // AFDate_KeystrokeEx(cFormat) | 1271 // AFDate_KeystrokeEx(cFormat) |
| 1273 FX_BOOL CJS_PublicMethods::AFDate_Keystroke( | 1272 FX_BOOL CJS_PublicMethods::AFDate_Keystroke( |
| 1274 IJS_Context* cc, | 1273 IJS_Context* cc, |
| 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; | |
| 1279 if (params.size() != 1) { | 1277 if (params.size() != 1) { |
| 1280 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1278 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
| 1281 return FALSE; | 1279 return FALSE; |
| 1282 } | 1280 } |
| 1283 | 1281 |
| 1284 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 1282 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 1285 int iIndex = params[0].ToInt(pRuntime); | 1283 int iIndex = params[0].ToInt(pRuntime); |
| 1286 const FX_WCHAR* cFormats[] = {L"m/d", | 1284 const FX_WCHAR* cFormats[] = {L"m/d", |
| 1287 L"m/d/yy", | 1285 L"m/d/yy", |
| 1288 L"mm/dd/yy", | 1286 L"mm/dd/yy", |
| 1289 L"mm/yy", | 1287 L"mm/yy", |
| 1290 L"d-mmm", | 1288 L"d-mmm", |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1305 newParams.push_back( | 1303 newParams.push_back( |
| 1306 CJS_Value(CJS_Runtime::FromContext(cc), cFormats[iIndex])); | 1304 CJS_Value(CJS_Runtime::FromContext(cc), cFormats[iIndex])); |
| 1307 return AFDate_KeystrokeEx(cc, newParams, vRet, sError); | 1305 return AFDate_KeystrokeEx(cc, newParams, vRet, sError); |
| 1308 } | 1306 } |
| 1309 | 1307 |
| 1310 // function AFTime_Format(ptf) | 1308 // function AFTime_Format(ptf) |
| 1311 FX_BOOL CJS_PublicMethods::AFTime_Format(IJS_Context* cc, | 1309 FX_BOOL CJS_PublicMethods::AFTime_Format(IJS_Context* cc, |
| 1312 const std::vector<CJS_Value>& params, | 1310 const std::vector<CJS_Value>& params, |
| 1313 CJS_Value& vRet, | 1311 CJS_Value& vRet, |
| 1314 CFX_WideString& sError) { | 1312 CFX_WideString& sError) { |
| 1315 CJS_Context* pContext = (CJS_Context*)cc; | |
| 1316 if (params.size() != 1) { | 1313 if (params.size() != 1) { |
| 1317 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1314 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
| 1318 return FALSE; | 1315 return FALSE; |
| 1319 } | 1316 } |
| 1320 | 1317 |
| 1321 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 1318 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 1322 int iIndex = params[0].ToInt(pRuntime); | 1319 int iIndex = params[0].ToInt(pRuntime); |
| 1323 const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss", | 1320 const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss", |
| 1324 L"h:MM:ss tt"}; | 1321 L"h:MM:ss tt"}; |
| 1325 | 1322 |
| 1326 if (iIndex < 0 || (static_cast<size_t>(iIndex) >= FX_ArraySize(cFormats))) | 1323 if (iIndex < 0 || (static_cast<size_t>(iIndex) >= FX_ArraySize(cFormats))) |
| 1327 iIndex = 0; | 1324 iIndex = 0; |
| 1328 | 1325 |
| 1329 std::vector<CJS_Value> newParams; | 1326 std::vector<CJS_Value> newParams; |
| 1330 newParams.push_back( | 1327 newParams.push_back( |
| 1331 CJS_Value(CJS_Runtime::FromContext(cc), cFormats[iIndex])); | 1328 CJS_Value(CJS_Runtime::FromContext(cc), cFormats[iIndex])); |
| 1332 return AFDate_FormatEx(cc, newParams, vRet, sError); | 1329 return AFDate_FormatEx(cc, newParams, vRet, sError); |
| 1333 } | 1330 } |
| 1334 | 1331 |
| 1335 FX_BOOL CJS_PublicMethods::AFTime_Keystroke( | 1332 FX_BOOL CJS_PublicMethods::AFTime_Keystroke( |
| 1336 IJS_Context* cc, | 1333 IJS_Context* cc, |
| 1337 const std::vector<CJS_Value>& params, | 1334 const std::vector<CJS_Value>& params, |
| 1338 CJS_Value& vRet, | 1335 CJS_Value& vRet, |
| 1339 CFX_WideString& sError) { | 1336 CFX_WideString& sError) { |
| 1340 CJS_Context* pContext = (CJS_Context*)cc; | |
| 1341 if (params.size() != 1) { | 1337 if (params.size() != 1) { |
| 1342 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1338 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
| 1343 return FALSE; | 1339 return FALSE; |
| 1344 } | 1340 } |
| 1345 | 1341 |
| 1346 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 1342 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 1347 int iIndex = params[0].ToInt(pRuntime); | 1343 int iIndex = params[0].ToInt(pRuntime); |
| 1348 const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss", | 1344 const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss", |
| 1349 L"h:MM:ss tt"}; | 1345 L"h:MM:ss tt"}; |
| 1350 | 1346 |
| 1351 if (iIndex < 0 || (static_cast<size_t>(iIndex) >= FX_ArraySize(cFormats))) | 1347 if (iIndex < 0 || (static_cast<size_t>(iIndex) >= FX_ArraySize(cFormats))) |
| 1352 iIndex = 0; | 1348 iIndex = 0; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1371 CFX_WideString& sError) { | 1367 CFX_WideString& sError) { |
| 1372 return AFDate_KeystrokeEx(cc, params, vRet, sError); | 1368 return AFDate_KeystrokeEx(cc, params, vRet, sError); |
| 1373 } | 1369 } |
| 1374 | 1370 |
| 1375 // function AFSpecial_Format(psf) | 1371 // function AFSpecial_Format(psf) |
| 1376 FX_BOOL CJS_PublicMethods::AFSpecial_Format( | 1372 FX_BOOL CJS_PublicMethods::AFSpecial_Format( |
| 1377 IJS_Context* cc, | 1373 IJS_Context* cc, |
| 1378 const std::vector<CJS_Value>& params, | 1374 const std::vector<CJS_Value>& params, |
| 1379 CJS_Value& vRet, | 1375 CJS_Value& vRet, |
| 1380 CFX_WideString& sError) { | 1376 CFX_WideString& sError) { |
| 1381 CJS_Context* pContext = (CJS_Context*)cc; | |
| 1382 if (params.size() != 1) { | 1377 if (params.size() != 1) { |
| 1383 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1378 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
| 1384 return FALSE; | 1379 return FALSE; |
| 1385 } | 1380 } |
| 1386 | 1381 |
| 1382 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 1387 CJS_EventHandler* pEvent = pContext->GetEventHandler(); | 1383 CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
| 1388 if (!pEvent->m_pValue) | 1384 if (!pEvent->m_pValue) |
| 1389 return FALSE; | 1385 return FALSE; |
| 1390 | 1386 |
| 1391 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 1387 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 1392 CFX_WideString wsSource = pEvent->Value(); | 1388 CFX_WideString wsSource = pEvent->Value(); |
| 1393 CFX_WideString wsFormat; | 1389 CFX_WideString wsFormat; |
| 1394 switch (params[0].ToInt(pRuntime)) { | 1390 switch (params[0].ToInt(pRuntime)) { |
| 1395 case 0: | 1391 case 0: |
| 1396 wsFormat = L"99999"; | 1392 wsFormat = L"99999"; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1417 FX_BOOL CJS_PublicMethods::AFSpecial_KeystrokeEx( | 1413 FX_BOOL CJS_PublicMethods::AFSpecial_KeystrokeEx( |
| 1418 IJS_Context* cc, | 1414 IJS_Context* cc, |
| 1419 const std::vector<CJS_Value>& params, | 1415 const std::vector<CJS_Value>& params, |
| 1420 CJS_Value& vRet, | 1416 CJS_Value& vRet, |
| 1421 CFX_WideString& sError) { | 1417 CFX_WideString& sError) { |
| 1422 CJS_Context* pContext = (CJS_Context*)cc; | 1418 CJS_Context* pContext = (CJS_Context*)cc; |
| 1423 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 1419 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 1424 CJS_EventHandler* pEvent = pContext->GetEventHandler(); | 1420 CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
| 1425 | 1421 |
| 1426 if (params.size() < 1) { | 1422 if (params.size() < 1) { |
| 1427 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1423 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
| 1428 return FALSE; | 1424 return FALSE; |
| 1429 } | 1425 } |
| 1430 | 1426 |
| 1431 if (!pEvent->m_pValue) | 1427 if (!pEvent->m_pValue) |
| 1432 return FALSE; | 1428 return FALSE; |
| 1429 |
| 1433 CFX_WideString& valEvent = pEvent->Value(); | 1430 CFX_WideString& valEvent = pEvent->Value(); |
| 1434 | |
| 1435 CFX_WideString wstrMask = params[0].ToCFXWideString(pRuntime); | 1431 CFX_WideString wstrMask = params[0].ToCFXWideString(pRuntime); |
| 1436 if (wstrMask.IsEmpty()) | 1432 if (wstrMask.IsEmpty()) |
| 1437 return TRUE; | 1433 return TRUE; |
| 1438 | 1434 |
| 1439 if (pEvent->WillCommit()) { | 1435 if (pEvent->WillCommit()) { |
| 1440 if (valEvent.IsEmpty()) | 1436 if (valEvent.IsEmpty()) |
| 1441 return TRUE; | 1437 return TRUE; |
| 1442 | 1438 |
| 1443 FX_STRSIZE iIndexMask = 0; | 1439 FX_STRSIZE iIndexMask = 0; |
| 1444 for (; iIndexMask < valEvent.GetLength(); ++iIndexMask) { | 1440 for (; iIndexMask < valEvent.GetLength(); ++iIndexMask) { |
| 1445 if (!maskSatisfied(valEvent[iIndexMask], wstrMask[iIndexMask])) | 1441 if (!maskSatisfied(valEvent[iIndexMask], wstrMask[iIndexMask])) |
| 1446 break; | 1442 break; |
| 1447 } | 1443 } |
| 1448 | 1444 |
| 1449 if (iIndexMask != wstrMask.GetLength() || | 1445 if (iIndexMask != wstrMask.GetLength() || |
| 1450 (iIndexMask != valEvent.GetLength() && wstrMask.GetLength() != 0)) { | 1446 (iIndexMask != valEvent.GetLength() && wstrMask.GetLength() != 0)) { |
| 1451 AlertIfPossible( | 1447 AlertIfPossible( |
| 1452 pContext, | 1448 pContext, JSGetStringFromID(IDS_STRING_JSAFNUMBER_KEYSTROKE).c_str()); |
| 1453 JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYSTROKE).c_str()); | |
| 1454 pEvent->Rc() = FALSE; | 1449 pEvent->Rc() = FALSE; |
| 1455 } | 1450 } |
| 1456 return TRUE; | 1451 return TRUE; |
| 1457 } | 1452 } |
| 1458 | 1453 |
| 1459 CFX_WideString& wideChange = pEvent->Change(); | 1454 CFX_WideString& wideChange = pEvent->Change(); |
| 1460 if (wideChange.IsEmpty()) | 1455 if (wideChange.IsEmpty()) |
| 1461 return TRUE; | 1456 return TRUE; |
| 1462 | 1457 |
| 1463 CFX_WideString wChange = wideChange; | 1458 CFX_WideString wChange = wideChange; |
| 1464 FX_STRSIZE iIndexMask = pEvent->SelStart(); | 1459 FX_STRSIZE iIndexMask = pEvent->SelStart(); |
| 1465 FX_STRSIZE combined_len = valEvent.GetLength() + wChange.GetLength() + | 1460 FX_STRSIZE combined_len = valEvent.GetLength() + wChange.GetLength() + |
| 1466 pEvent->SelStart() - pEvent->SelEnd(); | 1461 pEvent->SelStart() - pEvent->SelEnd(); |
| 1467 if (combined_len > wstrMask.GetLength()) { | 1462 if (combined_len > wstrMask.GetLength()) { |
| 1468 AlertIfPossible( | 1463 AlertIfPossible(pContext, |
| 1469 pContext, | 1464 JSGetStringFromID(IDS_STRING_JSPARAM_TOOLONG).c_str()); |
| 1470 JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG).c_str()); | |
| 1471 pEvent->Rc() = FALSE; | 1465 pEvent->Rc() = FALSE; |
| 1472 return TRUE; | 1466 return TRUE; |
| 1473 } | 1467 } |
| 1474 | 1468 |
| 1475 if (iIndexMask >= wstrMask.GetLength() && !wChange.IsEmpty()) { | 1469 if (iIndexMask >= wstrMask.GetLength() && !wChange.IsEmpty()) { |
| 1476 AlertIfPossible( | 1470 AlertIfPossible(pContext, |
| 1477 pContext, | 1471 JSGetStringFromID(IDS_STRING_JSPARAM_TOOLONG).c_str()); |
| 1478 JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG).c_str()); | |
| 1479 pEvent->Rc() = FALSE; | 1472 pEvent->Rc() = FALSE; |
| 1480 return TRUE; | 1473 return TRUE; |
| 1481 } | 1474 } |
| 1482 | 1475 |
| 1483 for (FX_STRSIZE i = 0; i < wChange.GetLength(); ++i) { | 1476 for (FX_STRSIZE i = 0; i < wChange.GetLength(); ++i) { |
| 1484 if (iIndexMask >= wstrMask.GetLength()) { | 1477 if (iIndexMask >= wstrMask.GetLength()) { |
| 1485 AlertIfPossible( | 1478 AlertIfPossible(pContext, |
| 1486 pContext, | 1479 JSGetStringFromID(IDS_STRING_JSPARAM_TOOLONG).c_str()); |
| 1487 JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG).c_str()); | |
| 1488 pEvent->Rc() = FALSE; | 1480 pEvent->Rc() = FALSE; |
| 1489 return TRUE; | 1481 return TRUE; |
| 1490 } | 1482 } |
| 1491 FX_WCHAR wMask = wstrMask[iIndexMask]; | 1483 FX_WCHAR wMask = wstrMask[iIndexMask]; |
| 1492 if (!isReservedMaskChar(wMask)) | 1484 if (!isReservedMaskChar(wMask)) |
| 1493 wChange.SetAt(i, wMask); | 1485 wChange.SetAt(i, wMask); |
| 1494 | 1486 |
| 1495 if (!maskSatisfied(wChange[i], wMask)) { | 1487 if (!maskSatisfied(wChange[i], wMask)) { |
| 1496 pEvent->Rc() = FALSE; | 1488 pEvent->Rc() = FALSE; |
| 1497 return TRUE; | 1489 return TRUE; |
| 1498 } | 1490 } |
| 1499 iIndexMask++; | 1491 iIndexMask++; |
| 1500 } | 1492 } |
| 1501 wideChange = wChange; | 1493 wideChange = wChange; |
| 1502 return TRUE; | 1494 return TRUE; |
| 1503 } | 1495 } |
| 1504 | 1496 |
| 1505 // function AFSpecial_Keystroke(psf) | 1497 // function AFSpecial_Keystroke(psf) |
| 1506 FX_BOOL CJS_PublicMethods::AFSpecial_Keystroke( | 1498 FX_BOOL CJS_PublicMethods::AFSpecial_Keystroke( |
| 1507 IJS_Context* cc, | 1499 IJS_Context* cc, |
| 1508 const std::vector<CJS_Value>& params, | 1500 const std::vector<CJS_Value>& params, |
| 1509 CJS_Value& vRet, | 1501 CJS_Value& vRet, |
| 1510 CFX_WideString& sError) { | 1502 CFX_WideString& sError) { |
| 1511 CJS_Context* pContext = (CJS_Context*)cc; | |
| 1512 if (params.size() != 1) { | 1503 if (params.size() != 1) { |
| 1513 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1504 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
| 1514 return FALSE; | 1505 return FALSE; |
| 1515 } | 1506 } |
| 1516 | 1507 |
| 1508 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 1517 CJS_EventHandler* pEvent = pContext->GetEventHandler(); | 1509 CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
| 1518 if (!pEvent->m_pValue) | 1510 if (!pEvent->m_pValue) |
| 1519 return FALSE; | 1511 return FALSE; |
| 1520 | 1512 |
| 1521 const char* cFormat = ""; | 1513 const char* cFormat = ""; |
| 1522 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 1514 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 1523 switch (params[0].ToInt(pRuntime)) { | 1515 switch (params[0].ToInt(pRuntime)) { |
| 1524 case 0: | 1516 case 0: |
| 1525 cFormat = "99999"; | 1517 cFormat = "99999"; |
| 1526 break; | 1518 break; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1540 | 1532 |
| 1541 std::vector<CJS_Value> params2; | 1533 std::vector<CJS_Value> params2; |
| 1542 params2.push_back(CJS_Value(CJS_Runtime::FromContext(cc), cFormat)); | 1534 params2.push_back(CJS_Value(CJS_Runtime::FromContext(cc), cFormat)); |
| 1543 return AFSpecial_KeystrokeEx(cc, params2, vRet, sError); | 1535 return AFSpecial_KeystrokeEx(cc, params2, vRet, sError); |
| 1544 } | 1536 } |
| 1545 | 1537 |
| 1546 FX_BOOL CJS_PublicMethods::AFMergeChange(IJS_Context* cc, | 1538 FX_BOOL CJS_PublicMethods::AFMergeChange(IJS_Context* cc, |
| 1547 const std::vector<CJS_Value>& params, | 1539 const std::vector<CJS_Value>& params, |
| 1548 CJS_Value& vRet, | 1540 CJS_Value& vRet, |
| 1549 CFX_WideString& sError) { | 1541 CFX_WideString& sError) { |
| 1550 CJS_Context* pContext = (CJS_Context*)cc; | 1542 if (params.size() != 1) { |
| 1543 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
| 1544 return FALSE; |
| 1545 } |
| 1546 |
| 1547 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 1551 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 1548 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 1552 CJS_EventHandler* pEventHandler = pContext->GetEventHandler(); | 1549 CJS_EventHandler* pEventHandler = pContext->GetEventHandler(); |
| 1553 | 1550 |
| 1554 if (params.size() != 1) { | |
| 1555 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | |
| 1556 return FALSE; | |
| 1557 } | |
| 1558 | |
| 1559 CFX_WideString swValue; | 1551 CFX_WideString swValue; |
| 1560 if (pEventHandler->m_pValue) | 1552 if (pEventHandler->m_pValue) |
| 1561 swValue = pEventHandler->Value(); | 1553 swValue = pEventHandler->Value(); |
| 1562 | 1554 |
| 1563 if (pEventHandler->WillCommit()) { | 1555 if (pEventHandler->WillCommit()) { |
| 1564 vRet = CJS_Value(pRuntime, swValue.c_str()); | 1556 vRet = CJS_Value(pRuntime, swValue.c_str()); |
| 1565 return TRUE; | 1557 return TRUE; |
| 1566 } | 1558 } |
| 1567 | 1559 |
| 1568 CFX_WideString prefix, postfix; | 1560 CFX_WideString prefix, postfix; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1581 | 1573 |
| 1582 vRet = | 1574 vRet = |
| 1583 CJS_Value(pRuntime, (prefix + pEventHandler->Change() + postfix).c_str()); | 1575 CJS_Value(pRuntime, (prefix + pEventHandler->Change() + postfix).c_str()); |
| 1584 return TRUE; | 1576 return TRUE; |
| 1585 } | 1577 } |
| 1586 | 1578 |
| 1587 FX_BOOL CJS_PublicMethods::AFParseDateEx(IJS_Context* cc, | 1579 FX_BOOL CJS_PublicMethods::AFParseDateEx(IJS_Context* cc, |
| 1588 const std::vector<CJS_Value>& params, | 1580 const std::vector<CJS_Value>& params, |
| 1589 CJS_Value& vRet, | 1581 CJS_Value& vRet, |
| 1590 CFX_WideString& sError) { | 1582 CFX_WideString& sError) { |
| 1591 CJS_Context* pContext = (CJS_Context*)cc; | |
| 1592 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | |
| 1593 | |
| 1594 if (params.size() != 2) { | 1583 if (params.size() != 2) { |
| 1595 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1584 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
| 1596 return FALSE; | 1585 return FALSE; |
| 1597 } | 1586 } |
| 1598 | 1587 |
| 1588 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 1599 CFX_WideString sValue = params[0].ToCFXWideString(pRuntime); | 1589 CFX_WideString sValue = params[0].ToCFXWideString(pRuntime); |
| 1600 CFX_WideString sFormat = params[1].ToCFXWideString(pRuntime); | 1590 CFX_WideString sFormat = params[1].ToCFXWideString(pRuntime); |
| 1601 | 1591 |
| 1602 double dDate = MakeRegularDate(sValue, sFormat, nullptr); | 1592 double dDate = MakeRegularDate(sValue, sFormat, nullptr); |
| 1603 | 1593 |
| 1604 if (JS_PortIsNan(dDate)) { | 1594 if (JS_PortIsNan(dDate)) { |
| 1605 CFX_WideString swMsg; | 1595 CFX_WideString swMsg; |
| 1606 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE).c_str(), | 1596 swMsg.Format(JSGetStringFromID(IDS_STRING_JSPARSEDATE).c_str(), |
| 1607 sFormat.c_str()); | 1597 sFormat.c_str()); |
| 1608 AlertIfPossible((CJS_Context*)cc, swMsg.c_str()); | 1598 AlertIfPossible((CJS_Context*)cc, swMsg.c_str()); |
| 1609 return FALSE; | 1599 return FALSE; |
| 1610 } | 1600 } |
| 1611 | 1601 |
| 1612 vRet = CJS_Value(pRuntime, dDate); | 1602 vRet = CJS_Value(pRuntime, dDate); |
| 1613 return TRUE; | 1603 return TRUE; |
| 1614 } | 1604 } |
| 1615 | 1605 |
| 1616 FX_BOOL CJS_PublicMethods::AFSimple(IJS_Context* cc, | 1606 FX_BOOL CJS_PublicMethods::AFSimple(IJS_Context* cc, |
| 1617 const std::vector<CJS_Value>& params, | 1607 const std::vector<CJS_Value>& params, |
| 1618 CJS_Value& vRet, | 1608 CJS_Value& vRet, |
| 1619 CFX_WideString& sError) { | 1609 CFX_WideString& sError) { |
| 1620 CJS_Context* pContext = (CJS_Context*)cc; | |
| 1621 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | |
| 1622 | |
| 1623 if (params.size() != 3) { | 1610 if (params.size() != 3) { |
| 1624 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1611 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
| 1625 return FALSE; | 1612 return FALSE; |
| 1626 } | 1613 } |
| 1627 | 1614 |
| 1615 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 1628 vRet = CJS_Value(pRuntime, static_cast<double>(AF_Simple( | 1616 vRet = CJS_Value(pRuntime, static_cast<double>(AF_Simple( |
| 1629 params[0].ToCFXWideString(pRuntime).c_str(), | 1617 params[0].ToCFXWideString(pRuntime).c_str(), |
| 1630 params[1].ToDouble(pRuntime), | 1618 params[1].ToDouble(pRuntime), |
| 1631 params[2].ToDouble(pRuntime)))); | 1619 params[2].ToDouble(pRuntime)))); |
| 1632 | 1620 |
| 1633 return TRUE; | 1621 return TRUE; |
| 1634 } | 1622 } |
| 1635 | 1623 |
| 1636 FX_BOOL CJS_PublicMethods::AFMakeNumber(IJS_Context* cc, | 1624 FX_BOOL CJS_PublicMethods::AFMakeNumber(IJS_Context* cc, |
| 1637 const std::vector<CJS_Value>& params, | 1625 const std::vector<CJS_Value>& params, |
| 1638 CJS_Value& vRet, | 1626 CJS_Value& vRet, |
| 1639 CFX_WideString& sError) { | 1627 CFX_WideString& sError) { |
| 1640 CJS_Context* pContext = (CJS_Context*)cc; | |
| 1641 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | |
| 1642 | |
| 1643 if (params.size() != 1) { | 1628 if (params.size() != 1) { |
| 1644 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1629 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
| 1645 return FALSE; | 1630 return FALSE; |
| 1646 } | 1631 } |
| 1647 | 1632 |
| 1633 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 1648 CFX_WideString ws = params[0].ToCFXWideString(pRuntime); | 1634 CFX_WideString ws = params[0].ToCFXWideString(pRuntime); |
| 1649 ws.Replace(L",", L"."); | 1635 ws.Replace(L",", L"."); |
| 1650 vRet = CJS_Value(pRuntime, ws.c_str()); | 1636 vRet = CJS_Value(pRuntime, ws.c_str()); |
| 1651 vRet.MaybeCoerceToNumber(pRuntime); | 1637 vRet.MaybeCoerceToNumber(pRuntime); |
| 1652 if (vRet.GetType() != CJS_Value::VT_number) | 1638 if (vRet.GetType() != CJS_Value::VT_number) |
| 1653 vRet = CJS_Value(pRuntime, 0); | 1639 vRet = CJS_Value(pRuntime, 0); |
| 1654 return TRUE; | 1640 return TRUE; |
| 1655 } | 1641 } |
| 1656 | 1642 |
| 1657 FX_BOOL CJS_PublicMethods::AFSimple_Calculate( | 1643 FX_BOOL CJS_PublicMethods::AFSimple_Calculate( |
| 1658 IJS_Context* cc, | 1644 IJS_Context* cc, |
| 1659 const std::vector<CJS_Value>& params, | 1645 const std::vector<CJS_Value>& params, |
| 1660 CJS_Value& vRet, | 1646 CJS_Value& vRet, |
| 1661 CFX_WideString& sError) { | 1647 CFX_WideString& sError) { |
| 1662 CJS_Context* pContext = (CJS_Context*)cc; | |
| 1663 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | |
| 1664 | |
| 1665 if (params.size() != 2) { | 1648 if (params.size() != 2) { |
| 1666 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1649 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
| 1667 return FALSE; | 1650 return FALSE; |
| 1668 } | 1651 } |
| 1669 | 1652 |
| 1670 CJS_Value params1 = params[1]; | 1653 CJS_Value params1 = params[1]; |
| 1671 if (!params1.IsArrayObject() && params1.GetType() != CJS_Value::VT_string) { | 1654 if (!params1.IsArrayObject() && params1.GetType() != CJS_Value::VT_string) { |
| 1672 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1655 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
| 1673 return FALSE; | 1656 return FALSE; |
| 1674 } | 1657 } |
| 1675 | 1658 |
| 1659 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 1660 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 1676 CPDFSDK_Document* pReaderDoc = pContext->GetReaderDocument(); | 1661 CPDFSDK_Document* pReaderDoc = pContext->GetReaderDocument(); |
| 1677 CPDFSDK_InterForm* pReaderInterForm = pReaderDoc->GetInterForm(); | 1662 CPDFSDK_InterForm* pReaderInterForm = pReaderDoc->GetInterForm(); |
| 1678 CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm(); | 1663 CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm(); |
| 1679 | 1664 |
| 1680 CFX_WideString sFunction = params[0].ToCFXWideString(pRuntime); | 1665 CFX_WideString sFunction = params[0].ToCFXWideString(pRuntime); |
| 1681 double dValue = wcscmp(sFunction.c_str(), L"PRD") == 0 ? 1.0 : 0.0; | 1666 double dValue = wcscmp(sFunction.c_str(), L"PRD") == 0 ? 1.0 : 0.0; |
| 1682 | 1667 |
| 1683 CJS_Array FieldNameArray = AF_MakeArrayFromList(pRuntime, params1); | 1668 CJS_Array FieldNameArray = AF_MakeArrayFromList(pRuntime, params1); |
| 1684 int nFieldsCount = 0; | 1669 int nFieldsCount = 0; |
| 1685 | 1670 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1753 } | 1738 } |
| 1754 | 1739 |
| 1755 /* This function validates the current event to ensure that its value is | 1740 /* This function validates the current event to ensure that its value is |
| 1756 ** within the specified range. */ | 1741 ** within the specified range. */ |
| 1757 | 1742 |
| 1758 FX_BOOL CJS_PublicMethods::AFRange_Validate( | 1743 FX_BOOL CJS_PublicMethods::AFRange_Validate( |
| 1759 IJS_Context* cc, | 1744 IJS_Context* cc, |
| 1760 const std::vector<CJS_Value>& params, | 1745 const std::vector<CJS_Value>& params, |
| 1761 CJS_Value& vRet, | 1746 CJS_Value& vRet, |
| 1762 CFX_WideString& sError) { | 1747 CFX_WideString& sError) { |
| 1763 CJS_Context* pContext = (CJS_Context*)cc; | 1748 if (params.size() != 4) { |
| 1749 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
| 1750 return FALSE; |
| 1751 } |
| 1752 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
| 1764 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 1753 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 1765 CJS_EventHandler* pEvent = pContext->GetEventHandler(); | 1754 CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
| 1766 | |
| 1767 if (params.size() != 4) { | |
| 1768 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | |
| 1769 return FALSE; | |
| 1770 } | |
| 1771 | |
| 1772 if (!pEvent->m_pValue) | 1755 if (!pEvent->m_pValue) |
| 1773 return FALSE; | 1756 return FALSE; |
| 1757 |
| 1774 if (pEvent->Value().IsEmpty()) | 1758 if (pEvent->Value().IsEmpty()) |
| 1775 return TRUE; | 1759 return TRUE; |
| 1760 |
| 1776 double dEentValue = | 1761 double dEentValue = |
| 1777 atof(CFX_ByteString::FromUnicode(pEvent->Value()).c_str()); | 1762 atof(CFX_ByteString::FromUnicode(pEvent->Value()).c_str()); |
| 1778 FX_BOOL bGreaterThan = params[0].ToBool(pRuntime); | 1763 FX_BOOL bGreaterThan = params[0].ToBool(pRuntime); |
| 1779 double dGreaterThan = params[1].ToDouble(pRuntime); | 1764 double dGreaterThan = params[1].ToDouble(pRuntime); |
| 1780 FX_BOOL bLessThan = params[2].ToBool(pRuntime); | 1765 FX_BOOL bLessThan = params[2].ToBool(pRuntime); |
| 1781 double dLessThan = params[3].ToDouble(pRuntime); | 1766 double dLessThan = params[3].ToDouble(pRuntime); |
| 1782 CFX_WideString swMsg; | 1767 CFX_WideString swMsg; |
| 1783 | 1768 |
| 1784 if (bGreaterThan && bLessThan) { | 1769 if (bGreaterThan && bLessThan) { |
| 1785 if (dEentValue < dGreaterThan || dEentValue > dLessThan) | 1770 if (dEentValue < dGreaterThan || dEentValue > dLessThan) |
| 1786 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE1).c_str(), | 1771 swMsg.Format(JSGetStringFromID(IDS_STRING_JSRANGE1).c_str(), |
| 1787 params[1].ToCFXWideString(pRuntime).c_str(), | 1772 params[1].ToCFXWideString(pRuntime).c_str(), |
| 1788 params[3].ToCFXWideString(pRuntime).c_str()); | 1773 params[3].ToCFXWideString(pRuntime).c_str()); |
| 1789 } else if (bGreaterThan) { | 1774 } else if (bGreaterThan) { |
| 1790 if (dEentValue < dGreaterThan) | 1775 if (dEentValue < dGreaterThan) |
| 1791 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE2).c_str(), | 1776 swMsg.Format(JSGetStringFromID(IDS_STRING_JSRANGE2).c_str(), |
| 1792 params[1].ToCFXWideString(pRuntime).c_str()); | 1777 params[1].ToCFXWideString(pRuntime).c_str()); |
| 1793 } else if (bLessThan) { | 1778 } else if (bLessThan) { |
| 1794 if (dEentValue > dLessThan) | 1779 if (dEentValue > dLessThan) |
| 1795 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE3).c_str(), | 1780 swMsg.Format(JSGetStringFromID(IDS_STRING_JSRANGE3).c_str(), |
| 1796 params[3].ToCFXWideString(pRuntime).c_str()); | 1781 params[3].ToCFXWideString(pRuntime).c_str()); |
| 1797 } | 1782 } |
| 1798 | 1783 |
| 1799 if (!swMsg.IsEmpty()) { | 1784 if (!swMsg.IsEmpty()) { |
| 1800 AlertIfPossible(pContext, swMsg.c_str()); | 1785 AlertIfPossible(pContext, swMsg.c_str()); |
| 1801 pEvent->Rc() = FALSE; | 1786 pEvent->Rc() = FALSE; |
| 1802 } | 1787 } |
| 1803 return TRUE; | 1788 return TRUE; |
| 1804 } | 1789 } |
| 1805 | 1790 |
| 1806 FX_BOOL CJS_PublicMethods::AFExtractNums(IJS_Context* cc, | 1791 FX_BOOL CJS_PublicMethods::AFExtractNums(IJS_Context* cc, |
| 1807 const std::vector<CJS_Value>& params, | 1792 const std::vector<CJS_Value>& params, |
| 1808 CJS_Value& vRet, | 1793 CJS_Value& vRet, |
| 1809 CFX_WideString& sError) { | 1794 CFX_WideString& sError) { |
| 1810 CJS_Context* pContext = (CJS_Context*)cc; | |
| 1811 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | |
| 1812 | |
| 1813 if (params.size() != 1) { | 1795 if (params.size() != 1) { |
| 1814 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); | 1796 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
| 1815 return FALSE; | 1797 return FALSE; |
| 1816 } | 1798 } |
| 1817 | 1799 |
| 1818 CJS_Array nums; | 1800 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
| 1819 CFX_WideString str = params[0].ToCFXWideString(pRuntime); | 1801 CFX_WideString str = params[0].ToCFXWideString(pRuntime); |
| 1820 CFX_WideString sPart; | 1802 CFX_WideString sPart; |
| 1803 CJS_Array nums; |
| 1821 | 1804 |
| 1822 if (str.GetAt(0) == L'.' || str.GetAt(0) == L',') | 1805 if (str.GetAt(0) == L'.' || str.GetAt(0) == L',') |
| 1823 str = L"0" + str; | 1806 str = L"0" + str; |
| 1824 | 1807 |
| 1825 int nIndex = 0; | 1808 int nIndex = 0; |
| 1826 for (int i = 0, sz = str.GetLength(); i < sz; i++) { | 1809 for (int i = 0, sz = str.GetLength(); i < sz; i++) { |
| 1827 FX_WCHAR wc = str.GetAt(i); | 1810 FX_WCHAR wc = str.GetAt(i); |
| 1828 if (FXSYS_iswdigit(wc)) { | 1811 if (FXSYS_iswdigit(wc)) { |
| 1829 sPart += wc; | 1812 sPart += wc; |
| 1830 } else { | 1813 } else { |
| 1831 if (sPart.GetLength() > 0) { | 1814 if (sPart.GetLength() > 0) { |
| 1832 nums.SetElement(pRuntime, nIndex, CJS_Value(pRuntime, sPart.c_str())); | 1815 nums.SetElement(pRuntime, nIndex, CJS_Value(pRuntime, sPart.c_str())); |
| 1833 sPart = L""; | 1816 sPart = L""; |
| 1834 nIndex++; | 1817 nIndex++; |
| 1835 } | 1818 } |
| 1836 } | 1819 } |
| 1837 } | 1820 } |
| 1838 | 1821 |
| 1839 if (sPart.GetLength() > 0) { | 1822 if (sPart.GetLength() > 0) { |
| 1840 nums.SetElement(pRuntime, nIndex, CJS_Value(pRuntime, sPart.c_str())); | 1823 nums.SetElement(pRuntime, nIndex, CJS_Value(pRuntime, sPart.c_str())); |
| 1841 } | 1824 } |
| 1842 | 1825 |
| 1843 if (nums.GetLength(pRuntime) > 0) | 1826 if (nums.GetLength(pRuntime) > 0) |
| 1844 vRet = CJS_Value(pRuntime, nums); | 1827 vRet = CJS_Value(pRuntime, nums); |
| 1845 else | 1828 else |
| 1846 vRet.SetNull(pRuntime); | 1829 vRet.SetNull(pRuntime); |
| 1847 | 1830 |
| 1848 return TRUE; | 1831 return TRUE; |
| 1849 } | 1832 } |
| OLD | NEW |