1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
7 #include "../../include/javascript/JavaScript.h"
8 #include "../../include/javascript/IJavaScript.h"
9 #include "../../include/javascript/JS_Define.h"
10 #include "../../include/javascript/JS_Object.h"
11 #include "../../include/javascript/JS_Value.h"
12 #include "../../include/javascript/PublicMethods.h"
13 #include "../../include/javascript/JS_EventHandler.h"
14 #include "../../include/javascript/resource.h"
15 #include "../../include/javascript/JS_Context.h"
16 #include "../../include/javascript/JS_Value.h"
17 #include "../../include/javascript/util.h"
18 #include "../../include/javascript/Field.h"
19 #include "../../include/javascript/color.h"
20 #include "../../include/javascript/JS_Runtime.h"
22 static v8::Isolate* GetIsolate(IFXJS_Context* cc)
24 CJS_Context* pContext = (CJS_Context *)cc;
25 ASSERT(pContext != NULL);
27 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
28 ASSERT(pRuntime != NULL);
30 return pRuntime->GetIsolate();
34 /* -------------------------------- CJS_PublicMethods -------------------------------- */
36 #define DOUBLE_CORRECT 0.000000000000001
38 BEGIN_JS_STATIC_GLOBAL_FUN(CJS_PublicMethods)
39 JS_STATIC_GLOBAL_FUN_ENTRY(AFNumber_Format,6)
40 JS_STATIC_GLOBAL_FUN_ENTRY(AFNumber_Keystroke,6)
41 JS_STATIC_GLOBAL_FUN_ENTRY(AFPercent_Format,2)
42 JS_STATIC_GLOBAL_FUN_ENTRY(AFPercent_Keystroke,2)
43 JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_FormatEx,1)
44 JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_KeystrokeEx,1)
45 JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_Format,1)
46 JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_Keystroke,1)
47 JS_STATIC_GLOBAL_FUN_ENTRY(AFTime_FormatEx,1)
48 JS_STATIC_GLOBAL_FUN_ENTRY(AFTime_KeystrokeEx,1)
49 JS_STATIC_GLOBAL_FUN_ENTRY(AFTime_Format,1)
50 JS_STATIC_GLOBAL_FUN_ENTRY(AFTime_Keystroke,1)
51 JS_STATIC_GLOBAL_FUN_ENTRY(AFSpecial_Format,1)
52 JS_STATIC_GLOBAL_FUN_ENTRY(AFSpecial_Keystroke,1)
53 JS_STATIC_GLOBAL_FUN_ENTRY(AFSpecial_KeystrokeEx,1)
54 JS_STATIC_GLOBAL_FUN_ENTRY(AFSimple,3)
55 JS_STATIC_GLOBAL_FUN_ENTRY(AFMakeNumber,1)
56 JS_STATIC_GLOBAL_FUN_ENTRY(AFSimple_Calculate,2)
57 JS_STATIC_GLOBAL_FUN_ENTRY(AFRange_Validate,4)
58 JS_STATIC_GLOBAL_FUN_ENTRY(AFMergeChange,1)
59 JS_STATIC_GLOBAL_FUN_ENTRY(AFParseDateEx,2)
60 JS_STATIC_GLOBAL_FUN_ENTRY(AFExtractNums,1)
61 END_JS_STATIC_GLOBAL_FUN()
63 IMPLEMENT_JS_STATIC_GLOBAL_FUN(CJS_PublicMethods)
68 FX_LPCSTR lpszCppMark;
71 static const stru_TbConvert fcTable[] = {
94 static FX_LPCWSTR months[] =
96 (FX_LPCWSTR)L"Jan", (FX_LPCWSTR)L"Feb", (FX_LPCWSTR)L"Mar", (FX_LPCWSTR)L"Apr", (FX_LPCWSTR)L"May", (FX_LPCWSTR)L"Jun", (FX_LPCWSTR)L"Jul", (FX_LPCWSTR)L"Aug", (FX_LPCWSTR)L"Sep", (FX_LPCWSTR)L"Oct", (FX_LPCWSTR)L"Nov", (FX_LPCWSTR)L"Dec"
99 static FX_LPCWSTR fullmonths[] =
101 (FX_LPCWSTR)L"January", (FX_LPCWSTR)L"February", (FX_LPCWSTR)L"March", (FX_LPCWSTR)L"April", (FX_LPCWSTR)L"May", (FX_LPCWSTR)L"June", (FX_LPCWSTR)L"July", (FX_LPCWSTR)L"August", (FX_LPCWSTR)L"September", (FX_LPCWSTR)L"October", (FX_LPCWSTR)L"November", (FX_LPCWSTR)L"December"
104 FX_BOOL CJS_PublicMethods::IsNumber(FX_LPCWSTR string)
106 CFX_WideString sTrim = StrTrim(string);
107 FX_LPCWSTR pTrim = sTrim;
108 FX_LPCWSTR p = pTrim;
111 FX_BOOL bDot = FALSE;
112 FX_BOOL bKXJS = FALSE;
117 if (c == '.' || c == ',')
119 if (bDot) return FALSE;
122 else if (c == '-' || c == '+')
127 else if (c == 'e' || c == 'E')
129 if (bKXJS) return FALSE;
133 if (c == '+' || c == '-')
142 else if (!IsDigit(c))
152 FX_BOOL CJS_PublicMethods::IsDigit(wchar_t ch)
154 return (ch >= L'0' && ch <= L'9');
157 FX_BOOL CJS_PublicMethods::IsDigit(char ch)
159 return (ch >= '0' && ch <= '9');
162 FX_BOOL CJS_PublicMethods::IsAlphabetic(wchar_t ch)
164 return ((ch >= L'a' && ch <= L'z') || (ch >= L'A' && ch <= L'Z'));
167 FX_BOOL CJS_PublicMethods::IsAlphaNumeric(wchar_t ch)
169 return (IsDigit(ch) || IsAlphabetic(ch));
172 FX_BOOL CJS_PublicMethods::maskSatisfied(wchar_t c_Change,wchar_t c_Mask)
177 return IsDigit(c_Change);
179 return IsAlphabetic(c_Change);
181 return IsAlphaNumeric(c_Change);
185 return (c_Change == c_Mask);
189 FX_BOOL CJS_PublicMethods::isReservedMaskChar(wchar_t ch)
191 return ch == L'9' || ch == L'A' || ch == L'O' || ch == L'X';
194 double CJS_PublicMethods::AF_Simple(FX_LPCWSTR sFuction, double dValue1, double dValue2)
196 if (FXSYS_wcsicmp(sFuction,(FX_LPCWSTR)L"AVG") == 0 || FXSYS_wcsicmp(sFuction,(FX_LPCWSTR)L"SUM") == 0)
198 return dValue1 + dValue2;
200 else if (FXSYS_wcsicmp(sFuction, (FX_LPCWSTR)L"PRD") == 0)
202 return dValue1 * dValue2;
204 else if (FXSYS_wcsicmp(sFuction,(FX_LPCWSTR)L"MIN") == 0)
206 return FX_MIN(dValue1, dValue2);
208 else if (FXSYS_wcsicmp(sFuction,(FX_LPCWSTR)L"MAX") == 0)
210 return FX_MAX(dValue1, dValue2);
216 CFX_WideString CJS_PublicMethods::StrLTrim(FX_LPCWSTR pStr)
218 while (*pStr && *pStr == L' ') pStr++;
223 CFX_WideString CJS_PublicMethods::StrRTrim(FX_LPCWSTR pStr)
227 while (p > pStr && *(p - 1) == L' ') p--;
229 return CFX_WideString(pStr, p - pStr);
232 CFX_WideString CJS_PublicMethods::StrTrim(FX_LPCWSTR pStr)
234 return StrRTrim(StrLTrim(pStr));
237 CFX_ByteString CJS_PublicMethods::StrLTrim(FX_LPCSTR pStr)
239 while (*pStr && *pStr == ' ') pStr++;
244 CFX_ByteString CJS_PublicMethods::StrRTrim(FX_LPCSTR pStr)
248 while (p > pStr && *(p - 1) == L' ') p--;
250 return CFX_ByteString(pStr,p-pStr);
253 CFX_ByteString CJS_PublicMethods::StrTrim(FX_LPCSTR pStr)
255 return StrRTrim(StrLTrim(pStr));
258 double CJS_PublicMethods::ParseNumber(FX_LPCWSTR swSource, FX_BOOL& bAllDigits, FX_BOOL& bDot, FX_BOOL& bSign, FX_BOOL& bKXJS)
264 FX_BOOL bDigitExist = FALSE;
266 FX_LPCWSTR p = swSource;
269 FX_LPCWSTR pStart = NULL;
270 FX_LPCWSTR pEnd = NULL;
274 if (!pStart && c != L' ')
289 while (pEnd != pStart)
300 CFX_WideString swDigits;
342 if (c == '+' || c == '-')
351 if (!bDigitExist && !bSign)
360 if (p != pStart && !bDot && bDigitExist)
378 if (swDigits.GetLength() > 0 && swDigits.GetLength() < 17)
380 CFX_ByteString sDigits = swDigits.UTF8Encode();
384 dRet = atof(sDigits);
391 dRet = ::strtod(sDigits, &pStopString);
395 dRet = atol(sDigits);
404 double CJS_PublicMethods::ParseStringToNumber(FX_LPCWSTR swSource)
406 FX_BOOL bAllDigits = FALSE;
407 FX_BOOL bDot = FALSE;
408 FX_BOOL bSign = FALSE;
409 FX_BOOL bKXJS = FALSE;
411 return ParseNumber(swSource, bAllDigits, bDot, bSign, bKXJS);
414 FX_BOOL CJS_PublicMethods::ConvertStringToNumber(FX_LPCWSTR swSource, double & dRet, FX_BOOL & bDot)
416 FX_BOOL bAllDigits = FALSE;
417 FX_BOOL bSign = FALSE;
418 FX_BOOL bKXJS = FALSE;
420 dRet = ParseNumber(swSource, bAllDigits, bDot, bSign, bKXJS);
425 CJS_Array CJS_PublicMethods::AF_MakeArrayFromList(v8::Isolate* isolate, CJS_Value val)
427 CJS_Array StrArray(isolate);
428 if(val.IsArrayObject())
430 val.ConvertToArray(StrArray);
433 CFX_WideString wsStr = val.operator CFX_WideString();
434 CFX_ByteString t = CFX_ByteString::FromUnicode(wsStr);
435 const char * p = (const char *)t;
443 const char * pTemp = strchr(p, ch);
446 StrArray.SetElement(nIndex, CJS_Value(isolate,(FX_LPCSTR)StrTrim(p)));
451 char * pSub = new char[pTemp - p + 1];
452 strncpy(pSub, p, pTemp - p);
453 *(pSub + (pTemp - p)) = '\0';
455 StrArray.SetElement(nIndex, CJS_Value(isolate,(FX_LPCSTR)StrTrim(pSub)));
466 int CJS_PublicMethods::ParseStringInteger(const CFX_WideString& string,int nStart,int& nSkip, int nMaxStep)
470 for (int i=nStart, sz=string.GetLength(); i < sz; i++)
475 FX_WCHAR c = string.GetAt(i);
476 if (IsDigit((wchar_t)c))
478 nRet = nRet * 10 + (c - '0');
479 nSkip = i - nStart + 1;
480 if (nSkip >= nMaxStep)
490 CFX_WideString CJS_PublicMethods::ParseStringString(const CFX_WideString& string, int nStart, int& nSkip)
492 CFX_WideString swRet;
494 for (int i=nStart, sz=string.GetLength(); i < sz; i++)
496 FX_WCHAR c = string.GetAt(i);
497 if ((c >= L'a' && c <= L'z') || (c >= L'A' && c <= L'Z'))
500 nSkip = i - nStart + 1;
509 double CJS_PublicMethods::ParseNormalDate(const CFX_WideString & value, FX_BOOL& bWrongFormat)
511 double dt = JS_GetDateTime();
513 int nYear = JS_GetYearFromTime(dt);
514 int nMonth = JS_GetMonthFromTime(dt) + 1;
515 int nDay = JS_GetDayFromTime(dt);
516 int nHour = JS_GetHourFromTime(dt);
517 int nMin = JS_GetMinFromTime(dt);
518 int nSec = JS_GetSecFromTime(dt);
523 int nLen = value.GetLength();
528 if (nIndex > 2) break;
530 FX_WCHAR c = value.GetAt(i);
531 if (IsDigit((wchar_t)c))
533 number[nIndex++] = ParseStringInteger(value, i, nSkip, 4);
546 if ((number[0] >= 1 && number[0] <= 12) && (number[1] >= 1 && number[1] <= 31))
551 else if ((number[0] >= 1 && number[0] <= 31) && (number[1] >= 1 && number[1] <= 12))
557 bWrongFormat = FALSE;
559 else if (nIndex == 3)
561 // case1: year/month/day
562 // case2: month/day/year
563 // case3: day/month/year
565 if (number[0] > 12 && (number[1] >= 1 && number[1] <= 12) && (number[2] >= 1 && number[2] <= 31))
571 else if ((number[0] >= 1 && number[0] <= 12) && (number[1] >= 1 && number[1] <= 31) && number[2] > 31)
577 else if ((number[0] >= 1 && number[0] <= 31) && (number[1] >= 1 && number[1] <= 12) && number[2] > 31)
584 bWrongFormat = FALSE;
592 CFX_WideString swTemp;
593 swTemp.Format((FX_LPCWSTR)L"%d/%d/%d %d:%d:%d",nMonth,nDay,nYear,nHour,nMin,nSec);
594 return JS_DateParse(swTemp);
597 double CJS_PublicMethods::MakeRegularDate(const CFX_WideString & value, const CFX_WideString & format, FX_BOOL& bWrongFormat)
599 double dt = JS_GetDateTime();
601 if (format.IsEmpty() || value.IsEmpty())
604 int nYear = JS_GetYearFromTime(dt);
605 int nMonth = JS_GetMonthFromTime(dt) + 1;
606 int nDay = JS_GetDayFromTime(dt);
607 int nHour = JS_GetHourFromTime(dt);
608 int nMin = JS_GetMinFromTime(dt);
609 int nSec = JS_GetSecFromTime(dt);
611 int nYearSub = 99; //nYear - 2000;
614 FX_BOOL bExit = FALSE;
615 bWrongFormat = FALSE;
620 while (i < format.GetLength())
624 FX_WCHAR c = format.GetAt(i);
647 int remaining = format.GetLength() - i - 1;
649 if (remaining == 0 || format.GetAt(i+1) != c)
658 nMonth = ParseStringInteger(value, j, nSkip, 2);
663 nDay = ParseStringInteger(value, j, nSkip, 2);
668 nHour = ParseStringInteger(value, j, nSkip, 2);
673 nHour = ParseStringInteger(value, j, nSkip, 2);
678 nMin = ParseStringInteger(value, j, nSkip, 2);
683 nSec = ParseStringInteger(value, j, nSkip, 2);
688 bPm = (j < value.GetLength() && value.GetAt(j) == 'p');
694 else if (remaining == 1 || format.GetAt(i+2) != c)
699 nYear = ParseStringInteger(value, j, nSkip, 4);
704 nMonth = ParseStringInteger(value, j, nSkip, 2);
709 nDay = ParseStringInteger(value, j, nSkip, 2);
714 nHour = ParseStringInteger(value, j, nSkip, 2);
719 nHour = ParseStringInteger(value, j, nSkip, 2);
724 nMin = ParseStringInteger(value, j, nSkip, 2);
729 nSec = ParseStringInteger(value, j, nSkip, 2);
734 bPm = (j + 1 < value.GetLength() && value.GetAt(j) == 'p' && value.GetAt(j+1) == 'm');
740 else if (remaining == 2 || format.GetAt(i+3) != c)
746 CFX_WideString sMonth = ParseStringString(value, j, nSkip);
747 FX_BOOL bFind = FALSE;
748 for (int m = 0; m < 12; m++)
750 if (sMonth.CompareNoCase(months[m]) == 0)
762 nMonth = ParseStringInteger(value, j, nSkip, 3);
776 else if (remaining == 3 || format.GetAt(i+4) != c)
783 nYear = ParseStringInteger(value, j, nSkip, 4);
789 FX_BOOL bFind = FALSE;
791 CFX_WideString sMonth = ParseStringString(value, j, nSkip);
794 for (int m = 0; m < 12; m++)
796 CFX_WideString sFullMonths = fullmonths[m];
797 sFullMonths.MakeLower();
799 if (sFullMonths.Find(sMonth, 0) != -1)
811 nMonth = ParseStringInteger(value, j, nSkip, 4);
825 if (j >= value.GetLength() || format.GetAt(i) != value.GetAt(j))
843 if (value.GetLength() <= j)
847 else if (format.GetAt(i) != value.GetAt(j))
859 if (bPm) nHour += 12;
861 if (nYear >= 0 && nYear <= nYearSub)
864 if (nMonth < 1 || nMonth > 12)
867 if (nDay < 1 || nDay > 31)
870 if (nHour < 0 || nHour > 24)
873 if (nMin < 0 || nMin > 60)
876 if (nSec < 0 || nSec > 60)
883 dRet = ParseNormalDate(value, bWrongFormat);
887 dRet = JS_MakeDate(JS_MakeDay(nYear,nMonth - 1,nDay),JS_MakeTime(nHour, nMin, nSec, 0));
889 if (JS_PortIsNan(dRet))
891 dRet = JS_DateParse(value);
895 if (JS_PortIsNan(dRet))
897 dRet = ParseNormalDate(value, bWrongFormat);
904 CFX_WideString CJS_PublicMethods::MakeFormatDate(double dDate, const CFX_WideString & format)
906 CFX_WideString sRet = L"",sPart = L"";
908 int nYear = JS_GetYearFromTime(dDate);
909 int nMonth = JS_GetMonthFromTime(dDate) + 1;
910 int nDay = JS_GetDayFromTime(dDate);
911 int nHour = JS_GetHourFromTime(dDate);
912 int nMin = JS_GetMinFromTime(dDate);
913 int nSec = JS_GetSecFromTime(dDate);
916 while (i < format.GetLength())
918 FX_WCHAR c = format.GetAt(i);
919 int remaining = format.GetLength() - i - 1;
931 if (remaining == 0 || format.GetAt(i+1) != c)
939 sPart.Format((FX_LPCWSTR)L"%d",nMonth);
942 sPart.Format((FX_LPCWSTR)L"%d",nDay);
945 sPart.Format((FX_LPCWSTR)L"%d",nHour);
948 sPart.Format((FX_LPCWSTR)L"%d",nHour>12?nHour - 12:nHour);
951 sPart.Format((FX_LPCWSTR)L"%d",nMin);
954 sPart.Format((FX_LPCWSTR)L"%d",nSec);
957 sPart += nHour>12?'p':'a';
962 else if (remaining == 1 || format.GetAt(i+2) != c)
967 sPart.Format((FX_LPCWSTR)L"%02d",nYear - (nYear / 100) * 100);
970 sPart.Format((FX_LPCWSTR)L"%02d",nMonth);
973 sPart.Format((FX_LPCWSTR)L"%02d",nDay);
976 sPart.Format((FX_LPCWSTR)L"%02d",nHour);
979 sPart.Format((FX_LPCWSTR)L"%02d",nHour>12?nHour - 12:nHour);
982 sPart.Format((FX_LPCWSTR)L"%02d",nMin);
985 sPart.Format((FX_LPCWSTR)L"%02d",nSec);
988 sPart = nHour>12? (FX_LPCWSTR)L"pm": (FX_LPCWSTR)L"am";
993 else if (remaining == 2 || format.GetAt(i+3) != c)
999 if (nMonth > 0&&nMonth <= 12)
1000 sPart += months[nMonth - 1];
1010 else if (remaining == 3 || format.GetAt(i+4) != c)
1015 sPart.Format((FX_LPCWSTR)L"%04d",nYear);
1020 if (nMonth > 0&&nMonth <= 12)
1021 sPart += fullmonths[nMonth - 1];
1050 /* -------------------------------------------------------------------------- */
1052 //function AFNumber_Format(nDec, sepStyle, negStyle, currStyle, strCurrency, bCurrencyPrepend)
1053 FX_BOOL CJS_PublicMethods::AFNumber_Format(OBJ_METHOD_PARAMS)
1055 #if _FX_OS_ != _FX_ANDROID_
1056 v8::Isolate* isolate = ::GetIsolate(cc);
1057 CJS_Context* pContext = (CJS_Context *)cc;
1058 ASSERT(pContext != NULL);
1059 CJS_EventHandler* pEvent = pContext->GetEventHandler();
1060 ASSERT(pEvent != NULL);
1062 if (params.size() != 6)
1064 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
1067 if(!pEvent->m_pValue)
1069 CFX_WideString& Value = pEvent->Value();
1070 CFX_ByteString strValue = StrTrim(CFX_ByteString::FromUnicode(Value));
1072 if (strValue.IsEmpty()) return TRUE;
1074 int iDec = params[0];
1075 int iSepStyle = params[1];
1076 int iNegStyle = params[2];
1077 // params[3] is iCurrStyle, it's not used.
1078 std::wstring wstrCurrency(params[4].operator CFX_WideString());
1079 FX_BOOL bCurrencyPrepend = params[5];
1081 if (iDec < 0) iDec = -iDec;
1083 if (iSepStyle < 0 || iSepStyle > 3)
1086 if (iNegStyle < 0 || iNegStyle > 3)
1090 //////////////////////////////////////////////////////
1091 //for processing decimal places
1092 strValue.Replace(",", ".");
1093 double dValue = atof(strValue);
1095 dValue += DOUBLE_CORRECT;//
1098 FX_BOOL bNagative = FALSE;
1100 strValue = fcvt(dValue,iDec,&iDec2,&bNagative);
1101 if (strValue.IsEmpty())
1104 strValue = fcvt(dValue,iDec,&iDec2,&bNagative);
1105 if (strValue.IsEmpty())
1115 for (int iNum = 0;iNum < abs(iDec2);iNum++)
1117 strValue = "0" + strValue;
1122 int iMax = strValue.GetLength();
1125 for (int iNum = 0;iNum <= iDec2 - iMax ;iNum++)
1131 ///////////////////////////////////////////////////////
1132 //for processing seperator style
1135 if (iSepStyle == 0 || iSepStyle == 1)
1137 strValue.Insert(iDec2, '.');
1140 else if (iSepStyle == 2 || iSepStyle == 3)
1142 strValue.Insert(iDec2, ',');
1147 strValue.Insert(iDec2, '0');
1149 if (iSepStyle == 0 || iSepStyle == 2)
1157 int iDecPositive,iDecNagative;
1158 iDecPositive = iDec2;
1159 iDecNagative = iDec2;
1161 for (iDecPositive = iDec2 -3; iDecPositive > 0;iDecPositive -= 3)
1163 strValue.Insert(iDecPositive, cSeperator);
1168 //////////////////////////////////////////////////////////////////////
1169 //for processing currency string
1171 Value = CFX_WideString::FromLocal(strValue);
1173 std::wstring strValue2(Value);
1175 if (bCurrencyPrepend)
1176 strValue2 = wstrCurrency + strValue2;
1178 strValue2 = strValue2 + wstrCurrency;
1182 /////////////////////////////////////////////////////////////////////////
1183 //for processing negative style
1188 strValue2.insert(0,L"-");
1190 if (iNegStyle == 2 || iNegStyle == 3)
1192 strValue2.insert(0,L"(");
1193 strValue2.insert(strValue2.length(),L")");
1195 if (iNegStyle == 1 || iNegStyle == 3)
1197 if (Field * fTarget = pEvent->Target_Field())
1199 CJS_Array arColor(isolate);
1200 CJS_Value vColElm(isolate);
1202 arColor.SetElement(0,vColElm);
1204 arColor.SetElement(1,vColElm);
1206 arColor.SetElement(2,vColElm);
1208 arColor.SetElement(3,vColElm);
1210 CJS_PropValue vProp(isolate);
1211 vProp.StartGetting();
1213 vProp.StartSetting();
1214 fTarget->textColor(cc,vProp,sError);// red
1220 if (iNegStyle == 1 || iNegStyle == 3)
1222 if (Field *fTarget = pEvent->Target_Field())
1224 CJS_Array arColor(isolate);
1225 CJS_Value vColElm(isolate);
1227 arColor.SetElement(0,vColElm);
1229 arColor.SetElement(1,vColElm);
1230 arColor.SetElement(2,vColElm);
1231 arColor.SetElement(3,vColElm);
1233 CJS_PropValue vProp(isolate);
1234 vProp.StartGetting();
1235 fTarget->textColor(cc,vProp,sError);
1237 CJS_Array aProp(isolate);
1238 vProp.ConvertToArray(aProp);
1242 color::ConvertArrayToPWLColor(aProp, crProp);
1243 color::ConvertArrayToPWLColor(arColor, crColor);
1245 if (crColor != crProp)
1247 CJS_PropValue vProp2(isolate);
1248 vProp2.StartGetting();
1250 vProp2.StartSetting();
1251 fTarget->textColor(cc,vProp2,sError);
1256 Value = strValue2.c_str();
1261 //function AFNumber_Keystroke(nDec, sepStyle, negStyle, currStyle, strCurrency, bCurrencyPrepend)
1262 FX_BOOL CJS_PublicMethods::AFNumber_Keystroke(OBJ_METHOD_PARAMS)
1264 CJS_Context* pContext = (CJS_Context *)cc;
1265 ASSERT(pContext != NULL);
1266 CJS_EventHandler* pEvent = pContext->GetEventHandler();
1267 ASSERT(pEvent != NULL);
1269 if(params.size() < 2)
1271 int iSepStyle = params[1];
1273 if (iSepStyle < 0 || iSepStyle > 3)
1275 if(!pEvent->m_pValue)
1277 CFX_WideString & val = pEvent->Value();
1278 CFX_WideString & w_strChange = pEvent->Change();
1279 CFX_WideString w_strValue = val;
1281 if (pEvent->WillCommit())
1283 CFX_WideString wstrChange = w_strChange;
1284 CFX_WideString wstrValue = StrLTrim(w_strValue);
1285 if (wstrValue.IsEmpty())
1288 CFX_WideString swTemp = wstrValue;
1289 swTemp.Replace((FX_LPCWSTR)L",", (FX_LPCWSTR)L".");
1290 if (!IsNumber(swTemp)) //!(IsNumber(wstrChange) &&
1292 pEvent->Rc() = FALSE;
1293 sError = JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYSTROKE);
1294 Alert(pContext, sError);
1297 return TRUE; // it happens after the last keystroke and before validating,
1300 std::wstring w_strValue2 (w_strValue);
1301 std::wstring w_strChange2(w_strChange);
1303 std::wstring w_strSelected;
1304 if(-1 != pEvent->SelStart())
1305 w_strSelected = w_strValue2.substr(pEvent->SelStart(),(pEvent->SelEnd() - pEvent->SelStart()));
1306 FX_BOOL bHasSign = (w_strValue2.find('-') != -1) && (w_strSelected.find('-') == -1);
1309 //can't insert "change" in front to sign postion.
1310 if (pEvent->SelStart() == 0)
1312 FX_BOOL &bRc = pEvent->Rc();
1332 FX_BOOL bHasSep = (w_strValue2.find(cSep) != -1);
1333 for (std::wstring::iterator it = w_strChange2.begin(); it != w_strChange2.end(); it++)
1339 FX_BOOL &bRc = pEvent->Rc();
1353 FX_BOOL &bRc = pEvent->Rc();
1357 else if (it != w_strChange2.begin()) //sign's position is not correct
1359 FX_BOOL &bRc = pEvent->Rc();
1363 else if (pEvent->SelStart() != 0)
1365 FX_BOOL &bRc = pEvent->Rc();
1375 FX_BOOL &bRc = pEvent->Rc();
1382 std::wstring w_prefix = w_strValue2.substr(0,pEvent->SelStart());
1383 std::wstring w_postfix;
1384 if (pEvent->SelEnd()<(int)w_strValue2.length())
1385 w_postfix = w_strValue2.substr(pEvent->SelEnd());
1386 w_strValue2 = w_prefix + w_strChange2 + w_postfix;
1387 w_strValue = w_strValue2.c_str();
1393 //function AFPercent_Format(nDec, sepStyle)
1394 FX_BOOL CJS_PublicMethods::AFPercent_Format(OBJ_METHOD_PARAMS)
1396 #if _FX_OS_ != _FX_ANDROID_
1397 CJS_Context* pContext = (CJS_Context *)cc;
1398 ASSERT(pContext != NULL);
1399 CJS_EventHandler* pEvent = pContext->GetEventHandler();
1400 ASSERT(pEvent != NULL);
1402 if (params.size() != 2)
1404 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
1407 if(!pEvent->m_pValue)
1409 CFX_WideString& Value = pEvent->Value();
1411 // HWND hMainFrame = NULL;
1413 // CPDFSDK_FormFillApp *pApp = pContext->GetReaderApp();
1415 // hMainFrame = pApp->GetMainFrameWnd();
1417 CFX_ByteString strValue = StrTrim(CFX_ByteString::FromUnicode(Value));
1419 if (strValue.IsEmpty())
1422 int iDec = params[0];
1423 int iSepStyle = params[1];
1429 if (iSepStyle < 0 || iSepStyle > 3)
1433 //////////////////////////////////////////////////////
1434 //for processing decimal places
1435 double dValue = atof(strValue);
1438 dValue += DOUBLE_CORRECT;//УÕý
1441 FX_BOOL bNagative = FALSE;
1442 strValue = fcvt(dValue,iDec,&iDec2,&bNagative);
1443 if (strValue.IsEmpty())
1446 strValue = fcvt(dValue,iDec,&iDec2,&bNagative);
1451 for (int iNum = 0; iNum < abs(iDec2); iNum++)
1453 strValue = "0" + strValue;
1458 int iMax = strValue.GetLength();
1461 for (int iNum = 0; iNum <= iDec2 - iMax; iNum++)
1467 ///////////////////////////////////////////////////////
1468 //for processing seperator style
1471 if (iSepStyle == 0 || iSepStyle == 1)
1473 strValue.Insert(iDec2, '.');
1476 else if (iSepStyle == 2 || iSepStyle == 3)
1478 strValue.Insert(iDec2, ',');
1483 strValue.Insert(iDec2, '0');
1485 if (iSepStyle == 0 || iSepStyle == 2)
1493 int iDecPositive,iDecNagative;
1494 iDecPositive = iDec2;
1495 iDecNagative = iDec2;
1497 for (iDecPositive = iDec2 -3; iDecPositive > 0; iDecPositive -= 3)
1499 strValue.Insert(iDecPositive,cSeperator);
1503 ////////////////////////////////////////////////////////////////////
1506 strValue = "-" + strValue;
1508 Value = CFX_WideString::FromLocal(strValue);
1512 //AFPercent_Keystroke(nDec, sepStyle)
1513 FX_BOOL CJS_PublicMethods::AFPercent_Keystroke(OBJ_METHOD_PARAMS)
1515 return AFNumber_Keystroke(cc,params,vRet,sError);
1518 //function AFDate_FormatEx(cFormat)
1519 FX_BOOL CJS_PublicMethods::AFDate_FormatEx(OBJ_METHOD_PARAMS)
1521 CJS_Context* pContext = (CJS_Context *)cc;
1522 ASSERT(pContext != NULL);
1523 CJS_EventHandler* pEvent = pContext->GetEventHandler();
1524 ASSERT(pEvent != NULL);
1526 if (params.size() != 1)
1528 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
1531 if(!pEvent->m_pValue)
1533 CFX_WideString& val = pEvent->Value();
1535 CFX_WideString strValue = val;
1536 if (strValue.IsEmpty()) return TRUE;
1538 CFX_WideString sFormat = params[0].operator CFX_WideString();
1540 FX_BOOL bWrongFormat = FALSE;
1541 double dDate = 0.0f;
1543 if(strValue.Find(L"GMT") != -1)
1545 //for GMT format time
1546 //such as "Tue Aug 11 14:24:16 GMT+08002009"
1547 dDate = MakeInterDate(strValue);
1551 dDate = MakeRegularDate(strValue,sFormat,bWrongFormat);
1554 if (JS_PortIsNan(dDate))
1556 CFX_WideString swMsg;
1557 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE), (FX_LPCWSTR)sFormat);
1558 Alert(pContext, swMsg);
1562 val = MakeFormatDate(dDate,sFormat);
1567 double CJS_PublicMethods::MakeInterDate(CFX_WideString strValue)
1576 CFX_WideStringArray wsArray;
1577 CFX_WideString sMonth = L"";
1578 CFX_WideString sTemp = L"";
1579 int nSize = strValue.GetLength();
1581 for(int i = 0; i < nSize; i++)
1583 FX_WCHAR c = strValue.GetAt(i);
1584 if(c == L' ' || c == L':')
1595 if(wsArray.GetSize() != 8)return 0;
1598 if(sTemp.Compare(L"Jan") == 0) nMonth = 1;
1599 if(sTemp.Compare(L"Feb") == 0) nMonth = 2;
1600 if(sTemp.Compare(L"Mar") == 0) nMonth = 3;
1601 if(sTemp.Compare(L"Apr") == 0) nMonth = 4;
1602 if(sTemp.Compare(L"May") == 0) nMonth = 5;
1603 if(sTemp.Compare(L"Jun") == 0) nMonth = 6;
1604 if(sTemp.Compare(L"Jul") == 0) nMonth = 7;
1605 if(sTemp.Compare(L"Aug") == 0) nMonth = 8;
1606 if(sTemp.Compare(L"Sep") == 0) nMonth = 9;
1607 if(sTemp.Compare(L"Oct") == 0) nMonth = 10;
1608 if(sTemp.Compare(L"Nov") == 0) nMonth = 11;
1609 if(sTemp.Compare(L"Dec") == 0) nMonth = 12;
1611 nDay = (int)ParseStringToNumber(wsArray[2]);
1612 nHour = (int)ParseStringToNumber(wsArray[3]);
1613 nMin = (int)ParseStringToNumber(wsArray[4]);
1614 nSec = (int)ParseStringToNumber(wsArray[5]);
1615 nYear = (int)ParseStringToNumber(wsArray[7]);
1617 double dRet = JS_MakeDate(JS_MakeDay(nYear,nMonth - 1,nDay),JS_MakeTime(nHour, nMin, nSec, 0));
1619 if (JS_PortIsNan(dRet))
1621 dRet = JS_DateParse(strValue);
1627 //AFDate_KeystrokeEx(cFormat)
1628 FX_BOOL CJS_PublicMethods::AFDate_KeystrokeEx(OBJ_METHOD_PARAMS)
1630 CJS_Context* pContext = (CJS_Context *)cc;
1631 ASSERT(pContext != NULL);
1632 CJS_EventHandler* pEvent = pContext->GetEventHandler();
1633 ASSERT(pEvent != NULL);
1635 if (params.size() != 1)
1637 sError = L"AFDate_KeystrokeEx's parameters' size r not correct";
1641 if (pEvent->WillCommit())
1643 if(!pEvent->m_pValue)
1645 CFX_WideString strValue = pEvent->Value();
1646 if (strValue.IsEmpty()) return TRUE;
1648 CFX_WideString sFormat = params[0].operator CFX_WideString();
1650 FX_BOOL bWrongFormat = FALSE;
1651 double dRet = MakeRegularDate(strValue,sFormat,bWrongFormat);
1652 if (bWrongFormat || JS_PortIsNan(dRet))
1654 CFX_WideString swMsg;
1655 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE), (FX_LPCWSTR)sFormat);
1656 Alert(pContext, swMsg);
1657 pEvent->Rc() = FALSE;
1664 FX_BOOL CJS_PublicMethods::AFDate_Format(OBJ_METHOD_PARAMS)
1666 v8::Isolate* isolate = ::GetIsolate(cc);
1668 if (params.size() != 1)
1670 CJS_Context* pContext = (CJS_Context*)cc;
1671 ASSERT(pContext != NULL);
1673 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
1677 int iIndex = params[0];
1678 FX_LPCWSTR cFormats[] = {(FX_LPCWSTR)L"m/d", (FX_LPCWSTR)L"m/d/yy", (FX_LPCWSTR)L"mm/dd/yy", (FX_LPCWSTR)L"mm/yy", (FX_LPCWSTR)L"d-mmm", (FX_LPCWSTR)L"d-mmm-yy", (FX_LPCWSTR)L"dd-mmm-yy",
1679 (FX_LPCWSTR)L"yy-mm-dd", (FX_LPCWSTR)L"mmm-yy", (FX_LPCWSTR)L"mmmm-yy", (FX_LPCWSTR)L"mmm d, yyyy", (FX_LPCWSTR)L"mmmm d, yyyy",
1680 (FX_LPCWSTR)L"m/d/yy h:MM tt", (FX_LPCWSTR)L"m/d/yy HH:MM" };
1682 ASSERT(iIndex < sizeof(cFormats)/sizeof(FX_LPCWSTR));
1686 if (iIndex >= sizeof(cFormats)/sizeof(FX_LPCWSTR))
1688 CJS_Parameters newParams;
1689 CJS_Value val(isolate,cFormats[iIndex]);
1690 newParams.push_back(val);
1691 return AFDate_FormatEx(cc,newParams,vRet,sError);
1694 //AFDate_KeystrokeEx(cFormat)
1695 FX_BOOL CJS_PublicMethods::AFDate_Keystroke(OBJ_METHOD_PARAMS)
1697 v8::Isolate* isolate = ::GetIsolate(cc);
1699 if (params.size() != 1)
1701 CJS_Context* pContext = (CJS_Context*)cc;
1702 ASSERT(pContext != NULL);
1704 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
1708 int iIndex = params[0];
1709 FX_LPCWSTR cFormats[] = {(FX_LPCWSTR)L"m/d", (FX_LPCWSTR)L"m/d/yy", (FX_LPCWSTR)L"mm/dd/yy", (FX_LPCWSTR)L"mm/yy", (FX_LPCWSTR)L"d-mmm", (FX_LPCWSTR)L"d-mmm-yy", (FX_LPCWSTR)L"dd-mmm-yy",
1710 (FX_LPCWSTR)L"yy-mm-dd", (FX_LPCWSTR)L"mmm-yy", (FX_LPCWSTR)L"mmmm-yy", (FX_LPCWSTR)L"mmm d, yyyy", (FX_LPCWSTR)L"mmmm d, yyyy",
1711 (FX_LPCWSTR)L"m/d/yy h:MM tt", (FX_LPCWSTR)L"m/d/yy HH:MM" };
1713 ASSERT(iIndex<sizeof(cFormats)/sizeof(FX_LPCWSTR));
1717 if (iIndex >= sizeof(cFormats)/sizeof(FX_LPCWSTR))
1719 CJS_Parameters newParams;
1720 CJS_Value val(isolate,cFormats[iIndex]);
1721 newParams.push_back(val);
1722 return AFDate_KeystrokeEx(cc,newParams,vRet,sError);
1725 //function AFTime_Format(ptf)
1726 FX_BOOL CJS_PublicMethods::AFTime_Format(OBJ_METHOD_PARAMS)
1728 v8::Isolate* isolate = ::GetIsolate(cc);
1730 if (params.size() != 1)
1732 CJS_Context* pContext = (CJS_Context*)cc;
1733 ASSERT(pContext != NULL);
1734 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
1738 int iIndex = params[0];
1739 FX_LPCWSTR cFormats[] = {(FX_LPCWSTR)L"HH:MM", (FX_LPCWSTR)L"h:MM tt", (FX_LPCWSTR)L"HH:MM:ss", (FX_LPCWSTR)L"h:MM:ss tt"};
1741 ASSERT(iIndex<sizeof(cFormats)/sizeof(FX_LPCWSTR));
1745 if (iIndex >= sizeof(cFormats)/sizeof(FX_LPCWSTR))
1747 CJS_Parameters newParams;
1748 CJS_Value val(isolate,cFormats[iIndex]);
1749 newParams.push_back(val);
1750 return AFDate_FormatEx(cc,newParams,vRet,sError);
1753 FX_BOOL CJS_PublicMethods::AFTime_Keystroke(OBJ_METHOD_PARAMS)
1755 v8::Isolate* isolate = ::GetIsolate(cc);
1756 if (params.size() != 1)
1758 CJS_Context* pContext = (CJS_Context*)cc;
1759 ASSERT(pContext != NULL);
1760 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
1764 int iIndex = params[0];
1765 FX_LPCWSTR cFormats[] = {(FX_LPCWSTR)L"HH:MM", (FX_LPCWSTR)L"h:MM tt", (FX_LPCWSTR)L"HH:MM:ss", (FX_LPCWSTR)L"h:MM:ss tt"};
1767 ASSERT(iIndex<sizeof(cFormats)/sizeof(FX_LPCWSTR));
1771 if (iIndex >= sizeof(cFormats)/sizeof(FX_LPCWSTR))
1773 CJS_Parameters newParams;
1774 CJS_Value val(isolate,cFormats[iIndex]);
1775 newParams.push_back(val);
1776 return AFDate_KeystrokeEx(cc,newParams,vRet,sError);
1779 FX_BOOL CJS_PublicMethods::AFTime_FormatEx(OBJ_METHOD_PARAMS)
1781 return AFDate_FormatEx(cc,params,vRet,sError);
1784 FX_BOOL CJS_PublicMethods::AFTime_KeystrokeEx(OBJ_METHOD_PARAMS)
1786 return AFDate_KeystrokeEx(cc,params,vRet,sError);
1789 //function AFSpecial_Format(psf)
1790 FX_BOOL CJS_PublicMethods::AFSpecial_Format(OBJ_METHOD_PARAMS)
1792 CJS_Context* pContext = (CJS_Context *)cc;
1793 ASSERT(pContext != NULL);
1795 if (params.size() != 1)
1797 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
1801 std::string cFormat;
1802 int iIndex = params[0];
1804 CJS_EventHandler* pEvent = pContext->GetEventHandler();
1805 ASSERT(pEvent != NULL);
1807 if(!pEvent->m_pValue)
1809 CFX_WideString& Value = pEvent->Value();
1810 std::string strSrc = (FX_LPCSTR)CFX_ByteString::FromUnicode(Value);
1818 cFormat = "99999-9999";
1822 std::string NumberStr;
1823 util::printx("9999999999", strSrc,NumberStr);
1824 if (NumberStr.length() >= 10 )
1825 cFormat = "(999) 999-9999";
1827 cFormat = "999-9999";
1831 cFormat = "999-99-9999";
1836 util::printx(cFormat,strSrc,strDes);
1837 Value = CFX_WideString::FromLocal(strDes.c_str());
1842 //function AFSpecial_KeystrokeEx(mask)
1843 FX_BOOL CJS_PublicMethods::AFSpecial_KeystrokeEx(OBJ_METHOD_PARAMS)
1845 CJS_Context* pContext = (CJS_Context *)cc;
1846 ASSERT(pContext != NULL);
1847 CJS_EventHandler* pEvent = pContext->GetEventHandler();
1849 ASSERT(pEvent != NULL);
1851 if (params.size() < 1)
1853 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
1857 if(!pEvent->m_pValue)
1859 CFX_WideString& valEvent = pEvent->Value();
1861 CFX_WideString wstrMask = params[0].operator CFX_WideString();
1862 if (wstrMask.IsEmpty()) return TRUE;
1864 std::wstring wstrValue(valEvent);
1866 if (pEvent->WillCommit())
1868 if (wstrValue.empty())
1871 for (std::wstring::iterator it = wstrValue.begin(); it != wstrValue.end(); it++)
1873 wchar_t w_Value = *it;
1874 if (!maskSatisfied(w_Value,wstrMask[iIndexMask]))
1879 if (iIndexMask != wstrMask.GetLength() || (iIndexMask != wstrValue.size() && wstrMask.GetLength() != 0))
1881 Alert(pContext, JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYSTROKE));
1882 pEvent->Rc() = FALSE;
1888 CFX_WideString &wideChange = pEvent->Change();
1889 std::wstring wChange(wideChange);
1891 if (wChange.empty())
1893 int iIndexMask = pEvent->SelStart();
1897 if (wstrValue.length() - (pEvent->SelEnd()-pEvent->SelStart()) + wChange.length() > (FX_DWORD)wstrMask.GetLength())
1899 Alert(pContext, JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG));
1900 pEvent->Rc() = FALSE;
1905 if (iIndexMask >= wstrMask.GetLength() && (!wChange.empty()))
1907 Alert(pContext, JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG));
1908 pEvent->Rc() = FALSE;
1912 for (std::wstring::iterator it = wChange.begin(); it != wChange.end(); it++)
1914 if (iIndexMask >= wstrMask.GetLength())
1916 Alert(pContext, JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG));
1917 pEvent->Rc() = FALSE;
1920 wchar_t w_Mask = wstrMask[iIndexMask];
1921 if (!isReservedMaskChar(w_Mask))
1923 //wChange.insert(it,w_Mask);
1926 wchar_t w_Change = *it;
1928 if (!maskSatisfied(w_Change,w_Mask))
1930 pEvent->Rc() = FALSE;
1936 wideChange = wChange.c_str();
1942 //function AFSpecial_Keystroke(psf)
1943 FX_BOOL CJS_PublicMethods::AFSpecial_Keystroke(OBJ_METHOD_PARAMS)
1945 v8::Isolate* isolate = ::GetIsolate(cc);
1947 CJS_Context* pContext = (CJS_Context *)cc;
1948 ASSERT(pContext != NULL);
1949 CJS_EventHandler* pEvent = pContext->GetEventHandler();
1950 ASSERT(pEvent != NULL);
1952 if (params.size() != 1)
1954 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
1958 std::string cFormat;
1959 int iIndex = (int)params[0];
1961 if(!pEvent->m_pValue)
1963 //CJS_Value val = pEvent->Value();
1964 CFX_WideString& val = pEvent->Value();
1965 std::string strSrc = (FX_LPCSTR)CFX_ByteString::FromUnicode(val);
1966 std::wstring wstrChange(pEvent->Change());
1974 //cFormat = "99999-9999";
1975 cFormat = "999999999";
1979 std::string NumberStr;
1980 util::printx("9999999999", strSrc,NumberStr);
1981 if (strSrc.length() + wstrChange.length() > 7 )
1982 //cFormat = "(999) 999-9999";
1983 cFormat = "9999999999";
1985 //cFormat = "999-9999";
1986 cFormat = "9999999";
1990 //cFormat = "999-99-9999";
1991 cFormat = "999999999";
1995 CJS_Parameters params2;
1996 CJS_Value vMask(isolate, cFormat.c_str());
1997 params2.push_back(vMask);
1999 return AFSpecial_KeystrokeEx(cc,params2,vRet,sError);
2002 FX_BOOL CJS_PublicMethods::AFMergeChange(OBJ_METHOD_PARAMS)
2004 CJS_Context* pContext = (CJS_Context *)cc;
2005 ASSERT(pContext != NULL);
2006 CJS_EventHandler* pEventHandler = pContext->GetEventHandler();
2007 ASSERT(pEventHandler != NULL);
2009 if (params.size() != 1)
2011 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
2015 CFX_WideString swValue;
2016 if (pEventHandler->m_pValue != NULL)
2017 swValue = pEventHandler->Value();
2019 if (pEventHandler->WillCommit())
2025 CFX_WideString prefix,postfix;
2027 if (pEventHandler->SelStart() >= 0)
2028 prefix = swValue.Mid(0,pEventHandler->SelStart());
2033 if (pEventHandler->SelEnd() >= 0 && pEventHandler->SelEnd() <= swValue.GetLength())
2034 postfix = swValue.Mid(pEventHandler->SelEnd(), swValue.GetLength() - pEventHandler->SelEnd());
2037 vRet = prefix + pEventHandler->Change() + postfix;
2042 FX_BOOL CJS_PublicMethods::AFParseDateEx(OBJ_METHOD_PARAMS)
2044 CJS_Context* pContext = (CJS_Context *)cc;
2045 ASSERT(pContext != NULL);
2047 if (params.size() != 2)
2049 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
2053 CFX_WideString sValue = params[0].operator CFX_WideString();
2054 CFX_WideString sFormat = params[1].operator CFX_WideString();
2056 FX_BOOL bWrongFormat = FALSE;
2057 double dDate = MakeRegularDate(sValue,sFormat,bWrongFormat);
2059 if (JS_PortIsNan(dDate))
2061 CFX_WideString swMsg;
2062 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE), (FX_LPCWSTR)sFormat);
2063 Alert((CJS_Context *)cc, swMsg);
2072 FX_BOOL CJS_PublicMethods::AFSimple(OBJ_METHOD_PARAMS)
2074 if (params.size() != 3)
2076 CJS_Context* pContext = (CJS_Context *)cc;
2077 ASSERT(pContext != NULL);
2079 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
2083 vRet = (double)AF_Simple(params[0].operator CFX_WideString(), (double)params[1], (double)params[2]);
2087 FX_BOOL CJS_PublicMethods::AFMakeNumber(OBJ_METHOD_PARAMS)
2089 if (params.size() != 1)
2091 CJS_Context* pContext = (CJS_Context *)cc;
2092 ASSERT(pContext != NULL);
2094 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
2097 vRet = ParseStringToNumber(params[0].operator CFX_WideString());
2101 FX_BOOL CJS_PublicMethods::AFSimple_Calculate(OBJ_METHOD_PARAMS)
2103 v8::Isolate* isolate = ::GetIsolate(cc);
2105 CJS_Context* pContext = (CJS_Context *)cc;
2106 ASSERT(pContext != NULL);
2108 if (params.size() != 2)
2110 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
2114 CJS_Value params1 = params[1];
2116 if (!params1.IsArrayObject() && params1.GetType() != VT_string)
2118 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
2122 CPDFSDK_Document* pReaderDoc = pContext->GetReaderDocument();
2123 ASSERT(pReaderDoc != NULL);
2125 CPDFSDK_InterForm* pReaderInterForm = pReaderDoc->GetInterForm();
2126 ASSERT(pReaderInterForm != NULL);
2128 CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm();
2129 ASSERT(pInterForm != NULL);
2132 CFX_WideString sFunction = params[0].operator CFX_WideString();
2133 if (wcscmp(sFunction, L"PRD") == 0)
2138 CJS_Array FieldNameArray = AF_MakeArrayFromList(isolate,params1);
2140 int nFieldsCount = 0;
2142 for (int i=0,isz=FieldNameArray.GetLength(); i<isz; i++)
2144 CJS_Value jsValue(isolate);
2145 FieldNameArray.GetElement(i,jsValue);
2146 CFX_WideString wsFieldName = jsValue.operator CFX_WideString();
2148 for (int j=0,jsz=pInterForm->CountFields(wsFieldName); j<jsz; j++)
2150 if (CPDF_FormField* pFormField = pInterForm->GetField(j, wsFieldName))
2154 switch (pFormField->GetFieldType())
2156 case FIELDTYPE_TEXTFIELD:
2157 case FIELDTYPE_COMBOBOX:
2159 dTemp = ParseStringToNumber(pFormField->GetValue());
2162 case FIELDTYPE_PUSHBUTTON:
2167 case FIELDTYPE_CHECKBOX:
2168 case FIELDTYPE_RADIOBUTTON:
2171 for (int c=0,csz=pFormField->CountControls(); c<csz; c++)
2173 if (CPDF_FormControl* pFormCtrl = pFormField->GetControl(c))
2175 if (pFormCtrl->IsChecked())
2177 dTemp += ParseStringToNumber(pFormCtrl->GetExportValue());
2186 case FIELDTYPE_LISTBOX:
2189 if (pFormField->CountSelectedItems() > 1)
2193 dTemp = ParseStringToNumber(pFormField->GetValue());
2201 if (i == 0 && j == 0 && (wcscmp(sFunction,L"MIN") == 0 || wcscmp(sFunction, L"MAX") == 0))
2204 dValue = AF_Simple(sFunction, dValue, dTemp);
2211 if (wcscmp(sFunction, L"AVG") == 0 && nFieldsCount > 0)
2212 dValue /= nFieldsCount;
2214 dValue = (double)floor(dValue * FXSYS_pow((double)10,(double)6) + 0.49) / FXSYS_pow((double)10,(double)6);
2215 CJS_Value jsValue(isolate,dValue);
2216 if((CJS_EventHandler*)pContext->GetEventHandler()->m_pValue)
2217 ((CJS_EventHandler*)pContext->GetEventHandler())->Value() = jsValue;
2222 /* This function validates the current event to ensure that its value is
2223 ** within the specified range. */
2225 FX_BOOL CJS_PublicMethods::AFRange_Validate(OBJ_METHOD_PARAMS)
2227 CJS_Context* pContext = (CJS_Context *)cc;
2228 ASSERT(pContext != NULL);
2229 CJS_EventHandler* pEvent = pContext->GetEventHandler();
2230 ASSERT(pEvent != NULL);
2232 if (params.size() != 4)
2234 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
2238 if(!pEvent->m_pValue)
2240 if (pEvent->Value().IsEmpty() )
2242 double dEentValue = atof(CFX_ByteString::FromUnicode(pEvent->Value()));
2243 FX_BOOL bGreaterThan, bLessThan;
2244 double dGreaterThan, dLessThan;
2245 bGreaterThan = (FX_BOOL)params[0];
2246 CFX_WideString swMsg;
2247 dGreaterThan = (double)params[1];
2248 bLessThan = (FX_BOOL)params[2];
2249 dLessThan = (double)params[3];
2251 if (bGreaterThan && bLessThan)
2253 if (dEentValue < dGreaterThan || dEentValue > dLessThan)
2254 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE1),(FX_LPCWSTR)params[1].operator CFX_WideString(), (FX_LPCWSTR)params[3].operator CFX_WideString());
2256 else if (bGreaterThan)
2258 if (dEentValue < dGreaterThan)
2259 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE2), (FX_LPCWSTR)params[1].operator CFX_WideString());
2263 if (dEentValue > dLessThan)
2264 swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE3), (FX_LPCWSTR)params[3].operator CFX_WideString());
2267 if (!swMsg.IsEmpty())
2269 Alert(pContext, swMsg);
2270 pEvent->Rc() = FALSE;
2275 FX_BOOL CJS_PublicMethods::AFExtractNums(OBJ_METHOD_PARAMS)
2277 v8::Isolate* isolate = ::GetIsolate(cc);
2278 CJS_Context* pContext = (CJS_Context*)cc;
2279 ASSERT(pContext != NULL);
2281 if (params.size() != 1)
2283 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
2287 CJS_Array nums(isolate);
2289 CFX_WideString str = params[0].operator CFX_WideString();
2290 CFX_WideString sPart;
2292 if (str.GetAt(0) == L'.' || str.GetAt(0) == L',')
2296 for (int i=0, sz=str.GetLength(); i<sz; i++)
2298 FX_WCHAR wc = str.GetAt(i);
2299 if (IsDigit((wchar_t)wc))
2305 if (sPart.GetLength() > 0)
2307 nums.SetElement(nIndex,CJS_Value(isolate,(FX_LPCWSTR)sPart));
2314 if (sPart.GetLength() > 0)
2316 nums.SetElement(nIndex,CJS_Value(isolate,(FX_LPCWSTR)sPart));
2319 if (nums.GetLength() > 0)