PageRenderTime 66ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/fpdfsdk/src/javascript/PublicMethods.cpp

https://github.com/hunslater/pdfium
C++ | 2335 lines | 1952 code | 322 blank | 61 comment | 568 complexity | 14f9b37cb3cae786554e62184941a011 MD5 | raw file
Possible License(s): BSD-3-Clause

Large files files are truncated, but you can click here to view the full file

  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.
  4. // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
  5. #include "../../include/javascript/JavaScript.h"
  6. #include "../../include/javascript/IJavaScript.h"
  7. #include "../../include/javascript/JS_Define.h"
  8. #include "../../include/javascript/JS_Object.h"
  9. #include "../../include/javascript/JS_Value.h"
  10. #include "../../include/javascript/PublicMethods.h"
  11. #include "../../include/javascript/JS_EventHandler.h"
  12. #include "../../include/javascript/resource.h"
  13. #include "../../include/javascript/JS_Context.h"
  14. #include "../../include/javascript/JS_Value.h"
  15. #include "../../include/javascript/util.h"
  16. #include "../../include/javascript/Field.h"
  17. #include "../../include/javascript/color.h"
  18. #include "../../include/javascript/JS_Runtime.h"
  19. static v8::Isolate* GetIsolate(IFXJS_Context* cc)
  20. {
  21. CJS_Context* pContext = (CJS_Context *)cc;
  22. ASSERT(pContext != NULL);
  23. CJS_Runtime* pRuntime = pContext->GetJSRuntime();
  24. ASSERT(pRuntime != NULL);
  25. return pRuntime->GetIsolate();
  26. }
  27. /* -------------------------------- CJS_PublicMethods -------------------------------- */
  28. #define DOUBLE_CORRECT 0.000000000000001
  29. BEGIN_JS_STATIC_GLOBAL_FUN(CJS_PublicMethods)
  30. JS_STATIC_GLOBAL_FUN_ENTRY(AFNumber_Format,6)
  31. JS_STATIC_GLOBAL_FUN_ENTRY(AFNumber_Keystroke,6)
  32. JS_STATIC_GLOBAL_FUN_ENTRY(AFPercent_Format,2)
  33. JS_STATIC_GLOBAL_FUN_ENTRY(AFPercent_Keystroke,2)
  34. JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_FormatEx,1)
  35. JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_KeystrokeEx,1)
  36. JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_Format,1)
  37. JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_Keystroke,1)
  38. JS_STATIC_GLOBAL_FUN_ENTRY(AFTime_FormatEx,1)
  39. JS_STATIC_GLOBAL_FUN_ENTRY(AFTime_KeystrokeEx,1)
  40. JS_STATIC_GLOBAL_FUN_ENTRY(AFTime_Format,1)
  41. JS_STATIC_GLOBAL_FUN_ENTRY(AFTime_Keystroke,1)
  42. JS_STATIC_GLOBAL_FUN_ENTRY(AFSpecial_Format,1)
  43. JS_STATIC_GLOBAL_FUN_ENTRY(AFSpecial_Keystroke,1)
  44. JS_STATIC_GLOBAL_FUN_ENTRY(AFSpecial_KeystrokeEx,1)
  45. JS_STATIC_GLOBAL_FUN_ENTRY(AFSimple,3)
  46. JS_STATIC_GLOBAL_FUN_ENTRY(AFMakeNumber,1)
  47. JS_STATIC_GLOBAL_FUN_ENTRY(AFSimple_Calculate,2)
  48. JS_STATIC_GLOBAL_FUN_ENTRY(AFRange_Validate,4)
  49. JS_STATIC_GLOBAL_FUN_ENTRY(AFMergeChange,1)
  50. JS_STATIC_GLOBAL_FUN_ENTRY(AFParseDateEx,2)
  51. JS_STATIC_GLOBAL_FUN_ENTRY(AFExtractNums,1)
  52. END_JS_STATIC_GLOBAL_FUN()
  53. IMPLEMENT_JS_STATIC_GLOBAL_FUN(CJS_PublicMethods)
  54. struct stru_TbConvert
  55. {
  56. FX_LPCSTR lpszJSMark;
  57. FX_LPCSTR lpszCppMark;
  58. };
  59. static const stru_TbConvert fcTable[] = {"mmmm","%B",
  60. "mmm", "%b",
  61. "mm", "%m",
  62. //"m"
  63. "dddd","%A",
  64. "ddd", "%a",
  65. "dd", "%d",
  66. //"d", "%w",
  67. "yyyy","%Y",
  68. "yy", "%y",
  69. "HH", "%H",
  70. //"H"
  71. "hh", "%I",
  72. //"h"
  73. "MM", "%M",
  74. //"M"
  75. "ss", "%S",
  76. //"s
  77. "tt", "%p"
  78. //"t"
  79. };
  80. static FX_LPCWSTR months[] =
  81. {
  82. (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"
  83. };
  84. static FX_LPCWSTR fullmonths[] =
  85. {
  86. (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"
  87. };
  88. FX_BOOL CJS_PublicMethods::IsNumber(FX_LPCWSTR string)
  89. {
  90. CFX_WideString sTrim = StrTrim(string);
  91. FX_LPCWSTR pTrim = sTrim;
  92. FX_LPCWSTR p = pTrim;
  93. FX_BOOL bDot = FALSE;
  94. FX_BOOL bKXJS = FALSE;
  95. wchar_t c;
  96. while ((c = *p))
  97. {
  98. if (c == '.' || c == ',')
  99. {
  100. if (bDot) return FALSE;
  101. bDot = TRUE;
  102. }
  103. else if (c == '-' || c == '+')
  104. {
  105. if (p != pTrim)
  106. return FALSE;
  107. }
  108. else if (c == 'e' || c == 'E')
  109. {
  110. if (bKXJS) return FALSE;
  111. p++;
  112. c = *p;
  113. if (c == '+' || c == '-')
  114. {
  115. bKXJS = TRUE;
  116. }
  117. else
  118. {
  119. return FALSE;
  120. }
  121. }
  122. else if (!IsDigit(c))
  123. {
  124. return FALSE;
  125. }
  126. p++;
  127. }
  128. return TRUE;
  129. }
  130. FX_BOOL CJS_PublicMethods::IsDigit(wchar_t ch)
  131. {
  132. return (ch >= L'0' && ch <= L'9');
  133. }
  134. FX_BOOL CJS_PublicMethods::IsDigit(char ch)
  135. {
  136. return (ch >= '0' && ch <= '9');
  137. }
  138. FX_BOOL CJS_PublicMethods::IsAlphabetic(wchar_t ch)
  139. {
  140. return ((ch >= L'a' && ch <= L'z') || (ch >= L'A' && ch <= L'Z'));
  141. }
  142. FX_BOOL CJS_PublicMethods::IsAlphaNumeric(wchar_t ch)
  143. {
  144. return (IsDigit(ch) || IsAlphabetic(ch));
  145. }
  146. FX_BOOL CJS_PublicMethods::maskSatisfied(wchar_t c_Change,wchar_t c_Mask)
  147. {
  148. switch (c_Mask)
  149. {
  150. case L'9':
  151. return IsDigit(c_Change);
  152. case L'A':
  153. return IsAlphabetic(c_Change);
  154. case L'O':
  155. return IsAlphaNumeric(c_Change);
  156. case L'X':
  157. return TRUE;
  158. default:
  159. return (c_Change == c_Mask);
  160. }
  161. }
  162. FX_BOOL CJS_PublicMethods::isReservedMaskChar(wchar_t ch)
  163. {
  164. return ch == L'9' || ch == L'A' || ch == L'O' || ch == L'X';
  165. }
  166. double CJS_PublicMethods::AF_Simple(FX_LPCWSTR sFuction, double dValue1, double dValue2)
  167. {
  168. if (FXSYS_wcsicmp(sFuction,(FX_LPCWSTR)L"AVG") == 0 || FXSYS_wcsicmp(sFuction,(FX_LPCWSTR)L"SUM") == 0)
  169. {
  170. return dValue1 + dValue2;
  171. }
  172. else if (FXSYS_wcsicmp(sFuction, (FX_LPCWSTR)L"PRD") == 0)
  173. {
  174. return dValue1 * dValue2;
  175. }
  176. else if (FXSYS_wcsicmp(sFuction,(FX_LPCWSTR)L"MIN") == 0)
  177. {
  178. return FX_MIN(dValue1, dValue2);
  179. }
  180. else if (FXSYS_wcsicmp(sFuction,(FX_LPCWSTR)L"MAX") == 0)
  181. {
  182. return FX_MAX(dValue1, dValue2);
  183. }
  184. return dValue1;
  185. }
  186. CFX_WideString CJS_PublicMethods::StrLTrim(FX_LPCWSTR pStr)
  187. {
  188. while (*pStr && *pStr == L' ') pStr++;
  189. return pStr;
  190. }
  191. CFX_WideString CJS_PublicMethods::StrRTrim(FX_LPCWSTR pStr)
  192. {
  193. FX_LPCWSTR p = pStr;
  194. while (*p) p++;
  195. p--;
  196. if (p >= pStr)
  197. {
  198. while (*p && *p == L' ') p--;
  199. p++;
  200. return CFX_WideString(pStr,p-pStr);
  201. }
  202. return L"";
  203. }
  204. CFX_WideString CJS_PublicMethods::StrTrim(FX_LPCWSTR pStr)
  205. {
  206. return StrRTrim(StrLTrim(pStr));
  207. }
  208. CFX_ByteString CJS_PublicMethods::StrLTrim(FX_LPCSTR pStr)
  209. {
  210. while (*pStr && *pStr == ' ') pStr++;
  211. return pStr;
  212. }
  213. CFX_ByteString CJS_PublicMethods::StrRTrim(FX_LPCSTR pStr)
  214. {
  215. FX_LPCSTR p = pStr;
  216. while (*p) p++;
  217. p--;
  218. if (p >= pStr)
  219. {
  220. while (*p && *p == ' ') p--;
  221. p++;
  222. return CFX_ByteString(pStr,p-pStr);
  223. }
  224. return "";
  225. }
  226. CFX_ByteString CJS_PublicMethods::StrTrim(FX_LPCSTR pStr)
  227. {
  228. return StrRTrim(StrLTrim(pStr));
  229. }
  230. double CJS_PublicMethods::ParseNumber(FX_LPCWSTR swSource, FX_BOOL& bAllDigits, FX_BOOL& bDot, FX_BOOL& bSign, FX_BOOL& bKXJS)
  231. {
  232. bDot = FALSE;
  233. bSign = FALSE;
  234. bKXJS = FALSE;
  235. FX_BOOL bDigitExist = FALSE;
  236. FX_LPCWSTR p = swSource;
  237. wchar_t c;
  238. FX_LPCWSTR pStart = NULL;
  239. FX_LPCWSTR pEnd = NULL;
  240. while ((c = *p))
  241. {
  242. if (!pStart && c != L' ')
  243. {
  244. pStart = p;
  245. }
  246. pEnd = p;
  247. p++;
  248. }
  249. if (!pStart)
  250. {
  251. bAllDigits = FALSE;
  252. return 0;
  253. }
  254. while (pEnd != pStart)
  255. {
  256. if (*pEnd == L' ')
  257. pEnd --;
  258. else
  259. break;
  260. }
  261. double dRet = 0;
  262. p = pStart;
  263. bAllDigits = TRUE;
  264. CFX_WideString swDigits;
  265. while (p <= pEnd)
  266. {
  267. c = *p;
  268. if (IsDigit(c))
  269. {
  270. swDigits += c;
  271. bDigitExist = TRUE;
  272. }
  273. else
  274. {
  275. switch (c)
  276. {
  277. case L' ':
  278. bAllDigits = FALSE;
  279. break;
  280. case L'.':
  281. case L',':
  282. if (!bDot)
  283. {
  284. if (bDigitExist)
  285. {
  286. swDigits += L'.';
  287. }
  288. else
  289. {
  290. swDigits += L'0';
  291. swDigits += L'.';
  292. bDigitExist = TRUE;
  293. }
  294. bDot = TRUE;
  295. break;
  296. }
  297. case 'e':
  298. case 'E':
  299. if (!bKXJS)
  300. {
  301. p++;
  302. c = *p;
  303. if (c == '+' || c == '-')
  304. {
  305. bKXJS = TRUE;
  306. swDigits += 'e';
  307. swDigits += c;
  308. }
  309. break;
  310. }
  311. case L'-':
  312. if (!bDigitExist && !bSign)
  313. {
  314. swDigits += c;
  315. bSign = TRUE;
  316. break;
  317. }
  318. default:
  319. bAllDigits = FALSE;
  320. if (p != pStart && !bDot && bDigitExist)
  321. {
  322. swDigits += L'.';
  323. bDot = TRUE;
  324. }
  325. else
  326. {
  327. bDot = FALSE;
  328. bDigitExist = FALSE;
  329. swDigits = L"";
  330. }
  331. break;
  332. }
  333. }
  334. p++;
  335. }
  336. if (swDigits.GetLength() > 0 && swDigits.GetLength() < 17)
  337. {
  338. CFX_ByteString sDigits = swDigits.UTF8Encode();
  339. if (bKXJS)
  340. {
  341. dRet = atof(sDigits);
  342. }
  343. else
  344. {
  345. if (bDot)
  346. {
  347. char* pStopString;
  348. dRet = ::strtod(sDigits, &pStopString);
  349. }
  350. else
  351. {
  352. dRet = atol(sDigits);
  353. }
  354. }
  355. }
  356. return dRet;
  357. }
  358. double CJS_PublicMethods::ParseStringToNumber(FX_LPCWSTR swSource)
  359. {
  360. FX_BOOL bAllDigits = FALSE;
  361. FX_BOOL bDot = FALSE;
  362. FX_BOOL bSign = FALSE;
  363. FX_BOOL bKXJS = FALSE;
  364. return ParseNumber(swSource, bAllDigits, bDot, bSign, bKXJS);
  365. }
  366. FX_BOOL CJS_PublicMethods::ConvertStringToNumber(FX_LPCWSTR swSource, double & dRet, FX_BOOL & bDot)
  367. {
  368. FX_BOOL bAllDigits = FALSE;
  369. FX_BOOL bSign = FALSE;
  370. FX_BOOL bKXJS = FALSE;
  371. dRet = ParseNumber(swSource, bAllDigits, bDot, bSign, bKXJS);
  372. return bAllDigits;
  373. }
  374. CJS_Array CJS_PublicMethods::AF_MakeArrayFromList(v8::Isolate* isolate, CJS_Value val)
  375. {
  376. CJS_Array StrArray(isolate);
  377. if(val.IsArrayObject())
  378. {
  379. val.ConvertToArray(StrArray);
  380. return StrArray;
  381. }
  382. CFX_WideString wsStr = val.operator CFX_WideString();
  383. CFX_ByteString t = CFX_ByteString::FromUnicode(wsStr);
  384. const char * p = (const char *)t;
  385. int ch = ',' ;
  386. int nIndex = 0;
  387. while (*p)
  388. {
  389. const char * pTemp = strchr(p, ch);
  390. if (pTemp == NULL)
  391. {
  392. StrArray.SetElement(nIndex, CJS_Value(isolate,(FX_LPCSTR)StrTrim(p)));
  393. break;
  394. }
  395. else
  396. {
  397. char * pSub = new char[pTemp - p + 1];
  398. strncpy(pSub, p, pTemp - p);
  399. *(pSub + (pTemp - p)) = '\0';
  400. StrArray.SetElement(nIndex, CJS_Value(isolate,(FX_LPCSTR)StrTrim(pSub)));
  401. delete []pSub;
  402. nIndex ++;
  403. p = ++pTemp;
  404. }
  405. }
  406. return StrArray;
  407. }
  408. int CJS_PublicMethods::ParseStringInteger(const CFX_WideString& string,int nStart,int& nSkip, int nMaxStep)
  409. {
  410. int nRet = 0;
  411. nSkip = 0;
  412. for (int i=nStart, sz=string.GetLength(); i < sz; i++)
  413. {
  414. if (i-nStart > 10)
  415. break;
  416. FX_WCHAR c = string.GetAt(i);
  417. if (IsDigit((wchar_t)c))
  418. {
  419. nRet = nRet * 10 + (c - '0');
  420. nSkip = i - nStart + 1;
  421. if (nSkip >= nMaxStep)
  422. break;
  423. }
  424. else
  425. break;
  426. }
  427. return nRet;
  428. }
  429. CFX_WideString CJS_PublicMethods::ParseStringString(const CFX_WideString& string, int nStart, int& nSkip)
  430. {
  431. CFX_WideString swRet;
  432. nSkip = 0;
  433. for (int i=nStart, sz=string.GetLength(); i < sz; i++)
  434. {
  435. FX_WCHAR c = string.GetAt(i);
  436. if ((c >= L'a' && c <= L'z') || (c >= L'A' && c <= L'Z'))
  437. {
  438. swRet += c;
  439. nSkip = i - nStart + 1;
  440. }
  441. else
  442. break;
  443. }
  444. return swRet;
  445. }
  446. double CJS_PublicMethods::ParseNormalDate(const CFX_WideString & value, FX_BOOL& bWrongFormat)
  447. {
  448. double dt = JS_GetDateTime();
  449. int nYear = JS_GetYearFromTime(dt);
  450. int nMonth = JS_GetMonthFromTime(dt) + 1;
  451. int nDay = JS_GetDayFromTime(dt);
  452. int nHour = JS_GetHourFromTime(dt);
  453. int nMin = JS_GetMinFromTime(dt);
  454. int nSec = JS_GetSecFromTime(dt);
  455. int number[3];
  456. int nSkip = 0;
  457. int nLen = value.GetLength();
  458. int nIndex = 0;
  459. int i = 0;
  460. while (i < nLen)
  461. {
  462. if (nIndex > 2) break;
  463. FX_WCHAR c = value.GetAt(i);
  464. if (IsDigit((wchar_t)c))
  465. {
  466. number[nIndex++] = ParseStringInteger(value, i, nSkip, 4);
  467. i += nSkip;
  468. }
  469. else
  470. {
  471. i ++;
  472. }
  473. }
  474. if (nIndex == 2)
  475. {
  476. // case2: month/day
  477. // case3: day/month
  478. if ((number[0] >= 1 && number[0] <= 12) && (number[1] >= 1 && number[1] <= 31))
  479. {
  480. nMonth = number[0];
  481. nDay = number[1];
  482. }
  483. else if ((number[0] >= 1 && number[0] <= 31) && (number[1] >= 1 && number[1] <= 12))
  484. {
  485. nDay = number[0];
  486. nMonth = number[1];
  487. }
  488. bWrongFormat = FALSE;
  489. }
  490. else if (nIndex == 3)
  491. {
  492. // case1: year/month/day
  493. // case2: month/day/year
  494. // case3: day/month/year
  495. if (number[0] > 12 && (number[1] >= 1 && number[1] <= 12) && (number[2] >= 1 && number[2] <= 31))
  496. {
  497. nYear = number[0];
  498. nMonth = number[1];
  499. nDay = number[2];
  500. }
  501. else if ((number[0] >= 1 && number[0] <= 12) && (number[1] >= 1 && number[1] <= 31) && number[2] > 31)
  502. {
  503. nMonth = number[0];
  504. nDay = number[1];
  505. nYear = number[2];
  506. }
  507. else if ((number[0] >= 1 && number[0] <= 31) && (number[1] >= 1 && number[1] <= 12) && number[2] > 31)
  508. {
  509. nDay = number[0];
  510. nMonth = number[1];
  511. nYear = number[2];
  512. }
  513. bWrongFormat = FALSE;
  514. }
  515. else
  516. {
  517. bWrongFormat = TRUE;
  518. return dt;
  519. }
  520. CFX_WideString swTemp;
  521. swTemp.Format((FX_LPCWSTR)L"%d/%d/%d %d:%d:%d",nMonth,nDay,nYear,nHour,nMin,nSec);
  522. return JS_DateParse(swTemp);
  523. }
  524. double CJS_PublicMethods::MakeRegularDate(const CFX_WideString & value, const CFX_WideString & format, FX_BOOL& bWrongFormat)
  525. {
  526. double dt = JS_GetDateTime();
  527. if (format.IsEmpty() || value.IsEmpty())
  528. return dt;
  529. int nYear = JS_GetYearFromTime(dt);
  530. int nMonth = JS_GetMonthFromTime(dt) + 1;
  531. int nDay = JS_GetDayFromTime(dt);
  532. int nHour = JS_GetHourFromTime(dt);
  533. int nMin = JS_GetMinFromTime(dt);
  534. int nSec = JS_GetSecFromTime(dt);
  535. int nYearSub = 99; //nYear - 2000;
  536. FX_BOOL bPm = FALSE;
  537. FX_BOOL bExit = FALSE;
  538. bWrongFormat = FALSE;
  539. int i=0;
  540. int j=0;
  541. while (i < format.GetLength())
  542. {
  543. if (bExit) break;
  544. FX_WCHAR c = format.GetAt(i);
  545. switch (c)
  546. {
  547. case ':':
  548. case '.':
  549. case '-':
  550. case '\\':
  551. case '/':
  552. i++;
  553. j++;
  554. break;
  555. case 'y':
  556. case 'm':
  557. case 'd':
  558. case 'H':
  559. case 'h':
  560. case 'M':
  561. case 's':
  562. case 't':
  563. {
  564. int oldj = j;
  565. int nSkip = 0;
  566. if (format.GetAt(i+1) != c)
  567. {
  568. switch (c)
  569. {
  570. case 'y':
  571. i++;
  572. j++;
  573. break;
  574. case 'm':
  575. nMonth = ParseStringInteger(value, j, nSkip, 2);
  576. i++;
  577. j += nSkip;
  578. break;
  579. case 'd':
  580. nDay = ParseStringInteger(value, j, nSkip, 2);
  581. i++;
  582. j += nSkip;
  583. break;
  584. case 'H':
  585. nHour = ParseStringInteger(value, j, nSkip, 2);
  586. i++;
  587. j += nSkip;
  588. break;
  589. case 'h':
  590. nHour = ParseStringInteger(value, j, nSkip, 2);
  591. i++;
  592. j += nSkip;
  593. break;
  594. case 'M':
  595. nMin = ParseStringInteger(value, j, nSkip, 2);
  596. i++;
  597. j += nSkip;
  598. break;
  599. case 's':
  600. nSec = ParseStringInteger(value, j, nSkip, 2);
  601. i++;
  602. j += nSkip;
  603. break;
  604. case 't':
  605. bPm = value.GetAt(i) == 'p';
  606. i++;
  607. j++;
  608. break;
  609. }
  610. }
  611. else if (format.GetAt(i+1) == c && format.GetAt(i+2) != c)
  612. {
  613. switch (c)
  614. {
  615. case 'y':
  616. nYear = ParseStringInteger(value, j, nSkip, 4);
  617. i += 2;
  618. j += nSkip;
  619. break;
  620. case 'm':
  621. nMonth = ParseStringInteger(value, j, nSkip, 2);
  622. i += 2;
  623. j += nSkip;
  624. break;
  625. case 'd':
  626. nDay = ParseStringInteger(value, j, nSkip, 2);
  627. i += 2;
  628. j += nSkip;
  629. break;
  630. case 'H':
  631. nHour = ParseStringInteger(value, j, nSkip, 2);
  632. i += 2;
  633. j += nSkip;
  634. break;
  635. case 'h':
  636. nHour = ParseStringInteger(value, j, nSkip, 2);
  637. i += 2;
  638. j += nSkip;
  639. break;
  640. case 'M':
  641. nMin = ParseStringInteger(value, j, nSkip, 2);
  642. i += 2;
  643. j += nSkip;
  644. break;
  645. case 's':
  646. nSec = ParseStringInteger(value, j, nSkip, 2);
  647. i += 2;
  648. j += nSkip;
  649. break;
  650. case 't':
  651. bPm = (value.GetAt(j) == 'p' && value.GetAt(j+1) == 'm');
  652. i += 2;
  653. j += 2;
  654. break;
  655. }
  656. }
  657. else if (format.GetAt(i+1) == c && format.GetAt(i+2) == c && format.GetAt(i+3) != c)
  658. {
  659. switch (c)
  660. {
  661. case 'm':
  662. {
  663. CFX_WideString sMonth = ParseStringString(value, j, nSkip);
  664. FX_BOOL bFind = FALSE;
  665. for (int m = 0; m < 12; m++)
  666. {
  667. if (sMonth.CompareNoCase(months[m]) == 0)
  668. {
  669. nMonth = m + 1;
  670. i+=3;
  671. j+=nSkip;
  672. bFind = TRUE;
  673. break;
  674. }
  675. }
  676. if (!bFind)
  677. {
  678. nMonth = ParseStringInteger(value, j, nSkip, 3);
  679. i+=3;
  680. j += nSkip;
  681. }
  682. }
  683. break;
  684. case 'y':
  685. break;
  686. default:
  687. i+=3;
  688. j+=3;
  689. break;
  690. }
  691. }
  692. else if (format.GetAt(i+1) == c && format.GetAt(i+2) == c && format.GetAt(i+3) == c && format.GetAt(i+4) != c)
  693. {
  694. switch (c)
  695. {
  696. case 'y':
  697. nYear = ParseStringInteger(value, j, nSkip, 4);
  698. j += nSkip;
  699. i += 4;
  700. break;
  701. case 'm':
  702. {
  703. FX_BOOL bFind = FALSE;
  704. CFX_WideString sMonth = ParseStringString(value, j, nSkip);
  705. sMonth.MakeLower();
  706. for (int m = 0; m < 12; m++)
  707. {
  708. CFX_WideString sFullMonths = fullmonths[m];
  709. sFullMonths.MakeLower();
  710. if (sFullMonths.Find(sMonth, 0) != -1)
  711. {
  712. nMonth = m + 1;
  713. i += 4;
  714. j += nSkip;
  715. bFind = TRUE;
  716. break;
  717. }
  718. }
  719. if (!bFind)
  720. {
  721. nMonth = ParseStringInteger(value, j, nSkip, 4);
  722. i+=4;
  723. j += nSkip;
  724. }
  725. }
  726. break;
  727. default:
  728. i += 4;
  729. j += 4;
  730. break;
  731. }
  732. }
  733. else
  734. {
  735. if (format.GetAt(i) != value.GetAt(j))
  736. {
  737. bWrongFormat = TRUE;
  738. bExit = TRUE;
  739. }
  740. i++;
  741. j++;
  742. }
  743. if (oldj == j)
  744. {
  745. bWrongFormat = TRUE;
  746. bExit = TRUE;
  747. }
  748. }
  749. break;
  750. default:
  751. if (value.GetLength() <= j)
  752. {
  753. bExit = TRUE;
  754. }
  755. else if (format.GetAt(i) != value.GetAt(j))
  756. {
  757. bWrongFormat = TRUE;
  758. bExit = TRUE;
  759. }
  760. i++;
  761. j++;
  762. break;
  763. }
  764. }
  765. if (bPm) nHour += 12;
  766. if (nYear >= 0 && nYear <= nYearSub)
  767. nYear += 2000;
  768. if (nMonth < 1 || nMonth > 12)
  769. bWrongFormat = TRUE;
  770. if (nDay < 1 || nDay > 31)
  771. bWrongFormat = TRUE;
  772. if (nHour < 0 || nHour > 24)
  773. bWrongFormat = TRUE;
  774. if (nMin < 0 || nMin > 60)
  775. bWrongFormat = TRUE;
  776. if (nSec < 0 || nSec > 60)
  777. bWrongFormat = TRUE;
  778. double dRet = 0;
  779. if (bWrongFormat)
  780. {
  781. dRet = ParseNormalDate(value, bWrongFormat);
  782. }
  783. else
  784. {
  785. dRet = JS_MakeDate(JS_MakeDay(nYear,nMonth - 1,nDay),JS_MakeTime(nHour, nMin, nSec, 0));
  786. if (JS_PortIsNan(dRet))
  787. {
  788. dRet = JS_DateParse(value);
  789. }
  790. }
  791. if (JS_PortIsNan(dRet))
  792. {
  793. dRet = ParseNormalDate(value, bWrongFormat);
  794. }
  795. return dRet;
  796. }
  797. CFX_WideString CJS_PublicMethods::MakeFormatDate(double dDate, const CFX_WideString & format)
  798. {
  799. CFX_WideString sRet = L"",sPart = L"";
  800. int nYear = JS_GetYearFromTime(dDate);
  801. int nMonth = JS_GetMonthFromTime(dDate) + 1;
  802. int nDay = JS_GetDayFromTime(dDate);
  803. int nHour = JS_GetHourFromTime(dDate);
  804. int nMin = JS_GetMinFromTime(dDate);
  805. int nSec = JS_GetSecFromTime(dDate);
  806. int i = 0;
  807. FX_WCHAR c;
  808. while (i < format.GetLength())
  809. {
  810. c = format.GetAt(i);
  811. sPart = L"";
  812. switch (c)
  813. {
  814. case 'y':
  815. case 'm':
  816. case 'd':
  817. case 'H':
  818. case 'h':
  819. case 'M':
  820. case 's':
  821. case 't':
  822. if (format.GetAt(i+1) != c)
  823. {
  824. switch (c)
  825. {
  826. case 'y':
  827. sPart += c;
  828. break;
  829. case 'm':
  830. sPart.Format((FX_LPCWSTR)L"%d",nMonth);
  831. break;
  832. case 'd':
  833. sPart.Format((FX_LPCWSTR)L"%d",nDay);
  834. break;
  835. case 'H':
  836. sPart.Format((FX_LPCWSTR)L"%d",nHour);
  837. break;
  838. case 'h':
  839. sPart.Format((FX_LPCWSTR)L"%d",nHour>12?nHour - 12:nHour);
  840. break;
  841. case 'M':
  842. sPart.Format((FX_LPCWSTR)L"%d",nMin);
  843. break;
  844. case 's':
  845. sPart.Format((FX_LPCWSTR)L"%d",nSec);
  846. break;
  847. case 't':
  848. sPart += nHour>12?'p':'a';
  849. break;
  850. }
  851. i++;
  852. }
  853. else if (format.GetAt(i+1) == c && format.GetAt(i+2) != c)
  854. {
  855. switch (c)
  856. {
  857. case 'y':
  858. sPart.Format((FX_LPCWSTR)L"%02d",nYear - (nYear / 100) * 100);
  859. break;
  860. case 'm':
  861. sPart.Format((FX_LPCWSTR)L"%02d",nMonth);
  862. break;
  863. case 'd':
  864. sPart.Format((FX_LPCWSTR)L"%02d",nDay);
  865. break;
  866. case 'H':
  867. sPart.Format((FX_LPCWSTR)L"%02d",nHour);
  868. break;
  869. case 'h':
  870. sPart.Format((FX_LPCWSTR)L"%02d",nHour>12?nHour - 12:nHour);
  871. break;
  872. case 'M':
  873. sPart.Format((FX_LPCWSTR)L"%02d",nMin);
  874. break;
  875. case 's':
  876. sPart.Format((FX_LPCWSTR)L"%02d",nSec);
  877. break;
  878. case 't':
  879. sPart = nHour>12? (FX_LPCWSTR)L"pm": (FX_LPCWSTR)L"am";
  880. break;
  881. }
  882. i+=2;
  883. }
  884. else if (format.GetAt(i+1) == c && format.GetAt(i+2) == c && format.GetAt(i+3) != c)
  885. {
  886. switch (c)
  887. {
  888. case 'm':
  889. i+=3;
  890. if (nMonth > 0&&nMonth <= 12)
  891. sPart += months[nMonth - 1];
  892. break;
  893. default:
  894. i+=3;
  895. sPart += c;
  896. sPart += c;
  897. sPart += c;
  898. break;
  899. }
  900. }
  901. else if (format.GetAt(i+1) == c && format.GetAt(i+2) == c && format.GetAt(i+3) == c && format.GetAt(i+4) != c)
  902. {
  903. switch (c)
  904. {
  905. case 'y':
  906. sPart.Format((FX_LPCWSTR)L"%04d",nYear);
  907. i += 4;
  908. break;
  909. case 'm':
  910. i+=4;
  911. if (nMonth > 0&&nMonth <= 12)
  912. sPart += fullmonths[nMonth - 1];
  913. break;
  914. default:
  915. i += 4;
  916. sPart += c;
  917. sPart += c;
  918. sPart += c;
  919. sPart += c;
  920. break;
  921. }
  922. }
  923. else
  924. {
  925. i++;
  926. sPart += c;
  927. }
  928. break;
  929. default:
  930. i++;
  931. sPart += c;
  932. break;
  933. }
  934. sRet += sPart;
  935. }
  936. return sRet;
  937. }
  938. /* -------------------------------------------------------------------------- */
  939. //function AFNumber_Format(nDec, sepStyle, negStyle, currStyle, strCurrency, bCurrencyPrepend)
  940. FX_BOOL CJS_PublicMethods::AFNumber_Format(OBJ_METHOD_PARAMS)
  941. {
  942. #if _FX_OS_ != _FX_ANDROID_
  943. v8::Isolate* isolate = ::GetIsolate(cc);
  944. CJS_Context* pContext = (CJS_Context *)cc;
  945. ASSERT(pContext != NULL);
  946. CJS_EventHandler* pEvent = pContext->GetEventHandler();
  947. ASSERT(pEvent != NULL);
  948. if (params.size() != 6)
  949. {
  950. sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
  951. return FALSE;
  952. }
  953. if(!pEvent->m_pValue)
  954. return FALSE;
  955. CFX_WideString& Value = pEvent->Value();
  956. CFX_ByteString strValue = StrTrim(CFX_ByteString::FromUnicode(Value));
  957. if (strValue.IsEmpty()) return TRUE;
  958. int iDec = params[0];
  959. int iSepStyle = params[1];
  960. int iNegStyle = params[2];
  961. int icurrStyle = params[3]; //it's no use!
  962. std::wstring wstrCurrency(params[4].operator CFX_WideString());
  963. FX_BOOL bCurrencyPrepend = params[5];
  964. if (iDec < 0) iDec = -iDec;
  965. if (iSepStyle < 0 || iSepStyle > 3)
  966. iSepStyle = 0;
  967. if (iNegStyle < 0 || iNegStyle > 3)
  968. iNegStyle = 0;
  969. //////////////////////////////////////////////////////
  970. //for processing decimal places
  971. strValue.Replace(",", ".");
  972. double dValue = atof(strValue);
  973. if (iDec > 0)
  974. dValue += DOUBLE_CORRECT;//
  975. int iDec2;
  976. FX_BOOL bNagative = FALSE;
  977. strValue = fcvt(dValue,iDec,&iDec2,&bNagative);
  978. if (strValue.IsEmpty())
  979. {
  980. dValue = 0;
  981. strValue = fcvt(dValue,iDec,&iDec2,&bNagative);
  982. if (strValue.IsEmpty())
  983. {
  984. strValue = "0";
  985. iDec2 = 1;
  986. }
  987. }
  988. if (iDec2 < 0)
  989. {
  990. for (int iNum = 0;iNum < abs(iDec2);iNum++)
  991. {
  992. strValue = "0" + strValue;
  993. }
  994. iDec2 = 0;
  995. }
  996. int iMax = strValue.GetLength();
  997. if (iDec2 > iMax)
  998. {
  999. for (int iNum = 0;iNum <= iDec2 - iMax ;iNum++)
  1000. {
  1001. strValue += "0";
  1002. }
  1003. iMax = iDec2+1;
  1004. }
  1005. ///////////////////////////////////////////////////////
  1006. //for processing seperator style
  1007. if (iDec2 < iMax)
  1008. {
  1009. if (iSepStyle == 0 || iSepStyle == 1)
  1010. {
  1011. strValue.Insert(iDec2, '.');
  1012. iMax++;
  1013. }
  1014. else if (iSepStyle == 2 || iSepStyle == 3)
  1015. {
  1016. strValue.Insert(iDec2, ',');
  1017. iMax++;
  1018. }
  1019. if (iDec2 == 0)
  1020. strValue.Insert(iDec2, '0');
  1021. }
  1022. if (iSepStyle == 0 || iSepStyle == 2)
  1023. {
  1024. char cSeperator;
  1025. if (iSepStyle == 0)
  1026. cSeperator = ',';
  1027. else
  1028. cSeperator = '.';
  1029. int iDecPositive,iDecNagative;
  1030. iDecPositive = iDec2;
  1031. iDecNagative = iDec2;
  1032. for (iDecPositive = iDec2 -3; iDecPositive > 0;iDecPositive -= 3)
  1033. {
  1034. strValue.Insert(iDecPositive, cSeperator);
  1035. iMax++;
  1036. }
  1037. }
  1038. //////////////////////////////////////////////////////////////////////
  1039. //for processing currency string
  1040. Value = CFX_WideString::FromLocal(strValue);
  1041. std::wstring strValue2(Value);
  1042. if (bCurrencyPrepend)
  1043. strValue2 = wstrCurrency + strValue2;
  1044. else
  1045. strValue2 = strValue2 + wstrCurrency;
  1046. /////////////////////////////////////////////////////////////////////////
  1047. //for processing negative style
  1048. if (bNagative)
  1049. {
  1050. if (iNegStyle == 0)
  1051. {
  1052. strValue2.insert(0,L"-");
  1053. }
  1054. if (iNegStyle == 2 || iNegStyle == 3)
  1055. {
  1056. strValue2.insert(0,L"(");
  1057. strValue2.insert(strValue2.length(),L")");
  1058. }
  1059. if (iNegStyle == 1 || iNegStyle == 3)
  1060. {
  1061. if (Field * fTarget = pEvent->Target_Field())
  1062. {
  1063. CJS_Array arColor(isolate);
  1064. CJS_Value vColElm(isolate);
  1065. vColElm = L"RGB";
  1066. arColor.SetElement(0,vColElm);
  1067. vColElm = 1;
  1068. arColor.SetElement(1,vColElm);
  1069. vColElm = 0;
  1070. arColor.SetElement(2,vColElm);
  1071. arColor.SetElement(3,vColElm);
  1072. CJS_PropValue vProp(isolate);
  1073. vProp.StartGetting();
  1074. vProp<<arColor;
  1075. vProp.StartSetting();
  1076. fTarget->textColor(cc,vProp,sError);// red
  1077. }
  1078. }
  1079. }
  1080. else
  1081. {
  1082. if (iNegStyle == 1 || iNegStyle == 3)
  1083. {
  1084. if (Field *fTarget = pEvent->Target_Field())
  1085. {
  1086. CJS_Array arColor(isolate);
  1087. CJS_Value vColElm(isolate);
  1088. vColElm = L"RGB";
  1089. arColor.SetElement(0,vColElm);
  1090. vColElm = 0;
  1091. arColor.SetElement(1,vColElm);
  1092. arColor.SetElement(2,vColElm);
  1093. arColor.SetElement(3,vColElm);
  1094. CJS_PropValue vProp(isolate);
  1095. vProp.StartGetting();
  1096. fTarget->textColor(cc,vProp,sError);
  1097. CJS_Array aProp(isolate);
  1098. vProp.ConvertToArray(aProp);
  1099. CPWL_Color crProp;
  1100. CPWL_Color crColor;
  1101. color::ConvertArrayToPWLColor(aProp, crProp);
  1102. color::ConvertArrayToPWLColor(arColor, crColor);
  1103. if (crColor != crProp)
  1104. {
  1105. CJS_PropValue vProp2(isolate);
  1106. vProp2.StartGetting();
  1107. vProp2<<arColor;
  1108. vProp2.StartSetting();
  1109. fTarget->textColor(cc,vProp2,sError);
  1110. }
  1111. }
  1112. }
  1113. }
  1114. Value = strValue2.c_str();
  1115. #endif
  1116. return TRUE;
  1117. }
  1118. //function AFNumber_Keystroke(nDec, sepStyle, negStyle, currStyle, strCurrency, bCurrencyPrepend)
  1119. FX_BOOL CJS_PublicMethods::AFNumber_Keystroke(OBJ_METHOD_PARAMS)
  1120. {
  1121. CJS_Context* pContext = (CJS_Context *)cc;
  1122. ASSERT(pContext != NULL);
  1123. CJS_EventHandler* pEvent = pContext->GetEventHandler();
  1124. ASSERT(pEvent != NULL);
  1125. if(params.size() < 2)
  1126. return FALSE;
  1127. int iSepStyle = params[1];
  1128. if (iSepStyle < 0 || iSepStyle > 3)
  1129. iSepStyle = 0;
  1130. if(!pEvent->m_pValue)
  1131. return FALSE;
  1132. CFX_WideString & val = pEvent->Value();
  1133. CFX_WideString & w_strChange = pEvent->Change();
  1134. CFX_WideString w_strValue = val;
  1135. if (pEvent->WillCommit())
  1136. {
  1137. CFX_WideString wstrChange = w_strChange;
  1138. CFX_WideString wstrValue = StrLTrim(w_strValue);
  1139. if (wstrValue.IsEmpty())
  1140. return TRUE;
  1141. CFX_WideString swTemp = wstrValue;
  1142. swTemp.Replace((FX_LPCWSTR)L",", (FX_LPCWSTR)L".");
  1143. if (!IsNumber(swTemp)) //!(IsNumber(wstrChange) &&
  1144. {
  1145. pEvent->Rc() = FALSE;
  1146. sError = JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYSTROKE);
  1147. Alert(pContext, sError);
  1148. return TRUE;
  1149. }
  1150. return TRUE; // it happens after the last keystroke and before validating,
  1151. }
  1152. std::wstring w_strValue2 (w_strValue);
  1153. std::wstring w_strChange2(w_strChange);
  1154. std::wstring w_strSelected;
  1155. if(-1 != pEvent->SelStart())
  1156. w_strSelected = w_strValue2.substr(pEvent->SelStart(),(pEvent->SelEnd() - pEvent->SelStart()));
  1157. FX_BOOL bHasSign = (w_strValue2.find('-') != -1) && (w_strSelected.find('-') == -1);
  1158. if (bHasSign)
  1159. {
  1160. //can't insert "change" in front to sign postion.
  1161. if (pEvent->SelStart() == 0)
  1162. {
  1163. FX_BOOL &bRc = pEvent->Rc();
  1164. bRc = FALSE;
  1165. return TRUE;
  1166. }
  1167. }
  1168. char cSep = L'.';
  1169. switch (iSepStyle)
  1170. {
  1171. case 0:
  1172. case 1:
  1173. cSep = L'.';
  1174. break;
  1175. case 2:
  1176. case 3:
  1177. cSep = L',';
  1178. break;
  1179. }
  1180. FX_BOOL bHasSep = (w_strValue2.find(cSep) != -1);
  1181. for (std::wstring::iterator it = w_strChange2.begin(); it != w_strChange2.end(); it++)
  1182. {
  1183. if (*it == cSep)
  1184. {
  1185. if (bHasSep)
  1186. {
  1187. FX_BOOL &bRc = pEvent->Rc();
  1188. bRc = FALSE;
  1189. return TRUE;
  1190. }
  1191. else
  1192. {
  1193. bHasSep = TRUE;
  1194. continue;
  1195. }
  1196. }
  1197. if (*it == L'-')
  1198. {
  1199. if (bHasSign)
  1200. {
  1201. FX_BOOL &bRc = pEvent->Rc();
  1202. bRc = FALSE;
  1203. return TRUE;
  1204. }
  1205. else if (it != w_strChange2.begin()) //sign's position is not correct
  1206. {
  1207. FX_BOOL &bRc = pEvent->Rc();
  1208. bRc = FALSE;
  1209. return TRUE;
  1210. }
  1211. else if (pEvent->SelStart() != 0)
  1212. {
  1213. FX_BOOL &bRc = pEvent->Rc();
  1214. bRc = FALSE;
  1215. return TRUE;
  1216. }
  1217. bHasSign = TRUE;
  1218. continue;
  1219. }
  1220. if (!IsDigit(*it))
  1221. {
  1222. FX_BOOL &bRc = pEvent->Rc();
  1223. bRc = FALSE;
  1224. return TRUE;
  1225. }
  1226. }
  1227. std::wstring w_prefix = w_strValue2.substr(0,pEvent->SelStart());
  1228. std::wstring w_postfix;
  1229. if (pEvent->SelEnd()<(int)w_strValue2.length())
  1230. w_postfix = w_strValue2.substr(pEvent->SelEnd());
  1231. w_strValue2 = w_prefix + w_strChange2 + w_postfix;
  1232. w_strValue = w_strValue2.c_str();
  1233. val = w_strValue;
  1234. return TRUE;
  1235. }
  1236. //function AFPercent_Format(nDec, sepStyle)
  1237. FX_BOOL CJS_PublicMethods::AFPercent_Format(OBJ_METHOD_PARAMS)
  1238. {
  1239. #if _FX_OS_ != _FX_ANDROID_
  1240. CJS_Context* pContext = (CJS_Context *)cc;
  1241. ASSERT(pContext != NULL);
  1242. CJS_EventHandler* pEvent = pContext->GetEventHandler();
  1243. ASSERT(pEvent != NULL);
  1244. if (params.size() != 2)
  1245. {
  1246. sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
  1247. return FALSE;
  1248. }
  1249. if(!pEvent->m_pValue)
  1250. return FALSE;
  1251. CFX_WideString& Value = pEvent->Value();
  1252. // HWND hMainFrame = NULL;
  1253. //
  1254. // CPDFSDK_FormFillApp *pApp = pContext->GetReaderApp();
  1255. // ASSERT(pApp);
  1256. // hMainFrame = pApp->GetMainFrameWnd();
  1257. CFX_ByteString strValue = StrTrim(CFX_ByteString::FromUnicode(Value));
  1258. if (strValue.IsEmpty())
  1259. return TRUE;
  1260. int iDec = params[0];
  1261. int iSepStyle = params[1];
  1262. //ASSERT(iDec > 0);
  1263. if (iDec < 0)
  1264. iDec = -iDec;
  1265. if (iSepStyle < 0 || iSepStyle > 3)
  1266. iSepStyle = 0;
  1267. //////////////////////////////////////////////////////
  1268. //for processing decimal places
  1269. double dValue = atof(strValue);
  1270. dValue *= 100;
  1271. if (iDec > 0)
  1272. dValue += DOUBLE_CORRECT;//校正
  1273. int iDec2;
  1274. FX_BOOL bNagative = FALSE;
  1275. strValue = fcvt(dValue,iDec,&iDec2,&bNagative);
  1276. if (strValue.IsEmpty())
  1277. {
  1278. dValue = 0;
  1279. strValue = fcvt(dValue,iDec,&iDec2,&bNagative);
  1280. }
  1281. if (iDec2 < 0)
  1282. {
  1283. for (int iNum = 0; iNum < abs(iDec2); iNum++)
  1284. {
  1285. strValue = "0" + strValue;
  1286. }
  1287. iDec2 = 0;
  1288. }
  1289. int iMax = strValue.GetLength();
  1290. if (iDec2 > iMax)
  1291. {
  1292. for (int iNum = 0; iNum <= iDec2 - iMax; iNum++)
  1293. {
  1294. strValue += "0";
  1295. }
  1296. iMax = iDec2+1;
  1297. }
  1298. ///////////////////////////////////////////////////////
  1299. //for processing seperator style
  1300. if (iDec2 < iMax)
  1301. {
  1302. if (iSepStyle == 0 || iSepStyle == 1)
  1303. {
  1304. strValue.Insert(iDec2, '.');
  1305. iMax++;
  1306. }
  1307. else if (iSepStyle == 2 || iSepStyle == 3)
  1308. {
  1309. strValue.Insert(iDec2, ',');
  1310. iMax++;
  1311. }
  1312. if (iDec2 == 0)
  1313. strValue.Insert(iDec2, '0');
  1314. }
  1315. if (iSepStyle == 0 || iSepStyle == 2)
  1316. {
  1317. char cSeperator;
  1318. if (iSepStyle == 0)
  1319. cSeperator = ',';
  1320. else
  1321. cSeperator = '.';
  1322. int iDecPositive,iDecNagative;
  1323. iDecPositive = iDec2;
  1324. iDecNagative = iDec2;
  1325. for (iDecPositive = iDec2 -3; iDecPositive > 0; iDecPositive -= 3)
  1326. {
  1327. strValue.Insert(iDecPositive,cSeperator);
  1328. iMax++;
  1329. }
  1330. }
  1331. ////////////////////////////////////////////////////////////////////
  1332. //nagative mark
  1333. if(bNagative)
  1334. strValue = "-" + strValue;
  1335. strValue += "%";
  1336. Value = CFX_WideString::FromLocal(strValue);
  1337. #endif
  1338. return TRUE;
  1339. }
  1340. //AFPercent_Keystroke(nDec, sepStyle)
  1341. FX_BOOL CJS_PublicMethods::AFPercent_Keystroke(OBJ_METHOD_PARAMS)
  1342. {
  1343. return AFNumber_Keystroke(cc,params,vRet,sError);
  1344. }
  1345. //function AFDate_FormatEx(cFormat)
  1346. FX_BOOL CJS_PublicMethods::AFDate_FormatEx(OBJ_METHOD_PARAMS)
  1347. {
  1348. CJS_Context* pContext = (CJS_Context *)cc;
  1349. ASSERT(pContext != NULL);
  1350. CJS_EventHandler* pEvent = pContext->GetEventHandler();
  1351. ASSERT(pEvent != NULL);
  1352. if (params.size() != 1)
  1353. {
  1354. sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
  1355. return FALSE;
  1356. }
  1357. if(!pEvent->m_pValue)
  1358. return FALSE;
  1359. CFX_WideString& val = pEvent->Value();
  1360. CFX_WideString strValue = val;
  1361. if (strValue.IsEmpty()) return TRUE;
  1362. CFX_WideString sFormat = params[0].operator CFX_WideString();
  1363. FX_BOOL bWrongFormat = FALSE;
  1364. double dDate = 0.0f;
  1365. if(strValue.Find(L"GMT") != -1)
  1366. {
  1367. //for GMT format time
  1368. //such as "Tue Aug 11 14:24:16 GMT+08002009"
  1369. dDate = MakeInterDate(strValue);
  1370. }
  1371. else
  1372. {
  1373. dDate = MakeRegularDate(strValue,sFormat,bWrongFormat);
  1374. }
  1375. if (JS_PortIsNan(dDate))
  1376. {
  1377. CFX_WideString swMsg;
  1378. swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE), (FX_LPCWSTR)sFormat);
  1379. Alert(pContext, swMsg);
  1380. return FALSE;
  1381. }
  1382. val = MakeFormatDate(dDate,sFormat);
  1383. return TRUE;
  1384. }
  1385. double CJS_PublicMethods::MakeInterDate(CFX_WideString strValue)
  1386. {
  1387. int nHour;
  1388. int nMin;
  1389. int nSec;
  1390. int nYear;
  1391. int nMonth;
  1392. int nDay;
  1393. CFX_WideStringArray wsArray;
  1394. CFX_WideString sMonth = L"";
  1395. CFX_WideString sTemp = L"";
  1396. int nSize = strValue.GetLength();
  1397. for(int i = 0; i < nSize; i++)
  1398. {
  1399. FX_WCHAR c = strValue.GetAt(i);
  1400. if(c == L' ' || c == L':')
  1401. {
  1402. wsArray.Add(sTemp);
  1403. sTemp = L"";
  1404. continue;
  1405. }
  1406. sTemp += c;
  1407. }
  1408. wsArray.Add(sTemp);
  1409. if(wsArray.GetSize() != 8)return 0;
  1410. sTemp = wsArray[1];
  1411. if(sTemp.Compare(L"Jan") == 0) nMonth = 1;
  1412. if(sTemp.Compare(L"Feb") == 0) nMonth = 2;
  1413. if(sTemp.Compare(L"Mar") == 0) nMonth = 3;
  1414. if(sTemp.Compare(L"Apr") == 0) nMonth = 4;
  1415. if(sTemp.Compare(L"May") == 0) nMonth = 5;
  1416. if(sTemp.Compare(L"Jun") == 0) nMonth = 6;
  1417. if(sTemp.Compare(L"Jul") == 0) nMonth = 7;
  1418. if(sTemp.Compare(L"Aug") == 0) nMonth = 8;
  1419. if(sTemp.Compare(L"Sep") == 0) nMonth = 9;
  1420. if(sTemp.Compare(L"Oct") == 0) nMonth = 10;
  1421. if(sTemp.Compare(L"Nov") == 0) nMonth = 11;
  1422. if(sTemp.Compare(L"Dec") == 0) nMonth = 12;
  1423. nDay = (int)ParseStringToNumber(wsArray[2]);
  1424. nHour = (int)ParseStringToNumber(wsArray[3]);
  1425. nMin = (int)ParseStringToNumber(wsArray[4]);
  1426. nSec = (int)ParseStringToNumber(wsArray[5]);
  1427. nYear = (int)ParseStringToNumber(wsArray[7]);
  1428. double dRet = JS_MakeDate(JS_MakeDay(nYear,nMonth - 1,nDay),JS_MakeTime(nHour, nMin, nSec, 0));
  1429. if (JS_PortIsNan(dRet))
  1430. {
  1431. dRet = JS_DateParse(strValue);
  1432. }
  1433. return dRet;
  1434. }
  1435. //AFDate_KeystrokeEx(cFormat)
  1436. FX_BOOL CJS_PublicMethods::AFDate_KeystrokeEx(OBJ_METHOD_PARAMS)
  1437. {
  1438. CJS_Context* pContext = (CJS_Context *)cc;
  1439. ASSERT(pContext != NULL);
  1440. CJS_EventHandler* pEvent = pContext->GetEventHandler();
  1441. ASSERT(pEvent != NULL);
  1442. if (params.size() != 1)
  1443. {
  1444. sError = L"AFDate_KeystrokeEx's parameters' size r not correct";
  1445. return FALSE;
  1446. }
  1447. if (pEvent->WillCommit())
  1448. {
  1449. if(!pEvent->m_pValue)
  1450. return FALSE;
  1451. CFX_WideString strValue = pEvent->Value();
  1452. if (strValue.IsEmpty()) return TRUE;
  1453. CFX_WideString sFormat = params[0].operator CFX_WideString();
  1454. FX_BOOL bWrongFormat = FALSE;
  1455. double dRet = MakeRegularDate(strValue,sFormat,bWrongFormat);
  1456. if (bWrongFormat || JS_PortIsNan(dRet))
  1457. {
  1458. CFX_WideString swMsg;
  1459. swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE), (FX_LPCWSTR)sFormat);
  1460. Alert(pContext, swMsg);
  1461. pEvent->Rc() = FALSE;
  1462. return TRUE;
  1463. }
  1464. }
  1465. return TRUE;
  1466. }
  1467. FX_BOOL CJS_PublicMethods::AFDate_Format(OBJ_METHOD_PARAMS)
  1468. {
  1469. v8::Isolate* isolate = ::GetIsolate(cc);
  1470. if (params.size() != 1)
  1471. {
  1472. CJS_Context* pContext = (CJS_Context*)cc;
  1473. ASSERT(pContext != NULL);
  1474. sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
  1475. return FALSE;
  1476. }
  1477. int iIndex = params[0];
  1478. 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",
  1479. (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",
  1480. (FX_LPCWSTR)L"m/d/yy h:MM tt", (FX_LPCWSTR)L"m/d/yy HH:MM" };
  1481. ASSERT(iIndex < sizeof(cFormats)/sizeof(FX_LPCWSTR));
  1482. if (iIndex < 0)
  1483. iIndex = 0;
  1484. if (iIndex >= sizeof(cFormats)/sizeof(FX_LPCWSTR))
  1485. iIndex = 0;
  1486. CJS_Parameters newParams;
  1487. CJS_Value val(isolate,cFormats[iIndex]);
  1488. newParams.push_back(val);
  1489. return AFDate_FormatEx(cc,newParams,vRet,sError);
  1490. }
  1491. //AFDate_KeystrokeEx(cFormat)
  1492. FX_BOOL CJS_PublicMethods::AFDate_Keystroke(OBJ_METHOD_PARAMS)
  1493. {
  1494. v8::Isolate* isolate = ::GetIsolate(cc);
  1495. if (params.size() != 1)
  1496. {
  1497. CJS_Context* pContext = (CJS_Context*)cc;
  1498. ASSERT(pContext != NULL);
  1499. sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
  1500. return FALSE;
  1501. }
  1502. int iIndex = params[0];
  1503. 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",
  1504. (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",
  1505. (FX_LPCWSTR)L"m/d/yy h:MM tt", (FX_LPCWSTR)L"m/d/yy HH:MM" };
  1506. ASSERT(iIndex<sizeof(cFormats)/sizeof(FX_LPCWSTR));
  1507. if (iIndex < 0)
  1508. iIndex = 0;
  1509. if (iIndex >= sizeof(cFormats)/sizeof(FX_LPCWSTR))
  1510. iIndex = 0;
  1511. CJS_Parameters newParams;
  1512. CJS_Value val(isolate,cFormats[iIndex]);
  1513. newParams.push_back(val);
  1514. return AFDate_KeystrokeEx(cc,newParams,vRet,sError);
  1515. }
  1516. //function AFTime_Format(ptf)
  1517. FX_BOOL CJS_PublicMethods::AFTime_Format(OBJ_METHOD_PARAMS)
  1518. {
  1519. v8::Isolate* isolate = ::GetIsolate(cc);
  1520. if (params.size() != 1)
  1521. {
  1522. CJS_Context* pContext = (CJS_Context*)cc;
  1523. ASSERT(pContext != NULL);
  1524. sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
  1525. return FALSE;
  1526. }
  1527. int iIndex = params[0];
  1528. 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"};
  1529. ASSERT(iIndex<sizeof(cFormats)/sizeof(FX_LPCWSTR));
  1530. if (iIndex < 0)
  1531. iIndex = 0;
  1532. if (iIndex >= sizeof(cFormats)/sizeof(FX_LPCWSTR))
  1533. iIndex = 0;
  1534. CJS_Parameters newParams;
  1535. CJS_Value val(isolate,cFormats[iIndex]);
  1536. newParams.push_back(val);
  1537. return AFDate_FormatEx(cc,newParams,vRet,sError);
  1538. }
  1539. FX_BOOL CJS_PublicMethods::AFTime_Keystroke(OBJ_METHOD_PARAMS)
  1540. {
  1541. v8::Isolate* isolate = ::GetIsolate(cc);
  1542. if (params.size() != 1)
  1543. {
  1544. CJS_Context* pContext = (CJS_Context*)cc;
  1545. ASSERT(pContext != NULL);
  1546. sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
  1547. return FALSE;
  1548. }
  1549. int iIndex = params[0];
  1550. 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"};
  1551. ASSERT(iIndex<sizeof(cFormats)/sizeof(FX_LPCWSTR));
  1552. if (iIndex < 0)
  1553. iIndex = 0;
  1554. if (iIndex >= sizeof(cFormats)/sizeof(FX_LPCWSTR))
  1555. iIndex = 0;
  1556. CJS_Parameters newParams;
  1557. CJS_Value val(isolate,cFormats[iIndex]);
  1558. newParams.push_back(val);
  1559. return AFDate_KeystrokeEx(cc,newParams,vRet,sError);
  1560. }
  1561. FX_BOOL CJS_PublicMethods::AFTime_FormatEx(OBJ_METHOD_PARAMS)
  1562. {
  1563. return AFDate_FormatEx(cc,params,vRet,sError);
  1564. }
  1565. FX_BOOL CJS_PublicMethods::AFTime_KeystrokeEx(OBJ_METHOD_PARAMS)
  1566. {
  1567. return AFDate_KeystrokeEx(cc,params,vRet,sError);
  1568. }
  1569. //function AFSpecial_Format(psf)
  1570. FX_BOOL CJS_PublicMethods::AFSpecial_Format(OBJ_METHOD_PARAMS)
  1571. {
  1572. CJS_Context* pContext = (CJS_Context *)cc;
  1573. ASSERT(pContext != NULL);
  1574. if (params.size() != 1)
  1575. {
  1576. sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
  1577. return FALSE;
  1578. }
  1579. std::string cFormat;
  1580. int iIndex = params[0];
  1581. CJS_EventHandler* pEvent = pContext->GetEventHandler();
  1582. ASSERT(pEvent != NULL);
  1583. if(!pEvent->m_pValue)
  1584. return FALSE;
  1585. CFX_WideString& Value = pEvent->Value();
  1586. std::string strSrc = (FX_LPCSTR)CFX_ByteString::FromUnicode(Value);
  1587. switch (iIndex)
  1588. {
  1589. case 0:
  1590. cFormat = "99999";
  1591. break;
  1592. case 1:
  1593. cFormat = "99999-9999";
  1594. break;
  1595. case 2:
  1596. {
  1597. std::string NumberStr;
  1598. util::printx("9999999999", strSrc,NumberStr);
  1599. if (NumberStr.length() >= 10 )
  1600. cFormat = "(999) 999-9999";
  1601. else
  1602. cFormat = "999-9999";
  1603. break;
  1604. }
  1605. case 3:
  1606. cFormat = "999-99-9999";
  1607. break;
  1608. }
  1609. std::string strDes;
  1610. util::printx(cFormat,strSrc,strDes);
  1611. Value = CFX_WideString::FromLocal(strDes.c_str());
  1612. return TRUE;
  1613. }
  1614. //function AFSpecial_KeystrokeEx(mask)
  1615. FX_BOOL CJS_PublicMethods::AFSpecial_KeystrokeEx(OBJ_METHOD_PARAMS)
  1616. {
  1617. CJS_Context* pContext = (CJS_Context *)cc;
  1618. ASSERT(pContext != NULL);
  1619. CJS_EventHandler* pEvent = pContext->GetEventHandler();
  1620. ASSERT(pEvent != NULL);
  1621. if (params.size() < 1)
  1622. {
  1623. sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
  1624. return FALSE;
  1625. }
  1626. if(!pEvent->m_pValue)
  1627. return FALSE;
  1628. CFX_WideString& valEvent = pEvent->Value();
  1629. CFX_WideString wstrMask = params[0].operator CFX_WideString();
  1630. if (wstrMask.IsEmpty()) return TRUE;
  1631. std::wstring wstrValue(valEvent);
  1632. if (pEvent->WillCommit())
  1633. {
  1634. if (wstrValue.empty())
  1635. return TRUE;
  1636. int iIndexMask = 0;
  1637. for (std::wstring::iterator it = wstrValue.begin(); it != wstrValue.end(); it++)
  1638. {
  1639. wchar_t w_Value = *it;
  1640. if (!maskSatisfied(w_Value,wstrMask[iIndexMask]))
  1641. break;
  1642. iIndexMask++;
  1643. }
  1644. if (iIndexMask != wstrMask.GetLength() || (iIndexMask != wstrValue.size() && wstrMask.GetLength() != 0))
  1645. {
  1646. Alert(pContext, JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYSTROKE));
  1647. pEvent->Rc() = FALSE;
  1648. }
  1649. return TRUE;
  1650. }
  1651. CFX_WideString &wideChange = pEvent->Change();
  1652. std::wstring wChange(wideChange);
  1653. if (wChange.empty())
  1654. return TRUE;
  1655. int iIndexMask = pEvent->SelStart();
  1656. //iIndexMask++;
  1657. if (wstrValue.length() - (pEvent->SelEnd()-pEvent->SelStart()) + wChange.length() > (FX_DWORD)wstrMask.GetLength())
  1658. {
  1659. Alert(pContext, JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG));
  1660. pEvent->Rc() = FALSE;
  1661. return TRUE;
  1662. }
  1663. if (iIndexMask >= wstrMask.GetLength() && (!wChange.empty()))
  1664. {
  1665. Alert(pContext, JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG));
  1666. pEvent->Rc() = FALSE;
  1667. return TRUE;
  1668. }
  1669. for (std::wstring::iterator it = wChange.begin(); it != wChange.end(); it++)
  1670. {
  1671. if (iIndexMask >= wstrMask.GetLength())
  1672. {
  1673. Alert(pContext, JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG));
  1674. pEvent->Rc() = FALSE;
  1675. return TRUE;
  1676. }
  1677. wchar_t w_Mask = wstrMask[iIndexMask];
  1678. if (!isReservedMaskChar(w_Mask))
  1679. {
  1680. //wChange.insert(it,w_Mask);
  1681. *it = w_Mask;
  1682. }
  1683. wchar_t w_Change = *it;
  1684. if (!maskSatisfied(w_Change,w_Mask))
  1685. {
  1686. pEvent->Rc() = FALSE;
  1687. return TRUE;
  1688. }
  1689. iIndexMask++;
  1690. }
  1691. wideChange = wChange.c_str();
  1692. return TRUE;
  1693. }
  1694. //function AFSpecial_Keystroke(psf)
  1695. FX_BOOL CJS_PublicMethods::AFSpecial_Keystroke(OBJ_METHOD_PARAMS)
  1696. {
  1697. v8::Isolate* isolate = ::GetIsolate(cc);
  1698. CJS_Context* pContext = (CJS_Context *)cc;
  1699. ASSERT(pContext != NULL);
  1700. CJS_EventHandler* pEvent = pContext->GetEventHandler();
  1701. ASSERT(pEvent != NULL);
  1702. if (params.size() != 1)
  1703. {
  1704. sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
  1705. return FALSE;
  1706. }
  1707. std::string cFormat;
  1708. int iIndex = (int)params[0];
  1709. if(!pEvent->m_pValue)
  1710. return FALSE;
  1711. //CJS_Value val = pEvent->Value();
  1712. CFX_WideString& val = pEvent->Value();
  1713. std::string strSrc = (FX_LPCSTR)CFX_ByteString::FromUnicode(val);
  1714. std::wstring wstrChange(pEvent->Change());
  1715. switch (iIndex)
  1716. {
  1717. case 0:
  1718. cFormat = "99999";
  1719. break;
  1720. case 1:
  1721. //cFormat = "99999-9999";
  1722. cFormat = "999999999";
  1723. break;
  1724. case 2:
  1725. {
  1726. std::string NumberStr;
  1727. util::printx("9999999999", strSrc,NumberStr);
  1728. if (strSrc.length() + wstrChange.length() > 7 )
  1729. //cFormat = "(999) 999-9999";
  1730. cFormat = "9999999999";
  1731. else
  1732. //cFormat = "999-9999";
  1733. cFormat = "9999999";
  1734. break;
  1735. }
  1736. case 3:
  1737. //cFormat = "999-99-9999";
  1738. cFormat = "999999999";
  1739. break;
  1740. }
  1741. CJS_Parameters params2;
  1742. CJS_Value vMask(isolate, cFormat.c_str());
  1743. params2.push_back(vMask);
  1744. return AFSpecial_KeystrokeEx(cc,params2,vRet,sError);
  1745. }
  1746. FX_BOOL CJS_PublicMethods::AFMergeChange(OBJ_METHOD_PARAMS)
  1747. {
  1748. CJS_Context* pContext = (CJS_Context *)cc;
  1749. ASSERT(pContext != NULL);
  1750. CJS_EventHandler* pEventHandler = pContext->GetEventHandler();
  1751. ASSERT(pEventHandler != NULL);
  1752. if (params.size() != 1)
  1753. {
  1754. sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
  1755. return FALSE;
  1756. }
  1757. CFX_WideString swValue;
  1758. if (pEventHandler->m_pValue != NULL)
  1759. swValue = pEventHandler->Value();
  1760. if (pEventHandler->WillCommit())
  1761. {
  1762. vRet = swValue;
  1763. return TRUE;
  1764. }
  1765. CFX_WideString prefix,postfix;
  1766. if (pEventHandler->SelStart() >= 0)
  1767. prefix = swValue.Mid(0,pEventHandler->SelStart());
  1768. else
  1769. prefix = L"";
  1770. if (pEventHandler->SelEnd() >= 0 && pEventHandler->SelEnd() <= swValue.GetLength())
  1771. postfix = swValue.Mid(pEventHandler->SelEnd(), swValue.GetLength() - pEventHandler->SelEnd());
  1772. else postfix = L"";
  1773. vRet = prefix + pEventHandler->Change() + postfix;
  1774. return TRUE;
  1775. }
  1776. FX_BOOL CJS_PublicMethods::AFParseDateEx(OBJ_METHOD_PARAMS)
  1777. {
  1778. CJS_Context* pContext = (CJS_Context *)cc;
  1779. ASSERT(pContext != NULL);
  1780. if (params.size() != 2)
  1781. {
  1782. sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
  1783. return FALSE;
  1784. }
  1785. CFX_WideString sValue = params[0].operator CFX_WideString();
  1786. CFX_WideString sFormat = params[1].operator CFX_WideString();
  1787. FX_BOOL bWrongFormat = FALSE;
  1788. double dDate = MakeRegularDate(sValue,sFormat,bWrongFormat);
  1789. if (JS_PortIsNan(dDate))
  1790. {
  1791. CFX_WideString swMsg;
  1792. swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE), (FX_LPCWSTR)sFormat);
  1793. Alert((CJS_Context *)cc, swMsg);
  1794. return FALSE;
  1795. }
  1796. vRet = dDate;
  1797. return TRUE;
  1798. }
  1799. FX_BOOL CJS_PublicMethods::AFSimple(OBJ_METHOD_PARAMS)
  1800. {
  1801. if (params.size() != 3)
  1802. {
  1803. CJS_Context* pContext = (CJS_Context *)cc;
  1804. ASSERT(pContext != NULL);
  1805. sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
  1806. return FALSE;
  1807. }
  1808. vRet = (double)AF_Simple(params[0].operator CFX_WideString(), (double)params[1], (double)params[2]);
  1809. return TRUE;
  1810. }
  1811. FX_BOOL CJS_PublicMethods::AFMakeNumber(OBJ_METHOD_PARAMS)
  1812. {
  1813. if (params.size() != 1)
  1814. {
  1815. CJS_Context* pContext = (CJS_Context *)cc;
  1816. ASSERT(pContext != NULL);
  1817. sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
  1818. return FALSE;
  1819. }
  1820. vRet = ParseStringToNumber(params[0].operator CFX_WideString());
  1821. return TRUE;
  1822. }
  1823. FX_BOOL CJS_PublicMethods::AFSimple_Calculate(OBJ_METHOD_PARAMS)
  1824. {
  1825. v8::Isolate* isolate = ::GetIsolate(cc);
  1826. CJS_Context* pContext = (CJS_Context *)cc;
  1827. ASSERT(pContext != NULL);
  1828. if (params.size() != 2)
  1829. {
  1830. sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
  1831. return FALSE;
  1832. }
  1833. CJS_Value params1 = params[1];
  1834. if (!params1.IsArrayObject() && params1.GetType() != VT_string)
  1835. {
  1836. sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
  1837. return FALSE;
  1838. }
  1839. CPDFSDK_Document* pReaderDoc = pContext->GetReaderDocument();
  1840. ASSERT(pReaderDoc != NULL);
  1841. CPDFSDK_InterForm* pReaderInterForm = pReaderDoc->GetInterForm();
  1842. ASSERT(pReaderInterForm != NULL);
  1843. CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm();
  1844. ASSERT(pInterForm != NULL);
  1845. double dValue;
  1846. CFX_WideString sFunction = params[0].operator CFX_WideString();
  1847. if (wcscmp(sFunction, L"PRD") == 0)
  1848. dValue = 1.0;
  1849. else
  1850. dValue = 0.0;
  1851. CJS_Array FieldNameArray = AF_MakeArrayFromList(isolate,params1);
  1852. int nFieldsCount = 0;
  1853. for (int i=0,isz=FieldNameArray.GetLength(); i<isz; i++)
  1854. {
  1855. CJS_Value jsValue(isolate);
  1856. FieldNameArray.GetElement(i,jsValue);
  1857. CFX_WideString wsFieldName = jsValue.operator CFX_WideString();
  1858. for (int j=0,jsz=pInterForm->CountFields(wsFieldName); j<jsz; j++)
  1859. {
  1860. if (CPDF_FormField* pFormField = pInterForm->GetField(j, wsFieldName))
  1861. {
  1862. double dTemp = 0.0;
  1863. switch (pFormField->GetFieldType())
  1864. {
  1865. case FIELDTYPE_TEXTFIELD:
  1866. case FIELDTYPE_COMBOBOX:
  1867. {
  1868. dTemp = ParseStringToNumber(pFormField->GetValue());
  1869. break;
  1870. }
  1871. case FIELDTYPE_PUSHBUTTON:
  1872. {
  1873. dTemp = 0.0;
  1874. break;
  1875. }
  1876. case FIELDTYPE_CHECKBOX:
  1877. case FIELDTYPE_RADIOBUTTON:
  1878. {
  1879. dTemp = 0.0;
  1880. for (int c=0,csz=pFormField->CountControls(); c<csz; c++)
  1881. {
  1882. if (CPDF_FormControl* pFormCtrl = pFormField->GetControl(c))
  1883. {
  1884. if (pFormCtrl->IsChecked())
  1885. {
  1886. dTemp += ParseStringToNumber(pFormCtrl->GetExportValue());
  1887. break;
  1888. }
  1889. else
  1890. continue;
  1891. }
  1892. }
  1893. break;
  1894. }
  1895. case FIELDTYPE_LISTBOX:
  1896. {
  1897. dTemp = 0.0;
  1898. if (pFormField->CountSelectedItems() > 1)
  1899. break;
  1900. else
  1901. {
  1902. dTemp = ParseStringToNumber(pFormField->GetValue());
  1903. break;
  1904. }
  1905. }
  1906. default:
  1907. break;
  1908. }
  1909. if (i == 0 && j == 0 && (wcscmp(sFunction,L"MIN") == 0 || wcscmp(sFunction, L"MAX") == 0))
  1910. dValue = dTemp;
  1911. dValue = AF_Simple(sFunction, dValue, dTemp);
  1912. nFieldsCount++;
  1913. }
  1914. }
  1915. }
  1916. if (wcscmp(sFunction, L"AVG") == 0 && nFieldsCount > 0)
  1917. dValue /= nFieldsCount;
  1918. dValue = (double)floor(dValue * FXSYS_pow((double)10,(double)6) + 0.49) / FXSYS_pow((double)10,(double)6);
  1919. CJS_Value jsValue(isolate,dValue);
  1920. if((CJS_EventHandler*)pContext->GetEventHandler()->m_pValue)
  1921. ((CJS_EventHandler*)pContext->GetEventHandler())->Value() = jsValue;
  1922. return TRUE;
  1923. }
  1924. /* This function validates the current event to ensure that its value is
  1925. ** within the specified range. */
  1926. FX_BOOL CJS_PublicMethods::AFRange_Validate(OBJ_METHOD_PARAMS)
  1927. {
  1928. CJS_Context* pContext = (CJS_Context *)cc;
  1929. ASSERT(pContext != NULL);
  1930. CJS_EventHandler* pEvent = pContext->GetEventHandler();
  1931. ASSERT(pEvent != NULL);
  1932. if (params.size() != 4)
  1933. {
  1934. sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
  1935. return FALSE;
  1936. }
  1937. if(!pEvent->m_pValue)
  1938. return FALSE;
  1939. if (pEvent->Value().IsEmpty() )
  1940. return TRUE;
  1941. double dEentValue = atof(CFX_ByteString::FromUnicode(pEvent->Value()));
  1942. FX_BOOL bGreaterThan, bLessThan;
  1943. double dGreaterThan, dLessThan;
  1944. bGreaterThan = (FX_BOOL)params[0];
  1945. CFX_WideString swMsg;
  1946. dGreaterThan = (double)params[1];
  1947. bLessThan = (FX_B

Large files files are truncated, but you can click here to view the full file