summaryrefslogtreecommitdiff
path: root/fpdfsdk/src/javascript
diff options
context:
space:
mode:
Diffstat (limited to 'fpdfsdk/src/javascript')
-rw-r--r--fpdfsdk/src/javascript/Consts.cpp494
-rw-r--r--fpdfsdk/src/javascript/Document.cpp5054
-rw-r--r--fpdfsdk/src/javascript/Field.cpp8256
-rw-r--r--fpdfsdk/src/javascript/Icon.cpp134
-rw-r--r--fpdfsdk/src/javascript/JS_Context.cpp728
-rw-r--r--fpdfsdk/src/javascript/JS_EventHandler.cpp1352
-rw-r--r--fpdfsdk/src/javascript/JS_GlobalData.cpp1162
-rw-r--r--fpdfsdk/src/javascript/JS_Object.cpp290
-rw-r--r--fpdfsdk/src/javascript/JS_Runtime.cpp940
-rw-r--r--fpdfsdk/src/javascript/JS_Value.cpp1286
-rw-r--r--fpdfsdk/src/javascript/PublicMethods.cpp4670
-rw-r--r--fpdfsdk/src/javascript/app.cpp2268
-rw-r--r--fpdfsdk/src/javascript/color.cpp506
-rw-r--r--fpdfsdk/src/javascript/console.cpp156
-rw-r--r--fpdfsdk/src/javascript/event.cpp758
-rw-r--r--fpdfsdk/src/javascript/global.cpp1100
-rw-r--r--fpdfsdk/src/javascript/report.cpp100
-rw-r--r--fpdfsdk/src/javascript/util.cpp1298
18 files changed, 15276 insertions, 15276 deletions
diff --git a/fpdfsdk/src/javascript/Consts.cpp b/fpdfsdk/src/javascript/Consts.cpp
index 09b8f8e1a0..278cd7eab8 100644
--- a/fpdfsdk/src/javascript/Consts.cpp
+++ b/fpdfsdk/src/javascript/Consts.cpp
@@ -1,247 +1,247 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/javascript/JavaScript.h"
-#include "../../include/javascript/IJavaScript.h"
-#include "../../include/javascript/JS_Define.h"
-#include "../../include/javascript/JS_Object.h"
-#include "../../include/javascript/JS_Value.h"
-#include "../../include/javascript/Consts.h"
-
-/* ------------------------------ border ------------------------------ */
-
-BEGIN_JS_STATIC_CONST(CJS_Border)
- JS_STATIC_CONST_ENTRY_STRING(s, solid)
- JS_STATIC_CONST_ENTRY_STRING(b, beveled)
- JS_STATIC_CONST_ENTRY_STRING(d, dashed)
- JS_STATIC_CONST_ENTRY_STRING(i, inset)
- JS_STATIC_CONST_ENTRY_STRING(u, underline)
-END_JS_STATIC_CONST()
-
-IMPLEMENT_JS_CLASS_CONST(CJS_Border,border)
-
-/* ------------------------------ display ------------------------------ */
-
-BEGIN_JS_STATIC_CONST(CJS_Display)
- JS_STATIC_CONST_ENTRY_NUMBER(visible, 0)
- JS_STATIC_CONST_ENTRY_NUMBER(hidden, 1)
- JS_STATIC_CONST_ENTRY_NUMBER(noPrint, 2)
- JS_STATIC_CONST_ENTRY_NUMBER(noView, 3)
-END_JS_STATIC_CONST()
-
-IMPLEMENT_JS_CLASS_CONST(CJS_Display,display)
-
-/* ------------------------------ font ------------------------------ */
-
-BEGIN_JS_STATIC_CONST(CJS_Font)
- JS_STATIC_CONST_ENTRY_STRING(Times, Times-Roman)
- JS_STATIC_CONST_ENTRY_STRING(TimesB, Times-Bold)
- JS_STATIC_CONST_ENTRY_STRING(TimesI, Times-Italic)
- JS_STATIC_CONST_ENTRY_STRING(TimesBI, Times-BoldItalic)
- JS_STATIC_CONST_ENTRY_STRING(Helv, Helvetica)
- JS_STATIC_CONST_ENTRY_STRING(HelvB, Helvetica-Bold)
- JS_STATIC_CONST_ENTRY_STRING(HelvI, Helvetica-Oblique)
- JS_STATIC_CONST_ENTRY_STRING(HelvBI, Helvetica-BoldOblique)
- JS_STATIC_CONST_ENTRY_STRING(Cour, Courier)
- JS_STATIC_CONST_ENTRY_STRING(CourB, Courier-Bold)
- JS_STATIC_CONST_ENTRY_STRING(CourI, Courier-Oblique)
- JS_STATIC_CONST_ENTRY_STRING(CourBI, Courier-BoldOblique)
- JS_STATIC_CONST_ENTRY_STRING(Symbol, Symbol)
- JS_STATIC_CONST_ENTRY_STRING(ZapfD, ZapfDingbats)
-END_JS_STATIC_CONST()
-
-IMPLEMENT_JS_CLASS_CONST(CJS_Font,font)
-
-/* ------------------------------ highlight ------------------------------ */
-
-BEGIN_JS_STATIC_CONST(CJS_Highlight)
- JS_STATIC_CONST_ENTRY_STRING(n, none)
- JS_STATIC_CONST_ENTRY_STRING(i, invert)
- JS_STATIC_CONST_ENTRY_STRING(p, push)
- JS_STATIC_CONST_ENTRY_STRING(o, outline)
-END_JS_STATIC_CONST()
-
-IMPLEMENT_JS_CLASS_CONST(CJS_Highlight,highlight)
-
-/* ------------------------------ position ------------------------------ */
-
-BEGIN_JS_STATIC_CONST(CJS_Position)
- JS_STATIC_CONST_ENTRY_NUMBER(textOnly, 0)
- JS_STATIC_CONST_ENTRY_NUMBER(iconOnly, 1)
- JS_STATIC_CONST_ENTRY_NUMBER(iconTextV, 2)
- JS_STATIC_CONST_ENTRY_NUMBER(textIconV, 3)
- JS_STATIC_CONST_ENTRY_NUMBER(iconTextH, 4)
- JS_STATIC_CONST_ENTRY_NUMBER(textIconH, 5)
- JS_STATIC_CONST_ENTRY_NUMBER(overlay, 6)
-END_JS_STATIC_CONST()
-
-IMPLEMENT_JS_CLASS_CONST(CJS_Position,position)
-
-/* ------------------------------ scaleHow ------------------------------ */
-
-BEGIN_JS_STATIC_CONST(CJS_ScaleHow)
- JS_STATIC_CONST_ENTRY_NUMBER(proportional, 0)
- JS_STATIC_CONST_ENTRY_NUMBER(anamorphic, 1)
-END_JS_STATIC_CONST()
-
-IMPLEMENT_JS_CLASS_CONST(CJS_ScaleHow,scaleHow)
-
-/* ------------------------------ scaleWhen ------------------------------ */
-
-BEGIN_JS_STATIC_CONST(CJS_ScaleWhen)
- JS_STATIC_CONST_ENTRY_NUMBER(always, 0)
- JS_STATIC_CONST_ENTRY_NUMBER(never, 1)
- JS_STATIC_CONST_ENTRY_NUMBER(tooBig, 2)
- JS_STATIC_CONST_ENTRY_NUMBER(tooSmall, 3)
-END_JS_STATIC_CONST()
-
-IMPLEMENT_JS_CLASS_CONST(CJS_ScaleWhen,scaleWhen)
-
-/* ------------------------------ style ------------------------------ */
-
-BEGIN_JS_STATIC_CONST(CJS_Style)
- JS_STATIC_CONST_ENTRY_STRING(ch, check)
- JS_STATIC_CONST_ENTRY_STRING(cr, cross)
- JS_STATIC_CONST_ENTRY_STRING(di, diamond)
- JS_STATIC_CONST_ENTRY_STRING(ci, circle)
- JS_STATIC_CONST_ENTRY_STRING(st, star)
- JS_STATIC_CONST_ENTRY_STRING(sq, square)
-END_JS_STATIC_CONST()
-
-IMPLEMENT_JS_CLASS_CONST(CJS_Style,style)
-
-
-/* ------------------------------ zoomtype ------------------------------ */
-
-BEGIN_JS_STATIC_CONST(CJS_Zoomtype)
- JS_STATIC_CONST_ENTRY_STRING(none, NoVary)
- JS_STATIC_CONST_ENTRY_STRING(fitP, FitPage)
- JS_STATIC_CONST_ENTRY_STRING(fitW, FitWidth)
- JS_STATIC_CONST_ENTRY_STRING(fitH, FitHeight)
- JS_STATIC_CONST_ENTRY_STRING(fitV, FitVisibleWidth)
- JS_STATIC_CONST_ENTRY_STRING(pref, Preferred)
- JS_STATIC_CONST_ENTRY_STRING(refW, ReflowWidth)
-END_JS_STATIC_CONST()
-
-IMPLEMENT_JS_CLASS_CONST(CJS_Zoomtype,zoomtype)
-
-/* ------------------------------ CJS_GlobalConsts ------------------------------ */
-
-int CJS_GlobalConsts::Init(IJS_Runtime* pRuntime)
-{
- DEFINE_GLOBAL_CONST(pRuntime, IDS_GREATER_THAN , Invalid value: must be greater than or equal to %s.);
- DEFINE_GLOBAL_CONST(pRuntime, IDS_GT_AND_LT,Invalid value: must be greater than or equal to %s and less than or equal to %s.);
- DEFINE_GLOBAL_CONST(pRuntime, IDS_LESS_THAN,Invalid value: must be less than or equal to %s.);
- DEFINE_GLOBAL_CONST(pRuntime, IDS_INVALID_MONTH,** Invalid **);
- DEFINE_GLOBAL_CONST(pRuntime, IDS_INVALID_DATE,Invalid date/time: please ensure that the date/time exists. Field);
- DEFINE_GLOBAL_CONST(pRuntime, IDS_INVALID_VALUE,The value entered does not match the format of the field);
- DEFINE_GLOBAL_CONST(pRuntime, IDS_AM,am);
- DEFINE_GLOBAL_CONST(pRuntime, IDS_PM,pm);
- DEFINE_GLOBAL_CONST(pRuntime, IDS_MONTH_INFO,January[1]February[2]March[3]April[4]May[5]June[6]July[7]August[8]September[9]October[10]November[11]December[12]Sept[9]Jan[1]Feb[2]Mar[3]Apr[4]Jun[6]Jul[7]Aug[8]Sep[9]Oct[10]Nov[11]Dec[12]);
- DEFINE_GLOBAL_CONST(pRuntime, IDS_STARTUP_CONSOLE_MSG, ** ^_^ **);
-
- return 0;
-}
-
-/* ------------------------------ CJS_GlobalArrays ------------------------------ */
-
-int CJS_GlobalArrays::Init(IJS_Runtime* pRuntime)
-{
- {
- FX_LPCWSTR ArrayName = (FX_LPCWSTR)L"RE_NUMBER_ENTRY_DOT_SEP";
- FX_LPCWSTR ArrayContent[] = {(FX_LPCWSTR)L"[+-]?\\d*\\.?\\d*"};
- DEFINE_GLOBAL_ARRAY(pRuntime);
- }
-
- {
- FX_LPCWSTR ArrayName = (FX_LPCWSTR)L"RE_NUMBER_COMMIT_DOT_SEP";
- FX_LPCWSTR ArrayContent[] = {(FX_LPCWSTR)L"[+-]?\\d+(\\.\\d+)?", /* -1.0 or -1 */
- (FX_LPCWSTR)L"[+-]?\\.\\d+", /* -.1 */
- (FX_LPCWSTR)L"[+-]?\\d+\\." /* -1. */
- };
- DEFINE_GLOBAL_ARRAY(pRuntime);
- }
-
- {
- FX_LPCWSTR ArrayName = (FX_LPCWSTR)L"RE_NUMBER_ENTRY_COMMA_SEP";
- FX_LPCWSTR ArrayContent[] = {(FX_LPCWSTR)L"[+-]?\\d*,?\\d*"};
-
- DEFINE_GLOBAL_ARRAY(pRuntime);
- }
-
- {
- FX_LPCWSTR ArrayName = (FX_LPCWSTR)L"RE_NUMBER_COMMIT_COMMA_SEP";
- FX_LPCWSTR ArrayContent[] = {(FX_LPCWSTR)L"[+-]?\\d+([.,]\\d+)?", /* -1,0 or -1 */
- (FX_LPCWSTR)L"[+-]?[.,]\\d+", /* -,1 */
- (FX_LPCWSTR)L"[+-]?\\d+[.,]" /* -1, */
- };
- DEFINE_GLOBAL_ARRAY(pRuntime);
- }
-
- {
- FX_LPCWSTR ArrayName = (FX_LPCWSTR)L"RE_ZIP_ENTRY";
- FX_LPCWSTR ArrayContent[] = {(FX_LPCWSTR)L"\\d{0,5}"};
- DEFINE_GLOBAL_ARRAY(pRuntime);
- }
-
- {
- FX_LPCWSTR ArrayName = (FX_LPCWSTR)L"RE_ZIP_COMMIT";
- FX_LPCWSTR ArrayContent[] = {(FX_LPCWSTR)L"\\d{5}"};
- DEFINE_GLOBAL_ARRAY(pRuntime);
- }
-
- {
- FX_LPCWSTR ArrayName = (FX_LPCWSTR)L"RE_ZIP4_ENTRY";
- FX_LPCWSTR ArrayContent[] = {(FX_LPCWSTR)L"\\d{0,5}(\\.|[- ])?\\d{0,4}"};
- DEFINE_GLOBAL_ARRAY(pRuntime);
- }
-
- {
- FX_LPCWSTR ArrayName = (FX_LPCWSTR)L"RE_ZIP4_COMMIT";
- FX_LPCWSTR ArrayContent[] = {(FX_LPCWSTR)L"\\d{5}(\\.|[- ])?\\d{4}"};
- DEFINE_GLOBAL_ARRAY(pRuntime);
- }
-
- {
- FX_LPCWSTR ArrayName = (FX_LPCWSTR)L"RE_PHONE_ENTRY";
- FX_LPCWSTR ArrayContent[] = {
- (FX_LPCWSTR)L"\\d{0,3}(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}", /* 555-1234 or 408 555-1234 */
- (FX_LPCWSTR)L"\\(\\d{0,3}", /* (408 */
- (FX_LPCWSTR)L"\\(\\d{0,3}\\)(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}", /* (408) 555-1234 */
- /* (allow the addition of parens as an afterthought) */
- (FX_LPCWSTR)L"\\(\\d{0,3}(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}", /* (408 555-1234 */
- (FX_LPCWSTR)L"\\d{0,3}\\)(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}", /* 408) 555-1234 */
- (FX_LPCWSTR)L"011(\\.|[- \\d])*" /* international */
- };
- DEFINE_GLOBAL_ARRAY(pRuntime);
- }
-
- {
- FX_LPCWSTR ArrayName = (FX_LPCWSTR)L"RE_PHONE_COMMIT";
- FX_LPCWSTR ArrayContent[] = {
- (FX_LPCWSTR)L"\\d{3}(\\.|[- ])?\\d{4}", /* 555-1234 */
- (FX_LPCWSTR)L"\\d{3}(\\.|[- ])?\\d{3}(\\.|[- ])?\\d{4}", /* 408 555-1234 */
- (FX_LPCWSTR)L"\\(\\d{3}\\)(\\.|[- ])?\\d{3}(\\.|[- ])?\\d{4}", /* (408) 555-1234 */
- (FX_LPCWSTR)L"011(\\.|[- \\d])*" /* international */
- };
- DEFINE_GLOBAL_ARRAY(pRuntime);
- }
-
- {
- FX_LPCWSTR ArrayName = (FX_LPCWSTR)L"RE_SSN_ENTRY";
- FX_LPCWSTR ArrayContent[] = {(FX_LPCWSTR)L"\\d{0,3}(\\.|[- ])?\\d{0,2}(\\.|[- ])?\\d{0,4}"};
- DEFINE_GLOBAL_ARRAY(pRuntime);
- }
-
- {
- FX_LPCWSTR ArrayName = (FX_LPCWSTR)L"RE_SSN_COMMIT";
- FX_LPCWSTR ArrayContent[] = {(FX_LPCWSTR)L"\\d{3}(\\.|[- ])?\\d{2}(\\.|[- ])?\\d{4}"};
- DEFINE_GLOBAL_ARRAY(pRuntime);
- }
-
- return 0;
-}
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/javascript/JavaScript.h"
+#include "../../include/javascript/IJavaScript.h"
+#include "../../include/javascript/JS_Define.h"
+#include "../../include/javascript/JS_Object.h"
+#include "../../include/javascript/JS_Value.h"
+#include "../../include/javascript/Consts.h"
+
+/* ------------------------------ border ------------------------------ */
+
+BEGIN_JS_STATIC_CONST(CJS_Border)
+ JS_STATIC_CONST_ENTRY_STRING(s, solid)
+ JS_STATIC_CONST_ENTRY_STRING(b, beveled)
+ JS_STATIC_CONST_ENTRY_STRING(d, dashed)
+ JS_STATIC_CONST_ENTRY_STRING(i, inset)
+ JS_STATIC_CONST_ENTRY_STRING(u, underline)
+END_JS_STATIC_CONST()
+
+IMPLEMENT_JS_CLASS_CONST(CJS_Border,border)
+
+/* ------------------------------ display ------------------------------ */
+
+BEGIN_JS_STATIC_CONST(CJS_Display)
+ JS_STATIC_CONST_ENTRY_NUMBER(visible, 0)
+ JS_STATIC_CONST_ENTRY_NUMBER(hidden, 1)
+ JS_STATIC_CONST_ENTRY_NUMBER(noPrint, 2)
+ JS_STATIC_CONST_ENTRY_NUMBER(noView, 3)
+END_JS_STATIC_CONST()
+
+IMPLEMENT_JS_CLASS_CONST(CJS_Display,display)
+
+/* ------------------------------ font ------------------------------ */
+
+BEGIN_JS_STATIC_CONST(CJS_Font)
+ JS_STATIC_CONST_ENTRY_STRING(Times, Times-Roman)
+ JS_STATIC_CONST_ENTRY_STRING(TimesB, Times-Bold)
+ JS_STATIC_CONST_ENTRY_STRING(TimesI, Times-Italic)
+ JS_STATIC_CONST_ENTRY_STRING(TimesBI, Times-BoldItalic)
+ JS_STATIC_CONST_ENTRY_STRING(Helv, Helvetica)
+ JS_STATIC_CONST_ENTRY_STRING(HelvB, Helvetica-Bold)
+ JS_STATIC_CONST_ENTRY_STRING(HelvI, Helvetica-Oblique)
+ JS_STATIC_CONST_ENTRY_STRING(HelvBI, Helvetica-BoldOblique)
+ JS_STATIC_CONST_ENTRY_STRING(Cour, Courier)
+ JS_STATIC_CONST_ENTRY_STRING(CourB, Courier-Bold)
+ JS_STATIC_CONST_ENTRY_STRING(CourI, Courier-Oblique)
+ JS_STATIC_CONST_ENTRY_STRING(CourBI, Courier-BoldOblique)
+ JS_STATIC_CONST_ENTRY_STRING(Symbol, Symbol)
+ JS_STATIC_CONST_ENTRY_STRING(ZapfD, ZapfDingbats)
+END_JS_STATIC_CONST()
+
+IMPLEMENT_JS_CLASS_CONST(CJS_Font,font)
+
+/* ------------------------------ highlight ------------------------------ */
+
+BEGIN_JS_STATIC_CONST(CJS_Highlight)
+ JS_STATIC_CONST_ENTRY_STRING(n, none)
+ JS_STATIC_CONST_ENTRY_STRING(i, invert)
+ JS_STATIC_CONST_ENTRY_STRING(p, push)
+ JS_STATIC_CONST_ENTRY_STRING(o, outline)
+END_JS_STATIC_CONST()
+
+IMPLEMENT_JS_CLASS_CONST(CJS_Highlight,highlight)
+
+/* ------------------------------ position ------------------------------ */
+
+BEGIN_JS_STATIC_CONST(CJS_Position)
+ JS_STATIC_CONST_ENTRY_NUMBER(textOnly, 0)
+ JS_STATIC_CONST_ENTRY_NUMBER(iconOnly, 1)
+ JS_STATIC_CONST_ENTRY_NUMBER(iconTextV, 2)
+ JS_STATIC_CONST_ENTRY_NUMBER(textIconV, 3)
+ JS_STATIC_CONST_ENTRY_NUMBER(iconTextH, 4)
+ JS_STATIC_CONST_ENTRY_NUMBER(textIconH, 5)
+ JS_STATIC_CONST_ENTRY_NUMBER(overlay, 6)
+END_JS_STATIC_CONST()
+
+IMPLEMENT_JS_CLASS_CONST(CJS_Position,position)
+
+/* ------------------------------ scaleHow ------------------------------ */
+
+BEGIN_JS_STATIC_CONST(CJS_ScaleHow)
+ JS_STATIC_CONST_ENTRY_NUMBER(proportional, 0)
+ JS_STATIC_CONST_ENTRY_NUMBER(anamorphic, 1)
+END_JS_STATIC_CONST()
+
+IMPLEMENT_JS_CLASS_CONST(CJS_ScaleHow,scaleHow)
+
+/* ------------------------------ scaleWhen ------------------------------ */
+
+BEGIN_JS_STATIC_CONST(CJS_ScaleWhen)
+ JS_STATIC_CONST_ENTRY_NUMBER(always, 0)
+ JS_STATIC_CONST_ENTRY_NUMBER(never, 1)
+ JS_STATIC_CONST_ENTRY_NUMBER(tooBig, 2)
+ JS_STATIC_CONST_ENTRY_NUMBER(tooSmall, 3)
+END_JS_STATIC_CONST()
+
+IMPLEMENT_JS_CLASS_CONST(CJS_ScaleWhen,scaleWhen)
+
+/* ------------------------------ style ------------------------------ */
+
+BEGIN_JS_STATIC_CONST(CJS_Style)
+ JS_STATIC_CONST_ENTRY_STRING(ch, check)
+ JS_STATIC_CONST_ENTRY_STRING(cr, cross)
+ JS_STATIC_CONST_ENTRY_STRING(di, diamond)
+ JS_STATIC_CONST_ENTRY_STRING(ci, circle)
+ JS_STATIC_CONST_ENTRY_STRING(st, star)
+ JS_STATIC_CONST_ENTRY_STRING(sq, square)
+END_JS_STATIC_CONST()
+
+IMPLEMENT_JS_CLASS_CONST(CJS_Style,style)
+
+
+/* ------------------------------ zoomtype ------------------------------ */
+
+BEGIN_JS_STATIC_CONST(CJS_Zoomtype)
+ JS_STATIC_CONST_ENTRY_STRING(none, NoVary)
+ JS_STATIC_CONST_ENTRY_STRING(fitP, FitPage)
+ JS_STATIC_CONST_ENTRY_STRING(fitW, FitWidth)
+ JS_STATIC_CONST_ENTRY_STRING(fitH, FitHeight)
+ JS_STATIC_CONST_ENTRY_STRING(fitV, FitVisibleWidth)
+ JS_STATIC_CONST_ENTRY_STRING(pref, Preferred)
+ JS_STATIC_CONST_ENTRY_STRING(refW, ReflowWidth)
+END_JS_STATIC_CONST()
+
+IMPLEMENT_JS_CLASS_CONST(CJS_Zoomtype,zoomtype)
+
+/* ------------------------------ CJS_GlobalConsts ------------------------------ */
+
+int CJS_GlobalConsts::Init(IJS_Runtime* pRuntime)
+{
+ DEFINE_GLOBAL_CONST(pRuntime, IDS_GREATER_THAN , Invalid value: must be greater than or equal to %s.);
+ DEFINE_GLOBAL_CONST(pRuntime, IDS_GT_AND_LT,Invalid value: must be greater than or equal to %s and less than or equal to %s.);
+ DEFINE_GLOBAL_CONST(pRuntime, IDS_LESS_THAN,Invalid value: must be less than or equal to %s.);
+ DEFINE_GLOBAL_CONST(pRuntime, IDS_INVALID_MONTH,** Invalid **);
+ DEFINE_GLOBAL_CONST(pRuntime, IDS_INVALID_DATE,Invalid date/time: please ensure that the date/time exists. Field);
+ DEFINE_GLOBAL_CONST(pRuntime, IDS_INVALID_VALUE,The value entered does not match the format of the field);
+ DEFINE_GLOBAL_CONST(pRuntime, IDS_AM,am);
+ DEFINE_GLOBAL_CONST(pRuntime, IDS_PM,pm);
+ DEFINE_GLOBAL_CONST(pRuntime, IDS_MONTH_INFO,January[1]February[2]March[3]April[4]May[5]June[6]July[7]August[8]September[9]October[10]November[11]December[12]Sept[9]Jan[1]Feb[2]Mar[3]Apr[4]Jun[6]Jul[7]Aug[8]Sep[9]Oct[10]Nov[11]Dec[12]);
+ DEFINE_GLOBAL_CONST(pRuntime, IDS_STARTUP_CONSOLE_MSG, ** ^_^ **);
+
+ return 0;
+}
+
+/* ------------------------------ CJS_GlobalArrays ------------------------------ */
+
+int CJS_GlobalArrays::Init(IJS_Runtime* pRuntime)
+{
+ {
+ FX_LPCWSTR ArrayName = (FX_LPCWSTR)L"RE_NUMBER_ENTRY_DOT_SEP";
+ FX_LPCWSTR ArrayContent[] = {(FX_LPCWSTR)L"[+-]?\\d*\\.?\\d*"};
+ DEFINE_GLOBAL_ARRAY(pRuntime);
+ }
+
+ {
+ FX_LPCWSTR ArrayName = (FX_LPCWSTR)L"RE_NUMBER_COMMIT_DOT_SEP";
+ FX_LPCWSTR ArrayContent[] = {(FX_LPCWSTR)L"[+-]?\\d+(\\.\\d+)?", /* -1.0 or -1 */
+ (FX_LPCWSTR)L"[+-]?\\.\\d+", /* -.1 */
+ (FX_LPCWSTR)L"[+-]?\\d+\\." /* -1. */
+ };
+ DEFINE_GLOBAL_ARRAY(pRuntime);
+ }
+
+ {
+ FX_LPCWSTR ArrayName = (FX_LPCWSTR)L"RE_NUMBER_ENTRY_COMMA_SEP";
+ FX_LPCWSTR ArrayContent[] = {(FX_LPCWSTR)L"[+-]?\\d*,?\\d*"};
+
+ DEFINE_GLOBAL_ARRAY(pRuntime);
+ }
+
+ {
+ FX_LPCWSTR ArrayName = (FX_LPCWSTR)L"RE_NUMBER_COMMIT_COMMA_SEP";
+ FX_LPCWSTR ArrayContent[] = {(FX_LPCWSTR)L"[+-]?\\d+([.,]\\d+)?", /* -1,0 or -1 */
+ (FX_LPCWSTR)L"[+-]?[.,]\\d+", /* -,1 */
+ (FX_LPCWSTR)L"[+-]?\\d+[.,]" /* -1, */
+ };
+ DEFINE_GLOBAL_ARRAY(pRuntime);
+ }
+
+ {
+ FX_LPCWSTR ArrayName = (FX_LPCWSTR)L"RE_ZIP_ENTRY";
+ FX_LPCWSTR ArrayContent[] = {(FX_LPCWSTR)L"\\d{0,5}"};
+ DEFINE_GLOBAL_ARRAY(pRuntime);
+ }
+
+ {
+ FX_LPCWSTR ArrayName = (FX_LPCWSTR)L"RE_ZIP_COMMIT";
+ FX_LPCWSTR ArrayContent[] = {(FX_LPCWSTR)L"\\d{5}"};
+ DEFINE_GLOBAL_ARRAY(pRuntime);
+ }
+
+ {
+ FX_LPCWSTR ArrayName = (FX_LPCWSTR)L"RE_ZIP4_ENTRY";
+ FX_LPCWSTR ArrayContent[] = {(FX_LPCWSTR)L"\\d{0,5}(\\.|[- ])?\\d{0,4}"};
+ DEFINE_GLOBAL_ARRAY(pRuntime);
+ }
+
+ {
+ FX_LPCWSTR ArrayName = (FX_LPCWSTR)L"RE_ZIP4_COMMIT";
+ FX_LPCWSTR ArrayContent[] = {(FX_LPCWSTR)L"\\d{5}(\\.|[- ])?\\d{4}"};
+ DEFINE_GLOBAL_ARRAY(pRuntime);
+ }
+
+ {
+ FX_LPCWSTR ArrayName = (FX_LPCWSTR)L"RE_PHONE_ENTRY";
+ FX_LPCWSTR ArrayContent[] = {
+ (FX_LPCWSTR)L"\\d{0,3}(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}", /* 555-1234 or 408 555-1234 */
+ (FX_LPCWSTR)L"\\(\\d{0,3}", /* (408 */
+ (FX_LPCWSTR)L"\\(\\d{0,3}\\)(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}", /* (408) 555-1234 */
+ /* (allow the addition of parens as an afterthought) */
+ (FX_LPCWSTR)L"\\(\\d{0,3}(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}", /* (408 555-1234 */
+ (FX_LPCWSTR)L"\\d{0,3}\\)(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}", /* 408) 555-1234 */
+ (FX_LPCWSTR)L"011(\\.|[- \\d])*" /* international */
+ };
+ DEFINE_GLOBAL_ARRAY(pRuntime);
+ }
+
+ {
+ FX_LPCWSTR ArrayName = (FX_LPCWSTR)L"RE_PHONE_COMMIT";
+ FX_LPCWSTR ArrayContent[] = {
+ (FX_LPCWSTR)L"\\d{3}(\\.|[- ])?\\d{4}", /* 555-1234 */
+ (FX_LPCWSTR)L"\\d{3}(\\.|[- ])?\\d{3}(\\.|[- ])?\\d{4}", /* 408 555-1234 */
+ (FX_LPCWSTR)L"\\(\\d{3}\\)(\\.|[- ])?\\d{3}(\\.|[- ])?\\d{4}", /* (408) 555-1234 */
+ (FX_LPCWSTR)L"011(\\.|[- \\d])*" /* international */
+ };
+ DEFINE_GLOBAL_ARRAY(pRuntime);
+ }
+
+ {
+ FX_LPCWSTR ArrayName = (FX_LPCWSTR)L"RE_SSN_ENTRY";
+ FX_LPCWSTR ArrayContent[] = {(FX_LPCWSTR)L"\\d{0,3}(\\.|[- ])?\\d{0,2}(\\.|[- ])?\\d{0,4}"};
+ DEFINE_GLOBAL_ARRAY(pRuntime);
+ }
+
+ {
+ FX_LPCWSTR ArrayName = (FX_LPCWSTR)L"RE_SSN_COMMIT";
+ FX_LPCWSTR ArrayContent[] = {(FX_LPCWSTR)L"\\d{3}(\\.|[- ])?\\d{2}(\\.|[- ])?\\d{4}"};
+ DEFINE_GLOBAL_ARRAY(pRuntime);
+ }
+
+ return 0;
+}
+
diff --git a/fpdfsdk/src/javascript/Document.cpp b/fpdfsdk/src/javascript/Document.cpp
index ec930b810d..0a6acfaea7 100644
--- a/fpdfsdk/src/javascript/Document.cpp
+++ b/fpdfsdk/src/javascript/Document.cpp
@@ -1,2527 +1,2527 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/javascript/JavaScript.h"
-#include "../../include/javascript/IJavaScript.h"
-#include "../../include/javascript/JS_Define.h"
-#include "../../include/javascript/JS_Object.h"
-#include "../../include/javascript/JS_Value.h"
-#include "../../include/javascript/Document.h"
-#include "../../include/javascript/JS_EventHandler.h"
-#include "../../include/javascript/JS_Context.h"
-#include "../../include/javascript/JS_Runtime.h"
-#include "../../include/javascript/app.h"
-#include "../../include/javascript/Field.h"
-#include "../../include/javascript/Icon.h"
-#include "../../include/javascript/Field.h"
-
-static v8::Isolate* GetIsolate(IFXJS_Context* cc)
-{
- CJS_Context* pContext = (CJS_Context *)cc;
- ASSERT(pContext != NULL);
-
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
-
- return pRuntime->GetIsolate();
-}
-
-BEGIN_JS_STATIC_CONST(CJS_PrintParamsObj)
-END_JS_STATIC_CONST()
-
-BEGIN_JS_STATIC_PROP(CJS_PrintParamsObj)
-END_JS_STATIC_PROP()
-
-BEGIN_JS_STATIC_METHOD(CJS_PrintParamsObj)
-END_JS_STATIC_METHOD()
-
-IMPLEMENT_JS_CLASS(CJS_PrintParamsObj, PrintParamsObj)
-
-PrintParamsObj::PrintParamsObj(CJS_Object* pJSObject)
-: CJS_EmbedObj(pJSObject)
-{
- bUI = TRUE;
- nStart = 0;
- nEnd = 0;
- bSilent = FALSE;
- bShrinkToFit = FALSE;
- bPrintAsImage = FALSE;
- bReverse = FALSE;
- bAnnotations = TRUE;
-}
-
-/* ---------------------- Document ---------------------- */
-
-#define MINWIDTH 5.0f
-#define MINHEIGHT 5.0f
-
-BEGIN_JS_STATIC_CONST(CJS_Document)
-END_JS_STATIC_CONST()
-
-BEGIN_JS_STATIC_PROP(CJS_Document)
- JS_STATIC_PROP_ENTRY(ADBE)
- JS_STATIC_PROP_ENTRY(author)
- JS_STATIC_PROP_ENTRY(baseURL)
- JS_STATIC_PROP_ENTRY(bookmarkRoot)
- JS_STATIC_PROP_ENTRY(calculate)
- JS_STATIC_PROP_ENTRY(Collab)
- JS_STATIC_PROP_ENTRY(creationDate)
- JS_STATIC_PROP_ENTRY(creator)
- JS_STATIC_PROP_ENTRY(delay)
- JS_STATIC_PROP_ENTRY(dirty)
- JS_STATIC_PROP_ENTRY(documentFileName)
- JS_STATIC_PROP_ENTRY(external)
- JS_STATIC_PROP_ENTRY(filesize)
- JS_STATIC_PROP_ENTRY(icons)
- JS_STATIC_PROP_ENTRY(info)
- JS_STATIC_PROP_ENTRY(keywords)
- JS_STATIC_PROP_ENTRY(layout)
- JS_STATIC_PROP_ENTRY(media)
- JS_STATIC_PROP_ENTRY(modDate)
- JS_STATIC_PROP_ENTRY(mouseX)
- JS_STATIC_PROP_ENTRY(mouseY)
- JS_STATIC_PROP_ENTRY(numFields)
- JS_STATIC_PROP_ENTRY(numPages)
- JS_STATIC_PROP_ENTRY(pageNum)
- JS_STATIC_PROP_ENTRY(pageWindowRect)
- JS_STATIC_PROP_ENTRY(path)
- JS_STATIC_PROP_ENTRY(producer)
- JS_STATIC_PROP_ENTRY(subject)
- JS_STATIC_PROP_ENTRY(title)
- JS_STATIC_PROP_ENTRY(zoom)
- JS_STATIC_PROP_ENTRY(zoomType)
-END_JS_STATIC_PROP()
-
-BEGIN_JS_STATIC_METHOD(CJS_Document)
- JS_STATIC_METHOD_ENTRY(addAnnot,0)
- JS_STATIC_METHOD_ENTRY(addField, 4)
- JS_STATIC_METHOD_ENTRY(addLink, 0)
- JS_STATIC_METHOD_ENTRY(addIcon, 0)
- JS_STATIC_METHOD_ENTRY(calculateNow, 0)
- JS_STATIC_METHOD_ENTRY(closeDoc, 0)
- JS_STATIC_METHOD_ENTRY(createDataObject, 0)
- JS_STATIC_METHOD_ENTRY(deletePages, 2)
- JS_STATIC_METHOD_ENTRY(exportAsText, 3)
- JS_STATIC_METHOD_ENTRY(exportAsFDF, 6)
- JS_STATIC_METHOD_ENTRY(exportAsXFDF, 5)
- JS_STATIC_METHOD_ENTRY(extractPages, 3)
- JS_STATIC_METHOD_ENTRY(getAnnot, 0)
- JS_STATIC_METHOD_ENTRY(getAnnots, 2)
- JS_STATIC_METHOD_ENTRY(getAnnot3D, 2)
- JS_STATIC_METHOD_ENTRY(getAnnots3D, 1)
- JS_STATIC_METHOD_ENTRY(getField, 1)
- JS_STATIC_METHOD_ENTRY(getIcon, 0)
- JS_STATIC_METHOD_ENTRY(getLinks, 0)
- JS_STATIC_METHOD_ENTRY(getNthFieldName, 1)
- JS_STATIC_METHOD_ENTRY(getOCGs, 0)
- JS_STATIC_METHOD_ENTRY(getPageBox, 0)
- JS_STATIC_METHOD_ENTRY(getPageNthWord, 3)
- JS_STATIC_METHOD_ENTRY(getPageNthWordQuads, 2)
- JS_STATIC_METHOD_ENTRY(getPageNumWords, 1)
- JS_STATIC_METHOD_ENTRY(getPrintParams, 0)
- JS_STATIC_METHOD_ENTRY(getURL, 2)
- JS_STATIC_METHOD_ENTRY(importAnFDF, 1)
- JS_STATIC_METHOD_ENTRY(importAnXFDF, 1)
- JS_STATIC_METHOD_ENTRY(importTextData, 2)
- JS_STATIC_METHOD_ENTRY(insertPages, 4)
- JS_STATIC_METHOD_ENTRY(mailForm, 6)
- JS_STATIC_METHOD_ENTRY(print, 9)
- JS_STATIC_METHOD_ENTRY(removeField, 1)
- JS_STATIC_METHOD_ENTRY(replacePages, 4)
- JS_STATIC_METHOD_ENTRY(resetForm, 1)
- JS_STATIC_METHOD_ENTRY(removeIcon, 0)
- JS_STATIC_METHOD_ENTRY(saveAs, 5)
- JS_STATIC_METHOD_ENTRY(submitForm, 23)
- JS_STATIC_METHOD_ENTRY(mailDoc, 0)
-END_JS_STATIC_METHOD()
-
-IMPLEMENT_JS_CLASS(CJS_Document, Document)
-
-FX_BOOL CJS_Document::InitInstance(IFXJS_Context* cc)
-{
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
-
- Document* pDoc = (Document*)GetEmbedObject();
- ASSERT(pDoc != NULL);
-
- pDoc->AttachDoc(pContext->GetReaderDocument());
- pDoc->SetIsolate(pContext->GetJSRuntime()->GetIsolate());
- return TRUE;
-};
-
-/* --------------------------------- Document --------------------------------- */
-
-Document::Document(CJS_Object* pJSObject) : CJS_EmbedObj(pJSObject),
- m_cwBaseURL(L""),
- m_pIconTree(NULL),
- m_pDocument(NULL),
- m_bDelay(FALSE),
- m_isolate(NULL)
-{
-}
-
-Document::~Document()
-{
- if (m_pIconTree)
- {
- m_pIconTree->DeleteIconTree();
- delete m_pIconTree;
- m_pIconTree = NULL;
- }
- for (int i=0; i<m_DelayData.GetSize(); i++)
- {
- if (CJS_DelayData* pData = m_DelayData.GetAt(i))
- {
- delete pData;
- pData = NULL;
- m_DelayData.SetAt(i, NULL);
-
- }
- }
-
- m_DelayData.RemoveAll();
- m_DelayAnnotData.RemoveAll();
-}
-
-//the total number of fileds in document.
-FX_BOOL Document::numFields(OBJ_PROP_PARAMS)
-{
- if (!vp.IsGetting()) return FALSE;
-
- ASSERT(m_pDocument != NULL);
-
- CPDFSDK_InterForm *pInterForm = m_pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- CPDF_InterForm *pPDFForm = pInterForm->GetInterForm();
- ASSERT(pPDFForm != NULL);
-
- vp << (int)pPDFForm->CountFields();
-
- return TRUE;
-}
-
-FX_BOOL Document::dirty(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsGetting())
- {
- if (m_pDocument->GetChangeMark())
- vp << true;
- else
- vp << false;
- }
- else
- {
- bool bChanged = false;
-
- vp >> bChanged;
-
- if (bChanged)
- m_pDocument->SetChangeMark();
- else
- m_pDocument->ClearChangeMark();
- }
-
- return TRUE;
-}
-
-FX_BOOL Document::ADBE(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsGetting())
- {
- vp.SetNull();
- }
- else
- {
- }
-
- return TRUE;
-}
-
-FX_BOOL Document::pageNum(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsGetting())
- {
- if (CPDFSDK_PageView* pPageView = m_pDocument->GetCurrentView())
- {
- vp << pPageView->GetPageIndex();
- }
- }
- else
- {
- int iPageCount = m_pDocument->GetPageCount();
-
- int iPageNum = 0;
- vp >> iPageNum;
-
- CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
- if(!pEnv)
- return FALSE;
-
- if (iPageNum >= 0 && iPageNum < iPageCount)
- {
- pEnv->JS_docgotoPage(iPageNum);
- }
- else if (iPageNum >= iPageCount)
- {
- pEnv->JS_docgotoPage(iPageCount-1);
- }
- else if (iPageNum < 0)
- {
- pEnv->JS_docgotoPage(0);
- }
- }
-
- return TRUE;
-}
-
-FX_BOOL Document::ParserParams(JSObject* pObj,CJS_AnnotObj& annotobj)
-{
- return TRUE;
-}
-
-FX_BOOL Document::addAnnot(OBJ_METHOD_PARAMS)
-{
- return TRUE;
-}
-
-FX_BOOL Document::addField(OBJ_METHOD_PARAMS)
-{
- //Doesn't support.
- return TRUE;
-}
-
-//exports form fields as a tab-delimited text file to a local hard disk.
-//comment: need reader support
-//note : watch the third parameter:cPath, for what case it can be safely saved?
-//int CPDFSDK_InterForm::ExportAsText(FX_BOOL bNoPassword,StringArray aFields,String cPath);
-//return value, int the index of the parameters illegal, the index is based on 1.
-
-FX_BOOL Document::exportAsText(OBJ_METHOD_PARAMS)
-{
- if (IsSafeMode(cc)) return TRUE;
- return TRUE;
-}
-
-//exports form fields as a fdf file to the local hard drive
-//comment: need reader supports
-//note:the last parameter hasn't been confirmed.because the previous one blocks the way.
-//int CPDFSDK_Document::ExportAsFDF(FX_BOOL bAllFields,BOOL bNoPassword,StringArray aFields,FX_BOOL bFlags,String cPath,FX_BOOL bAnnotations);
-
-FX_BOOL Document::exportAsFDF(OBJ_METHOD_PARAMS)
-{
- v8::Isolate* isolate = GetIsolate(cc);
- if (IsSafeMode(cc)) return TRUE;
-
- ASSERT(m_pDocument != NULL);
-
- if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE;
-
- FX_BOOL bAllFields = params.size() > 0 ? (FX_BOOL)params[0] : FALSE;
- FX_BOOL bNoPassWord = params.size() > 1 ? (FX_BOOL)params[1] : TRUE;
- FX_BOOL bWhole = params.size() > 2 ? (params[2].GetType() == VT_null) : TRUE;
- CJS_Array arrayFileds(isolate);
- if (!bWhole)
- arrayFileds.Attach(params[2]);
- //FX_BOOL bFlags = params.size() > 3 ? (FX_BOOL)params[3] : FALSE;
- CFX_WideString swFilePath = params.size() > 4 ? (FX_LPCWSTR)params[4].operator CFX_WideString() : (FX_LPCWSTR)L"";
-
- if (swFilePath.IsEmpty())
- {
- CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
- swFilePath = pEnv->JS_fieldBrowse();
- if(swFilePath.IsEmpty())
- return TRUE;
- }
- else
- {
- swFilePath = app::PDFPathToSysPath(swFilePath);
- }
-
- m_pDocument->SetFocusAnnot(NULL);
-
- CPDFSDK_InterForm* pInterForm= (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
- ASSERT(pPDFForm != NULL);
-
- CFX_PtrArray aFields;
-
- if (bWhole)
- {
- for (int j=0,jsz=pPDFForm->CountFields(); j<jsz; j++)
- {
- aFields.Add(pPDFForm->GetField(j));
- }
- }
- else
- {
- for (int i=0,isz=arrayFileds.GetLength(); i<isz; i++)
- {
- CJS_Value valName(isolate);
- arrayFileds.GetElement(i,valName);
- CFX_WideString swName = valName.operator CFX_WideString();
-
- for (int j=0, jsz=pPDFForm->CountFields(swName); j<jsz; j++)
- {
- aFields.Add(pPDFForm->GetField(j, swName));
- }
- }
- }
-
- CFX_PtrArray fields;
-
- for (int i=0,sz=aFields.GetSize(); i<sz; i++)
- {
- CPDF_FormField* pField = (CPDF_FormField*)aFields[i];
-
- if (!bAllFields)
- if (pField->GetValue() == L"")
- continue;
-
- if (bNoPassWord)
- if (pField->GetFieldFlags() & 0x2000)
- continue;
-
- fields.Add((void*)pField);
- }
-
- return pInterForm->ExportFieldsToFDFFile(swFilePath, fields, TRUE);
-}
-
-//exports form fields an XFDF file to the local hard drive
-//comment: need reder supports
-//note:the last parameter can't be test
-//int CPDFSDK_Document::ExportAsXFDF(FX_BOOL bAllFields,FX_BOOL bNoPassWord,StringArray aFields,String cPath,FX_BOOL bAnnoatations);
-
-FX_BOOL Document::exportAsXFDF(OBJ_METHOD_PARAMS)
-{
- if (IsSafeMode(cc)) return TRUE;
- ASSERT(m_pDocument != NULL);
-
- if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE;
-
- return TRUE;
-}
-
-//Maps a field object in PDF document to a JavaScript variable
-//comment:
-//note: the paremter cName, this is clue how to treat if the cName is not a valiable filed name in this document
-
-FX_BOOL Document::getField(OBJ_METHOD_PARAMS)
-{
- v8::Isolate* isolate = GetIsolate(cc);
- ASSERT(m_pDocument != NULL);
-
- if (params.size() < 1) return FALSE;
-
- CFX_WideString wideName = params[0].operator CFX_WideString();
-
- CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
- ASSERT(pPDFForm != NULL);
-
- if (pPDFForm->CountFields(wideName) <= 0)
- {
- vRet.SetNull();
- return TRUE;
- }
-
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
-
- JSFXObject pFieldObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"Field"));
-
- CJS_Field * pJSField = (CJS_Field*)JS_GetPrivate(isolate,pFieldObj);
- ASSERT(pJSField != NULL);
-
- Field * pField = (Field *)pJSField->GetEmbedObject();
- ASSERT(pField != NULL);
-
- pField->AttachField(this, wideName);
- vRet = pJSField;
-
- return TRUE;
-}
-
-//Gets the name of the nth field in the document
-//comment:
-//note: the parameter nIndex, if it is not available
-
-FX_BOOL Document::getNthFieldName(OBJ_METHOD_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- int nIndex = params.size() > 0 ? (int)params[0] : -1;
- if (nIndex == -1) return FALSE;
-
- CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
- ASSERT(pPDFForm != NULL);
-
- CPDF_FormField* pField = pPDFForm->GetField(nIndex);
- if (!pField)
- return FALSE;
-
- vRet = pField->GetFullName();
- return TRUE;
-}
-
-//imports the specified fdf file.
-//comments: need reader suppport
-//note:once the cpath is illigl then a file dialog box pops up in order to ask user to chooose the file
-//int CPDFSDK_Document::importAnFDF(String cPath);
-
-FX_BOOL Document::importAnFDF(OBJ_METHOD_PARAMS)
-{
- if (IsSafeMode(cc)) return TRUE;
- ASSERT(m_pDocument != NULL);
-
- if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) ||
- m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) ||
- m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) return FALSE;
-
-
- CFX_WideString swPath;
-
- if (params.size() > 0)
- swPath = params[0];
-
- if (swPath.IsEmpty())
- {
- CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
- swPath = pEnv->JS_fieldBrowse();
- if(swPath.IsEmpty())
- return TRUE;
- }
- else
- {
- swPath = app::PDFPathToSysPath(swPath);
- }
-
- m_pDocument->SetFocusAnnot(NULL);
-
- CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- if (!pInterForm->ImportFormFromFDFFile(swPath, TRUE))
- return FALSE;
-
- m_pDocument->SetChangeMark();
-// CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
-// ASSERT(pEnv != NULL);
-// IUndo* pUndo = IUndo::GetUndo(pEnv);
-// ASSERT(pUndo != NULL);
-// pUndo->Reset(m_pDocument);
-
- return TRUE;
-}
-
-//imports and specified XFDF file containing XML form data
-//comment: need reader supports
-//note: same as up
-//int CPDFSDK_Document::importAnFDF(String cPath)
-
-FX_BOOL Document::importAnXFDF(OBJ_METHOD_PARAMS)
-{
- if (IsSafeMode(cc)) return TRUE;
- ASSERT(m_pDocument != NULL);
-
- if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) ||
- m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) ||
- m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) return FALSE;
-
- return TRUE;
-}
-
-//imports and specified text file
-//commnet: need reader supports
-//note: same as up,when nRow is not rational,adobe is dumb for it.
-//int CPDFSDK_Document::importTextData(String cPath,int nRow);
-
-FX_BOOL Document::importTextData(OBJ_METHOD_PARAMS)
-{
- if (IsSafeMode(cc)) return TRUE;
- ASSERT(m_pDocument != NULL);
-
- if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) ||
- m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) ||
- m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) return FALSE;
-
- return TRUE;
-}
-
-//exports the form data and mails the resulting fdf file as an attachment to all recipients.
-//comment: need reader supports
-//note:
-//int CPDFSDK_Document::mailForm(FX_BOOL bUI,String cto,string ccc,string cbcc,string cSubject,string cms);
-
-FX_BOOL Document::mailForm(OBJ_METHOD_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE;
-
- int iLength = params.size();
-
- FX_BOOL bUI = iLength > 0 ? (FX_BOOL)params[0] : TRUE;
- CFX_WideString cTo = iLength > 1 ? (FX_LPCWSTR)params[1].operator CFX_WideString() : (FX_LPCWSTR)L"";
- CFX_WideString cCc = iLength > 2 ? (FX_LPCWSTR)params[2].operator CFX_WideString() : (FX_LPCWSTR)L"";
- CFX_WideString cBcc = iLength > 3 ? (FX_LPCWSTR)params[3].operator CFX_WideString() : (FX_LPCWSTR)L"";
- CFX_WideString cSubject = iLength > 4 ? (FX_LPCWSTR)params[4].operator CFX_WideString() : (FX_LPCWSTR)L"";
- CFX_WideString cMsg = iLength > 5 ? (FX_LPCWSTR)params[5].operator CFX_WideString() : (FX_LPCWSTR)L"";
-
- CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- CFX_ByteTextBuf textBuf;
- if (!pInterForm->ExportFormToFDFTextBuf(textBuf))
- return FALSE;
-
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CPDFDoc_Environment* pEnv = pContext->GetReaderApp();
- ASSERT(pEnv != NULL);
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
-
- pRuntime->BeginBlock();
- pEnv->JS_docmailForm(textBuf.GetBuffer(), textBuf.GetLength(), bUI, (FX_LPCWSTR)cTo, (FX_LPCWSTR)cSubject, (FX_LPCWSTR)cCc, (FX_LPCWSTR)cBcc, (FX_LPCWSTR)cMsg);
- pRuntime->EndBlock();
- return TRUE;
-}
-
-FX_BOOL Document::print(OBJ_METHOD_PARAMS)
-{
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
-
- FX_BOOL bUI = TRUE;
- int nStart = 0;
- int nEnd = 0;
- FX_BOOL bSilent = FALSE;
- FX_BOOL bShrinkToFit = FALSE;
- FX_BOOL bPrintAsImage = FALSE;
- FX_BOOL bReverse = FALSE;
- FX_BOOL bAnnotations = FALSE;
-
- int nlength = params.size();
- if(nlength ==9)
- {
- if (params[8].GetType() == VT_fxobject)
- {
- JSFXObject pObj = (JSFXObject)params[8];
- {
- if (JS_GetObjDefnID(pObj) == JS_GetObjDefnID(*pRuntime, L"PrintParamsObj"))
- {
- if (CJS_Object* pJSObj = (CJS_Object*)params[8])
- {
- if (PrintParamsObj* pprintparamsObj = (PrintParamsObj*)pJSObj->GetEmbedObject())
- {
- bUI = pprintparamsObj->bUI;
- nStart = pprintparamsObj->nStart;
- nEnd = pprintparamsObj->nEnd;
- bSilent = pprintparamsObj->bSilent;
- bShrinkToFit = pprintparamsObj->bShrinkToFit;
- bPrintAsImage = pprintparamsObj->bPrintAsImage;
- bReverse = pprintparamsObj->bReverse;
- bAnnotations = pprintparamsObj->bAnnotations;
- }
- }
- }
- }
- }
- }
- else
- {
- if(nlength >= 1)
- bUI = params[0];
- if(nlength >= 2)
- nStart = (int)params[1];
- if(nlength >= 3)
- nEnd = (int)params[2];
- if(nlength >= 4)
- bSilent = params[3];
- if(nlength >= 5)
- bShrinkToFit = params[4];
- if(nlength >= 6)
- bPrintAsImage = params[5];
- if(nlength >= 7)
- bReverse = params[6];
- if(nlength >= 8)
- bAnnotations = params[7];
- }
-
- ASSERT(m_pDocument != NULL);
-
- if (CPDFDoc_Environment* pEnv = m_pDocument->GetEnv())
- {
- pEnv->JS_docprint(bUI, nStart, nEnd, bSilent, bShrinkToFit, bPrintAsImage, bReverse, bAnnotations);
- return TRUE;
- }
- return FALSE;
-}
-
-//removes the specified field from the document.
-//comment:
-//note: if the filed name is not retional, adobe is dumb for it.
-
-FX_BOOL Document::removeField(OBJ_METHOD_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) ||
- m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM))) return FALSE;
-
- if (params.size() < 1)
- return TRUE;
-
- CFX_WideString sFieldName = params[0].operator CFX_WideString();
-
- CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- CFX_PtrArray widgets;
- pInterForm->GetWidgets(sFieldName, widgets);
-
- int nSize = widgets.GetSize();
-
- if (nSize > 0)
- {
- for (int i=0; i<nSize; i++)
- {
- CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)widgets[i];
- ASSERT(pWidget != NULL);
-
- CPDF_Rect rcAnnot = pWidget->GetRect();
- rcAnnot.left -= 1;
- rcAnnot.bottom -= 1;
- rcAnnot.right += 1;
- rcAnnot.top += 1;
-
- CFX_RectArray aRefresh;
- aRefresh.Add(rcAnnot);
-
- CPDF_Page* pPage = pWidget->GetPDFPage();
- ASSERT(pPage != NULL);
-
- CPDFSDK_PageView* pPageView = m_pDocument->GetPageView(pPage);
- pPageView->DeleteAnnot(pWidget);
-
- pPageView->UpdateRects(aRefresh);
- }
- m_pDocument->SetChangeMark();
- }
-
- return TRUE;
-}
-
-//reset filed values within a document.
-//comment:
-//note: if the fields names r not rational, aodbe is dumb for it.
-
-FX_BOOL Document::resetForm(OBJ_METHOD_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) ||
- m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) ||
- m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) return FALSE;
-
- CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
- ASSERT(pPDFForm != NULL);
-
- v8::Isolate* isolate = GetIsolate(cc);
- CJS_Array aName(isolate);
-
- if (params.size() > 0)
- {
- switch (params[0].GetType())
- {
- default:
- aName.Attach(params[0]);
- break;
- case VT_string:
- aName.SetElement(0,params[0]);
- break;
- }
-
- CFX_PtrArray aFields;
-
- for (int i=0,isz=aName.GetLength(); i<isz; i++)
- {
- CJS_Value valElement(isolate);
- aName.GetElement(i,valElement);
- CFX_WideString swVal = valElement.operator CFX_WideString();
-
- for (int j=0,jsz=pPDFForm->CountFields(swVal); j<jsz; j++)
- {
- aFields.Add((void*)pPDFForm->GetField(j,swVal));
- }
- }
-
- if (aFields.GetSize() > 0)
- {
- pPDFForm->ResetForm(aFields, TRUE, TRUE);
- m_pDocument->SetChangeMark();
-
- }
- }
- else
- {
- pPDFForm->ResetForm(TRUE);
- m_pDocument->SetChangeMark();
-
- }
-
- return TRUE;
-}
-
-
-FX_BOOL Document::saveAs(OBJ_METHOD_PARAMS)
-{
-
- if (IsSafeMode(cc)) return TRUE;
-
- ASSERT(m_pDocument != NULL);
-
-// m_pDocument->DoSaveAs();
-
- return TRUE;
-}
-
-
-FX_BOOL Document::submitForm(OBJ_METHOD_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
-// if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE;
-
- int nSize = params.size();
- if (nSize < 1) return FALSE;
-
- CFX_WideString strURL;
- FX_BOOL bFDF = TRUE;
- FX_BOOL bEmpty = FALSE;
- v8::Isolate* isolate = GetIsolate(cc);
- CJS_Array aFields(isolate);
-
- CJS_Value v = params[0];
- if (v.GetType() == VT_string)
- {
- strURL = params[0].operator CFX_WideString();
- if (nSize > 1)
- bFDF = params[1];
- if (nSize > 2)
- bEmpty = params[2];
- if (nSize > 3)
- aFields.Attach(params[3]);
- }
- else if (v.GetType() == VT_object)
- {
- JSObject pObj = (JSObject)params[0];
- v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj, L"cURL");
- if (!pValue.IsEmpty())
- strURL = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue));
- pValue = JS_GetObjectElement(isolate,pObj, L"bFDF");
- bFDF = CJS_Value(isolate,pValue, GET_VALUE_TYPE(pValue));
- pValue = JS_GetObjectElement(isolate,pObj, L"bEmpty");
- bEmpty = CJS_Value(isolate,pValue, GET_VALUE_TYPE(pValue));
- pValue = JS_GetObjectElement(isolate,pObj,L"aFields");
- aFields.Attach(CJS_Value(isolate,pValue, GET_VALUE_TYPE(pValue)));
- }
-
- CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
- CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm();
- ASSERT(pPDFInterForm != NULL);
-
- FX_BOOL bAll = (aFields.GetLength() == 0);
-
- if (bAll && bEmpty)
- {
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
-
-
- if (pPDFInterForm->CheckRequiredFields())
- {
- pRuntime->BeginBlock();
- pInterForm->SubmitForm(strURL, FALSE);
- pRuntime->EndBlock();
- }
-
- return TRUE;
- }
- else
- {
- CFX_PtrArray fieldObjects;
-
- for (int i=0,sz=aFields.GetLength(); i<sz; i++)
- {
- CJS_Value valName(isolate);
- aFields.GetElement(i, valName);
- CFX_WideString sName = valName.operator CFX_WideString();
-
- CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
- ASSERT(pPDFForm != NULL);
-
- for (int j=0, jsz=pPDFForm->CountFields(sName); j<jsz; j++)
- {
- CPDF_FormField* pField = pPDFForm->GetField(j, sName);
- if (!bEmpty && pField->GetValue().IsEmpty())
- continue;
-
- fieldObjects.Add(pField);
- }
- }
-
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
-
-
- if (pPDFInterForm->CheckRequiredFields(&fieldObjects, TRUE))
- {
- pRuntime->BeginBlock();
- pInterForm->SubmitFields(strURL, fieldObjects, TRUE, !bFDF);
- pRuntime->EndBlock();
- }
-
- return TRUE;
- }
-
-}
-
-//////////////////////////////////////////////////////////////////////////////////////////////
-
-void Document::AttachDoc(CPDFSDK_Document *pDoc)
-{
- m_pDocument = pDoc;
-}
-
-CPDFSDK_Document * Document::GetReaderDoc()
-{
- return m_pDocument;
-}
-
-FX_BOOL Document::ExtractFileName(CPDFSDK_Document *pDoc,CFX_ByteString &strFileName)
-{
- return FALSE;
-}
-
-FX_BOOL Document::ExtractFolderName(CPDFSDK_Document *pDoc,CFX_ByteString &strFolderName)
-{
- return FALSE;
-}
-
-FX_BOOL Document::bookmarkRoot(OBJ_PROP_PARAMS)
-{
- return TRUE;
-}
-
-FX_BOOL Document::mailDoc(OBJ_METHOD_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- FX_BOOL bUI = TRUE;
- CFX_WideString cTo = L"";
- CFX_WideString cCc = L"";
- CFX_WideString cBcc = L"";
- CFX_WideString cSubject = L"";
- CFX_WideString cMsg = L"";
-
-
- bUI = params.size()>=1?static_cast<FX_BOOL>(params[0]):TRUE;
- cTo = params.size()>=2?(const wchar_t*)params[1].operator CFX_WideString():L"";
- cCc = params.size()>=3?(const wchar_t*)params[2].operator CFX_WideString():L"";
- cBcc = params.size()>=4?(const wchar_t*)params[3].operator CFX_WideString():L"";
- cSubject = params.size()>=5?(const wchar_t*)params[4].operator CFX_WideString():L"";
- cMsg = params.size()>=6?(const wchar_t*)params[5].operator CFX_WideString():L"";
-
- v8::Isolate* isolate = GetIsolate(cc);
-
- if(params.size()>=1 && params[0].GetType() == VT_object)
- {
- JSObject pObj = (JSObject )params[0];
-
- v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj, L"bUI");
- bUI = (int)CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue));
-
- pValue = JS_GetObjectElement(isolate,pObj, L"cTo");
- cTo = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
-
- pValue = JS_GetObjectElement(isolate,pObj, L"cCc");
- cCc = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
-
- pValue = JS_GetObjectElement(isolate,pObj, L"cBcc");
- cBcc = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
-
- pValue = JS_GetObjectElement(isolate,pObj, L"cSubject");
- cSubject = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
-
- pValue = JS_GetObjectElement(isolate,pObj, L"cMsg");
- cMsg = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
-
- }
-
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
-
- pRuntime->BeginBlock();
- CPDFDoc_Environment* pEnv = pRuntime->GetReaderApp();
- pEnv->JS_docmailForm(NULL, 0, bUI, (FX_LPCWSTR)cTo, (FX_LPCWSTR)cSubject, (FX_LPCWSTR)cCc, (FX_LPCWSTR)cBcc, (FX_LPCWSTR)cMsg);
- pRuntime->EndBlock();
-
- return TRUE;
-}
-
-FX_BOOL Document::author(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
- if (!pDictionary)return FALSE;
-
- if (vp.IsGetting())
- {
- vp << pDictionary->GetUnicodeText("Author");
- return TRUE;
- }
- else
- {
- if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE;
-
- CFX_WideString csAuthor;
- vp >> csAuthor;
- pDictionary->SetAtString("Author", PDF_EncodeText(csAuthor));
- m_pDocument->SetChangeMark();
- return TRUE;
- }
-}
-
-FX_BOOL Document::info(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
- if (!pDictionary)return FALSE;
-
- CFX_WideString cwAuthor = pDictionary->GetUnicodeText("Author");
- CFX_WideString cwTitle = pDictionary->GetUnicodeText("Title");
- CFX_WideString cwSubject = pDictionary->GetUnicodeText("Subject");
- CFX_WideString cwKeywords = pDictionary->GetUnicodeText("Keywords");
- CFX_WideString cwCreator = pDictionary->GetUnicodeText("Creator");
- CFX_WideString cwProducer = pDictionary->GetUnicodeText("Producer");
- CFX_WideString cwCreationDate = pDictionary->GetUnicodeText("CreationDate");
- CFX_WideString cwModDate = pDictionary->GetUnicodeText("ModDate");
- CFX_WideString cwTrapped = pDictionary->GetUnicodeText("Trapped");
-
- v8::Isolate* isolate = GetIsolate(cc);
- if (!vp.IsSetting())
- {
- CJS_Context* pContext = (CJS_Context *)cc;
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
-
- JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContext, -1);
-
- JS_PutObjectString(isolate,pObj, L"Author", cwAuthor);
- JS_PutObjectString(isolate,pObj, L"Title", cwTitle);
- JS_PutObjectString(isolate,pObj, L"Subject", cwSubject);
- JS_PutObjectString(isolate,pObj, L"Keywords", cwKeywords);
- JS_PutObjectString(isolate,pObj, L"Creator", cwCreator);
- JS_PutObjectString(isolate,pObj, L"Producer", cwProducer);
- JS_PutObjectString(isolate,pObj, L"CreationDate", cwCreationDate);
- JS_PutObjectString(isolate,pObj, L"ModDate", cwModDate);
- JS_PutObjectString(isolate,pObj, L"Trapped", cwTrapped);
-
-// It's to be compatible to non-standard info dictionary.
- FX_POSITION pos = pDictionary->GetStartPos();
- while(pos)
- {
- CFX_ByteString bsKey;
- CPDF_Object* pValueObj = pDictionary->GetNextElement(pos, bsKey);
- CFX_WideString wsKey = CFX_WideString::FromUTF8(bsKey);
- if((pValueObj->GetType()==PDFOBJ_STRING) || (pValueObj->GetType()==PDFOBJ_NAME) )
- JS_PutObjectString(isolate,pObj, wsKey, pValueObj->GetUnicodeText());
- if(pValueObj->GetType()==PDFOBJ_NUMBER)
- JS_PutObjectNumber(isolate,pObj, wsKey, (float)pValueObj->GetNumber());
- if(pValueObj->GetType()==PDFOBJ_BOOLEAN)
- JS_PutObjectBoolean(isolate,pObj, wsKey, (bool)pValueObj->GetInteger());
- }
-
- vp << pObj;
- return TRUE;
- }
- else
- {
- return TRUE;
- }
-}
-
-FX_BOOL Document::creationDate(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
- if (!pDictionary)return FALSE;
-
- if (vp.IsGetting())
- {
- vp << pDictionary->GetUnicodeText("CreationDate");
- return TRUE;
- }
- else
- {
- if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE;
-
- CFX_WideString csCreationDate;
- vp >> csCreationDate;
- pDictionary->SetAtString("CreationDate", PDF_EncodeText(csCreationDate));
- m_pDocument->SetChangeMark();
-
- return TRUE;
- }
-}
-
-FX_BOOL Document::creator(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
- if (!pDictionary)return FALSE;
-
- if (vp.IsGetting())
- {
- vp << pDictionary->GetUnicodeText("Creator");
- return TRUE;
- }
- else
- {
- if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE;
-
- CFX_WideString csCreator;
- vp >> csCreator;
- pDictionary->SetAtString("Creator", PDF_EncodeText(csCreator));
- m_pDocument->SetChangeMark();
- return TRUE;
- }
-}
-
-FX_BOOL Document::delay(OBJ_PROP_PARAMS)
-{
- if (vp.IsGetting())
- {
- vp << m_bDelay;
- return TRUE;
- }
- else
- {
- ASSERT(m_pDocument != NULL);
-
- if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE;
-
- bool b;
- vp >> b;
-
- m_bDelay = b;
-
- if (m_bDelay)
- {
- for (int i=0,sz=m_DelayData.GetSize(); i<sz; i++)
- delete m_DelayData.GetAt(i);
-
- m_DelayData.RemoveAll();
- }
- else
- {
- for (int i=0,sz=m_DelayData.GetSize(); i<sz; i++)
- {
- if (CJS_DelayData* pData = m_DelayData.GetAt(i))
- {
- Field::DoDelay(m_pDocument, pData);
- delete m_DelayData.GetAt(i);
- }
- }
- m_DelayData.RemoveAll();
- }
-
- return TRUE;
- }
-}
-
-FX_BOOL Document::keywords(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
- if (!pDictionary)return FALSE;
-
- if (vp.IsGetting())
- {
- vp << pDictionary->GetUnicodeText("Keywords");
- return TRUE;
- }
- else
- {
- if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE;
-
- CFX_WideString csKeywords;
- vp >> csKeywords;
- pDictionary->SetAtString("Keywords", PDF_EncodeText(csKeywords));
- m_pDocument->SetChangeMark();
- return TRUE;
- }
-}
-
-FX_BOOL Document::modDate(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
- if (!pDictionary)return FALSE;
-
- if (vp.IsGetting())
- {
- vp << pDictionary->GetUnicodeText("ModDate");
- return TRUE;
- }
- else
- {
- if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE;
-
- CFX_WideString csmodDate;
- vp >> csmodDate;
- pDictionary->SetAtString("ModDate", PDF_EncodeText(csmodDate));
- m_pDocument->SetChangeMark();
- return TRUE;
- }
-}
-
-FX_BOOL Document::producer(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
- if (!pDictionary)return FALSE;
-
- if (vp.IsGetting())
- {
- vp << pDictionary->GetUnicodeText("Producer");
- return TRUE;
- }
- else
- {
- if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE;
-
- CFX_WideString csproducer;
- vp >> csproducer;
- pDictionary->SetAtString("Producer", PDF_EncodeText(csproducer));
- m_pDocument->SetChangeMark();
- return TRUE;
- }
-}
-
-FX_BOOL Document::subject(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
- if (!pDictionary)return FALSE;
-
- if (vp.IsGetting())
- {
- vp << pDictionary->GetUnicodeText("Subject");
- return TRUE;
- }
- else
- {
- if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE;
-
- CFX_WideString cssubject;
- vp >> cssubject;
- pDictionary->SetAtString("Subject", PDF_EncodeText(cssubject));
- m_pDocument->SetChangeMark();
- return TRUE;
- }
-}
-
-FX_BOOL Document::title(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (m_pDocument == NULL || m_pDocument->GetDocument() == NULL)
- return FALSE;
-
- CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
- if (!pDictionary)return FALSE;
-
- if (vp.IsGetting())
- {
- vp << pDictionary->GetUnicodeText("Title");
- return TRUE;
- }
- else
- {
- if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE;
-
- CFX_WideString cstitle;
- vp >> cstitle;
- pDictionary->SetAtString("Title", PDF_EncodeText(cstitle));
- m_pDocument->SetChangeMark();
- return TRUE;
- }
-}
-
-FX_BOOL Document::numPages(OBJ_PROP_PARAMS)
-{
- if (vp.IsGetting())
- {
- ASSERT(m_pDocument != NULL);
- vp << m_pDocument->GetPageCount();
- return TRUE;
- }
- else
- {
- return FALSE;
- }
-}
-
-FX_BOOL Document::external(OBJ_PROP_PARAMS)
-{
- //In Chrome case,should always return true.
- vp << TRUE;
- return TRUE;
-}
-
-FX_BOOL Document::filesize(OBJ_PROP_PARAMS)
-{
- if (!vp.IsGetting())return FALSE;
-
- ASSERT(m_pDocument != NULL);
-
-// CFile file(m_pDocument->GetPath(), CFile::modeRead | CFile::typeBinary | CFile::shareDenyNone);
-// vp << (double)file.GetLength();
-// file.Close();
-
- if ( m_pDocument->GetPath().IsEmpty() == FALSE)
- {
- CFX_ByteString bsStr = CFX_ByteString::FromUnicode( m_pDocument->GetPath() );
- FILE * pFile = NULL;
- pFile = fopen( bsStr.GetBuffer( bsStr.GetLength() ), "rb" );
- if ( pFile )
- {
- fseek( pFile, 0, SEEK_END );
- long lSize = ftell( pFile );
- fclose( pFile );
- pFile = NULL;
-
- vp << (FX_INT32)(lSize);
- return TRUE;
- }
- }
-
- vp << 0;
- return TRUE;
-}
-
-FX_BOOL Document::mouseX(OBJ_PROP_PARAMS)
-{
- return TRUE;
-}
-
-FX_BOOL Document::mouseY(OBJ_PROP_PARAMS)
-{
- return TRUE;
-}
-
-FX_BOOL Document::baseURL(OBJ_PROP_PARAMS)
-{
- if (vp.IsGetting())
- {
- vp << m_cwBaseURL;
- return TRUE;
- }
- else
- {
- vp >> m_cwBaseURL;
- return TRUE;
- }
-}
-
-FX_BOOL Document::calculate(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- if (vp.IsGetting())
- {
- if (pInterForm->IsCalculateEnabled())
- vp << true;
- else
- vp << false;
- }
- else
- {
- bool bCalculate;
- vp >> bCalculate;
-
- pInterForm->EnableCalculate(bCalculate);
- }
-
- return TRUE;
-}
-
-FX_BOOL Document::documentFileName(OBJ_PROP_PARAMS)
-{
- if (!vp.IsGetting())
- return FALSE;
-
- CFX_WideString wsFilePath = m_pDocument->GetPath();
-
- FX_INT32 i = wsFilePath.GetLength() - 1;
- for ( ; i >= 0; i-- )
- {
- if ( wsFilePath.GetAt( i ) == L'\\' || wsFilePath.GetAt( i ) == L'/' )
- break;
- }
- if ( i >= 0 && i < wsFilePath.GetLength() - 1 )
- {
- vp << ( wsFilePath.GetBuffer( wsFilePath.GetLength() ) + i + 1 );
- }else{
- vp << L"";
- }
- return TRUE;
-}
-
-CFX_WideString Document::ReversalStr(CFX_WideString cbFrom)
-{
- wchar_t* pFrom = NULL;
- int iLenth = cbFrom.GetLength();
- wchar_t* pResult = (wchar_t*)malloc((iLenth+1) * sizeof(wchar_t));
- memset(pResult, 0, (iLenth+1));
- pFrom = (wchar_t*)cbFrom.GetBuffer(iLenth);
-
- for (int i = 0; i < iLenth; i++)
- {
- pResult[i] = *(pFrom + iLenth - i - 1);
- }
-
- cbFrom.ReleaseBuffer();
- CFX_WideString cbRet = CFX_WideString(pResult);
- free(pResult);
- pResult = NULL;
- return cbRet;
-}
-
-CFX_WideString Document::CutString(CFX_WideString cbFrom)
-{
- wchar_t* pFrom = NULL;
- int iLenth = cbFrom.GetLength();
- wchar_t* pResult = (wchar_t*)malloc((iLenth+1) * sizeof(wchar_t));
- memset(pResult, 0, (iLenth+1));
- pFrom = (wchar_t*)cbFrom.GetBuffer(iLenth);
-
- for (int i = 0; i < iLenth; i++)
- {
- if (pFrom[i] == L'\\' || pFrom[i] == L'/')
- break;
- pResult[i] = pFrom[i];
- }
-
- cbFrom.ReleaseBuffer();
- CFX_WideString cbRet = CFX_WideString(pResult);
- free(pResult);
- pResult = NULL;
- return cbRet;
-}
-
-FX_BOOL Document::path(OBJ_PROP_PARAMS)
-{
- if (!vp.IsGetting()) return FALSE;
-
- vp << app::SysPathToPDFPath(m_pDocument->GetPath());
-
- return TRUE;
-}
-
-FX_BOOL Document::pageWindowRect(OBJ_PROP_PARAMS)
-{
- return TRUE;
-}
-
-FX_BOOL Document::layout(OBJ_PROP_PARAMS)
-{
- return TRUE;
-}
-
-FX_BOOL Document::addLink(OBJ_METHOD_PARAMS)
-{
- return TRUE;
-}
-
-FX_BOOL Document::closeDoc(OBJ_METHOD_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
-
-
-
-
- return TRUE;
-}
-
-FX_BOOL Document::getPageBox(OBJ_METHOD_PARAMS)
-{
- return TRUE;
-}
-
-
-FX_BOOL Document::getAnnot(OBJ_METHOD_PARAMS)
-{
- return TRUE;
-}
-
-FX_BOOL Document::getAnnots(OBJ_METHOD_PARAMS)
-{
- vRet.SetNull();
- return TRUE;
-}
-
-FX_BOOL Document::getAnnot3D(OBJ_METHOD_PARAMS)
-{
- vRet.SetNull();
- return TRUE;
-}
-
-FX_BOOL Document::getAnnots3D(OBJ_METHOD_PARAMS)
-{
- vRet = VT_undefined;
- return TRUE;
-}
-
-FX_BOOL Document::getOCGs(OBJ_METHOD_PARAMS)
-{
- return TRUE;
-}
-
-FX_BOOL Document::getLinks(OBJ_METHOD_PARAMS)
-{
- return TRUE;
-}
-
-bool Document::IsEnclosedInRect(CFX_FloatRect rect, CFX_FloatRect LinkRect)
-{
- if (rect.left <= LinkRect.left
- && rect.top <= LinkRect.top
- && rect.right >= LinkRect.right
- && rect.bottom >= LinkRect.bottom)
- return true;
- else
- return false;
-}
-
-void IconTree::InsertIconElement(IconElement* pNewIcon)
-{
- if (!pNewIcon)return;
-
- if (m_pHead == NULL && m_pEnd == NULL)
- {
- m_pHead = m_pEnd = pNewIcon;
- m_iLength++;
- }
- else
- {
- m_pEnd->NextIcon = pNewIcon;
- m_pEnd = pNewIcon;
- m_iLength++;
- }
-}
-
-void IconTree::DeleteIconTree()
-{
- if (!m_pHead || !m_pEnd)return;
-
- IconElement* pTemp = NULL;
- while(m_pEnd != m_pHead)
- {
- pTemp = m_pHead;
- m_pHead = m_pHead->NextIcon;
- delete pTemp;
- }
-
- delete m_pEnd;
- m_pHead = NULL;
- m_pEnd = NULL;
-}
-
-int IconTree::GetLength()
-{
- return m_iLength;
-}
-
-IconElement* IconTree::operator [](int iIndex)
-{
- if (iIndex >= 0 && iIndex <= m_iLength)
- {
- IconElement* pTemp = m_pHead;
- for (int i = 0; i < iIndex; i++)
- {
- pTemp = pTemp->NextIcon;
- }
- return pTemp;
- }
- else
- return NULL;
-}
-
-void IconTree::DeleteIconElement(CFX_WideString swIconName)
-{
- IconElement* pTemp = m_pHead;
- int iLoopCount = m_iLength;
- for (int i = 0; i < iLoopCount - 1; i++)
- {
- if (pTemp == m_pEnd)
- break;
-
- if (m_pHead->IconName == swIconName)
- {
- m_pHead = m_pHead->NextIcon;
- delete pTemp;
- m_iLength--;
- pTemp = m_pHead;
- }
- if (pTemp->NextIcon->IconName == swIconName)
- {
- if (pTemp->NextIcon == m_pEnd)
- {
- m_pEnd = pTemp;
- delete pTemp->NextIcon;
- m_iLength--;
- pTemp->NextIcon = NULL;
- }
- else
- {
- IconElement* pElement = pTemp->NextIcon;
- pTemp->NextIcon = pTemp->NextIcon->NextIcon;
- delete pElement;
- m_iLength--;
- pElement = NULL;
- }
-
- continue;
- }
-
- pTemp = pTemp->NextIcon;
- }
-}
-
-FX_BOOL Document::addIcon(OBJ_METHOD_PARAMS)
-{
- if (params.size() != 2)return FALSE;
-
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
-
- CFX_WideString swIconName = params[0].operator CFX_WideString();
-
- JSFXObject pJSIcon = (JSFXObject)params[1];
- if (JS_GetObjDefnID(pJSIcon) != JS_GetObjDefnID(*pRuntime, L"Icon")) return FALSE;
-
- CJS_EmbedObj* pEmbedObj = ((CJS_Object*)params[1])->GetEmbedObject();
- if (!pEmbedObj)return FALSE;
- Icon* pIcon = (Icon*)pEmbedObj;
-
- if (!m_pIconTree)
- m_pIconTree = new IconTree();
-
- IconElement* pNewIcon = new IconElement();
- pNewIcon->IconName = swIconName;
- pNewIcon->NextIcon = NULL;
- pNewIcon->IconStream = pIcon;
- m_pIconTree->InsertIconElement(pNewIcon);
- return TRUE;
-}
-
-FX_BOOL Document::icons(OBJ_PROP_PARAMS)
-{
- if (vp.IsSetting())
- return FALSE;
-
- if (!m_pIconTree)
- {
- vp.SetNull();
- return TRUE;
- }
-
- CJS_Array Icons(m_isolate);
- IconElement* pIconElement = NULL;
- int iIconTreeLength = m_pIconTree->GetLength();
-
- CJS_Context* pContext = (CJS_Context *)cc;
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
-
- for (int i = 0; i < iIconTreeLength; i++)
- {
- pIconElement = (*m_pIconTree)[i];
-
- JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"Icon"));
- if (pObj.IsEmpty()) return FALSE;
-
- CJS_Icon * pJS_Icon = (CJS_Icon *)JS_GetPrivate(pObj);
- if (!pJS_Icon) return FALSE;
-
- Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject();
- if (!pIcon)return FALSE;
-
- pIcon->SetStream(pIconElement->IconStream->GetStream());
- pIcon->SetIconName(pIconElement->IconName);
- Icons.SetElement(i, CJS_Value(m_isolate,pJS_Icon));
- }
-
- vp << Icons;
- return TRUE;
-}
-
-FX_BOOL Document::getIcon(OBJ_METHOD_PARAMS)
-{
- if (params.size() != 1)return FALSE;
- if(!m_pIconTree)
- return FALSE;
- CFX_WideString swIconName = params[0].operator CFX_WideString();
- int iIconCounts = m_pIconTree->GetLength();
-
- CJS_Context* pContext = (CJS_Context *)cc;
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
-
- for (int i = 0; i < iIconCounts; i++)
- {
- if ((*m_pIconTree)[i]->IconName == swIconName)
- {
- Icon* pRetIcon = (*m_pIconTree)[i]->IconStream;
-
- JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"Icon"));
- if (pObj.IsEmpty()) return FALSE;
-
- CJS_Icon * pJS_Icon = (CJS_Icon *)JS_GetPrivate(pObj);
- if (!pJS_Icon) return FALSE;
-
- Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject();
- if (!pIcon)return FALSE;
-
- pIcon->SetIconName(swIconName);
- pIcon->SetStream(pRetIcon->GetStream());
- vRet = pJS_Icon;
- return TRUE;
- }
- }
-
- return FALSE;
-}
-
-FX_BOOL Document::removeIcon(OBJ_METHOD_PARAMS)
-{
- if (params.size() != 1)return FALSE;
- if(!m_pIconTree)
- return FALSE;
- CFX_WideString swIconName = params[0].operator CFX_WideString();
-#ifndef FOXIT_CHROME_BUILD
- m_pIconTree->DeleteIconElement(swIconName);
-#endif
- return TRUE;
-}
-
-FX_BOOL Document::createDataObject(OBJ_METHOD_PARAMS)
-{
- if (IsSafeMode(cc)) return TRUE;
- ASSERT(m_pDocument != NULL);
-
- CFX_WideString swName = L"";
- CFX_ByteString sbName = "";
- CFX_WideString swValue = L"";
- CFX_WideString swMIMEType = L"";
- CFX_WideString swCryptFilter = L"";
- CFX_ByteString sbFileValue = "";
-
- int iParamSize = params.size();
- for (int i = 0; i < iParamSize; i++)
- {
- if (i == 0)
- swName = params[0];
- if (i == 1)
- swValue = params[1];
- if (i == 2)
- swMIMEType = params[2];
- if (i == 3)
- swCryptFilter = params[4];
- }
-
- FILE* pFile = NULL;
-
- //CFileStatus fileStatus;
- const int BUFSIZE = 17;
- FX_BYTE buf[BUFSIZE];
- FX_BYTE *pBuffer = NULL;
- char* pBuf = NULL;
- int nFileSize = 0;
- sbFileValue = CFX_ByteString::FromUnicode(swValue);
- sbName = CFX_ByteString::FromUnicode(swName);
- int iBufLength = sbFileValue.GetLength();
- pBuf = (char*)malloc(sizeof(char) * iBufLength);
- pBuf = sbFileValue.GetBuffer(iBufLength);
-
- if ( NULL == (pFile = FXSYS_fopen( sbName.GetBuffer(sbName.GetLength()), "wb+" )) )
- {
- return FALSE;
- }
-
- fwrite( pBuf, sizeof(char), iBufLength, pFile );
- fclose( pFile );
- pFile = NULL;
-
- pFile = FXSYS_fopen( sbName.GetBuffer(sbName.GetLength()), "rb+" );
- fseek( pFile, 0, SEEK_END );
- nFileSize = ftell( pFile );
-
- pBuffer = new FX_BYTE[nFileSize];
- fseek( pFile, 0, SEEK_SET );
- size_t s = fread( pBuffer, sizeof(char), nFileSize, pFile );
- if(s == 0)
- {
- delete[] pBuffer;
- return FALSE;
- }
-
- CRYPT_MD5Generate(pBuffer, nFileSize, buf);
- buf[BUFSIZE - 1] = 0;
- CFX_WideString csCheckSum((FX_LPCWSTR)buf, 16);
- delete[] pBuffer;
-
- return TRUE;
-}
-
-FX_BOOL Document::media(OBJ_PROP_PARAMS)
-{
- return TRUE;
-}
-
-FX_BOOL Document::calculateNow(OBJ_METHOD_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) ||
- m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) ||
- m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) return FALSE;
-
- CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
- pInterForm->OnCalculate();
- return TRUE;
-}
-
-FX_BOOL Document::Collab(OBJ_PROP_PARAMS)
-{
- return TRUE;
-}
-
-FX_BOOL Document::getPageNthWord(OBJ_METHOD_PARAMS)
-{
- //if (IsSafeMode(cc)) return TRUE;
-
- ASSERT(m_pDocument != NULL);
-
- if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE;
-
- int nPageNo = params.GetSize() > 0 ? (int)params[0] : 0;
- int nWordNo = params.GetSize() > 1 ? (int)params[1] : 0;
- bool bStrip = params.GetSize() > 2 ? (bool)params[2] : true;
-
- CPDF_Document* pDocument = m_pDocument->GetDocument();
- if (!pDocument) return FALSE;
-
- if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount())
- {
- //sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
-
- CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo);
- if (!pPageDict) return FALSE;
-
- CPDF_Page page;
- page.Load(pDocument, pPageDict);
- page.StartParse();
- page.ParseContent();
-
- FX_POSITION pos = page.GetFirstObjectPosition();
-
- int nWords = 0;
-
- CFX_WideString swRet;
-
- while (pos)
- {
- if (CPDF_PageObject* pPageObj = page.GetNextObject(pos))
- {
- if (pPageObj->m_Type == PDFPAGE_TEXT)
- {
- int nObjWords = CountWords((CPDF_TextObject*)pPageObj);
-
- if (nWords + nObjWords >= nWordNo)
- {
- swRet = GetObjWordStr((CPDF_TextObject*)pPageObj, nWordNo - nWords);
- break;
- }
-
- nWords += nObjWords;
- }
- }
- }
-
- if (bStrip)
- {
- swRet.TrimLeft();
- swRet.TrimRight();
- }
-
- vRet = swRet;
- return TRUE;
-}
-
-FX_BOOL Document::getPageNthWordQuads(OBJ_METHOD_PARAMS)
-{
- //if (IsSafeMode(cc)) return TRUE;
-
- ASSERT(m_pDocument != NULL);
-
- if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE;
-
- return FALSE;
-}
-
-FX_BOOL Document::getPageNumWords(OBJ_METHOD_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE;
-
- int nPageNo = params.GetSize() > 0 ? (int)params[0] : 0;
-
- CPDF_Document* pDocument = m_pDocument->GetDocument();
- ASSERT(pDocument != NULL);
-
- if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount())
- {
- //sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
-
- CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo);
- if (!pPageDict) return FALSE;
-
- CPDF_Page page;
- page.Load(pDocument, pPageDict);
- page.StartParse();
- page.ParseContent();
-
- FX_POSITION pos = page.GetFirstObjectPosition();
-
- int nWords = 0;
-
- while (pos)
- {
- if (CPDF_PageObject* pPageObj = page.GetNextObject(pos))
- {
- if (pPageObj->m_Type == PDFPAGE_TEXT)
- {
- CPDF_TextObject* pTextObj = (CPDF_TextObject*)pPageObj;
- nWords += CountWords(pTextObj);
- }
- }
- }
-
- vRet = nWords;
-
- return TRUE;
-}
-
-FX_BOOL Document::getPrintParams(OBJ_METHOD_PARAMS)
-{
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
- JSFXObject pRetObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"PrintParamsObj"));
- //not implemented yet.
- vRet = pRetObj;
-
- return TRUE;
-}
-
-#define ISLATINWORD(u) (u != 0x20 && u <= 0x28FF)
-
-int Document::CountWords(CPDF_TextObject* pTextObj)
-{
- if (!pTextObj) return 0;
-
- int nWords = 0;
-
- CPDF_Font* pFont = pTextObj->GetFont();
- if (!pFont) return 0;
-
- FX_BOOL bIsLatin = FALSE;
-
- for (int i=0, sz=pTextObj->CountChars(); i<sz; i++)
- {
- FX_DWORD charcode = -1;
- FX_FLOAT kerning;
-
- pTextObj->GetCharInfo(i, charcode, kerning);
- CFX_WideString swUnicode = pFont->UnicodeFromCharCode(charcode);
-
- FX_WORD unicode = 0;
- if (swUnicode.GetLength() > 0)
- unicode = swUnicode[0];
-
- if (ISLATINWORD(unicode) && bIsLatin)
- continue;
-
- bIsLatin = ISLATINWORD(unicode);
- if (unicode != 0x20)
- nWords++;
- }
-
- return nWords;
-}
-
-CFX_WideString Document::GetObjWordStr(CPDF_TextObject* pTextObj, int nWordIndex)
-{
- ASSERT(pTextObj != NULL);
-
- CFX_WideString swRet;
-
- CPDF_Font* pFont = pTextObj->GetFont();
- if (!pFont) return L"";
-
- int nWords = 0;
- FX_BOOL bIsLatin = FALSE;
-
- for (int i=0, sz=pTextObj->CountChars(); i<sz; i++)
- {
- FX_DWORD charcode = -1;
- FX_FLOAT kerning;
-
- pTextObj->GetCharInfo(i, charcode, kerning);
- CFX_WideString swUnicode = pFont->UnicodeFromCharCode(charcode);
-
- FX_WORD unicode = 0;
- if (swUnicode.GetLength() > 0)
- unicode = swUnicode[0];
-
- if (ISLATINWORD(unicode) && bIsLatin)
- {
- }
- else
- {
- bIsLatin = ISLATINWORD(unicode);
- if (unicode != 0x20)
- nWords++;
- }
-
- if (nWords-1 == nWordIndex)
- swRet += unicode;
- }
-
- return swRet;
-}
-
-FX_BOOL Document::zoom(OBJ_PROP_PARAMS)
-{
-
- return TRUE;
-}
-
-/**
-(none, NoVary)
-(fitP, FitPage)
-(fitW, FitWidth)
-(fitH, FitHeight)
-(fitV, FitVisibleWidth)
-(pref, Preferred)
-(refW, ReflowWidth)
-*/
-
-FX_BOOL Document::zoomType(OBJ_PROP_PARAMS)
-{
- return TRUE;
-}
-
-FX_BOOL Document::deletePages(OBJ_METHOD_PARAMS)
-{
-
-
-
-
-
-
- v8::Isolate* isolate = GetIsolate(cc);
-// if (pEnv->GetAppName().Compare(PHANTOM) != 0)
-// return TRUE;
-
- //if (IsSafeMode(cc)) return TRUE;
-
- ASSERT(m_pDocument != NULL);
-
- if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) ||
- m_pDocument->GetPermissions(FPDFPERM_ASSEMBLE))) return FALSE;
-
- int iSize = params.size();
-
- int nStart = 0;
- int nEnd = 0;
-
- if (iSize < 1)
- {
- }
- else if (iSize == 1)
- {
- if (params[0].GetType() == VT_object)
- {
- JSObject pObj = (JSObject )params[0];
- v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj, L"nStart");
- nStart = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue));
-
- pValue = JS_GetObjectElement(isolate,pObj, L"nEnd");
- nEnd = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue));
- }
- else
- {
- nStart = (int)params[0];
- }
- }
- else
- {
- nStart = (int)params[0];
- nEnd = (int)params[1];
- }
-
- int nTotal = m_pDocument->GetPageCount();
-
- if (nStart < 0) nStart = 0;
- if (nStart >= nTotal) nStart = nTotal - 1;
-
- if (nEnd < 0) nEnd = 0;
- if (nEnd >= nTotal) nEnd = nTotal - 1;
-
- if (nEnd < nStart) nEnd = nStart;
-
-
-
-#ifndef FOXIT_CHROME_BUILD
- return m_pDocument->DeletePages(nStart, nEnd - nStart + 1);
-#else
- return TRUE;
-#endif
-}
-
-FX_BOOL Document::extractPages(OBJ_METHOD_PARAMS)
-{
-
-
-
-
-
-
- v8::Isolate* isolate = GetIsolate(cc);
-
- if (IsSafeMode(cc)) return TRUE;
-
- ASSERT(m_pDocument != NULL);
-
- if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT)) return FALSE;
-
- int iSize = params.size();
-
- int nTotal = m_pDocument->GetPageCount();
- int nStart = 0;
- int nEnd = nTotal - 1;
-
- CFX_WideString swFilePath;
-
- if (iSize < 1)
- {
- }
- else if (iSize == 1)
- {
- if (params[0].GetType() == VT_object)
- {
- JSObject pObj = (JSObject )params[0];
- v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj, L"nStart");
- nStart = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue));
-
- pValue = JS_GetObjectElement(isolate,pObj, L"nEnd");
- nEnd = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue));
-
- pValue = JS_GetObjectElement(isolate,pObj, L"cPath");
- swFilePath = CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
- }
- else
- {
- nStart = (int)params[0];
- }
- }
- else if (iSize == 2)
- {
- nStart = (int)params[0];
- nEnd = (int)params[1];
- }
- else
- {
- nStart = (int)params[0];
- nEnd = (int)params[1];
- swFilePath = params[2].operator CFX_WideString();
- }
-
- if (nEnd < nStart)
- nEnd = nStart;
-
- CPDF_Document *pNewDoc = new CPDF_Document;
- pNewDoc->CreateNewDoc();
-
- CFX_WordArray array;
- for (int i=nStart; i<=nEnd; i++)
- array.Add(i);
-
-// m_pDocument->ExtractPages(array, pNewDoc);
-
- if (swFilePath.IsEmpty())
- {
-
- }
- else
- {
- swFilePath = app::PDFPathToSysPath(swFilePath);
- CPDF_Creator PDFCreater(pNewDoc);
- PDFCreater.Create(swFilePath);
- delete pNewDoc;
-// pEnv->OpenDocument(swFilePath);
- vRet.SetNull();
- }
-
- return TRUE;
-}
-
-FX_BOOL Document::insertPages(OBJ_METHOD_PARAMS)
-{
-
-
-
-
-
-
- v8::Isolate* isolate = GetIsolate(cc);
-
- if (IsSafeMode(cc)) return TRUE;
-
- ASSERT(m_pDocument != NULL);
-
- if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) ||
- m_pDocument->GetPermissions(FPDFPERM_ASSEMBLE))) return FALSE;
-
- int iSize = params.size();
-
- int nStart = 0;
- int nEnd = 0;
- int nPage = 0;
-
- CFX_WideString swFilePath;
-
- if (iSize < 1)
- {
- }
- else if (iSize == 1)
- {
- if (params[0].GetType() == VT_object)
- {
- JSObject pObj = (JSObject )params[0];
-
- v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj, L"nPage");
- nPage = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue));
-
- pValue = JS_GetObjectElement(isolate,pObj, L"cPath");
- swFilePath = CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
-
- pValue = JS_GetObjectElement(isolate,pObj, L"nStart");
- nStart = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue));
-
- pValue = JS_GetObjectElement(isolate,pObj, L"nEnd");
- nEnd = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue));
- }
- else
- {
- nPage = (int)params[0];
- }
- }
- else
- {
- nPage = (int)params[0];
-
- if (iSize >= 2)
- swFilePath = params[1].operator CFX_WideString();
-
- if (iSize >= 3)
- nStart = (int)params[2];
-
- if (iSize >= 4)
- nEnd = (int)params[3];
- }
-
- nPage++;
-
- if (nPage < 0)
- nPage = 0;
-
- if (nPage > m_pDocument->GetPageCount())
- nPage = m_pDocument->GetPageCount();
-
- if (swFilePath.IsEmpty()) return FALSE;
-
- swFilePath = app::PDFPathToSysPath(swFilePath);
-
- CPDF_Parser pdfParser;
- pdfParser.StartParse(swFilePath, FALSE);
- CPDF_Document* pSrcDoc = pdfParser.GetDocument();
-
- if (!pSrcDoc)
- {
- pdfParser.CloseParser();
- return FALSE;
- }
-
- int nTotal = pSrcDoc->GetPageCount();
-
- if (nStart < 0) nStart = 0;
- if (nStart >= nTotal) nStart = nTotal - 1;
-
- if (nEnd < 0) nEnd = 0;
- if (nEnd >= nTotal) nEnd = nTotal - 1;
-
- if (nEnd < nStart) nEnd = nStart;
-
- CFX_WordArray array;
- for (int i=nStart; i<=nEnd; i++)
- array.Add(i);
-
-// m_pDocument->InsertPages(nPage, pSrcDoc, array);
-
- pdfParser.CloseParser();
-
- return TRUE;
-}
-
-FX_BOOL Document::replacePages(OBJ_METHOD_PARAMS)
-{
-
-
-
-
-
-
- v8::Isolate* isolate = GetIsolate(cc);
-
- if (IsSafeMode(cc)) return TRUE;
-
- ASSERT(m_pDocument != NULL);
-
- if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) ||
- m_pDocument->GetPermissions(FPDFPERM_ASSEMBLE))) return FALSE;
-
- int iSize = params.size();
-
- int nStart = -1;
- int nEnd = -1;
- int nPage = 0;
-
- CFX_WideString swFilePath;
-
- if (iSize < 1)
- {
- }
- else if (iSize == 1)
- {
- if (params[0].GetType() == VT_object)
- {
- JSObject pObj = (JSObject )params[0];
-
- v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj, L"nPage");
- nPage = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue));
-
- pValue = JS_GetObjectElement(isolate,pObj, L"cPath");
- swFilePath = CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
-
- pValue = JS_GetObjectElement(isolate,pObj, L"nStart");
- nStart = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue));
-
- pValue = JS_GetObjectElement(isolate,pObj, L"nEnd");
- nEnd = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue));
- }
- else
- {
- nPage = (int)params[0];
- }
- }
- else
- {
- nPage = (int)params[0];
-
- if (iSize >= 2)
- swFilePath = params[1].operator CFX_WideString();
-
- if (iSize >= 3)
- nStart = (int)params[2];
-
- if (iSize >= 4)
- nEnd = (int)params[3];
- }
-
- if (nPage < 0)
- nPage = 0;
-
- if (nPage >= m_pDocument->GetPageCount())
- nPage = m_pDocument->GetPageCount() - 1;
-
- if (swFilePath.IsEmpty()) return FALSE;
-
- swFilePath = app::PDFPathToSysPath(swFilePath);
-
- CPDF_Parser pdfParser;
- pdfParser.StartParse(swFilePath, FALSE);
- CPDF_Document* pSrcDoc = pdfParser.GetDocument();
-
- if (!pSrcDoc)
- {
- pdfParser.CloseParser();
- return FALSE;
- }
-
- int nTotal = pSrcDoc->GetPageCount();
-
- if (nStart < 0)
- {
- if (nEnd < 0)
- {
- nStart = 0;
- nEnd = nTotal - 1;
- }
- else
- {
- nStart = 0;
- }
- }
- else
- {
- if (nEnd < 0)
- {
- nEnd = nStart;
- }
- else
- {
- if (nStart >= nTotal) nStart = nTotal - 1;
- if (nEnd >= nTotal) nEnd = nTotal - 1;
-
- if (nEnd < nStart) nEnd = nStart;
- }
- }
-
- CFX_WordArray array;
- for (int i=nStart; i<=nEnd; i++)
- array.Add(i);
-
-// m_pDocument->ReplacePages(nPage, pSrcDoc, array);
-
- pdfParser.CloseParser();
-
- return TRUE;
-}
-
-FX_BOOL Document::getURL(OBJ_METHOD_PARAMS)
-{
- if (IsSafeMode(cc)) return TRUE;
-
- return TRUE;
-}
-
-void Document::AddDelayData(CJS_DelayData* pData)
-{
- m_DelayData.Add(pData);
-}
-
-void Document::DoFieldDelay(const CFX_WideString& sFieldName, int nControlIndex)
-{
- CFX_DWordArray DelArray;
-
- for (int i=0,sz=m_DelayData.GetSize(); i<sz; i++)
- {
- if (CJS_DelayData* pData = m_DelayData.GetAt(i))
- {
- if (pData->sFieldName == sFieldName && pData->nControlIndex == nControlIndex)
- {
- Field::DoDelay(m_pDocument, pData);
- delete pData;
- m_DelayData.SetAt(i, NULL);
- DelArray.Add(i);
- }
- }
- }
-
- for (int j=DelArray.GetSize()-1; j>=0; j--)
- {
- m_DelayData.RemoveAt(DelArray[j]);
- }
-}
-
-void Document::AddDelayAnnotData(CJS_AnnotObj *pData)
-{
- m_DelayAnnotData.Add(pData);
-}
-
-void Document::DoAnnotDelay()
-{
- CFX_DWordArray DelArray;
-
- for (int j=DelArray.GetSize()-1; j>=0; j--)
- {
- m_DelayData.RemoveAt(DelArray[j]);
- }
-}
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/javascript/JavaScript.h"
+#include "../../include/javascript/IJavaScript.h"
+#include "../../include/javascript/JS_Define.h"
+#include "../../include/javascript/JS_Object.h"
+#include "../../include/javascript/JS_Value.h"
+#include "../../include/javascript/Document.h"
+#include "../../include/javascript/JS_EventHandler.h"
+#include "../../include/javascript/JS_Context.h"
+#include "../../include/javascript/JS_Runtime.h"
+#include "../../include/javascript/app.h"
+#include "../../include/javascript/Field.h"
+#include "../../include/javascript/Icon.h"
+#include "../../include/javascript/Field.h"
+
+static v8::Isolate* GetIsolate(IFXJS_Context* cc)
+{
+ CJS_Context* pContext = (CJS_Context *)cc;
+ ASSERT(pContext != NULL);
+
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ ASSERT(pRuntime != NULL);
+
+ return pRuntime->GetIsolate();
+}
+
+BEGIN_JS_STATIC_CONST(CJS_PrintParamsObj)
+END_JS_STATIC_CONST()
+
+BEGIN_JS_STATIC_PROP(CJS_PrintParamsObj)
+END_JS_STATIC_PROP()
+
+BEGIN_JS_STATIC_METHOD(CJS_PrintParamsObj)
+END_JS_STATIC_METHOD()
+
+IMPLEMENT_JS_CLASS(CJS_PrintParamsObj, PrintParamsObj)
+
+PrintParamsObj::PrintParamsObj(CJS_Object* pJSObject)
+: CJS_EmbedObj(pJSObject)
+{
+ bUI = TRUE;
+ nStart = 0;
+ nEnd = 0;
+ bSilent = FALSE;
+ bShrinkToFit = FALSE;
+ bPrintAsImage = FALSE;
+ bReverse = FALSE;
+ bAnnotations = TRUE;
+}
+
+/* ---------------------- Document ---------------------- */
+
+#define MINWIDTH 5.0f
+#define MINHEIGHT 5.0f
+
+BEGIN_JS_STATIC_CONST(CJS_Document)
+END_JS_STATIC_CONST()
+
+BEGIN_JS_STATIC_PROP(CJS_Document)
+ JS_STATIC_PROP_ENTRY(ADBE)
+ JS_STATIC_PROP_ENTRY(author)
+ JS_STATIC_PROP_ENTRY(baseURL)
+ JS_STATIC_PROP_ENTRY(bookmarkRoot)
+ JS_STATIC_PROP_ENTRY(calculate)
+ JS_STATIC_PROP_ENTRY(Collab)
+ JS_STATIC_PROP_ENTRY(creationDate)
+ JS_STATIC_PROP_ENTRY(creator)
+ JS_STATIC_PROP_ENTRY(delay)
+ JS_STATIC_PROP_ENTRY(dirty)
+ JS_STATIC_PROP_ENTRY(documentFileName)
+ JS_STATIC_PROP_ENTRY(external)
+ JS_STATIC_PROP_ENTRY(filesize)
+ JS_STATIC_PROP_ENTRY(icons)
+ JS_STATIC_PROP_ENTRY(info)
+ JS_STATIC_PROP_ENTRY(keywords)
+ JS_STATIC_PROP_ENTRY(layout)
+ JS_STATIC_PROP_ENTRY(media)
+ JS_STATIC_PROP_ENTRY(modDate)
+ JS_STATIC_PROP_ENTRY(mouseX)
+ JS_STATIC_PROP_ENTRY(mouseY)
+ JS_STATIC_PROP_ENTRY(numFields)
+ JS_STATIC_PROP_ENTRY(numPages)
+ JS_STATIC_PROP_ENTRY(pageNum)
+ JS_STATIC_PROP_ENTRY(pageWindowRect)
+ JS_STATIC_PROP_ENTRY(path)
+ JS_STATIC_PROP_ENTRY(producer)
+ JS_STATIC_PROP_ENTRY(subject)
+ JS_STATIC_PROP_ENTRY(title)
+ JS_STATIC_PROP_ENTRY(zoom)
+ JS_STATIC_PROP_ENTRY(zoomType)
+END_JS_STATIC_PROP()
+
+BEGIN_JS_STATIC_METHOD(CJS_Document)
+ JS_STATIC_METHOD_ENTRY(addAnnot,0)
+ JS_STATIC_METHOD_ENTRY(addField, 4)
+ JS_STATIC_METHOD_ENTRY(addLink, 0)
+ JS_STATIC_METHOD_ENTRY(addIcon, 0)
+ JS_STATIC_METHOD_ENTRY(calculateNow, 0)
+ JS_STATIC_METHOD_ENTRY(closeDoc, 0)
+ JS_STATIC_METHOD_ENTRY(createDataObject, 0)
+ JS_STATIC_METHOD_ENTRY(deletePages, 2)
+ JS_STATIC_METHOD_ENTRY(exportAsText, 3)
+ JS_STATIC_METHOD_ENTRY(exportAsFDF, 6)
+ JS_STATIC_METHOD_ENTRY(exportAsXFDF, 5)
+ JS_STATIC_METHOD_ENTRY(extractPages, 3)
+ JS_STATIC_METHOD_ENTRY(getAnnot, 0)
+ JS_STATIC_METHOD_ENTRY(getAnnots, 2)
+ JS_STATIC_METHOD_ENTRY(getAnnot3D, 2)
+ JS_STATIC_METHOD_ENTRY(getAnnots3D, 1)
+ JS_STATIC_METHOD_ENTRY(getField, 1)
+ JS_STATIC_METHOD_ENTRY(getIcon, 0)
+ JS_STATIC_METHOD_ENTRY(getLinks, 0)
+ JS_STATIC_METHOD_ENTRY(getNthFieldName, 1)
+ JS_STATIC_METHOD_ENTRY(getOCGs, 0)
+ JS_STATIC_METHOD_ENTRY(getPageBox, 0)
+ JS_STATIC_METHOD_ENTRY(getPageNthWord, 3)
+ JS_STATIC_METHOD_ENTRY(getPageNthWordQuads, 2)
+ JS_STATIC_METHOD_ENTRY(getPageNumWords, 1)
+ JS_STATIC_METHOD_ENTRY(getPrintParams, 0)
+ JS_STATIC_METHOD_ENTRY(getURL, 2)
+ JS_STATIC_METHOD_ENTRY(importAnFDF, 1)
+ JS_STATIC_METHOD_ENTRY(importAnXFDF, 1)
+ JS_STATIC_METHOD_ENTRY(importTextData, 2)
+ JS_STATIC_METHOD_ENTRY(insertPages, 4)
+ JS_STATIC_METHOD_ENTRY(mailForm, 6)
+ JS_STATIC_METHOD_ENTRY(print, 9)
+ JS_STATIC_METHOD_ENTRY(removeField, 1)
+ JS_STATIC_METHOD_ENTRY(replacePages, 4)
+ JS_STATIC_METHOD_ENTRY(resetForm, 1)
+ JS_STATIC_METHOD_ENTRY(removeIcon, 0)
+ JS_STATIC_METHOD_ENTRY(saveAs, 5)
+ JS_STATIC_METHOD_ENTRY(submitForm, 23)
+ JS_STATIC_METHOD_ENTRY(mailDoc, 0)
+END_JS_STATIC_METHOD()
+
+IMPLEMENT_JS_CLASS(CJS_Document, Document)
+
+FX_BOOL CJS_Document::InitInstance(IFXJS_Context* cc)
+{
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+
+ Document* pDoc = (Document*)GetEmbedObject();
+ ASSERT(pDoc != NULL);
+
+ pDoc->AttachDoc(pContext->GetReaderDocument());
+ pDoc->SetIsolate(pContext->GetJSRuntime()->GetIsolate());
+ return TRUE;
+};
+
+/* --------------------------------- Document --------------------------------- */
+
+Document::Document(CJS_Object* pJSObject) : CJS_EmbedObj(pJSObject),
+ m_cwBaseURL(L""),
+ m_pIconTree(NULL),
+ m_pDocument(NULL),
+ m_bDelay(FALSE),
+ m_isolate(NULL)
+{
+}
+
+Document::~Document()
+{
+ if (m_pIconTree)
+ {
+ m_pIconTree->DeleteIconTree();
+ delete m_pIconTree;
+ m_pIconTree = NULL;
+ }
+ for (int i=0; i<m_DelayData.GetSize(); i++)
+ {
+ if (CJS_DelayData* pData = m_DelayData.GetAt(i))
+ {
+ delete pData;
+ pData = NULL;
+ m_DelayData.SetAt(i, NULL);
+
+ }
+ }
+
+ m_DelayData.RemoveAll();
+ m_DelayAnnotData.RemoveAll();
+}
+
+//the total number of fileds in document.
+FX_BOOL Document::numFields(OBJ_PROP_PARAMS)
+{
+ if (!vp.IsGetting()) return FALSE;
+
+ ASSERT(m_pDocument != NULL);
+
+ CPDFSDK_InterForm *pInterForm = m_pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ CPDF_InterForm *pPDFForm = pInterForm->GetInterForm();
+ ASSERT(pPDFForm != NULL);
+
+ vp << (int)pPDFForm->CountFields();
+
+ return TRUE;
+}
+
+FX_BOOL Document::dirty(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsGetting())
+ {
+ if (m_pDocument->GetChangeMark())
+ vp << true;
+ else
+ vp << false;
+ }
+ else
+ {
+ bool bChanged = false;
+
+ vp >> bChanged;
+
+ if (bChanged)
+ m_pDocument->SetChangeMark();
+ else
+ m_pDocument->ClearChangeMark();
+ }
+
+ return TRUE;
+}
+
+FX_BOOL Document::ADBE(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsGetting())
+ {
+ vp.SetNull();
+ }
+ else
+ {
+ }
+
+ return TRUE;
+}
+
+FX_BOOL Document::pageNum(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsGetting())
+ {
+ if (CPDFSDK_PageView* pPageView = m_pDocument->GetCurrentView())
+ {
+ vp << pPageView->GetPageIndex();
+ }
+ }
+ else
+ {
+ int iPageCount = m_pDocument->GetPageCount();
+
+ int iPageNum = 0;
+ vp >> iPageNum;
+
+ CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
+ if(!pEnv)
+ return FALSE;
+
+ if (iPageNum >= 0 && iPageNum < iPageCount)
+ {
+ pEnv->JS_docgotoPage(iPageNum);
+ }
+ else if (iPageNum >= iPageCount)
+ {
+ pEnv->JS_docgotoPage(iPageCount-1);
+ }
+ else if (iPageNum < 0)
+ {
+ pEnv->JS_docgotoPage(0);
+ }
+ }
+
+ return TRUE;
+}
+
+FX_BOOL Document::ParserParams(JSObject* pObj,CJS_AnnotObj& annotobj)
+{
+ return TRUE;
+}
+
+FX_BOOL Document::addAnnot(OBJ_METHOD_PARAMS)
+{
+ return TRUE;
+}
+
+FX_BOOL Document::addField(OBJ_METHOD_PARAMS)
+{
+ //Doesn't support.
+ return TRUE;
+}
+
+//exports form fields as a tab-delimited text file to a local hard disk.
+//comment: need reader support
+//note : watch the third parameter:cPath, for what case it can be safely saved?
+//int CPDFSDK_InterForm::ExportAsText(FX_BOOL bNoPassword,StringArray aFields,String cPath);
+//return value, int the index of the parameters illegal, the index is based on 1.
+
+FX_BOOL Document::exportAsText(OBJ_METHOD_PARAMS)
+{
+ if (IsSafeMode(cc)) return TRUE;
+ return TRUE;
+}
+
+//exports form fields as a fdf file to the local hard drive
+//comment: need reader supports
+//note:the last parameter hasn't been confirmed.because the previous one blocks the way.
+//int CPDFSDK_Document::ExportAsFDF(FX_BOOL bAllFields,BOOL bNoPassword,StringArray aFields,FX_BOOL bFlags,String cPath,FX_BOOL bAnnotations);
+
+FX_BOOL Document::exportAsFDF(OBJ_METHOD_PARAMS)
+{
+ v8::Isolate* isolate = GetIsolate(cc);
+ if (IsSafeMode(cc)) return TRUE;
+
+ ASSERT(m_pDocument != NULL);
+
+ if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE;
+
+ FX_BOOL bAllFields = params.size() > 0 ? (FX_BOOL)params[0] : FALSE;
+ FX_BOOL bNoPassWord = params.size() > 1 ? (FX_BOOL)params[1] : TRUE;
+ FX_BOOL bWhole = params.size() > 2 ? (params[2].GetType() == VT_null) : TRUE;
+ CJS_Array arrayFileds(isolate);
+ if (!bWhole)
+ arrayFileds.Attach(params[2]);
+ //FX_BOOL bFlags = params.size() > 3 ? (FX_BOOL)params[3] : FALSE;
+ CFX_WideString swFilePath = params.size() > 4 ? (FX_LPCWSTR)params[4].operator CFX_WideString() : (FX_LPCWSTR)L"";
+
+ if (swFilePath.IsEmpty())
+ {
+ CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
+ swFilePath = pEnv->JS_fieldBrowse();
+ if(swFilePath.IsEmpty())
+ return TRUE;
+ }
+ else
+ {
+ swFilePath = app::PDFPathToSysPath(swFilePath);
+ }
+
+ m_pDocument->SetFocusAnnot(NULL);
+
+ CPDFSDK_InterForm* pInterForm= (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
+ ASSERT(pPDFForm != NULL);
+
+ CFX_PtrArray aFields;
+
+ if (bWhole)
+ {
+ for (int j=0,jsz=pPDFForm->CountFields(); j<jsz; j++)
+ {
+ aFields.Add(pPDFForm->GetField(j));
+ }
+ }
+ else
+ {
+ for (int i=0,isz=arrayFileds.GetLength(); i<isz; i++)
+ {
+ CJS_Value valName(isolate);
+ arrayFileds.GetElement(i,valName);
+ CFX_WideString swName = valName.operator CFX_WideString();
+
+ for (int j=0, jsz=pPDFForm->CountFields(swName); j<jsz; j++)
+ {
+ aFields.Add(pPDFForm->GetField(j, swName));
+ }
+ }
+ }
+
+ CFX_PtrArray fields;
+
+ for (int i=0,sz=aFields.GetSize(); i<sz; i++)
+ {
+ CPDF_FormField* pField = (CPDF_FormField*)aFields[i];
+
+ if (!bAllFields)
+ if (pField->GetValue() == L"")
+ continue;
+
+ if (bNoPassWord)
+ if (pField->GetFieldFlags() & 0x2000)
+ continue;
+
+ fields.Add((void*)pField);
+ }
+
+ return pInterForm->ExportFieldsToFDFFile(swFilePath, fields, TRUE);
+}
+
+//exports form fields an XFDF file to the local hard drive
+//comment: need reder supports
+//note:the last parameter can't be test
+//int CPDFSDK_Document::ExportAsXFDF(FX_BOOL bAllFields,FX_BOOL bNoPassWord,StringArray aFields,String cPath,FX_BOOL bAnnoatations);
+
+FX_BOOL Document::exportAsXFDF(OBJ_METHOD_PARAMS)
+{
+ if (IsSafeMode(cc)) return TRUE;
+ ASSERT(m_pDocument != NULL);
+
+ if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE;
+
+ return TRUE;
+}
+
+//Maps a field object in PDF document to a JavaScript variable
+//comment:
+//note: the paremter cName, this is clue how to treat if the cName is not a valiable filed name in this document
+
+FX_BOOL Document::getField(OBJ_METHOD_PARAMS)
+{
+ v8::Isolate* isolate = GetIsolate(cc);
+ ASSERT(m_pDocument != NULL);
+
+ if (params.size() < 1) return FALSE;
+
+ CFX_WideString wideName = params[0].operator CFX_WideString();
+
+ CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
+ ASSERT(pPDFForm != NULL);
+
+ if (pPDFForm->CountFields(wideName) <= 0)
+ {
+ vRet.SetNull();
+ return TRUE;
+ }
+
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ ASSERT(pRuntime != NULL);
+
+ JSFXObject pFieldObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"Field"));
+
+ CJS_Field * pJSField = (CJS_Field*)JS_GetPrivate(isolate,pFieldObj);
+ ASSERT(pJSField != NULL);
+
+ Field * pField = (Field *)pJSField->GetEmbedObject();
+ ASSERT(pField != NULL);
+
+ pField->AttachField(this, wideName);
+ vRet = pJSField;
+
+ return TRUE;
+}
+
+//Gets the name of the nth field in the document
+//comment:
+//note: the parameter nIndex, if it is not available
+
+FX_BOOL Document::getNthFieldName(OBJ_METHOD_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ int nIndex = params.size() > 0 ? (int)params[0] : -1;
+ if (nIndex == -1) return FALSE;
+
+ CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
+ ASSERT(pPDFForm != NULL);
+
+ CPDF_FormField* pField = pPDFForm->GetField(nIndex);
+ if (!pField)
+ return FALSE;
+
+ vRet = pField->GetFullName();
+ return TRUE;
+}
+
+//imports the specified fdf file.
+//comments: need reader suppport
+//note:once the cpath is illigl then a file dialog box pops up in order to ask user to chooose the file
+//int CPDFSDK_Document::importAnFDF(String cPath);
+
+FX_BOOL Document::importAnFDF(OBJ_METHOD_PARAMS)
+{
+ if (IsSafeMode(cc)) return TRUE;
+ ASSERT(m_pDocument != NULL);
+
+ if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) ||
+ m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) ||
+ m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) return FALSE;
+
+
+ CFX_WideString swPath;
+
+ if (params.size() > 0)
+ swPath = params[0];
+
+ if (swPath.IsEmpty())
+ {
+ CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
+ swPath = pEnv->JS_fieldBrowse();
+ if(swPath.IsEmpty())
+ return TRUE;
+ }
+ else
+ {
+ swPath = app::PDFPathToSysPath(swPath);
+ }
+
+ m_pDocument->SetFocusAnnot(NULL);
+
+ CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ if (!pInterForm->ImportFormFromFDFFile(swPath, TRUE))
+ return FALSE;
+
+ m_pDocument->SetChangeMark();
+// CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
+// ASSERT(pEnv != NULL);
+// IUndo* pUndo = IUndo::GetUndo(pEnv);
+// ASSERT(pUndo != NULL);
+// pUndo->Reset(m_pDocument);
+
+ return TRUE;
+}
+
+//imports and specified XFDF file containing XML form data
+//comment: need reader supports
+//note: same as up
+//int CPDFSDK_Document::importAnFDF(String cPath)
+
+FX_BOOL Document::importAnXFDF(OBJ_METHOD_PARAMS)
+{
+ if (IsSafeMode(cc)) return TRUE;
+ ASSERT(m_pDocument != NULL);
+
+ if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) ||
+ m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) ||
+ m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) return FALSE;
+
+ return TRUE;
+}
+
+//imports and specified text file
+//commnet: need reader supports
+//note: same as up,when nRow is not rational,adobe is dumb for it.
+//int CPDFSDK_Document::importTextData(String cPath,int nRow);
+
+FX_BOOL Document::importTextData(OBJ_METHOD_PARAMS)
+{
+ if (IsSafeMode(cc)) return TRUE;
+ ASSERT(m_pDocument != NULL);
+
+ if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) ||
+ m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) ||
+ m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) return FALSE;
+
+ return TRUE;
+}
+
+//exports the form data and mails the resulting fdf file as an attachment to all recipients.
+//comment: need reader supports
+//note:
+//int CPDFSDK_Document::mailForm(FX_BOOL bUI,String cto,string ccc,string cbcc,string cSubject,string cms);
+
+FX_BOOL Document::mailForm(OBJ_METHOD_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE;
+
+ int iLength = params.size();
+
+ FX_BOOL bUI = iLength > 0 ? (FX_BOOL)params[0] : TRUE;
+ CFX_WideString cTo = iLength > 1 ? (FX_LPCWSTR)params[1].operator CFX_WideString() : (FX_LPCWSTR)L"";
+ CFX_WideString cCc = iLength > 2 ? (FX_LPCWSTR)params[2].operator CFX_WideString() : (FX_LPCWSTR)L"";
+ CFX_WideString cBcc = iLength > 3 ? (FX_LPCWSTR)params[3].operator CFX_WideString() : (FX_LPCWSTR)L"";
+ CFX_WideString cSubject = iLength > 4 ? (FX_LPCWSTR)params[4].operator CFX_WideString() : (FX_LPCWSTR)L"";
+ CFX_WideString cMsg = iLength > 5 ? (FX_LPCWSTR)params[5].operator CFX_WideString() : (FX_LPCWSTR)L"";
+
+ CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ CFX_ByteTextBuf textBuf;
+ if (!pInterForm->ExportFormToFDFTextBuf(textBuf))
+ return FALSE;
+
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CPDFDoc_Environment* pEnv = pContext->GetReaderApp();
+ ASSERT(pEnv != NULL);
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ ASSERT(pRuntime != NULL);
+
+ pRuntime->BeginBlock();
+ pEnv->JS_docmailForm(textBuf.GetBuffer(), textBuf.GetLength(), bUI, (FX_LPCWSTR)cTo, (FX_LPCWSTR)cSubject, (FX_LPCWSTR)cCc, (FX_LPCWSTR)cBcc, (FX_LPCWSTR)cMsg);
+ pRuntime->EndBlock();
+ return TRUE;
+}
+
+FX_BOOL Document::print(OBJ_METHOD_PARAMS)
+{
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ ASSERT(pRuntime != NULL);
+
+ FX_BOOL bUI = TRUE;
+ int nStart = 0;
+ int nEnd = 0;
+ FX_BOOL bSilent = FALSE;
+ FX_BOOL bShrinkToFit = FALSE;
+ FX_BOOL bPrintAsImage = FALSE;
+ FX_BOOL bReverse = FALSE;
+ FX_BOOL bAnnotations = FALSE;
+
+ int nlength = params.size();
+ if(nlength ==9)
+ {
+ if (params[8].GetType() == VT_fxobject)
+ {
+ JSFXObject pObj = (JSFXObject)params[8];
+ {
+ if (JS_GetObjDefnID(pObj) == JS_GetObjDefnID(*pRuntime, L"PrintParamsObj"))
+ {
+ if (CJS_Object* pJSObj = (CJS_Object*)params[8])
+ {
+ if (PrintParamsObj* pprintparamsObj = (PrintParamsObj*)pJSObj->GetEmbedObject())
+ {
+ bUI = pprintparamsObj->bUI;
+ nStart = pprintparamsObj->nStart;
+ nEnd = pprintparamsObj->nEnd;
+ bSilent = pprintparamsObj->bSilent;
+ bShrinkToFit = pprintparamsObj->bShrinkToFit;
+ bPrintAsImage = pprintparamsObj->bPrintAsImage;
+ bReverse = pprintparamsObj->bReverse;
+ bAnnotations = pprintparamsObj->bAnnotations;
+ }
+ }
+ }
+ }
+ }
+ }
+ else
+ {
+ if(nlength >= 1)
+ bUI = params[0];
+ if(nlength >= 2)
+ nStart = (int)params[1];
+ if(nlength >= 3)
+ nEnd = (int)params[2];
+ if(nlength >= 4)
+ bSilent = params[3];
+ if(nlength >= 5)
+ bShrinkToFit = params[4];
+ if(nlength >= 6)
+ bPrintAsImage = params[5];
+ if(nlength >= 7)
+ bReverse = params[6];
+ if(nlength >= 8)
+ bAnnotations = params[7];
+ }
+
+ ASSERT(m_pDocument != NULL);
+
+ if (CPDFDoc_Environment* pEnv = m_pDocument->GetEnv())
+ {
+ pEnv->JS_docprint(bUI, nStart, nEnd, bSilent, bShrinkToFit, bPrintAsImage, bReverse, bAnnotations);
+ return TRUE;
+ }
+ return FALSE;
+}
+
+//removes the specified field from the document.
+//comment:
+//note: if the filed name is not retional, adobe is dumb for it.
+
+FX_BOOL Document::removeField(OBJ_METHOD_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) ||
+ m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM))) return FALSE;
+
+ if (params.size() < 1)
+ return TRUE;
+
+ CFX_WideString sFieldName = params[0].operator CFX_WideString();
+
+ CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ CFX_PtrArray widgets;
+ pInterForm->GetWidgets(sFieldName, widgets);
+
+ int nSize = widgets.GetSize();
+
+ if (nSize > 0)
+ {
+ for (int i=0; i<nSize; i++)
+ {
+ CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)widgets[i];
+ ASSERT(pWidget != NULL);
+
+ CPDF_Rect rcAnnot = pWidget->GetRect();
+ rcAnnot.left -= 1;
+ rcAnnot.bottom -= 1;
+ rcAnnot.right += 1;
+ rcAnnot.top += 1;
+
+ CFX_RectArray aRefresh;
+ aRefresh.Add(rcAnnot);
+
+ CPDF_Page* pPage = pWidget->GetPDFPage();
+ ASSERT(pPage != NULL);
+
+ CPDFSDK_PageView* pPageView = m_pDocument->GetPageView(pPage);
+ pPageView->DeleteAnnot(pWidget);
+
+ pPageView->UpdateRects(aRefresh);
+ }
+ m_pDocument->SetChangeMark();
+ }
+
+ return TRUE;
+}
+
+//reset filed values within a document.
+//comment:
+//note: if the fields names r not rational, aodbe is dumb for it.
+
+FX_BOOL Document::resetForm(OBJ_METHOD_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) ||
+ m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) ||
+ m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) return FALSE;
+
+ CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
+ ASSERT(pPDFForm != NULL);
+
+ v8::Isolate* isolate = GetIsolate(cc);
+ CJS_Array aName(isolate);
+
+ if (params.size() > 0)
+ {
+ switch (params[0].GetType())
+ {
+ default:
+ aName.Attach(params[0]);
+ break;
+ case VT_string:
+ aName.SetElement(0,params[0]);
+ break;
+ }
+
+ CFX_PtrArray aFields;
+
+ for (int i=0,isz=aName.GetLength(); i<isz; i++)
+ {
+ CJS_Value valElement(isolate);
+ aName.GetElement(i,valElement);
+ CFX_WideString swVal = valElement.operator CFX_WideString();
+
+ for (int j=0,jsz=pPDFForm->CountFields(swVal); j<jsz; j++)
+ {
+ aFields.Add((void*)pPDFForm->GetField(j,swVal));
+ }
+ }
+
+ if (aFields.GetSize() > 0)
+ {
+ pPDFForm->ResetForm(aFields, TRUE, TRUE);
+ m_pDocument->SetChangeMark();
+
+ }
+ }
+ else
+ {
+ pPDFForm->ResetForm(TRUE);
+ m_pDocument->SetChangeMark();
+
+ }
+
+ return TRUE;
+}
+
+
+FX_BOOL Document::saveAs(OBJ_METHOD_PARAMS)
+{
+
+ if (IsSafeMode(cc)) return TRUE;
+
+ ASSERT(m_pDocument != NULL);
+
+// m_pDocument->DoSaveAs();
+
+ return TRUE;
+}
+
+
+FX_BOOL Document::submitForm(OBJ_METHOD_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+// if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE;
+
+ int nSize = params.size();
+ if (nSize < 1) return FALSE;
+
+ CFX_WideString strURL;
+ FX_BOOL bFDF = TRUE;
+ FX_BOOL bEmpty = FALSE;
+ v8::Isolate* isolate = GetIsolate(cc);
+ CJS_Array aFields(isolate);
+
+ CJS_Value v = params[0];
+ if (v.GetType() == VT_string)
+ {
+ strURL = params[0].operator CFX_WideString();
+ if (nSize > 1)
+ bFDF = params[1];
+ if (nSize > 2)
+ bEmpty = params[2];
+ if (nSize > 3)
+ aFields.Attach(params[3]);
+ }
+ else if (v.GetType() == VT_object)
+ {
+ JSObject pObj = (JSObject)params[0];
+ v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj, L"cURL");
+ if (!pValue.IsEmpty())
+ strURL = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue));
+ pValue = JS_GetObjectElement(isolate,pObj, L"bFDF");
+ bFDF = CJS_Value(isolate,pValue, GET_VALUE_TYPE(pValue));
+ pValue = JS_GetObjectElement(isolate,pObj, L"bEmpty");
+ bEmpty = CJS_Value(isolate,pValue, GET_VALUE_TYPE(pValue));
+ pValue = JS_GetObjectElement(isolate,pObj,L"aFields");
+ aFields.Attach(CJS_Value(isolate,pValue, GET_VALUE_TYPE(pValue)));
+ }
+
+ CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
+ CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm();
+ ASSERT(pPDFInterForm != NULL);
+
+ FX_BOOL bAll = (aFields.GetLength() == 0);
+
+ if (bAll && bEmpty)
+ {
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ ASSERT(pRuntime != NULL);
+
+
+ if (pPDFInterForm->CheckRequiredFields())
+ {
+ pRuntime->BeginBlock();
+ pInterForm->SubmitForm(strURL, FALSE);
+ pRuntime->EndBlock();
+ }
+
+ return TRUE;
+ }
+ else
+ {
+ CFX_PtrArray fieldObjects;
+
+ for (int i=0,sz=aFields.GetLength(); i<sz; i++)
+ {
+ CJS_Value valName(isolate);
+ aFields.GetElement(i, valName);
+ CFX_WideString sName = valName.operator CFX_WideString();
+
+ CPDF_InterForm* pPDFForm = pInterForm->GetInterForm();
+ ASSERT(pPDFForm != NULL);
+
+ for (int j=0, jsz=pPDFForm->CountFields(sName); j<jsz; j++)
+ {
+ CPDF_FormField* pField = pPDFForm->GetField(j, sName);
+ if (!bEmpty && pField->GetValue().IsEmpty())
+ continue;
+
+ fieldObjects.Add(pField);
+ }
+ }
+
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ ASSERT(pRuntime != NULL);
+
+
+ if (pPDFInterForm->CheckRequiredFields(&fieldObjects, TRUE))
+ {
+ pRuntime->BeginBlock();
+ pInterForm->SubmitFields(strURL, fieldObjects, TRUE, !bFDF);
+ pRuntime->EndBlock();
+ }
+
+ return TRUE;
+ }
+
+}
+
+//////////////////////////////////////////////////////////////////////////////////////////////
+
+void Document::AttachDoc(CPDFSDK_Document *pDoc)
+{
+ m_pDocument = pDoc;
+}
+
+CPDFSDK_Document * Document::GetReaderDoc()
+{
+ return m_pDocument;
+}
+
+FX_BOOL Document::ExtractFileName(CPDFSDK_Document *pDoc,CFX_ByteString &strFileName)
+{
+ return FALSE;
+}
+
+FX_BOOL Document::ExtractFolderName(CPDFSDK_Document *pDoc,CFX_ByteString &strFolderName)
+{
+ return FALSE;
+}
+
+FX_BOOL Document::bookmarkRoot(OBJ_PROP_PARAMS)
+{
+ return TRUE;
+}
+
+FX_BOOL Document::mailDoc(OBJ_METHOD_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ FX_BOOL bUI = TRUE;
+ CFX_WideString cTo = L"";
+ CFX_WideString cCc = L"";
+ CFX_WideString cBcc = L"";
+ CFX_WideString cSubject = L"";
+ CFX_WideString cMsg = L"";
+
+
+ bUI = params.size()>=1?static_cast<FX_BOOL>(params[0]):TRUE;
+ cTo = params.size()>=2?(const wchar_t*)params[1].operator CFX_WideString():L"";
+ cCc = params.size()>=3?(const wchar_t*)params[2].operator CFX_WideString():L"";
+ cBcc = params.size()>=4?(const wchar_t*)params[3].operator CFX_WideString():L"";
+ cSubject = params.size()>=5?(const wchar_t*)params[4].operator CFX_WideString():L"";
+ cMsg = params.size()>=6?(const wchar_t*)params[5].operator CFX_WideString():L"";
+
+ v8::Isolate* isolate = GetIsolate(cc);
+
+ if(params.size()>=1 && params[0].GetType() == VT_object)
+ {
+ JSObject pObj = (JSObject )params[0];
+
+ v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj, L"bUI");
+ bUI = (int)CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue));
+
+ pValue = JS_GetObjectElement(isolate,pObj, L"cTo");
+ cTo = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
+
+ pValue = JS_GetObjectElement(isolate,pObj, L"cCc");
+ cCc = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
+
+ pValue = JS_GetObjectElement(isolate,pObj, L"cBcc");
+ cBcc = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
+
+ pValue = JS_GetObjectElement(isolate,pObj, L"cSubject");
+ cSubject = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
+
+ pValue = JS_GetObjectElement(isolate,pObj, L"cMsg");
+ cMsg = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
+
+ }
+
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ ASSERT(pRuntime != NULL);
+
+ pRuntime->BeginBlock();
+ CPDFDoc_Environment* pEnv = pRuntime->GetReaderApp();
+ pEnv->JS_docmailForm(NULL, 0, bUI, (FX_LPCWSTR)cTo, (FX_LPCWSTR)cSubject, (FX_LPCWSTR)cCc, (FX_LPCWSTR)cBcc, (FX_LPCWSTR)cMsg);
+ pRuntime->EndBlock();
+
+ return TRUE;
+}
+
+FX_BOOL Document::author(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
+ if (!pDictionary)return FALSE;
+
+ if (vp.IsGetting())
+ {
+ vp << pDictionary->GetUnicodeText("Author");
+ return TRUE;
+ }
+ else
+ {
+ if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE;
+
+ CFX_WideString csAuthor;
+ vp >> csAuthor;
+ pDictionary->SetAtString("Author", PDF_EncodeText(csAuthor));
+ m_pDocument->SetChangeMark();
+ return TRUE;
+ }
+}
+
+FX_BOOL Document::info(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
+ if (!pDictionary)return FALSE;
+
+ CFX_WideString cwAuthor = pDictionary->GetUnicodeText("Author");
+ CFX_WideString cwTitle = pDictionary->GetUnicodeText("Title");
+ CFX_WideString cwSubject = pDictionary->GetUnicodeText("Subject");
+ CFX_WideString cwKeywords = pDictionary->GetUnicodeText("Keywords");
+ CFX_WideString cwCreator = pDictionary->GetUnicodeText("Creator");
+ CFX_WideString cwProducer = pDictionary->GetUnicodeText("Producer");
+ CFX_WideString cwCreationDate = pDictionary->GetUnicodeText("CreationDate");
+ CFX_WideString cwModDate = pDictionary->GetUnicodeText("ModDate");
+ CFX_WideString cwTrapped = pDictionary->GetUnicodeText("Trapped");
+
+ v8::Isolate* isolate = GetIsolate(cc);
+ if (!vp.IsSetting())
+ {
+ CJS_Context* pContext = (CJS_Context *)cc;
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+
+ JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContext, -1);
+
+ JS_PutObjectString(isolate,pObj, L"Author", cwAuthor);
+ JS_PutObjectString(isolate,pObj, L"Title", cwTitle);
+ JS_PutObjectString(isolate,pObj, L"Subject", cwSubject);
+ JS_PutObjectString(isolate,pObj, L"Keywords", cwKeywords);
+ JS_PutObjectString(isolate,pObj, L"Creator", cwCreator);
+ JS_PutObjectString(isolate,pObj, L"Producer", cwProducer);
+ JS_PutObjectString(isolate,pObj, L"CreationDate", cwCreationDate);
+ JS_PutObjectString(isolate,pObj, L"ModDate", cwModDate);
+ JS_PutObjectString(isolate,pObj, L"Trapped", cwTrapped);
+
+// It's to be compatible to non-standard info dictionary.
+ FX_POSITION pos = pDictionary->GetStartPos();
+ while(pos)
+ {
+ CFX_ByteString bsKey;
+ CPDF_Object* pValueObj = pDictionary->GetNextElement(pos, bsKey);
+ CFX_WideString wsKey = CFX_WideString::FromUTF8(bsKey);
+ if((pValueObj->GetType()==PDFOBJ_STRING) || (pValueObj->GetType()==PDFOBJ_NAME) )
+ JS_PutObjectString(isolate,pObj, wsKey, pValueObj->GetUnicodeText());
+ if(pValueObj->GetType()==PDFOBJ_NUMBER)
+ JS_PutObjectNumber(isolate,pObj, wsKey, (float)pValueObj->GetNumber());
+ if(pValueObj->GetType()==PDFOBJ_BOOLEAN)
+ JS_PutObjectBoolean(isolate,pObj, wsKey, (bool)pValueObj->GetInteger());
+ }
+
+ vp << pObj;
+ return TRUE;
+ }
+ else
+ {
+ return TRUE;
+ }
+}
+
+FX_BOOL Document::creationDate(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
+ if (!pDictionary)return FALSE;
+
+ if (vp.IsGetting())
+ {
+ vp << pDictionary->GetUnicodeText("CreationDate");
+ return TRUE;
+ }
+ else
+ {
+ if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE;
+
+ CFX_WideString csCreationDate;
+ vp >> csCreationDate;
+ pDictionary->SetAtString("CreationDate", PDF_EncodeText(csCreationDate));
+ m_pDocument->SetChangeMark();
+
+ return TRUE;
+ }
+}
+
+FX_BOOL Document::creator(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
+ if (!pDictionary)return FALSE;
+
+ if (vp.IsGetting())
+ {
+ vp << pDictionary->GetUnicodeText("Creator");
+ return TRUE;
+ }
+ else
+ {
+ if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE;
+
+ CFX_WideString csCreator;
+ vp >> csCreator;
+ pDictionary->SetAtString("Creator", PDF_EncodeText(csCreator));
+ m_pDocument->SetChangeMark();
+ return TRUE;
+ }
+}
+
+FX_BOOL Document::delay(OBJ_PROP_PARAMS)
+{
+ if (vp.IsGetting())
+ {
+ vp << m_bDelay;
+ return TRUE;
+ }
+ else
+ {
+ ASSERT(m_pDocument != NULL);
+
+ if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE;
+
+ bool b;
+ vp >> b;
+
+ m_bDelay = b;
+
+ if (m_bDelay)
+ {
+ for (int i=0,sz=m_DelayData.GetSize(); i<sz; i++)
+ delete m_DelayData.GetAt(i);
+
+ m_DelayData.RemoveAll();
+ }
+ else
+ {
+ for (int i=0,sz=m_DelayData.GetSize(); i<sz; i++)
+ {
+ if (CJS_DelayData* pData = m_DelayData.GetAt(i))
+ {
+ Field::DoDelay(m_pDocument, pData);
+ delete m_DelayData.GetAt(i);
+ }
+ }
+ m_DelayData.RemoveAll();
+ }
+
+ return TRUE;
+ }
+}
+
+FX_BOOL Document::keywords(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
+ if (!pDictionary)return FALSE;
+
+ if (vp.IsGetting())
+ {
+ vp << pDictionary->GetUnicodeText("Keywords");
+ return TRUE;
+ }
+ else
+ {
+ if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE;
+
+ CFX_WideString csKeywords;
+ vp >> csKeywords;
+ pDictionary->SetAtString("Keywords", PDF_EncodeText(csKeywords));
+ m_pDocument->SetChangeMark();
+ return TRUE;
+ }
+}
+
+FX_BOOL Document::modDate(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
+ if (!pDictionary)return FALSE;
+
+ if (vp.IsGetting())
+ {
+ vp << pDictionary->GetUnicodeText("ModDate");
+ return TRUE;
+ }
+ else
+ {
+ if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE;
+
+ CFX_WideString csmodDate;
+ vp >> csmodDate;
+ pDictionary->SetAtString("ModDate", PDF_EncodeText(csmodDate));
+ m_pDocument->SetChangeMark();
+ return TRUE;
+ }
+}
+
+FX_BOOL Document::producer(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
+ if (!pDictionary)return FALSE;
+
+ if (vp.IsGetting())
+ {
+ vp << pDictionary->GetUnicodeText("Producer");
+ return TRUE;
+ }
+ else
+ {
+ if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE;
+
+ CFX_WideString csproducer;
+ vp >> csproducer;
+ pDictionary->SetAtString("Producer", PDF_EncodeText(csproducer));
+ m_pDocument->SetChangeMark();
+ return TRUE;
+ }
+}
+
+FX_BOOL Document::subject(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
+ if (!pDictionary)return FALSE;
+
+ if (vp.IsGetting())
+ {
+ vp << pDictionary->GetUnicodeText("Subject");
+ return TRUE;
+ }
+ else
+ {
+ if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE;
+
+ CFX_WideString cssubject;
+ vp >> cssubject;
+ pDictionary->SetAtString("Subject", PDF_EncodeText(cssubject));
+ m_pDocument->SetChangeMark();
+ return TRUE;
+ }
+}
+
+FX_BOOL Document::title(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (m_pDocument == NULL || m_pDocument->GetDocument() == NULL)
+ return FALSE;
+
+ CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
+ if (!pDictionary)return FALSE;
+
+ if (vp.IsGetting())
+ {
+ vp << pDictionary->GetUnicodeText("Title");
+ return TRUE;
+ }
+ else
+ {
+ if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) return FALSE;
+
+ CFX_WideString cstitle;
+ vp >> cstitle;
+ pDictionary->SetAtString("Title", PDF_EncodeText(cstitle));
+ m_pDocument->SetChangeMark();
+ return TRUE;
+ }
+}
+
+FX_BOOL Document::numPages(OBJ_PROP_PARAMS)
+{
+ if (vp.IsGetting())
+ {
+ ASSERT(m_pDocument != NULL);
+ vp << m_pDocument->GetPageCount();
+ return TRUE;
+ }
+ else
+ {
+ return FALSE;
+ }
+}
+
+FX_BOOL Document::external(OBJ_PROP_PARAMS)
+{
+ //In Chrome case,should always return true.
+ vp << TRUE;
+ return TRUE;
+}
+
+FX_BOOL Document::filesize(OBJ_PROP_PARAMS)
+{
+ if (!vp.IsGetting())return FALSE;
+
+ ASSERT(m_pDocument != NULL);
+
+// CFile file(m_pDocument->GetPath(), CFile::modeRead | CFile::typeBinary | CFile::shareDenyNone);
+// vp << (double)file.GetLength();
+// file.Close();
+
+ if ( m_pDocument->GetPath().IsEmpty() == FALSE)
+ {
+ CFX_ByteString bsStr = CFX_ByteString::FromUnicode( m_pDocument->GetPath() );
+ FILE * pFile = NULL;
+ pFile = fopen( bsStr.GetBuffer( bsStr.GetLength() ), "rb" );
+ if ( pFile )
+ {
+ fseek( pFile, 0, SEEK_END );
+ long lSize = ftell( pFile );
+ fclose( pFile );
+ pFile = NULL;
+
+ vp << (FX_INT32)(lSize);
+ return TRUE;
+ }
+ }
+
+ vp << 0;
+ return TRUE;
+}
+
+FX_BOOL Document::mouseX(OBJ_PROP_PARAMS)
+{
+ return TRUE;
+}
+
+FX_BOOL Document::mouseY(OBJ_PROP_PARAMS)
+{
+ return TRUE;
+}
+
+FX_BOOL Document::baseURL(OBJ_PROP_PARAMS)
+{
+ if (vp.IsGetting())
+ {
+ vp << m_cwBaseURL;
+ return TRUE;
+ }
+ else
+ {
+ vp >> m_cwBaseURL;
+ return TRUE;
+ }
+}
+
+FX_BOOL Document::calculate(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ if (vp.IsGetting())
+ {
+ if (pInterForm->IsCalculateEnabled())
+ vp << true;
+ else
+ vp << false;
+ }
+ else
+ {
+ bool bCalculate;
+ vp >> bCalculate;
+
+ pInterForm->EnableCalculate(bCalculate);
+ }
+
+ return TRUE;
+}
+
+FX_BOOL Document::documentFileName(OBJ_PROP_PARAMS)
+{
+ if (!vp.IsGetting())
+ return FALSE;
+
+ CFX_WideString wsFilePath = m_pDocument->GetPath();
+
+ FX_INT32 i = wsFilePath.GetLength() - 1;
+ for ( ; i >= 0; i-- )
+ {
+ if ( wsFilePath.GetAt( i ) == L'\\' || wsFilePath.GetAt( i ) == L'/' )
+ break;
+ }
+ if ( i >= 0 && i < wsFilePath.GetLength() - 1 )
+ {
+ vp << ( wsFilePath.GetBuffer( wsFilePath.GetLength() ) + i + 1 );
+ }else{
+ vp << L"";
+ }
+ return TRUE;
+}
+
+CFX_WideString Document::ReversalStr(CFX_WideString cbFrom)
+{
+ wchar_t* pFrom = NULL;
+ int iLenth = cbFrom.GetLength();
+ wchar_t* pResult = (wchar_t*)malloc((iLenth+1) * sizeof(wchar_t));
+ memset(pResult, 0, (iLenth+1));
+ pFrom = (wchar_t*)cbFrom.GetBuffer(iLenth);
+
+ for (int i = 0; i < iLenth; i++)
+ {
+ pResult[i] = *(pFrom + iLenth - i - 1);
+ }
+
+ cbFrom.ReleaseBuffer();
+ CFX_WideString cbRet = CFX_WideString(pResult);
+ free(pResult);
+ pResult = NULL;
+ return cbRet;
+}
+
+CFX_WideString Document::CutString(CFX_WideString cbFrom)
+{
+ wchar_t* pFrom = NULL;
+ int iLenth = cbFrom.GetLength();
+ wchar_t* pResult = (wchar_t*)malloc((iLenth+1) * sizeof(wchar_t));
+ memset(pResult, 0, (iLenth+1));
+ pFrom = (wchar_t*)cbFrom.GetBuffer(iLenth);
+
+ for (int i = 0; i < iLenth; i++)
+ {
+ if (pFrom[i] == L'\\' || pFrom[i] == L'/')
+ break;
+ pResult[i] = pFrom[i];
+ }
+
+ cbFrom.ReleaseBuffer();
+ CFX_WideString cbRet = CFX_WideString(pResult);
+ free(pResult);
+ pResult = NULL;
+ return cbRet;
+}
+
+FX_BOOL Document::path(OBJ_PROP_PARAMS)
+{
+ if (!vp.IsGetting()) return FALSE;
+
+ vp << app::SysPathToPDFPath(m_pDocument->GetPath());
+
+ return TRUE;
+}
+
+FX_BOOL Document::pageWindowRect(OBJ_PROP_PARAMS)
+{
+ return TRUE;
+}
+
+FX_BOOL Document::layout(OBJ_PROP_PARAMS)
+{
+ return TRUE;
+}
+
+FX_BOOL Document::addLink(OBJ_METHOD_PARAMS)
+{
+ return TRUE;
+}
+
+FX_BOOL Document::closeDoc(OBJ_METHOD_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+
+
+
+
+ return TRUE;
+}
+
+FX_BOOL Document::getPageBox(OBJ_METHOD_PARAMS)
+{
+ return TRUE;
+}
+
+
+FX_BOOL Document::getAnnot(OBJ_METHOD_PARAMS)
+{
+ return TRUE;
+}
+
+FX_BOOL Document::getAnnots(OBJ_METHOD_PARAMS)
+{
+ vRet.SetNull();
+ return TRUE;
+}
+
+FX_BOOL Document::getAnnot3D(OBJ_METHOD_PARAMS)
+{
+ vRet.SetNull();
+ return TRUE;
+}
+
+FX_BOOL Document::getAnnots3D(OBJ_METHOD_PARAMS)
+{
+ vRet = VT_undefined;
+ return TRUE;
+}
+
+FX_BOOL Document::getOCGs(OBJ_METHOD_PARAMS)
+{
+ return TRUE;
+}
+
+FX_BOOL Document::getLinks(OBJ_METHOD_PARAMS)
+{
+ return TRUE;
+}
+
+bool Document::IsEnclosedInRect(CFX_FloatRect rect, CFX_FloatRect LinkRect)
+{
+ if (rect.left <= LinkRect.left
+ && rect.top <= LinkRect.top
+ && rect.right >= LinkRect.right
+ && rect.bottom >= LinkRect.bottom)
+ return true;
+ else
+ return false;
+}
+
+void IconTree::InsertIconElement(IconElement* pNewIcon)
+{
+ if (!pNewIcon)return;
+
+ if (m_pHead == NULL && m_pEnd == NULL)
+ {
+ m_pHead = m_pEnd = pNewIcon;
+ m_iLength++;
+ }
+ else
+ {
+ m_pEnd->NextIcon = pNewIcon;
+ m_pEnd = pNewIcon;
+ m_iLength++;
+ }
+}
+
+void IconTree::DeleteIconTree()
+{
+ if (!m_pHead || !m_pEnd)return;
+
+ IconElement* pTemp = NULL;
+ while(m_pEnd != m_pHead)
+ {
+ pTemp = m_pHead;
+ m_pHead = m_pHead->NextIcon;
+ delete pTemp;
+ }
+
+ delete m_pEnd;
+ m_pHead = NULL;
+ m_pEnd = NULL;
+}
+
+int IconTree::GetLength()
+{
+ return m_iLength;
+}
+
+IconElement* IconTree::operator [](int iIndex)
+{
+ if (iIndex >= 0 && iIndex <= m_iLength)
+ {
+ IconElement* pTemp = m_pHead;
+ for (int i = 0; i < iIndex; i++)
+ {
+ pTemp = pTemp->NextIcon;
+ }
+ return pTemp;
+ }
+ else
+ return NULL;
+}
+
+void IconTree::DeleteIconElement(CFX_WideString swIconName)
+{
+ IconElement* pTemp = m_pHead;
+ int iLoopCount = m_iLength;
+ for (int i = 0; i < iLoopCount - 1; i++)
+ {
+ if (pTemp == m_pEnd)
+ break;
+
+ if (m_pHead->IconName == swIconName)
+ {
+ m_pHead = m_pHead->NextIcon;
+ delete pTemp;
+ m_iLength--;
+ pTemp = m_pHead;
+ }
+ if (pTemp->NextIcon->IconName == swIconName)
+ {
+ if (pTemp->NextIcon == m_pEnd)
+ {
+ m_pEnd = pTemp;
+ delete pTemp->NextIcon;
+ m_iLength--;
+ pTemp->NextIcon = NULL;
+ }
+ else
+ {
+ IconElement* pElement = pTemp->NextIcon;
+ pTemp->NextIcon = pTemp->NextIcon->NextIcon;
+ delete pElement;
+ m_iLength--;
+ pElement = NULL;
+ }
+
+ continue;
+ }
+
+ pTemp = pTemp->NextIcon;
+ }
+}
+
+FX_BOOL Document::addIcon(OBJ_METHOD_PARAMS)
+{
+ if (params.size() != 2)return FALSE;
+
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ ASSERT(pRuntime != NULL);
+
+ CFX_WideString swIconName = params[0].operator CFX_WideString();
+
+ JSFXObject pJSIcon = (JSFXObject)params[1];
+ if (JS_GetObjDefnID(pJSIcon) != JS_GetObjDefnID(*pRuntime, L"Icon")) return FALSE;
+
+ CJS_EmbedObj* pEmbedObj = ((CJS_Object*)params[1])->GetEmbedObject();
+ if (!pEmbedObj)return FALSE;
+ Icon* pIcon = (Icon*)pEmbedObj;
+
+ if (!m_pIconTree)
+ m_pIconTree = new IconTree();
+
+ IconElement* pNewIcon = new IconElement();
+ pNewIcon->IconName = swIconName;
+ pNewIcon->NextIcon = NULL;
+ pNewIcon->IconStream = pIcon;
+ m_pIconTree->InsertIconElement(pNewIcon);
+ return TRUE;
+}
+
+FX_BOOL Document::icons(OBJ_PROP_PARAMS)
+{
+ if (vp.IsSetting())
+ return FALSE;
+
+ if (!m_pIconTree)
+ {
+ vp.SetNull();
+ return TRUE;
+ }
+
+ CJS_Array Icons(m_isolate);
+ IconElement* pIconElement = NULL;
+ int iIconTreeLength = m_pIconTree->GetLength();
+
+ CJS_Context* pContext = (CJS_Context *)cc;
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+
+ for (int i = 0; i < iIconTreeLength; i++)
+ {
+ pIconElement = (*m_pIconTree)[i];
+
+ JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"Icon"));
+ if (pObj.IsEmpty()) return FALSE;
+
+ CJS_Icon * pJS_Icon = (CJS_Icon *)JS_GetPrivate(pObj);
+ if (!pJS_Icon) return FALSE;
+
+ Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject();
+ if (!pIcon)return FALSE;
+
+ pIcon->SetStream(pIconElement->IconStream->GetStream());
+ pIcon->SetIconName(pIconElement->IconName);
+ Icons.SetElement(i, CJS_Value(m_isolate,pJS_Icon));
+ }
+
+ vp << Icons;
+ return TRUE;
+}
+
+FX_BOOL Document::getIcon(OBJ_METHOD_PARAMS)
+{
+ if (params.size() != 1)return FALSE;
+ if(!m_pIconTree)
+ return FALSE;
+ CFX_WideString swIconName = params[0].operator CFX_WideString();
+ int iIconCounts = m_pIconTree->GetLength();
+
+ CJS_Context* pContext = (CJS_Context *)cc;
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+
+ for (int i = 0; i < iIconCounts; i++)
+ {
+ if ((*m_pIconTree)[i]->IconName == swIconName)
+ {
+ Icon* pRetIcon = (*m_pIconTree)[i]->IconStream;
+
+ JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"Icon"));
+ if (pObj.IsEmpty()) return FALSE;
+
+ CJS_Icon * pJS_Icon = (CJS_Icon *)JS_GetPrivate(pObj);
+ if (!pJS_Icon) return FALSE;
+
+ Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject();
+ if (!pIcon)return FALSE;
+
+ pIcon->SetIconName(swIconName);
+ pIcon->SetStream(pRetIcon->GetStream());
+ vRet = pJS_Icon;
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+FX_BOOL Document::removeIcon(OBJ_METHOD_PARAMS)
+{
+ if (params.size() != 1)return FALSE;
+ if(!m_pIconTree)
+ return FALSE;
+ CFX_WideString swIconName = params[0].operator CFX_WideString();
+#ifndef FOXIT_CHROME_BUILD
+ m_pIconTree->DeleteIconElement(swIconName);
+#endif
+ return TRUE;
+}
+
+FX_BOOL Document::createDataObject(OBJ_METHOD_PARAMS)
+{
+ if (IsSafeMode(cc)) return TRUE;
+ ASSERT(m_pDocument != NULL);
+
+ CFX_WideString swName = L"";
+ CFX_ByteString sbName = "";
+ CFX_WideString swValue = L"";
+ CFX_WideString swMIMEType = L"";
+ CFX_WideString swCryptFilter = L"";
+ CFX_ByteString sbFileValue = "";
+
+ int iParamSize = params.size();
+ for (int i = 0; i < iParamSize; i++)
+ {
+ if (i == 0)
+ swName = params[0];
+ if (i == 1)
+ swValue = params[1];
+ if (i == 2)
+ swMIMEType = params[2];
+ if (i == 3)
+ swCryptFilter = params[4];
+ }
+
+ FILE* pFile = NULL;
+
+ //CFileStatus fileStatus;
+ const int BUFSIZE = 17;
+ FX_BYTE buf[BUFSIZE];
+ FX_BYTE *pBuffer = NULL;
+ char* pBuf = NULL;
+ int nFileSize = 0;
+ sbFileValue = CFX_ByteString::FromUnicode(swValue);
+ sbName = CFX_ByteString::FromUnicode(swName);
+ int iBufLength = sbFileValue.GetLength();
+ pBuf = (char*)malloc(sizeof(char) * iBufLength);
+ pBuf = sbFileValue.GetBuffer(iBufLength);
+
+ if ( NULL == (pFile = FXSYS_fopen( sbName.GetBuffer(sbName.GetLength()), "wb+" )) )
+ {
+ return FALSE;
+ }
+
+ fwrite( pBuf, sizeof(char), iBufLength, pFile );
+ fclose( pFile );
+ pFile = NULL;
+
+ pFile = FXSYS_fopen( sbName.GetBuffer(sbName.GetLength()), "rb+" );
+ fseek( pFile, 0, SEEK_END );
+ nFileSize = ftell( pFile );
+
+ pBuffer = new FX_BYTE[nFileSize];
+ fseek( pFile, 0, SEEK_SET );
+ size_t s = fread( pBuffer, sizeof(char), nFileSize, pFile );
+ if(s == 0)
+ {
+ delete[] pBuffer;
+ return FALSE;
+ }
+
+ CRYPT_MD5Generate(pBuffer, nFileSize, buf);
+ buf[BUFSIZE - 1] = 0;
+ CFX_WideString csCheckSum((FX_LPCWSTR)buf, 16);
+ delete[] pBuffer;
+
+ return TRUE;
+}
+
+FX_BOOL Document::media(OBJ_PROP_PARAMS)
+{
+ return TRUE;
+}
+
+FX_BOOL Document::calculateNow(OBJ_METHOD_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) ||
+ m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) ||
+ m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) return FALSE;
+
+ CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
+ pInterForm->OnCalculate();
+ return TRUE;
+}
+
+FX_BOOL Document::Collab(OBJ_PROP_PARAMS)
+{
+ return TRUE;
+}
+
+FX_BOOL Document::getPageNthWord(OBJ_METHOD_PARAMS)
+{
+ //if (IsSafeMode(cc)) return TRUE;
+
+ ASSERT(m_pDocument != NULL);
+
+ if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE;
+
+ int nPageNo = params.GetSize() > 0 ? (int)params[0] : 0;
+ int nWordNo = params.GetSize() > 1 ? (int)params[1] : 0;
+ bool bStrip = params.GetSize() > 2 ? (bool)params[2] : true;
+
+ CPDF_Document* pDocument = m_pDocument->GetDocument();
+ if (!pDocument) return FALSE;
+
+ if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount())
+ {
+ //sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
+
+ CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo);
+ if (!pPageDict) return FALSE;
+
+ CPDF_Page page;
+ page.Load(pDocument, pPageDict);
+ page.StartParse();
+ page.ParseContent();
+
+ FX_POSITION pos = page.GetFirstObjectPosition();
+
+ int nWords = 0;
+
+ CFX_WideString swRet;
+
+ while (pos)
+ {
+ if (CPDF_PageObject* pPageObj = page.GetNextObject(pos))
+ {
+ if (pPageObj->m_Type == PDFPAGE_TEXT)
+ {
+ int nObjWords = CountWords((CPDF_TextObject*)pPageObj);
+
+ if (nWords + nObjWords >= nWordNo)
+ {
+ swRet = GetObjWordStr((CPDF_TextObject*)pPageObj, nWordNo - nWords);
+ break;
+ }
+
+ nWords += nObjWords;
+ }
+ }
+ }
+
+ if (bStrip)
+ {
+ swRet.TrimLeft();
+ swRet.TrimRight();
+ }
+
+ vRet = swRet;
+ return TRUE;
+}
+
+FX_BOOL Document::getPageNthWordQuads(OBJ_METHOD_PARAMS)
+{
+ //if (IsSafeMode(cc)) return TRUE;
+
+ ASSERT(m_pDocument != NULL);
+
+ if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE;
+
+ return FALSE;
+}
+
+FX_BOOL Document::getPageNumWords(OBJ_METHOD_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE;
+
+ int nPageNo = params.GetSize() > 0 ? (int)params[0] : 0;
+
+ CPDF_Document* pDocument = m_pDocument->GetDocument();
+ ASSERT(pDocument != NULL);
+
+ if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount())
+ {
+ //sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
+
+ CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo);
+ if (!pPageDict) return FALSE;
+
+ CPDF_Page page;
+ page.Load(pDocument, pPageDict);
+ page.StartParse();
+ page.ParseContent();
+
+ FX_POSITION pos = page.GetFirstObjectPosition();
+
+ int nWords = 0;
+
+ while (pos)
+ {
+ if (CPDF_PageObject* pPageObj = page.GetNextObject(pos))
+ {
+ if (pPageObj->m_Type == PDFPAGE_TEXT)
+ {
+ CPDF_TextObject* pTextObj = (CPDF_TextObject*)pPageObj;
+ nWords += CountWords(pTextObj);
+ }
+ }
+ }
+
+ vRet = nWords;
+
+ return TRUE;
+}
+
+FX_BOOL Document::getPrintParams(OBJ_METHOD_PARAMS)
+{
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ ASSERT(pRuntime != NULL);
+ JSFXObject pRetObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"PrintParamsObj"));
+ //not implemented yet.
+ vRet = pRetObj;
+
+ return TRUE;
+}
+
+#define ISLATINWORD(u) (u != 0x20 && u <= 0x28FF)
+
+int Document::CountWords(CPDF_TextObject* pTextObj)
+{
+ if (!pTextObj) return 0;
+
+ int nWords = 0;
+
+ CPDF_Font* pFont = pTextObj->GetFont();
+ if (!pFont) return 0;
+
+ FX_BOOL bIsLatin = FALSE;
+
+ for (int i=0, sz=pTextObj->CountChars(); i<sz; i++)
+ {
+ FX_DWORD charcode = -1;
+ FX_FLOAT kerning;
+
+ pTextObj->GetCharInfo(i, charcode, kerning);
+ CFX_WideString swUnicode = pFont->UnicodeFromCharCode(charcode);
+
+ FX_WORD unicode = 0;
+ if (swUnicode.GetLength() > 0)
+ unicode = swUnicode[0];
+
+ if (ISLATINWORD(unicode) && bIsLatin)
+ continue;
+
+ bIsLatin = ISLATINWORD(unicode);
+ if (unicode != 0x20)
+ nWords++;
+ }
+
+ return nWords;
+}
+
+CFX_WideString Document::GetObjWordStr(CPDF_TextObject* pTextObj, int nWordIndex)
+{
+ ASSERT(pTextObj != NULL);
+
+ CFX_WideString swRet;
+
+ CPDF_Font* pFont = pTextObj->GetFont();
+ if (!pFont) return L"";
+
+ int nWords = 0;
+ FX_BOOL bIsLatin = FALSE;
+
+ for (int i=0, sz=pTextObj->CountChars(); i<sz; i++)
+ {
+ FX_DWORD charcode = -1;
+ FX_FLOAT kerning;
+
+ pTextObj->GetCharInfo(i, charcode, kerning);
+ CFX_WideString swUnicode = pFont->UnicodeFromCharCode(charcode);
+
+ FX_WORD unicode = 0;
+ if (swUnicode.GetLength() > 0)
+ unicode = swUnicode[0];
+
+ if (ISLATINWORD(unicode) && bIsLatin)
+ {
+ }
+ else
+ {
+ bIsLatin = ISLATINWORD(unicode);
+ if (unicode != 0x20)
+ nWords++;
+ }
+
+ if (nWords-1 == nWordIndex)
+ swRet += unicode;
+ }
+
+ return swRet;
+}
+
+FX_BOOL Document::zoom(OBJ_PROP_PARAMS)
+{
+
+ return TRUE;
+}
+
+/**
+(none, NoVary)
+(fitP, FitPage)
+(fitW, FitWidth)
+(fitH, FitHeight)
+(fitV, FitVisibleWidth)
+(pref, Preferred)
+(refW, ReflowWidth)
+*/
+
+FX_BOOL Document::zoomType(OBJ_PROP_PARAMS)
+{
+ return TRUE;
+}
+
+FX_BOOL Document::deletePages(OBJ_METHOD_PARAMS)
+{
+
+
+
+
+
+
+ v8::Isolate* isolate = GetIsolate(cc);
+// if (pEnv->GetAppName().Compare(PHANTOM) != 0)
+// return TRUE;
+
+ //if (IsSafeMode(cc)) return TRUE;
+
+ ASSERT(m_pDocument != NULL);
+
+ if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) ||
+ m_pDocument->GetPermissions(FPDFPERM_ASSEMBLE))) return FALSE;
+
+ int iSize = params.size();
+
+ int nStart = 0;
+ int nEnd = 0;
+
+ if (iSize < 1)
+ {
+ }
+ else if (iSize == 1)
+ {
+ if (params[0].GetType() == VT_object)
+ {
+ JSObject pObj = (JSObject )params[0];
+ v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj, L"nStart");
+ nStart = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue));
+
+ pValue = JS_GetObjectElement(isolate,pObj, L"nEnd");
+ nEnd = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue));
+ }
+ else
+ {
+ nStart = (int)params[0];
+ }
+ }
+ else
+ {
+ nStart = (int)params[0];
+ nEnd = (int)params[1];
+ }
+
+ int nTotal = m_pDocument->GetPageCount();
+
+ if (nStart < 0) nStart = 0;
+ if (nStart >= nTotal) nStart = nTotal - 1;
+
+ if (nEnd < 0) nEnd = 0;
+ if (nEnd >= nTotal) nEnd = nTotal - 1;
+
+ if (nEnd < nStart) nEnd = nStart;
+
+
+
+#ifndef FOXIT_CHROME_BUILD
+ return m_pDocument->DeletePages(nStart, nEnd - nStart + 1);
+#else
+ return TRUE;
+#endif
+}
+
+FX_BOOL Document::extractPages(OBJ_METHOD_PARAMS)
+{
+
+
+
+
+
+
+ v8::Isolate* isolate = GetIsolate(cc);
+
+ if (IsSafeMode(cc)) return TRUE;
+
+ ASSERT(m_pDocument != NULL);
+
+ if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT)) return FALSE;
+
+ int iSize = params.size();
+
+ int nTotal = m_pDocument->GetPageCount();
+ int nStart = 0;
+ int nEnd = nTotal - 1;
+
+ CFX_WideString swFilePath;
+
+ if (iSize < 1)
+ {
+ }
+ else if (iSize == 1)
+ {
+ if (params[0].GetType() == VT_object)
+ {
+ JSObject pObj = (JSObject )params[0];
+ v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj, L"nStart");
+ nStart = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue));
+
+ pValue = JS_GetObjectElement(isolate,pObj, L"nEnd");
+ nEnd = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue));
+
+ pValue = JS_GetObjectElement(isolate,pObj, L"cPath");
+ swFilePath = CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
+ }
+ else
+ {
+ nStart = (int)params[0];
+ }
+ }
+ else if (iSize == 2)
+ {
+ nStart = (int)params[0];
+ nEnd = (int)params[1];
+ }
+ else
+ {
+ nStart = (int)params[0];
+ nEnd = (int)params[1];
+ swFilePath = params[2].operator CFX_WideString();
+ }
+
+ if (nEnd < nStart)
+ nEnd = nStart;
+
+ CPDF_Document *pNewDoc = new CPDF_Document;
+ pNewDoc->CreateNewDoc();
+
+ CFX_WordArray array;
+ for (int i=nStart; i<=nEnd; i++)
+ array.Add(i);
+
+// m_pDocument->ExtractPages(array, pNewDoc);
+
+ if (swFilePath.IsEmpty())
+ {
+
+ }
+ else
+ {
+ swFilePath = app::PDFPathToSysPath(swFilePath);
+ CPDF_Creator PDFCreater(pNewDoc);
+ PDFCreater.Create(swFilePath);
+ delete pNewDoc;
+// pEnv->OpenDocument(swFilePath);
+ vRet.SetNull();
+ }
+
+ return TRUE;
+}
+
+FX_BOOL Document::insertPages(OBJ_METHOD_PARAMS)
+{
+
+
+
+
+
+
+ v8::Isolate* isolate = GetIsolate(cc);
+
+ if (IsSafeMode(cc)) return TRUE;
+
+ ASSERT(m_pDocument != NULL);
+
+ if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) ||
+ m_pDocument->GetPermissions(FPDFPERM_ASSEMBLE))) return FALSE;
+
+ int iSize = params.size();
+
+ int nStart = 0;
+ int nEnd = 0;
+ int nPage = 0;
+
+ CFX_WideString swFilePath;
+
+ if (iSize < 1)
+ {
+ }
+ else if (iSize == 1)
+ {
+ if (params[0].GetType() == VT_object)
+ {
+ JSObject pObj = (JSObject )params[0];
+
+ v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj, L"nPage");
+ nPage = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue));
+
+ pValue = JS_GetObjectElement(isolate,pObj, L"cPath");
+ swFilePath = CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
+
+ pValue = JS_GetObjectElement(isolate,pObj, L"nStart");
+ nStart = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue));
+
+ pValue = JS_GetObjectElement(isolate,pObj, L"nEnd");
+ nEnd = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue));
+ }
+ else
+ {
+ nPage = (int)params[0];
+ }
+ }
+ else
+ {
+ nPage = (int)params[0];
+
+ if (iSize >= 2)
+ swFilePath = params[1].operator CFX_WideString();
+
+ if (iSize >= 3)
+ nStart = (int)params[2];
+
+ if (iSize >= 4)
+ nEnd = (int)params[3];
+ }
+
+ nPage++;
+
+ if (nPage < 0)
+ nPage = 0;
+
+ if (nPage > m_pDocument->GetPageCount())
+ nPage = m_pDocument->GetPageCount();
+
+ if (swFilePath.IsEmpty()) return FALSE;
+
+ swFilePath = app::PDFPathToSysPath(swFilePath);
+
+ CPDF_Parser pdfParser;
+ pdfParser.StartParse(swFilePath, FALSE);
+ CPDF_Document* pSrcDoc = pdfParser.GetDocument();
+
+ if (!pSrcDoc)
+ {
+ pdfParser.CloseParser();
+ return FALSE;
+ }
+
+ int nTotal = pSrcDoc->GetPageCount();
+
+ if (nStart < 0) nStart = 0;
+ if (nStart >= nTotal) nStart = nTotal - 1;
+
+ if (nEnd < 0) nEnd = 0;
+ if (nEnd >= nTotal) nEnd = nTotal - 1;
+
+ if (nEnd < nStart) nEnd = nStart;
+
+ CFX_WordArray array;
+ for (int i=nStart; i<=nEnd; i++)
+ array.Add(i);
+
+// m_pDocument->InsertPages(nPage, pSrcDoc, array);
+
+ pdfParser.CloseParser();
+
+ return TRUE;
+}
+
+FX_BOOL Document::replacePages(OBJ_METHOD_PARAMS)
+{
+
+
+
+
+
+
+ v8::Isolate* isolate = GetIsolate(cc);
+
+ if (IsSafeMode(cc)) return TRUE;
+
+ ASSERT(m_pDocument != NULL);
+
+ if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) ||
+ m_pDocument->GetPermissions(FPDFPERM_ASSEMBLE))) return FALSE;
+
+ int iSize = params.size();
+
+ int nStart = -1;
+ int nEnd = -1;
+ int nPage = 0;
+
+ CFX_WideString swFilePath;
+
+ if (iSize < 1)
+ {
+ }
+ else if (iSize == 1)
+ {
+ if (params[0].GetType() == VT_object)
+ {
+ JSObject pObj = (JSObject )params[0];
+
+ v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj, L"nPage");
+ nPage = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue));
+
+ pValue = JS_GetObjectElement(isolate,pObj, L"cPath");
+ swFilePath = CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
+
+ pValue = JS_GetObjectElement(isolate,pObj, L"nStart");
+ nStart = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue));
+
+ pValue = JS_GetObjectElement(isolate,pObj, L"nEnd");
+ nEnd = (int)CJS_Value(m_isolate,pValue,GET_VALUE_TYPE(pValue));
+ }
+ else
+ {
+ nPage = (int)params[0];
+ }
+ }
+ else
+ {
+ nPage = (int)params[0];
+
+ if (iSize >= 2)
+ swFilePath = params[1].operator CFX_WideString();
+
+ if (iSize >= 3)
+ nStart = (int)params[2];
+
+ if (iSize >= 4)
+ nEnd = (int)params[3];
+ }
+
+ if (nPage < 0)
+ nPage = 0;
+
+ if (nPage >= m_pDocument->GetPageCount())
+ nPage = m_pDocument->GetPageCount() - 1;
+
+ if (swFilePath.IsEmpty()) return FALSE;
+
+ swFilePath = app::PDFPathToSysPath(swFilePath);
+
+ CPDF_Parser pdfParser;
+ pdfParser.StartParse(swFilePath, FALSE);
+ CPDF_Document* pSrcDoc = pdfParser.GetDocument();
+
+ if (!pSrcDoc)
+ {
+ pdfParser.CloseParser();
+ return FALSE;
+ }
+
+ int nTotal = pSrcDoc->GetPageCount();
+
+ if (nStart < 0)
+ {
+ if (nEnd < 0)
+ {
+ nStart = 0;
+ nEnd = nTotal - 1;
+ }
+ else
+ {
+ nStart = 0;
+ }
+ }
+ else
+ {
+ if (nEnd < 0)
+ {
+ nEnd = nStart;
+ }
+ else
+ {
+ if (nStart >= nTotal) nStart = nTotal - 1;
+ if (nEnd >= nTotal) nEnd = nTotal - 1;
+
+ if (nEnd < nStart) nEnd = nStart;
+ }
+ }
+
+ CFX_WordArray array;
+ for (int i=nStart; i<=nEnd; i++)
+ array.Add(i);
+
+// m_pDocument->ReplacePages(nPage, pSrcDoc, array);
+
+ pdfParser.CloseParser();
+
+ return TRUE;
+}
+
+FX_BOOL Document::getURL(OBJ_METHOD_PARAMS)
+{
+ if (IsSafeMode(cc)) return TRUE;
+
+ return TRUE;
+}
+
+void Document::AddDelayData(CJS_DelayData* pData)
+{
+ m_DelayData.Add(pData);
+}
+
+void Document::DoFieldDelay(const CFX_WideString& sFieldName, int nControlIndex)
+{
+ CFX_DWordArray DelArray;
+
+ for (int i=0,sz=m_DelayData.GetSize(); i<sz; i++)
+ {
+ if (CJS_DelayData* pData = m_DelayData.GetAt(i))
+ {
+ if (pData->sFieldName == sFieldName && pData->nControlIndex == nControlIndex)
+ {
+ Field::DoDelay(m_pDocument, pData);
+ delete pData;
+ m_DelayData.SetAt(i, NULL);
+ DelArray.Add(i);
+ }
+ }
+ }
+
+ for (int j=DelArray.GetSize()-1; j>=0; j--)
+ {
+ m_DelayData.RemoveAt(DelArray[j]);
+ }
+}
+
+void Document::AddDelayAnnotData(CJS_AnnotObj *pData)
+{
+ m_DelayAnnotData.Add(pData);
+}
+
+void Document::DoAnnotDelay()
+{
+ CFX_DWordArray DelArray;
+
+ for (int j=DelArray.GetSize()-1; j>=0; j--)
+ {
+ m_DelayData.RemoveAt(DelArray[j]);
+ }
+}
diff --git a/fpdfsdk/src/javascript/Field.cpp b/fpdfsdk/src/javascript/Field.cpp
index 44a744f1d1..f5f9bf0539 100644
--- a/fpdfsdk/src/javascript/Field.cpp
+++ b/fpdfsdk/src/javascript/Field.cpp
@@ -1,4128 +1,4128 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/javascript/JavaScript.h"
-#include "../../include/javascript/IJavaScript.h"
-#include "../../include/javascript/JS_Define.h"
-#include "../../include/javascript/JS_Object.h"
-#include "../../include/javascript/JS_Value.h"
-#include "../../include/javascript/Field.h"
-#include "../../include/javascript/JS_EventHandler.h"
-//#include "../include/JS_ResMgr.h"
-#include "../../include/javascript/JS_Context.h"
-#include "../../include/javascript/JS_Runtime.h"
-#include "../../include/javascript/Document.h"
-#include "../../include/javascript/color.h"
-#include "../../include/javascript/PublicMethods.h"
-#include "../../include/javascript/Icon.h"
-
-
-/* ---------------------- Field ---------------------- */
-
-BEGIN_JS_STATIC_CONST(CJS_Field)
-END_JS_STATIC_CONST()
-
-BEGIN_JS_STATIC_PROP(CJS_Field)
- JS_STATIC_PROP_ENTRY(alignment)
- JS_STATIC_PROP_ENTRY(borderStyle)
- JS_STATIC_PROP_ENTRY(buttonAlignX)
- JS_STATIC_PROP_ENTRY(buttonAlignY)
- JS_STATIC_PROP_ENTRY(buttonFitBounds)
- JS_STATIC_PROP_ENTRY(buttonPosition)
- JS_STATIC_PROP_ENTRY(buttonScaleHow)
- JS_STATIC_PROP_ENTRY(buttonScaleWhen)
- JS_STATIC_PROP_ENTRY(calcOrderIndex)
- JS_STATIC_PROP_ENTRY(charLimit)
- JS_STATIC_PROP_ENTRY(comb)
- JS_STATIC_PROP_ENTRY(commitOnSelChange)
- JS_STATIC_PROP_ENTRY(currentValueIndices)
- JS_STATIC_PROP_ENTRY(defaultStyle)
- JS_STATIC_PROP_ENTRY(defaultValue)
- JS_STATIC_PROP_ENTRY(doNotScroll)
- JS_STATIC_PROP_ENTRY(doNotSpellCheck)
- JS_STATIC_PROP_ENTRY(delay)
- JS_STATIC_PROP_ENTRY(display)
- JS_STATIC_PROP_ENTRY(doc)
- JS_STATIC_PROP_ENTRY(editable)
- JS_STATIC_PROP_ENTRY(exportValues)
- JS_STATIC_PROP_ENTRY(hidden)
- JS_STATIC_PROP_ENTRY(fileSelect)
- JS_STATIC_PROP_ENTRY(fillColor)
- JS_STATIC_PROP_ENTRY(lineWidth)
- JS_STATIC_PROP_ENTRY(highlight)
- JS_STATIC_PROP_ENTRY(multiline)
- JS_STATIC_PROP_ENTRY(multipleSelection)
- JS_STATIC_PROP_ENTRY(name)
- JS_STATIC_PROP_ENTRY(numItems)
- JS_STATIC_PROP_ENTRY(page)
- JS_STATIC_PROP_ENTRY(password)
- JS_STATIC_PROP_ENTRY(print)
- JS_STATIC_PROP_ENTRY(radiosInUnison)
- JS_STATIC_PROP_ENTRY(readonly)
- JS_STATIC_PROP_ENTRY(rect)
- JS_STATIC_PROP_ENTRY(required)
- JS_STATIC_PROP_ENTRY(richText)
- JS_STATIC_PROP_ENTRY(richValue)
- JS_STATIC_PROP_ENTRY(rotation)
- JS_STATIC_PROP_ENTRY(strokeColor)
- JS_STATIC_PROP_ENTRY(style)
- JS_STATIC_PROP_ENTRY(submitName)
- JS_STATIC_PROP_ENTRY(textColor)
- JS_STATIC_PROP_ENTRY(textFont)
- JS_STATIC_PROP_ENTRY(textSize)
- JS_STATIC_PROP_ENTRY(type)
- JS_STATIC_PROP_ENTRY(userName)
- JS_STATIC_PROP_ENTRY(value)
- JS_STATIC_PROP_ENTRY(valueAsString)
- JS_STATIC_PROP_ENTRY(source)
-END_JS_STATIC_PROP()
-
-BEGIN_JS_STATIC_METHOD(CJS_Field)
- JS_STATIC_METHOD_ENTRY(browseForFileToSubmit, 0)
- JS_STATIC_METHOD_ENTRY(buttonGetCaption, 1)
- JS_STATIC_METHOD_ENTRY(buttonGetIcon, 1)
- JS_STATIC_METHOD_ENTRY(buttonImportIcon, 0)
- JS_STATIC_METHOD_ENTRY(buttonSetCaption, 2)
- JS_STATIC_METHOD_ENTRY(buttonSetIcon, 2)
- JS_STATIC_METHOD_ENTRY(checkThisBox, 2)
- JS_STATIC_METHOD_ENTRY(clearItems, 0)
- JS_STATIC_METHOD_ENTRY(defaultIsChecked, 2)
- JS_STATIC_METHOD_ENTRY(deleteItemAt, 1)
- JS_STATIC_METHOD_ENTRY(getArray , 0)
- JS_STATIC_METHOD_ENTRY(getItemAt, 0)
- JS_STATIC_METHOD_ENTRY(getLock, 0)
- JS_STATIC_METHOD_ENTRY(insertItemAt, 0)
- JS_STATIC_METHOD_ENTRY(isBoxChecked, 1)
- JS_STATIC_METHOD_ENTRY(isDefaultChecked, 1)
- JS_STATIC_METHOD_ENTRY(setAction, 2)
- JS_STATIC_METHOD_ENTRY(setFocus, 0)
- JS_STATIC_METHOD_ENTRY(setItems, 1)
- JS_STATIC_METHOD_ENTRY(setLock, 0)
- JS_STATIC_METHOD_ENTRY(signatureGetModifications, 0)
- JS_STATIC_METHOD_ENTRY(signatureGetSeedValue, 0)
- JS_STATIC_METHOD_ENTRY(signatureInfo, 0)
- JS_STATIC_METHOD_ENTRY(signatureSetSeedValue, 0)
- JS_STATIC_METHOD_ENTRY(signatureSign, 0)
- JS_STATIC_METHOD_ENTRY(signatureValidate, 0)
-END_JS_STATIC_METHOD()
-
-IMPLEMENT_JS_CLASS(CJS_Field, Field)
-
-FX_BOOL CJS_Field::InitInstance(IFXJS_Context* cc)
-{
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
-
- Field* pField = (Field*)GetEmbedObject();
- ASSERT(pField != NULL);
-
- pField->SetIsolate(pContext->GetJSRuntime()->GetIsolate());
-
- return TRUE;
-};
-
-Field::Field(CJS_Object* pJSObject): CJS_EmbedObj(pJSObject),
- m_pJSDoc(NULL),
- m_pDocument(NULL),
- m_nFormControlIndex(-1),
- m_bCanSet(FALSE),
- m_bDelay(FALSE),
- m_isolate(NULL)
-{
-}
-
-Field::~Field()
-{
-}
-
-//note: iControlNo = -1, means not a widget.
-void Field::ParseFieldName(const std::wstring &strFieldNameParsed,std::wstring &strFieldName,int & iControlNo)
-{
- int iStart = strFieldNameParsed.find_last_of(L'.');
- if (iStart == -1)
- {
- strFieldName = strFieldNameParsed;
- iControlNo = -1;
- return;
- }
- std::wstring suffixal = strFieldNameParsed.substr(iStart+1);
- iControlNo = FXSYS_wtoi((FX_LPCWSTR)suffixal.c_str());
- if (iControlNo == 0)
- {
- int iStart;
- while((iStart = suffixal.find_last_of(L" ")) != -1)
- {
- suffixal.erase(iStart,1);
- }
-
- if (suffixal.compare(L"0") != 0)
- {
- strFieldName = strFieldNameParsed;
- iControlNo = -1;
- return;
- }
-
- }
- strFieldName = strFieldNameParsed.substr(0,iStart);
-}
-
-FX_BOOL Field::AttachField(Document* pDocument, const CFX_WideString& csFieldName)
-{
- ASSERT(pDocument != NULL);
- m_pJSDoc = pDocument;
-
- m_pDocument = pDocument->GetReaderDoc();
- ASSERT(m_pDocument != NULL);
-
- m_bCanSet = m_pDocument->GetPermissions(FPDFPERM_FILL_FORM) ||
- m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) ||
- m_pDocument->GetPermissions(FPDFPERM_MODIFY);
-
- CPDFSDK_InterForm* pRDInterForm = m_pDocument->GetInterForm();
- ASSERT(pRDInterForm != NULL);
-
- CPDF_InterForm* pInterForm = pRDInterForm->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- CFX_WideString swFieldNameTemp = csFieldName;
- swFieldNameTemp.Replace((FX_LPCWSTR)L"..", (FX_LPCWSTR)L".");
-
- if (pInterForm->CountFields(swFieldNameTemp) <= 0)
- {
- std::wstring strFieldName;
- int iControlNo = -1;
- ParseFieldName((wchar_t*)(FX_LPCWSTR)swFieldNameTemp, strFieldName, iControlNo);
- if (iControlNo == -1) return FALSE;
-
- m_FieldName = strFieldName.c_str();
- m_nFormControlIndex = iControlNo;
- return TRUE;
- }
-
- m_FieldName = swFieldNameTemp;
- m_nFormControlIndex = -1;
-
- return TRUE;
-}
-
-void Field::GetFormFields(CPDFSDK_Document* pDocument, const CFX_WideString& csFieldName, CFX_PtrArray& FieldArray)
-{
- ASSERT(pDocument != NULL);
-
- CPDFSDK_InterForm* pReaderInterForm = pDocument->GetInterForm();
- ASSERT(pReaderInterForm != NULL);
-
- CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- ASSERT(FieldArray.GetSize() == 0);
-
- for (int i=0,sz=pInterForm->CountFields(csFieldName); i<sz; i++)
- {
- if (CPDF_FormField* pFormField = pInterForm->GetField(i, csFieldName))
- FieldArray.Add((void*)pFormField);
- }
-}
-
-void Field::GetFormFields(const CFX_WideString& csFieldName, CFX_PtrArray& FieldArray)
-{
- ASSERT(m_pDocument != NULL);
-
- Field::GetFormFields(m_pDocument, csFieldName, FieldArray);
-}
-
-void Field::UpdateFormField(CPDFSDK_Document* pDocument, CPDF_FormField* pFormField,
- FX_BOOL bChangeMark, FX_BOOL bResetAP, FX_BOOL bRefresh)
-{
- ASSERT(pDocument != NULL);
- ASSERT(pFormField != NULL);
-
- CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- CFX_PtrArray widgets;
- pInterForm->GetWidgets(pFormField, widgets);
-
- if (bResetAP)
- {
- int nFieldType = pFormField->GetFieldType();
- if (nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_TEXTFIELD)
- {
- for (int i=0,sz=widgets.GetSize(); i<sz; i++)
- {
- CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)widgets.GetAt(i);
- ASSERT(pWidget != NULL);
-
- FX_BOOL bFormated = FALSE;
- CFX_WideString sValue = pWidget->OnFormat(0, bFormated);
- if (bFormated)
- pWidget->ResetAppearance(sValue, FALSE);
- else
- pWidget->ResetAppearance(NULL, FALSE);
- }
- }
- else
- {
- for (int i=0,sz=widgets.GetSize(); i<sz; i++)
- {
- CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)widgets.GetAt(i);
- ASSERT(pWidget != NULL);
-
- pWidget->ResetAppearance(NULL, FALSE);
- }
- }
- }
-
- if (bRefresh)
- {
- for (int i=0,sz=widgets.GetSize(); i<sz; i++)
- {
- CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)widgets.GetAt(i);
- ASSERT(pWidget != NULL);
-
- CPDFSDK_InterForm * pInterForm = pWidget->GetInterForm();
- CPDFSDK_Document* pDoc = pInterForm->GetDocument();
-// CReader_Page* pPage = pWidget->GetPage();
- ASSERT(pDoc != NULL);
- pDoc->UpdateAllViews(NULL, pWidget);
- }
- }
-
- if (bChangeMark)
- pDocument->SetChangeMark();
-}
-
-void Field::UpdateFormControl(CPDFSDK_Document* pDocument, CPDF_FormControl* pFormControl,
- FX_BOOL bChangeMark, FX_BOOL bResetAP, FX_BOOL bRefresh)
-{
- ASSERT(pDocument != NULL);
- ASSERT(pFormControl != NULL);
-
- CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl);
-
- if (pWidget)
- {
- if (bResetAP)
- {
- int nFieldType = pWidget->GetFieldType();
- if (nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_TEXTFIELD)
- {
- FX_BOOL bFormated = FALSE;
- CFX_WideString sValue = pWidget->OnFormat(0, bFormated);
- if (bFormated)
- pWidget->ResetAppearance(sValue, FALSE);
- else
- pWidget->ResetAppearance(NULL, FALSE);
- }
- else
- {
- pWidget->ResetAppearance(NULL, FALSE);
- }
- }
-
- if (bRefresh)
- {
- CPDFSDK_InterForm * pInterForm = pWidget->GetInterForm();
- CPDFSDK_Document* pDoc = pInterForm->GetDocument();
- ASSERT(pDoc != NULL);
- pDoc->UpdateAllViews(NULL, pWidget);
- }
-
- }
-
- if (bChangeMark)
- pDocument->SetChangeMark();
-}
-
-CPDFSDK_Widget* Field::GetWidget(CPDFSDK_Document* pDocument, CPDF_FormControl* pFormControl)
-{
- ASSERT(pDocument != NULL);
- ASSERT(pFormControl != NULL);
-
- CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- return pInterForm->GetWidget(pFormControl);
-}
-
-FX_BOOL Field::ValueIsOccur(CPDF_FormField* pFormField, CFX_WideString csOptLabel)
-{
- ASSERT(pFormField != NULL);
-
- for (int i=0,sz = pFormField->CountOptions(); i < sz; i++)
- {
- if (csOptLabel.Compare(pFormField->GetOptionLabel(i)) == 0)
- return TRUE;
- }
-
- return FALSE;
-}
-
-CPDF_FormControl* Field::GetSmartFieldControl(CPDF_FormField* pFormField)
-{
- ASSERT(pFormField != NULL);
- if(!pFormField->CountControls() || m_nFormControlIndex>=pFormField->CountControls()) return NULL;
-
- if (m_nFormControlIndex<0)
- return pFormField->GetControl(0);
- else
- return pFormField->GetControl(m_nFormControlIndex);
-}
-
-/* ---------------------------------------- property ---------------------------------------- */
-
-FX_BOOL Field::alignment(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- CFX_ByteString alignStr;
- vp >> alignStr;
-
- if (m_bDelay)
- {
- AddDelay_String(FP_ALIGNMENT, alignStr);
- }
- else
- {
- Field::SetAlignment(m_pDocument, m_FieldName, m_nFormControlIndex, alignStr);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName, FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
- return FALSE;
-
- CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
- if (!pFormControl)return FALSE;
-
- switch (pFormControl->GetControlAlignment())
- {
- case 1:
- vp << (FX_LPCWSTR)L"center";
- break;
- case 0:
- vp << (FX_LPCWSTR)L"left";
- break;
- case 2:
- vp << (FX_LPCWSTR)L"right";
- break;
- default:
- vp << (FX_LPCWSTR)L"";
- }
- }
-
- return TRUE;
-}
-
-void Field::SetAlignment(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex,
- const CFX_ByteString& string)
-{
- //Not supported.
-}
-
-FX_BOOL Field::borderStyle(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- CFX_ByteString strType = "";
- vp >> strType;
-
- if (m_bDelay)
- {
- AddDelay_String(FP_BORDERSTYLE, strType);
- }
- else
- {
- Field::SetBorderStyle(m_pDocument, m_FieldName, m_nFormControlIndex, strType);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName, FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- if (!pFormField) return FALSE;
-
- CPDFSDK_Widget* pWidget = GetWidget(m_pDocument, GetSmartFieldControl(pFormField));
- if (!pWidget) return FALSE;
-
- int nBorderstyle = pWidget->GetBorderStyle();
-
- switch (nBorderstyle)
- {
- case BBS_SOLID:
- vp << (FX_LPCWSTR)L"solid";
- break;
- case BBS_DASH:
- vp << (FX_LPCWSTR)L"dashed";
- break;
- case BBS_BEVELED:
- vp << (FX_LPCWSTR)L"beveled";
- break;
- case BBS_INSET:
- vp << (FX_LPCWSTR)L"inset";
- break;
- case BBS_UNDERLINE:
- vp << (FX_LPCWSTR)L"underline";
- break;
- default:
- vp << (FX_LPCWSTR)L"";
- break;
- }
- }
-
- return TRUE;
-}
-
-void Field::SetBorderStyle(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex,
- const CFX_ByteString& string)
-{
- ASSERT(pDocument != NULL);
-
- int nBorderStyle = 0;
-
- if (string == "solid")
- nBorderStyle = BBS_SOLID;
- else if (string == "beveled")
- nBorderStyle = BBS_BEVELED;
- else if (string == "dashed")
- nBorderStyle = BBS_DASH;
- else if (string == "inset")
- nBorderStyle = BBS_INSET;
- else if (string == "underline")
- nBorderStyle = BBS_UNDERLINE;
- else return;
-
- CFX_PtrArray FieldArray;
- GetFormFields(pDocument, swFieldName, FieldArray);
-
- for (int i=0,isz=FieldArray.GetSize(); i<isz; i++)
- {
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(i);
- ASSERT(pFormField != NULL);
-
- if (nControlIndex < 0)
- {
- FX_BOOL bSet = FALSE;
- for (int j=0,jsz = pFormField->CountControls(); j<jsz; j++)
- {
- if (CPDFSDK_Widget* pWidget = GetWidget(pDocument, pFormField->GetControl(j)))
- {
- if (pWidget->GetBorderStyle() != nBorderStyle)
- {
- pWidget->SetBorderStyle(nBorderStyle);
- bSet = TRUE;
- }
- }
- }
- if (bSet) UpdateFormField(pDocument, pFormField, TRUE, TRUE, TRUE);
- }
- else
- {
- if(nControlIndex >= pFormField->CountControls()) return;
- if (CPDF_FormControl* pFormControl = pFormField->GetControl(nControlIndex))
- {
- if (CPDFSDK_Widget* pWidget = GetWidget(pDocument, pFormControl))
- {
- if (pWidget->GetBorderStyle() != nBorderStyle)
- {
- pWidget->SetBorderStyle(nBorderStyle);
- UpdateFormControl(pDocument, pFormControl, TRUE, TRUE, TRUE);
- }
- }
- }
- }
- }
-}
-
-FX_BOOL Field::buttonAlignX(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- int nVP;
- vp >> nVP;
-
- if (m_bDelay)
- {
- AddDelay_Int(FP_BUTTONALIGNX, nVP);
- }
- else
- {
- Field::SetButtonAlignX(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
- return FALSE;
-
- CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
- if (!pFormControl)return FALSE;
-
- CPDF_IconFit IconFit = pFormControl->GetIconFit();
-
- FX_FLOAT fLeft,fBottom;
- IconFit.GetIconPosition(fLeft,fBottom);
-
- vp << (FX_INT32)fLeft;
- }
-
- return TRUE;
-}
-
-void Field::SetButtonAlignX(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
-{
- //Not supported.
-}
-
-FX_BOOL Field::buttonAlignY(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- int nVP;
- vp >> nVP;
-
- if (m_bDelay)
- {
- AddDelay_Int(FP_BUTTONALIGNY, nVP);
- }
- else
- {
- Field::SetButtonAlignY(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
- return FALSE;
-
- CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
- if (!pFormControl)return FALSE;
-
- CPDF_IconFit IconFit = pFormControl->GetIconFit();
-
- FX_FLOAT fLeft,fBottom;
- IconFit.GetIconPosition(fLeft,fBottom);
-
- vp << (FX_INT32)fBottom;
- }
-
- return TRUE;
-}
-
-void Field::SetButtonAlignY(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
-{
- //Not supported.
-}
-
-FX_BOOL Field::buttonFitBounds(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- bool bVP;
- vp >> bVP;
-
- if (m_bDelay)
- {
- AddDelay_Bool(FP_BUTTONFITBOUNDS, bVP);
- }
- else
- {
- Field::SetButtonFitBounds(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
- return FALSE;
-
- CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
- if (!pFormControl)return FALSE;
-
- CPDF_IconFit IconFit = pFormControl->GetIconFit();
- vp << IconFit.GetFittingBounds();
- }
-
- return TRUE;
-}
-
-void Field::SetButtonFitBounds(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b)
-{
- //Not supported.
-}
-
-FX_BOOL Field::buttonPosition(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- int nVP;
- vp >> nVP;
-
- if (m_bDelay)
- {
- AddDelay_Int(FP_BUTTONPOSITION, nVP);
- }
- else
- {
- Field::SetButtonPosition(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
- return FALSE;
-
- CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
- if (!pFormControl)return FALSE;
-
- vp << pFormControl->GetTextPosition();
- }
- return TRUE;
-}
-
-void Field::SetButtonPosition(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
-{
- //Not supported.
-}
-
-FX_BOOL Field::buttonScaleHow(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- int nVP;
- vp >> nVP;
-
- if (m_bDelay)
- {
- AddDelay_Int(FP_BUTTONSCALEHOW, nVP);
- }
- else
- {
- Field::SetButtonScaleHow(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName, FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
- return FALSE;
-
- CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
- if (!pFormControl)return FALSE;
-
- CPDF_IconFit IconFit = pFormControl->GetIconFit();
- if (IconFit.IsProportionalScale())
- vp << (FX_INT32)0;
- else
- vp << (FX_INT32)1;
- }
-
- return TRUE;
-}
-
-void Field::SetButtonScaleHow(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
-{
- //Not supported.
-}
-
-FX_BOOL Field::buttonScaleWhen(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- int nVP;
- vp >> nVP;
-
- if (m_bDelay)
- {
- AddDelay_Int(FP_BUTTONSCALEWHEN, nVP);
- }
- else
- {
- Field::SetButtonScaleWhen(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*) FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
- return FALSE;
-
- CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
- if (!pFormControl) return FALSE;
-
- CPDF_IconFit IconFit = pFormControl->GetIconFit();
- int ScaleM = IconFit.GetScaleMethod();
- switch (ScaleM)
- {
- case CPDF_IconFit::Always :
- vp << (FX_INT32) CPDF_IconFit::Always;
- break;
- case CPDF_IconFit::Bigger :
- vp << (FX_INT32) CPDF_IconFit::Bigger;
- break;
- case CPDF_IconFit::Never :
- vp << (FX_INT32) CPDF_IconFit::Never;
- break;
- case CPDF_IconFit::Smaller :
- vp << (FX_INT32) CPDF_IconFit::Smaller;
- break;
- }
- }
-
- return TRUE;
-}
-
-void Field::SetButtonScaleWhen(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
-{
- //Not supported.
-}
-
-FX_BOOL Field::calcOrderIndex(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- int nVP;
- vp >> nVP;
-
- if (m_bDelay)
- {
- AddDelay_Int(FP_CALCORDERINDEX, nVP);
- }
- else
- {
- Field::SetCalcOrderIndex(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName, FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX && pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
- return FALSE;
-
- CPDFSDK_InterForm* pRDInterForm = m_pDocument->GetInterForm();
- ASSERT(pRDInterForm != NULL);
-
- CPDF_InterForm* pInterForm = pRDInterForm->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- vp << (FX_INT32)pInterForm->FindFieldInCalculationOrder(pFormField);
- }
-
- return TRUE;
-}
-
-void Field::SetCalcOrderIndex(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
-{
- //Not supported.
-}
-
-FX_BOOL Field::charLimit(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- int nVP;
- vp >> nVP;
-
- if (m_bDelay)
- {
- AddDelay_Int(FP_CHARLIMIT, nVP);
- }
- else
- {
- Field::SetCharLimit(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName, FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
- return FALSE;
-
- vp << (FX_INT32)pFormField->GetMaxLen();
- }
- return TRUE;
-}
-
-void Field::SetCharLimit(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
-{
- //Not supported.
-}
-
-FX_BOOL Field::comb(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- bool bVP;
- vp >> bVP;
-
- if (m_bDelay)
- {
- AddDelay_Bool(FP_COMB, bVP);
- }
- else
- {
- Field::SetComb(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
- return FALSE;
-
- if (pFormField->GetFieldFlags() & FIELDFLAG_COMB)
- vp << true;
- else
- vp << false;
- }
-
- return TRUE;
-}
-
-void Field::SetComb(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b)
-{
- //Not supported.
-}
-
-FX_BOOL Field::commitOnSelChange(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- bool bVP;
- vp >> bVP;
-
- if (m_bDelay)
- {
- AddDelay_Bool(FP_COMMITONSELCHANGE, bVP);
- }
- else
- {
- Field::SetCommitOnSelChange(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX && pFormField->GetFieldType() != FIELDTYPE_LISTBOX)
- return FALSE;
-
- if (pFormField->GetFieldFlags() & FIELDFLAG_COMMITONSELCHANGE)
- vp << true;
- else
- vp << false;
- }
-
- return TRUE;
-}
-
-void Field::SetCommitOnSelChange(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b)
-{
- //Not supported.
-}
-
-FX_BOOL Field::currentValueIndices(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- CFX_DWordArray array;
-
- if (vp.GetType() == VT_number)
- {
- int iSelecting = 0;
- vp >> iSelecting;
- array.Add(iSelecting);
- }
- else if (vp.IsArrayObject())
- {
- CJS_Array SelArray(m_isolate);
- CJS_Value SelValue(m_isolate);
- int iSelecting;
- vp >> SelArray;
- for (int i=0,sz=SelArray.GetLength(); i<sz; i++)
- {
- SelArray.GetElement(i,SelValue);
- iSelecting = (FX_INT32)SelValue;
- array.Add(iSelecting);
- }
- }
-
- if (m_bDelay)
- {
- AddDelay_WordArray(FP_CURRENTVALUEINDICES, array);
- }
- else
- {
- Field::SetCurrentValueIndices(m_pDocument, m_FieldName, m_nFormControlIndex, array);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX && pFormField->GetFieldType() != FIELDTYPE_LISTBOX)
- return FALSE;
-
- if (pFormField->CountSelectedItems() == 1)
- vp << pFormField->GetSelectedIndex(0);
- else if (pFormField->CountSelectedItems() > 1)
- {
- CJS_Array SelArray(m_isolate);
- for (int i=0,sz=pFormField->CountSelectedItems(); i<sz; i++)
- {
- SelArray.SetElement(i, CJS_Value(m_isolate,pFormField->GetSelectedIndex(i)));
- }
- vp << SelArray;
- }
- else
- vp << -1;
- }
-
- return TRUE;
-}
-
-void Field::SetCurrentValueIndices(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex,
- const CFX_DWordArray& array)
-{
- ASSERT(pDocument != NULL);
-
- CFX_PtrArray FieldArray;
- GetFormFields(pDocument, swFieldName, FieldArray);
-
- for (int i=0,isz=FieldArray.GetSize(); i<isz; i++)
- {
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(i);
- ASSERT(pFormField != NULL);
-
- int nFieldType = pFormField->GetFieldType();
- if (nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_LISTBOX)
- {
- FX_DWORD dwFieldFlags = pFormField->GetFieldFlags();
- pFormField->ClearSelection(TRUE);
-
- for (int i=0,sz=array.GetSize(); i<sz; i++)
- {
- if (i>0 && !(dwFieldFlags & (1<<21)))
- {
- break;
- }
-
- int iSelecting = (FX_INT32)array.GetAt(i);
- if (iSelecting < pFormField->CountOptions() && !pFormField->IsItemSelected(iSelecting))
- pFormField->SetItemSelection(iSelecting, TRUE);
-
- }
- UpdateFormField(pDocument, pFormField, TRUE, TRUE, TRUE);
- }
- }
-}
-
-FX_BOOL Field::defaultStyle(OBJ_PROP_PARAMS)
-{
- // MQG sError = JSGetStringFromID(IDS_STRING_NOTSUPPORT);
- return FALSE;
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- ;
- }
- else
- {
- ;
- }
- return TRUE;
-}
-
-void Field::SetDefaultStyle(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex)
-{
- //Not supported.
-}
-
-FX_BOOL Field::defaultValue(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- CFX_WideString WideStr;
- vp >> WideStr;
-
- if (m_bDelay)
- {
- AddDelay_WideString(FP_DEFAULTVALUE, WideStr);
- }
- else
- {
- Field::SetDefaultValue(m_pDocument, m_FieldName, m_nFormControlIndex, WideStr);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON ||
- pFormField->GetFieldType() == FIELDTYPE_SIGNATURE)
- return FALSE;
-
- vp << pFormField->GetDefaultValue();
- }
- return TRUE;
-}
-
-void Field::SetDefaultValue(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex,
- const CFX_WideString& string)
-{
- //Not supported.
-}
-
-FX_BOOL Field::doNotScroll(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- bool bVP;
- vp >> bVP;
-
- if (m_bDelay)
- {
- AddDelay_Bool(FP_DONOTSCROLL, bVP);
- }
- else
- {
- Field::SetDoNotScroll(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
- return FALSE;
-
- if (pFormField->GetFieldFlags() & FIELDFLAG_DONOTSCROLL)
- vp << true;
- else
- vp << false;
- }
-
- return TRUE;
-}
-
-void Field::SetDoNotScroll(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b)
-{
- //Not supported.
-}
-
-FX_BOOL Field::doNotSpellCheck(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- bool bVP;
- vp >> bVP;
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD &&
- pFormField->GetFieldType() != FIELDTYPE_COMBOBOX)
- return FALSE;
-
- if (pFormField->GetFieldFlags() & FIELDFLAG_DONOTSPELLCHECK)
- vp << true;
- else
- vp << false;
- }
-
- return TRUE;
-}
-
-void Field::SetDelay(FX_BOOL bDelay)
-{
- m_bDelay = bDelay;
-
- if (!m_bDelay)
- {
- if (m_pJSDoc)
- m_pJSDoc->DoFieldDelay(m_FieldName, m_nFormControlIndex);
- }
-}
-
-FX_BOOL Field::delay(OBJ_PROP_PARAMS)
-{
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- bool bVP;
- vp >> bVP;
-
- SetDelay(bVP);
- }
- else
- {
- vp << m_bDelay;
- }
- return TRUE;
-}
-
-FX_BOOL Field::display(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- int nVP;
- vp >> nVP;
-
- if (m_bDelay)
- {
- AddDelay_Int(FP_DISPLAY, nVP);
- }
- else
- {
- Field::SetDisplay(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- CPDFSDK_Widget* pWidget = pInterForm->GetWidget(GetSmartFieldControl(pFormField));
- if (!pWidget)return FALSE;
-
- FX_DWORD dwFlag = pWidget->GetFlags();
-
- if (ANNOTFLAG_INVISIBLE & dwFlag || ANNOTFLAG_HIDDEN & dwFlag)
- {
- vp << (FX_INT32)1;
- }
- else
- {
- if (ANNOTFLAG_PRINT & dwFlag)
- {
- if (ANNOTFLAG_NOVIEW & dwFlag)
- {
- vp << (FX_INT32)3;
- }
- else
- {
- vp << (FX_INT32)0;
- }
- }
- else
- {
- vp << (FX_INT32)2;
- }
- }
- }
-
- return TRUE;
-}
-
-void Field::SetDisplay(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
-{
- ASSERT(pDocument != NULL);
-
- CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- CFX_PtrArray FieldArray;
- GetFormFields(pDocument, swFieldName, FieldArray);
-
- for (int i=0,isz=FieldArray.GetSize(); i<isz; i++)
- {
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(i);
- ASSERT(pFormField != NULL);
-
- if (nControlIndex < 0)
- {
- FX_BOOL bSet = FALSE;
- for (int j=0,jsz = pFormField->CountControls(); j<jsz; j++)
- {
- CPDF_FormControl* pFormControl = pFormField->GetControl(j);
- ASSERT(pFormControl != NULL);
-
- if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl))
- {
- FX_DWORD dwFlag = pWidget->GetFlags();
- switch (number)
- {
- case 0:
- dwFlag &= (~ANNOTFLAG_INVISIBLE);
- dwFlag &= (~ANNOTFLAG_HIDDEN);
- dwFlag &= (~ANNOTFLAG_NOVIEW);
- dwFlag |= ANNOTFLAG_PRINT;
- break;
- case 1:
- dwFlag &= (~ANNOTFLAG_INVISIBLE);
- dwFlag &= (~ANNOTFLAG_NOVIEW);
- dwFlag |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT);
- break;
- case 2:
- dwFlag &= (~ANNOTFLAG_INVISIBLE);
- dwFlag &= (~ANNOTFLAG_PRINT);
- dwFlag &= (~ANNOTFLAG_HIDDEN);
- dwFlag &= (~ANNOTFLAG_NOVIEW);
- break;
- case 3:
- dwFlag |= ANNOTFLAG_NOVIEW;
- dwFlag |= ANNOTFLAG_PRINT;
- dwFlag &= (~ANNOTFLAG_HIDDEN);
- break;
- }
-
- if (dwFlag != pWidget->GetFlags())
- {
- pWidget->SetFlags(dwFlag);
- bSet = TRUE;
- }
- }
- }
-
- if (bSet) UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE);
- }
- else
- {
- if(nControlIndex >= pFormField->CountControls()) return;
- if (CPDF_FormControl* pFormControl = pFormField->GetControl(nControlIndex))
- {
- if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl))
- {
-
- FX_DWORD dwFlag = pWidget->GetFlags();
- switch (number)
- {
- case 0:
- dwFlag &= (~ANNOTFLAG_INVISIBLE);
- dwFlag &= (~ANNOTFLAG_HIDDEN);
- dwFlag &= (~ANNOTFLAG_NOVIEW);
- dwFlag |= ANNOTFLAG_PRINT;
- break;
- case 1:
- dwFlag &= (~ANNOTFLAG_INVISIBLE);
- dwFlag &= (~ANNOTFLAG_NOVIEW);
- dwFlag |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT);
- break;
- case 2:
- dwFlag &= (~ANNOTFLAG_INVISIBLE);
- dwFlag &= (~ANNOTFLAG_PRINT);
- dwFlag &= (~ANNOTFLAG_HIDDEN);
- dwFlag &= (~ANNOTFLAG_NOVIEW);
- break;
- case 3:
- dwFlag |= ANNOTFLAG_NOVIEW;
- dwFlag |= ANNOTFLAG_PRINT;
- dwFlag &= (~ANNOTFLAG_HIDDEN);
- break;
- }
- if (dwFlag != pWidget->GetFlags())
- {
- pWidget->SetFlags(dwFlag);
- UpdateFormControl(pDocument, pFormControl, TRUE, FALSE, TRUE);
- }
- }
- }
- }
- }
-}
-
-FX_BOOL Field::doc(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pJSDoc != NULL);
-
- if (!vp.IsGetting())return FALSE;
-
- vp << (CJS_Object*)(*m_pJSDoc);
-
- return TRUE;
-}
-
-FX_BOOL Field::editable(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- bool bVP;
- vp >> bVP;
-
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName, FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX)
- return FALSE;
-
- if (pFormField->GetFieldFlags() & FIELDFLAG_EDIT)
- vp << true;
- else
- vp << false;
- }
-
- return TRUE;
-}
-
-FX_BOOL Field::exportValues(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if (pFormField->GetFieldType() != FIELDTYPE_CHECKBOX &&
- pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON)
- return FALSE;
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
- if (!vp.IsArrayObject())return FALSE;
- }
- else
- {
- CJS_Array ExportValusArray(m_isolate);
-
- if (m_nFormControlIndex < 0)
- {
- for (int i=0,sz=pFormField->CountControls(); i<sz; i++)
- {
- CPDF_FormControl* pFormControl = pFormField->GetControl(i);
- ASSERT(pFormControl != NULL);
-
- ExportValusArray.SetElement(i, CJS_Value(m_isolate,(FX_LPCWSTR)pFormControl->GetExportValue()));
- }
- }
- else
- {
- if(m_nFormControlIndex >= pFormField->CountControls()) return FALSE;
- CPDF_FormControl* pFormControl = pFormField->GetControl(m_nFormControlIndex);
- if (!pFormControl) return FALSE;
-
- ExportValusArray.SetElement(0, CJS_Value(m_isolate,(FX_LPCWSTR)pFormControl->GetExportValue()));
- }
-
- vp << ExportValusArray;
- }
-
- return TRUE;
-}
-
-FX_BOOL Field::fileSelect(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName, FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
- return FALSE;
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- bool bVP;
- vp >> bVP;
-
- }
- else
- {
- if (pFormField->GetFieldFlags() & FIELDFLAG_FILESELECT)
- vp << true;
- else
- vp << false;
- }
-
- return TRUE;
-}
-
-FX_BOOL Field::fillColor(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- CJS_Array crArray(m_isolate);
-
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
- if (!vp.IsArrayObject()) return FALSE;
-
- vp >> crArray;
-
- CPWL_Color color;
- color::ConvertArrayToPWLColor(crArray, color);
-
- if (m_bDelay)
- {
- AddDelay_Color(FP_FILLCOLOR, color);
- }
- else
- {
- Field::SetFillColor(m_pDocument, m_FieldName, m_nFormControlIndex, color);
- }
- }
- else
- {
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
- if (!pFormControl)return FALSE;
-
- int iColorType;
- pFormControl->GetBackgroundColor(iColorType);
-
- CPWL_Color color;
-
- if (iColorType == COLORTYPE_TRANSPARENT)
- {
- color = CPWL_Color(COLORTYPE_TRANSPARENT);
- }
- else if (iColorType == COLORTYPE_GRAY)
- {
- color = CPWL_Color(COLORTYPE_GRAY, pFormControl->GetOriginalBackgroundColor(0));
- }
- else if (iColorType == COLORTYPE_RGB)
- {
- color = CPWL_Color(COLORTYPE_RGB, pFormControl->GetOriginalBackgroundColor(0),
- pFormControl->GetOriginalBackgroundColor(1),
- pFormControl->GetOriginalBackgroundColor(2));
- }
- else if (iColorType == COLORTYPE_CMYK)
- {
- color = CPWL_Color(COLORTYPE_CMYK, pFormControl->GetOriginalBackgroundColor(0),
- pFormControl->GetOriginalBackgroundColor(1),
- pFormControl->GetOriginalBackgroundColor(2),
- pFormControl->GetOriginalBackgroundColor(3));
- }
- else
- return FALSE;
-
- color::ConvertPWLColorToArray(color, crArray);
- vp << crArray;
- }
-
- return TRUE;
-}
-
-void Field::SetFillColor(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CPWL_Color& color)
-{
- //Not supported.
-}
-
-FX_BOOL Field::hidden(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- bool bVP;
- vp >> bVP;
-
- if (m_bDelay)
- {
- AddDelay_Bool(FP_HIDDEN, bVP);
- }
- else
- {
- Field::SetHidden(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- CPDFSDK_Widget* pWidget = pInterForm->GetWidget(GetSmartFieldControl(pFormField));
- if (!pWidget) return FALSE;
-
- FX_DWORD dwFlags = pWidget->GetFlags();
-
- if (ANNOTFLAG_INVISIBLE & dwFlags || ANNOTFLAG_HIDDEN & dwFlags)
- {
- vp << true;
- }
- else
- vp << false;
- }
-
- return TRUE;
-}
-
-void Field::SetHidden(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b)
-{
- ASSERT(pDocument != NULL);
-
- CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- CFX_PtrArray FieldArray;
- GetFormFields(pDocument, swFieldName, FieldArray);
-
- for (int i=0,isz=FieldArray.GetSize(); i<isz; i++)
- {
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(i);
- ASSERT(pFormField != NULL);
-
- if (nControlIndex < 0)
- {
- FX_BOOL bSet = FALSE;
- for (int j=0,jsz = pFormField->CountControls(); j<jsz; j++)
- {
- if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormField->GetControl(j)))
- {
- FX_DWORD dwFlags = pWidget->GetFlags();
-
- if (b)
- {
- dwFlags &= (~ANNOTFLAG_INVISIBLE);
- dwFlags &= (~ANNOTFLAG_NOVIEW);
- dwFlags |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT);
- }
- else
- {
- dwFlags &= (~ANNOTFLAG_INVISIBLE);
- dwFlags &= (~ANNOTFLAG_HIDDEN);
- dwFlags &= (~ANNOTFLAG_NOVIEW);
- dwFlags |= ANNOTFLAG_PRINT;
- }
-
- if (dwFlags != pWidget->GetFlags())
- {
- pWidget->SetFlags(dwFlags);
- bSet = TRUE;
- }
- }
- }
-
- if (bSet)
- UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE);
- }
- else
- {
- if(nControlIndex >= pFormField->CountControls()) return;
- if (CPDF_FormControl* pFormControl = pFormField->GetControl(nControlIndex))
- {
- if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl))
- {
- FX_DWORD dwFlags = pWidget->GetFlags();
-
- if (b)
- {
- dwFlags &= (~ANNOTFLAG_INVISIBLE);
- dwFlags &= (~ANNOTFLAG_NOVIEW);
- dwFlags |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT);
- }
- else
- {
- dwFlags &= (~ANNOTFLAG_INVISIBLE);
- dwFlags &= (~ANNOTFLAG_HIDDEN);
- dwFlags &= (~ANNOTFLAG_NOVIEW);
- dwFlags |= ANNOTFLAG_PRINT;
- }
-
- if (dwFlags != pWidget->GetFlags())
- {
- pWidget->SetFlags(dwFlags);
- UpdateFormControl(pDocument, pFormControl, TRUE, FALSE, TRUE);
- }
- }
- }
- }
- }
-}
-
-FX_BOOL Field::highlight(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- CFX_ByteString strMode;
- vp >> strMode;
-
- if (m_bDelay)
- {
- AddDelay_String(FP_HIGHLIGHT, strMode);
- }
- else
- {
- Field::SetHighlight(m_pDocument, m_FieldName, m_nFormControlIndex, strMode);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
- return FALSE;
-
- CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
- if (!pFormControl) return FALSE;
-
- int eHM = pFormControl->GetHighlightingMode();
- switch (eHM)
- {
- case CPDF_FormControl::None:
- vp << (FX_LPCWSTR)L"none";
- break;
- case CPDF_FormControl::Push:
- vp << (FX_LPCWSTR)L"push";
- break;
- case CPDF_FormControl::Invert:
- vp << (FX_LPCWSTR)L"invert";
- break;
- case CPDF_FormControl::Outline:
- vp << (FX_LPCWSTR)L"outline";
- break;
- case CPDF_FormControl::Toggle:
- vp << (FX_LPCWSTR)L"toggle";
- break;
- }
- }
-
- return TRUE;
-}
-
-void Field::SetHighlight(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CFX_ByteString& string)
-{
- //Not supported.
-}
-
-FX_BOOL Field::lineWidth(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- int iWidth;
- vp >> iWidth;
-
- if (m_bDelay)
- {
- AddDelay_Int(FP_LINEWIDTH, iWidth);
- }
- else
- {
- Field::SetLineWidth(m_pDocument, m_FieldName, m_nFormControlIndex, iWidth);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
- if (!pFormControl) return FALSE;
-
- CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- if(!pFormField->CountControls()) return FALSE;
-
- CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormField->GetControl(0));
- if (!pWidget) return FALSE;
-
- vp << (FX_INT32)pWidget->GetBorderWidth();
- }
-
- return TRUE;
-}
-
-void Field::SetLineWidth(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
-{
- ASSERT(pDocument != NULL);
-
- CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- CFX_PtrArray FieldArray;
- GetFormFields(pDocument, swFieldName, FieldArray);
-
- for (int i=0,isz=FieldArray.GetSize(); i<isz; i++)
- {
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(i);
- ASSERT(pFormField != NULL);
-
- if (nControlIndex < 0)
- {
- FX_BOOL bSet = FALSE;
- for (int j=0,jsz=pFormField->CountControls(); j<jsz; j++)
- {
- CPDF_FormControl* pFormControl = pFormField->GetControl(j);
- ASSERT(pFormControl != NULL);
-
- if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl))
- {
- if (number != pWidget->GetBorderWidth())
- {
- pWidget->SetBorderWidth(number);
- bSet = TRUE;
- }
- }
- }
- if (bSet) UpdateFormField(pDocument, pFormField, TRUE, TRUE, TRUE);
- }
- else
- {
- if(nControlIndex >= pFormField->CountControls()) return;
- if (CPDF_FormControl* pFormControl = pFormField->GetControl(nControlIndex))
- {
- if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl))
- {
- if (number != pWidget->GetBorderWidth())
- {
- pWidget->SetBorderWidth(number);
- UpdateFormControl(pDocument, pFormControl, TRUE, TRUE, TRUE);
- }
- }
- }
- }
- }
-}
-
-FX_BOOL Field::multiline(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- bool bVP;
- vp >> bVP;
-
- if (m_bDelay)
- {
- AddDelay_Bool(FP_MULTILINE, bVP);
- }
- else
- {
- Field::SetMultiline(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName, FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
- return FALSE;
-
- if (pFormField->GetFieldFlags() & FIELDFLAG_MULTILINE)
- vp << true;
- else
- vp << false;
- }
-
- return TRUE;
-}
-
-void Field::SetMultiline(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b)
-{
- //Not supported.
-}
-
-FX_BOOL Field::multipleSelection(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- bool bVP;
- vp >> bVP;
-
- if (m_bDelay)
- {
- AddDelay_Bool(FP_MULTIPLESELECTION, bVP);
- }
- else
- {
- Field::SetMultipleSelection(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if (pFormField->GetFieldType() != FIELDTYPE_LISTBOX)
- return FALSE;
-
- if (pFormField->GetFieldFlags() & FIELDFLAG_MULTISELECT)
- vp << true;
- else
- vp << false;
- }
-
- return TRUE;
-}
-
-void Field::SetMultipleSelection(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b)
-{
- //Not supported.
-}
-
-FX_BOOL Field::name(OBJ_PROP_PARAMS)
-{
- if (!vp.IsGetting()) return FALSE;
-
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName, FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- vp << m_FieldName;
-
- return TRUE;
-}
-
-FX_BOOL Field::numItems(OBJ_PROP_PARAMS)
-{
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName, FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
- pFormField->GetFieldType() != FIELDTYPE_LISTBOX)
- return FALSE;
-
- if (!vp.IsGetting()) return FALSE;
-
- vp << (FX_INT32)pFormField->CountOptions();
-
- return TRUE;
-}
-
-FX_BOOL Field::page(OBJ_PROP_PARAMS)
-{
- if (!vp.IsGetting()) return FALSE;
-
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName, FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- if (!pFormField) return FALSE;
-
- ASSERT(m_pDocument != NULL);
-
- CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- CFX_PtrArray widgetArray;
- pInterForm->GetWidgets(pFormField, widgetArray);
-
- if (widgetArray.GetSize() > 0)
- {
- CJS_Array PageArray(m_isolate);
-
- for (int i=0,sz=widgetArray.GetSize(); i<sz; i++)
- {
- CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)widgetArray.GetAt(i);
- ASSERT(pWidget != NULL);
-
- CPDFSDK_PageView* pPageView = pWidget->GetPageView();
- if(!pPageView)
- return FALSE;
-
- PageArray.SetElement(i, CJS_Value(m_isolate,(FX_INT32)pPageView->GetPageIndex()));
- }
-
- vp << PageArray;
- }
- else
- {
- vp << (FX_INT32) -1;
- }
-
- return TRUE;
-}
-
-FX_BOOL Field::password(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- bool bVP;
- vp >> bVP;
-
- if (m_bDelay)
- {
- AddDelay_Bool(FP_PASSWORD, bVP);
- }
- else
- {
- Field::SetPassword(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
- return FALSE;
-
- if (pFormField->GetFieldFlags() & FIELDFLAG_PASSWORD)
- vp << true;
- else
- vp << false;
- }
-
- return TRUE;
-}
-
-void Field::SetPassword(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b)
-{
- //Not supported.
-}
-
-FX_BOOL Field::print(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName, FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- bool bVP;
- vp >> bVP;
-
- for (int i=0,isz=FieldArray.GetSize(); i<isz; i++)
- {
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(i);
- ASSERT(pFormField != NULL);
-
- if (m_nFormControlIndex < 0)
- {
- FX_BOOL bSet = FALSE;
- for (int j=0,jsz = pFormField->CountControls(); j<jsz; j++)
- {
- if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormField->GetControl(j)))
- {
- FX_DWORD dwFlags = pWidget->GetFlags();
- if (bVP)
- dwFlags |= ANNOTFLAG_PRINT;
- else
- dwFlags &= ~ANNOTFLAG_PRINT;
-
- if (dwFlags != pWidget->GetFlags())
- {
- pWidget->SetFlags(dwFlags);
- bSet = TRUE;
- }
- }
- }
-
- if (bSet)
- UpdateFormField(m_pDocument, pFormField, TRUE, FALSE, TRUE);
- }
- else
- {
- if(m_nFormControlIndex >= pFormField->CountControls()) return FALSE;
- if (CPDF_FormControl* pFormControl = pFormField->GetControl(m_nFormControlIndex))
- {
- if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl))
- {
- FX_DWORD dwFlags = pWidget->GetFlags();
- if (bVP)
- dwFlags |= ANNOTFLAG_PRINT;
- else
- dwFlags &= ~ANNOTFLAG_PRINT;
-
- if (dwFlags != pWidget->GetFlags())
- {
- pWidget->SetFlags(dwFlags);
- UpdateFormControl(m_pDocument, pFormField->GetControl(m_nFormControlIndex), TRUE, FALSE, TRUE);
- }
- }
- }
- }
- }
- }
- else
- {
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- CPDFSDK_Widget* pWidget = pInterForm->GetWidget(GetSmartFieldControl(pFormField));
- if (!pWidget) return FALSE;
-
- if (pWidget->GetFlags() & ANNOTFLAG_PRINT)
- vp << true;
- else
- vp << false;
- }
-
- return TRUE;
-}
-
-FX_BOOL Field::radiosInUnison(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- bool bVP;
- vp >> bVP;
-
- }
- else
- {
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if (pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON)
- return FALSE;
-
- if (pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON)
- vp << true;
- else
- vp << false;
- }
-
- return TRUE;
-}
-
-FX_BOOL Field::readonly(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- bool bVP;
- vp >> bVP;
-
- }
- else
- {
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if (pFormField->GetFieldFlags() & FIELDFLAG_READONLY)
- vp << true;
- else
- vp << false;
- }
-
- return TRUE;
-}
-
-FX_BOOL Field::rect(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
- if (!vp.IsArrayObject())return FALSE;
-
- CJS_Array rcArray(m_isolate);
- vp >> rcArray;
- CJS_Value Upper_Leftx(m_isolate), Upper_Lefty(m_isolate), Lower_Rightx(m_isolate), Lower_Righty(m_isolate);
- rcArray.GetElement(0, Upper_Leftx);
- rcArray.GetElement(1, Upper_Lefty);
- rcArray.GetElement(2, Lower_Rightx);
- rcArray.GetElement(3, Lower_Righty);
-
- FX_FLOAT pArray[4] = {0.0f,0.0f,0.0f,0.0f};
- pArray[0] = (FX_FLOAT)(FX_INT32)Upper_Leftx;
- pArray[1] = (FX_FLOAT)(FX_INT32)Lower_Righty;
- pArray[2] = (FX_FLOAT)(FX_INT32)Lower_Rightx;
- pArray[3] = (FX_FLOAT)(FX_INT32)Upper_Lefty;
-
- CPDF_Rect crRect(pArray);
-
- if (m_bDelay)
- {
- AddDelay_Rect(FP_RECT, crRect);
- }
- else
- {
- Field::SetRect(m_pDocument, m_FieldName, m_nFormControlIndex, crRect);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- CPDFSDK_Widget* pWidget = pInterForm->GetWidget(GetSmartFieldControl(pFormField));
- if (!pWidget) return FALSE;
-
- CFX_FloatRect crRect = pWidget->GetRect();
- CJS_Value Upper_Leftx(m_isolate),Upper_Lefty(m_isolate),Lower_Rightx(m_isolate),Lower_Righty(m_isolate);
- Upper_Leftx = (FX_INT32)crRect.left;
- Upper_Lefty = (FX_INT32)crRect.top;
- Lower_Rightx = (FX_INT32)crRect.right;
- Lower_Righty = (FX_INT32)crRect.bottom;
-
- CJS_Array rcArray(m_isolate);
- rcArray.SetElement(0,Upper_Leftx);
- rcArray.SetElement(1,Upper_Lefty);
- rcArray.SetElement(2,Lower_Rightx);
- rcArray.SetElement(3,Lower_Righty);
-
- vp << rcArray;
- }
-
- return TRUE;
-}
-
-void Field::SetRect(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CPDF_Rect& rect)
-{
- ASSERT(pDocument != NULL);
-
- CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- CFX_PtrArray FieldArray;
- GetFormFields(pDocument, swFieldName, FieldArray);
-
- for (int i=0,isz=FieldArray.GetSize(); i<isz; i++)
- {
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(i);
- ASSERT(pFormField != NULL);
-
- if (nControlIndex < 0)
- {
- FX_BOOL bSet = FALSE;
- for (int i=0, sz=pFormField->CountControls(); i<sz; i++)
- {
- CPDF_FormControl* pFormControl = pFormField->GetControl(i);
- ASSERT(pFormControl != NULL);
-
- if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl))
- {
- CPDF_Rect crRect = rect;
-
- CPDF_Page* pPDFPage = pWidget->GetPDFPage();
- ASSERT(pPDFPage != NULL);
-
-// CPDF_Page* pPDFPage = pPage->GetPage();
-// ASSERT(pPDFPage != NULL);
-
- crRect.Intersect(pPDFPage->GetPageBBox());
-
- if (!crRect.IsEmpty())
- {
- CPDF_Rect rcOld = pWidget->GetRect();
- if (crRect.left != rcOld.left ||
- crRect.right != rcOld.right ||
- crRect.top != rcOld.top ||
- crRect.bottom != rcOld.bottom)
- {
- pWidget->SetRect(crRect);
- bSet = TRUE;
- }
- }
- }
- }
-
- if (bSet) UpdateFormField(pDocument, pFormField, TRUE, TRUE, TRUE);
- }
- else
- {
- if(nControlIndex >= pFormField->CountControls()) return;
- if (CPDF_FormControl* pFormControl = pFormField->GetControl(nControlIndex))
- {
- if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl))
- {
- CPDF_Rect crRect = rect;
-
- CPDF_Page* pPDFPage = pWidget->GetPDFPage();
- ASSERT(pPDFPage != NULL);
-
-// CPDF_Page* pPDFPage = pPage->GetPage();
-// ASSERT(pPDFPage != NULL);
-
- crRect.Intersect(pPDFPage->GetPageBBox());
-
- if (!crRect.IsEmpty())
- {
- CPDF_Rect rcOld = pWidget->GetRect();
- if (crRect.left != rcOld.left ||
- crRect.right != rcOld.right ||
- crRect.top != rcOld.top ||
- crRect.bottom != rcOld.bottom)
- {
- pWidget->SetRect(crRect);
- UpdateFormControl(pDocument, pFormControl, TRUE, TRUE, TRUE);
- }
- }
- }
- }
- }
- }
-}
-
-FX_BOOL Field::required(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
-
- bool bVP;
- vp >> bVP;
-
- }
- else
- {
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON)
- return FALSE;
-
- if (pFormField->GetFieldFlags() & FIELDFLAG_REQUIRED)
- vp << true;
- else
- vp << false;
- }
-
- return TRUE;
-}
-
-FX_BOOL Field::richText(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- bool bVP;
- vp >> bVP;
-
- if (m_bDelay)
- {
- AddDelay_Bool(FP_RICHTEXT, bVP);
- }
- else
- {
- Field::SetRichText(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
- return FALSE;
-
- if (pFormField->GetFieldFlags() & FIELDFLAG_RICHTEXT)
- vp << true;
- else
- vp << false;
- }
-
- return TRUE;
-}
-
-void Field::SetRichText(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b)
-{
- //Not supported.
-}
-
-FX_BOOL Field::richValue(OBJ_PROP_PARAMS)
-{
- return TRUE;
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
- ;
- }
- else
- {
- ;
- }
- return TRUE;
-}
-
-void Field::SetRichValue(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex)
-{
- //Not supported.
-}
-
-FX_BOOL Field::rotation(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- int nVP;
- vp >> nVP;
-
- if (m_bDelay)
- {
- AddDelay_Int(FP_ROTATION, nVP);
- }
- else
- {
- Field::SetRotation(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
- if (!pFormControl)return FALSE;
-
- vp << (FX_INT32)pFormControl->GetRotation();
- }
-
- return TRUE;
-}
-
-void Field::SetRotation(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
-{
- //Not supported.
-}
-
-FX_BOOL Field::strokeColor(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- if (!vp.IsArrayObject())return FALSE;
-
- CJS_Array crArray(m_isolate);
- vp >> crArray;
-
- CPWL_Color color;
- color::ConvertArrayToPWLColor(crArray, color);
-
- if (m_bDelay)
- {
- AddDelay_Color(FP_STROKECOLOR, color);
- }
- else
- {
- Field::SetStrokeColor(m_pDocument, m_FieldName, m_nFormControlIndex, color);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
- if (!pFormControl)return FALSE;
-
- int iColorType;
- pFormControl->GetBorderColor(iColorType);
-
- CPWL_Color color;
-
- if (iColorType == COLORTYPE_TRANSPARENT)
- {
- color = CPWL_Color(COLORTYPE_TRANSPARENT);
- }
- else if (iColorType == COLORTYPE_GRAY)
- {
- color = CPWL_Color(COLORTYPE_GRAY, pFormControl->GetOriginalBorderColor(0));
- }
- else if (iColorType == COLORTYPE_RGB)
- {
- color = CPWL_Color(COLORTYPE_RGB, pFormControl->GetOriginalBorderColor(0),
- pFormControl->GetOriginalBorderColor(1),
- pFormControl->GetOriginalBorderColor(2));
- }
- else if (iColorType == COLORTYPE_CMYK)
- {
- color = CPWL_Color(COLORTYPE_CMYK, pFormControl->GetOriginalBorderColor(0),
- pFormControl->GetOriginalBorderColor(1),
- pFormControl->GetOriginalBorderColor(2),
- pFormControl->GetOriginalBorderColor(3));
- }
- else
- return FALSE;
-
- CJS_Array crArray(m_isolate);
- color::ConvertPWLColorToArray(color, crArray);
- vp << crArray;
- }
-
- return TRUE;
-}
-
-void Field::SetStrokeColor(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CPWL_Color& color)
-{
- //Not supported.
-}
-
-FX_BOOL Field::style(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- CFX_ByteString csBCaption;
- vp >> csBCaption;
-
- if (m_bDelay)
- {
- AddDelay_String(FP_STYLE, csBCaption);
- }
- else
- {
- Field::SetStyle(m_pDocument, m_FieldName, m_nFormControlIndex, csBCaption);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if (pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON &&
- pFormField->GetFieldType() != FIELDTYPE_CHECKBOX)
- return FALSE;
-
- CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
- if (!pFormControl) return FALSE;
-
- CFX_WideString csWCaption = pFormControl->GetNormalCaption();
- CFX_ByteString csBCaption;
-
- switch (csWCaption[0])
- {
- case L'l':
- csBCaption = "circle";
- break;
- case L'8':
- csBCaption = "cross";
- break;
- case L'u':
- csBCaption = "diamond";
- break;
- case L'n':
- csBCaption = "square";
- break;
- case L'H':
- csBCaption = "star";
- break;
- default: //L'4'
- csBCaption = "check";
- break;
- }
- vp << csBCaption;
- }
-
- return TRUE;
-}
-
-void Field::SetStyle(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex,
- const CFX_ByteString& string)
-{
- //Not supported.
-}
-
-FX_BOOL Field::submitName(OBJ_PROP_PARAMS)
-{
- return TRUE;
-}
-
-FX_BOOL Field::textColor(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- CJS_Array crArray(m_isolate);
- if (!vp.IsArrayObject())return FALSE;
- vp >> crArray;
-
- CPWL_Color color;
- color::ConvertArrayToPWLColor(crArray, color);
-
- if (m_bDelay)
- {
- AddDelay_Color(FP_TEXTCOLOR, color);
- }
- else
- {
- Field::SetTextColor(m_pDocument, m_FieldName, m_nFormControlIndex, color);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
- if (!pFormControl)return FALSE;
-
- int iColorType;
- FX_ARGB color;
- CPDF_DefaultAppearance FieldAppearance = pFormControl->GetDefaultAppearance();
- FieldAppearance.GetColor(color, iColorType);
- FX_INT32 a,r,g,b;
- ArgbDecode(color, a, r, g, b);
-
- CPWL_Color crRet = CPWL_Color(COLORTYPE_RGB, r / 255.0f,
- g / 255.0f,
- b / 255.0f);
-
- if (iColorType == COLORTYPE_TRANSPARENT)
- crRet = CPWL_Color(COLORTYPE_TRANSPARENT);
-
- CJS_Array crArray(m_isolate);
- color::ConvertPWLColorToArray(crRet, crArray);
- vp << crArray;
- }
-
- return TRUE;
-}
-
-void Field::SetTextColor(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CPWL_Color& color)
-{
- //Not supported.
-}
-
-FX_BOOL Field::textFont(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- CFX_ByteString csFontName;
- vp >> csFontName;
- if (csFontName.IsEmpty()) return FALSE;
-
- if (m_bDelay)
- {
- AddDelay_String(FP_TEXTFONT, csFontName);
- }
- else
- {
- Field::SetTextFont(m_pDocument, m_FieldName, m_nFormControlIndex, csFontName);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
- if (!pFormControl)return FALSE;
-
- int nFieldType = pFormField->GetFieldType();
-
- if (nFieldType == FIELDTYPE_PUSHBUTTON ||
- nFieldType == FIELDTYPE_COMBOBOX ||
- nFieldType == FIELDTYPE_LISTBOX ||
- nFieldType == FIELDTYPE_TEXTFIELD)
- {
- CPDF_Font * pFont = pFormControl->GetDefaultControlFont();
- if (!pFont) return FALSE;
-
- vp << pFont->GetBaseFont();
- }
- else
- return FALSE;
- }
-
- return TRUE;
-}
-
-void Field::SetTextFont(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CFX_ByteString& string)
-{
- //Not supported.
-}
-
-FX_BOOL Field::textSize(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- int nVP;
- vp >> nVP;
-
- if (m_bDelay)
- {
- AddDelay_Int(FP_TEXTSIZE, nVP);
- }
- else
- {
- Field::SetTextSize(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
- if (!pFormControl)return FALSE;
-
- CPDF_DefaultAppearance FieldAppearance = pFormControl->GetDefaultAppearance();
-
- CFX_ByteString csFontNameTag;
- FX_FLOAT fFontSize;
- FieldAppearance.GetFont(csFontNameTag,fFontSize);
-
- vp << (int)fFontSize;
- }
-
- return TRUE;
-}
-
-void Field::SetTextSize(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
-{
- //Not supported.
-}
-
-FX_BOOL Field::type(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (!vp.IsGetting()) return FALSE;
-
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- switch (pFormField->GetFieldType())
- {
- case FIELDTYPE_UNKNOWN:
- vp << (FX_LPCWSTR)L"unknown";
- break;
- case FIELDTYPE_PUSHBUTTON:
- vp << (FX_LPCWSTR)L"button";
- break;
- case FIELDTYPE_CHECKBOX:
- vp << (FX_LPCWSTR)L"checkbox";
- break;
- case FIELDTYPE_RADIOBUTTON:
- vp << (FX_LPCWSTR)L"radiobutton";
- break;
- case FIELDTYPE_COMBOBOX:
- vp << (FX_LPCWSTR)L"combobox";
- break;
- case FIELDTYPE_LISTBOX:
- vp << (FX_LPCWSTR)L"listbox";
- break;
- case FIELDTYPE_TEXTFIELD:
- vp << (FX_LPCWSTR)L"text";
- break;
- case FIELDTYPE_SIGNATURE:
- vp << (FX_LPCWSTR)L"signature";
- break;
- default :
- vp << (FX_LPCWSTR)L"unknown";
- break;
- }
-
- return TRUE;
-}
-
-FX_BOOL Field::userName(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- CFX_WideString swName;
- vp >> swName;
-
- if (m_bDelay)
- {
- AddDelay_WideString(FP_USERNAME, swName);
- }
- else
- {
- Field::SetUserName(m_pDocument, m_FieldName, m_nFormControlIndex, swName);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- vp << (CFX_WideString)pFormField->GetAlternateName();
- }
-
- return TRUE;
-}
-
-void Field::SetUserName(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CFX_WideString& string)
-{
- //Not supported.
-}
-
-FX_BOOL Field::value(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (vp.IsSetting())
- {
- if (!m_bCanSet) return FALSE;
-
- CJS_WideStringArray strArray;
-
- if (vp.IsArrayObject())
- {
- CJS_Array ValueArray(m_isolate);
- vp.ConvertToArray(ValueArray);
- for (int i = 0,sz = ValueArray.GetLength(); i < sz; i++)
- {
- CJS_Value ElementValue(m_isolate);
- ValueArray.GetElement(i, ElementValue);
- strArray.Add(ElementValue.operator CFX_WideString());
- }
- }
- else
- {
- CFX_WideString swValue;
- vp >> swValue;
-
- strArray.Add(swValue);
- }
-
- if (m_bDelay)
- {
- AddDelay_WideStringArray(FP_VALUE, strArray);
- }
- else
- {
- Field::SetValue(m_pDocument, m_FieldName, m_nFormControlIndex, strArray);
- }
- }
- else
- {
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
-
-
- switch (pFormField->GetFieldType())
- {
- case FIELDTYPE_PUSHBUTTON:
- return FALSE;
- case FIELDTYPE_COMBOBOX:
- case FIELDTYPE_TEXTFIELD:
- {
- CFX_WideString swValue = pFormField->GetValue();
-
- double dRet;
- FX_BOOL bDot;
- if (CJS_PublicMethods::ConvertStringToNumber(swValue,dRet,bDot))
- {
- if (bDot)
- vp << dRet;
- else
- vp << dRet;
- }
- else
- vp << swValue;
- }
- break;
- case FIELDTYPE_LISTBOX:
- {
- if (pFormField->CountSelectedItems() > 1)
- {
- CJS_Array ValueArray(m_isolate);
- CJS_Value ElementValue(m_isolate);
- int iIndex;
- for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++)
- {
- iIndex = pFormField->GetSelectedIndex(i);
- ElementValue = pFormField->GetOptionValue(iIndex);
- if (FXSYS_wcslen((FX_LPCWSTR)ElementValue.operator CFX_WideString()) == 0)
- ElementValue = pFormField->GetOptionLabel(iIndex);
- ValueArray.SetElement(i, ElementValue);
- }
- vp << ValueArray;
- }
- else
- {
- CFX_WideString swValue = pFormField->GetValue();
-
- double dRet;
- FX_BOOL bDot;
- if (CJS_PublicMethods::ConvertStringToNumber(swValue,dRet,bDot))
- {
- if (bDot)
- vp << dRet;
- else
- vp << dRet;
- }
- else
- vp << swValue;
- }
- }
- break;
- case FIELDTYPE_CHECKBOX:
- case FIELDTYPE_RADIOBUTTON:
- {
- FX_BOOL bFind = FALSE;
- for (int i = 0 , sz = pFormField->CountControls(); i < sz; i++)
- {
- if (pFormField->GetControl(i)->IsChecked())
- {
- CFX_WideString swValue = pFormField->GetControl(i)->GetExportValue();
-
- double dRet;
- FX_BOOL bDot;
- if (CJS_PublicMethods::ConvertStringToNumber(swValue,dRet,bDot))
- {
- if (bDot)
- vp << dRet;
- else
- vp << dRet;
- }
- else
- vp << swValue;
-
- bFind = TRUE;
- break;
- }
- else
- continue;
- }
- if (!bFind)
- vp << (FX_LPCWSTR)L"Off";
- }
- break;
- default:
- vp << pFormField->GetValue();
- break;
- }
- }
-
- return TRUE;
-}
-
-void Field::SetValue(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName,
- int nControlIndex, const CJS_WideStringArray& strArray)
-{
- ASSERT(pDocument != NULL);
-
- if (strArray.GetSize() < 1) return;
-
- CFX_PtrArray FieldArray;
- GetFormFields(pDocument, swFieldName, FieldArray);
-
- for (int i=0,isz=FieldArray.GetSize(); i<isz; i++)
- {
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(i);
- ASSERT(pFormField != NULL);
-
- if (pFormField->GetFullName().Compare(swFieldName) != 0)
- continue;
-
- switch (pFormField->GetFieldType())
- {
- case FIELDTYPE_TEXTFIELD:
- case FIELDTYPE_COMBOBOX:
- if (pFormField->GetValue() != strArray.GetAt(0))
- {
- CFX_WideString WideString = strArray.GetAt(0);
- pFormField->SetValue(strArray.GetAt(0), TRUE);
- UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE);
- }
- break;
- case FIELDTYPE_CHECKBOX: //mantis: 0004493
- case FIELDTYPE_RADIOBUTTON:
- {
- if (pFormField->GetValue() != strArray.GetAt(0))
- {
- pFormField->SetValue(strArray.GetAt(0), TRUE);
- UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE);
- }
- }
- break;
- case FIELDTYPE_LISTBOX:
- {
- FX_BOOL bModified = FALSE;
-
- for (int i=0,sz=strArray.GetSize(); i<sz; i++)
- {
- int iIndex = pFormField->FindOption(strArray.GetAt(i));
-
- if (!pFormField->IsItemSelected(iIndex))
- {
- bModified = TRUE;
- break;
- }
- }
-
- if (bModified)
- {
- pFormField->ClearSelection(TRUE);
- for (int i=0,sz=strArray.GetSize(); i<sz; i++)
- {
- int iIndex = pFormField->FindOption(strArray.GetAt(i));
- pFormField->SetItemSelection(iIndex, TRUE, TRUE);
- }
-
- UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE);
- }
- }
- break;
- default:
- break;
- }
- }
-}
-
-FX_BOOL Field::valueAsString(OBJ_PROP_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (!vp.IsGetting()) return FALSE;
-
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON)
- return FALSE;
-
- if (pFormField->GetFieldType() == FIELDTYPE_CHECKBOX)
- {
- if(!pFormField->CountControls()) return FALSE;
-
- if (pFormField->GetControl(0)->IsChecked())
- vp << (FX_LPCWSTR)L"Yes";
- else
- vp << (FX_LPCWSTR)L"Off";
- }
- else if (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON && !(pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON))
- {
- for (int i=0, sz=pFormField->CountControls(); i<sz; i++)
- {
- if (pFormField->GetControl(i)->IsChecked())
- {
- vp << (FX_LPCWSTR)pFormField->GetControl(i)->GetExportValue();
- break;
- }
- else
- vp << (FX_LPCWSTR)L"Off";
- }
- }
- else if (pFormField->GetFieldType() == FIELDTYPE_LISTBOX && (pFormField->CountSelectedItems() > 1))
- {
- vp << (FX_LPCWSTR)L"";
- }
- else
- vp << (FX_LPCWSTR)pFormField->GetValue();
-
- return TRUE;
-}
-
-/* --------------------------------- methods --------------------------------- */
-
-FX_BOOL Field::browseForFileToSubmit(OBJ_METHOD_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName, FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- CPDFDoc_Environment* pApp = m_pDocument->GetEnv();
- ASSERT(pApp != NULL);
-
- if ((pFormField->GetFieldFlags() & FIELDFLAG_FILESELECT) &&
- (pFormField->GetFieldType() == FIELDTYPE_TEXTFIELD))
- {
- CFX_WideString wsFileName = pApp->JS_fieldBrowse();
- if(!wsFileName.IsEmpty())
- {
- pFormField->SetValue(wsFileName);
- UpdateFormField(m_pDocument, pFormField, TRUE, TRUE, TRUE);
- }
- }
- else
- return FALSE;
-
- return TRUE;
-}
-
-
-FX_BOOL Field::buttonGetCaption(OBJ_METHOD_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- int nface = 0;
- int iSize = params.size();
- if ( iSize >= 1)
- nface = (FX_INT32) params[0];
-
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
- return FALSE;
-
- CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
- if (!pFormControl)return FALSE;
-
- if (nface == 0)
- vRet = pFormControl->GetNormalCaption();
- else if (nface == 1)
- vRet = pFormControl->GetDownCaption();
- else if (nface == 2)
- vRet = pFormControl->GetRolloverCaption();
- else
- return FALSE;
-
- return TRUE;
-}
-
-//#pragma warning(disable: 4800)
-
-FX_BOOL Field::buttonGetIcon(OBJ_METHOD_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- int nface = 0;
- int iSize = params.size();
- if ( iSize >= 1)
- nface = (FX_INT32) params[0];
-
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
- return FALSE;
-
- CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
- if (!pFormControl)return FALSE;
-
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
-
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
-
- JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"Icon"));
- ASSERT(pObj.IsEmpty() == FALSE);
-
- CJS_Icon* pJS_Icon = (CJS_Icon*)JS_GetPrivate(pObj);
- ASSERT(pJS_Icon != NULL);
-
- Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject();
- ASSERT(pIcon != NULL);
-
- CPDF_Stream* pIconStream = NULL;
- if (nface == 0)
- pIconStream = pFormControl->GetNormalIcon();
- else if (nface == 1)
- pIconStream = pFormControl->GetDownIcon();
- else if (nface == 2)
- pIconStream = pFormControl->GetRolloverIcon();
- else
- return FALSE;
-
- pIcon->SetStream(pIconStream);
- vRet = pJS_Icon;
-
- return TRUE;
-}
-
-//#pragma warning(default: 4800)
-
-FX_BOOL Field::buttonImportIcon(OBJ_METHOD_PARAMS)
-{
-#if 0
- ASSERT(m_pDocument != NULL);
-
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- if (!pFormField)return FALSE;
-
- CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
- ASSERT(pEnv);
-
- CFX_WideString sIconFileName = pEnv->JS_fieldBrowse();
- if (sIconFileName.IsEmpty())
- {
- vRet = 1;
- return TRUE;
- }
-
- CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- CPDF_Stream* pStream = pInterForm->LoadImageFromFile(sIconFileName);
- if (!pStream)
- {
- vRet = -1;
- return TRUE;
- }
-
- CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
- if (!pFormControl)return FALSE;
-
- pFormControl->SetNormalIcon(pStream);
- UpdateFormControl(m_pDocument, pFormControl, TRUE, TRUE, TRUE);
-
- vRet = 0;
-#endif // 0
- return TRUE;
-}
-
-FX_BOOL Field::buttonSetCaption(OBJ_METHOD_PARAMS)
-{
- return FALSE;
-}
-
-FX_BOOL Field::buttonSetIcon(OBJ_METHOD_PARAMS)
-{
- return FALSE;
-}
-
-FX_BOOL Field::checkThisBox(OBJ_METHOD_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (!m_bCanSet) return FALSE;
-
- int iSize = params.size();
- int nWidget = -1;
- if ( iSize >= 1)
- nWidget= (FX_INT32) params[0];
- else
- return FALSE;
- FX_BOOL bCheckit = TRUE;
- if ( iSize >= 2)
- bCheckit = params[1];
-
-
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if (pFormField->GetFieldType() != FIELDTYPE_CHECKBOX && pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON)
- return FALSE;
- if(nWidget <0 || nWidget >= pFormField->CountControls())
- return FALSE;
- if (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON)
- pFormField->CheckControl(nWidget, bCheckit, TRUE);
- else
- pFormField->CheckControl(nWidget, bCheckit, TRUE);
-
- UpdateFormField(m_pDocument, pFormField, TRUE, TRUE, TRUE);
-
- return TRUE;
-}
-
-FX_BOOL Field::clearItems(OBJ_METHOD_PARAMS)
-{
- return TRUE;
-}
-
-FX_BOOL Field::defaultIsChecked(OBJ_METHOD_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- if (!m_bCanSet) return FALSE;
-
- int iSize = params.size();
- int nWidget = -1;
- if ( iSize >= 1)
- nWidget= (FX_INT32) params[0];
- else
- return FALSE;
- //FX_BOOL bIsDefaultChecked = TRUE;
- //if ( iSize >= 2)
- // bIsDefaultChecked = params[1];
-
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if(nWidget <0 || nWidget >= pFormField->CountControls())
- {
- vRet = FALSE;
- return FALSE;
- }
- if ((pFormField->GetFieldType() == FIELDTYPE_CHECKBOX)
- || (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON))
- {
-
- vRet = TRUE;
- }
- else
- vRet = FALSE;
-
- return TRUE;
-}
-
-FX_BOOL Field::deleteItemAt(OBJ_METHOD_PARAMS)
-{
- return TRUE;
-}
-
-int JS_COMPARESTRING(CFX_WideString* ps1, CFX_WideString* ps2)
-{
- ASSERT(ps1 != NULL);
- ASSERT(ps2 != NULL);
-
- return ps1->Compare(*ps2);
-}
-
-
-FX_BOOL Field::getArray(OBJ_METHOD_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CGW_ArrayTemplate<CFX_WideString*> swSort;
-
- for (int i=0,sz=FieldArray.GetSize(); i<sz; i++)
- {
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(i);
- ASSERT(pFormField != NULL);
-
- swSort.Add(new CFX_WideString(pFormField->GetFullName()));
-
- }
- swSort.Sort(JS_COMPARESTRING);
-
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
-
- CJS_Array FormFieldArray(m_isolate);
- for (int j=0,jsz = swSort.GetSize(); j<jsz; j++)
- {
- CFX_WideString* pStr = swSort.GetAt(j);
-
- JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"Field"));
- ASSERT(pObj.IsEmpty() == FALSE);
-
- CJS_Field* pJSField = (CJS_Field*)JS_GetPrivate(pObj);
- ASSERT(pJSField != NULL);
-
- Field* pField = (Field*)pJSField->GetEmbedObject();
- ASSERT(pField != NULL);
-
- pField->AttachField(this->m_pJSDoc, *pStr);
-
- CJS_Value FormFieldValue(m_isolate);
- FormFieldValue = pJSField;
- FormFieldArray.SetElement(j, FormFieldValue);
-
- delete pStr;
- }
-
- vRet = FormFieldArray;
- swSort.RemoveAll();
- return TRUE;
-}
-
-FX_BOOL Field::getItemAt(OBJ_METHOD_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- int nIdx = -1;
- if (params.size() >=1)
- nIdx = (FX_INT32) params[0];
- FX_BOOL bExport = TRUE;
- int iSize = params.size();
- if ( iSize >= 2)
- {
- bExport =(FX_BOOL) params[1];
- }
-
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if ((pFormField->GetFieldType() == FIELDTYPE_LISTBOX)
- || (pFormField->GetFieldType() == FIELDTYPE_COMBOBOX))
- {
- if (nIdx == -1 || nIdx > pFormField->CountOptions())
- nIdx = pFormField->CountOptions() -1;
- if (bExport)
- {
- CFX_WideString strval = pFormField->GetOptionValue(nIdx);
- if (strval.IsEmpty())
- vRet = pFormField->GetOptionLabel(nIdx);
- else
- vRet = strval;
- }
- else
- vRet = pFormField->GetOptionLabel(nIdx);
- }
- else
- return FALSE;
-
- return TRUE;
-}
-
-FX_BOOL Field::getLock(OBJ_METHOD_PARAMS)
-{
- return FALSE;
-}
-
-FX_BOOL Field::insertItemAt(OBJ_METHOD_PARAMS)
-{
- return TRUE;
-}
-
-FX_BOOL Field::isBoxChecked(OBJ_METHOD_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- int nIndex = -1;
- if (params.size() >=1)
- nIndex = (FX_INT32) params[0];
-
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if(nIndex <0 || nIndex >= pFormField->CountControls())
- {
- vRet = FALSE;
- return FALSE;
- }
-
- if ((pFormField->GetFieldType() == FIELDTYPE_CHECKBOX)
- || (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON))
- {
- if (pFormField->GetControl(nIndex)->IsChecked() !=0 )
- vRet = TRUE;
- else
- vRet = FALSE;
- }
- else
- vRet = FALSE;
-
- return TRUE;
-}
-
-FX_BOOL Field::isDefaultChecked(OBJ_METHOD_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- int nIndex = -1;
- if (params.size() >=1)
- nIndex = (FX_INT32) params[0];
-
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- if(nIndex <0 || nIndex >= pFormField->CountControls())
- {
- vRet = FALSE;
- return FALSE;
- }
- if ((pFormField->GetFieldType() == FIELDTYPE_CHECKBOX)
- || (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON))
- {
- if (pFormField->GetControl(nIndex)->IsDefaultChecked() != 0)
- vRet = TRUE;
- else
- vRet = FALSE;
- }
- else
- vRet = FALSE;
-
- return TRUE;
-}
-
-FX_BOOL Field::setAction(OBJ_METHOD_PARAMS)
-{
- return TRUE;
-}
-
-FX_BOOL Field::setFocus(OBJ_METHOD_PARAMS)
-{
- ASSERT(m_pDocument != NULL);
-
- CFX_PtrArray FieldArray;
- GetFormFields(m_FieldName,FieldArray);
- if (FieldArray.GetSize() <= 0) return FALSE;
-
- CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
- ASSERT(pFormField != NULL);
-
- FX_INT32 nCount = pFormField->CountControls();
-
- if (nCount < 1) return FALSE;
-
- CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- CPDFSDK_Widget* pWidget = NULL;
- if (nCount == 1)
- {
- pWidget = pInterForm->GetWidget(pFormField->GetControl(0));
- }
- else
- {
- CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
- ASSERT(pEnv);
- CPDF_Page* pPage = (CPDF_Page*)pEnv->FFI_GetCurrentPage(m_pDocument->GetDocument());
- if(!pPage)
- return FALSE;
- if (CPDFSDK_PageView* pCurPageView = m_pDocument->GetPageView(pPage))
- {
- for (FX_INT32 i=0; i<nCount; i++)
- {
- if (CPDFSDK_Widget* pTempWidget = pInterForm->GetWidget(pFormField->GetControl(i)))
- {
- if (pTempWidget->GetPDFPage() == pCurPageView->GetPDFPage())
- {
- pWidget = pTempWidget;
- break;
- }
- }
- }
- }
- }
-
- if (pWidget)
- {
- m_pDocument->SetFocusAnnot(pWidget);
- }
-
- return TRUE;
-}
-
-FX_BOOL Field::setItems(OBJ_METHOD_PARAMS)
-{
- return TRUE;
-}
-
-FX_BOOL Field::setLock(OBJ_METHOD_PARAMS)
-{
- return FALSE;
-}
-
-FX_BOOL Field::signatureGetModifications(OBJ_METHOD_PARAMS)
-{
- return FALSE;
-}
-
-FX_BOOL Field::signatureGetSeedValue(OBJ_METHOD_PARAMS)
-{
- return FALSE;
-}
-
-FX_BOOL Field::signatureInfo(OBJ_METHOD_PARAMS)
-{
- return FALSE;
-}
-
-FX_BOOL Field::signatureSetSeedValue(OBJ_METHOD_PARAMS)
-{
- return FALSE;
-}
-
-FX_BOOL Field::signatureSign(OBJ_METHOD_PARAMS)
-{
- return FALSE;
-}
-
-FX_BOOL Field::signatureValidate(OBJ_METHOD_PARAMS)
-{
- return FALSE;
-}
-
-FX_BOOL Field::source(OBJ_PROP_PARAMS)
-{
- if (vp.IsGetting())
- {
- vp << (CJS_Object*)NULL;
- }
-
- return TRUE;
-}
-
-/////////////////////////////////////////// delay /////////////////////////////////////////////
-
-void Field::AddDelay_Int(enum FIELD_PROP prop, FX_INT32 n)
-{
- ASSERT(m_pJSDoc != NULL);
-
- CJS_DelayData* pNewData = new CJS_DelayData;
- pNewData->sFieldName = m_FieldName;
- pNewData->nControlIndex = m_nFormControlIndex;
- pNewData->eProp = prop;
- pNewData->num = n;
-
- m_pJSDoc->AddDelayData(pNewData);
-}
-
-void Field::AddDelay_Bool(enum FIELD_PROP prop,bool b)
-{
- ASSERT(m_pJSDoc != NULL);
-
- CJS_DelayData* pNewData = new CJS_DelayData;
- pNewData->sFieldName = m_FieldName;
- pNewData->nControlIndex = m_nFormControlIndex;
- pNewData->eProp = prop;
- pNewData->b = b;
-
- m_pJSDoc->AddDelayData(pNewData);
-}
-
-void Field::AddDelay_String(enum FIELD_PROP prop, const CFX_ByteString& string)
-{
- ASSERT(m_pJSDoc != NULL);
-
- CJS_DelayData* pNewData = new CJS_DelayData;
- pNewData->sFieldName = m_FieldName;
- pNewData->nControlIndex = m_nFormControlIndex;
- pNewData->eProp = prop;
- pNewData->string = string;
-
- m_pJSDoc->AddDelayData(pNewData);
-}
-
-void Field::AddDelay_WideString(enum FIELD_PROP prop, const CFX_WideString& string)
-{
- ASSERT(m_pJSDoc != NULL);
-
- CJS_DelayData* pNewData = new CJS_DelayData;
- pNewData->sFieldName = m_FieldName;
- pNewData->nControlIndex = m_nFormControlIndex;
- pNewData->eProp = prop;
- pNewData->widestring = string;
-
- m_pJSDoc->AddDelayData(pNewData);
-}
-
-void Field::AddDelay_Rect(enum FIELD_PROP prop, const CPDF_Rect& rect)
-{
- ASSERT(m_pJSDoc != NULL);
-
- CJS_DelayData* pNewData = new CJS_DelayData;
- pNewData->sFieldName = m_FieldName;
- pNewData->nControlIndex = m_nFormControlIndex;
- pNewData->eProp = prop;
- pNewData->rect = rect;
-
- m_pJSDoc->AddDelayData(pNewData);
-}
-
-void Field::AddDelay_Color(enum FIELD_PROP prop, const CPWL_Color& color)
-{
- ASSERT(m_pJSDoc != NULL);
-
- CJS_DelayData* pNewData = new CJS_DelayData;
- pNewData->sFieldName = m_FieldName;
- pNewData->nControlIndex = m_nFormControlIndex;
- pNewData->eProp = prop;
- pNewData->color = color;
-
- m_pJSDoc->AddDelayData(pNewData);
-}
-
-void Field::AddDelay_WordArray(enum FIELD_PROP prop, const CFX_DWordArray& array)
-{
- ASSERT(m_pJSDoc != NULL);
-
- CJS_DelayData* pNewData = new CJS_DelayData;
- pNewData->sFieldName = m_FieldName;
- pNewData->nControlIndex = m_nFormControlIndex;
- pNewData->eProp = prop;
-
- for (int i=0,sz=array.GetSize(); i<sz; i++)
- pNewData->wordarray.Add(array.GetAt(i));
-
- m_pJSDoc->AddDelayData(pNewData);
-}
-
-void Field::AddDelay_WideStringArray(enum FIELD_PROP prop, const CJS_WideStringArray& array)
-{
- ASSERT(m_pJSDoc != NULL);
-
- CJS_DelayData* pNewData = new CJS_DelayData;
- pNewData->sFieldName = m_FieldName;
- pNewData->nControlIndex = m_nFormControlIndex;
- pNewData->eProp = prop;
- for (int i=0,sz=array.GetSize(); i<sz; i++)
- pNewData->widestringarray.Add(array.GetAt(i));
-
- m_pJSDoc->AddDelayData(pNewData);
-}
-
-void Field::DoDelay(CPDFSDK_Document* pDocument, CJS_DelayData* pData)
-{
- ASSERT(pDocument != NULL);
- ASSERT(pData != NULL);
-
- switch (pData->eProp)
- {
- case FP_ALIGNMENT:
- Field::SetAlignment(pDocument, pData->sFieldName, pData->nControlIndex, pData->string);
- break;
- case FP_BORDERSTYLE:
- Field::SetBorderStyle(pDocument, pData->sFieldName, pData->nControlIndex, pData->string);
- break;
- case FP_BUTTONALIGNX:
- Field::SetButtonAlignX(pDocument, pData->sFieldName, pData->nControlIndex, pData->num);
- break;
- case FP_BUTTONALIGNY:
- Field::SetButtonAlignY(pDocument, pData->sFieldName, pData->nControlIndex, pData->num);
- break;
- case FP_BUTTONFITBOUNDS:
- Field::SetButtonFitBounds(pDocument, pData->sFieldName, pData->nControlIndex, pData->b);
- break;
- case FP_BUTTONPOSITION:
- Field::SetButtonPosition(pDocument, pData->sFieldName, pData->nControlIndex, pData->num);
- break;
- case FP_BUTTONSCALEHOW:
- Field::SetButtonScaleHow(pDocument, pData->sFieldName, pData->nControlIndex, pData->num);
- break;
- case FP_BUTTONSCALEWHEN:
- Field::SetButtonScaleWhen(pDocument, pData->sFieldName, pData->nControlIndex, pData->num);
- break;
- case FP_CALCORDERINDEX:
- Field::SetCalcOrderIndex(pDocument, pData->sFieldName, pData->nControlIndex, pData->num);
- break;
- case FP_CHARLIMIT:
- Field::SetCharLimit(pDocument, pData->sFieldName, pData->nControlIndex, pData->num);
- break;
- case FP_COMB:
- Field::SetComb(pDocument, pData->sFieldName, pData->nControlIndex, pData->b);
- break;
- case FP_COMMITONSELCHANGE:
- Field::SetCommitOnSelChange(pDocument, pData->sFieldName, pData->nControlIndex, pData->b);
- break;
- case FP_CURRENTVALUEINDICES:
- Field::SetCurrentValueIndices(pDocument, pData->sFieldName, pData->nControlIndex, pData->wordarray);
- break;
- case FP_DEFAULTVALUE:
- Field::SetDefaultValue(pDocument, pData->sFieldName, pData->nControlIndex, pData->widestring);
- break;
- case FP_DONOTSCROLL:
- Field::SetDoNotScroll(pDocument, pData->sFieldName, pData->nControlIndex, pData->b);
- break;
- case FP_DISPLAY:
- Field::SetDisplay(pDocument, pData->sFieldName, pData->nControlIndex, pData->num);
- break;
- case FP_FILLCOLOR:
- Field::SetFillColor(pDocument, pData->sFieldName, pData->nControlIndex, pData->color);
- break;
- case FP_HIDDEN:
- Field::SetHidden(pDocument, pData->sFieldName, pData->nControlIndex, pData->b);
- break;
- case FP_HIGHLIGHT:
- Field::SetHighlight(pDocument, pData->sFieldName, pData->nControlIndex, pData->string);
- break;
- case FP_LINEWIDTH:
- Field::SetLineWidth(pDocument, pData->sFieldName, pData->nControlIndex, pData->num);
- break;
- case FP_MULTILINE:
- Field::SetMultiline(pDocument, pData->sFieldName, pData->nControlIndex, pData->b);
- break;
- case FP_MULTIPLESELECTION:
- Field::SetMultipleSelection(pDocument, pData->sFieldName, pData->nControlIndex, pData->b);
- break;
- case FP_PASSWORD:
- Field::SetPassword(pDocument, pData->sFieldName, pData->nControlIndex, pData->b);
- break;
- case FP_RECT:
- Field::SetRect(pDocument, pData->sFieldName, pData->nControlIndex, pData->rect);
- break;
- case FP_RICHTEXT:
- Field::SetRichText(pDocument, pData->sFieldName, pData->nControlIndex, pData->b);
- break;
- case FP_RICHVALUE:
- break;
- case FP_ROTATION:
- Field::SetRotation(pDocument, pData->sFieldName, pData->nControlIndex, pData->num);
- break;
- case FP_STROKECOLOR:
- Field::SetStrokeColor(pDocument, pData->sFieldName, pData->nControlIndex, pData->color);
- break;
- case FP_STYLE:
- Field::SetStyle(pDocument, pData->sFieldName, pData->nControlIndex, pData->string);
- break;
- case FP_TEXTCOLOR:
- Field::SetTextColor(pDocument, pData->sFieldName, pData->nControlIndex, pData->color);
- break;
- case FP_TEXTFONT:
- Field::SetTextFont(pDocument, pData->sFieldName, pData->nControlIndex, pData->string);
- break;
- case FP_TEXTSIZE:
- Field::SetTextSize(pDocument, pData->sFieldName, pData->nControlIndex, pData->num);
- break;
- case FP_USERNAME:
- Field::SetUserName(pDocument, pData->sFieldName, pData->nControlIndex, pData->widestring);
- break;
- case FP_VALUE:
- Field::SetValue(pDocument, pData->sFieldName, pData->nControlIndex, pData->widestringarray);
- break;
- }
-}
-
-#define JS_FIELD_MINWIDTH 1
-#define JS_FIELD_MINHEIGHT 1
-
-void Field::AddField(CPDFSDK_Document* pDocument, int nPageIndex, int nFieldType,
- const CFX_WideString& sName, const CPDF_Rect& rcCoords)
-{
- //Not supported.
-}
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/javascript/JavaScript.h"
+#include "../../include/javascript/IJavaScript.h"
+#include "../../include/javascript/JS_Define.h"
+#include "../../include/javascript/JS_Object.h"
+#include "../../include/javascript/JS_Value.h"
+#include "../../include/javascript/Field.h"
+#include "../../include/javascript/JS_EventHandler.h"
+//#include "../include/JS_ResMgr.h"
+#include "../../include/javascript/JS_Context.h"
+#include "../../include/javascript/JS_Runtime.h"
+#include "../../include/javascript/Document.h"
+#include "../../include/javascript/color.h"
+#include "../../include/javascript/PublicMethods.h"
+#include "../../include/javascript/Icon.h"
+
+
+/* ---------------------- Field ---------------------- */
+
+BEGIN_JS_STATIC_CONST(CJS_Field)
+END_JS_STATIC_CONST()
+
+BEGIN_JS_STATIC_PROP(CJS_Field)
+ JS_STATIC_PROP_ENTRY(alignment)
+ JS_STATIC_PROP_ENTRY(borderStyle)
+ JS_STATIC_PROP_ENTRY(buttonAlignX)
+ JS_STATIC_PROP_ENTRY(buttonAlignY)
+ JS_STATIC_PROP_ENTRY(buttonFitBounds)
+ JS_STATIC_PROP_ENTRY(buttonPosition)
+ JS_STATIC_PROP_ENTRY(buttonScaleHow)
+ JS_STATIC_PROP_ENTRY(buttonScaleWhen)
+ JS_STATIC_PROP_ENTRY(calcOrderIndex)
+ JS_STATIC_PROP_ENTRY(charLimit)
+ JS_STATIC_PROP_ENTRY(comb)
+ JS_STATIC_PROP_ENTRY(commitOnSelChange)
+ JS_STATIC_PROP_ENTRY(currentValueIndices)
+ JS_STATIC_PROP_ENTRY(defaultStyle)
+ JS_STATIC_PROP_ENTRY(defaultValue)
+ JS_STATIC_PROP_ENTRY(doNotScroll)
+ JS_STATIC_PROP_ENTRY(doNotSpellCheck)
+ JS_STATIC_PROP_ENTRY(delay)
+ JS_STATIC_PROP_ENTRY(display)
+ JS_STATIC_PROP_ENTRY(doc)
+ JS_STATIC_PROP_ENTRY(editable)
+ JS_STATIC_PROP_ENTRY(exportValues)
+ JS_STATIC_PROP_ENTRY(hidden)
+ JS_STATIC_PROP_ENTRY(fileSelect)
+ JS_STATIC_PROP_ENTRY(fillColor)
+ JS_STATIC_PROP_ENTRY(lineWidth)
+ JS_STATIC_PROP_ENTRY(highlight)
+ JS_STATIC_PROP_ENTRY(multiline)
+ JS_STATIC_PROP_ENTRY(multipleSelection)
+ JS_STATIC_PROP_ENTRY(name)
+ JS_STATIC_PROP_ENTRY(numItems)
+ JS_STATIC_PROP_ENTRY(page)
+ JS_STATIC_PROP_ENTRY(password)
+ JS_STATIC_PROP_ENTRY(print)
+ JS_STATIC_PROP_ENTRY(radiosInUnison)
+ JS_STATIC_PROP_ENTRY(readonly)
+ JS_STATIC_PROP_ENTRY(rect)
+ JS_STATIC_PROP_ENTRY(required)
+ JS_STATIC_PROP_ENTRY(richText)
+ JS_STATIC_PROP_ENTRY(richValue)
+ JS_STATIC_PROP_ENTRY(rotation)
+ JS_STATIC_PROP_ENTRY(strokeColor)
+ JS_STATIC_PROP_ENTRY(style)
+ JS_STATIC_PROP_ENTRY(submitName)
+ JS_STATIC_PROP_ENTRY(textColor)
+ JS_STATIC_PROP_ENTRY(textFont)
+ JS_STATIC_PROP_ENTRY(textSize)
+ JS_STATIC_PROP_ENTRY(type)
+ JS_STATIC_PROP_ENTRY(userName)
+ JS_STATIC_PROP_ENTRY(value)
+ JS_STATIC_PROP_ENTRY(valueAsString)
+ JS_STATIC_PROP_ENTRY(source)
+END_JS_STATIC_PROP()
+
+BEGIN_JS_STATIC_METHOD(CJS_Field)
+ JS_STATIC_METHOD_ENTRY(browseForFileToSubmit, 0)
+ JS_STATIC_METHOD_ENTRY(buttonGetCaption, 1)
+ JS_STATIC_METHOD_ENTRY(buttonGetIcon, 1)
+ JS_STATIC_METHOD_ENTRY(buttonImportIcon, 0)
+ JS_STATIC_METHOD_ENTRY(buttonSetCaption, 2)
+ JS_STATIC_METHOD_ENTRY(buttonSetIcon, 2)
+ JS_STATIC_METHOD_ENTRY(checkThisBox, 2)
+ JS_STATIC_METHOD_ENTRY(clearItems, 0)
+ JS_STATIC_METHOD_ENTRY(defaultIsChecked, 2)
+ JS_STATIC_METHOD_ENTRY(deleteItemAt, 1)
+ JS_STATIC_METHOD_ENTRY(getArray , 0)
+ JS_STATIC_METHOD_ENTRY(getItemAt, 0)
+ JS_STATIC_METHOD_ENTRY(getLock, 0)
+ JS_STATIC_METHOD_ENTRY(insertItemAt, 0)
+ JS_STATIC_METHOD_ENTRY(isBoxChecked, 1)
+ JS_STATIC_METHOD_ENTRY(isDefaultChecked, 1)
+ JS_STATIC_METHOD_ENTRY(setAction, 2)
+ JS_STATIC_METHOD_ENTRY(setFocus, 0)
+ JS_STATIC_METHOD_ENTRY(setItems, 1)
+ JS_STATIC_METHOD_ENTRY(setLock, 0)
+ JS_STATIC_METHOD_ENTRY(signatureGetModifications, 0)
+ JS_STATIC_METHOD_ENTRY(signatureGetSeedValue, 0)
+ JS_STATIC_METHOD_ENTRY(signatureInfo, 0)
+ JS_STATIC_METHOD_ENTRY(signatureSetSeedValue, 0)
+ JS_STATIC_METHOD_ENTRY(signatureSign, 0)
+ JS_STATIC_METHOD_ENTRY(signatureValidate, 0)
+END_JS_STATIC_METHOD()
+
+IMPLEMENT_JS_CLASS(CJS_Field, Field)
+
+FX_BOOL CJS_Field::InitInstance(IFXJS_Context* cc)
+{
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+
+ Field* pField = (Field*)GetEmbedObject();
+ ASSERT(pField != NULL);
+
+ pField->SetIsolate(pContext->GetJSRuntime()->GetIsolate());
+
+ return TRUE;
+};
+
+Field::Field(CJS_Object* pJSObject): CJS_EmbedObj(pJSObject),
+ m_pJSDoc(NULL),
+ m_pDocument(NULL),
+ m_nFormControlIndex(-1),
+ m_bCanSet(FALSE),
+ m_bDelay(FALSE),
+ m_isolate(NULL)
+{
+}
+
+Field::~Field()
+{
+}
+
+//note: iControlNo = -1, means not a widget.
+void Field::ParseFieldName(const std::wstring &strFieldNameParsed,std::wstring &strFieldName,int & iControlNo)
+{
+ int iStart = strFieldNameParsed.find_last_of(L'.');
+ if (iStart == -1)
+ {
+ strFieldName = strFieldNameParsed;
+ iControlNo = -1;
+ return;
+ }
+ std::wstring suffixal = strFieldNameParsed.substr(iStart+1);
+ iControlNo = FXSYS_wtoi((FX_LPCWSTR)suffixal.c_str());
+ if (iControlNo == 0)
+ {
+ int iStart;
+ while((iStart = suffixal.find_last_of(L" ")) != -1)
+ {
+ suffixal.erase(iStart,1);
+ }
+
+ if (suffixal.compare(L"0") != 0)
+ {
+ strFieldName = strFieldNameParsed;
+ iControlNo = -1;
+ return;
+ }
+
+ }
+ strFieldName = strFieldNameParsed.substr(0,iStart);
+}
+
+FX_BOOL Field::AttachField(Document* pDocument, const CFX_WideString& csFieldName)
+{
+ ASSERT(pDocument != NULL);
+ m_pJSDoc = pDocument;
+
+ m_pDocument = pDocument->GetReaderDoc();
+ ASSERT(m_pDocument != NULL);
+
+ m_bCanSet = m_pDocument->GetPermissions(FPDFPERM_FILL_FORM) ||
+ m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) ||
+ m_pDocument->GetPermissions(FPDFPERM_MODIFY);
+
+ CPDFSDK_InterForm* pRDInterForm = m_pDocument->GetInterForm();
+ ASSERT(pRDInterForm != NULL);
+
+ CPDF_InterForm* pInterForm = pRDInterForm->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ CFX_WideString swFieldNameTemp = csFieldName;
+ swFieldNameTemp.Replace((FX_LPCWSTR)L"..", (FX_LPCWSTR)L".");
+
+ if (pInterForm->CountFields(swFieldNameTemp) <= 0)
+ {
+ std::wstring strFieldName;
+ int iControlNo = -1;
+ ParseFieldName((wchar_t*)(FX_LPCWSTR)swFieldNameTemp, strFieldName, iControlNo);
+ if (iControlNo == -1) return FALSE;
+
+ m_FieldName = strFieldName.c_str();
+ m_nFormControlIndex = iControlNo;
+ return TRUE;
+ }
+
+ m_FieldName = swFieldNameTemp;
+ m_nFormControlIndex = -1;
+
+ return TRUE;
+}
+
+void Field::GetFormFields(CPDFSDK_Document* pDocument, const CFX_WideString& csFieldName, CFX_PtrArray& FieldArray)
+{
+ ASSERT(pDocument != NULL);
+
+ CPDFSDK_InterForm* pReaderInterForm = pDocument->GetInterForm();
+ ASSERT(pReaderInterForm != NULL);
+
+ CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ ASSERT(FieldArray.GetSize() == 0);
+
+ for (int i=0,sz=pInterForm->CountFields(csFieldName); i<sz; i++)
+ {
+ if (CPDF_FormField* pFormField = pInterForm->GetField(i, csFieldName))
+ FieldArray.Add((void*)pFormField);
+ }
+}
+
+void Field::GetFormFields(const CFX_WideString& csFieldName, CFX_PtrArray& FieldArray)
+{
+ ASSERT(m_pDocument != NULL);
+
+ Field::GetFormFields(m_pDocument, csFieldName, FieldArray);
+}
+
+void Field::UpdateFormField(CPDFSDK_Document* pDocument, CPDF_FormField* pFormField,
+ FX_BOOL bChangeMark, FX_BOOL bResetAP, FX_BOOL bRefresh)
+{
+ ASSERT(pDocument != NULL);
+ ASSERT(pFormField != NULL);
+
+ CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ CFX_PtrArray widgets;
+ pInterForm->GetWidgets(pFormField, widgets);
+
+ if (bResetAP)
+ {
+ int nFieldType = pFormField->GetFieldType();
+ if (nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_TEXTFIELD)
+ {
+ for (int i=0,sz=widgets.GetSize(); i<sz; i++)
+ {
+ CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)widgets.GetAt(i);
+ ASSERT(pWidget != NULL);
+
+ FX_BOOL bFormated = FALSE;
+ CFX_WideString sValue = pWidget->OnFormat(0, bFormated);
+ if (bFormated)
+ pWidget->ResetAppearance(sValue, FALSE);
+ else
+ pWidget->ResetAppearance(NULL, FALSE);
+ }
+ }
+ else
+ {
+ for (int i=0,sz=widgets.GetSize(); i<sz; i++)
+ {
+ CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)widgets.GetAt(i);
+ ASSERT(pWidget != NULL);
+
+ pWidget->ResetAppearance(NULL, FALSE);
+ }
+ }
+ }
+
+ if (bRefresh)
+ {
+ for (int i=0,sz=widgets.GetSize(); i<sz; i++)
+ {
+ CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)widgets.GetAt(i);
+ ASSERT(pWidget != NULL);
+
+ CPDFSDK_InterForm * pInterForm = pWidget->GetInterForm();
+ CPDFSDK_Document* pDoc = pInterForm->GetDocument();
+// CReader_Page* pPage = pWidget->GetPage();
+ ASSERT(pDoc != NULL);
+ pDoc->UpdateAllViews(NULL, pWidget);
+ }
+ }
+
+ if (bChangeMark)
+ pDocument->SetChangeMark();
+}
+
+void Field::UpdateFormControl(CPDFSDK_Document* pDocument, CPDF_FormControl* pFormControl,
+ FX_BOOL bChangeMark, FX_BOOL bResetAP, FX_BOOL bRefresh)
+{
+ ASSERT(pDocument != NULL);
+ ASSERT(pFormControl != NULL);
+
+ CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl);
+
+ if (pWidget)
+ {
+ if (bResetAP)
+ {
+ int nFieldType = pWidget->GetFieldType();
+ if (nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_TEXTFIELD)
+ {
+ FX_BOOL bFormated = FALSE;
+ CFX_WideString sValue = pWidget->OnFormat(0, bFormated);
+ if (bFormated)
+ pWidget->ResetAppearance(sValue, FALSE);
+ else
+ pWidget->ResetAppearance(NULL, FALSE);
+ }
+ else
+ {
+ pWidget->ResetAppearance(NULL, FALSE);
+ }
+ }
+
+ if (bRefresh)
+ {
+ CPDFSDK_InterForm * pInterForm = pWidget->GetInterForm();
+ CPDFSDK_Document* pDoc = pInterForm->GetDocument();
+ ASSERT(pDoc != NULL);
+ pDoc->UpdateAllViews(NULL, pWidget);
+ }
+
+ }
+
+ if (bChangeMark)
+ pDocument->SetChangeMark();
+}
+
+CPDFSDK_Widget* Field::GetWidget(CPDFSDK_Document* pDocument, CPDF_FormControl* pFormControl)
+{
+ ASSERT(pDocument != NULL);
+ ASSERT(pFormControl != NULL);
+
+ CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ return pInterForm->GetWidget(pFormControl);
+}
+
+FX_BOOL Field::ValueIsOccur(CPDF_FormField* pFormField, CFX_WideString csOptLabel)
+{
+ ASSERT(pFormField != NULL);
+
+ for (int i=0,sz = pFormField->CountOptions(); i < sz; i++)
+ {
+ if (csOptLabel.Compare(pFormField->GetOptionLabel(i)) == 0)
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+CPDF_FormControl* Field::GetSmartFieldControl(CPDF_FormField* pFormField)
+{
+ ASSERT(pFormField != NULL);
+ if(!pFormField->CountControls() || m_nFormControlIndex>=pFormField->CountControls()) return NULL;
+
+ if (m_nFormControlIndex<0)
+ return pFormField->GetControl(0);
+ else
+ return pFormField->GetControl(m_nFormControlIndex);
+}
+
+/* ---------------------------------------- property ---------------------------------------- */
+
+FX_BOOL Field::alignment(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ CFX_ByteString alignStr;
+ vp >> alignStr;
+
+ if (m_bDelay)
+ {
+ AddDelay_String(FP_ALIGNMENT, alignStr);
+ }
+ else
+ {
+ Field::SetAlignment(m_pDocument, m_FieldName, m_nFormControlIndex, alignStr);
+ }
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName, FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
+ return FALSE;
+
+ CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
+ if (!pFormControl)return FALSE;
+
+ switch (pFormControl->GetControlAlignment())
+ {
+ case 1:
+ vp << (FX_LPCWSTR)L"center";
+ break;
+ case 0:
+ vp << (FX_LPCWSTR)L"left";
+ break;
+ case 2:
+ vp << (FX_LPCWSTR)L"right";
+ break;
+ default:
+ vp << (FX_LPCWSTR)L"";
+ }
+ }
+
+ return TRUE;
+}
+
+void Field::SetAlignment(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex,
+ const CFX_ByteString& string)
+{
+ //Not supported.
+}
+
+FX_BOOL Field::borderStyle(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ CFX_ByteString strType = "";
+ vp >> strType;
+
+ if (m_bDelay)
+ {
+ AddDelay_String(FP_BORDERSTYLE, strType);
+ }
+ else
+ {
+ Field::SetBorderStyle(m_pDocument, m_FieldName, m_nFormControlIndex, strType);
+ }
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName, FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ if (!pFormField) return FALSE;
+
+ CPDFSDK_Widget* pWidget = GetWidget(m_pDocument, GetSmartFieldControl(pFormField));
+ if (!pWidget) return FALSE;
+
+ int nBorderstyle = pWidget->GetBorderStyle();
+
+ switch (nBorderstyle)
+ {
+ case BBS_SOLID:
+ vp << (FX_LPCWSTR)L"solid";
+ break;
+ case BBS_DASH:
+ vp << (FX_LPCWSTR)L"dashed";
+ break;
+ case BBS_BEVELED:
+ vp << (FX_LPCWSTR)L"beveled";
+ break;
+ case BBS_INSET:
+ vp << (FX_LPCWSTR)L"inset";
+ break;
+ case BBS_UNDERLINE:
+ vp << (FX_LPCWSTR)L"underline";
+ break;
+ default:
+ vp << (FX_LPCWSTR)L"";
+ break;
+ }
+ }
+
+ return TRUE;
+}
+
+void Field::SetBorderStyle(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex,
+ const CFX_ByteString& string)
+{
+ ASSERT(pDocument != NULL);
+
+ int nBorderStyle = 0;
+
+ if (string == "solid")
+ nBorderStyle = BBS_SOLID;
+ else if (string == "beveled")
+ nBorderStyle = BBS_BEVELED;
+ else if (string == "dashed")
+ nBorderStyle = BBS_DASH;
+ else if (string == "inset")
+ nBorderStyle = BBS_INSET;
+ else if (string == "underline")
+ nBorderStyle = BBS_UNDERLINE;
+ else return;
+
+ CFX_PtrArray FieldArray;
+ GetFormFields(pDocument, swFieldName, FieldArray);
+
+ for (int i=0,isz=FieldArray.GetSize(); i<isz; i++)
+ {
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(i);
+ ASSERT(pFormField != NULL);
+
+ if (nControlIndex < 0)
+ {
+ FX_BOOL bSet = FALSE;
+ for (int j=0,jsz = pFormField->CountControls(); j<jsz; j++)
+ {
+ if (CPDFSDK_Widget* pWidget = GetWidget(pDocument, pFormField->GetControl(j)))
+ {
+ if (pWidget->GetBorderStyle() != nBorderStyle)
+ {
+ pWidget->SetBorderStyle(nBorderStyle);
+ bSet = TRUE;
+ }
+ }
+ }
+ if (bSet) UpdateFormField(pDocument, pFormField, TRUE, TRUE, TRUE);
+ }
+ else
+ {
+ if(nControlIndex >= pFormField->CountControls()) return;
+ if (CPDF_FormControl* pFormControl = pFormField->GetControl(nControlIndex))
+ {
+ if (CPDFSDK_Widget* pWidget = GetWidget(pDocument, pFormControl))
+ {
+ if (pWidget->GetBorderStyle() != nBorderStyle)
+ {
+ pWidget->SetBorderStyle(nBorderStyle);
+ UpdateFormControl(pDocument, pFormControl, TRUE, TRUE, TRUE);
+ }
+ }
+ }
+ }
+ }
+}
+
+FX_BOOL Field::buttonAlignX(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ int nVP;
+ vp >> nVP;
+
+ if (m_bDelay)
+ {
+ AddDelay_Int(FP_BUTTONALIGNX, nVP);
+ }
+ else
+ {
+ Field::SetButtonAlignX(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
+ }
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
+ return FALSE;
+
+ CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
+ if (!pFormControl)return FALSE;
+
+ CPDF_IconFit IconFit = pFormControl->GetIconFit();
+
+ FX_FLOAT fLeft,fBottom;
+ IconFit.GetIconPosition(fLeft,fBottom);
+
+ vp << (FX_INT32)fLeft;
+ }
+
+ return TRUE;
+}
+
+void Field::SetButtonAlignX(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
+{
+ //Not supported.
+}
+
+FX_BOOL Field::buttonAlignY(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ int nVP;
+ vp >> nVP;
+
+ if (m_bDelay)
+ {
+ AddDelay_Int(FP_BUTTONALIGNY, nVP);
+ }
+ else
+ {
+ Field::SetButtonAlignY(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
+ }
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
+ return FALSE;
+
+ CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
+ if (!pFormControl)return FALSE;
+
+ CPDF_IconFit IconFit = pFormControl->GetIconFit();
+
+ FX_FLOAT fLeft,fBottom;
+ IconFit.GetIconPosition(fLeft,fBottom);
+
+ vp << (FX_INT32)fBottom;
+ }
+
+ return TRUE;
+}
+
+void Field::SetButtonAlignY(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
+{
+ //Not supported.
+}
+
+FX_BOOL Field::buttonFitBounds(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ bool bVP;
+ vp >> bVP;
+
+ if (m_bDelay)
+ {
+ AddDelay_Bool(FP_BUTTONFITBOUNDS, bVP);
+ }
+ else
+ {
+ Field::SetButtonFitBounds(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
+ }
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
+ return FALSE;
+
+ CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
+ if (!pFormControl)return FALSE;
+
+ CPDF_IconFit IconFit = pFormControl->GetIconFit();
+ vp << IconFit.GetFittingBounds();
+ }
+
+ return TRUE;
+}
+
+void Field::SetButtonFitBounds(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b)
+{
+ //Not supported.
+}
+
+FX_BOOL Field::buttonPosition(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ int nVP;
+ vp >> nVP;
+
+ if (m_bDelay)
+ {
+ AddDelay_Int(FP_BUTTONPOSITION, nVP);
+ }
+ else
+ {
+ Field::SetButtonPosition(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
+ }
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
+ return FALSE;
+
+ CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
+ if (!pFormControl)return FALSE;
+
+ vp << pFormControl->GetTextPosition();
+ }
+ return TRUE;
+}
+
+void Field::SetButtonPosition(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
+{
+ //Not supported.
+}
+
+FX_BOOL Field::buttonScaleHow(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ int nVP;
+ vp >> nVP;
+
+ if (m_bDelay)
+ {
+ AddDelay_Int(FP_BUTTONSCALEHOW, nVP);
+ }
+ else
+ {
+ Field::SetButtonScaleHow(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
+ }
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName, FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
+ return FALSE;
+
+ CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
+ if (!pFormControl)return FALSE;
+
+ CPDF_IconFit IconFit = pFormControl->GetIconFit();
+ if (IconFit.IsProportionalScale())
+ vp << (FX_INT32)0;
+ else
+ vp << (FX_INT32)1;
+ }
+
+ return TRUE;
+}
+
+void Field::SetButtonScaleHow(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
+{
+ //Not supported.
+}
+
+FX_BOOL Field::buttonScaleWhen(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ int nVP;
+ vp >> nVP;
+
+ if (m_bDelay)
+ {
+ AddDelay_Int(FP_BUTTONSCALEWHEN, nVP);
+ }
+ else
+ {
+ Field::SetButtonScaleWhen(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
+ }
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*) FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
+ return FALSE;
+
+ CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
+ if (!pFormControl) return FALSE;
+
+ CPDF_IconFit IconFit = pFormControl->GetIconFit();
+ int ScaleM = IconFit.GetScaleMethod();
+ switch (ScaleM)
+ {
+ case CPDF_IconFit::Always :
+ vp << (FX_INT32) CPDF_IconFit::Always;
+ break;
+ case CPDF_IconFit::Bigger :
+ vp << (FX_INT32) CPDF_IconFit::Bigger;
+ break;
+ case CPDF_IconFit::Never :
+ vp << (FX_INT32) CPDF_IconFit::Never;
+ break;
+ case CPDF_IconFit::Smaller :
+ vp << (FX_INT32) CPDF_IconFit::Smaller;
+ break;
+ }
+ }
+
+ return TRUE;
+}
+
+void Field::SetButtonScaleWhen(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
+{
+ //Not supported.
+}
+
+FX_BOOL Field::calcOrderIndex(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ int nVP;
+ vp >> nVP;
+
+ if (m_bDelay)
+ {
+ AddDelay_Int(FP_CALCORDERINDEX, nVP);
+ }
+ else
+ {
+ Field::SetCalcOrderIndex(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
+ }
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName, FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX && pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
+ return FALSE;
+
+ CPDFSDK_InterForm* pRDInterForm = m_pDocument->GetInterForm();
+ ASSERT(pRDInterForm != NULL);
+
+ CPDF_InterForm* pInterForm = pRDInterForm->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ vp << (FX_INT32)pInterForm->FindFieldInCalculationOrder(pFormField);
+ }
+
+ return TRUE;
+}
+
+void Field::SetCalcOrderIndex(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
+{
+ //Not supported.
+}
+
+FX_BOOL Field::charLimit(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ int nVP;
+ vp >> nVP;
+
+ if (m_bDelay)
+ {
+ AddDelay_Int(FP_CHARLIMIT, nVP);
+ }
+ else
+ {
+ Field::SetCharLimit(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
+ }
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName, FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
+ return FALSE;
+
+ vp << (FX_INT32)pFormField->GetMaxLen();
+ }
+ return TRUE;
+}
+
+void Field::SetCharLimit(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
+{
+ //Not supported.
+}
+
+FX_BOOL Field::comb(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ bool bVP;
+ vp >> bVP;
+
+ if (m_bDelay)
+ {
+ AddDelay_Bool(FP_COMB, bVP);
+ }
+ else
+ {
+ Field::SetComb(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
+ }
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
+ return FALSE;
+
+ if (pFormField->GetFieldFlags() & FIELDFLAG_COMB)
+ vp << true;
+ else
+ vp << false;
+ }
+
+ return TRUE;
+}
+
+void Field::SetComb(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b)
+{
+ //Not supported.
+}
+
+FX_BOOL Field::commitOnSelChange(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ bool bVP;
+ vp >> bVP;
+
+ if (m_bDelay)
+ {
+ AddDelay_Bool(FP_COMMITONSELCHANGE, bVP);
+ }
+ else
+ {
+ Field::SetCommitOnSelChange(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
+ }
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX && pFormField->GetFieldType() != FIELDTYPE_LISTBOX)
+ return FALSE;
+
+ if (pFormField->GetFieldFlags() & FIELDFLAG_COMMITONSELCHANGE)
+ vp << true;
+ else
+ vp << false;
+ }
+
+ return TRUE;
+}
+
+void Field::SetCommitOnSelChange(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b)
+{
+ //Not supported.
+}
+
+FX_BOOL Field::currentValueIndices(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ CFX_DWordArray array;
+
+ if (vp.GetType() == VT_number)
+ {
+ int iSelecting = 0;
+ vp >> iSelecting;
+ array.Add(iSelecting);
+ }
+ else if (vp.IsArrayObject())
+ {
+ CJS_Array SelArray(m_isolate);
+ CJS_Value SelValue(m_isolate);
+ int iSelecting;
+ vp >> SelArray;
+ for (int i=0,sz=SelArray.GetLength(); i<sz; i++)
+ {
+ SelArray.GetElement(i,SelValue);
+ iSelecting = (FX_INT32)SelValue;
+ array.Add(iSelecting);
+ }
+ }
+
+ if (m_bDelay)
+ {
+ AddDelay_WordArray(FP_CURRENTVALUEINDICES, array);
+ }
+ else
+ {
+ Field::SetCurrentValueIndices(m_pDocument, m_FieldName, m_nFormControlIndex, array);
+ }
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX && pFormField->GetFieldType() != FIELDTYPE_LISTBOX)
+ return FALSE;
+
+ if (pFormField->CountSelectedItems() == 1)
+ vp << pFormField->GetSelectedIndex(0);
+ else if (pFormField->CountSelectedItems() > 1)
+ {
+ CJS_Array SelArray(m_isolate);
+ for (int i=0,sz=pFormField->CountSelectedItems(); i<sz; i++)
+ {
+ SelArray.SetElement(i, CJS_Value(m_isolate,pFormField->GetSelectedIndex(i)));
+ }
+ vp << SelArray;
+ }
+ else
+ vp << -1;
+ }
+
+ return TRUE;
+}
+
+void Field::SetCurrentValueIndices(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex,
+ const CFX_DWordArray& array)
+{
+ ASSERT(pDocument != NULL);
+
+ CFX_PtrArray FieldArray;
+ GetFormFields(pDocument, swFieldName, FieldArray);
+
+ for (int i=0,isz=FieldArray.GetSize(); i<isz; i++)
+ {
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(i);
+ ASSERT(pFormField != NULL);
+
+ int nFieldType = pFormField->GetFieldType();
+ if (nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_LISTBOX)
+ {
+ FX_DWORD dwFieldFlags = pFormField->GetFieldFlags();
+ pFormField->ClearSelection(TRUE);
+
+ for (int i=0,sz=array.GetSize(); i<sz; i++)
+ {
+ if (i>0 && !(dwFieldFlags & (1<<21)))
+ {
+ break;
+ }
+
+ int iSelecting = (FX_INT32)array.GetAt(i);
+ if (iSelecting < pFormField->CountOptions() && !pFormField->IsItemSelected(iSelecting))
+ pFormField->SetItemSelection(iSelecting, TRUE);
+
+ }
+ UpdateFormField(pDocument, pFormField, TRUE, TRUE, TRUE);
+ }
+ }
+}
+
+FX_BOOL Field::defaultStyle(OBJ_PROP_PARAMS)
+{
+ // MQG sError = JSGetStringFromID(IDS_STRING_NOTSUPPORT);
+ return FALSE;
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ ;
+ }
+ else
+ {
+ ;
+ }
+ return TRUE;
+}
+
+void Field::SetDefaultStyle(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex)
+{
+ //Not supported.
+}
+
+FX_BOOL Field::defaultValue(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ CFX_WideString WideStr;
+ vp >> WideStr;
+
+ if (m_bDelay)
+ {
+ AddDelay_WideString(FP_DEFAULTVALUE, WideStr);
+ }
+ else
+ {
+ Field::SetDefaultValue(m_pDocument, m_FieldName, m_nFormControlIndex, WideStr);
+ }
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON ||
+ pFormField->GetFieldType() == FIELDTYPE_SIGNATURE)
+ return FALSE;
+
+ vp << pFormField->GetDefaultValue();
+ }
+ return TRUE;
+}
+
+void Field::SetDefaultValue(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex,
+ const CFX_WideString& string)
+{
+ //Not supported.
+}
+
+FX_BOOL Field::doNotScroll(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ bool bVP;
+ vp >> bVP;
+
+ if (m_bDelay)
+ {
+ AddDelay_Bool(FP_DONOTSCROLL, bVP);
+ }
+ else
+ {
+ Field::SetDoNotScroll(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
+ }
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
+ return FALSE;
+
+ if (pFormField->GetFieldFlags() & FIELDFLAG_DONOTSCROLL)
+ vp << true;
+ else
+ vp << false;
+ }
+
+ return TRUE;
+}
+
+void Field::SetDoNotScroll(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b)
+{
+ //Not supported.
+}
+
+FX_BOOL Field::doNotSpellCheck(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ bool bVP;
+ vp >> bVP;
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD &&
+ pFormField->GetFieldType() != FIELDTYPE_COMBOBOX)
+ return FALSE;
+
+ if (pFormField->GetFieldFlags() & FIELDFLAG_DONOTSPELLCHECK)
+ vp << true;
+ else
+ vp << false;
+ }
+
+ return TRUE;
+}
+
+void Field::SetDelay(FX_BOOL bDelay)
+{
+ m_bDelay = bDelay;
+
+ if (!m_bDelay)
+ {
+ if (m_pJSDoc)
+ m_pJSDoc->DoFieldDelay(m_FieldName, m_nFormControlIndex);
+ }
+}
+
+FX_BOOL Field::delay(OBJ_PROP_PARAMS)
+{
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ bool bVP;
+ vp >> bVP;
+
+ SetDelay(bVP);
+ }
+ else
+ {
+ vp << m_bDelay;
+ }
+ return TRUE;
+}
+
+FX_BOOL Field::display(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ int nVP;
+ vp >> nVP;
+
+ if (m_bDelay)
+ {
+ AddDelay_Int(FP_DISPLAY, nVP);
+ }
+ else
+ {
+ Field::SetDisplay(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
+ }
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ CPDFSDK_Widget* pWidget = pInterForm->GetWidget(GetSmartFieldControl(pFormField));
+ if (!pWidget)return FALSE;
+
+ FX_DWORD dwFlag = pWidget->GetFlags();
+
+ if (ANNOTFLAG_INVISIBLE & dwFlag || ANNOTFLAG_HIDDEN & dwFlag)
+ {
+ vp << (FX_INT32)1;
+ }
+ else
+ {
+ if (ANNOTFLAG_PRINT & dwFlag)
+ {
+ if (ANNOTFLAG_NOVIEW & dwFlag)
+ {
+ vp << (FX_INT32)3;
+ }
+ else
+ {
+ vp << (FX_INT32)0;
+ }
+ }
+ else
+ {
+ vp << (FX_INT32)2;
+ }
+ }
+ }
+
+ return TRUE;
+}
+
+void Field::SetDisplay(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
+{
+ ASSERT(pDocument != NULL);
+
+ CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ CFX_PtrArray FieldArray;
+ GetFormFields(pDocument, swFieldName, FieldArray);
+
+ for (int i=0,isz=FieldArray.GetSize(); i<isz; i++)
+ {
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(i);
+ ASSERT(pFormField != NULL);
+
+ if (nControlIndex < 0)
+ {
+ FX_BOOL bSet = FALSE;
+ for (int j=0,jsz = pFormField->CountControls(); j<jsz; j++)
+ {
+ CPDF_FormControl* pFormControl = pFormField->GetControl(j);
+ ASSERT(pFormControl != NULL);
+
+ if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl))
+ {
+ FX_DWORD dwFlag = pWidget->GetFlags();
+ switch (number)
+ {
+ case 0:
+ dwFlag &= (~ANNOTFLAG_INVISIBLE);
+ dwFlag &= (~ANNOTFLAG_HIDDEN);
+ dwFlag &= (~ANNOTFLAG_NOVIEW);
+ dwFlag |= ANNOTFLAG_PRINT;
+ break;
+ case 1:
+ dwFlag &= (~ANNOTFLAG_INVISIBLE);
+ dwFlag &= (~ANNOTFLAG_NOVIEW);
+ dwFlag |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT);
+ break;
+ case 2:
+ dwFlag &= (~ANNOTFLAG_INVISIBLE);
+ dwFlag &= (~ANNOTFLAG_PRINT);
+ dwFlag &= (~ANNOTFLAG_HIDDEN);
+ dwFlag &= (~ANNOTFLAG_NOVIEW);
+ break;
+ case 3:
+ dwFlag |= ANNOTFLAG_NOVIEW;
+ dwFlag |= ANNOTFLAG_PRINT;
+ dwFlag &= (~ANNOTFLAG_HIDDEN);
+ break;
+ }
+
+ if (dwFlag != pWidget->GetFlags())
+ {
+ pWidget->SetFlags(dwFlag);
+ bSet = TRUE;
+ }
+ }
+ }
+
+ if (bSet) UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE);
+ }
+ else
+ {
+ if(nControlIndex >= pFormField->CountControls()) return;
+ if (CPDF_FormControl* pFormControl = pFormField->GetControl(nControlIndex))
+ {
+ if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl))
+ {
+
+ FX_DWORD dwFlag = pWidget->GetFlags();
+ switch (number)
+ {
+ case 0:
+ dwFlag &= (~ANNOTFLAG_INVISIBLE);
+ dwFlag &= (~ANNOTFLAG_HIDDEN);
+ dwFlag &= (~ANNOTFLAG_NOVIEW);
+ dwFlag |= ANNOTFLAG_PRINT;
+ break;
+ case 1:
+ dwFlag &= (~ANNOTFLAG_INVISIBLE);
+ dwFlag &= (~ANNOTFLAG_NOVIEW);
+ dwFlag |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT);
+ break;
+ case 2:
+ dwFlag &= (~ANNOTFLAG_INVISIBLE);
+ dwFlag &= (~ANNOTFLAG_PRINT);
+ dwFlag &= (~ANNOTFLAG_HIDDEN);
+ dwFlag &= (~ANNOTFLAG_NOVIEW);
+ break;
+ case 3:
+ dwFlag |= ANNOTFLAG_NOVIEW;
+ dwFlag |= ANNOTFLAG_PRINT;
+ dwFlag &= (~ANNOTFLAG_HIDDEN);
+ break;
+ }
+ if (dwFlag != pWidget->GetFlags())
+ {
+ pWidget->SetFlags(dwFlag);
+ UpdateFormControl(pDocument, pFormControl, TRUE, FALSE, TRUE);
+ }
+ }
+ }
+ }
+ }
+}
+
+FX_BOOL Field::doc(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pJSDoc != NULL);
+
+ if (!vp.IsGetting())return FALSE;
+
+ vp << (CJS_Object*)(*m_pJSDoc);
+
+ return TRUE;
+}
+
+FX_BOOL Field::editable(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ bool bVP;
+ vp >> bVP;
+
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName, FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX)
+ return FALSE;
+
+ if (pFormField->GetFieldFlags() & FIELDFLAG_EDIT)
+ vp << true;
+ else
+ vp << false;
+ }
+
+ return TRUE;
+}
+
+FX_BOOL Field::exportValues(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if (pFormField->GetFieldType() != FIELDTYPE_CHECKBOX &&
+ pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON)
+ return FALSE;
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+ if (!vp.IsArrayObject())return FALSE;
+ }
+ else
+ {
+ CJS_Array ExportValusArray(m_isolate);
+
+ if (m_nFormControlIndex < 0)
+ {
+ for (int i=0,sz=pFormField->CountControls(); i<sz; i++)
+ {
+ CPDF_FormControl* pFormControl = pFormField->GetControl(i);
+ ASSERT(pFormControl != NULL);
+
+ ExportValusArray.SetElement(i, CJS_Value(m_isolate,(FX_LPCWSTR)pFormControl->GetExportValue()));
+ }
+ }
+ else
+ {
+ if(m_nFormControlIndex >= pFormField->CountControls()) return FALSE;
+ CPDF_FormControl* pFormControl = pFormField->GetControl(m_nFormControlIndex);
+ if (!pFormControl) return FALSE;
+
+ ExportValusArray.SetElement(0, CJS_Value(m_isolate,(FX_LPCWSTR)pFormControl->GetExportValue()));
+ }
+
+ vp << ExportValusArray;
+ }
+
+ return TRUE;
+}
+
+FX_BOOL Field::fileSelect(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName, FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
+ return FALSE;
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ bool bVP;
+ vp >> bVP;
+
+ }
+ else
+ {
+ if (pFormField->GetFieldFlags() & FIELDFLAG_FILESELECT)
+ vp << true;
+ else
+ vp << false;
+ }
+
+ return TRUE;
+}
+
+FX_BOOL Field::fillColor(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ CJS_Array crArray(m_isolate);
+
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+ if (!vp.IsArrayObject()) return FALSE;
+
+ vp >> crArray;
+
+ CPWL_Color color;
+ color::ConvertArrayToPWLColor(crArray, color);
+
+ if (m_bDelay)
+ {
+ AddDelay_Color(FP_FILLCOLOR, color);
+ }
+ else
+ {
+ Field::SetFillColor(m_pDocument, m_FieldName, m_nFormControlIndex, color);
+ }
+ }
+ else
+ {
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
+ if (!pFormControl)return FALSE;
+
+ int iColorType;
+ pFormControl->GetBackgroundColor(iColorType);
+
+ CPWL_Color color;
+
+ if (iColorType == COLORTYPE_TRANSPARENT)
+ {
+ color = CPWL_Color(COLORTYPE_TRANSPARENT);
+ }
+ else if (iColorType == COLORTYPE_GRAY)
+ {
+ color = CPWL_Color(COLORTYPE_GRAY, pFormControl->GetOriginalBackgroundColor(0));
+ }
+ else if (iColorType == COLORTYPE_RGB)
+ {
+ color = CPWL_Color(COLORTYPE_RGB, pFormControl->GetOriginalBackgroundColor(0),
+ pFormControl->GetOriginalBackgroundColor(1),
+ pFormControl->GetOriginalBackgroundColor(2));
+ }
+ else if (iColorType == COLORTYPE_CMYK)
+ {
+ color = CPWL_Color(COLORTYPE_CMYK, pFormControl->GetOriginalBackgroundColor(0),
+ pFormControl->GetOriginalBackgroundColor(1),
+ pFormControl->GetOriginalBackgroundColor(2),
+ pFormControl->GetOriginalBackgroundColor(3));
+ }
+ else
+ return FALSE;
+
+ color::ConvertPWLColorToArray(color, crArray);
+ vp << crArray;
+ }
+
+ return TRUE;
+}
+
+void Field::SetFillColor(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CPWL_Color& color)
+{
+ //Not supported.
+}
+
+FX_BOOL Field::hidden(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ bool bVP;
+ vp >> bVP;
+
+ if (m_bDelay)
+ {
+ AddDelay_Bool(FP_HIDDEN, bVP);
+ }
+ else
+ {
+ Field::SetHidden(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
+ }
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ CPDFSDK_Widget* pWidget = pInterForm->GetWidget(GetSmartFieldControl(pFormField));
+ if (!pWidget) return FALSE;
+
+ FX_DWORD dwFlags = pWidget->GetFlags();
+
+ if (ANNOTFLAG_INVISIBLE & dwFlags || ANNOTFLAG_HIDDEN & dwFlags)
+ {
+ vp << true;
+ }
+ else
+ vp << false;
+ }
+
+ return TRUE;
+}
+
+void Field::SetHidden(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b)
+{
+ ASSERT(pDocument != NULL);
+
+ CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ CFX_PtrArray FieldArray;
+ GetFormFields(pDocument, swFieldName, FieldArray);
+
+ for (int i=0,isz=FieldArray.GetSize(); i<isz; i++)
+ {
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(i);
+ ASSERT(pFormField != NULL);
+
+ if (nControlIndex < 0)
+ {
+ FX_BOOL bSet = FALSE;
+ for (int j=0,jsz = pFormField->CountControls(); j<jsz; j++)
+ {
+ if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormField->GetControl(j)))
+ {
+ FX_DWORD dwFlags = pWidget->GetFlags();
+
+ if (b)
+ {
+ dwFlags &= (~ANNOTFLAG_INVISIBLE);
+ dwFlags &= (~ANNOTFLAG_NOVIEW);
+ dwFlags |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT);
+ }
+ else
+ {
+ dwFlags &= (~ANNOTFLAG_INVISIBLE);
+ dwFlags &= (~ANNOTFLAG_HIDDEN);
+ dwFlags &= (~ANNOTFLAG_NOVIEW);
+ dwFlags |= ANNOTFLAG_PRINT;
+ }
+
+ if (dwFlags != pWidget->GetFlags())
+ {
+ pWidget->SetFlags(dwFlags);
+ bSet = TRUE;
+ }
+ }
+ }
+
+ if (bSet)
+ UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE);
+ }
+ else
+ {
+ if(nControlIndex >= pFormField->CountControls()) return;
+ if (CPDF_FormControl* pFormControl = pFormField->GetControl(nControlIndex))
+ {
+ if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl))
+ {
+ FX_DWORD dwFlags = pWidget->GetFlags();
+
+ if (b)
+ {
+ dwFlags &= (~ANNOTFLAG_INVISIBLE);
+ dwFlags &= (~ANNOTFLAG_NOVIEW);
+ dwFlags |= (ANNOTFLAG_HIDDEN | ANNOTFLAG_PRINT);
+ }
+ else
+ {
+ dwFlags &= (~ANNOTFLAG_INVISIBLE);
+ dwFlags &= (~ANNOTFLAG_HIDDEN);
+ dwFlags &= (~ANNOTFLAG_NOVIEW);
+ dwFlags |= ANNOTFLAG_PRINT;
+ }
+
+ if (dwFlags != pWidget->GetFlags())
+ {
+ pWidget->SetFlags(dwFlags);
+ UpdateFormControl(pDocument, pFormControl, TRUE, FALSE, TRUE);
+ }
+ }
+ }
+ }
+ }
+}
+
+FX_BOOL Field::highlight(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ CFX_ByteString strMode;
+ vp >> strMode;
+
+ if (m_bDelay)
+ {
+ AddDelay_String(FP_HIGHLIGHT, strMode);
+ }
+ else
+ {
+ Field::SetHighlight(m_pDocument, m_FieldName, m_nFormControlIndex, strMode);
+ }
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
+ return FALSE;
+
+ CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
+ if (!pFormControl) return FALSE;
+
+ int eHM = pFormControl->GetHighlightingMode();
+ switch (eHM)
+ {
+ case CPDF_FormControl::None:
+ vp << (FX_LPCWSTR)L"none";
+ break;
+ case CPDF_FormControl::Push:
+ vp << (FX_LPCWSTR)L"push";
+ break;
+ case CPDF_FormControl::Invert:
+ vp << (FX_LPCWSTR)L"invert";
+ break;
+ case CPDF_FormControl::Outline:
+ vp << (FX_LPCWSTR)L"outline";
+ break;
+ case CPDF_FormControl::Toggle:
+ vp << (FX_LPCWSTR)L"toggle";
+ break;
+ }
+ }
+
+ return TRUE;
+}
+
+void Field::SetHighlight(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CFX_ByteString& string)
+{
+ //Not supported.
+}
+
+FX_BOOL Field::lineWidth(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ int iWidth;
+ vp >> iWidth;
+
+ if (m_bDelay)
+ {
+ AddDelay_Int(FP_LINEWIDTH, iWidth);
+ }
+ else
+ {
+ Field::SetLineWidth(m_pDocument, m_FieldName, m_nFormControlIndex, iWidth);
+ }
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
+ if (!pFormControl) return FALSE;
+
+ CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ if(!pFormField->CountControls()) return FALSE;
+
+ CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormField->GetControl(0));
+ if (!pWidget) return FALSE;
+
+ vp << (FX_INT32)pWidget->GetBorderWidth();
+ }
+
+ return TRUE;
+}
+
+void Field::SetLineWidth(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
+{
+ ASSERT(pDocument != NULL);
+
+ CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ CFX_PtrArray FieldArray;
+ GetFormFields(pDocument, swFieldName, FieldArray);
+
+ for (int i=0,isz=FieldArray.GetSize(); i<isz; i++)
+ {
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(i);
+ ASSERT(pFormField != NULL);
+
+ if (nControlIndex < 0)
+ {
+ FX_BOOL bSet = FALSE;
+ for (int j=0,jsz=pFormField->CountControls(); j<jsz; j++)
+ {
+ CPDF_FormControl* pFormControl = pFormField->GetControl(j);
+ ASSERT(pFormControl != NULL);
+
+ if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl))
+ {
+ if (number != pWidget->GetBorderWidth())
+ {
+ pWidget->SetBorderWidth(number);
+ bSet = TRUE;
+ }
+ }
+ }
+ if (bSet) UpdateFormField(pDocument, pFormField, TRUE, TRUE, TRUE);
+ }
+ else
+ {
+ if(nControlIndex >= pFormField->CountControls()) return;
+ if (CPDF_FormControl* pFormControl = pFormField->GetControl(nControlIndex))
+ {
+ if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl))
+ {
+ if (number != pWidget->GetBorderWidth())
+ {
+ pWidget->SetBorderWidth(number);
+ UpdateFormControl(pDocument, pFormControl, TRUE, TRUE, TRUE);
+ }
+ }
+ }
+ }
+ }
+}
+
+FX_BOOL Field::multiline(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ bool bVP;
+ vp >> bVP;
+
+ if (m_bDelay)
+ {
+ AddDelay_Bool(FP_MULTILINE, bVP);
+ }
+ else
+ {
+ Field::SetMultiline(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
+ }
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName, FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
+ return FALSE;
+
+ if (pFormField->GetFieldFlags() & FIELDFLAG_MULTILINE)
+ vp << true;
+ else
+ vp << false;
+ }
+
+ return TRUE;
+}
+
+void Field::SetMultiline(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b)
+{
+ //Not supported.
+}
+
+FX_BOOL Field::multipleSelection(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ bool bVP;
+ vp >> bVP;
+
+ if (m_bDelay)
+ {
+ AddDelay_Bool(FP_MULTIPLESELECTION, bVP);
+ }
+ else
+ {
+ Field::SetMultipleSelection(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
+ }
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if (pFormField->GetFieldType() != FIELDTYPE_LISTBOX)
+ return FALSE;
+
+ if (pFormField->GetFieldFlags() & FIELDFLAG_MULTISELECT)
+ vp << true;
+ else
+ vp << false;
+ }
+
+ return TRUE;
+}
+
+void Field::SetMultipleSelection(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b)
+{
+ //Not supported.
+}
+
+FX_BOOL Field::name(OBJ_PROP_PARAMS)
+{
+ if (!vp.IsGetting()) return FALSE;
+
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName, FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ vp << m_FieldName;
+
+ return TRUE;
+}
+
+FX_BOOL Field::numItems(OBJ_PROP_PARAMS)
+{
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName, FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX &&
+ pFormField->GetFieldType() != FIELDTYPE_LISTBOX)
+ return FALSE;
+
+ if (!vp.IsGetting()) return FALSE;
+
+ vp << (FX_INT32)pFormField->CountOptions();
+
+ return TRUE;
+}
+
+FX_BOOL Field::page(OBJ_PROP_PARAMS)
+{
+ if (!vp.IsGetting()) return FALSE;
+
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName, FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ if (!pFormField) return FALSE;
+
+ ASSERT(m_pDocument != NULL);
+
+ CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ CFX_PtrArray widgetArray;
+ pInterForm->GetWidgets(pFormField, widgetArray);
+
+ if (widgetArray.GetSize() > 0)
+ {
+ CJS_Array PageArray(m_isolate);
+
+ for (int i=0,sz=widgetArray.GetSize(); i<sz; i++)
+ {
+ CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)widgetArray.GetAt(i);
+ ASSERT(pWidget != NULL);
+
+ CPDFSDK_PageView* pPageView = pWidget->GetPageView();
+ if(!pPageView)
+ return FALSE;
+
+ PageArray.SetElement(i, CJS_Value(m_isolate,(FX_INT32)pPageView->GetPageIndex()));
+ }
+
+ vp << PageArray;
+ }
+ else
+ {
+ vp << (FX_INT32) -1;
+ }
+
+ return TRUE;
+}
+
+FX_BOOL Field::password(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ bool bVP;
+ vp >> bVP;
+
+ if (m_bDelay)
+ {
+ AddDelay_Bool(FP_PASSWORD, bVP);
+ }
+ else
+ {
+ Field::SetPassword(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
+ }
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
+ return FALSE;
+
+ if (pFormField->GetFieldFlags() & FIELDFLAG_PASSWORD)
+ vp << true;
+ else
+ vp << false;
+ }
+
+ return TRUE;
+}
+
+void Field::SetPassword(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b)
+{
+ //Not supported.
+}
+
+FX_BOOL Field::print(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName, FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ bool bVP;
+ vp >> bVP;
+
+ for (int i=0,isz=FieldArray.GetSize(); i<isz; i++)
+ {
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(i);
+ ASSERT(pFormField != NULL);
+
+ if (m_nFormControlIndex < 0)
+ {
+ FX_BOOL bSet = FALSE;
+ for (int j=0,jsz = pFormField->CountControls(); j<jsz; j++)
+ {
+ if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormField->GetControl(j)))
+ {
+ FX_DWORD dwFlags = pWidget->GetFlags();
+ if (bVP)
+ dwFlags |= ANNOTFLAG_PRINT;
+ else
+ dwFlags &= ~ANNOTFLAG_PRINT;
+
+ if (dwFlags != pWidget->GetFlags())
+ {
+ pWidget->SetFlags(dwFlags);
+ bSet = TRUE;
+ }
+ }
+ }
+
+ if (bSet)
+ UpdateFormField(m_pDocument, pFormField, TRUE, FALSE, TRUE);
+ }
+ else
+ {
+ if(m_nFormControlIndex >= pFormField->CountControls()) return FALSE;
+ if (CPDF_FormControl* pFormControl = pFormField->GetControl(m_nFormControlIndex))
+ {
+ if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl))
+ {
+ FX_DWORD dwFlags = pWidget->GetFlags();
+ if (bVP)
+ dwFlags |= ANNOTFLAG_PRINT;
+ else
+ dwFlags &= ~ANNOTFLAG_PRINT;
+
+ if (dwFlags != pWidget->GetFlags())
+ {
+ pWidget->SetFlags(dwFlags);
+ UpdateFormControl(m_pDocument, pFormField->GetControl(m_nFormControlIndex), TRUE, FALSE, TRUE);
+ }
+ }
+ }
+ }
+ }
+ }
+ else
+ {
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ CPDFSDK_Widget* pWidget = pInterForm->GetWidget(GetSmartFieldControl(pFormField));
+ if (!pWidget) return FALSE;
+
+ if (pWidget->GetFlags() & ANNOTFLAG_PRINT)
+ vp << true;
+ else
+ vp << false;
+ }
+
+ return TRUE;
+}
+
+FX_BOOL Field::radiosInUnison(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ bool bVP;
+ vp >> bVP;
+
+ }
+ else
+ {
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if (pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON)
+ return FALSE;
+
+ if (pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON)
+ vp << true;
+ else
+ vp << false;
+ }
+
+ return TRUE;
+}
+
+FX_BOOL Field::readonly(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ bool bVP;
+ vp >> bVP;
+
+ }
+ else
+ {
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if (pFormField->GetFieldFlags() & FIELDFLAG_READONLY)
+ vp << true;
+ else
+ vp << false;
+ }
+
+ return TRUE;
+}
+
+FX_BOOL Field::rect(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+ if (!vp.IsArrayObject())return FALSE;
+
+ CJS_Array rcArray(m_isolate);
+ vp >> rcArray;
+ CJS_Value Upper_Leftx(m_isolate), Upper_Lefty(m_isolate), Lower_Rightx(m_isolate), Lower_Righty(m_isolate);
+ rcArray.GetElement(0, Upper_Leftx);
+ rcArray.GetElement(1, Upper_Lefty);
+ rcArray.GetElement(2, Lower_Rightx);
+ rcArray.GetElement(3, Lower_Righty);
+
+ FX_FLOAT pArray[4] = {0.0f,0.0f,0.0f,0.0f};
+ pArray[0] = (FX_FLOAT)(FX_INT32)Upper_Leftx;
+ pArray[1] = (FX_FLOAT)(FX_INT32)Lower_Righty;
+ pArray[2] = (FX_FLOAT)(FX_INT32)Lower_Rightx;
+ pArray[3] = (FX_FLOAT)(FX_INT32)Upper_Lefty;
+
+ CPDF_Rect crRect(pArray);
+
+ if (m_bDelay)
+ {
+ AddDelay_Rect(FP_RECT, crRect);
+ }
+ else
+ {
+ Field::SetRect(m_pDocument, m_FieldName, m_nFormControlIndex, crRect);
+ }
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ CPDFSDK_Widget* pWidget = pInterForm->GetWidget(GetSmartFieldControl(pFormField));
+ if (!pWidget) return FALSE;
+
+ CFX_FloatRect crRect = pWidget->GetRect();
+ CJS_Value Upper_Leftx(m_isolate),Upper_Lefty(m_isolate),Lower_Rightx(m_isolate),Lower_Righty(m_isolate);
+ Upper_Leftx = (FX_INT32)crRect.left;
+ Upper_Lefty = (FX_INT32)crRect.top;
+ Lower_Rightx = (FX_INT32)crRect.right;
+ Lower_Righty = (FX_INT32)crRect.bottom;
+
+ CJS_Array rcArray(m_isolate);
+ rcArray.SetElement(0,Upper_Leftx);
+ rcArray.SetElement(1,Upper_Lefty);
+ rcArray.SetElement(2,Lower_Rightx);
+ rcArray.SetElement(3,Lower_Righty);
+
+ vp << rcArray;
+ }
+
+ return TRUE;
+}
+
+void Field::SetRect(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CPDF_Rect& rect)
+{
+ ASSERT(pDocument != NULL);
+
+ CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ CFX_PtrArray FieldArray;
+ GetFormFields(pDocument, swFieldName, FieldArray);
+
+ for (int i=0,isz=FieldArray.GetSize(); i<isz; i++)
+ {
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(i);
+ ASSERT(pFormField != NULL);
+
+ if (nControlIndex < 0)
+ {
+ FX_BOOL bSet = FALSE;
+ for (int i=0, sz=pFormField->CountControls(); i<sz; i++)
+ {
+ CPDF_FormControl* pFormControl = pFormField->GetControl(i);
+ ASSERT(pFormControl != NULL);
+
+ if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl))
+ {
+ CPDF_Rect crRect = rect;
+
+ CPDF_Page* pPDFPage = pWidget->GetPDFPage();
+ ASSERT(pPDFPage != NULL);
+
+// CPDF_Page* pPDFPage = pPage->GetPage();
+// ASSERT(pPDFPage != NULL);
+
+ crRect.Intersect(pPDFPage->GetPageBBox());
+
+ if (!crRect.IsEmpty())
+ {
+ CPDF_Rect rcOld = pWidget->GetRect();
+ if (crRect.left != rcOld.left ||
+ crRect.right != rcOld.right ||
+ crRect.top != rcOld.top ||
+ crRect.bottom != rcOld.bottom)
+ {
+ pWidget->SetRect(crRect);
+ bSet = TRUE;
+ }
+ }
+ }
+ }
+
+ if (bSet) UpdateFormField(pDocument, pFormField, TRUE, TRUE, TRUE);
+ }
+ else
+ {
+ if(nControlIndex >= pFormField->CountControls()) return;
+ if (CPDF_FormControl* pFormControl = pFormField->GetControl(nControlIndex))
+ {
+ if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl))
+ {
+ CPDF_Rect crRect = rect;
+
+ CPDF_Page* pPDFPage = pWidget->GetPDFPage();
+ ASSERT(pPDFPage != NULL);
+
+// CPDF_Page* pPDFPage = pPage->GetPage();
+// ASSERT(pPDFPage != NULL);
+
+ crRect.Intersect(pPDFPage->GetPageBBox());
+
+ if (!crRect.IsEmpty())
+ {
+ CPDF_Rect rcOld = pWidget->GetRect();
+ if (crRect.left != rcOld.left ||
+ crRect.right != rcOld.right ||
+ crRect.top != rcOld.top ||
+ crRect.bottom != rcOld.bottom)
+ {
+ pWidget->SetRect(crRect);
+ UpdateFormControl(pDocument, pFormControl, TRUE, TRUE, TRUE);
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+FX_BOOL Field::required(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+
+ bool bVP;
+ vp >> bVP;
+
+ }
+ else
+ {
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON)
+ return FALSE;
+
+ if (pFormField->GetFieldFlags() & FIELDFLAG_REQUIRED)
+ vp << true;
+ else
+ vp << false;
+ }
+
+ return TRUE;
+}
+
+FX_BOOL Field::richText(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ bool bVP;
+ vp >> bVP;
+
+ if (m_bDelay)
+ {
+ AddDelay_Bool(FP_RICHTEXT, bVP);
+ }
+ else
+ {
+ Field::SetRichText(m_pDocument, m_FieldName, m_nFormControlIndex, bVP);
+ }
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD)
+ return FALSE;
+
+ if (pFormField->GetFieldFlags() & FIELDFLAG_RICHTEXT)
+ vp << true;
+ else
+ vp << false;
+ }
+
+ return TRUE;
+}
+
+void Field::SetRichText(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b)
+{
+ //Not supported.
+}
+
+FX_BOOL Field::richValue(OBJ_PROP_PARAMS)
+{
+ return TRUE;
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+ ;
+ }
+ else
+ {
+ ;
+ }
+ return TRUE;
+}
+
+void Field::SetRichValue(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex)
+{
+ //Not supported.
+}
+
+FX_BOOL Field::rotation(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ int nVP;
+ vp >> nVP;
+
+ if (m_bDelay)
+ {
+ AddDelay_Int(FP_ROTATION, nVP);
+ }
+ else
+ {
+ Field::SetRotation(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
+ }
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
+ if (!pFormControl)return FALSE;
+
+ vp << (FX_INT32)pFormControl->GetRotation();
+ }
+
+ return TRUE;
+}
+
+void Field::SetRotation(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
+{
+ //Not supported.
+}
+
+FX_BOOL Field::strokeColor(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ if (!vp.IsArrayObject())return FALSE;
+
+ CJS_Array crArray(m_isolate);
+ vp >> crArray;
+
+ CPWL_Color color;
+ color::ConvertArrayToPWLColor(crArray, color);
+
+ if (m_bDelay)
+ {
+ AddDelay_Color(FP_STROKECOLOR, color);
+ }
+ else
+ {
+ Field::SetStrokeColor(m_pDocument, m_FieldName, m_nFormControlIndex, color);
+ }
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
+ if (!pFormControl)return FALSE;
+
+ int iColorType;
+ pFormControl->GetBorderColor(iColorType);
+
+ CPWL_Color color;
+
+ if (iColorType == COLORTYPE_TRANSPARENT)
+ {
+ color = CPWL_Color(COLORTYPE_TRANSPARENT);
+ }
+ else if (iColorType == COLORTYPE_GRAY)
+ {
+ color = CPWL_Color(COLORTYPE_GRAY, pFormControl->GetOriginalBorderColor(0));
+ }
+ else if (iColorType == COLORTYPE_RGB)
+ {
+ color = CPWL_Color(COLORTYPE_RGB, pFormControl->GetOriginalBorderColor(0),
+ pFormControl->GetOriginalBorderColor(1),
+ pFormControl->GetOriginalBorderColor(2));
+ }
+ else if (iColorType == COLORTYPE_CMYK)
+ {
+ color = CPWL_Color(COLORTYPE_CMYK, pFormControl->GetOriginalBorderColor(0),
+ pFormControl->GetOriginalBorderColor(1),
+ pFormControl->GetOriginalBorderColor(2),
+ pFormControl->GetOriginalBorderColor(3));
+ }
+ else
+ return FALSE;
+
+ CJS_Array crArray(m_isolate);
+ color::ConvertPWLColorToArray(color, crArray);
+ vp << crArray;
+ }
+
+ return TRUE;
+}
+
+void Field::SetStrokeColor(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CPWL_Color& color)
+{
+ //Not supported.
+}
+
+FX_BOOL Field::style(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ CFX_ByteString csBCaption;
+ vp >> csBCaption;
+
+ if (m_bDelay)
+ {
+ AddDelay_String(FP_STYLE, csBCaption);
+ }
+ else
+ {
+ Field::SetStyle(m_pDocument, m_FieldName, m_nFormControlIndex, csBCaption);
+ }
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if (pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON &&
+ pFormField->GetFieldType() != FIELDTYPE_CHECKBOX)
+ return FALSE;
+
+ CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
+ if (!pFormControl) return FALSE;
+
+ CFX_WideString csWCaption = pFormControl->GetNormalCaption();
+ CFX_ByteString csBCaption;
+
+ switch (csWCaption[0])
+ {
+ case L'l':
+ csBCaption = "circle";
+ break;
+ case L'8':
+ csBCaption = "cross";
+ break;
+ case L'u':
+ csBCaption = "diamond";
+ break;
+ case L'n':
+ csBCaption = "square";
+ break;
+ case L'H':
+ csBCaption = "star";
+ break;
+ default: //L'4'
+ csBCaption = "check";
+ break;
+ }
+ vp << csBCaption;
+ }
+
+ return TRUE;
+}
+
+void Field::SetStyle(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex,
+ const CFX_ByteString& string)
+{
+ //Not supported.
+}
+
+FX_BOOL Field::submitName(OBJ_PROP_PARAMS)
+{
+ return TRUE;
+}
+
+FX_BOOL Field::textColor(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ CJS_Array crArray(m_isolate);
+ if (!vp.IsArrayObject())return FALSE;
+ vp >> crArray;
+
+ CPWL_Color color;
+ color::ConvertArrayToPWLColor(crArray, color);
+
+ if (m_bDelay)
+ {
+ AddDelay_Color(FP_TEXTCOLOR, color);
+ }
+ else
+ {
+ Field::SetTextColor(m_pDocument, m_FieldName, m_nFormControlIndex, color);
+ }
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
+ if (!pFormControl)return FALSE;
+
+ int iColorType;
+ FX_ARGB color;
+ CPDF_DefaultAppearance FieldAppearance = pFormControl->GetDefaultAppearance();
+ FieldAppearance.GetColor(color, iColorType);
+ FX_INT32 a,r,g,b;
+ ArgbDecode(color, a, r, g, b);
+
+ CPWL_Color crRet = CPWL_Color(COLORTYPE_RGB, r / 255.0f,
+ g / 255.0f,
+ b / 255.0f);
+
+ if (iColorType == COLORTYPE_TRANSPARENT)
+ crRet = CPWL_Color(COLORTYPE_TRANSPARENT);
+
+ CJS_Array crArray(m_isolate);
+ color::ConvertPWLColorToArray(crRet, crArray);
+ vp << crArray;
+ }
+
+ return TRUE;
+}
+
+void Field::SetTextColor(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CPWL_Color& color)
+{
+ //Not supported.
+}
+
+FX_BOOL Field::textFont(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ CFX_ByteString csFontName;
+ vp >> csFontName;
+ if (csFontName.IsEmpty()) return FALSE;
+
+ if (m_bDelay)
+ {
+ AddDelay_String(FP_TEXTFONT, csFontName);
+ }
+ else
+ {
+ Field::SetTextFont(m_pDocument, m_FieldName, m_nFormControlIndex, csFontName);
+ }
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
+ if (!pFormControl)return FALSE;
+
+ int nFieldType = pFormField->GetFieldType();
+
+ if (nFieldType == FIELDTYPE_PUSHBUTTON ||
+ nFieldType == FIELDTYPE_COMBOBOX ||
+ nFieldType == FIELDTYPE_LISTBOX ||
+ nFieldType == FIELDTYPE_TEXTFIELD)
+ {
+ CPDF_Font * pFont = pFormControl->GetDefaultControlFont();
+ if (!pFont) return FALSE;
+
+ vp << pFont->GetBaseFont();
+ }
+ else
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+void Field::SetTextFont(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CFX_ByteString& string)
+{
+ //Not supported.
+}
+
+FX_BOOL Field::textSize(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ int nVP;
+ vp >> nVP;
+
+ if (m_bDelay)
+ {
+ AddDelay_Int(FP_TEXTSIZE, nVP);
+ }
+ else
+ {
+ Field::SetTextSize(m_pDocument, m_FieldName, m_nFormControlIndex, nVP);
+ }
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
+ if (!pFormControl)return FALSE;
+
+ CPDF_DefaultAppearance FieldAppearance = pFormControl->GetDefaultAppearance();
+
+ CFX_ByteString csFontNameTag;
+ FX_FLOAT fFontSize;
+ FieldAppearance.GetFont(csFontNameTag,fFontSize);
+
+ vp << (int)fFontSize;
+ }
+
+ return TRUE;
+}
+
+void Field::SetTextSize(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number)
+{
+ //Not supported.
+}
+
+FX_BOOL Field::type(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (!vp.IsGetting()) return FALSE;
+
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ switch (pFormField->GetFieldType())
+ {
+ case FIELDTYPE_UNKNOWN:
+ vp << (FX_LPCWSTR)L"unknown";
+ break;
+ case FIELDTYPE_PUSHBUTTON:
+ vp << (FX_LPCWSTR)L"button";
+ break;
+ case FIELDTYPE_CHECKBOX:
+ vp << (FX_LPCWSTR)L"checkbox";
+ break;
+ case FIELDTYPE_RADIOBUTTON:
+ vp << (FX_LPCWSTR)L"radiobutton";
+ break;
+ case FIELDTYPE_COMBOBOX:
+ vp << (FX_LPCWSTR)L"combobox";
+ break;
+ case FIELDTYPE_LISTBOX:
+ vp << (FX_LPCWSTR)L"listbox";
+ break;
+ case FIELDTYPE_TEXTFIELD:
+ vp << (FX_LPCWSTR)L"text";
+ break;
+ case FIELDTYPE_SIGNATURE:
+ vp << (FX_LPCWSTR)L"signature";
+ break;
+ default :
+ vp << (FX_LPCWSTR)L"unknown";
+ break;
+ }
+
+ return TRUE;
+}
+
+FX_BOOL Field::userName(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ CFX_WideString swName;
+ vp >> swName;
+
+ if (m_bDelay)
+ {
+ AddDelay_WideString(FP_USERNAME, swName);
+ }
+ else
+ {
+ Field::SetUserName(m_pDocument, m_FieldName, m_nFormControlIndex, swName);
+ }
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ vp << (CFX_WideString)pFormField->GetAlternateName();
+ }
+
+ return TRUE;
+}
+
+void Field::SetUserName(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CFX_WideString& string)
+{
+ //Not supported.
+}
+
+FX_BOOL Field::value(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (vp.IsSetting())
+ {
+ if (!m_bCanSet) return FALSE;
+
+ CJS_WideStringArray strArray;
+
+ if (vp.IsArrayObject())
+ {
+ CJS_Array ValueArray(m_isolate);
+ vp.ConvertToArray(ValueArray);
+ for (int i = 0,sz = ValueArray.GetLength(); i < sz; i++)
+ {
+ CJS_Value ElementValue(m_isolate);
+ ValueArray.GetElement(i, ElementValue);
+ strArray.Add(ElementValue.operator CFX_WideString());
+ }
+ }
+ else
+ {
+ CFX_WideString swValue;
+ vp >> swValue;
+
+ strArray.Add(swValue);
+ }
+
+ if (m_bDelay)
+ {
+ AddDelay_WideStringArray(FP_VALUE, strArray);
+ }
+ else
+ {
+ Field::SetValue(m_pDocument, m_FieldName, m_nFormControlIndex, strArray);
+ }
+ }
+ else
+ {
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+
+
+ switch (pFormField->GetFieldType())
+ {
+ case FIELDTYPE_PUSHBUTTON:
+ return FALSE;
+ case FIELDTYPE_COMBOBOX:
+ case FIELDTYPE_TEXTFIELD:
+ {
+ CFX_WideString swValue = pFormField->GetValue();
+
+ double dRet;
+ FX_BOOL bDot;
+ if (CJS_PublicMethods::ConvertStringToNumber(swValue,dRet,bDot))
+ {
+ if (bDot)
+ vp << dRet;
+ else
+ vp << dRet;
+ }
+ else
+ vp << swValue;
+ }
+ break;
+ case FIELDTYPE_LISTBOX:
+ {
+ if (pFormField->CountSelectedItems() > 1)
+ {
+ CJS_Array ValueArray(m_isolate);
+ CJS_Value ElementValue(m_isolate);
+ int iIndex;
+ for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++)
+ {
+ iIndex = pFormField->GetSelectedIndex(i);
+ ElementValue = pFormField->GetOptionValue(iIndex);
+ if (FXSYS_wcslen((FX_LPCWSTR)ElementValue.operator CFX_WideString()) == 0)
+ ElementValue = pFormField->GetOptionLabel(iIndex);
+ ValueArray.SetElement(i, ElementValue);
+ }
+ vp << ValueArray;
+ }
+ else
+ {
+ CFX_WideString swValue = pFormField->GetValue();
+
+ double dRet;
+ FX_BOOL bDot;
+ if (CJS_PublicMethods::ConvertStringToNumber(swValue,dRet,bDot))
+ {
+ if (bDot)
+ vp << dRet;
+ else
+ vp << dRet;
+ }
+ else
+ vp << swValue;
+ }
+ }
+ break;
+ case FIELDTYPE_CHECKBOX:
+ case FIELDTYPE_RADIOBUTTON:
+ {
+ FX_BOOL bFind = FALSE;
+ for (int i = 0 , sz = pFormField->CountControls(); i < sz; i++)
+ {
+ if (pFormField->GetControl(i)->IsChecked())
+ {
+ CFX_WideString swValue = pFormField->GetControl(i)->GetExportValue();
+
+ double dRet;
+ FX_BOOL bDot;
+ if (CJS_PublicMethods::ConvertStringToNumber(swValue,dRet,bDot))
+ {
+ if (bDot)
+ vp << dRet;
+ else
+ vp << dRet;
+ }
+ else
+ vp << swValue;
+
+ bFind = TRUE;
+ break;
+ }
+ else
+ continue;
+ }
+ if (!bFind)
+ vp << (FX_LPCWSTR)L"Off";
+ }
+ break;
+ default:
+ vp << pFormField->GetValue();
+ break;
+ }
+ }
+
+ return TRUE;
+}
+
+void Field::SetValue(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName,
+ int nControlIndex, const CJS_WideStringArray& strArray)
+{
+ ASSERT(pDocument != NULL);
+
+ if (strArray.GetSize() < 1) return;
+
+ CFX_PtrArray FieldArray;
+ GetFormFields(pDocument, swFieldName, FieldArray);
+
+ for (int i=0,isz=FieldArray.GetSize(); i<isz; i++)
+ {
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(i);
+ ASSERT(pFormField != NULL);
+
+ if (pFormField->GetFullName().Compare(swFieldName) != 0)
+ continue;
+
+ switch (pFormField->GetFieldType())
+ {
+ case FIELDTYPE_TEXTFIELD:
+ case FIELDTYPE_COMBOBOX:
+ if (pFormField->GetValue() != strArray.GetAt(0))
+ {
+ CFX_WideString WideString = strArray.GetAt(0);
+ pFormField->SetValue(strArray.GetAt(0), TRUE);
+ UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE);
+ }
+ break;
+ case FIELDTYPE_CHECKBOX: //mantis: 0004493
+ case FIELDTYPE_RADIOBUTTON:
+ {
+ if (pFormField->GetValue() != strArray.GetAt(0))
+ {
+ pFormField->SetValue(strArray.GetAt(0), TRUE);
+ UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE);
+ }
+ }
+ break;
+ case FIELDTYPE_LISTBOX:
+ {
+ FX_BOOL bModified = FALSE;
+
+ for (int i=0,sz=strArray.GetSize(); i<sz; i++)
+ {
+ int iIndex = pFormField->FindOption(strArray.GetAt(i));
+
+ if (!pFormField->IsItemSelected(iIndex))
+ {
+ bModified = TRUE;
+ break;
+ }
+ }
+
+ if (bModified)
+ {
+ pFormField->ClearSelection(TRUE);
+ for (int i=0,sz=strArray.GetSize(); i<sz; i++)
+ {
+ int iIndex = pFormField->FindOption(strArray.GetAt(i));
+ pFormField->SetItemSelection(iIndex, TRUE, TRUE);
+ }
+
+ UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE);
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ }
+}
+
+FX_BOOL Field::valueAsString(OBJ_PROP_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (!vp.IsGetting()) return FALSE;
+
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON)
+ return FALSE;
+
+ if (pFormField->GetFieldType() == FIELDTYPE_CHECKBOX)
+ {
+ if(!pFormField->CountControls()) return FALSE;
+
+ if (pFormField->GetControl(0)->IsChecked())
+ vp << (FX_LPCWSTR)L"Yes";
+ else
+ vp << (FX_LPCWSTR)L"Off";
+ }
+ else if (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON && !(pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON))
+ {
+ for (int i=0, sz=pFormField->CountControls(); i<sz; i++)
+ {
+ if (pFormField->GetControl(i)->IsChecked())
+ {
+ vp << (FX_LPCWSTR)pFormField->GetControl(i)->GetExportValue();
+ break;
+ }
+ else
+ vp << (FX_LPCWSTR)L"Off";
+ }
+ }
+ else if (pFormField->GetFieldType() == FIELDTYPE_LISTBOX && (pFormField->CountSelectedItems() > 1))
+ {
+ vp << (FX_LPCWSTR)L"";
+ }
+ else
+ vp << (FX_LPCWSTR)pFormField->GetValue();
+
+ return TRUE;
+}
+
+/* --------------------------------- methods --------------------------------- */
+
+FX_BOOL Field::browseForFileToSubmit(OBJ_METHOD_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName, FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ CPDFDoc_Environment* pApp = m_pDocument->GetEnv();
+ ASSERT(pApp != NULL);
+
+ if ((pFormField->GetFieldFlags() & FIELDFLAG_FILESELECT) &&
+ (pFormField->GetFieldType() == FIELDTYPE_TEXTFIELD))
+ {
+ CFX_WideString wsFileName = pApp->JS_fieldBrowse();
+ if(!wsFileName.IsEmpty())
+ {
+ pFormField->SetValue(wsFileName);
+ UpdateFormField(m_pDocument, pFormField, TRUE, TRUE, TRUE);
+ }
+ }
+ else
+ return FALSE;
+
+ return TRUE;
+}
+
+
+FX_BOOL Field::buttonGetCaption(OBJ_METHOD_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ int nface = 0;
+ int iSize = params.size();
+ if ( iSize >= 1)
+ nface = (FX_INT32) params[0];
+
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
+ return FALSE;
+
+ CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
+ if (!pFormControl)return FALSE;
+
+ if (nface == 0)
+ vRet = pFormControl->GetNormalCaption();
+ else if (nface == 1)
+ vRet = pFormControl->GetDownCaption();
+ else if (nface == 2)
+ vRet = pFormControl->GetRolloverCaption();
+ else
+ return FALSE;
+
+ return TRUE;
+}
+
+//#pragma warning(disable: 4800)
+
+FX_BOOL Field::buttonGetIcon(OBJ_METHOD_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ int nface = 0;
+ int iSize = params.size();
+ if ( iSize >= 1)
+ nface = (FX_INT32) params[0];
+
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON)
+ return FALSE;
+
+ CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
+ if (!pFormControl)return FALSE;
+
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ ASSERT(pRuntime != NULL);
+
+ JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"Icon"));
+ ASSERT(pObj.IsEmpty() == FALSE);
+
+ CJS_Icon* pJS_Icon = (CJS_Icon*)JS_GetPrivate(pObj);
+ ASSERT(pJS_Icon != NULL);
+
+ Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject();
+ ASSERT(pIcon != NULL);
+
+ CPDF_Stream* pIconStream = NULL;
+ if (nface == 0)
+ pIconStream = pFormControl->GetNormalIcon();
+ else if (nface == 1)
+ pIconStream = pFormControl->GetDownIcon();
+ else if (nface == 2)
+ pIconStream = pFormControl->GetRolloverIcon();
+ else
+ return FALSE;
+
+ pIcon->SetStream(pIconStream);
+ vRet = pJS_Icon;
+
+ return TRUE;
+}
+
+//#pragma warning(default: 4800)
+
+FX_BOOL Field::buttonImportIcon(OBJ_METHOD_PARAMS)
+{
+#if 0
+ ASSERT(m_pDocument != NULL);
+
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ if (!pFormField)return FALSE;
+
+ CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
+ ASSERT(pEnv);
+
+ CFX_WideString sIconFileName = pEnv->JS_fieldBrowse();
+ if (sIconFileName.IsEmpty())
+ {
+ vRet = 1;
+ return TRUE;
+ }
+
+ CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ CPDF_Stream* pStream = pInterForm->LoadImageFromFile(sIconFileName);
+ if (!pStream)
+ {
+ vRet = -1;
+ return TRUE;
+ }
+
+ CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField);
+ if (!pFormControl)return FALSE;
+
+ pFormControl->SetNormalIcon(pStream);
+ UpdateFormControl(m_pDocument, pFormControl, TRUE, TRUE, TRUE);
+
+ vRet = 0;
+#endif // 0
+ return TRUE;
+}
+
+FX_BOOL Field::buttonSetCaption(OBJ_METHOD_PARAMS)
+{
+ return FALSE;
+}
+
+FX_BOOL Field::buttonSetIcon(OBJ_METHOD_PARAMS)
+{
+ return FALSE;
+}
+
+FX_BOOL Field::checkThisBox(OBJ_METHOD_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (!m_bCanSet) return FALSE;
+
+ int iSize = params.size();
+ int nWidget = -1;
+ if ( iSize >= 1)
+ nWidget= (FX_INT32) params[0];
+ else
+ return FALSE;
+ FX_BOOL bCheckit = TRUE;
+ if ( iSize >= 2)
+ bCheckit = params[1];
+
+
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if (pFormField->GetFieldType() != FIELDTYPE_CHECKBOX && pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON)
+ return FALSE;
+ if(nWidget <0 || nWidget >= pFormField->CountControls())
+ return FALSE;
+ if (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON)
+ pFormField->CheckControl(nWidget, bCheckit, TRUE);
+ else
+ pFormField->CheckControl(nWidget, bCheckit, TRUE);
+
+ UpdateFormField(m_pDocument, pFormField, TRUE, TRUE, TRUE);
+
+ return TRUE;
+}
+
+FX_BOOL Field::clearItems(OBJ_METHOD_PARAMS)
+{
+ return TRUE;
+}
+
+FX_BOOL Field::defaultIsChecked(OBJ_METHOD_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (!m_bCanSet) return FALSE;
+
+ int iSize = params.size();
+ int nWidget = -1;
+ if ( iSize >= 1)
+ nWidget= (FX_INT32) params[0];
+ else
+ return FALSE;
+ //FX_BOOL bIsDefaultChecked = TRUE;
+ //if ( iSize >= 2)
+ // bIsDefaultChecked = params[1];
+
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if(nWidget <0 || nWidget >= pFormField->CountControls())
+ {
+ vRet = FALSE;
+ return FALSE;
+ }
+ if ((pFormField->GetFieldType() == FIELDTYPE_CHECKBOX)
+ || (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON))
+ {
+
+ vRet = TRUE;
+ }
+ else
+ vRet = FALSE;
+
+ return TRUE;
+}
+
+FX_BOOL Field::deleteItemAt(OBJ_METHOD_PARAMS)
+{
+ return TRUE;
+}
+
+int JS_COMPARESTRING(CFX_WideString* ps1, CFX_WideString* ps2)
+{
+ ASSERT(ps1 != NULL);
+ ASSERT(ps2 != NULL);
+
+ return ps1->Compare(*ps2);
+}
+
+
+FX_BOOL Field::getArray(OBJ_METHOD_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CGW_ArrayTemplate<CFX_WideString*> swSort;
+
+ for (int i=0,sz=FieldArray.GetSize(); i<sz; i++)
+ {
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(i);
+ ASSERT(pFormField != NULL);
+
+ swSort.Add(new CFX_WideString(pFormField->GetFullName()));
+
+ }
+ swSort.Sort(JS_COMPARESTRING);
+
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ ASSERT(pRuntime != NULL);
+
+ CJS_Array FormFieldArray(m_isolate);
+ for (int j=0,jsz = swSort.GetSize(); j<jsz; j++)
+ {
+ CFX_WideString* pStr = swSort.GetAt(j);
+
+ JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"Field"));
+ ASSERT(pObj.IsEmpty() == FALSE);
+
+ CJS_Field* pJSField = (CJS_Field*)JS_GetPrivate(pObj);
+ ASSERT(pJSField != NULL);
+
+ Field* pField = (Field*)pJSField->GetEmbedObject();
+ ASSERT(pField != NULL);
+
+ pField->AttachField(this->m_pJSDoc, *pStr);
+
+ CJS_Value FormFieldValue(m_isolate);
+ FormFieldValue = pJSField;
+ FormFieldArray.SetElement(j, FormFieldValue);
+
+ delete pStr;
+ }
+
+ vRet = FormFieldArray;
+ swSort.RemoveAll();
+ return TRUE;
+}
+
+FX_BOOL Field::getItemAt(OBJ_METHOD_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ int nIdx = -1;
+ if (params.size() >=1)
+ nIdx = (FX_INT32) params[0];
+ FX_BOOL bExport = TRUE;
+ int iSize = params.size();
+ if ( iSize >= 2)
+ {
+ bExport =(FX_BOOL) params[1];
+ }
+
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if ((pFormField->GetFieldType() == FIELDTYPE_LISTBOX)
+ || (pFormField->GetFieldType() == FIELDTYPE_COMBOBOX))
+ {
+ if (nIdx == -1 || nIdx > pFormField->CountOptions())
+ nIdx = pFormField->CountOptions() -1;
+ if (bExport)
+ {
+ CFX_WideString strval = pFormField->GetOptionValue(nIdx);
+ if (strval.IsEmpty())
+ vRet = pFormField->GetOptionLabel(nIdx);
+ else
+ vRet = strval;
+ }
+ else
+ vRet = pFormField->GetOptionLabel(nIdx);
+ }
+ else
+ return FALSE;
+
+ return TRUE;
+}
+
+FX_BOOL Field::getLock(OBJ_METHOD_PARAMS)
+{
+ return FALSE;
+}
+
+FX_BOOL Field::insertItemAt(OBJ_METHOD_PARAMS)
+{
+ return TRUE;
+}
+
+FX_BOOL Field::isBoxChecked(OBJ_METHOD_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ int nIndex = -1;
+ if (params.size() >=1)
+ nIndex = (FX_INT32) params[0];
+
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if(nIndex <0 || nIndex >= pFormField->CountControls())
+ {
+ vRet = FALSE;
+ return FALSE;
+ }
+
+ if ((pFormField->GetFieldType() == FIELDTYPE_CHECKBOX)
+ || (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON))
+ {
+ if (pFormField->GetControl(nIndex)->IsChecked() !=0 )
+ vRet = TRUE;
+ else
+ vRet = FALSE;
+ }
+ else
+ vRet = FALSE;
+
+ return TRUE;
+}
+
+FX_BOOL Field::isDefaultChecked(OBJ_METHOD_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ int nIndex = -1;
+ if (params.size() >=1)
+ nIndex = (FX_INT32) params[0];
+
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ if(nIndex <0 || nIndex >= pFormField->CountControls())
+ {
+ vRet = FALSE;
+ return FALSE;
+ }
+ if ((pFormField->GetFieldType() == FIELDTYPE_CHECKBOX)
+ || (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON))
+ {
+ if (pFormField->GetControl(nIndex)->IsDefaultChecked() != 0)
+ vRet = TRUE;
+ else
+ vRet = FALSE;
+ }
+ else
+ vRet = FALSE;
+
+ return TRUE;
+}
+
+FX_BOOL Field::setAction(OBJ_METHOD_PARAMS)
+{
+ return TRUE;
+}
+
+FX_BOOL Field::setFocus(OBJ_METHOD_PARAMS)
+{
+ ASSERT(m_pDocument != NULL);
+
+ CFX_PtrArray FieldArray;
+ GetFormFields(m_FieldName,FieldArray);
+ if (FieldArray.GetSize() <= 0) return FALSE;
+
+ CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0);
+ ASSERT(pFormField != NULL);
+
+ FX_INT32 nCount = pFormField->CountControls();
+
+ if (nCount < 1) return FALSE;
+
+ CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ CPDFSDK_Widget* pWidget = NULL;
+ if (nCount == 1)
+ {
+ pWidget = pInterForm->GetWidget(pFormField->GetControl(0));
+ }
+ else
+ {
+ CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
+ ASSERT(pEnv);
+ CPDF_Page* pPage = (CPDF_Page*)pEnv->FFI_GetCurrentPage(m_pDocument->GetDocument());
+ if(!pPage)
+ return FALSE;
+ if (CPDFSDK_PageView* pCurPageView = m_pDocument->GetPageView(pPage))
+ {
+ for (FX_INT32 i=0; i<nCount; i++)
+ {
+ if (CPDFSDK_Widget* pTempWidget = pInterForm->GetWidget(pFormField->GetControl(i)))
+ {
+ if (pTempWidget->GetPDFPage() == pCurPageView->GetPDFPage())
+ {
+ pWidget = pTempWidget;
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ if (pWidget)
+ {
+ m_pDocument->SetFocusAnnot(pWidget);
+ }
+
+ return TRUE;
+}
+
+FX_BOOL Field::setItems(OBJ_METHOD_PARAMS)
+{
+ return TRUE;
+}
+
+FX_BOOL Field::setLock(OBJ_METHOD_PARAMS)
+{
+ return FALSE;
+}
+
+FX_BOOL Field::signatureGetModifications(OBJ_METHOD_PARAMS)
+{
+ return FALSE;
+}
+
+FX_BOOL Field::signatureGetSeedValue(OBJ_METHOD_PARAMS)
+{
+ return FALSE;
+}
+
+FX_BOOL Field::signatureInfo(OBJ_METHOD_PARAMS)
+{
+ return FALSE;
+}
+
+FX_BOOL Field::signatureSetSeedValue(OBJ_METHOD_PARAMS)
+{
+ return FALSE;
+}
+
+FX_BOOL Field::signatureSign(OBJ_METHOD_PARAMS)
+{
+ return FALSE;
+}
+
+FX_BOOL Field::signatureValidate(OBJ_METHOD_PARAMS)
+{
+ return FALSE;
+}
+
+FX_BOOL Field::source(OBJ_PROP_PARAMS)
+{
+ if (vp.IsGetting())
+ {
+ vp << (CJS_Object*)NULL;
+ }
+
+ return TRUE;
+}
+
+/////////////////////////////////////////// delay /////////////////////////////////////////////
+
+void Field::AddDelay_Int(enum FIELD_PROP prop, FX_INT32 n)
+{
+ ASSERT(m_pJSDoc != NULL);
+
+ CJS_DelayData* pNewData = new CJS_DelayData;
+ pNewData->sFieldName = m_FieldName;
+ pNewData->nControlIndex = m_nFormControlIndex;
+ pNewData->eProp = prop;
+ pNewData->num = n;
+
+ m_pJSDoc->AddDelayData(pNewData);
+}
+
+void Field::AddDelay_Bool(enum FIELD_PROP prop,bool b)
+{
+ ASSERT(m_pJSDoc != NULL);
+
+ CJS_DelayData* pNewData = new CJS_DelayData;
+ pNewData->sFieldName = m_FieldName;
+ pNewData->nControlIndex = m_nFormControlIndex;
+ pNewData->eProp = prop;
+ pNewData->b = b;
+
+ m_pJSDoc->AddDelayData(pNewData);
+}
+
+void Field::AddDelay_String(enum FIELD_PROP prop, const CFX_ByteString& string)
+{
+ ASSERT(m_pJSDoc != NULL);
+
+ CJS_DelayData* pNewData = new CJS_DelayData;
+ pNewData->sFieldName = m_FieldName;
+ pNewData->nControlIndex = m_nFormControlIndex;
+ pNewData->eProp = prop;
+ pNewData->string = string;
+
+ m_pJSDoc->AddDelayData(pNewData);
+}
+
+void Field::AddDelay_WideString(enum FIELD_PROP prop, const CFX_WideString& string)
+{
+ ASSERT(m_pJSDoc != NULL);
+
+ CJS_DelayData* pNewData = new CJS_DelayData;
+ pNewData->sFieldName = m_FieldName;
+ pNewData->nControlIndex = m_nFormControlIndex;
+ pNewData->eProp = prop;
+ pNewData->widestring = string;
+
+ m_pJSDoc->AddDelayData(pNewData);
+}
+
+void Field::AddDelay_Rect(enum FIELD_PROP prop, const CPDF_Rect& rect)
+{
+ ASSERT(m_pJSDoc != NULL);
+
+ CJS_DelayData* pNewData = new CJS_DelayData;
+ pNewData->sFieldName = m_FieldName;
+ pNewData->nControlIndex = m_nFormControlIndex;
+ pNewData->eProp = prop;
+ pNewData->rect = rect;
+
+ m_pJSDoc->AddDelayData(pNewData);
+}
+
+void Field::AddDelay_Color(enum FIELD_PROP prop, const CPWL_Color& color)
+{
+ ASSERT(m_pJSDoc != NULL);
+
+ CJS_DelayData* pNewData = new CJS_DelayData;
+ pNewData->sFieldName = m_FieldName;
+ pNewData->nControlIndex = m_nFormControlIndex;
+ pNewData->eProp = prop;
+ pNewData->color = color;
+
+ m_pJSDoc->AddDelayData(pNewData);
+}
+
+void Field::AddDelay_WordArray(enum FIELD_PROP prop, const CFX_DWordArray& array)
+{
+ ASSERT(m_pJSDoc != NULL);
+
+ CJS_DelayData* pNewData = new CJS_DelayData;
+ pNewData->sFieldName = m_FieldName;
+ pNewData->nControlIndex = m_nFormControlIndex;
+ pNewData->eProp = prop;
+
+ for (int i=0,sz=array.GetSize(); i<sz; i++)
+ pNewData->wordarray.Add(array.GetAt(i));
+
+ m_pJSDoc->AddDelayData(pNewData);
+}
+
+void Field::AddDelay_WideStringArray(enum FIELD_PROP prop, const CJS_WideStringArray& array)
+{
+ ASSERT(m_pJSDoc != NULL);
+
+ CJS_DelayData* pNewData = new CJS_DelayData;
+ pNewData->sFieldName = m_FieldName;
+ pNewData->nControlIndex = m_nFormControlIndex;
+ pNewData->eProp = prop;
+ for (int i=0,sz=array.GetSize(); i<sz; i++)
+ pNewData->widestringarray.Add(array.GetAt(i));
+
+ m_pJSDoc->AddDelayData(pNewData);
+}
+
+void Field::DoDelay(CPDFSDK_Document* pDocument, CJS_DelayData* pData)
+{
+ ASSERT(pDocument != NULL);
+ ASSERT(pData != NULL);
+
+ switch (pData->eProp)
+ {
+ case FP_ALIGNMENT:
+ Field::SetAlignment(pDocument, pData->sFieldName, pData->nControlIndex, pData->string);
+ break;
+ case FP_BORDERSTYLE:
+ Field::SetBorderStyle(pDocument, pData->sFieldName, pData->nControlIndex, pData->string);
+ break;
+ case FP_BUTTONALIGNX:
+ Field::SetButtonAlignX(pDocument, pData->sFieldName, pData->nControlIndex, pData->num);
+ break;
+ case FP_BUTTONALIGNY:
+ Field::SetButtonAlignY(pDocument, pData->sFieldName, pData->nControlIndex, pData->num);
+ break;
+ case FP_BUTTONFITBOUNDS:
+ Field::SetButtonFitBounds(pDocument, pData->sFieldName, pData->nControlIndex, pData->b);
+ break;
+ case FP_BUTTONPOSITION:
+ Field::SetButtonPosition(pDocument, pData->sFieldName, pData->nControlIndex, pData->num);
+ break;
+ case FP_BUTTONSCALEHOW:
+ Field::SetButtonScaleHow(pDocument, pData->sFieldName, pData->nControlIndex, pData->num);
+ break;
+ case FP_BUTTONSCALEWHEN:
+ Field::SetButtonScaleWhen(pDocument, pData->sFieldName, pData->nControlIndex, pData->num);
+ break;
+ case FP_CALCORDERINDEX:
+ Field::SetCalcOrderIndex(pDocument, pData->sFieldName, pData->nControlIndex, pData->num);
+ break;
+ case FP_CHARLIMIT:
+ Field::SetCharLimit(pDocument, pData->sFieldName, pData->nControlIndex, pData->num);
+ break;
+ case FP_COMB:
+ Field::SetComb(pDocument, pData->sFieldName, pData->nControlIndex, pData->b);
+ break;
+ case FP_COMMITONSELCHANGE:
+ Field::SetCommitOnSelChange(pDocument, pData->sFieldName, pData->nControlIndex, pData->b);
+ break;
+ case FP_CURRENTVALUEINDICES:
+ Field::SetCurrentValueIndices(pDocument, pData->sFieldName, pData->nControlIndex, pData->wordarray);
+ break;
+ case FP_DEFAULTVALUE:
+ Field::SetDefaultValue(pDocument, pData->sFieldName, pData->nControlIndex, pData->widestring);
+ break;
+ case FP_DONOTSCROLL:
+ Field::SetDoNotScroll(pDocument, pData->sFieldName, pData->nControlIndex, pData->b);
+ break;
+ case FP_DISPLAY:
+ Field::SetDisplay(pDocument, pData->sFieldName, pData->nControlIndex, pData->num);
+ break;
+ case FP_FILLCOLOR:
+ Field::SetFillColor(pDocument, pData->sFieldName, pData->nControlIndex, pData->color);
+ break;
+ case FP_HIDDEN:
+ Field::SetHidden(pDocument, pData->sFieldName, pData->nControlIndex, pData->b);
+ break;
+ case FP_HIGHLIGHT:
+ Field::SetHighlight(pDocument, pData->sFieldName, pData->nControlIndex, pData->string);
+ break;
+ case FP_LINEWIDTH:
+ Field::SetLineWidth(pDocument, pData->sFieldName, pData->nControlIndex, pData->num);
+ break;
+ case FP_MULTILINE:
+ Field::SetMultiline(pDocument, pData->sFieldName, pData->nControlIndex, pData->b);
+ break;
+ case FP_MULTIPLESELECTION:
+ Field::SetMultipleSelection(pDocument, pData->sFieldName, pData->nControlIndex, pData->b);
+ break;
+ case FP_PASSWORD:
+ Field::SetPassword(pDocument, pData->sFieldName, pData->nControlIndex, pData->b);
+ break;
+ case FP_RECT:
+ Field::SetRect(pDocument, pData->sFieldName, pData->nControlIndex, pData->rect);
+ break;
+ case FP_RICHTEXT:
+ Field::SetRichText(pDocument, pData->sFieldName, pData->nControlIndex, pData->b);
+ break;
+ case FP_RICHVALUE:
+ break;
+ case FP_ROTATION:
+ Field::SetRotation(pDocument, pData->sFieldName, pData->nControlIndex, pData->num);
+ break;
+ case FP_STROKECOLOR:
+ Field::SetStrokeColor(pDocument, pData->sFieldName, pData->nControlIndex, pData->color);
+ break;
+ case FP_STYLE:
+ Field::SetStyle(pDocument, pData->sFieldName, pData->nControlIndex, pData->string);
+ break;
+ case FP_TEXTCOLOR:
+ Field::SetTextColor(pDocument, pData->sFieldName, pData->nControlIndex, pData->color);
+ break;
+ case FP_TEXTFONT:
+ Field::SetTextFont(pDocument, pData->sFieldName, pData->nControlIndex, pData->string);
+ break;
+ case FP_TEXTSIZE:
+ Field::SetTextSize(pDocument, pData->sFieldName, pData->nControlIndex, pData->num);
+ break;
+ case FP_USERNAME:
+ Field::SetUserName(pDocument, pData->sFieldName, pData->nControlIndex, pData->widestring);
+ break;
+ case FP_VALUE:
+ Field::SetValue(pDocument, pData->sFieldName, pData->nControlIndex, pData->widestringarray);
+ break;
+ }
+}
+
+#define JS_FIELD_MINWIDTH 1
+#define JS_FIELD_MINHEIGHT 1
+
+void Field::AddField(CPDFSDK_Document* pDocument, int nPageIndex, int nFieldType,
+ const CFX_WideString& sName, const CPDF_Rect& rcCoords)
+{
+ //Not supported.
+}
+
diff --git a/fpdfsdk/src/javascript/Icon.cpp b/fpdfsdk/src/javascript/Icon.cpp
index 418fcd53d5..286980c205 100644
--- a/fpdfsdk/src/javascript/Icon.cpp
+++ b/fpdfsdk/src/javascript/Icon.cpp
@@ -1,67 +1,67 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/javascript/JavaScript.h"
-#include "../../include/javascript/IJavaScript.h"
-#include "../../include/javascript/JS_Define.h"
-#include "../../include/javascript/JS_Object.h"
-#include "../../include/javascript/JS_Value.h"
-#include "../../include/javascript/Icon.h"
-
-/* ---------------------- Icon ---------------------- */
-
-BEGIN_JS_STATIC_CONST(CJS_Icon)
-END_JS_STATIC_CONST()
-
-BEGIN_JS_STATIC_PROP(CJS_Icon)
- JS_STATIC_PROP_ENTRY(name)
-END_JS_STATIC_PROP()
-
-BEGIN_JS_STATIC_METHOD(CJS_Icon)
-END_JS_STATIC_METHOD()
-
-IMPLEMENT_JS_CLASS(CJS_Icon,Icon)
-
-Icon::Icon(CJS_Object* pJSObject) : CJS_EmbedObj(pJSObject),
- m_pIconStream(NULL),
- m_swIconName(L"")
-{
-}
-
-Icon::~Icon()
-{
-
-}
-
-void Icon::SetStream(CPDF_Stream* pIconStream)
-{
- if(pIconStream)
- m_pIconStream = pIconStream;
-}
-
-CPDF_Stream* Icon::GetStream()
-{
- return m_pIconStream;
-}
-
-void Icon::SetIconName(CFX_WideString name)
-{
- m_swIconName = name;
-}
-
-CFX_WideString Icon::GetIconName()
-{
- return m_swIconName;
-}
-
-FX_BOOL Icon::name(OBJ_PROP_PARAMS)
-{
- if(!vp.IsGetting())return FALSE;
-
- vp << m_swIconName;
- return TRUE;
-}
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/javascript/JavaScript.h"
+#include "../../include/javascript/IJavaScript.h"
+#include "../../include/javascript/JS_Define.h"
+#include "../../include/javascript/JS_Object.h"
+#include "../../include/javascript/JS_Value.h"
+#include "../../include/javascript/Icon.h"
+
+/* ---------------------- Icon ---------------------- */
+
+BEGIN_JS_STATIC_CONST(CJS_Icon)
+END_JS_STATIC_CONST()
+
+BEGIN_JS_STATIC_PROP(CJS_Icon)
+ JS_STATIC_PROP_ENTRY(name)
+END_JS_STATIC_PROP()
+
+BEGIN_JS_STATIC_METHOD(CJS_Icon)
+END_JS_STATIC_METHOD()
+
+IMPLEMENT_JS_CLASS(CJS_Icon,Icon)
+
+Icon::Icon(CJS_Object* pJSObject) : CJS_EmbedObj(pJSObject),
+ m_pIconStream(NULL),
+ m_swIconName(L"")
+{
+}
+
+Icon::~Icon()
+{
+
+}
+
+void Icon::SetStream(CPDF_Stream* pIconStream)
+{
+ if(pIconStream)
+ m_pIconStream = pIconStream;
+}
+
+CPDF_Stream* Icon::GetStream()
+{
+ return m_pIconStream;
+}
+
+void Icon::SetIconName(CFX_WideString name)
+{
+ m_swIconName = name;
+}
+
+CFX_WideString Icon::GetIconName()
+{
+ return m_swIconName;
+}
+
+FX_BOOL Icon::name(OBJ_PROP_PARAMS)
+{
+ if(!vp.IsGetting())return FALSE;
+
+ vp << m_swIconName;
+ return TRUE;
+}
+
diff --git a/fpdfsdk/src/javascript/JS_Context.cpp b/fpdfsdk/src/javascript/JS_Context.cpp
index c0d4e0847e..e34ffb51ba 100644
--- a/fpdfsdk/src/javascript/JS_Context.cpp
+++ b/fpdfsdk/src/javascript/JS_Context.cpp
@@ -1,364 +1,364 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/javascript/JavaScript.h"
-#include "../../include/javascript/IJavaScript.h"
-//#include "../../include/javascript/JS_ResMgr.h"
-#include "../../include/javascript/JS_Context.h"
-#include "../../include/javascript/JS_EventHandler.h"
-#include "../../include/javascript/JS_Runtime.h"
-#include "../../include/javascript/resource.h"
-
-/* -------------------------- CJS_Context -------------------------- */
-
-CJS_Context::CJS_Context(CJS_Runtime* pRuntime) :
- m_pRuntime(pRuntime),
- m_bBusy(FALSE),
- m_bMsgBoxEnable(TRUE)
-{
- m_pEventHandler = new CJS_EventHandler(this);
-}
-
-CJS_Context::~CJS_Context(void)
-{
- if (m_pEventHandler)
- {
- delete m_pEventHandler;
- m_pEventHandler = NULL;
- }
-}
-
-CPDFSDK_Document* CJS_Context::GetReaderDocument()
-{
- ASSERT(m_pRuntime != NULL);
-
- return m_pRuntime->GetReaderDocument();
-}
-
-CPDFDoc_Environment* CJS_Context::GetReaderApp()
-{
- ASSERT(m_pRuntime != NULL);
-
- return m_pRuntime->GetReaderApp();
-}
-
-FX_BOOL CJS_Context::DoJob(int nMode, const CFX_WideString& script, CFX_WideString& info)
-{
- if (m_bBusy)
- {
- info = JSGetStringFromID(this, IDS_STRING_JSBUSY);
- return FALSE;
- }
-
- m_bBusy = TRUE;
-
- ASSERT(m_pRuntime != NULL);
- ASSERT(m_pEventHandler != NULL);
- ASSERT(m_pEventHandler->IsValid());
-
- if (!m_pRuntime->AddEventToLoop(m_pEventHandler->TargetName(), m_pEventHandler->EventType()))
- {
- info = JSGetStringFromID(this, IDS_STRING_JSEVENT);
- return FALSE;
- }
-
- FXJSErr error ={NULL,NULL, 0};
- int nRet = 0;
-
- try
- {
- if (script.GetLength() > 0)
- {
- if (nMode == 0)
- {
- nRet = JS_Execute(*m_pRuntime, this, script, script.GetLength(), &error);
- }
- else
- {
- nRet = JS_Parse(*m_pRuntime, this, script, script.GetLength(), &error);
- }
- }
-
- if (nRet < 0)
- {
- CFX_WideString sLine;
- sLine.Format((FX_LPCWSTR)L"[ Line: %05d { %s } ] : %s",error.linnum-1,error.srcline,error.message);
-
-// TRACE(L"/* -------------- JS Error -------------- */\n");
-// TRACE(sLine);
-// TRACE(L"\n");
- //CFX_ByteString sTemp = CFX_ByteString::FromUnicode(error.message);
- info += sLine;
- }
- else
- {
- info = JSGetStringFromID(this, IDS_STRING_RUN);
- }
-
- }
- catch (...)
- {
- info = JSGetStringFromID(this, IDS_STRING_UNHANDLED);
- nRet = -1;
- }
-
- m_pRuntime->RemoveEventInLoop(m_pEventHandler->TargetName(), m_pEventHandler->EventType());
-
- m_pEventHandler->Destroy();
- m_bBusy = FALSE;
-
- return nRet >= 0;
-}
-
-FX_BOOL CJS_Context::RunScript(const CFX_WideString& script, CFX_WideString& info)
-{
- v8::Isolate::Scope isolate_scope(m_pRuntime->GetIsolate());
- v8::HandleScope handle_scope(m_pRuntime->GetIsolate());
- v8::Local<v8::Context> context = m_pRuntime->NewJSContext();
- v8::Context::Scope context_scope(context);
-
- return DoJob(0, script, info);
-}
-
-FX_BOOL CJS_Context::Compile(const CFX_WideString& script, CFX_WideString& info)
-{
- v8::Isolate::Scope isolate_scope(m_pRuntime->GetIsolate());
- v8::HandleScope handle_scope(m_pRuntime->GetIsolate());
- v8::Local<v8::Context> context = m_pRuntime->NewJSContext();
- v8::Context::Scope context_scope(context);
-
- return DoJob(1, script, info);
-}
-
-void CJS_Context::OnApp_Init()
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnApp_Init();
-}
-
-void CJS_Context::OnDoc_Open(CPDFSDK_Document* pDoc, const CFX_WideString &strTargetName)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnDoc_Open(pDoc,strTargetName);
-}
-
-void CJS_Context::OnDoc_WillPrint(CPDFSDK_Document* pDoc)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnDoc_WillPrint(pDoc);
-}
-
-void CJS_Context::OnDoc_DidPrint(CPDFSDK_Document* pDoc)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnDoc_DidPrint(pDoc);
-}
-
-void CJS_Context::OnDoc_WillSave(CPDFSDK_Document* pDoc)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnDoc_WillSave(pDoc);
-}
-
-void CJS_Context::OnDoc_DidSave(CPDFSDK_Document* pDoc)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnDoc_DidSave(pDoc);
-}
-
-void CJS_Context::OnDoc_WillClose(CPDFSDK_Document* pDoc)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnDoc_WillClose(pDoc);
-}
-
-void CJS_Context::OnPage_Open(CPDFSDK_Document* pTarget)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnPage_Open(pTarget);
-}
-
-void CJS_Context::OnPage_Close(CPDFSDK_Document* pTarget)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnPage_Close(pTarget);
-}
-
-void CJS_Context::OnPage_InView(CPDFSDK_Document* pTarget)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnPage_InView(pTarget);
-}
-
-void CJS_Context::OnPage_OutView(CPDFSDK_Document* pTarget)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnPage_OutView(pTarget);
-}
-
-void CJS_Context::OnField_MouseDown(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField *pTarget)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnField_MouseDown(bModifier, bShift, pTarget);
-}
-
-void CJS_Context::OnField_MouseEnter(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField *pTarget)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnField_MouseEnter(bModifier, bShift, pTarget);
-}
-
-void CJS_Context::OnField_MouseExit(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField *pTarget)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnField_MouseExit(bModifier, bShift, pTarget);
-}
-
-void CJS_Context::OnField_MouseUp(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField *pTarget)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnField_MouseUp(bModifier, bShift, pTarget);
-}
-
-void CJS_Context::OnField_Focus(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget, const CFX_WideString& Value)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnField_Focus(bModifier, bShift, pTarget, Value);
-}
-
-void CJS_Context::OnField_Blur(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget, const CFX_WideString& Value)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnField_Blur(bModifier, bShift, pTarget, Value);
-}
-
-void CJS_Context::OnField_Calculate(CPDF_FormField* pSource, CPDF_FormField* pTarget, CFX_WideString& Value, FX_BOOL& bRc)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnField_Calculate(pSource, pTarget, Value, bRc);
-}
-
-void CJS_Context::OnField_Format(int nCommitKey, CPDF_FormField* pTarget, CFX_WideString& Value, FX_BOOL bWillCommit)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnField_Format(nCommitKey, pTarget, Value, bWillCommit);
-}
-
-
-void CJS_Context::OnField_Keystroke(int nCommitKey, CFX_WideString& strChange, const CFX_WideString& strChangeEx,
- FX_BOOL bKeyDown, FX_BOOL bModifier, int &nSelEnd,int &nSelStart,
- FX_BOOL bShift, CPDF_FormField* pTarget, CFX_WideString& Value,
- FX_BOOL bWillCommit, FX_BOOL bFieldFull, FX_BOOL& bRc)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnField_Keystroke(nCommitKey, strChange, strChangeEx, bKeyDown,
- bModifier, nSelEnd, nSelStart, bShift, pTarget, Value, bWillCommit, bFieldFull, bRc);
-}
-
-void CJS_Context::OnField_Validate(CFX_WideString& strChange,const CFX_WideString& strChangeEx,
- FX_BOOL bKeyDown, FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget,
- CFX_WideString& Value, FX_BOOL& bRc)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnField_Validate(strChange, strChangeEx, bKeyDown, bModifier, bShift, pTarget, Value, bRc);
-}
-
-void CJS_Context::OnScreen_Focus(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnScreen_Focus(bModifier, bShift, pScreen);
-}
-
-void CJS_Context::OnScreen_Blur(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnScreen_Blur(bModifier, bShift, pScreen);
-}
-
-void CJS_Context::OnScreen_Open(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnScreen_Open(bModifier, bShift, pScreen);
-}
-
-void CJS_Context::OnScreen_Close(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnScreen_Close(bModifier, bShift, pScreen);
-}
-
-void CJS_Context::OnScreen_MouseDown(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnScreen_MouseDown(bModifier, bShift, pScreen);
-}
-
-void CJS_Context::OnScreen_MouseUp(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnScreen_MouseUp(bModifier, bShift, pScreen);
-}
-
-void CJS_Context::OnScreen_MouseEnter(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnScreen_MouseEnter(bModifier, bShift, pScreen);
-}
-
-void CJS_Context::OnScreen_MouseExit(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnScreen_MouseExit(bModifier, bShift, pScreen);
-}
-
-void CJS_Context::OnScreen_InView(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnScreen_InView(bModifier, bShift, pScreen);
-}
-
-void CJS_Context::OnScreen_OutView(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnScreen_OutView(bModifier, bShift, pScreen);
-}
-
-void CJS_Context::OnBookmark_MouseUp(CPDF_Bookmark* pBookMark)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnBookmark_MouseUp(pBookMark);
-}
-
-void CJS_Context::OnLink_MouseUp(CPDFSDK_Document* pTarget)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnLink_MouseUp(pTarget);
-}
-
-void CJS_Context::OnConsole_Exec()
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnConsole_Exec();
-}
-
-void CJS_Context::OnExternal_Exec()
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnExternal_Exec();
-}
-
-void CJS_Context::OnBatchExec(CPDFSDK_Document* pTarget)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnBatchExec(pTarget);
-}
-
-void CJS_Context::OnMenu_Exec(CPDFSDK_Document* pTarget,const CFX_WideString& strTargetName)
-{
- ASSERT(m_pEventHandler != NULL);
- m_pEventHandler->OnMenu_Exec(pTarget, strTargetName);
-}
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/javascript/JavaScript.h"
+#include "../../include/javascript/IJavaScript.h"
+//#include "../../include/javascript/JS_ResMgr.h"
+#include "../../include/javascript/JS_Context.h"
+#include "../../include/javascript/JS_EventHandler.h"
+#include "../../include/javascript/JS_Runtime.h"
+#include "../../include/javascript/resource.h"
+
+/* -------------------------- CJS_Context -------------------------- */
+
+CJS_Context::CJS_Context(CJS_Runtime* pRuntime) :
+ m_pRuntime(pRuntime),
+ m_bBusy(FALSE),
+ m_bMsgBoxEnable(TRUE)
+{
+ m_pEventHandler = new CJS_EventHandler(this);
+}
+
+CJS_Context::~CJS_Context(void)
+{
+ if (m_pEventHandler)
+ {
+ delete m_pEventHandler;
+ m_pEventHandler = NULL;
+ }
+}
+
+CPDFSDK_Document* CJS_Context::GetReaderDocument()
+{
+ ASSERT(m_pRuntime != NULL);
+
+ return m_pRuntime->GetReaderDocument();
+}
+
+CPDFDoc_Environment* CJS_Context::GetReaderApp()
+{
+ ASSERT(m_pRuntime != NULL);
+
+ return m_pRuntime->GetReaderApp();
+}
+
+FX_BOOL CJS_Context::DoJob(int nMode, const CFX_WideString& script, CFX_WideString& info)
+{
+ if (m_bBusy)
+ {
+ info = JSGetStringFromID(this, IDS_STRING_JSBUSY);
+ return FALSE;
+ }
+
+ m_bBusy = TRUE;
+
+ ASSERT(m_pRuntime != NULL);
+ ASSERT(m_pEventHandler != NULL);
+ ASSERT(m_pEventHandler->IsValid());
+
+ if (!m_pRuntime->AddEventToLoop(m_pEventHandler->TargetName(), m_pEventHandler->EventType()))
+ {
+ info = JSGetStringFromID(this, IDS_STRING_JSEVENT);
+ return FALSE;
+ }
+
+ FXJSErr error ={NULL,NULL, 0};
+ int nRet = 0;
+
+ try
+ {
+ if (script.GetLength() > 0)
+ {
+ if (nMode == 0)
+ {
+ nRet = JS_Execute(*m_pRuntime, this, script, script.GetLength(), &error);
+ }
+ else
+ {
+ nRet = JS_Parse(*m_pRuntime, this, script, script.GetLength(), &error);
+ }
+ }
+
+ if (nRet < 0)
+ {
+ CFX_WideString sLine;
+ sLine.Format((FX_LPCWSTR)L"[ Line: %05d { %s } ] : %s",error.linnum-1,error.srcline,error.message);
+
+// TRACE(L"/* -------------- JS Error -------------- */\n");
+// TRACE(sLine);
+// TRACE(L"\n");
+ //CFX_ByteString sTemp = CFX_ByteString::FromUnicode(error.message);
+ info += sLine;
+ }
+ else
+ {
+ info = JSGetStringFromID(this, IDS_STRING_RUN);
+ }
+
+ }
+ catch (...)
+ {
+ info = JSGetStringFromID(this, IDS_STRING_UNHANDLED);
+ nRet = -1;
+ }
+
+ m_pRuntime->RemoveEventInLoop(m_pEventHandler->TargetName(), m_pEventHandler->EventType());
+
+ m_pEventHandler->Destroy();
+ m_bBusy = FALSE;
+
+ return nRet >= 0;
+}
+
+FX_BOOL CJS_Context::RunScript(const CFX_WideString& script, CFX_WideString& info)
+{
+ v8::Isolate::Scope isolate_scope(m_pRuntime->GetIsolate());
+ v8::HandleScope handle_scope(m_pRuntime->GetIsolate());
+ v8::Local<v8::Context> context = m_pRuntime->NewJSContext();
+ v8::Context::Scope context_scope(context);
+
+ return DoJob(0, script, info);
+}
+
+FX_BOOL CJS_Context::Compile(const CFX_WideString& script, CFX_WideString& info)
+{
+ v8::Isolate::Scope isolate_scope(m_pRuntime->GetIsolate());
+ v8::HandleScope handle_scope(m_pRuntime->GetIsolate());
+ v8::Local<v8::Context> context = m_pRuntime->NewJSContext();
+ v8::Context::Scope context_scope(context);
+
+ return DoJob(1, script, info);
+}
+
+void CJS_Context::OnApp_Init()
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnApp_Init();
+}
+
+void CJS_Context::OnDoc_Open(CPDFSDK_Document* pDoc, const CFX_WideString &strTargetName)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnDoc_Open(pDoc,strTargetName);
+}
+
+void CJS_Context::OnDoc_WillPrint(CPDFSDK_Document* pDoc)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnDoc_WillPrint(pDoc);
+}
+
+void CJS_Context::OnDoc_DidPrint(CPDFSDK_Document* pDoc)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnDoc_DidPrint(pDoc);
+}
+
+void CJS_Context::OnDoc_WillSave(CPDFSDK_Document* pDoc)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnDoc_WillSave(pDoc);
+}
+
+void CJS_Context::OnDoc_DidSave(CPDFSDK_Document* pDoc)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnDoc_DidSave(pDoc);
+}
+
+void CJS_Context::OnDoc_WillClose(CPDFSDK_Document* pDoc)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnDoc_WillClose(pDoc);
+}
+
+void CJS_Context::OnPage_Open(CPDFSDK_Document* pTarget)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnPage_Open(pTarget);
+}
+
+void CJS_Context::OnPage_Close(CPDFSDK_Document* pTarget)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnPage_Close(pTarget);
+}
+
+void CJS_Context::OnPage_InView(CPDFSDK_Document* pTarget)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnPage_InView(pTarget);
+}
+
+void CJS_Context::OnPage_OutView(CPDFSDK_Document* pTarget)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnPage_OutView(pTarget);
+}
+
+void CJS_Context::OnField_MouseDown(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField *pTarget)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnField_MouseDown(bModifier, bShift, pTarget);
+}
+
+void CJS_Context::OnField_MouseEnter(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField *pTarget)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnField_MouseEnter(bModifier, bShift, pTarget);
+}
+
+void CJS_Context::OnField_MouseExit(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField *pTarget)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnField_MouseExit(bModifier, bShift, pTarget);
+}
+
+void CJS_Context::OnField_MouseUp(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField *pTarget)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnField_MouseUp(bModifier, bShift, pTarget);
+}
+
+void CJS_Context::OnField_Focus(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget, const CFX_WideString& Value)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnField_Focus(bModifier, bShift, pTarget, Value);
+}
+
+void CJS_Context::OnField_Blur(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget, const CFX_WideString& Value)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnField_Blur(bModifier, bShift, pTarget, Value);
+}
+
+void CJS_Context::OnField_Calculate(CPDF_FormField* pSource, CPDF_FormField* pTarget, CFX_WideString& Value, FX_BOOL& bRc)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnField_Calculate(pSource, pTarget, Value, bRc);
+}
+
+void CJS_Context::OnField_Format(int nCommitKey, CPDF_FormField* pTarget, CFX_WideString& Value, FX_BOOL bWillCommit)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnField_Format(nCommitKey, pTarget, Value, bWillCommit);
+}
+
+
+void CJS_Context::OnField_Keystroke(int nCommitKey, CFX_WideString& strChange, const CFX_WideString& strChangeEx,
+ FX_BOOL bKeyDown, FX_BOOL bModifier, int &nSelEnd,int &nSelStart,
+ FX_BOOL bShift, CPDF_FormField* pTarget, CFX_WideString& Value,
+ FX_BOOL bWillCommit, FX_BOOL bFieldFull, FX_BOOL& bRc)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnField_Keystroke(nCommitKey, strChange, strChangeEx, bKeyDown,
+ bModifier, nSelEnd, nSelStart, bShift, pTarget, Value, bWillCommit, bFieldFull, bRc);
+}
+
+void CJS_Context::OnField_Validate(CFX_WideString& strChange,const CFX_WideString& strChangeEx,
+ FX_BOOL bKeyDown, FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget,
+ CFX_WideString& Value, FX_BOOL& bRc)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnField_Validate(strChange, strChangeEx, bKeyDown, bModifier, bShift, pTarget, Value, bRc);
+}
+
+void CJS_Context::OnScreen_Focus(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnScreen_Focus(bModifier, bShift, pScreen);
+}
+
+void CJS_Context::OnScreen_Blur(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnScreen_Blur(bModifier, bShift, pScreen);
+}
+
+void CJS_Context::OnScreen_Open(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnScreen_Open(bModifier, bShift, pScreen);
+}
+
+void CJS_Context::OnScreen_Close(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnScreen_Close(bModifier, bShift, pScreen);
+}
+
+void CJS_Context::OnScreen_MouseDown(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnScreen_MouseDown(bModifier, bShift, pScreen);
+}
+
+void CJS_Context::OnScreen_MouseUp(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnScreen_MouseUp(bModifier, bShift, pScreen);
+}
+
+void CJS_Context::OnScreen_MouseEnter(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnScreen_MouseEnter(bModifier, bShift, pScreen);
+}
+
+void CJS_Context::OnScreen_MouseExit(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnScreen_MouseExit(bModifier, bShift, pScreen);
+}
+
+void CJS_Context::OnScreen_InView(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnScreen_InView(bModifier, bShift, pScreen);
+}
+
+void CJS_Context::OnScreen_OutView(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnScreen_OutView(bModifier, bShift, pScreen);
+}
+
+void CJS_Context::OnBookmark_MouseUp(CPDF_Bookmark* pBookMark)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnBookmark_MouseUp(pBookMark);
+}
+
+void CJS_Context::OnLink_MouseUp(CPDFSDK_Document* pTarget)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnLink_MouseUp(pTarget);
+}
+
+void CJS_Context::OnConsole_Exec()
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnConsole_Exec();
+}
+
+void CJS_Context::OnExternal_Exec()
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnExternal_Exec();
+}
+
+void CJS_Context::OnBatchExec(CPDFSDK_Document* pTarget)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnBatchExec(pTarget);
+}
+
+void CJS_Context::OnMenu_Exec(CPDFSDK_Document* pTarget,const CFX_WideString& strTargetName)
+{
+ ASSERT(m_pEventHandler != NULL);
+ m_pEventHandler->OnMenu_Exec(pTarget, strTargetName);
+}
+
diff --git a/fpdfsdk/src/javascript/JS_EventHandler.cpp b/fpdfsdk/src/javascript/JS_EventHandler.cpp
index ce69e6b9d2..76c6d37f03 100644
--- a/fpdfsdk/src/javascript/JS_EventHandler.cpp
+++ b/fpdfsdk/src/javascript/JS_EventHandler.cpp
@@ -1,676 +1,676 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/javascript/JavaScript.h"
-#include "../../include/javascript/IJavaScript.h"
-#include "../../include/javascript/JS_EventHandler.h"
-//#include "../../include/javascript/JS_ResMgr.h"
-#include "../../include/javascript/JS_Context.h"
-#include "../../include/javascript/JS_Runtime.h"
-#include "../../include/javascript/JS_Define.h"
-#include "../../include/javascript/JS_Object.h"
-#include "../../include/javascript/JS_Value.h"
-#include "../../include/javascript/Document.h"
-#include "../../include/javascript/Field.h"
-
-/* ---------------------------- CJS_EventHandler ---------------------------- */
-
-CJS_EventHandler::CJS_EventHandler(CJS_Context * pContext) :
- m_pJSContext(pContext),
- m_eEventType(JET_UNKNOWN),
- m_bValid(FALSE),
- m_pWideStrChange(NULL),
- m_nCommitKey(-1),
- m_bKeyDown(FALSE),
- m_bModifier(FALSE),
- m_bShift(FALSE),
- m_pISelEnd(NULL),
- m_nSelEndDu(0),
- m_pISelStart(NULL),
- m_nSelStartDu(0),
- m_bWillCommit(FALSE),
- m_pValue(NULL),
- m_bFieldFull(FALSE),
- m_pbRc(NULL),
- m_bRcDu(FALSE),
- m_pSourceDoc(NULL),
- m_pTargetBookMark(NULL),
- m_pTargetDoc(NULL),
- m_pTargetAnnot(NULL)
-{
-}
-
-CJS_EventHandler::~CJS_EventHandler()
-{
-}
-
-void CJS_EventHandler::OnApp_Init()
-{
- Initial(JET_APP_INIT);
-}
-
-void CJS_EventHandler::OnDoc_Open(CPDFSDK_Document* pDoc, const CFX_WideString& strTargetName)
-{
- Initial(JET_DOC_OPEN);
-
- m_pTargetDoc = pDoc;
- m_strTargetName = strTargetName;
-}
-
-void CJS_EventHandler::OnDoc_WillPrint(CPDFSDK_Document* pDoc)
-{
- Initial(JET_DOC_WILLPRINT);
-
- m_pTargetDoc = pDoc;
-}
-
-void CJS_EventHandler::OnDoc_DidPrint(CPDFSDK_Document* pDoc)
-{
- Initial(JET_DOC_DIDPRINT);
-
- m_pTargetDoc = pDoc;
-}
-
-void CJS_EventHandler::OnDoc_WillSave(CPDFSDK_Document* pDoc)
-{
- Initial(JET_DOC_WILLSAVE);
- m_pTargetDoc = pDoc;
-}
-
-void CJS_EventHandler::OnDoc_DidSave(CPDFSDK_Document* pDoc)
-{
- Initial(JET_DOC_DIDSAVE);
-
- m_pTargetDoc = pDoc;
-}
-
-void CJS_EventHandler::OnDoc_WillClose(CPDFSDK_Document* pDoc)
-{
- Initial(JET_DOC_WILLCLOSE);
-
- m_pTargetDoc = pDoc;
-}
-
-void CJS_EventHandler::OnPage_Open(CPDFSDK_Document* pDoc)
-{
- Initial(JET_PAGE_OPEN);
-
- m_pTargetDoc = pDoc;
-}
-
-void CJS_EventHandler::OnPage_Close(CPDFSDK_Document* pDoc)
-{
- Initial(JET_PAGE_CLOSE);
-
- m_pTargetDoc = pDoc;
-}
-
-void CJS_EventHandler::OnPage_InView(CPDFSDK_Document* pDoc)
-{
- Initial(JET_PAGE_INVIEW);
-
- m_pTargetDoc = pDoc;
-}
-
-void CJS_EventHandler::OnPage_OutView(CPDFSDK_Document* pDoc)
-{
- Initial(JET_PAGE_OUTVIEW);
-
- m_pTargetDoc = pDoc;
-}
-
-void CJS_EventHandler::OnField_MouseEnter(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget)
-{
- Initial(JET_FIELD_MOUSEENTER);
-
- m_bModifier = bModifier;
- m_bShift = bShift;
-
- ASSERT(pTarget != NULL);
- m_strTargetName = pTarget->GetFullName();
-}
-
-void CJS_EventHandler::OnField_MouseExit(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget)
-{
- Initial(JET_FIELD_MOUSEEXIT);
-
- m_bModifier = bModifier;
- m_bShift = bShift;
- ASSERT(pTarget != NULL);
- m_strTargetName = pTarget->GetFullName();
-}
-
-void CJS_EventHandler::OnField_MouseDown(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget)
-{
- Initial(JET_FIELD_MOUSEDOWN);
- m_eEventType = JET_FIELD_MOUSEDOWN;
-
- m_bModifier = bModifier;
- m_bShift = bShift;
- ASSERT(pTarget != NULL);
- m_strTargetName = pTarget->GetFullName();
-}
-
-void CJS_EventHandler::OnField_MouseUp(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget)
-{
- Initial(JET_FIELD_MOUSEUP);
-
- m_bModifier = bModifier;
- m_bShift = bShift;
- ASSERT(pTarget != NULL);
- m_strTargetName = pTarget->GetFullName();
-}
-
-void CJS_EventHandler::OnField_Focus(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget,
- const CFX_WideString& Value)
-{
- Initial(JET_FIELD_FOCUS);
-
- m_bModifier = bModifier;
- m_bShift = bShift;
- ASSERT(pTarget != NULL);
- m_strTargetName = pTarget->GetFullName();
- m_pValue = (CFX_WideString*)&Value;
-}
-
-void CJS_EventHandler::OnField_Blur(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget,
- const CFX_WideString& Value)
-{
- Initial(JET_FIELD_BLUR);
-
- m_bModifier = bModifier;
- m_bShift = bShift;
- ASSERT(pTarget != NULL);
- m_strTargetName = pTarget->GetFullName();
- m_pValue = (CFX_WideString*)&Value;
-}
-
-void CJS_EventHandler::OnField_Keystroke(int nCommitKey, CFX_WideString &strChange,
- const CFX_WideString& strChangeEx, FX_BOOL KeyDown,
- FX_BOOL bModifier, int& nSelEnd, int& nSelStart,
- FX_BOOL bShift, CPDF_FormField* pTarget,
- CFX_WideString& Value, FX_BOOL bWillCommit,
- FX_BOOL bFieldFull, FX_BOOL& bRc)
-{
- Initial(JET_FIELD_KEYSTROKE);
-
- m_nCommitKey = nCommitKey;
- m_pWideStrChange = &strChange;
- m_WideStrChangeEx = strChangeEx;
- m_bKeyDown = KeyDown;
- m_bModifier = bModifier;
- m_pISelEnd = &nSelEnd;
- m_pISelStart = &nSelStart;
- m_bShift = bShift;
- ASSERT(pTarget != NULL);
- m_strTargetName = pTarget->GetFullName();
- m_pValue = &Value;
- m_bWillCommit = bWillCommit;
- m_pbRc = &bRc;
- m_bFieldFull = bFieldFull;
-}
-
-void CJS_EventHandler::OnField_Validate(CFX_WideString& strChange, const CFX_WideString& strChangeEx,
- FX_BOOL bKeyDown, FX_BOOL bModifier, FX_BOOL bShift,
- CPDF_FormField* pTarget, CFX_WideString& Value, FX_BOOL& bRc)
-{
- Initial(JET_FIELD_VALIDATE);
-
- m_pWideStrChange = &strChange;
- m_WideStrChangeEx = strChangeEx;
- m_bKeyDown = bKeyDown;
- m_bModifier = bModifier;
- m_bShift = bShift;
- ASSERT(pTarget != NULL);
- m_strTargetName = pTarget->GetFullName();
- m_pValue = &Value;
- m_pbRc = &bRc;
-}
-
-void CJS_EventHandler::OnField_Calculate(CPDF_FormField* pSource, CPDF_FormField* pTarget,
- CFX_WideString& Value, FX_BOOL& bRc)
-{
- Initial(JET_FIELD_CALCULATE);
-
- if (pSource)
- m_strSourceName = pSource->GetFullName();
- ASSERT(pTarget != NULL);
- m_strTargetName = pTarget->GetFullName();
- m_pValue = &Value;
- m_pbRc = &bRc;
-}
-
-void CJS_EventHandler::OnField_Format(int nCommitKey, CPDF_FormField* pTarget,
- CFX_WideString& Value, FX_BOOL bWillCommit)
-{
- Initial(JET_FIELD_FORMAT);
-
- m_nCommitKey = nCommitKey;
- ASSERT(pTarget != NULL);
- m_strTargetName = pTarget->GetFullName();
- m_pValue = &Value;
- m_bWillCommit = bWillCommit;
-}
-
-void CJS_EventHandler::OnScreen_Focus(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
-{
- Initial(JET_SCREEN_FOCUS);
-
- m_bModifier = bModifier;
- m_bShift = bShift;
- m_pTargetAnnot = pScreen;
-}
-
-void CJS_EventHandler::OnScreen_Blur(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
-{
- Initial(JET_SCREEN_BLUR);
-
- m_bModifier = bModifier;
- m_bShift = bShift;
- m_pTargetAnnot = pScreen;
-}
-
-void CJS_EventHandler::OnScreen_Open(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
-{
- Initial(JET_SCREEN_OPEN);
-
- m_bModifier = bModifier;
- m_bShift = bShift;
- m_pTargetAnnot = pScreen;
-}
-
-void CJS_EventHandler::OnScreen_Close(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
-{
- Initial(JET_SCREEN_CLOSE);
-
- m_bModifier = bModifier;
- m_bShift = bShift;
- m_pTargetAnnot = pScreen;
-}
-
-void CJS_EventHandler::OnScreen_MouseDown(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
-{
- Initial(JET_SCREEN_MOUSEDOWN);
-
- m_bModifier = bModifier;
- m_bShift = bShift;
- m_pTargetAnnot = pScreen;
-}
-
-void CJS_EventHandler::OnScreen_MouseUp(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
-{
- Initial(JET_SCREEN_MOUSEUP);
-
- m_bModifier = bModifier;
- m_bShift = bShift;
- m_pTargetAnnot = pScreen;
-}
-
-void CJS_EventHandler::OnScreen_MouseEnter(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
-{
- Initial(JET_SCREEN_MOUSEENTER);
-
- m_bModifier = bModifier;
- m_bShift = bShift;
- m_pTargetAnnot = pScreen;
-}
-
-void CJS_EventHandler::OnScreen_MouseExit(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
-{
- Initial(JET_SCREEN_MOUSEEXIT);
-
- m_bModifier = bModifier;
- m_bShift = bShift;
- m_pTargetAnnot = pScreen;
-}
-
-void CJS_EventHandler::OnScreen_InView(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
-{
- Initial(JET_SCREEN_INVIEW);
-
- m_bModifier = bModifier;
- m_bShift = bShift;
- m_pTargetAnnot = pScreen;
-}
-
-void CJS_EventHandler::OnScreen_OutView(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
-{
- Initial(JET_SCREEN_OUTVIEW);
-
- m_bModifier = bModifier;
- m_bShift = bShift;
- m_pTargetAnnot = pScreen;
-}
-
-void CJS_EventHandler::OnLink_MouseUp(CPDFSDK_Document* pTarget)
-{
- Initial(JET_LINK_MOUSEUP);
-
- m_pTargetDoc = pTarget;
-}
-
-void CJS_EventHandler::OnBookmark_MouseUp(CPDF_Bookmark* pBookMark)
-{
- Initial(JET_BOOKMARK_MOUSEUP);
-
- m_pTargetBookMark = pBookMark;
-}
-
-void CJS_EventHandler::OnMenu_Exec(CPDFSDK_Document* pTarget, const CFX_WideString& strTargetName)
-{
- Initial(JET_MENU_EXEC);
-
- m_pTargetDoc = pTarget;
- m_strTargetName = strTargetName;
-}
-
-void CJS_EventHandler::OnExternal_Exec()
-{
- Initial(JET_EXTERNAL_EXEC);
-}
-
-void CJS_EventHandler::OnBatchExec(CPDFSDK_Document* pTarget)
-{
- Initial(JET_BATCH_EXEC);
-
- m_pTargetDoc = pTarget;
-}
-
-void CJS_EventHandler::OnConsole_Exec()
-{
- Initial(JET_CONSOLE_EXEC);
-}
-
-
-void CJS_EventHandler::Initial(JS_EVENT_T type)
-{
- m_eEventType = type;
-
- m_strTargetName = L"";
- m_strSourceName = L"";
- m_pWideStrChange = NULL;
- m_WideStrChangeDu = L"";
- m_WideStrChangeEx = L"";
- m_nCommitKey = -1;
- m_bKeyDown = FALSE;
- m_bModifier = FALSE;
- m_bShift = FALSE;
- m_pISelEnd = NULL;
- m_nSelEndDu = 0;
- m_pISelStart = NULL;
- m_nSelStartDu = 0;
- m_bWillCommit = FALSE;
- m_pValue = NULL;
- m_bFieldFull = FALSE;
- m_pbRc = NULL;
- m_bRcDu = FALSE;
-
- m_pSourceDoc = NULL;
- m_pTargetBookMark = NULL;
- m_pTargetDoc = NULL;
- m_pTargetAnnot = NULL;
-
- m_bValid = TRUE;
-}
-
-void CJS_EventHandler::Destroy()
-{
- m_bValid = FALSE;
-}
-
-FX_BOOL CJS_EventHandler::IsValid()
-{
- return m_bValid;
-}
-
-CFX_WideString & CJS_EventHandler::Change()
-{
- if (m_pWideStrChange != NULL)
- return *m_pWideStrChange;
- else
- {
- return m_WideStrChangeDu;
- }
-}
-
-CFX_WideString CJS_EventHandler::ChangeEx()
-{
- return m_WideStrChangeEx;
-}
-
-int CJS_EventHandler::CommitKey()
-{
- return m_nCommitKey;
-}
-
-FX_BOOL CJS_EventHandler::FieldFull()
-{
- return m_bFieldFull;
-}
-
-FX_BOOL CJS_EventHandler::KeyDown()
-{
- return m_bKeyDown;
-}
-
-FX_BOOL CJS_EventHandler::Modifier()
-{
- return m_bModifier;
-}
-
-FX_LPCWSTR CJS_EventHandler::Name()
-{
- switch (m_eEventType)
- {
- case JET_APP_INIT: return (FX_LPCWSTR)L"Init";
- case JET_BATCH_EXEC: return (FX_LPCWSTR)L"Exec";
- case JET_BOOKMARK_MOUSEUP: return (FX_LPCWSTR)L"Mouse Up";
- case JET_CONSOLE_EXEC: return (FX_LPCWSTR)L"Exec";
- case JET_DOC_DIDPRINT: return (FX_LPCWSTR)L"DidPrint";
- case JET_DOC_DIDSAVE: return (FX_LPCWSTR)L"DidSave";
- case JET_DOC_OPEN: return (FX_LPCWSTR)L"Open";
- case JET_DOC_WILLCLOSE: return (FX_LPCWSTR)L"WillClose";
- case JET_DOC_WILLPRINT: return (FX_LPCWSTR)L"WillPrint";
- case JET_DOC_WILLSAVE: return (FX_LPCWSTR)L"WillSave";
- case JET_EXTERNAL_EXEC: return (FX_LPCWSTR)L"Exec";
- case JET_FIELD_FOCUS:
- case JET_SCREEN_FOCUS: return (FX_LPCWSTR)L"Focus";
- case JET_FIELD_BLUR:
- case JET_SCREEN_BLUR: return (FX_LPCWSTR)L"Blur";
- case JET_FIELD_MOUSEDOWN:
- case JET_SCREEN_MOUSEDOWN: return (FX_LPCWSTR)L"Mouse Down";
- case JET_FIELD_MOUSEUP:
- case JET_SCREEN_MOUSEUP: return (FX_LPCWSTR)L"Mouse Up";
- case JET_FIELD_MOUSEENTER:
- case JET_SCREEN_MOUSEENTER: return (FX_LPCWSTR)L"Mouse Enter";
- case JET_FIELD_MOUSEEXIT:
- case JET_SCREEN_MOUSEEXIT: return (FX_LPCWSTR)L"Mouse Exit";
- case JET_FIELD_CALCULATE: return (FX_LPCWSTR)L"Calculate";
- case JET_FIELD_FORMAT: return (FX_LPCWSTR)L"Format";
- case JET_FIELD_KEYSTROKE: return (FX_LPCWSTR)L"Keystroke";
- case JET_FIELD_VALIDATE: return (FX_LPCWSTR)L"Validate";
- case JET_LINK_MOUSEUP: return (FX_LPCWSTR)L"Mouse Up";
- case JET_MENU_EXEC: return (FX_LPCWSTR)L"Exec";
- case JET_PAGE_OPEN:
- case JET_SCREEN_OPEN: return (FX_LPCWSTR)L"Open";
- case JET_PAGE_CLOSE:
- case JET_SCREEN_CLOSE: return (FX_LPCWSTR)L"Close";
- case JET_SCREEN_INVIEW:
- case JET_PAGE_INVIEW: return (FX_LPCWSTR)L"InView";
- case JET_PAGE_OUTVIEW:
- case JET_SCREEN_OUTVIEW: return (FX_LPCWSTR)L"OutView";
- default:
- return (FX_LPCWSTR)L"";
- }
-
- return (FX_LPCWSTR)L"";
-}
-
-FX_LPCWSTR CJS_EventHandler::Type()
-{
- switch (m_eEventType)
- {
- case JET_APP_INIT: return (FX_LPCWSTR)L"App";
- case JET_BATCH_EXEC: return (FX_LPCWSTR)L"Batch";
- case JET_BOOKMARK_MOUSEUP: return (FX_LPCWSTR)L"BookMark";
- case JET_CONSOLE_EXEC: return (FX_LPCWSTR)L"Console";
- case JET_DOC_DIDPRINT:
- case JET_DOC_DIDSAVE:
- case JET_DOC_OPEN:
- case JET_DOC_WILLCLOSE:
- case JET_DOC_WILLPRINT:
- case JET_DOC_WILLSAVE: return (FX_LPCWSTR)L"Doc";
- case JET_EXTERNAL_EXEC: return (FX_LPCWSTR)L"External";
- case JET_FIELD_BLUR:
- case JET_FIELD_FOCUS:
- case JET_FIELD_MOUSEDOWN:
- case JET_FIELD_MOUSEENTER:
- case JET_FIELD_MOUSEEXIT:
- case JET_FIELD_MOUSEUP:
- case JET_FIELD_CALCULATE:
- case JET_FIELD_FORMAT:
- case JET_FIELD_KEYSTROKE:
- case JET_FIELD_VALIDATE: return (FX_LPCWSTR)L"Field";
- case JET_SCREEN_FOCUS:
- case JET_SCREEN_BLUR:
- case JET_SCREEN_OPEN:
- case JET_SCREEN_CLOSE:
- case JET_SCREEN_MOUSEDOWN:
- case JET_SCREEN_MOUSEUP:
- case JET_SCREEN_MOUSEENTER:
- case JET_SCREEN_MOUSEEXIT:
- case JET_SCREEN_INVIEW:
- case JET_SCREEN_OUTVIEW: return (FX_LPCWSTR)L"Screen";
- case JET_LINK_MOUSEUP: return (FX_LPCWSTR)L"Link";
- case JET_MENU_EXEC: return (FX_LPCWSTR)L"Menu";
- case JET_PAGE_OPEN:
- case JET_PAGE_CLOSE:
- case JET_PAGE_INVIEW:
- case JET_PAGE_OUTVIEW:return (FX_LPCWSTR)L"Page";
- default:
- return (FX_LPCWSTR)L"";
- }
-
- return (FX_LPCWSTR)L"";
-}
-
-FX_BOOL& CJS_EventHandler::Rc()
-{
- if (m_pbRc != NULL)
- return *m_pbRc;
- else
- {
- return m_bRcDu;
- }
-}
-
-int & CJS_EventHandler::SelEnd()
-{
- if (m_pISelEnd != NULL)
- {
- return *m_pISelEnd;
- }
- else
- {
- return m_nSelEndDu;
- }
-}
-
-int & CJS_EventHandler::SelStart()
-{
- if (m_pISelStart != NULL)
- return * m_pISelStart;
- else
- {
- return m_nSelStartDu;
- }
-}
-
-FX_BOOL CJS_EventHandler::Shift()
-{
- return m_bShift;
-}
-
-Field* CJS_EventHandler::Source()
-{
- ASSERT(m_pJSContext != NULL);
-
- CJS_Runtime* pRuntime = m_pJSContext->GetJSRuntime();
-
- JSFXObject pDocObj = JS_NewFxDynamicObj(*pRuntime, m_pJSContext, JS_GetObjDefnID(*pRuntime, L"Document"));
- ASSERT(pDocObj.IsEmpty() == FALSE);
- JSFXObject pFieldObj = JS_NewFxDynamicObj(*pRuntime, m_pJSContext, JS_GetObjDefnID(*pRuntime, L"Field"));
- ASSERT(pFieldObj.IsEmpty() == FALSE);
-
- CJS_Document* pJSDocument = (CJS_Document*)JS_GetPrivate(pDocObj);
- ASSERT(pJSDocument != NULL);
- Document* pDocument = (Document*)pJSDocument->GetEmbedObject();
- ASSERT(pDocument != NULL);
- if (m_pTargetDoc != NULL)
- pDocument->AttachDoc(m_pTargetDoc);
- else
- pDocument->AttachDoc(m_pJSContext->GetReaderDocument());
-
- //if (m_pSourceField == NULL)
- // return NULL;
- //CRAO_Widget *pWidget = IBCL_Widget::GetWidget(m_pSourceField);
- //CPDF_FormField* pFormField = pWidget->GetFormField();
- //ASSERT(pFormField);
- //CFX_WideString csFieldName = pFormField->GetFullName();
- CJS_Field * pJSField = (CJS_Field*)JS_GetPrivate(pFieldObj);
- ASSERT(pJSField != NULL);
- Field * pField = (Field *)pJSField->GetEmbedObject();
- ASSERT(pField != NULL);
- pField->AttachField(pDocument, m_strSourceName);
- return pField;
-}
-
-Field* CJS_EventHandler::Target_Field()
-{
- ASSERT(m_pJSContext != NULL);
-
- CJS_Runtime* pRuntime = m_pJSContext->GetJSRuntime();
-
- JSFXObject pDocObj = JS_NewFxDynamicObj(*pRuntime, m_pJSContext, JS_GetObjDefnID(*pRuntime, L"Document"));
- ASSERT(pDocObj.IsEmpty() == FALSE);
- JSFXObject pFieldObj = JS_NewFxDynamicObj(*pRuntime, m_pJSContext, JS_GetObjDefnID(*pRuntime, L"Field"));
- ASSERT(pFieldObj.IsEmpty() == FALSE);
-
- CJS_Document* pJSDocument = (CJS_Document*)JS_GetPrivate(pDocObj);
- ASSERT(pJSDocument != NULL);
- Document* pDocument = (Document*)pJSDocument->GetEmbedObject();
- ASSERT(pDocument != NULL);
- if (m_pTargetDoc != NULL)
- pDocument->AttachDoc(m_pTargetDoc);
- else
- pDocument->AttachDoc(m_pJSContext->GetReaderDocument());
-
- CJS_Field* pJSField = (CJS_Field*)JS_GetPrivate(pFieldObj);
- ASSERT(pJSField != NULL);
-
- Field* pField = (Field *)pJSField->GetEmbedObject();
- ASSERT(pField != NULL);
-
- pField->AttachField(pDocument, m_strTargetName);
- return pField;
-}
-
-CFX_WideString& CJS_EventHandler::Value()
-{
- return *m_pValue;
-}
-
-FX_BOOL CJS_EventHandler::WillCommit()
-{
- return m_bWillCommit;
-}
-
-CFX_WideString CJS_EventHandler::TargetName()
-{
- return m_strTargetName;
-}
-
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/javascript/JavaScript.h"
+#include "../../include/javascript/IJavaScript.h"
+#include "../../include/javascript/JS_EventHandler.h"
+//#include "../../include/javascript/JS_ResMgr.h"
+#include "../../include/javascript/JS_Context.h"
+#include "../../include/javascript/JS_Runtime.h"
+#include "../../include/javascript/JS_Define.h"
+#include "../../include/javascript/JS_Object.h"
+#include "../../include/javascript/JS_Value.h"
+#include "../../include/javascript/Document.h"
+#include "../../include/javascript/Field.h"
+
+/* ---------------------------- CJS_EventHandler ---------------------------- */
+
+CJS_EventHandler::CJS_EventHandler(CJS_Context * pContext) :
+ m_pJSContext(pContext),
+ m_eEventType(JET_UNKNOWN),
+ m_bValid(FALSE),
+ m_pWideStrChange(NULL),
+ m_nCommitKey(-1),
+ m_bKeyDown(FALSE),
+ m_bModifier(FALSE),
+ m_bShift(FALSE),
+ m_pISelEnd(NULL),
+ m_nSelEndDu(0),
+ m_pISelStart(NULL),
+ m_nSelStartDu(0),
+ m_bWillCommit(FALSE),
+ m_pValue(NULL),
+ m_bFieldFull(FALSE),
+ m_pbRc(NULL),
+ m_bRcDu(FALSE),
+ m_pSourceDoc(NULL),
+ m_pTargetBookMark(NULL),
+ m_pTargetDoc(NULL),
+ m_pTargetAnnot(NULL)
+{
+}
+
+CJS_EventHandler::~CJS_EventHandler()
+{
+}
+
+void CJS_EventHandler::OnApp_Init()
+{
+ Initial(JET_APP_INIT);
+}
+
+void CJS_EventHandler::OnDoc_Open(CPDFSDK_Document* pDoc, const CFX_WideString& strTargetName)
+{
+ Initial(JET_DOC_OPEN);
+
+ m_pTargetDoc = pDoc;
+ m_strTargetName = strTargetName;
+}
+
+void CJS_EventHandler::OnDoc_WillPrint(CPDFSDK_Document* pDoc)
+{
+ Initial(JET_DOC_WILLPRINT);
+
+ m_pTargetDoc = pDoc;
+}
+
+void CJS_EventHandler::OnDoc_DidPrint(CPDFSDK_Document* pDoc)
+{
+ Initial(JET_DOC_DIDPRINT);
+
+ m_pTargetDoc = pDoc;
+}
+
+void CJS_EventHandler::OnDoc_WillSave(CPDFSDK_Document* pDoc)
+{
+ Initial(JET_DOC_WILLSAVE);
+ m_pTargetDoc = pDoc;
+}
+
+void CJS_EventHandler::OnDoc_DidSave(CPDFSDK_Document* pDoc)
+{
+ Initial(JET_DOC_DIDSAVE);
+
+ m_pTargetDoc = pDoc;
+}
+
+void CJS_EventHandler::OnDoc_WillClose(CPDFSDK_Document* pDoc)
+{
+ Initial(JET_DOC_WILLCLOSE);
+
+ m_pTargetDoc = pDoc;
+}
+
+void CJS_EventHandler::OnPage_Open(CPDFSDK_Document* pDoc)
+{
+ Initial(JET_PAGE_OPEN);
+
+ m_pTargetDoc = pDoc;
+}
+
+void CJS_EventHandler::OnPage_Close(CPDFSDK_Document* pDoc)
+{
+ Initial(JET_PAGE_CLOSE);
+
+ m_pTargetDoc = pDoc;
+}
+
+void CJS_EventHandler::OnPage_InView(CPDFSDK_Document* pDoc)
+{
+ Initial(JET_PAGE_INVIEW);
+
+ m_pTargetDoc = pDoc;
+}
+
+void CJS_EventHandler::OnPage_OutView(CPDFSDK_Document* pDoc)
+{
+ Initial(JET_PAGE_OUTVIEW);
+
+ m_pTargetDoc = pDoc;
+}
+
+void CJS_EventHandler::OnField_MouseEnter(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget)
+{
+ Initial(JET_FIELD_MOUSEENTER);
+
+ m_bModifier = bModifier;
+ m_bShift = bShift;
+
+ ASSERT(pTarget != NULL);
+ m_strTargetName = pTarget->GetFullName();
+}
+
+void CJS_EventHandler::OnField_MouseExit(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget)
+{
+ Initial(JET_FIELD_MOUSEEXIT);
+
+ m_bModifier = bModifier;
+ m_bShift = bShift;
+ ASSERT(pTarget != NULL);
+ m_strTargetName = pTarget->GetFullName();
+}
+
+void CJS_EventHandler::OnField_MouseDown(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget)
+{
+ Initial(JET_FIELD_MOUSEDOWN);
+ m_eEventType = JET_FIELD_MOUSEDOWN;
+
+ m_bModifier = bModifier;
+ m_bShift = bShift;
+ ASSERT(pTarget != NULL);
+ m_strTargetName = pTarget->GetFullName();
+}
+
+void CJS_EventHandler::OnField_MouseUp(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget)
+{
+ Initial(JET_FIELD_MOUSEUP);
+
+ m_bModifier = bModifier;
+ m_bShift = bShift;
+ ASSERT(pTarget != NULL);
+ m_strTargetName = pTarget->GetFullName();
+}
+
+void CJS_EventHandler::OnField_Focus(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget,
+ const CFX_WideString& Value)
+{
+ Initial(JET_FIELD_FOCUS);
+
+ m_bModifier = bModifier;
+ m_bShift = bShift;
+ ASSERT(pTarget != NULL);
+ m_strTargetName = pTarget->GetFullName();
+ m_pValue = (CFX_WideString*)&Value;
+}
+
+void CJS_EventHandler::OnField_Blur(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget,
+ const CFX_WideString& Value)
+{
+ Initial(JET_FIELD_BLUR);
+
+ m_bModifier = bModifier;
+ m_bShift = bShift;
+ ASSERT(pTarget != NULL);
+ m_strTargetName = pTarget->GetFullName();
+ m_pValue = (CFX_WideString*)&Value;
+}
+
+void CJS_EventHandler::OnField_Keystroke(int nCommitKey, CFX_WideString &strChange,
+ const CFX_WideString& strChangeEx, FX_BOOL KeyDown,
+ FX_BOOL bModifier, int& nSelEnd, int& nSelStart,
+ FX_BOOL bShift, CPDF_FormField* pTarget,
+ CFX_WideString& Value, FX_BOOL bWillCommit,
+ FX_BOOL bFieldFull, FX_BOOL& bRc)
+{
+ Initial(JET_FIELD_KEYSTROKE);
+
+ m_nCommitKey = nCommitKey;
+ m_pWideStrChange = &strChange;
+ m_WideStrChangeEx = strChangeEx;
+ m_bKeyDown = KeyDown;
+ m_bModifier = bModifier;
+ m_pISelEnd = &nSelEnd;
+ m_pISelStart = &nSelStart;
+ m_bShift = bShift;
+ ASSERT(pTarget != NULL);
+ m_strTargetName = pTarget->GetFullName();
+ m_pValue = &Value;
+ m_bWillCommit = bWillCommit;
+ m_pbRc = &bRc;
+ m_bFieldFull = bFieldFull;
+}
+
+void CJS_EventHandler::OnField_Validate(CFX_WideString& strChange, const CFX_WideString& strChangeEx,
+ FX_BOOL bKeyDown, FX_BOOL bModifier, FX_BOOL bShift,
+ CPDF_FormField* pTarget, CFX_WideString& Value, FX_BOOL& bRc)
+{
+ Initial(JET_FIELD_VALIDATE);
+
+ m_pWideStrChange = &strChange;
+ m_WideStrChangeEx = strChangeEx;
+ m_bKeyDown = bKeyDown;
+ m_bModifier = bModifier;
+ m_bShift = bShift;
+ ASSERT(pTarget != NULL);
+ m_strTargetName = pTarget->GetFullName();
+ m_pValue = &Value;
+ m_pbRc = &bRc;
+}
+
+void CJS_EventHandler::OnField_Calculate(CPDF_FormField* pSource, CPDF_FormField* pTarget,
+ CFX_WideString& Value, FX_BOOL& bRc)
+{
+ Initial(JET_FIELD_CALCULATE);
+
+ if (pSource)
+ m_strSourceName = pSource->GetFullName();
+ ASSERT(pTarget != NULL);
+ m_strTargetName = pTarget->GetFullName();
+ m_pValue = &Value;
+ m_pbRc = &bRc;
+}
+
+void CJS_EventHandler::OnField_Format(int nCommitKey, CPDF_FormField* pTarget,
+ CFX_WideString& Value, FX_BOOL bWillCommit)
+{
+ Initial(JET_FIELD_FORMAT);
+
+ m_nCommitKey = nCommitKey;
+ ASSERT(pTarget != NULL);
+ m_strTargetName = pTarget->GetFullName();
+ m_pValue = &Value;
+ m_bWillCommit = bWillCommit;
+}
+
+void CJS_EventHandler::OnScreen_Focus(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
+{
+ Initial(JET_SCREEN_FOCUS);
+
+ m_bModifier = bModifier;
+ m_bShift = bShift;
+ m_pTargetAnnot = pScreen;
+}
+
+void CJS_EventHandler::OnScreen_Blur(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
+{
+ Initial(JET_SCREEN_BLUR);
+
+ m_bModifier = bModifier;
+ m_bShift = bShift;
+ m_pTargetAnnot = pScreen;
+}
+
+void CJS_EventHandler::OnScreen_Open(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
+{
+ Initial(JET_SCREEN_OPEN);
+
+ m_bModifier = bModifier;
+ m_bShift = bShift;
+ m_pTargetAnnot = pScreen;
+}
+
+void CJS_EventHandler::OnScreen_Close(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
+{
+ Initial(JET_SCREEN_CLOSE);
+
+ m_bModifier = bModifier;
+ m_bShift = bShift;
+ m_pTargetAnnot = pScreen;
+}
+
+void CJS_EventHandler::OnScreen_MouseDown(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
+{
+ Initial(JET_SCREEN_MOUSEDOWN);
+
+ m_bModifier = bModifier;
+ m_bShift = bShift;
+ m_pTargetAnnot = pScreen;
+}
+
+void CJS_EventHandler::OnScreen_MouseUp(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
+{
+ Initial(JET_SCREEN_MOUSEUP);
+
+ m_bModifier = bModifier;
+ m_bShift = bShift;
+ m_pTargetAnnot = pScreen;
+}
+
+void CJS_EventHandler::OnScreen_MouseEnter(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
+{
+ Initial(JET_SCREEN_MOUSEENTER);
+
+ m_bModifier = bModifier;
+ m_bShift = bShift;
+ m_pTargetAnnot = pScreen;
+}
+
+void CJS_EventHandler::OnScreen_MouseExit(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
+{
+ Initial(JET_SCREEN_MOUSEEXIT);
+
+ m_bModifier = bModifier;
+ m_bShift = bShift;
+ m_pTargetAnnot = pScreen;
+}
+
+void CJS_EventHandler::OnScreen_InView(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
+{
+ Initial(JET_SCREEN_INVIEW);
+
+ m_bModifier = bModifier;
+ m_bShift = bShift;
+ m_pTargetAnnot = pScreen;
+}
+
+void CJS_EventHandler::OnScreen_OutView(FX_BOOL bModifier, FX_BOOL bShift, CPDFSDK_Annot* pScreen)
+{
+ Initial(JET_SCREEN_OUTVIEW);
+
+ m_bModifier = bModifier;
+ m_bShift = bShift;
+ m_pTargetAnnot = pScreen;
+}
+
+void CJS_EventHandler::OnLink_MouseUp(CPDFSDK_Document* pTarget)
+{
+ Initial(JET_LINK_MOUSEUP);
+
+ m_pTargetDoc = pTarget;
+}
+
+void CJS_EventHandler::OnBookmark_MouseUp(CPDF_Bookmark* pBookMark)
+{
+ Initial(JET_BOOKMARK_MOUSEUP);
+
+ m_pTargetBookMark = pBookMark;
+}
+
+void CJS_EventHandler::OnMenu_Exec(CPDFSDK_Document* pTarget, const CFX_WideString& strTargetName)
+{
+ Initial(JET_MENU_EXEC);
+
+ m_pTargetDoc = pTarget;
+ m_strTargetName = strTargetName;
+}
+
+void CJS_EventHandler::OnExternal_Exec()
+{
+ Initial(JET_EXTERNAL_EXEC);
+}
+
+void CJS_EventHandler::OnBatchExec(CPDFSDK_Document* pTarget)
+{
+ Initial(JET_BATCH_EXEC);
+
+ m_pTargetDoc = pTarget;
+}
+
+void CJS_EventHandler::OnConsole_Exec()
+{
+ Initial(JET_CONSOLE_EXEC);
+}
+
+
+void CJS_EventHandler::Initial(JS_EVENT_T type)
+{
+ m_eEventType = type;
+
+ m_strTargetName = L"";
+ m_strSourceName = L"";
+ m_pWideStrChange = NULL;
+ m_WideStrChangeDu = L"";
+ m_WideStrChangeEx = L"";
+ m_nCommitKey = -1;
+ m_bKeyDown = FALSE;
+ m_bModifier = FALSE;
+ m_bShift = FALSE;
+ m_pISelEnd = NULL;
+ m_nSelEndDu = 0;
+ m_pISelStart = NULL;
+ m_nSelStartDu = 0;
+ m_bWillCommit = FALSE;
+ m_pValue = NULL;
+ m_bFieldFull = FALSE;
+ m_pbRc = NULL;
+ m_bRcDu = FALSE;
+
+ m_pSourceDoc = NULL;
+ m_pTargetBookMark = NULL;
+ m_pTargetDoc = NULL;
+ m_pTargetAnnot = NULL;
+
+ m_bValid = TRUE;
+}
+
+void CJS_EventHandler::Destroy()
+{
+ m_bValid = FALSE;
+}
+
+FX_BOOL CJS_EventHandler::IsValid()
+{
+ return m_bValid;
+}
+
+CFX_WideString & CJS_EventHandler::Change()
+{
+ if (m_pWideStrChange != NULL)
+ return *m_pWideStrChange;
+ else
+ {
+ return m_WideStrChangeDu;
+ }
+}
+
+CFX_WideString CJS_EventHandler::ChangeEx()
+{
+ return m_WideStrChangeEx;
+}
+
+int CJS_EventHandler::CommitKey()
+{
+ return m_nCommitKey;
+}
+
+FX_BOOL CJS_EventHandler::FieldFull()
+{
+ return m_bFieldFull;
+}
+
+FX_BOOL CJS_EventHandler::KeyDown()
+{
+ return m_bKeyDown;
+}
+
+FX_BOOL CJS_EventHandler::Modifier()
+{
+ return m_bModifier;
+}
+
+FX_LPCWSTR CJS_EventHandler::Name()
+{
+ switch (m_eEventType)
+ {
+ case JET_APP_INIT: return (FX_LPCWSTR)L"Init";
+ case JET_BATCH_EXEC: return (FX_LPCWSTR)L"Exec";
+ case JET_BOOKMARK_MOUSEUP: return (FX_LPCWSTR)L"Mouse Up";
+ case JET_CONSOLE_EXEC: return (FX_LPCWSTR)L"Exec";
+ case JET_DOC_DIDPRINT: return (FX_LPCWSTR)L"DidPrint";
+ case JET_DOC_DIDSAVE: return (FX_LPCWSTR)L"DidSave";
+ case JET_DOC_OPEN: return (FX_LPCWSTR)L"Open";
+ case JET_DOC_WILLCLOSE: return (FX_LPCWSTR)L"WillClose";
+ case JET_DOC_WILLPRINT: return (FX_LPCWSTR)L"WillPrint";
+ case JET_DOC_WILLSAVE: return (FX_LPCWSTR)L"WillSave";
+ case JET_EXTERNAL_EXEC: return (FX_LPCWSTR)L"Exec";
+ case JET_FIELD_FOCUS:
+ case JET_SCREEN_FOCUS: return (FX_LPCWSTR)L"Focus";
+ case JET_FIELD_BLUR:
+ case JET_SCREEN_BLUR: return (FX_LPCWSTR)L"Blur";
+ case JET_FIELD_MOUSEDOWN:
+ case JET_SCREEN_MOUSEDOWN: return (FX_LPCWSTR)L"Mouse Down";
+ case JET_FIELD_MOUSEUP:
+ case JET_SCREEN_MOUSEUP: return (FX_LPCWSTR)L"Mouse Up";
+ case JET_FIELD_MOUSEENTER:
+ case JET_SCREEN_MOUSEENTER: return (FX_LPCWSTR)L"Mouse Enter";
+ case JET_FIELD_MOUSEEXIT:
+ case JET_SCREEN_MOUSEEXIT: return (FX_LPCWSTR)L"Mouse Exit";
+ case JET_FIELD_CALCULATE: return (FX_LPCWSTR)L"Calculate";
+ case JET_FIELD_FORMAT: return (FX_LPCWSTR)L"Format";
+ case JET_FIELD_KEYSTROKE: return (FX_LPCWSTR)L"Keystroke";
+ case JET_FIELD_VALIDATE: return (FX_LPCWSTR)L"Validate";
+ case JET_LINK_MOUSEUP: return (FX_LPCWSTR)L"Mouse Up";
+ case JET_MENU_EXEC: return (FX_LPCWSTR)L"Exec";
+ case JET_PAGE_OPEN:
+ case JET_SCREEN_OPEN: return (FX_LPCWSTR)L"Open";
+ case JET_PAGE_CLOSE:
+ case JET_SCREEN_CLOSE: return (FX_LPCWSTR)L"Close";
+ case JET_SCREEN_INVIEW:
+ case JET_PAGE_INVIEW: return (FX_LPCWSTR)L"InView";
+ case JET_PAGE_OUTVIEW:
+ case JET_SCREEN_OUTVIEW: return (FX_LPCWSTR)L"OutView";
+ default:
+ return (FX_LPCWSTR)L"";
+ }
+
+ return (FX_LPCWSTR)L"";
+}
+
+FX_LPCWSTR CJS_EventHandler::Type()
+{
+ switch (m_eEventType)
+ {
+ case JET_APP_INIT: return (FX_LPCWSTR)L"App";
+ case JET_BATCH_EXEC: return (FX_LPCWSTR)L"Batch";
+ case JET_BOOKMARK_MOUSEUP: return (FX_LPCWSTR)L"BookMark";
+ case JET_CONSOLE_EXEC: return (FX_LPCWSTR)L"Console";
+ case JET_DOC_DIDPRINT:
+ case JET_DOC_DIDSAVE:
+ case JET_DOC_OPEN:
+ case JET_DOC_WILLCLOSE:
+ case JET_DOC_WILLPRINT:
+ case JET_DOC_WILLSAVE: return (FX_LPCWSTR)L"Doc";
+ case JET_EXTERNAL_EXEC: return (FX_LPCWSTR)L"External";
+ case JET_FIELD_BLUR:
+ case JET_FIELD_FOCUS:
+ case JET_FIELD_MOUSEDOWN:
+ case JET_FIELD_MOUSEENTER:
+ case JET_FIELD_MOUSEEXIT:
+ case JET_FIELD_MOUSEUP:
+ case JET_FIELD_CALCULATE:
+ case JET_FIELD_FORMAT:
+ case JET_FIELD_KEYSTROKE:
+ case JET_FIELD_VALIDATE: return (FX_LPCWSTR)L"Field";
+ case JET_SCREEN_FOCUS:
+ case JET_SCREEN_BLUR:
+ case JET_SCREEN_OPEN:
+ case JET_SCREEN_CLOSE:
+ case JET_SCREEN_MOUSEDOWN:
+ case JET_SCREEN_MOUSEUP:
+ case JET_SCREEN_MOUSEENTER:
+ case JET_SCREEN_MOUSEEXIT:
+ case JET_SCREEN_INVIEW:
+ case JET_SCREEN_OUTVIEW: return (FX_LPCWSTR)L"Screen";
+ case JET_LINK_MOUSEUP: return (FX_LPCWSTR)L"Link";
+ case JET_MENU_EXEC: return (FX_LPCWSTR)L"Menu";
+ case JET_PAGE_OPEN:
+ case JET_PAGE_CLOSE:
+ case JET_PAGE_INVIEW:
+ case JET_PAGE_OUTVIEW:return (FX_LPCWSTR)L"Page";
+ default:
+ return (FX_LPCWSTR)L"";
+ }
+
+ return (FX_LPCWSTR)L"";
+}
+
+FX_BOOL& CJS_EventHandler::Rc()
+{
+ if (m_pbRc != NULL)
+ return *m_pbRc;
+ else
+ {
+ return m_bRcDu;
+ }
+}
+
+int & CJS_EventHandler::SelEnd()
+{
+ if (m_pISelEnd != NULL)
+ {
+ return *m_pISelEnd;
+ }
+ else
+ {
+ return m_nSelEndDu;
+ }
+}
+
+int & CJS_EventHandler::SelStart()
+{
+ if (m_pISelStart != NULL)
+ return * m_pISelStart;
+ else
+ {
+ return m_nSelStartDu;
+ }
+}
+
+FX_BOOL CJS_EventHandler::Shift()
+{
+ return m_bShift;
+}
+
+Field* CJS_EventHandler::Source()
+{
+ ASSERT(m_pJSContext != NULL);
+
+ CJS_Runtime* pRuntime = m_pJSContext->GetJSRuntime();
+
+ JSFXObject pDocObj = JS_NewFxDynamicObj(*pRuntime, m_pJSContext, JS_GetObjDefnID(*pRuntime, L"Document"));
+ ASSERT(pDocObj.IsEmpty() == FALSE);
+ JSFXObject pFieldObj = JS_NewFxDynamicObj(*pRuntime, m_pJSContext, JS_GetObjDefnID(*pRuntime, L"Field"));
+ ASSERT(pFieldObj.IsEmpty() == FALSE);
+
+ CJS_Document* pJSDocument = (CJS_Document*)JS_GetPrivate(pDocObj);
+ ASSERT(pJSDocument != NULL);
+ Document* pDocument = (Document*)pJSDocument->GetEmbedObject();
+ ASSERT(pDocument != NULL);
+ if (m_pTargetDoc != NULL)
+ pDocument->AttachDoc(m_pTargetDoc);
+ else
+ pDocument->AttachDoc(m_pJSContext->GetReaderDocument());
+
+ //if (m_pSourceField == NULL)
+ // return NULL;
+ //CRAO_Widget *pWidget = IBCL_Widget::GetWidget(m_pSourceField);
+ //CPDF_FormField* pFormField = pWidget->GetFormField();
+ //ASSERT(pFormField);
+ //CFX_WideString csFieldName = pFormField->GetFullName();
+ CJS_Field * pJSField = (CJS_Field*)JS_GetPrivate(pFieldObj);
+ ASSERT(pJSField != NULL);
+ Field * pField = (Field *)pJSField->GetEmbedObject();
+ ASSERT(pField != NULL);
+ pField->AttachField(pDocument, m_strSourceName);
+ return pField;
+}
+
+Field* CJS_EventHandler::Target_Field()
+{
+ ASSERT(m_pJSContext != NULL);
+
+ CJS_Runtime* pRuntime = m_pJSContext->GetJSRuntime();
+
+ JSFXObject pDocObj = JS_NewFxDynamicObj(*pRuntime, m_pJSContext, JS_GetObjDefnID(*pRuntime, L"Document"));
+ ASSERT(pDocObj.IsEmpty() == FALSE);
+ JSFXObject pFieldObj = JS_NewFxDynamicObj(*pRuntime, m_pJSContext, JS_GetObjDefnID(*pRuntime, L"Field"));
+ ASSERT(pFieldObj.IsEmpty() == FALSE);
+
+ CJS_Document* pJSDocument = (CJS_Document*)JS_GetPrivate(pDocObj);
+ ASSERT(pJSDocument != NULL);
+ Document* pDocument = (Document*)pJSDocument->GetEmbedObject();
+ ASSERT(pDocument != NULL);
+ if (m_pTargetDoc != NULL)
+ pDocument->AttachDoc(m_pTargetDoc);
+ else
+ pDocument->AttachDoc(m_pJSContext->GetReaderDocument());
+
+ CJS_Field* pJSField = (CJS_Field*)JS_GetPrivate(pFieldObj);
+ ASSERT(pJSField != NULL);
+
+ Field* pField = (Field *)pJSField->GetEmbedObject();
+ ASSERT(pField != NULL);
+
+ pField->AttachField(pDocument, m_strTargetName);
+ return pField;
+}
+
+CFX_WideString& CJS_EventHandler::Value()
+{
+ return *m_pValue;
+}
+
+FX_BOOL CJS_EventHandler::WillCommit()
+{
+ return m_bWillCommit;
+}
+
+CFX_WideString CJS_EventHandler::TargetName()
+{
+ return m_strTargetName;
+}
+
+
diff --git a/fpdfsdk/src/javascript/JS_GlobalData.cpp b/fpdfsdk/src/javascript/JS_GlobalData.cpp
index 97bba8d243..2207726890 100644
--- a/fpdfsdk/src/javascript/JS_GlobalData.cpp
+++ b/fpdfsdk/src/javascript/JS_GlobalData.cpp
@@ -1,581 +1,581 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/javascript/JavaScript.h"
-#include "../../include/javascript/IJavaScript.h"
-#include "../../include/javascript/JS_GlobalData.h"
-
-#define JS_MAXGLOBALDATA (1024 * 4 - 8)
-
-/* --------------------- CJS_GlobalVariableArray --------------------- */
-
-CJS_GlobalVariableArray::CJS_GlobalVariableArray()
-{
-}
-
-CJS_GlobalVariableArray::~CJS_GlobalVariableArray()
-{
- Empty();
-}
-
-void CJS_GlobalVariableArray::Copy(const CJS_GlobalVariableArray& array)
-{
- Empty();
- for (int i=0,sz=array.Count(); i<sz; i++)
- {
- CJS_KeyValue* pOldObjData = array.GetAt(i);
- ASSERT(pOldObjData != NULL);
-
- switch (pOldObjData->nType)
- {
- case JS_GLOBALDATA_TYPE_NUMBER:
- {
- CJS_KeyValue* pNewObjData = new CJS_KeyValue;
- pNewObjData->sKey = pOldObjData->sKey;
- pNewObjData->nType = pOldObjData->nType;
- pNewObjData->dData = pOldObjData->dData;
- Add(pNewObjData);
- }
- break;
- case JS_GLOBALDATA_TYPE_BOOLEAN:
- {
- CJS_KeyValue* pNewObjData = new CJS_KeyValue;
- pNewObjData->sKey = pOldObjData->sKey;
- pNewObjData->nType = pOldObjData->nType;
- pNewObjData->bData = pOldObjData->bData;
- Add(pNewObjData);
- }
- break;
- case JS_GLOBALDATA_TYPE_STRING:
- {
- CJS_KeyValue* pNewObjData = new CJS_KeyValue;
- pNewObjData->sKey = pOldObjData->sKey;
- pNewObjData->nType = pOldObjData->nType;
- pNewObjData->sData = pOldObjData->sData;
- Add(pNewObjData);
- }
- break;
- case JS_GLOBALDATA_TYPE_OBJECT:
- {
- CJS_KeyValue* pNewObjData = new CJS_KeyValue;
- pNewObjData->sKey = pOldObjData->sKey;
- pNewObjData->nType = pOldObjData->nType;
- pNewObjData->objData.Copy(pOldObjData->objData);
- Add(pNewObjData);
- }
- case JS_GLOBALDATA_TYPE_NULL:
- {
- CJS_KeyValue* pNewObjData = new CJS_KeyValue;
- pNewObjData->sKey = pOldObjData->sKey;
- pNewObjData->nType = pOldObjData->nType;
- Add(pNewObjData);
- }
- }
- }
-}
-
-void CJS_GlobalVariableArray::Add(CJS_KeyValue* p)
-{
- array.Add(p);
-}
-
-int CJS_GlobalVariableArray::Count() const
-{
- return array.GetSize();
-}
-
-CJS_KeyValue* CJS_GlobalVariableArray::GetAt(int index) const
-{
- return array.GetAt(index);
-}
-
-void CJS_GlobalVariableArray::Empty()
-{
- for (int i=0,sz=array.GetSize(); i<sz; i++)
- delete array.GetAt(i);
- array.RemoveAll();
-}
-
-/* -------------------------- CJS_GlobalData -------------------------- */
-
-#define READER_JS_GLOBALDATA_FILENAME L"Reader_JsGlobal.Data"
-#define PHANTOM_JS_GLOBALDATA_FILENAME L"Phantom_JsGlobal.Data"
-#define SDK_JS_GLOBALDATA_FILENAME L"SDK_JsGlobal.Data"
-
-static const FX_BYTE JS_RC4KEY[] = {0x19,0xa8,0xe8,0x01,0xf6,0xa8,0xb6,0x4d,0x82,0x04,
- 0x45,0x6d,0xb4,0xcf,0xd7,0x77,0x67,0xf9,0x75,0x9f,
- 0xf0,0xe0,0x1e,0x51,0xee,0x46,0xfd,0x0b,0xc9,0x93,
- 0x25,0x55,0x4a,0xee,0xe0,0x16,0xd0,0xdf,0x8c,0xfa,
- 0x2a,0xa9,0x49,0xfd,0x97,0x1c,0x0e,0x22,0x13,0x28,
- 0x7c,0xaf,0xc4,0xfc,0x9c,0x12,0x65,0x8c,0x4e,0x5b,
- 0x04,0x75,0x89,0xc9,0xb1,0xed,0x50,0xca,0x96,0x6f,
- 0x1a,0x7a,0xfe,0x58,0x5d,0xec,0x19,0x4a,0xf6,0x35,
- 0x6a,0x97,0x14,0x00,0x0e,0xd0,0x6b,0xbb,0xd5,0x75,
- 0x55,0x8b,0x6e,0x6b,0x19,0xa0,0xf8,0x77,0xd5,0xa3
- };
-
-CJS_GlobalData::CJS_GlobalData(CPDFDoc_Environment* pApp) : m_pApp(pApp)
-{
-// IBaseAnnot* pBaseAnnot = IBaseAnnot::GetBaseAnnot(m_pApp);
-// ASSERT(pBaseAnnot != NULL);
-//
-// m_sFilePath = pBaseAnnot->GetUserPath();
- m_sFilePath += SDK_JS_GLOBALDATA_FILENAME;
-
- LoadGlobalPersistentVariables();
-}
-
-CJS_GlobalData::~CJS_GlobalData()
-{
- SaveGlobalPersisitentVariables();
-
- for (int i=0,sz=m_arrayGlobalData.GetSize(); i<sz; i++)
- delete m_arrayGlobalData.GetAt(i);
-
- m_arrayGlobalData.RemoveAll();
-}
-
-int CJS_GlobalData::FindGlobalVariable(FX_LPCSTR propname)
-{
- ASSERT(propname != NULL);
-
- int nRet = -1;
-
- for (int i=0,sz=m_arrayGlobalData.GetSize(); i<sz; i++)
- {
- CJS_GlobalData_Element* pTemp = m_arrayGlobalData.GetAt(i);
- if (pTemp->data.sKey[0] == *propname && pTemp->data.sKey == propname)
- {
- nRet = i;
- break;
- }
- }
-
- return nRet;
-}
-
-CJS_GlobalData_Element* CJS_GlobalData::GetGlobalVariable(FX_LPCSTR propname)
-{
- ASSERT(propname != NULL);
-
- int nFind = FindGlobalVariable(propname);
-
- if (nFind >= 0)
- return m_arrayGlobalData.GetAt(nFind);
- else
- return NULL;
-}
-
-void CJS_GlobalData::SetGlobalVariableNumber(FX_LPCSTR propname, double dData)
-{
- ASSERT(propname != NULL);
- CFX_ByteString sPropName = propname;
-
- sPropName.TrimLeft();
- sPropName.TrimRight();
-
- if (sPropName.GetLength() == 0) return;
-
- if (CJS_GlobalData_Element* pData = GetGlobalVariable(sPropName))
- {
- pData->data.nType = JS_GLOBALDATA_TYPE_NUMBER;
- pData->data.dData = dData;
- }
- else
- {
- CJS_GlobalData_Element* pNewData = new CJS_GlobalData_Element;
- pNewData->data.sKey = sPropName;
- pNewData->data.nType = JS_GLOBALDATA_TYPE_NUMBER;
- pNewData->data.dData = dData;
-
- m_arrayGlobalData.Add(pNewData);
- }
-}
-
-void CJS_GlobalData::SetGlobalVariableBoolean(FX_LPCSTR propname, bool bData)
-{
- ASSERT(propname != NULL);
- CFX_ByteString sPropName = propname;
-
- sPropName.TrimLeft();
- sPropName.TrimRight();
-
- if (sPropName.GetLength() == 0) return;
-
- if (CJS_GlobalData_Element* pData = GetGlobalVariable(sPropName))
- {
- pData->data.nType = JS_GLOBALDATA_TYPE_BOOLEAN;
- pData->data.bData = bData;
- }
- else
- {
- CJS_GlobalData_Element* pNewData = new CJS_GlobalData_Element;
- pNewData->data.sKey = sPropName;
- pNewData->data.nType = JS_GLOBALDATA_TYPE_BOOLEAN;
- pNewData->data.bData = bData;
-
- m_arrayGlobalData.Add(pNewData);
- }
-}
-
-void CJS_GlobalData::SetGlobalVariableString(FX_LPCSTR propname, const CFX_ByteString& sData)
-{
- ASSERT(propname != NULL);
- CFX_ByteString sPropName = propname;
-
- sPropName.TrimLeft();
- sPropName.TrimRight();
-
- if (sPropName.GetLength() == 0) return;
-
- if (CJS_GlobalData_Element* pData = GetGlobalVariable(sPropName))
- {
- pData->data.nType = JS_GLOBALDATA_TYPE_STRING;
- pData->data.sData = sData;
- }
- else
- {
- CJS_GlobalData_Element* pNewData = new CJS_GlobalData_Element;
- pNewData->data.sKey = sPropName;
- pNewData->data.nType = JS_GLOBALDATA_TYPE_STRING;
- pNewData->data.sData = sData;
-
- m_arrayGlobalData.Add(pNewData);
- }
-}
-
-void CJS_GlobalData::SetGlobalVariableObject(FX_LPCSTR propname, const CJS_GlobalVariableArray& array)
-{
- ASSERT(propname != NULL);
- CFX_ByteString sPropName = propname;
-
- sPropName.TrimLeft();
- sPropName.TrimRight();
-
- if (sPropName.GetLength() == 0) return;
-
- if (CJS_GlobalData_Element* pData = GetGlobalVariable(sPropName))
- {
- pData->data.nType = JS_GLOBALDATA_TYPE_OBJECT;
- pData->data.objData.Copy(array);
- }
- else
- {
- CJS_GlobalData_Element* pNewData = new CJS_GlobalData_Element;
- pNewData->data.sKey = sPropName;
- pNewData->data.nType = JS_GLOBALDATA_TYPE_OBJECT;
- pNewData->data.objData.Copy(array);
-
- m_arrayGlobalData.Add(pNewData);
- }
-}
-
-void CJS_GlobalData::SetGlobalVariableNull(FX_LPCSTR propname)
-{
- ASSERT(propname != NULL);
- CFX_ByteString sPropName = propname;
-
- sPropName.TrimLeft();
- sPropName.TrimRight();
-
- if (sPropName.GetLength() == 0) return;
-
- if (CJS_GlobalData_Element* pData = GetGlobalVariable(sPropName))
- {
- pData->data.nType = JS_GLOBALDATA_TYPE_NULL;
- }
- else
- {
- CJS_GlobalData_Element* pNewData = new CJS_GlobalData_Element;
- pNewData->data.sKey = sPropName;
- pNewData->data.nType = JS_GLOBALDATA_TYPE_NULL;
-
- m_arrayGlobalData.Add(pNewData);
- }
-}
-
-FX_BOOL CJS_GlobalData::SetGlobalVariablePersistent(FX_LPCSTR propname, FX_BOOL bPersistent)
-{
- ASSERT(propname != NULL);
- CFX_ByteString sPropName = propname;
-
- sPropName.TrimLeft();
- sPropName.TrimRight();
-
- if (sPropName.GetLength() == 0) return FALSE;
-
- if (CJS_GlobalData_Element* pData = GetGlobalVariable(sPropName))
- {
- pData->bPersistent = bPersistent;
- return TRUE;
- }
-
- return FALSE;
-}
-
-FX_BOOL CJS_GlobalData::DeleteGlobalVariable(FX_LPCSTR propname)
-{
- ASSERT(propname != NULL);
- CFX_ByteString sPropName = propname;
-
- sPropName.TrimLeft();
- sPropName.TrimRight();
-
- if (sPropName.GetLength() == 0) return FALSE;
-
- int nFind = FindGlobalVariable(sPropName);
-
- if (nFind >= 0)
- {
- delete m_arrayGlobalData.GetAt(nFind);
- m_arrayGlobalData.RemoveAt(nFind);
- return TRUE;
- }
-
- return FALSE;
-}
-
-FX_INT32 CJS_GlobalData::GetSize() const
-{
- return m_arrayGlobalData.GetSize();
-}
-
-CJS_GlobalData_Element* CJS_GlobalData::GetAt(int index) const
-{
- return m_arrayGlobalData.GetAt(index);
-}
-
-void CJS_GlobalData::LoadGlobalPersistentVariables()
-{
- FX_LPBYTE pBuffer = NULL;
- FX_INT32 nLength = 0;
-
- LoadFileBuffer(m_sFilePath, pBuffer, nLength);
-
- CRYPT_ArcFourCryptBlock(pBuffer, nLength, JS_RC4KEY, sizeof(JS_RC4KEY));
-
- if (pBuffer)
- {
- FX_LPBYTE p = pBuffer;
- FX_WORD wType = *((FX_WORD*)p);
- p += sizeof(FX_WORD);
-
- //FX_WORD wTemp = (FX_WORD)(('X' << 8) | 'F');
-
- if (wType == (FX_WORD)(('X' << 8) | 'F'))
- {
- FX_WORD wVersion = *((FX_WORD*)p);
- p += sizeof(FX_WORD);
-
- ASSERT(wVersion <= 2);
-
- FX_DWORD dwCount = *((FX_DWORD*)p);
- p += sizeof(FX_DWORD);
-
- FX_DWORD dwSize = *((FX_DWORD*)p);
- p += sizeof(FX_DWORD);
-
- if (dwSize == nLength - sizeof(FX_WORD) * 2 - sizeof(FX_DWORD)* 2)
- {
- for (FX_INT32 i=0,sz=dwCount; i<sz; i++)
- {
- if (p > pBuffer + nLength)
- break;
-
- FX_DWORD dwNameLen = *((FX_DWORD*)p);
- p += sizeof(FX_DWORD);
-
- if (p + dwNameLen > pBuffer + nLength)
- break;
-
- CFX_ByteString sEntry = CFX_ByteString(p, dwNameLen);
- p += sizeof(char) * dwNameLen;
-
- FX_WORD wDataType = *((FX_WORD*)p);
- p += sizeof(FX_WORD);
-
- switch (wDataType)
- {
- case JS_GLOBALDATA_TYPE_NUMBER:
- {
- double dData = 0;
- switch (wVersion)
- {
- case 1:
- {
- FX_DWORD dwData = *((FX_DWORD*)p);
- p += sizeof(FX_DWORD);
- dData = dwData;
- }
- break;
- case 2:
- {
- dData = *((double*)p);
- p += sizeof(double);
- }
- break;
- }
- SetGlobalVariableNumber(sEntry, dData);
- SetGlobalVariablePersistent(sEntry, TRUE);
- }
- break;
- case JS_GLOBALDATA_TYPE_BOOLEAN:
- {
- FX_WORD wData = *((FX_WORD*)p);
- p += sizeof(FX_WORD);
- SetGlobalVariableBoolean(sEntry, (bool)(wData == 1));
- SetGlobalVariablePersistent(sEntry, TRUE);
- }
- break;
- case JS_GLOBALDATA_TYPE_STRING:
- {
- FX_DWORD dwLength = *((FX_DWORD*)p);
- p += sizeof(FX_DWORD);
-
- if (p + dwLength > pBuffer + nLength)
- break;
-
- SetGlobalVariableString(sEntry, CFX_ByteString(p, dwLength));
- SetGlobalVariablePersistent(sEntry, TRUE);
- p += sizeof(char) * dwLength;
- }
- break;
- case JS_GLOBALDATA_TYPE_NULL:
- {
- SetGlobalVariableNull(sEntry);
- SetGlobalVariablePersistent(sEntry, TRUE);
- }
- }
- }
- }
- }
- FX_Free(pBuffer);
- }
-}
-
-/*
-struct js_global_datafile_header
-{
- FX_WORD type; //FX ('X' << 8) | 'F'
- FX_WORD version; //1.0
- FX_DWORD datacount;
-};
-struct js_global_datafile_data
-{
- FX_WORD type;
- FX_DWORD nData;
- FX_WORD bData;
- FX_DWORD nStrLen;
- char* pStr;
-};
-*/
-
-void CJS_GlobalData::SaveGlobalPersisitentVariables()
-{
- FX_DWORD nCount = 0;
- CFX_BinaryBuf sData;
-
- for (int i=0,sz=m_arrayGlobalData.GetSize(); i<sz; i++)
- {
- CJS_GlobalData_Element* pElement = m_arrayGlobalData.GetAt(i);
- ASSERT(pElement != NULL);
-
- if (pElement->bPersistent)
- {
- CFX_BinaryBuf sElement;
- MakeByteString(pElement->data.sKey, &pElement->data, sElement);
-
- if (sData.GetSize() + sElement.GetSize() > JS_MAXGLOBALDATA)
- break;
-
- sData.AppendBlock(sElement.GetBuffer(), sElement.GetSize());
- nCount++;
- }
- }
-
- CFX_BinaryBuf sFile;
-
- FX_WORD wType = (FX_WORD)(('X' << 8) | 'F');
- sFile.AppendBlock(&wType, sizeof(FX_WORD));
- FX_WORD wVersion = 2;
- sFile.AppendBlock(&wVersion, sizeof(FX_WORD));
- sFile.AppendBlock(&nCount, sizeof(FX_DWORD));
- FX_DWORD dwSize = sData.GetSize();
- sFile.AppendBlock(&dwSize, sizeof(FX_DWORD));
-
- sFile.AppendBlock(sData.GetBuffer(), sData.GetSize());
-
- CRYPT_ArcFourCryptBlock(sFile.GetBuffer(), sFile.GetSize(), JS_RC4KEY, sizeof(JS_RC4KEY));
- WriteFileBuffer(m_sFilePath, (FX_LPCSTR)sFile.GetBuffer(), sFile.GetSize());
-}
-
-void CJS_GlobalData::LoadFileBuffer(FX_LPCWSTR sFilePath, FX_LPBYTE& pBuffer, FX_INT32& nLength)
-{
-//UnSupport.
-}
-
-void CJS_GlobalData::WriteFileBuffer(FX_LPCWSTR sFilePath, FX_LPCSTR pBuffer, FX_INT32 nLength)
-{
-//UnSupport.
-}
-
-void CJS_GlobalData::MakeByteString(const CFX_ByteString& name, CJS_KeyValue* pData, CFX_BinaryBuf& sData)
-{
- ASSERT(pData != NULL);
-
- FX_WORD wType = (FX_WORD)pData->nType;
-
- switch (wType)
- {
- case JS_GLOBALDATA_TYPE_NUMBER:
- {
- FX_DWORD dwNameLen = (FX_DWORD)name.GetLength();
- sData.AppendBlock(&dwNameLen, sizeof(FX_DWORD));
- sData.AppendString(name);
-
- sData.AppendBlock(&wType, sizeof(FX_WORD));
- double dData = pData->dData;
- sData.AppendBlock(&dData, sizeof(double));
- }
- break;
- case JS_GLOBALDATA_TYPE_BOOLEAN:
- {
- FX_DWORD dwNameLen = (FX_DWORD)name.GetLength();
- sData.AppendBlock(&dwNameLen, sizeof(FX_DWORD));
- sData.AppendString(name);
-
- sData.AppendBlock(&wType, sizeof(FX_WORD));
- FX_WORD wData = (FX_WORD)pData->bData;
- sData.AppendBlock(&wData, sizeof(FX_WORD));
- }
- break;
- case JS_GLOBALDATA_TYPE_STRING:
- {
- FX_DWORD dwNameLen = (FX_DWORD)name.GetLength();
- sData.AppendBlock(&dwNameLen, sizeof(FX_DWORD));
- sData.AppendString(name);
-
- sData.AppendBlock(&wType, sizeof(FX_WORD));
-
- FX_DWORD dwDataLen = (FX_DWORD)pData->sData.GetLength();
- sData.AppendBlock(&dwDataLen, sizeof(FX_DWORD));
- sData.AppendString(pData->sData);
- }
- break;
- case JS_GLOBALDATA_TYPE_NULL:
- {
- FX_DWORD dwNameLen = (FX_DWORD)name.GetLength();
- sData.AppendBlock(&dwNameLen, sizeof(FX_DWORD));
- sData.AppendString(name);
-
- sData.AppendBlock(&wType, sizeof(FX_DWORD));
- }
- break;
- default:
- break;
- }
-}
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/javascript/JavaScript.h"
+#include "../../include/javascript/IJavaScript.h"
+#include "../../include/javascript/JS_GlobalData.h"
+
+#define JS_MAXGLOBALDATA (1024 * 4 - 8)
+
+/* --------------------- CJS_GlobalVariableArray --------------------- */
+
+CJS_GlobalVariableArray::CJS_GlobalVariableArray()
+{
+}
+
+CJS_GlobalVariableArray::~CJS_GlobalVariableArray()
+{
+ Empty();
+}
+
+void CJS_GlobalVariableArray::Copy(const CJS_GlobalVariableArray& array)
+{
+ Empty();
+ for (int i=0,sz=array.Count(); i<sz; i++)
+ {
+ CJS_KeyValue* pOldObjData = array.GetAt(i);
+ ASSERT(pOldObjData != NULL);
+
+ switch (pOldObjData->nType)
+ {
+ case JS_GLOBALDATA_TYPE_NUMBER:
+ {
+ CJS_KeyValue* pNewObjData = new CJS_KeyValue;
+ pNewObjData->sKey = pOldObjData->sKey;
+ pNewObjData->nType = pOldObjData->nType;
+ pNewObjData->dData = pOldObjData->dData;
+ Add(pNewObjData);
+ }
+ break;
+ case JS_GLOBALDATA_TYPE_BOOLEAN:
+ {
+ CJS_KeyValue* pNewObjData = new CJS_KeyValue;
+ pNewObjData->sKey = pOldObjData->sKey;
+ pNewObjData->nType = pOldObjData->nType;
+ pNewObjData->bData = pOldObjData->bData;
+ Add(pNewObjData);
+ }
+ break;
+ case JS_GLOBALDATA_TYPE_STRING:
+ {
+ CJS_KeyValue* pNewObjData = new CJS_KeyValue;
+ pNewObjData->sKey = pOldObjData->sKey;
+ pNewObjData->nType = pOldObjData->nType;
+ pNewObjData->sData = pOldObjData->sData;
+ Add(pNewObjData);
+ }
+ break;
+ case JS_GLOBALDATA_TYPE_OBJECT:
+ {
+ CJS_KeyValue* pNewObjData = new CJS_KeyValue;
+ pNewObjData->sKey = pOldObjData->sKey;
+ pNewObjData->nType = pOldObjData->nType;
+ pNewObjData->objData.Copy(pOldObjData->objData);
+ Add(pNewObjData);
+ }
+ case JS_GLOBALDATA_TYPE_NULL:
+ {
+ CJS_KeyValue* pNewObjData = new CJS_KeyValue;
+ pNewObjData->sKey = pOldObjData->sKey;
+ pNewObjData->nType = pOldObjData->nType;
+ Add(pNewObjData);
+ }
+ }
+ }
+}
+
+void CJS_GlobalVariableArray::Add(CJS_KeyValue* p)
+{
+ array.Add(p);
+}
+
+int CJS_GlobalVariableArray::Count() const
+{
+ return array.GetSize();
+}
+
+CJS_KeyValue* CJS_GlobalVariableArray::GetAt(int index) const
+{
+ return array.GetAt(index);
+}
+
+void CJS_GlobalVariableArray::Empty()
+{
+ for (int i=0,sz=array.GetSize(); i<sz; i++)
+ delete array.GetAt(i);
+ array.RemoveAll();
+}
+
+/* -------------------------- CJS_GlobalData -------------------------- */
+
+#define READER_JS_GLOBALDATA_FILENAME L"Reader_JsGlobal.Data"
+#define PHANTOM_JS_GLOBALDATA_FILENAME L"Phantom_JsGlobal.Data"
+#define SDK_JS_GLOBALDATA_FILENAME L"SDK_JsGlobal.Data"
+
+static const FX_BYTE JS_RC4KEY[] = {0x19,0xa8,0xe8,0x01,0xf6,0xa8,0xb6,0x4d,0x82,0x04,
+ 0x45,0x6d,0xb4,0xcf,0xd7,0x77,0x67,0xf9,0x75,0x9f,
+ 0xf0,0xe0,0x1e,0x51,0xee,0x46,0xfd,0x0b,0xc9,0x93,
+ 0x25,0x55,0x4a,0xee,0xe0,0x16,0xd0,0xdf,0x8c,0xfa,
+ 0x2a,0xa9,0x49,0xfd,0x97,0x1c,0x0e,0x22,0x13,0x28,
+ 0x7c,0xaf,0xc4,0xfc,0x9c,0x12,0x65,0x8c,0x4e,0x5b,
+ 0x04,0x75,0x89,0xc9,0xb1,0xed,0x50,0xca,0x96,0x6f,
+ 0x1a,0x7a,0xfe,0x58,0x5d,0xec,0x19,0x4a,0xf6,0x35,
+ 0x6a,0x97,0x14,0x00,0x0e,0xd0,0x6b,0xbb,0xd5,0x75,
+ 0x55,0x8b,0x6e,0x6b,0x19,0xa0,0xf8,0x77,0xd5,0xa3
+ };
+
+CJS_GlobalData::CJS_GlobalData(CPDFDoc_Environment* pApp) : m_pApp(pApp)
+{
+// IBaseAnnot* pBaseAnnot = IBaseAnnot::GetBaseAnnot(m_pApp);
+// ASSERT(pBaseAnnot != NULL);
+//
+// m_sFilePath = pBaseAnnot->GetUserPath();
+ m_sFilePath += SDK_JS_GLOBALDATA_FILENAME;
+
+ LoadGlobalPersistentVariables();
+}
+
+CJS_GlobalData::~CJS_GlobalData()
+{
+ SaveGlobalPersisitentVariables();
+
+ for (int i=0,sz=m_arrayGlobalData.GetSize(); i<sz; i++)
+ delete m_arrayGlobalData.GetAt(i);
+
+ m_arrayGlobalData.RemoveAll();
+}
+
+int CJS_GlobalData::FindGlobalVariable(FX_LPCSTR propname)
+{
+ ASSERT(propname != NULL);
+
+ int nRet = -1;
+
+ for (int i=0,sz=m_arrayGlobalData.GetSize(); i<sz; i++)
+ {
+ CJS_GlobalData_Element* pTemp = m_arrayGlobalData.GetAt(i);
+ if (pTemp->data.sKey[0] == *propname && pTemp->data.sKey == propname)
+ {
+ nRet = i;
+ break;
+ }
+ }
+
+ return nRet;
+}
+
+CJS_GlobalData_Element* CJS_GlobalData::GetGlobalVariable(FX_LPCSTR propname)
+{
+ ASSERT(propname != NULL);
+
+ int nFind = FindGlobalVariable(propname);
+
+ if (nFind >= 0)
+ return m_arrayGlobalData.GetAt(nFind);
+ else
+ return NULL;
+}
+
+void CJS_GlobalData::SetGlobalVariableNumber(FX_LPCSTR propname, double dData)
+{
+ ASSERT(propname != NULL);
+ CFX_ByteString sPropName = propname;
+
+ sPropName.TrimLeft();
+ sPropName.TrimRight();
+
+ if (sPropName.GetLength() == 0) return;
+
+ if (CJS_GlobalData_Element* pData = GetGlobalVariable(sPropName))
+ {
+ pData->data.nType = JS_GLOBALDATA_TYPE_NUMBER;
+ pData->data.dData = dData;
+ }
+ else
+ {
+ CJS_GlobalData_Element* pNewData = new CJS_GlobalData_Element;
+ pNewData->data.sKey = sPropName;
+ pNewData->data.nType = JS_GLOBALDATA_TYPE_NUMBER;
+ pNewData->data.dData = dData;
+
+ m_arrayGlobalData.Add(pNewData);
+ }
+}
+
+void CJS_GlobalData::SetGlobalVariableBoolean(FX_LPCSTR propname, bool bData)
+{
+ ASSERT(propname != NULL);
+ CFX_ByteString sPropName = propname;
+
+ sPropName.TrimLeft();
+ sPropName.TrimRight();
+
+ if (sPropName.GetLength() == 0) return;
+
+ if (CJS_GlobalData_Element* pData = GetGlobalVariable(sPropName))
+ {
+ pData->data.nType = JS_GLOBALDATA_TYPE_BOOLEAN;
+ pData->data.bData = bData;
+ }
+ else
+ {
+ CJS_GlobalData_Element* pNewData = new CJS_GlobalData_Element;
+ pNewData->data.sKey = sPropName;
+ pNewData->data.nType = JS_GLOBALDATA_TYPE_BOOLEAN;
+ pNewData->data.bData = bData;
+
+ m_arrayGlobalData.Add(pNewData);
+ }
+}
+
+void CJS_GlobalData::SetGlobalVariableString(FX_LPCSTR propname, const CFX_ByteString& sData)
+{
+ ASSERT(propname != NULL);
+ CFX_ByteString sPropName = propname;
+
+ sPropName.TrimLeft();
+ sPropName.TrimRight();
+
+ if (sPropName.GetLength() == 0) return;
+
+ if (CJS_GlobalData_Element* pData = GetGlobalVariable(sPropName))
+ {
+ pData->data.nType = JS_GLOBALDATA_TYPE_STRING;
+ pData->data.sData = sData;
+ }
+ else
+ {
+ CJS_GlobalData_Element* pNewData = new CJS_GlobalData_Element;
+ pNewData->data.sKey = sPropName;
+ pNewData->data.nType = JS_GLOBALDATA_TYPE_STRING;
+ pNewData->data.sData = sData;
+
+ m_arrayGlobalData.Add(pNewData);
+ }
+}
+
+void CJS_GlobalData::SetGlobalVariableObject(FX_LPCSTR propname, const CJS_GlobalVariableArray& array)
+{
+ ASSERT(propname != NULL);
+ CFX_ByteString sPropName = propname;
+
+ sPropName.TrimLeft();
+ sPropName.TrimRight();
+
+ if (sPropName.GetLength() == 0) return;
+
+ if (CJS_GlobalData_Element* pData = GetGlobalVariable(sPropName))
+ {
+ pData->data.nType = JS_GLOBALDATA_TYPE_OBJECT;
+ pData->data.objData.Copy(array);
+ }
+ else
+ {
+ CJS_GlobalData_Element* pNewData = new CJS_GlobalData_Element;
+ pNewData->data.sKey = sPropName;
+ pNewData->data.nType = JS_GLOBALDATA_TYPE_OBJECT;
+ pNewData->data.objData.Copy(array);
+
+ m_arrayGlobalData.Add(pNewData);
+ }
+}
+
+void CJS_GlobalData::SetGlobalVariableNull(FX_LPCSTR propname)
+{
+ ASSERT(propname != NULL);
+ CFX_ByteString sPropName = propname;
+
+ sPropName.TrimLeft();
+ sPropName.TrimRight();
+
+ if (sPropName.GetLength() == 0) return;
+
+ if (CJS_GlobalData_Element* pData = GetGlobalVariable(sPropName))
+ {
+ pData->data.nType = JS_GLOBALDATA_TYPE_NULL;
+ }
+ else
+ {
+ CJS_GlobalData_Element* pNewData = new CJS_GlobalData_Element;
+ pNewData->data.sKey = sPropName;
+ pNewData->data.nType = JS_GLOBALDATA_TYPE_NULL;
+
+ m_arrayGlobalData.Add(pNewData);
+ }
+}
+
+FX_BOOL CJS_GlobalData::SetGlobalVariablePersistent(FX_LPCSTR propname, FX_BOOL bPersistent)
+{
+ ASSERT(propname != NULL);
+ CFX_ByteString sPropName = propname;
+
+ sPropName.TrimLeft();
+ sPropName.TrimRight();
+
+ if (sPropName.GetLength() == 0) return FALSE;
+
+ if (CJS_GlobalData_Element* pData = GetGlobalVariable(sPropName))
+ {
+ pData->bPersistent = bPersistent;
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+FX_BOOL CJS_GlobalData::DeleteGlobalVariable(FX_LPCSTR propname)
+{
+ ASSERT(propname != NULL);
+ CFX_ByteString sPropName = propname;
+
+ sPropName.TrimLeft();
+ sPropName.TrimRight();
+
+ if (sPropName.GetLength() == 0) return FALSE;
+
+ int nFind = FindGlobalVariable(sPropName);
+
+ if (nFind >= 0)
+ {
+ delete m_arrayGlobalData.GetAt(nFind);
+ m_arrayGlobalData.RemoveAt(nFind);
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+FX_INT32 CJS_GlobalData::GetSize() const
+{
+ return m_arrayGlobalData.GetSize();
+}
+
+CJS_GlobalData_Element* CJS_GlobalData::GetAt(int index) const
+{
+ return m_arrayGlobalData.GetAt(index);
+}
+
+void CJS_GlobalData::LoadGlobalPersistentVariables()
+{
+ FX_LPBYTE pBuffer = NULL;
+ FX_INT32 nLength = 0;
+
+ LoadFileBuffer(m_sFilePath, pBuffer, nLength);
+
+ CRYPT_ArcFourCryptBlock(pBuffer, nLength, JS_RC4KEY, sizeof(JS_RC4KEY));
+
+ if (pBuffer)
+ {
+ FX_LPBYTE p = pBuffer;
+ FX_WORD wType = *((FX_WORD*)p);
+ p += sizeof(FX_WORD);
+
+ //FX_WORD wTemp = (FX_WORD)(('X' << 8) | 'F');
+
+ if (wType == (FX_WORD)(('X' << 8) | 'F'))
+ {
+ FX_WORD wVersion = *((FX_WORD*)p);
+ p += sizeof(FX_WORD);
+
+ ASSERT(wVersion <= 2);
+
+ FX_DWORD dwCount = *((FX_DWORD*)p);
+ p += sizeof(FX_DWORD);
+
+ FX_DWORD dwSize = *((FX_DWORD*)p);
+ p += sizeof(FX_DWORD);
+
+ if (dwSize == nLength - sizeof(FX_WORD) * 2 - sizeof(FX_DWORD)* 2)
+ {
+ for (FX_INT32 i=0,sz=dwCount; i<sz; i++)
+ {
+ if (p > pBuffer + nLength)
+ break;
+
+ FX_DWORD dwNameLen = *((FX_DWORD*)p);
+ p += sizeof(FX_DWORD);
+
+ if (p + dwNameLen > pBuffer + nLength)
+ break;
+
+ CFX_ByteString sEntry = CFX_ByteString(p, dwNameLen);
+ p += sizeof(char) * dwNameLen;
+
+ FX_WORD wDataType = *((FX_WORD*)p);
+ p += sizeof(FX_WORD);
+
+ switch (wDataType)
+ {
+ case JS_GLOBALDATA_TYPE_NUMBER:
+ {
+ double dData = 0;
+ switch (wVersion)
+ {
+ case 1:
+ {
+ FX_DWORD dwData = *((FX_DWORD*)p);
+ p += sizeof(FX_DWORD);
+ dData = dwData;
+ }
+ break;
+ case 2:
+ {
+ dData = *((double*)p);
+ p += sizeof(double);
+ }
+ break;
+ }
+ SetGlobalVariableNumber(sEntry, dData);
+ SetGlobalVariablePersistent(sEntry, TRUE);
+ }
+ break;
+ case JS_GLOBALDATA_TYPE_BOOLEAN:
+ {
+ FX_WORD wData = *((FX_WORD*)p);
+ p += sizeof(FX_WORD);
+ SetGlobalVariableBoolean(sEntry, (bool)(wData == 1));
+ SetGlobalVariablePersistent(sEntry, TRUE);
+ }
+ break;
+ case JS_GLOBALDATA_TYPE_STRING:
+ {
+ FX_DWORD dwLength = *((FX_DWORD*)p);
+ p += sizeof(FX_DWORD);
+
+ if (p + dwLength > pBuffer + nLength)
+ break;
+
+ SetGlobalVariableString(sEntry, CFX_ByteString(p, dwLength));
+ SetGlobalVariablePersistent(sEntry, TRUE);
+ p += sizeof(char) * dwLength;
+ }
+ break;
+ case JS_GLOBALDATA_TYPE_NULL:
+ {
+ SetGlobalVariableNull(sEntry);
+ SetGlobalVariablePersistent(sEntry, TRUE);
+ }
+ }
+ }
+ }
+ }
+ FX_Free(pBuffer);
+ }
+}
+
+/*
+struct js_global_datafile_header
+{
+ FX_WORD type; //FX ('X' << 8) | 'F'
+ FX_WORD version; //1.0
+ FX_DWORD datacount;
+};
+struct js_global_datafile_data
+{
+ FX_WORD type;
+ FX_DWORD nData;
+ FX_WORD bData;
+ FX_DWORD nStrLen;
+ char* pStr;
+};
+*/
+
+void CJS_GlobalData::SaveGlobalPersisitentVariables()
+{
+ FX_DWORD nCount = 0;
+ CFX_BinaryBuf sData;
+
+ for (int i=0,sz=m_arrayGlobalData.GetSize(); i<sz; i++)
+ {
+ CJS_GlobalData_Element* pElement = m_arrayGlobalData.GetAt(i);
+ ASSERT(pElement != NULL);
+
+ if (pElement->bPersistent)
+ {
+ CFX_BinaryBuf sElement;
+ MakeByteString(pElement->data.sKey, &pElement->data, sElement);
+
+ if (sData.GetSize() + sElement.GetSize() > JS_MAXGLOBALDATA)
+ break;
+
+ sData.AppendBlock(sElement.GetBuffer(), sElement.GetSize());
+ nCount++;
+ }
+ }
+
+ CFX_BinaryBuf sFile;
+
+ FX_WORD wType = (FX_WORD)(('X' << 8) | 'F');
+ sFile.AppendBlock(&wType, sizeof(FX_WORD));
+ FX_WORD wVersion = 2;
+ sFile.AppendBlock(&wVersion, sizeof(FX_WORD));
+ sFile.AppendBlock(&nCount, sizeof(FX_DWORD));
+ FX_DWORD dwSize = sData.GetSize();
+ sFile.AppendBlock(&dwSize, sizeof(FX_DWORD));
+
+ sFile.AppendBlock(sData.GetBuffer(), sData.GetSize());
+
+ CRYPT_ArcFourCryptBlock(sFile.GetBuffer(), sFile.GetSize(), JS_RC4KEY, sizeof(JS_RC4KEY));
+ WriteFileBuffer(m_sFilePath, (FX_LPCSTR)sFile.GetBuffer(), sFile.GetSize());
+}
+
+void CJS_GlobalData::LoadFileBuffer(FX_LPCWSTR sFilePath, FX_LPBYTE& pBuffer, FX_INT32& nLength)
+{
+//UnSupport.
+}
+
+void CJS_GlobalData::WriteFileBuffer(FX_LPCWSTR sFilePath, FX_LPCSTR pBuffer, FX_INT32 nLength)
+{
+//UnSupport.
+}
+
+void CJS_GlobalData::MakeByteString(const CFX_ByteString& name, CJS_KeyValue* pData, CFX_BinaryBuf& sData)
+{
+ ASSERT(pData != NULL);
+
+ FX_WORD wType = (FX_WORD)pData->nType;
+
+ switch (wType)
+ {
+ case JS_GLOBALDATA_TYPE_NUMBER:
+ {
+ FX_DWORD dwNameLen = (FX_DWORD)name.GetLength();
+ sData.AppendBlock(&dwNameLen, sizeof(FX_DWORD));
+ sData.AppendString(name);
+
+ sData.AppendBlock(&wType, sizeof(FX_WORD));
+ double dData = pData->dData;
+ sData.AppendBlock(&dData, sizeof(double));
+ }
+ break;
+ case JS_GLOBALDATA_TYPE_BOOLEAN:
+ {
+ FX_DWORD dwNameLen = (FX_DWORD)name.GetLength();
+ sData.AppendBlock(&dwNameLen, sizeof(FX_DWORD));
+ sData.AppendString(name);
+
+ sData.AppendBlock(&wType, sizeof(FX_WORD));
+ FX_WORD wData = (FX_WORD)pData->bData;
+ sData.AppendBlock(&wData, sizeof(FX_WORD));
+ }
+ break;
+ case JS_GLOBALDATA_TYPE_STRING:
+ {
+ FX_DWORD dwNameLen = (FX_DWORD)name.GetLength();
+ sData.AppendBlock(&dwNameLen, sizeof(FX_DWORD));
+ sData.AppendString(name);
+
+ sData.AppendBlock(&wType, sizeof(FX_WORD));
+
+ FX_DWORD dwDataLen = (FX_DWORD)pData->sData.GetLength();
+ sData.AppendBlock(&dwDataLen, sizeof(FX_DWORD));
+ sData.AppendString(pData->sData);
+ }
+ break;
+ case JS_GLOBALDATA_TYPE_NULL:
+ {
+ FX_DWORD dwNameLen = (FX_DWORD)name.GetLength();
+ sData.AppendBlock(&dwNameLen, sizeof(FX_DWORD));
+ sData.AppendString(name);
+
+ sData.AppendBlock(&wType, sizeof(FX_DWORD));
+ }
+ break;
+ default:
+ break;
+ }
+}
+
diff --git a/fpdfsdk/src/javascript/JS_Object.cpp b/fpdfsdk/src/javascript/JS_Object.cpp
index 3830b2ac53..3b7774d4d8 100644
--- a/fpdfsdk/src/javascript/JS_Object.cpp
+++ b/fpdfsdk/src/javascript/JS_Object.cpp
@@ -1,145 +1,145 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/javascript/JavaScript.h"
-#include "../../include/javascript/IJavaScript.h"
-#include "../../include/javascript/JS_Define.h"
-#include "../../include/javascript/JS_Object.h"
-// #include "../../include/javascript/JS_MsgBox.h"
-// #include "../../include/javascript/JS_ResMgr.h"
-#include "../../include/javascript/JS_Context.h"
-
-int FXJS_MsgBox(CPDFDoc_Environment* pApp, CPDFSDK_PageView* pPageView, FX_LPCWSTR swMsg, FX_LPCWSTR swTitle, FX_UINT nType, FX_UINT nIcon)
-{
- int nRet = 0;
-
- if(pApp)
- {
- CPDFSDK_Document* pDoc = pApp->GetCurrentDoc();
- if(pDoc)
- pDoc->KillFocusAnnot();
- nRet = pApp->JS_appAlert(swMsg, swTitle, nType, nIcon);
- }
-
- return nRet;
-}
-
-CPDFSDK_PageView* FXJS_GetPageView(IFXJS_Context* cc)
-{
- if (CJS_Context* pContext = (CJS_Context *)cc)
- {
- if (pContext->GetReaderDocument())
- return NULL;
- }
- return NULL;
-}
-
-/* --------------------------------- CJS_EmbedObj --------------------------------- */
-
-CJS_EmbedObj::CJS_EmbedObj(CJS_Object* pJSObject) :
- m_pJSObject(pJSObject)
-{
-}
-
-CJS_EmbedObj::~CJS_EmbedObj()
-{
- m_pJSObject = NULL;
-
-}
-
-CPDFSDK_PageView* CJS_EmbedObj::JSGetPageView(IFXJS_Context* cc)
-{
- return FXJS_GetPageView(cc);
-}
-
-int CJS_EmbedObj::MsgBox(CPDFDoc_Environment* pApp, CPDFSDK_PageView* pPageView,FX_LPCWSTR swMsg,FX_LPCWSTR swTitle,FX_UINT nType,FX_UINT nIcon)
-{
- return FXJS_MsgBox(pApp, pPageView, swMsg, swTitle, nType, nIcon);
-}
-
-void CJS_EmbedObj::Alert(CJS_Context* pContext, FX_LPCWSTR swMsg)
-{
- CJS_Object::Alert(pContext, swMsg);
-}
-
-CJS_Timer* CJS_EmbedObj::BeginTimer(CPDFDoc_Environment * pApp,FX_UINT nElapse)
-{
- CJS_Timer* pTimer = new CJS_Timer(this,pApp);
- pTimer->SetJSTimer(nElapse);
-
- return pTimer;
-}
-
-void CJS_EmbedObj::EndTimer(CJS_Timer* pTimer)
-{
- ASSERT(pTimer != NULL);
- pTimer->KillJSTimer();
- delete pTimer;
-}
-
-FX_BOOL CJS_EmbedObj::IsSafeMode(IFXJS_Context* cc)
-{
- ASSERT(cc != NULL);
-
- return TRUE;
-}
-
-/* --------------------------------- CJS_Object --------------------------------- */
-void FreeObject(const v8::WeakCallbackData<v8::Object, CJS_Object>& data)
-{
- CJS_Object* pJSObj = data.GetParameter();
- if(pJSObj)
- {
- pJSObj->ExitInstance();
- delete pJSObj;
- }
- v8::Local<v8::Object> obj = data.GetValue();
- JS_FreePrivate(obj);
-}
-
-CJS_Object::CJS_Object(JSFXObject pObject) :m_pEmbedObj(NULL)
-{
- v8::Local<v8::Context> context = pObject->CreationContext();
- m_pIsolate = context->GetIsolate();
- m_pObject.Reset(m_pIsolate, pObject);
-};
-
-CJS_Object::~CJS_Object(void)
-{
- delete m_pEmbedObj;
- m_pEmbedObj = NULL;
-
- m_pObject.Reset();
-};
-
-void CJS_Object::MakeWeak()
-{
- m_pObject.SetWeak(this, FreeObject);
-}
-
-CPDFSDK_PageView* CJS_Object::JSGetPageView(IFXJS_Context* cc)
-{
- return FXJS_GetPageView(cc);
-}
-
-int CJS_Object::MsgBox(CPDFDoc_Environment* pApp, CPDFSDK_PageView* pPageView, FX_LPCWSTR swMsg, FX_LPCWSTR swTitle, FX_UINT nType, FX_UINT nIcon)
-{
- return FXJS_MsgBox(pApp, pPageView, swMsg, swTitle, nType, nIcon);
-}
-
-void CJS_Object::Alert(CJS_Context* pContext, FX_LPCWSTR swMsg)
-{
- ASSERT(pContext != NULL);
-
- if (pContext->IsMsgBoxEnabled())
- {
- CPDFDoc_Environment* pApp = pContext->GetReaderApp();
- if(pApp)
- pApp->JS_appAlert(swMsg, NULL, 0, 3);
- }
-}
-
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/javascript/JavaScript.h"
+#include "../../include/javascript/IJavaScript.h"
+#include "../../include/javascript/JS_Define.h"
+#include "../../include/javascript/JS_Object.h"
+// #include "../../include/javascript/JS_MsgBox.h"
+// #include "../../include/javascript/JS_ResMgr.h"
+#include "../../include/javascript/JS_Context.h"
+
+int FXJS_MsgBox(CPDFDoc_Environment* pApp, CPDFSDK_PageView* pPageView, FX_LPCWSTR swMsg, FX_LPCWSTR swTitle, FX_UINT nType, FX_UINT nIcon)
+{
+ int nRet = 0;
+
+ if(pApp)
+ {
+ CPDFSDK_Document* pDoc = pApp->GetCurrentDoc();
+ if(pDoc)
+ pDoc->KillFocusAnnot();
+ nRet = pApp->JS_appAlert(swMsg, swTitle, nType, nIcon);
+ }
+
+ return nRet;
+}
+
+CPDFSDK_PageView* FXJS_GetPageView(IFXJS_Context* cc)
+{
+ if (CJS_Context* pContext = (CJS_Context *)cc)
+ {
+ if (pContext->GetReaderDocument())
+ return NULL;
+ }
+ return NULL;
+}
+
+/* --------------------------------- CJS_EmbedObj --------------------------------- */
+
+CJS_EmbedObj::CJS_EmbedObj(CJS_Object* pJSObject) :
+ m_pJSObject(pJSObject)
+{
+}
+
+CJS_EmbedObj::~CJS_EmbedObj()
+{
+ m_pJSObject = NULL;
+
+}
+
+CPDFSDK_PageView* CJS_EmbedObj::JSGetPageView(IFXJS_Context* cc)
+{
+ return FXJS_GetPageView(cc);
+}
+
+int CJS_EmbedObj::MsgBox(CPDFDoc_Environment* pApp, CPDFSDK_PageView* pPageView,FX_LPCWSTR swMsg,FX_LPCWSTR swTitle,FX_UINT nType,FX_UINT nIcon)
+{
+ return FXJS_MsgBox(pApp, pPageView, swMsg, swTitle, nType, nIcon);
+}
+
+void CJS_EmbedObj::Alert(CJS_Context* pContext, FX_LPCWSTR swMsg)
+{
+ CJS_Object::Alert(pContext, swMsg);
+}
+
+CJS_Timer* CJS_EmbedObj::BeginTimer(CPDFDoc_Environment * pApp,FX_UINT nElapse)
+{
+ CJS_Timer* pTimer = new CJS_Timer(this,pApp);
+ pTimer->SetJSTimer(nElapse);
+
+ return pTimer;
+}
+
+void CJS_EmbedObj::EndTimer(CJS_Timer* pTimer)
+{
+ ASSERT(pTimer != NULL);
+ pTimer->KillJSTimer();
+ delete pTimer;
+}
+
+FX_BOOL CJS_EmbedObj::IsSafeMode(IFXJS_Context* cc)
+{
+ ASSERT(cc != NULL);
+
+ return TRUE;
+}
+
+/* --------------------------------- CJS_Object --------------------------------- */
+void FreeObject(const v8::WeakCallbackData<v8::Object, CJS_Object>& data)
+{
+ CJS_Object* pJSObj = data.GetParameter();
+ if(pJSObj)
+ {
+ pJSObj->ExitInstance();
+ delete pJSObj;
+ }
+ v8::Local<v8::Object> obj = data.GetValue();
+ JS_FreePrivate(obj);
+}
+
+CJS_Object::CJS_Object(JSFXObject pObject) :m_pEmbedObj(NULL)
+{
+ v8::Local<v8::Context> context = pObject->CreationContext();
+ m_pIsolate = context->GetIsolate();
+ m_pObject.Reset(m_pIsolate, pObject);
+};
+
+CJS_Object::~CJS_Object(void)
+{
+ delete m_pEmbedObj;
+ m_pEmbedObj = NULL;
+
+ m_pObject.Reset();
+};
+
+void CJS_Object::MakeWeak()
+{
+ m_pObject.SetWeak(this, FreeObject);
+}
+
+CPDFSDK_PageView* CJS_Object::JSGetPageView(IFXJS_Context* cc)
+{
+ return FXJS_GetPageView(cc);
+}
+
+int CJS_Object::MsgBox(CPDFDoc_Environment* pApp, CPDFSDK_PageView* pPageView, FX_LPCWSTR swMsg, FX_LPCWSTR swTitle, FX_UINT nType, FX_UINT nIcon)
+{
+ return FXJS_MsgBox(pApp, pPageView, swMsg, swTitle, nType, nIcon);
+}
+
+void CJS_Object::Alert(CJS_Context* pContext, FX_LPCWSTR swMsg)
+{
+ ASSERT(pContext != NULL);
+
+ if (pContext->IsMsgBoxEnabled())
+ {
+ CPDFDoc_Environment* pApp = pContext->GetReaderApp();
+ if(pApp)
+ pApp->JS_appAlert(swMsg, NULL, 0, 3);
+ }
+}
+
+
diff --git a/fpdfsdk/src/javascript/JS_Runtime.cpp b/fpdfsdk/src/javascript/JS_Runtime.cpp
index 77796431d4..c7a92ebde2 100644
--- a/fpdfsdk/src/javascript/JS_Runtime.cpp
+++ b/fpdfsdk/src/javascript/JS_Runtime.cpp
@@ -1,470 +1,470 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/javascript/JavaScript.h"
-#include "../../include/javascript/IJavaScript.h"
-#include "../../include/javascript/JS_EventHandler.h"
-#include "../../include/javascript/JS_Runtime.h"
-#include "../../include/javascript/JS_Context.h"
-#include "../../include/javascript/JS_Define.h"
-#include "../../include/javascript/JS_Object.h"
-#include "../../include/javascript/JS_Value.h"
-#include "../../include/javascript/Document.h"
-#include "../../include/javascript/app.h"
-#include "../../include/javascript/color.h"
-#include "../../include/javascript/Consts.h"
-#include "../../include/javascript/Document.h"
-#include "../../include/javascript/event.h"
-#include "../../include/javascript/Field.h"
-#include "../../include/javascript/Icon.h"
-#include "../../include/javascript/PublicMethods.h"
-#include "../../include/javascript/report.h"
-#include "../../include/javascript/util.h"
-#include "../../include/javascript/JS_GlobalData.h"
-#include "../../include/javascript/global.h"
-#include "../../include/javascript/console.h"
-
-CJS_RuntimeFactory::~CJS_RuntimeFactory()
-{
-}
-
-IFXJS_Runtime* CJS_RuntimeFactory::NewJSRuntime(CPDFDoc_Environment* pApp)
-{
- if (!m_bInit)
- {
- JS_Initial();
-
- m_bInit = TRUE;
- }
- return new CJS_Runtime(pApp);
-}
-void CJS_RuntimeFactory::AddRef()
-{
- //to do.Should be implemented as atom manipulation.
- m_nRef++;
-}
-void CJS_RuntimeFactory::Release()
-{
- if(m_bInit)
- {
- //to do.Should be implemented as atom manipulation.
- if (--m_nRef == 0)
- {
- JS_Release();
- ReleaseGlobalData();
- m_bInit = FALSE;
- }
- }
-}
-
-void CJS_RuntimeFactory::DeleteJSRuntime(IFXJS_Runtime* pRuntime)
-{
- if(pRuntime)
- delete (CJS_Runtime*)pRuntime;
-}
-
-CJS_GlobalData* CJS_RuntimeFactory::NewGlobalData(CPDFDoc_Environment* pApp)
-{
- if (m_pGlobalData)
- {
- m_nGlobalDataCount++;
- return m_pGlobalData;
- }
- else
- {
- m_nGlobalDataCount = 1;
- m_pGlobalData = new CJS_GlobalData(pApp);
- return m_pGlobalData;
- }
-}
-
-void CJS_RuntimeFactory::ReleaseGlobalData()
-{
- m_nGlobalDataCount--;
-
- if (m_nGlobalDataCount <= 0)
- {
- delete m_pGlobalData;
- m_pGlobalData = NULL;
- }
-}
-
-/* ------------------------------ CJS_Runtime ------------------------------ */
-
-CJS_Runtime::CJS_Runtime(CPDFDoc_Environment * pApp) :
- m_pApp(pApp),
- m_pDocument(NULL),
- m_pFieldEventPath(NULL),
- m_bBlocking(FALSE),
- m_bRegistered(FALSE)
-{
- m_isolate = v8::Isolate::New();
- //m_isolate->Enter();
-
- InitJSObjects();
-
- CJS_Context * pContext = (CJS_Context*)NewContext();
- JS_InitialRuntime(*this, this, pContext, m_context);
- ReleaseContext(pContext);
-}
-
-CJS_Runtime::~CJS_Runtime()
-{
- for (int i=0, sz=m_ContextArray.GetSize(); i<sz; i++)
- delete m_ContextArray.GetAt(i);
-
- m_ContextArray.RemoveAll();
-
- JS_ReleaseRuntime(*this, m_context);
-
- RemoveEventsInLoop(m_pFieldEventPath);
-
- m_pApp = NULL;
- m_pDocument = NULL;
- m_pFieldEventPath = NULL;
- m_context.Reset();
-
- //m_isolate->Exit();
- m_isolate->Dispose();
-}
-
-FX_BOOL CJS_Runtime::InitJSObjects()
-{
- v8::Isolate::Scope isolate_scope(GetIsolate());
- v8::HandleScope handle_scope(GetIsolate());
- v8::Handle<v8::Context> context = v8::Context::New(GetIsolate());
- v8::Context::Scope context_scope(context);
- //0 - 8
- if (CJS_Border::Init(*this, JS_STATIC) < 0) return FALSE;
- if (CJS_Display::Init(*this, JS_STATIC) < 0) return FALSE;
- if (CJS_Font::Init(*this, JS_STATIC) < 0) return FALSE;
- if (CJS_Highlight::Init(*this, JS_STATIC) < 0) return FALSE;
- if (CJS_Position::Init(*this, JS_STATIC) < 0) return FALSE;
- if (CJS_ScaleHow::Init(*this, JS_STATIC) < 0) return FALSE;
- if (CJS_ScaleWhen::Init(*this, JS_STATIC) < 0) return FALSE;
- if (CJS_Style::Init(*this, JS_STATIC) < 0) return FALSE;
- if (CJS_Zoomtype::Init(*this, JS_STATIC) < 0) return FALSE;
-
- //9 - 11
- if (CJS_App::Init(*this, JS_STATIC) < 0) return FALSE;
- if (CJS_Color::Init(*this, JS_STATIC) < 0) return FALSE;
- if (CJS_Console::Init(*this, JS_STATIC) < 0) return FALSE;
-
- //12 - 14
- if (CJS_Document::Init(*this, JS_DYNAMIC) < 0) return FALSE;
- if (CJS_Event::Init(*this, JS_STATIC) < 0) return FALSE;
- if (CJS_Field::Init(*this, JS_DYNAMIC) < 0) return FALSE;
-
- //15 - 17
- if (CJS_Global::Init(*this, JS_STATIC) < 0) return FALSE;
- if (CJS_Icon::Init(*this, JS_DYNAMIC) < 0) return FALSE;
- if (CJS_Util::Init(*this, JS_STATIC) < 0) return FALSE;
-
- if (CJS_PublicMethods::Init(*this) < 0) return FALSE;
- if (CJS_GlobalConsts::Init(*this) < 0) return FALSE;
- if (CJS_GlobalArrays::Init(*this) < 0) return FALSE;
-
- if (CJS_TimerObj::Init(*this, JS_DYNAMIC) < 0) return FALSE;
- if (CJS_PrintParamsObj::Init(*this, JS_DYNAMIC) <0) return FALSE;
-
- return TRUE;
-}
-
-IFXJS_Context* CJS_Runtime::NewContext()
-{
- CJS_Context * p = new CJS_Context(this);
- m_ContextArray.Add(p);
- return p;
-}
-
-void CJS_Runtime::ReleaseContext(IFXJS_Context * pContext)
-{
- CJS_Context* pJSContext = (CJS_Context*)pContext;
-
- for (int i=0, sz=m_ContextArray.GetSize(); i<sz; i++)
- {
- if (pJSContext == m_ContextArray.GetAt(i))
- {
- delete pJSContext;
- m_ContextArray.RemoveAt(i);
- break;
- }
- }
-}
-
-IFXJS_Context* CJS_Runtime::GetCurrentContext()
-{
- if(!m_ContextArray.GetSize())
- return NULL;
- return m_ContextArray.GetAt(m_ContextArray.GetSize()-1);
-}
-
-void CJS_Runtime::SetReaderDocument(CPDFSDK_Document* pReaderDoc)
-{
- if (m_pDocument != pReaderDoc)
- {
- v8::Isolate::Scope isolate_scope(m_isolate);
- v8::HandleScope handle_scope(m_isolate);
- v8::Local<v8::Context> context =v8::Local<v8::Context>::New(m_isolate, m_context);
- v8::Context::Scope context_scope(context);
-
- m_pDocument = pReaderDoc;
-
- if (pReaderDoc)
- {
- JSObject pThis = JS_GetThisObj(*this);
- if(!pThis.IsEmpty())
- {
- if (JS_GetObjDefnID(pThis) == JS_GetObjDefnID(*this, L"Document"))
- {
- if (CJS_Document* pJSDocument = (CJS_Document*)JS_GetPrivate(pThis))
- {
- if (Document * pDocument = (Document*)pJSDocument->GetEmbedObject())
- pDocument->AttachDoc(pReaderDoc);
- }
- }
- }
- JS_SetThisObj(*this, JS_GetObjDefnID(*this, L"Document"));
- }
- else
- {
- JS_SetThisObj(*this, JS_GetObjDefnID(*this, L"app"));
- }
- }
-}
-
-FX_BOOL CJS_Runtime::AddEventToLoop(const CFX_WideString& sTargetName, JS_EVENT_T eEventType)
-{
- if (m_pFieldEventPath == NULL)
- {
- m_pFieldEventPath = new CJS_FieldEvent;
- m_pFieldEventPath->sTargetName = sTargetName;
- m_pFieldEventPath->eEventType = eEventType;
- m_pFieldEventPath->pNext = NULL;
-
- return TRUE;
- }
-
- //to search
- CJS_FieldEvent* p = m_pFieldEventPath;
- CJS_FieldEvent* pLast = m_pFieldEventPath;
- while (p)
- {
- if (p->eEventType == eEventType && p->sTargetName == sTargetName)
- return FALSE;
-
- pLast = p;
- p = p->pNext;
- }
-
- //to add
- CJS_FieldEvent* pNew = new CJS_FieldEvent;
- pNew->sTargetName = sTargetName;
- pNew->eEventType = eEventType;
- pNew->pNext = NULL;
-
- pLast->pNext = pNew;
-
- return TRUE;
-}
-
-void CJS_Runtime::RemoveEventInLoop(const CFX_WideString& sTargetName, JS_EVENT_T eEventType)
-{
- FX_BOOL bFind = FALSE;
-
- CJS_FieldEvent* p = m_pFieldEventPath;
- CJS_FieldEvent* pLast = NULL;
- while (p)
- {
- if (p->eEventType == eEventType && p->sTargetName == sTargetName)
- {
- bFind = TRUE;
- break;
- }
-
- pLast = p;
- p = p->pNext;
- }
-
- if (bFind)
- {
- RemoveEventsInLoop(p);
-
- if (p == m_pFieldEventPath)
- m_pFieldEventPath = NULL;
-
- if (pLast)
- pLast->pNext = NULL;
- }
-}
-
-void CJS_Runtime::RemoveEventsInLoop(CJS_FieldEvent* pStart)
-{
- CJS_FieldEvent* p = pStart;
-
- while (p)
- {
- CJS_FieldEvent* pOld = p;
- p = pOld->pNext;
-
- delete pOld;
- }
-}
-
-v8::Handle<v8::Context> CJS_Runtime::NewJSContext()
-{
- return v8::Local<v8::Context>::New(m_isolate, m_context);
-}
-
-CFX_WideString ChangeObjName(const CFX_WideString& str)
-{
- CFX_WideString sRet = str;
- sRet.Replace((FX_LPCWSTR)L"_", (FX_LPCWSTR)L".");
- return sRet;
-}
-
-void CJS_Runtime::GetObjectNames(CFX_WideStringArray& array)
-{
- array.RemoveAll();
-
- array.Add(CJS_Border::m_pClassName);
- array.Add(CJS_Display::m_pClassName);
- array.Add(CJS_Font::m_pClassName);
- array.Add(CJS_Highlight::m_pClassName);
- array.Add(CJS_Position::m_pClassName);
- array.Add(CJS_ScaleHow::m_pClassName);
- array.Add(CJS_ScaleWhen::m_pClassName);
- array.Add(CJS_Style::m_pClassName);
- array.Add(CJS_Zoomtype::m_pClassName);
-
- array.Add(CJS_App::m_pClassName);
- array.Add((FX_LPCWSTR)"this");
- array.Add(CJS_Event::m_pClassName);
-
- array.Add(CJS_Global::m_pClassName);
- array.Add(CJS_Util::m_pClassName);
-}
-
-void CJS_Runtime::GetObjectConsts(const CFX_WideString& sObjName, CFX_WideStringArray& array)
-{
- JSConstSpec* pConsts = NULL;
- int nSize = 0;
-
- if (sObjName == CJS_Border::m_pClassName)
- CJS_Border::GetConsts(pConsts, nSize);
- else if (sObjName == CJS_Display::m_pClassName)
- CJS_Display::GetConsts(pConsts, nSize);
- else if (sObjName == CJS_Font::m_pClassName)
- CJS_Font::GetConsts(pConsts, nSize);
- else if (sObjName == CJS_Highlight::m_pClassName)
- CJS_Highlight::GetConsts(pConsts, nSize);
- else if (sObjName == CJS_Position::m_pClassName)
- CJS_Position::GetConsts(pConsts, nSize);
- else if (sObjName == CJS_ScaleHow::m_pClassName)
- CJS_ScaleHow::GetConsts(pConsts, nSize);
- else if (sObjName == CJS_ScaleWhen::m_pClassName)
- CJS_ScaleWhen::GetConsts(pConsts, nSize);
- else if (sObjName == CJS_Style::m_pClassName)
- CJS_Style::GetConsts(pConsts, nSize);
- else if (sObjName == CJS_Zoomtype::m_pClassName)
- CJS_Zoomtype::GetConsts(pConsts, nSize);
-
- else if (sObjName == CJS_App::m_pClassName)
- CJS_App::GetConsts(pConsts, nSize);
- else if (sObjName == CJS_Color::m_pClassName)
- CJS_Color::GetConsts(pConsts, nSize);
-
- else if (sObjName == L"this")
- {
- if (GetReaderDocument())
- CJS_Document::GetConsts(pConsts, nSize);
- else
- CJS_App::GetConsts(pConsts, nSize);
- }
-
- if (sObjName == CJS_Event::m_pClassName)
- CJS_Event::GetConsts(pConsts, nSize);
- else if (sObjName == CJS_Field::m_pClassName)
- CJS_Field::GetConsts(pConsts, nSize);
- else if (sObjName == CJS_Global::m_pClassName)
- CJS_Global::GetConsts(pConsts, nSize);
- else if (sObjName == CJS_Util::m_pClassName)
- CJS_Util::GetConsts(pConsts, nSize);
-
- for (int i=0; i<nSize; i++)
- array.Add(pConsts[i].pName);
-}
-
-void CJS_Runtime::GetObjectProps(const CFX_WideString& sObjName, CFX_WideStringArray& array)
-{
- JSPropertySpec* pProperties = NULL;
- int nSize = 0;
-
- if (sObjName == CJS_App::m_pClassName)
- CJS_App::GetProperties(pProperties, nSize);
- else if (sObjName == CJS_Color::m_pClassName)
- CJS_Color::GetProperties(pProperties, nSize);
- else if (sObjName == L"this")
- {
- if (GetReaderDocument())
- CJS_Document::GetProperties(pProperties, nSize);
- else
- CJS_App::GetProperties(pProperties, nSize);
- }
- else if (sObjName == CJS_Event::m_pClassName)
- CJS_Event::GetProperties(pProperties, nSize);
- else if (sObjName == CJS_Field::m_pClassName)
- CJS_Field::GetProperties(pProperties, nSize);
- else if (sObjName == CJS_Global::m_pClassName)
- CJS_Global::GetProperties(pProperties, nSize);
- else if (sObjName == CJS_Util::m_pClassName)
- CJS_Util::GetProperties(pProperties, nSize);
-
- for (int i=0; i<nSize; i++)
- array.Add(pProperties[i].pName);
-}
-
-void CJS_Runtime::GetObjectMethods(const CFX_WideString& sObjName, CFX_WideStringArray& array)
-{
- JSMethodSpec* pMethods = NULL;
- int nSize = 0;
-
- if (sObjName == CJS_App::m_pClassName)
- CJS_App::GetMethods(pMethods, nSize);
- else if (sObjName == CJS_Color::m_pClassName)
- CJS_Color::GetMethods(pMethods, nSize);
- else if (sObjName == L"this")
- {
- if (GetReaderDocument())
- CJS_Document::GetMethods(pMethods, nSize);
- else
- CJS_App::GetMethods(pMethods, nSize);
- }
- else if (sObjName == CJS_Event::m_pClassName)
- CJS_Event::GetMethods(pMethods, nSize);
- else if (sObjName == CJS_Field::m_pClassName)
- CJS_Field::GetMethods(pMethods, nSize);
- else if (sObjName == CJS_Global::m_pClassName)
- CJS_Global::GetMethods(pMethods, nSize);
- else if (sObjName == CJS_Util::m_pClassName)
- CJS_Util::GetMethods(pMethods, nSize);
-
- for (int i=0; i<nSize; i++)
- array.Add(pMethods[i].pName);
-}
-
-FX_BOOL CJS_Runtime::IsEntered()
-{
- return v8::Isolate::GetCurrent() == m_isolate;
-}
-void CJS_Runtime::Exit()
-{
- if(m_isolate) m_isolate->Exit();
-}
-void CJS_Runtime::Enter()
-{
- if(m_isolate) m_isolate->Enter();
-}
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/javascript/JavaScript.h"
+#include "../../include/javascript/IJavaScript.h"
+#include "../../include/javascript/JS_EventHandler.h"
+#include "../../include/javascript/JS_Runtime.h"
+#include "../../include/javascript/JS_Context.h"
+#include "../../include/javascript/JS_Define.h"
+#include "../../include/javascript/JS_Object.h"
+#include "../../include/javascript/JS_Value.h"
+#include "../../include/javascript/Document.h"
+#include "../../include/javascript/app.h"
+#include "../../include/javascript/color.h"
+#include "../../include/javascript/Consts.h"
+#include "../../include/javascript/Document.h"
+#include "../../include/javascript/event.h"
+#include "../../include/javascript/Field.h"
+#include "../../include/javascript/Icon.h"
+#include "../../include/javascript/PublicMethods.h"
+#include "../../include/javascript/report.h"
+#include "../../include/javascript/util.h"
+#include "../../include/javascript/JS_GlobalData.h"
+#include "../../include/javascript/global.h"
+#include "../../include/javascript/console.h"
+
+CJS_RuntimeFactory::~CJS_RuntimeFactory()
+{
+}
+
+IFXJS_Runtime* CJS_RuntimeFactory::NewJSRuntime(CPDFDoc_Environment* pApp)
+{
+ if (!m_bInit)
+ {
+ JS_Initial();
+
+ m_bInit = TRUE;
+ }
+ return new CJS_Runtime(pApp);
+}
+void CJS_RuntimeFactory::AddRef()
+{
+ //to do.Should be implemented as atom manipulation.
+ m_nRef++;
+}
+void CJS_RuntimeFactory::Release()
+{
+ if(m_bInit)
+ {
+ //to do.Should be implemented as atom manipulation.
+ if (--m_nRef == 0)
+ {
+ JS_Release();
+ ReleaseGlobalData();
+ m_bInit = FALSE;
+ }
+ }
+}
+
+void CJS_RuntimeFactory::DeleteJSRuntime(IFXJS_Runtime* pRuntime)
+{
+ if(pRuntime)
+ delete (CJS_Runtime*)pRuntime;
+}
+
+CJS_GlobalData* CJS_RuntimeFactory::NewGlobalData(CPDFDoc_Environment* pApp)
+{
+ if (m_pGlobalData)
+ {
+ m_nGlobalDataCount++;
+ return m_pGlobalData;
+ }
+ else
+ {
+ m_nGlobalDataCount = 1;
+ m_pGlobalData = new CJS_GlobalData(pApp);
+ return m_pGlobalData;
+ }
+}
+
+void CJS_RuntimeFactory::ReleaseGlobalData()
+{
+ m_nGlobalDataCount--;
+
+ if (m_nGlobalDataCount <= 0)
+ {
+ delete m_pGlobalData;
+ m_pGlobalData = NULL;
+ }
+}
+
+/* ------------------------------ CJS_Runtime ------------------------------ */
+
+CJS_Runtime::CJS_Runtime(CPDFDoc_Environment * pApp) :
+ m_pApp(pApp),
+ m_pDocument(NULL),
+ m_pFieldEventPath(NULL),
+ m_bBlocking(FALSE),
+ m_bRegistered(FALSE)
+{
+ m_isolate = v8::Isolate::New();
+ //m_isolate->Enter();
+
+ InitJSObjects();
+
+ CJS_Context * pContext = (CJS_Context*)NewContext();
+ JS_InitialRuntime(*this, this, pContext, m_context);
+ ReleaseContext(pContext);
+}
+
+CJS_Runtime::~CJS_Runtime()
+{
+ for (int i=0, sz=m_ContextArray.GetSize(); i<sz; i++)
+ delete m_ContextArray.GetAt(i);
+
+ m_ContextArray.RemoveAll();
+
+ JS_ReleaseRuntime(*this, m_context);
+
+ RemoveEventsInLoop(m_pFieldEventPath);
+
+ m_pApp = NULL;
+ m_pDocument = NULL;
+ m_pFieldEventPath = NULL;
+ m_context.Reset();
+
+ //m_isolate->Exit();
+ m_isolate->Dispose();
+}
+
+FX_BOOL CJS_Runtime::InitJSObjects()
+{
+ v8::Isolate::Scope isolate_scope(GetIsolate());
+ v8::HandleScope handle_scope(GetIsolate());
+ v8::Handle<v8::Context> context = v8::Context::New(GetIsolate());
+ v8::Context::Scope context_scope(context);
+ //0 - 8
+ if (CJS_Border::Init(*this, JS_STATIC) < 0) return FALSE;
+ if (CJS_Display::Init(*this, JS_STATIC) < 0) return FALSE;
+ if (CJS_Font::Init(*this, JS_STATIC) < 0) return FALSE;
+ if (CJS_Highlight::Init(*this, JS_STATIC) < 0) return FALSE;
+ if (CJS_Position::Init(*this, JS_STATIC) < 0) return FALSE;
+ if (CJS_ScaleHow::Init(*this, JS_STATIC) < 0) return FALSE;
+ if (CJS_ScaleWhen::Init(*this, JS_STATIC) < 0) return FALSE;
+ if (CJS_Style::Init(*this, JS_STATIC) < 0) return FALSE;
+ if (CJS_Zoomtype::Init(*this, JS_STATIC) < 0) return FALSE;
+
+ //9 - 11
+ if (CJS_App::Init(*this, JS_STATIC) < 0) return FALSE;
+ if (CJS_Color::Init(*this, JS_STATIC) < 0) return FALSE;
+ if (CJS_Console::Init(*this, JS_STATIC) < 0) return FALSE;
+
+ //12 - 14
+ if (CJS_Document::Init(*this, JS_DYNAMIC) < 0) return FALSE;
+ if (CJS_Event::Init(*this, JS_STATIC) < 0) return FALSE;
+ if (CJS_Field::Init(*this, JS_DYNAMIC) < 0) return FALSE;
+
+ //15 - 17
+ if (CJS_Global::Init(*this, JS_STATIC) < 0) return FALSE;
+ if (CJS_Icon::Init(*this, JS_DYNAMIC) < 0) return FALSE;
+ if (CJS_Util::Init(*this, JS_STATIC) < 0) return FALSE;
+
+ if (CJS_PublicMethods::Init(*this) < 0) return FALSE;
+ if (CJS_GlobalConsts::Init(*this) < 0) return FALSE;
+ if (CJS_GlobalArrays::Init(*this) < 0) return FALSE;
+
+ if (CJS_TimerObj::Init(*this, JS_DYNAMIC) < 0) return FALSE;
+ if (CJS_PrintParamsObj::Init(*this, JS_DYNAMIC) <0) return FALSE;
+
+ return TRUE;
+}
+
+IFXJS_Context* CJS_Runtime::NewContext()
+{
+ CJS_Context * p = new CJS_Context(this);
+ m_ContextArray.Add(p);
+ return p;
+}
+
+void CJS_Runtime::ReleaseContext(IFXJS_Context * pContext)
+{
+ CJS_Context* pJSContext = (CJS_Context*)pContext;
+
+ for (int i=0, sz=m_ContextArray.GetSize(); i<sz; i++)
+ {
+ if (pJSContext == m_ContextArray.GetAt(i))
+ {
+ delete pJSContext;
+ m_ContextArray.RemoveAt(i);
+ break;
+ }
+ }
+}
+
+IFXJS_Context* CJS_Runtime::GetCurrentContext()
+{
+ if(!m_ContextArray.GetSize())
+ return NULL;
+ return m_ContextArray.GetAt(m_ContextArray.GetSize()-1);
+}
+
+void CJS_Runtime::SetReaderDocument(CPDFSDK_Document* pReaderDoc)
+{
+ if (m_pDocument != pReaderDoc)
+ {
+ v8::Isolate::Scope isolate_scope(m_isolate);
+ v8::HandleScope handle_scope(m_isolate);
+ v8::Local<v8::Context> context =v8::Local<v8::Context>::New(m_isolate, m_context);
+ v8::Context::Scope context_scope(context);
+
+ m_pDocument = pReaderDoc;
+
+ if (pReaderDoc)
+ {
+ JSObject pThis = JS_GetThisObj(*this);
+ if(!pThis.IsEmpty())
+ {
+ if (JS_GetObjDefnID(pThis) == JS_GetObjDefnID(*this, L"Document"))
+ {
+ if (CJS_Document* pJSDocument = (CJS_Document*)JS_GetPrivate(pThis))
+ {
+ if (Document * pDocument = (Document*)pJSDocument->GetEmbedObject())
+ pDocument->AttachDoc(pReaderDoc);
+ }
+ }
+ }
+ JS_SetThisObj(*this, JS_GetObjDefnID(*this, L"Document"));
+ }
+ else
+ {
+ JS_SetThisObj(*this, JS_GetObjDefnID(*this, L"app"));
+ }
+ }
+}
+
+FX_BOOL CJS_Runtime::AddEventToLoop(const CFX_WideString& sTargetName, JS_EVENT_T eEventType)
+{
+ if (m_pFieldEventPath == NULL)
+ {
+ m_pFieldEventPath = new CJS_FieldEvent;
+ m_pFieldEventPath->sTargetName = sTargetName;
+ m_pFieldEventPath->eEventType = eEventType;
+ m_pFieldEventPath->pNext = NULL;
+
+ return TRUE;
+ }
+
+ //to search
+ CJS_FieldEvent* p = m_pFieldEventPath;
+ CJS_FieldEvent* pLast = m_pFieldEventPath;
+ while (p)
+ {
+ if (p->eEventType == eEventType && p->sTargetName == sTargetName)
+ return FALSE;
+
+ pLast = p;
+ p = p->pNext;
+ }
+
+ //to add
+ CJS_FieldEvent* pNew = new CJS_FieldEvent;
+ pNew->sTargetName = sTargetName;
+ pNew->eEventType = eEventType;
+ pNew->pNext = NULL;
+
+ pLast->pNext = pNew;
+
+ return TRUE;
+}
+
+void CJS_Runtime::RemoveEventInLoop(const CFX_WideString& sTargetName, JS_EVENT_T eEventType)
+{
+ FX_BOOL bFind = FALSE;
+
+ CJS_FieldEvent* p = m_pFieldEventPath;
+ CJS_FieldEvent* pLast = NULL;
+ while (p)
+ {
+ if (p->eEventType == eEventType && p->sTargetName == sTargetName)
+ {
+ bFind = TRUE;
+ break;
+ }
+
+ pLast = p;
+ p = p->pNext;
+ }
+
+ if (bFind)
+ {
+ RemoveEventsInLoop(p);
+
+ if (p == m_pFieldEventPath)
+ m_pFieldEventPath = NULL;
+
+ if (pLast)
+ pLast->pNext = NULL;
+ }
+}
+
+void CJS_Runtime::RemoveEventsInLoop(CJS_FieldEvent* pStart)
+{
+ CJS_FieldEvent* p = pStart;
+
+ while (p)
+ {
+ CJS_FieldEvent* pOld = p;
+ p = pOld->pNext;
+
+ delete pOld;
+ }
+}
+
+v8::Handle<v8::Context> CJS_Runtime::NewJSContext()
+{
+ return v8::Local<v8::Context>::New(m_isolate, m_context);
+}
+
+CFX_WideString ChangeObjName(const CFX_WideString& str)
+{
+ CFX_WideString sRet = str;
+ sRet.Replace((FX_LPCWSTR)L"_", (FX_LPCWSTR)L".");
+ return sRet;
+}
+
+void CJS_Runtime::GetObjectNames(CFX_WideStringArray& array)
+{
+ array.RemoveAll();
+
+ array.Add(CJS_Border::m_pClassName);
+ array.Add(CJS_Display::m_pClassName);
+ array.Add(CJS_Font::m_pClassName);
+ array.Add(CJS_Highlight::m_pClassName);
+ array.Add(CJS_Position::m_pClassName);
+ array.Add(CJS_ScaleHow::m_pClassName);
+ array.Add(CJS_ScaleWhen::m_pClassName);
+ array.Add(CJS_Style::m_pClassName);
+ array.Add(CJS_Zoomtype::m_pClassName);
+
+ array.Add(CJS_App::m_pClassName);
+ array.Add((FX_LPCWSTR)"this");
+ array.Add(CJS_Event::m_pClassName);
+
+ array.Add(CJS_Global::m_pClassName);
+ array.Add(CJS_Util::m_pClassName);
+}
+
+void CJS_Runtime::GetObjectConsts(const CFX_WideString& sObjName, CFX_WideStringArray& array)
+{
+ JSConstSpec* pConsts = NULL;
+ int nSize = 0;
+
+ if (sObjName == CJS_Border::m_pClassName)
+ CJS_Border::GetConsts(pConsts, nSize);
+ else if (sObjName == CJS_Display::m_pClassName)
+ CJS_Display::GetConsts(pConsts, nSize);
+ else if (sObjName == CJS_Font::m_pClassName)
+ CJS_Font::GetConsts(pConsts, nSize);
+ else if (sObjName == CJS_Highlight::m_pClassName)
+ CJS_Highlight::GetConsts(pConsts, nSize);
+ else if (sObjName == CJS_Position::m_pClassName)
+ CJS_Position::GetConsts(pConsts, nSize);
+ else if (sObjName == CJS_ScaleHow::m_pClassName)
+ CJS_ScaleHow::GetConsts(pConsts, nSize);
+ else if (sObjName == CJS_ScaleWhen::m_pClassName)
+ CJS_ScaleWhen::GetConsts(pConsts, nSize);
+ else if (sObjName == CJS_Style::m_pClassName)
+ CJS_Style::GetConsts(pConsts, nSize);
+ else if (sObjName == CJS_Zoomtype::m_pClassName)
+ CJS_Zoomtype::GetConsts(pConsts, nSize);
+
+ else if (sObjName == CJS_App::m_pClassName)
+ CJS_App::GetConsts(pConsts, nSize);
+ else if (sObjName == CJS_Color::m_pClassName)
+ CJS_Color::GetConsts(pConsts, nSize);
+
+ else if (sObjName == L"this")
+ {
+ if (GetReaderDocument())
+ CJS_Document::GetConsts(pConsts, nSize);
+ else
+ CJS_App::GetConsts(pConsts, nSize);
+ }
+
+ if (sObjName == CJS_Event::m_pClassName)
+ CJS_Event::GetConsts(pConsts, nSize);
+ else if (sObjName == CJS_Field::m_pClassName)
+ CJS_Field::GetConsts(pConsts, nSize);
+ else if (sObjName == CJS_Global::m_pClassName)
+ CJS_Global::GetConsts(pConsts, nSize);
+ else if (sObjName == CJS_Util::m_pClassName)
+ CJS_Util::GetConsts(pConsts, nSize);
+
+ for (int i=0; i<nSize; i++)
+ array.Add(pConsts[i].pName);
+}
+
+void CJS_Runtime::GetObjectProps(const CFX_WideString& sObjName, CFX_WideStringArray& array)
+{
+ JSPropertySpec* pProperties = NULL;
+ int nSize = 0;
+
+ if (sObjName == CJS_App::m_pClassName)
+ CJS_App::GetProperties(pProperties, nSize);
+ else if (sObjName == CJS_Color::m_pClassName)
+ CJS_Color::GetProperties(pProperties, nSize);
+ else if (sObjName == L"this")
+ {
+ if (GetReaderDocument())
+ CJS_Document::GetProperties(pProperties, nSize);
+ else
+ CJS_App::GetProperties(pProperties, nSize);
+ }
+ else if (sObjName == CJS_Event::m_pClassName)
+ CJS_Event::GetProperties(pProperties, nSize);
+ else if (sObjName == CJS_Field::m_pClassName)
+ CJS_Field::GetProperties(pProperties, nSize);
+ else if (sObjName == CJS_Global::m_pClassName)
+ CJS_Global::GetProperties(pProperties, nSize);
+ else if (sObjName == CJS_Util::m_pClassName)
+ CJS_Util::GetProperties(pProperties, nSize);
+
+ for (int i=0; i<nSize; i++)
+ array.Add(pProperties[i].pName);
+}
+
+void CJS_Runtime::GetObjectMethods(const CFX_WideString& sObjName, CFX_WideStringArray& array)
+{
+ JSMethodSpec* pMethods = NULL;
+ int nSize = 0;
+
+ if (sObjName == CJS_App::m_pClassName)
+ CJS_App::GetMethods(pMethods, nSize);
+ else if (sObjName == CJS_Color::m_pClassName)
+ CJS_Color::GetMethods(pMethods, nSize);
+ else if (sObjName == L"this")
+ {
+ if (GetReaderDocument())
+ CJS_Document::GetMethods(pMethods, nSize);
+ else
+ CJS_App::GetMethods(pMethods, nSize);
+ }
+ else if (sObjName == CJS_Event::m_pClassName)
+ CJS_Event::GetMethods(pMethods, nSize);
+ else if (sObjName == CJS_Field::m_pClassName)
+ CJS_Field::GetMethods(pMethods, nSize);
+ else if (sObjName == CJS_Global::m_pClassName)
+ CJS_Global::GetMethods(pMethods, nSize);
+ else if (sObjName == CJS_Util::m_pClassName)
+ CJS_Util::GetMethods(pMethods, nSize);
+
+ for (int i=0; i<nSize; i++)
+ array.Add(pMethods[i].pName);
+}
+
+FX_BOOL CJS_Runtime::IsEntered()
+{
+ return v8::Isolate::GetCurrent() == m_isolate;
+}
+void CJS_Runtime::Exit()
+{
+ if(m_isolate) m_isolate->Exit();
+}
+void CJS_Runtime::Enter()
+{
+ if(m_isolate) m_isolate->Enter();
+}
diff --git a/fpdfsdk/src/javascript/JS_Value.cpp b/fpdfsdk/src/javascript/JS_Value.cpp
index 037f6184ed..0217ea1374 100644
--- a/fpdfsdk/src/javascript/JS_Value.cpp
+++ b/fpdfsdk/src/javascript/JS_Value.cpp
@@ -1,643 +1,643 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/javascript/JavaScript.h"
-#include "../../include/javascript/JS_Define.h"
-#include "../../include/javascript/JS_Object.h"
-#include "../../include/javascript/JS_Value.h"
-
-/* ---------------------------- CJS_Value ---------------------------- */
-
-CJS_Value::CJS_Value(v8::Isolate* isolate) : m_isolate(isolate),m_eType(VT_unknown)
-{
-}
-CJS_Value::CJS_Value(v8::Isolate* isolate, v8::Handle<v8::Value> pValue,FXJSVALUETYPE t) :m_isolate(isolate), m_pValue(pValue) , m_eType(t)
-{
-}
-
-CJS_Value::CJS_Value(v8::Isolate* isolate, const int &iValue):m_isolate(isolate)
-{
- operator =(iValue);
-}
-
-CJS_Value::CJS_Value(v8::Isolate* isolate, const bool &bValue):m_isolate(isolate)
-{
- operator =(bValue);
-}
-
-CJS_Value::CJS_Value(v8::Isolate* isolate, const float &fValue):m_isolate(isolate)
-{
- operator =(fValue);
-}
-
-CJS_Value::CJS_Value(v8::Isolate* isolate, const double &dValue):m_isolate(isolate)
-{
- operator =(dValue);
-}
-
-CJS_Value::CJS_Value(v8::Isolate* isolate, JSFXObject pJsObj):m_isolate(isolate)
-{
- operator =(pJsObj);
-}
-
-CJS_Value::CJS_Value(v8::Isolate* isolate, CJS_Object * pJsObj):m_isolate(isolate)
-{
- operator =(pJsObj);
-}
-
-CJS_Value::CJS_Value(v8::Isolate* isolate, FX_LPCWSTR pWstr):m_isolate(isolate)
-{
- operator =(pWstr);
-}
-
-CJS_Value::CJS_Value(v8::Isolate* isolate, FX_LPCSTR pStr):m_isolate(isolate)
-{
- operator = (pStr);
-}
-
-CJS_Value::CJS_Value(v8::Isolate* isolate, CJS_Array& array):m_isolate(isolate)
-{
- operator = (array);
-}
-
-CJS_Value::~CJS_Value()
-{
-}
-
-void CJS_Value::Attach(v8::Handle<v8::Value> pValue,FXJSVALUETYPE t)
-{
- m_pValue = pValue;
- m_eType = t;
-}
-
-void CJS_Value::Attach(CJS_Value *pValue)
-{
- if (pValue)
- Attach(pValue->ToJSValue(),pValue->GetType());
-}
-
-void CJS_Value::Detach()
-{
- m_pValue = v8::Handle<v8::Value>();
- m_eType = VT_unknown;
-}
-
-/* ---------------------------------------------------------------------------------------- */
-
-CJS_Value::operator int() const
-{
-
- return JS_ToInt32(m_pValue);
-
-}
-
-CJS_Value::operator bool() const
-{
-
- return JS_ToBoolean(m_pValue);
-
-}
-
-CJS_Value::operator double() const
-{
-
- return JS_ToNumber(m_pValue);
-
-}
-
-CJS_Value::operator float() const
-{
-
- return (float)JS_ToNumber(m_pValue);
-
-}
-
-CJS_Value::operator CJS_Object *() const
-{
-
- v8::Handle<v8::Object> pObj = JS_ToObject(m_pValue);
- return (CJS_Object*)JS_GetPrivate(m_isolate, pObj);
-}
-
-CJS_Value::operator v8::Handle<v8::Object>() const
-{
- return JS_ToObject(m_pValue);
-}
-
-CJS_Value::operator CFX_WideString() const
-{
- return JS_ToString(m_pValue);
-}
-
-CJS_Value::operator CFX_ByteString() const
-{
- return CFX_ByteString::FromUnicode(operator CFX_WideString());
-}
-
-v8::Handle<v8::Value> CJS_Value::ToJSValue()
-{
- return m_pValue;
-}
-
-
-CJS_Value::operator v8::Handle<v8::Array>() const
-{
- if (IsArrayObject())
- return v8::Handle<v8::Array>::Cast(JS_ToObject(m_pValue));
- return v8::Handle<v8::Array>();
-}
-
-/* ---------------------------------------------------------------------------------------- */
-
-void CJS_Value::operator =(int iValue)
-{
- m_pValue = JS_NewNumber(m_isolate, iValue);
-
- m_eType = VT_number;
-}
-
-void CJS_Value::operator =(bool bValue)
-{
- m_pValue = JS_NewBoolean(m_isolate, bValue);
-
- m_eType = VT_boolean;
-}
-
-void CJS_Value::operator =(double dValue)
-{
- m_pValue = JS_NewNumber(m_isolate,dValue);
-
- m_eType = VT_number;
-}
-
-void CJS_Value::operator = (float fValue)
-{
- m_pValue = JS_NewNumber(m_isolate,fValue);
- m_eType = VT_number;
-}
-
-void CJS_Value::operator =(v8::Handle<v8::Object> pObj)
-{
-
- m_pValue = JS_NewObject(m_isolate,pObj);
-
- m_eType = VT_fxobject;
-}
-
-void CJS_Value::operator =(CJS_Object * pObj)
-{
- if (pObj)
- operator = ((JSFXObject)*pObj);
-}
-
-void CJS_Value::operator =(FX_LPCWSTR pWstr)
-{
- m_pValue = JS_NewString(m_isolate,(wchar_t *)pWstr);
-
- m_eType = VT_string;
-}
-
-void CJS_Value::SetNull()
-{
- m_pValue = JS_NewNull();
-
- m_eType = VT_null;
-}
-
-void CJS_Value::operator = (FX_LPCSTR pStr)
-{
- operator = (CFX_WideString::FromLocal(pStr));
-}
-
-void CJS_Value::operator = (CJS_Array & array)
-{
- m_pValue = JS_NewObject2(m_isolate,(v8::Handle<v8::Array>)array);
-
- m_eType = VT_object;
-}
-
-void CJS_Value::operator = (CJS_Date & date)
-{
- m_pValue = JS_NewDate(m_isolate, (double)date);
-
- m_eType = VT_date;
-}
-
-void CJS_Value::operator = (CJS_Value value)
-{
- m_pValue = value.ToJSValue();
-
- m_eType = value.m_eType;
-}
-
-/* ---------------------------------------------------------------------------------------- */
-
-FXJSVALUETYPE CJS_Value::GetType() const
-{
- if(m_pValue.IsEmpty()) return VT_unknown;
- if(m_pValue->IsString()) return VT_string;
- if(m_pValue->IsNumber()) return VT_number;
- if(m_pValue->IsBoolean()) return VT_boolean;
- if(m_pValue->IsDate()) return VT_date;
- if(m_pValue->IsObject()) return VT_object;
- if(m_pValue->IsNull()) return VT_null;
- if(m_pValue->IsUndefined()) return VT_undefined;
- return VT_unknown;
-}
-
-FX_BOOL CJS_Value::IsArrayObject() const
-{
- if(m_pValue.IsEmpty()) return FALSE;
- return m_pValue->IsArray();
-}
-
-FX_BOOL CJS_Value::IsDateObject() const
-{
- if(m_pValue.IsEmpty()) return FALSE;
- return m_pValue->IsDate();
-}
-
-//CJS_Value::operator CJS_Array()
-FX_BOOL CJS_Value::ConvertToArray(CJS_Array &array) const
-{
- if (IsArrayObject())
- {
- array.Attach(JS_ToArray(m_pValue));
- return TRUE;
- }
-
- return FALSE;
-}
-
-FX_BOOL CJS_Value::ConvertToDate(CJS_Date &date) const
-{
-// if (GetType() == VT_date)
-// {
-// date = (double)(*this);
-// return TRUE;
-// }
-
- if (IsDateObject())
- {
- date.Attach(m_pValue);
- return TRUE;
- }
-
- return FALSE;
-}
-
-/* ---------------------------- CJS_PropValue ---------------------------- */
-
-CJS_PropValue::CJS_PropValue(const CJS_Value &value) :
- CJS_Value(value),
- m_bIsSetting(0)
-{
-}
-
-CJS_PropValue::CJS_PropValue(v8::Isolate* isolate) : CJS_Value(isolate),
- m_bIsSetting(0)
-{
-}
-
-CJS_PropValue::~CJS_PropValue()
-{
-}
-
-FX_BOOL CJS_PropValue::IsSetting()
-{
- return m_bIsSetting;
-}
-
-FX_BOOL CJS_PropValue::IsGetting()
-{
- return !m_bIsSetting;
-}
-
-void CJS_PropValue::operator <<(int iValue)
-{
- ASSERT(!m_bIsSetting);
- CJS_Value::operator =(iValue);
-}
-
-void CJS_PropValue::operator >>(int & iValue) const
-{
- ASSERT(m_bIsSetting);
- iValue = CJS_Value::operator int();
-}
-
-
-void CJS_PropValue::operator <<(bool bValue)
-{
- ASSERT(!m_bIsSetting);
- CJS_Value::operator =(bValue);
-}
-
-void CJS_PropValue::operator >>(bool &bValue) const
-{
- ASSERT(m_bIsSetting);
- bValue = CJS_Value::operator bool();
-
-}
-
-void CJS_PropValue::operator <<(double dValue)
-{
- ASSERT(!m_bIsSetting);
- CJS_Value::operator =(dValue);
-}
-
-void CJS_PropValue::operator >>(double &dValue) const
-{
- ASSERT(m_bIsSetting);
- dValue = CJS_Value::operator double();
-}
-
-void CJS_PropValue::operator <<(CJS_Object *pObj)
-{
- ASSERT(!m_bIsSetting);
- CJS_Value::operator = (pObj);
-}
-
-void CJS_PropValue::operator >>(CJS_Object *&ppObj) const
-{
- ASSERT(m_bIsSetting);
- ppObj = CJS_Value::operator CJS_Object *();
-}
-
-void CJS_PropValue::operator<<(JSFXObject pObj)
-{
- ASSERT(!m_bIsSetting);
- CJS_Value::operator = (pObj);
-}
-
-void CJS_PropValue::operator>>(JSFXObject &ppObj) const
-{
- ASSERT(m_bIsSetting);
- ppObj = CJS_Value::operator JSFXObject ();
-}
-
-
-void CJS_PropValue::StartSetting()
-{
- m_bIsSetting = 1;
-}
-
-void CJS_PropValue::StartGetting()
-{
- m_bIsSetting = 0;
-}
-void CJS_PropValue::operator <<(CFX_ByteString string)
-{
- ASSERT(!m_bIsSetting);
- CJS_Value::operator =((FX_LPCSTR)string);
-}
-
-void CJS_PropValue::operator >>(CFX_ByteString &string) const
-{
- ASSERT(m_bIsSetting);
- string = CJS_Value::operator CFX_ByteString();
-}
-
-void CJS_PropValue::operator <<(FX_LPCWSTR c_string)
-{
- ASSERT(!m_bIsSetting);
- CJS_Value::operator =(c_string);
-}
-
-void CJS_PropValue::operator >>(CFX_WideString &wide_string) const
-{
- ASSERT(m_bIsSetting);
- wide_string = CJS_Value::operator CFX_WideString();
-}
-
-void CJS_PropValue::operator <<(CFX_WideString wide_string)
-{
- ASSERT(!m_bIsSetting);
- CJS_Value::operator = (wide_string);
-}
-
-void CJS_PropValue::operator >>(CJS_Array &array) const
-{
- ASSERT(m_bIsSetting);
- ConvertToArray(array);
-}
-
-void CJS_PropValue::operator <<(CJS_Array &array)
-{
- ASSERT(!m_bIsSetting);
- CJS_Value::operator=(array);
-}
-
-void CJS_PropValue::operator>>(CJS_Date &date) const
-{
- ASSERT(m_bIsSetting);
- ConvertToDate(date);
-}
-
-void CJS_PropValue::operator<<(CJS_Date &date)
-{
- ASSERT(!m_bIsSetting);
- CJS_Value::operator=(date);
-}
-
-CJS_PropValue::operator v8::Handle<v8::Value>() const
-{
- return m_pValue;
-}
-
-/* ======================================== CJS_Array ========================================= */
-CJS_Array::CJS_Array(v8::Isolate* isolate):m_isolate(isolate)
-{
-}
-
-CJS_Array::~CJS_Array()
-{
-}
-
-void CJS_Array::Attach(v8::Handle<v8::Array> pArray)
-{
- m_pArray = pArray;
-}
-
-FX_BOOL CJS_Array::IsAttached()
-{
- return FALSE;
-}
-
-void CJS_Array::GetElement(unsigned index,CJS_Value &value)
-{
- if (m_pArray.IsEmpty())
- return;
- v8::Handle<v8::Value> p = JS_GetArrayElemnet(m_pArray,index);
- value.Attach(p,VT_object);
-}
-
-void CJS_Array::SetElement(unsigned index,CJS_Value value)
-{
- if (m_pArray.IsEmpty())
- m_pArray = JS_NewArray(m_isolate);
-
- JS_PutArrayElement(m_pArray,index,value.ToJSValue(),value.GetType());
-}
-
-int CJS_Array::GetLength()
-{
- if (m_pArray.IsEmpty())
- return 0;
- return JS_GetArrayLength(m_pArray);
-}
-
-CJS_Array:: operator v8::Handle<v8::Array>()
-{
- if (m_pArray.IsEmpty())
- m_pArray = JS_NewArray(m_isolate);
-
- return m_pArray;
-}
-
-/* ======================================== CJS_Date ========================================= */
-
-CJS_Date::CJS_Date(v8::Isolate* isolate) :m_isolate(isolate)
-{
-}
-
-CJS_Date::CJS_Date(v8::Isolate* isolate,double dMsec_time)
-{
- m_isolate = isolate;
- m_pDate = JS_NewDate(isolate,dMsec_time);
-}
-
-CJS_Date::CJS_Date(v8::Isolate* isolate,int year, int mon, int day,int hour, int min, int sec)
-{
- m_isolate = isolate;
- m_pDate = JS_NewDate(isolate,MakeDate(year,mon,day,hour,min,sec,0));
-}
-
-double CJS_Date::MakeDate(int year, int mon, int day,int hour, int min, int sec,int ms)
-{
- return JS_MakeDate(JS_MakeDay(year,mon,day), JS_MakeTime(hour,min,sec,ms));
-}
-
-CJS_Date::~CJS_Date()
-{
-}
-
-FX_BOOL CJS_Date::IsValidDate()
-{
- if(m_pDate.IsEmpty()) return FALSE;
- return !JS_PortIsNan(JS_ToNumber(m_pDate));
-}
-
-void CJS_Date::Attach(v8::Handle<v8::Value> pDate)
-{
- m_pDate = pDate;
-}
-
-int CJS_Date::GetYear()
-{
- if (IsValidDate())
- return JS_GetYearFromTime(JS_LocalTime(JS_ToNumber(m_pDate)));
-
- return 0;
-}
-
-void CJS_Date::SetYear(int iYear)
-{
- double date = MakeDate(iYear,GetMonth(),GetDay(),GetHours(),GetMinutes(),GetSeconds(),0);
- JS_ValueCopy(m_pDate, JS_NewDate(m_isolate,date));
-}
-
-int CJS_Date::GetMonth()
-{
- if (IsValidDate())
- return JS_GetMonthFromTime(JS_LocalTime(JS_ToNumber(m_pDate)));
-
- return 0;
-}
-
-void CJS_Date::SetMonth(int iMonth)
-{
-
- double date = MakeDate(GetYear(),iMonth,GetDay(),GetHours(),GetMinutes(),GetSeconds(),0);
- JS_ValueCopy(m_pDate, JS_NewDate(m_isolate,date));
-
-}
-
-int CJS_Date::GetDay()
-{
- if (IsValidDate())
- return JS_GetDayFromTime(JS_LocalTime(JS_ToNumber(m_pDate)));
-
- return 0;
-}
-
-void CJS_Date::SetDay(int iDay)
-{
-
- double date = MakeDate(GetYear(),GetMonth(),iDay,GetHours(),GetMinutes(),GetSeconds(),0);
- JS_ValueCopy(m_pDate,JS_NewDate(m_isolate,date));
-
-}
-
-int CJS_Date::GetHours()
-{
- if (IsValidDate())
- return JS_GetHourFromTime(JS_LocalTime(JS_ToNumber(m_pDate)));
-
- return 0;
-}
-
-void CJS_Date::SetHours(int iHours)
-{
- double date = MakeDate(GetYear(),GetMonth(),GetDay(),iHours,GetMinutes(),GetSeconds(),0);
- JS_ValueCopy(m_pDate,JS_NewDate(m_isolate,date));
-}
-
-int CJS_Date::GetMinutes()
-{
- if (IsValidDate())
- return JS_GetMinFromTime(JS_LocalTime(JS_ToNumber(m_pDate)));
-
- return 0;
-}
-
-void CJS_Date::SetMinutes(int minutes)
-{
- double date = MakeDate(GetYear(),GetMonth(),GetDay(),GetHours(),minutes,GetSeconds(),0);
- JS_ValueCopy(m_pDate,JS_NewDate(m_isolate,date));
-}
-
-int CJS_Date::GetSeconds()
-{
- if (IsValidDate())
- return JS_GetSecFromTime(JS_LocalTime(JS_ToNumber(m_pDate)));
-
- return 0;
-}
-
-void CJS_Date::SetSeconds(int seconds)
-{
- double date = MakeDate(GetYear(),GetMonth(),GetDay(),GetHours(),GetMinutes(),seconds,0);
- JS_ValueCopy(m_pDate,JS_NewDate(m_isolate,date));
-}
-
-CJS_Date::operator v8::Handle<v8::Value>()
-{
- return m_pDate;
-}
-
-CJS_Date::operator double() const
-{
- if(m_pDate.IsEmpty())
- return 0.0;
- return JS_ToNumber(m_pDate);
-}
-
-CFX_WideString CJS_Date::ToString() const
-{
- if(m_pDate.IsEmpty())
- return L"";
- return JS_ToString(m_pDate);
-}
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/javascript/JavaScript.h"
+#include "../../include/javascript/JS_Define.h"
+#include "../../include/javascript/JS_Object.h"
+#include "../../include/javascript/JS_Value.h"
+
+/* ---------------------------- CJS_Value ---------------------------- */
+
+CJS_Value::CJS_Value(v8::Isolate* isolate) : m_isolate(isolate),m_eType(VT_unknown)
+{
+}
+CJS_Value::CJS_Value(v8::Isolate* isolate, v8::Handle<v8::Value> pValue,FXJSVALUETYPE t) :m_isolate(isolate), m_pValue(pValue) , m_eType(t)
+{
+}
+
+CJS_Value::CJS_Value(v8::Isolate* isolate, const int &iValue):m_isolate(isolate)
+{
+ operator =(iValue);
+}
+
+CJS_Value::CJS_Value(v8::Isolate* isolate, const bool &bValue):m_isolate(isolate)
+{
+ operator =(bValue);
+}
+
+CJS_Value::CJS_Value(v8::Isolate* isolate, const float &fValue):m_isolate(isolate)
+{
+ operator =(fValue);
+}
+
+CJS_Value::CJS_Value(v8::Isolate* isolate, const double &dValue):m_isolate(isolate)
+{
+ operator =(dValue);
+}
+
+CJS_Value::CJS_Value(v8::Isolate* isolate, JSFXObject pJsObj):m_isolate(isolate)
+{
+ operator =(pJsObj);
+}
+
+CJS_Value::CJS_Value(v8::Isolate* isolate, CJS_Object * pJsObj):m_isolate(isolate)
+{
+ operator =(pJsObj);
+}
+
+CJS_Value::CJS_Value(v8::Isolate* isolate, FX_LPCWSTR pWstr):m_isolate(isolate)
+{
+ operator =(pWstr);
+}
+
+CJS_Value::CJS_Value(v8::Isolate* isolate, FX_LPCSTR pStr):m_isolate(isolate)
+{
+ operator = (pStr);
+}
+
+CJS_Value::CJS_Value(v8::Isolate* isolate, CJS_Array& array):m_isolate(isolate)
+{
+ operator = (array);
+}
+
+CJS_Value::~CJS_Value()
+{
+}
+
+void CJS_Value::Attach(v8::Handle<v8::Value> pValue,FXJSVALUETYPE t)
+{
+ m_pValue = pValue;
+ m_eType = t;
+}
+
+void CJS_Value::Attach(CJS_Value *pValue)
+{
+ if (pValue)
+ Attach(pValue->ToJSValue(),pValue->GetType());
+}
+
+void CJS_Value::Detach()
+{
+ m_pValue = v8::Handle<v8::Value>();
+ m_eType = VT_unknown;
+}
+
+/* ---------------------------------------------------------------------------------------- */
+
+CJS_Value::operator int() const
+{
+
+ return JS_ToInt32(m_pValue);
+
+}
+
+CJS_Value::operator bool() const
+{
+
+ return JS_ToBoolean(m_pValue);
+
+}
+
+CJS_Value::operator double() const
+{
+
+ return JS_ToNumber(m_pValue);
+
+}
+
+CJS_Value::operator float() const
+{
+
+ return (float)JS_ToNumber(m_pValue);
+
+}
+
+CJS_Value::operator CJS_Object *() const
+{
+
+ v8::Handle<v8::Object> pObj = JS_ToObject(m_pValue);
+ return (CJS_Object*)JS_GetPrivate(m_isolate, pObj);
+}
+
+CJS_Value::operator v8::Handle<v8::Object>() const
+{
+ return JS_ToObject(m_pValue);
+}
+
+CJS_Value::operator CFX_WideString() const
+{
+ return JS_ToString(m_pValue);
+}
+
+CJS_Value::operator CFX_ByteString() const
+{
+ return CFX_ByteString::FromUnicode(operator CFX_WideString());
+}
+
+v8::Handle<v8::Value> CJS_Value::ToJSValue()
+{
+ return m_pValue;
+}
+
+
+CJS_Value::operator v8::Handle<v8::Array>() const
+{
+ if (IsArrayObject())
+ return v8::Handle<v8::Array>::Cast(JS_ToObject(m_pValue));
+ return v8::Handle<v8::Array>();
+}
+
+/* ---------------------------------------------------------------------------------------- */
+
+void CJS_Value::operator =(int iValue)
+{
+ m_pValue = JS_NewNumber(m_isolate, iValue);
+
+ m_eType = VT_number;
+}
+
+void CJS_Value::operator =(bool bValue)
+{
+ m_pValue = JS_NewBoolean(m_isolate, bValue);
+
+ m_eType = VT_boolean;
+}
+
+void CJS_Value::operator =(double dValue)
+{
+ m_pValue = JS_NewNumber(m_isolate,dValue);
+
+ m_eType = VT_number;
+}
+
+void CJS_Value::operator = (float fValue)
+{
+ m_pValue = JS_NewNumber(m_isolate,fValue);
+ m_eType = VT_number;
+}
+
+void CJS_Value::operator =(v8::Handle<v8::Object> pObj)
+{
+
+ m_pValue = JS_NewObject(m_isolate,pObj);
+
+ m_eType = VT_fxobject;
+}
+
+void CJS_Value::operator =(CJS_Object * pObj)
+{
+ if (pObj)
+ operator = ((JSFXObject)*pObj);
+}
+
+void CJS_Value::operator =(FX_LPCWSTR pWstr)
+{
+ m_pValue = JS_NewString(m_isolate,(wchar_t *)pWstr);
+
+ m_eType = VT_string;
+}
+
+void CJS_Value::SetNull()
+{
+ m_pValue = JS_NewNull();
+
+ m_eType = VT_null;
+}
+
+void CJS_Value::operator = (FX_LPCSTR pStr)
+{
+ operator = (CFX_WideString::FromLocal(pStr));
+}
+
+void CJS_Value::operator = (CJS_Array & array)
+{
+ m_pValue = JS_NewObject2(m_isolate,(v8::Handle<v8::Array>)array);
+
+ m_eType = VT_object;
+}
+
+void CJS_Value::operator = (CJS_Date & date)
+{
+ m_pValue = JS_NewDate(m_isolate, (double)date);
+
+ m_eType = VT_date;
+}
+
+void CJS_Value::operator = (CJS_Value value)
+{
+ m_pValue = value.ToJSValue();
+
+ m_eType = value.m_eType;
+}
+
+/* ---------------------------------------------------------------------------------------- */
+
+FXJSVALUETYPE CJS_Value::GetType() const
+{
+ if(m_pValue.IsEmpty()) return VT_unknown;
+ if(m_pValue->IsString()) return VT_string;
+ if(m_pValue->IsNumber()) return VT_number;
+ if(m_pValue->IsBoolean()) return VT_boolean;
+ if(m_pValue->IsDate()) return VT_date;
+ if(m_pValue->IsObject()) return VT_object;
+ if(m_pValue->IsNull()) return VT_null;
+ if(m_pValue->IsUndefined()) return VT_undefined;
+ return VT_unknown;
+}
+
+FX_BOOL CJS_Value::IsArrayObject() const
+{
+ if(m_pValue.IsEmpty()) return FALSE;
+ return m_pValue->IsArray();
+}
+
+FX_BOOL CJS_Value::IsDateObject() const
+{
+ if(m_pValue.IsEmpty()) return FALSE;
+ return m_pValue->IsDate();
+}
+
+//CJS_Value::operator CJS_Array()
+FX_BOOL CJS_Value::ConvertToArray(CJS_Array &array) const
+{
+ if (IsArrayObject())
+ {
+ array.Attach(JS_ToArray(m_pValue));
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+FX_BOOL CJS_Value::ConvertToDate(CJS_Date &date) const
+{
+// if (GetType() == VT_date)
+// {
+// date = (double)(*this);
+// return TRUE;
+// }
+
+ if (IsDateObject())
+ {
+ date.Attach(m_pValue);
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+/* ---------------------------- CJS_PropValue ---------------------------- */
+
+CJS_PropValue::CJS_PropValue(const CJS_Value &value) :
+ CJS_Value(value),
+ m_bIsSetting(0)
+{
+}
+
+CJS_PropValue::CJS_PropValue(v8::Isolate* isolate) : CJS_Value(isolate),
+ m_bIsSetting(0)
+{
+}
+
+CJS_PropValue::~CJS_PropValue()
+{
+}
+
+FX_BOOL CJS_PropValue::IsSetting()
+{
+ return m_bIsSetting;
+}
+
+FX_BOOL CJS_PropValue::IsGetting()
+{
+ return !m_bIsSetting;
+}
+
+void CJS_PropValue::operator <<(int iValue)
+{
+ ASSERT(!m_bIsSetting);
+ CJS_Value::operator =(iValue);
+}
+
+void CJS_PropValue::operator >>(int & iValue) const
+{
+ ASSERT(m_bIsSetting);
+ iValue = CJS_Value::operator int();
+}
+
+
+void CJS_PropValue::operator <<(bool bValue)
+{
+ ASSERT(!m_bIsSetting);
+ CJS_Value::operator =(bValue);
+}
+
+void CJS_PropValue::operator >>(bool &bValue) const
+{
+ ASSERT(m_bIsSetting);
+ bValue = CJS_Value::operator bool();
+
+}
+
+void CJS_PropValue::operator <<(double dValue)
+{
+ ASSERT(!m_bIsSetting);
+ CJS_Value::operator =(dValue);
+}
+
+void CJS_PropValue::operator >>(double &dValue) const
+{
+ ASSERT(m_bIsSetting);
+ dValue = CJS_Value::operator double();
+}
+
+void CJS_PropValue::operator <<(CJS_Object *pObj)
+{
+ ASSERT(!m_bIsSetting);
+ CJS_Value::operator = (pObj);
+}
+
+void CJS_PropValue::operator >>(CJS_Object *&ppObj) const
+{
+ ASSERT(m_bIsSetting);
+ ppObj = CJS_Value::operator CJS_Object *();
+}
+
+void CJS_PropValue::operator<<(JSFXObject pObj)
+{
+ ASSERT(!m_bIsSetting);
+ CJS_Value::operator = (pObj);
+}
+
+void CJS_PropValue::operator>>(JSFXObject &ppObj) const
+{
+ ASSERT(m_bIsSetting);
+ ppObj = CJS_Value::operator JSFXObject ();
+}
+
+
+void CJS_PropValue::StartSetting()
+{
+ m_bIsSetting = 1;
+}
+
+void CJS_PropValue::StartGetting()
+{
+ m_bIsSetting = 0;
+}
+void CJS_PropValue::operator <<(CFX_ByteString string)
+{
+ ASSERT(!m_bIsSetting);
+ CJS_Value::operator =((FX_LPCSTR)string);
+}
+
+void CJS_PropValue::operator >>(CFX_ByteString &string) const
+{
+ ASSERT(m_bIsSetting);
+ string = CJS_Value::operator CFX_ByteString();
+}
+
+void CJS_PropValue::operator <<(FX_LPCWSTR c_string)
+{
+ ASSERT(!m_bIsSetting);
+ CJS_Value::operator =(c_string);
+}
+
+void CJS_PropValue::operator >>(CFX_WideString &wide_string) const
+{
+ ASSERT(m_bIsSetting);
+ wide_string = CJS_Value::operator CFX_WideString();
+}
+
+void CJS_PropValue::operator <<(CFX_WideString wide_string)
+{
+ ASSERT(!m_bIsSetting);
+ CJS_Value::operator = (wide_string);
+}
+
+void CJS_PropValue::operator >>(CJS_Array &array) const
+{
+ ASSERT(m_bIsSetting);
+ ConvertToArray(array);
+}
+
+void CJS_PropValue::operator <<(CJS_Array &array)
+{
+ ASSERT(!m_bIsSetting);
+ CJS_Value::operator=(array);
+}
+
+void CJS_PropValue::operator>>(CJS_Date &date) const
+{
+ ASSERT(m_bIsSetting);
+ ConvertToDate(date);
+}
+
+void CJS_PropValue::operator<<(CJS_Date &date)
+{
+ ASSERT(!m_bIsSetting);
+ CJS_Value::operator=(date);
+}
+
+CJS_PropValue::operator v8::Handle<v8::Value>() const
+{
+ return m_pValue;
+}
+
+/* ======================================== CJS_Array ========================================= */
+CJS_Array::CJS_Array(v8::Isolate* isolate):m_isolate(isolate)
+{
+}
+
+CJS_Array::~CJS_Array()
+{
+}
+
+void CJS_Array::Attach(v8::Handle<v8::Array> pArray)
+{
+ m_pArray = pArray;
+}
+
+FX_BOOL CJS_Array::IsAttached()
+{
+ return FALSE;
+}
+
+void CJS_Array::GetElement(unsigned index,CJS_Value &value)
+{
+ if (m_pArray.IsEmpty())
+ return;
+ v8::Handle<v8::Value> p = JS_GetArrayElemnet(m_pArray,index);
+ value.Attach(p,VT_object);
+}
+
+void CJS_Array::SetElement(unsigned index,CJS_Value value)
+{
+ if (m_pArray.IsEmpty())
+ m_pArray = JS_NewArray(m_isolate);
+
+ JS_PutArrayElement(m_pArray,index,value.ToJSValue(),value.GetType());
+}
+
+int CJS_Array::GetLength()
+{
+ if (m_pArray.IsEmpty())
+ return 0;
+ return JS_GetArrayLength(m_pArray);
+}
+
+CJS_Array:: operator v8::Handle<v8::Array>()
+{
+ if (m_pArray.IsEmpty())
+ m_pArray = JS_NewArray(m_isolate);
+
+ return m_pArray;
+}
+
+/* ======================================== CJS_Date ========================================= */
+
+CJS_Date::CJS_Date(v8::Isolate* isolate) :m_isolate(isolate)
+{
+}
+
+CJS_Date::CJS_Date(v8::Isolate* isolate,double dMsec_time)
+{
+ m_isolate = isolate;
+ m_pDate = JS_NewDate(isolate,dMsec_time);
+}
+
+CJS_Date::CJS_Date(v8::Isolate* isolate,int year, int mon, int day,int hour, int min, int sec)
+{
+ m_isolate = isolate;
+ m_pDate = JS_NewDate(isolate,MakeDate(year,mon,day,hour,min,sec,0));
+}
+
+double CJS_Date::MakeDate(int year, int mon, int day,int hour, int min, int sec,int ms)
+{
+ return JS_MakeDate(JS_MakeDay(year,mon,day), JS_MakeTime(hour,min,sec,ms));
+}
+
+CJS_Date::~CJS_Date()
+{
+}
+
+FX_BOOL CJS_Date::IsValidDate()
+{
+ if(m_pDate.IsEmpty()) return FALSE;
+ return !JS_PortIsNan(JS_ToNumber(m_pDate));
+}
+
+void CJS_Date::Attach(v8::Handle<v8::Value> pDate)
+{
+ m_pDate = pDate;
+}
+
+int CJS_Date::GetYear()
+{
+ if (IsValidDate())
+ return JS_GetYearFromTime(JS_LocalTime(JS_ToNumber(m_pDate)));
+
+ return 0;
+}
+
+void CJS_Date::SetYear(int iYear)
+{
+ double date = MakeDate(iYear,GetMonth(),GetDay(),GetHours(),GetMinutes(),GetSeconds(),0);
+ JS_ValueCopy(m_pDate, JS_NewDate(m_isolate,date));
+}
+
+int CJS_Date::GetMonth()
+{
+ if (IsValidDate())
+ return JS_GetMonthFromTime(JS_LocalTime(JS_ToNumber(m_pDate)));
+
+ return 0;
+}
+
+void CJS_Date::SetMonth(int iMonth)
+{
+
+ double date = MakeDate(GetYear(),iMonth,GetDay(),GetHours(),GetMinutes(),GetSeconds(),0);
+ JS_ValueCopy(m_pDate, JS_NewDate(m_isolate,date));
+
+}
+
+int CJS_Date::GetDay()
+{
+ if (IsValidDate())
+ return JS_GetDayFromTime(JS_LocalTime(JS_ToNumber(m_pDate)));
+
+ return 0;
+}
+
+void CJS_Date::SetDay(int iDay)
+{
+
+ double date = MakeDate(GetYear(),GetMonth(),iDay,GetHours(),GetMinutes(),GetSeconds(),0);
+ JS_ValueCopy(m_pDate,JS_NewDate(m_isolate,date));
+
+}
+
+int CJS_Date::GetHours()
+{
+ if (IsValidDate())
+ return JS_GetHourFromTime(JS_LocalTime(JS_ToNumber(m_pDate)));
+
+ return 0;
+}
+
+void CJS_Date::SetHours(int iHours)
+{
+ double date = MakeDate(GetYear(),GetMonth(),GetDay(),iHours,GetMinutes(),GetSeconds(),0);
+ JS_ValueCopy(m_pDate,JS_NewDate(m_isolate,date));
+}
+
+int CJS_Date::GetMinutes()
+{
+ if (IsValidDate())
+ return JS_GetMinFromTime(JS_LocalTime(JS_ToNumber(m_pDate)));
+
+ return 0;
+}
+
+void CJS_Date::SetMinutes(int minutes)
+{
+ double date = MakeDate(GetYear(),GetMonth(),GetDay(),GetHours(),minutes,GetSeconds(),0);
+ JS_ValueCopy(m_pDate,JS_NewDate(m_isolate,date));
+}
+
+int CJS_Date::GetSeconds()
+{
+ if (IsValidDate())
+ return JS_GetSecFromTime(JS_LocalTime(JS_ToNumber(m_pDate)));
+
+ return 0;
+}
+
+void CJS_Date::SetSeconds(int seconds)
+{
+ double date = MakeDate(GetYear(),GetMonth(),GetDay(),GetHours(),GetMinutes(),seconds,0);
+ JS_ValueCopy(m_pDate,JS_NewDate(m_isolate,date));
+}
+
+CJS_Date::operator v8::Handle<v8::Value>()
+{
+ return m_pDate;
+}
+
+CJS_Date::operator double() const
+{
+ if(m_pDate.IsEmpty())
+ return 0.0;
+ return JS_ToNumber(m_pDate);
+}
+
+CFX_WideString CJS_Date::ToString() const
+{
+ if(m_pDate.IsEmpty())
+ return L"";
+ return JS_ToString(m_pDate);
+}
diff --git a/fpdfsdk/src/javascript/PublicMethods.cpp b/fpdfsdk/src/javascript/PublicMethods.cpp
index c39c8a00dd..bd4acaef9a 100644
--- a/fpdfsdk/src/javascript/PublicMethods.cpp
+++ b/fpdfsdk/src/javascript/PublicMethods.cpp
@@ -1,2335 +1,2335 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/javascript/JavaScript.h"
-#include "../../include/javascript/IJavaScript.h"
-#include "../../include/javascript/JS_Define.h"
-#include "../../include/javascript/JS_Object.h"
-#include "../../include/javascript/JS_Value.h"
-#include "../../include/javascript/PublicMethods.h"
-#include "../../include/javascript/JS_EventHandler.h"
-#include "../../include/javascript/resource.h"
-#include "../../include/javascript/JS_Context.h"
-#include "../../include/javascript/JS_Value.h"
-#include "../../include/javascript/util.h"
-#include "../../include/javascript/Field.h"
-#include "../../include/javascript/color.h"
-#include "../../include/javascript/JS_Runtime.h"
-
-static v8::Isolate* GetIsolate(IFXJS_Context* cc)
-{
- CJS_Context* pContext = (CJS_Context *)cc;
- ASSERT(pContext != NULL);
-
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
-
- return pRuntime->GetIsolate();
-}
-
-
-/* -------------------------------- CJS_PublicMethods -------------------------------- */
-
-#define DOUBLE_CORRECT 0.000000000000001
-
-BEGIN_JS_STATIC_GLOBAL_FUN(CJS_PublicMethods)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFNumber_Format,6)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFNumber_Keystroke,6)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFPercent_Format,2)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFPercent_Keystroke,2)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_FormatEx,1)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_KeystrokeEx,1)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_Format,1)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_Keystroke,1)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFTime_FormatEx,1)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFTime_KeystrokeEx,1)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFTime_Format,1)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFTime_Keystroke,1)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFSpecial_Format,1)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFSpecial_Keystroke,1)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFSpecial_KeystrokeEx,1)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFSimple,3)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFMakeNumber,1)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFSimple_Calculate,2)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFRange_Validate,4)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFMergeChange,1)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFParseDateEx,2)
- JS_STATIC_GLOBAL_FUN_ENTRY(AFExtractNums,1)
-END_JS_STATIC_GLOBAL_FUN()
-
-IMPLEMENT_JS_STATIC_GLOBAL_FUN(CJS_PublicMethods)
-
-struct stru_TbConvert
-{
- FX_LPCSTR lpszJSMark;
- FX_LPCSTR lpszCppMark;
-};
-
-static const stru_TbConvert fcTable[] = {"mmmm","%B",
- "mmm", "%b",
- "mm", "%m",
- //"m"
- "dddd","%A",
- "ddd", "%a",
- "dd", "%d",
- //"d", "%w",
- "yyyy","%Y",
- "yy", "%y",
- "HH", "%H",
- //"H"
- "hh", "%I",
- //"h"
- "MM", "%M",
- //"M"
- "ss", "%S",
- //"s
- "tt", "%p"
- //"t"
-};
-
-static FX_LPCWSTR months[] =
-{
- (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"
-};
-
-static FX_LPCWSTR fullmonths[] =
-{
- (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"
-};
-
-FX_BOOL CJS_PublicMethods::IsNumber(FX_LPCWSTR string)
-{
- CFX_WideString sTrim = StrTrim(string);
- FX_LPCWSTR pTrim = sTrim;
- FX_LPCWSTR p = pTrim;
-
-
- FX_BOOL bDot = FALSE;
- FX_BOOL bKXJS = FALSE;
-
- wchar_t c;
- while ((c = *p))
- {
- if (c == '.' || c == ',')
- {
- if (bDot) return FALSE;
- bDot = TRUE;
- }
- else if (c == '-' || c == '+')
- {
- if (p != pTrim)
- return FALSE;
- }
- else if (c == 'e' || c == 'E')
- {
- if (bKXJS) return FALSE;
-
- p++;
- c = *p;
- if (c == '+' || c == '-')
- {
- bKXJS = TRUE;
- }
- else
- {
- return FALSE;
- }
- }
- else if (!IsDigit(c))
- {
- return FALSE;
- }
- p++;
- }
-
- return TRUE;
-}
-
-FX_BOOL CJS_PublicMethods::IsDigit(wchar_t ch)
-{
- return (ch >= L'0' && ch <= L'9');
-}
-
-FX_BOOL CJS_PublicMethods::IsDigit(char ch)
-{
- return (ch >= '0' && ch <= '9');
-}
-
-FX_BOOL CJS_PublicMethods::IsAlphabetic(wchar_t ch)
-{
- return ((ch >= L'a' && ch <= L'z') || (ch >= L'A' && ch <= L'Z'));
-}
-
-FX_BOOL CJS_PublicMethods::IsAlphaNumeric(wchar_t ch)
-{
- return (IsDigit(ch) || IsAlphabetic(ch));
-}
-
-FX_BOOL CJS_PublicMethods::maskSatisfied(wchar_t c_Change,wchar_t c_Mask)
-{
- switch (c_Mask)
- {
- case L'9':
- return IsDigit(c_Change);
- case L'A':
- return IsAlphabetic(c_Change);
- case L'O':
- return IsAlphaNumeric(c_Change);
- case L'X':
- return TRUE;
- default:
- return (c_Change == c_Mask);
- }
-}
-
-FX_BOOL CJS_PublicMethods::isReservedMaskChar(wchar_t ch)
-{
- return ch == L'9' || ch == L'A' || ch == L'O' || ch == L'X';
-}
-
-double CJS_PublicMethods::AF_Simple(FX_LPCWSTR sFuction, double dValue1, double dValue2)
-{
- if (FXSYS_wcsicmp(sFuction,(FX_LPCWSTR)L"AVG") == 0 || FXSYS_wcsicmp(sFuction,(FX_LPCWSTR)L"SUM") == 0)
- {
- return dValue1 + dValue2;
- }
- else if (FXSYS_wcsicmp(sFuction, (FX_LPCWSTR)L"PRD") == 0)
- {
- return dValue1 * dValue2;
- }
- else if (FXSYS_wcsicmp(sFuction,(FX_LPCWSTR)L"MIN") == 0)
- {
- return FX_MIN(dValue1, dValue2);
- }
- else if (FXSYS_wcsicmp(sFuction,(FX_LPCWSTR)L"MAX") == 0)
- {
- return FX_MAX(dValue1, dValue2);
- }
-
- return dValue1;
-}
-
-CFX_WideString CJS_PublicMethods::StrLTrim(FX_LPCWSTR pStr)
-{
- while (*pStr && *pStr == L' ') pStr++;
-
- return pStr;
-}
-
-CFX_WideString CJS_PublicMethods::StrRTrim(FX_LPCWSTR pStr)
-{
- FX_LPCWSTR p = pStr;
-
- while (*p) p++;
- p--;
- if (p >= pStr)
- {
- while (*p && *p == L' ') p--;
- p++;
- return CFX_WideString(pStr,p-pStr);
- }
- return L"";
-}
-
-CFX_WideString CJS_PublicMethods::StrTrim(FX_LPCWSTR pStr)
-{
- return StrRTrim(StrLTrim(pStr));
-}
-
-CFX_ByteString CJS_PublicMethods::StrLTrim(FX_LPCSTR pStr)
-{
- while (*pStr && *pStr == ' ') pStr++;
-
- return pStr;
-}
-
-CFX_ByteString CJS_PublicMethods::StrRTrim(FX_LPCSTR pStr)
-{
- FX_LPCSTR p = pStr;
-
- while (*p) p++;
- p--;
- if (p >= pStr)
- {
- while (*p && *p == ' ') p--;
- p++;
- return CFX_ByteString(pStr,p-pStr);
- }
- return "";
-}
-
-CFX_ByteString CJS_PublicMethods::StrTrim(FX_LPCSTR pStr)
-{
- return StrRTrim(StrLTrim(pStr));
-}
-
-double CJS_PublicMethods::ParseNumber(FX_LPCWSTR swSource, FX_BOOL& bAllDigits, FX_BOOL& bDot, FX_BOOL& bSign, FX_BOOL& bKXJS)
-{
- bDot = FALSE;
- bSign = FALSE;
- bKXJS = FALSE;
-
- FX_BOOL bDigitExist = FALSE;
-
- FX_LPCWSTR p = swSource;
- wchar_t c;
-
- FX_LPCWSTR pStart = NULL;
- FX_LPCWSTR pEnd = NULL;
-
- while ((c = *p))
- {
- if (!pStart && c != L' ')
- {
- pStart = p;
- }
-
- pEnd = p;
- p++;
- }
-
- if (!pStart)
- {
- bAllDigits = FALSE;
- return 0;
- }
-
- while (pEnd != pStart)
- {
- if (*pEnd == L' ')
- pEnd --;
- else
- break;
- }
-
- double dRet = 0;
- p = pStart;
- bAllDigits = TRUE;
- CFX_WideString swDigits;
-
- while (p <= pEnd)
- {
- c = *p;
-
- if (IsDigit(c))
- {
- swDigits += c;
- bDigitExist = TRUE;
- }
- else
- {
- switch (c)
- {
- case L' ':
- bAllDigits = FALSE;
- break;
- case L'.':
- case L',':
- if (!bDot)
- {
- if (bDigitExist)
- {
- swDigits += L'.';
- }
- else
- {
- swDigits += L'0';
- swDigits += L'.';
- bDigitExist = TRUE;
- }
-
- bDot = TRUE;
- break;
- }
- case 'e':
- case 'E':
- if (!bKXJS)
- {
- p++;
- c = *p;
- if (c == '+' || c == '-')
- {
- bKXJS = TRUE;
- swDigits += 'e';
- swDigits += c;
- }
- break;
- }
- case L'-':
- if (!bDigitExist && !bSign)
- {
- swDigits += c;
- bSign = TRUE;
- break;
- }
- default:
- bAllDigits = FALSE;
-
- if (p != pStart && !bDot && bDigitExist)
- {
- swDigits += L'.';
- bDot = TRUE;
- }
- else
- {
- bDot = FALSE;
- bDigitExist = FALSE;
- swDigits = L"";
- }
- break;
- }
- }
-
- p++;
- }
-
- if (swDigits.GetLength() > 0 && swDigits.GetLength() < 17)
- {
- CFX_ByteString sDigits = swDigits.UTF8Encode();
-
- if (bKXJS)
- {
- dRet = atof(sDigits);
- }
- else
- {
- if (bDot)
- {
- char* pStopString;
- dRet = ::strtod(sDigits, &pStopString);
- }
- else
- {
- dRet = atol(sDigits);
- }
- }
-
- }
-
- return dRet;
-}
-
-double CJS_PublicMethods::ParseStringToNumber(FX_LPCWSTR swSource)
-{
- FX_BOOL bAllDigits = FALSE;
- FX_BOOL bDot = FALSE;
- FX_BOOL bSign = FALSE;
- FX_BOOL bKXJS = FALSE;
-
- return ParseNumber(swSource, bAllDigits, bDot, bSign, bKXJS);
-}
-
-FX_BOOL CJS_PublicMethods::ConvertStringToNumber(FX_LPCWSTR swSource, double & dRet, FX_BOOL & bDot)
-{
- FX_BOOL bAllDigits = FALSE;
- FX_BOOL bSign = FALSE;
- FX_BOOL bKXJS = FALSE;
-
- dRet = ParseNumber(swSource, bAllDigits, bDot, bSign, bKXJS);
-
- return bAllDigits;
-}
-
-CJS_Array CJS_PublicMethods::AF_MakeArrayFromList(v8::Isolate* isolate, CJS_Value val)
-{
- CJS_Array StrArray(isolate);
- if(val.IsArrayObject())
- {
- val.ConvertToArray(StrArray);
- return StrArray;
- }
- CFX_WideString wsStr = val.operator CFX_WideString();
- CFX_ByteString t = CFX_ByteString::FromUnicode(wsStr);
- const char * p = (const char *)t;
-
-
- int ch = ',' ;
- int nIndex = 0;
-
- while (*p)
- {
- const char * pTemp = strchr(p, ch);
- if (pTemp == NULL)
- {
- StrArray.SetElement(nIndex, CJS_Value(isolate,(FX_LPCSTR)StrTrim(p)));
- break;
- }
- else
- {
- char * pSub = new char[pTemp - p + 1];
- strncpy(pSub, p, pTemp - p);
- *(pSub + (pTemp - p)) = '\0';
-
- StrArray.SetElement(nIndex, CJS_Value(isolate,(FX_LPCSTR)StrTrim(pSub)));
- delete []pSub;
-
- nIndex ++;
- p = ++pTemp;
- }
-
- }
- return StrArray;
-}
-
-int CJS_PublicMethods::ParseStringInteger(const CFX_WideString& string,int nStart,int& nSkip, int nMaxStep)
-{
- int nRet = 0;
- nSkip = 0;
- for (int i=nStart, sz=string.GetLength(); i < sz; i++)
- {
- if (i-nStart > 10)
- break;
-
- FX_WCHAR c = string.GetAt(i);
- if (IsDigit((wchar_t)c))
- {
- nRet = nRet * 10 + (c - '0');
- nSkip = i - nStart + 1;
- if (nSkip >= nMaxStep)
- break;
- }
- else
- break;
- }
-
- return nRet;
-}
-
-CFX_WideString CJS_PublicMethods::ParseStringString(const CFX_WideString& string, int nStart, int& nSkip)
-{
- CFX_WideString swRet;
- nSkip = 0;
- for (int i=nStart, sz=string.GetLength(); i < sz; i++)
- {
- FX_WCHAR c = string.GetAt(i);
- if ((c >= L'a' && c <= L'z') || (c >= L'A' && c <= L'Z'))
- {
- swRet += c;
- nSkip = i - nStart + 1;
- }
- else
- break;
- }
-
- return swRet;
-}
-
-double CJS_PublicMethods::ParseNormalDate(const CFX_WideString & value, FX_BOOL& bWrongFormat)
-{
- double dt = JS_GetDateTime();
-
- int nYear = JS_GetYearFromTime(dt);
- int nMonth = JS_GetMonthFromTime(dt) + 1;
- int nDay = JS_GetDayFromTime(dt);
- int nHour = JS_GetHourFromTime(dt);
- int nMin = JS_GetMinFromTime(dt);
- int nSec = JS_GetSecFromTime(dt);
-
- int number[3];
-
- int nSkip = 0;
- int nLen = value.GetLength();
- int nIndex = 0;
- int i = 0;
- while (i < nLen)
- {
- if (nIndex > 2) break;
-
- FX_WCHAR c = value.GetAt(i);
- if (IsDigit((wchar_t)c))
- {
- number[nIndex++] = ParseStringInteger(value, i, nSkip, 4);
- i += nSkip;
- }
- else
- {
- i ++;
- }
- }
-
- if (nIndex == 2)
- {
- // case2: month/day
- // case3: day/month
- if ((number[0] >= 1 && number[0] <= 12) && (number[1] >= 1 && number[1] <= 31))
- {
- nMonth = number[0];
- nDay = number[1];
- }
- else if ((number[0] >= 1 && number[0] <= 31) && (number[1] >= 1 && number[1] <= 12))
- {
- nDay = number[0];
- nMonth = number[1];
- }
-
- bWrongFormat = FALSE;
- }
- else if (nIndex == 3)
- {
- // case1: year/month/day
- // case2: month/day/year
- // case3: day/month/year
-
- if (number[0] > 12 && (number[1] >= 1 && number[1] <= 12) && (number[2] >= 1 && number[2] <= 31))
- {
- nYear = number[0];
- nMonth = number[1];
- nDay = number[2];
- }
- else if ((number[0] >= 1 && number[0] <= 12) && (number[1] >= 1 && number[1] <= 31) && number[2] > 31)
- {
- nMonth = number[0];
- nDay = number[1];
- nYear = number[2];
- }
- else if ((number[0] >= 1 && number[0] <= 31) && (number[1] >= 1 && number[1] <= 12) && number[2] > 31)
- {
- nDay = number[0];
- nMonth = number[1];
- nYear = number[2];
- }
-
- bWrongFormat = FALSE;
- }
- else
- {
- bWrongFormat = TRUE;
- return dt;
- }
-
- CFX_WideString swTemp;
- swTemp.Format((FX_LPCWSTR)L"%d/%d/%d %d:%d:%d",nMonth,nDay,nYear,nHour,nMin,nSec);
- return JS_DateParse(swTemp);
-}
-
-double CJS_PublicMethods::MakeRegularDate(const CFX_WideString & value, const CFX_WideString & format, FX_BOOL& bWrongFormat)
-{
- double dt = JS_GetDateTime();
-
- if (format.IsEmpty() || value.IsEmpty())
- return dt;
-
- int nYear = JS_GetYearFromTime(dt);
- int nMonth = JS_GetMonthFromTime(dt) + 1;
- int nDay = JS_GetDayFromTime(dt);
- int nHour = JS_GetHourFromTime(dt);
- int nMin = JS_GetMinFromTime(dt);
- int nSec = JS_GetSecFromTime(dt);
-
- int nYearSub = 99; //nYear - 2000;
-
- FX_BOOL bPm = FALSE;
- FX_BOOL bExit = FALSE;
- bWrongFormat = FALSE;
-
- int i=0;
- int j=0;
-
- while (i < format.GetLength())
- {
- if (bExit) break;
-
- FX_WCHAR c = format.GetAt(i);
- switch (c)
- {
- case ':':
- case '.':
- case '-':
- case '\\':
- case '/':
- i++;
- j++;
- break;
-
- case 'y':
- case 'm':
- case 'd':
- case 'H':
- case 'h':
- case 'M':
- case 's':
- case 't':
- {
- int oldj = j;
- int nSkip = 0;
-
- if (format.GetAt(i+1) != c)
- {
- switch (c)
- {
- case 'y':
- i++;
- j++;
- break;
- case 'm':
- nMonth = ParseStringInteger(value, j, nSkip, 2);
- i++;
- j += nSkip;
- break;
- case 'd':
- nDay = ParseStringInteger(value, j, nSkip, 2);
- i++;
- j += nSkip;
- break;
- case 'H':
- nHour = ParseStringInteger(value, j, nSkip, 2);
- i++;
- j += nSkip;
- break;
- case 'h':
- nHour = ParseStringInteger(value, j, nSkip, 2);
- i++;
- j += nSkip;
- break;
- case 'M':
- nMin = ParseStringInteger(value, j, nSkip, 2);
- i++;
- j += nSkip;
- break;
- case 's':
- nSec = ParseStringInteger(value, j, nSkip, 2);
- i++;
- j += nSkip;
- break;
- case 't':
- bPm = value.GetAt(i) == 'p';
- i++;
- j++;
- break;
- }
- }
- else if (format.GetAt(i+1) == c && format.GetAt(i+2) != c)
- {
- switch (c)
- {
- case 'y':
- nYear = ParseStringInteger(value, j, nSkip, 4);
- i += 2;
- j += nSkip;
- break;
- case 'm':
- nMonth = ParseStringInteger(value, j, nSkip, 2);
- i += 2;
- j += nSkip;
- break;
- case 'd':
- nDay = ParseStringInteger(value, j, nSkip, 2);
- i += 2;
- j += nSkip;
- break;
- case 'H':
- nHour = ParseStringInteger(value, j, nSkip, 2);
- i += 2;
- j += nSkip;
- break;
- case 'h':
- nHour = ParseStringInteger(value, j, nSkip, 2);
- i += 2;
- j += nSkip;
- break;
- case 'M':
- nMin = ParseStringInteger(value, j, nSkip, 2);
- i += 2;
- j += nSkip;
- break;
- case 's':
- nSec = ParseStringInteger(value, j, nSkip, 2);
- i += 2;
- j += nSkip;
- break;
- case 't':
- bPm = (value.GetAt(j) == 'p' && value.GetAt(j+1) == 'm');
- i += 2;
- j += 2;
- break;
- }
- }
- else if (format.GetAt(i+1) == c && format.GetAt(i+2) == c && format.GetAt(i+3) != c)
- {
- switch (c)
- {
- case 'm':
- {
- CFX_WideString sMonth = ParseStringString(value, j, nSkip);
- FX_BOOL bFind = FALSE;
- for (int m = 0; m < 12; m++)
- {
- if (sMonth.CompareNoCase(months[m]) == 0)
- {
- nMonth = m + 1;
- i+=3;
- j+=nSkip;
- bFind = TRUE;
- break;
- }
- }
-
- if (!bFind)
- {
- nMonth = ParseStringInteger(value, j, nSkip, 3);
- i+=3;
- j += nSkip;
- }
- }
- break;
- case 'y':
- break;
- default:
- i+=3;
- j+=3;
- break;
- }
- }
- else if (format.GetAt(i+1) == c && format.GetAt(i+2) == c && format.GetAt(i+3) == c && format.GetAt(i+4) != c)
- {
- switch (c)
- {
-
-
- case 'y':
- nYear = ParseStringInteger(value, j, nSkip, 4);
- j += nSkip;
- i += 4;
- break;
- case 'm':
- {
- FX_BOOL bFind = FALSE;
-
- CFX_WideString sMonth = ParseStringString(value, j, nSkip);
- sMonth.MakeLower();
-
- for (int m = 0; m < 12; m++)
- {
- CFX_WideString sFullMonths = fullmonths[m];
- sFullMonths.MakeLower();
-
- if (sFullMonths.Find(sMonth, 0) != -1)
- {
- nMonth = m + 1;
- i += 4;
- j += nSkip;
- bFind = TRUE;
- break;
- }
- }
-
- if (!bFind)
- {
- nMonth = ParseStringInteger(value, j, nSkip, 4);
- i+=4;
- j += nSkip;
- }
- }
- break;
- default:
- i += 4;
- j += 4;
- break;
- }
- }
- else
- {
- if (format.GetAt(i) != value.GetAt(j))
- {
- bWrongFormat = TRUE;
- bExit = TRUE;
- }
- i++;
- j++;
- }
-
- if (oldj == j)
- {
- bWrongFormat = TRUE;
- bExit = TRUE;
- }
- }
-
- break;
- default:
- if (value.GetLength() <= j)
- {
- bExit = TRUE;
- }
- else if (format.GetAt(i) != value.GetAt(j))
- {
- bWrongFormat = TRUE;
- bExit = TRUE;
- }
-
- i++;
- j++;
- break;
- }
- }
-
- if (bPm) nHour += 12;
-
- if (nYear >= 0 && nYear <= nYearSub)
- nYear += 2000;
-
- if (nMonth < 1 || nMonth > 12)
- bWrongFormat = TRUE;
-
- if (nDay < 1 || nDay > 31)
- bWrongFormat = TRUE;
-
- if (nHour < 0 || nHour > 24)
- bWrongFormat = TRUE;
-
- if (nMin < 0 || nMin > 60)
- bWrongFormat = TRUE;
-
- if (nSec < 0 || nSec > 60)
- bWrongFormat = TRUE;
-
- double dRet = 0;
-
- if (bWrongFormat)
- {
- dRet = ParseNormalDate(value, bWrongFormat);
- }
- else
- {
- dRet = JS_MakeDate(JS_MakeDay(nYear,nMonth - 1,nDay),JS_MakeTime(nHour, nMin, nSec, 0));
-
- if (JS_PortIsNan(dRet))
- {
- dRet = JS_DateParse(value);
- }
- }
-
- if (JS_PortIsNan(dRet))
- {
- dRet = ParseNormalDate(value, bWrongFormat);
- }
-
- return dRet;
-
-}
-
-CFX_WideString CJS_PublicMethods::MakeFormatDate(double dDate, const CFX_WideString & format)
-{
- CFX_WideString sRet = L"",sPart = L"";
-
- int nYear = JS_GetYearFromTime(dDate);
- int nMonth = JS_GetMonthFromTime(dDate) + 1;
- int nDay = JS_GetDayFromTime(dDate);
- int nHour = JS_GetHourFromTime(dDate);
- int nMin = JS_GetMinFromTime(dDate);
- int nSec = JS_GetSecFromTime(dDate);
-
- int i = 0;
- FX_WCHAR c;
- while (i < format.GetLength())
- {
- c = format.GetAt(i);
- sPart = L"";
- switch (c)
- {
- case 'y':
- case 'm':
- case 'd':
- case 'H':
- case 'h':
- case 'M':
- case 's':
- case 't':
- if (format.GetAt(i+1) != c)
- {
- switch (c)
- {
- case 'y':
- sPart += c;
- break;
- case 'm':
- sPart.Format((FX_LPCWSTR)L"%d",nMonth);
- break;
- case 'd':
- sPart.Format((FX_LPCWSTR)L"%d",nDay);
- break;
- case 'H':
- sPart.Format((FX_LPCWSTR)L"%d",nHour);
- break;
- case 'h':
- sPart.Format((FX_LPCWSTR)L"%d",nHour>12?nHour - 12:nHour);
- break;
- case 'M':
- sPart.Format((FX_LPCWSTR)L"%d",nMin);
- break;
- case 's':
- sPart.Format((FX_LPCWSTR)L"%d",nSec);
- break;
- case 't':
- sPart += nHour>12?'p':'a';
- break;
- }
- i++;
- }
- else if (format.GetAt(i+1) == c && format.GetAt(i+2) != c)
- {
- switch (c)
- {
- case 'y':
- sPart.Format((FX_LPCWSTR)L"%02d",nYear - (nYear / 100) * 100);
- break;
- case 'm':
- sPart.Format((FX_LPCWSTR)L"%02d",nMonth);
- break;
- case 'd':
- sPart.Format((FX_LPCWSTR)L"%02d",nDay);
- break;
- case 'H':
- sPart.Format((FX_LPCWSTR)L"%02d",nHour);
- break;
- case 'h':
- sPart.Format((FX_LPCWSTR)L"%02d",nHour>12?nHour - 12:nHour);
- break;
- case 'M':
- sPart.Format((FX_LPCWSTR)L"%02d",nMin);
- break;
- case 's':
- sPart.Format((FX_LPCWSTR)L"%02d",nSec);
- break;
- case 't':
- sPart = nHour>12? (FX_LPCWSTR)L"pm": (FX_LPCWSTR)L"am";
- break;
- }
- i+=2;
- }
- else if (format.GetAt(i+1) == c && format.GetAt(i+2) == c && format.GetAt(i+3) != c)
- {
- switch (c)
- {
- case 'm':
- i+=3;
- if (nMonth > 0&&nMonth <= 12)
- sPart += months[nMonth - 1];
- break;
- default:
- i+=3;
- sPart += c;
- sPart += c;
- sPart += c;
- break;
- }
- }
- else if (format.GetAt(i+1) == c && format.GetAt(i+2) == c && format.GetAt(i+3) == c && format.GetAt(i+4) != c)
- {
- switch (c)
- {
- case 'y':
- sPart.Format((FX_LPCWSTR)L"%04d",nYear);
- i += 4;
- break;
- case 'm':
- i+=4;
- if (nMonth > 0&&nMonth <= 12)
- sPart += fullmonths[nMonth - 1];
- break;
- default:
- i += 4;
- sPart += c;
- sPart += c;
- sPart += c;
- sPart += c;
- break;
- }
- }
- else
- {
- i++;
- sPart += c;
- }
- break;
- default:
- i++;
- sPart += c;
- break;
- }
-
- sRet += sPart;
- }
-
- return sRet;
-}
-
-/* -------------------------------------------------------------------------- */
-
-//function AFNumber_Format(nDec, sepStyle, negStyle, currStyle, strCurrency, bCurrencyPrepend)
-FX_BOOL CJS_PublicMethods::AFNumber_Format(OBJ_METHOD_PARAMS)
-{
-#if _FX_OS_ != _FX_ANDROID_
- v8::Isolate* isolate = ::GetIsolate(cc);
- CJS_Context* pContext = (CJS_Context *)cc;
- ASSERT(pContext != NULL);
- CJS_EventHandler* pEvent = pContext->GetEventHandler();
- ASSERT(pEvent != NULL);
-
- if (params.size() != 6)
- {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
- if(!pEvent->m_pValue)
- return FALSE;
- CFX_WideString& Value = pEvent->Value();
- CFX_ByteString strValue = StrTrim(CFX_ByteString::FromUnicode(Value));
-
- if (strValue.IsEmpty()) return TRUE;
-
- int iDec = params[0];
- int iSepStyle = params[1];
- int iNegStyle = params[2];
- int icurrStyle = params[3]; //it's no use!
- std::wstring wstrCurrency(params[4].operator CFX_WideString());
- FX_BOOL bCurrencyPrepend = params[5];
-
- if (iDec < 0) iDec = -iDec;
-
- if (iSepStyle < 0 || iSepStyle > 3)
- iSepStyle = 0;
-
- if (iNegStyle < 0 || iNegStyle > 3)
- iNegStyle = 0;
-
-
- //////////////////////////////////////////////////////
- //for processing decimal places
- strValue.Replace(",", ".");
- double dValue = atof(strValue);
- if (iDec > 0)
- dValue += DOUBLE_CORRECT;//
-
- int iDec2;
- FX_BOOL bNagative = FALSE;
-
- strValue = fcvt(dValue,iDec,&iDec2,&bNagative);
- if (strValue.IsEmpty())
- {
- dValue = 0;
- strValue = fcvt(dValue,iDec,&iDec2,&bNagative);
- if (strValue.IsEmpty())
- {
- strValue = "0";
- iDec2 = 1;
- }
-
- }
-
- if (iDec2 < 0)
- {
- for (int iNum = 0;iNum < abs(iDec2);iNum++)
- {
- strValue = "0" + strValue;
- }
- iDec2 = 0;
-
- }
- int iMax = strValue.GetLength();
- if (iDec2 > iMax)
- {
- for (int iNum = 0;iNum <= iDec2 - iMax ;iNum++)
- {
- strValue += "0";
- }
- iMax = iDec2+1;
- }
- ///////////////////////////////////////////////////////
- //for processing seperator style
- if (iDec2 < iMax)
- {
- if (iSepStyle == 0 || iSepStyle == 1)
- {
- strValue.Insert(iDec2, '.');
- iMax++;
- }
- else if (iSepStyle == 2 || iSepStyle == 3)
- {
- strValue.Insert(iDec2, ',');
- iMax++;
- }
-
- if (iDec2 == 0)
- strValue.Insert(iDec2, '0');
- }
- if (iSepStyle == 0 || iSepStyle == 2)
- {
- char cSeperator;
- if (iSepStyle == 0)
- cSeperator = ',';
- else
- cSeperator = '.';
-
- int iDecPositive,iDecNagative;
- iDecPositive = iDec2;
- iDecNagative = iDec2;
-
- for (iDecPositive = iDec2 -3; iDecPositive > 0;iDecPositive -= 3)
- {
- strValue.Insert(iDecPositive, cSeperator);
- iMax++;
- }
- }
-
- //////////////////////////////////////////////////////////////////////
- //for processing currency string
-
- Value = CFX_WideString::FromLocal(strValue);
-
- std::wstring strValue2(Value);
-
- if (bCurrencyPrepend)
- strValue2 = wstrCurrency + strValue2;
- else
- strValue2 = strValue2 + wstrCurrency;
-
-
-
- /////////////////////////////////////////////////////////////////////////
- //for processing negative style
- if (bNagative)
- {
- if (iNegStyle == 0)
- {
- strValue2.insert(0,L"-");
- }
- if (iNegStyle == 2 || iNegStyle == 3)
- {
- strValue2.insert(0,L"(");
- strValue2.insert(strValue2.length(),L")");
- }
- if (iNegStyle == 1 || iNegStyle == 3)
- {
- if (Field * fTarget = pEvent->Target_Field())
- {
- CJS_Array arColor(isolate);
- CJS_Value vColElm(isolate);
- vColElm = L"RGB";
- arColor.SetElement(0,vColElm);
- vColElm = 1;
- arColor.SetElement(1,vColElm);
- vColElm = 0;
- arColor.SetElement(2,vColElm);
-
- arColor.SetElement(3,vColElm);
-
- CJS_PropValue vProp(isolate);
- vProp.StartGetting();
- vProp<<arColor;
- vProp.StartSetting();
- fTarget->textColor(cc,vProp,sError);// red
- }
- }
- }
- else
- {
- if (iNegStyle == 1 || iNegStyle == 3)
- {
- if (Field *fTarget = pEvent->Target_Field())
- {
- CJS_Array arColor(isolate);
- CJS_Value vColElm(isolate);
- vColElm = L"RGB";
- arColor.SetElement(0,vColElm);
- vColElm = 0;
- arColor.SetElement(1,vColElm);
- arColor.SetElement(2,vColElm);
- arColor.SetElement(3,vColElm);
-
- CJS_PropValue vProp(isolate);
- vProp.StartGetting();
- fTarget->textColor(cc,vProp,sError);
-
- CJS_Array aProp(isolate);
- vProp.ConvertToArray(aProp);
-
- CPWL_Color crProp;
- CPWL_Color crColor;
- color::ConvertArrayToPWLColor(aProp, crProp);
- color::ConvertArrayToPWLColor(arColor, crColor);
-
- if (crColor != crProp)
- {
- CJS_PropValue vProp2(isolate);
- vProp2.StartGetting();
- vProp2<<arColor;
- vProp2.StartSetting();
- fTarget->textColor(cc,vProp2,sError);
- }
- }
- }
- }
- Value = strValue2.c_str();
-#endif
- return TRUE;
-}
-
-//function AFNumber_Keystroke(nDec, sepStyle, negStyle, currStyle, strCurrency, bCurrencyPrepend)
-FX_BOOL CJS_PublicMethods::AFNumber_Keystroke(OBJ_METHOD_PARAMS)
-{
- CJS_Context* pContext = (CJS_Context *)cc;
- ASSERT(pContext != NULL);
- CJS_EventHandler* pEvent = pContext->GetEventHandler();
- ASSERT(pEvent != NULL);
-
- if(params.size() < 2)
- return FALSE;
- int iSepStyle = params[1];
-
- if (iSepStyle < 0 || iSepStyle > 3)
- iSepStyle = 0;
- if(!pEvent->m_pValue)
- return FALSE;
- CFX_WideString & val = pEvent->Value();
- CFX_WideString & w_strChange = pEvent->Change();
- CFX_WideString w_strValue = val;
-
- if (pEvent->WillCommit())
- {
- CFX_WideString wstrChange = w_strChange;
- CFX_WideString wstrValue = StrLTrim(w_strValue);
- if (wstrValue.IsEmpty())
- return TRUE;
-
- CFX_WideString swTemp = wstrValue;
- swTemp.Replace((FX_LPCWSTR)L",", (FX_LPCWSTR)L".");
- if (!IsNumber(swTemp)) //!(IsNumber(wstrChange) &&
- {
- pEvent->Rc() = FALSE;
- sError = JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYSTROKE);
- Alert(pContext, sError);
- return TRUE;
- }
- return TRUE; // it happens after the last keystroke and before validating,
- }
-
- std::wstring w_strValue2 (w_strValue);
- std::wstring w_strChange2(w_strChange);
-
- std::wstring w_strSelected;
- if(-1 != pEvent->SelStart())
- w_strSelected = w_strValue2.substr(pEvent->SelStart(),(pEvent->SelEnd() - pEvent->SelStart()));
- FX_BOOL bHasSign = (w_strValue2.find('-') != -1) && (w_strSelected.find('-') == -1);
- if (bHasSign)
- {
- //can't insert "change" in front to sign postion.
- if (pEvent->SelStart() == 0)
- {
- FX_BOOL &bRc = pEvent->Rc();
- bRc = FALSE;
- return TRUE;
- }
- }
-
- char cSep = L'.';
-
- switch (iSepStyle)
- {
- case 0:
- case 1:
- cSep = L'.';
- break;
- case 2:
- case 3:
- cSep = L',';
- break;
- }
-
- FX_BOOL bHasSep = (w_strValue2.find(cSep) != -1);
- for (std::wstring::iterator it = w_strChange2.begin(); it != w_strChange2.end(); it++)
- {
- if (*it == cSep)
- {
- if (bHasSep)
- {
- FX_BOOL &bRc = pEvent->Rc();
- bRc = FALSE;
- return TRUE;
- }
- else
- {
- bHasSep = TRUE;
- continue;
- }
- }
- if (*it == L'-')
- {
- if (bHasSign)
- {
- FX_BOOL &bRc = pEvent->Rc();
- bRc = FALSE;
- return TRUE;
- }
- else if (it != w_strChange2.begin()) //sign's position is not correct
- {
- FX_BOOL &bRc = pEvent->Rc();
- bRc = FALSE;
- return TRUE;
- }
- else if (pEvent->SelStart() != 0)
- {
- FX_BOOL &bRc = pEvent->Rc();
- bRc = FALSE;
- return TRUE;
- }
- bHasSign = TRUE;
- continue;
- }
-
- if (!IsDigit(*it))
- {
- FX_BOOL &bRc = pEvent->Rc();
- bRc = FALSE;
- return TRUE;
- }
- }
-
-
- std::wstring w_prefix = w_strValue2.substr(0,pEvent->SelStart());
- std::wstring w_postfix;
- if (pEvent->SelEnd()<(int)w_strValue2.length())
- w_postfix = w_strValue2.substr(pEvent->SelEnd());
- w_strValue2 = w_prefix + w_strChange2 + w_postfix;
- w_strValue = w_strValue2.c_str();
- val = w_strValue;
- return TRUE;
-
-}
-
-//function AFPercent_Format(nDec, sepStyle)
-FX_BOOL CJS_PublicMethods::AFPercent_Format(OBJ_METHOD_PARAMS)
-{
-#if _FX_OS_ != _FX_ANDROID_
- CJS_Context* pContext = (CJS_Context *)cc;
- ASSERT(pContext != NULL);
- CJS_EventHandler* pEvent = pContext->GetEventHandler();
- ASSERT(pEvent != NULL);
-
- if (params.size() != 2)
- {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
- if(!pEvent->m_pValue)
- return FALSE;
- CFX_WideString& Value = pEvent->Value();
-
-// HWND hMainFrame = NULL;
-//
-// CPDFSDK_FormFillApp *pApp = pContext->GetReaderApp();
-// ASSERT(pApp);
-// hMainFrame = pApp->GetMainFrameWnd();
-
- CFX_ByteString strValue = StrTrim(CFX_ByteString::FromUnicode(Value));
-
- if (strValue.IsEmpty())
- return TRUE;
-
- int iDec = params[0];
- int iSepStyle = params[1];
-
- //ASSERT(iDec > 0);
- if (iDec < 0)
- iDec = -iDec;
-
- if (iSepStyle < 0 || iSepStyle > 3)
- iSepStyle = 0;
-
-
- //////////////////////////////////////////////////////
- //for processing decimal places
- double dValue = atof(strValue);
- dValue *= 100;
- if (iDec > 0)
- dValue += DOUBLE_CORRECT;//��
-
- int iDec2;
- FX_BOOL bNagative = FALSE;
- strValue = fcvt(dValue,iDec,&iDec2,&bNagative);
- if (strValue.IsEmpty())
- {
- dValue = 0;
- strValue = fcvt(dValue,iDec,&iDec2,&bNagative);
- }
-
- if (iDec2 < 0)
- {
- for (int iNum = 0; iNum < abs(iDec2); iNum++)
- {
- strValue = "0" + strValue;
- }
- iDec2 = 0;
-
- }
- int iMax = strValue.GetLength();
- if (iDec2 > iMax)
- {
- for (int iNum = 0; iNum <= iDec2 - iMax; iNum++)
- {
- strValue += "0";
- }
- iMax = iDec2+1;
- }
- ///////////////////////////////////////////////////////
- //for processing seperator style
- if (iDec2 < iMax)
- {
- if (iSepStyle == 0 || iSepStyle == 1)
- {
- strValue.Insert(iDec2, '.');
- iMax++;
- }
- else if (iSepStyle == 2 || iSepStyle == 3)
- {
- strValue.Insert(iDec2, ',');
- iMax++;
- }
-
- if (iDec2 == 0)
- strValue.Insert(iDec2, '0');
- }
- if (iSepStyle == 0 || iSepStyle == 2)
- {
- char cSeperator;
- if (iSepStyle == 0)
- cSeperator = ',';
- else
- cSeperator = '.';
-
- int iDecPositive,iDecNagative;
- iDecPositive = iDec2;
- iDecNagative = iDec2;
-
- for (iDecPositive = iDec2 -3; iDecPositive > 0; iDecPositive -= 3)
- {
- strValue.Insert(iDecPositive,cSeperator);
- iMax++;
- }
- }
- ////////////////////////////////////////////////////////////////////
- //nagative mark
- if(bNagative)
- strValue = "-" + strValue;
- strValue += "%";
- Value = CFX_WideString::FromLocal(strValue);
-#endif
- return TRUE;
-}
-//AFPercent_Keystroke(nDec, sepStyle)
-FX_BOOL CJS_PublicMethods::AFPercent_Keystroke(OBJ_METHOD_PARAMS)
-{
- return AFNumber_Keystroke(cc,params,vRet,sError);
-}
-
-//function AFDate_FormatEx(cFormat)
-FX_BOOL CJS_PublicMethods::AFDate_FormatEx(OBJ_METHOD_PARAMS)
-{
- CJS_Context* pContext = (CJS_Context *)cc;
- ASSERT(pContext != NULL);
- CJS_EventHandler* pEvent = pContext->GetEventHandler();
- ASSERT(pEvent != NULL);
-
- if (params.size() != 1)
- {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
- if(!pEvent->m_pValue)
- return FALSE;
- CFX_WideString& val = pEvent->Value();
-
- CFX_WideString strValue = val;
- if (strValue.IsEmpty()) return TRUE;
-
- CFX_WideString sFormat = params[0].operator CFX_WideString();
-
- FX_BOOL bWrongFormat = FALSE;
- double dDate = 0.0f;
-
- if(strValue.Find(L"GMT") != -1)
- {
- //for GMT format time
- //such as "Tue Aug 11 14:24:16 GMT+08002009"
- dDate = MakeInterDate(strValue);
- }
- else
- {
- dDate = MakeRegularDate(strValue,sFormat,bWrongFormat);
- }
-
- if (JS_PortIsNan(dDate))
- {
- CFX_WideString swMsg;
- swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE), (FX_LPCWSTR)sFormat);
- Alert(pContext, swMsg);
- return FALSE;
- }
-
- val = MakeFormatDate(dDate,sFormat);
-
- return TRUE;
-}
-
-double CJS_PublicMethods::MakeInterDate(CFX_WideString strValue)
-{
- int nHour;
- int nMin;
- int nSec;
- int nYear;
- int nMonth;
- int nDay;
-
- CFX_WideStringArray wsArray;
- CFX_WideString sMonth = L"";
- CFX_WideString sTemp = L"";
- int nSize = strValue.GetLength();
-
- for(int i = 0; i < nSize; i++)
- {
- FX_WCHAR c = strValue.GetAt(i);
- if(c == L' ' || c == L':')
- {
- wsArray.Add(sTemp);
- sTemp = L"";
- continue;
- }
-
- sTemp += c;
- }
-
- wsArray.Add(sTemp);
- if(wsArray.GetSize() != 8)return 0;
-
- sTemp = wsArray[1];
- if(sTemp.Compare(L"Jan") == 0) nMonth = 1;
- if(sTemp.Compare(L"Feb") == 0) nMonth = 2;
- if(sTemp.Compare(L"Mar") == 0) nMonth = 3;
- if(sTemp.Compare(L"Apr") == 0) nMonth = 4;
- if(sTemp.Compare(L"May") == 0) nMonth = 5;
- if(sTemp.Compare(L"Jun") == 0) nMonth = 6;
- if(sTemp.Compare(L"Jul") == 0) nMonth = 7;
- if(sTemp.Compare(L"Aug") == 0) nMonth = 8;
- if(sTemp.Compare(L"Sep") == 0) nMonth = 9;
- if(sTemp.Compare(L"Oct") == 0) nMonth = 10;
- if(sTemp.Compare(L"Nov") == 0) nMonth = 11;
- if(sTemp.Compare(L"Dec") == 0) nMonth = 12;
-
- nDay = (int)ParseStringToNumber(wsArray[2]);
- nHour = (int)ParseStringToNumber(wsArray[3]);
- nMin = (int)ParseStringToNumber(wsArray[4]);
- nSec = (int)ParseStringToNumber(wsArray[5]);
- nYear = (int)ParseStringToNumber(wsArray[7]);
-
- double dRet = JS_MakeDate(JS_MakeDay(nYear,nMonth - 1,nDay),JS_MakeTime(nHour, nMin, nSec, 0));
-
- if (JS_PortIsNan(dRet))
- {
- dRet = JS_DateParse(strValue);
- }
-
- return dRet;
-}
-
-//AFDate_KeystrokeEx(cFormat)
-FX_BOOL CJS_PublicMethods::AFDate_KeystrokeEx(OBJ_METHOD_PARAMS)
-{
- CJS_Context* pContext = (CJS_Context *)cc;
- ASSERT(pContext != NULL);
- CJS_EventHandler* pEvent = pContext->GetEventHandler();
- ASSERT(pEvent != NULL);
-
- if (params.size() != 1)
- {
- sError = L"AFDate_KeystrokeEx's parameters' size r not correct";
- return FALSE;
- }
-
- if (pEvent->WillCommit())
- {
- if(!pEvent->m_pValue)
- return FALSE;
- CFX_WideString strValue = pEvent->Value();
- if (strValue.IsEmpty()) return TRUE;
-
- CFX_WideString sFormat = params[0].operator CFX_WideString();
-
- FX_BOOL bWrongFormat = FALSE;
- double dRet = MakeRegularDate(strValue,sFormat,bWrongFormat);
- if (bWrongFormat || JS_PortIsNan(dRet))
- {
- CFX_WideString swMsg;
- swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE), (FX_LPCWSTR)sFormat);
- Alert(pContext, swMsg);
- pEvent->Rc() = FALSE;
- return TRUE;
- }
- }
- return TRUE;
-}
-
-FX_BOOL CJS_PublicMethods::AFDate_Format(OBJ_METHOD_PARAMS)
-{
- v8::Isolate* isolate = ::GetIsolate(cc);
-
- if (params.size() != 1)
- {
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
-
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
-
- int iIndex = params[0];
- 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",
- (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",
- (FX_LPCWSTR)L"m/d/yy h:MM tt", (FX_LPCWSTR)L"m/d/yy HH:MM" };
-
- ASSERT(iIndex < sizeof(cFormats)/sizeof(FX_LPCWSTR));
-
- if (iIndex < 0)
- iIndex = 0;
- if (iIndex >= sizeof(cFormats)/sizeof(FX_LPCWSTR))
- iIndex = 0;
- CJS_Parameters newParams;
- CJS_Value val(isolate,cFormats[iIndex]);
- newParams.push_back(val);
- return AFDate_FormatEx(cc,newParams,vRet,sError);
-}
-
-//AFDate_KeystrokeEx(cFormat)
-FX_BOOL CJS_PublicMethods::AFDate_Keystroke(OBJ_METHOD_PARAMS)
-{
- v8::Isolate* isolate = ::GetIsolate(cc);
-
- if (params.size() != 1)
- {
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
-
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
-
- int iIndex = params[0];
- 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",
- (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",
- (FX_LPCWSTR)L"m/d/yy h:MM tt", (FX_LPCWSTR)L"m/d/yy HH:MM" };
-
- ASSERT(iIndex<sizeof(cFormats)/sizeof(FX_LPCWSTR));
-
- if (iIndex < 0)
- iIndex = 0;
- if (iIndex >= sizeof(cFormats)/sizeof(FX_LPCWSTR))
- iIndex = 0;
- CJS_Parameters newParams;
- CJS_Value val(isolate,cFormats[iIndex]);
- newParams.push_back(val);
- return AFDate_KeystrokeEx(cc,newParams,vRet,sError);
-}
-
-//function AFTime_Format(ptf)
-FX_BOOL CJS_PublicMethods::AFTime_Format(OBJ_METHOD_PARAMS)
-{
- v8::Isolate* isolate = ::GetIsolate(cc);
-
- if (params.size() != 1)
- {
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
-
- int iIndex = params[0];
- 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"};
-
- ASSERT(iIndex<sizeof(cFormats)/sizeof(FX_LPCWSTR));
-
- if (iIndex < 0)
- iIndex = 0;
- if (iIndex >= sizeof(cFormats)/sizeof(FX_LPCWSTR))
- iIndex = 0;
- CJS_Parameters newParams;
- CJS_Value val(isolate,cFormats[iIndex]);
- newParams.push_back(val);
- return AFDate_FormatEx(cc,newParams,vRet,sError);
-}
-
-FX_BOOL CJS_PublicMethods::AFTime_Keystroke(OBJ_METHOD_PARAMS)
-{
- v8::Isolate* isolate = ::GetIsolate(cc);
- if (params.size() != 1)
- {
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
-
- int iIndex = params[0];
- 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"};
-
- ASSERT(iIndex<sizeof(cFormats)/sizeof(FX_LPCWSTR));
-
- if (iIndex < 0)
- iIndex = 0;
- if (iIndex >= sizeof(cFormats)/sizeof(FX_LPCWSTR))
- iIndex = 0;
- CJS_Parameters newParams;
- CJS_Value val(isolate,cFormats[iIndex]);
- newParams.push_back(val);
- return AFDate_KeystrokeEx(cc,newParams,vRet,sError);
-}
-
-FX_BOOL CJS_PublicMethods::AFTime_FormatEx(OBJ_METHOD_PARAMS)
-{
- return AFDate_FormatEx(cc,params,vRet,sError);
-}
-
-FX_BOOL CJS_PublicMethods::AFTime_KeystrokeEx(OBJ_METHOD_PARAMS)
-{
- return AFDate_KeystrokeEx(cc,params,vRet,sError);
-}
-
-//function AFSpecial_Format(psf)
-FX_BOOL CJS_PublicMethods::AFSpecial_Format(OBJ_METHOD_PARAMS)
-{
- CJS_Context* pContext = (CJS_Context *)cc;
- ASSERT(pContext != NULL);
-
- if (params.size() != 1)
- {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
-
- std::string cFormat;
- int iIndex = params[0];
-
- CJS_EventHandler* pEvent = pContext->GetEventHandler();
- ASSERT(pEvent != NULL);
-
- if(!pEvent->m_pValue)
- return FALSE;
- CFX_WideString& Value = pEvent->Value();
- std::string strSrc = (FX_LPCSTR)CFX_ByteString::FromUnicode(Value);
-
- switch (iIndex)
- {
- case 0:
- cFormat = "99999";
- break;
- case 1:
- cFormat = "99999-9999";
- break;
- case 2:
- {
- std::string NumberStr;
- util::printx("9999999999", strSrc,NumberStr);
- if (NumberStr.length() >= 10 )
- cFormat = "(999) 999-9999";
- else
- cFormat = "999-9999";
- break;
- }
- case 3:
- cFormat = "999-99-9999";
- break;
- }
-
- std::string strDes;
- util::printx(cFormat,strSrc,strDes);
- Value = CFX_WideString::FromLocal(strDes.c_str());
- return TRUE;
-}
-
-
-//function AFSpecial_KeystrokeEx(mask)
-FX_BOOL CJS_PublicMethods::AFSpecial_KeystrokeEx(OBJ_METHOD_PARAMS)
-{
- CJS_Context* pContext = (CJS_Context *)cc;
- ASSERT(pContext != NULL);
- CJS_EventHandler* pEvent = pContext->GetEventHandler();
-
- ASSERT(pEvent != NULL);
-
- if (params.size() < 1)
- {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
-
- if(!pEvent->m_pValue)
- return FALSE;
- CFX_WideString& valEvent = pEvent->Value();
-
- CFX_WideString wstrMask = params[0].operator CFX_WideString();
- if (wstrMask.IsEmpty()) return TRUE;
-
- std::wstring wstrValue(valEvent);
-
- if (pEvent->WillCommit())
- {
- if (wstrValue.empty())
- return TRUE;
- int iIndexMask = 0;
- for (std::wstring::iterator it = wstrValue.begin(); it != wstrValue.end(); it++)
- {
- wchar_t w_Value = *it;
- if (!maskSatisfied(w_Value,wstrMask[iIndexMask]))
- break;
- iIndexMask++;
- }
-
- if (iIndexMask != wstrMask.GetLength() || (iIndexMask != wstrValue.size() && wstrMask.GetLength() != 0))
- {
- Alert(pContext, JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYSTROKE));
- pEvent->Rc() = FALSE;
- }
- return TRUE;
- }
-
-
- CFX_WideString &wideChange = pEvent->Change();
- std::wstring wChange(wideChange);
-
- if (wChange.empty())
- return TRUE;
- int iIndexMask = pEvent->SelStart();
- //iIndexMask++;
-
-
- if (wstrValue.length() - (pEvent->SelEnd()-pEvent->SelStart()) + wChange.length() > (FX_DWORD)wstrMask.GetLength())
- {
- Alert(pContext, JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG));
- pEvent->Rc() = FALSE;
- return TRUE;
- }
-
-
- if (iIndexMask >= wstrMask.GetLength() && (!wChange.empty()))
- {
- Alert(pContext, JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG));
- pEvent->Rc() = FALSE;
- return TRUE;
- }
-
- for (std::wstring::iterator it = wChange.begin(); it != wChange.end(); it++)
- {
- if (iIndexMask >= wstrMask.GetLength())
- {
- Alert(pContext, JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG));
- pEvent->Rc() = FALSE;
- return TRUE;
- }
- wchar_t w_Mask = wstrMask[iIndexMask];
- if (!isReservedMaskChar(w_Mask))
- {
- //wChange.insert(it,w_Mask);
- *it = w_Mask;
- }
- wchar_t w_Change = *it;
-
- if (!maskSatisfied(w_Change,w_Mask))
- {
- pEvent->Rc() = FALSE;
- return TRUE;
- }
- iIndexMask++;
- }
-
- wideChange = wChange.c_str();
-
- return TRUE;
-}
-
-
-//function AFSpecial_Keystroke(psf)
-FX_BOOL CJS_PublicMethods::AFSpecial_Keystroke(OBJ_METHOD_PARAMS)
-{
- v8::Isolate* isolate = ::GetIsolate(cc);
-
- CJS_Context* pContext = (CJS_Context *)cc;
- ASSERT(pContext != NULL);
- CJS_EventHandler* pEvent = pContext->GetEventHandler();
- ASSERT(pEvent != NULL);
-
- if (params.size() != 1)
- {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
-
- std::string cFormat;
- int iIndex = (int)params[0];
-
- if(!pEvent->m_pValue)
- return FALSE;
- //CJS_Value val = pEvent->Value();
- CFX_WideString& val = pEvent->Value();
- std::string strSrc = (FX_LPCSTR)CFX_ByteString::FromUnicode(val);
- std::wstring wstrChange(pEvent->Change());
-
- switch (iIndex)
- {
- case 0:
- cFormat = "99999";
- break;
- case 1:
- //cFormat = "99999-9999";
- cFormat = "999999999";
- break;
- case 2:
- {
- std::string NumberStr;
- util::printx("9999999999", strSrc,NumberStr);
- if (strSrc.length() + wstrChange.length() > 7 )
- //cFormat = "(999) 999-9999";
- cFormat = "9999999999";
- else
- //cFormat = "999-9999";
- cFormat = "9999999";
- break;
- }
- case 3:
- //cFormat = "999-99-9999";
- cFormat = "999999999";
- break;
- }
-
- CJS_Parameters params2;
- CJS_Value vMask(isolate, cFormat.c_str());
- params2.push_back(vMask);
-
- return AFSpecial_KeystrokeEx(cc,params2,vRet,sError);
-}
-
-FX_BOOL CJS_PublicMethods::AFMergeChange(OBJ_METHOD_PARAMS)
-{
- CJS_Context* pContext = (CJS_Context *)cc;
- ASSERT(pContext != NULL);
- CJS_EventHandler* pEventHandler = pContext->GetEventHandler();
- ASSERT(pEventHandler != NULL);
-
- if (params.size() != 1)
- {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
-
- CFX_WideString swValue;
- if (pEventHandler->m_pValue != NULL)
- swValue = pEventHandler->Value();
-
- if (pEventHandler->WillCommit())
- {
- vRet = swValue;
- return TRUE;
- }
-
- CFX_WideString prefix,postfix;
-
- if (pEventHandler->SelStart() >= 0)
- prefix = swValue.Mid(0,pEventHandler->SelStart());
- else
- prefix = L"";
-
-
- if (pEventHandler->SelEnd() >= 0 && pEventHandler->SelEnd() <= swValue.GetLength())
- postfix = swValue.Mid(pEventHandler->SelEnd(), swValue.GetLength() - pEventHandler->SelEnd());
- else postfix = L"";
-
- vRet = prefix + pEventHandler->Change() + postfix;
-
- return TRUE;
-}
-
-FX_BOOL CJS_PublicMethods::AFParseDateEx(OBJ_METHOD_PARAMS)
-{
- CJS_Context* pContext = (CJS_Context *)cc;
- ASSERT(pContext != NULL);
-
- if (params.size() != 2)
- {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
-
- CFX_WideString sValue = params[0].operator CFX_WideString();
- CFX_WideString sFormat = params[1].operator CFX_WideString();
-
- FX_BOOL bWrongFormat = FALSE;
- double dDate = MakeRegularDate(sValue,sFormat,bWrongFormat);
-
- if (JS_PortIsNan(dDate))
- {
- CFX_WideString swMsg;
- swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE), (FX_LPCWSTR)sFormat);
- Alert((CJS_Context *)cc, swMsg);
- return FALSE;
- }
-
- vRet = dDate;
-
- return TRUE;
-}
-
-FX_BOOL CJS_PublicMethods::AFSimple(OBJ_METHOD_PARAMS)
-{
- if (params.size() != 3)
- {
- CJS_Context* pContext = (CJS_Context *)cc;
- ASSERT(pContext != NULL);
-
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
-
- vRet = (double)AF_Simple(params[0].operator CFX_WideString(), (double)params[1], (double)params[2]);
- return TRUE;
-}
-
-FX_BOOL CJS_PublicMethods::AFMakeNumber(OBJ_METHOD_PARAMS)
-{
- if (params.size() != 1)
- {
- CJS_Context* pContext = (CJS_Context *)cc;
- ASSERT(pContext != NULL);
-
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
- vRet = ParseStringToNumber(params[0].operator CFX_WideString());
- return TRUE;
-}
-
-FX_BOOL CJS_PublicMethods::AFSimple_Calculate(OBJ_METHOD_PARAMS)
-{
- v8::Isolate* isolate = ::GetIsolate(cc);
-
- CJS_Context* pContext = (CJS_Context *)cc;
- ASSERT(pContext != NULL);
-
- if (params.size() != 2)
- {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
-
- CJS_Value params1 = params[1];
-
- if (!params1.IsArrayObject() && params1.GetType() != VT_string)
- {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
-
- CPDFSDK_Document* pReaderDoc = pContext->GetReaderDocument();
- ASSERT(pReaderDoc != NULL);
-
- CPDFSDK_InterForm* pReaderInterForm = pReaderDoc->GetInterForm();
- ASSERT(pReaderInterForm != NULL);
-
- CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm();
- ASSERT(pInterForm != NULL);
-
- double dValue;
- CFX_WideString sFunction = params[0].operator CFX_WideString();
- if (wcscmp(sFunction, L"PRD") == 0)
- dValue = 1.0;
- else
- dValue = 0.0;
-
- CJS_Array FieldNameArray = AF_MakeArrayFromList(isolate,params1);
-
- int nFieldsCount = 0;
-
- for (int i=0,isz=FieldNameArray.GetLength(); i<isz; i++)
- {
- CJS_Value jsValue(isolate);
- FieldNameArray.GetElement(i,jsValue);
- CFX_WideString wsFieldName = jsValue.operator CFX_WideString();
-
- for (int j=0,jsz=pInterForm->CountFields(wsFieldName); j<jsz; j++)
- {
- if (CPDF_FormField* pFormField = pInterForm->GetField(j, wsFieldName))
- {
- double dTemp = 0.0;
-
- switch (pFormField->GetFieldType())
- {
- case FIELDTYPE_TEXTFIELD:
- case FIELDTYPE_COMBOBOX:
- {
- dTemp = ParseStringToNumber(pFormField->GetValue());
- break;
- }
- case FIELDTYPE_PUSHBUTTON:
- {
- dTemp = 0.0;
- break;
- }
- case FIELDTYPE_CHECKBOX:
- case FIELDTYPE_RADIOBUTTON:
- {
- dTemp = 0.0;
- for (int c=0,csz=pFormField->CountControls(); c<csz; c++)
- {
- if (CPDF_FormControl* pFormCtrl = pFormField->GetControl(c))
- {
- if (pFormCtrl->IsChecked())
- {
- dTemp += ParseStringToNumber(pFormCtrl->GetExportValue());
- break;
- }
- else
- continue;
- }
- }
- break;
- }
- case FIELDTYPE_LISTBOX:
- {
- dTemp = 0.0;
- if (pFormField->CountSelectedItems() > 1)
- break;
- else
- {
- dTemp = ParseStringToNumber(pFormField->GetValue());
- break;
- }
- }
- default:
- break;
- }
-
- if (i == 0 && j == 0 && (wcscmp(sFunction,L"MIN") == 0 || wcscmp(sFunction, L"MAX") == 0))
- dValue = dTemp;
-
- dValue = AF_Simple(sFunction, dValue, dTemp);
-
- nFieldsCount++;
- }
- }
- }
-
- if (wcscmp(sFunction, L"AVG") == 0 && nFieldsCount > 0)
- dValue /= nFieldsCount;
-
- dValue = (double)floor(dValue * FXSYS_pow((double)10,(double)6) + 0.49) / FXSYS_pow((double)10,(double)6);
- CJS_Value jsValue(isolate,dValue);
- if((CJS_EventHandler*)pContext->GetEventHandler()->m_pValue)
- ((CJS_EventHandler*)pContext->GetEventHandler())->Value() = jsValue;
-
- return TRUE;
-}
-
-/* This function validates the current event to ensure that its value is
-** within the specified range. */
-
-FX_BOOL CJS_PublicMethods::AFRange_Validate(OBJ_METHOD_PARAMS)
-{
- CJS_Context* pContext = (CJS_Context *)cc;
- ASSERT(pContext != NULL);
- CJS_EventHandler* pEvent = pContext->GetEventHandler();
- ASSERT(pEvent != NULL);
-
- if (params.size() != 4)
- {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
-
- if(!pEvent->m_pValue)
- return FALSE;
- if (pEvent->Value().IsEmpty() )
- return TRUE;
- double dEentValue = atof(CFX_ByteString::FromUnicode(pEvent->Value()));
- FX_BOOL bGreaterThan, bLessThan;
- double dGreaterThan, dLessThan;
- bGreaterThan = (FX_BOOL)params[0];
- CFX_WideString swMsg;
- dGreaterThan = (double)params[1];
- bLessThan = (FX_BOOL)params[2];
- dLessThan = (double)params[3];
-
- if (bGreaterThan && bLessThan)
- {
- if (dEentValue < dGreaterThan || dEentValue > dLessThan)
- swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE1),(FX_LPCWSTR)params[1].operator CFX_WideString(), (FX_LPCWSTR)params[3].operator CFX_WideString());
- }
- else if (bGreaterThan)
- {
- if (dEentValue < dGreaterThan)
- swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE2), (FX_LPCWSTR)params[1].operator CFX_WideString());
- }
- else if (bLessThan)
- {
- if (dEentValue > dLessThan)
- swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE3), (FX_LPCWSTR)params[3].operator CFX_WideString());
- }
-
- if (!swMsg.IsEmpty())
- {
- Alert(pContext, swMsg);
- pEvent->Rc() = FALSE;
- }
- return TRUE;
-}
-
-FX_BOOL CJS_PublicMethods::AFExtractNums(OBJ_METHOD_PARAMS)
-{
- v8::Isolate* isolate = ::GetIsolate(cc);
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
-
- if (params.size() != 1)
- {
- sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
-
- CJS_Array nums(isolate);
-
- CFX_WideString str = params[0].operator CFX_WideString();
- CFX_WideString sPart;
-
- if (str.GetAt(0) == L'.' || str.GetAt(0) == L',')
- str = L"0" + str;
-
- int nIndex = 0;
- for (int i=0, sz=str.GetLength(); i<sz; i++)
- {
- FX_WCHAR wc = str.GetAt(i);
- if (IsDigit((wchar_t)wc))
- {
- sPart += wc;
- }
- else
- {
- if (sPart.GetLength() > 0)
- {
- nums.SetElement(nIndex,CJS_Value(isolate,(FX_LPCWSTR)sPart));
- sPart = L"";
- nIndex ++;
- }
- }
- }
-
- if (sPart.GetLength() > 0)
- {
- nums.SetElement(nIndex,CJS_Value(isolate,(FX_LPCWSTR)sPart));
- }
-
- if (nums.GetLength() > 0)
- vRet = nums;
- else
- vRet.SetNull();
-
- return TRUE;
-}
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/javascript/JavaScript.h"
+#include "../../include/javascript/IJavaScript.h"
+#include "../../include/javascript/JS_Define.h"
+#include "../../include/javascript/JS_Object.h"
+#include "../../include/javascript/JS_Value.h"
+#include "../../include/javascript/PublicMethods.h"
+#include "../../include/javascript/JS_EventHandler.h"
+#include "../../include/javascript/resource.h"
+#include "../../include/javascript/JS_Context.h"
+#include "../../include/javascript/JS_Value.h"
+#include "../../include/javascript/util.h"
+#include "../../include/javascript/Field.h"
+#include "../../include/javascript/color.h"
+#include "../../include/javascript/JS_Runtime.h"
+
+static v8::Isolate* GetIsolate(IFXJS_Context* cc)
+{
+ CJS_Context* pContext = (CJS_Context *)cc;
+ ASSERT(pContext != NULL);
+
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ ASSERT(pRuntime != NULL);
+
+ return pRuntime->GetIsolate();
+}
+
+
+/* -------------------------------- CJS_PublicMethods -------------------------------- */
+
+#define DOUBLE_CORRECT 0.000000000000001
+
+BEGIN_JS_STATIC_GLOBAL_FUN(CJS_PublicMethods)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFNumber_Format,6)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFNumber_Keystroke,6)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFPercent_Format,2)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFPercent_Keystroke,2)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_FormatEx,1)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_KeystrokeEx,1)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_Format,1)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_Keystroke,1)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFTime_FormatEx,1)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFTime_KeystrokeEx,1)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFTime_Format,1)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFTime_Keystroke,1)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFSpecial_Format,1)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFSpecial_Keystroke,1)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFSpecial_KeystrokeEx,1)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFSimple,3)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFMakeNumber,1)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFSimple_Calculate,2)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFRange_Validate,4)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFMergeChange,1)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFParseDateEx,2)
+ JS_STATIC_GLOBAL_FUN_ENTRY(AFExtractNums,1)
+END_JS_STATIC_GLOBAL_FUN()
+
+IMPLEMENT_JS_STATIC_GLOBAL_FUN(CJS_PublicMethods)
+
+struct stru_TbConvert
+{
+ FX_LPCSTR lpszJSMark;
+ FX_LPCSTR lpszCppMark;
+};
+
+static const stru_TbConvert fcTable[] = {"mmmm","%B",
+ "mmm", "%b",
+ "mm", "%m",
+ //"m"
+ "dddd","%A",
+ "ddd", "%a",
+ "dd", "%d",
+ //"d", "%w",
+ "yyyy","%Y",
+ "yy", "%y",
+ "HH", "%H",
+ //"H"
+ "hh", "%I",
+ //"h"
+ "MM", "%M",
+ //"M"
+ "ss", "%S",
+ //"s
+ "tt", "%p"
+ //"t"
+};
+
+static FX_LPCWSTR months[] =
+{
+ (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"
+};
+
+static FX_LPCWSTR fullmonths[] =
+{
+ (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"
+};
+
+FX_BOOL CJS_PublicMethods::IsNumber(FX_LPCWSTR string)
+{
+ CFX_WideString sTrim = StrTrim(string);
+ FX_LPCWSTR pTrim = sTrim;
+ FX_LPCWSTR p = pTrim;
+
+
+ FX_BOOL bDot = FALSE;
+ FX_BOOL bKXJS = FALSE;
+
+ wchar_t c;
+ while ((c = *p))
+ {
+ if (c == '.' || c == ',')
+ {
+ if (bDot) return FALSE;
+ bDot = TRUE;
+ }
+ else if (c == '-' || c == '+')
+ {
+ if (p != pTrim)
+ return FALSE;
+ }
+ else if (c == 'e' || c == 'E')
+ {
+ if (bKXJS) return FALSE;
+
+ p++;
+ c = *p;
+ if (c == '+' || c == '-')
+ {
+ bKXJS = TRUE;
+ }
+ else
+ {
+ return FALSE;
+ }
+ }
+ else if (!IsDigit(c))
+ {
+ return FALSE;
+ }
+ p++;
+ }
+
+ return TRUE;
+}
+
+FX_BOOL CJS_PublicMethods::IsDigit(wchar_t ch)
+{
+ return (ch >= L'0' && ch <= L'9');
+}
+
+FX_BOOL CJS_PublicMethods::IsDigit(char ch)
+{
+ return (ch >= '0' && ch <= '9');
+}
+
+FX_BOOL CJS_PublicMethods::IsAlphabetic(wchar_t ch)
+{
+ return ((ch >= L'a' && ch <= L'z') || (ch >= L'A' && ch <= L'Z'));
+}
+
+FX_BOOL CJS_PublicMethods::IsAlphaNumeric(wchar_t ch)
+{
+ return (IsDigit(ch) || IsAlphabetic(ch));
+}
+
+FX_BOOL CJS_PublicMethods::maskSatisfied(wchar_t c_Change,wchar_t c_Mask)
+{
+ switch (c_Mask)
+ {
+ case L'9':
+ return IsDigit(c_Change);
+ case L'A':
+ return IsAlphabetic(c_Change);
+ case L'O':
+ return IsAlphaNumeric(c_Change);
+ case L'X':
+ return TRUE;
+ default:
+ return (c_Change == c_Mask);
+ }
+}
+
+FX_BOOL CJS_PublicMethods::isReservedMaskChar(wchar_t ch)
+{
+ return ch == L'9' || ch == L'A' || ch == L'O' || ch == L'X';
+}
+
+double CJS_PublicMethods::AF_Simple(FX_LPCWSTR sFuction, double dValue1, double dValue2)
+{
+ if (FXSYS_wcsicmp(sFuction,(FX_LPCWSTR)L"AVG") == 0 || FXSYS_wcsicmp(sFuction,(FX_LPCWSTR)L"SUM") == 0)
+ {
+ return dValue1 + dValue2;
+ }
+ else if (FXSYS_wcsicmp(sFuction, (FX_LPCWSTR)L"PRD") == 0)
+ {
+ return dValue1 * dValue2;
+ }
+ else if (FXSYS_wcsicmp(sFuction,(FX_LPCWSTR)L"MIN") == 0)
+ {
+ return FX_MIN(dValue1, dValue2);
+ }
+ else if (FXSYS_wcsicmp(sFuction,(FX_LPCWSTR)L"MAX") == 0)
+ {
+ return FX_MAX(dValue1, dValue2);
+ }
+
+ return dValue1;
+}
+
+CFX_WideString CJS_PublicMethods::StrLTrim(FX_LPCWSTR pStr)
+{
+ while (*pStr && *pStr == L' ') pStr++;
+
+ return pStr;
+}
+
+CFX_WideString CJS_PublicMethods::StrRTrim(FX_LPCWSTR pStr)
+{
+ FX_LPCWSTR p = pStr;
+
+ while (*p) p++;
+ p--;
+ if (p >= pStr)
+ {
+ while (*p && *p == L' ') p--;
+ p++;
+ return CFX_WideString(pStr,p-pStr);
+ }
+ return L"";
+}
+
+CFX_WideString CJS_PublicMethods::StrTrim(FX_LPCWSTR pStr)
+{
+ return StrRTrim(StrLTrim(pStr));
+}
+
+CFX_ByteString CJS_PublicMethods::StrLTrim(FX_LPCSTR pStr)
+{
+ while (*pStr && *pStr == ' ') pStr++;
+
+ return pStr;
+}
+
+CFX_ByteString CJS_PublicMethods::StrRTrim(FX_LPCSTR pStr)
+{
+ FX_LPCSTR p = pStr;
+
+ while (*p) p++;
+ p--;
+ if (p >= pStr)
+ {
+ while (*p && *p == ' ') p--;
+ p++;
+ return CFX_ByteString(pStr,p-pStr);
+ }
+ return "";
+}
+
+CFX_ByteString CJS_PublicMethods::StrTrim(FX_LPCSTR pStr)
+{
+ return StrRTrim(StrLTrim(pStr));
+}
+
+double CJS_PublicMethods::ParseNumber(FX_LPCWSTR swSource, FX_BOOL& bAllDigits, FX_BOOL& bDot, FX_BOOL& bSign, FX_BOOL& bKXJS)
+{
+ bDot = FALSE;
+ bSign = FALSE;
+ bKXJS = FALSE;
+
+ FX_BOOL bDigitExist = FALSE;
+
+ FX_LPCWSTR p = swSource;
+ wchar_t c;
+
+ FX_LPCWSTR pStart = NULL;
+ FX_LPCWSTR pEnd = NULL;
+
+ while ((c = *p))
+ {
+ if (!pStart && c != L' ')
+ {
+ pStart = p;
+ }
+
+ pEnd = p;
+ p++;
+ }
+
+ if (!pStart)
+ {
+ bAllDigits = FALSE;
+ return 0;
+ }
+
+ while (pEnd != pStart)
+ {
+ if (*pEnd == L' ')
+ pEnd --;
+ else
+ break;
+ }
+
+ double dRet = 0;
+ p = pStart;
+ bAllDigits = TRUE;
+ CFX_WideString swDigits;
+
+ while (p <= pEnd)
+ {
+ c = *p;
+
+ if (IsDigit(c))
+ {
+ swDigits += c;
+ bDigitExist = TRUE;
+ }
+ else
+ {
+ switch (c)
+ {
+ case L' ':
+ bAllDigits = FALSE;
+ break;
+ case L'.':
+ case L',':
+ if (!bDot)
+ {
+ if (bDigitExist)
+ {
+ swDigits += L'.';
+ }
+ else
+ {
+ swDigits += L'0';
+ swDigits += L'.';
+ bDigitExist = TRUE;
+ }
+
+ bDot = TRUE;
+ break;
+ }
+ case 'e':
+ case 'E':
+ if (!bKXJS)
+ {
+ p++;
+ c = *p;
+ if (c == '+' || c == '-')
+ {
+ bKXJS = TRUE;
+ swDigits += 'e';
+ swDigits += c;
+ }
+ break;
+ }
+ case L'-':
+ if (!bDigitExist && !bSign)
+ {
+ swDigits += c;
+ bSign = TRUE;
+ break;
+ }
+ default:
+ bAllDigits = FALSE;
+
+ if (p != pStart && !bDot && bDigitExist)
+ {
+ swDigits += L'.';
+ bDot = TRUE;
+ }
+ else
+ {
+ bDot = FALSE;
+ bDigitExist = FALSE;
+ swDigits = L"";
+ }
+ break;
+ }
+ }
+
+ p++;
+ }
+
+ if (swDigits.GetLength() > 0 && swDigits.GetLength() < 17)
+ {
+ CFX_ByteString sDigits = swDigits.UTF8Encode();
+
+ if (bKXJS)
+ {
+ dRet = atof(sDigits);
+ }
+ else
+ {
+ if (bDot)
+ {
+ char* pStopString;
+ dRet = ::strtod(sDigits, &pStopString);
+ }
+ else
+ {
+ dRet = atol(sDigits);
+ }
+ }
+
+ }
+
+ return dRet;
+}
+
+double CJS_PublicMethods::ParseStringToNumber(FX_LPCWSTR swSource)
+{
+ FX_BOOL bAllDigits = FALSE;
+ FX_BOOL bDot = FALSE;
+ FX_BOOL bSign = FALSE;
+ FX_BOOL bKXJS = FALSE;
+
+ return ParseNumber(swSource, bAllDigits, bDot, bSign, bKXJS);
+}
+
+FX_BOOL CJS_PublicMethods::ConvertStringToNumber(FX_LPCWSTR swSource, double & dRet, FX_BOOL & bDot)
+{
+ FX_BOOL bAllDigits = FALSE;
+ FX_BOOL bSign = FALSE;
+ FX_BOOL bKXJS = FALSE;
+
+ dRet = ParseNumber(swSource, bAllDigits, bDot, bSign, bKXJS);
+
+ return bAllDigits;
+}
+
+CJS_Array CJS_PublicMethods::AF_MakeArrayFromList(v8::Isolate* isolate, CJS_Value val)
+{
+ CJS_Array StrArray(isolate);
+ if(val.IsArrayObject())
+ {
+ val.ConvertToArray(StrArray);
+ return StrArray;
+ }
+ CFX_WideString wsStr = val.operator CFX_WideString();
+ CFX_ByteString t = CFX_ByteString::FromUnicode(wsStr);
+ const char * p = (const char *)t;
+
+
+ int ch = ',' ;
+ int nIndex = 0;
+
+ while (*p)
+ {
+ const char * pTemp = strchr(p, ch);
+ if (pTemp == NULL)
+ {
+ StrArray.SetElement(nIndex, CJS_Value(isolate,(FX_LPCSTR)StrTrim(p)));
+ break;
+ }
+ else
+ {
+ char * pSub = new char[pTemp - p + 1];
+ strncpy(pSub, p, pTemp - p);
+ *(pSub + (pTemp - p)) = '\0';
+
+ StrArray.SetElement(nIndex, CJS_Value(isolate,(FX_LPCSTR)StrTrim(pSub)));
+ delete []pSub;
+
+ nIndex ++;
+ p = ++pTemp;
+ }
+
+ }
+ return StrArray;
+}
+
+int CJS_PublicMethods::ParseStringInteger(const CFX_WideString& string,int nStart,int& nSkip, int nMaxStep)
+{
+ int nRet = 0;
+ nSkip = 0;
+ for (int i=nStart, sz=string.GetLength(); i < sz; i++)
+ {
+ if (i-nStart > 10)
+ break;
+
+ FX_WCHAR c = string.GetAt(i);
+ if (IsDigit((wchar_t)c))
+ {
+ nRet = nRet * 10 + (c - '0');
+ nSkip = i - nStart + 1;
+ if (nSkip >= nMaxStep)
+ break;
+ }
+ else
+ break;
+ }
+
+ return nRet;
+}
+
+CFX_WideString CJS_PublicMethods::ParseStringString(const CFX_WideString& string, int nStart, int& nSkip)
+{
+ CFX_WideString swRet;
+ nSkip = 0;
+ for (int i=nStart, sz=string.GetLength(); i < sz; i++)
+ {
+ FX_WCHAR c = string.GetAt(i);
+ if ((c >= L'a' && c <= L'z') || (c >= L'A' && c <= L'Z'))
+ {
+ swRet += c;
+ nSkip = i - nStart + 1;
+ }
+ else
+ break;
+ }
+
+ return swRet;
+}
+
+double CJS_PublicMethods::ParseNormalDate(const CFX_WideString & value, FX_BOOL& bWrongFormat)
+{
+ double dt = JS_GetDateTime();
+
+ int nYear = JS_GetYearFromTime(dt);
+ int nMonth = JS_GetMonthFromTime(dt) + 1;
+ int nDay = JS_GetDayFromTime(dt);
+ int nHour = JS_GetHourFromTime(dt);
+ int nMin = JS_GetMinFromTime(dt);
+ int nSec = JS_GetSecFromTime(dt);
+
+ int number[3];
+
+ int nSkip = 0;
+ int nLen = value.GetLength();
+ int nIndex = 0;
+ int i = 0;
+ while (i < nLen)
+ {
+ if (nIndex > 2) break;
+
+ FX_WCHAR c = value.GetAt(i);
+ if (IsDigit((wchar_t)c))
+ {
+ number[nIndex++] = ParseStringInteger(value, i, nSkip, 4);
+ i += nSkip;
+ }
+ else
+ {
+ i ++;
+ }
+ }
+
+ if (nIndex == 2)
+ {
+ // case2: month/day
+ // case3: day/month
+ if ((number[0] >= 1 && number[0] <= 12) && (number[1] >= 1 && number[1] <= 31))
+ {
+ nMonth = number[0];
+ nDay = number[1];
+ }
+ else if ((number[0] >= 1 && number[0] <= 31) && (number[1] >= 1 && number[1] <= 12))
+ {
+ nDay = number[0];
+ nMonth = number[1];
+ }
+
+ bWrongFormat = FALSE;
+ }
+ else if (nIndex == 3)
+ {
+ // case1: year/month/day
+ // case2: month/day/year
+ // case3: day/month/year
+
+ if (number[0] > 12 && (number[1] >= 1 && number[1] <= 12) && (number[2] >= 1 && number[2] <= 31))
+ {
+ nYear = number[0];
+ nMonth = number[1];
+ nDay = number[2];
+ }
+ else if ((number[0] >= 1 && number[0] <= 12) && (number[1] >= 1 && number[1] <= 31) && number[2] > 31)
+ {
+ nMonth = number[0];
+ nDay = number[1];
+ nYear = number[2];
+ }
+ else if ((number[0] >= 1 && number[0] <= 31) && (number[1] >= 1 && number[1] <= 12) && number[2] > 31)
+ {
+ nDay = number[0];
+ nMonth = number[1];
+ nYear = number[2];
+ }
+
+ bWrongFormat = FALSE;
+ }
+ else
+ {
+ bWrongFormat = TRUE;
+ return dt;
+ }
+
+ CFX_WideString swTemp;
+ swTemp.Format((FX_LPCWSTR)L"%d/%d/%d %d:%d:%d",nMonth,nDay,nYear,nHour,nMin,nSec);
+ return JS_DateParse(swTemp);
+}
+
+double CJS_PublicMethods::MakeRegularDate(const CFX_WideString & value, const CFX_WideString & format, FX_BOOL& bWrongFormat)
+{
+ double dt = JS_GetDateTime();
+
+ if (format.IsEmpty() || value.IsEmpty())
+ return dt;
+
+ int nYear = JS_GetYearFromTime(dt);
+ int nMonth = JS_GetMonthFromTime(dt) + 1;
+ int nDay = JS_GetDayFromTime(dt);
+ int nHour = JS_GetHourFromTime(dt);
+ int nMin = JS_GetMinFromTime(dt);
+ int nSec = JS_GetSecFromTime(dt);
+
+ int nYearSub = 99; //nYear - 2000;
+
+ FX_BOOL bPm = FALSE;
+ FX_BOOL bExit = FALSE;
+ bWrongFormat = FALSE;
+
+ int i=0;
+ int j=0;
+
+ while (i < format.GetLength())
+ {
+ if (bExit) break;
+
+ FX_WCHAR c = format.GetAt(i);
+ switch (c)
+ {
+ case ':':
+ case '.':
+ case '-':
+ case '\\':
+ case '/':
+ i++;
+ j++;
+ break;
+
+ case 'y':
+ case 'm':
+ case 'd':
+ case 'H':
+ case 'h':
+ case 'M':
+ case 's':
+ case 't':
+ {
+ int oldj = j;
+ int nSkip = 0;
+
+ if (format.GetAt(i+1) != c)
+ {
+ switch (c)
+ {
+ case 'y':
+ i++;
+ j++;
+ break;
+ case 'm':
+ nMonth = ParseStringInteger(value, j, nSkip, 2);
+ i++;
+ j += nSkip;
+ break;
+ case 'd':
+ nDay = ParseStringInteger(value, j, nSkip, 2);
+ i++;
+ j += nSkip;
+ break;
+ case 'H':
+ nHour = ParseStringInteger(value, j, nSkip, 2);
+ i++;
+ j += nSkip;
+ break;
+ case 'h':
+ nHour = ParseStringInteger(value, j, nSkip, 2);
+ i++;
+ j += nSkip;
+ break;
+ case 'M':
+ nMin = ParseStringInteger(value, j, nSkip, 2);
+ i++;
+ j += nSkip;
+ break;
+ case 's':
+ nSec = ParseStringInteger(value, j, nSkip, 2);
+ i++;
+ j += nSkip;
+ break;
+ case 't':
+ bPm = value.GetAt(i) == 'p';
+ i++;
+ j++;
+ break;
+ }
+ }
+ else if (format.GetAt(i+1) == c && format.GetAt(i+2) != c)
+ {
+ switch (c)
+ {
+ case 'y':
+ nYear = ParseStringInteger(value, j, nSkip, 4);
+ i += 2;
+ j += nSkip;
+ break;
+ case 'm':
+ nMonth = ParseStringInteger(value, j, nSkip, 2);
+ i += 2;
+ j += nSkip;
+ break;
+ case 'd':
+ nDay = ParseStringInteger(value, j, nSkip, 2);
+ i += 2;
+ j += nSkip;
+ break;
+ case 'H':
+ nHour = ParseStringInteger(value, j, nSkip, 2);
+ i += 2;
+ j += nSkip;
+ break;
+ case 'h':
+ nHour = ParseStringInteger(value, j, nSkip, 2);
+ i += 2;
+ j += nSkip;
+ break;
+ case 'M':
+ nMin = ParseStringInteger(value, j, nSkip, 2);
+ i += 2;
+ j += nSkip;
+ break;
+ case 's':
+ nSec = ParseStringInteger(value, j, nSkip, 2);
+ i += 2;
+ j += nSkip;
+ break;
+ case 't':
+ bPm = (value.GetAt(j) == 'p' && value.GetAt(j+1) == 'm');
+ i += 2;
+ j += 2;
+ break;
+ }
+ }
+ else if (format.GetAt(i+1) == c && format.GetAt(i+2) == c && format.GetAt(i+3) != c)
+ {
+ switch (c)
+ {
+ case 'm':
+ {
+ CFX_WideString sMonth = ParseStringString(value, j, nSkip);
+ FX_BOOL bFind = FALSE;
+ for (int m = 0; m < 12; m++)
+ {
+ if (sMonth.CompareNoCase(months[m]) == 0)
+ {
+ nMonth = m + 1;
+ i+=3;
+ j+=nSkip;
+ bFind = TRUE;
+ break;
+ }
+ }
+
+ if (!bFind)
+ {
+ nMonth = ParseStringInteger(value, j, nSkip, 3);
+ i+=3;
+ j += nSkip;
+ }
+ }
+ break;
+ case 'y':
+ break;
+ default:
+ i+=3;
+ j+=3;
+ break;
+ }
+ }
+ else if (format.GetAt(i+1) == c && format.GetAt(i+2) == c && format.GetAt(i+3) == c && format.GetAt(i+4) != c)
+ {
+ switch (c)
+ {
+
+
+ case 'y':
+ nYear = ParseStringInteger(value, j, nSkip, 4);
+ j += nSkip;
+ i += 4;
+ break;
+ case 'm':
+ {
+ FX_BOOL bFind = FALSE;
+
+ CFX_WideString sMonth = ParseStringString(value, j, nSkip);
+ sMonth.MakeLower();
+
+ for (int m = 0; m < 12; m++)
+ {
+ CFX_WideString sFullMonths = fullmonths[m];
+ sFullMonths.MakeLower();
+
+ if (sFullMonths.Find(sMonth, 0) != -1)
+ {
+ nMonth = m + 1;
+ i += 4;
+ j += nSkip;
+ bFind = TRUE;
+ break;
+ }
+ }
+
+ if (!bFind)
+ {
+ nMonth = ParseStringInteger(value, j, nSkip, 4);
+ i+=4;
+ j += nSkip;
+ }
+ }
+ break;
+ default:
+ i += 4;
+ j += 4;
+ break;
+ }
+ }
+ else
+ {
+ if (format.GetAt(i) != value.GetAt(j))
+ {
+ bWrongFormat = TRUE;
+ bExit = TRUE;
+ }
+ i++;
+ j++;
+ }
+
+ if (oldj == j)
+ {
+ bWrongFormat = TRUE;
+ bExit = TRUE;
+ }
+ }
+
+ break;
+ default:
+ if (value.GetLength() <= j)
+ {
+ bExit = TRUE;
+ }
+ else if (format.GetAt(i) != value.GetAt(j))
+ {
+ bWrongFormat = TRUE;
+ bExit = TRUE;
+ }
+
+ i++;
+ j++;
+ break;
+ }
+ }
+
+ if (bPm) nHour += 12;
+
+ if (nYear >= 0 && nYear <= nYearSub)
+ nYear += 2000;
+
+ if (nMonth < 1 || nMonth > 12)
+ bWrongFormat = TRUE;
+
+ if (nDay < 1 || nDay > 31)
+ bWrongFormat = TRUE;
+
+ if (nHour < 0 || nHour > 24)
+ bWrongFormat = TRUE;
+
+ if (nMin < 0 || nMin > 60)
+ bWrongFormat = TRUE;
+
+ if (nSec < 0 || nSec > 60)
+ bWrongFormat = TRUE;
+
+ double dRet = 0;
+
+ if (bWrongFormat)
+ {
+ dRet = ParseNormalDate(value, bWrongFormat);
+ }
+ else
+ {
+ dRet = JS_MakeDate(JS_MakeDay(nYear,nMonth - 1,nDay),JS_MakeTime(nHour, nMin, nSec, 0));
+
+ if (JS_PortIsNan(dRet))
+ {
+ dRet = JS_DateParse(value);
+ }
+ }
+
+ if (JS_PortIsNan(dRet))
+ {
+ dRet = ParseNormalDate(value, bWrongFormat);
+ }
+
+ return dRet;
+
+}
+
+CFX_WideString CJS_PublicMethods::MakeFormatDate(double dDate, const CFX_WideString & format)
+{
+ CFX_WideString sRet = L"",sPart = L"";
+
+ int nYear = JS_GetYearFromTime(dDate);
+ int nMonth = JS_GetMonthFromTime(dDate) + 1;
+ int nDay = JS_GetDayFromTime(dDate);
+ int nHour = JS_GetHourFromTime(dDate);
+ int nMin = JS_GetMinFromTime(dDate);
+ int nSec = JS_GetSecFromTime(dDate);
+
+ int i = 0;
+ FX_WCHAR c;
+ while (i < format.GetLength())
+ {
+ c = format.GetAt(i);
+ sPart = L"";
+ switch (c)
+ {
+ case 'y':
+ case 'm':
+ case 'd':
+ case 'H':
+ case 'h':
+ case 'M':
+ case 's':
+ case 't':
+ if (format.GetAt(i+1) != c)
+ {
+ switch (c)
+ {
+ case 'y':
+ sPart += c;
+ break;
+ case 'm':
+ sPart.Format((FX_LPCWSTR)L"%d",nMonth);
+ break;
+ case 'd':
+ sPart.Format((FX_LPCWSTR)L"%d",nDay);
+ break;
+ case 'H':
+ sPart.Format((FX_LPCWSTR)L"%d",nHour);
+ break;
+ case 'h':
+ sPart.Format((FX_LPCWSTR)L"%d",nHour>12?nHour - 12:nHour);
+ break;
+ case 'M':
+ sPart.Format((FX_LPCWSTR)L"%d",nMin);
+ break;
+ case 's':
+ sPart.Format((FX_LPCWSTR)L"%d",nSec);
+ break;
+ case 't':
+ sPart += nHour>12?'p':'a';
+ break;
+ }
+ i++;
+ }
+ else if (format.GetAt(i+1) == c && format.GetAt(i+2) != c)
+ {
+ switch (c)
+ {
+ case 'y':
+ sPart.Format((FX_LPCWSTR)L"%02d",nYear - (nYear / 100) * 100);
+ break;
+ case 'm':
+ sPart.Format((FX_LPCWSTR)L"%02d",nMonth);
+ break;
+ case 'd':
+ sPart.Format((FX_LPCWSTR)L"%02d",nDay);
+ break;
+ case 'H':
+ sPart.Format((FX_LPCWSTR)L"%02d",nHour);
+ break;
+ case 'h':
+ sPart.Format((FX_LPCWSTR)L"%02d",nHour>12?nHour - 12:nHour);
+ break;
+ case 'M':
+ sPart.Format((FX_LPCWSTR)L"%02d",nMin);
+ break;
+ case 's':
+ sPart.Format((FX_LPCWSTR)L"%02d",nSec);
+ break;
+ case 't':
+ sPart = nHour>12? (FX_LPCWSTR)L"pm": (FX_LPCWSTR)L"am";
+ break;
+ }
+ i+=2;
+ }
+ else if (format.GetAt(i+1) == c && format.GetAt(i+2) == c && format.GetAt(i+3) != c)
+ {
+ switch (c)
+ {
+ case 'm':
+ i+=3;
+ if (nMonth > 0&&nMonth <= 12)
+ sPart += months[nMonth - 1];
+ break;
+ default:
+ i+=3;
+ sPart += c;
+ sPart += c;
+ sPart += c;
+ break;
+ }
+ }
+ else if (format.GetAt(i+1) == c && format.GetAt(i+2) == c && format.GetAt(i+3) == c && format.GetAt(i+4) != c)
+ {
+ switch (c)
+ {
+ case 'y':
+ sPart.Format((FX_LPCWSTR)L"%04d",nYear);
+ i += 4;
+ break;
+ case 'm':
+ i+=4;
+ if (nMonth > 0&&nMonth <= 12)
+ sPart += fullmonths[nMonth - 1];
+ break;
+ default:
+ i += 4;
+ sPart += c;
+ sPart += c;
+ sPart += c;
+ sPart += c;
+ break;
+ }
+ }
+ else
+ {
+ i++;
+ sPart += c;
+ }
+ break;
+ default:
+ i++;
+ sPart += c;
+ break;
+ }
+
+ sRet += sPart;
+ }
+
+ return sRet;
+}
+
+/* -------------------------------------------------------------------------- */
+
+//function AFNumber_Format(nDec, sepStyle, negStyle, currStyle, strCurrency, bCurrencyPrepend)
+FX_BOOL CJS_PublicMethods::AFNumber_Format(OBJ_METHOD_PARAMS)
+{
+#if _FX_OS_ != _FX_ANDROID_
+ v8::Isolate* isolate = ::GetIsolate(cc);
+ CJS_Context* pContext = (CJS_Context *)cc;
+ ASSERT(pContext != NULL);
+ CJS_EventHandler* pEvent = pContext->GetEventHandler();
+ ASSERT(pEvent != NULL);
+
+ if (params.size() != 6)
+ {
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
+ if(!pEvent->m_pValue)
+ return FALSE;
+ CFX_WideString& Value = pEvent->Value();
+ CFX_ByteString strValue = StrTrim(CFX_ByteString::FromUnicode(Value));
+
+ if (strValue.IsEmpty()) return TRUE;
+
+ int iDec = params[0];
+ int iSepStyle = params[1];
+ int iNegStyle = params[2];
+ int icurrStyle = params[3]; //it's no use!
+ std::wstring wstrCurrency(params[4].operator CFX_WideString());
+ FX_BOOL bCurrencyPrepend = params[5];
+
+ if (iDec < 0) iDec = -iDec;
+
+ if (iSepStyle < 0 || iSepStyle > 3)
+ iSepStyle = 0;
+
+ if (iNegStyle < 0 || iNegStyle > 3)
+ iNegStyle = 0;
+
+
+ //////////////////////////////////////////////////////
+ //for processing decimal places
+ strValue.Replace(",", ".");
+ double dValue = atof(strValue);
+ if (iDec > 0)
+ dValue += DOUBLE_CORRECT;//
+
+ int iDec2;
+ FX_BOOL bNagative = FALSE;
+
+ strValue = fcvt(dValue,iDec,&iDec2,&bNagative);
+ if (strValue.IsEmpty())
+ {
+ dValue = 0;
+ strValue = fcvt(dValue,iDec,&iDec2,&bNagative);
+ if (strValue.IsEmpty())
+ {
+ strValue = "0";
+ iDec2 = 1;
+ }
+
+ }
+
+ if (iDec2 < 0)
+ {
+ for (int iNum = 0;iNum < abs(iDec2);iNum++)
+ {
+ strValue = "0" + strValue;
+ }
+ iDec2 = 0;
+
+ }
+ int iMax = strValue.GetLength();
+ if (iDec2 > iMax)
+ {
+ for (int iNum = 0;iNum <= iDec2 - iMax ;iNum++)
+ {
+ strValue += "0";
+ }
+ iMax = iDec2+1;
+ }
+ ///////////////////////////////////////////////////////
+ //for processing seperator style
+ if (iDec2 < iMax)
+ {
+ if (iSepStyle == 0 || iSepStyle == 1)
+ {
+ strValue.Insert(iDec2, '.');
+ iMax++;
+ }
+ else if (iSepStyle == 2 || iSepStyle == 3)
+ {
+ strValue.Insert(iDec2, ',');
+ iMax++;
+ }
+
+ if (iDec2 == 0)
+ strValue.Insert(iDec2, '0');
+ }
+ if (iSepStyle == 0 || iSepStyle == 2)
+ {
+ char cSeperator;
+ if (iSepStyle == 0)
+ cSeperator = ',';
+ else
+ cSeperator = '.';
+
+ int iDecPositive,iDecNagative;
+ iDecPositive = iDec2;
+ iDecNagative = iDec2;
+
+ for (iDecPositive = iDec2 -3; iDecPositive > 0;iDecPositive -= 3)
+ {
+ strValue.Insert(iDecPositive, cSeperator);
+ iMax++;
+ }
+ }
+
+ //////////////////////////////////////////////////////////////////////
+ //for processing currency string
+
+ Value = CFX_WideString::FromLocal(strValue);
+
+ std::wstring strValue2(Value);
+
+ if (bCurrencyPrepend)
+ strValue2 = wstrCurrency + strValue2;
+ else
+ strValue2 = strValue2 + wstrCurrency;
+
+
+
+ /////////////////////////////////////////////////////////////////////////
+ //for processing negative style
+ if (bNagative)
+ {
+ if (iNegStyle == 0)
+ {
+ strValue2.insert(0,L"-");
+ }
+ if (iNegStyle == 2 || iNegStyle == 3)
+ {
+ strValue2.insert(0,L"(");
+ strValue2.insert(strValue2.length(),L")");
+ }
+ if (iNegStyle == 1 || iNegStyle == 3)
+ {
+ if (Field * fTarget = pEvent->Target_Field())
+ {
+ CJS_Array arColor(isolate);
+ CJS_Value vColElm(isolate);
+ vColElm = L"RGB";
+ arColor.SetElement(0,vColElm);
+ vColElm = 1;
+ arColor.SetElement(1,vColElm);
+ vColElm = 0;
+ arColor.SetElement(2,vColElm);
+
+ arColor.SetElement(3,vColElm);
+
+ CJS_PropValue vProp(isolate);
+ vProp.StartGetting();
+ vProp<<arColor;
+ vProp.StartSetting();
+ fTarget->textColor(cc,vProp,sError);// red
+ }
+ }
+ }
+ else
+ {
+ if (iNegStyle == 1 || iNegStyle == 3)
+ {
+ if (Field *fTarget = pEvent->Target_Field())
+ {
+ CJS_Array arColor(isolate);
+ CJS_Value vColElm(isolate);
+ vColElm = L"RGB";
+ arColor.SetElement(0,vColElm);
+ vColElm = 0;
+ arColor.SetElement(1,vColElm);
+ arColor.SetElement(2,vColElm);
+ arColor.SetElement(3,vColElm);
+
+ CJS_PropValue vProp(isolate);
+ vProp.StartGetting();
+ fTarget->textColor(cc,vProp,sError);
+
+ CJS_Array aProp(isolate);
+ vProp.ConvertToArray(aProp);
+
+ CPWL_Color crProp;
+ CPWL_Color crColor;
+ color::ConvertArrayToPWLColor(aProp, crProp);
+ color::ConvertArrayToPWLColor(arColor, crColor);
+
+ if (crColor != crProp)
+ {
+ CJS_PropValue vProp2(isolate);
+ vProp2.StartGetting();
+ vProp2<<arColor;
+ vProp2.StartSetting();
+ fTarget->textColor(cc,vProp2,sError);
+ }
+ }
+ }
+ }
+ Value = strValue2.c_str();
+#endif
+ return TRUE;
+}
+
+//function AFNumber_Keystroke(nDec, sepStyle, negStyle, currStyle, strCurrency, bCurrencyPrepend)
+FX_BOOL CJS_PublicMethods::AFNumber_Keystroke(OBJ_METHOD_PARAMS)
+{
+ CJS_Context* pContext = (CJS_Context *)cc;
+ ASSERT(pContext != NULL);
+ CJS_EventHandler* pEvent = pContext->GetEventHandler();
+ ASSERT(pEvent != NULL);
+
+ if(params.size() < 2)
+ return FALSE;
+ int iSepStyle = params[1];
+
+ if (iSepStyle < 0 || iSepStyle > 3)
+ iSepStyle = 0;
+ if(!pEvent->m_pValue)
+ return FALSE;
+ CFX_WideString & val = pEvent->Value();
+ CFX_WideString & w_strChange = pEvent->Change();
+ CFX_WideString w_strValue = val;
+
+ if (pEvent->WillCommit())
+ {
+ CFX_WideString wstrChange = w_strChange;
+ CFX_WideString wstrValue = StrLTrim(w_strValue);
+ if (wstrValue.IsEmpty())
+ return TRUE;
+
+ CFX_WideString swTemp = wstrValue;
+ swTemp.Replace((FX_LPCWSTR)L",", (FX_LPCWSTR)L".");
+ if (!IsNumber(swTemp)) //!(IsNumber(wstrChange) &&
+ {
+ pEvent->Rc() = FALSE;
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYSTROKE);
+ Alert(pContext, sError);
+ return TRUE;
+ }
+ return TRUE; // it happens after the last keystroke and before validating,
+ }
+
+ std::wstring w_strValue2 (w_strValue);
+ std::wstring w_strChange2(w_strChange);
+
+ std::wstring w_strSelected;
+ if(-1 != pEvent->SelStart())
+ w_strSelected = w_strValue2.substr(pEvent->SelStart(),(pEvent->SelEnd() - pEvent->SelStart()));
+ FX_BOOL bHasSign = (w_strValue2.find('-') != -1) && (w_strSelected.find('-') == -1);
+ if (bHasSign)
+ {
+ //can't insert "change" in front to sign postion.
+ if (pEvent->SelStart() == 0)
+ {
+ FX_BOOL &bRc = pEvent->Rc();
+ bRc = FALSE;
+ return TRUE;
+ }
+ }
+
+ char cSep = L'.';
+
+ switch (iSepStyle)
+ {
+ case 0:
+ case 1:
+ cSep = L'.';
+ break;
+ case 2:
+ case 3:
+ cSep = L',';
+ break;
+ }
+
+ FX_BOOL bHasSep = (w_strValue2.find(cSep) != -1);
+ for (std::wstring::iterator it = w_strChange2.begin(); it != w_strChange2.end(); it++)
+ {
+ if (*it == cSep)
+ {
+ if (bHasSep)
+ {
+ FX_BOOL &bRc = pEvent->Rc();
+ bRc = FALSE;
+ return TRUE;
+ }
+ else
+ {
+ bHasSep = TRUE;
+ continue;
+ }
+ }
+ if (*it == L'-')
+ {
+ if (bHasSign)
+ {
+ FX_BOOL &bRc = pEvent->Rc();
+ bRc = FALSE;
+ return TRUE;
+ }
+ else if (it != w_strChange2.begin()) //sign's position is not correct
+ {
+ FX_BOOL &bRc = pEvent->Rc();
+ bRc = FALSE;
+ return TRUE;
+ }
+ else if (pEvent->SelStart() != 0)
+ {
+ FX_BOOL &bRc = pEvent->Rc();
+ bRc = FALSE;
+ return TRUE;
+ }
+ bHasSign = TRUE;
+ continue;
+ }
+
+ if (!IsDigit(*it))
+ {
+ FX_BOOL &bRc = pEvent->Rc();
+ bRc = FALSE;
+ return TRUE;
+ }
+ }
+
+
+ std::wstring w_prefix = w_strValue2.substr(0,pEvent->SelStart());
+ std::wstring w_postfix;
+ if (pEvent->SelEnd()<(int)w_strValue2.length())
+ w_postfix = w_strValue2.substr(pEvent->SelEnd());
+ w_strValue2 = w_prefix + w_strChange2 + w_postfix;
+ w_strValue = w_strValue2.c_str();
+ val = w_strValue;
+ return TRUE;
+
+}
+
+//function AFPercent_Format(nDec, sepStyle)
+FX_BOOL CJS_PublicMethods::AFPercent_Format(OBJ_METHOD_PARAMS)
+{
+#if _FX_OS_ != _FX_ANDROID_
+ CJS_Context* pContext = (CJS_Context *)cc;
+ ASSERT(pContext != NULL);
+ CJS_EventHandler* pEvent = pContext->GetEventHandler();
+ ASSERT(pEvent != NULL);
+
+ if (params.size() != 2)
+ {
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
+ if(!pEvent->m_pValue)
+ return FALSE;
+ CFX_WideString& Value = pEvent->Value();
+
+// HWND hMainFrame = NULL;
+//
+// CPDFSDK_FormFillApp *pApp = pContext->GetReaderApp();
+// ASSERT(pApp);
+// hMainFrame = pApp->GetMainFrameWnd();
+
+ CFX_ByteString strValue = StrTrim(CFX_ByteString::FromUnicode(Value));
+
+ if (strValue.IsEmpty())
+ return TRUE;
+
+ int iDec = params[0];
+ int iSepStyle = params[1];
+
+ //ASSERT(iDec > 0);
+ if (iDec < 0)
+ iDec = -iDec;
+
+ if (iSepStyle < 0 || iSepStyle > 3)
+ iSepStyle = 0;
+
+
+ //////////////////////////////////////////////////////
+ //for processing decimal places
+ double dValue = atof(strValue);
+ dValue *= 100;
+ if (iDec > 0)
+ dValue += DOUBLE_CORRECT;//��
+
+ int iDec2;
+ FX_BOOL bNagative = FALSE;
+ strValue = fcvt(dValue,iDec,&iDec2,&bNagative);
+ if (strValue.IsEmpty())
+ {
+ dValue = 0;
+ strValue = fcvt(dValue,iDec,&iDec2,&bNagative);
+ }
+
+ if (iDec2 < 0)
+ {
+ for (int iNum = 0; iNum < abs(iDec2); iNum++)
+ {
+ strValue = "0" + strValue;
+ }
+ iDec2 = 0;
+
+ }
+ int iMax = strValue.GetLength();
+ if (iDec2 > iMax)
+ {
+ for (int iNum = 0; iNum <= iDec2 - iMax; iNum++)
+ {
+ strValue += "0";
+ }
+ iMax = iDec2+1;
+ }
+ ///////////////////////////////////////////////////////
+ //for processing seperator style
+ if (iDec2 < iMax)
+ {
+ if (iSepStyle == 0 || iSepStyle == 1)
+ {
+ strValue.Insert(iDec2, '.');
+ iMax++;
+ }
+ else if (iSepStyle == 2 || iSepStyle == 3)
+ {
+ strValue.Insert(iDec2, ',');
+ iMax++;
+ }
+
+ if (iDec2 == 0)
+ strValue.Insert(iDec2, '0');
+ }
+ if (iSepStyle == 0 || iSepStyle == 2)
+ {
+ char cSeperator;
+ if (iSepStyle == 0)
+ cSeperator = ',';
+ else
+ cSeperator = '.';
+
+ int iDecPositive,iDecNagative;
+ iDecPositive = iDec2;
+ iDecNagative = iDec2;
+
+ for (iDecPositive = iDec2 -3; iDecPositive > 0; iDecPositive -= 3)
+ {
+ strValue.Insert(iDecPositive,cSeperator);
+ iMax++;
+ }
+ }
+ ////////////////////////////////////////////////////////////////////
+ //nagative mark
+ if(bNagative)
+ strValue = "-" + strValue;
+ strValue += "%";
+ Value = CFX_WideString::FromLocal(strValue);
+#endif
+ return TRUE;
+}
+//AFPercent_Keystroke(nDec, sepStyle)
+FX_BOOL CJS_PublicMethods::AFPercent_Keystroke(OBJ_METHOD_PARAMS)
+{
+ return AFNumber_Keystroke(cc,params,vRet,sError);
+}
+
+//function AFDate_FormatEx(cFormat)
+FX_BOOL CJS_PublicMethods::AFDate_FormatEx(OBJ_METHOD_PARAMS)
+{
+ CJS_Context* pContext = (CJS_Context *)cc;
+ ASSERT(pContext != NULL);
+ CJS_EventHandler* pEvent = pContext->GetEventHandler();
+ ASSERT(pEvent != NULL);
+
+ if (params.size() != 1)
+ {
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
+ if(!pEvent->m_pValue)
+ return FALSE;
+ CFX_WideString& val = pEvent->Value();
+
+ CFX_WideString strValue = val;
+ if (strValue.IsEmpty()) return TRUE;
+
+ CFX_WideString sFormat = params[0].operator CFX_WideString();
+
+ FX_BOOL bWrongFormat = FALSE;
+ double dDate = 0.0f;
+
+ if(strValue.Find(L"GMT") != -1)
+ {
+ //for GMT format time
+ //such as "Tue Aug 11 14:24:16 GMT+08002009"
+ dDate = MakeInterDate(strValue);
+ }
+ else
+ {
+ dDate = MakeRegularDate(strValue,sFormat,bWrongFormat);
+ }
+
+ if (JS_PortIsNan(dDate))
+ {
+ CFX_WideString swMsg;
+ swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE), (FX_LPCWSTR)sFormat);
+ Alert(pContext, swMsg);
+ return FALSE;
+ }
+
+ val = MakeFormatDate(dDate,sFormat);
+
+ return TRUE;
+}
+
+double CJS_PublicMethods::MakeInterDate(CFX_WideString strValue)
+{
+ int nHour;
+ int nMin;
+ int nSec;
+ int nYear;
+ int nMonth;
+ int nDay;
+
+ CFX_WideStringArray wsArray;
+ CFX_WideString sMonth = L"";
+ CFX_WideString sTemp = L"";
+ int nSize = strValue.GetLength();
+
+ for(int i = 0; i < nSize; i++)
+ {
+ FX_WCHAR c = strValue.GetAt(i);
+ if(c == L' ' || c == L':')
+ {
+ wsArray.Add(sTemp);
+ sTemp = L"";
+ continue;
+ }
+
+ sTemp += c;
+ }
+
+ wsArray.Add(sTemp);
+ if(wsArray.GetSize() != 8)return 0;
+
+ sTemp = wsArray[1];
+ if(sTemp.Compare(L"Jan") == 0) nMonth = 1;
+ if(sTemp.Compare(L"Feb") == 0) nMonth = 2;
+ if(sTemp.Compare(L"Mar") == 0) nMonth = 3;
+ if(sTemp.Compare(L"Apr") == 0) nMonth = 4;
+ if(sTemp.Compare(L"May") == 0) nMonth = 5;
+ if(sTemp.Compare(L"Jun") == 0) nMonth = 6;
+ if(sTemp.Compare(L"Jul") == 0) nMonth = 7;
+ if(sTemp.Compare(L"Aug") == 0) nMonth = 8;
+ if(sTemp.Compare(L"Sep") == 0) nMonth = 9;
+ if(sTemp.Compare(L"Oct") == 0) nMonth = 10;
+ if(sTemp.Compare(L"Nov") == 0) nMonth = 11;
+ if(sTemp.Compare(L"Dec") == 0) nMonth = 12;
+
+ nDay = (int)ParseStringToNumber(wsArray[2]);
+ nHour = (int)ParseStringToNumber(wsArray[3]);
+ nMin = (int)ParseStringToNumber(wsArray[4]);
+ nSec = (int)ParseStringToNumber(wsArray[5]);
+ nYear = (int)ParseStringToNumber(wsArray[7]);
+
+ double dRet = JS_MakeDate(JS_MakeDay(nYear,nMonth - 1,nDay),JS_MakeTime(nHour, nMin, nSec, 0));
+
+ if (JS_PortIsNan(dRet))
+ {
+ dRet = JS_DateParse(strValue);
+ }
+
+ return dRet;
+}
+
+//AFDate_KeystrokeEx(cFormat)
+FX_BOOL CJS_PublicMethods::AFDate_KeystrokeEx(OBJ_METHOD_PARAMS)
+{
+ CJS_Context* pContext = (CJS_Context *)cc;
+ ASSERT(pContext != NULL);
+ CJS_EventHandler* pEvent = pContext->GetEventHandler();
+ ASSERT(pEvent != NULL);
+
+ if (params.size() != 1)
+ {
+ sError = L"AFDate_KeystrokeEx's parameters' size r not correct";
+ return FALSE;
+ }
+
+ if (pEvent->WillCommit())
+ {
+ if(!pEvent->m_pValue)
+ return FALSE;
+ CFX_WideString strValue = pEvent->Value();
+ if (strValue.IsEmpty()) return TRUE;
+
+ CFX_WideString sFormat = params[0].operator CFX_WideString();
+
+ FX_BOOL bWrongFormat = FALSE;
+ double dRet = MakeRegularDate(strValue,sFormat,bWrongFormat);
+ if (bWrongFormat || JS_PortIsNan(dRet))
+ {
+ CFX_WideString swMsg;
+ swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE), (FX_LPCWSTR)sFormat);
+ Alert(pContext, swMsg);
+ pEvent->Rc() = FALSE;
+ return TRUE;
+ }
+ }
+ return TRUE;
+}
+
+FX_BOOL CJS_PublicMethods::AFDate_Format(OBJ_METHOD_PARAMS)
+{
+ v8::Isolate* isolate = ::GetIsolate(cc);
+
+ if (params.size() != 1)
+ {
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
+
+ int iIndex = params[0];
+ 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",
+ (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",
+ (FX_LPCWSTR)L"m/d/yy h:MM tt", (FX_LPCWSTR)L"m/d/yy HH:MM" };
+
+ ASSERT(iIndex < sizeof(cFormats)/sizeof(FX_LPCWSTR));
+
+ if (iIndex < 0)
+ iIndex = 0;
+ if (iIndex >= sizeof(cFormats)/sizeof(FX_LPCWSTR))
+ iIndex = 0;
+ CJS_Parameters newParams;
+ CJS_Value val(isolate,cFormats[iIndex]);
+ newParams.push_back(val);
+ return AFDate_FormatEx(cc,newParams,vRet,sError);
+}
+
+//AFDate_KeystrokeEx(cFormat)
+FX_BOOL CJS_PublicMethods::AFDate_Keystroke(OBJ_METHOD_PARAMS)
+{
+ v8::Isolate* isolate = ::GetIsolate(cc);
+
+ if (params.size() != 1)
+ {
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
+
+ int iIndex = params[0];
+ 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",
+ (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",
+ (FX_LPCWSTR)L"m/d/yy h:MM tt", (FX_LPCWSTR)L"m/d/yy HH:MM" };
+
+ ASSERT(iIndex<sizeof(cFormats)/sizeof(FX_LPCWSTR));
+
+ if (iIndex < 0)
+ iIndex = 0;
+ if (iIndex >= sizeof(cFormats)/sizeof(FX_LPCWSTR))
+ iIndex = 0;
+ CJS_Parameters newParams;
+ CJS_Value val(isolate,cFormats[iIndex]);
+ newParams.push_back(val);
+ return AFDate_KeystrokeEx(cc,newParams,vRet,sError);
+}
+
+//function AFTime_Format(ptf)
+FX_BOOL CJS_PublicMethods::AFTime_Format(OBJ_METHOD_PARAMS)
+{
+ v8::Isolate* isolate = ::GetIsolate(cc);
+
+ if (params.size() != 1)
+ {
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
+
+ int iIndex = params[0];
+ 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"};
+
+ ASSERT(iIndex<sizeof(cFormats)/sizeof(FX_LPCWSTR));
+
+ if (iIndex < 0)
+ iIndex = 0;
+ if (iIndex >= sizeof(cFormats)/sizeof(FX_LPCWSTR))
+ iIndex = 0;
+ CJS_Parameters newParams;
+ CJS_Value val(isolate,cFormats[iIndex]);
+ newParams.push_back(val);
+ return AFDate_FormatEx(cc,newParams,vRet,sError);
+}
+
+FX_BOOL CJS_PublicMethods::AFTime_Keystroke(OBJ_METHOD_PARAMS)
+{
+ v8::Isolate* isolate = ::GetIsolate(cc);
+ if (params.size() != 1)
+ {
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
+
+ int iIndex = params[0];
+ 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"};
+
+ ASSERT(iIndex<sizeof(cFormats)/sizeof(FX_LPCWSTR));
+
+ if (iIndex < 0)
+ iIndex = 0;
+ if (iIndex >= sizeof(cFormats)/sizeof(FX_LPCWSTR))
+ iIndex = 0;
+ CJS_Parameters newParams;
+ CJS_Value val(isolate,cFormats[iIndex]);
+ newParams.push_back(val);
+ return AFDate_KeystrokeEx(cc,newParams,vRet,sError);
+}
+
+FX_BOOL CJS_PublicMethods::AFTime_FormatEx(OBJ_METHOD_PARAMS)
+{
+ return AFDate_FormatEx(cc,params,vRet,sError);
+}
+
+FX_BOOL CJS_PublicMethods::AFTime_KeystrokeEx(OBJ_METHOD_PARAMS)
+{
+ return AFDate_KeystrokeEx(cc,params,vRet,sError);
+}
+
+//function AFSpecial_Format(psf)
+FX_BOOL CJS_PublicMethods::AFSpecial_Format(OBJ_METHOD_PARAMS)
+{
+ CJS_Context* pContext = (CJS_Context *)cc;
+ ASSERT(pContext != NULL);
+
+ if (params.size() != 1)
+ {
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
+
+ std::string cFormat;
+ int iIndex = params[0];
+
+ CJS_EventHandler* pEvent = pContext->GetEventHandler();
+ ASSERT(pEvent != NULL);
+
+ if(!pEvent->m_pValue)
+ return FALSE;
+ CFX_WideString& Value = pEvent->Value();
+ std::string strSrc = (FX_LPCSTR)CFX_ByteString::FromUnicode(Value);
+
+ switch (iIndex)
+ {
+ case 0:
+ cFormat = "99999";
+ break;
+ case 1:
+ cFormat = "99999-9999";
+ break;
+ case 2:
+ {
+ std::string NumberStr;
+ util::printx("9999999999", strSrc,NumberStr);
+ if (NumberStr.length() >= 10 )
+ cFormat = "(999) 999-9999";
+ else
+ cFormat = "999-9999";
+ break;
+ }
+ case 3:
+ cFormat = "999-99-9999";
+ break;
+ }
+
+ std::string strDes;
+ util::printx(cFormat,strSrc,strDes);
+ Value = CFX_WideString::FromLocal(strDes.c_str());
+ return TRUE;
+}
+
+
+//function AFSpecial_KeystrokeEx(mask)
+FX_BOOL CJS_PublicMethods::AFSpecial_KeystrokeEx(OBJ_METHOD_PARAMS)
+{
+ CJS_Context* pContext = (CJS_Context *)cc;
+ ASSERT(pContext != NULL);
+ CJS_EventHandler* pEvent = pContext->GetEventHandler();
+
+ ASSERT(pEvent != NULL);
+
+ if (params.size() < 1)
+ {
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
+
+ if(!pEvent->m_pValue)
+ return FALSE;
+ CFX_WideString& valEvent = pEvent->Value();
+
+ CFX_WideString wstrMask = params[0].operator CFX_WideString();
+ if (wstrMask.IsEmpty()) return TRUE;
+
+ std::wstring wstrValue(valEvent);
+
+ if (pEvent->WillCommit())
+ {
+ if (wstrValue.empty())
+ return TRUE;
+ int iIndexMask = 0;
+ for (std::wstring::iterator it = wstrValue.begin(); it != wstrValue.end(); it++)
+ {
+ wchar_t w_Value = *it;
+ if (!maskSatisfied(w_Value,wstrMask[iIndexMask]))
+ break;
+ iIndexMask++;
+ }
+
+ if (iIndexMask != wstrMask.GetLength() || (iIndexMask != wstrValue.size() && wstrMask.GetLength() != 0))
+ {
+ Alert(pContext, JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYSTROKE));
+ pEvent->Rc() = FALSE;
+ }
+ return TRUE;
+ }
+
+
+ CFX_WideString &wideChange = pEvent->Change();
+ std::wstring wChange(wideChange);
+
+ if (wChange.empty())
+ return TRUE;
+ int iIndexMask = pEvent->SelStart();
+ //iIndexMask++;
+
+
+ if (wstrValue.length() - (pEvent->SelEnd()-pEvent->SelStart()) + wChange.length() > (FX_DWORD)wstrMask.GetLength())
+ {
+ Alert(pContext, JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG));
+ pEvent->Rc() = FALSE;
+ return TRUE;
+ }
+
+
+ if (iIndexMask >= wstrMask.GetLength() && (!wChange.empty()))
+ {
+ Alert(pContext, JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG));
+ pEvent->Rc() = FALSE;
+ return TRUE;
+ }
+
+ for (std::wstring::iterator it = wChange.begin(); it != wChange.end(); it++)
+ {
+ if (iIndexMask >= wstrMask.GetLength())
+ {
+ Alert(pContext, JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG));
+ pEvent->Rc() = FALSE;
+ return TRUE;
+ }
+ wchar_t w_Mask = wstrMask[iIndexMask];
+ if (!isReservedMaskChar(w_Mask))
+ {
+ //wChange.insert(it,w_Mask);
+ *it = w_Mask;
+ }
+ wchar_t w_Change = *it;
+
+ if (!maskSatisfied(w_Change,w_Mask))
+ {
+ pEvent->Rc() = FALSE;
+ return TRUE;
+ }
+ iIndexMask++;
+ }
+
+ wideChange = wChange.c_str();
+
+ return TRUE;
+}
+
+
+//function AFSpecial_Keystroke(psf)
+FX_BOOL CJS_PublicMethods::AFSpecial_Keystroke(OBJ_METHOD_PARAMS)
+{
+ v8::Isolate* isolate = ::GetIsolate(cc);
+
+ CJS_Context* pContext = (CJS_Context *)cc;
+ ASSERT(pContext != NULL);
+ CJS_EventHandler* pEvent = pContext->GetEventHandler();
+ ASSERT(pEvent != NULL);
+
+ if (params.size() != 1)
+ {
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
+
+ std::string cFormat;
+ int iIndex = (int)params[0];
+
+ if(!pEvent->m_pValue)
+ return FALSE;
+ //CJS_Value val = pEvent->Value();
+ CFX_WideString& val = pEvent->Value();
+ std::string strSrc = (FX_LPCSTR)CFX_ByteString::FromUnicode(val);
+ std::wstring wstrChange(pEvent->Change());
+
+ switch (iIndex)
+ {
+ case 0:
+ cFormat = "99999";
+ break;
+ case 1:
+ //cFormat = "99999-9999";
+ cFormat = "999999999";
+ break;
+ case 2:
+ {
+ std::string NumberStr;
+ util::printx("9999999999", strSrc,NumberStr);
+ if (strSrc.length() + wstrChange.length() > 7 )
+ //cFormat = "(999) 999-9999";
+ cFormat = "9999999999";
+ else
+ //cFormat = "999-9999";
+ cFormat = "9999999";
+ break;
+ }
+ case 3:
+ //cFormat = "999-99-9999";
+ cFormat = "999999999";
+ break;
+ }
+
+ CJS_Parameters params2;
+ CJS_Value vMask(isolate, cFormat.c_str());
+ params2.push_back(vMask);
+
+ return AFSpecial_KeystrokeEx(cc,params2,vRet,sError);
+}
+
+FX_BOOL CJS_PublicMethods::AFMergeChange(OBJ_METHOD_PARAMS)
+{
+ CJS_Context* pContext = (CJS_Context *)cc;
+ ASSERT(pContext != NULL);
+ CJS_EventHandler* pEventHandler = pContext->GetEventHandler();
+ ASSERT(pEventHandler != NULL);
+
+ if (params.size() != 1)
+ {
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
+
+ CFX_WideString swValue;
+ if (pEventHandler->m_pValue != NULL)
+ swValue = pEventHandler->Value();
+
+ if (pEventHandler->WillCommit())
+ {
+ vRet = swValue;
+ return TRUE;
+ }
+
+ CFX_WideString prefix,postfix;
+
+ if (pEventHandler->SelStart() >= 0)
+ prefix = swValue.Mid(0,pEventHandler->SelStart());
+ else
+ prefix = L"";
+
+
+ if (pEventHandler->SelEnd() >= 0 && pEventHandler->SelEnd() <= swValue.GetLength())
+ postfix = swValue.Mid(pEventHandler->SelEnd(), swValue.GetLength() - pEventHandler->SelEnd());
+ else postfix = L"";
+
+ vRet = prefix + pEventHandler->Change() + postfix;
+
+ return TRUE;
+}
+
+FX_BOOL CJS_PublicMethods::AFParseDateEx(OBJ_METHOD_PARAMS)
+{
+ CJS_Context* pContext = (CJS_Context *)cc;
+ ASSERT(pContext != NULL);
+
+ if (params.size() != 2)
+ {
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
+
+ CFX_WideString sValue = params[0].operator CFX_WideString();
+ CFX_WideString sFormat = params[1].operator CFX_WideString();
+
+ FX_BOOL bWrongFormat = FALSE;
+ double dDate = MakeRegularDate(sValue,sFormat,bWrongFormat);
+
+ if (JS_PortIsNan(dDate))
+ {
+ CFX_WideString swMsg;
+ swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE), (FX_LPCWSTR)sFormat);
+ Alert((CJS_Context *)cc, swMsg);
+ return FALSE;
+ }
+
+ vRet = dDate;
+
+ return TRUE;
+}
+
+FX_BOOL CJS_PublicMethods::AFSimple(OBJ_METHOD_PARAMS)
+{
+ if (params.size() != 3)
+ {
+ CJS_Context* pContext = (CJS_Context *)cc;
+ ASSERT(pContext != NULL);
+
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
+
+ vRet = (double)AF_Simple(params[0].operator CFX_WideString(), (double)params[1], (double)params[2]);
+ return TRUE;
+}
+
+FX_BOOL CJS_PublicMethods::AFMakeNumber(OBJ_METHOD_PARAMS)
+{
+ if (params.size() != 1)
+ {
+ CJS_Context* pContext = (CJS_Context *)cc;
+ ASSERT(pContext != NULL);
+
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
+ vRet = ParseStringToNumber(params[0].operator CFX_WideString());
+ return TRUE;
+}
+
+FX_BOOL CJS_PublicMethods::AFSimple_Calculate(OBJ_METHOD_PARAMS)
+{
+ v8::Isolate* isolate = ::GetIsolate(cc);
+
+ CJS_Context* pContext = (CJS_Context *)cc;
+ ASSERT(pContext != NULL);
+
+ if (params.size() != 2)
+ {
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
+
+ CJS_Value params1 = params[1];
+
+ if (!params1.IsArrayObject() && params1.GetType() != VT_string)
+ {
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
+
+ CPDFSDK_Document* pReaderDoc = pContext->GetReaderDocument();
+ ASSERT(pReaderDoc != NULL);
+
+ CPDFSDK_InterForm* pReaderInterForm = pReaderDoc->GetInterForm();
+ ASSERT(pReaderInterForm != NULL);
+
+ CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ double dValue;
+ CFX_WideString sFunction = params[0].operator CFX_WideString();
+ if (wcscmp(sFunction, L"PRD") == 0)
+ dValue = 1.0;
+ else
+ dValue = 0.0;
+
+ CJS_Array FieldNameArray = AF_MakeArrayFromList(isolate,params1);
+
+ int nFieldsCount = 0;
+
+ for (int i=0,isz=FieldNameArray.GetLength(); i<isz; i++)
+ {
+ CJS_Value jsValue(isolate);
+ FieldNameArray.GetElement(i,jsValue);
+ CFX_WideString wsFieldName = jsValue.operator CFX_WideString();
+
+ for (int j=0,jsz=pInterForm->CountFields(wsFieldName); j<jsz; j++)
+ {
+ if (CPDF_FormField* pFormField = pInterForm->GetField(j, wsFieldName))
+ {
+ double dTemp = 0.0;
+
+ switch (pFormField->GetFieldType())
+ {
+ case FIELDTYPE_TEXTFIELD:
+ case FIELDTYPE_COMBOBOX:
+ {
+ dTemp = ParseStringToNumber(pFormField->GetValue());
+ break;
+ }
+ case FIELDTYPE_PUSHBUTTON:
+ {
+ dTemp = 0.0;
+ break;
+ }
+ case FIELDTYPE_CHECKBOX:
+ case FIELDTYPE_RADIOBUTTON:
+ {
+ dTemp = 0.0;
+ for (int c=0,csz=pFormField->CountControls(); c<csz; c++)
+ {
+ if (CPDF_FormControl* pFormCtrl = pFormField->GetControl(c))
+ {
+ if (pFormCtrl->IsChecked())
+ {
+ dTemp += ParseStringToNumber(pFormCtrl->GetExportValue());
+ break;
+ }
+ else
+ continue;
+ }
+ }
+ break;
+ }
+ case FIELDTYPE_LISTBOX:
+ {
+ dTemp = 0.0;
+ if (pFormField->CountSelectedItems() > 1)
+ break;
+ else
+ {
+ dTemp = ParseStringToNumber(pFormField->GetValue());
+ break;
+ }
+ }
+ default:
+ break;
+ }
+
+ if (i == 0 && j == 0 && (wcscmp(sFunction,L"MIN") == 0 || wcscmp(sFunction, L"MAX") == 0))
+ dValue = dTemp;
+
+ dValue = AF_Simple(sFunction, dValue, dTemp);
+
+ nFieldsCount++;
+ }
+ }
+ }
+
+ if (wcscmp(sFunction, L"AVG") == 0 && nFieldsCount > 0)
+ dValue /= nFieldsCount;
+
+ dValue = (double)floor(dValue * FXSYS_pow((double)10,(double)6) + 0.49) / FXSYS_pow((double)10,(double)6);
+ CJS_Value jsValue(isolate,dValue);
+ if((CJS_EventHandler*)pContext->GetEventHandler()->m_pValue)
+ ((CJS_EventHandler*)pContext->GetEventHandler())->Value() = jsValue;
+
+ return TRUE;
+}
+
+/* This function validates the current event to ensure that its value is
+** within the specified range. */
+
+FX_BOOL CJS_PublicMethods::AFRange_Validate(OBJ_METHOD_PARAMS)
+{
+ CJS_Context* pContext = (CJS_Context *)cc;
+ ASSERT(pContext != NULL);
+ CJS_EventHandler* pEvent = pContext->GetEventHandler();
+ ASSERT(pEvent != NULL);
+
+ if (params.size() != 4)
+ {
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
+
+ if(!pEvent->m_pValue)
+ return FALSE;
+ if (pEvent->Value().IsEmpty() )
+ return TRUE;
+ double dEentValue = atof(CFX_ByteString::FromUnicode(pEvent->Value()));
+ FX_BOOL bGreaterThan, bLessThan;
+ double dGreaterThan, dLessThan;
+ bGreaterThan = (FX_BOOL)params[0];
+ CFX_WideString swMsg;
+ dGreaterThan = (double)params[1];
+ bLessThan = (FX_BOOL)params[2];
+ dLessThan = (double)params[3];
+
+ if (bGreaterThan && bLessThan)
+ {
+ if (dEentValue < dGreaterThan || dEentValue > dLessThan)
+ swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE1),(FX_LPCWSTR)params[1].operator CFX_WideString(), (FX_LPCWSTR)params[3].operator CFX_WideString());
+ }
+ else if (bGreaterThan)
+ {
+ if (dEentValue < dGreaterThan)
+ swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE2), (FX_LPCWSTR)params[1].operator CFX_WideString());
+ }
+ else if (bLessThan)
+ {
+ if (dEentValue > dLessThan)
+ swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE3), (FX_LPCWSTR)params[3].operator CFX_WideString());
+ }
+
+ if (!swMsg.IsEmpty())
+ {
+ Alert(pContext, swMsg);
+ pEvent->Rc() = FALSE;
+ }
+ return TRUE;
+}
+
+FX_BOOL CJS_PublicMethods::AFExtractNums(OBJ_METHOD_PARAMS)
+{
+ v8::Isolate* isolate = ::GetIsolate(cc);
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+
+ if (params.size() != 1)
+ {
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
+
+ CJS_Array nums(isolate);
+
+ CFX_WideString str = params[0].operator CFX_WideString();
+ CFX_WideString sPart;
+
+ if (str.GetAt(0) == L'.' || str.GetAt(0) == L',')
+ str = L"0" + str;
+
+ int nIndex = 0;
+ for (int i=0, sz=str.GetLength(); i<sz; i++)
+ {
+ FX_WCHAR wc = str.GetAt(i);
+ if (IsDigit((wchar_t)wc))
+ {
+ sPart += wc;
+ }
+ else
+ {
+ if (sPart.GetLength() > 0)
+ {
+ nums.SetElement(nIndex,CJS_Value(isolate,(FX_LPCWSTR)sPart));
+ sPart = L"";
+ nIndex ++;
+ }
+ }
+ }
+
+ if (sPart.GetLength() > 0)
+ {
+ nums.SetElement(nIndex,CJS_Value(isolate,(FX_LPCWSTR)sPart));
+ }
+
+ if (nums.GetLength() > 0)
+ vRet = nums;
+ else
+ vRet.SetNull();
+
+ return TRUE;
+}
diff --git a/fpdfsdk/src/javascript/app.cpp b/fpdfsdk/src/javascript/app.cpp
index c1ef76c3b8..a3e61c01ab 100644
--- a/fpdfsdk/src/javascript/app.cpp
+++ b/fpdfsdk/src/javascript/app.cpp
@@ -1,1134 +1,1134 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/javascript/JavaScript.h"
-#include "../../include/javascript/IJavaScript.h"
-#include "../../include/javascript/JS_Define.h"
-#include "../../include/javascript/JS_Object.h"
-#include "../../include/javascript/JS_Value.h"
-#include "../../include/javascript/app.h"
-#include "../../include/javascript/JS_EventHandler.h"
-#include "../../include/javascript/resource.h"
-#include "../../include/javascript/JS_Context.h"
-#include "../../include/javascript/JS_Runtime.h"
-#include "../../include/javascript/Document.h"
-
-
-static v8::Isolate* GetIsolate(IFXJS_Context* cc)
-{
- CJS_Context* pContext = (CJS_Context *)cc;
- ASSERT(pContext != NULL);
-
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
-
- return pRuntime->GetIsolate();
-}
-
-/* ---------------------------- TimerObj ---------------------------- */
-
-BEGIN_JS_STATIC_CONST(CJS_TimerObj)
-END_JS_STATIC_CONST()
-
-BEGIN_JS_STATIC_PROP(CJS_TimerObj)
-END_JS_STATIC_PROP()
-
-BEGIN_JS_STATIC_METHOD(CJS_TimerObj)
-END_JS_STATIC_METHOD()
-
-IMPLEMENT_JS_CLASS(CJS_TimerObj, TimerObj)
-
-TimerObj::TimerObj(CJS_Object* pJSObject)
-: CJS_EmbedObj(pJSObject),
-m_pTimer(NULL)
-{
-
-}
-
-TimerObj::~TimerObj()
-{
-}
-
-void TimerObj::SetTimer(CJS_Timer* pTimer)
-{
- m_pTimer = pTimer;
-}
-
-CJS_Timer* TimerObj::GetTimer() const
-{
- return m_pTimer;
-}
-
-#define JS_STR_VIEWERTYPE_READER L"Reader"
-#define JS_STR_VIEWERTYPE_STANDARD L"Exchange"
-#define JS_STR_VIEWERVARIATION L"Full"
-#define JS_STR_PLATFORM L"WIN"
-#define JS_STR_LANGUANGE L"ENU"
-#define JS_STR_VIEWERVERSION 8
-#define JS_NUM_FORMSVERSION 7
-
-#define JS_FILEPATH_MAXLEN 2000
-
-/* ---------------------------- app ---------------------------- */
-
-BEGIN_JS_STATIC_CONST(CJS_App)
-END_JS_STATIC_CONST()
-
-BEGIN_JS_STATIC_PROP(CJS_App)
- JS_STATIC_PROP_ENTRY(activeDocs)
- JS_STATIC_PROP_ENTRY(calculate)
- JS_STATIC_PROP_ENTRY(formsVersion)
- JS_STATIC_PROP_ENTRY(fs)
- JS_STATIC_PROP_ENTRY(fullscreen)
- JS_STATIC_PROP_ENTRY(language)
- JS_STATIC_PROP_ENTRY(media)
- JS_STATIC_PROP_ENTRY(platform)
- JS_STATIC_PROP_ENTRY(runtimeHighlight)
- JS_STATIC_PROP_ENTRY(viewerType)
- JS_STATIC_PROP_ENTRY(viewerVariation)
- JS_STATIC_PROP_ENTRY(viewerVersion)
-END_JS_STATIC_PROP()
-
-BEGIN_JS_STATIC_METHOD(CJS_App)
- JS_STATIC_METHOD_ENTRY(alert, 6)
- JS_STATIC_METHOD_ENTRY(beep, 1)
- JS_STATIC_METHOD_ENTRY(browseForDoc, 0)
- JS_STATIC_METHOD_ENTRY(clearInterval, 1)
- JS_STATIC_METHOD_ENTRY(clearTimeOut, 1)
- JS_STATIC_METHOD_ENTRY(execDialog, 3)
- JS_STATIC_METHOD_ENTRY(execMenuItem, 1)
- JS_STATIC_METHOD_ENTRY(findComponent, 1)
- JS_STATIC_METHOD_ENTRY(goBack, 0)
- JS_STATIC_METHOD_ENTRY(goForward, 0)
- JS_STATIC_METHOD_ENTRY(launchURL, 0)
- JS_STATIC_METHOD_ENTRY(mailMsg, 0)
- JS_STATIC_METHOD_ENTRY(newFDF, 0)
- JS_STATIC_METHOD_ENTRY(newDoc, 0)
- JS_STATIC_METHOD_ENTRY(openDoc, 0)
- JS_STATIC_METHOD_ENTRY(openFDF, 5)
- JS_STATIC_METHOD_ENTRY(popUpMenuEx, 0)
- JS_STATIC_METHOD_ENTRY(popUpMenu, 0)
- JS_STATIC_METHOD_ENTRY(response, 0)
- JS_STATIC_METHOD_ENTRY(setInterval, 2)
- JS_STATIC_METHOD_ENTRY(setTimeOut, 2)
-END_JS_STATIC_METHOD()
-
-IMPLEMENT_JS_CLASS(CJS_App,app)
-
-app::app(CJS_Object * pJSObject) : CJS_EmbedObj(pJSObject) ,
- m_bCalculate(true),
- m_pRuntime(NULL),
- m_bRuntimeHighLight(false)
-// m_pMenuHead(NULL)
-{
-}
-
-app::~app(void)
-{
- for (int i=0,sz=m_aTimer.GetSize(); i<sz; i++)
- delete m_aTimer[i];
-
- m_aTimer.RemoveAll();
-}
-
-FX_BOOL app::activeDocs(OBJ_PROP_PARAMS)
-{
- if (vp.IsGetting())
- {
-
- CJS_Context* pContext = (CJS_Context *)cc;
- ASSERT(pContext != NULL);
-
- CPDFDoc_Environment* pApp = pContext->GetReaderApp();
- ASSERT(pApp != NULL);
-
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
-
- CPDFSDK_Document* pCurDoc = pContext->GetReaderDocument();
-
- CJS_Array aDocs(pRuntime->GetIsolate());
-// int iNumDocs = pApp->CountDocuments();
-
-// for(int iIndex = 0; iIndex<iNumDocs; iIndex++)
-// {
- CPDFSDK_Document* pDoc = pApp->GetCurrentDoc();
- if (pDoc)
- {
- CJS_Document * pJSDocument = NULL;
-
- if (pDoc == pCurDoc)
- {
- JSFXObject pObj = JS_GetThisObj(*pRuntime);
-
- if (JS_GetObjDefnID(pObj) == JS_GetObjDefnID(*pRuntime, L"Document"))
- {
- pJSDocument = (CJS_Document*)JS_GetPrivate(pRuntime->GetIsolate(),pObj);
- }
- }
- else
- {
- JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime,L"Document"));
- pJSDocument = (CJS_Document*)JS_GetPrivate(pRuntime->GetIsolate(),pObj);
- ASSERT(pJSDocument != NULL);
-
-
- // pDocument->AttachDoc(pDoc);
- }
-
- aDocs.SetElement(0,CJS_Value(pRuntime->GetIsolate(),pJSDocument));
- }
- // }
-
- if (aDocs.GetLength() > 0)
- vp << aDocs;
- else
- vp.SetNull();
- return TRUE;
- }
- return FALSE;
-}
-
-FX_BOOL app::calculate(OBJ_PROP_PARAMS)
-{
- if (vp.IsSetting())
- {
- bool bVP;
- vp >> bVP;
- m_bCalculate = (FX_BOOL)bVP;
-
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
-
- CPDFDoc_Environment* pApp = pContext->GetReaderApp();
- ASSERT(pApp != NULL);
-
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
-
- CJS_Array aDocs(pRuntime->GetIsolate());
-// int iNumDocs = pApp->CountDocuments();
-//
-// for (int iIndex = 0;iIndex < iNumDocs; iIndex++)
-// {
- if (CPDFSDK_Document* pDoc = pApp->GetCurrentDoc())
- {
- CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDoc->GetInterForm();
- ASSERT(pInterForm != NULL);
- pInterForm->EnableCalculate((FX_BOOL)m_bCalculate);
- }
-// }
- }
- else
- {
- vp << (bool)m_bCalculate;
- }
-
- return TRUE;
-}
-
-FX_BOOL app::formsVersion(OBJ_PROP_PARAMS)
-{
- if (vp.IsGetting())
- {
- vp << JS_NUM_FORMSVERSION;
- return TRUE;
- }
-
- return FALSE;
-}
-
-FX_BOOL app::viewerType(OBJ_PROP_PARAMS)
-{
-
-
-
-
-
-
- if (vp.IsGetting())
- {
-// if (pApp->GetAppName() == PHANTOM)
-// vp << JS_STR_VIEWERTYPE_STANDARD;
-// else
-// vp << JS_STR_VIEWERTYPE_READER;
- vp << L"unknown";
-
- //vp << pApp->GetAppTitle();
- return TRUE;
- }
-
- return FALSE;
-}
-
-FX_BOOL app::viewerVariation(OBJ_PROP_PARAMS)
-{
- if (vp.IsGetting())
- {
- vp << JS_STR_VIEWERVARIATION;
- return TRUE;
- }
-
- return FALSE;
-}
-
-FX_BOOL app::viewerVersion(OBJ_PROP_PARAMS)
-{
- if (vp.IsGetting())
- {
- vp << JS_STR_VIEWERVERSION;
- return TRUE;
- }
-
- return FALSE;
-}
-
-FX_BOOL app::platform(OBJ_PROP_PARAMS)
-{
- if (vp.IsGetting())
- {
- vp << JS_STR_PLATFORM;
- return TRUE;
- }
-
- return FALSE;
-}
-
-FX_BOOL app::language(OBJ_PROP_PARAMS)
-{
- if (vp.IsGetting())
- {
- vp << JS_STR_LANGUANGE;
- return TRUE;
- }
-
- return FALSE;
-}
-
-//creates a new fdf object that contains no data
-//comment: need reader support
-//note:
-//CFDF_Document * CPDFDoc_Environment::NewFDF();
-FX_BOOL app::newFDF(OBJ_METHOD_PARAMS)
-{
- return TRUE;
-}
-//opens a specified pdf document and returns its document object
-//comment:need reader support
-//note: as defined in js reference, the proto of this function's fourth parmeters, how old an fdf document while do not show it.
-//CFDF_Document * CPDFDoc_Environment::OpenFDF(string strPath,bool bUserConv);
-
-FX_BOOL app::openFDF(OBJ_METHOD_PARAMS)
-{
- return TRUE;
-}
-
-FX_BOOL app::alert(OBJ_METHOD_PARAMS)
-{
- int iSize = params.size();
- if (iSize < 1)
- return FALSE;
-
- CFX_WideString swMsg = L"";
- CFX_WideString swTitle = L"";
- int iIcon = 0;
- int iType = 0;
-
- v8::Isolate* isolate = GetIsolate(cc);
-
- if (iSize == 1)
- {
- if (params[0].GetType() == VT_object)
- {
- JSObject pObj = params[0];
- {
- v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate, pObj, L"cMsg");
- swMsg = CJS_Value(isolate,pValue,VT_unknown).operator CFX_WideString();
-
- pValue = JS_GetObjectElement(isolate,pObj,L"cTitle");
- swTitle = CJS_Value(isolate, pValue,VT_unknown).operator CFX_WideString();
-
- pValue = JS_GetObjectElement(isolate,pObj,L"nIcon");
- iIcon = (int)CJS_Value(isolate,pValue,VT_unknown);
-
- pValue = JS_GetObjectElement(isolate,pObj,L"nType");
- iType = (int)CJS_Value(isolate,pValue,VT_unknown);
- }
-
- if (swMsg == L"")
- {
- CJS_Array carray(isolate);
- if (params[0].ConvertToArray(carray))
- {
- int iLenth = carray.GetLength();
- CJS_Value* pValue = new CJS_Value(isolate);
-// if (iLenth == 1)
-// pValue = new CJS_Value(isolate);
-// else if (iLenth > 1)
-// pValue = new CJS_Value[iLenth];
-
- for(int i = 0; i < iLenth; i++)
- {
- carray.GetElement(i, *pValue);
- swMsg += (*pValue).operator CFX_WideString();
- if (i < iLenth - 1)
- swMsg += L", ";
- }
-
- if(pValue) delete pValue;
-// if ((iLenth > 1) && pValue)
-// {
-// delete[]pValue;
-// pValue = NULL;
-// }
-// else if ((iLenth == 1) && pValue)
-// {
-// delete pValue;
-// pValue = NULL;
-// }
- }
- }
-
- if (swTitle == L"")
- swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSALERT);
- }
- else if (params[0].GetType() == VT_boolean)
- {
- FX_BOOL bGet = (FX_BOOL)params[0];
- if (bGet)
- swMsg = L"true";
- else
- swMsg = L"false";
-
- swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSALERT);
- }
- else
- {
- swMsg = params[0];
- swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSALERT);
- }
- }
- else
- {
- if (params[0].GetType() == VT_boolean)
- {
- FX_BOOL bGet = (FX_BOOL)params[0];
- if (bGet)
- swMsg = L"true";
- else
- swMsg = L"false";
- }
- else
- {
- swMsg = params[0];
- }
- swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSALERT);
-
- for(int i = 1;i<iSize;i++)
- {
- if (i == 1)
- iIcon = int(params[i]);
- if (i == 2)
- iType = int(params[i]);
- if (i == 3)
- swTitle = params[i];
- }
- }
-
-
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
- pRuntime->BeginBlock();
- vRet = MsgBox(pRuntime->GetReaderApp(), JSGetPageView(cc),swMsg,swTitle,iType,iIcon);
- pRuntime->EndBlock();
-
- return TRUE;
-}
-
-
-FX_BOOL app::beep(OBJ_METHOD_PARAMS)
-{
- if (params.size() == 1)
- {
- CJS_Context* pContext = (CJS_Context*)cc;
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- CPDFDoc_Environment * pEnv = pRuntime->GetReaderApp();
- pEnv->JS_appBeep((int)params[0]);
-
- return TRUE;
- }
- else
- {
- sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
-}
-
-FX_BOOL app::findComponent(OBJ_METHOD_PARAMS)
-{
- return TRUE;
-}
-
-FX_BOOL app::popUpMenuEx(OBJ_METHOD_PARAMS)
-{
- return FALSE;
-}
-
-FX_BOOL app::fs(OBJ_PROP_PARAMS)
-{
-#ifdef FOXIT_CHROME_BUILD
- return FALSE;
-#else
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
-
- if (vp.IsGetting())
- {
- return TRUE;
- }
- else
- {
- return TRUE;
- }
-#endif
-}
-
-FX_BOOL app::setInterval(OBJ_METHOD_PARAMS)
-{
- if (params.size() > 2 || params.size() == 0)
- {
- sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
-
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
-
- CFX_WideString script = params.size() > 0 ? (FX_LPCWSTR)(params[0].operator CFX_WideString()) : (FX_LPCWSTR)L"";
- if (script.IsEmpty())
- {
- sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSAFNUMBER_KEYSTROKE);
- return TRUE;
- }
-
- FX_DWORD dwInterval = params.size() > 1 ? (int)params[1] : 1000;
-
- CPDFDoc_Environment* pApp = pRuntime->GetReaderApp();
- ASSERT(pApp);
- CJS_Timer* pTimer = new CJS_Timer(this, pApp);
- m_aTimer.Add(pTimer);
-
- pTimer->SetType(0);
- pTimer->SetRuntime(pRuntime);
- pTimer->SetJScript(script);
- pTimer->SetTimeOut(0);
-// pTimer->SetStartTime(GetTickCount());
- pTimer->SetJSTimer(dwInterval);
-
- JSFXObject pRetObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"TimerObj"));
-
- CJS_TimerObj* pJS_TimerObj = (CJS_TimerObj*)JS_GetPrivate(pRuntime->GetIsolate(),pRetObj);
- ASSERT(pJS_TimerObj != NULL);
-
- TimerObj* pTimerObj = (TimerObj*)pJS_TimerObj->GetEmbedObject();
- ASSERT(pTimerObj != NULL);
-
- pTimerObj->SetTimer(pTimer);
-
- vRet = pRetObj;
-
- return TRUE;
-}
-
-FX_BOOL app::setTimeOut(OBJ_METHOD_PARAMS)
-{
- if (params.size() > 2 || params.size() == 0)
- {
- sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
-
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
-
- CFX_WideString script = params.size() > 0 ? (FX_LPCWSTR)(params[0].operator CFX_WideString()) : (FX_LPCWSTR)L"";
- if (script.IsEmpty())
- {
- sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSAFNUMBER_KEYSTROKE);
- return TRUE;
- }
-
- FX_DWORD dwTimeOut = params.size() > 1 ? (int)params[1] : 1000;
-
- CPDFDoc_Environment* pApp = pRuntime->GetReaderApp();
- ASSERT(pApp);
- CJS_Timer* pTimer = new CJS_Timer(this, pApp);
- m_aTimer.Add(pTimer);
-
- pTimer->SetType(1);
- pTimer->SetRuntime(pRuntime);
- pTimer->SetJScript(script);
- pTimer->SetTimeOut(dwTimeOut);
-// pTimer->SetStartTime(GetTickCount());
-// pTimer->SetJSTimer(1000);
- pTimer->SetJSTimer(dwTimeOut);
-
- JSFXObject pRetObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"TimerObj"));
-// ASSERT(pRetObj != NULL);
-
- CJS_TimerObj* pJS_TimerObj = (CJS_TimerObj*)JS_GetPrivate(pRuntime->GetIsolate(),pRetObj);
- ASSERT(pJS_TimerObj != NULL);
-
- TimerObj* pTimerObj = (TimerObj*)pJS_TimerObj->GetEmbedObject();
- ASSERT(pTimerObj != NULL);
-
- pTimerObj->SetTimer(pTimer);
-
- vRet = pRetObj;
-
- return TRUE;
-}
-
-FX_BOOL app::clearTimeOut(OBJ_METHOD_PARAMS)
-{
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
-
- if (params.size() != 1)
- {
- sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
-
- if (params[0].GetType() == VT_fxobject)
- {
- JSFXObject pObj = (JSFXObject)params[0];
- {
- if (JS_GetObjDefnID(pObj) == JS_GetObjDefnID(*pRuntime, L"TimerObj"))
- {
- if (CJS_Object* pJSObj = (CJS_Object*)params[0])
- {
- if (TimerObj* pTimerObj = (TimerObj*)pJSObj->GetEmbedObject())
- {
- if (CJS_Timer* pTimer = pTimerObj->GetTimer())
- {
- pTimer->KillJSTimer();
-
- for (int i=0,sz=m_aTimer.GetSize(); i<sz; i++)
- {
- if (m_aTimer[i] == pTimer)
- {
- m_aTimer.RemoveAt(i);
- break;
- }
- }
-
- delete pTimer;
- pTimerObj->SetTimer(NULL);
- }
- }
- }
- }
- }
- }
-
- return TRUE;
-}
-
-FX_BOOL app::clearInterval(OBJ_METHOD_PARAMS)
-{
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
-
- if (params.size() != 1)
- {
- sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
-
- if (params[0].GetType() == VT_fxobject)
- {
- JSFXObject pObj = (JSFXObject)params[0];
- {
- if (JS_GetObjDefnID(pObj) == JS_GetObjDefnID(*pRuntime, L"TimerObj"))
- {
- if (CJS_Object* pJSObj = (CJS_Object*)params[0])
- {
- if (TimerObj* pTimerObj = (TimerObj*)pJSObj->GetEmbedObject())
- {
- if (CJS_Timer* pTimer = pTimerObj->GetTimer())
- {
- pTimer->KillJSTimer();
-
- for (int i=0,sz=m_aTimer.GetSize(); i<sz; i++)
- {
- if (m_aTimer[i] == pTimer)
- {
- m_aTimer.RemoveAt(i);
- break;
- }
- }
-
- delete pTimer;
- pTimerObj->SetTimer(NULL);
- }
- }
- }
- }
- }
- }
-
- return TRUE;
-}
-
-FX_BOOL app::execMenuItem(OBJ_METHOD_PARAMS)
-{
- return FALSE;
-}
-
-void app::TimerProc(CJS_Timer* pTimer)
-{
- ASSERT(pTimer != NULL);
-
- switch (pTimer->GetType())
- {
- case 0: //interval
- RunJsScript(pTimer->GetRuntime(), pTimer->GetJScript());
- break;
- case 1:
- if (pTimer->GetTimeOut() > 0)
- {
- RunJsScript(pTimer->GetRuntime(), pTimer->GetJScript());
- pTimer->KillJSTimer();
- }
- break;
- }
-
-}
-
-void app::RunJsScript(CJS_Runtime* pRuntime,const CFX_WideString& wsScript)
-{
- ASSERT(pRuntime != NULL);
-
- if (!pRuntime->IsBlocking())
- {
- IFXJS_Context* pContext = pRuntime->NewContext();
- ASSERT(pContext != NULL);
- pContext->OnExternal_Exec();
- CFX_WideString wtInfo;
- pContext->RunScript(wsScript,wtInfo);
- pRuntime->ReleaseContext(pContext);
- }
-}
-
-FX_BOOL app::goBack(OBJ_METHOD_PARAMS)
-{
-
-
-
-
-
-
- return TRUE;
-}
-
-FX_BOOL app::goForward(OBJ_METHOD_PARAMS)
-{
-
-
-
-
-
-
- return TRUE;
-}
-
-FX_BOOL app::mailMsg(OBJ_METHOD_PARAMS)
-{
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
-
- v8::Isolate* isolate = GetIsolate(cc);
-
- FX_BOOL bUI = TRUE;
- CFX_WideString cTo = L"";
- CFX_WideString cCc = L"";
- CFX_WideString cBcc = L"";
- CFX_WideString cSubject = L"";
- CFX_WideString cMsg = L"";
- if(params.size() < 2)
- return FALSE;
-
- bUI = params.size()>=1?(int)params[0]:TRUE;
- cTo = params.size()>=2?(const wchar_t*)(FX_LPCWSTR)params[1].operator CFX_WideString():L"";
- cCc = params.size()>=3?(const wchar_t*)(FX_LPCWSTR)params[2].operator CFX_WideString():L"";
- cBcc = params.size()>=4?(const wchar_t*)(FX_LPCWSTR)params[3].operator CFX_WideString():L"";
- cSubject = params.size()>=5?(const wchar_t*)(FX_LPCWSTR)params[4].operator CFX_WideString():L"";
- cMsg = params.size()>=6?(const wchar_t*)(FX_LPCWSTR)params[5].operator CFX_WideString():L"";
-
-
- if (params[0].GetType() == VT_object)
- {
- JSObject pObj = (JSObject)params[0];
-
- v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj, L"bUI");
- bUI = (int)CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue));
-
- pValue = JS_GetObjectElement(isolate, pObj, L"cTo");
- cTo = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
-
- pValue = JS_GetObjectElement(isolate,pObj, L"cCc");
- cCc = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
-
- pValue = JS_GetObjectElement(isolate,pObj, L"cBcc");
- cBcc = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
-
- pValue = JS_GetObjectElement(isolate,pObj, L"cSubject");
- cSubject = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
-
- pValue = JS_GetObjectElement(isolate,pObj, L"cMsg");
- cMsg = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
- }
-
-
-
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
-
- CPDFDoc_Environment* pApp = pContext->GetReaderApp();
- ASSERT(pApp != NULL);
-
- pRuntime->BeginBlock();
- pApp->JS_docmailForm(NULL, 0, bUI, (FX_LPCWSTR)cTo, (FX_LPCWSTR)cSubject, (FX_LPCWSTR)cCc, (FX_LPCWSTR)cBcc, (FX_LPCWSTR)cMsg);
- ///////////////////////////////////////////////////////////////////////////////////////////////
- pRuntime->EndBlock();
-
- //return bRet;
- return FALSE;
-}
-
-FX_BOOL app::launchURL(OBJ_METHOD_PARAMS)
-{
- if (IsSafeMode(cc)) return TRUE;
-
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
-
-
-
-
- CFX_WideString swURL = params[0].operator CFX_WideString();
-
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
-
- pRuntime->BeginBlock();
-// FX_BOOL bRet = pApp->OpenURL(swURL);
- pRuntime->EndBlock();
-
-// return bRet;
- return FALSE;
-}
-
-FX_BOOL app::runtimeHighlight(OBJ_PROP_PARAMS)
-{
- if (vp.IsSetting())
- {
- vp>>m_bRuntimeHighLight;
- }
- else
- {
- vp<<m_bRuntimeHighLight;
- }
-
- return TRUE;
-}
-
-FX_BOOL app::fullscreen(OBJ_PROP_PARAMS)
-{
- return FALSE;
-}
-
-FX_BOOL app::popUpMenu(OBJ_METHOD_PARAMS)
-{
- return FALSE;
-}
-
-
-FX_BOOL app::browseForDoc(OBJ_METHOD_PARAMS)
-{
- //This method may trigger a "file save" dialog,while enable user to save contents of the document.
- //Such action is considered to be unsafe.
- if (IsSafeMode(cc)) return TRUE;
-
- v8::Isolate* isolate = GetIsolate(cc);
-
- bool bSave = false;
- CFX_ByteString cFilenameInit = CFX_ByteString();
- CFX_ByteString cFSInit = CFX_ByteString();
-
- if(params.size()>0 && (params[0].GetType() == VT_object))
- {
- JSObject pObj = (JSObject )params[0];
-
- v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj,L"bSave");
- bSave = (bool)CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue));
-
- pValue = JS_GetObjectElement(isolate, pObj,L"cFilenameInit");
- {
- CJS_Value t = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue));
- cFilenameInit = t.operator CFX_ByteString();
- }
-
- pValue = JS_GetObjectElement(isolate,pObj,L"cFSInit");
- {
- CJS_Value t = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue));
- cFSInit = t.operator CFX_ByteString();
- }
- }
- else
- {
- if(params.size() >= 1)
- {
- bSave = (bool)params[0];
- }
- if(params.size() >= 2)
- {
- CJS_Value t = params[1];
- cFilenameInit = t.operator CFX_ByteString();
- }
- if(params.size() >= 3)
- {
- CJS_Value t = params[2];
- cFSInit = t.operator CFX_ByteString();
- }
- }
- CJS_Context* pContext = (CJS_Context *)cc;
- ASSERT(pContext != NULL);
-
- CPDFDoc_Environment* pApp = pContext->GetReaderApp();
- ASSERT(pApp != NULL);
-
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
-
- CFX_WideString wsFileNameInit = CFX_WideString::FromLocal(cFilenameInit);
- CFX_WideString wsFSInit = CFX_WideString::FromLocal(cFSInit);
- CFX_WideString wsFilePath = pApp->JS_appbrowseForDoc(bSave, wsFileNameInit);
- if(wsFilePath.IsEmpty())
- return FALSE;
-
- JSFXObject pRetObj = JS_NewFxDynamicObj(*pRuntime, pContext, -1);
-
- JS_PutObjectString(isolate,pRetObj, L"cPath", SysPathToPDFPath(wsFilePath));
- JS_PutObjectString(isolate,pRetObj, L"cURL", SysPathToPDFPath(wsFilePath));
-
- if (!cFSInit.IsEmpty())
- {
- JS_PutObjectString(isolate,pRetObj, L"cFS", CFX_WideString::FromLocal(cFSInit.GetBuffer(cFSInit.GetLength())));
- }
- else
- {
- JS_PutObjectString(isolate,pRetObj, L"cFS", CFX_WideString::FromLocal("DOS"));
- }
-
- vRet = pRetObj;
-
- return TRUE;
-}
-
-CFX_WideString app::SysPathToPDFPath(const CFX_WideString& sOldPath)
-{
- CFX_WideString sRet = L"/";
-
- for (int i=0,sz=sOldPath.GetLength(); i<sz; i++)
- {
- wchar_t c = sOldPath.GetAt(i);
- if (c == L':')
- {
- }
- else
- {
- if (c == L'\\')
- {
- sRet += L"/";
- }
- else
- {
- sRet += c;
- }
- }
- }
-
- return sRet;
-}
-
-CFX_WideString app::PDFPathToSysPath(const CFX_WideString& sOldPath)
-{
- //strLPath = "D:\temporay.fdf";
- CFX_WideString strOPath = sOldPath;
- strOPath.TrimLeft();
- strOPath.TrimRight();
-
- if (strOPath.GetAt(0) == L'/' && strOPath.GetAt(2) == L'/')
- {
- wchar_t c_Drive = strOPath.GetAt(1);
- if ((c_Drive >= L'a' && c_Drive <= L'z' )||( c_Drive >= L'A' && c_Drive <= L'Z'))
- {
- strOPath.Replace((FX_LPCWSTR)L"/",(FX_LPCWSTR)L"\\");
- //strOPath.SetAt(0,'');
- strOPath.Insert(2,':');
- strOPath.Delete(0);
- }
- }
-
- return strOPath;
-}
-
-CFX_WideString app::RelativePathToSysPath(const CFX_WideString& sOldPath, const CFX_WideString& sFilePath)
-{
-// if (!PathIsRelative(sOldPath)) return sOldPath;
-
- int nSplit = 0;
- for (int i=sFilePath.GetLength()-1; i>=0; i--)
- {
- if (sFilePath[i] == '\\' || sFilePath[i] == '/')
- {
- nSplit = i;
- break;
- }
- }
-
- return sFilePath.Left(nSplit+1) + sOldPath;
-}
-
-FX_BOOL app::newDoc(OBJ_METHOD_PARAMS)
-{
- return FALSE;
-}
-
-FX_BOOL app::openDoc(OBJ_METHOD_PARAMS)
-{
- return FALSE;
-}
-
-FX_BOOL app::response(OBJ_METHOD_PARAMS)
-{
- CFX_WideString swQuestion = L"";
- CFX_WideString swLabel = L"";
-#ifndef FOXIT_CHROME_BUILD
- CFX_WideString swTitle = L"Foxit";
-#else
- CFX_WideString swTitle = L"PDF";
-#endif
- CFX_WideString swDefault = L"";
- CFX_WideString swResponse = L"";
- bool bPassWord = false;
-
- v8::Isolate* isolate = GetIsolate(cc);
-
- int iLength = params.size();
- if (iLength > 0 && params[0].GetType() == VT_object)
- {
-
- JSObject pObj = (JSObject )params[0];
- v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj,L"cQuestion");
- swQuestion = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
-
- pValue = JS_GetObjectElement(isolate,pObj,L"cTitle");
- swTitle = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
-
- pValue = JS_GetObjectElement(isolate,pObj,L"cDefault");
- swDefault = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
-
- pValue = JS_GetObjectElement(isolate,pObj,L"cLabel");
- swLabel = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
-
- pValue = JS_GetObjectElement(isolate,pObj,L"bPassword");
- bPassWord = (bool)CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue));
- }
- else
- {
- switch(iLength)
- {
- case 1:
- swQuestion = params[0];
- break;
- case 2:
- swQuestion = params[0];
- swTitle = params[1];
- break;
- case 3:
- swQuestion = params[0];
- swTitle = params[1];
- swDefault = params[2];
- break;
- case 4:
- swQuestion = params[0];
- swTitle = params[1];
- swDefault = params[2];
- bPassWord = params[3];
- break;
- case 5:
- swQuestion = params[0];
- swTitle = params[1];
- swDefault = params[2];
- bPassWord = params[3];
- swLabel = params[4];
- break;
- default:
- break;
- }
- }
-
- CJS_Context* pContext = (CJS_Context *)cc;
- ASSERT(pContext != NULL);
-
- CPDFDoc_Environment* pApp = pContext->GetReaderApp();
- ASSERT(pApp != NULL);
- int nLength = 2048;
- char* pBuff = new char[nLength];
- nLength = pApp->JS_appResponse(swQuestion, swTitle, swDefault, swLabel, bPassWord, pBuff, nLength);
- if(nLength<=0)
- {
- vRet.SetNull();
- return FALSE;
- }
- else
- {
- nLength = nLength>2046?2046:nLength;
- pBuff[nLength] = 0;
- pBuff[nLength+1] = 0;
- swResponse = CFX_WideString::FromUTF16LE((unsigned short*)pBuff, nLength);
- vRet = swResponse;
- }
- delete[] pBuff;
-
- return TRUE;
-}
-
-FX_BOOL app::media(OBJ_PROP_PARAMS)
-{
- return FALSE;
-}
-
-FX_BOOL app::execDialog(OBJ_METHOD_PARAMS)
-{
- return TRUE;
-}
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/javascript/JavaScript.h"
+#include "../../include/javascript/IJavaScript.h"
+#include "../../include/javascript/JS_Define.h"
+#include "../../include/javascript/JS_Object.h"
+#include "../../include/javascript/JS_Value.h"
+#include "../../include/javascript/app.h"
+#include "../../include/javascript/JS_EventHandler.h"
+#include "../../include/javascript/resource.h"
+#include "../../include/javascript/JS_Context.h"
+#include "../../include/javascript/JS_Runtime.h"
+#include "../../include/javascript/Document.h"
+
+
+static v8::Isolate* GetIsolate(IFXJS_Context* cc)
+{
+ CJS_Context* pContext = (CJS_Context *)cc;
+ ASSERT(pContext != NULL);
+
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ ASSERT(pRuntime != NULL);
+
+ return pRuntime->GetIsolate();
+}
+
+/* ---------------------------- TimerObj ---------------------------- */
+
+BEGIN_JS_STATIC_CONST(CJS_TimerObj)
+END_JS_STATIC_CONST()
+
+BEGIN_JS_STATIC_PROP(CJS_TimerObj)
+END_JS_STATIC_PROP()
+
+BEGIN_JS_STATIC_METHOD(CJS_TimerObj)
+END_JS_STATIC_METHOD()
+
+IMPLEMENT_JS_CLASS(CJS_TimerObj, TimerObj)
+
+TimerObj::TimerObj(CJS_Object* pJSObject)
+: CJS_EmbedObj(pJSObject),
+m_pTimer(NULL)
+{
+
+}
+
+TimerObj::~TimerObj()
+{
+}
+
+void TimerObj::SetTimer(CJS_Timer* pTimer)
+{
+ m_pTimer = pTimer;
+}
+
+CJS_Timer* TimerObj::GetTimer() const
+{
+ return m_pTimer;
+}
+
+#define JS_STR_VIEWERTYPE_READER L"Reader"
+#define JS_STR_VIEWERTYPE_STANDARD L"Exchange"
+#define JS_STR_VIEWERVARIATION L"Full"
+#define JS_STR_PLATFORM L"WIN"
+#define JS_STR_LANGUANGE L"ENU"
+#define JS_STR_VIEWERVERSION 8
+#define JS_NUM_FORMSVERSION 7
+
+#define JS_FILEPATH_MAXLEN 2000
+
+/* ---------------------------- app ---------------------------- */
+
+BEGIN_JS_STATIC_CONST(CJS_App)
+END_JS_STATIC_CONST()
+
+BEGIN_JS_STATIC_PROP(CJS_App)
+ JS_STATIC_PROP_ENTRY(activeDocs)
+ JS_STATIC_PROP_ENTRY(calculate)
+ JS_STATIC_PROP_ENTRY(formsVersion)
+ JS_STATIC_PROP_ENTRY(fs)
+ JS_STATIC_PROP_ENTRY(fullscreen)
+ JS_STATIC_PROP_ENTRY(language)
+ JS_STATIC_PROP_ENTRY(media)
+ JS_STATIC_PROP_ENTRY(platform)
+ JS_STATIC_PROP_ENTRY(runtimeHighlight)
+ JS_STATIC_PROP_ENTRY(viewerType)
+ JS_STATIC_PROP_ENTRY(viewerVariation)
+ JS_STATIC_PROP_ENTRY(viewerVersion)
+END_JS_STATIC_PROP()
+
+BEGIN_JS_STATIC_METHOD(CJS_App)
+ JS_STATIC_METHOD_ENTRY(alert, 6)
+ JS_STATIC_METHOD_ENTRY(beep, 1)
+ JS_STATIC_METHOD_ENTRY(browseForDoc, 0)
+ JS_STATIC_METHOD_ENTRY(clearInterval, 1)
+ JS_STATIC_METHOD_ENTRY(clearTimeOut, 1)
+ JS_STATIC_METHOD_ENTRY(execDialog, 3)
+ JS_STATIC_METHOD_ENTRY(execMenuItem, 1)
+ JS_STATIC_METHOD_ENTRY(findComponent, 1)
+ JS_STATIC_METHOD_ENTRY(goBack, 0)
+ JS_STATIC_METHOD_ENTRY(goForward, 0)
+ JS_STATIC_METHOD_ENTRY(launchURL, 0)
+ JS_STATIC_METHOD_ENTRY(mailMsg, 0)
+ JS_STATIC_METHOD_ENTRY(newFDF, 0)
+ JS_STATIC_METHOD_ENTRY(newDoc, 0)
+ JS_STATIC_METHOD_ENTRY(openDoc, 0)
+ JS_STATIC_METHOD_ENTRY(openFDF, 5)
+ JS_STATIC_METHOD_ENTRY(popUpMenuEx, 0)
+ JS_STATIC_METHOD_ENTRY(popUpMenu, 0)
+ JS_STATIC_METHOD_ENTRY(response, 0)
+ JS_STATIC_METHOD_ENTRY(setInterval, 2)
+ JS_STATIC_METHOD_ENTRY(setTimeOut, 2)
+END_JS_STATIC_METHOD()
+
+IMPLEMENT_JS_CLASS(CJS_App,app)
+
+app::app(CJS_Object * pJSObject) : CJS_EmbedObj(pJSObject) ,
+ m_bCalculate(true),
+ m_pRuntime(NULL),
+ m_bRuntimeHighLight(false)
+// m_pMenuHead(NULL)
+{
+}
+
+app::~app(void)
+{
+ for (int i=0,sz=m_aTimer.GetSize(); i<sz; i++)
+ delete m_aTimer[i];
+
+ m_aTimer.RemoveAll();
+}
+
+FX_BOOL app::activeDocs(OBJ_PROP_PARAMS)
+{
+ if (vp.IsGetting())
+ {
+
+ CJS_Context* pContext = (CJS_Context *)cc;
+ ASSERT(pContext != NULL);
+
+ CPDFDoc_Environment* pApp = pContext->GetReaderApp();
+ ASSERT(pApp != NULL);
+
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ ASSERT(pRuntime != NULL);
+
+ CPDFSDK_Document* pCurDoc = pContext->GetReaderDocument();
+
+ CJS_Array aDocs(pRuntime->GetIsolate());
+// int iNumDocs = pApp->CountDocuments();
+
+// for(int iIndex = 0; iIndex<iNumDocs; iIndex++)
+// {
+ CPDFSDK_Document* pDoc = pApp->GetCurrentDoc();
+ if (pDoc)
+ {
+ CJS_Document * pJSDocument = NULL;
+
+ if (pDoc == pCurDoc)
+ {
+ JSFXObject pObj = JS_GetThisObj(*pRuntime);
+
+ if (JS_GetObjDefnID(pObj) == JS_GetObjDefnID(*pRuntime, L"Document"))
+ {
+ pJSDocument = (CJS_Document*)JS_GetPrivate(pRuntime->GetIsolate(),pObj);
+ }
+ }
+ else
+ {
+ JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime,L"Document"));
+ pJSDocument = (CJS_Document*)JS_GetPrivate(pRuntime->GetIsolate(),pObj);
+ ASSERT(pJSDocument != NULL);
+
+
+ // pDocument->AttachDoc(pDoc);
+ }
+
+ aDocs.SetElement(0,CJS_Value(pRuntime->GetIsolate(),pJSDocument));
+ }
+ // }
+
+ if (aDocs.GetLength() > 0)
+ vp << aDocs;
+ else
+ vp.SetNull();
+ return TRUE;
+ }
+ return FALSE;
+}
+
+FX_BOOL app::calculate(OBJ_PROP_PARAMS)
+{
+ if (vp.IsSetting())
+ {
+ bool bVP;
+ vp >> bVP;
+ m_bCalculate = (FX_BOOL)bVP;
+
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+
+ CPDFDoc_Environment* pApp = pContext->GetReaderApp();
+ ASSERT(pApp != NULL);
+
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ ASSERT(pRuntime != NULL);
+
+ CJS_Array aDocs(pRuntime->GetIsolate());
+// int iNumDocs = pApp->CountDocuments();
+//
+// for (int iIndex = 0;iIndex < iNumDocs; iIndex++)
+// {
+ if (CPDFSDK_Document* pDoc = pApp->GetCurrentDoc())
+ {
+ CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDoc->GetInterForm();
+ ASSERT(pInterForm != NULL);
+ pInterForm->EnableCalculate((FX_BOOL)m_bCalculate);
+ }
+// }
+ }
+ else
+ {
+ vp << (bool)m_bCalculate;
+ }
+
+ return TRUE;
+}
+
+FX_BOOL app::formsVersion(OBJ_PROP_PARAMS)
+{
+ if (vp.IsGetting())
+ {
+ vp << JS_NUM_FORMSVERSION;
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+FX_BOOL app::viewerType(OBJ_PROP_PARAMS)
+{
+
+
+
+
+
+
+ if (vp.IsGetting())
+ {
+// if (pApp->GetAppName() == PHANTOM)
+// vp << JS_STR_VIEWERTYPE_STANDARD;
+// else
+// vp << JS_STR_VIEWERTYPE_READER;
+ vp << L"unknown";
+
+ //vp << pApp->GetAppTitle();
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+FX_BOOL app::viewerVariation(OBJ_PROP_PARAMS)
+{
+ if (vp.IsGetting())
+ {
+ vp << JS_STR_VIEWERVARIATION;
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+FX_BOOL app::viewerVersion(OBJ_PROP_PARAMS)
+{
+ if (vp.IsGetting())
+ {
+ vp << JS_STR_VIEWERVERSION;
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+FX_BOOL app::platform(OBJ_PROP_PARAMS)
+{
+ if (vp.IsGetting())
+ {
+ vp << JS_STR_PLATFORM;
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+FX_BOOL app::language(OBJ_PROP_PARAMS)
+{
+ if (vp.IsGetting())
+ {
+ vp << JS_STR_LANGUANGE;
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+//creates a new fdf object that contains no data
+//comment: need reader support
+//note:
+//CFDF_Document * CPDFDoc_Environment::NewFDF();
+FX_BOOL app::newFDF(OBJ_METHOD_PARAMS)
+{
+ return TRUE;
+}
+//opens a specified pdf document and returns its document object
+//comment:need reader support
+//note: as defined in js reference, the proto of this function's fourth parmeters, how old an fdf document while do not show it.
+//CFDF_Document * CPDFDoc_Environment::OpenFDF(string strPath,bool bUserConv);
+
+FX_BOOL app::openFDF(OBJ_METHOD_PARAMS)
+{
+ return TRUE;
+}
+
+FX_BOOL app::alert(OBJ_METHOD_PARAMS)
+{
+ int iSize = params.size();
+ if (iSize < 1)
+ return FALSE;
+
+ CFX_WideString swMsg = L"";
+ CFX_WideString swTitle = L"";
+ int iIcon = 0;
+ int iType = 0;
+
+ v8::Isolate* isolate = GetIsolate(cc);
+
+ if (iSize == 1)
+ {
+ if (params[0].GetType() == VT_object)
+ {
+ JSObject pObj = params[0];
+ {
+ v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate, pObj, L"cMsg");
+ swMsg = CJS_Value(isolate,pValue,VT_unknown).operator CFX_WideString();
+
+ pValue = JS_GetObjectElement(isolate,pObj,L"cTitle");
+ swTitle = CJS_Value(isolate, pValue,VT_unknown).operator CFX_WideString();
+
+ pValue = JS_GetObjectElement(isolate,pObj,L"nIcon");
+ iIcon = (int)CJS_Value(isolate,pValue,VT_unknown);
+
+ pValue = JS_GetObjectElement(isolate,pObj,L"nType");
+ iType = (int)CJS_Value(isolate,pValue,VT_unknown);
+ }
+
+ if (swMsg == L"")
+ {
+ CJS_Array carray(isolate);
+ if (params[0].ConvertToArray(carray))
+ {
+ int iLenth = carray.GetLength();
+ CJS_Value* pValue = new CJS_Value(isolate);
+// if (iLenth == 1)
+// pValue = new CJS_Value(isolate);
+// else if (iLenth > 1)
+// pValue = new CJS_Value[iLenth];
+
+ for(int i = 0; i < iLenth; i++)
+ {
+ carray.GetElement(i, *pValue);
+ swMsg += (*pValue).operator CFX_WideString();
+ if (i < iLenth - 1)
+ swMsg += L", ";
+ }
+
+ if(pValue) delete pValue;
+// if ((iLenth > 1) && pValue)
+// {
+// delete[]pValue;
+// pValue = NULL;
+// }
+// else if ((iLenth == 1) && pValue)
+// {
+// delete pValue;
+// pValue = NULL;
+// }
+ }
+ }
+
+ if (swTitle == L"")
+ swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSALERT);
+ }
+ else if (params[0].GetType() == VT_boolean)
+ {
+ FX_BOOL bGet = (FX_BOOL)params[0];
+ if (bGet)
+ swMsg = L"true";
+ else
+ swMsg = L"false";
+
+ swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSALERT);
+ }
+ else
+ {
+ swMsg = params[0];
+ swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSALERT);
+ }
+ }
+ else
+ {
+ if (params[0].GetType() == VT_boolean)
+ {
+ FX_BOOL bGet = (FX_BOOL)params[0];
+ if (bGet)
+ swMsg = L"true";
+ else
+ swMsg = L"false";
+ }
+ else
+ {
+ swMsg = params[0];
+ }
+ swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSALERT);
+
+ for(int i = 1;i<iSize;i++)
+ {
+ if (i == 1)
+ iIcon = int(params[i]);
+ if (i == 2)
+ iType = int(params[i]);
+ if (i == 3)
+ swTitle = params[i];
+ }
+ }
+
+
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ ASSERT(pRuntime != NULL);
+ pRuntime->BeginBlock();
+ vRet = MsgBox(pRuntime->GetReaderApp(), JSGetPageView(cc),swMsg,swTitle,iType,iIcon);
+ pRuntime->EndBlock();
+
+ return TRUE;
+}
+
+
+FX_BOOL app::beep(OBJ_METHOD_PARAMS)
+{
+ if (params.size() == 1)
+ {
+ CJS_Context* pContext = (CJS_Context*)cc;
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ CPDFDoc_Environment * pEnv = pRuntime->GetReaderApp();
+ pEnv->JS_appBeep((int)params[0]);
+
+ return TRUE;
+ }
+ else
+ {
+ sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
+}
+
+FX_BOOL app::findComponent(OBJ_METHOD_PARAMS)
+{
+ return TRUE;
+}
+
+FX_BOOL app::popUpMenuEx(OBJ_METHOD_PARAMS)
+{
+ return FALSE;
+}
+
+FX_BOOL app::fs(OBJ_PROP_PARAMS)
+{
+#ifdef FOXIT_CHROME_BUILD
+ return FALSE;
+#else
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ ASSERT(pRuntime != NULL);
+
+ if (vp.IsGetting())
+ {
+ return TRUE;
+ }
+ else
+ {
+ return TRUE;
+ }
+#endif
+}
+
+FX_BOOL app::setInterval(OBJ_METHOD_PARAMS)
+{
+ if (params.size() > 2 || params.size() == 0)
+ {
+ sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
+
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ ASSERT(pRuntime != NULL);
+
+ CFX_WideString script = params.size() > 0 ? (FX_LPCWSTR)(params[0].operator CFX_WideString()) : (FX_LPCWSTR)L"";
+ if (script.IsEmpty())
+ {
+ sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSAFNUMBER_KEYSTROKE);
+ return TRUE;
+ }
+
+ FX_DWORD dwInterval = params.size() > 1 ? (int)params[1] : 1000;
+
+ CPDFDoc_Environment* pApp = pRuntime->GetReaderApp();
+ ASSERT(pApp);
+ CJS_Timer* pTimer = new CJS_Timer(this, pApp);
+ m_aTimer.Add(pTimer);
+
+ pTimer->SetType(0);
+ pTimer->SetRuntime(pRuntime);
+ pTimer->SetJScript(script);
+ pTimer->SetTimeOut(0);
+// pTimer->SetStartTime(GetTickCount());
+ pTimer->SetJSTimer(dwInterval);
+
+ JSFXObject pRetObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"TimerObj"));
+
+ CJS_TimerObj* pJS_TimerObj = (CJS_TimerObj*)JS_GetPrivate(pRuntime->GetIsolate(),pRetObj);
+ ASSERT(pJS_TimerObj != NULL);
+
+ TimerObj* pTimerObj = (TimerObj*)pJS_TimerObj->GetEmbedObject();
+ ASSERT(pTimerObj != NULL);
+
+ pTimerObj->SetTimer(pTimer);
+
+ vRet = pRetObj;
+
+ return TRUE;
+}
+
+FX_BOOL app::setTimeOut(OBJ_METHOD_PARAMS)
+{
+ if (params.size() > 2 || params.size() == 0)
+ {
+ sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
+
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ ASSERT(pRuntime != NULL);
+
+ CFX_WideString script = params.size() > 0 ? (FX_LPCWSTR)(params[0].operator CFX_WideString()) : (FX_LPCWSTR)L"";
+ if (script.IsEmpty())
+ {
+ sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSAFNUMBER_KEYSTROKE);
+ return TRUE;
+ }
+
+ FX_DWORD dwTimeOut = params.size() > 1 ? (int)params[1] : 1000;
+
+ CPDFDoc_Environment* pApp = pRuntime->GetReaderApp();
+ ASSERT(pApp);
+ CJS_Timer* pTimer = new CJS_Timer(this, pApp);
+ m_aTimer.Add(pTimer);
+
+ pTimer->SetType(1);
+ pTimer->SetRuntime(pRuntime);
+ pTimer->SetJScript(script);
+ pTimer->SetTimeOut(dwTimeOut);
+// pTimer->SetStartTime(GetTickCount());
+// pTimer->SetJSTimer(1000);
+ pTimer->SetJSTimer(dwTimeOut);
+
+ JSFXObject pRetObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"TimerObj"));
+// ASSERT(pRetObj != NULL);
+
+ CJS_TimerObj* pJS_TimerObj = (CJS_TimerObj*)JS_GetPrivate(pRuntime->GetIsolate(),pRetObj);
+ ASSERT(pJS_TimerObj != NULL);
+
+ TimerObj* pTimerObj = (TimerObj*)pJS_TimerObj->GetEmbedObject();
+ ASSERT(pTimerObj != NULL);
+
+ pTimerObj->SetTimer(pTimer);
+
+ vRet = pRetObj;
+
+ return TRUE;
+}
+
+FX_BOOL app::clearTimeOut(OBJ_METHOD_PARAMS)
+{
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ ASSERT(pRuntime != NULL);
+
+ if (params.size() != 1)
+ {
+ sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
+
+ if (params[0].GetType() == VT_fxobject)
+ {
+ JSFXObject pObj = (JSFXObject)params[0];
+ {
+ if (JS_GetObjDefnID(pObj) == JS_GetObjDefnID(*pRuntime, L"TimerObj"))
+ {
+ if (CJS_Object* pJSObj = (CJS_Object*)params[0])
+ {
+ if (TimerObj* pTimerObj = (TimerObj*)pJSObj->GetEmbedObject())
+ {
+ if (CJS_Timer* pTimer = pTimerObj->GetTimer())
+ {
+ pTimer->KillJSTimer();
+
+ for (int i=0,sz=m_aTimer.GetSize(); i<sz; i++)
+ {
+ if (m_aTimer[i] == pTimer)
+ {
+ m_aTimer.RemoveAt(i);
+ break;
+ }
+ }
+
+ delete pTimer;
+ pTimerObj->SetTimer(NULL);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return TRUE;
+}
+
+FX_BOOL app::clearInterval(OBJ_METHOD_PARAMS)
+{
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ ASSERT(pRuntime != NULL);
+
+ if (params.size() != 1)
+ {
+ sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
+
+ if (params[0].GetType() == VT_fxobject)
+ {
+ JSFXObject pObj = (JSFXObject)params[0];
+ {
+ if (JS_GetObjDefnID(pObj) == JS_GetObjDefnID(*pRuntime, L"TimerObj"))
+ {
+ if (CJS_Object* pJSObj = (CJS_Object*)params[0])
+ {
+ if (TimerObj* pTimerObj = (TimerObj*)pJSObj->GetEmbedObject())
+ {
+ if (CJS_Timer* pTimer = pTimerObj->GetTimer())
+ {
+ pTimer->KillJSTimer();
+
+ for (int i=0,sz=m_aTimer.GetSize(); i<sz; i++)
+ {
+ if (m_aTimer[i] == pTimer)
+ {
+ m_aTimer.RemoveAt(i);
+ break;
+ }
+ }
+
+ delete pTimer;
+ pTimerObj->SetTimer(NULL);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return TRUE;
+}
+
+FX_BOOL app::execMenuItem(OBJ_METHOD_PARAMS)
+{
+ return FALSE;
+}
+
+void app::TimerProc(CJS_Timer* pTimer)
+{
+ ASSERT(pTimer != NULL);
+
+ switch (pTimer->GetType())
+ {
+ case 0: //interval
+ RunJsScript(pTimer->GetRuntime(), pTimer->GetJScript());
+ break;
+ case 1:
+ if (pTimer->GetTimeOut() > 0)
+ {
+ RunJsScript(pTimer->GetRuntime(), pTimer->GetJScript());
+ pTimer->KillJSTimer();
+ }
+ break;
+ }
+
+}
+
+void app::RunJsScript(CJS_Runtime* pRuntime,const CFX_WideString& wsScript)
+{
+ ASSERT(pRuntime != NULL);
+
+ if (!pRuntime->IsBlocking())
+ {
+ IFXJS_Context* pContext = pRuntime->NewContext();
+ ASSERT(pContext != NULL);
+ pContext->OnExternal_Exec();
+ CFX_WideString wtInfo;
+ pContext->RunScript(wsScript,wtInfo);
+ pRuntime->ReleaseContext(pContext);
+ }
+}
+
+FX_BOOL app::goBack(OBJ_METHOD_PARAMS)
+{
+
+
+
+
+
+
+ return TRUE;
+}
+
+FX_BOOL app::goForward(OBJ_METHOD_PARAMS)
+{
+
+
+
+
+
+
+ return TRUE;
+}
+
+FX_BOOL app::mailMsg(OBJ_METHOD_PARAMS)
+{
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+
+ v8::Isolate* isolate = GetIsolate(cc);
+
+ FX_BOOL bUI = TRUE;
+ CFX_WideString cTo = L"";
+ CFX_WideString cCc = L"";
+ CFX_WideString cBcc = L"";
+ CFX_WideString cSubject = L"";
+ CFX_WideString cMsg = L"";
+ if(params.size() < 2)
+ return FALSE;
+
+ bUI = params.size()>=1?(int)params[0]:TRUE;
+ cTo = params.size()>=2?(const wchar_t*)(FX_LPCWSTR)params[1].operator CFX_WideString():L"";
+ cCc = params.size()>=3?(const wchar_t*)(FX_LPCWSTR)params[2].operator CFX_WideString():L"";
+ cBcc = params.size()>=4?(const wchar_t*)(FX_LPCWSTR)params[3].operator CFX_WideString():L"";
+ cSubject = params.size()>=5?(const wchar_t*)(FX_LPCWSTR)params[4].operator CFX_WideString():L"";
+ cMsg = params.size()>=6?(const wchar_t*)(FX_LPCWSTR)params[5].operator CFX_WideString():L"";
+
+
+ if (params[0].GetType() == VT_object)
+ {
+ JSObject pObj = (JSObject)params[0];
+
+ v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj, L"bUI");
+ bUI = (int)CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue));
+
+ pValue = JS_GetObjectElement(isolate, pObj, L"cTo");
+ cTo = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
+
+ pValue = JS_GetObjectElement(isolate,pObj, L"cCc");
+ cCc = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
+
+ pValue = JS_GetObjectElement(isolate,pObj, L"cBcc");
+ cBcc = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
+
+ pValue = JS_GetObjectElement(isolate,pObj, L"cSubject");
+ cSubject = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
+
+ pValue = JS_GetObjectElement(isolate,pObj, L"cMsg");
+ cMsg = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
+ }
+
+
+
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ ASSERT(pRuntime != NULL);
+
+ CPDFDoc_Environment* pApp = pContext->GetReaderApp();
+ ASSERT(pApp != NULL);
+
+ pRuntime->BeginBlock();
+ pApp->JS_docmailForm(NULL, 0, bUI, (FX_LPCWSTR)cTo, (FX_LPCWSTR)cSubject, (FX_LPCWSTR)cCc, (FX_LPCWSTR)cBcc, (FX_LPCWSTR)cMsg);
+ ///////////////////////////////////////////////////////////////////////////////////////////////
+ pRuntime->EndBlock();
+
+ //return bRet;
+ return FALSE;
+}
+
+FX_BOOL app::launchURL(OBJ_METHOD_PARAMS)
+{
+ if (IsSafeMode(cc)) return TRUE;
+
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+
+
+
+
+ CFX_WideString swURL = params[0].operator CFX_WideString();
+
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ ASSERT(pRuntime != NULL);
+
+ pRuntime->BeginBlock();
+// FX_BOOL bRet = pApp->OpenURL(swURL);
+ pRuntime->EndBlock();
+
+// return bRet;
+ return FALSE;
+}
+
+FX_BOOL app::runtimeHighlight(OBJ_PROP_PARAMS)
+{
+ if (vp.IsSetting())
+ {
+ vp>>m_bRuntimeHighLight;
+ }
+ else
+ {
+ vp<<m_bRuntimeHighLight;
+ }
+
+ return TRUE;
+}
+
+FX_BOOL app::fullscreen(OBJ_PROP_PARAMS)
+{
+ return FALSE;
+}
+
+FX_BOOL app::popUpMenu(OBJ_METHOD_PARAMS)
+{
+ return FALSE;
+}
+
+
+FX_BOOL app::browseForDoc(OBJ_METHOD_PARAMS)
+{
+ //This method may trigger a "file save" dialog,while enable user to save contents of the document.
+ //Such action is considered to be unsafe.
+ if (IsSafeMode(cc)) return TRUE;
+
+ v8::Isolate* isolate = GetIsolate(cc);
+
+ bool bSave = false;
+ CFX_ByteString cFilenameInit = CFX_ByteString();
+ CFX_ByteString cFSInit = CFX_ByteString();
+
+ if(params.size()>0 && (params[0].GetType() == VT_object))
+ {
+ JSObject pObj = (JSObject )params[0];
+
+ v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj,L"bSave");
+ bSave = (bool)CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue));
+
+ pValue = JS_GetObjectElement(isolate, pObj,L"cFilenameInit");
+ {
+ CJS_Value t = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue));
+ cFilenameInit = t.operator CFX_ByteString();
+ }
+
+ pValue = JS_GetObjectElement(isolate,pObj,L"cFSInit");
+ {
+ CJS_Value t = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue));
+ cFSInit = t.operator CFX_ByteString();
+ }
+ }
+ else
+ {
+ if(params.size() >= 1)
+ {
+ bSave = (bool)params[0];
+ }
+ if(params.size() >= 2)
+ {
+ CJS_Value t = params[1];
+ cFilenameInit = t.operator CFX_ByteString();
+ }
+ if(params.size() >= 3)
+ {
+ CJS_Value t = params[2];
+ cFSInit = t.operator CFX_ByteString();
+ }
+ }
+ CJS_Context* pContext = (CJS_Context *)cc;
+ ASSERT(pContext != NULL);
+
+ CPDFDoc_Environment* pApp = pContext->GetReaderApp();
+ ASSERT(pApp != NULL);
+
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ ASSERT(pRuntime != NULL);
+
+ CFX_WideString wsFileNameInit = CFX_WideString::FromLocal(cFilenameInit);
+ CFX_WideString wsFSInit = CFX_WideString::FromLocal(cFSInit);
+ CFX_WideString wsFilePath = pApp->JS_appbrowseForDoc(bSave, wsFileNameInit);
+ if(wsFilePath.IsEmpty())
+ return FALSE;
+
+ JSFXObject pRetObj = JS_NewFxDynamicObj(*pRuntime, pContext, -1);
+
+ JS_PutObjectString(isolate,pRetObj, L"cPath", SysPathToPDFPath(wsFilePath));
+ JS_PutObjectString(isolate,pRetObj, L"cURL", SysPathToPDFPath(wsFilePath));
+
+ if (!cFSInit.IsEmpty())
+ {
+ JS_PutObjectString(isolate,pRetObj, L"cFS", CFX_WideString::FromLocal(cFSInit.GetBuffer(cFSInit.GetLength())));
+ }
+ else
+ {
+ JS_PutObjectString(isolate,pRetObj, L"cFS", CFX_WideString::FromLocal("DOS"));
+ }
+
+ vRet = pRetObj;
+
+ return TRUE;
+}
+
+CFX_WideString app::SysPathToPDFPath(const CFX_WideString& sOldPath)
+{
+ CFX_WideString sRet = L"/";
+
+ for (int i=0,sz=sOldPath.GetLength(); i<sz; i++)
+ {
+ wchar_t c = sOldPath.GetAt(i);
+ if (c == L':')
+ {
+ }
+ else
+ {
+ if (c == L'\\')
+ {
+ sRet += L"/";
+ }
+ else
+ {
+ sRet += c;
+ }
+ }
+ }
+
+ return sRet;
+}
+
+CFX_WideString app::PDFPathToSysPath(const CFX_WideString& sOldPath)
+{
+ //strLPath = "D:\temporay.fdf";
+ CFX_WideString strOPath = sOldPath;
+ strOPath.TrimLeft();
+ strOPath.TrimRight();
+
+ if (strOPath.GetAt(0) == L'/' && strOPath.GetAt(2) == L'/')
+ {
+ wchar_t c_Drive = strOPath.GetAt(1);
+ if ((c_Drive >= L'a' && c_Drive <= L'z' )||( c_Drive >= L'A' && c_Drive <= L'Z'))
+ {
+ strOPath.Replace((FX_LPCWSTR)L"/",(FX_LPCWSTR)L"\\");
+ //strOPath.SetAt(0,'');
+ strOPath.Insert(2,':');
+ strOPath.Delete(0);
+ }
+ }
+
+ return strOPath;
+}
+
+CFX_WideString app::RelativePathToSysPath(const CFX_WideString& sOldPath, const CFX_WideString& sFilePath)
+{
+// if (!PathIsRelative(sOldPath)) return sOldPath;
+
+ int nSplit = 0;
+ for (int i=sFilePath.GetLength()-1; i>=0; i--)
+ {
+ if (sFilePath[i] == '\\' || sFilePath[i] == '/')
+ {
+ nSplit = i;
+ break;
+ }
+ }
+
+ return sFilePath.Left(nSplit+1) + sOldPath;
+}
+
+FX_BOOL app::newDoc(OBJ_METHOD_PARAMS)
+{
+ return FALSE;
+}
+
+FX_BOOL app::openDoc(OBJ_METHOD_PARAMS)
+{
+ return FALSE;
+}
+
+FX_BOOL app::response(OBJ_METHOD_PARAMS)
+{
+ CFX_WideString swQuestion = L"";
+ CFX_WideString swLabel = L"";
+#ifndef FOXIT_CHROME_BUILD
+ CFX_WideString swTitle = L"Foxit";
+#else
+ CFX_WideString swTitle = L"PDF";
+#endif
+ CFX_WideString swDefault = L"";
+ CFX_WideString swResponse = L"";
+ bool bPassWord = false;
+
+ v8::Isolate* isolate = GetIsolate(cc);
+
+ int iLength = params.size();
+ if (iLength > 0 && params[0].GetType() == VT_object)
+ {
+
+ JSObject pObj = (JSObject )params[0];
+ v8::Handle<v8::Value> pValue = JS_GetObjectElement(isolate,pObj,L"cQuestion");
+ swQuestion = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
+
+ pValue = JS_GetObjectElement(isolate,pObj,L"cTitle");
+ swTitle = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
+
+ pValue = JS_GetObjectElement(isolate,pObj,L"cDefault");
+ swDefault = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
+
+ pValue = JS_GetObjectElement(isolate,pObj,L"cLabel");
+ swLabel = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).operator CFX_WideString();
+
+ pValue = JS_GetObjectElement(isolate,pObj,L"bPassword");
+ bPassWord = (bool)CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue));
+ }
+ else
+ {
+ switch(iLength)
+ {
+ case 1:
+ swQuestion = params[0];
+ break;
+ case 2:
+ swQuestion = params[0];
+ swTitle = params[1];
+ break;
+ case 3:
+ swQuestion = params[0];
+ swTitle = params[1];
+ swDefault = params[2];
+ break;
+ case 4:
+ swQuestion = params[0];
+ swTitle = params[1];
+ swDefault = params[2];
+ bPassWord = params[3];
+ break;
+ case 5:
+ swQuestion = params[0];
+ swTitle = params[1];
+ swDefault = params[2];
+ bPassWord = params[3];
+ swLabel = params[4];
+ break;
+ default:
+ break;
+ }
+ }
+
+ CJS_Context* pContext = (CJS_Context *)cc;
+ ASSERT(pContext != NULL);
+
+ CPDFDoc_Environment* pApp = pContext->GetReaderApp();
+ ASSERT(pApp != NULL);
+ int nLength = 2048;
+ char* pBuff = new char[nLength];
+ nLength = pApp->JS_appResponse(swQuestion, swTitle, swDefault, swLabel, bPassWord, pBuff, nLength);
+ if(nLength<=0)
+ {
+ vRet.SetNull();
+ return FALSE;
+ }
+ else
+ {
+ nLength = nLength>2046?2046:nLength;
+ pBuff[nLength] = 0;
+ pBuff[nLength+1] = 0;
+ swResponse = CFX_WideString::FromUTF16LE((unsigned short*)pBuff, nLength);
+ vRet = swResponse;
+ }
+ delete[] pBuff;
+
+ return TRUE;
+}
+
+FX_BOOL app::media(OBJ_PROP_PARAMS)
+{
+ return FALSE;
+}
+
+FX_BOOL app::execDialog(OBJ_METHOD_PARAMS)
+{
+ return TRUE;
+}
+
diff --git a/fpdfsdk/src/javascript/color.cpp b/fpdfsdk/src/javascript/color.cpp
index de5a53fc5f..3841706743 100644
--- a/fpdfsdk/src/javascript/color.cpp
+++ b/fpdfsdk/src/javascript/color.cpp
@@ -1,253 +1,253 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/javascript/JavaScript.h"
-#include "../../include/javascript/IJavaScript.h"
-#include "../../include/javascript/JS_Define.h"
-#include "../../include/javascript/JS_Object.h"
-#include "../../include/javascript/JS_Value.h"
-#include "../../include/javascript/color.h"
-#include "../../include/javascript/JS_EventHandler.h"
-#include "../../include/javascript/JS_Context.h"
-#include "../../include/javascript/JS_Runtime.h"
-
-static v8::Isolate* GetIsolate(IFXJS_Context* cc)
-{
- CJS_Context* pContext = (CJS_Context *)cc;
- ASSERT(pContext != NULL);
-
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
-
- return pRuntime->GetIsolate();
-}
-/* -------------------------- color -------------------------- */
-
-BEGIN_JS_STATIC_CONST(CJS_Color)
-END_JS_STATIC_CONST()
-
-BEGIN_JS_STATIC_PROP(CJS_Color)
- JS_STATIC_PROP_ENTRY(black)
- JS_STATIC_PROP_ENTRY(blue)
- JS_STATIC_PROP_ENTRY(cyan)
- JS_STATIC_PROP_ENTRY(dkGray)
- JS_STATIC_PROP_ENTRY(gray)
- JS_STATIC_PROP_ENTRY(green)
- JS_STATIC_PROP_ENTRY(ltGray)
- JS_STATIC_PROP_ENTRY(magenta)
- JS_STATIC_PROP_ENTRY(red)
- JS_STATIC_PROP_ENTRY(transparent)
- JS_STATIC_PROP_ENTRY(white)
- JS_STATIC_PROP_ENTRY(yellow)
-END_JS_STATIC_PROP()
-
-BEGIN_JS_STATIC_METHOD(CJS_Color)
- JS_STATIC_METHOD_ENTRY(convert, 2)
- JS_STATIC_METHOD_ENTRY(equal, 2)
-END_JS_STATIC_METHOD()
-
-IMPLEMENT_JS_CLASS(CJS_Color,color)
-
-color::color(CJS_Object* pJSObject): CJS_EmbedObj(pJSObject)
-{
- m_crTransparent = CPWL_Color(COLORTYPE_TRANSPARENT);
- m_crBlack = CPWL_Color(COLORTYPE_GRAY, 0);
- m_crWhite = CPWL_Color(COLORTYPE_GRAY, 1);
- m_crRed = CPWL_Color(COLORTYPE_RGB, 1, 0 ,0);
- m_crGreen = CPWL_Color(COLORTYPE_RGB, 0, 1 ,0);
- m_crBlue = CPWL_Color(COLORTYPE_RGB, 0, 0 ,1);
- m_crCyan = CPWL_Color(COLORTYPE_CMYK, 1, 0 ,0, 0);
- m_crMagenta = CPWL_Color(COLORTYPE_CMYK, 0, 1 ,0, 0);
- m_crYellow = CPWL_Color(COLORTYPE_CMYK, 0, 0 ,1, 0);
- m_crDKGray = CPWL_Color(COLORTYPE_GRAY, 0.25);
- m_crGray = CPWL_Color(COLORTYPE_GRAY, 0.5);
- m_crLTGray = CPWL_Color(COLORTYPE_GRAY, 0.75);
-}
-
-color::~color(void)
-{
-}
-
-void color::ConvertPWLColorToArray(const CPWL_Color& color, CJS_Array& array)
-{
- switch (color.nColorType)
- {
- case COLORTYPE_TRANSPARENT:
- array.SetElement(0, CJS_Value(array.GetIsolate(), "T"));
- break;
- case COLORTYPE_GRAY:
- array.SetElement(0, CJS_Value(array.GetIsolate(),"G"));
- array.SetElement(1, CJS_Value(array.GetIsolate(),color.fColor1));
- break;
- case COLORTYPE_RGB:
- array.SetElement(0, CJS_Value(array.GetIsolate(),"RGB"));
- array.SetElement(1, CJS_Value(array.GetIsolate(),color.fColor1));
- array.SetElement(2, CJS_Value(array.GetIsolate(),color.fColor2));
- array.SetElement(3, CJS_Value(array.GetIsolate(),color.fColor3));
- break;
- case COLORTYPE_CMYK:
- array.SetElement(0, CJS_Value(array.GetIsolate(),"CMYK"));
- array.SetElement(1, CJS_Value(array.GetIsolate(),color.fColor1));
- array.SetElement(2, CJS_Value(array.GetIsolate(),color.fColor2));
- array.SetElement(3, CJS_Value(array.GetIsolate(),color.fColor3));
- array.SetElement(4, CJS_Value(array.GetIsolate(),color.fColor4));
- break;
- }
-}
-
-void color::ConvertArrayToPWLColor(CJS_Array& array, CPWL_Color& color)
-{
- int nArrayLen = array.GetLength();
- if (nArrayLen < 1) return;
-
- CJS_Value value(array.GetIsolate());
- CFX_ByteString sSpace;
- array.GetElement(0, value);
- sSpace = value;
-
- double d1 = 0;
- double d2 = 0;
- double d3 = 0;
- double d4 = 0;
-
- if (nArrayLen > 1)
- {
- array.GetElement(1, value);
- d1 = value;
- }
-
- if (nArrayLen > 2)
- {
- array.GetElement(2, value);
- d2 = value;
- }
-
- if (nArrayLen > 3)
- {
- array.GetElement(3, value);
- d3 = value;
- }
-
- if (nArrayLen > 4)
- {
- array.GetElement(4, value);
- d4 = value;
- }
-
- if (sSpace == "T")
- {
- color = CPWL_Color(COLORTYPE_TRANSPARENT);
- }
- else if (sSpace == "G")
- {
- color = CPWL_Color(COLORTYPE_GRAY, (FX_FLOAT)d1);
- }
- else if (sSpace == "RGB")
- {
- color = CPWL_Color(COLORTYPE_RGB, (FX_FLOAT)d1, (FX_FLOAT)d2, (FX_FLOAT)d3);
- }
- else if (sSpace == "CMYK")
- {
- color = CPWL_Color(COLORTYPE_CMYK, (FX_FLOAT)d1, (FX_FLOAT)d2, (FX_FLOAT)d3, (FX_FLOAT)d4);
- }
-}
-
-#define JS_IMPLEMENT_COLORPROP(prop, var)\
-FX_BOOL color::prop(OBJ_PROP_PARAMS)\
-{\
- CJS_Context* pContext = (CJS_Context*)cc;\
- v8::Isolate* isolate = pContext->GetJSRuntime()->GetIsolate();\
- if (vp.IsGetting())\
- {\
- CJS_Array array(isolate);\
- ConvertPWLColorToArray(var, array);\
- vp << array;\
- }\
- else\
- {\
- CJS_Array array(isolate);\
- if (!vp.ConvertToArray(array)) return FALSE;\
- ConvertArrayToPWLColor(array, var);\
- }\
- return TRUE;\
-}
-
-JS_IMPLEMENT_COLORPROP(transparent, m_crTransparent)
-JS_IMPLEMENT_COLORPROP(black, m_crBlack)
-JS_IMPLEMENT_COLORPROP(white, m_crWhite)
-JS_IMPLEMENT_COLORPROP(red, m_crRed)
-JS_IMPLEMENT_COLORPROP(green, m_crGreen)
-JS_IMPLEMENT_COLORPROP(blue, m_crBlue)
-JS_IMPLEMENT_COLORPROP(cyan, m_crCyan)
-JS_IMPLEMENT_COLORPROP(magenta, m_crMagenta)
-JS_IMPLEMENT_COLORPROP(yellow, m_crYellow)
-JS_IMPLEMENT_COLORPROP(dkGray, m_crDKGray)
-JS_IMPLEMENT_COLORPROP(gray, m_crGray)
-JS_IMPLEMENT_COLORPROP(ltGray, m_crLTGray)
-
-FX_BOOL color::convert(OBJ_METHOD_PARAMS)
-{
- v8::Isolate* isolate = GetIsolate(cc);
- int iSize = params.size();
- if (iSize < 2) return FALSE;
- CJS_Array aSource(isolate);
- if (!params[0].ConvertToArray(aSource)) return FALSE;
-
- CPWL_Color crSource;
- ConvertArrayToPWLColor(aSource, crSource);
-
- CFX_ByteString sDestSpace = params[1];
-
- int nColorType = COLORTYPE_TRANSPARENT;
-
- if (sDestSpace == "T")
- {
- nColorType = COLORTYPE_TRANSPARENT;
- }
- else if (sDestSpace == "G")
- {
- nColorType = COLORTYPE_GRAY;
- }
- else if (sDestSpace == "RGB")
- {
- nColorType = COLORTYPE_RGB;
- }
- else if (sDestSpace == "CMYK")
- {
- nColorType = COLORTYPE_CMYK;
- }
-
- CJS_Array aDest(isolate);
- CPWL_Color crDest = crSource;
- crDest.ConvertColorType(nColorType);
- ConvertPWLColorToArray(crDest, aDest);
- vRet = aDest;
-
- return TRUE;
-}
-
-FX_BOOL color::equal(OBJ_METHOD_PARAMS)
-{
- v8::Isolate* isolate = GetIsolate(cc);
- if (params.size() < 2) return FALSE;
-
- CJS_Array array1(isolate), array2(isolate);
-
- if (!params[0].ConvertToArray(array1)) return FALSE;
- if (!params[1].ConvertToArray(array2)) return FALSE;
-
- CPWL_Color color1;
- CPWL_Color color2;
-
- ConvertArrayToPWLColor(array1, color1);
- ConvertArrayToPWLColor(array2, color2);
-
- color1.ConvertColorType(color2.nColorType);
-
- vRet = color1 == color2;
- return TRUE;
-}
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/javascript/JavaScript.h"
+#include "../../include/javascript/IJavaScript.h"
+#include "../../include/javascript/JS_Define.h"
+#include "../../include/javascript/JS_Object.h"
+#include "../../include/javascript/JS_Value.h"
+#include "../../include/javascript/color.h"
+#include "../../include/javascript/JS_EventHandler.h"
+#include "../../include/javascript/JS_Context.h"
+#include "../../include/javascript/JS_Runtime.h"
+
+static v8::Isolate* GetIsolate(IFXJS_Context* cc)
+{
+ CJS_Context* pContext = (CJS_Context *)cc;
+ ASSERT(pContext != NULL);
+
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ ASSERT(pRuntime != NULL);
+
+ return pRuntime->GetIsolate();
+}
+/* -------------------------- color -------------------------- */
+
+BEGIN_JS_STATIC_CONST(CJS_Color)
+END_JS_STATIC_CONST()
+
+BEGIN_JS_STATIC_PROP(CJS_Color)
+ JS_STATIC_PROP_ENTRY(black)
+ JS_STATIC_PROP_ENTRY(blue)
+ JS_STATIC_PROP_ENTRY(cyan)
+ JS_STATIC_PROP_ENTRY(dkGray)
+ JS_STATIC_PROP_ENTRY(gray)
+ JS_STATIC_PROP_ENTRY(green)
+ JS_STATIC_PROP_ENTRY(ltGray)
+ JS_STATIC_PROP_ENTRY(magenta)
+ JS_STATIC_PROP_ENTRY(red)
+ JS_STATIC_PROP_ENTRY(transparent)
+ JS_STATIC_PROP_ENTRY(white)
+ JS_STATIC_PROP_ENTRY(yellow)
+END_JS_STATIC_PROP()
+
+BEGIN_JS_STATIC_METHOD(CJS_Color)
+ JS_STATIC_METHOD_ENTRY(convert, 2)
+ JS_STATIC_METHOD_ENTRY(equal, 2)
+END_JS_STATIC_METHOD()
+
+IMPLEMENT_JS_CLASS(CJS_Color,color)
+
+color::color(CJS_Object* pJSObject): CJS_EmbedObj(pJSObject)
+{
+ m_crTransparent = CPWL_Color(COLORTYPE_TRANSPARENT);
+ m_crBlack = CPWL_Color(COLORTYPE_GRAY, 0);
+ m_crWhite = CPWL_Color(COLORTYPE_GRAY, 1);
+ m_crRed = CPWL_Color(COLORTYPE_RGB, 1, 0 ,0);
+ m_crGreen = CPWL_Color(COLORTYPE_RGB, 0, 1 ,0);
+ m_crBlue = CPWL_Color(COLORTYPE_RGB, 0, 0 ,1);
+ m_crCyan = CPWL_Color(COLORTYPE_CMYK, 1, 0 ,0, 0);
+ m_crMagenta = CPWL_Color(COLORTYPE_CMYK, 0, 1 ,0, 0);
+ m_crYellow = CPWL_Color(COLORTYPE_CMYK, 0, 0 ,1, 0);
+ m_crDKGray = CPWL_Color(COLORTYPE_GRAY, 0.25);
+ m_crGray = CPWL_Color(COLORTYPE_GRAY, 0.5);
+ m_crLTGray = CPWL_Color(COLORTYPE_GRAY, 0.75);
+}
+
+color::~color(void)
+{
+}
+
+void color::ConvertPWLColorToArray(const CPWL_Color& color, CJS_Array& array)
+{
+ switch (color.nColorType)
+ {
+ case COLORTYPE_TRANSPARENT:
+ array.SetElement(0, CJS_Value(array.GetIsolate(), "T"));
+ break;
+ case COLORTYPE_GRAY:
+ array.SetElement(0, CJS_Value(array.GetIsolate(),"G"));
+ array.SetElement(1, CJS_Value(array.GetIsolate(),color.fColor1));
+ break;
+ case COLORTYPE_RGB:
+ array.SetElement(0, CJS_Value(array.GetIsolate(),"RGB"));
+ array.SetElement(1, CJS_Value(array.GetIsolate(),color.fColor1));
+ array.SetElement(2, CJS_Value(array.GetIsolate(),color.fColor2));
+ array.SetElement(3, CJS_Value(array.GetIsolate(),color.fColor3));
+ break;
+ case COLORTYPE_CMYK:
+ array.SetElement(0, CJS_Value(array.GetIsolate(),"CMYK"));
+ array.SetElement(1, CJS_Value(array.GetIsolate(),color.fColor1));
+ array.SetElement(2, CJS_Value(array.GetIsolate(),color.fColor2));
+ array.SetElement(3, CJS_Value(array.GetIsolate(),color.fColor3));
+ array.SetElement(4, CJS_Value(array.GetIsolate(),color.fColor4));
+ break;
+ }
+}
+
+void color::ConvertArrayToPWLColor(CJS_Array& array, CPWL_Color& color)
+{
+ int nArrayLen = array.GetLength();
+ if (nArrayLen < 1) return;
+
+ CJS_Value value(array.GetIsolate());
+ CFX_ByteString sSpace;
+ array.GetElement(0, value);
+ sSpace = value;
+
+ double d1 = 0;
+ double d2 = 0;
+ double d3 = 0;
+ double d4 = 0;
+
+ if (nArrayLen > 1)
+ {
+ array.GetElement(1, value);
+ d1 = value;
+ }
+
+ if (nArrayLen > 2)
+ {
+ array.GetElement(2, value);
+ d2 = value;
+ }
+
+ if (nArrayLen > 3)
+ {
+ array.GetElement(3, value);
+ d3 = value;
+ }
+
+ if (nArrayLen > 4)
+ {
+ array.GetElement(4, value);
+ d4 = value;
+ }
+
+ if (sSpace == "T")
+ {
+ color = CPWL_Color(COLORTYPE_TRANSPARENT);
+ }
+ else if (sSpace == "G")
+ {
+ color = CPWL_Color(COLORTYPE_GRAY, (FX_FLOAT)d1);
+ }
+ else if (sSpace == "RGB")
+ {
+ color = CPWL_Color(COLORTYPE_RGB, (FX_FLOAT)d1, (FX_FLOAT)d2, (FX_FLOAT)d3);
+ }
+ else if (sSpace == "CMYK")
+ {
+ color = CPWL_Color(COLORTYPE_CMYK, (FX_FLOAT)d1, (FX_FLOAT)d2, (FX_FLOAT)d3, (FX_FLOAT)d4);
+ }
+}
+
+#define JS_IMPLEMENT_COLORPROP(prop, var)\
+FX_BOOL color::prop(OBJ_PROP_PARAMS)\
+{\
+ CJS_Context* pContext = (CJS_Context*)cc;\
+ v8::Isolate* isolate = pContext->GetJSRuntime()->GetIsolate();\
+ if (vp.IsGetting())\
+ {\
+ CJS_Array array(isolate);\
+ ConvertPWLColorToArray(var, array);\
+ vp << array;\
+ }\
+ else\
+ {\
+ CJS_Array array(isolate);\
+ if (!vp.ConvertToArray(array)) return FALSE;\
+ ConvertArrayToPWLColor(array, var);\
+ }\
+ return TRUE;\
+}
+
+JS_IMPLEMENT_COLORPROP(transparent, m_crTransparent)
+JS_IMPLEMENT_COLORPROP(black, m_crBlack)
+JS_IMPLEMENT_COLORPROP(white, m_crWhite)
+JS_IMPLEMENT_COLORPROP(red, m_crRed)
+JS_IMPLEMENT_COLORPROP(green, m_crGreen)
+JS_IMPLEMENT_COLORPROP(blue, m_crBlue)
+JS_IMPLEMENT_COLORPROP(cyan, m_crCyan)
+JS_IMPLEMENT_COLORPROP(magenta, m_crMagenta)
+JS_IMPLEMENT_COLORPROP(yellow, m_crYellow)
+JS_IMPLEMENT_COLORPROP(dkGray, m_crDKGray)
+JS_IMPLEMENT_COLORPROP(gray, m_crGray)
+JS_IMPLEMENT_COLORPROP(ltGray, m_crLTGray)
+
+FX_BOOL color::convert(OBJ_METHOD_PARAMS)
+{
+ v8::Isolate* isolate = GetIsolate(cc);
+ int iSize = params.size();
+ if (iSize < 2) return FALSE;
+ CJS_Array aSource(isolate);
+ if (!params[0].ConvertToArray(aSource)) return FALSE;
+
+ CPWL_Color crSource;
+ ConvertArrayToPWLColor(aSource, crSource);
+
+ CFX_ByteString sDestSpace = params[1];
+
+ int nColorType = COLORTYPE_TRANSPARENT;
+
+ if (sDestSpace == "T")
+ {
+ nColorType = COLORTYPE_TRANSPARENT;
+ }
+ else if (sDestSpace == "G")
+ {
+ nColorType = COLORTYPE_GRAY;
+ }
+ else if (sDestSpace == "RGB")
+ {
+ nColorType = COLORTYPE_RGB;
+ }
+ else if (sDestSpace == "CMYK")
+ {
+ nColorType = COLORTYPE_CMYK;
+ }
+
+ CJS_Array aDest(isolate);
+ CPWL_Color crDest = crSource;
+ crDest.ConvertColorType(nColorType);
+ ConvertPWLColorToArray(crDest, aDest);
+ vRet = aDest;
+
+ return TRUE;
+}
+
+FX_BOOL color::equal(OBJ_METHOD_PARAMS)
+{
+ v8::Isolate* isolate = GetIsolate(cc);
+ if (params.size() < 2) return FALSE;
+
+ CJS_Array array1(isolate), array2(isolate);
+
+ if (!params[0].ConvertToArray(array1)) return FALSE;
+ if (!params[1].ConvertToArray(array2)) return FALSE;
+
+ CPWL_Color color1;
+ CPWL_Color color2;
+
+ ConvertArrayToPWLColor(array1, color1);
+ ConvertArrayToPWLColor(array2, color2);
+
+ color1.ConvertColorType(color2.nColorType);
+
+ vRet = color1 == color2;
+ return TRUE;
+}
+
diff --git a/fpdfsdk/src/javascript/console.cpp b/fpdfsdk/src/javascript/console.cpp
index 25e5559a06..350b4e1dcc 100644
--- a/fpdfsdk/src/javascript/console.cpp
+++ b/fpdfsdk/src/javascript/console.cpp
@@ -1,78 +1,78 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/javascript/JavaScript.h"
-#include "../../include/javascript/IJavaScript.h"
-#include "../../include/javascript/JS_Define.h"
-#include "../../include/javascript/JS_Object.h"
-#include "../../include/javascript/JS_Value.h"
-#include "../../include/javascript/console.h"
-//#include "../../include/javascript/JS_Module.h"
-#include "../../include/javascript/JS_EventHandler.h"
-//#include "../../include/javascript/JS_ResMgr.h"
-#include "../../include/javascript/JS_Context.h"
-
-/* ------------------------ console ------------------------ */
-
-BEGIN_JS_STATIC_CONST(CJS_Console)
-END_JS_STATIC_CONST()
-
-BEGIN_JS_STATIC_PROP(CJS_Console)
-END_JS_STATIC_PROP()
-
-BEGIN_JS_STATIC_METHOD(CJS_Console)
- JS_STATIC_METHOD_ENTRY(clear, 0)
- JS_STATIC_METHOD_ENTRY(hide, 0)
- JS_STATIC_METHOD_ENTRY(println, 1)
- JS_STATIC_METHOD_ENTRY(show, 0)
-END_JS_STATIC_METHOD()
-
-IMPLEMENT_JS_CLASS(CJS_Console,console)
-
-#define MAXCONSOLECONTENTS 10000
-
-console::console(CJS_Object* pJSObject): CJS_EmbedObj(pJSObject)
-{
-}
-
-console::~console()
-{
-}
-
-FX_BOOL console::clear(OBJ_METHOD_PARAMS)
-{
-
-
-
- return TRUE;
-}
-
-FX_BOOL console::hide(OBJ_METHOD_PARAMS)
-{
-
-
-
-
- return TRUE;
-}
-
-FX_BOOL console::println(OBJ_METHOD_PARAMS)
-{
- if (params.size() < 1)
- {
- return FALSE;
- }
-
- return TRUE;
-}
-
-FX_BOOL console::show(OBJ_METHOD_PARAMS)
-{
- return TRUE;
-}
-
-
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/javascript/JavaScript.h"
+#include "../../include/javascript/IJavaScript.h"
+#include "../../include/javascript/JS_Define.h"
+#include "../../include/javascript/JS_Object.h"
+#include "../../include/javascript/JS_Value.h"
+#include "../../include/javascript/console.h"
+//#include "../../include/javascript/JS_Module.h"
+#include "../../include/javascript/JS_EventHandler.h"
+//#include "../../include/javascript/JS_ResMgr.h"
+#include "../../include/javascript/JS_Context.h"
+
+/* ------------------------ console ------------------------ */
+
+BEGIN_JS_STATIC_CONST(CJS_Console)
+END_JS_STATIC_CONST()
+
+BEGIN_JS_STATIC_PROP(CJS_Console)
+END_JS_STATIC_PROP()
+
+BEGIN_JS_STATIC_METHOD(CJS_Console)
+ JS_STATIC_METHOD_ENTRY(clear, 0)
+ JS_STATIC_METHOD_ENTRY(hide, 0)
+ JS_STATIC_METHOD_ENTRY(println, 1)
+ JS_STATIC_METHOD_ENTRY(show, 0)
+END_JS_STATIC_METHOD()
+
+IMPLEMENT_JS_CLASS(CJS_Console,console)
+
+#define MAXCONSOLECONTENTS 10000
+
+console::console(CJS_Object* pJSObject): CJS_EmbedObj(pJSObject)
+{
+}
+
+console::~console()
+{
+}
+
+FX_BOOL console::clear(OBJ_METHOD_PARAMS)
+{
+
+
+
+ return TRUE;
+}
+
+FX_BOOL console::hide(OBJ_METHOD_PARAMS)
+{
+
+
+
+
+ return TRUE;
+}
+
+FX_BOOL console::println(OBJ_METHOD_PARAMS)
+{
+ if (params.size() < 1)
+ {
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+FX_BOOL console::show(OBJ_METHOD_PARAMS)
+{
+ return TRUE;
+}
+
+
+
diff --git a/fpdfsdk/src/javascript/event.cpp b/fpdfsdk/src/javascript/event.cpp
index 9168a2e0cf..5188765a04 100644
--- a/fpdfsdk/src/javascript/event.cpp
+++ b/fpdfsdk/src/javascript/event.cpp
@@ -1,379 +1,379 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/javascript/JavaScript.h"
-#include "../../include/javascript/IJavaScript.h"
-#include "../../include/javascript/JS_Define.h"
-#include "../../include/javascript/JS_Object.h"
-#include "../../include/javascript/JS_Value.h"
-#include "../../include/javascript/JS_EventHandler.h"
-//#include "../include/JS_ResMgr.h"
-#include "../../include/javascript/JS_Context.h"
-#include "../../include/javascript/event.h"
-#include "../../include/javascript/Field.h"
-
-/* -------------------------- event -------------------------- */
-
-BEGIN_JS_STATIC_CONST(CJS_Event)
-END_JS_STATIC_CONST()
-
-BEGIN_JS_STATIC_PROP(CJS_Event)
- JS_STATIC_PROP_ENTRY(change)
- JS_STATIC_PROP_ENTRY(changeEx)
- JS_STATIC_PROP_ENTRY(commitKey)
- JS_STATIC_PROP_ENTRY(fieldFull)
- JS_STATIC_PROP_ENTRY(keyDown)
- JS_STATIC_PROP_ENTRY(modifier)
- JS_STATIC_PROP_ENTRY(name)
- JS_STATIC_PROP_ENTRY(rc)
- JS_STATIC_PROP_ENTRY(richChange)
- JS_STATIC_PROP_ENTRY(richChangeEx)
- JS_STATIC_PROP_ENTRY(richValue)
- JS_STATIC_PROP_ENTRY(selEnd)
- JS_STATIC_PROP_ENTRY(selStart)
- JS_STATIC_PROP_ENTRY(shift)
- JS_STATIC_PROP_ENTRY(source)
- JS_STATIC_PROP_ENTRY(target)
- JS_STATIC_PROP_ENTRY(targetName)
- JS_STATIC_PROP_ENTRY(type)
- JS_STATIC_PROP_ENTRY(value)
- JS_STATIC_PROP_ENTRY(willCommit)
-END_JS_STATIC_PROP()
-
-BEGIN_JS_STATIC_METHOD(CJS_Event)
-END_JS_STATIC_METHOD()
-
-IMPLEMENT_JS_CLASS(CJS_Event,event)
-
-event::event(CJS_Object * pJsObject) : CJS_EmbedObj(pJsObject)
-{
-}
-
-event::~event(void)
-{
-}
-
-FX_BOOL event::change(OBJ_PROP_PARAMS)
-{
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_EventHandler* pEvent = pContext->GetEventHandler();
- ASSERT(pEvent != NULL);
-
- CFX_WideString &wChange = pEvent->Change();
- if (vp.IsSetting())
- {
- if (vp.GetType() == VT_string)
- vp >> wChange;
- }
- else
- {
- vp << wChange;
- }
- return TRUE;
-}
-
-FX_BOOL event::changeEx(OBJ_PROP_PARAMS)
-{
- if (!vp.IsGetting())return FALSE;
-
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_EventHandler* pEvent = pContext->GetEventHandler();
- ASSERT(pEvent != NULL);
-
- vp << pEvent->ChangeEx();
- return TRUE;
-}
-
-FX_BOOL event::commitKey(OBJ_PROP_PARAMS)
-{
- if (!vp.IsGetting())return FALSE;
-
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_EventHandler* pEvent = pContext->GetEventHandler();
- ASSERT(pEvent != NULL);
-
- vp << pEvent->CommitKey();
- return TRUE;
-}
-
-FX_BOOL event::fieldFull(OBJ_PROP_PARAMS)
-{
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_EventHandler* pEvent = pContext->GetEventHandler();
- ASSERT(pEvent != NULL);
-
- if (!vp.IsGetting() && wcscmp((const wchar_t*)pEvent->Name(),L"Keystroke") != 0)
- return FALSE;
-
- if (pEvent->FieldFull())
- vp << TRUE;
- else
- vp << FALSE;
- return TRUE;
-}
-
-FX_BOOL event::keyDown(OBJ_PROP_PARAMS)
-{
- if (!vp.IsGetting())return FALSE;
-
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_EventHandler* pEvent = pContext->GetEventHandler();
- ASSERT(pEvent != NULL);
-
- if (pEvent->KeyDown())
- vp << TRUE;
- else
- vp << FALSE;
- return TRUE;
-}
-
-FX_BOOL event::modifier(OBJ_PROP_PARAMS)
-{
- if (!vp.IsGetting())return FALSE;
-
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_EventHandler* pEvent = pContext->GetEventHandler();
- ASSERT(pEvent != NULL);
-
- if (pEvent->Modifier())
- vp << TRUE;
- else
- vp << FALSE;
- return TRUE;
-}
-
-FX_BOOL event::name(OBJ_PROP_PARAMS)
-{
- if (!vp.IsGetting())return FALSE;
-
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_EventHandler* pEvent = pContext->GetEventHandler();
- ASSERT(pEvent != NULL);
-
- vp << pEvent->Name();
- return TRUE;
-}
-
-FX_BOOL event::rc(OBJ_PROP_PARAMS)
-{
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_EventHandler* pEvent = pContext->GetEventHandler();
- ASSERT(pEvent != NULL);
-
- FX_BOOL &bRc = pEvent->Rc();
- if (vp.IsSetting())
- {
- vp>>bRc;
- }
- else
- {
- vp<<bRc;
- }
- return TRUE;
-}
-
-FX_BOOL event::richChange(OBJ_PROP_PARAMS)
-{
- return TRUE;
- if (vp.IsSetting())
- {
- }
- else
- {
- ;
- }
- return TRUE;
-}
-
-FX_BOOL event::richChangeEx(OBJ_PROP_PARAMS)
-{
- return TRUE;
- if (vp.IsSetting())
- {
- }
- else
- {
- ;
- }
- return TRUE;
-}
-
-
-FX_BOOL event::richValue(OBJ_PROP_PARAMS)
-{
- return TRUE;
- if (vp.IsSetting())
- {
- }
- else
- {
- ;
- }
- return TRUE;
-}
-
-FX_BOOL event::selEnd(OBJ_PROP_PARAMS)
-{
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_EventHandler* pEvent = pContext->GetEventHandler();
- ASSERT(pEvent != NULL);
-
- if (wcscmp((const wchar_t*)pEvent->Name(),L"Keystroke") != 0)
- {
- return TRUE;
- }
-
- int &iSelEnd = pEvent->SelEnd();
- if (vp.IsSetting())
- {
- vp >> iSelEnd;
- }
- else
- {
- vp << iSelEnd;
- }
- return TRUE;
-}
-
-FX_BOOL event::selStart(OBJ_PROP_PARAMS)
-{
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_EventHandler* pEvent = pContext->GetEventHandler();
- ASSERT(pEvent != NULL);
-
- if (wcscmp((const wchar_t*)pEvent->Name(),L"Keystroke") != 0)
- {
- return TRUE;
- }
- int &iSelStart = pEvent->SelStart();
- if (vp.IsSetting())
- {
- vp >> iSelStart;
- }
- else
- {
- vp << iSelStart;
- }
- return TRUE;
-}
-
-FX_BOOL event::shift(OBJ_PROP_PARAMS)
-{
- if (!vp.IsGetting())return FALSE;
-
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_EventHandler* pEvent = pContext->GetEventHandler();
- ASSERT(pEvent != NULL);
-
- if (pEvent->Shift())
- vp << TRUE;
- else
- vp << FALSE;
- return TRUE;
-}
-
-FX_BOOL event::source(OBJ_PROP_PARAMS)
-{
- if (!vp.IsGetting())return FALSE;
-
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_EventHandler* pEvent = pContext->GetEventHandler();
- ASSERT(pEvent != NULL);
-
- vp << pEvent->Source()->GetJSObject();
- return TRUE;
-}
-
-FX_BOOL event::target(OBJ_PROP_PARAMS)
-{
- if (!vp.IsGetting())return FALSE;
-
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_EventHandler* pEvent = pContext->GetEventHandler();
- ASSERT(pEvent != NULL);
-
- vp<<pEvent->Target_Field()->GetJSObject();
- return TRUE;
-}
-
-FX_BOOL event::targetName(OBJ_PROP_PARAMS)
-{
- if (!vp.IsGetting())return FALSE;
-
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_EventHandler* pEvent = pContext->GetEventHandler();
- ASSERT(pEvent != NULL);
-
- vp << pEvent->TargetName();
- return TRUE;
-}
-
-FX_BOOL event::type(OBJ_PROP_PARAMS)
-{
- if (!vp.IsGetting())return FALSE;
-
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_EventHandler* pEvent = pContext->GetEventHandler();
- ASSERT(pEvent != NULL);
-
- vp << pEvent->Type();
- return TRUE;
-}
-
-FX_BOOL event::value(OBJ_PROP_PARAMS)
-{
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_EventHandler* pEvent = pContext->GetEventHandler();
- ASSERT(pEvent != NULL);
-
- if (wcscmp((const wchar_t*)pEvent->Type(),L"Field") != 0)
- return FALSE;
- if(!pEvent->m_pValue)
- return FALSE;
- CFX_WideString & val = pEvent->Value();
- if (vp.IsSetting())
- {
- val = vp;
- }
- else
- {
- vp << val;
- }
- return TRUE;
-}
-
-FX_BOOL event::willCommit(OBJ_PROP_PARAMS)
-{
- if (!vp.IsGetting())return FALSE;
-
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
- CJS_EventHandler* pEvent = pContext->GetEventHandler();
- ASSERT(pEvent != NULL);
-
- if (pEvent->WillCommit())
- vp << TRUE;
- else
- vp << FALSE;
- return TRUE;
-}
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/javascript/JavaScript.h"
+#include "../../include/javascript/IJavaScript.h"
+#include "../../include/javascript/JS_Define.h"
+#include "../../include/javascript/JS_Object.h"
+#include "../../include/javascript/JS_Value.h"
+#include "../../include/javascript/JS_EventHandler.h"
+//#include "../include/JS_ResMgr.h"
+#include "../../include/javascript/JS_Context.h"
+#include "../../include/javascript/event.h"
+#include "../../include/javascript/Field.h"
+
+/* -------------------------- event -------------------------- */
+
+BEGIN_JS_STATIC_CONST(CJS_Event)
+END_JS_STATIC_CONST()
+
+BEGIN_JS_STATIC_PROP(CJS_Event)
+ JS_STATIC_PROP_ENTRY(change)
+ JS_STATIC_PROP_ENTRY(changeEx)
+ JS_STATIC_PROP_ENTRY(commitKey)
+ JS_STATIC_PROP_ENTRY(fieldFull)
+ JS_STATIC_PROP_ENTRY(keyDown)
+ JS_STATIC_PROP_ENTRY(modifier)
+ JS_STATIC_PROP_ENTRY(name)
+ JS_STATIC_PROP_ENTRY(rc)
+ JS_STATIC_PROP_ENTRY(richChange)
+ JS_STATIC_PROP_ENTRY(richChangeEx)
+ JS_STATIC_PROP_ENTRY(richValue)
+ JS_STATIC_PROP_ENTRY(selEnd)
+ JS_STATIC_PROP_ENTRY(selStart)
+ JS_STATIC_PROP_ENTRY(shift)
+ JS_STATIC_PROP_ENTRY(source)
+ JS_STATIC_PROP_ENTRY(target)
+ JS_STATIC_PROP_ENTRY(targetName)
+ JS_STATIC_PROP_ENTRY(type)
+ JS_STATIC_PROP_ENTRY(value)
+ JS_STATIC_PROP_ENTRY(willCommit)
+END_JS_STATIC_PROP()
+
+BEGIN_JS_STATIC_METHOD(CJS_Event)
+END_JS_STATIC_METHOD()
+
+IMPLEMENT_JS_CLASS(CJS_Event,event)
+
+event::event(CJS_Object * pJsObject) : CJS_EmbedObj(pJsObject)
+{
+}
+
+event::~event(void)
+{
+}
+
+FX_BOOL event::change(OBJ_PROP_PARAMS)
+{
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CJS_EventHandler* pEvent = pContext->GetEventHandler();
+ ASSERT(pEvent != NULL);
+
+ CFX_WideString &wChange = pEvent->Change();
+ if (vp.IsSetting())
+ {
+ if (vp.GetType() == VT_string)
+ vp >> wChange;
+ }
+ else
+ {
+ vp << wChange;
+ }
+ return TRUE;
+}
+
+FX_BOOL event::changeEx(OBJ_PROP_PARAMS)
+{
+ if (!vp.IsGetting())return FALSE;
+
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CJS_EventHandler* pEvent = pContext->GetEventHandler();
+ ASSERT(pEvent != NULL);
+
+ vp << pEvent->ChangeEx();
+ return TRUE;
+}
+
+FX_BOOL event::commitKey(OBJ_PROP_PARAMS)
+{
+ if (!vp.IsGetting())return FALSE;
+
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CJS_EventHandler* pEvent = pContext->GetEventHandler();
+ ASSERT(pEvent != NULL);
+
+ vp << pEvent->CommitKey();
+ return TRUE;
+}
+
+FX_BOOL event::fieldFull(OBJ_PROP_PARAMS)
+{
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CJS_EventHandler* pEvent = pContext->GetEventHandler();
+ ASSERT(pEvent != NULL);
+
+ if (!vp.IsGetting() && wcscmp((const wchar_t*)pEvent->Name(),L"Keystroke") != 0)
+ return FALSE;
+
+ if (pEvent->FieldFull())
+ vp << TRUE;
+ else
+ vp << FALSE;
+ return TRUE;
+}
+
+FX_BOOL event::keyDown(OBJ_PROP_PARAMS)
+{
+ if (!vp.IsGetting())return FALSE;
+
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CJS_EventHandler* pEvent = pContext->GetEventHandler();
+ ASSERT(pEvent != NULL);
+
+ if (pEvent->KeyDown())
+ vp << TRUE;
+ else
+ vp << FALSE;
+ return TRUE;
+}
+
+FX_BOOL event::modifier(OBJ_PROP_PARAMS)
+{
+ if (!vp.IsGetting())return FALSE;
+
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CJS_EventHandler* pEvent = pContext->GetEventHandler();
+ ASSERT(pEvent != NULL);
+
+ if (pEvent->Modifier())
+ vp << TRUE;
+ else
+ vp << FALSE;
+ return TRUE;
+}
+
+FX_BOOL event::name(OBJ_PROP_PARAMS)
+{
+ if (!vp.IsGetting())return FALSE;
+
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CJS_EventHandler* pEvent = pContext->GetEventHandler();
+ ASSERT(pEvent != NULL);
+
+ vp << pEvent->Name();
+ return TRUE;
+}
+
+FX_BOOL event::rc(OBJ_PROP_PARAMS)
+{
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CJS_EventHandler* pEvent = pContext->GetEventHandler();
+ ASSERT(pEvent != NULL);
+
+ FX_BOOL &bRc = pEvent->Rc();
+ if (vp.IsSetting())
+ {
+ vp>>bRc;
+ }
+ else
+ {
+ vp<<bRc;
+ }
+ return TRUE;
+}
+
+FX_BOOL event::richChange(OBJ_PROP_PARAMS)
+{
+ return TRUE;
+ if (vp.IsSetting())
+ {
+ }
+ else
+ {
+ ;
+ }
+ return TRUE;
+}
+
+FX_BOOL event::richChangeEx(OBJ_PROP_PARAMS)
+{
+ return TRUE;
+ if (vp.IsSetting())
+ {
+ }
+ else
+ {
+ ;
+ }
+ return TRUE;
+}
+
+
+FX_BOOL event::richValue(OBJ_PROP_PARAMS)
+{
+ return TRUE;
+ if (vp.IsSetting())
+ {
+ }
+ else
+ {
+ ;
+ }
+ return TRUE;
+}
+
+FX_BOOL event::selEnd(OBJ_PROP_PARAMS)
+{
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CJS_EventHandler* pEvent = pContext->GetEventHandler();
+ ASSERT(pEvent != NULL);
+
+ if (wcscmp((const wchar_t*)pEvent->Name(),L"Keystroke") != 0)
+ {
+ return TRUE;
+ }
+
+ int &iSelEnd = pEvent->SelEnd();
+ if (vp.IsSetting())
+ {
+ vp >> iSelEnd;
+ }
+ else
+ {
+ vp << iSelEnd;
+ }
+ return TRUE;
+}
+
+FX_BOOL event::selStart(OBJ_PROP_PARAMS)
+{
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CJS_EventHandler* pEvent = pContext->GetEventHandler();
+ ASSERT(pEvent != NULL);
+
+ if (wcscmp((const wchar_t*)pEvent->Name(),L"Keystroke") != 0)
+ {
+ return TRUE;
+ }
+ int &iSelStart = pEvent->SelStart();
+ if (vp.IsSetting())
+ {
+ vp >> iSelStart;
+ }
+ else
+ {
+ vp << iSelStart;
+ }
+ return TRUE;
+}
+
+FX_BOOL event::shift(OBJ_PROP_PARAMS)
+{
+ if (!vp.IsGetting())return FALSE;
+
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CJS_EventHandler* pEvent = pContext->GetEventHandler();
+ ASSERT(pEvent != NULL);
+
+ if (pEvent->Shift())
+ vp << TRUE;
+ else
+ vp << FALSE;
+ return TRUE;
+}
+
+FX_BOOL event::source(OBJ_PROP_PARAMS)
+{
+ if (!vp.IsGetting())return FALSE;
+
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CJS_EventHandler* pEvent = pContext->GetEventHandler();
+ ASSERT(pEvent != NULL);
+
+ vp << pEvent->Source()->GetJSObject();
+ return TRUE;
+}
+
+FX_BOOL event::target(OBJ_PROP_PARAMS)
+{
+ if (!vp.IsGetting())return FALSE;
+
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CJS_EventHandler* pEvent = pContext->GetEventHandler();
+ ASSERT(pEvent != NULL);
+
+ vp<<pEvent->Target_Field()->GetJSObject();
+ return TRUE;
+}
+
+FX_BOOL event::targetName(OBJ_PROP_PARAMS)
+{
+ if (!vp.IsGetting())return FALSE;
+
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CJS_EventHandler* pEvent = pContext->GetEventHandler();
+ ASSERT(pEvent != NULL);
+
+ vp << pEvent->TargetName();
+ return TRUE;
+}
+
+FX_BOOL event::type(OBJ_PROP_PARAMS)
+{
+ if (!vp.IsGetting())return FALSE;
+
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CJS_EventHandler* pEvent = pContext->GetEventHandler();
+ ASSERT(pEvent != NULL);
+
+ vp << pEvent->Type();
+ return TRUE;
+}
+
+FX_BOOL event::value(OBJ_PROP_PARAMS)
+{
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CJS_EventHandler* pEvent = pContext->GetEventHandler();
+ ASSERT(pEvent != NULL);
+
+ if (wcscmp((const wchar_t*)pEvent->Type(),L"Field") != 0)
+ return FALSE;
+ if(!pEvent->m_pValue)
+ return FALSE;
+ CFX_WideString & val = pEvent->Value();
+ if (vp.IsSetting())
+ {
+ val = vp;
+ }
+ else
+ {
+ vp << val;
+ }
+ return TRUE;
+}
+
+FX_BOOL event::willCommit(OBJ_PROP_PARAMS)
+{
+ if (!vp.IsGetting())return FALSE;
+
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+ CJS_EventHandler* pEvent = pContext->GetEventHandler();
+ ASSERT(pEvent != NULL);
+
+ if (pEvent->WillCommit())
+ vp << TRUE;
+ else
+ vp << FALSE;
+ return TRUE;
+}
+
diff --git a/fpdfsdk/src/javascript/global.cpp b/fpdfsdk/src/javascript/global.cpp
index 984ba55cb4..295a8d49af 100644
--- a/fpdfsdk/src/javascript/global.cpp
+++ b/fpdfsdk/src/javascript/global.cpp
@@ -1,550 +1,550 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/javascript/JavaScript.h"
-#include "../../include/javascript/IJavaScript.h"
-#include "../../include/javascript/JS_Define.h"
-#include "../../include/javascript/JS_Object.h"
-#include "../../include/javascript/JS_Value.h"
-#include "../../include/javascript/JS_GlobalData.h"
-#include "../../include/javascript/global.h"
-#include "../../include/javascript/JS_EventHandler.h"
-#include "../../include/javascript/JS_Context.h"
-
-/* ---------------------------- global ---------------------------- */
-
-BEGIN_JS_STATIC_CONST(CJS_Global)
-END_JS_STATIC_CONST()
-
-BEGIN_JS_STATIC_PROP(CJS_Global)
-END_JS_STATIC_PROP()
-
-BEGIN_JS_STATIC_METHOD(CJS_Global)
- JS_STATIC_METHOD_ENTRY(setPersistent, 2)
-END_JS_STATIC_METHOD()
-
-IMPLEMENT_SPECIAL_JS_CLASS(CJS_Global, global_alternate, global);
-
-FX_BOOL CJS_Global::InitInstance(IFXJS_Context* cc)
-{
- CJS_Context* pContext = (CJS_Context*)cc;
- ASSERT(pContext != NULL);
-
- global_alternate* pGlobal = (global_alternate*)GetEmbedObject();
- ASSERT(pGlobal != NULL);
-
- pGlobal->Initial(pContext->GetReaderApp());
-
- return TRUE;
-};
-
-global_alternate::global_alternate(CJS_Object* pJSObject)
- : CJS_EmbedObj(pJSObject),
- m_pApp(NULL)
-{
-}
-
-global_alternate::~global_alternate(void)
-{
- ASSERT(m_pApp != NULL);
-
-// CommitGlobalPersisitentVariables();
- DestroyGlobalPersisitentVariables();
-
- CJS_RuntimeFactory* pFactory = m_pApp->m_pJSRuntimeFactory;
- ASSERT(pFactory);
-
- pFactory->ReleaseGlobalData();
-}
-
-void global_alternate::Initial(CPDFDoc_Environment* pApp)
-{
- m_pApp = pApp;
-
- CJS_RuntimeFactory* pFactory = pApp->m_pJSRuntimeFactory;
- ASSERT(pFactory);
- m_pGlobalData = pFactory->NewGlobalData(pApp);
- UpdateGlobalPersistentVariables();
-}
-
-FX_BOOL global_alternate::QueryProperty(FX_LPCWSTR propname)
-{
- return CFX_WideString(propname) != L"setPersistent";
-}
-
-FX_BOOL global_alternate::DelProperty(IFXJS_Context* cc, FX_LPCWSTR propname, JS_ErrorString& sError)
-{
- js_global_data* pData = NULL;
- CFX_ByteString sPropName = CFX_ByteString::FromUnicode(propname);
-
- if (m_mapGlobal.Lookup(sPropName, (FX_LPVOID&)pData))
- {
- pData->bDeleted = TRUE;
- return TRUE;
- }
-
- return FALSE;
-}
-
-FX_BOOL global_alternate::DoProperty(IFXJS_Context* cc, FX_LPCWSTR propname, CJS_PropValue& vp, JS_ErrorString& sError)
-{
- if (vp.IsSetting())
- {
- CFX_ByteString sPropName = CFX_ByteString::FromUnicode(propname);
- switch (vp.GetType())
- {
- case VT_number:
- {
- double dData;
- vp >> dData;
- return SetGlobalVariables(sPropName, JS_GLOBALDATA_TYPE_NUMBER, dData, false, "", v8::Handle<v8::Object>(), FALSE);
- }
- case VT_boolean:
- {
- bool bData;
- vp >> bData;
- return SetGlobalVariables(sPropName, JS_GLOBALDATA_TYPE_BOOLEAN, 0, (bool)vp, "", v8::Handle<v8::Object>(), FALSE);
- }
- case VT_string:
- {
- CFX_ByteString sData;
- vp >> sData;
- return SetGlobalVariables(sPropName, JS_GLOBALDATA_TYPE_STRING, 0, false, sData, v8::Handle<v8::Object>(), FALSE);
- }
- case VT_object:
- {
- JSObject pData = (JSObject)vp;
- return SetGlobalVariables(sPropName, JS_GLOBALDATA_TYPE_OBJECT, 0, false, "", pData, FALSE);
-// else
-// {
-// if (vp.IsArrayObject())
-// {
-// CJS_Array array;
-// vp.ConvertToArray(array);
-// return SetGlobalVariables(sPropName, JS_GLOBALDATA_TYPE_OBJECT, 0, false, "",
-// (Dobject*)(Darray*)array, FALSE);
-// }
-// else
-// return FALSE;
-// }
- }
- case VT_null:
- {
- return SetGlobalVariables(sPropName, JS_GLOBALDATA_TYPE_NULL, 0, false, "", v8::Handle<v8::Object>(), FALSE);
- }
- case VT_undefined:
- {
- DelProperty(cc, propname, sError);
- return TRUE;
- }
- default:
- return FALSE;
- }
- }
- else
- {
- js_global_data* pData = NULL;
- CFX_ByteString sPropName = CFX_ByteString::FromUnicode(propname);
-
- if (m_mapGlobal.Lookup(sPropName, (FX_LPVOID&)pData))
- {
- if (pData)
- {
- if (!pData->bDeleted)
- {
- switch (pData->nType)
- {
- case JS_GLOBALDATA_TYPE_NUMBER:
- vp << pData->dData;
- break;
- case JS_GLOBALDATA_TYPE_BOOLEAN:
- vp << pData->bData;
- break;
- case JS_GLOBALDATA_TYPE_STRING:
- vp << pData->sData;
- break;
- case JS_GLOBALDATA_TYPE_OBJECT:
- {
- v8::Handle<v8::Object> obj = v8::Local<v8::Object>::New(vp.GetIsolate(),pData->pData);
- vp << obj;
- break;
- }
- case JS_GLOBALDATA_TYPE_NULL:
- vp.SetNull();
- break;
- default:
- return FALSE;
- }
- return TRUE;
- }
- else
- {
- return TRUE;
- }
- }
- else
- {
- vp.SetNull();
- return TRUE;
- }
- }
- else
- {
- vp.SetNull();
- return TRUE;
- }
- }
-
- return FALSE;
-}
-
-FX_BOOL global_alternate::setPersistent(OBJ_METHOD_PARAMS)
-{
- if (params.size() != 2)
- {
- //sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
- return FALSE;
- }
-
- CFX_ByteString sName = params[0];
-
- js_global_data* pData = NULL;
- if (m_mapGlobal.Lookup(sName, (FX_LPVOID&)pData))
- {
- if (pData && !pData->bDeleted)
- {
- pData->bPersistent = (bool)params[1];
- return TRUE;
- }
- }
-
- //sError = JSGetStringFromID(IDS_JSPARAM_INCORRECT);
- return FALSE;
-}
-
-void global_alternate::UpdateGlobalPersistentVariables()
-{
- ASSERT(m_pGlobalData != NULL);
-
- for (int i=0,sz=m_pGlobalData->GetSize(); i<sz; i++)
- {
- CJS_GlobalData_Element* pData = m_pGlobalData->GetAt(i);
- ASSERT(pData != NULL);
-
- switch (pData->data.nType)
- {
- case JS_GLOBALDATA_TYPE_NUMBER:
- this->SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_NUMBER, pData->data.dData, false, "", v8::Handle<v8::Object>(), pData->bPersistent == 1);
- JS_PutObjectNumber(NULL,(JSFXObject)(*m_pJSObject),
- pData->data.sKey.UTF8Decode(), pData->data.dData);
- break;
- case JS_GLOBALDATA_TYPE_BOOLEAN:
- this->SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_BOOLEAN, 0, (bool)(pData->data.bData == 1), "", v8::Handle<v8::Object>(), pData->bPersistent == 1);
- JS_PutObjectBoolean(NULL,(JSFXObject)(*m_pJSObject),
- pData->data.sKey.UTF8Decode(), (bool)(pData->data.bData == 1));
- break;
- case JS_GLOBALDATA_TYPE_STRING:
- this->SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_STRING, 0, false, pData->data.sData, v8::Handle<v8::Object>(), pData->bPersistent == 1);
- JS_PutObjectString(NULL,(JSFXObject)(*m_pJSObject),
- pData->data.sKey.UTF8Decode(),
- pData->data.sData.UTF8Decode());
- break;
- case JS_GLOBALDATA_TYPE_OBJECT:
- {
- IJS_Runtime* pRuntime = JS_GetRuntime((JSFXObject)(*m_pJSObject));
- v8::Handle<v8::Object> pObj = JS_NewFxDynamicObj(pRuntime, NULL, -1);
-
- PutObjectProperty(pObj, &pData->data);
-
- this->SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_OBJECT, 0, false, "",
- (JSObject)pObj, pData->bPersistent == 1);
- JS_PutObjectObject(NULL,(JSFXObject)(*m_pJSObject),
- pData->data.sKey.UTF8Decode(), (JSObject)pObj);
- }
- break;
- case JS_GLOBALDATA_TYPE_NULL:
- this->SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_NULL, 0, false, "", v8::Handle<v8::Object>(), pData->bPersistent == 1);
- JS_PutObjectNull(NULL,(JSFXObject)(*m_pJSObject),
- pData->data.sKey.UTF8Decode());
- break;
- }
- }
-}
-
-void global_alternate::CommitGlobalPersisitentVariables()
-{
- ASSERT(m_pGlobalData != NULL);
-
- FX_POSITION pos = m_mapGlobal.GetStartPosition();
- while (pos)
- {
- CFX_ByteString name;
- js_global_data* pData = NULL;
- m_mapGlobal.GetNextAssoc(pos, name, (FX_LPVOID&)pData);
-
- if (pData)
- {
- if (pData->bDeleted)
- {
- m_pGlobalData->DeleteGlobalVariable(name);
- }
- else
- {
- switch (pData->nType)
- {
- case JS_GLOBALDATA_TYPE_NUMBER:
- m_pGlobalData->SetGlobalVariableNumber(name, pData->dData);
- m_pGlobalData->SetGlobalVariablePersistent(name, pData->bPersistent);
- break;
- case JS_GLOBALDATA_TYPE_BOOLEAN:
- m_pGlobalData->SetGlobalVariableBoolean(name, pData->bData);
- m_pGlobalData->SetGlobalVariablePersistent(name, pData->bPersistent);
- break;
- case JS_GLOBALDATA_TYPE_STRING:
- m_pGlobalData->SetGlobalVariableString(name, pData->sData);
- m_pGlobalData->SetGlobalVariablePersistent(name, pData->bPersistent);
- break;
- case JS_GLOBALDATA_TYPE_OBJECT:
- //if (pData->pData)
- {
- CJS_GlobalVariableArray array;
- v8::Handle<v8::Object> obj = v8::Local<v8::Object>::New(GetJSObject()->GetIsolate(),pData->pData);
- ObjectToArray(obj, array);
- m_pGlobalData->SetGlobalVariableObject(name, array);
- m_pGlobalData->SetGlobalVariablePersistent(name, pData->bPersistent);
- }
- break;
- case JS_GLOBALDATA_TYPE_NULL:
- m_pGlobalData->SetGlobalVariableNull(name);
- m_pGlobalData->SetGlobalVariablePersistent(name, pData->bPersistent);
- break;
- }
- }
- }
- }
-}
-
-void global_alternate::ObjectToArray(v8::Handle<v8::Object> pObj, CJS_GlobalVariableArray& array)
-{
- v8::Handle<v8::Array> pKeyList = JS_GetObjectElementNames(pObj);
- int nObjElements = pKeyList->Length();
-
- v8::Local<v8::Context> context = pObj->CreationContext();
- v8::Isolate* isolate = context->GetIsolate();
-
- for (int i=0; i<nObjElements; i++)
- {
-
- CFX_WideString ws = JS_ToString(JS_GetArrayElemnet(pKeyList, i));
- CFX_ByteString sKey = ws.UTF8Encode();
-
- v8::Handle<v8::Value> v = JS_GetObjectElement(isolate, pObj, (const wchar_t*)(FX_LPCWSTR)ws);
- FXJSVALUETYPE vt = GET_VALUE_TYPE(v);
- switch (vt)
- {
- case VT_number:
- {
- CJS_KeyValue* pObjElement = new CJS_KeyValue;
- pObjElement->nType = JS_GLOBALDATA_TYPE_NUMBER;
- pObjElement->sKey = sKey;
- pObjElement->dData = JS_ToNumber(v);
- array.Add(pObjElement);
- }
- break;
- case VT_boolean:
- {
- CJS_KeyValue* pObjElement = new CJS_KeyValue;
- pObjElement->nType = JS_GLOBALDATA_TYPE_BOOLEAN;
- pObjElement->sKey = sKey;
- pObjElement->dData = JS_ToBoolean(v);
- array.Add(pObjElement);
- }
- break;
- case VT_string:
- {
- CFX_ByteString sValue = CJS_Value(isolate, v, VT_string);
- CJS_KeyValue* pObjElement = new CJS_KeyValue;
- pObjElement->nType = JS_GLOBALDATA_TYPE_STRING;
- pObjElement->sKey = sKey;
- pObjElement->sData = sValue;
- array.Add(pObjElement);
- }
- break;
- case VT_object:
- {
- CJS_KeyValue* pObjElement = new CJS_KeyValue;
- pObjElement->nType = JS_GLOBALDATA_TYPE_OBJECT;
- pObjElement->sKey = sKey;
- ObjectToArray(JS_ToObject(v), pObjElement->objData);
- array.Add(pObjElement);
- }
- break;
- case VT_null:
- {
- CJS_KeyValue* pObjElement = new CJS_KeyValue;
- pObjElement->nType = JS_GLOBALDATA_TYPE_NULL;
- pObjElement->sKey = sKey;
- array.Add(pObjElement);
- }
- break;
- default:
- break;
- }
- }
-}
-
-void global_alternate::PutObjectProperty(v8::Handle<v8::Object> pObj, CJS_KeyValue* pData)
-{
- ASSERT(pData != NULL);
-
- for (int i=0,sz=pData->objData.Count(); i<sz; i++)
- {
- CJS_KeyValue* pObjData = pData->objData.GetAt(i);
- ASSERT(pObjData != NULL);
-
- switch (pObjData->nType)
- {
- case JS_GLOBALDATA_TYPE_NUMBER:
- JS_PutObjectNumber(NULL,(JSObject)pObj, pObjData->sKey.UTF8Decode(), pObjData->dData);
- break;
- case JS_GLOBALDATA_TYPE_BOOLEAN:
- JS_PutObjectBoolean(NULL,(JSObject)pObj, pObjData->sKey.UTF8Decode(), (bool)(pObjData->bData == 1));
- break;
- case JS_GLOBALDATA_TYPE_STRING:
- JS_PutObjectString(NULL,(JSObject)pObj, pObjData->sKey.UTF8Decode(), pObjData->sData.UTF8Decode());
- break;
- case JS_GLOBALDATA_TYPE_OBJECT:
- {
- IJS_Runtime* pRuntime = JS_GetRuntime((JSFXObject)(*m_pJSObject));
- v8::Handle<v8::Object> pNewObj = JS_NewFxDynamicObj(pRuntime, NULL, -1);
- PutObjectProperty(pNewObj, pObjData);
- JS_PutObjectObject(NULL, (JSObject)pObj, pObjData->sKey.UTF8Decode(), (JSObject)pNewObj);
- }
- break;
- case JS_GLOBALDATA_TYPE_NULL:
- JS_PutObjectNull(NULL,(JSObject)pObj, pObjData->sKey.UTF8Decode());
- break;
- }
- }
-}
-
-void global_alternate::DestroyGlobalPersisitentVariables()
-{
- FX_POSITION pos = m_mapGlobal.GetStartPosition();
- while (pos)
- {
- CFX_ByteString name;
- js_global_data* pData = NULL;
- m_mapGlobal.GetNextAssoc(pos, name, (FX_LPVOID&)pData);
- delete pData;
- }
-
- m_mapGlobal.RemoveAll();
-}
-
-
-FX_BOOL global_alternate::SetGlobalVariables(FX_LPCSTR propname, int nType,
- double dData, bool bData, const CFX_ByteString& sData, JSObject pData, bool bDefaultPersistent)
-{
- if (propname == NULL) return FALSE;
-
- js_global_data* pTemp = NULL;
- m_mapGlobal.Lookup(propname, (FX_LPVOID&)pTemp);
-
- if (pTemp)
- {
- if (pTemp->bDeleted || pTemp->nType != nType)
- {
- pTemp->dData = 0;
- pTemp->bData = 0;
- pTemp->sData = "";
- pTemp->nType = nType;
- }
-
- pTemp->bDeleted = FALSE;
-
- switch (nType)
- {
- case JS_GLOBALDATA_TYPE_NUMBER:
- {
- pTemp->dData = dData;
- }
- break;
- case JS_GLOBALDATA_TYPE_BOOLEAN:
- {
- pTemp->bData = bData;
- }
- break;
- case JS_GLOBALDATA_TYPE_STRING:
- {
- pTemp->sData = sData;
- }
- break;
- case JS_GLOBALDATA_TYPE_OBJECT:
- {
- pTemp->pData.Reset(JS_GetRuntime(pData), pData);
- }
- break;
- case JS_GLOBALDATA_TYPE_NULL:
- break;
- default:
- return FALSE;
- }
-
- return TRUE;
- }
-
- js_global_data* pNewData = NULL;
-
- switch (nType)
- {
- case JS_GLOBALDATA_TYPE_NUMBER:
- {
- pNewData = new js_global_data;
- pNewData->nType = JS_GLOBALDATA_TYPE_NUMBER;
- pNewData->dData = dData;
- pNewData->bPersistent = bDefaultPersistent;
- }
- break;
- case JS_GLOBALDATA_TYPE_BOOLEAN:
- {
- pNewData = new js_global_data;
- pNewData->nType = JS_GLOBALDATA_TYPE_BOOLEAN;
- pNewData->bData = bData;
- pNewData->bPersistent = bDefaultPersistent;
- }
- break;
- case JS_GLOBALDATA_TYPE_STRING:
- {
- pNewData = new js_global_data;
- pNewData->nType = JS_GLOBALDATA_TYPE_STRING;
- pNewData->sData = sData;
- pNewData->bPersistent = bDefaultPersistent;
- }
- break;
- case JS_GLOBALDATA_TYPE_OBJECT:
- {
- pNewData = new js_global_data;
- pNewData->nType = JS_GLOBALDATA_TYPE_OBJECT;
- pNewData->pData.Reset(JS_GetRuntime(pData), pData);
- pNewData->bPersistent = bDefaultPersistent;
- }
- break;
- case JS_GLOBALDATA_TYPE_NULL:
- {
- pNewData = new js_global_data;
- pNewData->nType = JS_GLOBALDATA_TYPE_NULL;
- pNewData->bPersistent = bDefaultPersistent;
- }
- break;
- default:
- return FALSE;
- }
-
- m_mapGlobal.SetAt(propname, (FX_LPVOID)pNewData);
-
- return TRUE;
-}
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/javascript/JavaScript.h"
+#include "../../include/javascript/IJavaScript.h"
+#include "../../include/javascript/JS_Define.h"
+#include "../../include/javascript/JS_Object.h"
+#include "../../include/javascript/JS_Value.h"
+#include "../../include/javascript/JS_GlobalData.h"
+#include "../../include/javascript/global.h"
+#include "../../include/javascript/JS_EventHandler.h"
+#include "../../include/javascript/JS_Context.h"
+
+/* ---------------------------- global ---------------------------- */
+
+BEGIN_JS_STATIC_CONST(CJS_Global)
+END_JS_STATIC_CONST()
+
+BEGIN_JS_STATIC_PROP(CJS_Global)
+END_JS_STATIC_PROP()
+
+BEGIN_JS_STATIC_METHOD(CJS_Global)
+ JS_STATIC_METHOD_ENTRY(setPersistent, 2)
+END_JS_STATIC_METHOD()
+
+IMPLEMENT_SPECIAL_JS_CLASS(CJS_Global, global_alternate, global);
+
+FX_BOOL CJS_Global::InitInstance(IFXJS_Context* cc)
+{
+ CJS_Context* pContext = (CJS_Context*)cc;
+ ASSERT(pContext != NULL);
+
+ global_alternate* pGlobal = (global_alternate*)GetEmbedObject();
+ ASSERT(pGlobal != NULL);
+
+ pGlobal->Initial(pContext->GetReaderApp());
+
+ return TRUE;
+};
+
+global_alternate::global_alternate(CJS_Object* pJSObject)
+ : CJS_EmbedObj(pJSObject),
+ m_pApp(NULL)
+{
+}
+
+global_alternate::~global_alternate(void)
+{
+ ASSERT(m_pApp != NULL);
+
+// CommitGlobalPersisitentVariables();
+ DestroyGlobalPersisitentVariables();
+
+ CJS_RuntimeFactory* pFactory = m_pApp->m_pJSRuntimeFactory;
+ ASSERT(pFactory);
+
+ pFactory->ReleaseGlobalData();
+}
+
+void global_alternate::Initial(CPDFDoc_Environment* pApp)
+{
+ m_pApp = pApp;
+
+ CJS_RuntimeFactory* pFactory = pApp->m_pJSRuntimeFactory;
+ ASSERT(pFactory);
+ m_pGlobalData = pFactory->NewGlobalData(pApp);
+ UpdateGlobalPersistentVariables();
+}
+
+FX_BOOL global_alternate::QueryProperty(FX_LPCWSTR propname)
+{
+ return CFX_WideString(propname) != L"setPersistent";
+}
+
+FX_BOOL global_alternate::DelProperty(IFXJS_Context* cc, FX_LPCWSTR propname, JS_ErrorString& sError)
+{
+ js_global_data* pData = NULL;
+ CFX_ByteString sPropName = CFX_ByteString::FromUnicode(propname);
+
+ if (m_mapGlobal.Lookup(sPropName, (FX_LPVOID&)pData))
+ {
+ pData->bDeleted = TRUE;
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+FX_BOOL global_alternate::DoProperty(IFXJS_Context* cc, FX_LPCWSTR propname, CJS_PropValue& vp, JS_ErrorString& sError)
+{
+ if (vp.IsSetting())
+ {
+ CFX_ByteString sPropName = CFX_ByteString::FromUnicode(propname);
+ switch (vp.GetType())
+ {
+ case VT_number:
+ {
+ double dData;
+ vp >> dData;
+ return SetGlobalVariables(sPropName, JS_GLOBALDATA_TYPE_NUMBER, dData, false, "", v8::Handle<v8::Object>(), FALSE);
+ }
+ case VT_boolean:
+ {
+ bool bData;
+ vp >> bData;
+ return SetGlobalVariables(sPropName, JS_GLOBALDATA_TYPE_BOOLEAN, 0, (bool)vp, "", v8::Handle<v8::Object>(), FALSE);
+ }
+ case VT_string:
+ {
+ CFX_ByteString sData;
+ vp >> sData;
+ return SetGlobalVariables(sPropName, JS_GLOBALDATA_TYPE_STRING, 0, false, sData, v8::Handle<v8::Object>(), FALSE);
+ }
+ case VT_object:
+ {
+ JSObject pData = (JSObject)vp;
+ return SetGlobalVariables(sPropName, JS_GLOBALDATA_TYPE_OBJECT, 0, false, "", pData, FALSE);
+// else
+// {
+// if (vp.IsArrayObject())
+// {
+// CJS_Array array;
+// vp.ConvertToArray(array);
+// return SetGlobalVariables(sPropName, JS_GLOBALDATA_TYPE_OBJECT, 0, false, "",
+// (Dobject*)(Darray*)array, FALSE);
+// }
+// else
+// return FALSE;
+// }
+ }
+ case VT_null:
+ {
+ return SetGlobalVariables(sPropName, JS_GLOBALDATA_TYPE_NULL, 0, false, "", v8::Handle<v8::Object>(), FALSE);
+ }
+ case VT_undefined:
+ {
+ DelProperty(cc, propname, sError);
+ return TRUE;
+ }
+ default:
+ return FALSE;
+ }
+ }
+ else
+ {
+ js_global_data* pData = NULL;
+ CFX_ByteString sPropName = CFX_ByteString::FromUnicode(propname);
+
+ if (m_mapGlobal.Lookup(sPropName, (FX_LPVOID&)pData))
+ {
+ if (pData)
+ {
+ if (!pData->bDeleted)
+ {
+ switch (pData->nType)
+ {
+ case JS_GLOBALDATA_TYPE_NUMBER:
+ vp << pData->dData;
+ break;
+ case JS_GLOBALDATA_TYPE_BOOLEAN:
+ vp << pData->bData;
+ break;
+ case JS_GLOBALDATA_TYPE_STRING:
+ vp << pData->sData;
+ break;
+ case JS_GLOBALDATA_TYPE_OBJECT:
+ {
+ v8::Handle<v8::Object> obj = v8::Local<v8::Object>::New(vp.GetIsolate(),pData->pData);
+ vp << obj;
+ break;
+ }
+ case JS_GLOBALDATA_TYPE_NULL:
+ vp.SetNull();
+ break;
+ default:
+ return FALSE;
+ }
+ return TRUE;
+ }
+ else
+ {
+ return TRUE;
+ }
+ }
+ else
+ {
+ vp.SetNull();
+ return TRUE;
+ }
+ }
+ else
+ {
+ vp.SetNull();
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+FX_BOOL global_alternate::setPersistent(OBJ_METHOD_PARAMS)
+{
+ if (params.size() != 2)
+ {
+ //sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
+
+ CFX_ByteString sName = params[0];
+
+ js_global_data* pData = NULL;
+ if (m_mapGlobal.Lookup(sName, (FX_LPVOID&)pData))
+ {
+ if (pData && !pData->bDeleted)
+ {
+ pData->bPersistent = (bool)params[1];
+ return TRUE;
+ }
+ }
+
+ //sError = JSGetStringFromID(IDS_JSPARAM_INCORRECT);
+ return FALSE;
+}
+
+void global_alternate::UpdateGlobalPersistentVariables()
+{
+ ASSERT(m_pGlobalData != NULL);
+
+ for (int i=0,sz=m_pGlobalData->GetSize(); i<sz; i++)
+ {
+ CJS_GlobalData_Element* pData = m_pGlobalData->GetAt(i);
+ ASSERT(pData != NULL);
+
+ switch (pData->data.nType)
+ {
+ case JS_GLOBALDATA_TYPE_NUMBER:
+ this->SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_NUMBER, pData->data.dData, false, "", v8::Handle<v8::Object>(), pData->bPersistent == 1);
+ JS_PutObjectNumber(NULL,(JSFXObject)(*m_pJSObject),
+ pData->data.sKey.UTF8Decode(), pData->data.dData);
+ break;
+ case JS_GLOBALDATA_TYPE_BOOLEAN:
+ this->SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_BOOLEAN, 0, (bool)(pData->data.bData == 1), "", v8::Handle<v8::Object>(), pData->bPersistent == 1);
+ JS_PutObjectBoolean(NULL,(JSFXObject)(*m_pJSObject),
+ pData->data.sKey.UTF8Decode(), (bool)(pData->data.bData == 1));
+ break;
+ case JS_GLOBALDATA_TYPE_STRING:
+ this->SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_STRING, 0, false, pData->data.sData, v8::Handle<v8::Object>(), pData->bPersistent == 1);
+ JS_PutObjectString(NULL,(JSFXObject)(*m_pJSObject),
+ pData->data.sKey.UTF8Decode(),
+ pData->data.sData.UTF8Decode());
+ break;
+ case JS_GLOBALDATA_TYPE_OBJECT:
+ {
+ IJS_Runtime* pRuntime = JS_GetRuntime((JSFXObject)(*m_pJSObject));
+ v8::Handle<v8::Object> pObj = JS_NewFxDynamicObj(pRuntime, NULL, -1);
+
+ PutObjectProperty(pObj, &pData->data);
+
+ this->SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_OBJECT, 0, false, "",
+ (JSObject)pObj, pData->bPersistent == 1);
+ JS_PutObjectObject(NULL,(JSFXObject)(*m_pJSObject),
+ pData->data.sKey.UTF8Decode(), (JSObject)pObj);
+ }
+ break;
+ case JS_GLOBALDATA_TYPE_NULL:
+ this->SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_NULL, 0, false, "", v8::Handle<v8::Object>(), pData->bPersistent == 1);
+ JS_PutObjectNull(NULL,(JSFXObject)(*m_pJSObject),
+ pData->data.sKey.UTF8Decode());
+ break;
+ }
+ }
+}
+
+void global_alternate::CommitGlobalPersisitentVariables()
+{
+ ASSERT(m_pGlobalData != NULL);
+
+ FX_POSITION pos = m_mapGlobal.GetStartPosition();
+ while (pos)
+ {
+ CFX_ByteString name;
+ js_global_data* pData = NULL;
+ m_mapGlobal.GetNextAssoc(pos, name, (FX_LPVOID&)pData);
+
+ if (pData)
+ {
+ if (pData->bDeleted)
+ {
+ m_pGlobalData->DeleteGlobalVariable(name);
+ }
+ else
+ {
+ switch (pData->nType)
+ {
+ case JS_GLOBALDATA_TYPE_NUMBER:
+ m_pGlobalData->SetGlobalVariableNumber(name, pData->dData);
+ m_pGlobalData->SetGlobalVariablePersistent(name, pData->bPersistent);
+ break;
+ case JS_GLOBALDATA_TYPE_BOOLEAN:
+ m_pGlobalData->SetGlobalVariableBoolean(name, pData->bData);
+ m_pGlobalData->SetGlobalVariablePersistent(name, pData->bPersistent);
+ break;
+ case JS_GLOBALDATA_TYPE_STRING:
+ m_pGlobalData->SetGlobalVariableString(name, pData->sData);
+ m_pGlobalData->SetGlobalVariablePersistent(name, pData->bPersistent);
+ break;
+ case JS_GLOBALDATA_TYPE_OBJECT:
+ //if (pData->pData)
+ {
+ CJS_GlobalVariableArray array;
+ v8::Handle<v8::Object> obj = v8::Local<v8::Object>::New(GetJSObject()->GetIsolate(),pData->pData);
+ ObjectToArray(obj, array);
+ m_pGlobalData->SetGlobalVariableObject(name, array);
+ m_pGlobalData->SetGlobalVariablePersistent(name, pData->bPersistent);
+ }
+ break;
+ case JS_GLOBALDATA_TYPE_NULL:
+ m_pGlobalData->SetGlobalVariableNull(name);
+ m_pGlobalData->SetGlobalVariablePersistent(name, pData->bPersistent);
+ break;
+ }
+ }
+ }
+ }
+}
+
+void global_alternate::ObjectToArray(v8::Handle<v8::Object> pObj, CJS_GlobalVariableArray& array)
+{
+ v8::Handle<v8::Array> pKeyList = JS_GetObjectElementNames(pObj);
+ int nObjElements = pKeyList->Length();
+
+ v8::Local<v8::Context> context = pObj->CreationContext();
+ v8::Isolate* isolate = context->GetIsolate();
+
+ for (int i=0; i<nObjElements; i++)
+ {
+
+ CFX_WideString ws = JS_ToString(JS_GetArrayElemnet(pKeyList, i));
+ CFX_ByteString sKey = ws.UTF8Encode();
+
+ v8::Handle<v8::Value> v = JS_GetObjectElement(isolate, pObj, (const wchar_t*)(FX_LPCWSTR)ws);
+ FXJSVALUETYPE vt = GET_VALUE_TYPE(v);
+ switch (vt)
+ {
+ case VT_number:
+ {
+ CJS_KeyValue* pObjElement = new CJS_KeyValue;
+ pObjElement->nType = JS_GLOBALDATA_TYPE_NUMBER;
+ pObjElement->sKey = sKey;
+ pObjElement->dData = JS_ToNumber(v);
+ array.Add(pObjElement);
+ }
+ break;
+ case VT_boolean:
+ {
+ CJS_KeyValue* pObjElement = new CJS_KeyValue;
+ pObjElement->nType = JS_GLOBALDATA_TYPE_BOOLEAN;
+ pObjElement->sKey = sKey;
+ pObjElement->dData = JS_ToBoolean(v);
+ array.Add(pObjElement);
+ }
+ break;
+ case VT_string:
+ {
+ CFX_ByteString sValue = CJS_Value(isolate, v, VT_string);
+ CJS_KeyValue* pObjElement = new CJS_KeyValue;
+ pObjElement->nType = JS_GLOBALDATA_TYPE_STRING;
+ pObjElement->sKey = sKey;
+ pObjElement->sData = sValue;
+ array.Add(pObjElement);
+ }
+ break;
+ case VT_object:
+ {
+ CJS_KeyValue* pObjElement = new CJS_KeyValue;
+ pObjElement->nType = JS_GLOBALDATA_TYPE_OBJECT;
+ pObjElement->sKey = sKey;
+ ObjectToArray(JS_ToObject(v), pObjElement->objData);
+ array.Add(pObjElement);
+ }
+ break;
+ case VT_null:
+ {
+ CJS_KeyValue* pObjElement = new CJS_KeyValue;
+ pObjElement->nType = JS_GLOBALDATA_TYPE_NULL;
+ pObjElement->sKey = sKey;
+ array.Add(pObjElement);
+ }
+ break;
+ default:
+ break;
+ }
+ }
+}
+
+void global_alternate::PutObjectProperty(v8::Handle<v8::Object> pObj, CJS_KeyValue* pData)
+{
+ ASSERT(pData != NULL);
+
+ for (int i=0,sz=pData->objData.Count(); i<sz; i++)
+ {
+ CJS_KeyValue* pObjData = pData->objData.GetAt(i);
+ ASSERT(pObjData != NULL);
+
+ switch (pObjData->nType)
+ {
+ case JS_GLOBALDATA_TYPE_NUMBER:
+ JS_PutObjectNumber(NULL,(JSObject)pObj, pObjData->sKey.UTF8Decode(), pObjData->dData);
+ break;
+ case JS_GLOBALDATA_TYPE_BOOLEAN:
+ JS_PutObjectBoolean(NULL,(JSObject)pObj, pObjData->sKey.UTF8Decode(), (bool)(pObjData->bData == 1));
+ break;
+ case JS_GLOBALDATA_TYPE_STRING:
+ JS_PutObjectString(NULL,(JSObject)pObj, pObjData->sKey.UTF8Decode(), pObjData->sData.UTF8Decode());
+ break;
+ case JS_GLOBALDATA_TYPE_OBJECT:
+ {
+ IJS_Runtime* pRuntime = JS_GetRuntime((JSFXObject)(*m_pJSObject));
+ v8::Handle<v8::Object> pNewObj = JS_NewFxDynamicObj(pRuntime, NULL, -1);
+ PutObjectProperty(pNewObj, pObjData);
+ JS_PutObjectObject(NULL, (JSObject)pObj, pObjData->sKey.UTF8Decode(), (JSObject)pNewObj);
+ }
+ break;
+ case JS_GLOBALDATA_TYPE_NULL:
+ JS_PutObjectNull(NULL,(JSObject)pObj, pObjData->sKey.UTF8Decode());
+ break;
+ }
+ }
+}
+
+void global_alternate::DestroyGlobalPersisitentVariables()
+{
+ FX_POSITION pos = m_mapGlobal.GetStartPosition();
+ while (pos)
+ {
+ CFX_ByteString name;
+ js_global_data* pData = NULL;
+ m_mapGlobal.GetNextAssoc(pos, name, (FX_LPVOID&)pData);
+ delete pData;
+ }
+
+ m_mapGlobal.RemoveAll();
+}
+
+
+FX_BOOL global_alternate::SetGlobalVariables(FX_LPCSTR propname, int nType,
+ double dData, bool bData, const CFX_ByteString& sData, JSObject pData, bool bDefaultPersistent)
+{
+ if (propname == NULL) return FALSE;
+
+ js_global_data* pTemp = NULL;
+ m_mapGlobal.Lookup(propname, (FX_LPVOID&)pTemp);
+
+ if (pTemp)
+ {
+ if (pTemp->bDeleted || pTemp->nType != nType)
+ {
+ pTemp->dData = 0;
+ pTemp->bData = 0;
+ pTemp->sData = "";
+ pTemp->nType = nType;
+ }
+
+ pTemp->bDeleted = FALSE;
+
+ switch (nType)
+ {
+ case JS_GLOBALDATA_TYPE_NUMBER:
+ {
+ pTemp->dData = dData;
+ }
+ break;
+ case JS_GLOBALDATA_TYPE_BOOLEAN:
+ {
+ pTemp->bData = bData;
+ }
+ break;
+ case JS_GLOBALDATA_TYPE_STRING:
+ {
+ pTemp->sData = sData;
+ }
+ break;
+ case JS_GLOBALDATA_TYPE_OBJECT:
+ {
+ pTemp->pData.Reset(JS_GetRuntime(pData), pData);
+ }
+ break;
+ case JS_GLOBALDATA_TYPE_NULL:
+ break;
+ default:
+ return FALSE;
+ }
+
+ return TRUE;
+ }
+
+ js_global_data* pNewData = NULL;
+
+ switch (nType)
+ {
+ case JS_GLOBALDATA_TYPE_NUMBER:
+ {
+ pNewData = new js_global_data;
+ pNewData->nType = JS_GLOBALDATA_TYPE_NUMBER;
+ pNewData->dData = dData;
+ pNewData->bPersistent = bDefaultPersistent;
+ }
+ break;
+ case JS_GLOBALDATA_TYPE_BOOLEAN:
+ {
+ pNewData = new js_global_data;
+ pNewData->nType = JS_GLOBALDATA_TYPE_BOOLEAN;
+ pNewData->bData = bData;
+ pNewData->bPersistent = bDefaultPersistent;
+ }
+ break;
+ case JS_GLOBALDATA_TYPE_STRING:
+ {
+ pNewData = new js_global_data;
+ pNewData->nType = JS_GLOBALDATA_TYPE_STRING;
+ pNewData->sData = sData;
+ pNewData->bPersistent = bDefaultPersistent;
+ }
+ break;
+ case JS_GLOBALDATA_TYPE_OBJECT:
+ {
+ pNewData = new js_global_data;
+ pNewData->nType = JS_GLOBALDATA_TYPE_OBJECT;
+ pNewData->pData.Reset(JS_GetRuntime(pData), pData);
+ pNewData->bPersistent = bDefaultPersistent;
+ }
+ break;
+ case JS_GLOBALDATA_TYPE_NULL:
+ {
+ pNewData = new js_global_data;
+ pNewData->nType = JS_GLOBALDATA_TYPE_NULL;
+ pNewData->bPersistent = bDefaultPersistent;
+ }
+ break;
+ default:
+ return FALSE;
+ }
+
+ m_mapGlobal.SetAt(propname, (FX_LPVOID)pNewData);
+
+ return TRUE;
+}
diff --git a/fpdfsdk/src/javascript/report.cpp b/fpdfsdk/src/javascript/report.cpp
index 5063c68e4c..9cb9da5051 100644
--- a/fpdfsdk/src/javascript/report.cpp
+++ b/fpdfsdk/src/javascript/report.cpp
@@ -1,50 +1,50 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/javascript/JavaScript.h"
-#include "../../include/javascript/IJavaScript.h"
-#include "../../include/javascript/JS_Define.h"
-#include "../../include/javascript/JS_Object.h"
-#include "../../include/javascript/JS_Value.h"
-#include "../../include/javascript/report.h"
-
-/* ---------------------- report ---------------------- */
-
-BEGIN_JS_STATIC_CONST(CJS_Report)
-END_JS_STATIC_CONST()
-
-BEGIN_JS_STATIC_PROP(CJS_Report)
-END_JS_STATIC_PROP()
-
-BEGIN_JS_STATIC_METHOD(CJS_Report)
- JS_STATIC_METHOD_ENTRY(save, 1)
- JS_STATIC_METHOD_ENTRY(writeText,1)
-END_JS_STATIC_METHOD()
-
-IMPLEMENT_JS_CLASS(CJS_Report, Report)
-
-Report::Report(CJS_Object* pJSObject) : CJS_EmbedObj(pJSObject)
-{
-
-}
-
-Report::~Report()
-{
-
-}
-
-FX_BOOL Report::writeText(OBJ_METHOD_PARAMS)
-{
- if (IsSafeMode(cc)) return TRUE;
- return TRUE;
-}
-
-FX_BOOL Report::save(OBJ_METHOD_PARAMS)
-{
- if (IsSafeMode(cc)) return TRUE;
- return TRUE;
-}
-
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/javascript/JavaScript.h"
+#include "../../include/javascript/IJavaScript.h"
+#include "../../include/javascript/JS_Define.h"
+#include "../../include/javascript/JS_Object.h"
+#include "../../include/javascript/JS_Value.h"
+#include "../../include/javascript/report.h"
+
+/* ---------------------- report ---------------------- */
+
+BEGIN_JS_STATIC_CONST(CJS_Report)
+END_JS_STATIC_CONST()
+
+BEGIN_JS_STATIC_PROP(CJS_Report)
+END_JS_STATIC_PROP()
+
+BEGIN_JS_STATIC_METHOD(CJS_Report)
+ JS_STATIC_METHOD_ENTRY(save, 1)
+ JS_STATIC_METHOD_ENTRY(writeText,1)
+END_JS_STATIC_METHOD()
+
+IMPLEMENT_JS_CLASS(CJS_Report, Report)
+
+Report::Report(CJS_Object* pJSObject) : CJS_EmbedObj(pJSObject)
+{
+
+}
+
+Report::~Report()
+{
+
+}
+
+FX_BOOL Report::writeText(OBJ_METHOD_PARAMS)
+{
+ if (IsSafeMode(cc)) return TRUE;
+ return TRUE;
+}
+
+FX_BOOL Report::save(OBJ_METHOD_PARAMS)
+{
+ if (IsSafeMode(cc)) return TRUE;
+ return TRUE;
+}
+
diff --git a/fpdfsdk/src/javascript/util.cpp b/fpdfsdk/src/javascript/util.cpp
index b7303a7578..bafdb22da9 100644
--- a/fpdfsdk/src/javascript/util.cpp
+++ b/fpdfsdk/src/javascript/util.cpp
@@ -1,649 +1,649 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "../../include/javascript/JavaScript.h"
-#include "../../include/javascript/IJavaScript.h"
-#include "../../include/javascript/JS_Define.h"
-#include "../../include/javascript/JS_Object.h"
-#include "../../include/javascript/JS_Value.h"
-#include "../../include/javascript/util.h"
-#include "../../include/javascript/PublicMethods.h"
-#include "../../include/javascript/resource.h"
-#include "../../include/javascript/JS_Context.h"
-#include "../../include/javascript/JS_EventHandler.h"
-#include "../../include/javascript/JS_Runtime.h"
-
-#if _FX_OS_ == _FX_ANDROID_
-#include <ctype.h>
-#endif
-
-static v8::Isolate* GetIsolate(IFXJS_Context* cc)
-{
- CJS_Context* pContext = (CJS_Context *)cc;
- ASSERT(pContext != NULL);
-
- CJS_Runtime* pRuntime = pContext->GetJSRuntime();
- ASSERT(pRuntime != NULL);
-
- return pRuntime->GetIsolate();
-}
-
-BEGIN_JS_STATIC_CONST(CJS_Util)
-END_JS_STATIC_CONST()
-
-BEGIN_JS_STATIC_PROP(CJS_Util)
-END_JS_STATIC_PROP()
-
-BEGIN_JS_STATIC_METHOD(CJS_Util)
- JS_STATIC_METHOD_ENTRY(printd, 3)
- JS_STATIC_METHOD_ENTRY(printf, 20)
- JS_STATIC_METHOD_ENTRY(printx, 2)
- JS_STATIC_METHOD_ENTRY(scand, 2)
- JS_STATIC_METHOD_ENTRY(byteToChar, 1)
-END_JS_STATIC_METHOD()
-
-IMPLEMENT_JS_CLASS(CJS_Util,util)
-
-util::util(CJS_Object *pJSObject) : CJS_EmbedObj(pJSObject)
-{
-}
-
-util::~util(void)
-{
-}
-
-
-struct stru_TbConvert
-{
- FX_LPCWSTR lpszJSMark;
- FX_LPCWSTR lpszCppMark;
-};
-
-const stru_TbConvert fcTable[] = {
- (FX_LPCWSTR)L"mmmm", (FX_LPCWSTR)L"%B",
- (FX_LPCWSTR)L"mmm", (FX_LPCWSTR)L"%b",
- (FX_LPCWSTR)L"mm", (FX_LPCWSTR)L"%m",
- //"m"
- (FX_LPCWSTR)L"dddd", (FX_LPCWSTR)L"%A",
- (FX_LPCWSTR)L"ddd", (FX_LPCWSTR)L"%a",
- (FX_LPCWSTR)L"dd", (FX_LPCWSTR)L"%d",
- //"d", "%w",
- (FX_LPCWSTR)L"yyyy", (FX_LPCWSTR)L"%Y",
- (FX_LPCWSTR)L"yy", (FX_LPCWSTR)L"%y",
- (FX_LPCWSTR)L"HH", (FX_LPCWSTR)L"%H",
- //"H"
- (FX_LPCWSTR)L"hh", (FX_LPCWSTR)L"%I",
- //"h"
- (FX_LPCWSTR)L"MM", (FX_LPCWSTR)L"%M",
- //"M"
- (FX_LPCWSTR)L"ss", (FX_LPCWSTR)L"%S",
- //"s
- (FX_LPCWSTR)L"TT", (FX_LPCWSTR)L"%p",
- //"t"
-#if defined(_WIN32)
- (FX_LPCWSTR)L"tt", (FX_LPCWSTR)L"%p",
- (FX_LPCWSTR)L"h", (FX_LPCWSTR)L"%#I",
-#else
- (FX_LPCWSTR)L"tt", (FX_LPCWSTR)L"%P",
- (FX_LPCWSTR)L"h", (FX_LPCWSTR)L"%l",
-#endif
-};
-
-#define UTIL_INT 0
-#define UTIL_DOUBLE 1
-#define UTIL_STRING 2
-
-int util::ParstDataType(std::wstring* sFormat)
-{
- size_t i = 0;
- bool bPercent = FALSE;
- for (i=0; i<sFormat->length(); ++i)
- {
- wchar_t c = (*sFormat)[i];
- if (c == L'%')
- {
- bPercent = true;
- continue;
- }
-
- if (bPercent)
- {
- if (c == L'c' || c == L'C' || c == L'd' || c == L'i' || c == L'o' || c == L'u' || c == L'x' || c == L'X')
- {
- return UTIL_INT;
- }
- else if (c == L'e' || c == L'E' || c == L'f' || c == L'g' || c == L'G')
- {
- return UTIL_DOUBLE;
- }
- else if (c == L's' || c == L'S')
- {
- // Map s to S since we always deal internally
- // with wchar_t strings.
- (*sFormat)[i] = L'S';
- return UTIL_STRING;
- }
- else if (c == L'.' || c == L'+' || c == L'-' || c == L'#' || c == L' ' || CJS_PublicMethods::IsDigit(c))
- {
- continue;
- }
- else break;
- }
- }
-
- return -1;
-}
-
-FX_BOOL util::printf(OBJ_METHOD_PARAMS)
-{
- int iSize = params.size();
- if (iSize < 1)
- return FALSE;
- std::wstring c_ConvChar((const wchar_t*)(FX_LPCWSTR)params[0].operator CFX_WideString());
- std::vector<std::wstring> c_strConvers;
- int iOffset = 0;
- int iOffend = 0;
- c_ConvChar.insert(c_ConvChar.begin(),L'S');
- while(iOffset != -1)
- {
- iOffend = c_ConvChar.find(L"%",iOffset+1);
- std::wstring strSub;
- if (iOffend == -1)
- strSub = c_ConvChar.substr(iOffset);
- else
- strSub = c_ConvChar.substr(iOffset ,iOffend - iOffset);
- c_strConvers.push_back(strSub);
- iOffset = iOffend ;
- }
-
- std::wstring c_strResult;
-
- //for(int iIndex = 1;iIndex < params.size();iIndex++)
- std::wstring c_strFormat;
- for(int iIndex = 0;iIndex < (int)c_strConvers.size();iIndex++)
- {
- c_strFormat = c_strConvers[iIndex];
- if (iIndex == 0)
- {
- c_strResult = c_strFormat;
- continue;
- }
-
-
- CFX_WideString strSegment;
- if (iIndex >= iSize) {
- c_strResult += c_strFormat;
- continue;
- }
-
- switch (ParstDataType(&c_strFormat))
- {
- case UTIL_INT:
- strSegment.Format((FX_LPCWSTR)c_strFormat.c_str(),(int)params[iIndex]);
- break;
- case UTIL_DOUBLE:
- strSegment.Format((FX_LPCWSTR)c_strFormat.c_str(),(double)params[iIndex]);
- break;
- case UTIL_STRING:
- strSegment.Format((FX_LPCWSTR)c_strFormat.c_str(),(FX_LPCWSTR)params[iIndex].operator CFX_WideString());
- break;
- default:
- strSegment.Format((FX_LPCWSTR)L"%S", (FX_LPCWSTR)c_strFormat.c_str());
- break;
- }
- c_strResult += (wchar_t*)strSegment.GetBuffer(strSegment.GetLength()+1);
- }
-
- c_strResult.erase(c_strResult.begin());
- vRet = (FX_LPCWSTR)c_strResult.c_str();
- return TRUE;
-}
-
-FX_BOOL util::printd(OBJ_METHOD_PARAMS)
-{
- v8::Isolate* isolate = GetIsolate(cc);
-
- int iSize = params.size();
- if (iSize < 2)
- return FALSE;
-
- CJS_Value p1(isolate);
- p1 = params[0];
-
- CJS_Value p2 = params[1];
- CJS_Date jsDate(isolate);
- if (!p2.ConvertToDate(jsDate))
- {
- sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPRINT1);
- return FALSE;
- }
-
- if (!jsDate.IsValidDate())
- {
- sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPRINT2);
- return FALSE;
- }
-
- if (p1.GetType() == VT_number)
- {
- int nFormat = p1;
-
- CFX_WideString swResult;
-
- switch (nFormat)
- {
- case 0:
- swResult.Format((FX_LPCWSTR)L"D:%04d%02d%02d%02d%02d%02d",
- jsDate.GetYear(),
- jsDate.GetMonth() + 1,
- jsDate.GetDay(),
- jsDate.GetHours(),
- jsDate.GetMinutes(),
- jsDate.GetSeconds());
- break;
- case 1:
- swResult.Format((FX_LPCWSTR)L"%04d.%02d.%02d %02d:%02d:%02d",
- jsDate.GetYear(),
- jsDate.GetMonth() + 1,
- jsDate.GetDay(),
- jsDate.GetHours(),
- jsDate.GetMinutes(),
- jsDate.GetSeconds());
- break;
- case 2:
- swResult.Format((FX_LPCWSTR)L"%04d/%02d/%02d %02d:%02d:%02d",
- jsDate.GetYear(),
- jsDate.GetMonth() + 1,
- jsDate.GetDay(),
- jsDate.GetHours(),
- jsDate.GetMinutes(),
- jsDate.GetSeconds());
- break;
- default:
- return FALSE;
- }
-
- vRet = swResult;
- return TRUE;
- }
- else if (p1.GetType() == VT_string)
- {
- std::basic_string<wchar_t> cFormat = (wchar_t*)(FX_LPCWSTR)p1.operator CFX_WideString();
-
- bool bXFAPicture = false;
- if (iSize > 2)
- {
- //CJS_Value value;
- bXFAPicture = params[2];
- }
-
- if (bXFAPicture)
- {
- return FALSE; //currently, it doesn't support XFAPicture.
- }
-
- int iIndex;
- for(iIndex = 0;iIndex<sizeof(fcTable)/sizeof(stru_TbConvert);iIndex++)
- {
- int iStart = 0;
- int iEnd;
- while((iEnd = cFormat.find((CFX_WideString)fcTable[iIndex].lpszJSMark, iStart)) != -1)
- {
- cFormat.replace(iEnd, FXSYS_wcslen(fcTable[iIndex].lpszJSMark), (CFX_WideString)fcTable[iIndex].lpszCppMark);
- iStart = iEnd;
- }
- }
-
- int iYear,iMonth,iDay,iHour,iMin,iSec;
- iYear = jsDate.GetYear();
- iMonth = jsDate.GetMonth();
- iDay = jsDate.GetDay();
- iHour = jsDate.GetHours();
- iMin = jsDate.GetMinutes();
- iSec = jsDate.GetSeconds();
-
- struct tm time = {0};
- time.tm_year = iYear-1900;
- time.tm_mon = iMonth;
- time.tm_mday = iDay;
- time.tm_hour = iHour;
- time.tm_min = iMin;
- time.tm_sec = iSec;
- //COleDateTime cppTm(iYear,iMonth+1,iDay,iHour,iMin,iSec);
- //CString strFormat = cppTm.Format(cFormat.c_str());
-
- struct stru_TbConvertAd
- {
- FX_LPCWSTR lpszJSMark;
- int iValue;
- };
-
- stru_TbConvertAd cTableAd[] ={
- (FX_LPCWSTR)L"m", iMonth+1,
- (FX_LPCWSTR)L"d", iDay,
- (FX_LPCWSTR)L"H", iHour,
- (FX_LPCWSTR)L"h", iHour>12?iHour-12:iHour,
- (FX_LPCWSTR)L"M", iMin,
- (FX_LPCWSTR)L"s", iSec
- };
-
- //cFormat = strFormat.GetBuffer(strFormat.GetLength()+1);
- for(iIndex = 0;iIndex<sizeof(cTableAd)/sizeof(stru_TbConvertAd);iIndex++)
- {
- wchar_t tszValue[10];
- //_itot(cTableAd[iIndex].iValue,tszValue,10);
- CFX_WideString sValue;
- sValue.Format((FX_LPCWSTR)L"%d",cTableAd[iIndex].iValue);
- memcpy(tszValue, (wchar_t *)sValue.GetBuffer(sValue.GetLength()+1),
- (sValue.GetLength()+1)*sizeof(wchar_t));
-
- //strFormat.Replace(cTableAd[iIndex].lpszJSMark,"%d");
- //strFormat.Format(strFormat,cTableAd[iIndex].iValue);
- int iStart = 0;
- int iEnd;
- while((iEnd = cFormat.find((CFX_WideString)cTableAd[iIndex].lpszJSMark,iStart)) != -1)
- {
- if (iEnd > 0)
- {
- if (cFormat[iEnd-1] == L'%')
- {
- iStart = iEnd+1;
- continue;
- }
- }
- cFormat.replace(iEnd, FXSYS_wcslen(cTableAd[iIndex].lpszJSMark), tszValue);
- iStart = iEnd;
- }
- }
-
- CFX_WideString strFormat;
-// strFormat.Format((FX_LPCWSTR)L"%d,%d,%d,%d,%d,%d",iYear, iMonth, iDay, iHour, iMin, iSec);
-// CString strFormat = cppTm.Format(cFormat.c_str());
- wchar_t buf[64] = {0};
- strFormat = wcsftime(buf, 64, cFormat.c_str(), &time);
- cFormat = buf;
- vRet = (FX_LPCWSTR)cFormat.c_str();
- //rtRet = strFormat.GetBuffer(strFormat.GetLength()+1);
- return TRUE;
- }
- return FALSE;
-}
-
-void util::printd(const std::wstring &cFormat2, CJS_Date jsDate, bool bXFAPicture, std::wstring &cPurpose)
-{
- std::wstring cFormat = cFormat2;
-
- if (bXFAPicture)
- {
- return ; //currently, it doesn't support XFAPicture.
- }
-
- int iIndex;
- for(iIndex = 0;iIndex<sizeof(fcTable)/sizeof(stru_TbConvert);iIndex++)
- {
- int iStart = 0;
- int iEnd;
- while((iEnd = cFormat.find((CFX_WideString)fcTable[iIndex].lpszJSMark,iStart)) != -1)
- {
- cFormat.replace(iEnd,FXSYS_wcslen(fcTable[iIndex].lpszJSMark), (CFX_WideString)fcTable[iIndex].lpszCppMark);
- iStart = iEnd;
- }
- }
-
- int iYear,iMonth,iDay,iHour,iMin,iSec;
- iYear = jsDate.GetYear();
- iMonth = jsDate.GetMonth();
- iDay = jsDate.GetDay();
- iHour = jsDate.GetHours();
- iMin = jsDate.GetMinutes();
- iSec = jsDate.GetSeconds();
-
- struct tm time = {0};
- time.tm_year = iYear-1900;
- time.tm_mon = iMonth;
- time.tm_mday = iDay;
- time.tm_hour = iHour;
- time.tm_min = iMin;
- time.tm_sec = iSec;
-// COleDateTime cppTm(iYear,iMonth+1,iDay,iHour,iMin,iSec);
- //CString strFormat = cppTm.Format(cFormat.c_str());
-
- struct stru_TbConvertAd
- {
- FX_LPCWSTR lpszJSMark;
- int iValue;
- };
-
- stru_TbConvertAd cTableAd[] ={
- (FX_LPCWSTR)L"m", iMonth+1,
- (FX_LPCWSTR)L"d", iDay,
- (FX_LPCWSTR)L"H", iHour,
- (FX_LPCWSTR)L"h", iHour>12?iHour-12:iHour,
- (FX_LPCWSTR)L"M", iMin,
- (FX_LPCWSTR)L"s", iSec
- };
-
- //cFormat = strFormat.GetBuffer(strFormat.GetLength()+1);
- for(iIndex = 0;iIndex<sizeof(cTableAd)/sizeof(stru_TbConvertAd);iIndex++)
- {
- wchar_t tszValue[10];
- //_itot(cTableAd[iIndex].iValue,tszValue,10);
- CFX_WideString sValue;
- sValue.Format((FX_LPCWSTR)L"%d",cTableAd[iIndex].iValue);
- memcpy(tszValue, (wchar_t *)sValue.GetBuffer(sValue.GetLength()+1),sValue.GetLength()*sizeof(wchar_t));
-
-
- //strFormat.Replace(cTableAd[iIndex].lpszJSMark,"%d");
- //strFormat.Format(strFormat,cTableAd[iIndex].iValue);
- int iStart = 0;
- int iEnd;
- while((iEnd = cFormat.find((CFX_WideString)cTableAd[iIndex].lpszJSMark,iStart)) != -1)
- {
- if (iEnd > 0)
- {
- if (cFormat[iEnd-1] == L'%')
- {
- iStart = iEnd+1;
- continue;
- }
- }
- cFormat.replace(iEnd,FXSYS_wcslen(cTableAd[iIndex].lpszJSMark),tszValue);
- iStart = iEnd;
- }
- }
-
- CFX_WideString strFormat;
-// strFormat.Format((FX_LPCWSTR)L"%d,%d,%d,%d,%d,%d",iYear, iMonth, iDay, iHour, iMin, iSec);
-// CString strFormat = cppTm.Format(cFormat.c_str());
- wchar_t buf[64] = {0};
- strFormat = wcsftime(buf, 64, cFormat.c_str(), &time);
- cFormat = buf;
- cPurpose = cFormat;
-}
-
-FX_BOOL util::printx(OBJ_METHOD_PARAMS)
-{
- int iSize = params.size();
- if (iSize<2)
- return FALSE;
- CFX_WideString sFormat = params[0].operator CFX_WideString();
- CFX_WideString sSource = params[1].operator CFX_WideString();
- std::string cFormat = (FX_LPCSTR)CFX_ByteString::FromUnicode(sFormat);
- std::string cSource = (FX_LPCSTR)CFX_ByteString::FromUnicode(sSource);
- std::string cDest;
- printx(cFormat,cSource,cDest);
- vRet = cDest.c_str();
- return TRUE;
-}
-
-void util::printx(const std::string &cFormat,const std::string &cSource2,std::string &cPurpose)
-{
- std::string cSource(cSource2);
- if (!cPurpose.empty())
- //cPurpose.clear();
- cPurpose.erase();
- int itSource = 0;
- int iSize = cSource.size();
- for(int iIndex = 0; iIndex < (int)cFormat.size() && itSource<iSize; iIndex++)
- {
- char letter = cFormat[iIndex];
- switch(letter)
- {
- case '?':
- //cPurpose.push_back(cSource[itSource]);
- cPurpose += cSource[itSource];
- itSource++;
- break;
- case 'X':
- {
- while(itSource < iSize)
- {
- if ((cSource[itSource]>='0'&&cSource[itSource]<='9') || (cSource[itSource]>='a' && cSource[itSource]<='z') || (cSource[itSource]>='A' && cSource[itSource]<='Z'))
- {
- //cPurpose.push_back(cSource[itSource]);
- cPurpose += cSource[itSource];
- itSource++;
- break;
- }
- itSource++;
- }
- break;
- }
- break;
- case 'A':
- {
- while(itSource < iSize)
- {
- if ((cSource[itSource]>='a' && cSource[itSource]<='z') || (cSource[itSource]>='A' && cSource[itSource]<='Z'))
- {
- //cPurpose.push_back(cSource[itSource]);
- cPurpose += cSource[itSource];
- itSource++;
- break;
- }
- itSource++;
- }
- break;
- }
- break;
- case '9':
- {
- while(itSource < iSize)
- {
- if (cSource[itSource]>='0'&&cSource[itSource]<='9')
- {
- //cPurpose.push_back(cSource[itSource]);
- cPurpose += cSource[itSource];
- itSource++;
- break;
- }
- itSource++;
- }
- break;
- }
- case '*':
- {
- cPurpose.append(cSource,itSource,iSize-itSource);
- itSource = iSize-1;
- break;
- }
- case '\\':
- break;
- case '>':
- {
- for(std::string::iterator it = cSource.begin();it != cSource.end(); it++)
- {
- *it = toupper(*it);
- }
- break;
- }
- case '<':
- {
- for(std::string::iterator it = cSource.begin();it != cSource.end(); it++)
- {
- *it = tolower(*it);
- }
- break;
- }
- case '=':
- break;
- default:
- //cPurpose.push_back(letter);
- cPurpose += letter;
- break;
- }
- }
-}
-
-FX_BOOL util::scand(OBJ_METHOD_PARAMS)
-{
- v8::Isolate* isolate = GetIsolate(cc);
- int iSize = params.size();
- if (iSize < 2)
- return FALSE;
- CFX_WideString sFormat = params[0].operator CFX_WideString();
- CFX_WideString sDate = params[1].operator CFX_WideString();
-
- double dDate = JS_GetDateTime();
- if (sDate.GetLength() > 0)
- {
- FX_BOOL bWrongFormat = FALSE;
- dDate = CJS_PublicMethods::MakeRegularDate(sDate,sFormat,bWrongFormat);
- }
-
- if (!JS_PortIsNan(dDate))
- {
- CJS_Date date(isolate,dDate);
- vRet = date;
- }
- else
- {
- vRet.SetNull();
- }
-
- return TRUE;
-}
-
-FX_INT64 FX_atoi64(const char *nptr)
-{
- int c; /* current char */
- FX_INT64 total; /* current total */
- int sign; /* if '-', then negative, otherwise positive */
-
- /* skip whitespace */
- while ( isspace((int)(unsigned char)*nptr) )
- ++nptr;
-
- c = (int)(unsigned char)*nptr++;
- sign = c; /* save sign indication */
- if (c == '-' || c == '+')
- c = (int)(unsigned char)*nptr++; /* skip sign */
-
- total = 0;
-
- while (isdigit(c)) {
- total = 10 * total + (c - '0'); /* accumulate digit */
- c = (int)(unsigned char)*nptr++; /* get next char */
- }
-
- if (sign == '-')
- return -total;
- else
- return total; /* return result, negated if necessary */
-}
-
-FX_BOOL util::byteToChar(OBJ_METHOD_PARAMS)
-{
- int iSize = params.size();
- if (iSize == 0)
- return FALSE;
- int nByte = (int)params[0];
- unsigned char cByte = (unsigned char)nByte;
- CFX_WideString csValue;
- csValue.Format((FX_LPCWSTR)L"%c", cByte);
- vRet = csValue;
- return TRUE;
-}
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/javascript/JavaScript.h"
+#include "../../include/javascript/IJavaScript.h"
+#include "../../include/javascript/JS_Define.h"
+#include "../../include/javascript/JS_Object.h"
+#include "../../include/javascript/JS_Value.h"
+#include "../../include/javascript/util.h"
+#include "../../include/javascript/PublicMethods.h"
+#include "../../include/javascript/resource.h"
+#include "../../include/javascript/JS_Context.h"
+#include "../../include/javascript/JS_EventHandler.h"
+#include "../../include/javascript/JS_Runtime.h"
+
+#if _FX_OS_ == _FX_ANDROID_
+#include <ctype.h>
+#endif
+
+static v8::Isolate* GetIsolate(IFXJS_Context* cc)
+{
+ CJS_Context* pContext = (CJS_Context *)cc;
+ ASSERT(pContext != NULL);
+
+ CJS_Runtime* pRuntime = pContext->GetJSRuntime();
+ ASSERT(pRuntime != NULL);
+
+ return pRuntime->GetIsolate();
+}
+
+BEGIN_JS_STATIC_CONST(CJS_Util)
+END_JS_STATIC_CONST()
+
+BEGIN_JS_STATIC_PROP(CJS_Util)
+END_JS_STATIC_PROP()
+
+BEGIN_JS_STATIC_METHOD(CJS_Util)
+ JS_STATIC_METHOD_ENTRY(printd, 3)
+ JS_STATIC_METHOD_ENTRY(printf, 20)
+ JS_STATIC_METHOD_ENTRY(printx, 2)
+ JS_STATIC_METHOD_ENTRY(scand, 2)
+ JS_STATIC_METHOD_ENTRY(byteToChar, 1)
+END_JS_STATIC_METHOD()
+
+IMPLEMENT_JS_CLASS(CJS_Util,util)
+
+util::util(CJS_Object *pJSObject) : CJS_EmbedObj(pJSObject)
+{
+}
+
+util::~util(void)
+{
+}
+
+
+struct stru_TbConvert
+{
+ FX_LPCWSTR lpszJSMark;
+ FX_LPCWSTR lpszCppMark;
+};
+
+const stru_TbConvert fcTable[] = {
+ (FX_LPCWSTR)L"mmmm", (FX_LPCWSTR)L"%B",
+ (FX_LPCWSTR)L"mmm", (FX_LPCWSTR)L"%b",
+ (FX_LPCWSTR)L"mm", (FX_LPCWSTR)L"%m",
+ //"m"
+ (FX_LPCWSTR)L"dddd", (FX_LPCWSTR)L"%A",
+ (FX_LPCWSTR)L"ddd", (FX_LPCWSTR)L"%a",
+ (FX_LPCWSTR)L"dd", (FX_LPCWSTR)L"%d",
+ //"d", "%w",
+ (FX_LPCWSTR)L"yyyy", (FX_LPCWSTR)L"%Y",
+ (FX_LPCWSTR)L"yy", (FX_LPCWSTR)L"%y",
+ (FX_LPCWSTR)L"HH", (FX_LPCWSTR)L"%H",
+ //"H"
+ (FX_LPCWSTR)L"hh", (FX_LPCWSTR)L"%I",
+ //"h"
+ (FX_LPCWSTR)L"MM", (FX_LPCWSTR)L"%M",
+ //"M"
+ (FX_LPCWSTR)L"ss", (FX_LPCWSTR)L"%S",
+ //"s
+ (FX_LPCWSTR)L"TT", (FX_LPCWSTR)L"%p",
+ //"t"
+#if defined(_WIN32)
+ (FX_LPCWSTR)L"tt", (FX_LPCWSTR)L"%p",
+ (FX_LPCWSTR)L"h", (FX_LPCWSTR)L"%#I",
+#else
+ (FX_LPCWSTR)L"tt", (FX_LPCWSTR)L"%P",
+ (FX_LPCWSTR)L"h", (FX_LPCWSTR)L"%l",
+#endif
+};
+
+#define UTIL_INT 0
+#define UTIL_DOUBLE 1
+#define UTIL_STRING 2
+
+int util::ParstDataType(std::wstring* sFormat)
+{
+ size_t i = 0;
+ bool bPercent = FALSE;
+ for (i=0; i<sFormat->length(); ++i)
+ {
+ wchar_t c = (*sFormat)[i];
+ if (c == L'%')
+ {
+ bPercent = true;
+ continue;
+ }
+
+ if (bPercent)
+ {
+ if (c == L'c' || c == L'C' || c == L'd' || c == L'i' || c == L'o' || c == L'u' || c == L'x' || c == L'X')
+ {
+ return UTIL_INT;
+ }
+ else if (c == L'e' || c == L'E' || c == L'f' || c == L'g' || c == L'G')
+ {
+ return UTIL_DOUBLE;
+ }
+ else if (c == L's' || c == L'S')
+ {
+ // Map s to S since we always deal internally
+ // with wchar_t strings.
+ (*sFormat)[i] = L'S';
+ return UTIL_STRING;
+ }
+ else if (c == L'.' || c == L'+' || c == L'-' || c == L'#' || c == L' ' || CJS_PublicMethods::IsDigit(c))
+ {
+ continue;
+ }
+ else break;
+ }
+ }
+
+ return -1;
+}
+
+FX_BOOL util::printf(OBJ_METHOD_PARAMS)
+{
+ int iSize = params.size();
+ if (iSize < 1)
+ return FALSE;
+ std::wstring c_ConvChar((const wchar_t*)(FX_LPCWSTR)params[0].operator CFX_WideString());
+ std::vector<std::wstring> c_strConvers;
+ int iOffset = 0;
+ int iOffend = 0;
+ c_ConvChar.insert(c_ConvChar.begin(),L'S');
+ while(iOffset != -1)
+ {
+ iOffend = c_ConvChar.find(L"%",iOffset+1);
+ std::wstring strSub;
+ if (iOffend == -1)
+ strSub = c_ConvChar.substr(iOffset);
+ else
+ strSub = c_ConvChar.substr(iOffset ,iOffend - iOffset);
+ c_strConvers.push_back(strSub);
+ iOffset = iOffend ;
+ }
+
+ std::wstring c_strResult;
+
+ //for(int iIndex = 1;iIndex < params.size();iIndex++)
+ std::wstring c_strFormat;
+ for(int iIndex = 0;iIndex < (int)c_strConvers.size();iIndex++)
+ {
+ c_strFormat = c_strConvers[iIndex];
+ if (iIndex == 0)
+ {
+ c_strResult = c_strFormat;
+ continue;
+ }
+
+
+ CFX_WideString strSegment;
+ if (iIndex >= iSize) {
+ c_strResult += c_strFormat;
+ continue;
+ }
+
+ switch (ParstDataType(&c_strFormat))
+ {
+ case UTIL_INT:
+ strSegment.Format((FX_LPCWSTR)c_strFormat.c_str(),(int)params[iIndex]);
+ break;
+ case UTIL_DOUBLE:
+ strSegment.Format((FX_LPCWSTR)c_strFormat.c_str(),(double)params[iIndex]);
+ break;
+ case UTIL_STRING:
+ strSegment.Format((FX_LPCWSTR)c_strFormat.c_str(),(FX_LPCWSTR)params[iIndex].operator CFX_WideString());
+ break;
+ default:
+ strSegment.Format((FX_LPCWSTR)L"%S", (FX_LPCWSTR)c_strFormat.c_str());
+ break;
+ }
+ c_strResult += (wchar_t*)strSegment.GetBuffer(strSegment.GetLength()+1);
+ }
+
+ c_strResult.erase(c_strResult.begin());
+ vRet = (FX_LPCWSTR)c_strResult.c_str();
+ return TRUE;
+}
+
+FX_BOOL util::printd(OBJ_METHOD_PARAMS)
+{
+ v8::Isolate* isolate = GetIsolate(cc);
+
+ int iSize = params.size();
+ if (iSize < 2)
+ return FALSE;
+
+ CJS_Value p1(isolate);
+ p1 = params[0];
+
+ CJS_Value p2 = params[1];
+ CJS_Date jsDate(isolate);
+ if (!p2.ConvertToDate(jsDate))
+ {
+ sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPRINT1);
+ return FALSE;
+ }
+
+ if (!jsDate.IsValidDate())
+ {
+ sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPRINT2);
+ return FALSE;
+ }
+
+ if (p1.GetType() == VT_number)
+ {
+ int nFormat = p1;
+
+ CFX_WideString swResult;
+
+ switch (nFormat)
+ {
+ case 0:
+ swResult.Format((FX_LPCWSTR)L"D:%04d%02d%02d%02d%02d%02d",
+ jsDate.GetYear(),
+ jsDate.GetMonth() + 1,
+ jsDate.GetDay(),
+ jsDate.GetHours(),
+ jsDate.GetMinutes(),
+ jsDate.GetSeconds());
+ break;
+ case 1:
+ swResult.Format((FX_LPCWSTR)L"%04d.%02d.%02d %02d:%02d:%02d",
+ jsDate.GetYear(),
+ jsDate.GetMonth() + 1,
+ jsDate.GetDay(),
+ jsDate.GetHours(),
+ jsDate.GetMinutes(),
+ jsDate.GetSeconds());
+ break;
+ case 2:
+ swResult.Format((FX_LPCWSTR)L"%04d/%02d/%02d %02d:%02d:%02d",
+ jsDate.GetYear(),
+ jsDate.GetMonth() + 1,
+ jsDate.GetDay(),
+ jsDate.GetHours(),
+ jsDate.GetMinutes(),
+ jsDate.GetSeconds());
+ break;
+ default:
+ return FALSE;
+ }
+
+ vRet = swResult;
+ return TRUE;
+ }
+ else if (p1.GetType() == VT_string)
+ {
+ std::basic_string<wchar_t> cFormat = (wchar_t*)(FX_LPCWSTR)p1.operator CFX_WideString();
+
+ bool bXFAPicture = false;
+ if (iSize > 2)
+ {
+ //CJS_Value value;
+ bXFAPicture = params[2];
+ }
+
+ if (bXFAPicture)
+ {
+ return FALSE; //currently, it doesn't support XFAPicture.
+ }
+
+ int iIndex;
+ for(iIndex = 0;iIndex<sizeof(fcTable)/sizeof(stru_TbConvert);iIndex++)
+ {
+ int iStart = 0;
+ int iEnd;
+ while((iEnd = cFormat.find((CFX_WideString)fcTable[iIndex].lpszJSMark, iStart)) != -1)
+ {
+ cFormat.replace(iEnd, FXSYS_wcslen(fcTable[iIndex].lpszJSMark), (CFX_WideString)fcTable[iIndex].lpszCppMark);
+ iStart = iEnd;
+ }
+ }
+
+ int iYear,iMonth,iDay,iHour,iMin,iSec;
+ iYear = jsDate.GetYear();
+ iMonth = jsDate.GetMonth();
+ iDay = jsDate.GetDay();
+ iHour = jsDate.GetHours();
+ iMin = jsDate.GetMinutes();
+ iSec = jsDate.GetSeconds();
+
+ struct tm time = {0};
+ time.tm_year = iYear-1900;
+ time.tm_mon = iMonth;
+ time.tm_mday = iDay;
+ time.tm_hour = iHour;
+ time.tm_min = iMin;
+ time.tm_sec = iSec;
+ //COleDateTime cppTm(iYear,iMonth+1,iDay,iHour,iMin,iSec);
+ //CString strFormat = cppTm.Format(cFormat.c_str());
+
+ struct stru_TbConvertAd
+ {
+ FX_LPCWSTR lpszJSMark;
+ int iValue;
+ };
+
+ stru_TbConvertAd cTableAd[] ={
+ (FX_LPCWSTR)L"m", iMonth+1,
+ (FX_LPCWSTR)L"d", iDay,
+ (FX_LPCWSTR)L"H", iHour,
+ (FX_LPCWSTR)L"h", iHour>12?iHour-12:iHour,
+ (FX_LPCWSTR)L"M", iMin,
+ (FX_LPCWSTR)L"s", iSec
+ };
+
+ //cFormat = strFormat.GetBuffer(strFormat.GetLength()+1);
+ for(iIndex = 0;iIndex<sizeof(cTableAd)/sizeof(stru_TbConvertAd);iIndex++)
+ {
+ wchar_t tszValue[10];
+ //_itot(cTableAd[iIndex].iValue,tszValue,10);
+ CFX_WideString sValue;
+ sValue.Format((FX_LPCWSTR)L"%d",cTableAd[iIndex].iValue);
+ memcpy(tszValue, (wchar_t *)sValue.GetBuffer(sValue.GetLength()+1),
+ (sValue.GetLength()+1)*sizeof(wchar_t));
+
+ //strFormat.Replace(cTableAd[iIndex].lpszJSMark,"%d");
+ //strFormat.Format(strFormat,cTableAd[iIndex].iValue);
+ int iStart = 0;
+ int iEnd;
+ while((iEnd = cFormat.find((CFX_WideString)cTableAd[iIndex].lpszJSMark,iStart)) != -1)
+ {
+ if (iEnd > 0)
+ {
+ if (cFormat[iEnd-1] == L'%')
+ {
+ iStart = iEnd+1;
+ continue;
+ }
+ }
+ cFormat.replace(iEnd, FXSYS_wcslen(cTableAd[iIndex].lpszJSMark), tszValue);
+ iStart = iEnd;
+ }
+ }
+
+ CFX_WideString strFormat;
+// strFormat.Format((FX_LPCWSTR)L"%d,%d,%d,%d,%d,%d",iYear, iMonth, iDay, iHour, iMin, iSec);
+// CString strFormat = cppTm.Format(cFormat.c_str());
+ wchar_t buf[64] = {0};
+ strFormat = wcsftime(buf, 64, cFormat.c_str(), &time);
+ cFormat = buf;
+ vRet = (FX_LPCWSTR)cFormat.c_str();
+ //rtRet = strFormat.GetBuffer(strFormat.GetLength()+1);
+ return TRUE;
+ }
+ return FALSE;
+}
+
+void util::printd(const std::wstring &cFormat2, CJS_Date jsDate, bool bXFAPicture, std::wstring &cPurpose)
+{
+ std::wstring cFormat = cFormat2;
+
+ if (bXFAPicture)
+ {
+ return ; //currently, it doesn't support XFAPicture.
+ }
+
+ int iIndex;
+ for(iIndex = 0;iIndex<sizeof(fcTable)/sizeof(stru_TbConvert);iIndex++)
+ {
+ int iStart = 0;
+ int iEnd;
+ while((iEnd = cFormat.find((CFX_WideString)fcTable[iIndex].lpszJSMark,iStart)) != -1)
+ {
+ cFormat.replace(iEnd,FXSYS_wcslen(fcTable[iIndex].lpszJSMark), (CFX_WideString)fcTable[iIndex].lpszCppMark);
+ iStart = iEnd;
+ }
+ }
+
+ int iYear,iMonth,iDay,iHour,iMin,iSec;
+ iYear = jsDate.GetYear();
+ iMonth = jsDate.GetMonth();
+ iDay = jsDate.GetDay();
+ iHour = jsDate.GetHours();
+ iMin = jsDate.GetMinutes();
+ iSec = jsDate.GetSeconds();
+
+ struct tm time = {0};
+ time.tm_year = iYear-1900;
+ time.tm_mon = iMonth;
+ time.tm_mday = iDay;
+ time.tm_hour = iHour;
+ time.tm_min = iMin;
+ time.tm_sec = iSec;
+// COleDateTime cppTm(iYear,iMonth+1,iDay,iHour,iMin,iSec);
+ //CString strFormat = cppTm.Format(cFormat.c_str());
+
+ struct stru_TbConvertAd
+ {
+ FX_LPCWSTR lpszJSMark;
+ int iValue;
+ };
+
+ stru_TbConvertAd cTableAd[] ={
+ (FX_LPCWSTR)L"m", iMonth+1,
+ (FX_LPCWSTR)L"d", iDay,
+ (FX_LPCWSTR)L"H", iHour,
+ (FX_LPCWSTR)L"h", iHour>12?iHour-12:iHour,
+ (FX_LPCWSTR)L"M", iMin,
+ (FX_LPCWSTR)L"s", iSec
+ };
+
+ //cFormat = strFormat.GetBuffer(strFormat.GetLength()+1);
+ for(iIndex = 0;iIndex<sizeof(cTableAd)/sizeof(stru_TbConvertAd);iIndex++)
+ {
+ wchar_t tszValue[10];
+ //_itot(cTableAd[iIndex].iValue,tszValue,10);
+ CFX_WideString sValue;
+ sValue.Format((FX_LPCWSTR)L"%d",cTableAd[iIndex].iValue);
+ memcpy(tszValue, (wchar_t *)sValue.GetBuffer(sValue.GetLength()+1),sValue.GetLength()*sizeof(wchar_t));
+
+
+ //strFormat.Replace(cTableAd[iIndex].lpszJSMark,"%d");
+ //strFormat.Format(strFormat,cTableAd[iIndex].iValue);
+ int iStart = 0;
+ int iEnd;
+ while((iEnd = cFormat.find((CFX_WideString)cTableAd[iIndex].lpszJSMark,iStart)) != -1)
+ {
+ if (iEnd > 0)
+ {
+ if (cFormat[iEnd-1] == L'%')
+ {
+ iStart = iEnd+1;
+ continue;
+ }
+ }
+ cFormat.replace(iEnd,FXSYS_wcslen(cTableAd[iIndex].lpszJSMark),tszValue);
+ iStart = iEnd;
+ }
+ }
+
+ CFX_WideString strFormat;
+// strFormat.Format((FX_LPCWSTR)L"%d,%d,%d,%d,%d,%d",iYear, iMonth, iDay, iHour, iMin, iSec);
+// CString strFormat = cppTm.Format(cFormat.c_str());
+ wchar_t buf[64] = {0};
+ strFormat = wcsftime(buf, 64, cFormat.c_str(), &time);
+ cFormat = buf;
+ cPurpose = cFormat;
+}
+
+FX_BOOL util::printx(OBJ_METHOD_PARAMS)
+{
+ int iSize = params.size();
+ if (iSize<2)
+ return FALSE;
+ CFX_WideString sFormat = params[0].operator CFX_WideString();
+ CFX_WideString sSource = params[1].operator CFX_WideString();
+ std::string cFormat = (FX_LPCSTR)CFX_ByteString::FromUnicode(sFormat);
+ std::string cSource = (FX_LPCSTR)CFX_ByteString::FromUnicode(sSource);
+ std::string cDest;
+ printx(cFormat,cSource,cDest);
+ vRet = cDest.c_str();
+ return TRUE;
+}
+
+void util::printx(const std::string &cFormat,const std::string &cSource2,std::string &cPurpose)
+{
+ std::string cSource(cSource2);
+ if (!cPurpose.empty())
+ //cPurpose.clear();
+ cPurpose.erase();
+ int itSource = 0;
+ int iSize = cSource.size();
+ for(int iIndex = 0; iIndex < (int)cFormat.size() && itSource<iSize; iIndex++)
+ {
+ char letter = cFormat[iIndex];
+ switch(letter)
+ {
+ case '?':
+ //cPurpose.push_back(cSource[itSource]);
+ cPurpose += cSource[itSource];
+ itSource++;
+ break;
+ case 'X':
+ {
+ while(itSource < iSize)
+ {
+ if ((cSource[itSource]>='0'&&cSource[itSource]<='9') || (cSource[itSource]>='a' && cSource[itSource]<='z') || (cSource[itSource]>='A' && cSource[itSource]<='Z'))
+ {
+ //cPurpose.push_back(cSource[itSource]);
+ cPurpose += cSource[itSource];
+ itSource++;
+ break;
+ }
+ itSource++;
+ }
+ break;
+ }
+ break;
+ case 'A':
+ {
+ while(itSource < iSize)
+ {
+ if ((cSource[itSource]>='a' && cSource[itSource]<='z') || (cSource[itSource]>='A' && cSource[itSource]<='Z'))
+ {
+ //cPurpose.push_back(cSource[itSource]);
+ cPurpose += cSource[itSource];
+ itSource++;
+ break;
+ }
+ itSource++;
+ }
+ break;
+ }
+ break;
+ case '9':
+ {
+ while(itSource < iSize)
+ {
+ if (cSource[itSource]>='0'&&cSource[itSource]<='9')
+ {
+ //cPurpose.push_back(cSource[itSource]);
+ cPurpose += cSource[itSource];
+ itSource++;
+ break;
+ }
+ itSource++;
+ }
+ break;
+ }
+ case '*':
+ {
+ cPurpose.append(cSource,itSource,iSize-itSource);
+ itSource = iSize-1;
+ break;
+ }
+ case '\\':
+ break;
+ case '>':
+ {
+ for(std::string::iterator it = cSource.begin();it != cSource.end(); it++)
+ {
+ *it = toupper(*it);
+ }
+ break;
+ }
+ case '<':
+ {
+ for(std::string::iterator it = cSource.begin();it != cSource.end(); it++)
+ {
+ *it = tolower(*it);
+ }
+ break;
+ }
+ case '=':
+ break;
+ default:
+ //cPurpose.push_back(letter);
+ cPurpose += letter;
+ break;
+ }
+ }
+}
+
+FX_BOOL util::scand(OBJ_METHOD_PARAMS)
+{
+ v8::Isolate* isolate = GetIsolate(cc);
+ int iSize = params.size();
+ if (iSize < 2)
+ return FALSE;
+ CFX_WideString sFormat = params[0].operator CFX_WideString();
+ CFX_WideString sDate = params[1].operator CFX_WideString();
+
+ double dDate = JS_GetDateTime();
+ if (sDate.GetLength() > 0)
+ {
+ FX_BOOL bWrongFormat = FALSE;
+ dDate = CJS_PublicMethods::MakeRegularDate(sDate,sFormat,bWrongFormat);
+ }
+
+ if (!JS_PortIsNan(dDate))
+ {
+ CJS_Date date(isolate,dDate);
+ vRet = date;
+ }
+ else
+ {
+ vRet.SetNull();
+ }
+
+ return TRUE;
+}
+
+FX_INT64 FX_atoi64(const char *nptr)
+{
+ int c; /* current char */
+ FX_INT64 total; /* current total */
+ int sign; /* if '-', then negative, otherwise positive */
+
+ /* skip whitespace */
+ while ( isspace((int)(unsigned char)*nptr) )
+ ++nptr;
+
+ c = (int)(unsigned char)*nptr++;
+ sign = c; /* save sign indication */
+ if (c == '-' || c == '+')
+ c = (int)(unsigned char)*nptr++; /* skip sign */
+
+ total = 0;
+
+ while (isdigit(c)) {
+ total = 10 * total + (c - '0'); /* accumulate digit */
+ c = (int)(unsigned char)*nptr++; /* get next char */
+ }
+
+ if (sign == '-')
+ return -total;
+ else
+ return total; /* return result, negated if necessary */
+}
+
+FX_BOOL util::byteToChar(OBJ_METHOD_PARAMS)
+{
+ int iSize = params.size();
+ if (iSize == 0)
+ return FALSE;
+ int nByte = (int)params[0];
+ unsigned char cByte = (unsigned char)nByte;
+ CFX_WideString csValue;
+ csValue.Format((FX_LPCWSTR)L"%c", cByte);
+ vRet = csValue;
+ return TRUE;
+}