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 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 | 328 |
329 int nYear = JS_GetYearFromTime(dt); | 329 int nYear = JS_GetYearFromTime(dt); |
330 int nMonth = JS_GetMonthFromTime(dt) + 1; | 330 int nMonth = JS_GetMonthFromTime(dt) + 1; |
331 int nDay = JS_GetDayFromTime(dt); | 331 int nDay = JS_GetDayFromTime(dt); |
332 int nHour = JS_GetHourFromTime(dt); | 332 int nHour = JS_GetHourFromTime(dt); |
333 int nMin = JS_GetMinFromTime(dt); | 333 int nMin = JS_GetMinFromTime(dt); |
334 int nSec = JS_GetSecFromTime(dt); | 334 int nSec = JS_GetSecFromTime(dt); |
335 | 335 |
336 int nYearSub = 99; // nYear - 2000; | 336 int nYearSub = 99; // nYear - 2000; |
337 | 337 |
338 FX_BOOL bPm = FALSE; | 338 bool bPm = false; |
339 FX_BOOL bExit = FALSE; | 339 bool bExit = false; |
340 bool bBadFormat = false; | 340 bool bBadFormat = false; |
341 | 341 |
342 int i = 0; | 342 int i = 0; |
343 int j = 0; | 343 int j = 0; |
344 | 344 |
345 while (i < format.GetLength()) { | 345 while (i < format.GetLength()) { |
346 if (bExit) | 346 if (bExit) |
347 break; | 347 break; |
348 | 348 |
349 FX_WCHAR c = format.GetAt(i); | 349 FX_WCHAR c = format.GetAt(i); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 bPm = (j + 1 < value.GetLength() && value.GetAt(j) == 'p' && | 452 bPm = (j + 1 < value.GetLength() && value.GetAt(j) == 'p' && |
453 value.GetAt(j + 1) == 'm'); | 453 value.GetAt(j + 1) == 'm'); |
454 i += 2; | 454 i += 2; |
455 j += 2; | 455 j += 2; |
456 break; | 456 break; |
457 } | 457 } |
458 } else if (remaining == 2 || format.GetAt(i + 3) != c) { | 458 } else if (remaining == 2 || format.GetAt(i + 3) != c) { |
459 switch (c) { | 459 switch (c) { |
460 case 'm': { | 460 case 'm': { |
461 CFX_WideString sMonth = ParseStringString(value, j, nSkip); | 461 CFX_WideString sMonth = ParseStringString(value, j, nSkip); |
462 FX_BOOL bFind = FALSE; | 462 bool bFind = false; |
463 for (int m = 0; m < 12; m++) { | 463 for (int m = 0; m < 12; m++) { |
464 if (sMonth.CompareNoCase(months[m]) == 0) { | 464 if (sMonth.CompareNoCase(months[m]) == 0) { |
465 nMonth = m + 1; | 465 nMonth = m + 1; |
466 i += 3; | 466 i += 3; |
467 j += nSkip; | 467 j += nSkip; |
468 bFind = TRUE; | 468 bFind = true; |
469 break; | 469 break; |
470 } | 470 } |
471 } | 471 } |
472 | 472 |
473 if (!bFind) { | 473 if (!bFind) { |
474 nMonth = ParseStringInteger(value, j, nSkip, 3); | 474 nMonth = ParseStringInteger(value, j, nSkip, 3); |
475 i += 3; | 475 i += 3; |
476 j += nSkip; | 476 j += nSkip; |
477 } | 477 } |
478 } break; | 478 } break; |
479 case 'y': | 479 case 'y': |
480 break; | 480 break; |
481 default: | 481 default: |
482 i += 3; | 482 i += 3; |
483 j += 3; | 483 j += 3; |
484 break; | 484 break; |
485 } | 485 } |
486 } else if (remaining == 3 || format.GetAt(i + 4) != c) { | 486 } else if (remaining == 3 || format.GetAt(i + 4) != c) { |
487 switch (c) { | 487 switch (c) { |
488 case 'y': | 488 case 'y': |
489 nYear = ParseStringInteger(value, j, nSkip, 4); | 489 nYear = ParseStringInteger(value, j, nSkip, 4); |
490 j += nSkip; | 490 j += nSkip; |
491 i += 4; | 491 i += 4; |
492 break; | 492 break; |
493 case 'm': { | 493 case 'm': { |
494 FX_BOOL bFind = FALSE; | 494 bool bFind = false; |
495 | 495 |
496 CFX_WideString sMonth = ParseStringString(value, j, nSkip); | 496 CFX_WideString sMonth = ParseStringString(value, j, nSkip); |
497 sMonth.MakeLower(); | 497 sMonth.MakeLower(); |
498 | 498 |
499 for (int m = 0; m < 12; m++) { | 499 for (int m = 0; m < 12; m++) { |
500 CFX_WideString sFullMonths = fullmonths[m]; | 500 CFX_WideString sFullMonths = fullmonths[m]; |
501 sFullMonths.MakeLower(); | 501 sFullMonths.MakeLower(); |
502 | 502 |
503 if (sFullMonths.Find(sMonth.c_str(), 0) != -1) { | 503 if (sFullMonths.Find(sMonth.c_str(), 0) != -1) { |
504 nMonth = m + 1; | 504 nMonth = m + 1; |
505 i += 4; | 505 i += 4; |
506 j += nSkip; | 506 j += nSkip; |
507 bFind = TRUE; | 507 bFind = true; |
508 break; | 508 break; |
509 } | 509 } |
510 } | 510 } |
511 | 511 |
512 if (!bFind) { | 512 if (!bFind) { |
513 nMonth = ParseStringInteger(value, j, nSkip, 4); | 513 nMonth = ParseStringInteger(value, j, nSkip, 4); |
514 i += 4; | 514 i += 4; |
515 j += nSkip; | 515 j += nSkip; |
516 } | 516 } |
517 } break; | 517 } break; |
518 default: | 518 default: |
519 i += 4; | 519 i += 4; |
520 j += 4; | 520 j += 4; |
521 break; | 521 break; |
522 } | 522 } |
523 } else { | 523 } else { |
524 if (j >= value.GetLength() || format.GetAt(i) != value.GetAt(j)) { | 524 if (j >= value.GetLength() || format.GetAt(i) != value.GetAt(j)) { |
525 bBadFormat = true; | 525 bBadFormat = true; |
526 bExit = TRUE; | 526 bExit = true; |
527 } | 527 } |
528 i++; | 528 i++; |
529 j++; | 529 j++; |
530 } | 530 } |
531 | 531 |
532 if (oldj == j) { | 532 if (oldj == j) { |
533 bBadFormat = true; | 533 bBadFormat = true; |
534 bExit = TRUE; | 534 bExit = true; |
535 } | 535 } |
536 } | 536 } |
537 | 537 |
538 break; | 538 break; |
539 default: | 539 default: |
540 if (value.GetLength() <= j) { | 540 if (value.GetLength() <= j) { |
541 bExit = TRUE; | 541 bExit = true; |
542 } else if (format.GetAt(i) != value.GetAt(j)) { | 542 } else if (format.GetAt(i) != value.GetAt(j)) { |
543 bBadFormat = true; | 543 bBadFormat = true; |
544 bExit = TRUE; | 544 bExit = true; |
545 } | 545 } |
546 | 546 |
547 i++; | 547 i++; |
548 j++; | 548 j++; |
549 break; | 549 break; |
550 } | 550 } |
551 } | 551 } |
552 | 552 |
553 if (bPm) | 553 if (bPm) |
554 nHour += 12; | 554 nHour += 12; |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
716 } | 716 } |
717 | 717 |
718 sRet += sPart; | 718 sRet += sPart; |
719 } | 719 } |
720 | 720 |
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 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 if (params.size() != 6) { | 731 if (params.size() != 6) { |
732 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); | 732 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
733 return FALSE; | 733 return false; |
734 } | 734 } |
735 | 735 |
736 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 736 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
737 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 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); |
748 int iSepStyle = params[1].ToInt(pRuntime); | 748 int iSepStyle = params[1].ToInt(pRuntime); |
749 int iNegStyle = params[2].ToInt(pRuntime); | 749 int iNegStyle = params[2].ToInt(pRuntime); |
750 // params[3] is iCurrStyle, it's not used. | 750 // params[3] is iCurrStyle, it's not used. |
751 CFX_WideString wstrCurrency = params[4].ToCFXWideString(pRuntime); | 751 CFX_WideString wstrCurrency = params[4].ToCFXWideString(pRuntime); |
752 FX_BOOL bCurrencyPrepend = params[5].ToBool(pRuntime); | 752 bool bCurrencyPrepend = params[5].ToBool(pRuntime); |
753 | 753 |
754 if (iDec < 0) | 754 if (iDec < 0) |
755 iDec = -iDec; | 755 iDec = -iDec; |
756 | 756 |
757 if (iSepStyle < 0 || iSepStyle > 3) | 757 if (iSepStyle < 0 || iSepStyle > 3) |
758 iSepStyle = 0; | 758 iSepStyle = 0; |
759 | 759 |
760 if (iNegStyle < 0 || iNegStyle > 3) | 760 if (iNegStyle < 0 || iNegStyle > 3) |
761 iNegStyle = 0; | 761 iNegStyle = 0; |
762 | 762 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
881 CJS_PropValue vProp2(pRuntime); | 881 CJS_PropValue vProp2(pRuntime); |
882 vProp2.StartGetting(); | 882 vProp2.StartGetting(); |
883 vProp2 << arColor; | 883 vProp2 << arColor; |
884 vProp2.StartSetting(); | 884 vProp2.StartSetting(); |
885 fTarget->textColor(cc, vProp2, sError); | 885 fTarget->textColor(cc, vProp2, sError); |
886 } | 886 } |
887 } | 887 } |
888 } | 888 } |
889 } | 889 } |
890 #endif | 890 #endif |
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 bool CJS_PublicMethods::AFNumber_Keystroke(IJS_Context* cc, |
897 IJS_Context* cc, | 897 const std::vector<CJS_Value>& params, |
898 const std::vector<CJS_Value>& params, | 898 CJS_Value& vRet, |
899 CJS_Value& vRet, | 899 CFX_WideString& sError) { |
900 CFX_WideString& sError) { | |
901 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 900 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
902 CJS_EventHandler* pEvent = pContext->GetEventHandler(); | 901 CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
903 | 902 |
904 if (params.size() < 2) | 903 if (params.size() < 2) |
905 return FALSE; | 904 return false; |
906 | 905 |
907 if (!pEvent->m_pValue) | 906 if (!pEvent->m_pValue) |
908 return FALSE; | 907 return false; |
909 | 908 |
910 CFX_WideString& val = pEvent->Value(); | 909 CFX_WideString& val = pEvent->Value(); |
911 CFX_WideString& wstrChange = pEvent->Change(); | 910 CFX_WideString& wstrChange = pEvent->Change(); |
912 CFX_WideString wstrValue = val; | 911 CFX_WideString wstrValue = val; |
913 | 912 |
914 if (pEvent->WillCommit()) { | 913 if (pEvent->WillCommit()) { |
915 CFX_WideString swTemp = StrTrim(wstrValue); | 914 CFX_WideString swTemp = StrTrim(wstrValue); |
916 if (swTemp.IsEmpty()) | 915 if (swTemp.IsEmpty()) |
917 return TRUE; | 916 return true; |
918 | 917 |
919 swTemp.Replace(L",", L"."); | 918 swTemp.Replace(L",", L"."); |
920 if (!IsNumber(swTemp.c_str())) { | 919 if (!IsNumber(swTemp.c_str())) { |
921 pEvent->Rc() = FALSE; | 920 pEvent->Rc() = false; |
922 sError = JSGetStringFromID(IDS_STRING_JSAFNUMBER_KEYSTROKE); | 921 sError = JSGetStringFromID(IDS_STRING_JSAFNUMBER_KEYSTROKE); |
923 AlertIfPossible(pContext, sError.c_str()); | 922 AlertIfPossible(pContext, sError.c_str()); |
924 } | 923 } |
925 return TRUE; // it happens after the last keystroke and before validating, | 924 return true; // it happens after the last keystroke and before validating, |
926 } | 925 } |
927 | 926 |
928 CFX_WideString wstrSelected; | 927 CFX_WideString wstrSelected; |
929 if (pEvent->SelStart() != -1) { | 928 if (pEvent->SelStart() != -1) { |
930 wstrSelected = wstrValue.Mid(pEvent->SelStart(), | 929 wstrSelected = wstrValue.Mid(pEvent->SelStart(), |
931 pEvent->SelEnd() - pEvent->SelStart()); | 930 pEvent->SelEnd() - pEvent->SelStart()); |
932 } | 931 } |
933 | 932 |
934 bool bHasSign = wstrValue.Find(L'-') != -1 && wstrSelected.Find(L'-') == -1; | 933 bool bHasSign = wstrValue.Find(L'-') != -1 && wstrSelected.Find(L'-') == -1; |
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 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); | 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 bool& bRc = pEvent->Rc(); |
955 bRc = FALSE; | 954 bRc = false; |
956 return TRUE; | 955 return true; |
957 } | 956 } |
958 bHasSep = TRUE; | 957 bHasSep = true; |
959 continue; | 958 continue; |
960 } | 959 } |
961 if (wstrChange[i] == L'-') { | 960 if (wstrChange[i] == L'-') { |
962 if (bHasSign) { | 961 if (bHasSign) { |
963 FX_BOOL& bRc = pEvent->Rc(); | 962 bool& bRc = pEvent->Rc(); |
964 bRc = FALSE; | 963 bRc = false; |
965 return TRUE; | 964 return true; |
966 } | 965 } |
967 // sign's position is not correct | 966 // sign's position is not correct |
968 if (i != 0) { | 967 if (i != 0) { |
969 FX_BOOL& bRc = pEvent->Rc(); | 968 bool& bRc = pEvent->Rc(); |
970 bRc = FALSE; | 969 bRc = false; |
971 return TRUE; | 970 return true; |
972 } | 971 } |
973 if (pEvent->SelStart() != 0) { | 972 if (pEvent->SelStart() != 0) { |
974 FX_BOOL& bRc = pEvent->Rc(); | 973 bool& bRc = pEvent->Rc(); |
975 bRc = FALSE; | 974 bRc = false; |
976 return TRUE; | 975 return true; |
977 } | 976 } |
978 bHasSign = TRUE; | 977 bHasSign = true; |
979 continue; | 978 continue; |
980 } | 979 } |
981 | 980 |
982 if (!FXSYS_iswdigit(wstrChange[i])) { | 981 if (!FXSYS_iswdigit(wstrChange[i])) { |
983 FX_BOOL& bRc = pEvent->Rc(); | 982 bool& bRc = pEvent->Rc(); |
984 bRc = FALSE; | 983 bRc = false; |
985 return TRUE; | 984 return true; |
986 } | 985 } |
987 } | 986 } |
988 | 987 |
989 CFX_WideString wprefix = wstrValue.Mid(0, pEvent->SelStart()); | 988 CFX_WideString wprefix = wstrValue.Mid(0, pEvent->SelStart()); |
990 CFX_WideString wpostfix; | 989 CFX_WideString wpostfix; |
991 if (pEvent->SelEnd() < wstrValue.GetLength()) | 990 if (pEvent->SelEnd() < wstrValue.GetLength()) |
992 wpostfix = wstrValue.Mid(pEvent->SelEnd()); | 991 wpostfix = wstrValue.Mid(pEvent->SelEnd()); |
993 val = wprefix + wstrChange + wpostfix; | 992 val = wprefix + wstrChange + wpostfix; |
994 return TRUE; | 993 return true; |
995 } | 994 } |
996 | 995 |
997 // function AFPercent_Format(nDec, sepStyle) | 996 // function AFPercent_Format(nDec, sepStyle) |
998 FX_BOOL CJS_PublicMethods::AFPercent_Format( | 997 bool CJS_PublicMethods::AFPercent_Format(IJS_Context* cc, |
999 IJS_Context* cc, | 998 const std::vector<CJS_Value>& params, |
1000 const std::vector<CJS_Value>& params, | 999 CJS_Value& vRet, |
1001 CJS_Value& vRet, | 1000 CFX_WideString& sError) { |
1002 CFX_WideString& sError) { | |
1003 #if _FX_OS_ != _FX_ANDROID_ | 1001 #if _FX_OS_ != _FX_ANDROID_ |
1004 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 1002 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
1005 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 1003 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
1006 CJS_EventHandler* pEvent = pContext->GetEventHandler(); | 1004 CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
1007 | 1005 |
1008 if (params.size() != 2) { | 1006 if (params.size() != 2) { |
1009 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); | 1007 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
1010 return FALSE; | 1008 return false; |
1011 } | 1009 } |
1012 if (!pEvent->m_pValue) | 1010 if (!pEvent->m_pValue) |
1013 return FALSE; | 1011 return false; |
1014 | 1012 |
1015 CFX_WideString& Value = pEvent->Value(); | 1013 CFX_WideString& Value = pEvent->Value(); |
1016 CFX_ByteString strValue = StrTrim(CFX_ByteString::FromUnicode(Value)); | 1014 CFX_ByteString strValue = StrTrim(CFX_ByteString::FromUnicode(Value)); |
1017 if (strValue.IsEmpty()) | 1015 if (strValue.IsEmpty()) |
1018 return TRUE; | 1016 return true; |
1019 | 1017 |
1020 int iDec = params[0].ToInt(pRuntime); | 1018 int iDec = params[0].ToInt(pRuntime); |
1021 if (iDec < 0) | 1019 if (iDec < 0) |
1022 iDec = -iDec; | 1020 iDec = -iDec; |
1023 | 1021 |
1024 int iSepStyle = params[1].ToInt(pRuntime); | 1022 int iSepStyle = params[1].ToInt(pRuntime); |
1025 if (iSepStyle < 0 || iSepStyle > 3) | 1023 if (iSepStyle < 0 || iSepStyle > 3) |
1026 iSepStyle = 0; | 1024 iSepStyle = 0; |
1027 | 1025 |
1028 // for processing decimal places | 1026 // for processing decimal places |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1078 iMax++; | 1076 iMax++; |
1079 } | 1077 } |
1080 } | 1078 } |
1081 | 1079 |
1082 // negative mark | 1080 // negative mark |
1083 if (iNegative) | 1081 if (iNegative) |
1084 strValue = "-" + strValue; | 1082 strValue = "-" + strValue; |
1085 strValue += "%"; | 1083 strValue += "%"; |
1086 Value = CFX_WideString::FromLocal(strValue.AsStringC()); | 1084 Value = CFX_WideString::FromLocal(strValue.AsStringC()); |
1087 #endif | 1085 #endif |
1088 return TRUE; | 1086 return true; |
1089 } | 1087 } |
1090 // AFPercent_Keystroke(nDec, sepStyle) | 1088 // AFPercent_Keystroke(nDec, sepStyle) |
1091 FX_BOOL CJS_PublicMethods::AFPercent_Keystroke( | 1089 bool CJS_PublicMethods::AFPercent_Keystroke( |
1092 IJS_Context* cc, | 1090 IJS_Context* cc, |
1093 const std::vector<CJS_Value>& params, | 1091 const std::vector<CJS_Value>& params, |
1094 CJS_Value& vRet, | 1092 CJS_Value& vRet, |
1095 CFX_WideString& sError) { | 1093 CFX_WideString& sError) { |
1096 return AFNumber_Keystroke(cc, params, vRet, sError); | 1094 return AFNumber_Keystroke(cc, params, vRet, sError); |
1097 } | 1095 } |
1098 | 1096 |
1099 // function AFDate_FormatEx(cFormat) | 1097 // function AFDate_FormatEx(cFormat) |
1100 FX_BOOL CJS_PublicMethods::AFDate_FormatEx(IJS_Context* cc, | 1098 bool CJS_PublicMethods::AFDate_FormatEx(IJS_Context* cc, |
1101 const std::vector<CJS_Value>& params, | 1099 const std::vector<CJS_Value>& params, |
1102 CJS_Value& vRet, | 1100 CJS_Value& vRet, |
1103 CFX_WideString& sError) { | 1101 CFX_WideString& sError) { |
1104 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 1102 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
1105 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 1103 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
1106 CJS_EventHandler* pEvent = pContext->GetEventHandler(); | 1104 CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
1107 | 1105 |
1108 if (params.size() != 1) { | 1106 if (params.size() != 1) { |
1109 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); | 1107 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
1110 return FALSE; | 1108 return false; |
1111 } | 1109 } |
1112 if (!pEvent->m_pValue) | 1110 if (!pEvent->m_pValue) |
1113 return FALSE; | 1111 return false; |
1114 | 1112 |
1115 CFX_WideString& val = pEvent->Value(); | 1113 CFX_WideString& val = pEvent->Value(); |
1116 CFX_WideString strValue = val; | 1114 CFX_WideString strValue = val; |
1117 if (strValue.IsEmpty()) | 1115 if (strValue.IsEmpty()) |
1118 return TRUE; | 1116 return true; |
1119 | 1117 |
1120 CFX_WideString sFormat = params[0].ToCFXWideString(pRuntime); | 1118 CFX_WideString sFormat = params[0].ToCFXWideString(pRuntime); |
1121 double dDate = 0.0f; | 1119 double dDate = 0.0f; |
1122 | 1120 |
1123 if (strValue.Find(L"GMT") != -1) { | 1121 if (strValue.Find(L"GMT") != -1) { |
1124 // for GMT format time | 1122 // for GMT format time |
1125 // such as "Tue Aug 11 14:24:16 GMT+08002009" | 1123 // such as "Tue Aug 11 14:24:16 GMT+08002009" |
1126 dDate = MakeInterDate(strValue); | 1124 dDate = MakeInterDate(strValue); |
1127 } else { | 1125 } else { |
1128 dDate = MakeRegularDate(strValue, sFormat, nullptr); | 1126 dDate = MakeRegularDate(strValue, sFormat, nullptr); |
1129 } | 1127 } |
1130 | 1128 |
1131 if (JS_PortIsNan(dDate)) { | 1129 if (JS_PortIsNan(dDate)) { |
1132 CFX_WideString swMsg; | 1130 CFX_WideString swMsg; |
1133 swMsg.Format(JSGetStringFromID(IDS_STRING_JSPARSEDATE).c_str(), | 1131 swMsg.Format(JSGetStringFromID(IDS_STRING_JSPARSEDATE).c_str(), |
1134 sFormat.c_str()); | 1132 sFormat.c_str()); |
1135 AlertIfPossible(pContext, swMsg.c_str()); | 1133 AlertIfPossible(pContext, swMsg.c_str()); |
1136 return FALSE; | 1134 return false; |
1137 } | 1135 } |
1138 | 1136 |
1139 val = MakeFormatDate(dDate, sFormat); | 1137 val = MakeFormatDate(dDate, sFormat); |
1140 return TRUE; | 1138 return true; |
1141 } | 1139 } |
1142 | 1140 |
1143 double CJS_PublicMethods::MakeInterDate(const CFX_WideString& strValue) { | 1141 double CJS_PublicMethods::MakeInterDate(const CFX_WideString& strValue) { |
1144 std::vector<CFX_WideString> wsArray; | 1142 std::vector<CFX_WideString> wsArray; |
1145 CFX_WideString sTemp = L""; | 1143 CFX_WideString sTemp = L""; |
1146 for (int i = 0; i < strValue.GetLength(); ++i) { | 1144 for (int i = 0; i < strValue.GetLength(); ++i) { |
1147 FX_WCHAR c = strValue.GetAt(i); | 1145 FX_WCHAR c = strValue.GetAt(i); |
1148 if (c == L' ' || c == L':') { | 1146 if (c == L' ' || c == L':') { |
1149 wsArray.push_back(sTemp); | 1147 wsArray.push_back(sTemp); |
1150 sTemp = L""; | 1148 sTemp = L""; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1190 int nYear = FX_atof(wsArray[7].AsStringC()); | 1188 int nYear = FX_atof(wsArray[7].AsStringC()); |
1191 double dRet = JS_MakeDate(JS_MakeDay(nYear, nMonth - 1, nDay), | 1189 double dRet = JS_MakeDate(JS_MakeDay(nYear, nMonth - 1, nDay), |
1192 JS_MakeTime(nHour, nMin, nSec, 0)); | 1190 JS_MakeTime(nHour, nMin, nSec, 0)); |
1193 if (JS_PortIsNan(dRet)) | 1191 if (JS_PortIsNan(dRet)) |
1194 dRet = JS_DateParse(strValue); | 1192 dRet = JS_DateParse(strValue); |
1195 | 1193 |
1196 return dRet; | 1194 return dRet; |
1197 } | 1195 } |
1198 | 1196 |
1199 // AFDate_KeystrokeEx(cFormat) | 1197 // AFDate_KeystrokeEx(cFormat) |
1200 FX_BOOL CJS_PublicMethods::AFDate_KeystrokeEx( | 1198 bool CJS_PublicMethods::AFDate_KeystrokeEx(IJS_Context* cc, |
1201 IJS_Context* cc, | 1199 const std::vector<CJS_Value>& params, |
1202 const std::vector<CJS_Value>& params, | 1200 CJS_Value& vRet, |
1203 CJS_Value& vRet, | 1201 CFX_WideString& sError) { |
1204 CFX_WideString& sError) { | |
1205 CJS_Context* pContext = (CJS_Context*)cc; | 1202 CJS_Context* pContext = (CJS_Context*)cc; |
1206 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 1203 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
1207 CJS_EventHandler* pEvent = pContext->GetEventHandler(); | 1204 CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
1208 | 1205 |
1209 if (params.size() != 1) { | 1206 if (params.size() != 1) { |
1210 sError = L"AFDate_KeystrokeEx's parameters' size r not correct"; | 1207 sError = L"AFDate_KeystrokeEx's parameters' size r not correct"; |
1211 return FALSE; | 1208 return false; |
1212 } | 1209 } |
1213 | 1210 |
1214 if (pEvent->WillCommit()) { | 1211 if (pEvent->WillCommit()) { |
1215 if (!pEvent->m_pValue) | 1212 if (!pEvent->m_pValue) |
1216 return FALSE; | 1213 return false; |
1217 CFX_WideString strValue = pEvent->Value(); | 1214 CFX_WideString strValue = pEvent->Value(); |
1218 if (strValue.IsEmpty()) | 1215 if (strValue.IsEmpty()) |
1219 return TRUE; | 1216 return true; |
1220 | 1217 |
1221 CFX_WideString sFormat = params[0].ToCFXWideString(pRuntime); | 1218 CFX_WideString sFormat = params[0].ToCFXWideString(pRuntime); |
1222 bool bWrongFormat = FALSE; | 1219 bool bWrongFormat = false; |
1223 double dRet = MakeRegularDate(strValue, sFormat, &bWrongFormat); | 1220 double dRet = MakeRegularDate(strValue, sFormat, &bWrongFormat); |
1224 if (bWrongFormat || JS_PortIsNan(dRet)) { | 1221 if (bWrongFormat || JS_PortIsNan(dRet)) { |
1225 CFX_WideString swMsg; | 1222 CFX_WideString swMsg; |
1226 swMsg.Format(JSGetStringFromID(IDS_STRING_JSPARSEDATE).c_str(), | 1223 swMsg.Format(JSGetStringFromID(IDS_STRING_JSPARSEDATE).c_str(), |
1227 sFormat.c_str()); | 1224 sFormat.c_str()); |
1228 AlertIfPossible(pContext, swMsg.c_str()); | 1225 AlertIfPossible(pContext, swMsg.c_str()); |
1229 pEvent->Rc() = FALSE; | 1226 pEvent->Rc() = false; |
1230 return TRUE; | 1227 return true; |
1231 } | 1228 } |
1232 } | 1229 } |
1233 return TRUE; | 1230 return true; |
1234 } | 1231 } |
1235 | 1232 |
1236 FX_BOOL CJS_PublicMethods::AFDate_Format(IJS_Context* cc, | 1233 bool CJS_PublicMethods::AFDate_Format(IJS_Context* cc, |
1237 const std::vector<CJS_Value>& params, | 1234 const std::vector<CJS_Value>& params, |
1238 CJS_Value& vRet, | 1235 CJS_Value& vRet, |
1239 CFX_WideString& sError) { | 1236 CFX_WideString& sError) { |
1240 if (params.size() != 1) { | 1237 if (params.size() != 1) { |
1241 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); | 1238 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
1242 return FALSE; | 1239 return false; |
1243 } | 1240 } |
1244 | 1241 |
1245 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 1242 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
1246 int iIndex = params[0].ToInt(pRuntime); | 1243 int iIndex = params[0].ToInt(pRuntime); |
1247 const FX_WCHAR* cFormats[] = {L"m/d", | 1244 const FX_WCHAR* cFormats[] = {L"m/d", |
1248 L"m/d/yy", | 1245 L"m/d/yy", |
1249 L"mm/dd/yy", | 1246 L"mm/dd/yy", |
1250 L"mm/yy", | 1247 L"mm/yy", |
1251 L"d-mmm", | 1248 L"d-mmm", |
1252 L"d-mmm-yy", | 1249 L"d-mmm-yy", |
1253 L"dd-mmm-yy", | 1250 L"dd-mmm-yy", |
1254 L"yy-mm-dd", | 1251 L"yy-mm-dd", |
1255 L"mmm-yy", | 1252 L"mmm-yy", |
1256 L"mmmm-yy", | 1253 L"mmmm-yy", |
1257 L"mmm d, yyyy", | 1254 L"mmm d, yyyy", |
1258 L"mmmm d, yyyy", | 1255 L"mmmm d, yyyy", |
1259 L"m/d/yy h:MM tt", | 1256 L"m/d/yy h:MM tt", |
1260 L"m/d/yy HH:MM"}; | 1257 L"m/d/yy HH:MM"}; |
1261 | 1258 |
1262 if (iIndex < 0 || (static_cast<size_t>(iIndex) >= FX_ArraySize(cFormats))) | 1259 if (iIndex < 0 || (static_cast<size_t>(iIndex) >= FX_ArraySize(cFormats))) |
1263 iIndex = 0; | 1260 iIndex = 0; |
1264 | 1261 |
1265 std::vector<CJS_Value> newParams; | 1262 std::vector<CJS_Value> newParams; |
1266 newParams.push_back( | 1263 newParams.push_back( |
1267 CJS_Value(CJS_Runtime::FromContext(cc), cFormats[iIndex])); | 1264 CJS_Value(CJS_Runtime::FromContext(cc), cFormats[iIndex])); |
1268 return AFDate_FormatEx(cc, newParams, vRet, sError); | 1265 return AFDate_FormatEx(cc, newParams, vRet, sError); |
1269 } | 1266 } |
1270 | 1267 |
1271 // AFDate_KeystrokeEx(cFormat) | 1268 // AFDate_KeystrokeEx(cFormat) |
1272 FX_BOOL CJS_PublicMethods::AFDate_Keystroke( | 1269 bool CJS_PublicMethods::AFDate_Keystroke(IJS_Context* cc, |
1273 IJS_Context* cc, | 1270 const std::vector<CJS_Value>& params, |
1274 const std::vector<CJS_Value>& params, | 1271 CJS_Value& vRet, |
1275 CJS_Value& vRet, | 1272 CFX_WideString& sError) { |
1276 CFX_WideString& sError) { | |
1277 if (params.size() != 1) { | 1273 if (params.size() != 1) { |
1278 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); | 1274 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
1279 return FALSE; | 1275 return false; |
1280 } | 1276 } |
1281 | 1277 |
1282 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 1278 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
1283 int iIndex = params[0].ToInt(pRuntime); | 1279 int iIndex = params[0].ToInt(pRuntime); |
1284 const FX_WCHAR* cFormats[] = {L"m/d", | 1280 const FX_WCHAR* cFormats[] = {L"m/d", |
1285 L"m/d/yy", | 1281 L"m/d/yy", |
1286 L"mm/dd/yy", | 1282 L"mm/dd/yy", |
1287 L"mm/yy", | 1283 L"mm/yy", |
1288 L"d-mmm", | 1284 L"d-mmm", |
1289 L"d-mmm-yy", | 1285 L"d-mmm-yy", |
1290 L"dd-mmm-yy", | 1286 L"dd-mmm-yy", |
1291 L"yy-mm-dd", | 1287 L"yy-mm-dd", |
1292 L"mmm-yy", | 1288 L"mmm-yy", |
1293 L"mmmm-yy", | 1289 L"mmmm-yy", |
1294 L"mmm d, yyyy", | 1290 L"mmm d, yyyy", |
1295 L"mmmm d, yyyy", | 1291 L"mmmm d, yyyy", |
1296 L"m/d/yy h:MM tt", | 1292 L"m/d/yy h:MM tt", |
1297 L"m/d/yy HH:MM"}; | 1293 L"m/d/yy HH:MM"}; |
1298 | 1294 |
1299 if (iIndex < 0 || (static_cast<size_t>(iIndex) >= FX_ArraySize(cFormats))) | 1295 if (iIndex < 0 || (static_cast<size_t>(iIndex) >= FX_ArraySize(cFormats))) |
1300 iIndex = 0; | 1296 iIndex = 0; |
1301 | 1297 |
1302 std::vector<CJS_Value> newParams; | 1298 std::vector<CJS_Value> newParams; |
1303 newParams.push_back( | 1299 newParams.push_back( |
1304 CJS_Value(CJS_Runtime::FromContext(cc), cFormats[iIndex])); | 1300 CJS_Value(CJS_Runtime::FromContext(cc), cFormats[iIndex])); |
1305 return AFDate_KeystrokeEx(cc, newParams, vRet, sError); | 1301 return AFDate_KeystrokeEx(cc, newParams, vRet, sError); |
1306 } | 1302 } |
1307 | 1303 |
1308 // function AFTime_Format(ptf) | 1304 // function AFTime_Format(ptf) |
1309 FX_BOOL CJS_PublicMethods::AFTime_Format(IJS_Context* cc, | 1305 bool CJS_PublicMethods::AFTime_Format(IJS_Context* cc, |
1310 const std::vector<CJS_Value>& params, | 1306 const std::vector<CJS_Value>& params, |
1311 CJS_Value& vRet, | 1307 CJS_Value& vRet, |
1312 CFX_WideString& sError) { | 1308 CFX_WideString& sError) { |
1313 if (params.size() != 1) { | 1309 if (params.size() != 1) { |
1314 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); | 1310 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
1315 return FALSE; | 1311 return false; |
1316 } | 1312 } |
1317 | 1313 |
1318 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 1314 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
1319 int iIndex = params[0].ToInt(pRuntime); | 1315 int iIndex = params[0].ToInt(pRuntime); |
1320 const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss", | 1316 const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss", |
1321 L"h:MM:ss tt"}; | 1317 L"h:MM:ss tt"}; |
1322 | 1318 |
1323 if (iIndex < 0 || (static_cast<size_t>(iIndex) >= FX_ArraySize(cFormats))) | 1319 if (iIndex < 0 || (static_cast<size_t>(iIndex) >= FX_ArraySize(cFormats))) |
1324 iIndex = 0; | 1320 iIndex = 0; |
1325 | 1321 |
1326 std::vector<CJS_Value> newParams; | 1322 std::vector<CJS_Value> newParams; |
1327 newParams.push_back( | 1323 newParams.push_back( |
1328 CJS_Value(CJS_Runtime::FromContext(cc), cFormats[iIndex])); | 1324 CJS_Value(CJS_Runtime::FromContext(cc), cFormats[iIndex])); |
1329 return AFDate_FormatEx(cc, newParams, vRet, sError); | 1325 return AFDate_FormatEx(cc, newParams, vRet, sError); |
1330 } | 1326 } |
1331 | 1327 |
1332 FX_BOOL CJS_PublicMethods::AFTime_Keystroke( | 1328 bool CJS_PublicMethods::AFTime_Keystroke(IJS_Context* cc, |
1333 IJS_Context* cc, | 1329 const std::vector<CJS_Value>& params, |
1334 const std::vector<CJS_Value>& params, | 1330 CJS_Value& vRet, |
1335 CJS_Value& vRet, | 1331 CFX_WideString& sError) { |
1336 CFX_WideString& sError) { | |
1337 if (params.size() != 1) { | 1332 if (params.size() != 1) { |
1338 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); | 1333 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
1339 return FALSE; | 1334 return false; |
1340 } | 1335 } |
1341 | 1336 |
1342 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 1337 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
1343 int iIndex = params[0].ToInt(pRuntime); | 1338 int iIndex = params[0].ToInt(pRuntime); |
1344 const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss", | 1339 const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss", |
1345 L"h:MM:ss tt"}; | 1340 L"h:MM:ss tt"}; |
1346 | 1341 |
1347 if (iIndex < 0 || (static_cast<size_t>(iIndex) >= FX_ArraySize(cFormats))) | 1342 if (iIndex < 0 || (static_cast<size_t>(iIndex) >= FX_ArraySize(cFormats))) |
1348 iIndex = 0; | 1343 iIndex = 0; |
1349 | 1344 |
1350 std::vector<CJS_Value> newParams; | 1345 std::vector<CJS_Value> newParams; |
1351 newParams.push_back( | 1346 newParams.push_back( |
1352 CJS_Value(CJS_Runtime::FromContext(cc), cFormats[iIndex])); | 1347 CJS_Value(CJS_Runtime::FromContext(cc), cFormats[iIndex])); |
1353 return AFDate_KeystrokeEx(cc, newParams, vRet, sError); | 1348 return AFDate_KeystrokeEx(cc, newParams, vRet, sError); |
1354 } | 1349 } |
1355 | 1350 |
1356 FX_BOOL CJS_PublicMethods::AFTime_FormatEx(IJS_Context* cc, | 1351 bool CJS_PublicMethods::AFTime_FormatEx(IJS_Context* cc, |
| 1352 const std::vector<CJS_Value>& params, |
| 1353 CJS_Value& vRet, |
| 1354 CFX_WideString& sError) { |
| 1355 return AFDate_FormatEx(cc, params, vRet, sError); |
| 1356 } |
| 1357 |
| 1358 bool CJS_PublicMethods::AFTime_KeystrokeEx(IJS_Context* cc, |
1357 const std::vector<CJS_Value>& params, | 1359 const std::vector<CJS_Value>& params, |
1358 CJS_Value& vRet, | 1360 CJS_Value& vRet, |
1359 CFX_WideString& sError) { | 1361 CFX_WideString& sError) { |
1360 return AFDate_FormatEx(cc, params, vRet, sError); | |
1361 } | |
1362 | |
1363 FX_BOOL CJS_PublicMethods::AFTime_KeystrokeEx( | |
1364 IJS_Context* cc, | |
1365 const std::vector<CJS_Value>& params, | |
1366 CJS_Value& vRet, | |
1367 CFX_WideString& sError) { | |
1368 return AFDate_KeystrokeEx(cc, params, vRet, sError); | 1362 return AFDate_KeystrokeEx(cc, params, vRet, sError); |
1369 } | 1363 } |
1370 | 1364 |
1371 // function AFSpecial_Format(psf) | 1365 // function AFSpecial_Format(psf) |
1372 FX_BOOL CJS_PublicMethods::AFSpecial_Format( | 1366 bool CJS_PublicMethods::AFSpecial_Format(IJS_Context* cc, |
1373 IJS_Context* cc, | 1367 const std::vector<CJS_Value>& params, |
1374 const std::vector<CJS_Value>& params, | 1368 CJS_Value& vRet, |
1375 CJS_Value& vRet, | 1369 CFX_WideString& sError) { |
1376 CFX_WideString& sError) { | |
1377 if (params.size() != 1) { | 1370 if (params.size() != 1) { |
1378 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); | 1371 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
1379 return FALSE; | 1372 return false; |
1380 } | 1373 } |
1381 | 1374 |
1382 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 1375 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
1383 CJS_EventHandler* pEvent = pContext->GetEventHandler(); | 1376 CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
1384 if (!pEvent->m_pValue) | 1377 if (!pEvent->m_pValue) |
1385 return FALSE; | 1378 return false; |
1386 | 1379 |
1387 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 1380 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
1388 CFX_WideString wsSource = pEvent->Value(); | 1381 CFX_WideString wsSource = pEvent->Value(); |
1389 CFX_WideString wsFormat; | 1382 CFX_WideString wsFormat; |
1390 switch (params[0].ToInt(pRuntime)) { | 1383 switch (params[0].ToInt(pRuntime)) { |
1391 case 0: | 1384 case 0: |
1392 wsFormat = L"99999"; | 1385 wsFormat = L"99999"; |
1393 break; | 1386 break; |
1394 case 1: | 1387 case 1: |
1395 wsFormat = L"99999-9999"; | 1388 wsFormat = L"99999-9999"; |
1396 break; | 1389 break; |
1397 case 2: | 1390 case 2: |
1398 if (util::printx(L"9999999999", wsSource).GetLength() >= 10) | 1391 if (util::printx(L"9999999999", wsSource).GetLength() >= 10) |
1399 wsFormat = L"(999) 999-9999"; | 1392 wsFormat = L"(999) 999-9999"; |
1400 else | 1393 else |
1401 wsFormat = L"999-9999"; | 1394 wsFormat = L"999-9999"; |
1402 break; | 1395 break; |
1403 case 3: | 1396 case 3: |
1404 wsFormat = L"999-99-9999"; | 1397 wsFormat = L"999-99-9999"; |
1405 break; | 1398 break; |
1406 } | 1399 } |
1407 | 1400 |
1408 pEvent->Value() = util::printx(wsFormat, wsSource); | 1401 pEvent->Value() = util::printx(wsFormat, wsSource); |
1409 return TRUE; | 1402 return true; |
1410 } | 1403 } |
1411 | 1404 |
1412 // function AFSpecial_KeystrokeEx(mask) | 1405 // function AFSpecial_KeystrokeEx(mask) |
1413 FX_BOOL CJS_PublicMethods::AFSpecial_KeystrokeEx( | 1406 bool CJS_PublicMethods::AFSpecial_KeystrokeEx( |
1414 IJS_Context* cc, | 1407 IJS_Context* cc, |
1415 const std::vector<CJS_Value>& params, | 1408 const std::vector<CJS_Value>& params, |
1416 CJS_Value& vRet, | 1409 CJS_Value& vRet, |
1417 CFX_WideString& sError) { | 1410 CFX_WideString& sError) { |
1418 CJS_Context* pContext = (CJS_Context*)cc; | 1411 CJS_Context* pContext = (CJS_Context*)cc; |
1419 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 1412 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
1420 CJS_EventHandler* pEvent = pContext->GetEventHandler(); | 1413 CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
1421 | 1414 |
1422 if (params.size() < 1) { | 1415 if (params.size() < 1) { |
1423 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); | 1416 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
1424 return FALSE; | 1417 return false; |
1425 } | 1418 } |
1426 | 1419 |
1427 if (!pEvent->m_pValue) | 1420 if (!pEvent->m_pValue) |
1428 return FALSE; | 1421 return false; |
1429 | 1422 |
1430 CFX_WideString& valEvent = pEvent->Value(); | 1423 CFX_WideString& valEvent = pEvent->Value(); |
1431 CFX_WideString wstrMask = params[0].ToCFXWideString(pRuntime); | 1424 CFX_WideString wstrMask = params[0].ToCFXWideString(pRuntime); |
1432 if (wstrMask.IsEmpty()) | 1425 if (wstrMask.IsEmpty()) |
1433 return TRUE; | 1426 return true; |
1434 | 1427 |
1435 if (pEvent->WillCommit()) { | 1428 if (pEvent->WillCommit()) { |
1436 if (valEvent.IsEmpty()) | 1429 if (valEvent.IsEmpty()) |
1437 return TRUE; | 1430 return true; |
1438 | 1431 |
1439 FX_STRSIZE iIndexMask = 0; | 1432 FX_STRSIZE iIndexMask = 0; |
1440 for (; iIndexMask < valEvent.GetLength(); ++iIndexMask) { | 1433 for (; iIndexMask < valEvent.GetLength(); ++iIndexMask) { |
1441 if (!maskSatisfied(valEvent[iIndexMask], wstrMask[iIndexMask])) | 1434 if (!maskSatisfied(valEvent[iIndexMask], wstrMask[iIndexMask])) |
1442 break; | 1435 break; |
1443 } | 1436 } |
1444 | 1437 |
1445 if (iIndexMask != wstrMask.GetLength() || | 1438 if (iIndexMask != wstrMask.GetLength() || |
1446 (iIndexMask != valEvent.GetLength() && wstrMask.GetLength() != 0)) { | 1439 (iIndexMask != valEvent.GetLength() && wstrMask.GetLength() != 0)) { |
1447 AlertIfPossible( | 1440 AlertIfPossible( |
1448 pContext, JSGetStringFromID(IDS_STRING_JSAFNUMBER_KEYSTROKE).c_str()); | 1441 pContext, JSGetStringFromID(IDS_STRING_JSAFNUMBER_KEYSTROKE).c_str()); |
1449 pEvent->Rc() = FALSE; | 1442 pEvent->Rc() = false; |
1450 } | 1443 } |
1451 return TRUE; | 1444 return true; |
1452 } | 1445 } |
1453 | 1446 |
1454 CFX_WideString& wideChange = pEvent->Change(); | 1447 CFX_WideString& wideChange = pEvent->Change(); |
1455 if (wideChange.IsEmpty()) | 1448 if (wideChange.IsEmpty()) |
1456 return TRUE; | 1449 return true; |
1457 | 1450 |
1458 CFX_WideString wChange = wideChange; | 1451 CFX_WideString wChange = wideChange; |
1459 FX_STRSIZE iIndexMask = pEvent->SelStart(); | 1452 FX_STRSIZE iIndexMask = pEvent->SelStart(); |
1460 FX_STRSIZE combined_len = valEvent.GetLength() + wChange.GetLength() + | 1453 FX_STRSIZE combined_len = valEvent.GetLength() + wChange.GetLength() + |
1461 pEvent->SelStart() - pEvent->SelEnd(); | 1454 pEvent->SelStart() - pEvent->SelEnd(); |
1462 if (combined_len > wstrMask.GetLength()) { | 1455 if (combined_len > wstrMask.GetLength()) { |
1463 AlertIfPossible(pContext, | 1456 AlertIfPossible(pContext, |
1464 JSGetStringFromID(IDS_STRING_JSPARAM_TOOLONG).c_str()); | 1457 JSGetStringFromID(IDS_STRING_JSPARAM_TOOLONG).c_str()); |
1465 pEvent->Rc() = FALSE; | 1458 pEvent->Rc() = false; |
1466 return TRUE; | 1459 return true; |
1467 } | 1460 } |
1468 | 1461 |
1469 if (iIndexMask >= wstrMask.GetLength() && !wChange.IsEmpty()) { | 1462 if (iIndexMask >= wstrMask.GetLength() && !wChange.IsEmpty()) { |
1470 AlertIfPossible(pContext, | 1463 AlertIfPossible(pContext, |
1471 JSGetStringFromID(IDS_STRING_JSPARAM_TOOLONG).c_str()); | 1464 JSGetStringFromID(IDS_STRING_JSPARAM_TOOLONG).c_str()); |
1472 pEvent->Rc() = FALSE; | 1465 pEvent->Rc() = false; |
1473 return TRUE; | 1466 return true; |
1474 } | 1467 } |
1475 | 1468 |
1476 for (FX_STRSIZE i = 0; i < wChange.GetLength(); ++i) { | 1469 for (FX_STRSIZE i = 0; i < wChange.GetLength(); ++i) { |
1477 if (iIndexMask >= wstrMask.GetLength()) { | 1470 if (iIndexMask >= wstrMask.GetLength()) { |
1478 AlertIfPossible(pContext, | 1471 AlertIfPossible(pContext, |
1479 JSGetStringFromID(IDS_STRING_JSPARAM_TOOLONG).c_str()); | 1472 JSGetStringFromID(IDS_STRING_JSPARAM_TOOLONG).c_str()); |
1480 pEvent->Rc() = FALSE; | 1473 pEvent->Rc() = false; |
1481 return TRUE; | 1474 return true; |
1482 } | 1475 } |
1483 FX_WCHAR wMask = wstrMask[iIndexMask]; | 1476 FX_WCHAR wMask = wstrMask[iIndexMask]; |
1484 if (!isReservedMaskChar(wMask)) | 1477 if (!isReservedMaskChar(wMask)) |
1485 wChange.SetAt(i, wMask); | 1478 wChange.SetAt(i, wMask); |
1486 | 1479 |
1487 if (!maskSatisfied(wChange[i], wMask)) { | 1480 if (!maskSatisfied(wChange[i], wMask)) { |
1488 pEvent->Rc() = FALSE; | 1481 pEvent->Rc() = false; |
1489 return TRUE; | 1482 return true; |
1490 } | 1483 } |
1491 iIndexMask++; | 1484 iIndexMask++; |
1492 } | 1485 } |
1493 wideChange = wChange; | 1486 wideChange = wChange; |
1494 return TRUE; | 1487 return true; |
1495 } | 1488 } |
1496 | 1489 |
1497 // function AFSpecial_Keystroke(psf) | 1490 // function AFSpecial_Keystroke(psf) |
1498 FX_BOOL CJS_PublicMethods::AFSpecial_Keystroke( | 1491 bool CJS_PublicMethods::AFSpecial_Keystroke( |
1499 IJS_Context* cc, | 1492 IJS_Context* cc, |
1500 const std::vector<CJS_Value>& params, | 1493 const std::vector<CJS_Value>& params, |
1501 CJS_Value& vRet, | 1494 CJS_Value& vRet, |
1502 CFX_WideString& sError) { | 1495 CFX_WideString& sError) { |
1503 if (params.size() != 1) { | 1496 if (params.size() != 1) { |
1504 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); | 1497 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
1505 return FALSE; | 1498 return false; |
1506 } | 1499 } |
1507 | 1500 |
1508 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 1501 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
1509 CJS_EventHandler* pEvent = pContext->GetEventHandler(); | 1502 CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
1510 if (!pEvent->m_pValue) | 1503 if (!pEvent->m_pValue) |
1511 return FALSE; | 1504 return false; |
1512 | 1505 |
1513 const char* cFormat = ""; | 1506 const char* cFormat = ""; |
1514 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 1507 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
1515 switch (params[0].ToInt(pRuntime)) { | 1508 switch (params[0].ToInt(pRuntime)) { |
1516 case 0: | 1509 case 0: |
1517 cFormat = "99999"; | 1510 cFormat = "99999"; |
1518 break; | 1511 break; |
1519 case 1: | 1512 case 1: |
1520 cFormat = "999999999"; | 1513 cFormat = "999999999"; |
1521 break; | 1514 break; |
1522 case 2: | 1515 case 2: |
1523 if (pEvent->Value().GetLength() + pEvent->Change().GetLength() > 7) | 1516 if (pEvent->Value().GetLength() + pEvent->Change().GetLength() > 7) |
1524 cFormat = "9999999999"; | 1517 cFormat = "9999999999"; |
1525 else | 1518 else |
1526 cFormat = "9999999"; | 1519 cFormat = "9999999"; |
1527 break; | 1520 break; |
1528 case 3: | 1521 case 3: |
1529 cFormat = "999999999"; | 1522 cFormat = "999999999"; |
1530 break; | 1523 break; |
1531 } | 1524 } |
1532 | 1525 |
1533 std::vector<CJS_Value> params2; | 1526 std::vector<CJS_Value> params2; |
1534 params2.push_back(CJS_Value(CJS_Runtime::FromContext(cc), cFormat)); | 1527 params2.push_back(CJS_Value(CJS_Runtime::FromContext(cc), cFormat)); |
1535 return AFSpecial_KeystrokeEx(cc, params2, vRet, sError); | 1528 return AFSpecial_KeystrokeEx(cc, params2, vRet, sError); |
1536 } | 1529 } |
1537 | 1530 |
1538 FX_BOOL CJS_PublicMethods::AFMergeChange(IJS_Context* cc, | 1531 bool CJS_PublicMethods::AFMergeChange(IJS_Context* cc, |
1539 const std::vector<CJS_Value>& params, | 1532 const std::vector<CJS_Value>& params, |
1540 CJS_Value& vRet, | 1533 CJS_Value& vRet, |
1541 CFX_WideString& sError) { | 1534 CFX_WideString& sError) { |
1542 if (params.size() != 1) { | 1535 if (params.size() != 1) { |
1543 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); | 1536 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
1544 return FALSE; | 1537 return false; |
1545 } | 1538 } |
1546 | 1539 |
1547 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 1540 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
1548 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 1541 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
1549 CJS_EventHandler* pEventHandler = pContext->GetEventHandler(); | 1542 CJS_EventHandler* pEventHandler = pContext->GetEventHandler(); |
1550 | 1543 |
1551 CFX_WideString swValue; | 1544 CFX_WideString swValue; |
1552 if (pEventHandler->m_pValue) | 1545 if (pEventHandler->m_pValue) |
1553 swValue = pEventHandler->Value(); | 1546 swValue = pEventHandler->Value(); |
1554 | 1547 |
1555 if (pEventHandler->WillCommit()) { | 1548 if (pEventHandler->WillCommit()) { |
1556 vRet = CJS_Value(pRuntime, swValue.c_str()); | 1549 vRet = CJS_Value(pRuntime, swValue.c_str()); |
1557 return TRUE; | 1550 return true; |
1558 } | 1551 } |
1559 | 1552 |
1560 CFX_WideString prefix, postfix; | 1553 CFX_WideString prefix, postfix; |
1561 | 1554 |
1562 if (pEventHandler->SelStart() >= 0) | 1555 if (pEventHandler->SelStart() >= 0) |
1563 prefix = swValue.Mid(0, pEventHandler->SelStart()); | 1556 prefix = swValue.Mid(0, pEventHandler->SelStart()); |
1564 else | 1557 else |
1565 prefix = L""; | 1558 prefix = L""; |
1566 | 1559 |
1567 if (pEventHandler->SelEnd() >= 0 && | 1560 if (pEventHandler->SelEnd() >= 0 && |
1568 pEventHandler->SelEnd() <= swValue.GetLength()) | 1561 pEventHandler->SelEnd() <= swValue.GetLength()) |
1569 postfix = swValue.Mid(pEventHandler->SelEnd(), | 1562 postfix = swValue.Mid(pEventHandler->SelEnd(), |
1570 swValue.GetLength() - pEventHandler->SelEnd()); | 1563 swValue.GetLength() - pEventHandler->SelEnd()); |
1571 else | 1564 else |
1572 postfix = L""; | 1565 postfix = L""; |
1573 | 1566 |
1574 vRet = | 1567 vRet = |
1575 CJS_Value(pRuntime, (prefix + pEventHandler->Change() + postfix).c_str()); | 1568 CJS_Value(pRuntime, (prefix + pEventHandler->Change() + postfix).c_str()); |
1576 return TRUE; | 1569 return true; |
1577 } | 1570 } |
1578 | 1571 |
1579 FX_BOOL CJS_PublicMethods::AFParseDateEx(IJS_Context* cc, | 1572 bool CJS_PublicMethods::AFParseDateEx(IJS_Context* cc, |
1580 const std::vector<CJS_Value>& params, | 1573 const std::vector<CJS_Value>& params, |
1581 CJS_Value& vRet, | 1574 CJS_Value& vRet, |
1582 CFX_WideString& sError) { | 1575 CFX_WideString& sError) { |
1583 if (params.size() != 2) { | 1576 if (params.size() != 2) { |
1584 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); | 1577 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
1585 return FALSE; | 1578 return false; |
1586 } | 1579 } |
1587 | 1580 |
1588 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 1581 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
1589 CFX_WideString sValue = params[0].ToCFXWideString(pRuntime); | 1582 CFX_WideString sValue = params[0].ToCFXWideString(pRuntime); |
1590 CFX_WideString sFormat = params[1].ToCFXWideString(pRuntime); | 1583 CFX_WideString sFormat = params[1].ToCFXWideString(pRuntime); |
1591 | 1584 |
1592 double dDate = MakeRegularDate(sValue, sFormat, nullptr); | 1585 double dDate = MakeRegularDate(sValue, sFormat, nullptr); |
1593 | 1586 |
1594 if (JS_PortIsNan(dDate)) { | 1587 if (JS_PortIsNan(dDate)) { |
1595 CFX_WideString swMsg; | 1588 CFX_WideString swMsg; |
1596 swMsg.Format(JSGetStringFromID(IDS_STRING_JSPARSEDATE).c_str(), | 1589 swMsg.Format(JSGetStringFromID(IDS_STRING_JSPARSEDATE).c_str(), |
1597 sFormat.c_str()); | 1590 sFormat.c_str()); |
1598 AlertIfPossible((CJS_Context*)cc, swMsg.c_str()); | 1591 AlertIfPossible((CJS_Context*)cc, swMsg.c_str()); |
1599 return FALSE; | 1592 return false; |
1600 } | 1593 } |
1601 | 1594 |
1602 vRet = CJS_Value(pRuntime, dDate); | 1595 vRet = CJS_Value(pRuntime, dDate); |
1603 return TRUE; | 1596 return true; |
1604 } | 1597 } |
1605 | 1598 |
1606 FX_BOOL CJS_PublicMethods::AFSimple(IJS_Context* cc, | 1599 bool CJS_PublicMethods::AFSimple(IJS_Context* cc, |
1607 const std::vector<CJS_Value>& params, | 1600 const std::vector<CJS_Value>& params, |
1608 CJS_Value& vRet, | 1601 CJS_Value& vRet, |
1609 CFX_WideString& sError) { | 1602 CFX_WideString& sError) { |
1610 if (params.size() != 3) { | 1603 if (params.size() != 3) { |
1611 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); | 1604 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
1612 return FALSE; | 1605 return false; |
1613 } | 1606 } |
1614 | 1607 |
1615 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 1608 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
1616 vRet = CJS_Value(pRuntime, static_cast<double>(AF_Simple( | 1609 vRet = CJS_Value(pRuntime, static_cast<double>(AF_Simple( |
1617 params[0].ToCFXWideString(pRuntime).c_str(), | 1610 params[0].ToCFXWideString(pRuntime).c_str(), |
1618 params[1].ToDouble(pRuntime), | 1611 params[1].ToDouble(pRuntime), |
1619 params[2].ToDouble(pRuntime)))); | 1612 params[2].ToDouble(pRuntime)))); |
1620 | 1613 |
1621 return TRUE; | 1614 return true; |
1622 } | 1615 } |
1623 | 1616 |
1624 FX_BOOL CJS_PublicMethods::AFMakeNumber(IJS_Context* cc, | 1617 bool CJS_PublicMethods::AFMakeNumber(IJS_Context* cc, |
1625 const std::vector<CJS_Value>& params, | 1618 const std::vector<CJS_Value>& params, |
1626 CJS_Value& vRet, | 1619 CJS_Value& vRet, |
1627 CFX_WideString& sError) { | 1620 CFX_WideString& sError) { |
1628 if (params.size() != 1) { | 1621 if (params.size() != 1) { |
1629 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); | 1622 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
1630 return FALSE; | 1623 return false; |
1631 } | 1624 } |
1632 | 1625 |
1633 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 1626 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
1634 CFX_WideString ws = params[0].ToCFXWideString(pRuntime); | 1627 CFX_WideString ws = params[0].ToCFXWideString(pRuntime); |
1635 ws.Replace(L",", L"."); | 1628 ws.Replace(L",", L"."); |
1636 vRet = CJS_Value(pRuntime, ws.c_str()); | 1629 vRet = CJS_Value(pRuntime, ws.c_str()); |
1637 vRet.MaybeCoerceToNumber(pRuntime); | 1630 vRet.MaybeCoerceToNumber(pRuntime); |
1638 if (vRet.GetType() != CJS_Value::VT_number) | 1631 if (vRet.GetType() != CJS_Value::VT_number) |
1639 vRet = CJS_Value(pRuntime, 0); | 1632 vRet = CJS_Value(pRuntime, 0); |
1640 return TRUE; | 1633 return true; |
1641 } | 1634 } |
1642 | 1635 |
1643 FX_BOOL CJS_PublicMethods::AFSimple_Calculate( | 1636 bool CJS_PublicMethods::AFSimple_Calculate(IJS_Context* cc, |
1644 IJS_Context* cc, | 1637 const std::vector<CJS_Value>& params, |
1645 const std::vector<CJS_Value>& params, | 1638 CJS_Value& vRet, |
1646 CJS_Value& vRet, | 1639 CFX_WideString& sError) { |
1647 CFX_WideString& sError) { | |
1648 if (params.size() != 2) { | 1640 if (params.size() != 2) { |
1649 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); | 1641 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
1650 return FALSE; | 1642 return false; |
1651 } | 1643 } |
1652 | 1644 |
1653 CJS_Value params1 = params[1]; | 1645 CJS_Value params1 = params[1]; |
1654 if (!params1.IsArrayObject() && params1.GetType() != CJS_Value::VT_string) { | 1646 if (!params1.IsArrayObject() && params1.GetType() != CJS_Value::VT_string) { |
1655 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); | 1647 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
1656 return FALSE; | 1648 return false; |
1657 } | 1649 } |
1658 | 1650 |
1659 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 1651 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
1660 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 1652 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
1661 CPDFSDK_InterForm* pReaderInterForm = | 1653 CPDFSDK_InterForm* pReaderInterForm = |
1662 pContext->GetFormFillEnv()->GetInterForm(); | 1654 pContext->GetFormFillEnv()->GetInterForm(); |
1663 CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm(); | 1655 CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm(); |
1664 | 1656 |
1665 CFX_WideString sFunction = params[0].ToCFXWideString(pRuntime); | 1657 CFX_WideString sFunction = params[0].ToCFXWideString(pRuntime); |
1666 double dValue = wcscmp(sFunction.c_str(), L"PRD") == 0 ? 1.0 : 0.0; | 1658 double dValue = wcscmp(sFunction.c_str(), L"PRD") == 0 ? 1.0 : 0.0; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1727 | 1719 |
1728 if (wcscmp(sFunction.c_str(), L"AVG") == 0 && nFieldsCount > 0) | 1720 if (wcscmp(sFunction.c_str(), L"AVG") == 0 && nFieldsCount > 0) |
1729 dValue /= nFieldsCount; | 1721 dValue /= nFieldsCount; |
1730 | 1722 |
1731 dValue = (double)floor(dValue * FXSYS_pow((double)10, (double)6) + 0.49) / | 1723 dValue = (double)floor(dValue * FXSYS_pow((double)10, (double)6) + 0.49) / |
1732 FXSYS_pow((double)10, (double)6); | 1724 FXSYS_pow((double)10, (double)6); |
1733 CJS_Value jsValue(pRuntime, dValue); | 1725 CJS_Value jsValue(pRuntime, dValue); |
1734 if (pContext->GetEventHandler()->m_pValue) | 1726 if (pContext->GetEventHandler()->m_pValue) |
1735 pContext->GetEventHandler()->Value() = jsValue.ToCFXWideString(pRuntime); | 1727 pContext->GetEventHandler()->Value() = jsValue.ToCFXWideString(pRuntime); |
1736 | 1728 |
1737 return TRUE; | 1729 return true; |
1738 } | 1730 } |
1739 | 1731 |
1740 /* This function validates the current event to ensure that its value is | 1732 /* This function validates the current event to ensure that its value is |
1741 ** within the specified range. */ | 1733 ** within the specified range. */ |
1742 | 1734 |
1743 FX_BOOL CJS_PublicMethods::AFRange_Validate( | 1735 bool CJS_PublicMethods::AFRange_Validate(IJS_Context* cc, |
1744 IJS_Context* cc, | 1736 const std::vector<CJS_Value>& params, |
1745 const std::vector<CJS_Value>& params, | 1737 CJS_Value& vRet, |
1746 CJS_Value& vRet, | 1738 CFX_WideString& sError) { |
1747 CFX_WideString& sError) { | |
1748 if (params.size() != 4) { | 1739 if (params.size() != 4) { |
1749 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); | 1740 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
1750 return FALSE; | 1741 return false; |
1751 } | 1742 } |
1752 CJS_Context* pContext = static_cast<CJS_Context*>(cc); | 1743 CJS_Context* pContext = static_cast<CJS_Context*>(cc); |
1753 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 1744 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
1754 CJS_EventHandler* pEvent = pContext->GetEventHandler(); | 1745 CJS_EventHandler* pEvent = pContext->GetEventHandler(); |
1755 if (!pEvent->m_pValue) | 1746 if (!pEvent->m_pValue) |
1756 return FALSE; | 1747 return false; |
1757 | 1748 |
1758 if (pEvent->Value().IsEmpty()) | 1749 if (pEvent->Value().IsEmpty()) |
1759 return TRUE; | 1750 return true; |
1760 | 1751 |
1761 double dEentValue = | 1752 double dEentValue = |
1762 atof(CFX_ByteString::FromUnicode(pEvent->Value()).c_str()); | 1753 atof(CFX_ByteString::FromUnicode(pEvent->Value()).c_str()); |
1763 FX_BOOL bGreaterThan = params[0].ToBool(pRuntime); | 1754 bool bGreaterThan = params[0].ToBool(pRuntime); |
1764 double dGreaterThan = params[1].ToDouble(pRuntime); | 1755 double dGreaterThan = params[1].ToDouble(pRuntime); |
1765 FX_BOOL bLessThan = params[2].ToBool(pRuntime); | 1756 bool bLessThan = params[2].ToBool(pRuntime); |
1766 double dLessThan = params[3].ToDouble(pRuntime); | 1757 double dLessThan = params[3].ToDouble(pRuntime); |
1767 CFX_WideString swMsg; | 1758 CFX_WideString swMsg; |
1768 | 1759 |
1769 if (bGreaterThan && bLessThan) { | 1760 if (bGreaterThan && bLessThan) { |
1770 if (dEentValue < dGreaterThan || dEentValue > dLessThan) | 1761 if (dEentValue < dGreaterThan || dEentValue > dLessThan) |
1771 swMsg.Format(JSGetStringFromID(IDS_STRING_JSRANGE1).c_str(), | 1762 swMsg.Format(JSGetStringFromID(IDS_STRING_JSRANGE1).c_str(), |
1772 params[1].ToCFXWideString(pRuntime).c_str(), | 1763 params[1].ToCFXWideString(pRuntime).c_str(), |
1773 params[3].ToCFXWideString(pRuntime).c_str()); | 1764 params[3].ToCFXWideString(pRuntime).c_str()); |
1774 } else if (bGreaterThan) { | 1765 } else if (bGreaterThan) { |
1775 if (dEentValue < dGreaterThan) | 1766 if (dEentValue < dGreaterThan) |
1776 swMsg.Format(JSGetStringFromID(IDS_STRING_JSRANGE2).c_str(), | 1767 swMsg.Format(JSGetStringFromID(IDS_STRING_JSRANGE2).c_str(), |
1777 params[1].ToCFXWideString(pRuntime).c_str()); | 1768 params[1].ToCFXWideString(pRuntime).c_str()); |
1778 } else if (bLessThan) { | 1769 } else if (bLessThan) { |
1779 if (dEentValue > dLessThan) | 1770 if (dEentValue > dLessThan) |
1780 swMsg.Format(JSGetStringFromID(IDS_STRING_JSRANGE3).c_str(), | 1771 swMsg.Format(JSGetStringFromID(IDS_STRING_JSRANGE3).c_str(), |
1781 params[3].ToCFXWideString(pRuntime).c_str()); | 1772 params[3].ToCFXWideString(pRuntime).c_str()); |
1782 } | 1773 } |
1783 | 1774 |
1784 if (!swMsg.IsEmpty()) { | 1775 if (!swMsg.IsEmpty()) { |
1785 AlertIfPossible(pContext, swMsg.c_str()); | 1776 AlertIfPossible(pContext, swMsg.c_str()); |
1786 pEvent->Rc() = FALSE; | 1777 pEvent->Rc() = false; |
1787 } | 1778 } |
1788 return TRUE; | 1779 return true; |
1789 } | 1780 } |
1790 | 1781 |
1791 FX_BOOL CJS_PublicMethods::AFExtractNums(IJS_Context* cc, | 1782 bool CJS_PublicMethods::AFExtractNums(IJS_Context* cc, |
1792 const std::vector<CJS_Value>& params, | 1783 const std::vector<CJS_Value>& params, |
1793 CJS_Value& vRet, | 1784 CJS_Value& vRet, |
1794 CFX_WideString& sError) { | 1785 CFX_WideString& sError) { |
1795 if (params.size() != 1) { | 1786 if (params.size() != 1) { |
1796 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); | 1787 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR); |
1797 return FALSE; | 1788 return false; |
1798 } | 1789 } |
1799 | 1790 |
1800 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); | 1791 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc); |
1801 CFX_WideString str = params[0].ToCFXWideString(pRuntime); | 1792 CFX_WideString str = params[0].ToCFXWideString(pRuntime); |
1802 CFX_WideString sPart; | 1793 CFX_WideString sPart; |
1803 CJS_Array nums; | 1794 CJS_Array nums; |
1804 | 1795 |
1805 if (str.GetAt(0) == L'.' || str.GetAt(0) == L',') | 1796 if (str.GetAt(0) == L'.' || str.GetAt(0) == L',') |
1806 str = L"0" + str; | 1797 str = L"0" + str; |
1807 | 1798 |
(...skipping 13 matching lines...) Expand all Loading... |
1821 | 1812 |
1822 if (sPart.GetLength() > 0) { | 1813 if (sPart.GetLength() > 0) { |
1823 nums.SetElement(pRuntime, nIndex, CJS_Value(pRuntime, sPart.c_str())); | 1814 nums.SetElement(pRuntime, nIndex, CJS_Value(pRuntime, sPart.c_str())); |
1824 } | 1815 } |
1825 | 1816 |
1826 if (nums.GetLength(pRuntime) > 0) | 1817 if (nums.GetLength(pRuntime) > 0) |
1827 vRet = CJS_Value(pRuntime, nums); | 1818 vRet = CJS_Value(pRuntime, nums); |
1828 else | 1819 else |
1829 vRet.SetNull(pRuntime); | 1820 vRet.SetNull(pRuntime); |
1830 | 1821 |
1831 return TRUE; | 1822 return true; |
1832 } | 1823 } |
OLD | NEW |