From b048f791a15f2da781a01eba5b09eb9d389f9c11 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Tue, 4 Aug 2015 12:19:10 -0700 Subject: clang-format all pdfium code. No behavior change. Generated by: find . -name '*.cpp' -o -name '*.h' | \ grep -E -v 'third_party|thirdparties|lpng_v163' | \ xargs ../../buildtools/mac/clang-format -i See thread "tabs vs spaces" on pdfium@googlegroups.com for discussion. BUG=none R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1265503005 . --- fpdfsdk/src/javascript/Consts.cpp | 373 +- fpdfsdk/src/javascript/Document.cpp | 2834 ++++++------- fpdfsdk/src/javascript/Field.cpp | 6338 ++++++++++++++-------------- fpdfsdk/src/javascript/Icon.cpp | 51 +- fpdfsdk/src/javascript/JS_Context.cpp | 474 ++- fpdfsdk/src/javascript/JS_EventHandler.cpp | 927 ++-- fpdfsdk/src/javascript/JS_GlobalData.cpp | 840 ++-- fpdfsdk/src/javascript/JS_Object.cpp | 171 +- fpdfsdk/src/javascript/JS_Runtime.cpp | 484 ++- fpdfsdk/src/javascript/JS_Value.cpp | 784 ++-- fpdfsdk/src/javascript/PublicMethods.cpp | 3818 ++++++++--------- fpdfsdk/src/javascript/app.cpp | 1529 ++++--- fpdfsdk/src/javascript/color.cpp | 367 +- fpdfsdk/src/javascript/console.cpp | 60 +- fpdfsdk/src/javascript/event.cpp | 590 +-- fpdfsdk/src/javascript/global.cpp | 857 ++-- fpdfsdk/src/javascript/report.cpp | 26 +- fpdfsdk/src/javascript/resource.cpp | 64 +- fpdfsdk/src/javascript/util.cpp | 960 ++--- 19 files changed, 10562 insertions(+), 10985 deletions(-) (limited to 'fpdfsdk/src/javascript') diff --git a/fpdfsdk/src/javascript/Consts.cpp b/fpdfsdk/src/javascript/Consts.cpp index 9edb6f443b..5ff5528e29 100644 --- a/fpdfsdk/src/javascript/Consts.cpp +++ b/fpdfsdk/src/javascript/Consts.cpp @@ -14,234 +14,251 @@ /* ------------------------------ 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) +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) +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) +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) +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) +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) +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) +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) +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) +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) +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) +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) +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) +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) +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) +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) - +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) +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; +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) -{ - { - const FX_WCHAR* ArrayName = L"RE_NUMBER_ENTRY_DOT_SEP"; - const FX_WCHAR* ArrayContent[] = {L"[+-]?\\d*\\.?\\d*"}; - DEFINE_GLOBAL_ARRAY(pRuntime); - } - - { - const FX_WCHAR* ArrayName = L"RE_NUMBER_COMMIT_DOT_SEP"; - const FX_WCHAR* ArrayContent[] = { L"[+-]?\\d+(\\.\\d+)?", /* -1.0 or -1 */ - L"[+-]?\\.\\d+", /* -.1 */ - L"[+-]?\\d+\\." /* -1. */ - }; - DEFINE_GLOBAL_ARRAY(pRuntime); - } - - { - const FX_WCHAR* ArrayName = L"RE_NUMBER_ENTRY_COMMA_SEP"; - const FX_WCHAR* ArrayContent[] = {L"[+-]?\\d*,?\\d*"}; - - DEFINE_GLOBAL_ARRAY(pRuntime); - } - - { - const FX_WCHAR* ArrayName = L"RE_NUMBER_COMMIT_COMMA_SEP"; - const FX_WCHAR* ArrayContent[] = { L"[+-]?\\d+([.,]\\d+)?", /* -1,0 or -1 */ - L"[+-]?[.,]\\d+", /* -,1 */ - L"[+-]?\\d+[.,]" /* -1, */ - }; - DEFINE_GLOBAL_ARRAY(pRuntime); - } - - { - const FX_WCHAR* ArrayName = L"RE_ZIP_ENTRY"; - const FX_WCHAR* ArrayContent[] = {L"\\d{0,5}"}; - DEFINE_GLOBAL_ARRAY(pRuntime); - } - - { - const FX_WCHAR* ArrayName = L"RE_ZIP_COMMIT"; - const FX_WCHAR* ArrayContent[] = {L"\\d{5}"}; - DEFINE_GLOBAL_ARRAY(pRuntime); - } - - { - const FX_WCHAR* ArrayName = L"RE_ZIP4_ENTRY"; - const FX_WCHAR* ArrayContent[] = {L"\\d{0,5}(\\.|[- ])?\\d{0,4}"}; - DEFINE_GLOBAL_ARRAY(pRuntime); - } - - { - const FX_WCHAR* ArrayName = L"RE_ZIP4_COMMIT"; - const FX_WCHAR* ArrayContent[] = {L"\\d{5}(\\.|[- ])?\\d{4}"}; - DEFINE_GLOBAL_ARRAY(pRuntime); - } - - { - const FX_WCHAR* ArrayName = L"RE_PHONE_ENTRY"; - const FX_WCHAR* ArrayContent[] = { - L"\\d{0,3}(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}", /* 555-1234 or 408 555-1234 */ - L"\\(\\d{0,3}", /* (408 */ - L"\\(\\d{0,3}\\)(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}", /* (408) 555-1234 */ - /* (allow the addition of parens as an afterthought) */ - L"\\(\\d{0,3}(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}", /* (408 555-1234 */ - L"\\d{0,3}\\)(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}", /* 408) 555-1234 */ - L"011(\\.|[- \\d])*" /* international */ - }; - DEFINE_GLOBAL_ARRAY(pRuntime); - } - - { - const FX_WCHAR* ArrayName = L"RE_PHONE_COMMIT"; - const FX_WCHAR* ArrayContent[] = { - L"\\d{3}(\\.|[- ])?\\d{4}", /* 555-1234 */ - L"\\d{3}(\\.|[- ])?\\d{3}(\\.|[- ])?\\d{4}", /* 408 555-1234 */ - L"\\(\\d{3}\\)(\\.|[- ])?\\d{3}(\\.|[- ])?\\d{4}", /* (408) 555-1234 */ - L"011(\\.|[- \\d])*" /* international */ - }; - DEFINE_GLOBAL_ARRAY(pRuntime); - } - - { - const FX_WCHAR* ArrayName = L"RE_SSN_ENTRY"; - const FX_WCHAR* ArrayContent[] = {L"\\d{0,3}(\\.|[- ])?\\d{0,2}(\\.|[- ])?\\d{0,4}"}; - DEFINE_GLOBAL_ARRAY(pRuntime); - } - - { - const FX_WCHAR* ArrayName = L"RE_SSN_COMMIT"; - const FX_WCHAR* ArrayContent[] = {L"\\d{3}(\\.|[- ])?\\d{2}(\\.|[- ])?\\d{4}"}; - DEFINE_GLOBAL_ARRAY(pRuntime); - } - - return 0; +/* ------------------------------ CJS_GlobalArrays + * ------------------------------ */ + +int CJS_GlobalArrays::Init(IJS_Runtime* pRuntime) { + { + const FX_WCHAR* ArrayName = L"RE_NUMBER_ENTRY_DOT_SEP"; + const FX_WCHAR* ArrayContent[] = {L"[+-]?\\d*\\.?\\d*"}; + DEFINE_GLOBAL_ARRAY(pRuntime); + } + + { + const FX_WCHAR* ArrayName = L"RE_NUMBER_COMMIT_DOT_SEP"; + const FX_WCHAR* ArrayContent[] = { + L"[+-]?\\d+(\\.\\d+)?", /* -1.0 or -1 */ + L"[+-]?\\.\\d+", /* -.1 */ + L"[+-]?\\d+\\." /* -1. */ + }; + DEFINE_GLOBAL_ARRAY(pRuntime); + } + + { + const FX_WCHAR* ArrayName = L"RE_NUMBER_ENTRY_COMMA_SEP"; + const FX_WCHAR* ArrayContent[] = {L"[+-]?\\d*,?\\d*"}; + + DEFINE_GLOBAL_ARRAY(pRuntime); + } + + { + const FX_WCHAR* ArrayName = L"RE_NUMBER_COMMIT_COMMA_SEP"; + const FX_WCHAR* ArrayContent[] = { + L"[+-]?\\d+([.,]\\d+)?", /* -1,0 or -1 */ + L"[+-]?[.,]\\d+", /* -,1 */ + L"[+-]?\\d+[.,]" /* -1, */ + }; + DEFINE_GLOBAL_ARRAY(pRuntime); + } + + { + const FX_WCHAR* ArrayName = L"RE_ZIP_ENTRY"; + const FX_WCHAR* ArrayContent[] = {L"\\d{0,5}"}; + DEFINE_GLOBAL_ARRAY(pRuntime); + } + + { + const FX_WCHAR* ArrayName = L"RE_ZIP_COMMIT"; + const FX_WCHAR* ArrayContent[] = {L"\\d{5}"}; + DEFINE_GLOBAL_ARRAY(pRuntime); + } + + { + const FX_WCHAR* ArrayName = L"RE_ZIP4_ENTRY"; + const FX_WCHAR* ArrayContent[] = {L"\\d{0,5}(\\.|[- ])?\\d{0,4}"}; + DEFINE_GLOBAL_ARRAY(pRuntime); + } + + { + const FX_WCHAR* ArrayName = L"RE_ZIP4_COMMIT"; + const FX_WCHAR* ArrayContent[] = {L"\\d{5}(\\.|[- ])?\\d{4}"}; + DEFINE_GLOBAL_ARRAY(pRuntime); + } + + { + const FX_WCHAR* ArrayName = L"RE_PHONE_ENTRY"; + const FX_WCHAR* ArrayContent[] = { + L"\\d{0,3}(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}", /* 555-1234 or 408 + 555-1234 */ + L"\\(\\d{0,3}", /* (408 */ + L"\\(\\d{0,3}\\)(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}", /* (408) + 555-1234 */ + /* (allow the addition of parens as an afterthought) */ + L"\\(\\d{0,3}(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}", /* (408 555-1234 + */ + L"\\d{0,3}\\)(\\.|[- ])?\\d{0,3}(\\.|[- ])?\\d{0,4}", /* 408) 555-1234 + */ + L"011(\\.|[- \\d])*" /* international */ + }; + DEFINE_GLOBAL_ARRAY(pRuntime); + } + + { + const FX_WCHAR* ArrayName = L"RE_PHONE_COMMIT"; + const FX_WCHAR* ArrayContent[] = { + L"\\d{3}(\\.|[- ])?\\d{4}", /* 555-1234 */ + L"\\d{3}(\\.|[- ])?\\d{3}(\\.|[- ])?\\d{4}", /* 408 555-1234 */ + L"\\(\\d{3}\\)(\\.|[- ])?\\d{3}(\\.|[- ])?\\d{4}", /* (408) 555-1234 */ + L"011(\\.|[- \\d])*" /* international */ + }; + DEFINE_GLOBAL_ARRAY(pRuntime); + } + + { + const FX_WCHAR* ArrayName = L"RE_SSN_ENTRY"; + const FX_WCHAR* ArrayContent[] = { + L"\\d{0,3}(\\.|[- ])?\\d{0,2}(\\.|[- ])?\\d{0,4}"}; + DEFINE_GLOBAL_ARRAY(pRuntime); + } + + { + const FX_WCHAR* ArrayName = L"RE_SSN_COMMIT"; + const FX_WCHAR* ArrayContent[] = { + 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 59816f091f..7ce8449f3c 100644 --- a/fpdfsdk/src/javascript/Document.cpp +++ b/fpdfsdk/src/javascript/Document.cpp @@ -20,15 +20,14 @@ #include "../../../third_party/base/numerics/safe_math.h" -static v8::Isolate* GetIsolate(IFXJS_Context* cc) -{ - CJS_Context* pContext = (CJS_Context *)cc; - ASSERT(pContext != NULL); +static v8::Isolate* GetIsolate(IFXJS_Context* cc) { + CJS_Context* pContext = (CJS_Context*)cc; + ASSERT(pContext != NULL); - CJS_Runtime* pRuntime = pContext->GetJSRuntime(); - ASSERT(pRuntime != NULL); + CJS_Runtime* pRuntime = pContext->GetJSRuntime(); + ASSERT(pRuntime != NULL); - return pRuntime->GetIsolate(); + return pRuntime->GetIsolate(); } BEGIN_JS_STATIC_CONST(CJS_PrintParamsObj) @@ -43,1699 +42,1709 @@ 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; + : 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 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) +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) - JS_STATIC_METHOD_ENTRY(addField) - JS_STATIC_METHOD_ENTRY(addLink) - JS_STATIC_METHOD_ENTRY(addIcon) - JS_STATIC_METHOD_ENTRY(calculateNow) - JS_STATIC_METHOD_ENTRY(closeDoc) - JS_STATIC_METHOD_ENTRY(createDataObject) - JS_STATIC_METHOD_ENTRY(deletePages) - JS_STATIC_METHOD_ENTRY(exportAsText) - JS_STATIC_METHOD_ENTRY(exportAsFDF) - JS_STATIC_METHOD_ENTRY(exportAsXFDF) - JS_STATIC_METHOD_ENTRY(extractPages) - JS_STATIC_METHOD_ENTRY(getAnnot) - JS_STATIC_METHOD_ENTRY(getAnnots) - JS_STATIC_METHOD_ENTRY(getAnnot3D) - JS_STATIC_METHOD_ENTRY(getAnnots3D) - JS_STATIC_METHOD_ENTRY(getField) - JS_STATIC_METHOD_ENTRY(getIcon) - JS_STATIC_METHOD_ENTRY(getLinks) - JS_STATIC_METHOD_ENTRY(getNthFieldName) - JS_STATIC_METHOD_ENTRY(getOCGs) - JS_STATIC_METHOD_ENTRY(getPageBox) - JS_STATIC_METHOD_ENTRY(getPageNthWord) - JS_STATIC_METHOD_ENTRY(getPageNthWordQuads) - JS_STATIC_METHOD_ENTRY(getPageNumWords) - JS_STATIC_METHOD_ENTRY(getPrintParams) - JS_STATIC_METHOD_ENTRY(getURL) - JS_STATIC_METHOD_ENTRY(importAnFDF) - JS_STATIC_METHOD_ENTRY(importAnXFDF) - JS_STATIC_METHOD_ENTRY(importTextData) - JS_STATIC_METHOD_ENTRY(insertPages) - JS_STATIC_METHOD_ENTRY(mailForm) - JS_STATIC_METHOD_ENTRY(print) - JS_STATIC_METHOD_ENTRY(removeField) - JS_STATIC_METHOD_ENTRY(replacePages) - JS_STATIC_METHOD_ENTRY(resetForm) - JS_STATIC_METHOD_ENTRY(removeIcon) - JS_STATIC_METHOD_ENTRY(saveAs) - JS_STATIC_METHOD_ENTRY(submitForm) - JS_STATIC_METHOD_ENTRY(mailDoc) +JS_STATIC_METHOD_ENTRY(addAnnot) +JS_STATIC_METHOD_ENTRY(addField) +JS_STATIC_METHOD_ENTRY(addLink) +JS_STATIC_METHOD_ENTRY(addIcon) +JS_STATIC_METHOD_ENTRY(calculateNow) +JS_STATIC_METHOD_ENTRY(closeDoc) +JS_STATIC_METHOD_ENTRY(createDataObject) +JS_STATIC_METHOD_ENTRY(deletePages) +JS_STATIC_METHOD_ENTRY(exportAsText) +JS_STATIC_METHOD_ENTRY(exportAsFDF) +JS_STATIC_METHOD_ENTRY(exportAsXFDF) +JS_STATIC_METHOD_ENTRY(extractPages) +JS_STATIC_METHOD_ENTRY(getAnnot) +JS_STATIC_METHOD_ENTRY(getAnnots) +JS_STATIC_METHOD_ENTRY(getAnnot3D) +JS_STATIC_METHOD_ENTRY(getAnnots3D) +JS_STATIC_METHOD_ENTRY(getField) +JS_STATIC_METHOD_ENTRY(getIcon) +JS_STATIC_METHOD_ENTRY(getLinks) +JS_STATIC_METHOD_ENTRY(getNthFieldName) +JS_STATIC_METHOD_ENTRY(getOCGs) +JS_STATIC_METHOD_ENTRY(getPageBox) +JS_STATIC_METHOD_ENTRY(getPageNthWord) +JS_STATIC_METHOD_ENTRY(getPageNthWordQuads) +JS_STATIC_METHOD_ENTRY(getPageNumWords) +JS_STATIC_METHOD_ENTRY(getPrintParams) +JS_STATIC_METHOD_ENTRY(getURL) +JS_STATIC_METHOD_ENTRY(importAnFDF) +JS_STATIC_METHOD_ENTRY(importAnXFDF) +JS_STATIC_METHOD_ENTRY(importTextData) +JS_STATIC_METHOD_ENTRY(insertPages) +JS_STATIC_METHOD_ENTRY(mailForm) +JS_STATIC_METHOD_ENTRY(print) +JS_STATIC_METHOD_ENTRY(removeField) +JS_STATIC_METHOD_ENTRY(replacePages) +JS_STATIC_METHOD_ENTRY(resetForm) +JS_STATIC_METHOD_ENTRY(removeIcon) +JS_STATIC_METHOD_ENTRY(saveAs) +JS_STATIC_METHOD_ENTRY(submitForm) +JS_STATIC_METHOD_ENTRY(mailDoc) 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); +FX_BOOL CJS_Document::InitInstance(IFXJS_Context* cc) { + CJS_Context* pContext = (CJS_Context*)cc; + ASSERT(pContext != NULL); - Document* pDoc = (Document*)GetEmbedObject(); - ASSERT(pDoc != NULL); + Document* pDoc = (Document*)GetEmbedObject(); + ASSERT(pDoc != NULL); - pDoc->AttachDoc(pContext->GetReaderDocument()); - pDoc->SetIsolate(pContext->GetJSRuntime()->GetIsolate()); - return TRUE; + pDoc->AttachDoc(pContext->GetReaderDocument()); + pDoc->SetIsolate(pContext->GetJSRuntime()->GetIsolate()); + return TRUE; }; -/* --------------------------------- Document --------------------------------- */ - -Document::Document(CJS_Object* pJSObject) : CJS_EmbedObj(pJSObject), - m_isolate(NULL), - m_pIconTree(NULL), - m_pDocument(NULL), - m_cwBaseURL(L""), - m_bDelay(FALSE) -{ -} - -Document::~Document() -{ - if (m_pIconTree) - { - m_pIconTree->DeleteIconTree(); - delete m_pIconTree; - m_pIconTree = NULL; - } - for (int i=0; i(cc); - sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY); - return FALSE; - } - CPDFSDK_InterForm *pInterForm = m_pDocument->GetInterForm(); - CPDF_InterForm *pPDFForm = pInterForm->GetInterForm(); - vp << (int)pPDFForm->CountFields(); - return TRUE; +/* --------------------------------- Document --------------------------------- + */ + +Document::Document(CJS_Object* pJSObject) + : CJS_EmbedObj(pJSObject), + m_isolate(NULL), + m_pIconTree(NULL), + m_pDocument(NULL), + m_cwBaseURL(L""), + m_bDelay(FALSE) {} + +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(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + if (vp.IsSetting()) { + CJS_Context* pContext = static_cast(cc); + sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY); + return FALSE; + } + CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); + CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); + vp << (int)pPDFForm->CountFields(); + return TRUE; } -FX_BOOL Document::dirty(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); +FX_BOOL Document::dirty(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); - if (vp.IsGetting()) - { - if (m_pDocument->GetChangeMark()) - vp << true; - else - vp << false; - } + if (vp.IsGetting()) { + if (m_pDocument->GetChangeMark()) + vp << true; else - { - bool bChanged = false; + vp << false; + } else { + bool bChanged = false; - vp >> bChanged; + vp >> bChanged; - if (bChanged) - m_pDocument->SetChangeMark(); - else - m_pDocument->ClearChangeMark(); - } + if (bChanged) + m_pDocument->SetChangeMark(); + else + m_pDocument->ClearChangeMark(); + } - return TRUE; + return TRUE; } -FX_BOOL Document::ADBE(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); +FX_BOOL Document::ADBE(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); - if (vp.IsGetting()) - { - vp.SetNull(); - } - else - { - } + if (vp.IsGetting()) { + vp.SetNull(); + } else { + } - return TRUE; + return TRUE; } -FX_BOOL Document::pageNum(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); +FX_BOOL Document::pageNum(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); - if (vp.IsGetting()) - { - if (CPDFSDK_PageView* pPageView = m_pDocument->GetCurrentView()) - { - vp << pPageView->GetPageIndex(); - } + 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 (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); - } + } else { + int iPageCount = m_pDocument->GetPageCount(); + int iPageNum = 0; + vp >> iPageNum; + + CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); + 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; + return TRUE; } -FX_BOOL Document::ParserParams(JSObject* pObj,CJS_AnnotObj& annotobj) -{ - // Not supported. - return TRUE; +FX_BOOL Document::ParserParams(JSObject* pObj, CJS_AnnotObj& annotobj) { + // Not supported. + return TRUE; } -FX_BOOL Document::addAnnot(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - // Not supported. - return TRUE; +FX_BOOL Document::addAnnot(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + // Not supported. + return TRUE; } -FX_BOOL Document::addField(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - // Not supported. - return TRUE; +FX_BOOL Document::addField(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + // Not supported. + return TRUE; } -FX_BOOL Document::exportAsText(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - // Unsafe, not supported. - return TRUE; +FX_BOOL Document::exportAsText(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + // Unsafe, not supported. + return TRUE; } -FX_BOOL Document::exportAsFDF(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - // Unsafe, not supported. - return TRUE; +FX_BOOL Document::exportAsFDF(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + // Unsafe, not supported. + return TRUE; } -FX_BOOL Document::exportAsXFDF(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - // Unsafe, not supported. - return TRUE; +FX_BOOL Document::exportAsXFDF(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + // Unsafe, not supported. + 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 +// 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(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - CJS_Context* pContext = (CJS_Context*)cc; - if (params.size() < 1) { - sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); - return FALSE; - } +FX_BOOL Document::getField(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + CJS_Context* pContext = (CJS_Context*)cc; + if (params.size() < 1) { + sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); + return FALSE; + } - CFX_WideString wideName = params[0].ToCFXWideString(); + CFX_WideString wideName = params[0].ToCFXWideString(); - CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); - CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); - if (pPDFForm->CountFields(wideName) <= 0) - { - vRet.SetNull(); - return TRUE; - } + CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); + CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); + if (pPDFForm->CountFields(wideName) <= 0) { + vRet.SetNull(); + return TRUE; + } - CJS_Runtime* pRuntime = pContext->GetJSRuntime(); - JSFXObject pFieldObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"Field")); + CJS_Runtime* pRuntime = pContext->GetJSRuntime(); + JSFXObject pFieldObj = JS_NewFxDynamicObj( + *pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"Field")); - v8::Isolate* isolate = GetIsolate(cc); - CJS_Field* pJSField = (CJS_Field*)JS_GetPrivate(isolate,pFieldObj); - Field* pField = (Field *)pJSField->GetEmbedObject(); - pField->AttachField(this, wideName); + v8::Isolate* isolate = GetIsolate(cc); + CJS_Field* pJSField = (CJS_Field*)JS_GetPrivate(isolate, pFieldObj); + Field* pField = (Field*)pJSField->GetEmbedObject(); + pField->AttachField(this, wideName); - vRet = pJSField; - return TRUE; + vRet = pJSField; + return TRUE; } -//Gets the name of the nth field in the document -FX_BOOL Document::getNthFieldName(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - CJS_Context* pContext = (CJS_Context*)cc; - if (params.size() != 1) { - sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); - return FALSE; - } +// Gets the name of the nth field in the document +FX_BOOL Document::getNthFieldName(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + CJS_Context* pContext = (CJS_Context*)cc; + if (params.size() != 1) { + sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); + return FALSE; + } - int nIndex = params[0].ToInt(); - if (nIndex < 0) { - sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR); - return FALSE; - } + int nIndex = params[0].ToInt(); + if (nIndex < 0) { + sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR); + return FALSE; + } - CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); - CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); - CPDF_FormField* pField = pPDFForm->GetField(nIndex); - if (!pField) - return FALSE; + CPDFSDK_InterForm* pInterForm = m_pDocument->GetInterForm(); + CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); + CPDF_FormField* pField = pPDFForm->GetField(nIndex); + if (!pField) + return FALSE; - vRet = pField->GetFullName().c_str(); - return TRUE; + vRet = pField->GetFullName().c_str(); + return TRUE; } -FX_BOOL Document::importAnFDF(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - // Unsafe, not supported. - return TRUE; +FX_BOOL Document::importAnFDF(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + // Unsafe, not supported. + return TRUE; } -FX_BOOL Document::importAnXFDF(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - // Unsafe, not supported. - return TRUE; +FX_BOOL Document::importAnXFDF(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + // Unsafe, not supported. + return TRUE; } -FX_BOOL Document::importTextData(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - // Unsafe, not supported. - return TRUE; +FX_BOOL Document::importTextData(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + // Unsafe, not supported. + 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(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); +// 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); - if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE; +FX_BOOL Document::mailForm(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); - int iLength = params.size(); + if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) + return FALSE; - FX_BOOL bUI = iLength > 0 ? params[0].ToBool() : TRUE; - CFX_WideString cTo = iLength > 1 ? params[1].ToCFXWideString() : L""; - CFX_WideString cCc = iLength > 2 ? params[2].ToCFXWideString() : L""; - CFX_WideString cBcc = iLength > 3 ? params[3].ToCFXWideString() : L""; - CFX_WideString cSubject = iLength > 4 ? params[4].ToCFXWideString() : L""; - CFX_WideString cMsg = iLength > 5 ? params[5].ToCFXWideString() : L""; + int iLength = params.size(); - CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); - ASSERT(pInterForm != NULL); + FX_BOOL bUI = iLength > 0 ? params[0].ToBool() : TRUE; + CFX_WideString cTo = iLength > 1 ? params[1].ToCFXWideString() : L""; + CFX_WideString cCc = iLength > 2 ? params[2].ToCFXWideString() : L""; + CFX_WideString cBcc = iLength > 3 ? params[3].ToCFXWideString() : L""; + CFX_WideString cSubject = iLength > 4 ? params[4].ToCFXWideString() : L""; + CFX_WideString cMsg = iLength > 5 ? params[5].ToCFXWideString() : L""; - CFX_ByteTextBuf textBuf; - if (!pInterForm->ExportFormToFDFTextBuf(textBuf)) - return FALSE; + CPDFSDK_InterForm* pInterForm = + (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); + ASSERT(pInterForm != NULL); - 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); + CFX_ByteTextBuf textBuf; + if (!pInterForm->ExportFormToFDFTextBuf(textBuf)) + return FALSE; - pRuntime->BeginBlock(); - pEnv->JS_docmailForm(textBuf.GetBuffer(), textBuf.GetLength(), bUI, cTo.c_str(), cSubject.c_str(), cCc.c_str(), cBcc.c_str(), cMsg.c_str()); - pRuntime->EndBlock(); - return TRUE; + 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, + cTo.c_str(), cSubject.c_str(), cCc.c_str(), cBcc.c_str(), + cMsg.c_str()); + pRuntime->EndBlock(); + return TRUE; } -FX_BOOL Document::print(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - 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 = params[8].ToV8Object(); - { - if (JS_GetObjDefnID(pObj) == JS_GetObjDefnID(*pRuntime, L"PrintParamsObj")) - { - if (CJS_Object* pJSObj = params[8].ToCJSObject()) - { - 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; - } - } - } +FX_BOOL Document::print(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + 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 = params[8].ToV8Object(); + { + if (JS_GetObjDefnID(pObj) == + JS_GetObjDefnID(*pRuntime, L"PrintParamsObj")) { + if (CJS_Object* pJSObj = params[8].ToCJSObject()) { + 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].ToBool(); - if(nlength >= 2) - nStart = params[1].ToInt(); - if(nlength >= 3) - nEnd = params[2].ToInt(); - if(nlength >= 4) - bSilent = params[3].ToBool(); - if(nlength >= 5) - bShrinkToFit = params[4].ToBool(); - if(nlength >= 6) - bPrintAsImage = params[5].ToBool(); - if(nlength >= 7) - bReverse = params[6].ToBool(); - if(nlength >= 8) - bAnnotations = params[7].ToBool(); - } - - 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; + } + } + } else { + if (nlength >= 1) + bUI = params[0].ToBool(); + if (nlength >= 2) + nStart = params[1].ToInt(); + if (nlength >= 3) + nEnd = params[2].ToInt(); + if (nlength >= 4) + bSilent = params[3].ToBool(); + if (nlength >= 5) + bShrinkToFit = params[4].ToBool(); + if (nlength >= 6) + bPrintAsImage = params[5].ToBool(); + if (nlength >= 7) + bReverse = params[6].ToBool(); + if (nlength >= 8) + bAnnotations = params[7].ToBool(); + } + + 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. +// 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(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); +FX_BOOL Document::removeField(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); - if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || - m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM))) return FALSE; + if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || + m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM))) + return FALSE; - CJS_Context* pContext = (CJS_Context*)cc; - if (params.size() != 1) { - sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); - return FALSE; - } + CJS_Context* pContext = (CJS_Context*)cc; + if (params.size() != 1) { + sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); + return FALSE; + } - CFX_WideString sFieldName = params[0].ToCFXWideString(); - CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); - ASSERT(pInterForm != NULL); + CFX_WideString sFieldName = params[0].ToCFXWideString(); + CPDFSDK_InterForm* pInterForm = + (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); + ASSERT(pInterForm != NULL); - CFX_PtrArray widgets; - pInterForm->GetWidgets(sFieldName, widgets); + CFX_PtrArray widgets; + pInterForm->GetWidgets(sFieldName, widgets); - int nSize = widgets.GetSize(); + int nSize = widgets.GetSize(); - if (nSize > 0) - { - for (int i=0; i 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; + CPDF_Rect rcAnnot = pWidget->GetRect(); + rcAnnot.left -= 1; + rcAnnot.bottom -= 1; + rcAnnot.right += 1; + rcAnnot.top += 1; - CFX_RectArray aRefresh; - aRefresh.Add(rcAnnot); + CFX_RectArray aRefresh; + aRefresh.Add(rcAnnot); - CPDF_Page* pPage = pWidget->GetPDFPage(); - ASSERT(pPage != NULL); + CPDF_Page* pPage = pWidget->GetPDFPage(); + ASSERT(pPage != NULL); - CPDFSDK_PageView* pPageView = m_pDocument->GetPageView(pPage); - pPageView->DeleteAnnot(pWidget); + CPDFSDK_PageView* pPageView = m_pDocument->GetPageView(pPage); + pPageView->DeleteAnnot(pWidget); - pPageView->UpdateRects(aRefresh); - } - m_pDocument->SetChangeMark(); + pPageView->UpdateRects(aRefresh); } + m_pDocument->SetChangeMark(); + } - return TRUE; + return TRUE; } -//reset filed values within a document. -//comment: -//note: if the fields names r not rational, aodbe is dumb for it. +// reset filed values within a document. +// comment: +// note: if the fields names r not rational, aodbe is dumb for it. -FX_BOOL Document::resetForm(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); +FX_BOOL Document::resetForm(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); - if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || + if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) || - m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) return FALSE; + m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) + return FALSE; - CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); - ASSERT(pInterForm != NULL); + 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].ToV8Array()); - break; - case VT_string: - aName.SetElement(0,params[0]); - break; - } + CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); + ASSERT(pPDFForm != NULL); - CFX_PtrArray aFields; + v8::Isolate* isolate = GetIsolate(cc); + CJS_Array aName(isolate); - for (int i=0,isz=aName.GetLength(); i 0) { + switch (params[0].GetType()) { + default: + aName.Attach(params[0].ToV8Array()); + break; + case VT_string: + aName.SetElement(0, params[0]); + break; + } - for (int j=0,jsz=pPDFForm->CountFields(swVal); jGetField(j,swVal)); - } - } + CFX_PtrArray aFields; - if (aFields.GetSize() > 0) - { - pPDFForm->ResetForm(aFields, TRUE, TRUE); - m_pDocument->SetChangeMark(); + for (int i = 0, isz = aName.GetLength(); i < isz; i++) { + CJS_Value valElement(isolate); + aName.GetElement(i, valElement); + CFX_WideString swVal = valElement.ToCFXWideString(); - } + for (int j = 0, jsz = pPDFForm->CountFields(swVal); j < jsz; j++) { + aFields.Add((void*)pPDFForm->GetField(j, swVal)); + } } - else - { - pPDFForm->ResetForm(TRUE); - m_pDocument->SetChangeMark(); + if (aFields.GetSize() > 0) { + pPDFForm->ResetForm(aFields, TRUE, TRUE); + m_pDocument->SetChangeMark(); } + } else { + pPDFForm->ResetForm(TRUE); + m_pDocument->SetChangeMark(); + } - return TRUE; + return TRUE; } - -FX_BOOL Document::saveAs(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ +FX_BOOL Document::saveAs(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { // Unsafe, not supported. return TRUE; } - -FX_BOOL Document::submitForm(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); - CJS_Context* pContext = (CJS_Context*)cc; - int nSize = params.size(); - if (nSize < 1) { - sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); - return FALSE; +FX_BOOL Document::submitForm(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); + CJS_Context* pContext = (CJS_Context*)cc; + int nSize = params.size(); + if (nSize < 1) { + sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); + 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].ToCFXWideString(); + if (nSize > 1) + bFDF = params[1].ToBool(); + if (nSize > 2) + bEmpty = params[2].ToBool(); + if (nSize > 3) + aFields.Attach(params[3].ToV8Array()); + } else if (v.GetType() == VT_object) { + JSObject pObj = params[0].ToV8Object(); + v8::Local pValue = JS_GetObjectElement(isolate, pObj, L"cURL"); + if (!pValue.IsEmpty()) + strURL = + CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); + pValue = JS_GetObjectElement(isolate, pObj, L"bFDF"); + bFDF = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToBool(); + pValue = JS_GetObjectElement(isolate, pObj, L"bEmpty"); + bEmpty = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToBool(); + pValue = JS_GetObjectElement(isolate, pObj, L"aFields"); + aFields.Attach( + CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToV8Array()); + } + + CJS_Runtime* pRuntime = pContext->GetJSRuntime(); + CPDFSDK_InterForm* pInterForm = + (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); + CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); + FX_BOOL bAll = (aFields.GetLength() == 0); + if (bAll && bEmpty) { + if (pPDFInterForm->CheckRequiredFields()) { + pRuntime->BeginBlock(); + pInterForm->SubmitForm(strURL, FALSE); + pRuntime->EndBlock(); } + return TRUE; + } - 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].ToCFXWideString(); - if (nSize > 1) - bFDF = params[1].ToBool(); - if (nSize > 2) - bEmpty = params[2].ToBool(); - if (nSize > 3) - aFields.Attach(params[3].ToV8Array()); - } - else if (v.GetType() == VT_object) - { - JSObject pObj = params[0].ToV8Object(); - v8::Local pValue = JS_GetObjectElement(isolate, pObj, L"cURL"); - if (!pValue.IsEmpty()) - strURL = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); - pValue = JS_GetObjectElement(isolate, pObj, L"bFDF"); - bFDF = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToBool(); - pValue = JS_GetObjectElement(isolate, pObj, L"bEmpty"); - bEmpty = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToBool(); - pValue = JS_GetObjectElement(isolate, pObj,L"aFields"); - aFields.Attach(CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToV8Array()); - } + CFX_PtrArray fieldObjects; + for (int i = 0, sz = aFields.GetLength(); i < sz; i++) { + CJS_Value valName(isolate); + aFields.GetElement(i, valName); - CJS_Runtime* pRuntime = pContext->GetJSRuntime(); - CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); - CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); - FX_BOOL bAll = (aFields.GetLength() == 0); - if (bAll && bEmpty) - { - if (pPDFInterForm->CheckRequiredFields()) - { - pRuntime->BeginBlock(); - pInterForm->SubmitForm(strURL, FALSE); - pRuntime->EndBlock(); - } - return TRUE; - } + CFX_WideString sName = valName.ToCFXWideString(); + CPDF_InterForm* pPDFForm = pInterForm->GetInterForm(); + for (int j = 0, jsz = pPDFForm->CountFields(sName); j < jsz; ++j) { + CPDF_FormField* pField = pPDFForm->GetField(j, sName); + if (!bEmpty && pField->GetValue().IsEmpty()) + continue; - CFX_PtrArray fieldObjects; - for (int i=0,sz=aFields.GetLength(); iGetInterForm(); - 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); - } + fieldObjects.Add(pField); } + } - if (pPDFInterForm->CheckRequiredFields(&fieldObjects, TRUE)) - { - pRuntime->BeginBlock(); - pInterForm->SubmitFields(strURL, fieldObjects, TRUE, !bFDF); - pRuntime->EndBlock(); - } - return TRUE; + 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; +void Document::AttachDoc(CPDFSDK_Document* pDoc) { + m_pDocument = pDoc; } -CPDFSDK_Document * Document::GetReaderDoc() -{ - return m_pDocument; +CPDFSDK_Document* Document::GetReaderDoc() { + return m_pDocument; } -FX_BOOL Document::ExtractFileName(CPDFSDK_Document *pDoc,CFX_ByteString &strFileName) -{ - return FALSE; +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::ExtractFolderName(CPDFSDK_Document* pDoc, + CFX_ByteString& strFolderName) { + return FALSE; } -FX_BOOL Document::bookmarkRoot(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - return TRUE; +FX_BOOL Document::bookmarkRoot(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + return TRUE; } -FX_BOOL Document::mailDoc(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - 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""; - - if (params.size() >= 1) - bUI = params[0].ToBool(); - if (params.size() >= 2) - cTo = params[1].ToCFXWideString(); - if (params.size() >= 3) - cCc = params[2].ToCFXWideString(); - if (params.size() >= 4) - cBcc = params[3].ToCFXWideString(); - if (params.size() >= 5) - cSubject = params[4].ToCFXWideString(); - if (params.size() >= 6) - cMsg = params[5].ToCFXWideString(); - - v8::Isolate* isolate = GetIsolate(cc); - - if(params.size() >= 1 && params[0].GetType() == VT_object) - { - JSObject pObj = params[0].ToV8Object(); - - v8::Local pValue = JS_GetObjectElement(isolate,pObj, L"bUI"); - bUI = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).ToInt(); - - pValue = JS_GetObjectElement(isolate,pObj, L"cTo"); - cTo = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).ToCFXWideString(); - - pValue = JS_GetObjectElement(isolate,pObj, L"cCc"); - cCc = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).ToCFXWideString(); - - pValue = JS_GetObjectElement(isolate,pObj, L"cBcc"); - cBcc = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).ToCFXWideString(); +FX_BOOL Document::mailDoc(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + 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""; + + if (params.size() >= 1) + bUI = params[0].ToBool(); + if (params.size() >= 2) + cTo = params[1].ToCFXWideString(); + if (params.size() >= 3) + cCc = params[2].ToCFXWideString(); + if (params.size() >= 4) + cBcc = params[3].ToCFXWideString(); + if (params.size() >= 5) + cSubject = params[4].ToCFXWideString(); + if (params.size() >= 6) + cMsg = params[5].ToCFXWideString(); + + v8::Isolate* isolate = GetIsolate(cc); + + if (params.size() >= 1 && params[0].GetType() == VT_object) { + JSObject pObj = params[0].ToV8Object(); + + v8::Local pValue = JS_GetObjectElement(isolate, pObj, L"bUI"); + bUI = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToInt(); + + pValue = JS_GetObjectElement(isolate, pObj, L"cTo"); + cTo = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); + + pValue = JS_GetObjectElement(isolate, pObj, L"cCc"); + cCc = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); + + pValue = JS_GetObjectElement(isolate, pObj, L"cBcc"); + cBcc = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); + + pValue = JS_GetObjectElement(isolate, pObj, L"cSubject"); + cSubject = + CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); + + pValue = JS_GetObjectElement(isolate, pObj, L"cMsg"); + cMsg = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); + } + + 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, cTo.c_str(), cSubject.c_str(), cCc.c_str(), + cBcc.c_str(), cMsg.c_str()); + pRuntime->EndBlock(); - pValue = JS_GetObjectElement(isolate,pObj, L"cSubject"); - cSubject = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).ToCFXWideString(); - - pValue = JS_GetObjectElement(isolate,pObj, L"cMsg"); - cMsg = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).ToCFXWideString(); - - } - - 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, cTo.c_str(), cSubject.c_str(), cCc.c_str(), cBcc.c_str(), cMsg.c_str()); - pRuntime->EndBlock(); - - return TRUE; + return TRUE; } -FX_BOOL Document::author(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); +FX_BOOL Document::author(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); - CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo(); - if (!pDictionary)return FALSE; + 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; - } + 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(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); +FX_BOOL Document::info(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); - CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo(); - if (!pDictionary) - return FALSE; + 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.IsGetting()) - { - 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.c_str()); - JS_PutObjectString(isolate, pObj, L"Title", cwTitle.c_str()); - JS_PutObjectString(isolate, pObj, L"Subject", cwSubject.c_str()); - JS_PutObjectString(isolate, pObj, L"Keywords", cwKeywords.c_str()); - JS_PutObjectString(isolate, pObj, L"Creator", cwCreator.c_str()); - JS_PutObjectString(isolate, pObj, L"Producer", cwProducer.c_str()); - JS_PutObjectString(isolate, pObj, L"CreationDate", cwCreationDate.c_str()); - JS_PutObjectString(isolate, pObj, L"ModDate", cwModDate.c_str()); - JS_PutObjectString(isolate, pObj, L"Trapped", cwTrapped.c_str()); - - // 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, bsKey.GetLength()); - if((pValueObj->GetType()==PDFOBJ_STRING) || (pValueObj->GetType()==PDFOBJ_NAME) ) - JS_PutObjectString(isolate, pObj, wsKey.c_str(), pValueObj->GetUnicodeText().c_str()); - if(pValueObj->GetType()==PDFOBJ_NUMBER) - JS_PutObjectNumber(isolate,pObj, wsKey.c_str(), (float)pValueObj->GetNumber()); - if(pValueObj->GetType()==PDFOBJ_BOOLEAN) - JS_PutObjectBoolean(isolate,pObj, wsKey.c_str(), (bool)pValueObj->GetInteger()); - } - vp << pObj; - } - return TRUE; + 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.IsGetting()) { + 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.c_str()); + JS_PutObjectString(isolate, pObj, L"Title", cwTitle.c_str()); + JS_PutObjectString(isolate, pObj, L"Subject", cwSubject.c_str()); + JS_PutObjectString(isolate, pObj, L"Keywords", cwKeywords.c_str()); + JS_PutObjectString(isolate, pObj, L"Creator", cwCreator.c_str()); + JS_PutObjectString(isolate, pObj, L"Producer", cwProducer.c_str()); + JS_PutObjectString(isolate, pObj, L"CreationDate", cwCreationDate.c_str()); + JS_PutObjectString(isolate, pObj, L"ModDate", cwModDate.c_str()); + JS_PutObjectString(isolate, pObj, L"Trapped", cwTrapped.c_str()); + + // 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, bsKey.GetLength()); + if ((pValueObj->GetType() == PDFOBJ_STRING) || + (pValueObj->GetType() == PDFOBJ_NAME)) + JS_PutObjectString(isolate, pObj, wsKey.c_str(), + pValueObj->GetUnicodeText().c_str()); + if (pValueObj->GetType() == PDFOBJ_NUMBER) + JS_PutObjectNumber(isolate, pObj, wsKey.c_str(), + (float)pValueObj->GetNumber()); + if (pValueObj->GetType() == PDFOBJ_BOOLEAN) + JS_PutObjectBoolean(isolate, pObj, wsKey.c_str(), + (bool)pValueObj->GetInteger()); + } + vp << pObj; + } + return TRUE; } -FX_BOOL Document::creationDate(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo(); - if (!pDictionary) - return FALSE; +FX_BOOL Document::creationDate(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo(); + if (!pDictionary) + return FALSE; - if (vp.IsGetting()) - { - vp << pDictionary->GetUnicodeText("CreationDate"); - } - 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; + if (vp.IsGetting()) { + vp << pDictionary->GetUnicodeText("CreationDate"); + } 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(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo(); - if (!pDictionary) - return FALSE; +FX_BOOL Document::creator(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo(); + if (!pDictionary) + return FALSE; - if (vp.IsGetting()) - { - vp << pDictionary->GetUnicodeText("Creator"); - } - 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; + if (vp.IsGetting()) { + vp << pDictionary->GetUnicodeText("Creator"); + } 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(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - if (vp.IsGetting()) - { - vp << m_bDelay; - } - else - { - if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) - return FALSE; - - vp >> m_bDelay; - if (m_bDelay) - { - for (int i=0,sz=m_DelayData.GetSize(); i DelayDataToProcess; - for (int i=0,sz=m_DelayData.GetSize(); i < sz; i++) - { - if (CJS_DelayData* pData = m_DelayData.GetAt(i)) - { - DelayDataToProcess.Add(pData); - m_DelayData.SetAt(i, NULL); - } - } - m_DelayData.RemoveAll(); - for (int i=0,sz=DelayDataToProcess.GetSize(); i < sz; i++) - { - CJS_DelayData* pData = DelayDataToProcess.GetAt(i); - Field::DoDelay(m_pDocument, pData); - DelayDataToProcess.SetAt(i,NULL); - delete pData; - } +FX_BOOL Document::delay(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + if (vp.IsGetting()) { + vp << m_bDelay; + } else { + if (!m_pDocument->GetPermissions(FPDFPERM_MODIFY)) + return FALSE; + + vp >> m_bDelay; + if (m_bDelay) { + for (int i = 0, sz = m_DelayData.GetSize(); i < sz; i++) + delete m_DelayData.GetAt(i); + + m_DelayData.RemoveAll(); + } else { + CFX_ArrayTemplate DelayDataToProcess; + for (int i = 0, sz = m_DelayData.GetSize(); i < sz; i++) { + if (CJS_DelayData* pData = m_DelayData.GetAt(i)) { + DelayDataToProcess.Add(pData); + m_DelayData.SetAt(i, NULL); } + } + m_DelayData.RemoveAll(); + for (int i = 0, sz = DelayDataToProcess.GetSize(); i < sz; i++) { + CJS_DelayData* pData = DelayDataToProcess.GetAt(i); + Field::DoDelay(m_pDocument, pData); + DelayDataToProcess.SetAt(i, NULL); + delete pData; + } } - return TRUE; + } + return TRUE; } -FX_BOOL Document::keywords(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo(); - if (!pDictionary) - return FALSE; +FX_BOOL Document::keywords(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo(); + if (!pDictionary) + return FALSE; - if (vp.IsGetting()) - { - vp << pDictionary->GetUnicodeText("Keywords"); - } - 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; + if (vp.IsGetting()) { + vp << pDictionary->GetUnicodeText("Keywords"); + } 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(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo(); - if (!pDictionary) - return FALSE; +FX_BOOL Document::modDate(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo(); + if (!pDictionary) + return FALSE; - if (vp.IsGetting()) - { - vp << pDictionary->GetUnicodeText("ModDate"); - } - 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; + if (vp.IsGetting()) { + vp << pDictionary->GetUnicodeText("ModDate"); + } 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(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo(); - if (!pDictionary) - return FALSE; +FX_BOOL Document::producer(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo(); + if (!pDictionary) + return FALSE; - if (vp.IsGetting()) - { - vp << pDictionary->GetUnicodeText("Producer"); - } - 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; + if (vp.IsGetting()) { + vp << pDictionary->GetUnicodeText("Producer"); + } 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(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo(); - if (!pDictionary) - return FALSE; +FX_BOOL Document::subject(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo(); + if (!pDictionary) + return FALSE; - if (vp.IsGetting()) - { - vp << pDictionary->GetUnicodeText("Subject"); - } - 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; + if (vp.IsGetting()) { + vp << pDictionary->GetUnicodeText("Subject"); + } 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(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - if (m_pDocument == NULL || m_pDocument->GetDocument() == NULL) - return FALSE; +FX_BOOL Document::title(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + if (m_pDocument == NULL || m_pDocument->GetDocument() == NULL) + return FALSE; - CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo(); - if (!pDictionary) - return FALSE; + CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo(); + if (!pDictionary) + return FALSE; - if (vp.IsGetting()) - { - vp << pDictionary->GetUnicodeText("Title"); - } - 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; + if (vp.IsGetting()) { + vp << pDictionary->GetUnicodeText("Title"); + } 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(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - if (vp.IsSetting()) { - CJS_Context* pContext = static_cast(cc); - sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY); - return FALSE; - } - vp << m_pDocument->GetPageCount(); - return TRUE; +FX_BOOL Document::numPages(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + if (vp.IsSetting()) { + CJS_Context* pContext = static_cast(cc); + sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY); + return FALSE; + } + vp << m_pDocument->GetPageCount(); + return TRUE; } -FX_BOOL Document::external(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - //In Chrome case,should always return true. - if (vp.IsGetting()) { - vp << true; - } - return TRUE; +FX_BOOL Document::external(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + // In Chrome case,should always return true. + if (vp.IsGetting()) { + vp << true; + } + return TRUE; } -FX_BOOL Document::filesize(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - if (vp.IsSetting()) { - CJS_Context* pContext = static_cast(cc); - sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY); - return FALSE; - } - vp << 0; - return TRUE; +FX_BOOL Document::filesize(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + if (vp.IsSetting()) { + CJS_Context* pContext = static_cast(cc); + sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY); + return FALSE; + } + vp << 0; + return TRUE; } -FX_BOOL Document::mouseX(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - return TRUE; +FX_BOOL Document::mouseX(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + return TRUE; } -FX_BOOL Document::mouseY(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - return TRUE; +FX_BOOL Document::mouseY(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + return TRUE; } -FX_BOOL Document::baseURL(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - if (vp.IsGetting()) - { - vp << m_cwBaseURL; - } - else - { - vp >> m_cwBaseURL; - } - return TRUE; +FX_BOOL Document::baseURL(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + if (vp.IsGetting()) { + vp << m_cwBaseURL; + } else { + vp >> m_cwBaseURL; + } + return TRUE; } -FX_BOOL Document::calculate(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); +FX_BOOL Document::calculate(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); - CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); - ASSERT(pInterForm != NULL); + CPDFSDK_InterForm* pInterForm = + (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); + ASSERT(pInterForm != NULL); - if (vp.IsGetting()) - { - if (pInterForm->IsCalculateEnabled()) - vp << true; - else - vp << false; - } + if (vp.IsGetting()) { + if (pInterForm->IsCalculateEnabled()) + vp << true; else - { - bool bCalculate; - vp >> bCalculate; - - pInterForm->EnableCalculate(bCalculate); - } + vp << false; + } else { + bool bCalculate; + vp >> bCalculate; - return TRUE; -} + pInterForm->EnableCalculate(bCalculate); + } -FX_BOOL Document::documentFileName(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - if (vp.IsSetting()) { - CJS_Context* pContext = static_cast(cc); - sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY); - return FALSE; - } - CFX_WideString wsFilePath = m_pDocument->GetPath(); - int32_t 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; + return TRUE; } -CFX_WideString Document::ReversalStr(CFX_WideString cbFrom) -{ - size_t iLength = cbFrom.GetLength(); - pdfium::base::CheckedNumeric iSize = sizeof(wchar_t); - iSize *= (iLength + 1); - wchar_t* pResult = (wchar_t*)malloc(iSize.ValueOrDie()); - wchar_t* pFrom = (wchar_t*)cbFrom.GetBuffer(iLength); - - for (size_t i = 0; i < iLength; i++) - { - pResult[i] = *(pFrom + iLength - i - 1); - } - pResult[iLength] = L'\0'; - - cbFrom.ReleaseBuffer(); - CFX_WideString cbRet = CFX_WideString(pResult); - free(pResult); - pResult = NULL; - return cbRet; -} - -CFX_WideString Document::CutString(CFX_WideString cbFrom) -{ - size_t iLength = cbFrom.GetLength(); - pdfium::base::CheckedNumeric iSize = sizeof(wchar_t); - iSize *= (iLength + 1); - wchar_t* pResult = (wchar_t*)malloc(iSize.ValueOrDie()); - wchar_t* pFrom = (wchar_t*)cbFrom.GetBuffer(iLength); - - for (int i = 0; i < iLength; i++) - { - if (pFrom[i] == L'\\' || pFrom[i] == L'/') - { - pResult[i] = L'\0'; - break; - } - pResult[i] = pFrom[i]; - } - pResult[iLength] = L'\0'; - - cbFrom.ReleaseBuffer(); - CFX_WideString cbRet = CFX_WideString(pResult); - free(pResult); - pResult = NULL; - return cbRet; +FX_BOOL Document::documentFileName(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + if (vp.IsSetting()) { + CJS_Context* pContext = static_cast(cc); + sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY); + return FALSE; + } + CFX_WideString wsFilePath = m_pDocument->GetPath(); + int32_t 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; } -FX_BOOL Document::path(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - if (vp.IsSetting()) { - CJS_Context* pContext = static_cast(cc); - sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY); - return FALSE; - } - vp << app::SysPathToPDFPath(m_pDocument->GetPath()); - return TRUE; +CFX_WideString Document::ReversalStr(CFX_WideString cbFrom) { + size_t iLength = cbFrom.GetLength(); + pdfium::base::CheckedNumeric iSize = sizeof(wchar_t); + iSize *= (iLength + 1); + wchar_t* pResult = (wchar_t*)malloc(iSize.ValueOrDie()); + wchar_t* pFrom = (wchar_t*)cbFrom.GetBuffer(iLength); + + for (size_t i = 0; i < iLength; i++) { + pResult[i] = *(pFrom + iLength - i - 1); + } + pResult[iLength] = L'\0'; + + cbFrom.ReleaseBuffer(); + CFX_WideString cbRet = CFX_WideString(pResult); + free(pResult); + pResult = NULL; + return cbRet; +} + +CFX_WideString Document::CutString(CFX_WideString cbFrom) { + size_t iLength = cbFrom.GetLength(); + pdfium::base::CheckedNumeric iSize = sizeof(wchar_t); + iSize *= (iLength + 1); + wchar_t* pResult = (wchar_t*)malloc(iSize.ValueOrDie()); + wchar_t* pFrom = (wchar_t*)cbFrom.GetBuffer(iLength); + + for (int i = 0; i < iLength; i++) { + if (pFrom[i] == L'\\' || pFrom[i] == L'/') { + pResult[i] = L'\0'; + break; + } + pResult[i] = pFrom[i]; + } + pResult[iLength] = L'\0'; + + cbFrom.ReleaseBuffer(); + CFX_WideString cbRet = CFX_WideString(pResult); + free(pResult); + pResult = NULL; + return cbRet; +} + +FX_BOOL Document::path(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + if (vp.IsSetting()) { + CJS_Context* pContext = static_cast(cc); + sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY); + return FALSE; + } + vp << app::SysPathToPDFPath(m_pDocument->GetPath()); + return TRUE; } -FX_BOOL Document::pageWindowRect(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - return TRUE; +FX_BOOL Document::pageWindowRect(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + return TRUE; } -FX_BOOL Document::layout(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - return TRUE; +FX_BOOL Document::layout(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + return TRUE; } -FX_BOOL Document::addLink(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - return TRUE; +FX_BOOL Document::addLink(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + return TRUE; } -FX_BOOL Document::closeDoc(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); - return TRUE; +FX_BOOL Document::closeDoc(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); + return TRUE; } -FX_BOOL Document::getPageBox(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - return TRUE; +FX_BOOL Document::getPageBox(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + return TRUE; } -FX_BOOL Document::getAnnot(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - return TRUE; +FX_BOOL Document::getAnnot(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + return TRUE; } -FX_BOOL Document::getAnnots(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - vRet.SetNull(); - return TRUE; +FX_BOOL Document::getAnnots(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + vRet.SetNull(); + return TRUE; } -FX_BOOL Document::getAnnot3D(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - vRet.SetNull(); - return TRUE; +FX_BOOL Document::getAnnot3D(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + vRet.SetNull(); + return TRUE; } -FX_BOOL Document::getAnnots3D(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - vRet = VT_undefined; - return TRUE; +FX_BOOL Document::getAnnots3D(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + vRet = VT_undefined; + return TRUE; } -FX_BOOL Document::getOCGs(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - return TRUE; +FX_BOOL Document::getOCGs(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + return TRUE; } -FX_BOOL Document::getLinks(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - return TRUE; +FX_BOOL Document::getLinks(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + return TRUE; } -bool Document::IsEnclosedInRect(CFX_FloatRect rect, CFX_FloatRect LinkRect) -{ - return (rect.left <= LinkRect.left && - rect.top <= LinkRect.top && - rect.right >= LinkRect.right && - rect.bottom >= LinkRect.bottom); +bool Document::IsEnclosedInRect(CFX_FloatRect rect, CFX_FloatRect LinkRect) { + return (rect.left <= LinkRect.left && rect.top <= LinkRect.top && + rect.right >= LinkRect.right && rect.bottom >= LinkRect.bottom); } -void IconTree::InsertIconElement(IconElement* pNewIcon) -{ - if (!pNewIcon)return; +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++; - } + 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; +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; - } + 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; + delete m_pEnd; + m_pHead = NULL; + m_pEnd = NULL; } -int IconTree::GetLength() -{ - return m_iLength; +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; +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 NULL; + return pTemp; + } + return NULL; } -FX_BOOL Document::addIcon(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - CJS_Context* pContext = (CJS_Context*)cc; - if (params.size() != 2) { - sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); - return FALSE; - } +FX_BOOL Document::addIcon(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + CJS_Context* pContext = (CJS_Context*)cc; + if (params.size() != 2) { + sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); + return FALSE; + } - CFX_WideString swIconName = params[0].ToCFXWideString(); - JSFXObject pJSIcon = params[1].ToV8Object(); + CFX_WideString swIconName = params[0].ToCFXWideString(); + JSFXObject pJSIcon = params[1].ToV8Object(); - CJS_Runtime* pRuntime = pContext->GetJSRuntime(); - if (JS_GetObjDefnID(pJSIcon) != JS_GetObjDefnID(*pRuntime, L"Icon")) { - sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR); - return FALSE; - } + CJS_Runtime* pRuntime = pContext->GetJSRuntime(); + if (JS_GetObjDefnID(pJSIcon) != JS_GetObjDefnID(*pRuntime, L"Icon")) { + sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR); + return FALSE; + } - CJS_EmbedObj* pEmbedObj = params[1].ToCJSObject()->GetEmbedObject(); - if (!pEmbedObj) { - sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR); - return FALSE; - } + CJS_EmbedObj* pEmbedObj = params[1].ToCJSObject()->GetEmbedObject(); + if (!pEmbedObj) { + sError = JSGetStringFromID(pContext, IDS_STRING_JSTYPEERROR); + return FALSE; + } - Icon* pIcon = (Icon*)pEmbedObj; - if (!m_pIconTree) - m_pIconTree = new IconTree(); + 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; + IconElement* pNewIcon = new IconElement(); + pNewIcon->IconName = swIconName; + pNewIcon->NextIcon = NULL; + pNewIcon->IconStream = pIcon; + m_pIconTree->InsertIconElement(pNewIcon); + return TRUE; } -FX_BOOL Document::icons(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - if (vp.IsSetting()) { - CJS_Context* pContext = static_cast(cc); - sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY); - return FALSE; - } +FX_BOOL Document::icons(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + if (vp.IsSetting()) { + CJS_Context* pContext = static_cast(cc); + sError = JSGetStringFromID(pContext, IDS_STRING_JSREADONLY); + return FALSE; + } - if (!m_pIconTree) - { - vp.SetNull(); - return TRUE; - } + if (!m_pIconTree) { + vp.SetNull(); + return TRUE; + } - CJS_Array Icons(m_isolate); - IconElement* pIconElement = NULL; - int iIconTreeLength = m_pIconTree->GetLength(); + CJS_Array Icons(m_isolate); + IconElement* pIconElement = NULL; + int iIconTreeLength = m_pIconTree->GetLength(); - CJS_Context* pContext = (CJS_Context *)cc; - CJS_Runtime* pRuntime = pContext->GetJSRuntime(); + CJS_Context* pContext = (CJS_Context*)cc; + CJS_Runtime* pRuntime = pContext->GetJSRuntime(); - for (int i = 0; i < iIconTreeLength; i++) - { - pIconElement = (*m_pIconTree)[i]; + 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; + 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; + CJS_Icon* pJS_Icon = (CJS_Icon*)JS_GetPrivate(pObj); + if (!pJS_Icon) + return FALSE; - Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject(); - if (!pIcon)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)); - } + pIcon->SetStream(pIconElement->IconStream->GetStream()); + pIcon->SetIconName(pIconElement->IconName); + Icons.SetElement(i, CJS_Value(m_isolate, pJS_Icon)); + } - vp << Icons; - return TRUE; + vp << Icons; + return TRUE; } -FX_BOOL Document::getIcon(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - CJS_Context* pContext = (CJS_Context *)cc; - if (params.size() != 1) { - sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); - return FALSE; - } +FX_BOOL Document::getIcon(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + CJS_Context* pContext = (CJS_Context*)cc; + if (params.size() != 1) { + sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); + return FALSE; + } - if(!m_pIconTree) - return FALSE; - CFX_WideString swIconName = params[0].ToCFXWideString(); - int iIconCounts = m_pIconTree->GetLength(); + if (!m_pIconTree) + return FALSE; + CFX_WideString swIconName = params[0].ToCFXWideString(); + int iIconCounts = m_pIconTree->GetLength(); - CJS_Runtime* pRuntime = pContext->GetJSRuntime(); + CJS_Runtime* pRuntime = pContext->GetJSRuntime(); - for (int i = 0; i < iIconCounts; i++) - { - if ((*m_pIconTree)[i]->IconName == swIconName) - { - Icon* pRetIcon = (*m_pIconTree)[i]->IconStream; + 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; + 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; + CJS_Icon* pJS_Icon = (CJS_Icon*)JS_GetPrivate(pObj); + if (!pJS_Icon) + return FALSE; - Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject(); - if (!pIcon)return FALSE; + Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject(); + if (!pIcon) + return FALSE; - pIcon->SetIconName(swIconName); - pIcon->SetStream(pRetIcon->GetStream()); - vRet = pJS_Icon; - return TRUE; - } + pIcon->SetIconName(swIconName); + pIcon->SetStream(pRetIcon->GetStream()); + vRet = pJS_Icon; + return TRUE; } + } - return FALSE; + return FALSE; } -FX_BOOL Document::removeIcon(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ +FX_BOOL Document::removeIcon(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { // Unsafe, no supported. return TRUE; } -FX_BOOL Document::createDataObject(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ +FX_BOOL Document::createDataObject(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { // Unsafe, not implemented. return TRUE; } -FX_BOOL Document::media(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - return TRUE; +FX_BOOL Document::media(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + return TRUE; } -FX_BOOL Document::calculateNow(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); +FX_BOOL Document::calculateNow(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); - if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || + if (!(m_pDocument->GetPermissions(FPDFPERM_MODIFY) || m_pDocument->GetPermissions(FPDFPERM_ANNOT_FORM) || - m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) return FALSE; + m_pDocument->GetPermissions(FPDFPERM_FILL_FORM))) + return FALSE; - CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); - ASSERT(pInterForm != NULL); - pInterForm->OnCalculate(); - return TRUE; + CPDFSDK_InterForm* pInterForm = + (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); + ASSERT(pInterForm != NULL); + pInterForm->OnCalculate(); + return TRUE; } -FX_BOOL Document::Collab(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - return TRUE; +FX_BOOL Document::Collab(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + return TRUE; } -FX_BOOL Document::getPageNthWord(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); +FX_BOOL Document::getPageNthWord(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); - if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE; - - int nPageNo = params.GetSize() > 0 ? params[0].ToInt() : 0; - int nWordNo = params.GetSize() > 1 ? params[1].ToInt() : 0; - bool bStrip = params.GetSize() > 2 ? params[2].ToBool() : true; + if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) + return FALSE; - CPDF_Document* pDocument = m_pDocument->GetDocument(); - if (!pDocument) return FALSE; + int nPageNo = params.GetSize() > 0 ? params[0].ToInt() : 0; + int nWordNo = params.GetSize() > 1 ? params[1].ToInt() : 0; + bool bStrip = params.GetSize() > 2 ? params[2].ToBool() : true; - CJS_Context* pContext = static_cast(cc); - if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) - { - sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR); - return FALSE; - } + CPDF_Document* pDocument = m_pDocument->GetDocument(); + if (!pDocument) + return FALSE; - CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo); - if (!pPageDict) return FALSE; + CJS_Context* pContext = static_cast(cc); + if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) { + sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR); + return FALSE; + } - CPDF_Page page; - page.Load(pDocument, pPageDict); - page.StartParse(); - page.ParseContent(); + CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo); + if (!pPageDict) + return FALSE; - FX_POSITION pos = page.GetFirstObjectPosition(); + CPDF_Page page; + page.Load(pDocument, pPageDict); + page.StartParse(); + page.ParseContent(); - int nWords = 0; + FX_POSITION pos = page.GetFirstObjectPosition(); - CFX_WideString swRet; + int nWords = 0; - while (pos) - { - if (CPDF_PageObject* pPageObj = page.GetNextObject(pos)) - { - if (pPageObj->m_Type == PDFPAGE_TEXT) - { - int nObjWords = CountWords((CPDF_TextObject*)pPageObj); + CFX_WideString swRet; - if (nWords + nObjWords >= nWordNo) - { - swRet = GetObjWordStr((CPDF_TextObject*)pPageObj, nWordNo - nWords); - break; - } + while (pos) { + if (CPDF_PageObject* pPageObj = page.GetNextObject(pos)) { + if (pPageObj->m_Type == PDFPAGE_TEXT) { + int nObjWords = CountWords((CPDF_TextObject*)pPageObj); - nWords += nObjWords; - } + if (nWords + nObjWords >= nWordNo) { + swRet = GetObjWordStr((CPDF_TextObject*)pPageObj, nWordNo - nWords); + break; } - } - if (bStrip) - { - swRet.TrimLeft(); - swRet.TrimRight(); + nWords += nObjWords; + } } + } - vRet = swRet.c_str(); - return TRUE; -} + if (bStrip) { + swRet.TrimLeft(); + swRet.TrimRight(); + } -FX_BOOL Document::getPageNthWordQuads(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); + vRet = swRet.c_str(); + return TRUE; +} - if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE; +FX_BOOL Document::getPageNthWordQuads(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); + if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE; + + return FALSE; } -FX_BOOL Document::getPageNumWords(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); +FX_BOOL Document::getPageNumWords(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); - if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) return FALSE; + if (!m_pDocument->GetPermissions(FPDFPERM_EXTRACT_ACCESS)) + return FALSE; - int nPageNo = params.GetSize() > 0 ? params[0].ToInt() : 0; + int nPageNo = params.GetSize() > 0 ? params[0].ToInt() : 0; - CPDF_Document* pDocument = m_pDocument->GetDocument(); - ASSERT(pDocument != NULL); + CPDF_Document* pDocument = m_pDocument->GetDocument(); + ASSERT(pDocument != NULL); - CJS_Context* pContext = static_cast(cc); - if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) - { - sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR); - return FALSE; - } + CJS_Context* pContext = static_cast(cc); + if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount()) { + sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR); + return FALSE; + } - CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo); - if (!pPageDict) return FALSE; + CPDF_Dictionary* pPageDict = pDocument->GetPage(nPageNo); + if (!pPageDict) + return FALSE; - CPDF_Page page; - page.Load(pDocument, pPageDict); - page.StartParse(); - page.ParseContent(); + CPDF_Page page; + page.Load(pDocument, pPageDict); + page.StartParse(); + page.ParseContent(); - FX_POSITION pos = page.GetFirstObjectPosition(); + FX_POSITION pos = page.GetFirstObjectPosition(); - int nWords = 0; + 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); - } - } + 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; + vRet = nWords; - return TRUE; + return TRUE; } -FX_BOOL Document::getPrintParams(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - CJS_Context* pContext = (CJS_Context*)cc; - CJS_Runtime* pRuntime = pContext->GetJSRuntime(); - JSFXObject pRetObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"PrintParamsObj")); +FX_BOOL Document::getPrintParams(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + CJS_Context* pContext = (CJS_Context*)cc; + CJS_Runtime* pRuntime = pContext->GetJSRuntime(); + JSFXObject pRetObj = JS_NewFxDynamicObj( + *pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"PrintParamsObj")); - // Not implemented yet. + // Not implemented yet. - vRet = pRetObj; - return TRUE; + vRet = pRetObj; + return TRUE; } -#define ISLATINWORD(u) (u != 0x20 && u <= 0x28FF) +#define ISLATINWORD(u) (u != 0x20 && u <= 0x28FF) -int Document::CountWords(CPDF_TextObject* pTextObj) -{ - if (!pTextObj) return 0; +int Document::CountWords(CPDF_TextObject* pTextObj) { + if (!pTextObj) + return 0; - int nWords = 0; + int nWords = 0; - CPDF_Font* pFont = pTextObj->GetFont(); - if (!pFont) return 0; + CPDF_Font* pFont = pTextObj->GetFont(); + if (!pFont) + return 0; - FX_BOOL bIsLatin = FALSE; + FX_BOOL bIsLatin = FALSE; - for (int i=0, sz=pTextObj->CountChars(); iCountChars(); i < sz; i++) { + FX_DWORD charcode = -1; + FX_FLOAT kerning; - pTextObj->GetCharInfo(i, charcode, kerning); - CFX_WideString swUnicode = pFont->UnicodeFromCharCode(charcode); + pTextObj->GetCharInfo(i, charcode, kerning); + CFX_WideString swUnicode = pFont->UnicodeFromCharCode(charcode); - FX_WORD unicode = 0; - if (swUnicode.GetLength() > 0) - unicode = swUnicode[0]; + FX_WORD unicode = 0; + if (swUnicode.GetLength() > 0) + unicode = swUnicode[0]; - if (ISLATINWORD(unicode) && bIsLatin) - continue; + if (ISLATINWORD(unicode) && bIsLatin) + continue; - bIsLatin = ISLATINWORD(unicode); - if (unicode != 0x20) - nWords++; - } + bIsLatin = ISLATINWORD(unicode); + if (unicode != 0x20) + nWords++; + } - return nWords; + return nWords; } -CFX_WideString Document::GetObjWordStr(CPDF_TextObject* pTextObj, int nWordIndex) -{ - ASSERT(pTextObj != NULL); - - CFX_WideString swRet; +CFX_WideString Document::GetObjWordStr(CPDF_TextObject* pTextObj, + int nWordIndex) { + ASSERT(pTextObj != NULL); - CPDF_Font* pFont = pTextObj->GetFont(); - if (!pFont) return L""; + CFX_WideString swRet; - int nWords = 0; - FX_BOOL bIsLatin = FALSE; + CPDF_Font* pFont = pTextObj->GetFont(); + if (!pFont) + return L""; - for (int i=0, sz=pTextObj->CountChars(); iGetCharInfo(i, charcode, kerning); - CFX_WideString swUnicode = pFont->UnicodeFromCharCode(charcode); + for (int i = 0, sz = pTextObj->CountChars(); i < sz; i++) { + FX_DWORD charcode = -1; + FX_FLOAT kerning; - FX_WORD unicode = 0; - if (swUnicode.GetLength() > 0) - unicode = swUnicode[0]; + pTextObj->GetCharInfo(i, charcode, kerning); + CFX_WideString swUnicode = pFont->UnicodeFromCharCode(charcode); - if (ISLATINWORD(unicode) && bIsLatin) - { - } - else - { - bIsLatin = ISLATINWORD(unicode); - if (unicode != 0x20) - nWords++; - } + FX_WORD unicode = 0; + if (swUnicode.GetLength() > 0) + unicode = swUnicode[0]; - if (nWords-1 == nWordIndex) - swRet += unicode; + if (ISLATINWORD(unicode) && bIsLatin) { + } else { + bIsLatin = ISLATINWORD(unicode); + if (unicode != 0x20) + nWords++; } - return swRet; -} + if (nWords - 1 == nWordIndex) + swRet += unicode; + } -FX_BOOL Document::zoom(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ + return swRet; +} - return TRUE; +FX_BOOL Document::zoom(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + return TRUE; } /** @@ -1748,94 +1757,97 @@ FX_BOOL Document::zoom(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sEr (refW, ReflowWidth) */ -FX_BOOL Document::zoomType(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - return TRUE; +FX_BOOL Document::zoomType(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + return TRUE; } -FX_BOOL Document::deletePages(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ +FX_BOOL Document::deletePages(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { // Unsafe, no supported. return TRUE; } -FX_BOOL Document::extractPages(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ +FX_BOOL Document::extractPages(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { // Unsafe, not supported. return TRUE; } -FX_BOOL Document::insertPages(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ +FX_BOOL Document::insertPages(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { // Unsafe, not supported. return TRUE; } -FX_BOOL Document::replacePages(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ +FX_BOOL Document::replacePages(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { // Unsafe, not supported. return TRUE; } -FX_BOOL Document::getURL(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ +FX_BOOL Document::getURL(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { // Unsafe, not supported. return TRUE; } -void Document::AddDelayData(CJS_DelayData* pData) -{ - m_DelayData.Add(pData); +void Document::AddDelayData(CJS_DelayData* pData) { + m_DelayData.Add(pData); } -void Document::DoFieldDelay(const CFX_WideString& sFieldName, int nControlIndex) -{ - CFX_DWordArray DelArray; - CFX_ArrayTemplate DelayDataForFieldAndControlIndex; +void Document::DoFieldDelay(const CFX_WideString& sFieldName, + int nControlIndex) { + CFX_DWordArray DelArray; + CFX_ArrayTemplate DelayDataForFieldAndControlIndex; - for (int i=0,sz=m_DelayData.GetSize(); isFieldName == sFieldName && pData->nControlIndex == nControlIndex) - { - DelayDataForFieldAndControlIndex.Add(pData); - m_DelayData.SetAt(i, NULL); - DelArray.Add(i); - } - } + 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) { + DelayDataForFieldAndControlIndex.Add(pData); + m_DelayData.SetAt(i, NULL); + DelArray.Add(i); + } } + } - for (int j=DelArray.GetSize()-1; j>=0; j--) - { - m_DelayData.RemoveAt(DelArray[j]); - } + for (int j = DelArray.GetSize() - 1; j >= 0; j--) { + m_DelayData.RemoveAt(DelArray[j]); + } - for (int i=0,sz=DelayDataForFieldAndControlIndex.GetSize(); i < sz; i++) - { - CJS_DelayData* pData = DelayDataForFieldAndControlIndex.GetAt(i); - Field::DoDelay(m_pDocument, pData); - DelayDataForFieldAndControlIndex.SetAt(i,NULL); - delete pData; - } + for (int i = 0, sz = DelayDataForFieldAndControlIndex.GetSize(); i < sz; + i++) { + CJS_DelayData* pData = DelayDataForFieldAndControlIndex.GetAt(i); + Field::DoDelay(m_pDocument, pData); + DelayDataForFieldAndControlIndex.SetAt(i, NULL); + delete pData; + } } -void Document::AddDelayAnnotData(CJS_AnnotObj *pData) -{ - m_DelayAnnotData.Add(pData); +void Document::AddDelayAnnotData(CJS_AnnotObj* pData) { + m_DelayAnnotData.Add(pData); } -void Document::DoAnnotDelay() -{ - CFX_DWordArray DelArray; +void Document::DoAnnotDelay() { + CFX_DWordArray DelArray; - for (int j=DelArray.GetSize()-1; j>=0; j--) - { - m_DelayData.RemoveAt(DelArray[j]); - } + for (int j = DelArray.GetSize() - 1; j >= 0; j--) { + m_DelayData.RemoveAt(DelArray[j]); + } } -CJS_Document* Document::GetCJSDoc() const -{ - return static_cast(m_pJSObject); +CJS_Document* Document::GetCJSDoc() const { + return static_cast(m_pJSObject); } diff --git a/fpdfsdk/src/javascript/Field.cpp b/fpdfsdk/src/javascript/Field.cpp index 614843426e..c44636872b 100644 --- a/fpdfsdk/src/javascript/Field.cpp +++ b/fpdfsdk/src/javascript/Field.cpp @@ -18,3448 +18,3335 @@ #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) +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) - JS_STATIC_METHOD_ENTRY(buttonGetCaption) - JS_STATIC_METHOD_ENTRY(buttonGetIcon) - JS_STATIC_METHOD_ENTRY(buttonImportIcon) - JS_STATIC_METHOD_ENTRY(buttonSetCaption) - JS_STATIC_METHOD_ENTRY(buttonSetIcon) - JS_STATIC_METHOD_ENTRY(checkThisBox) - JS_STATIC_METHOD_ENTRY(clearItems) - JS_STATIC_METHOD_ENTRY(defaultIsChecked) - JS_STATIC_METHOD_ENTRY(deleteItemAt) - JS_STATIC_METHOD_ENTRY(getArray ) - JS_STATIC_METHOD_ENTRY(getItemAt) - JS_STATIC_METHOD_ENTRY(getLock) - JS_STATIC_METHOD_ENTRY(insertItemAt) - JS_STATIC_METHOD_ENTRY(isBoxChecked) - JS_STATIC_METHOD_ENTRY(isDefaultChecked) - JS_STATIC_METHOD_ENTRY(setAction) - JS_STATIC_METHOD_ENTRY(setFocus) - JS_STATIC_METHOD_ENTRY(setItems) - JS_STATIC_METHOD_ENTRY(setLock) - JS_STATIC_METHOD_ENTRY(signatureGetModifications) - JS_STATIC_METHOD_ENTRY(signatureGetSeedValue) - JS_STATIC_METHOD_ENTRY(signatureInfo) - JS_STATIC_METHOD_ENTRY(signatureSetSeedValue) - JS_STATIC_METHOD_ENTRY(signatureSign) - JS_STATIC_METHOD_ENTRY(signatureValidate) +JS_STATIC_METHOD_ENTRY(browseForFileToSubmit) +JS_STATIC_METHOD_ENTRY(buttonGetCaption) +JS_STATIC_METHOD_ENTRY(buttonGetIcon) +JS_STATIC_METHOD_ENTRY(buttonImportIcon) +JS_STATIC_METHOD_ENTRY(buttonSetCaption) +JS_STATIC_METHOD_ENTRY(buttonSetIcon) +JS_STATIC_METHOD_ENTRY(checkThisBox) +JS_STATIC_METHOD_ENTRY(clearItems) +JS_STATIC_METHOD_ENTRY(defaultIsChecked) +JS_STATIC_METHOD_ENTRY(deleteItemAt) +JS_STATIC_METHOD_ENTRY(getArray) +JS_STATIC_METHOD_ENTRY(getItemAt) +JS_STATIC_METHOD_ENTRY(getLock) +JS_STATIC_METHOD_ENTRY(insertItemAt) +JS_STATIC_METHOD_ENTRY(isBoxChecked) +JS_STATIC_METHOD_ENTRY(isDefaultChecked) +JS_STATIC_METHOD_ENTRY(setAction) +JS_STATIC_METHOD_ENTRY(setFocus) +JS_STATIC_METHOD_ENTRY(setItems) +JS_STATIC_METHOD_ENTRY(setLock) +JS_STATIC_METHOD_ENTRY(signatureGetModifications) +JS_STATIC_METHOD_ENTRY(signatureGetSeedValue) +JS_STATIC_METHOD_ENTRY(signatureInfo) +JS_STATIC_METHOD_ENTRY(signatureSetSeedValue) +JS_STATIC_METHOD_ENTRY(signatureSign) +JS_STATIC_METHOD_ENTRY(signatureValidate) 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); +FX_BOOL CJS_Field::InitInstance(IFXJS_Context* cc) { + CJS_Context* pContext = (CJS_Context*)cc; + ASSERT(pContext != NULL); - Field* pField = (Field*)GetEmbedObject(); - ASSERT(pField != NULL); + Field* pField = (Field*)GetEmbedObject(); + ASSERT(pField != NULL); - pField->SetIsolate(pContext->GetJSRuntime()->GetIsolate()); + pField->SetIsolate(pContext->GetJSRuntime()->GetIsolate()); - return TRUE; + 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(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() -{ -} +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; +// 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(suffixal.c_str()); + if (iControlNo == 0) { + int iStart; + while ((iStart = suffixal.find_last_of(L" ")) != -1) { + suffixal.erase(iStart, 1); } - std::wstring suffixal = strFieldNameParsed.substr(iStart+1); - iControlNo = FXSYS_wtoi(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; - } + if (suffixal.compare(L"0") != 0) { + strFieldName = strFieldNameParsed; + iControlNo = -1; + return; } - strFieldName = strFieldNameParsed.substr(0,iStart); + } + strFieldName = strFieldNameParsed.substr(0, iStart); } -FX_BOOL Field::AttachField(Document* pDocument, const CFX_WideString& csFieldName) -{ - ASSERT(pDocument != NULL); - m_pJSDoc = pDocument; +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_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); + 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); + CPDFSDK_InterForm* pRDInterForm = m_pDocument->GetInterForm(); + ASSERT(pRDInterForm != NULL); - CPDF_InterForm* pInterForm = pRDInterForm->GetInterForm(); - ASSERT(pInterForm != NULL); + CPDF_InterForm* pInterForm = pRDInterForm->GetInterForm(); + ASSERT(pInterForm != NULL); - CFX_WideString swFieldNameTemp = csFieldName; - swFieldNameTemp.Replace(L"..", L"."); + CFX_WideString swFieldNameTemp = csFieldName; + swFieldNameTemp.Replace(L"..", L"."); - if (pInterForm->CountFields(swFieldNameTemp) <= 0) - { - std::wstring strFieldName; - int iControlNo = -1; - ParseFieldName(swFieldNameTemp.c_str(), strFieldName, iControlNo); - if (iControlNo == -1) return FALSE; + if (pInterForm->CountFields(swFieldNameTemp) <= 0) { + std::wstring strFieldName; + int iControlNo = -1; + ParseFieldName(swFieldNameTemp.c_str(), strFieldName, iControlNo); + if (iControlNo == -1) + return FALSE; - m_FieldName = strFieldName.c_str(); - m_nFormControlIndex = iControlNo; - return TRUE; - } + m_FieldName = strFieldName.c_str(); + m_nFormControlIndex = iControlNo; + return TRUE; + } - m_FieldName = swFieldNameTemp; - m_nFormControlIndex = -1; + m_FieldName = swFieldNameTemp; + m_nFormControlIndex = -1; - return TRUE; + return TRUE; } -void Field::GetFormFields(CPDFSDK_Document* pDocument, const CFX_WideString& csFieldName, CFX_PtrArray& FieldArray) -{ - ASSERT(pDocument != NULL); +void Field::GetFormFields(CPDFSDK_Document* pDocument, + const CFX_WideString& csFieldName, + CFX_PtrArray& FieldArray) { + ASSERT(pDocument != NULL); - CPDFSDK_InterForm* pReaderInterForm = pDocument->GetInterForm(); - ASSERT(pReaderInterForm != NULL); + CPDFSDK_InterForm* pReaderInterForm = pDocument->GetInterForm(); + ASSERT(pReaderInterForm != NULL); - CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm(); - ASSERT(pInterForm != NULL); + CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm(); + ASSERT(pInterForm != NULL); - ASSERT(FieldArray.GetSize() == 0); + ASSERT(FieldArray.GetSize() == 0); - for (int i=0,sz=pInterForm->CountFields(csFieldName); iGetField(i, csFieldName)) - FieldArray.Add((void*)pFormField); - } + 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); +void Field::GetFormFields(const CFX_WideString& csFieldName, + CFX_PtrArray& FieldArray) { + ASSERT(m_pDocument != NULL); - Field::GetFormFields(m_pDocument, csFieldName, FieldArray); + 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); +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); + CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm(); + ASSERT(pInterForm != NULL); - CFX_PtrArray widgets; - pInterForm->GetWidgets(pFormField, widgets); + 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(); iOnFormat(bFormated); - if (bFormated) - pWidget->ResetAppearance(sValue.c_str(), FALSE); - else - pWidget->ResetAppearance(NULL, FALSE); - } - } + 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(bFormated); + if (bFormated) + pWidget->ResetAppearance(sValue.c_str(), FALSE); else - { - for (int i=0,sz=widgets.GetSize(); iResetAppearance(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); - } - } + pWidget->ResetAppearance(NULL, FALSE); + } } + } - if (bRefresh) - { - for (int i=0,sz=widgets.GetSize(); iGetInterForm(); - CPDFSDK_Document* pDoc = pInterForm->GetDocument(); -// CReader_Page* pPage = pWidget->GetPage(); - ASSERT(pDoc != NULL); - pDoc->UpdateAllViews(NULL, pWidget); - } + 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(); + 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); +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); + CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm(); + ASSERT(pInterForm != NULL); - if (pWidget) - { - if (bResetAP) - { - int nFieldType = pWidget->GetFieldType(); - if (nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_TEXTFIELD) - { - FX_BOOL bFormated = FALSE; - CFX_WideString sValue = pWidget->OnFormat(bFormated); - if (bFormated) - pWidget->ResetAppearance(sValue.c_str(), FALSE); - else - pWidget->ResetAppearance(NULL, FALSE); - } - else - { - pWidget->ResetAppearance(NULL, FALSE); - } - } + CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl); - if (bRefresh) - { - CPDFSDK_InterForm * pInterForm = pWidget->GetInterForm(); - CPDFSDK_Document* pDoc = pInterForm->GetDocument(); - ASSERT(pDoc != NULL); - pDoc->UpdateAllViews(NULL, pWidget); - } + if (pWidget) { + if (bResetAP) { + int nFieldType = pWidget->GetFieldType(); + if (nFieldType == FIELDTYPE_COMBOBOX || + nFieldType == FIELDTYPE_TEXTFIELD) { + FX_BOOL bFormated = FALSE; + CFX_WideString sValue = pWidget->OnFormat(bFormated); + if (bFormated) + pWidget->ResetAppearance(sValue.c_str(), 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(); + if (bChangeMark) + pDocument->SetChangeMark(); } -CPDFSDK_Widget* Field::GetWidget(CPDFSDK_Document* pDocument, CPDF_FormControl* pFormControl) -{ - ASSERT(pDocument != NULL); - ASSERT(pFormControl != NULL); +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); + CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm(); + ASSERT(pInterForm != NULL); - return pInterForm->GetWidget(pFormControl); + return pInterForm->GetWidget(pFormControl); } -FX_BOOL Field::ValueIsOccur(CPDF_FormField* pFormField, CFX_WideString csOptLabel) -{ - ASSERT(pFormField != NULL); +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; - } + for (int i = 0, sz = pFormField->CountOptions(); i < sz; i++) { + if (csOptLabel.Compare(pFormField->GetOptionLabel(i)) == 0) + return TRUE; + } - return FALSE; + return FALSE; } -CPDF_FormControl* Field::GetSmartFieldControl(CPDF_FormField* pFormField) -{ - if (!pFormField->CountControls() || m_nFormControlIndex >= pFormField->CountControls()) - return NULL; +CPDF_FormControl* Field::GetSmartFieldControl(CPDF_FormField* pFormField) { + if (!pFormField->CountControls() || + m_nFormControlIndex >= pFormField->CountControls()) + return NULL; - if (m_nFormControlIndex < 0) - return pFormField->GetControl(0); + if (m_nFormControlIndex < 0) + return pFormField->GetControl(0); - return pFormField->GetControl(m_nFormControlIndex); + return pFormField->GetControl(m_nFormControlIndex); } -/* ---------------------------------------- property ---------------------------------------- */ +/* ---------------------------------------- property + * ---------------------------------------- */ -FX_BOOL Field::alignment(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); +FX_BOOL Field::alignment(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); - if (vp.IsSetting()) - { - if (!m_bCanSet) return FALSE; + if (vp.IsSetting()) { + if (!m_bCanSet) + return FALSE; - CFX_ByteString alignStr; - vp >> alignStr; + CFX_ByteString alignStr; + vp >> alignStr; - if (m_bDelay) - { - AddDelay_String(FP_ALIGNMENT, alignStr); - } - else - { - Field::SetAlignment(m_pDocument, m_FieldName, m_nFormControlIndex, 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; + } 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_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); + ASSERT(pFormField != NULL); - if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) - return FALSE; + if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) + return FALSE; - CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); - if (!pFormControl)return FALSE; + CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); + if (!pFormControl) + return FALSE; - switch (pFormControl->GetControlAlignment()) - { - case 1: - vp << L"center"; - break; - case 0: - vp << L"left"; - break; - case 2: - vp << L"right"; - break; - default: - vp << L""; - } + switch (pFormControl->GetControlAlignment()) { + case 1: + vp << L"center"; + break; + case 0: + vp << L"left"; + break; + case 2: + vp << L"right"; + break; + default: + vp << L""; } + } - return TRUE; + return TRUE; } -void Field::SetAlignment(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, - const CFX_ByteString& string) -{ - //Not supported. +void Field::SetAlignment(CPDFSDK_Document* pDocument, + const CFX_WideString& swFieldName, + int nControlIndex, + const CFX_ByteString& string) { + // Not supported. } -FX_BOOL Field::borderStyle(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); +FX_BOOL Field::borderStyle(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); - if (vp.IsSetting()) - { - if (!m_bCanSet) return FALSE; + if (vp.IsSetting()) { + if (!m_bCanSet) + return FALSE; - CFX_ByteString strType = ""; - vp >> strType; + CFX_ByteString strType = ""; + vp >> strType; - if (m_bDelay) - { - AddDelay_String(FP_BORDERSTYLE, strType); - } - else - { - Field::SetBorderStyle(m_pDocument, m_FieldName, m_nFormControlIndex, 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 << L"solid"; - break; - case BBS_DASH: - vp << L"dashed"; - break; - case BBS_BEVELED: - vp << L"beveled"; - break; - case BBS_INSET: - vp << L"inset"; - break; - case BBS_UNDERLINE: - vp << L"underline"; - break; - default: - vp << L""; - break; - } + } 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 << L"solid"; + break; + case BBS_DASH: + vp << L"dashed"; + break; + case BBS_BEVELED: + vp << L"beveled"; + break; + case BBS_INSET: + vp << L"inset"; + break; + case BBS_UNDERLINE: + vp << L"underline"; + break; + default: + vp << L""; + break; } + } - return TRUE; + return TRUE; } -void Field::SetBorderStyle(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, - const CFX_ByteString& string) -{ - ASSERT(pDocument != NULL); +void Field::SetBorderStyle(CPDFSDK_Document* pDocument, + const CFX_WideString& swFieldName, + int nControlIndex, + const CFX_ByteString& string) { + ASSERT(pDocument != NULL); - int nBorderStyle = 0; + 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; + 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); + CFX_PtrArray FieldArray; + GetFormFields(pDocument, swFieldName, FieldArray); - for (int i=0,isz=FieldArray.GetSize(); iCountControls(); jGetControl(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); - } - } - } + 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(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); +FX_BOOL Field::buttonAlignX(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); - if (vp.IsSetting()) - { - if (!m_bCanSet) return FALSE; + if (vp.IsSetting()) { + if (!m_bCanSet) + return FALSE; - int nVP; - vp >> nVP; + int nVP; + vp >> nVP; - if (m_bDelay) - { - AddDelay_Int(FP_BUTTONALIGNX, nVP); - } - else - { - Field::SetButtonAlignX(m_pDocument, m_FieldName, m_nFormControlIndex, 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; + } 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_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); + ASSERT(pFormField != NULL); - if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON) - return FALSE; + if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON) + return FALSE; - CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); - if (!pFormControl)return FALSE; + CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); + if (!pFormControl) + return FALSE; - CPDF_IconFit IconFit = pFormControl->GetIconFit(); + CPDF_IconFit IconFit = pFormControl->GetIconFit(); - FX_FLOAT fLeft,fBottom; - IconFit.GetIconPosition(fLeft,fBottom); + FX_FLOAT fLeft, fBottom; + IconFit.GetIconPosition(fLeft, fBottom); - vp << (int32_t)fLeft; - } + vp << (int32_t)fLeft; + } - return TRUE; + return TRUE; } -void Field::SetButtonAlignX(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number) -{ - //Not supported. +void Field::SetButtonAlignX(CPDFSDK_Document* pDocument, + const CFX_WideString& swFieldName, + int nControlIndex, + int number) { + // Not supported. } -FX_BOOL Field::buttonAlignY(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); +FX_BOOL Field::buttonAlignY(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); - if (vp.IsSetting()) - { - if (!m_bCanSet) return FALSE; + if (vp.IsSetting()) { + if (!m_bCanSet) + return FALSE; - int nVP; - vp >> nVP; + int nVP; + vp >> nVP; - if (m_bDelay) - { - AddDelay_Int(FP_BUTTONALIGNY, nVP); - } - else - { - Field::SetButtonAlignY(m_pDocument, m_FieldName, m_nFormControlIndex, 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; + } 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_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); + ASSERT(pFormField != NULL); - if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON) - return FALSE; + if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON) + return FALSE; - CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); - if (!pFormControl)return FALSE; + CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); + if (!pFormControl) + return FALSE; - CPDF_IconFit IconFit = pFormControl->GetIconFit(); + CPDF_IconFit IconFit = pFormControl->GetIconFit(); - FX_FLOAT fLeft,fBottom; - IconFit.GetIconPosition(fLeft,fBottom); + FX_FLOAT fLeft, fBottom; + IconFit.GetIconPosition(fLeft, fBottom); - vp << (int32_t)fBottom; - } + vp << (int32_t)fBottom; + } - return TRUE; + return TRUE; } -void Field::SetButtonAlignY(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number) -{ - //Not supported. +void Field::SetButtonAlignY(CPDFSDK_Document* pDocument, + const CFX_WideString& swFieldName, + int nControlIndex, + int number) { + // Not supported. } -FX_BOOL Field::buttonFitBounds(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); +FX_BOOL Field::buttonFitBounds(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); - if (vp.IsSetting()) - { - if (!m_bCanSet) return FALSE; + if (vp.IsSetting()) { + if (!m_bCanSet) + return FALSE; - bool bVP; - vp >> bVP; + bool bVP; + vp >> bVP; - if (m_bDelay) - { - AddDelay_Bool(FP_BUTTONFITBOUNDS, bVP); - } - else - { - Field::SetButtonFitBounds(m_pDocument, m_FieldName, m_nFormControlIndex, 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; + } 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_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); + ASSERT(pFormField != NULL); - if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON) - return FALSE; + if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON) + return FALSE; - CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); - if (!pFormControl)return FALSE; + CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); + if (!pFormControl) + return FALSE; - CPDF_IconFit IconFit = pFormControl->GetIconFit(); - vp << IconFit.GetFittingBounds(); - } + CPDF_IconFit IconFit = pFormControl->GetIconFit(); + vp << IconFit.GetFittingBounds(); + } - return TRUE; + return TRUE; } -void Field::SetButtonFitBounds(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b) -{ - //Not supported. +void Field::SetButtonFitBounds(CPDFSDK_Document* pDocument, + const CFX_WideString& swFieldName, + int nControlIndex, + bool b) { + // Not supported. } -FX_BOOL Field::buttonPosition(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); +FX_BOOL Field::buttonPosition(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); - if (vp.IsSetting()) - { - if (!m_bCanSet) return FALSE; + if (vp.IsSetting()) { + if (!m_bCanSet) + return FALSE; - int nVP; - vp >> nVP; + int nVP; + vp >> nVP; - if (m_bDelay) - { - AddDelay_Int(FP_BUTTONPOSITION, nVP); - } - else - { - Field::SetButtonPosition(m_pDocument, m_FieldName, m_nFormControlIndex, 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; + } 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_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); + ASSERT(pFormField != NULL); - if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON) - return FALSE; + if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON) + return FALSE; - CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); - if (!pFormControl)return FALSE; + CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); + if (!pFormControl) + return FALSE; - vp << pFormControl->GetTextPosition(); - } - return TRUE; + vp << pFormControl->GetTextPosition(); + } + return TRUE; } -void Field::SetButtonPosition(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number) -{ - //Not supported. +void Field::SetButtonPosition(CPDFSDK_Document* pDocument, + const CFX_WideString& swFieldName, + int nControlIndex, + int number) { + // Not supported. } -FX_BOOL Field::buttonScaleHow(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); +FX_BOOL Field::buttonScaleHow(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); - if (vp.IsSetting()) - { - if (!m_bCanSet) return FALSE; + if (vp.IsSetting()) { + if (!m_bCanSet) + return FALSE; - int nVP; - vp >> nVP; + int nVP; + vp >> nVP; - if (m_bDelay) - { - AddDelay_Int(FP_BUTTONSCALEHOW, nVP); - } - else - { - Field::SetButtonScaleHow(m_pDocument, m_FieldName, m_nFormControlIndex, 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; + } 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_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); + ASSERT(pFormField != NULL); - if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON) - return FALSE; + if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON) + return FALSE; - CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); - if (!pFormControl)return FALSE; + CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); + if (!pFormControl) + return FALSE; - CPDF_IconFit IconFit = pFormControl->GetIconFit(); - if (IconFit.IsProportionalScale()) - vp << (int32_t)0; - else - vp << (int32_t)1; - } + CPDF_IconFit IconFit = pFormControl->GetIconFit(); + if (IconFit.IsProportionalScale()) + vp << (int32_t)0; + else + vp << (int32_t)1; + } - return TRUE; + return TRUE; } -void Field::SetButtonScaleHow(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number) -{ - //Not supported. +void Field::SetButtonScaleHow(CPDFSDK_Document* pDocument, + const CFX_WideString& swFieldName, + int nControlIndex, + int number) { + // Not supported. } -FX_BOOL Field::buttonScaleWhen(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); +FX_BOOL Field::buttonScaleWhen(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); - if (vp.IsSetting()) - { - if (!m_bCanSet) return FALSE; + if (vp.IsSetting()) { + if (!m_bCanSet) + return FALSE; - int nVP; - vp >> nVP; + int nVP; + vp >> nVP; - if (m_bDelay) - { - AddDelay_Int(FP_BUTTONSCALEWHEN, nVP); - } - else - { - Field::SetButtonScaleWhen(m_pDocument, m_FieldName, m_nFormControlIndex, 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 << (int32_t) CPDF_IconFit::Always; - break; - case CPDF_IconFit::Bigger : - vp << (int32_t) CPDF_IconFit::Bigger; - break; - case CPDF_IconFit::Never : - vp << (int32_t) CPDF_IconFit::Never; - break; - case CPDF_IconFit::Smaller : - vp << (int32_t) CPDF_IconFit::Smaller; - break; - } + } 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 << (int32_t)CPDF_IconFit::Always; + break; + case CPDF_IconFit::Bigger: + vp << (int32_t)CPDF_IconFit::Bigger; + break; + case CPDF_IconFit::Never: + vp << (int32_t)CPDF_IconFit::Never; + break; + case CPDF_IconFit::Smaller: + vp << (int32_t)CPDF_IconFit::Smaller; + break; } + } - return TRUE; + return TRUE; } -void Field::SetButtonScaleWhen(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number) -{ - //Not supported. +void Field::SetButtonScaleWhen(CPDFSDK_Document* pDocument, + const CFX_WideString& swFieldName, + int nControlIndex, + int number) { + // Not supported. } -FX_BOOL Field::calcOrderIndex(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); +FX_BOOL Field::calcOrderIndex(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); - if (vp.IsSetting()) - { - if (!m_bCanSet) return FALSE; + if (vp.IsSetting()) { + if (!m_bCanSet) + return FALSE; - int nVP; - vp >> nVP; + int nVP; + vp >> nVP; - if (m_bDelay) - { - AddDelay_Int(FP_CALCORDERINDEX, nVP); - } - else - { - Field::SetCalcOrderIndex(m_pDocument, m_FieldName, m_nFormControlIndex, 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; + } 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_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); + ASSERT(pFormField != NULL); - if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX && pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) - return FALSE; + if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX && + pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) + return FALSE; - CPDFSDK_InterForm* pRDInterForm = m_pDocument->GetInterForm(); - ASSERT(pRDInterForm != NULL); + CPDFSDK_InterForm* pRDInterForm = m_pDocument->GetInterForm(); + ASSERT(pRDInterForm != NULL); - CPDF_InterForm* pInterForm = pRDInterForm->GetInterForm(); - ASSERT(pInterForm != NULL); + CPDF_InterForm* pInterForm = pRDInterForm->GetInterForm(); + ASSERT(pInterForm != NULL); - vp << (int32_t)pInterForm->FindFieldInCalculationOrder(pFormField); - } + vp << (int32_t)pInterForm->FindFieldInCalculationOrder(pFormField); + } - return TRUE; + return TRUE; } -void Field::SetCalcOrderIndex(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number) -{ - //Not supported. +void Field::SetCalcOrderIndex(CPDFSDK_Document* pDocument, + const CFX_WideString& swFieldName, + int nControlIndex, + int number) { + // Not supported. } -FX_BOOL Field::charLimit(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); +FX_BOOL Field::charLimit(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); - if (vp.IsSetting()) - { - if (!m_bCanSet) return FALSE; + if (vp.IsSetting()) { + if (!m_bCanSet) + return FALSE; - int nVP; - vp >> nVP; + int nVP; + vp >> nVP; - if (m_bDelay) - { - AddDelay_Int(FP_CHARLIMIT, nVP); - } - else - { - Field::SetCharLimit(m_pDocument, m_FieldName, m_nFormControlIndex, 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; + } 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_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); + ASSERT(pFormField != NULL); - if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) - return FALSE; + if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) + return FALSE; - vp << (int32_t)pFormField->GetMaxLen(); - } - return TRUE; + vp << (int32_t)pFormField->GetMaxLen(); + } + return TRUE; } -void Field::SetCharLimit(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number) -{ - //Not supported. +void Field::SetCharLimit(CPDFSDK_Document* pDocument, + const CFX_WideString& swFieldName, + int nControlIndex, + int number) { + // Not supported. } -FX_BOOL Field::comb(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); +FX_BOOL Field::comb(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); - if (vp.IsSetting()) - { - if (!m_bCanSet) return FALSE; + if (vp.IsSetting()) { + if (!m_bCanSet) + return FALSE; - bool bVP; - vp >> bVP; + bool bVP; + vp >> bVP; - if (m_bDelay) - { - AddDelay_Bool(FP_COMB, bVP); - } - else - { - Field::SetComb(m_pDocument, m_FieldName, m_nFormControlIndex, 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; + } 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_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); + ASSERT(pFormField != NULL); - if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) - return FALSE; + if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) + return FALSE; - if (pFormField->GetFieldFlags() & FIELDFLAG_COMB) - vp << true; - else - vp << false; - } + if (pFormField->GetFieldFlags() & FIELDFLAG_COMB) + vp << true; + else + vp << false; + } - return TRUE; + return TRUE; } -void Field::SetComb(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b) -{ - //Not supported. +void Field::SetComb(CPDFSDK_Document* pDocument, + const CFX_WideString& swFieldName, + int nControlIndex, + bool b) { + // Not supported. } -FX_BOOL Field::commitOnSelChange(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); +FX_BOOL Field::commitOnSelChange(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); - if (vp.IsSetting()) - { - if (!m_bCanSet) return FALSE; + if (vp.IsSetting()) { + if (!m_bCanSet) + return FALSE; - bool bVP; - vp >> bVP; + bool bVP; + vp >> bVP; - if (m_bDelay) - { - AddDelay_Bool(FP_COMMITONSELCHANGE, bVP); - } - else - { - Field::SetCommitOnSelChange(m_pDocument, m_FieldName, m_nFormControlIndex, 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; + } 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_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); + ASSERT(pFormField != NULL); - if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX && pFormField->GetFieldType() != FIELDTYPE_LISTBOX) - return FALSE; + if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX && + pFormField->GetFieldType() != FIELDTYPE_LISTBOX) + return FALSE; - if (pFormField->GetFieldFlags() & FIELDFLAG_COMMITONSELCHANGE) - vp << true; - else - vp << false; - } + if (pFormField->GetFieldFlags() & FIELDFLAG_COMMITONSELCHANGE) + vp << true; + else + vp << false; + } - return TRUE; + return TRUE; } -void Field::SetCommitOnSelChange(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b) -{ - //Not supported. +void Field::SetCommitOnSelChange(CPDFSDK_Document* pDocument, + const CFX_WideString& swFieldName, + int nControlIndex, + bool b) { + // Not supported. } -FX_BOOL Field::currentValueIndices(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); +FX_BOOL Field::currentValueIndices(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); - if (vp.IsSetting()) - { - if (!m_bCanSet) return FALSE; + if (vp.IsSetting()) { + if (!m_bCanSet) + return FALSE; - CFX_DWordArray array; + 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(); iGetFieldType() != 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(); iGetSelectedIndex(i))); - } - vp << SelArray; - } - else - vp << -1; + 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 = SelValue.ToInt(); + array.Add(iSelecting); + } } - return TRUE; -} + 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; -void Field::SetCurrentValueIndices(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, - const CFX_DWordArray& array) -{ - ASSERT(pDocument != NULL); + CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); + ASSERT(pFormField != NULL); - CFX_PtrArray FieldArray; - GetFormFields(pDocument, swFieldName, FieldArray); + 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); - for (int i=0,isz=FieldArray.GetSize(); iGetFieldType(); - if (nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_LISTBOX) - { - FX_DWORD dwFieldFlags = pFormField->GetFieldFlags(); - pFormField->ClearSelection(TRUE); - - for (int i=0,sz=array.GetSize(); i0 && !(dwFieldFlags & (1<<21))) - { - break; - } - - int iSelecting = (int32_t)array.GetAt(i); - if (iSelecting < pFormField->CountOptions() && !pFormField->IsItemSelected(iSelecting)) - pFormField->SetItemSelection(iSelecting, TRUE); + int nFieldType = pFormField->GetFieldType(); + if (nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_LISTBOX) { + FX_DWORD dwFieldFlags = pFormField->GetFieldFlags(); + pFormField->ClearSelection(TRUE); - } - UpdateFormField(pDocument, pFormField, TRUE, TRUE, TRUE); + for (int i = 0, sz = array.GetSize(); i < sz; i++) { + if (i > 0 && !(dwFieldFlags & (1 << 21))) { + break; } + + int iSelecting = (int32_t)array.GetAt(i); + if (iSelecting < pFormField->CountOptions() && + !pFormField->IsItemSelected(iSelecting)) + pFormField->SetItemSelection(iSelecting, TRUE); + } + UpdateFormField(pDocument, pFormField, TRUE, TRUE, TRUE); } + } } -FX_BOOL Field::defaultStyle(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - // MQG sError = JSGetStringFromID(IDS_STRING_NOTSUPPORT); - return FALSE; +FX_BOOL Field::defaultStyle(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + // MQG sError = JSGetStringFromID(IDS_STRING_NOTSUPPORT); + return FALSE; - if (vp.IsSetting()) - { - if (!m_bCanSet) return FALSE; + if (vp.IsSetting()) { + if (!m_bCanSet) + return FALSE; - ; - } - else - { - ; - } - return TRUE; + ; + } else { + ; + } + return TRUE; } -void Field::SetDefaultStyle(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex) -{ - //Not supported. +void Field::SetDefaultStyle(CPDFSDK_Document* pDocument, + const CFX_WideString& swFieldName, + int nControlIndex) { + // Not supported. } -FX_BOOL Field::defaultValue(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); +FX_BOOL Field::defaultValue(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); - if (vp.IsSetting()) - { - if (!m_bCanSet) return FALSE; + if (vp.IsSetting()) { + if (!m_bCanSet) + return FALSE; - CFX_WideString WideStr; - vp >> WideStr; + CFX_WideString WideStr; + vp >> WideStr; - if (m_bDelay) - { - AddDelay_WideString(FP_DEFAULTVALUE, WideStr); - } - else - { - Field::SetDefaultValue(m_pDocument, m_FieldName, m_nFormControlIndex, 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; + } 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_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); + ASSERT(pFormField != NULL); - if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON || - pFormField->GetFieldType() == FIELDTYPE_SIGNATURE) - return FALSE; + if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON || + pFormField->GetFieldType() == FIELDTYPE_SIGNATURE) + return FALSE; - vp << pFormField->GetDefaultValue(); - } - return TRUE; + vp << pFormField->GetDefaultValue(); + } + return TRUE; } -void Field::SetDefaultValue(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, - const CFX_WideString& string) -{ - //Not supported. +void Field::SetDefaultValue(CPDFSDK_Document* pDocument, + const CFX_WideString& swFieldName, + int nControlIndex, + const CFX_WideString& string) { + // Not supported. } -FX_BOOL Field::doNotScroll(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); +FX_BOOL Field::doNotScroll(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); - if (vp.IsSetting()) - { - if (!m_bCanSet) return FALSE; + if (vp.IsSetting()) { + if (!m_bCanSet) + return FALSE; - bool bVP; - vp >> bVP; + bool bVP; + vp >> bVP; - if (m_bDelay) - { - AddDelay_Bool(FP_DONOTSCROLL, bVP); - } - else - { - Field::SetDoNotScroll(m_pDocument, m_FieldName, m_nFormControlIndex, 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; + } 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_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); + ASSERT(pFormField != NULL); - if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) - return FALSE; + if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) + return FALSE; - if (pFormField->GetFieldFlags() & FIELDFLAG_DONOTSCROLL) - vp << true; - else - vp << false; - } + if (pFormField->GetFieldFlags() & FIELDFLAG_DONOTSCROLL) + vp << true; + else + vp << false; + } - return TRUE; + return TRUE; } -void Field::SetDoNotScroll(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b) -{ - //Not supported. +void Field::SetDoNotScroll(CPDFSDK_Document* pDocument, + const CFX_WideString& swFieldName, + int nControlIndex, + bool b) { + // Not supported. } -FX_BOOL Field::doNotSpellCheck(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); +FX_BOOL Field::doNotSpellCheck(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); - if (vp.IsSetting()) - { - if (!m_bCanSet) return FALSE; + 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; + 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); + CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); + ASSERT(pFormField != NULL); - if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD && - pFormField->GetFieldType() != FIELDTYPE_COMBOBOX) - return FALSE; + if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD && + pFormField->GetFieldType() != FIELDTYPE_COMBOBOX) + return FALSE; - if (pFormField->GetFieldFlags() & FIELDFLAG_DONOTSPELLCHECK) - vp << true; - else - vp << false; - } + if (pFormField->GetFieldFlags() & FIELDFLAG_DONOTSPELLCHECK) + vp << true; + else + vp << false; + } - return TRUE; + return TRUE; } -void Field::SetDelay(FX_BOOL bDelay) -{ - m_bDelay = bDelay; +void Field::SetDelay(FX_BOOL bDelay) { + m_bDelay = bDelay; - if (!m_bDelay) - { - if (m_pJSDoc) - m_pJSDoc->DoFieldDelay(m_FieldName, m_nFormControlIndex); - } + if (!m_bDelay) { + if (m_pJSDoc) + m_pJSDoc->DoFieldDelay(m_FieldName, m_nFormControlIndex); + } } -FX_BOOL Field::delay(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - if (vp.IsSetting()) - { - if (!m_bCanSet) return FALSE; +FX_BOOL Field::delay(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + if (vp.IsSetting()) { + if (!m_bCanSet) + return FALSE; - bool bVP; - vp >> bVP; + bool bVP; + vp >> bVP; - SetDelay(bVP); - } - else - { - vp << m_bDelay; - } - return TRUE; + SetDelay(bVP); + } else { + vp << m_bDelay; + } + return TRUE; } -FX_BOOL Field::display(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); - - if (vp.IsSetting()) - { - if (!m_bCanSet) return FALSE; - - int nVP; - vp >> nVP; +FX_BOOL Field::display(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); - 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; + if (vp.IsSetting()) { + if (!m_bCanSet) + return FALSE; - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); - ASSERT(pFormField != NULL); + int nVP; + vp >> nVP; - 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 << (int32_t)1; - } - else - { - if (ANNOTFLAG_PRINT & dwFlag) - { - if (ANNOTFLAG_NOVIEW & dwFlag) - { - vp << (int32_t)3; - } - else - { - vp << (int32_t)0; - } - } - else - { - vp << (int32_t)2; - } - } + 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; - return TRUE; -} - -void Field::SetDisplay(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number) -{ - ASSERT(pDocument != NULL); + CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); + ASSERT(pFormField != NULL); - CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm(); + CPDFSDK_InterForm* pInterForm = + (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); ASSERT(pInterForm != NULL); - CFX_PtrArray FieldArray; - GetFormFields(pDocument, swFieldName, FieldArray); + CPDFSDK_Widget* pWidget = + pInterForm->GetWidget(GetSmartFieldControl(pFormField)); + if (!pWidget) + return FALSE; - for (int i=0,isz=FieldArray.GetSize(); iCountControls(); jGetControl(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; - } - } - } + FX_DWORD dwFlag = pWidget->GetFlags(); - 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); - } - } - } + if (ANNOTFLAG_INVISIBLE & dwFlag || ANNOTFLAG_HIDDEN & dwFlag) { + vp << (int32_t)1; + } else { + if (ANNOTFLAG_PRINT & dwFlag) { + if (ANNOTFLAG_NOVIEW & dwFlag) { + vp << (int32_t)3; + } else { + vp << (int32_t)0; } + } else { + vp << (int32_t)2; + } } -} + } -FX_BOOL Field::doc(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - if (!vp.IsGetting()) { - return FALSE; - } - vp << m_pJSDoc->GetCJSDoc(); - return TRUE; + return TRUE; } -FX_BOOL Field::editable(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); - if (vp.IsSetting()) - { - if (!m_bCanSet) return FALSE; +void Field::SetDisplay(CPDFSDK_Document* pDocument, + const CFX_WideString& swFieldName, + int nControlIndex, + int number) { + ASSERT(pDocument != NULL); - bool bVP; - vp >> bVP; - } - else - { - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) return FALSE; + CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm(); + ASSERT(pInterForm != NULL); - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); - ASSERT(pFormField != NULL); + CFX_PtrArray FieldArray; + GetFormFields(pDocument, swFieldName, FieldArray); - if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX) - return FALSE; - - if (pFormField->GetFieldFlags() & FIELDFLAG_EDIT) - vp << true; - else - vp << false; - } - - return TRUE; -} + for (int i = 0, isz = FieldArray.GetSize(); i < isz; i++) { + CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(i); + ASSERT(pFormField != NULL); -FX_BOOL Field::exportValues(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - ASSERT(m_pDocument != 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(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + if (!vp.IsGetting()) { + return FALSE; + } + vp << m_pJSDoc->GetCJSDoc(); + return TRUE; +} + +FX_BOOL Field::editable(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); + if (vp.IsSetting()) { + if (!m_bCanSet) + return FALSE; + + bool bVP; + vp >> bVP; + } else { CFX_PtrArray FieldArray; - GetFormFields(m_FieldName,FieldArray); + GetFormFields(m_FieldName, FieldArray); if (FieldArray.GetSize() <= 0) - return FALSE; + return FALSE; CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); - if (pFormField->GetFieldType() != FIELDTYPE_CHECKBOX && - pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON) - return FALSE; + ASSERT(pFormField != NULL); - if (vp.IsSetting()) - { - if (!m_bCanSet) - return FALSE; + if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX) + return FALSE; - if (!vp.IsArrayObject()) - return FALSE; - } + if (pFormField->GetFieldFlags() & FIELDFLAG_EDIT) + vp << true; else - { - CJS_Array ExportValusArray(m_isolate); - if (m_nFormControlIndex < 0) - { - for (int i=0,sz=pFormField->CountControls(); iGetControl(i); - ExportValusArray.SetElement(i, CJS_Value(m_isolate,pFormControl->GetExportValue().c_str())); - } - } - else - { - if (m_nFormControlIndex >= pFormField->CountControls()) - return FALSE; + vp << false; + } - CPDF_FormControl* pFormControl = pFormField->GetControl(m_nFormControlIndex); - if (!pFormControl) - return FALSE; - - ExportValusArray.SetElement(0, CJS_Value(m_isolate,pFormControl->GetExportValue().c_str())); - } - vp << ExportValusArray; - } - return TRUE; + return TRUE; } -FX_BOOL Field::fileSelect(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); +FX_BOOL Field::exportValues(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) - 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->GetFieldType() != FIELDTYPE_TEXTFIELD) + CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); + 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); + ExportValusArray.SetElement( + i, CJS_Value(m_isolate, pFormControl->GetExportValue().c_str())); + } + } else { + if (m_nFormControlIndex >= pFormField->CountControls()) return FALSE; - if (vp.IsSetting()) - { - if (!m_bCanSet) - return FALSE; + CPDF_FormControl* pFormControl = + pFormField->GetControl(m_nFormControlIndex); + if (!pFormControl) + return FALSE; - bool bVP; - vp >> bVP; + ExportValusArray.SetElement( + 0, CJS_Value(m_isolate, pFormControl->GetExportValue().c_str())); } - else - { - if (pFormField->GetFieldFlags() & FIELDFLAG_FILESELECT) - vp << true; - else - vp << false; - } - return TRUE; + vp << ExportValusArray; + } + return TRUE; } -FX_BOOL Field::fillColor(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); - - CJS_Array crArray(m_isolate); - - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) - return FALSE; +FX_BOOL Field::fileSelect(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); - if (vp.IsSetting()) - { - if (!m_bCanSet) - return FALSE; + CFX_PtrArray FieldArray; + GetFormFields(m_FieldName, FieldArray); + if (FieldArray.GetSize() <= 0) + return FALSE; - if (!vp.IsArrayObject()) - return FALSE; + CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); + if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) + return FALSE; - vp >> crArray; + if (vp.IsSetting()) { + if (!m_bCanSet) + return FALSE; - 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); - } - } + bool bVP; + vp >> bVP; + } else { + if (pFormField->GetFieldFlags() & FIELDFLAG_FILESELECT) + vp << true; 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. + vp << false; + } + return TRUE; } -FX_BOOL Field::hidden(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); - - if (vp.IsSetting()) - { - if (!m_bCanSet) return FALSE; +FX_BOOL Field::fillColor(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); - bool bVP; - vp >> bVP; + CJS_Array crArray(m_isolate); - 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); + CFX_PtrArray FieldArray; + GetFormFields(m_FieldName, FieldArray); + if (FieldArray.GetSize() <= 0) + return FALSE; - CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); - ASSERT(pInterForm != NULL); + if (vp.IsSetting()) { + if (!m_bCanSet) + return FALSE; - CPDFSDK_Widget* pWidget = pInterForm->GetWidget(GetSmartFieldControl(pFormField)); - if (!pWidget) return FALSE; + if (!vp.IsArrayObject()) + return FALSE; - FX_DWORD dwFlags = pWidget->GetFlags(); + vp >> crArray; - if (ANNOTFLAG_INVISIBLE & dwFlags || ANNOTFLAG_HIDDEN & dwFlags) - { - vp << true; - } - else - vp << false; + 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); - return TRUE; -} + 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(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + 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; -void Field::SetHidden(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b) -{ - ASSERT(pDocument != NULL); + CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); + ASSERT(pFormField != NULL); - CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm(); + CPDFSDK_InterForm* pInterForm = + (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); ASSERT(pInterForm != NULL); - CFX_PtrArray FieldArray; - GetFormFields(pDocument, swFieldName, FieldArray); + CPDFSDK_Widget* pWidget = + pInterForm->GetWidget(GetSmartFieldControl(pFormField)); + if (!pWidget) + return FALSE; - for (int i=0,isz=FieldArray.GetSize(); iCountControls(); jGetWidget(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; - } - } - } + FX_DWORD dwFlags = pWidget->GetFlags(); - 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); - } - } - } - } - } + if (ANNOTFLAG_INVISIBLE & dwFlags || ANNOTFLAG_HIDDEN & dwFlags) { + vp << true; + } else + vp << false; + } + + return TRUE; } -FX_BOOL Field::highlight(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); +void Field::SetHidden(CPDFSDK_Document* pDocument, + const CFX_WideString& swFieldName, + int nControlIndex, + bool b) { + ASSERT(pDocument != NULL); - if (vp.IsSetting()) - { - if (!m_bCanSet) return FALSE; + CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm(); + ASSERT(pInterForm != NULL); - CFX_ByteString strMode; - vp >> strMode; + CFX_PtrArray FieldArray; + GetFormFields(pDocument, swFieldName, FieldArray); - 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; + for (int i = 0, isz = FieldArray.GetSize(); i < isz; i++) { + CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(i); + ASSERT(pFormField != NULL); - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); - 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(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + 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; - if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON) - return FALSE; + CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); + ASSERT(pFormField != NULL); - CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); - if (!pFormControl) return FALSE; + if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON) + return FALSE; - int eHM = pFormControl->GetHighlightingMode(); - switch (eHM) - { - case CPDF_FormControl::None: - vp << L"none"; - break; - case CPDF_FormControl::Push: - vp << L"push"; - break; - case CPDF_FormControl::Invert: - vp << L"invert"; - break; - case CPDF_FormControl::Outline: - vp << L"outline"; - break; - case CPDF_FormControl::Toggle: - vp << L"toggle"; - break; - } + CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); + if (!pFormControl) + return FALSE; + + int eHM = pFormControl->GetHighlightingMode(); + switch (eHM) { + case CPDF_FormControl::None: + vp << L"none"; + break; + case CPDF_FormControl::Push: + vp << L"push"; + break; + case CPDF_FormControl::Invert: + vp << L"invert"; + break; + case CPDF_FormControl::Outline: + vp << L"outline"; + break; + case CPDF_FormControl::Toggle: + vp << L"toggle"; + break; } + } - return TRUE; + return TRUE; } -void Field::SetHighlight(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CFX_ByteString& string) -{ - //Not supported. +void Field::SetHighlight(CPDFSDK_Document* pDocument, + const CFX_WideString& swFieldName, + int nControlIndex, + const CFX_ByteString& string) { + // Not supported. } -FX_BOOL Field::lineWidth(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); +FX_BOOL Field::lineWidth(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); - if (vp.IsSetting()) - { - if (!m_bCanSet) return FALSE; + if (vp.IsSetting()) { + if (!m_bCanSet) + return FALSE; - int iWidth; - vp >> iWidth; + int iWidth; + vp >> iWidth; - if (m_bDelay) - { - AddDelay_Int(FP_LINEWIDTH, iWidth); - } - else - { - Field::SetLineWidth(m_pDocument, m_FieldName, m_nFormControlIndex, 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; + } 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_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); + ASSERT(pFormField != NULL); - CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); - if (!pFormControl) return FALSE; + CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); + if (!pFormControl) + return FALSE; - CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); - ASSERT(pInterForm != NULL); + CPDFSDK_InterForm* pInterForm = + (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); + ASSERT(pInterForm != NULL); - if(!pFormField->CountControls()) return FALSE; + if (!pFormField->CountControls()) + return FALSE; - CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormField->GetControl(0)); - if (!pWidget) return FALSE; + CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormField->GetControl(0)); + if (!pWidget) + return FALSE; - vp << (int32_t)pWidget->GetBorderWidth(); - } + vp << (int32_t)pWidget->GetBorderWidth(); + } - return TRUE; + return TRUE; } -void Field::SetLineWidth(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number) -{ - ASSERT(pDocument != NULL); +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); + CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm(); + ASSERT(pInterForm != NULL); - CFX_PtrArray FieldArray; - GetFormFields(pDocument, swFieldName, FieldArray); + CFX_PtrArray FieldArray; + GetFormFields(pDocument, swFieldName, FieldArray); - for (int i=0,isz=FieldArray.GetSize(); iCountControls(); jGetControl(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); - } - } - } + 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(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); +FX_BOOL Field::multiline(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); - if (vp.IsSetting()) - { - if (!m_bCanSet) return FALSE; + if (vp.IsSetting()) { + if (!m_bCanSet) + return FALSE; - bool bVP; - vp >> bVP; + bool bVP; + vp >> bVP; - if (m_bDelay) - { - AddDelay_Bool(FP_MULTILINE, bVP); - } - else - { - Field::SetMultiline(m_pDocument, m_FieldName, m_nFormControlIndex, 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; + } 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_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); + ASSERT(pFormField != NULL); - if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) - return FALSE; + if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) + return FALSE; - if (pFormField->GetFieldFlags() & FIELDFLAG_MULTILINE) - vp << true; - else - vp << false; - } + if (pFormField->GetFieldFlags() & FIELDFLAG_MULTILINE) + vp << true; + else + vp << false; + } - return TRUE; + return TRUE; } -void Field::SetMultiline(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b) -{ - //Not supported. +void Field::SetMultiline(CPDFSDK_Document* pDocument, + const CFX_WideString& swFieldName, + int nControlIndex, + bool b) { + // Not supported. } -FX_BOOL Field::multipleSelection(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); +FX_BOOL Field::multipleSelection(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); - if (vp.IsSetting()) - { - if (!m_bCanSet) return FALSE; + if (vp.IsSetting()) { + if (!m_bCanSet) + return FALSE; - bool bVP; - vp >> bVP; + bool bVP; + vp >> bVP; - if (m_bDelay) - { - AddDelay_Bool(FP_MULTIPLESELECTION, bVP); - } - else - { - Field::SetMultipleSelection(m_pDocument, m_FieldName, m_nFormControlIndex, 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; + } 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_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); + ASSERT(pFormField != NULL); - if (pFormField->GetFieldType() != FIELDTYPE_LISTBOX) - return FALSE; + if (pFormField->GetFieldType() != FIELDTYPE_LISTBOX) + return FALSE; - if (pFormField->GetFieldFlags() & FIELDFLAG_MULTISELECT) - vp << true; - else - vp << false; - } + if (pFormField->GetFieldFlags() & FIELDFLAG_MULTISELECT) + vp << true; + else + vp << false; + } - return TRUE; + return TRUE; } -void Field::SetMultipleSelection(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b) -{ - //Not supported. +void Field::SetMultipleSelection(CPDFSDK_Document* pDocument, + const CFX_WideString& swFieldName, + int nControlIndex, + bool b) { + // Not supported. } -FX_BOOL Field::name(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - if (!vp.IsGetting()) return FALSE; +FX_BOOL Field::name(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + if (!vp.IsGetting()) + return FALSE; - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) return FALSE; + CFX_PtrArray FieldArray; + GetFormFields(m_FieldName, FieldArray); + if (FieldArray.GetSize() <= 0) + return FALSE; - vp << m_FieldName; + vp << m_FieldName; - return TRUE; + return TRUE; } -FX_BOOL Field::numItems(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) return FALSE; +FX_BOOL Field::numItems(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + 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_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); + ASSERT(pFormField != NULL); - if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX && - pFormField->GetFieldType() != FIELDTYPE_LISTBOX) - return FALSE; + if (pFormField->GetFieldType() != FIELDTYPE_COMBOBOX && + pFormField->GetFieldType() != FIELDTYPE_LISTBOX) + return FALSE; - if (!vp.IsGetting()) return FALSE; + if (!vp.IsGetting()) + return FALSE; - vp << (int32_t)pFormField->CountOptions(); + vp << (int32_t)pFormField->CountOptions(); - return TRUE; + return TRUE; } -FX_BOOL Field::page(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - if (!vp.IsGetting()) return FALSE; - - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) return FALSE; +FX_BOOL Field::page(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + if (!vp.IsGetting()) + return FALSE; - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); - if (!pFormField) return FALSE; + CFX_PtrArray FieldArray; + GetFormFields(m_FieldName, FieldArray); + if (FieldArray.GetSize() <= 0) + return FALSE; - ASSERT(m_pDocument != NULL); + CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); + if (!pFormField) + return FALSE; - CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); - ASSERT(pInterForm != NULL); + ASSERT(m_pDocument != NULL); - CFX_PtrArray widgetArray; - pInterForm->GetWidgets(pFormField, widgetArray); + CPDFSDK_InterForm* pInterForm = + (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); + ASSERT(pInterForm != NULL); - if (widgetArray.GetSize() > 0) - { - CJS_Array PageArray(m_isolate); + CFX_PtrArray widgetArray; + pInterForm->GetWidgets(pFormField, widgetArray); - for (int i=0,sz=widgetArray.GetSize(); i 0) { + CJS_Array PageArray(m_isolate); - CPDFSDK_PageView* pPageView = pWidget->GetPageView(); - if(!pPageView) - return FALSE; + for (int i = 0, sz = widgetArray.GetSize(); i < sz; i++) { + CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)widgetArray.GetAt(i); + ASSERT(pWidget != NULL); - PageArray.SetElement(i, CJS_Value(m_isolate,(int32_t)pPageView->GetPageIndex())); - } + CPDFSDK_PageView* pPageView = pWidget->GetPageView(); + if (!pPageView) + return FALSE; - vp << PageArray; - } - else - { - vp << (int32_t) -1; + PageArray.SetElement( + i, CJS_Value(m_isolate, (int32_t)pPageView->GetPageIndex())); } - return TRUE; + vp << PageArray; + } else { + vp << (int32_t)-1; + } + + return TRUE; } -FX_BOOL Field::password(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); +FX_BOOL Field::password(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); - if (vp.IsSetting()) - { - if (!m_bCanSet) return FALSE; + if (vp.IsSetting()) { + if (!m_bCanSet) + return FALSE; - bool bVP; - vp >> bVP; + bool bVP; + vp >> bVP; - if (m_bDelay) - { - AddDelay_Bool(FP_PASSWORD, bVP); - } - else - { - Field::SetPassword(m_pDocument, m_FieldName, m_nFormControlIndex, 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; + } 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_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); + ASSERT(pFormField != NULL); - if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) - return FALSE; + if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) + return FALSE; - if (pFormField->GetFieldFlags() & FIELDFLAG_PASSWORD) - vp << true; - else - vp << false; - } + if (pFormField->GetFieldFlags() & FIELDFLAG_PASSWORD) + vp << true; + else + vp << false; + } - return TRUE; + return TRUE; } -void Field::SetPassword(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b) -{ - //Not supported. +void Field::SetPassword(CPDFSDK_Document* pDocument, + const CFX_WideString& swFieldName, + int nControlIndex, + bool b) { + // Not supported. } -FX_BOOL Field::print(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); +FX_BOOL Field::print(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); - CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); - ASSERT(pInterForm != 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; + 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(); iCountControls(); jGetWidget(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); + 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 - { - 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); - } - } - } + 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); + } else { + CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); + ASSERT(pFormField != NULL); - CPDFSDK_Widget* pWidget = pInterForm->GetWidget(GetSmartFieldControl(pFormField)); - if (!pWidget) return FALSE; + CPDFSDK_Widget* pWidget = + pInterForm->GetWidget(GetSmartFieldControl(pFormField)); + if (!pWidget) + return FALSE; - if (pWidget->GetFlags() & ANNOTFLAG_PRINT) - vp << true; - else - vp << false; - } + if (pWidget->GetFlags() & ANNOTFLAG_PRINT) + vp << true; + else + vp << false; + } - return TRUE; + return TRUE; } -FX_BOOL Field::radiosInUnison(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); +FX_BOOL Field::radiosInUnison(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName,FieldArray); - if (FieldArray.GetSize() <= 0) return FALSE; + CFX_PtrArray FieldArray; + GetFormFields(m_FieldName, FieldArray); + if (FieldArray.GetSize() <= 0) + return FALSE; - if (vp.IsSetting()) - { - if (!m_bCanSet) return FALSE; + if (vp.IsSetting()) { + if (!m_bCanSet) + return FALSE; - bool bVP; - vp >> bVP; + bool bVP; + vp >> bVP; - } - else - { - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); - ASSERT(pFormField != NULL); + } else { + CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); + ASSERT(pFormField != NULL); - if (pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON) - return FALSE; + if (pFormField->GetFieldType() != FIELDTYPE_RADIOBUTTON) + return FALSE; - if (pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON) - vp << true; - else - vp << false; - } + if (pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON) + vp << true; + else + vp << false; + } - return TRUE; + return TRUE; } -FX_BOOL Field::readonly(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); +FX_BOOL Field::readonly(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName,FieldArray); - if (FieldArray.GetSize() <= 0) return FALSE; + CFX_PtrArray FieldArray; + GetFormFields(m_FieldName, FieldArray); + if (FieldArray.GetSize() <= 0) + return FALSE; - if (vp.IsSetting()) - { - if (!m_bCanSet) return FALSE; + if (vp.IsSetting()) { + if (!m_bCanSet) + return FALSE; - bool bVP; - vp >> bVP; + bool bVP; + vp >> bVP; - } + } else { + CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); + ASSERT(pFormField != NULL); + + if (pFormField->GetFieldFlags() & FIELDFLAG_READONLY) + vp << true; else - { - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); - ASSERT(pFormField != NULL); + vp << false; + } + + return TRUE; +} + +FX_BOOL Field::rect(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + 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)Upper_Leftx.ToInt(); + pArray[1] = (FX_FLOAT)Lower_Righty.ToInt(); + pArray[2] = (FX_FLOAT)Lower_Rightx.ToInt(); + pArray[3] = (FX_FLOAT)Upper_Lefty.ToInt(); + + 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; - if (pFormField->GetFieldFlags() & FIELDFLAG_READONLY) - vp << true; - else - vp << false; - } + CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); + ASSERT(pFormField != NULL); - return TRUE; + 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 = (int32_t)crRect.left; + Upper_Lefty = (int32_t)crRect.top; + Lower_Rightx = (int32_t)crRect.right; + Lower_Righty = (int32_t)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; } -FX_BOOL Field::rect(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); +void Field::SetRect(CPDFSDK_Document* pDocument, + const CFX_WideString& swFieldName, + int nControlIndex, + const CPDF_Rect& rect) { + ASSERT(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)Upper_Leftx.ToInt(); - pArray[1] = (FX_FLOAT)Lower_Righty.ToInt(); - pArray[2] = (FX_FLOAT)Lower_Rightx.ToInt(); - pArray[3] = (FX_FLOAT)Upper_Lefty.ToInt(); - - 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; + CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm(); + ASSERT(pInterForm != NULL); - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); - ASSERT(pFormField != NULL); + CFX_PtrArray FieldArray; + GetFormFields(pDocument, swFieldName, FieldArray); - CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); - ASSERT(pInterForm != NULL); + for (int i = 0, isz = FieldArray.GetSize(); i < isz; i++) { + CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(i); + ASSERT(pFormField != NULL); - CPDFSDK_Widget* pWidget = pInterForm->GetWidget(GetSmartFieldControl(pFormField)); - if (!pWidget) return FALSE; + 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); - 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 = (int32_t)crRect.left; - Upper_Lefty = (int32_t)crRect.top; - Lower_Rightx = (int32_t)crRect.right; - Lower_Righty = (int32_t)crRect.bottom; + if (CPDFSDK_Widget* pWidget = pInterForm->GetWidget(pFormControl)) { + CPDF_Rect crRect = rect; - 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); + CPDF_Page* pPDFPage = pWidget->GetPDFPage(); + ASSERT(pPDFPage != NULL); - vp << rcArray; - } + // CPDF_Page* pPDFPage = pPage->GetPage(); + // ASSERT(pPDFPage != NULL); - return TRUE; -} + crRect.Intersect(pPDFPage->GetPageBBox()); -void Field::SetRect(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CPDF_Rect& rect) -{ - ASSERT(pDocument != NULL); + 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; + } + } + } + } - CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm(); - ASSERT(pInterForm != NULL); + 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; - CFX_PtrArray FieldArray; - GetFormFields(pDocument, swFieldName, FieldArray); + CPDF_Page* pPDFPage = pWidget->GetPDFPage(); + ASSERT(pPDFPage != NULL); - for (int i=0,isz=FieldArray.GetSize(); iCountControls(); iGetControl(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; - } - } - } - } + // CPDF_Page* pPDFPage = pPage->GetPage(); + // ASSERT(pPDFPage != NULL); - 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); - } - } - } + 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(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); - - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName,FieldArray); - if (FieldArray.GetSize() <= 0) return FALSE; +FX_BOOL Field::required(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); - if (vp.IsSetting()) - { - if (!m_bCanSet) return FALSE; + 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; + bool bVP; + vp >> bVP; - } - else - { - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); - ASSERT(pFormField != NULL); + } else { + CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); + ASSERT(pFormField != NULL); - if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON) - return FALSE; + if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON) + return FALSE; - if (pFormField->GetFieldFlags() & FIELDFLAG_REQUIRED) - vp << true; - else - vp << false; - } + if (pFormField->GetFieldFlags() & FIELDFLAG_REQUIRED) + vp << true; + else + vp << false; + } - return TRUE; + return TRUE; } -FX_BOOL Field::richText(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); +FX_BOOL Field::richText(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); - if (vp.IsSetting()) - { - if (!m_bCanSet) return FALSE; + if (vp.IsSetting()) { + if (!m_bCanSet) + return FALSE; - bool bVP; - vp >> bVP; + bool bVP; + vp >> bVP; - if (m_bDelay) - { - AddDelay_Bool(FP_RICHTEXT, bVP); - } - else - { - Field::SetRichText(m_pDocument, m_FieldName, m_nFormControlIndex, 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; + } 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_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); + ASSERT(pFormField != NULL); - if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) - return FALSE; + if (pFormField->GetFieldType() != FIELDTYPE_TEXTFIELD) + return FALSE; - if (pFormField->GetFieldFlags() & FIELDFLAG_RICHTEXT) - vp << true; - else - vp << false; - } + if (pFormField->GetFieldFlags() & FIELDFLAG_RICHTEXT) + vp << true; + else + vp << false; + } - return TRUE; + return TRUE; } -void Field::SetRichText(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, bool b) -{ - //Not supported. +void Field::SetRichText(CPDFSDK_Document* pDocument, + const CFX_WideString& swFieldName, + int nControlIndex, + bool b) { + // Not supported. } -FX_BOOL Field::richValue(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - return TRUE; - if (vp.IsSetting()) - { - if (!m_bCanSet) return FALSE; - ; - } - else - { - ; - } - return TRUE; +FX_BOOL Field::richValue(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + 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. +void Field::SetRichValue(CPDFSDK_Document* pDocument, + const CFX_WideString& swFieldName, + int nControlIndex) { + // Not supported. } -FX_BOOL Field::rotation(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); +FX_BOOL Field::rotation(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); - if (vp.IsSetting()) - { - if (!m_bCanSet) return FALSE; + if (vp.IsSetting()) { + if (!m_bCanSet) + return FALSE; - int nVP; - vp >> nVP; + int nVP; + vp >> nVP; - if (m_bDelay) - { - AddDelay_Int(FP_ROTATION, nVP); - } - else - { - Field::SetRotation(m_pDocument, m_FieldName, m_nFormControlIndex, 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; + } 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_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); + ASSERT(pFormField != NULL); - CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); - if (!pFormControl)return FALSE; + CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); + if (!pFormControl) + return FALSE; - vp << (int32_t)pFormControl->GetRotation(); - } + vp << (int32_t)pFormControl->GetRotation(); + } - return TRUE; + return TRUE; } -void Field::SetRotation(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number) -{ - //Not supported. +void Field::SetRotation(CPDFSDK_Document* pDocument, + const CFX_WideString& swFieldName, + int nControlIndex, + int number) { + // Not supported. } -FX_BOOL Field::strokeColor(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); +FX_BOOL Field::strokeColor(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); - if (vp.IsSetting()) - { - if (!m_bCanSet) return FALSE; + if (vp.IsSetting()) { + if (!m_bCanSet) + return FALSE; - if (!vp.IsArrayObject())return FALSE; + if (!vp.IsArrayObject()) + return FALSE; - CJS_Array crArray(m_isolate); - vp >> crArray; + CJS_Array crArray(m_isolate); + vp >> crArray; - CPWL_Color color; - color::ConvertArrayToPWLColor(crArray, color); + 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); - } + 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); + } else { + CFX_PtrArray FieldArray; + GetFormFields(m_FieldName, FieldArray); + if (FieldArray.GetSize() <= 0) + return FALSE; - CPWL_Color color; + CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); + ASSERT(pFormField != NULL); - 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; + 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; - } + CJS_Array crArray(m_isolate); + color::ConvertPWLColorToArray(color, crArray); + vp << crArray; + } - return TRUE; + return TRUE; } -void Field::SetStrokeColor(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CPWL_Color& color) -{ - //Not supported. +void Field::SetStrokeColor(CPDFSDK_Document* pDocument, + const CFX_WideString& swFieldName, + int nControlIndex, + const CPWL_Color& color) { + // Not supported. } -FX_BOOL Field::style(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); +FX_BOOL Field::style(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); - if (vp.IsSetting()) - { - if (!m_bCanSet) return FALSE; + if (vp.IsSetting()) { + if (!m_bCanSet) + return FALSE; - CFX_ByteString csBCaption; - vp >> csBCaption; + CFX_ByteString csBCaption; + vp >> csBCaption; - if (m_bDelay) - { - AddDelay_String(FP_STYLE, csBCaption); - } - else - { - Field::SetStyle(m_pDocument, m_FieldName, m_nFormControlIndex, 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; + } 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; + return TRUE; } -void Field::SetStyle(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, - const CFX_ByteString& string) -{ - //Not supported. +void Field::SetStyle(CPDFSDK_Document* pDocument, + const CFX_WideString& swFieldName, + int nControlIndex, + const CFX_ByteString& string) { + // Not supported. } -FX_BOOL Field::submitName(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - return TRUE; +FX_BOOL Field::submitName(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + return TRUE; } -FX_BOOL Field::textColor(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); +FX_BOOL Field::textColor(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); - if (vp.IsSetting()) - { - if (!m_bCanSet) return FALSE; + if (vp.IsSetting()) { + if (!m_bCanSet) + return FALSE; - CJS_Array crArray(m_isolate); - if (!vp.IsArrayObject())return FALSE; - vp >> crArray; + CJS_Array crArray(m_isolate); + if (!vp.IsArrayObject()) + return FALSE; + vp >> crArray; - CPWL_Color color; - color::ConvertArrayToPWLColor(crArray, color); + 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); - } + 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; + } 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_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); + ASSERT(pFormField != NULL); - CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); - if (!pFormControl)return FALSE; + CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); + if (!pFormControl) + return FALSE; - int iColorType; - FX_ARGB color; - CPDF_DefaultAppearance FieldAppearance = pFormControl->GetDefaultAppearance(); - FieldAppearance.GetColor(color, iColorType); - int32_t a,r,g,b; - ArgbDecode(color, a, r, g, b); + int iColorType; + FX_ARGB color; + CPDF_DefaultAppearance FieldAppearance = + pFormControl->GetDefaultAppearance(); + FieldAppearance.GetColor(color, iColorType); + int32_t 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); + 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); + if (iColorType == COLORTYPE_TRANSPARENT) + crRet = CPWL_Color(COLORTYPE_TRANSPARENT); - CJS_Array crArray(m_isolate); - color::ConvertPWLColorToArray(crRet, crArray); - vp << crArray; - } + CJS_Array crArray(m_isolate); + color::ConvertPWLColorToArray(crRet, crArray); + vp << crArray; + } - return TRUE; + return TRUE; } -void Field::SetTextColor(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CPWL_Color& color) -{ - //Not supported. +void Field::SetTextColor(CPDFSDK_Document* pDocument, + const CFX_WideString& swFieldName, + int nControlIndex, + const CPWL_Color& color) { + // Not supported. } -FX_BOOL Field::textFont(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); +FX_BOOL Field::textFont(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); - if (vp.IsSetting()) - { - if (!m_bCanSet) return FALSE; + if (vp.IsSetting()) { + if (!m_bCanSet) + return FALSE; - CFX_ByteString csFontName; - vp >> csFontName; - if (csFontName.IsEmpty()) 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); - } + 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; + } 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_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); + ASSERT(pFormField != NULL); - CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); - if (!pFormControl)return FALSE; + CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); + if (!pFormControl) + return FALSE; - int nFieldType = pFormField->GetFieldType(); + 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; + 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; - } + vp << pFont->GetBaseFont(); + } else + return FALSE; + } - return TRUE; + return TRUE; } -void Field::SetTextFont(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CFX_ByteString& string) -{ - //Not supported. +void Field::SetTextFont(CPDFSDK_Document* pDocument, + const CFX_WideString& swFieldName, + int nControlIndex, + const CFX_ByteString& string) { + // Not supported. } -FX_BOOL Field::textSize(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); +FX_BOOL Field::textSize(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); - if (vp.IsSetting()) - { - if (!m_bCanSet) return FALSE; + if (vp.IsSetting()) { + if (!m_bCanSet) + return FALSE; - int nVP; - vp >> nVP; + int nVP; + vp >> nVP; - if (m_bDelay) - { - AddDelay_Int(FP_TEXTSIZE, nVP); - } - else - { - Field::SetTextSize(m_pDocument, m_FieldName, m_nFormControlIndex, 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; + } 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_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); + ASSERT(pFormField != NULL); - CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); - if (!pFormControl)return FALSE; + CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); + if (!pFormControl) + return FALSE; - CPDF_DefaultAppearance FieldAppearance = pFormControl->GetDefaultAppearance(); + CPDF_DefaultAppearance FieldAppearance = + pFormControl->GetDefaultAppearance(); - CFX_ByteString csFontNameTag; - FX_FLOAT fFontSize; - FieldAppearance.GetFont(csFontNameTag,fFontSize); + CFX_ByteString csFontNameTag; + FX_FLOAT fFontSize; + FieldAppearance.GetFont(csFontNameTag, fFontSize); - vp << (int)fFontSize; - } + vp << (int)fFontSize; + } - return TRUE; + return TRUE; } -void Field::SetTextSize(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, int number) -{ - //Not supported. +void Field::SetTextSize(CPDFSDK_Document* pDocument, + const CFX_WideString& swFieldName, + int nControlIndex, + int number) { + // Not supported. } -FX_BOOL Field::type(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); +FX_BOOL Field::type(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); + + if (!vp.IsGetting()) + return FALSE; - 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 << L"unknown"; + break; + case FIELDTYPE_PUSHBUTTON: + vp << L"button"; + break; + case FIELDTYPE_CHECKBOX: + vp << L"checkbox"; + break; + case FIELDTYPE_RADIOBUTTON: + vp << L"radiobutton"; + break; + case FIELDTYPE_COMBOBOX: + vp << L"combobox"; + break; + case FIELDTYPE_LISTBOX: + vp << L"listbox"; + break; + case FIELDTYPE_TEXTFIELD: + vp << L"text"; + break; + case FIELDTYPE_SIGNATURE: + vp << L"signature"; + break; + default: + vp << L"unknown"; + break; + } + + return TRUE; +} + +FX_BOOL Field::userName(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + 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; + 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 << L"unknown"; - break; - case FIELDTYPE_PUSHBUTTON: - vp << L"button"; - break; - case FIELDTYPE_CHECKBOX: - vp << L"checkbox"; - break; - case FIELDTYPE_RADIOBUTTON: - vp << L"radiobutton"; - break; - case FIELDTYPE_COMBOBOX: - vp << L"combobox"; - break; - case FIELDTYPE_LISTBOX: - vp << L"listbox"; - break; - case FIELDTYPE_TEXTFIELD: - vp << L"text"; - break; - case FIELDTYPE_SIGNATURE: - vp << L"signature"; - break; - default : - vp << L"unknown"; - break; - } + vp << (CFX_WideString)pFormField->GetAlternateName(); + } - return TRUE; + return TRUE; } -FX_BOOL Field::userName(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); +void Field::SetUserName(CPDFSDK_Document* pDocument, + const CFX_WideString& swFieldName, + int nControlIndex, + const CFX_WideString& string) { + // Not supported. +} - if (vp.IsSetting()) - { - if (!m_bCanSet) return FALSE; +FX_BOOL Field::value(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); - CFX_WideString swName; - vp >> swName; + if (vp.IsSetting()) { + if (!m_bCanSet) + return FALSE; - 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; + CJS_WideStringArray strArray; - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); - ASSERT(pFormField != NULL); + 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.ToCFXWideString()); + } + } else { + CFX_WideString swValue; + vp >> swValue; - vp << (CFX_WideString)pFormField->GetAlternateName(); + strArray.Add(swValue); } - return TRUE; -} - -void Field::SetUserName(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, int nControlIndex, const CFX_WideString& string) -{ - //Not supported. -} - -FX_BOOL Field::value(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - 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.ToCFXWideString()); - } - } - else - { - CFX_WideString swValue; - vp >> 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; - strArray.Add(swValue); - } + CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); + ASSERT(pFormField != NULL); - 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.c_str(), 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).c_str(); - if (FXSYS_wcslen(ElementValue.ToCFXWideString().c_str()) == 0) - ElementValue = pFormField->GetOptionLabel(iIndex).c_str(); - ValueArray.SetElement(i, ElementValue); - } - vp << ValueArray; - } - else - { - CFX_WideString swValue = pFormField->GetValue(); - - double dRet; - FX_BOOL bDot; - if (CJS_PublicMethods::ConvertStringToNumber(swValue.c_str(), 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.c_str(), dRet, bDot)) - { - if (bDot) - vp << dRet; - else - vp << dRet; - } - else - vp << swValue; - - bFind = TRUE; - break; - } - else - continue; - } - if (!bFind) - vp << L"Off"; - } - break; - default: - vp << pFormField->GetValue(); + 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.c_str(), 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).c_str(); + if (FXSYS_wcslen(ElementValue.ToCFXWideString().c_str()) == 0) + ElementValue = pFormField->GetOptionLabel(iIndex).c_str(); + ValueArray.SetElement(i, ElementValue); + } + vp << ValueArray; + } else { + CFX_WideString swValue = pFormField->GetValue(); + + double dRet; + FX_BOOL bDot; + if (CJS_PublicMethods::ConvertStringToNumber(swValue.c_str(), 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.c_str(), dRet, + bDot)) { + if (bDot) + vp << dRet; + else + vp << dRet; + } else + vp << swValue; + + bFind = TRUE; break; + } else + continue; } + if (!bFind) + vp << L"Off"; + } break; + default: + vp << pFormField->GetValue(); + break; } + } - return TRUE; + return TRUE; } -void Field::SetValue(CPDFSDK_Document* pDocument, const CFX_WideString& swFieldName, - int nControlIndex, const CJS_WideStringArray& strArray) -{ - ASSERT(pDocument != NULL); +void Field::SetValue(CPDFSDK_Document* pDocument, + const CFX_WideString& swFieldName, + int nControlIndex, + const CJS_WideStringArray& strArray) { + ASSERT(pDocument != NULL); - if (strArray.GetSize() < 1) return; + if (strArray.GetSize() < 1) + return; - CFX_PtrArray FieldArray; - GetFormFields(pDocument, swFieldName, FieldArray); + CFX_PtrArray FieldArray; + GetFormFields(pDocument, swFieldName, FieldArray); - for (int i=0,isz=FieldArray.GetSize(); iGetFullName().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 (pFormField->GetFullName().Compare(swFieldName) != 0) - continue; + 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); + } - 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(); iFindOption(strArray.GetAt(i)); - - if (!pFormField->IsItemSelected(iIndex)) - { - bModified = TRUE; - break; - } - } - - if (bModified) - { - pFormField->ClearSelection(TRUE); - for (int i=0,sz=strArray.GetSize(); iFindOption(strArray.GetAt(i)); - pFormField->SetItemSelection(iIndex, TRUE, TRUE); - } - - UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE); - } - } - break; - default: - break; + UpdateFormField(pDocument, pFormField, TRUE, FALSE, TRUE); } + } break; + default: + break; } + } } -FX_BOOL Field::valueAsString(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); +FX_BOOL Field::valueAsString(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); - if (!vp.IsGetting()) return FALSE; + if (!vp.IsGetting()) + return FALSE; - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName,FieldArray); - if (FieldArray.GetSize() <= 0) 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); + CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); + ASSERT(pFormField != NULL); - if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON) - return FALSE; + if (pFormField->GetFieldType() == FIELDTYPE_PUSHBUTTON) + return FALSE; - if (pFormField->GetFieldType() == FIELDTYPE_CHECKBOX) - { - if(!pFormField->CountControls()) return FALSE; + if (pFormField->GetFieldType() == FIELDTYPE_CHECKBOX) { + if (!pFormField->CountControls()) + return FALSE; - if (pFormField->GetControl(0)->IsChecked()) - vp << L"Yes"; - else - vp << L"Off"; - } - else if (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON && !(pFormField->GetFieldFlags() & FIELDFLAG_RADIOSINUNISON)) - { - for (int i=0, sz=pFormField->CountControls(); iGetControl(i)->IsChecked()) - { - vp << pFormField->GetControl(i)->GetExportValue().c_str(); - break; - } - else - vp << L"Off"; - } - } - else if (pFormField->GetFieldType() == FIELDTYPE_LISTBOX && (pFormField->CountSelectedItems() > 1)) - { - vp << L""; - } + if (pFormField->GetControl(0)->IsChecked()) + vp << L"Yes"; else - vp << pFormField->GetValue().c_str(); + vp << 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 << pFormField->GetControl(i)->GetExportValue().c_str(); + break; + } else + vp << L"Off"; + } + } else if (pFormField->GetFieldType() == FIELDTYPE_LISTBOX && + (pFormField->CountSelectedItems() > 1)) { + vp << L""; + } else + vp << pFormField->GetValue().c_str(); - return TRUE; + return TRUE; } -/* --------------------------------- methods --------------------------------- */ +/* --------------------------------- methods --------------------------------- + */ -FX_BOOL Field::browseForFileToSubmit(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); +FX_BOOL Field::browseForFileToSubmit(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName, FieldArray); - if (FieldArray.GetSize() <= 0) 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); + CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); + ASSERT(pFormField != NULL); - CPDFDoc_Environment* pApp = m_pDocument->GetEnv(); - ASSERT(pApp != 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); - } + 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; + } else + return FALSE; - return TRUE; + return TRUE; } +FX_BOOL Field::buttonGetCaption(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); -FX_BOOL Field::buttonGetCaption(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); - - int nface = 0; - int iSize = params.size(); - if (iSize >= 1) - nface = params[0].ToInt(); + int nface = 0; + int iSize = params.size(); + if (iSize >= 1) + nface = params[0].ToInt(); - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName,FieldArray); - if (FieldArray.GetSize() <= 0) 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); + CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); + ASSERT(pFormField != NULL); - if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON) - return FALSE; + if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON) + return FALSE; - CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); - if (!pFormControl)return FALSE; + CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); + if (!pFormControl) + return FALSE; - if (nface == 0) - vRet = pFormControl->GetNormalCaption().c_str(); - else if (nface == 1) - vRet = pFormControl->GetDownCaption().c_str(); - else if (nface == 2) - vRet = pFormControl->GetRolloverCaption().c_str(); - else - return FALSE; + if (nface == 0) + vRet = pFormControl->GetNormalCaption().c_str(); + else if (nface == 1) + vRet = pFormControl->GetDownCaption().c_str(); + else if (nface == 2) + vRet = pFormControl->GetRolloverCaption().c_str(); + else + return FALSE; - return TRUE; + return TRUE; } //#pragma warning(disable: 4800) -FX_BOOL Field::buttonGetIcon(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); +FX_BOOL Field::buttonGetIcon(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); - int nface = 0; - int iSize = params.size(); - if (iSize >= 1) - nface = params[0].ToInt(); + int nface = 0; + int iSize = params.size(); + if (iSize >= 1) + nface = params[0].ToInt(); - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName,FieldArray); - if (FieldArray.GetSize() <= 0) 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); + CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); + ASSERT(pFormField != NULL); - if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON) - return FALSE; + if (pFormField->GetFieldType() != FIELDTYPE_PUSHBUTTON) + return FALSE; - CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); - if (!pFormControl)return FALSE; + CPDF_FormControl* pFormControl = GetSmartFieldControl(pFormField); + if (!pFormControl) + return FALSE; - CJS_Context* pContext = (CJS_Context*)cc; - ASSERT(pContext != NULL); + CJS_Context* pContext = (CJS_Context*)cc; + ASSERT(pContext != NULL); - CJS_Runtime* pRuntime = pContext->GetJSRuntime(); - ASSERT(pRuntime != NULL); + CJS_Runtime* pRuntime = pContext->GetJSRuntime(); + ASSERT(pRuntime != NULL); - JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime, L"Icon")); - ASSERT(pObj.IsEmpty() == FALSE); + 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); + CJS_Icon* pJS_Icon = (CJS_Icon*)JS_GetPrivate(pObj); + ASSERT(pJS_Icon != NULL); - Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject(); - ASSERT(pIcon != 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; + 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; + pIcon->SetStream(pIconStream); + vRet = pJS_Icon; - return TRUE; + return TRUE; } //#pragma warning(default: 4800) -FX_BOOL Field::buttonImportIcon(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ +FX_BOOL Field::buttonImportIcon(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { #if 0 ASSERT(m_pDocument != NULL); @@ -3497,620 +3384,681 @@ FX_BOOL Field::buttonImportIcon(IFXJS_Context* cc, const CJS_Parameters& params, UpdateFormControl(m_pDocument, pFormControl, TRUE, TRUE, TRUE); vRet = 0; -#endif // 0 - return TRUE; +#endif // 0 + return TRUE; } -FX_BOOL Field::buttonSetCaption(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - return FALSE; +FX_BOOL Field::buttonSetCaption(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + return FALSE; } -FX_BOOL Field::buttonSetIcon(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - return FALSE; +FX_BOOL Field::buttonSetIcon(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + return FALSE; } -FX_BOOL Field::checkThisBox(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); +FX_BOOL Field::checkThisBox(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); - if (!m_bCanSet) return FALSE; + if (!m_bCanSet) + return FALSE; - int iSize = params.size(); - if (iSize < 1) - return FALSE; + int iSize = params.size(); + if (iSize < 1) + return FALSE; - int nWidget = params[0].ToInt(); + int nWidget = params[0].ToInt(); - FX_BOOL bCheckit = TRUE; - if (iSize >= 2) - bCheckit = params[1].ToBool(); + FX_BOOL bCheckit = TRUE; + if (iSize >= 2) + bCheckit = params[1].ToBool(); - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName,FieldArray); - if (FieldArray.GetSize() <= 0) 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); + 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); + 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; + UpdateFormField(m_pDocument, pFormField, TRUE, TRUE, TRUE); + return TRUE; } -FX_BOOL Field::clearItems(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - return TRUE; +FX_BOOL Field::clearItems(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + return TRUE; } -FX_BOOL Field::defaultIsChecked(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); - - if (!m_bCanSet) return FALSE; +FX_BOOL Field::defaultIsChecked(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); - int iSize = params.size(); - if (iSize < 1) - return FALSE; + if (!m_bCanSet) + return FALSE; - int nWidget = params[0].ToInt(); + int iSize = params.size(); + if (iSize < 1) + return FALSE; - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName,FieldArray); - if (FieldArray.GetSize() <= 0) return FALSE; + int nWidget = params[0].ToInt(); - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); - ASSERT(pFormField != NULL); + CFX_PtrArray FieldArray; + GetFormFields(m_FieldName, FieldArray); + if (FieldArray.GetSize() <= 0) + return FALSE; - if(nWidget <0 || nWidget >= pFormField->CountControls()) - { - vRet = FALSE; - return FALSE; - } - if ((pFormField->GetFieldType() == FIELDTYPE_CHECKBOX) - || (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON)) - { + CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); + ASSERT(pFormField != NULL); - vRet = TRUE; - } - else - vRet = FALSE; + 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; + return TRUE; } -FX_BOOL Field::deleteItemAt(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - return TRUE; +FX_BOOL Field::deleteItemAt(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + return TRUE; } -int JS_COMPARESTRING(CFX_WideString* ps1, CFX_WideString* ps2) -{ - ASSERT(ps1 != NULL); - ASSERT(ps2 != NULL); +int JS_COMPARESTRING(CFX_WideString* ps1, CFX_WideString* ps2) { + ASSERT(ps1 != NULL); + ASSERT(ps2 != NULL); - return ps1->Compare(*ps2); + return ps1->Compare(*ps2); } +FX_BOOL Field::getArray(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); -FX_BOOL Field::getArray(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); - - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName,FieldArray); - if (FieldArray.GetSize() <= 0) return FALSE; - - CGW_ArrayTemplate swSort; + CFX_PtrArray FieldArray; + GetFormFields(m_FieldName, FieldArray); + if (FieldArray.GetSize() <= 0) + return FALSE; - for (int i=0,sz=FieldArray.GetSize(); i swSort; - swSort.Add(new CFX_WideString(pFormField->GetFullName())); + for (int i = 0, sz = FieldArray.GetSize(); i < sz; i++) { + CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(i); + ASSERT(pFormField != NULL); - } - swSort.Sort(JS_COMPARESTRING); + 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_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(); jGetEmbedObject(); - ASSERT(pField != NULL); + Field* pField = (Field*)pJSField->GetEmbedObject(); + ASSERT(pField != NULL); - pField->AttachField(m_pJSDoc, *pStr); + pField->AttachField(m_pJSDoc, *pStr); - CJS_Value FormFieldValue(m_isolate); - FormFieldValue = pJSField; - FormFieldArray.SetElement(j, FormFieldValue); + CJS_Value FormFieldValue(m_isolate); + FormFieldValue = pJSField; + FormFieldArray.SetElement(j, FormFieldValue); - delete pStr; - } + delete pStr; + } - vRet = FormFieldArray; - swSort.RemoveAll(); - return TRUE; + vRet = FormFieldArray; + swSort.RemoveAll(); + return TRUE; } -FX_BOOL Field::getItemAt(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); - int iSize = params.size(); - - int nIdx = -1; - if (iSize >= 1) - nIdx = params[0].ToInt(); +FX_BOOL Field::getItemAt(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); + int iSize = params.size(); - FX_BOOL bExport = TRUE; - if (iSize >= 2) - bExport = params[1].ToBool(); + int nIdx = -1; + if (iSize >= 1) + nIdx = params[0].ToInt(); - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName,FieldArray); - if (FieldArray.GetSize() <= 0) return FALSE; + FX_BOOL bExport = TRUE; + if (iSize >= 2) + bExport = params[1].ToBool(); - CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); - ASSERT(pFormField != NULL); + CFX_PtrArray FieldArray; + GetFormFields(m_FieldName, FieldArray); + if (FieldArray.GetSize() <= 0) + return FALSE; - 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).c_str(); - else - vRet = strval.c_str(); - } - else - vRet = pFormField->GetOptionLabel(nIdx).c_str(); - } - else - 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).c_str(); + else + vRet = strval.c_str(); + } else + vRet = pFormField->GetOptionLabel(nIdx).c_str(); + } else + return FALSE; - return TRUE; + return TRUE; } -FX_BOOL Field::getLock(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - return FALSE; +FX_BOOL Field::getLock(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + return FALSE; } -FX_BOOL Field::insertItemAt(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - return TRUE; +FX_BOOL Field::insertItemAt(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + return TRUE; } -FX_BOOL Field::isBoxChecked(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); +FX_BOOL Field::isBoxChecked(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); - int nIndex = -1; - if (params.size() >= 1) - nIndex = params[0].ToInt(); + int nIndex = -1; + if (params.size() >= 1) + nIndex = params[0].ToInt(); - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName,FieldArray); - if (FieldArray.GetSize() <= 0) 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); + CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); + ASSERT(pFormField != NULL); - if(nIndex <0 || nIndex >= pFormField->CountControls()) - { - vRet = FALSE; - return FALSE; - } + 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; - } + if ((pFormField->GetFieldType() == FIELDTYPE_CHECKBOX) || + (pFormField->GetFieldType() == FIELDTYPE_RADIOBUTTON)) { + if (pFormField->GetControl(nIndex)->IsChecked() != 0) + vRet = TRUE; else - vRet = FALSE; + vRet = FALSE; + } else + vRet = FALSE; - return TRUE; + return TRUE; } -FX_BOOL Field::isDefaultChecked(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); +FX_BOOL Field::isDefaultChecked(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); - int nIndex = -1; - if (params.size() >= 1) - nIndex = params[0].ToInt(); + int nIndex = -1; + if (params.size() >= 1) + nIndex = params[0].ToInt(); - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName,FieldArray); - if (FieldArray.GetSize() <= 0) 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); + 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; - } + 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; + vRet = FALSE; + } else + vRet = FALSE; - return TRUE; + return TRUE; } -FX_BOOL Field::setAction(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - return TRUE; +FX_BOOL Field::setAction(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + return TRUE; } -FX_BOOL Field::setFocus(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - ASSERT(m_pDocument != NULL); +FX_BOOL Field::setFocus(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + ASSERT(m_pDocument != NULL); - CFX_PtrArray FieldArray; - GetFormFields(m_FieldName,FieldArray); - if (FieldArray.GetSize() <= 0) 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); + CPDF_FormField* pFormField = (CPDF_FormField*)FieldArray.ElementAt(0); + ASSERT(pFormField != NULL); - int32_t nCount = pFormField->CountControls(); + int32_t nCount = pFormField->CountControls(); - if (nCount < 1) return FALSE; + if (nCount < 1) + return FALSE; - CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); - ASSERT(pInterForm != NULL); + 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 (int32_t i=0; iGetWidget(pFormField->GetControl(i))) - { - if (pTempWidget->GetPDFPage() == pCurPageView->GetPDFPage()) - { - pWidget = pTempWidget; - break; - } - } - } + 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 (int32_t 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); - } + if (pWidget) { + m_pDocument->SetFocusAnnot(pWidget); + } - return TRUE; + return TRUE; } -FX_BOOL Field::setItems(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - return TRUE; +FX_BOOL Field::setItems(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + return TRUE; } -FX_BOOL Field::setLock(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - return FALSE; +FX_BOOL Field::setLock(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + return FALSE; } -FX_BOOL Field::signatureGetModifications(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - return FALSE; +FX_BOOL Field::signatureGetModifications(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + return FALSE; } -FX_BOOL Field::signatureGetSeedValue(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - return FALSE; +FX_BOOL Field::signatureGetSeedValue(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + return FALSE; } -FX_BOOL Field::signatureInfo(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - return FALSE; +FX_BOOL Field::signatureInfo(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + return FALSE; } -FX_BOOL Field::signatureSetSeedValue(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - return FALSE; +FX_BOOL Field::signatureSetSeedValue(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + return FALSE; } -FX_BOOL Field::signatureSign(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - return FALSE; +FX_BOOL Field::signatureSign(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + return FALSE; } -FX_BOOL Field::signatureValidate(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - return FALSE; +FX_BOOL Field::signatureValidate(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + return FALSE; } -FX_BOOL Field::source(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - if (vp.IsGetting()) - { - vp << (CJS_Object*)NULL; - } +FX_BOOL Field::source(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + if (vp.IsGetting()) { + vp << (CJS_Object*)NULL; + } - return TRUE; + return TRUE; } -/////////////////////////////////////////// delay ///////////////////////////////////////////// +/////////////////////////////////////////// delay +//////////////////////////////////////////////// -void Field::AddDelay_Int(enum FIELD_PROP prop, int32_t n) -{ - ASSERT(m_pJSDoc != NULL); +void Field::AddDelay_Int(enum FIELD_PROP prop, int32_t 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; + CJS_DelayData* pNewData = new CJS_DelayData; + pNewData->sFieldName = m_FieldName; + pNewData->nControlIndex = m_nFormControlIndex; + pNewData->eProp = prop; + pNewData->num = n; - m_pJSDoc->AddDelayData(pNewData); + m_pJSDoc->AddDelayData(pNewData); } -void Field::AddDelay_Bool(enum FIELD_PROP prop,bool b) -{ - ASSERT(m_pJSDoc != NULL); +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; + CJS_DelayData* pNewData = new CJS_DelayData; + pNewData->sFieldName = m_FieldName; + pNewData->nControlIndex = m_nFormControlIndex; + pNewData->eProp = prop; + pNewData->b = b; - m_pJSDoc->AddDelayData(pNewData); + m_pJSDoc->AddDelayData(pNewData); } -void Field::AddDelay_String(enum FIELD_PROP prop, const CFX_ByteString& string) -{ - ASSERT(m_pJSDoc != NULL); +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; + CJS_DelayData* pNewData = new CJS_DelayData; + pNewData->sFieldName = m_FieldName; + pNewData->nControlIndex = m_nFormControlIndex; + pNewData->eProp = prop; + pNewData->string = string; - m_pJSDoc->AddDelayData(pNewData); + m_pJSDoc->AddDelayData(pNewData); } -void Field::AddDelay_WideString(enum FIELD_PROP prop, const CFX_WideString& string) -{ - ASSERT(m_pJSDoc != NULL); +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; + CJS_DelayData* pNewData = new CJS_DelayData; + pNewData->sFieldName = m_FieldName; + pNewData->nControlIndex = m_nFormControlIndex; + pNewData->eProp = prop; + pNewData->widestring = string; - m_pJSDoc->AddDelayData(pNewData); + m_pJSDoc->AddDelayData(pNewData); } -void Field::AddDelay_Rect(enum FIELD_PROP prop, const CPDF_Rect& rect) -{ - ASSERT(m_pJSDoc != NULL); +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; + CJS_DelayData* pNewData = new CJS_DelayData; + pNewData->sFieldName = m_FieldName; + pNewData->nControlIndex = m_nFormControlIndex; + pNewData->eProp = prop; + pNewData->rect = rect; - m_pJSDoc->AddDelayData(pNewData); + m_pJSDoc->AddDelayData(pNewData); } -void Field::AddDelay_Color(enum FIELD_PROP prop, const CPWL_Color& color) -{ - ASSERT(m_pJSDoc != NULL); +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; + CJS_DelayData* pNewData = new CJS_DelayData; + pNewData->sFieldName = m_FieldName; + pNewData->nControlIndex = m_nFormControlIndex; + pNewData->eProp = prop; + pNewData->color = color; - m_pJSDoc->AddDelayData(pNewData); + m_pJSDoc->AddDelayData(pNewData); } -void Field::AddDelay_WordArray(enum FIELD_PROP prop, const CFX_DWordArray& array) -{ - ASSERT(m_pJSDoc != NULL); +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; + CJS_DelayData* pNewData = new CJS_DelayData; + pNewData->sFieldName = m_FieldName; + pNewData->nControlIndex = m_nFormControlIndex; + pNewData->eProp = prop; - for (int i=0,sz=array.GetSize(); iwordarray.Add(array.GetAt(i)); + for (int i = 0, sz = array.GetSize(); i < sz; i++) + pNewData->wordarray.Add(array.GetAt(i)); - m_pJSDoc->AddDelayData(pNewData); + m_pJSDoc->AddDelayData(pNewData); } -void Field::AddDelay_WideStringArray(enum FIELD_PROP prop, const CJS_WideStringArray& array) -{ - ASSERT(m_pJSDoc != NULL); +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(); iwidestringarray.Add(array.GetAt(i)); + 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); + m_pJSDoc->AddDelayData(pNewData); } -void Field::DoDelay(CPDFSDK_Document* pDocument, CJS_DelayData* pData) -{ - ASSERT(pDocument != NULL); - ASSERT(pData != NULL); +void Field::DoDelay(CPDFSDK_Document* pDocument, CJS_DelayData* pData) { + ASSERT(pDocument != NULL); + ASSERT(pData != NULL); - switch (pData->eProp) - { + switch (pData->eProp) { case FP_ALIGNMENT: - Field::SetAlignment(pDocument, pData->sFieldName, pData->nControlIndex, pData->string); - break; + Field::SetAlignment(pDocument, pData->sFieldName, pData->nControlIndex, + pData->string); + break; case FP_BORDERSTYLE: - Field::SetBorderStyle(pDocument, pData->sFieldName, pData->nControlIndex, pData->string); - break; + Field::SetBorderStyle(pDocument, pData->sFieldName, pData->nControlIndex, + pData->string); + break; case FP_BUTTONALIGNX: - Field::SetButtonAlignX(pDocument, pData->sFieldName, pData->nControlIndex, pData->num); - break; + Field::SetButtonAlignX(pDocument, pData->sFieldName, pData->nControlIndex, + pData->num); + break; case FP_BUTTONALIGNY: - Field::SetButtonAlignY(pDocument, pData->sFieldName, pData->nControlIndex, pData->num); - break; + Field::SetButtonAlignY(pDocument, pData->sFieldName, pData->nControlIndex, + pData->num); + break; case FP_BUTTONFITBOUNDS: - Field::SetButtonFitBounds(pDocument, pData->sFieldName, pData->nControlIndex, pData->b); - break; + Field::SetButtonFitBounds(pDocument, pData->sFieldName, + pData->nControlIndex, pData->b); + break; case FP_BUTTONPOSITION: - Field::SetButtonPosition(pDocument, pData->sFieldName, pData->nControlIndex, pData->num); - break; + Field::SetButtonPosition(pDocument, pData->sFieldName, + pData->nControlIndex, pData->num); + break; case FP_BUTTONSCALEHOW: - Field::SetButtonScaleHow(pDocument, pData->sFieldName, pData->nControlIndex, pData->num); - break; + Field::SetButtonScaleHow(pDocument, pData->sFieldName, + pData->nControlIndex, pData->num); + break; case FP_BUTTONSCALEWHEN: - Field::SetButtonScaleWhen(pDocument, pData->sFieldName, pData->nControlIndex, pData->num); - break; + Field::SetButtonScaleWhen(pDocument, pData->sFieldName, + pData->nControlIndex, pData->num); + break; case FP_CALCORDERINDEX: - Field::SetCalcOrderIndex(pDocument, pData->sFieldName, pData->nControlIndex, pData->num); - break; + Field::SetCalcOrderIndex(pDocument, pData->sFieldName, + pData->nControlIndex, pData->num); + break; case FP_CHARLIMIT: - Field::SetCharLimit(pDocument, pData->sFieldName, pData->nControlIndex, pData->num); - break; + Field::SetCharLimit(pDocument, pData->sFieldName, pData->nControlIndex, + pData->num); + break; case FP_COMB: - Field::SetComb(pDocument, pData->sFieldName, pData->nControlIndex, pData->b); - break; + Field::SetComb(pDocument, pData->sFieldName, pData->nControlIndex, + pData->b); + break; case FP_COMMITONSELCHANGE: - Field::SetCommitOnSelChange(pDocument, pData->sFieldName, pData->nControlIndex, pData->b); - break; + Field::SetCommitOnSelChange(pDocument, pData->sFieldName, + pData->nControlIndex, pData->b); + break; case FP_CURRENTVALUEINDICES: - Field::SetCurrentValueIndices(pDocument, pData->sFieldName, pData->nControlIndex, pData->wordarray); - break; + Field::SetCurrentValueIndices(pDocument, pData->sFieldName, + pData->nControlIndex, pData->wordarray); + break; case FP_DEFAULTVALUE: - Field::SetDefaultValue(pDocument, pData->sFieldName, pData->nControlIndex, pData->widestring); - break; + Field::SetDefaultValue(pDocument, pData->sFieldName, pData->nControlIndex, + pData->widestring); + break; case FP_DONOTSCROLL: - Field::SetDoNotScroll(pDocument, pData->sFieldName, pData->nControlIndex, pData->b); - break; + Field::SetDoNotScroll(pDocument, pData->sFieldName, pData->nControlIndex, + pData->b); + break; case FP_DISPLAY: - Field::SetDisplay(pDocument, pData->sFieldName, pData->nControlIndex, pData->num); - break; + Field::SetDisplay(pDocument, pData->sFieldName, pData->nControlIndex, + pData->num); + break; case FP_FILLCOLOR: - Field::SetFillColor(pDocument, pData->sFieldName, pData->nControlIndex, pData->color); - break; + Field::SetFillColor(pDocument, pData->sFieldName, pData->nControlIndex, + pData->color); + break; case FP_HIDDEN: - Field::SetHidden(pDocument, pData->sFieldName, pData->nControlIndex, pData->b); - break; + Field::SetHidden(pDocument, pData->sFieldName, pData->nControlIndex, + pData->b); + break; case FP_HIGHLIGHT: - Field::SetHighlight(pDocument, pData->sFieldName, pData->nControlIndex, pData->string); - break; + Field::SetHighlight(pDocument, pData->sFieldName, pData->nControlIndex, + pData->string); + break; case FP_LINEWIDTH: - Field::SetLineWidth(pDocument, pData->sFieldName, pData->nControlIndex, pData->num); - break; + Field::SetLineWidth(pDocument, pData->sFieldName, pData->nControlIndex, + pData->num); + break; case FP_MULTILINE: - Field::SetMultiline(pDocument, pData->sFieldName, pData->nControlIndex, pData->b); - break; + Field::SetMultiline(pDocument, pData->sFieldName, pData->nControlIndex, + pData->b); + break; case FP_MULTIPLESELECTION: - Field::SetMultipleSelection(pDocument, pData->sFieldName, pData->nControlIndex, pData->b); - break; + Field::SetMultipleSelection(pDocument, pData->sFieldName, + pData->nControlIndex, pData->b); + break; case FP_PASSWORD: - Field::SetPassword(pDocument, pData->sFieldName, pData->nControlIndex, pData->b); - break; + Field::SetPassword(pDocument, pData->sFieldName, pData->nControlIndex, + pData->b); + break; case FP_RECT: - Field::SetRect(pDocument, pData->sFieldName, pData->nControlIndex, pData->rect); - break; + Field::SetRect(pDocument, pData->sFieldName, pData->nControlIndex, + pData->rect); + break; case FP_RICHTEXT: - Field::SetRichText(pDocument, pData->sFieldName, pData->nControlIndex, pData->b); - break; + Field::SetRichText(pDocument, pData->sFieldName, pData->nControlIndex, + pData->b); + break; case FP_RICHVALUE: - break; + break; case FP_ROTATION: - Field::SetRotation(pDocument, pData->sFieldName, pData->nControlIndex, pData->num); - break; + Field::SetRotation(pDocument, pData->sFieldName, pData->nControlIndex, + pData->num); + break; case FP_STROKECOLOR: - Field::SetStrokeColor(pDocument, pData->sFieldName, pData->nControlIndex, pData->color); - break; + Field::SetStrokeColor(pDocument, pData->sFieldName, pData->nControlIndex, + pData->color); + break; case FP_STYLE: - Field::SetStyle(pDocument, pData->sFieldName, pData->nControlIndex, pData->string); - break; + Field::SetStyle(pDocument, pData->sFieldName, pData->nControlIndex, + pData->string); + break; case FP_TEXTCOLOR: - Field::SetTextColor(pDocument, pData->sFieldName, pData->nControlIndex, pData->color); - break; + Field::SetTextColor(pDocument, pData->sFieldName, pData->nControlIndex, + pData->color); + break; case FP_TEXTFONT: - Field::SetTextFont(pDocument, pData->sFieldName, pData->nControlIndex, pData->string); - break; + Field::SetTextFont(pDocument, pData->sFieldName, pData->nControlIndex, + pData->string); + break; case FP_TEXTSIZE: - Field::SetTextSize(pDocument, pData->sFieldName, pData->nControlIndex, pData->num); - break; + Field::SetTextSize(pDocument, pData->sFieldName, pData->nControlIndex, + pData->num); + break; case FP_USERNAME: - Field::SetUserName(pDocument, pData->sFieldName, pData->nControlIndex, pData->widestring); - break; + Field::SetUserName(pDocument, pData->sFieldName, pData->nControlIndex, + pData->widestring); + break; case FP_VALUE: - Field::SetValue(pDocument, pData->sFieldName, pData->nControlIndex, pData->widestringarray); - break; - } + Field::SetValue(pDocument, pData->sFieldName, pData->nControlIndex, + pData->widestringarray); + break; + } } -#define JS_FIELD_MINWIDTH 1 -#define JS_FIELD_MINHEIGHT 1 +#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. +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 6b3e02e1ec..0e96a05e5e 100644 --- a/fpdfsdk/src/javascript/Icon.cpp +++ b/fpdfsdk/src/javascript/Icon.cpp @@ -17,51 +17,42 @@ BEGIN_JS_STATIC_CONST(CJS_Icon) END_JS_STATIC_CONST() BEGIN_JS_STATIC_PROP(CJS_Icon) - JS_STATIC_PROP_ENTRY(name) +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) +IMPLEMENT_JS_CLASS(CJS_Icon, Icon) -Icon::Icon(CJS_Object* pJSObject) : CJS_EmbedObj(pJSObject), - m_pIconStream(NULL), - m_swIconName(L"") -{ -} - -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; +void Icon::SetStream(CPDF_Stream* pIconStream) { + if (pIconStream) + m_pIconStream = pIconStream; } -CPDF_Stream* Icon::GetStream() -{ - return m_pIconStream; +CPDF_Stream* Icon::GetStream() { + return m_pIconStream; } -void Icon::SetIconName(CFX_WideString name) -{ - m_swIconName = name; +void Icon::SetIconName(CFX_WideString name) { + m_swIconName = name; } -CFX_WideString Icon::GetIconName() -{ - return m_swIconName; +CFX_WideString Icon::GetIconName() { + return m_swIconName; } -FX_BOOL Icon::name(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - if(!vp.IsGetting())return FALSE; +FX_BOOL Icon::name(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + if (!vp.IsGetting()) + return FALSE; - vp << m_swIconName; - return TRUE; + vp << m_swIconName; + return TRUE; } - diff --git a/fpdfsdk/src/javascript/JS_Context.cpp b/fpdfsdk/src/javascript/JS_Context.cpp index 72be34d751..6e935e8647 100644 --- a/fpdfsdk/src/javascript/JS_Context.cpp +++ b/fpdfsdk/src/javascript/JS_Context.cpp @@ -14,337 +14,345 @@ /* -------------------------- 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(CJS_Runtime* pRuntime) + : m_pRuntime(pRuntime), m_bBusy(FALSE), m_bMsgBoxEnable(TRUE) { + m_pEventHandler = new CJS_EventHandler(this); } -CJS_Context::~CJS_Context(void) -{ - delete m_pEventHandler; +CJS_Context::~CJS_Context(void) { + delete m_pEventHandler; } -CPDFSDK_Document* CJS_Context::GetReaderDocument() -{ - ASSERT(m_pRuntime != NULL); +CPDFSDK_Document* CJS_Context::GetReaderDocument() { + ASSERT(m_pRuntime != NULL); - return m_pRuntime->GetReaderDocument(); + return m_pRuntime->GetReaderDocument(); } -CPDFDoc_Environment* CJS_Context::GetReaderApp() -{ - ASSERT(m_pRuntime != NULL); +CPDFDoc_Environment* CJS_Context::GetReaderApp() { + ASSERT(m_pRuntime != NULL); - return m_pRuntime->GetReaderApp(); + 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; - } +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; + m_bBusy = TRUE; - ASSERT(m_pRuntime != NULL); - ASSERT(m_pEventHandler != NULL); - ASSERT(m_pEventHandler->IsValid()); + 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; - } + 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; + FXJSErr error = {NULL, NULL, 0}; + int nRet = 0; - if (script.GetLength() > 0) - { - if (nMode == 0) - { - nRet = JS_Execute(*m_pRuntime, this, script.c_str(), script.GetLength(), &error); - } - else - { - nRet = JS_Parse(*m_pRuntime, this, script.c_str(), script.GetLength(), &error); - } - } + if (script.GetLength() > 0) { + if (nMode == 0) { + nRet = JS_Execute(*m_pRuntime, this, script.c_str(), script.GetLength(), + &error); + } else { + nRet = JS_Parse(*m_pRuntime, this, script.c_str(), script.GetLength(), + &error); + } + } - if (nRet < 0) - { - CFX_WideString sLine; - sLine.Format(L"[ Line: %05d { %s } ] : %s",error.linnum-1,error.srcline,error.message); + if (nRet < 0) { + CFX_WideString sLine; + sLine.Format(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); - } + // 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); + } - m_pRuntime->RemoveEventInLoop(m_pEventHandler->TargetName(), m_pEventHandler->EventType()); + m_pRuntime->RemoveEventInLoop(m_pEventHandler->TargetName(), + m_pEventHandler->EventType()); - m_pEventHandler->Destroy(); - m_bBusy = FALSE; + m_pEventHandler->Destroy(); + m_bBusy = FALSE; - return nRet >= 0; + 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 context = m_pRuntime->NewJSContext(); - v8::Context::Scope context_scope(context); +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 context = m_pRuntime->NewJSContext(); + v8::Context::Scope context_scope(context); - return DoJob(0, script, info); + 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 context = m_pRuntime->NewJSContext(); - v8::Context::Scope context_scope(context); +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 context = m_pRuntime->NewJSContext(); + v8::Context::Scope context_scope(context); - return DoJob(1, script, info); + return DoJob(1, script, info); } -void CJS_Context::OnApp_Init() -{ - ASSERT(m_pEventHandler != NULL); - m_pEventHandler->OnApp_Init(); +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_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_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_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_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_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::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_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_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_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::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_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_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_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_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_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_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_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(CPDF_FormField* pTarget, CFX_WideString& Value, FX_BOOL bWillCommit) -{ - m_pEventHandler->OnField_Format(pTarget, Value, bWillCommit); +void CJS_Context::OnField_Format(CPDF_FormField* pTarget, + CFX_WideString& Value, + FX_BOOL bWillCommit) { + m_pEventHandler->OnField_Format(pTarget, Value, bWillCommit); } - -void CJS_Context::OnField_Keystroke(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) -{ - m_pEventHandler->OnField_Keystroke( - strChange, strChangeEx, bKeyDown, bModifier, nSelEnd, nSelStart, - bShift, pTarget, Value, bWillCommit, bFieldFull, bRc); +void CJS_Context::OnField_Keystroke(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) { + m_pEventHandler->OnField_Keystroke( + 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::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_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_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_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_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_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_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_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_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_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::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::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::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::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::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::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); +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 1769e3053f..1eee92ddc1 100644 --- a/fpdfsdk/src/javascript/JS_EventHandler.cpp +++ b/fpdfsdk/src/javascript/JS_EventHandler.cpp @@ -17,511 +17,536 @@ /* ---------------------------- 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(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() -{ -} +CJS_EventHandler::~CJS_EventHandler() {} -void CJS_EventHandler::OnApp_Init() -{ - Initial(JET_APP_INIT); +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); +void CJS_EventHandler::OnDoc_Open(CPDFSDK_Document* pDoc, + const CFX_WideString& strTargetName) { + Initial(JET_DOC_OPEN); - m_pTargetDoc = pDoc; - m_strTargetName = strTargetName; + m_pTargetDoc = pDoc; + m_strTargetName = strTargetName; } -void CJS_EventHandler::OnDoc_WillPrint(CPDFSDK_Document* pDoc) -{ - Initial(JET_DOC_WILLPRINT); +void CJS_EventHandler::OnDoc_WillPrint(CPDFSDK_Document* pDoc) { + Initial(JET_DOC_WILLPRINT); - m_pTargetDoc = pDoc; + m_pTargetDoc = pDoc; } -void CJS_EventHandler::OnDoc_DidPrint(CPDFSDK_Document* pDoc) -{ - Initial(JET_DOC_DIDPRINT); +void CJS_EventHandler::OnDoc_DidPrint(CPDFSDK_Document* pDoc) { + Initial(JET_DOC_DIDPRINT); - m_pTargetDoc = pDoc; + m_pTargetDoc = pDoc; } -void CJS_EventHandler::OnDoc_WillSave(CPDFSDK_Document* pDoc) -{ - Initial(JET_DOC_WILLSAVE); - 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); +void CJS_EventHandler::OnDoc_DidSave(CPDFSDK_Document* pDoc) { + Initial(JET_DOC_DIDSAVE); - m_pTargetDoc = pDoc; + m_pTargetDoc = pDoc; } -void CJS_EventHandler::OnDoc_WillClose(CPDFSDK_Document* pDoc) -{ - Initial(JET_DOC_WILLCLOSE); +void CJS_EventHandler::OnDoc_WillClose(CPDFSDK_Document* pDoc) { + Initial(JET_DOC_WILLCLOSE); - m_pTargetDoc = pDoc; + m_pTargetDoc = pDoc; } -void CJS_EventHandler::OnPage_Open(CPDFSDK_Document* pDoc) -{ - Initial(JET_PAGE_OPEN); +void CJS_EventHandler::OnPage_Open(CPDFSDK_Document* pDoc) { + Initial(JET_PAGE_OPEN); - m_pTargetDoc = pDoc; + m_pTargetDoc = pDoc; } -void CJS_EventHandler::OnPage_Close(CPDFSDK_Document* pDoc) -{ - Initial(JET_PAGE_CLOSE); +void CJS_EventHandler::OnPage_Close(CPDFSDK_Document* pDoc) { + Initial(JET_PAGE_CLOSE); - m_pTargetDoc = pDoc; + m_pTargetDoc = pDoc; } -void CJS_EventHandler::OnPage_InView(CPDFSDK_Document* pDoc) -{ - Initial(JET_PAGE_INVIEW); +void CJS_EventHandler::OnPage_InView(CPDFSDK_Document* pDoc) { + Initial(JET_PAGE_INVIEW); - m_pTargetDoc = pDoc; + m_pTargetDoc = pDoc; } -void CJS_EventHandler::OnPage_OutView(CPDFSDK_Document* pDoc) -{ - Initial(JET_PAGE_OUTVIEW); +void CJS_EventHandler::OnPage_OutView(CPDFSDK_Document* pDoc) { + Initial(JET_PAGE_OUTVIEW); - m_pTargetDoc = pDoc; + m_pTargetDoc = pDoc; } -void CJS_EventHandler::OnField_MouseEnter(FX_BOOL bModifier, FX_BOOL bShift, CPDF_FormField* pTarget) -{ - Initial(JET_FIELD_MOUSEENTER); +void CJS_EventHandler::OnField_MouseEnter(FX_BOOL bModifier, + FX_BOOL bShift, + CPDF_FormField* pTarget) { + Initial(JET_FIELD_MOUSEENTER); - m_bModifier = bModifier; - m_bShift = bShift; + m_bModifier = bModifier; + m_bShift = bShift; - ASSERT(pTarget != NULL); - m_strTargetName = pTarget->GetFullName(); + 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); +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(); + 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; +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(); + 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); +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(); + 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); +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; + 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); +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; + m_bModifier = bModifier; + m_bShift = bShift; + ASSERT(pTarget != NULL); + m_strTargetName = pTarget->GetFullName(); + m_pValue = (CFX_WideString*)&Value; } -void CJS_EventHandler::OnField_Keystroke(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 = 0; - 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_Keystroke(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 = 0; + 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(CPDF_FormField* pTarget, CFX_WideString& Value, - FX_BOOL bWillCommit) -{ - Initial(JET_FIELD_FORMAT); + FX_BOOL bWillCommit) { + Initial(JET_FIELD_FORMAT); - m_nCommitKey = 0; - ASSERT(pTarget != NULL); - m_strTargetName = pTarget->GetFullName(); - m_pValue = &Value; - m_bWillCommit = bWillCommit; + m_nCommitKey = 0; + 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); +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; + 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); +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; + 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); +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; + 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); +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; + 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); +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; + 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); +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; + 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); +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; + 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); +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; + 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); +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; + 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); +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; + m_bModifier = bModifier; + m_bShift = bShift; + m_pTargetAnnot = pScreen; } -void CJS_EventHandler::OnLink_MouseUp(CPDFSDK_Document* pTarget) -{ - Initial(JET_LINK_MOUSEUP); +void CJS_EventHandler::OnLink_MouseUp(CPDFSDK_Document* pTarget) { + Initial(JET_LINK_MOUSEUP); - m_pTargetDoc = pTarget; + m_pTargetDoc = pTarget; } -void CJS_EventHandler::OnBookmark_MouseUp(CPDF_Bookmark* pBookMark) -{ - Initial(JET_BOOKMARK_MOUSEUP); +void CJS_EventHandler::OnBookmark_MouseUp(CPDF_Bookmark* pBookMark) { + Initial(JET_BOOKMARK_MOUSEUP); - m_pTargetBookMark = pBookMark; + m_pTargetBookMark = pBookMark; } -void CJS_EventHandler::OnMenu_Exec(CPDFSDK_Document* pTarget, const CFX_WideString& strTargetName) -{ - Initial(JET_MENU_EXEC); +void CJS_EventHandler::OnMenu_Exec(CPDFSDK_Document* pTarget, + const CFX_WideString& strTargetName) { + Initial(JET_MENU_EXEC); - m_pTargetDoc = pTarget; - m_strTargetName = strTargetName; + m_pTargetDoc = pTarget; + m_strTargetName = strTargetName; } -void CJS_EventHandler::OnExternal_Exec() -{ - Initial(JET_EXTERNAL_EXEC); +void CJS_EventHandler::OnExternal_Exec() { + Initial(JET_EXTERNAL_EXEC); } -void CJS_EventHandler::OnBatchExec(CPDFSDK_Document* pTarget) -{ - Initial(JET_BATCH_EXEC); +void CJS_EventHandler::OnBatchExec(CPDFSDK_Document* pTarget) { + Initial(JET_BATCH_EXEC); - m_pTargetDoc = pTarget; + m_pTargetDoc = pTarget; } -void CJS_EventHandler::OnConsole_Exec() -{ - Initial(JET_CONSOLE_EXEC); +void CJS_EventHandler::OnConsole_Exec() { + Initial(JET_CONSOLE_EXEC); } +void CJS_EventHandler::Initial(JS_EVENT_T type) { + m_eEventType = type; -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_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_pSourceDoc = NULL; + m_pTargetBookMark = NULL; + m_pTargetDoc = NULL; + m_pTargetAnnot = NULL; - m_bValid = TRUE; + m_bValid = TRUE; } -void CJS_EventHandler::Destroy() -{ - m_bValid = FALSE; +void CJS_EventHandler::Destroy() { + m_bValid = FALSE; } -FX_BOOL CJS_EventHandler::IsValid() -{ - return m_bValid; +FX_BOOL CJS_EventHandler::IsValid() { + return m_bValid; } -CFX_WideString & CJS_EventHandler::Change() -{ - if (m_pWideStrChange) { - return *m_pWideStrChange; - } - return m_WideStrChangeDu; +CFX_WideString& CJS_EventHandler::Change() { + if (m_pWideStrChange) { + return *m_pWideStrChange; + } + return m_WideStrChangeDu; } -CFX_WideString CJS_EventHandler::ChangeEx() -{ - return m_WideStrChangeEx; +CFX_WideString CJS_EventHandler::ChangeEx() { + return m_WideStrChangeEx; } -int CJS_EventHandler::CommitKey() -{ - return m_nCommitKey; +int CJS_EventHandler::CommitKey() { + return m_nCommitKey; } -FX_BOOL CJS_EventHandler::FieldFull() -{ - return m_bFieldFull; +FX_BOOL CJS_EventHandler::FieldFull() { + return m_bFieldFull; } -FX_BOOL CJS_EventHandler::KeyDown() -{ - return m_bKeyDown; +FX_BOOL CJS_EventHandler::KeyDown() { + return m_bKeyDown; } -FX_BOOL CJS_EventHandler::Modifier() -{ - return m_bModifier; +FX_BOOL CJS_EventHandler::Modifier() { + return m_bModifier; } -const FX_WCHAR* CJS_EventHandler::Name() -{ - switch (m_eEventType) - { - case JET_APP_INIT: return L"Init"; - case JET_BATCH_EXEC: return L"Exec"; - case JET_BOOKMARK_MOUSEUP: return L"Mouse Up"; - case JET_CONSOLE_EXEC: return L"Exec"; - case JET_DOC_DIDPRINT: return L"DidPrint"; - case JET_DOC_DIDSAVE: return L"DidSave"; - case JET_DOC_OPEN: return L"Open"; - case JET_DOC_WILLCLOSE: return L"WillClose"; - case JET_DOC_WILLPRINT: return L"WillPrint"; - case JET_DOC_WILLSAVE: return L"WillSave"; - case JET_EXTERNAL_EXEC: return L"Exec"; +const FX_WCHAR* CJS_EventHandler::Name() { + switch (m_eEventType) { + case JET_APP_INIT: + return L"Init"; + case JET_BATCH_EXEC: + return L"Exec"; + case JET_BOOKMARK_MOUSEUP: + return L"Mouse Up"; + case JET_CONSOLE_EXEC: + return L"Exec"; + case JET_DOC_DIDPRINT: + return L"DidPrint"; + case JET_DOC_DIDSAVE: + return L"DidSave"; + case JET_DOC_OPEN: + return L"Open"; + case JET_DOC_WILLCLOSE: + return L"WillClose"; + case JET_DOC_WILLPRINT: + return L"WillPrint"; + case JET_DOC_WILLSAVE: + return L"WillSave"; + case JET_EXTERNAL_EXEC: + return L"Exec"; case JET_FIELD_FOCUS: - case JET_SCREEN_FOCUS: return L"Focus"; + case JET_SCREEN_FOCUS: + return L"Focus"; case JET_FIELD_BLUR: - case JET_SCREEN_BLUR: return L"Blur"; + case JET_SCREEN_BLUR: + return L"Blur"; case JET_FIELD_MOUSEDOWN: - case JET_SCREEN_MOUSEDOWN: return L"Mouse Down"; + case JET_SCREEN_MOUSEDOWN: + return L"Mouse Down"; case JET_FIELD_MOUSEUP: - case JET_SCREEN_MOUSEUP: return L"Mouse Up"; + case JET_SCREEN_MOUSEUP: + return L"Mouse Up"; case JET_FIELD_MOUSEENTER: - case JET_SCREEN_MOUSEENTER: return L"Mouse Enter"; + case JET_SCREEN_MOUSEENTER: + return L"Mouse Enter"; case JET_FIELD_MOUSEEXIT: - case JET_SCREEN_MOUSEEXIT: return L"Mouse Exit"; - case JET_FIELD_CALCULATE: return L"Calculate"; - case JET_FIELD_FORMAT: return L"Format"; - case JET_FIELD_KEYSTROKE: return L"Keystroke"; - case JET_FIELD_VALIDATE: return L"Validate"; - case JET_LINK_MOUSEUP: return L"Mouse Up"; - case JET_MENU_EXEC: return L"Exec"; + case JET_SCREEN_MOUSEEXIT: + return L"Mouse Exit"; + case JET_FIELD_CALCULATE: + return L"Calculate"; + case JET_FIELD_FORMAT: + return L"Format"; + case JET_FIELD_KEYSTROKE: + return L"Keystroke"; + case JET_FIELD_VALIDATE: + return L"Validate"; + case JET_LINK_MOUSEUP: + return L"Mouse Up"; + case JET_MENU_EXEC: + return L"Exec"; case JET_PAGE_OPEN: - case JET_SCREEN_OPEN: return L"Open"; + case JET_SCREEN_OPEN: + return L"Open"; case JET_PAGE_CLOSE: - case JET_SCREEN_CLOSE: return L"Close"; + case JET_SCREEN_CLOSE: + return L"Close"; case JET_SCREEN_INVIEW: - case JET_PAGE_INVIEW: return L"InView"; + case JET_PAGE_INVIEW: + return L"InView"; case JET_PAGE_OUTVIEW: - case JET_SCREEN_OUTVIEW: return L"OutView"; + case JET_SCREEN_OUTVIEW: + return L"OutView"; default: - return L""; - } - - return L""; -} - -const FX_WCHAR* CJS_EventHandler::Type() -{ - switch (m_eEventType) - { - case JET_APP_INIT: return L"App"; - case JET_BATCH_EXEC: return L"Batch"; - case JET_BOOKMARK_MOUSEUP: return L"BookMark"; - case JET_CONSOLE_EXEC: return L"Console"; + return L""; + } + + return L""; +} + +const FX_WCHAR* CJS_EventHandler::Type() { + switch (m_eEventType) { + case JET_APP_INIT: + return L"App"; + case JET_BATCH_EXEC: + return L"Batch"; + case JET_BOOKMARK_MOUSEUP: + return L"BookMark"; + case JET_CONSOLE_EXEC: + return 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 L"Doc"; - case JET_EXTERNAL_EXEC: return L"External"; + case JET_DOC_WILLSAVE: + return L"Doc"; + case JET_EXTERNAL_EXEC: + return L"External"; case JET_FIELD_BLUR: case JET_FIELD_FOCUS: case JET_FIELD_MOUSEDOWN: @@ -531,7 +556,8 @@ const FX_WCHAR* CJS_EventHandler::Type() case JET_FIELD_CALCULATE: case JET_FIELD_FORMAT: case JET_FIELD_KEYSTROKE: - case JET_FIELD_VALIDATE: return L"Field"; + case JET_FIELD_VALIDATE: + return L"Field"; case JET_SCREEN_FOCUS: case JET_SCREEN_BLUR: case JET_SCREEN_OPEN: @@ -541,124 +567,123 @@ const FX_WCHAR* CJS_EventHandler::Type() case JET_SCREEN_MOUSEENTER: case JET_SCREEN_MOUSEEXIT: case JET_SCREEN_INVIEW: - case JET_SCREEN_OUTVIEW: return L"Screen"; - case JET_LINK_MOUSEUP: return L"Link"; - case JET_MENU_EXEC: return L"Menu"; + case JET_SCREEN_OUTVIEW: + return L"Screen"; + case JET_LINK_MOUSEUP: + return L"Link"; + case JET_MENU_EXEC: + return L"Menu"; case JET_PAGE_OPEN: case JET_PAGE_CLOSE: case JET_PAGE_INVIEW: - case JET_PAGE_OUTVIEW:return L"Page"; + case JET_PAGE_OUTVIEW: + return L"Page"; default: - return L""; - } + return L""; + } - return L""; + return L""; } -FX_BOOL& CJS_EventHandler::Rc() -{ - if (m_pbRc) { - return *m_pbRc; - } - return m_bRcDu; +FX_BOOL& CJS_EventHandler::Rc() { + if (m_pbRc) { + return *m_pbRc; + } + return m_bRcDu; } -int & CJS_EventHandler::SelEnd() -{ - if (m_pISelEnd) { - return *m_pISelEnd; - } - return m_nSelEndDu; +int& CJS_EventHandler::SelEnd() { + if (m_pISelEnd) { + return *m_pISelEnd; + } + return m_nSelEndDu; } -int & CJS_EventHandler::SelStart() -{ - if (m_pISelStart) { - return *m_pISelStart; - } - return m_nSelStartDu; +int& CJS_EventHandler::SelStart() { + if (m_pISelStart) { + return *m_pISelStart; + } + return m_nSelStartDu; } -FX_BOOL CJS_EventHandler::Shift() -{ - return m_bShift; +FX_BOOL CJS_EventHandler::Shift() { + return m_bShift; } -Field* CJS_EventHandler::Source() -{ - ASSERT(m_pJSContext != NULL); +Field* CJS_EventHandler::Source() { + ASSERT(m_pJSContext != NULL); - CJS_Runtime* pRuntime = m_pJSContext->GetJSRuntime(); + 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); + 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_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; + // 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); +Field* CJS_EventHandler::Target_Field() { + ASSERT(m_pJSContext != NULL); - CJS_Runtime* pRuntime = m_pJSContext->GetJSRuntime(); + 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); + 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_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); + CJS_Field* pJSField = (CJS_Field*)JS_GetPrivate(pFieldObj); + ASSERT(pJSField != NULL); - Field* pField = (Field *)pJSField->GetEmbedObject(); - ASSERT(pField != NULL); + Field* pField = (Field*)pJSField->GetEmbedObject(); + ASSERT(pField != NULL); - pField->AttachField(pDocument, m_strTargetName); - return pField; + pField->AttachField(pDocument, m_strTargetName); + return pField; } -CFX_WideString& CJS_EventHandler::Value() -{ - return *m_pValue; +CFX_WideString& CJS_EventHandler::Value() { + return *m_pValue; } -FX_BOOL CJS_EventHandler::WillCommit() -{ - return m_bWillCommit; +FX_BOOL CJS_EventHandler::WillCommit() { + return m_bWillCommit; } -CFX_WideString CJS_EventHandler::TargetName() -{ - return m_strTargetName; +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 8c7bd7150e..9f954acee5 100644 --- a/fpdfsdk/src/javascript/JS_GlobalData.cpp +++ b/fpdfsdk/src/javascript/JS_GlobalData.cpp @@ -9,449 +9,393 @@ #include "../../include/javascript/IJavaScript.h" #include "../../include/javascript/JS_GlobalData.h" -#define JS_MAXGLOBALDATA (1024 * 4 - 8) +#define JS_MAXGLOBALDATA (1024 * 4 - 8) /* --------------------- CJS_GlobalVariableArray --------------------- */ -CJS_GlobalVariableArray::CJS_GlobalVariableArray() -{ -} +CJS_GlobalVariableArray::CJS_GlobalVariableArray() {} -CJS_GlobalVariableArray::~CJS_GlobalVariableArray() -{ - Empty(); +CJS_GlobalVariableArray::~CJS_GlobalVariableArray() { + Empty(); } -void CJS_GlobalVariableArray::Copy(const CJS_GlobalVariableArray& array) -{ - Empty(); - for (int i=0,sz=array.Count(); inType) - { - 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::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); +void CJS_GlobalVariableArray::Add(CJS_KeyValue* p) { + array.Add(p); } -int CJS_GlobalVariableArray::Count() const -{ - return array.GetSize(); +int CJS_GlobalVariableArray::Count() const { + return array.GetSize(); } -CJS_KeyValue* CJS_GlobalVariableArray::GetAt(int index) const -{ - return array.GetAt(index); +CJS_KeyValue* CJS_GlobalVariableArray::GetAt(int index) const { + return array.GetAt(index); } -void CJS_GlobalVariableArray::Empty() -{ - for (int i=0,sz=array.GetSize(); iGetUserPath(); - m_sFilePath += SDK_JS_GLOBALDATA_FILENAME; - - LoadGlobalPersistentVariables(); +#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 uint8_t 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) { + // 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(); +CJS_GlobalData::~CJS_GlobalData() { + SaveGlobalPersisitentVariables(); - for (int i=0,sz=m_arrayGlobalData.GetSize(); idata.sKey[0] == *propname && pTemp->data.sKey == propname) - { - nRet = i; - break; - } + 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; + return nRet; } -CJS_GlobalData_Element* CJS_GlobalData::GetGlobalVariable(const FX_CHAR* propname) -{ - ASSERT(propname != NULL); +CJS_GlobalData_Element* CJS_GlobalData::GetGlobalVariable( + const FX_CHAR* propname) { + ASSERT(propname != NULL); - int nFind = FindGlobalVariable(propname); - if (nFind >= 0) - return m_arrayGlobalData.GetAt(nFind); + int nFind = FindGlobalVariable(propname); + if (nFind >= 0) + return m_arrayGlobalData.GetAt(nFind); - return NULL; + return NULL; } -void CJS_GlobalData::SetGlobalVariableNumber(const FX_CHAR* 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::SetGlobalVariableNumber(const FX_CHAR* 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(const FX_CHAR* propname, bool bData) -{ - ASSERT(propname != NULL); - CFX_ByteString sPropName = propname; +void CJS_GlobalData::SetGlobalVariableBoolean(const FX_CHAR* propname, + bool bData) { + ASSERT(propname != NULL); + CFX_ByteString sPropName = propname; - sPropName.TrimLeft(); - sPropName.TrimRight(); + sPropName.TrimLeft(); + sPropName.TrimRight(); - if (sPropName.GetLength() == 0) return; + 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(const FX_CHAR* propname, const CFX_ByteString& sData) -{ - ASSERT(propname != NULL); - CFX_ByteString sPropName = propname; + 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; - sPropName.TrimLeft(); - sPropName.TrimRight(); + m_arrayGlobalData.Add(pNewData); + } +} - if (sPropName.GetLength() == 0) return; +void CJS_GlobalData::SetGlobalVariableString(const FX_CHAR* propname, + const CFX_ByteString& sData) { + ASSERT(propname != NULL); + CFX_ByteString sPropName = propname; - 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); - } -} + sPropName.TrimLeft(); + sPropName.TrimRight(); -void CJS_GlobalData::SetGlobalVariableObject(const FX_CHAR* propname, const CJS_GlobalVariableArray& array) -{ - ASSERT(propname != NULL); - CFX_ByteString sPropName = propname; + if (sPropName.GetLength() == 0) + return; - sPropName.TrimLeft(); - sPropName.TrimRight(); + 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; - if (sPropName.GetLength() == 0) return; + m_arrayGlobalData.Add(pNewData); + } +} - 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::SetGlobalVariableObject( + const FX_CHAR* 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(const FX_CHAR* propname) -{ - ASSERT(propname != NULL); - CFX_ByteString sPropName = propname; +void CJS_GlobalData::SetGlobalVariableNull(const FX_CHAR* propname) { + ASSERT(propname != NULL); + CFX_ByteString sPropName = propname; - sPropName.TrimLeft(); - sPropName.TrimRight(); + sPropName.TrimLeft(); + sPropName.TrimRight(); - if (sPropName.GetLength() == 0) return; + 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; + 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); - } + m_arrayGlobalData.Add(pNewData); + } } -FX_BOOL CJS_GlobalData::SetGlobalVariablePersistent(const FX_CHAR* propname, FX_BOOL bPersistent) -{ - ASSERT(propname != NULL); - CFX_ByteString sPropName = propname; +FX_BOOL CJS_GlobalData::SetGlobalVariablePersistent(const FX_CHAR* propname, + FX_BOOL bPersistent) { + ASSERT(propname != NULL); + CFX_ByteString sPropName = propname; - sPropName.TrimLeft(); - sPropName.TrimRight(); + sPropName.TrimLeft(); + sPropName.TrimRight(); - if (sPropName.GetLength() == 0) return FALSE; + if (sPropName.GetLength() == 0) + return FALSE; - if (CJS_GlobalData_Element* pData = GetGlobalVariable(sPropName)) - { - pData->bPersistent = bPersistent; - return TRUE; - } + if (CJS_GlobalData_Element* pData = GetGlobalVariable(sPropName)) { + pData->bPersistent = bPersistent; + return TRUE; + } - return FALSE; + return FALSE; } -FX_BOOL CJS_GlobalData::DeleteGlobalVariable(const FX_CHAR* propname) -{ - ASSERT(propname != NULL); - CFX_ByteString sPropName = propname; +FX_BOOL CJS_GlobalData::DeleteGlobalVariable(const FX_CHAR* propname) { + ASSERT(propname != NULL); + CFX_ByteString sPropName = propname; - sPropName.TrimLeft(); - sPropName.TrimRight(); + sPropName.TrimLeft(); + sPropName.TrimRight(); - if (sPropName.GetLength() == 0) return FALSE; + if (sPropName.GetLength() == 0) + return FALSE; - int nFind = FindGlobalVariable(sPropName); + int nFind = FindGlobalVariable(sPropName); - if (nFind >= 0) - { - delete m_arrayGlobalData.GetAt(nFind); - m_arrayGlobalData.RemoveAt(nFind); - return TRUE; - } + if (nFind >= 0) { + delete m_arrayGlobalData.GetAt(nFind); + m_arrayGlobalData.RemoveAt(nFind); + return TRUE; + } - return FALSE; + return FALSE; } -int32_t CJS_GlobalData::GetSize() const -{ - return m_arrayGlobalData.GetSize(); +int32_t CJS_GlobalData::GetSize() const { + return m_arrayGlobalData.GetSize(); } -CJS_GlobalData_Element* CJS_GlobalData::GetAt(int index) const -{ - return m_arrayGlobalData.GetAt(index); +CJS_GlobalData_Element* CJS_GlobalData::GetAt(int index) const { + return m_arrayGlobalData.GetAt(index); } -void CJS_GlobalData::LoadGlobalPersistentVariables() -{ - uint8_t* pBuffer = NULL; - int32_t nLength = 0; - - LoadFileBuffer(m_sFilePath.c_str(), pBuffer, nLength); - CRYPT_ArcFourCryptBlock(pBuffer, nLength, JS_RC4KEY, sizeof(JS_RC4KEY)); - - if (pBuffer) - { - uint8_t* 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 (int32_t i=0,sz=dwCount; i 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); - } - } - } +void CJS_GlobalData::LoadGlobalPersistentVariables() { + uint8_t* pBuffer = NULL; + int32_t nLength = 0; + + LoadFileBuffer(m_sFilePath.c_str(), pBuffer, nLength); + CRYPT_ArcFourCryptBlock(pBuffer, nLength, JS_RC4KEY, sizeof(JS_RC4KEY)); + + if (pBuffer) { + uint8_t* 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 (int32_t 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); + } } + FX_Free(pBuffer); + } } /* @@ -471,104 +415,96 @@ struct js_global_datafile_data }; */ -void CJS_GlobalData::SaveGlobalPersisitentVariables() -{ - FX_DWORD nCount = 0; - CFX_BinaryBuf sData; +void CJS_GlobalData::SaveGlobalPersisitentVariables() { + FX_DWORD nCount = 0; + CFX_BinaryBuf sData; - for (int i=0,sz=m_arrayGlobalData.GetSize(); ibPersistent) - { - CFX_BinaryBuf sElement; - MakeByteString(pElement->data.sKey, &pElement->data, sElement); + if (pElement->bPersistent) { + CFX_BinaryBuf sElement; + MakeByteString(pElement->data.sKey, &pElement->data, sElement); - if (sData.GetSize() + sElement.GetSize() > JS_MAXGLOBALDATA) - break; + if (sData.GetSize() + sElement.GetSize() > JS_MAXGLOBALDATA) + break; - sData.AppendBlock(sElement.GetBuffer(), sElement.GetSize()); - nCount++; - } + sData.AppendBlock(sElement.GetBuffer(), sElement.GetSize()); + nCount++; } + } - CFX_BinaryBuf sFile; + 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)); + 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()); + sFile.AppendBlock(sData.GetBuffer(), sData.GetSize()); - CRYPT_ArcFourCryptBlock(sFile.GetBuffer(), sFile.GetSize(), JS_RC4KEY, sizeof(JS_RC4KEY)); - WriteFileBuffer(m_sFilePath.c_str(), (const FX_CHAR*)sFile.GetBuffer(), sFile.GetSize()); + CRYPT_ArcFourCryptBlock(sFile.GetBuffer(), sFile.GetSize(), JS_RC4KEY, + sizeof(JS_RC4KEY)); + WriteFileBuffer(m_sFilePath.c_str(), (const FX_CHAR*)sFile.GetBuffer(), + sFile.GetSize()); } -void CJS_GlobalData::LoadFileBuffer(const FX_WCHAR* sFilePath, uint8_t*& pBuffer, int32_t& nLength) -{ -//UnSupport. +void CJS_GlobalData::LoadFileBuffer(const FX_WCHAR* sFilePath, + uint8_t*& pBuffer, + int32_t& nLength) { + // UnSupport. } -void CJS_GlobalData::WriteFileBuffer(const FX_WCHAR* sFilePath, const FX_CHAR* pBuffer, int32_t nLength) -{ -//UnSupport. +void CJS_GlobalData::WriteFileBuffer(const FX_WCHAR* sFilePath, + const FX_CHAR* pBuffer, + int32_t nLength) { + // UnSupport. } -void CJS_GlobalData::MakeByteString(const CFX_ByteString& name, CJS_KeyValue* pData, CFX_BinaryBuf& sData) -{ - 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; +void CJS_GlobalData::MakeByteString(const CFX_ByteString& name, + CJS_KeyValue* pData, + CFX_BinaryBuf& sData) { + 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; - } + break; + } } - diff --git a/fpdfsdk/src/javascript/JS_Object.cpp b/fpdfsdk/src/javascript/JS_Object.cpp index 7a1b150ad8..eb089ed563 100644 --- a/fpdfsdk/src/javascript/JS_Object.cpp +++ b/fpdfsdk/src/javascript/JS_Object.cpp @@ -10,137 +10,130 @@ #include "../../include/javascript/JS_Object.h" #include "../../include/javascript/JS_Context.h" -JS_TIMER_MAPARRAY& GetTimeMap() -{ +JS_TIMER_MAPARRAY& GetTimeMap() { // Leak the timer array at shutdown. static auto* timeMap = new JS_TIMER_MAPARRAY; return *timeMap; } -int FXJS_MsgBox(CPDFDoc_Environment* pApp, CPDFSDK_PageView* pPageView, const FX_WCHAR* swMsg, const FX_WCHAR* swTitle, FX_UINT nType, FX_UINT nIcon) -{ - if (!pApp) - return 0; +int FXJS_MsgBox(CPDFDoc_Environment* pApp, + CPDFSDK_PageView* pPageView, + const FX_WCHAR* swMsg, + const FX_WCHAR* swTitle, + FX_UINT nType, + FX_UINT nIcon) { + if (!pApp) + return 0; - if (CPDFSDK_Document* pDoc = pApp->GetSDKDocument()) - pDoc->KillFocusAnnot(); + if (CPDFSDK_Document* pDoc = pApp->GetSDKDocument()) + pDoc->KillFocusAnnot(); - return pApp->JS_appAlert(swMsg, swTitle, nType, nIcon); + return pApp->JS_appAlert(swMsg, swTitle, nType, nIcon); } -CPDFSDK_PageView* FXJS_GetPageView(IFXJS_Context* cc) -{ - if (CJS_Context* pContext = (CJS_Context *)cc) - { - if (pContext->GetReaderDocument()) - return NULL; - } - return NULL; +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_EmbedObj(CJS_Object* pJSObject) : - m_pJSObject(pJSObject) -{ -} - -CJS_EmbedObj::~CJS_EmbedObj() -{ - m_pJSObject = NULL; +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); +CPDFSDK_PageView* CJS_EmbedObj::JSGetPageView(IFXJS_Context* cc) { + return FXJS_GetPageView(cc); } -int CJS_EmbedObj::MsgBox(CPDFDoc_Environment* pApp, CPDFSDK_PageView* pPageView,const FX_WCHAR* swMsg,const FX_WCHAR* swTitle,FX_UINT nType,FX_UINT nIcon) -{ - return FXJS_MsgBox(pApp, pPageView, swMsg, swTitle, nType, nIcon); +int CJS_EmbedObj::MsgBox(CPDFDoc_Environment* pApp, + CPDFSDK_PageView* pPageView, + const FX_WCHAR* swMsg, + const FX_WCHAR* swTitle, + FX_UINT nType, + FX_UINT nIcon) { + return FXJS_MsgBox(pApp, pPageView, swMsg, swTitle, nType, nIcon); } -void CJS_EmbedObj::Alert(CJS_Context* pContext, const FX_WCHAR* swMsg) -{ - CJS_Object::Alert(pContext, swMsg); +void CJS_EmbedObj::Alert(CJS_Context* pContext, const FX_WCHAR* 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); +CJS_Timer* CJS_EmbedObj::BeginTimer(CPDFDoc_Environment* pApp, + FX_UINT nElapse) { + CJS_Timer* pTimer = new CJS_Timer(this, pApp); + pTimer->SetJSTimer(nElapse); - return pTimer; + return pTimer; } -void CJS_EmbedObj::EndTimer(CJS_Timer* pTimer) -{ - ASSERT(pTimer != NULL); - pTimer->KillJSTimer(); - delete pTimer; +void CJS_EmbedObj::EndTimer(CJS_Timer* pTimer) { + ASSERT(pTimer != NULL); + pTimer->KillJSTimer(); + delete pTimer; } -/* --------------------------------- CJS_Object --------------------------------- */ -void FreeObject(const v8::WeakCallbackInfo& data) -{ - CJS_Object* pJSObj = data.GetParameter(); - pJSObj->ExitInstance(); - delete pJSObj; - JS_FreePrivate(data.GetInternalField(0)); +/* --------------------------------- CJS_Object + * --------------------------------- */ +void FreeObject(const v8::WeakCallbackInfo& data) { + CJS_Object* pJSObj = data.GetParameter(); + pJSObj->ExitInstance(); + delete pJSObj; + JS_FreePrivate(data.GetInternalField(0)); } -void DisposeObject(const v8::WeakCallbackInfo& data) -{ - CJS_Object* pJSObj = data.GetParameter(); - pJSObj->Dispose(); - data.SetSecondPassCallback(FreeObject); +void DisposeObject(const v8::WeakCallbackInfo& data) { + CJS_Object* pJSObj = data.GetParameter(); + pJSObj->Dispose(); + data.SetSecondPassCallback(FreeObject); } -CJS_Object::CJS_Object(JSFXObject pObject) :m_pEmbedObj(NULL) -{ - v8::Local context = pObject->CreationContext(); - m_pIsolate = context->GetIsolate(); - m_pObject.Reset(m_pIsolate, pObject); +CJS_Object::CJS_Object(JSFXObject pObject) : m_pEmbedObj(NULL) { + v8::Local context = pObject->CreationContext(); + m_pIsolate = context->GetIsolate(); + m_pObject.Reset(m_pIsolate, pObject); }; -CJS_Object::~CJS_Object(void) -{ - delete m_pEmbedObj; - m_pEmbedObj = NULL; +CJS_Object::~CJS_Object(void) { + delete m_pEmbedObj; + m_pEmbedObj = NULL; - m_pObject.Reset(); + m_pObject.Reset(); }; -void CJS_Object::MakeWeak() -{ - m_pObject.SetWeak( - this, DisposeObject, v8::WeakCallbackType::kInternalFields); +void CJS_Object::MakeWeak() { + m_pObject.SetWeak(this, DisposeObject, v8::WeakCallbackType::kInternalFields); } -void CJS_Object::Dispose() -{ - m_pObject.Reset(); +void CJS_Object::Dispose() { + m_pObject.Reset(); } -CPDFSDK_PageView* CJS_Object::JSGetPageView(IFXJS_Context* cc) -{ - return FXJS_GetPageView(cc); +CPDFSDK_PageView* CJS_Object::JSGetPageView(IFXJS_Context* cc) { + return FXJS_GetPageView(cc); } -int CJS_Object::MsgBox(CPDFDoc_Environment* pApp, CPDFSDK_PageView* pPageView, const FX_WCHAR* swMsg, const FX_WCHAR* swTitle, FX_UINT nType, FX_UINT nIcon) -{ - return FXJS_MsgBox(pApp, pPageView, swMsg, swTitle, nType, nIcon); +int CJS_Object::MsgBox(CPDFDoc_Environment* pApp, + CPDFSDK_PageView* pPageView, + const FX_WCHAR* swMsg, + const FX_WCHAR* swTitle, + FX_UINT nType, + FX_UINT nIcon) { + return FXJS_MsgBox(pApp, pPageView, swMsg, swTitle, nType, nIcon); } -void CJS_Object::Alert(CJS_Context* pContext, const FX_WCHAR* swMsg) -{ - ASSERT(pContext != NULL); +void CJS_Object::Alert(CJS_Context* pContext, const FX_WCHAR* swMsg) { + ASSERT(pContext != NULL); - if (pContext->IsMsgBoxEnabled()) - { - CPDFDoc_Environment* pApp = pContext->GetReaderApp(); - if(pApp) - pApp->JS_appAlert(swMsg, NULL, 0, 3); - } + 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 485cd27813..08cd87c768 100644 --- a/fpdfsdk/src/javascript/JS_Runtime.cpp +++ b/fpdfsdk/src/javascript/JS_Runtime.cpp @@ -27,320 +27,308 @@ #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) - { - unsigned int embedderDataSlot = 0; - if (pApp->GetFormFillInfo()->m_pJsPlatform->version >= 2) { - embedderDataSlot = pApp->GetFormFillInfo()->m_pJsPlatform->m_v8EmbedderSlot; - } - JS_Initial(embedderDataSlot); - m_bInit = TRUE; +CJS_RuntimeFactory::~CJS_RuntimeFactory() {} + +IFXJS_Runtime* CJS_RuntimeFactory::NewJSRuntime(CPDFDoc_Environment* pApp) { + if (!m_bInit) { + unsigned int embedderDataSlot = 0; + if (pApp->GetFormFillInfo()->m_pJsPlatform->version >= 2) { + embedderDataSlot = + pApp->GetFormFillInfo()->m_pJsPlatform->m_v8EmbedderSlot; } - return new CJS_Runtime(pApp); + JS_Initial(embedderDataSlot); + 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::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::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) -{ - delete (CJS_Runtime*)pRuntime; +void CJS_RuntimeFactory::DeleteJSRuntime(IFXJS_Runtime* pRuntime) { + delete (CJS_Runtime*)pRuntime; } -CJS_GlobalData* CJS_RuntimeFactory::NewGlobalData(CPDFDoc_Environment* pApp) -{ - if (m_pGlobalData) - { - m_nGlobalDataCount++; - return m_pGlobalData; - } - m_nGlobalDataCount = 1; - m_pGlobalData = new CJS_GlobalData(pApp); +CJS_GlobalData* CJS_RuntimeFactory::NewGlobalData(CPDFDoc_Environment* pApp) { + if (m_pGlobalData) { + m_nGlobalDataCount++; return m_pGlobalData; + } + m_nGlobalDataCount = 1; + m_pGlobalData = new CJS_GlobalData(pApp); + return m_pGlobalData; } -void CJS_RuntimeFactory::ReleaseGlobalData() -{ - m_nGlobalDataCount--; +void CJS_RuntimeFactory::ReleaseGlobalData() { + m_nGlobalDataCount--; - if (m_nGlobalDataCount <= 0) - { - delete m_pGlobalData; - m_pGlobalData = NULL; - } + if (m_nGlobalDataCount <= 0) { + delete m_pGlobalData; + m_pGlobalData = NULL; + } } void* CJS_ArrayBufferAllocator::Allocate(size_t length) { - return calloc(1, length); + return calloc(1, length); } void* CJS_ArrayBufferAllocator::AllocateUninitialized(size_t length) { - return malloc(length); + return malloc(length); } void CJS_ArrayBufferAllocator::Free(void* data, size_t length) { - free(data); + free(data); } /* ------------------------------ CJS_Runtime ------------------------------ */ -CJS_Runtime::CJS_Runtime(CPDFDoc_Environment * pApp) : - m_pApp(pApp), - m_pDocument(NULL), - m_bBlocking(FALSE), - m_pFieldEventPath(NULL), - m_isolate(NULL) -{ - if (m_pApp->GetFormFillInfo()->m_pJsPlatform->version >= 2) { - m_isolate = reinterpret_cast(m_pApp->GetFormFillInfo()->m_pJsPlatform->m_isolate); - } - if (!m_isolate) { - m_pArrayBufferAllocator.reset(new CJS_ArrayBufferAllocator()); - - v8::Isolate::CreateParams params; - params.array_buffer_allocator = m_pArrayBufferAllocator.get(); - m_isolate = v8::Isolate::New(params); - } - - InitJSObjects(); - - CJS_Context * pContext = (CJS_Context*)NewContext(); - JS_InitialRuntime(*this, this, pContext, m_context); - ReleaseContext(pContext); +CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp) + : m_pApp(pApp), + m_pDocument(NULL), + m_bBlocking(FALSE), + m_pFieldEventPath(NULL), + m_isolate(NULL) { + if (m_pApp->GetFormFillInfo()->m_pJsPlatform->version >= 2) { + m_isolate = reinterpret_cast( + m_pApp->GetFormFillInfo()->m_pJsPlatform->m_isolate); + } + if (!m_isolate) { + m_pArrayBufferAllocator.reset(new CJS_ArrayBufferAllocator()); + + v8::Isolate::CreateParams params; + params.array_buffer_allocator = m_pArrayBufferAllocator.get(); + m_isolate = v8::Isolate::New(params); + } + + 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(); iExit(); - m_isolate->Dispose(); + // m_isolate->Exit(); + m_isolate->Dispose(); } -FX_BOOL CJS_Runtime::InitJSObjects() -{ - v8::Isolate::Scope isolate_scope(GetIsolate()); - v8::HandleScope handle_scope(GetIsolate()); - v8::Local 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; +FX_BOOL CJS_Runtime::InitJSObjects() { + v8::Isolate::Scope isolate_scope(GetIsolate()); + v8::HandleScope handle_scope(GetIsolate()); + v8::Local 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; +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 context =v8::Local::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")); +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 context = + v8::Local::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; +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; - } + 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; + // 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; - } + pLast = p; + p = p->pNext; + } - //to add - CJS_FieldEvent* pNew = new CJS_FieldEvent; - pNew->sTargetName = sTargetName; - pNew->eEventType = eEventType; - pNew->pNext = NULL; + // to add + CJS_FieldEvent* pNew = new CJS_FieldEvent; + pNew->sTargetName = sTargetName; + pNew->eEventType = eEventType; + pNew->pNext = NULL; - pLast->pNext = pNew; + pLast->pNext = pNew; - return TRUE; + 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; - } +void CJS_Runtime::RemoveEventInLoop(const CFX_WideString& sTargetName, + JS_EVENT_T eEventType) { + FX_BOOL bFind = FALSE; - pLast = p; - p = p->pNext; + CJS_FieldEvent* p = m_pFieldEventPath; + CJS_FieldEvent* pLast = NULL; + while (p) { + if (p->eEventType == eEventType && p->sTargetName == sTargetName) { + bFind = TRUE; + break; } - if (bFind) - { - RemoveEventsInLoop(p); + pLast = p; + p = p->pNext; + } - if (p == m_pFieldEventPath) - m_pFieldEventPath = NULL; + if (bFind) { + RemoveEventsInLoop(p); - if (pLast) - pLast->pNext = NULL; - } + if (p == m_pFieldEventPath) + m_pFieldEventPath = NULL; + + if (pLast) + pLast->pNext = NULL; + } } -void CJS_Runtime::RemoveEventsInLoop(CJS_FieldEvent* pStart) -{ - CJS_FieldEvent* p = pStart; +void CJS_Runtime::RemoveEventsInLoop(CJS_FieldEvent* pStart) { + CJS_FieldEvent* p = pStart; - while (p) - { - CJS_FieldEvent* pOld = p; - p = pOld->pNext; + while (p) { + CJS_FieldEvent* pOld = p; + p = pOld->pNext; - delete pOld; - } + delete pOld; + } } -v8::Local CJS_Runtime::NewJSContext() -{ - return v8::Local::New(m_isolate, m_context); +v8::Local CJS_Runtime::NewJSContext() { + return v8::Local::New(m_isolate, m_context); } -CFX_WideString ChangeObjName(const CFX_WideString& str) -{ - CFX_WideString sRet = str; - sRet.Replace(L"_", L"."); - return sRet; +CFX_WideString ChangeObjName(const CFX_WideString& str) { + CFX_WideString sRet = str; + sRet.Replace(L"_", L"."); + return sRet; } diff --git a/fpdfsdk/src/javascript/JS_Value.cpp b/fpdfsdk/src/javascript/JS_Value.cpp index 058f2eaf45..faa1eeb6fc 100644 --- a/fpdfsdk/src/javascript/JS_Value.cpp +++ b/fpdfsdk/src/javascript/JS_Value.cpp @@ -12,651 +12,577 @@ /* ---------------------------- CJS_Value ---------------------------- */ -CJS_Value::CJS_Value(v8::Isolate* isolate) : m_eType(VT_unknown),m_isolate(isolate) -{ -} -CJS_Value::CJS_Value(v8::Isolate* isolate, v8::Local pValue,FXJSVALUETYPE t) : - m_pValue(pValue), m_eType(t), m_isolate(isolate) -{ -} +CJS_Value::CJS_Value(v8::Isolate* isolate) + : m_eType(VT_unknown), m_isolate(isolate) {} +CJS_Value::CJS_Value(v8::Isolate* isolate, + v8::Local pValue, + FXJSVALUETYPE t) + : m_pValue(pValue), m_eType(t), m_isolate(isolate) {} -CJS_Value::CJS_Value(v8::Isolate* isolate, const int &iValue):m_isolate(isolate) -{ - operator =(iValue); +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 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 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, 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, 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, CJS_Object* pJsObj) + : m_isolate(isolate) { + operator=(pJsObj); } -CJS_Value::CJS_Value(v8::Isolate* isolate, CJS_Document* pJsDoc):m_isolate(isolate) -{ - m_eType = VT_object; - if (pJsDoc) - m_pValue = (JSFXObject)*pJsDoc; +CJS_Value::CJS_Value(v8::Isolate* isolate, CJS_Document* pJsDoc) + : m_isolate(isolate) { + m_eType = VT_object; + if (pJsDoc) + m_pValue = (JSFXObject)*pJsDoc; } -CJS_Value::CJS_Value(v8::Isolate* isolate, const FX_WCHAR* pWstr):m_isolate(isolate) -{ - operator =(pWstr); +CJS_Value::CJS_Value(v8::Isolate* isolate, const FX_WCHAR* pWstr) + : m_isolate(isolate) { + operator=(pWstr); } -CJS_Value::CJS_Value(v8::Isolate* isolate, const FX_CHAR* pStr):m_isolate(isolate) -{ - operator = (pStr); +CJS_Value::CJS_Value(v8::Isolate* isolate, const FX_CHAR* 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(v8::Isolate* isolate, CJS_Array& array) + : m_isolate(isolate) { + operator=(array); } -CJS_Value::~CJS_Value() -{ -} +CJS_Value::~CJS_Value() {} -void CJS_Value::Attach(v8::Local pValue,FXJSVALUETYPE t) -{ - m_pValue = pValue; - m_eType = t; +void CJS_Value::Attach(v8::Local pValue, FXJSVALUETYPE t) { + m_pValue = pValue; + m_eType = t; } -void CJS_Value::Attach(CJS_Value *pValue) -{ - if (pValue) - Attach(pValue->ToV8Value(), pValue->GetType()); +void CJS_Value::Attach(CJS_Value* pValue) { + if (pValue) + Attach(pValue->ToV8Value(), pValue->GetType()); } -void CJS_Value::Detach() -{ - m_pValue = v8::Local(); - m_eType = VT_unknown; +void CJS_Value::Detach() { + m_pValue = v8::Local(); + m_eType = VT_unknown; } -/* ---------------------------------------------------------------------------------------- */ +/* ---------------------------------------------------------------------------------------- + */ -int CJS_Value::ToInt() const -{ - return JS_ToInt32(m_isolate, m_pValue); +int CJS_Value::ToInt() const { + return JS_ToInt32(m_isolate, m_pValue); } -bool CJS_Value::ToBool() const -{ - return JS_ToBoolean(m_isolate, m_pValue); +bool CJS_Value::ToBool() const { + return JS_ToBoolean(m_isolate, m_pValue); } -double CJS_Value::ToDouble() const -{ - return JS_ToNumber(m_isolate, m_pValue); +double CJS_Value::ToDouble() const { + return JS_ToNumber(m_isolate, m_pValue); } -float CJS_Value::ToFloat() const -{ - return (float)ToDouble(); +float CJS_Value::ToFloat() const { + return (float)ToDouble(); } -CJS_Object* CJS_Value::ToCJSObject() const -{ - v8::Local pObj = JS_ToObject(m_isolate, m_pValue); - return (CJS_Object*)JS_GetPrivate(m_isolate, pObj); +CJS_Object* CJS_Value::ToCJSObject() const { + v8::Local pObj = JS_ToObject(m_isolate, m_pValue); + return (CJS_Object*)JS_GetPrivate(m_isolate, pObj); } -v8::Local CJS_Value::ToV8Object() const -{ - return JS_ToObject(m_isolate, m_pValue); +v8::Local CJS_Value::ToV8Object() const { + return JS_ToObject(m_isolate, m_pValue); } -CFX_WideString CJS_Value::ToCFXWideString() const -{ - return JS_ToString(m_isolate, m_pValue); +CFX_WideString CJS_Value::ToCFXWideString() const { + return JS_ToString(m_isolate, m_pValue); } -CFX_ByteString CJS_Value::ToCFXByteString() const -{ - return CFX_ByteString::FromUnicode(ToCFXWideString()); +CFX_ByteString CJS_Value::ToCFXByteString() const { + return CFX_ByteString::FromUnicode(ToCFXWideString()); } -v8::Local CJS_Value::ToV8Value() const -{ - return m_pValue; +v8::Local CJS_Value::ToV8Value() const { + return m_pValue; } -v8::LocalCJS_Value::ToV8Array() const -{ - if (IsArrayObject()) - return v8::Local::Cast(JS_ToObject(m_isolate, m_pValue)); - return v8::Local(); +v8::Local CJS_Value::ToV8Array() const { + if (IsArrayObject()) + return v8::Local::Cast(JS_ToObject(m_isolate, m_pValue)); + return v8::Local(); } -/* ---------------------------------------------------------------------------------------- */ +/* ---------------------------------------------------------------------------------------- + */ -void CJS_Value::operator =(int iValue) -{ - m_pValue = JS_NewNumber(m_isolate, iValue); +void CJS_Value::operator=(int iValue) { + m_pValue = JS_NewNumber(m_isolate, iValue); - m_eType = VT_number; + m_eType = VT_number; } -void CJS_Value::operator =(bool bValue) -{ - m_pValue = JS_NewBoolean(m_isolate, bValue); +void CJS_Value::operator=(bool bValue) { + m_pValue = JS_NewBoolean(m_isolate, bValue); - m_eType = VT_boolean; + m_eType = VT_boolean; } -void CJS_Value::operator =(double dValue) -{ - m_pValue = JS_NewNumber(m_isolate,dValue); +void CJS_Value::operator=(double dValue) { + m_pValue = JS_NewNumber(m_isolate, dValue); - m_eType = VT_number; + 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=(float fValue) { + m_pValue = JS_NewNumber(m_isolate, fValue); + m_eType = VT_number; } -void CJS_Value::operator =(v8::Local pObj) -{ +void CJS_Value::operator=(v8::Local pObj) { + m_pValue = JS_NewObject(m_isolate, pObj); - m_pValue = JS_NewObject(m_isolate,pObj); - - m_eType = VT_fxobject; + m_eType = VT_fxobject; } -void CJS_Value::operator =(CJS_Object * pObj) -{ - if (pObj) - operator = ((JSFXObject)*pObj); +void CJS_Value::operator=(CJS_Object* pObj) { + if (pObj) + operator=((JSFXObject)*pObj); } -void CJS_Value::operator = (CJS_Document* pJsDoc) -{ - m_eType = VT_object; - if (pJsDoc) { - m_pValue = static_cast(*pJsDoc); - } +void CJS_Value::operator=(CJS_Document* pJsDoc) { + m_eType = VT_object; + if (pJsDoc) { + m_pValue = static_cast(*pJsDoc); + } } -void CJS_Value::operator =(const FX_WCHAR* pWstr) -{ - m_pValue = JS_NewString(m_isolate,(wchar_t *)pWstr); +void CJS_Value::operator=(const FX_WCHAR* pWstr) { + m_pValue = JS_NewString(m_isolate, (wchar_t*)pWstr); - m_eType = VT_string; + m_eType = VT_string; } -void CJS_Value::SetNull() -{ - m_pValue = JS_NewNull(); +void CJS_Value::SetNull() { + m_pValue = JS_NewNull(); - m_eType = VT_null; + m_eType = VT_null; } -void CJS_Value::operator = (const FX_CHAR* pStr) -{ - operator = (CFX_WideString::FromLocal(pStr).c_str()); +void CJS_Value::operator=(const FX_CHAR* pStr) { + operator=(CFX_WideString::FromLocal(pStr).c_str()); } -void CJS_Value::operator = (CJS_Array & array) -{ - m_pValue = JS_NewObject2(m_isolate,(v8::Local)array); +void CJS_Value::operator=(CJS_Array& array) { + m_pValue = JS_NewObject2(m_isolate, (v8::Local)array); - m_eType = VT_object; + m_eType = VT_object; } -void CJS_Value::operator = (CJS_Date & date) -{ - m_pValue = JS_NewDate(m_isolate, (double)date); +void CJS_Value::operator=(CJS_Date& date) { + m_pValue = JS_NewDate(m_isolate, (double)date); - m_eType = VT_date; + m_eType = VT_date; } -void CJS_Value::operator = (CJS_Value value) -{ - m_pValue = value.ToV8Value(); +void CJS_Value::operator=(CJS_Value value) { + m_pValue = value.ToV8Value(); - m_eType = value.m_eType; - m_isolate = value.m_isolate; + m_eType = value.m_eType; + m_isolate = value.m_isolate; } -/* ---------------------------------------------------------------------------------------- */ +/* ---------------------------------------------------------------------------------------- + */ -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; +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::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(); +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_isolate, m_pValue)); - return TRUE; - } +// CJS_Value::operator CJS_Array() +FX_BOOL CJS_Value::ConvertToArray(CJS_Array& array) const { + if (IsArrayObject()) { + array.Attach(JS_ToArray(m_isolate, m_pValue)); + return TRUE; + } - return FALSE; + return FALSE; } -FX_BOOL CJS_Value::ConvertToDate(CJS_Date &date) const -{ -// if (GetType() == VT_date) -// { -// date = (double)(*this); -// return TRUE; -// } +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; - } + if (IsDateObject()) { + date.Attach(m_pValue); + return TRUE; + } - return FALSE; + return FALSE; } /* ---------------------------- CJS_PropValue ---------------------------- */ -CJS_PropValue::CJS_PropValue(const CJS_Value &value) : - CJS_Value(value), - m_bIsSetting(0) -{ -} +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(v8::Isolate* isolate) + : CJS_Value(isolate), m_bIsSetting(0) {} -CJS_PropValue::~CJS_PropValue() -{ -} +CJS_PropValue::~CJS_PropValue() {} -FX_BOOL CJS_PropValue::IsSetting() -{ - return m_bIsSetting; +FX_BOOL CJS_PropValue::IsSetting() { + return m_bIsSetting; } -FX_BOOL CJS_PropValue::IsGetting() -{ - 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) { + ASSERT(!m_bIsSetting); + CJS_Value::operator=(iValue); } -void CJS_PropValue::operator >>(int & iValue) const -{ - ASSERT(m_bIsSetting); - iValue = CJS_Value::ToInt(); +void CJS_PropValue::operator>>(int& iValue) const { + ASSERT(m_bIsSetting); + iValue = CJS_Value::ToInt(); } - -void CJS_PropValue::operator <<(bool bValue) -{ - ASSERT(!m_bIsSetting); - CJS_Value::operator =(bValue); +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::ToBool(); +void CJS_PropValue::operator>>(bool& bValue) const { + ASSERT(m_bIsSetting); + bValue = CJS_Value::ToBool(); } -void CJS_PropValue::operator <<(double dValue) -{ - ASSERT(!m_bIsSetting); - CJS_Value::operator =(dValue); +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::ToDouble(); +void CJS_PropValue::operator>>(double& dValue) const { + ASSERT(m_bIsSetting); + dValue = CJS_Value::ToDouble(); } -void CJS_PropValue::operator <<(CJS_Object* pObj) -{ - ASSERT(!m_bIsSetting); - CJS_Value::operator = (pObj); +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::ToCJSObject(); +void CJS_PropValue::operator>>(CJS_Object*& ppObj) const { + ASSERT(m_bIsSetting); + ppObj = CJS_Value::ToCJSObject(); } -void CJS_PropValue::operator <<(CJS_Document* pJsDoc) -{ - ASSERT(!m_bIsSetting); - CJS_Value::operator = (pJsDoc); +void CJS_PropValue::operator<<(CJS_Document* pJsDoc) { + ASSERT(!m_bIsSetting); + CJS_Value::operator=(pJsDoc); } -void CJS_PropValue::operator >>(CJS_Document*& ppJsDoc) const -{ - ASSERT(m_bIsSetting); - ppJsDoc = static_cast(CJS_Value::ToCJSObject()); +void CJS_PropValue::operator>>(CJS_Document*& ppJsDoc) const { + ASSERT(m_bIsSetting); + ppJsDoc = static_cast(CJS_Value::ToCJSObject()); } -void CJS_PropValue::operator<<(JSFXObject pObj) -{ - ASSERT(!m_bIsSetting); - CJS_Value::operator = (pObj); +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::ToV8Object(); +void CJS_PropValue::operator>>(JSFXObject& ppObj) const { + ASSERT(m_bIsSetting); + ppObj = CJS_Value::ToV8Object(); } - -void CJS_PropValue::StartSetting() -{ - m_bIsSetting = 1; +void CJS_PropValue::StartSetting() { + m_bIsSetting = 1; } -void CJS_PropValue::StartGetting() -{ - m_bIsSetting = 0; +void CJS_PropValue::StartGetting() { + m_bIsSetting = 0; } -void CJS_PropValue::operator <<(CFX_ByteString string) -{ - ASSERT(!m_bIsSetting); - CJS_Value::operator = (string.c_str()); +void CJS_PropValue::operator<<(CFX_ByteString string) { + ASSERT(!m_bIsSetting); + CJS_Value::operator=(string.c_str()); } -void CJS_PropValue::operator >>(CFX_ByteString &string) const -{ - ASSERT(m_bIsSetting); - string = CJS_Value::ToCFXByteString(); +void CJS_PropValue::operator>>(CFX_ByteString& string) const { + ASSERT(m_bIsSetting); + string = CJS_Value::ToCFXByteString(); } -void CJS_PropValue::operator <<(const FX_WCHAR* c_string) -{ - ASSERT(!m_bIsSetting); - CJS_Value::operator =(c_string); +void CJS_PropValue::operator<<(const FX_WCHAR* 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::ToCFXWideString(); +void CJS_PropValue::operator>>(CFX_WideString& wide_string) const { + ASSERT(m_bIsSetting); + wide_string = CJS_Value::ToCFXWideString(); } -void CJS_PropValue::operator <<(CFX_WideString wide_string) -{ - ASSERT(!m_bIsSetting); - CJS_Value::operator = (wide_string.c_str()); +void CJS_PropValue::operator<<(CFX_WideString wide_string) { + ASSERT(!m_bIsSetting); + CJS_Value::operator=(wide_string.c_str()); } -void CJS_PropValue::operator >>(CJS_Array &array) const -{ - ASSERT(m_bIsSetting); - ConvertToArray(array); +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_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) const { + ASSERT(m_bIsSetting); + ConvertToDate(date); } -void CJS_PropValue::operator<<(CJS_Date &date) -{ - ASSERT(!m_bIsSetting); - CJS_Value::operator=(date); +void CJS_PropValue::operator<<(CJS_Date& date) { + ASSERT(!m_bIsSetting); + CJS_Value::operator=(date); } -CJS_PropValue::operator v8::Local() const -{ - return m_pValue; +CJS_PropValue::operator v8::Local() const { + return m_pValue; } -/* ======================================== CJS_Array ========================================= */ -CJS_Array::CJS_Array(v8::Isolate* isolate):m_isolate(isolate) -{ -} +/* ======================================== CJS_Array + * ========================================= */ +CJS_Array::CJS_Array(v8::Isolate* isolate) : m_isolate(isolate) {} -CJS_Array::~CJS_Array() -{ -} +CJS_Array::~CJS_Array() {} -void CJS_Array::Attach(v8::Local pArray) -{ - m_pArray = pArray; +void CJS_Array::Attach(v8::Local pArray) { + m_pArray = pArray; } -FX_BOOL CJS_Array::IsAttached() -{ - return FALSE; +FX_BOOL CJS_Array::IsAttached() { + return FALSE; } -void CJS_Array::GetElement(unsigned index,CJS_Value &value) -{ - if (m_pArray.IsEmpty()) - return; - v8::Local p = JS_GetArrayElement(m_isolate, m_pArray,index); - value.Attach(p,VT_object); +void CJS_Array::GetElement(unsigned index, CJS_Value& value) { + if (m_pArray.IsEmpty()) + return; + v8::Local p = JS_GetArrayElement(m_isolate, 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); +void CJS_Array::SetElement(unsigned index, CJS_Value value) { + if (m_pArray.IsEmpty()) + m_pArray = JS_NewArray(m_isolate); - JS_PutArrayElement(m_isolate, m_pArray, index, value.ToV8Value(), value.GetType()); + JS_PutArrayElement(m_isolate, m_pArray, index, value.ToV8Value(), + value.GetType()); } -int CJS_Array::GetLength() -{ - if (m_pArray.IsEmpty()) - return 0; - return JS_GetArrayLength(m_pArray); +int CJS_Array::GetLength() { + if (m_pArray.IsEmpty()) + return 0; + return JS_GetArrayLength(m_pArray); } -CJS_Array:: operator v8::Local() -{ - if (m_pArray.IsEmpty()) - m_pArray = JS_NewArray(m_isolate); +CJS_Array::operator v8::Local() { + if (m_pArray.IsEmpty()) + m_pArray = JS_NewArray(m_isolate); - return m_pArray; + return m_pArray; } -/* ======================================== CJS_Date ========================================= */ +/* ======================================== CJS_Date + * ========================================= */ -CJS_Date::CJS_Date(v8::Isolate* isolate) :m_isolate(isolate) -{ -} +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, 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)); +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)); +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() -{ -} +CJS_Date::~CJS_Date() {} -FX_BOOL CJS_Date::IsValidDate() -{ - if(m_pDate.IsEmpty()) return FALSE; - return !JS_PortIsNan(JS_ToNumber(m_isolate, m_pDate)); +FX_BOOL CJS_Date::IsValidDate() { + if (m_pDate.IsEmpty()) + return FALSE; + return !JS_PortIsNan(JS_ToNumber(m_isolate, m_pDate)); } -void CJS_Date::Attach(v8::Local pDate) -{ - m_pDate = pDate; +void CJS_Date::Attach(v8::Local pDate) { + m_pDate = pDate; } -int CJS_Date::GetYear() -{ - if (IsValidDate()) - return JS_GetYearFromTime(JS_LocalTime(JS_ToNumber(m_isolate, m_pDate))); +int CJS_Date::GetYear() { + if (IsValidDate()) + return JS_GetYearFromTime(JS_LocalTime(JS_ToNumber(m_isolate, m_pDate))); - return 0; + 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)); +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_isolate, m_pDate))); +int CJS_Date::GetMonth() { + if (IsValidDate()) + return JS_GetMonthFromTime(JS_LocalTime(JS_ToNumber(m_isolate, m_pDate))); - return 0; + 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)); - +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_isolate, m_pDate))); +int CJS_Date::GetDay() { + if (IsValidDate()) + return JS_GetDayFromTime(JS_LocalTime(JS_ToNumber(m_isolate, m_pDate))); - return 0; + 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)); - +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_isolate, m_pDate))); +int CJS_Date::GetHours() { + if (IsValidDate()) + return JS_GetHourFromTime(JS_LocalTime(JS_ToNumber(m_isolate, m_pDate))); - return 0; + 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)); +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_isolate, m_pDate))); +int CJS_Date::GetMinutes() { + if (IsValidDate()) + return JS_GetMinFromTime(JS_LocalTime(JS_ToNumber(m_isolate, m_pDate))); - return 0; + 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)); +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_isolate, m_pDate))); +int CJS_Date::GetSeconds() { + if (IsValidDate()) + return JS_GetSecFromTime(JS_LocalTime(JS_ToNumber(m_isolate, m_pDate))); - return 0; + 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)); +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::Local() -{ - return m_pDate; +CJS_Date::operator v8::Local() { + return m_pDate; } -CJS_Date::operator double() const -{ - if(m_pDate.IsEmpty()) - return 0.0; - return JS_ToNumber(m_isolate, m_pDate); +CJS_Date::operator double() const { + if (m_pDate.IsEmpty()) + return 0.0; + return JS_ToNumber(m_isolate, m_pDate); } -CFX_WideString CJS_Date::ToString() const -{ - if(m_pDate.IsEmpty()) - return L""; - return JS_ToString(m_isolate, m_pDate); +CFX_WideString CJS_Date::ToString() const { + if (m_pDate.IsEmpty()) + return L""; + return JS_ToString(m_isolate, m_pDate); } diff --git a/fpdfsdk/src/javascript/PublicMethods.cpp b/fpdfsdk/src/javascript/PublicMethods.cpp index daecdbec89..30400789b8 100644 --- a/fpdfsdk/src/javascript/PublicMethods.cpp +++ b/fpdfsdk/src/javascript/PublicMethods.cpp @@ -19,2255 +19,2123 @@ #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); +static v8::Isolate* GetIsolate(IFXJS_Context* cc) { + CJS_Context* pContext = (CJS_Context*)cc; + ASSERT(pContext != NULL); - CJS_Runtime* pRuntime = pContext->GetJSRuntime(); - ASSERT(pRuntime != NULL); + CJS_Runtime* pRuntime = pContext->GetJSRuntime(); + ASSERT(pRuntime != NULL); - return pRuntime->GetIsolate(); + return pRuntime->GetIsolate(); } +/* -------------------------------- CJS_PublicMethods + * -------------------------------- */ -/* -------------------------------- CJS_PublicMethods -------------------------------- */ - -#define DOUBLE_CORRECT 0.000000000000001 +#define DOUBLE_CORRECT 0.000000000000001 BEGIN_JS_STATIC_GLOBAL_FUN(CJS_PublicMethods) - JS_STATIC_GLOBAL_FUN_ENTRY(AFNumber_Format) - JS_STATIC_GLOBAL_FUN_ENTRY(AFNumber_Keystroke) - JS_STATIC_GLOBAL_FUN_ENTRY(AFPercent_Format) - JS_STATIC_GLOBAL_FUN_ENTRY(AFPercent_Keystroke) - JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_FormatEx) - JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_KeystrokeEx) - JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_Format) - JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_Keystroke) - JS_STATIC_GLOBAL_FUN_ENTRY(AFTime_FormatEx) - JS_STATIC_GLOBAL_FUN_ENTRY(AFTime_KeystrokeEx) - JS_STATIC_GLOBAL_FUN_ENTRY(AFTime_Format) - JS_STATIC_GLOBAL_FUN_ENTRY(AFTime_Keystroke) - JS_STATIC_GLOBAL_FUN_ENTRY(AFSpecial_Format) - JS_STATIC_GLOBAL_FUN_ENTRY(AFSpecial_Keystroke) - JS_STATIC_GLOBAL_FUN_ENTRY(AFSpecial_KeystrokeEx) - JS_STATIC_GLOBAL_FUN_ENTRY(AFSimple) - JS_STATIC_GLOBAL_FUN_ENTRY(AFMakeNumber) - JS_STATIC_GLOBAL_FUN_ENTRY(AFSimple_Calculate) - JS_STATIC_GLOBAL_FUN_ENTRY(AFRange_Validate) - JS_STATIC_GLOBAL_FUN_ENTRY(AFMergeChange) - JS_STATIC_GLOBAL_FUN_ENTRY(AFParseDateEx) - JS_STATIC_GLOBAL_FUN_ENTRY(AFExtractNums) +JS_STATIC_GLOBAL_FUN_ENTRY(AFNumber_Format) +JS_STATIC_GLOBAL_FUN_ENTRY(AFNumber_Keystroke) +JS_STATIC_GLOBAL_FUN_ENTRY(AFPercent_Format) +JS_STATIC_GLOBAL_FUN_ENTRY(AFPercent_Keystroke) +JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_FormatEx) +JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_KeystrokeEx) +JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_Format) +JS_STATIC_GLOBAL_FUN_ENTRY(AFDate_Keystroke) +JS_STATIC_GLOBAL_FUN_ENTRY(AFTime_FormatEx) +JS_STATIC_GLOBAL_FUN_ENTRY(AFTime_KeystrokeEx) +JS_STATIC_GLOBAL_FUN_ENTRY(AFTime_Format) +JS_STATIC_GLOBAL_FUN_ENTRY(AFTime_Keystroke) +JS_STATIC_GLOBAL_FUN_ENTRY(AFSpecial_Format) +JS_STATIC_GLOBAL_FUN_ENTRY(AFSpecial_Keystroke) +JS_STATIC_GLOBAL_FUN_ENTRY(AFSpecial_KeystrokeEx) +JS_STATIC_GLOBAL_FUN_ENTRY(AFSimple) +JS_STATIC_GLOBAL_FUN_ENTRY(AFMakeNumber) +JS_STATIC_GLOBAL_FUN_ENTRY(AFSimple_Calculate) +JS_STATIC_GLOBAL_FUN_ENTRY(AFRange_Validate) +JS_STATIC_GLOBAL_FUN_ENTRY(AFMergeChange) +JS_STATIC_GLOBAL_FUN_ENTRY(AFParseDateEx) +JS_STATIC_GLOBAL_FUN_ENTRY(AFExtractNums) END_JS_STATIC_GLOBAL_FUN() IMPLEMENT_JS_STATIC_GLOBAL_FUN(CJS_PublicMethods) -static const FX_WCHAR* months[] = -{ - L"Jan", L"Feb", L"Mar", L"Apr", L"May", L"Jun", L"Jul", L"Aug", L"Sep", L"Oct", L"Nov", L"Dec" -}; +static const FX_WCHAR* months[] = {L"Jan", L"Feb", L"Mar", L"Apr", + L"May", L"Jun", L"Jul", L"Aug", + L"Sep", L"Oct", L"Nov", L"Dec"}; -static const FX_WCHAR* fullmonths[] = -{ - L"January", L"February", L"March", L"April", L"May", L"June", L"July", L"August", L"September", L"October", L"November", L"December" -}; +static const FX_WCHAR* fullmonths[] = {L"January", L"February", L"March", + L"April", L"May", L"June", + L"July", L"August", L"September", + L"October", L"November", L"December"}; -FX_BOOL CJS_PublicMethods::IsNumber(const FX_WCHAR* string) -{ - CFX_WideString sTrim = StrTrim(string); - const FX_WCHAR* pTrim = sTrim.c_str(); - const FX_WCHAR* p = pTrim; +FX_BOOL CJS_PublicMethods::IsNumber(const FX_WCHAR* string) { + CFX_WideString sTrim = StrTrim(string); + const FX_WCHAR* pTrim = sTrim.c_str(); + const FX_WCHAR* p = pTrim; + FX_BOOL bDot = FALSE; + FX_BOOL bKXJS = FALSE; - 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; + 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++; + p++; + c = *p; + if (c == '+' || c == '-') { + bKXJS = TRUE; + } else { + return FALSE; + } + } else if (!IsDigit(c)) { + return FALSE; } + p++; + } - return TRUE; + return TRUE; } -FX_BOOL CJS_PublicMethods::IsDigit(wchar_t ch) -{ - return (ch >= L'0' && ch <= L'9'); +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::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::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::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) - { +FX_BOOL CJS_PublicMethods::maskSatisfied(wchar_t c_Change, wchar_t c_Mask) { + switch (c_Mask) { case L'9': - return IsDigit(c_Change); + return IsDigit(c_Change); case L'A': - return IsAlphabetic(c_Change); + return IsAlphabetic(c_Change); case L'O': - return IsAlphaNumeric(c_Change); + return IsAlphaNumeric(c_Change); case L'X': - return TRUE; + return TRUE; default: - return (c_Change == c_Mask); - } + 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'; +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(const FX_WCHAR* sFuction, double dValue1, double dValue2) -{ - if (FXSYS_wcsicmp(sFuction,L"AVG") == 0 || FXSYS_wcsicmp(sFuction,L"SUM") == 0) - { - return dValue1 + dValue2; - } - if (FXSYS_wcsicmp(sFuction, L"PRD") == 0) - { - return dValue1 * dValue2; - } - if (FXSYS_wcsicmp(sFuction,L"MIN") == 0) - { - return FX_MIN(dValue1, dValue2); - } - if (FXSYS_wcsicmp(sFuction,L"MAX") == 0) - { - return FX_MAX(dValue1, dValue2); - } - return dValue1; +double CJS_PublicMethods::AF_Simple(const FX_WCHAR* sFuction, + double dValue1, + double dValue2) { + if (FXSYS_wcsicmp(sFuction, L"AVG") == 0 || + FXSYS_wcsicmp(sFuction, L"SUM") == 0) { + return dValue1 + dValue2; + } + if (FXSYS_wcsicmp(sFuction, L"PRD") == 0) { + return dValue1 * dValue2; + } + if (FXSYS_wcsicmp(sFuction, L"MIN") == 0) { + return FX_MIN(dValue1, dValue2); + } + if (FXSYS_wcsicmp(sFuction, L"MAX") == 0) { + return FX_MAX(dValue1, dValue2); + } + return dValue1; } -CFX_WideString CJS_PublicMethods::StrLTrim(const FX_WCHAR* pStr) -{ - while (*pStr && *pStr == L' ') pStr++; +CFX_WideString CJS_PublicMethods::StrLTrim(const FX_WCHAR* pStr) { + while (*pStr && *pStr == L' ') + pStr++; - return pStr; + return pStr; } -CFX_WideString CJS_PublicMethods::StrRTrim(const FX_WCHAR* pStr) -{ - const FX_WCHAR* p = pStr; - while (*p) p++; - while (p > pStr && *(p - 1) == L' ') p--; +CFX_WideString CJS_PublicMethods::StrRTrim(const FX_WCHAR* pStr) { + const FX_WCHAR* p = pStr; + while (*p) + p++; + while (p > pStr && *(p - 1) == L' ') + p--; - return CFX_WideString(pStr, p - pStr); + return CFX_WideString(pStr, p - pStr); } -CFX_WideString CJS_PublicMethods::StrTrim(const FX_WCHAR* pStr) -{ - return StrRTrim(StrLTrim(pStr).c_str()); +CFX_WideString CJS_PublicMethods::StrTrim(const FX_WCHAR* pStr) { + return StrRTrim(StrLTrim(pStr).c_str()); } -CFX_ByteString CJS_PublicMethods::StrLTrim(const FX_CHAR* pStr) -{ - while (*pStr && *pStr == ' ') pStr++; +CFX_ByteString CJS_PublicMethods::StrLTrim(const FX_CHAR* pStr) { + while (*pStr && *pStr == ' ') + pStr++; - return pStr; + return pStr; } -CFX_ByteString CJS_PublicMethods::StrRTrim(const FX_CHAR* pStr) -{ - const FX_CHAR* p = pStr; - while (*p) p++; - while (p > pStr && *(p - 1) == L' ') p--; +CFX_ByteString CJS_PublicMethods::StrRTrim(const FX_CHAR* pStr) { + const FX_CHAR* p = pStr; + while (*p) + p++; + while (p > pStr && *(p - 1) == L' ') + p--; - return CFX_ByteString(pStr,p-pStr); + return CFX_ByteString(pStr, p - pStr); } -CFX_ByteString CJS_PublicMethods::StrTrim(const FX_CHAR* pStr) -{ - return StrRTrim(StrLTrim(pStr)); +CFX_ByteString CJS_PublicMethods::StrTrim(const FX_CHAR* pStr) { + return StrRTrim(StrLTrim(pStr)); } -double CJS_PublicMethods::ParseNumber(const FX_WCHAR* swSource, FX_BOOL& bAllDigits, FX_BOOL& bDot, FX_BOOL& bSign, FX_BOOL& bKXJS) -{ - bDot = FALSE; - bSign = FALSE; - bKXJS = FALSE; +double CJS_PublicMethods::ParseNumber(const FX_WCHAR* swSource, + FX_BOOL& bAllDigits, + FX_BOOL& bDot, + FX_BOOL& bSign, + FX_BOOL& bKXJS) { + bDot = FALSE; + bSign = FALSE; + bKXJS = FALSE; - FX_BOOL bDigitExist = FALSE; + FX_BOOL bDigitExist = FALSE; - const FX_WCHAR* p = swSource; - wchar_t c; + const FX_WCHAR* p = swSource; + wchar_t c; - const FX_WCHAR* pStart = NULL; - const FX_WCHAR* pEnd = NULL; - - while ((c = *p)) - { - if (!pStart && c != L' ') - { - pStart = p; - } + const FX_WCHAR* pStart = NULL; + const FX_WCHAR* pEnd = NULL; - pEnd = p; - p++; + while ((c = *p)) { + if (!pStart && c != L' ') { + pStart = p; } - if (!pStart) - { - bAllDigits = FALSE; - return 0; - } + pEnd = p; + p++; + } - while (pEnd != pStart) - { - if (*pEnd == L' ') - pEnd --; - else - break; - } + if (!pStart) { + bAllDigits = FALSE; + return 0; + } - 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; + 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; } - } - 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); + 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; - return dRet; + 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(const FX_WCHAR* swSource) -{ - FX_BOOL bAllDigits = FALSE; - FX_BOOL bDot = FALSE; - FX_BOOL bSign = FALSE; - FX_BOOL bKXJS = FALSE; +double CJS_PublicMethods::ParseStringToNumber(const FX_WCHAR* swSource) { + FX_BOOL bAllDigits = FALSE; + FX_BOOL bDot = FALSE; + FX_BOOL bSign = FALSE; + FX_BOOL bKXJS = FALSE; - return ParseNumber(swSource, bAllDigits, bDot, bSign, bKXJS); + return ParseNumber(swSource, bAllDigits, bDot, bSign, bKXJS); } -FX_BOOL CJS_PublicMethods::ConvertStringToNumber(const FX_WCHAR* swSource, double & dRet, FX_BOOL & bDot) -{ - FX_BOOL bAllDigits = FALSE; - FX_BOOL bSign = FALSE; - FX_BOOL bKXJS = FALSE; +FX_BOOL CJS_PublicMethods::ConvertStringToNumber(const FX_WCHAR* 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); + dRet = ParseNumber(swSource, bAllDigits, bDot, bSign, bKXJS); - return bAllDigits; + 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.ToCFXWideString(); - 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, StrTrim(p).c_str())); - break; - } - else - { - char * pSub = new char[pTemp - p + 1]; - strncpy(pSub, p, pTemp - p); - *(pSub + (pTemp - p)) = '\0'; - - StrArray.SetElement(nIndex, CJS_Value(isolate, StrTrim(pSub).c_str())); - delete []pSub; - - nIndex ++; - p = ++pTemp; - } - - } +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.ToCFXWideString(); + 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, StrTrim(p).c_str())); + break; + } else { + char* pSub = new char[pTemp - p + 1]; + strncpy(pSub, p, pTemp - p); + *(pSub + (pTemp - p)) = '\0'; + + StrArray.SetElement(nIndex, CJS_Value(isolate, StrTrim(pSub).c_str())); + 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; - } +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; + 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; +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; +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]; } - 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; + 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]; } - CFX_WideString swTemp; - swTemp.Format(L"%d/%d/%d %d:%d:%d",nMonth,nDay,nYear,nHour,nMin,nSec); - return JS_DateParse(swTemp.c_str()); -} - -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; + } else { + bWrongFormat = TRUE; + return dt; + } + + CFX_WideString swTemp; + swTemp.Format(L"%d/%d/%d %d:%d:%d", nMonth, nDay, nYear, nHour, nMin, nSec); + return JS_DateParse(swTemp.c_str()); +} - 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; +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; + int remaining = format.GetLength() - i - 1; + + if (remaining == 0 || 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': - { - int oldj = j; - int nSkip = 0; - int remaining = format.GetLength() - i - 1; - - if (remaining == 0 || 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 = (j < value.GetLength() && value.GetAt(j) == 'p'); - i++; - j++; - break; - } - } - else if (remaining == 1 || 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 = (j + 1 < value.GetLength() && value.GetAt(j) == 'p' && value.GetAt(j+1) == 'm'); - i += 2; - j += 2; - break; - } - } - else if (remaining == 2 || 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 (remaining == 3 || 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.c_str(), 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 (j >= value.GetLength() || format.GetAt(i) != value.GetAt(j)) - { - bWrongFormat = TRUE; - bExit = TRUE; - } - i++; - j++; - } - - if (oldj == j) - { - bWrongFormat = TRUE; - bExit = TRUE; - } + bPm = (j < value.GetLength() && value.GetAt(j) == 'p'); + i++; + j++; + break; + } + } else if (remaining == 1 || 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 = (j + 1 < value.GetLength() && value.GetAt(j) == 'p' && + value.GetAt(j + 1) == 'm'); + i += 2; + j += 2; + break; + } + } else if (remaining == 2 || 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; } - - break; + } + + if (!bFind) { + nMonth = ParseStringInteger(value, j, nSkip, 3); + i += 3; + j += nSkip; + } + } break; + case 'y': + break; default: - if (value.GetLength() <= j) - { - bExit = TRUE; - } - else if (format.GetAt(i) != value.GetAt(j)) - { - bWrongFormat = TRUE; - bExit = TRUE; + i += 3; + j += 3; + break; + } + } else if (remaining == 3 || 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.c_str(), 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 (j >= value.GetLength() || format.GetAt(i) != value.GetAt(j)) { + bWrongFormat = TRUE; + bExit = TRUE; + } + i++; + j++; + } - i++; - j++; - break; + 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; } - } - if (bPm) nHour += 12; + i++; + j++; + break; + } + } - if (nYear >= 0 && nYear <= nYearSub) - nYear += 2000; + if (bPm) + nHour += 12; - if (nMonth < 1 || nMonth > 12) - bWrongFormat = TRUE; + if (nYear >= 0 && nYear <= nYearSub) + nYear += 2000; - if (nDay < 1 || nDay > 31) - bWrongFormat = TRUE; + if (nMonth < 1 || nMonth > 12) + bWrongFormat = TRUE; - if (nHour < 0 || nHour > 24) - bWrongFormat = TRUE; + if (nDay < 1 || nDay > 31) + bWrongFormat = TRUE; - if (nMin < 0 || nMin > 60) - bWrongFormat = TRUE; + if (nHour < 0 || nHour > 24) + bWrongFormat = TRUE; - if (nSec < 0 || nSec > 60) - bWrongFormat = TRUE; + if (nMin < 0 || nMin > 60) + bWrongFormat = TRUE; - double dRet = 0; + if (nSec < 0 || nSec > 60) + bWrongFormat = TRUE; - if (bWrongFormat) - { - dRet = ParseNormalDate(value, bWrongFormat); - } - else - { - dRet = JS_MakeDate(JS_MakeDay(nYear,nMonth - 1,nDay),JS_MakeTime(nHour, nMin, nSec, 0)); + double dRet = 0; - if (JS_PortIsNan(dRet)) - { - dRet = JS_DateParse(value.c_str()); - } - } + 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 = ParseNormalDate(value, bWrongFormat); + if (JS_PortIsNan(dRet)) { + dRet = JS_DateParse(value.c_str()); } + } - return dRet; + 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; - while (i < format.GetLength()) - { - FX_WCHAR c = format.GetAt(i); - int remaining = format.GetLength() - i - 1; - sPart = L""; - switch (c) - { +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; + while (i < format.GetLength()) { + FX_WCHAR c = format.GetAt(i); + int remaining = format.GetLength() - i - 1; + sPart = L""; + switch (c) { + case 'y': + case 'm': + case 'd': + case 'H': + case 'h': + case 'M': + case 's': + case 't': + if (remaining == 0 || format.GetAt(i + 1) != c) { + switch (c) { case 'y': + sPart += c; + break; case 'm': + sPart.Format(L"%d", nMonth); + break; case 'd': + sPart.Format(L"%d", nDay); + break; case 'H': + sPart.Format(L"%d", nHour); + break; case 'h': + sPart.Format(L"%d", nHour > 12 ? nHour - 12 : nHour); + break; case 'M': + sPart.Format(L"%d", nMin); + break; case 's': + sPart.Format(L"%d", nSec); + break; case 't': - if (remaining == 0 || format.GetAt(i+1) != c) - { - switch (c) - { - case 'y': - sPart += c; - break; - case 'm': - sPart.Format(L"%d",nMonth); - break; - case 'd': - sPart.Format(L"%d",nDay); - break; - case 'H': - sPart.Format(L"%d",nHour); - break; - case 'h': - sPart.Format(L"%d",nHour>12?nHour - 12:nHour); - break; - case 'M': - sPart.Format(L"%d",nMin); - break; - case 's': - sPart.Format(L"%d",nSec); - break; - case 't': - sPart += nHour>12?'p':'a'; - break; - } - i++; - } - else if (remaining == 1 || format.GetAt(i+2) != c) - { - switch (c) - { - case 'y': - sPart.Format(L"%02d",nYear - (nYear / 100) * 100); - break; - case 'm': - sPart.Format(L"%02d",nMonth); - break; - case 'd': - sPart.Format(L"%02d",nDay); - break; - case 'H': - sPart.Format(L"%02d",nHour); - break; - case 'h': - sPart.Format(L"%02d",nHour>12?nHour - 12:nHour); - break; - case 'M': - sPart.Format(L"%02d",nMin); - break; - case 's': - sPart.Format(L"%02d",nSec); - break; - case 't': - sPart = nHour>12? L"pm": L"am"; - break; - } - i+=2; - } - else if (remaining == 2 || 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 (remaining == 3 || format.GetAt(i+4) != c) - { - switch (c) - { - case 'y': - sPart.Format(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; + sPart += nHour > 12 ? 'p' : 'a'; + break; + } + i++; + } else if (remaining == 1 || format.GetAt(i + 2) != c) { + switch (c) { + case 'y': + sPart.Format(L"%02d", nYear - (nYear / 100) * 100); + break; + case 'm': + sPart.Format(L"%02d", nMonth); + break; + case 'd': + sPart.Format(L"%02d", nDay); + break; + case 'H': + sPart.Format(L"%02d", nHour); + break; + case 'h': + sPart.Format(L"%02d", nHour > 12 ? nHour - 12 : nHour); + break; + case 'M': + sPart.Format(L"%02d", nMin); + break; + case 's': + sPart.Format(L"%02d", nSec); + break; + case 't': + sPart = nHour > 12 ? L"pm" : L"am"; + break; + } + i += 2; + } else if (remaining == 2 || format.GetAt(i + 3) != c) { + switch (c) { + case 'm': + i += 3; + if (nMonth > 0 && nMonth <= 12) + sPart += months[nMonth - 1]; + break; default: - i++; - sPart += c; - break; + i += 3; + sPart += c; + sPart += c; + sPart += c; + break; + } + } else if (remaining == 3 || format.GetAt(i + 4) != c) { + switch (c) { + case 'y': + sPart.Format(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; } - - sRet += sPart; + break; + default: + i++; + sPart += c; + break; } - return sRet; + sRet += sPart; + } + + return sRet; } /* -------------------------------------------------------------------------- */ -//function AFNumber_Format(nDec, sepStyle, negStyle, currStyle, strCurrency, bCurrencyPrepend) -FX_BOOL CJS_PublicMethods::AFNumber_Format(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ +// function AFNumber_Format(nDec, sepStyle, negStyle, currStyle, strCurrency, +// bCurrencyPrepend) +FX_BOOL CJS_PublicMethods::AFNumber_Format(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { #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].ToInt(); - int iSepStyle = params[1].ToInt(); - int iNegStyle = params[2].ToInt(); - // params[3] is iCurrStyle, it's not used. - std::wstring wstrCurrency(params[4].ToCFXWideString().c_str()); - FX_BOOL bCurrencyPrepend = params[5].ToBool(); + 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; - if (iDec < 0) iDec = -iDec; + int iDec = params[0].ToInt(); + int iSepStyle = params[1].ToInt(); + int iNegStyle = params[2].ToInt(); + // params[3] is iCurrStyle, it's not used. + std::wstring wstrCurrency(params[4].ToCFXWideString().c_str()); + FX_BOOL bCurrencyPrepend = params[5].ToBool(); - if (iSepStyle < 0 || iSepStyle > 3) - iSepStyle = 0; + if (iDec < 0) + iDec = -iDec; - if (iNegStyle < 0 || iNegStyle > 3) - iNegStyle = 0; + 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; + ////////////////////////////////////////////////////// + // for processing decimal places + strValue.Replace(",", "."); + double dValue = atof(strValue); + if (iDec > 0) + dValue += DOUBLE_CORRECT; - int iDec2; - int iNegative = 0; + int iDec2; + int iNegative = 0; + strValue = fcvt(dValue, iDec, &iDec2, &iNegative); + if (strValue.IsEmpty()) { + dValue = 0; strValue = fcvt(dValue, iDec, &iDec2, &iNegative); - if (strValue.IsEmpty()) - { - dValue = 0; - strValue = fcvt(dValue, iDec, &iDec2, &iNegative); - 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; - iDecPositive = 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.c_str(); - - if (bCurrencyPrepend) - strValue2 = wstrCurrency + strValue2; + 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 - strValue2 = strValue2 + wstrCurrency; - - - - ///////////////////////////////////////////////////////////////////////// - //for processing negative style - if (iNegative) - { - 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<textColor(cc,vProp,sError);// red - } + cSeperator = '.'; + + int iDecPositive; + iDecPositive = 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.c_str(); + + if (bCurrencyPrepend) + strValue2 = wstrCurrency + strValue2; + else + strValue2 = strValue2 + wstrCurrency; + + ///////////////////////////////////////////////////////////////////////// + // for processing negative style + if (iNegative) { + 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); } + } } - 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<textColor(cc,vProp2,sError); - } - } - } - } - Value = strValue2.c_str(); + } + Value = strValue2.c_str(); #endif - return TRUE; + return TRUE; } -//function AFNumber_Keystroke(nDec, sepStyle, negStyle, currStyle, strCurrency, bCurrencyPrepend) -FX_BOOL CJS_PublicMethods::AFNumber_Keystroke(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - 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].ToInt(); - - 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.c_str()); - if (wstrValue.IsEmpty()) - return TRUE; - - CFX_WideString swTemp = wstrValue; - swTemp.Replace(L",", L"."); - if (!IsNumber(swTemp.c_str())) - { - pEvent->Rc() = FALSE; - sError = JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYSTROKE); - Alert(pContext, sError.c_str()); - return TRUE; - } - return TRUE; // it happens after the last keystroke and before validating, - } - - std::wstring w_strValue2 = w_strValue.c_str(); - std::wstring w_strChange2 = w_strChange.c_str(); - 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) - { +// function AFNumber_Keystroke(nDec, sepStyle, negStyle, currStyle, strCurrency, +// bCurrencyPrepend) +FX_BOOL CJS_PublicMethods::AFNumber_Keystroke(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + 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].ToInt(); + + 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.c_str()); + if (wstrValue.IsEmpty()) + return TRUE; + + CFX_WideString swTemp = wstrValue; + swTemp.Replace(L",", L"."); + if (!IsNumber(swTemp.c_str())) { + pEvent->Rc() = FALSE; + sError = JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYSTROKE); + Alert(pContext, sError.c_str()); + return TRUE; + } + return TRUE; // it happens after the last keystroke and before validating, + } + + std::wstring w_strValue2 = w_strValue.c_str(); + std::wstring w_strChange2 = w_strChange.c_str(); + 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; + 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; - } - bHasSep = TRUE; - continue; - } - if (*it == L'-') - { - if (bHasSign) - { - FX_BOOL &bRc = pEvent->Rc(); - bRc = FALSE; - return TRUE; - } - if (it != w_strChange2.begin()) //sign's position is not correct - { - FX_BOOL &bRc = pEvent->Rc(); - bRc = FALSE; - return TRUE; - } - 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; - + 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; + } + bHasSep = TRUE; + continue; + } + if (*it == L'-') { + if (bHasSign) { + FX_BOOL& bRc = pEvent->Rc(); + bRc = FALSE; + return TRUE; + } + if (it != w_strChange2.begin()) // sign's position is not correct + { + FX_BOOL& bRc = pEvent->Rc(); + bRc = FALSE; + return TRUE; + } + 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(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ +// function AFPercent_Format(nDec, sepStyle) +FX_BOOL CJS_PublicMethods::AFPercent_Format(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { #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(); - CFX_ByteString strValue = StrTrim(CFX_ByteString::FromUnicode(Value)); - if (strValue.IsEmpty()) - return TRUE; - - int iDec = params[0].ToInt(); - if (iDec < 0) - iDec = -iDec; - - int iSepStyle = params[1].ToInt(); - if (iSepStyle < 0 || iSepStyle > 3) - iSepStyle = 0; - - ////////////////////////////////////////////////////// - //for processing decimal places - double dValue = atof(strValue); - dValue *= 100; - if (iDec > 0) - dValue += DOUBLE_CORRECT;//УÕý + 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(); + CFX_ByteString strValue = StrTrim(CFX_ByteString::FromUnicode(Value)); + if (strValue.IsEmpty()) + return TRUE; - int iDec2; - int iNegative = 0; + int iDec = params[0].ToInt(); + if (iDec < 0) + iDec = -iDec; + + int iSepStyle = params[1].ToInt(); + 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; + int iNegative = 0; + strValue = fcvt(dValue, iDec, &iDec2, &iNegative); + if (strValue.IsEmpty()) { + dValue = 0; strValue = fcvt(dValue, iDec, &iDec2, &iNegative); - if (strValue.IsEmpty()) - { - dValue = 0; - strValue = fcvt(dValue, iDec, &iDec2, &iNegative); - } - - 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; - iDecPositive = iDec2; - - for (iDecPositive = iDec2 -3; iDecPositive > 0; iDecPositive -= 3) - { - strValue.Insert(iDecPositive,cSeperator); - iMax++; - } - } - //////////////////////////////////////////////////////////////////// - //negative mark - if (iNegative) - strValue = "-" + strValue; - strValue += "%"; - Value = CFX_WideString::FromLocal(strValue); + } + + 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; + iDecPositive = iDec2; + + for (iDecPositive = iDec2 - 3; iDecPositive > 0; iDecPositive -= 3) { + strValue.Insert(iDecPositive, cSeperator); + iMax++; + } + } + //////////////////////////////////////////////////////////////////// + // negative mark + if (iNegative) + strValue = "-" + strValue; + strValue += "%"; + Value = CFX_WideString::FromLocal(strValue); #endif - return TRUE; + return TRUE; } -//AFPercent_Keystroke(nDec, sepStyle) -FX_BOOL CJS_PublicMethods::AFPercent_Keystroke(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - return AFNumber_Keystroke(cc,params,vRet,sError); +// AFPercent_Keystroke(nDec, sepStyle) +FX_BOOL CJS_PublicMethods::AFPercent_Keystroke(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + return AFNumber_Keystroke(cc, params, vRet, sError); } -//function AFDate_FormatEx(cFormat) -FX_BOOL CJS_PublicMethods::AFDate_FormatEx(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - 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].ToCFXWideString(); - 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).c_str(), sFormat.c_str()); - Alert(pContext, swMsg.c_str()); - return FALSE; - } - - val = MakeFormatDate(dDate,sFormat); +// function AFDate_FormatEx(cFormat) +FX_BOOL CJS_PublicMethods::AFDate_FormatEx(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + 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; -} -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; - } + CFX_WideString sFormat = params[0].ToCFXWideString(); + FX_BOOL bWrongFormat = FALSE; + double dDate = 0.0f; - 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].c_str()); - nHour = (int)ParseStringToNumber(wsArray[3].c_str()); - nMin = (int)ParseStringToNumber(wsArray[4].c_str()); - nSec = (int)ParseStringToNumber(wsArray[5].c_str()); - nYear = (int)ParseStringToNumber(wsArray[7].c_str()); - - double dRet = JS_MakeDate(JS_MakeDay(nYear,nMonth - 1,nDay),JS_MakeTime(nHour, nMin, nSec, 0)); - - if (JS_PortIsNan(dRet)) - { - dRet = JS_DateParse(strValue.c_str()); - } + 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); + } - return dRet; + if (JS_PortIsNan(dDate)) { + CFX_WideString swMsg; + swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE).c_str(), + sFormat.c_str()); + Alert(pContext, swMsg.c_str()); + return FALSE; + } + + val = MakeFormatDate(dDate, sFormat); + return TRUE; } -//AFDate_KeystrokeEx(cFormat) -FX_BOOL CJS_PublicMethods::AFDate_KeystrokeEx(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - 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].ToCFXWideString(); - 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).c_str(), sFormat.c_str()); - Alert(pContext, swMsg.c_str()); - pEvent->Rc() = FALSE; - return TRUE; - } - } - 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].c_str()); + nHour = (int)ParseStringToNumber(wsArray[3].c_str()); + nMin = (int)ParseStringToNumber(wsArray[4].c_str()); + nSec = (int)ParseStringToNumber(wsArray[5].c_str()); + nYear = (int)ParseStringToNumber(wsArray[7].c_str()); + + double dRet = JS_MakeDate(JS_MakeDay(nYear, nMonth - 1, nDay), + JS_MakeTime(nHour, nMin, nSec, 0)); + + if (JS_PortIsNan(dRet)) { + dRet = JS_DateParse(strValue.c_str()); + } + + return dRet; } -FX_BOOL CJS_PublicMethods::AFDate_Format(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - 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; - } +// AFDate_KeystrokeEx(cFormat) +FX_BOOL CJS_PublicMethods::AFDate_KeystrokeEx(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + 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; - int iIndex = params[0].ToInt(); - const FX_WCHAR* cFormats[] = {L"m/d", L"m/d/yy", L"mm/dd/yy", L"mm/yy", L"d-mmm", L"d-mmm-yy", L"dd-mmm-yy", - L"yy-mm-dd", L"mmm-yy", L"mmmm-yy", L"mmm d, yyyy", L"mmmm d, yyyy", - L"m/d/yy h:MM tt", L"m/d/yy HH:MM" }; - - ASSERT(iIndex < FX_ArraySize(cFormats)); - - if (iIndex < 0) - iIndex = 0; - if (iIndex >= FX_ArraySize(cFormats)) - iIndex = 0; - CJS_Parameters newParams; - CJS_Value val(isolate,cFormats[iIndex]); - newParams.push_back(val); - return AFDate_FormatEx(cc,newParams,vRet,sError); + CFX_WideString sFormat = params[0].ToCFXWideString(); + 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).c_str(), + sFormat.c_str()); + Alert(pContext, swMsg.c_str()); + pEvent->Rc() = FALSE; + return TRUE; + } + } + return TRUE; } -//AFDate_KeystrokeEx(cFormat) -FX_BOOL CJS_PublicMethods::AFDate_Keystroke(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - v8::Isolate* isolate = ::GetIsolate(cc); - - if (params.size() != 1) - { - CJS_Context* pContext = (CJS_Context*)cc; - ASSERT(pContext != NULL); +FX_BOOL CJS_PublicMethods::AFDate_Format(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + v8::Isolate* isolate = ::GetIsolate(cc); - sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); - return FALSE; - } + if (params.size() != 1) { + CJS_Context* pContext = (CJS_Context*)cc; + ASSERT(pContext != NULL); - int iIndex = params[0].ToInt(); - const FX_WCHAR* cFormats[] = {L"m/d", L"m/d/yy", L"mm/dd/yy", L"mm/yy", L"d-mmm", L"d-mmm-yy", L"dd-mmm-yy", - L"yy-mm-dd", L"mmm-yy", L"mmmm-yy", L"mmm d, yyyy", L"mmmm d, yyyy", - L"m/d/yy h:MM tt", L"m/d/yy HH:MM" }; - - ASSERT(iIndex= FX_ArraySize(cFormats)) - iIndex = 0; - CJS_Parameters newParams; - CJS_Value val(isolate,cFormats[iIndex]); - newParams.push_back(val); - return AFDate_KeystrokeEx(cc,newParams,vRet,sError); + sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); + return FALSE; + } + + int iIndex = params[0].ToInt(); + const FX_WCHAR* cFormats[] = {L"m/d", + L"m/d/yy", + L"mm/dd/yy", + L"mm/yy", + L"d-mmm", + L"d-mmm-yy", + L"dd-mmm-yy", + L"yy-mm-dd", + L"mmm-yy", + L"mmmm-yy", + L"mmm d, yyyy", + L"mmmm d, yyyy", + L"m/d/yy h:MM tt", + L"m/d/yy HH:MM"}; + + ASSERT(iIndex < FX_ArraySize(cFormats)); + + if (iIndex < 0) + iIndex = 0; + if (iIndex >= FX_ArraySize(cFormats)) + iIndex = 0; + CJS_Parameters newParams; + CJS_Value val(isolate, cFormats[iIndex]); + newParams.push_back(val); + return AFDate_FormatEx(cc, newParams, vRet, sError); } -//function AFTime_Format(ptf) -FX_BOOL CJS_PublicMethods::AFTime_Format(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - 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; - } +// AFDate_KeystrokeEx(cFormat) +FX_BOOL CJS_PublicMethods::AFDate_Keystroke(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + v8::Isolate* isolate = ::GetIsolate(cc); - int iIndex = params[0].ToInt(); - const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss", L"h:MM:ss tt"}; - - ASSERT(iIndex= FX_ArraySize(cFormats)) - iIndex = 0; - CJS_Parameters newParams; - CJS_Value val(isolate,cFormats[iIndex]); - newParams.push_back(val); - return AFDate_FormatEx(cc,newParams,vRet,sError); + sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); + return FALSE; + } + + int iIndex = params[0].ToInt(); + const FX_WCHAR* cFormats[] = {L"m/d", + L"m/d/yy", + L"mm/dd/yy", + L"mm/yy", + L"d-mmm", + L"d-mmm-yy", + L"dd-mmm-yy", + L"yy-mm-dd", + L"mmm-yy", + L"mmmm-yy", + L"mmm d, yyyy", + L"mmmm d, yyyy", + L"m/d/yy h:MM tt", + L"m/d/yy HH:MM"}; + + ASSERT(iIndex < FX_ArraySize(cFormats)); + + if (iIndex < 0) + iIndex = 0; + if (iIndex >= FX_ArraySize(cFormats)) + 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_Keystroke(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - 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].ToInt(); - const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss", L"h:MM:ss tt"}; +// function AFTime_Format(ptf) +FX_BOOL CJS_PublicMethods::AFTime_Format(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + v8::Isolate* isolate = ::GetIsolate(cc); - ASSERT(iIndex= FX_ArraySize(cFormats)) + iIndex = 0; + CJS_Parameters newParams; + CJS_Value val(isolate, cFormats[iIndex]); + newParams.push_back(val); + return AFDate_FormatEx(cc, newParams, vRet, sError); +} - if (iIndex < 0) - iIndex = 0; - if (iIndex >= FX_ArraySize(cFormats)) - 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_Keystroke(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + 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].ToInt(); + const FX_WCHAR* cFormats[] = {L"HH:MM", L"h:MM tt", L"HH:MM:ss", + L"h:MM:ss tt"}; + + ASSERT(iIndex < FX_ArraySize(cFormats)); + + if (iIndex < 0) + iIndex = 0; + if (iIndex >= FX_ArraySize(cFormats)) + 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(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - return AFDate_FormatEx(cc,params,vRet,sError); +FX_BOOL CJS_PublicMethods::AFTime_FormatEx(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + return AFDate_FormatEx(cc, params, vRet, sError); } -FX_BOOL CJS_PublicMethods::AFTime_KeystrokeEx(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - return AFDate_KeystrokeEx(cc,params,vRet,sError); +FX_BOOL CJS_PublicMethods::AFTime_KeystrokeEx(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + return AFDate_KeystrokeEx(cc, params, vRet, sError); } -//function AFSpecial_Format(psf) -FX_BOOL CJS_PublicMethods::AFSpecial_Format(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - CJS_Context* pContext = (CJS_Context *)cc; - ASSERT(pContext != NULL); +// function AFSpecial_Format(psf) +FX_BOOL CJS_PublicMethods::AFSpecial_Format(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + CJS_Context* pContext = (CJS_Context*)cc; + ASSERT(pContext != NULL); - if (params.size() != 1) - { - sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); - return FALSE; - } + if (params.size() != 1) { + sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); + return FALSE; + } - std::string cFormat; - int iIndex = params[0].ToInt(); + std::string cFormat; + int iIndex = params[0].ToInt(); - CJS_EventHandler* pEvent = pContext->GetEventHandler(); - ASSERT(pEvent != NULL); + CJS_EventHandler* pEvent = pContext->GetEventHandler(); + ASSERT(pEvent != NULL); - if(!pEvent->m_pValue) - return FALSE; - CFX_WideString& Value = pEvent->Value(); - std::string strSrc = CFX_ByteString::FromUnicode(Value).c_str(); + if (!pEvent->m_pValue) + return FALSE; + CFX_WideString& Value = pEvent->Value(); + std::string strSrc = CFX_ByteString::FromUnicode(Value).c_str(); - switch (iIndex) - { + switch (iIndex) { case 0: - cFormat = "99999"; - break; + 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; + 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; } - - std::string strDes; - util::printx(cFormat,strSrc,strDes); - Value = CFX_WideString::FromLocal(strDes.c_str()); - return TRUE; + 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(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + CJS_Context* pContext = (CJS_Context*)cc; + ASSERT(pContext != NULL); + CJS_EventHandler* pEvent = pContext->GetEventHandler(); -//function AFSpecial_KeystrokeEx(mask) -FX_BOOL CJS_PublicMethods::AFSpecial_KeystrokeEx(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - CJS_Context* pContext = (CJS_Context *)cc; - ASSERT(pContext != NULL); - CJS_EventHandler* pEvent = pContext->GetEventHandler(); + ASSERT(pEvent != NULL); - ASSERT(pEvent != NULL); + if (params.size() < 1) { + sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); + return FALSE; + } - if (params.size() < 1) - { - sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); - return FALSE; - } - - if(!pEvent->m_pValue) - return FALSE; - CFX_WideString& valEvent = pEvent->Value(); + if (!pEvent->m_pValue) + return FALSE; + CFX_WideString& valEvent = pEvent->Value(); - CFX_WideString wstrMask = params[0].ToCFXWideString(); - if (wstrMask.IsEmpty()) - return TRUE; - - std::wstring wstrValue = valEvent.c_str(); - - 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).c_str()); - pEvent->Rc() = FALSE; - } - return TRUE; - } - - CFX_WideString &wideChange = pEvent->Change(); - std::wstring wChange = wideChange.c_str(); - if (wChange.empty()) - return TRUE; - - int iIndexMask = pEvent->SelStart(); + CFX_WideString wstrMask = params[0].ToCFXWideString(); + if (wstrMask.IsEmpty()) + return TRUE; - if (wstrValue.length() - (pEvent->SelEnd()-pEvent->SelStart()) + wChange.length() > (FX_DWORD)wstrMask.GetLength()) - { - Alert(pContext, JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG).c_str()); - pEvent->Rc() = FALSE; - return TRUE; - } + std::wstring wstrValue = valEvent.c_str(); - if (iIndexMask >= wstrMask.GetLength() && (!wChange.empty())) - { - Alert(pContext, JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG).c_str()); - pEvent->Rc() = FALSE; - return TRUE; + 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++; } - for (std::wstring::iterator it = wChange.begin(); it != wChange.end(); it++) - { - if (iIndexMask >= wstrMask.GetLength()) - { - Alert(pContext, JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG).c_str()); - pEvent->Rc() = FALSE; - return TRUE; - } - wchar_t w_Mask = wstrMask[iIndexMask]; - if (!isReservedMaskChar(w_Mask)) - { - *it = w_Mask; - } - wchar_t w_Change = *it; - if (!maskSatisfied(w_Change,w_Mask)) - { - pEvent->Rc() = FALSE; - return TRUE; - } - iIndexMask++; + if (iIndexMask != wstrMask.GetLength() || + (iIndexMask != wstrValue.size() && wstrMask.GetLength() != 0)) { + Alert( + pContext, + JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYSTROKE).c_str()); + pEvent->Rc() = FALSE; } + return TRUE; + } - wideChange = wChange.c_str(); + CFX_WideString& wideChange = pEvent->Change(); + std::wstring wChange = wideChange.c_str(); + if (wChange.empty()) return TRUE; -} + int iIndexMask = pEvent->SelStart(); -//function AFSpecial_Keystroke(psf) -FX_BOOL CJS_PublicMethods::AFSpecial_Keystroke(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - v8::Isolate* isolate = ::GetIsolate(cc); + if (wstrValue.length() - (pEvent->SelEnd() - pEvent->SelStart()) + + wChange.length() > + (FX_DWORD)wstrMask.GetLength()) { + Alert(pContext, + JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG).c_str()); + pEvent->Rc() = FALSE; + return TRUE; + } - CJS_Context* pContext = (CJS_Context *)cc; - ASSERT(pContext != NULL); - CJS_EventHandler* pEvent = pContext->GetEventHandler(); - ASSERT(pEvent != NULL); + if (iIndexMask >= wstrMask.GetLength() && (!wChange.empty())) { + Alert(pContext, + JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG).c_str()); + pEvent->Rc() = FALSE; + return TRUE; + } - if (params.size() != 1) - { - sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); - return FALSE; + for (std::wstring::iterator it = wChange.begin(); it != wChange.end(); it++) { + if (iIndexMask >= wstrMask.GetLength()) { + Alert(pContext, + JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG).c_str()); + pEvent->Rc() = FALSE; + return TRUE; } + wchar_t w_Mask = wstrMask[iIndexMask]; + if (!isReservedMaskChar(w_Mask)) { + *it = w_Mask; + } + wchar_t w_Change = *it; + if (!maskSatisfied(w_Change, w_Mask)) { + pEvent->Rc() = FALSE; + return TRUE; + } + iIndexMask++; + } - std::string cFormat; - int iIndex = params[0].ToInt(); - - if(!pEvent->m_pValue) - return FALSE; - //CJS_Value val = pEvent->Value(); - CFX_WideString& val = pEvent->Value(); - std::string strSrc = CFX_ByteString::FromUnicode(val).c_str(); - std::wstring wstrChange = pEvent->Change().c_str(); + wideChange = wChange.c_str(); + return TRUE; +} - switch (iIndex) - { +// function AFSpecial_Keystroke(psf) +FX_BOOL CJS_PublicMethods::AFSpecial_Keystroke(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + 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 = params[0].ToInt(); + + if (!pEvent->m_pValue) + return FALSE; + // CJS_Value val = pEvent->Value(); + CFX_WideString& val = pEvent->Value(); + std::string strSrc = CFX_ByteString::FromUnicode(val).c_str(); + std::wstring wstrChange = pEvent->Change().c_str(); + + switch (iIndex) { case 0: - cFormat = "99999"; - break; + 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; + // 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); + CJS_Parameters params2; + CJS_Value vMask(isolate, cFormat.c_str()); + params2.push_back(vMask); - return AFSpecial_KeystrokeEx(cc,params2,vRet,sError); + return AFSpecial_KeystrokeEx(cc, params2, vRet, sError); } -FX_BOOL CJS_PublicMethods::AFMergeChange(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - CJS_Context* pContext = (CJS_Context *)cc; - ASSERT(pContext != NULL); - CJS_EventHandler* pEventHandler = pContext->GetEventHandler(); - ASSERT(pEventHandler != NULL); +FX_BOOL CJS_PublicMethods::AFMergeChange(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + 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.c_str(); + return TRUE; + } - if (params.size() != 1) - { - sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); - return FALSE; - } + CFX_WideString prefix, postfix; - CFX_WideString swValue; - if (pEventHandler->m_pValue != NULL) - swValue = pEventHandler->Value(); + if (pEventHandler->SelStart() >= 0) + prefix = swValue.Mid(0, pEventHandler->SelStart()); + else + prefix = L""; - if (pEventHandler->WillCommit()) - { - vRet = swValue.c_str(); - return TRUE; - } + if (pEventHandler->SelEnd() >= 0 && + pEventHandler->SelEnd() <= swValue.GetLength()) + postfix = swValue.Mid(pEventHandler->SelEnd(), + swValue.GetLength() - pEventHandler->SelEnd()); + else + postfix = L""; - CFX_WideString prefix,postfix; + vRet = (prefix + pEventHandler->Change() + postfix).c_str(); - if (pEventHandler->SelStart() >= 0) - prefix = swValue.Mid(0,pEventHandler->SelStart()); - else - prefix = L""; + return TRUE; +} +FX_BOOL CJS_PublicMethods::AFParseDateEx(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + CJS_Context* pContext = (CJS_Context*)cc; + ASSERT(pContext != NULL); - if (pEventHandler->SelEnd() >= 0 && pEventHandler->SelEnd() <= swValue.GetLength()) - postfix = swValue.Mid(pEventHandler->SelEnd(), swValue.GetLength() - pEventHandler->SelEnd()); - else postfix = L""; + if (params.size() != 2) { + sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); + return FALSE; + } - vRet = (prefix + pEventHandler->Change() + postfix).c_str(); + CFX_WideString sValue = params[0].ToCFXWideString(); + CFX_WideString sFormat = params[1].ToCFXWideString(); - return TRUE; + FX_BOOL bWrongFormat = FALSE; + double dDate = MakeRegularDate(sValue, sFormat, bWrongFormat); + + if (JS_PortIsNan(dDate)) { + CFX_WideString swMsg; + swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE).c_str(), + sFormat.c_str()); + Alert((CJS_Context*)cc, swMsg.c_str()); + return FALSE; + } + + vRet = dDate; + return TRUE; } -FX_BOOL CJS_PublicMethods::AFParseDateEx(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - CJS_Context* pContext = (CJS_Context *)cc; +FX_BOOL CJS_PublicMethods::AFSimple(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + if (params.size() != 3) { + 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].ToCFXWideString(); - CFX_WideString sFormat = params[1].ToCFXWideString(); - - FX_BOOL bWrongFormat = FALSE; - double dDate = MakeRegularDate(sValue,sFormat,bWrongFormat); + sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); + return FALSE; + } - if (JS_PortIsNan(dDate)) - { - CFX_WideString swMsg; - swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE).c_str(), sFormat.c_str()); - Alert((CJS_Context *)cc, swMsg.c_str()); - return FALSE; - } - - vRet = dDate; - return TRUE; + vRet = (double)AF_Simple(params[0].ToCFXWideString().c_str(), + params[1].ToDouble(), params[2].ToDouble()); + return TRUE; } -FX_BOOL CJS_PublicMethods::AFSimple(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - if (params.size() != 3) - { - CJS_Context* pContext = (CJS_Context *)cc; - ASSERT(pContext != NULL); - - sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); - return FALSE; - } +FX_BOOL CJS_PublicMethods::AFMakeNumber(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + if (params.size() != 1) { + CJS_Context* pContext = (CJS_Context*)cc; + ASSERT(pContext != NULL); - vRet = (double)AF_Simple(params[0].ToCFXWideString().c_str(), params[1].ToDouble(), params[2].ToDouble()); - return TRUE; + sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); + return FALSE; + } + vRet = ParseStringToNumber(params[0].ToCFXWideString().c_str()); + return TRUE; } -FX_BOOL CJS_PublicMethods::AFMakeNumber(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - if (params.size() != 1) - { - CJS_Context* pContext = (CJS_Context *)cc; - ASSERT(pContext != NULL); +FX_BOOL CJS_PublicMethods::AFSimple_Calculate(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + v8::Isolate* isolate = ::GetIsolate(cc); - sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); - return FALSE; - } - vRet = ParseStringToNumber(params[0].ToCFXWideString().c_str()); - return TRUE; -} + CJS_Context* pContext = (CJS_Context*)cc; + ASSERT(pContext != NULL); -FX_BOOL CJS_PublicMethods::AFSimple_Calculate(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - v8::Isolate* isolate = ::GetIsolate(cc); + if (params.size() != 2) { + sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); + return FALSE; + } - CJS_Context* pContext = (CJS_Context *)cc; - ASSERT(pContext != NULL); + CJS_Value params1 = params[1]; - if (params.size() != 2) - { - sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); - return FALSE; - } + if (!params1.IsArrayObject() && params1.GetType() != VT_string) { + sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); + return FALSE; + } - CJS_Value params1 = params[1]; + CPDFSDK_Document* pReaderDoc = pContext->GetReaderDocument(); + ASSERT(pReaderDoc != NULL); - if (!params1.IsArrayObject() && params1.GetType() != VT_string) - { - sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); - return FALSE; - } + CPDFSDK_InterForm* pReaderInterForm = pReaderDoc->GetInterForm(); + ASSERT(pReaderInterForm != NULL); - CPDFSDK_Document* pReaderDoc = pContext->GetReaderDocument(); - ASSERT(pReaderDoc != NULL); + CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm(); + ASSERT(pInterForm != NULL); - CPDFSDK_InterForm* pReaderInterForm = pReaderDoc->GetInterForm(); - ASSERT(pReaderInterForm != NULL); + double dValue; + CFX_WideString sFunction = params[0].ToCFXWideString(); + if (wcscmp(sFunction.c_str(), L"PRD") == 0) + dValue = 1.0; + else + dValue = 0.0; - CPDF_InterForm* pInterForm = pReaderInterForm->GetInterForm(); - ASSERT(pInterForm != NULL); + CJS_Array FieldNameArray = AF_MakeArrayFromList(isolate, params1); - double dValue; - CFX_WideString sFunction = params[0].ToCFXWideString(); - if (wcscmp(sFunction.c_str(), 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(); iCountFields(wsFieldName); jGetField(j, wsFieldName)) - { - double dTemp = 0.0; - - switch (pFormField->GetFieldType()) - { - case FIELDTYPE_TEXTFIELD: - case FIELDTYPE_COMBOBOX: - { - dTemp = ParseStringToNumber(pFormField->GetValue().c_str()); - break; - } - case FIELDTYPE_PUSHBUTTON: - { - dTemp = 0.0; - break; - } - case FIELDTYPE_CHECKBOX: - case FIELDTYPE_RADIOBUTTON: - { - dTemp = 0.0; - for (int c=0,csz=pFormField->CountControls(); cGetControl(c)) - { - if (pFormCtrl->IsChecked()) - { - dTemp += ParseStringToNumber(pFormCtrl->GetExportValue().c_str()); - break; - } - else - continue; - } - } - break; - } - case FIELDTYPE_LISTBOX: - { - dTemp = 0.0; - if (pFormField->CountSelectedItems() > 1) - break; - else - { - dTemp = ParseStringToNumber(pFormField->GetValue().c_str()); - break; - } - } - default: - break; - } + int nFieldsCount = 0; - if (i == 0 && j == 0 && (wcscmp(sFunction.c_str(), L"MIN") == 0 || wcscmp(sFunction.c_str(), L"MAX") == 0)) - dValue = dTemp; + for (int i = 0, isz = FieldNameArray.GetLength(); i < isz; i++) { + CJS_Value jsValue(isolate); + FieldNameArray.GetElement(i, jsValue); + CFX_WideString wsFieldName = jsValue.ToCFXWideString(); - dValue = AF_Simple(sFunction.c_str(), dValue, dTemp); + for (int j = 0, jsz = pInterForm->CountFields(wsFieldName); j < jsz; j++) { + if (CPDF_FormField* pFormField = pInterForm->GetField(j, wsFieldName)) { + double dTemp = 0.0; - nFieldsCount++; + switch (pFormField->GetFieldType()) { + case FIELDTYPE_TEXTFIELD: + case FIELDTYPE_COMBOBOX: { + dTemp = ParseStringToNumber(pFormField->GetValue().c_str()); + 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().c_str()); + break; + } else + continue; + } } + break; + } + case FIELDTYPE_LISTBOX: { + dTemp = 0.0; + if (pFormField->CountSelectedItems() > 1) + break; + else { + dTemp = ParseStringToNumber(pFormField->GetValue().c_str()); + break; + } + } + default: + break; } + + if (i == 0 && j == 0 && (wcscmp(sFunction.c_str(), L"MIN") == 0 || + wcscmp(sFunction.c_str(), L"MAX") == 0)) + dValue = dTemp; + + dValue = AF_Simple(sFunction.c_str(), dValue, dTemp); + + nFieldsCount++; + } } + } - if (wcscmp(sFunction.c_str(), L"AVG") == 0 && nFieldsCount > 0) - dValue /= nFieldsCount; + if (wcscmp(sFunction.c_str(), 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.ToCFXWideString(); + 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.ToCFXWideString(); - return TRUE; + return TRUE; } /* This function validates the current event to ensure that its value is ** within the specified range. */ -FX_BOOL CJS_PublicMethods::AFRange_Validate(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - 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 = params[0].ToBool(); - double dGreaterThan = params[1].ToDouble(); - FX_BOOL bLessThan = params[2].ToBool(); - double dLessThan = params[3].ToDouble(); - CFX_WideString swMsg; - - if (bGreaterThan && bLessThan) - { - if (dEentValue < dGreaterThan || dEentValue > dLessThan) - swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE1).c_str(), - params[1].ToCFXWideString().c_str(), - params[3].ToCFXWideString().c_str()); - } - else if (bGreaterThan) - { - if (dEentValue < dGreaterThan) - swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE2).c_str(), - params[1].ToCFXWideString().c_str()); - } - else if (bLessThan) - { - if (dEentValue > dLessThan) - swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE3).c_str(), - params[3].ToCFXWideString().c_str()); - } - - if (!swMsg.IsEmpty()) - { - Alert(pContext, swMsg.c_str()); - pEvent->Rc() = FALSE; - } +FX_BOOL CJS_PublicMethods::AFRange_Validate(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + 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 = params[0].ToBool(); + double dGreaterThan = params[1].ToDouble(); + FX_BOOL bLessThan = params[2].ToBool(); + double dLessThan = params[3].ToDouble(); + CFX_WideString swMsg; + + if (bGreaterThan && bLessThan) { + if (dEentValue < dGreaterThan || dEentValue > dLessThan) + swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE1).c_str(), + params[1].ToCFXWideString().c_str(), + params[3].ToCFXWideString().c_str()); + } else if (bGreaterThan) { + if (dEentValue < dGreaterThan) + swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE2).c_str(), + params[1].ToCFXWideString().c_str()); + } else if (bLessThan) { + if (dEentValue > dLessThan) + swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSRANGE3).c_str(), + params[3].ToCFXWideString().c_str()); + } + + if (!swMsg.IsEmpty()) { + Alert(pContext, swMsg.c_str()); + pEvent->Rc() = FALSE; + } + return TRUE; } -FX_BOOL CJS_PublicMethods::AFExtractNums(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - 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].ToCFXWideString(); - 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 0) - { - nums.SetElement(nIndex,CJS_Value(isolate,sPart.c_str())); - sPart = L""; - nIndex ++; - } - } +FX_BOOL CJS_PublicMethods::AFExtractNums(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + 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].ToCFXWideString(); + 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, sPart.c_str())); + sPart = L""; + nIndex++; + } } + } - if (sPart.GetLength() > 0) - { - nums.SetElement(nIndex,CJS_Value(isolate,sPart.c_str())); - } + if (sPart.GetLength() > 0) { + nums.SetElement(nIndex, CJS_Value(isolate, sPart.c_str())); + } - if (nums.GetLength() > 0) - vRet = nums; - else - vRet.SetNull(); + if (nums.GetLength() > 0) + vRet = nums; + else + vRet.SetNull(); - return TRUE; + return TRUE; } diff --git a/fpdfsdk/src/javascript/app.cpp b/fpdfsdk/src/javascript/app.cpp index af329655fd..29007a4a2a 100644 --- a/fpdfsdk/src/javascript/app.cpp +++ b/fpdfsdk/src/javascript/app.cpp @@ -17,16 +17,14 @@ #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); -static v8::Isolate* GetIsolate(IFXJS_Context* cc) -{ - CJS_Context* pContext = (CJS_Context *)cc; - ASSERT(pContext != NULL); + CJS_Runtime* pRuntime = pContext->GetJSRuntime(); + ASSERT(pRuntime != NULL); - CJS_Runtime* pRuntime = pContext->GetJSRuntime(); - ASSERT(pRuntime != NULL); - - return pRuntime->GetIsolate(); + return pRuntime->GetIsolate(); } /* ---------------------------- TimerObj ---------------------------- */ @@ -43,35 +41,27 @@ END_JS_STATIC_METHOD() IMPLEMENT_JS_CLASS(CJS_TimerObj, TimerObj) TimerObj::TimerObj(CJS_Object* pJSObject) -: CJS_EmbedObj(pJSObject), -m_pTimer(NULL) -{ - -} + : CJS_EmbedObj(pJSObject), m_pTimer(NULL) {} -TimerObj::~TimerObj() -{ -} +TimerObj::~TimerObj() {} -void TimerObj::SetTimer(CJS_Timer* pTimer) -{ - m_pTimer = pTimer; +void TimerObj::SetTimer(CJS_Timer* pTimer) { + m_pTimer = pTimer; } -CJS_Timer* TimerObj::GetTimer() const -{ - return m_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_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 +#define JS_FILEPATH_MAXLEN 2000 /* ---------------------------- app ---------------------------- */ @@ -79,817 +69,804 @@ 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) +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) - JS_STATIC_METHOD_ENTRY(beep) - JS_STATIC_METHOD_ENTRY(browseForDoc) - JS_STATIC_METHOD_ENTRY(clearInterval) - JS_STATIC_METHOD_ENTRY(clearTimeOut) - JS_STATIC_METHOD_ENTRY(execDialog) - JS_STATIC_METHOD_ENTRY(execMenuItem) - JS_STATIC_METHOD_ENTRY(findComponent) - JS_STATIC_METHOD_ENTRY(goBack) - JS_STATIC_METHOD_ENTRY(goForward) - JS_STATIC_METHOD_ENTRY(launchURL) - JS_STATIC_METHOD_ENTRY(mailMsg) - JS_STATIC_METHOD_ENTRY(newFDF) - JS_STATIC_METHOD_ENTRY(newDoc) - JS_STATIC_METHOD_ENTRY(openDoc) - JS_STATIC_METHOD_ENTRY(openFDF) - JS_STATIC_METHOD_ENTRY(popUpMenuEx) - JS_STATIC_METHOD_ENTRY(popUpMenu) - JS_STATIC_METHOD_ENTRY(response) - JS_STATIC_METHOD_ENTRY(setInterval) - JS_STATIC_METHOD_ENTRY(setTimeOut) +JS_STATIC_METHOD_ENTRY(alert) +JS_STATIC_METHOD_ENTRY(beep) +JS_STATIC_METHOD_ENTRY(browseForDoc) +JS_STATIC_METHOD_ENTRY(clearInterval) +JS_STATIC_METHOD_ENTRY(clearTimeOut) +JS_STATIC_METHOD_ENTRY(execDialog) +JS_STATIC_METHOD_ENTRY(execMenuItem) +JS_STATIC_METHOD_ENTRY(findComponent) +JS_STATIC_METHOD_ENTRY(goBack) +JS_STATIC_METHOD_ENTRY(goForward) +JS_STATIC_METHOD_ENTRY(launchURL) +JS_STATIC_METHOD_ENTRY(mailMsg) +JS_STATIC_METHOD_ENTRY(newFDF) +JS_STATIC_METHOD_ENTRY(newDoc) +JS_STATIC_METHOD_ENTRY(openDoc) +JS_STATIC_METHOD_ENTRY(openFDF) +JS_STATIC_METHOD_ENTRY(popUpMenuEx) +JS_STATIC_METHOD_ENTRY(popUpMenu) +JS_STATIC_METHOD_ENTRY(response) +JS_STATIC_METHOD_ENTRY(setInterval) +JS_STATIC_METHOD_ENTRY(setTimeOut) END_JS_STATIC_METHOD() -IMPLEMENT_JS_CLASS(CJS_App,app) - -app::app(CJS_Object * pJSObject) - : CJS_EmbedObj(pJSObject), - m_bCalculate(true), - m_bRuntimeHighLight(false) -{ -} - -app::~app(void) -{ - for (int i=0,sz=m_aTimer.GetSize(); iGetReaderApp(); + CJS_Runtime* pRuntime = pContext->GetJSRuntime(); + CPDFSDK_Document* pCurDoc = pContext->GetReaderDocument(); + CJS_Array aDocs(pRuntime->GetIsolate()); + if (CPDFSDK_Document* pDoc = pApp->GetSDKDocument()) { + 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); + } + aDocs.SetElement(0, CJS_Value(pRuntime->GetIsolate(), pJSDocument)); + } + if (aDocs.GetLength() > 0) + vp << aDocs; + else + vp.SetNull(); - m_aTimer.RemoveAll(); + return TRUE; } -FX_BOOL app::activeDocs(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - if (!vp.IsGetting()) - return FALSE; +FX_BOOL app::calculate(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + if (vp.IsSetting()) { + bool bVP; + vp >> bVP; + m_bCalculate = (FX_BOOL)bVP; - CJS_Context* pContext = (CJS_Context *)cc; + CJS_Context* pContext = (CJS_Context*)cc; CPDFDoc_Environment* pApp = pContext->GetReaderApp(); CJS_Runtime* pRuntime = pContext->GetJSRuntime(); - CPDFSDK_Document* pCurDoc = pContext->GetReaderDocument(); CJS_Array aDocs(pRuntime->GetIsolate()); if (CPDFSDK_Document* pDoc = pApp->GetSDKDocument()) + pDoc->GetInterForm()->EnableCalculate((FX_BOOL)m_bCalculate); + } else { + vp << (bool)m_bCalculate; + } + return TRUE; +} + +FX_BOOL app::formsVersion(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + if (vp.IsGetting()) { + vp << JS_NUM_FORMSVERSION; + return TRUE; + } + + return FALSE; +} + +FX_BOOL app::viewerType(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + if (vp.IsGetting()) { + vp << L"unknown"; + return TRUE; + } + + return FALSE; +} + +FX_BOOL app::viewerVariation(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + if (vp.IsGetting()) { + vp << JS_STR_VIEWERVARIATION; + return TRUE; + } + + return FALSE; +} + +FX_BOOL app::viewerVersion(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + if (vp.IsGetting()) { + vp << JS_STR_VIEWERVERSION; + return TRUE; + } + + return FALSE; +} + +FX_BOOL app::platform(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + if (vp.IsGetting()) { + vp << JS_STR_PLATFORM; + return TRUE; + } + + return FALSE; +} + +FX_BOOL app::language(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + 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(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + 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(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + return TRUE; +} + +FX_BOOL app::alert(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + 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].ToV8Object(); + { + v8::Local pValue = + JS_GetObjectElement(isolate, pObj, L"cMsg"); + swMsg = CJS_Value(isolate, pValue, VT_unknown).ToCFXWideString(); + + pValue = JS_GetObjectElement(isolate, pObj, L"cTitle"); + swTitle = CJS_Value(isolate, pValue, VT_unknown).ToCFXWideString(); + + pValue = JS_GetObjectElement(isolate, pObj, L"nIcon"); + iIcon = CJS_Value(isolate, pValue, VT_unknown).ToInt(); + + pValue = JS_GetObjectElement(isolate, pObj, L"nType"); + iType = CJS_Value(isolate, pValue, VT_unknown).ToInt(); + } + + 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).ToCFXWideString(); + if (i < iLenth - 1) + swMsg += L", "; + } + + delete pValue; + } + } + + if (swTitle == L"") + swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSALERT); + } else if (params[0].GetType() == VT_boolean) { + FX_BOOL bGet = params[0].ToBool(); + if (bGet) + swMsg = L"true"; + else + swMsg = L"false"; + + swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSALERT); + } else { + swMsg = params[0].ToCFXWideString(); + swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSALERT); + } + } else { + if (params[0].GetType() == VT_boolean) { + FX_BOOL bGet = params[0].ToBool(); + if (bGet) + swMsg = L"true"; + else + swMsg = L"false"; + } else { + swMsg = params[0].ToCFXWideString(); + } + swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSALERT); + + for (int i = 1; i < iSize; i++) { + if (i == 1) + iIcon = params[i].ToInt(); + if (i == 2) + iType = params[i].ToInt(); + if (i == 3) + swTitle = params[i].ToCFXWideString(); + } + } + + 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.c_str(), + swTitle.c_str(), iType, iIcon); + pRuntime->EndBlock(); + + return TRUE; +} + +FX_BOOL app::beep(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + if (params.size() == 1) { + CJS_Context* pContext = (CJS_Context*)cc; + CJS_Runtime* pRuntime = pContext->GetJSRuntime(); + CPDFDoc_Environment* pEnv = pRuntime->GetReaderApp(); + pEnv->JS_appBeep(params[0].ToInt()); + return TRUE; + } + + sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR); + return FALSE; +} + +FX_BOOL app::findComponent(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + return TRUE; +} + +FX_BOOL app::popUpMenuEx(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + return FALSE; +} + +FX_BOOL app::fs(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { + return FALSE; +} + +FX_BOOL app::setInterval(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + CJS_Context* pContext = (CJS_Context*)cc; + if (params.size() > 2 || params.size() == 0) { + sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); + return FALSE; + } + + CFX_WideString script = params.size() > 0 ? params[0].ToCFXWideString() : L""; + if (script.IsEmpty()) { + sError = JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYSTROKE); + return TRUE; + } + + CJS_Runtime* pRuntime = pContext->GetJSRuntime(); + FX_DWORD dwInterval = params.size() > 1 ? params[1].ToInt() : 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(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + 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 ? params[0].ToCFXWideString() : L""; + if (script.IsEmpty()) { + sError = + JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSAFNUMBER_KEYSTROKE); + return TRUE; + } + + FX_DWORD dwTimeOut = params.size() > 1 ? params[1].ToInt() : 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->SetJSTimer(dwTimeOut); + + 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::clearTimeOut(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + 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 = params[0].ToV8Object(); { - 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); + if (JS_GetObjDefnID(pObj) == JS_GetObjDefnID(*pRuntime, L"TimerObj")) { + if (CJS_Object* pJSObj = params[0].ToCJSObject()) { + 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); + } + } } - else - { - JSFXObject pObj = JS_NewFxDynamicObj(*pRuntime, pContext, JS_GetObjDefnID(*pRuntime,L"Document")); - pJSDocument = (CJS_Document*)JS_GetPrivate(pRuntime->GetIsolate(),pObj); - ASSERT(pJSDocument != NULL); + } + } + } + + return TRUE; +} + +FX_BOOL app::clearInterval(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + 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 = params[0].ToV8Object(); + { + if (JS_GetObjDefnID(pObj) == JS_GetObjDefnID(*pRuntime, L"TimerObj")) { + if (CJS_Object* pJSObj = params[0].ToCJSObject()) { + 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); + } + } } - aDocs.SetElement(0,CJS_Value(pRuntime->GetIsolate(),pJSDocument)); + } } - if (aDocs.GetLength() > 0) - vp << aDocs; - else - vp.SetNull(); + } - return TRUE; + return TRUE; } -FX_BOOL app::calculate(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - if (vp.IsSetting()) - { - bool bVP; - vp >> bVP; - m_bCalculate = (FX_BOOL)bVP; +FX_BOOL app::execMenuItem(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + return FALSE; +} + +void app::TimerProc(CJS_Timer* pTimer) { + ASSERT(pTimer != NULL); - CJS_Context* pContext = (CJS_Context*)cc; - CPDFDoc_Environment* pApp = pContext->GetReaderApp(); - CJS_Runtime* pRuntime = pContext->GetJSRuntime(); - CJS_Array aDocs(pRuntime->GetIsolate()); - if (CPDFSDK_Document* pDoc = pApp->GetSDKDocument()) - pDoc->GetInterForm()->EnableCalculate((FX_BOOL)m_bCalculate); - } - else - { - vp << (bool)m_bCalculate; - } - return TRUE; + 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; + } } - -FX_BOOL app::formsVersion(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - if (vp.IsGetting()) - { - vp << JS_NUM_FORMSVERSION; - return TRUE; - } - - return FALSE; -} - -FX_BOOL app::viewerType(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - if (vp.IsGetting()) - { - vp << L"unknown"; - return TRUE; - } - - return FALSE; -} - -FX_BOOL app::viewerVariation(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - if (vp.IsGetting()) - { - vp << JS_STR_VIEWERVARIATION; - return TRUE; - } - - return FALSE; -} - -FX_BOOL app::viewerVersion(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - if (vp.IsGetting()) - { - vp << JS_STR_VIEWERVERSION; - return TRUE; - } - - return FALSE; -} - -FX_BOOL app::platform(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - if (vp.IsGetting()) - { - vp << JS_STR_PLATFORM; - return TRUE; - } - - return FALSE; -} - -FX_BOOL app::language(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - 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(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - 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(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - return TRUE; -} - -FX_BOOL app::alert(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - 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].ToV8Object(); - { - v8::Local pValue = JS_GetObjectElement(isolate, pObj, L"cMsg"); - swMsg = CJS_Value(isolate, pValue, VT_unknown).ToCFXWideString(); - - pValue = JS_GetObjectElement(isolate, pObj, L"cTitle"); - swTitle = CJS_Value(isolate, pValue, VT_unknown).ToCFXWideString(); - - pValue = JS_GetObjectElement(isolate, pObj, L"nIcon"); - iIcon = CJS_Value(isolate, pValue, VT_unknown).ToInt(); - - pValue = JS_GetObjectElement(isolate, pObj, L"nType"); - iType = CJS_Value(isolate, pValue, VT_unknown).ToInt(); - } - - 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).ToCFXWideString(); - if (i < iLenth - 1) - swMsg += L", "; - } - - delete pValue; - } - } - - if (swTitle == L"") - swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSALERT); - } - else if (params[0].GetType() == VT_boolean) - { - FX_BOOL bGet = params[0].ToBool(); - if (bGet) - swMsg = L"true"; - else - swMsg = L"false"; - - swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSALERT); - } - else - { - swMsg = params[0].ToCFXWideString(); - swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSALERT); - } - } - else - { - if (params[0].GetType() == VT_boolean) - { - FX_BOOL bGet = params[0].ToBool(); - if (bGet) - swMsg = L"true"; - else - swMsg = L"false"; - } - else - { - swMsg = params[0].ToCFXWideString(); - } - swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSALERT); - - for(int i = 1;iGetJSRuntime(); - ASSERT(pRuntime != NULL); - pRuntime->BeginBlock(); - vRet = MsgBox(pRuntime->GetReaderApp(), JSGetPageView(cc), swMsg.c_str(), swTitle.c_str(), iType, iIcon); - pRuntime->EndBlock(); - - return TRUE; -} - - -FX_BOOL app::beep(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - if (params.size() == 1) - { - CJS_Context* pContext = (CJS_Context*)cc; - CJS_Runtime* pRuntime = pContext->GetJSRuntime(); - CPDFDoc_Environment * pEnv = pRuntime->GetReaderApp(); - pEnv->JS_appBeep(params[0].ToInt()); - return TRUE; - } - - sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR); - return FALSE; -} - -FX_BOOL app::findComponent(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - return TRUE; -} - -FX_BOOL app::popUpMenuEx(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - return FALSE; -} - -FX_BOOL app::fs(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - return FALSE; -} - -FX_BOOL app::setInterval(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - CJS_Context* pContext = (CJS_Context*)cc; - if (params.size() > 2 || params.size() == 0) - { - sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); - return FALSE; - } - - CFX_WideString script = params.size() > 0 ? params[0].ToCFXWideString() : L""; - if (script.IsEmpty()) - { - sError = JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYSTROKE); - return TRUE; - } - - CJS_Runtime* pRuntime = pContext->GetJSRuntime(); - FX_DWORD dwInterval = params.size() > 1 ? params[1].ToInt() : 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(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - 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 ? params[0].ToCFXWideString() : L""; - if (script.IsEmpty()) - { - sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSAFNUMBER_KEYSTROKE); - return TRUE; - } - - FX_DWORD dwTimeOut = params.size() > 1 ? params[1].ToInt() : 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->SetJSTimer(dwTimeOut); - - 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::clearTimeOut(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - 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 = params[0].ToV8Object(); - { - if (JS_GetObjDefnID(pObj) == JS_GetObjDefnID(*pRuntime, L"TimerObj")) - { - if (CJS_Object* pJSObj = params[0].ToCJSObject()) - { - if (TimerObj* pTimerObj = (TimerObj*)pJSObj->GetEmbedObject()) - { - if (CJS_Timer* pTimer = pTimerObj->GetTimer()) - { - pTimer->KillJSTimer(); - - for (int i=0,sz=m_aTimer.GetSize(); iSetTimer(NULL); - } - } - } - } - } - } - - return TRUE; -} - -FX_BOOL app::clearInterval(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - 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 = params[0].ToV8Object(); - { - if (JS_GetObjDefnID(pObj) == JS_GetObjDefnID(*pRuntime, L"TimerObj")) - { - if (CJS_Object* pJSObj = params[0].ToCJSObject()) - { - if (TimerObj* pTimerObj = (TimerObj*)pJSObj->GetEmbedObject()) - { - if (CJS_Timer* pTimer = pTimerObj->GetTimer()) - { - pTimer->KillJSTimer(); - - for (int i=0,sz=m_aTimer.GetSize(); iSetTimer(NULL); - } - } - } - } - } - } - - return TRUE; -} - -FX_BOOL app::execMenuItem(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - 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(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ + +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(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { // Not supported. return TRUE; } -FX_BOOL app::goForward(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ +FX_BOOL app::goForward(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { // Not supported. return TRUE; } -FX_BOOL app::mailMsg(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - CJS_Context* pContext = (CJS_Context*)cc; - v8::Isolate* isolate = GetIsolate(cc); +FX_BOOL app::mailMsg(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + CJS_Context* pContext = (CJS_Context*)cc; + 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""; + 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() < 1) - return FALSE; + if (params.size() < 1) + return FALSE; - if (params[0].GetType() == VT_object) - { - JSObject pObj = params[0].ToV8Object(); + if (params[0].GetType() == VT_object) { + JSObject pObj = params[0].ToV8Object(); - v8::Local pValue = JS_GetObjectElement(isolate, pObj, L"bUI"); - bUI = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToBool(); + v8::Local pValue = JS_GetObjectElement(isolate, pObj, L"bUI"); + bUI = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToBool(); - pValue = JS_GetObjectElement(isolate, pObj, L"cTo"); - cTo = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); + pValue = JS_GetObjectElement(isolate, pObj, L"cTo"); + cTo = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); - pValue = JS_GetObjectElement(isolate, pObj, L"cCc"); - cCc = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); + pValue = JS_GetObjectElement(isolate, pObj, L"cCc"); + cCc = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); - pValue = JS_GetObjectElement(isolate, pObj, L"cBcc"); - cBcc = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); + pValue = JS_GetObjectElement(isolate, pObj, L"cBcc"); + cBcc = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); - pValue = JS_GetObjectElement(isolate, pObj, L"cSubject"); - cSubject = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); + pValue = JS_GetObjectElement(isolate, pObj, L"cSubject"); + cSubject = + CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); - pValue = JS_GetObjectElement(isolate, pObj, L"cMsg"); - cMsg = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); - } else { - if (params.size() < 2) - return FALSE; + pValue = JS_GetObjectElement(isolate, pObj, L"cMsg"); + cMsg = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); + } else { + if (params.size() < 2) + return FALSE; - bUI = params[0].ToBool(); - cTo = params[1].ToCFXWideString(); + bUI = params[0].ToBool(); + cTo = params[1].ToCFXWideString(); - if (params.size() >= 3) - cCc = params[2].ToCFXWideString(); - if (params.size() >= 4) - cBcc = params[3].ToCFXWideString(); - if (params.size() >= 5) - cSubject = params[4].ToCFXWideString(); - if (params.size() >= 6) - cMsg = params[5].ToCFXWideString(); - } + if (params.size() >= 3) + cCc = params[2].ToCFXWideString(); + if (params.size() >= 4) + cBcc = params[3].ToCFXWideString(); + if (params.size() >= 5) + cSubject = params[4].ToCFXWideString(); + if (params.size() >= 6) + cMsg = params[5].ToCFXWideString(); + } - CJS_Runtime* pRuntime = pContext->GetJSRuntime(); - ASSERT(pRuntime != NULL); + CJS_Runtime* pRuntime = pContext->GetJSRuntime(); + ASSERT(pRuntime != NULL); - CPDFDoc_Environment* pApp = pContext->GetReaderApp(); - ASSERT(pApp != NULL); + CPDFDoc_Environment* pApp = pContext->GetReaderApp(); + ASSERT(pApp != NULL); - pRuntime->BeginBlock(); - pApp->JS_docmailForm(NULL, 0, bUI, cTo.c_str(), cSubject.c_str(), cCc.c_str(), cBcc.c_str(), cMsg.c_str()); - pRuntime->EndBlock(); + pRuntime->BeginBlock(); + pApp->JS_docmailForm(NULL, 0, bUI, cTo.c_str(), cSubject.c_str(), cCc.c_str(), + cBcc.c_str(), cMsg.c_str()); + pRuntime->EndBlock(); - return FALSE; + return FALSE; } -FX_BOOL app::launchURL(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ +FX_BOOL app::launchURL(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { // Unsafe, not supported. return TRUE; } -FX_BOOL app::runtimeHighlight(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - if (vp.IsSetting()) - { - vp>>m_bRuntimeHighLight; - } - else - { - vp<> m_bRuntimeHighLight; + } else { + vp << m_bRuntimeHighLight; + } - return TRUE; + return TRUE; } -FX_BOOL app::fullscreen(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - return FALSE; +FX_BOOL app::fullscreen(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + return FALSE; } -FX_BOOL app::popUpMenu(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - return FALSE; +FX_BOOL app::popUpMenu(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + return FALSE; } - -FX_BOOL app::browseForDoc(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ +FX_BOOL app::browseForDoc(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { // Unsafe, not supported. return TRUE; } -CFX_WideString app::SysPathToPDFPath(const CFX_WideString& sOldPath) -{ - CFX_WideString sRet = L"/"; - - for (int i=0,sz=sOldPath.GetLength(); i 0 && params[0].GetType() == VT_object) - { - JSObject pObj = params[0].ToV8Object(); - v8::Local pValue = JS_GetObjectElement(isolate,pObj,L"cQuestion"); - swQuestion = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).ToCFXWideString(); - - pValue = JS_GetObjectElement(isolate,pObj,L"cTitle"); - swTitle = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).ToCFXWideString(); - - pValue = JS_GetObjectElement(isolate,pObj,L"cDefault"); - swDefault = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).ToCFXWideString(); - - pValue = JS_GetObjectElement(isolate,pObj,L"cLabel"); - swLabel = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).ToCFXWideString(); - - pValue = JS_GetObjectElement(isolate,pObj,L"bPassword"); - bPassWord = CJS_Value(isolate,pValue,GET_VALUE_TYPE(pValue)).ToBool(); - } - else - { - switch(iLength) - { - case 5: - swLabel = params[4].ToCFXWideString(); - // FALLTHROUGH - case 4: - bPassWord = params[3].ToBool(); - // FALLTHROUGH - case 3: - swDefault = params[2].ToCFXWideString(); - // FALLTHROUGH - case 2: - swTitle = params[1].ToCFXWideString(); - // FALLTHROUGH - case 1: - swQuestion = params[0].ToCFXWideString(); - // FALLTHROUGH - default: - break; - } - } - - CJS_Context* pContext = (CJS_Context *)cc; - ASSERT(pContext != NULL); - - CPDFDoc_Environment* pApp = pContext->GetReaderApp(); - ASSERT(pApp != NULL); - - const int MAX_INPUT_BYTES = 2048; - nonstd::unique_ptr pBuff(new char[MAX_INPUT_BYTES + 2]); - memset(pBuff.get(), 0, MAX_INPUT_BYTES + 2); - int nLengthBytes = pApp->JS_appResponse(swQuestion.c_str(), - swTitle.c_str(), - swDefault.c_str(), - swLabel.c_str(), - bPassWord, - pBuff.get(), - MAX_INPUT_BYTES); - if (nLengthBytes <= 0) { - vRet.SetNull(); - return FALSE; - } - nLengthBytes = std::min(nLengthBytes, MAX_INPUT_BYTES); +CFX_WideString app::SysPathToPDFPath(const CFX_WideString& sOldPath) { + CFX_WideString sRet = L"/"; - CFX_WideString ret_string = - CFX_WideString::FromUTF16LE((unsigned short*)pBuff.get(), - nLengthBytes / sizeof(unsigned short)); - vRet = ret_string.c_str(); - return TRUE; + 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; +} + +FX_BOOL app::newDoc(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + return FALSE; +} + +FX_BOOL app::openDoc(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + return FALSE; +} + +FX_BOOL app::response(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + CFX_WideString swQuestion = L""; + CFX_WideString swLabel = L""; + CFX_WideString swTitle = L"PDF"; + CFX_WideString swDefault = L""; + bool bPassWord = false; + + v8::Isolate* isolate = GetIsolate(cc); + + int iLength = params.size(); + if (iLength > 0 && params[0].GetType() == VT_object) { + JSObject pObj = params[0].ToV8Object(); + v8::Local pValue = + JS_GetObjectElement(isolate, pObj, L"cQuestion"); + swQuestion = + CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); + + pValue = JS_GetObjectElement(isolate, pObj, L"cTitle"); + swTitle = + CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); + + pValue = JS_GetObjectElement(isolate, pObj, L"cDefault"); + swDefault = + CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); + + pValue = JS_GetObjectElement(isolate, pObj, L"cLabel"); + swLabel = + CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString(); + + pValue = JS_GetObjectElement(isolate, pObj, L"bPassword"); + bPassWord = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToBool(); + } else { + switch (iLength) { + case 5: + swLabel = params[4].ToCFXWideString(); + // FALLTHROUGH + case 4: + bPassWord = params[3].ToBool(); + // FALLTHROUGH + case 3: + swDefault = params[2].ToCFXWideString(); + // FALLTHROUGH + case 2: + swTitle = params[1].ToCFXWideString(); + // FALLTHROUGH + case 1: + swQuestion = params[0].ToCFXWideString(); + // FALLTHROUGH + default: + break; + } + } + + CJS_Context* pContext = (CJS_Context*)cc; + ASSERT(pContext != NULL); + + CPDFDoc_Environment* pApp = pContext->GetReaderApp(); + ASSERT(pApp != NULL); + + const int MAX_INPUT_BYTES = 2048; + nonstd::unique_ptr pBuff(new char[MAX_INPUT_BYTES + 2]); + memset(pBuff.get(), 0, MAX_INPUT_BYTES + 2); + int nLengthBytes = pApp->JS_appResponse( + swQuestion.c_str(), swTitle.c_str(), swDefault.c_str(), swLabel.c_str(), + bPassWord, pBuff.get(), MAX_INPUT_BYTES); + if (nLengthBytes <= 0) { + vRet.SetNull(); + return FALSE; + } + nLengthBytes = std::min(nLengthBytes, MAX_INPUT_BYTES); + + CFX_WideString ret_string = CFX_WideString::FromUTF16LE( + (unsigned short*)pBuff.get(), nLengthBytes / sizeof(unsigned short)); + vRet = ret_string.c_str(); + return TRUE; } -FX_BOOL app::media(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - return FALSE; +FX_BOOL app::media(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + return FALSE; } -FX_BOOL app::execDialog(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - return TRUE; +FX_BOOL app::execDialog(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + return TRUE; } diff --git a/fpdfsdk/src/javascript/color.cpp b/fpdfsdk/src/javascript/color.cpp index a2bbadcd51..0659ab94a4 100644 --- a/fpdfsdk/src/javascript/color.cpp +++ b/fpdfsdk/src/javascript/color.cpp @@ -14,15 +14,14 @@ #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); +static v8::Isolate* GetIsolate(IFXJS_Context* cc) { + CJS_Context* pContext = (CJS_Context*)cc; + ASSERT(pContext != NULL); - CJS_Runtime* pRuntime = pContext->GetJSRuntime(); - ASSERT(pRuntime != NULL); + CJS_Runtime* pRuntime = pContext->GetJSRuntime(); + ASSERT(pRuntime != NULL); - return pRuntime->GetIsolate(); + return pRuntime->GetIsolate(); } /* -------------------------- color -------------------------- */ @@ -30,149 +29,132 @@ 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) +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) - JS_STATIC_METHOD_ENTRY(equal) +JS_STATIC_METHOD_ENTRY(convert) +JS_STATIC_METHOD_ENTRY(equal) 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); +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) -{ +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::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()); + array.GetElement(0, value); + CFX_ByteString sSpace = value.ToCFXByteString(); + + double d1 = 0; + double d2 = 0; + double d3 = 0; + double d4 = 0; + + if (nArrayLen > 1) { + array.GetElement(1, value); + d1 = value.ToDouble(); + } + + if (nArrayLen > 2) { + array.GetElement(2, value); + d2 = value.ToDouble(); + } + + if (nArrayLen > 3) { + array.GetElement(3, value); + d3 = value.ToDouble(); + } + + if (nArrayLen > 4) { + array.GetElement(4, value); + d4 = value.ToDouble(); + } + + 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); + } } -void color::ConvertArrayToPWLColor(CJS_Array& array, CPWL_Color& color) -{ - int nArrayLen = array.GetLength(); - if (nArrayLen < 1) return; - - CJS_Value value(array.GetIsolate()); - array.GetElement(0, value); - CFX_ByteString sSpace = value.ToCFXByteString(); - - double d1 = 0; - double d2 = 0; - double d3 = 0; - double d4 = 0; - - if (nArrayLen > 1) - { - array.GetElement(1, value); - d1 = value.ToDouble(); - } - - if (nArrayLen > 2) - { - array.GetElement(2, value); - d2 = value.ToDouble(); - } - - if (nArrayLen > 3) - { - array.GetElement(3, value); - d3 = value.ToDouble(); - } - - if (nArrayLen > 4) - { - array.GetElement(4, value); - d4 = value.ToDouble(); - } - - 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(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)\ -{\ - 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;\ -} +#define JS_IMPLEMENT_COLORPROP(prop, var) \ + FX_BOOL color::prop(IFXJS_Context* cc, CJS_PropValue& vp, \ + CFX_WideString& sError) { \ + 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) @@ -187,65 +169,66 @@ JS_IMPLEMENT_COLORPROP(dkGray, m_crDKGray) JS_IMPLEMENT_COLORPROP(gray, m_crGray) JS_IMPLEMENT_COLORPROP(ltGray, m_crLTGray) -FX_BOOL color::convert(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - 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].ToCFXByteString(); - 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::convert(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + 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].ToCFXByteString(); + 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(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - v8::Isolate* isolate = GetIsolate(cc); - if (params.size() < 2) return FALSE; +FX_BOOL color::equal(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + v8::Isolate* isolate = GetIsolate(cc); + if (params.size() < 2) + return FALSE; - CJS_Array array1(isolate), array2(isolate); + CJS_Array array1(isolate), array2(isolate); - if (!params[0].ConvertToArray(array1)) return FALSE; - if (!params[1].ConvertToArray(array2)) return FALSE; + if (!params[0].ConvertToArray(array1)) + return FALSE; + if (!params[1].ConvertToArray(array2)) + return FALSE; - CPWL_Color color1; - CPWL_Color color2; + CPWL_Color color1; + CPWL_Color color2; - ConvertArrayToPWLColor(array1, color1); - ConvertArrayToPWLColor(array2, color2); + ConvertArrayToPWLColor(array1, color1); + ConvertArrayToPWLColor(array2, color2); - color1.ConvertColorType(color2.nColorType); + color1.ConvertColorType(color2.nColorType); - vRet = color1 == color2; - return TRUE; + vRet = color1 == color2; + return TRUE; } - diff --git a/fpdfsdk/src/javascript/console.cpp b/fpdfsdk/src/javascript/console.cpp index ed9b1fbc56..cc64e1091b 100644 --- a/fpdfsdk/src/javascript/console.cpp +++ b/fpdfsdk/src/javascript/console.cpp @@ -22,45 +22,45 @@ BEGIN_JS_STATIC_PROP(CJS_Console) END_JS_STATIC_PROP() BEGIN_JS_STATIC_METHOD(CJS_Console) - JS_STATIC_METHOD_ENTRY(clear) - JS_STATIC_METHOD_ENTRY(hide) - JS_STATIC_METHOD_ENTRY(println) - JS_STATIC_METHOD_ENTRY(show) +JS_STATIC_METHOD_ENTRY(clear) +JS_STATIC_METHOD_ENTRY(hide) +JS_STATIC_METHOD_ENTRY(println) +JS_STATIC_METHOD_ENTRY(show) END_JS_STATIC_METHOD() -IMPLEMENT_JS_CLASS(CJS_Console,console) +IMPLEMENT_JS_CLASS(CJS_Console, console) -console::console(CJS_Object* pJSObject): CJS_EmbedObj(pJSObject) -{ -} +console::console(CJS_Object* pJSObject) : CJS_EmbedObj(pJSObject) {} -console::~console() -{ -} +console::~console() {} -FX_BOOL console::clear(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - return TRUE; +FX_BOOL console::clear(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + return TRUE; } -FX_BOOL console::hide(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - return TRUE; +FX_BOOL console::hide(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + return TRUE; } -FX_BOOL console::println(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - if (params.size() < 1) - { - return FALSE; - } - return TRUE; +FX_BOOL console::println(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + if (params.size() < 1) { + return FALSE; + } + return TRUE; } -FX_BOOL console::show(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - return TRUE; +FX_BOOL console::show(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + return TRUE; } - - - diff --git a/fpdfsdk/src/javascript/event.cpp b/fpdfsdk/src/javascript/event.cpp index f57b1fb607..4bcdcce3a0 100644 --- a/fpdfsdk/src/javascript/event.cpp +++ b/fpdfsdk/src/javascript/event.cpp @@ -21,359 +21,359 @@ 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) +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) +IMPLEMENT_JS_CLASS(CJS_Event, event) -event::event(CJS_Object * pJsObject) : CJS_EmbedObj(pJsObject) -{ -} +event::event(CJS_Object* pJsObject) : CJS_EmbedObj(pJsObject) {} -event::~event(void) -{ -} +event::~event(void) {} -FX_BOOL event::change(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - 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::change(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + 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(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - if (!vp.IsGetting())return FALSE; +FX_BOOL event::changeEx(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + if (!vp.IsGetting()) + return FALSE; - CJS_Context* pContext = (CJS_Context*)cc; - ASSERT(pContext != NULL); - CJS_EventHandler* pEvent = pContext->GetEventHandler(); - ASSERT(pEvent != NULL); + CJS_Context* pContext = (CJS_Context*)cc; + ASSERT(pContext != NULL); + CJS_EventHandler* pEvent = pContext->GetEventHandler(); + ASSERT(pEvent != NULL); - vp << pEvent->ChangeEx(); - return TRUE; + vp << pEvent->ChangeEx(); + return TRUE; } -FX_BOOL event::commitKey(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - if (!vp.IsGetting())return FALSE; +FX_BOOL event::commitKey(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + if (!vp.IsGetting()) + return FALSE; - CJS_Context* pContext = (CJS_Context*)cc; - ASSERT(pContext != NULL); - CJS_EventHandler* pEvent = pContext->GetEventHandler(); - ASSERT(pEvent != NULL); + CJS_Context* pContext = (CJS_Context*)cc; + ASSERT(pContext != NULL); + CJS_EventHandler* pEvent = pContext->GetEventHandler(); + ASSERT(pEvent != NULL); - vp << pEvent->CommitKey(); - return TRUE; + vp << pEvent->CommitKey(); + return TRUE; } -FX_BOOL event::fieldFull(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - 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::fieldFull(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + 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(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - 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::keyDown(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + 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(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - 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::modifier(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + 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(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - if (!vp.IsGetting())return FALSE; +FX_BOOL event::name(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + if (!vp.IsGetting()) + return FALSE; - CJS_Context* pContext = (CJS_Context*)cc; - ASSERT(pContext != NULL); - CJS_EventHandler* pEvent = pContext->GetEventHandler(); - ASSERT(pEvent != NULL); + CJS_Context* pContext = (CJS_Context*)cc; + ASSERT(pContext != NULL); + CJS_EventHandler* pEvent = pContext->GetEventHandler(); + ASSERT(pEvent != NULL); - vp << pEvent->Name(); - return TRUE; + vp << pEvent->Name(); + return TRUE; } -FX_BOOL event::rc(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - 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<GetEventHandler(); + ASSERT(pEvent != NULL); + + FX_BOOL& bRc = pEvent->Rc(); + if (vp.IsSetting()) { + vp >> bRc; + } else { + vp << bRc; + } + return TRUE; } -FX_BOOL event::richChange(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - return TRUE; - if (vp.IsSetting()) - { - } - else - { - ; - } - return TRUE; +FX_BOOL event::richChange(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + return TRUE; + if (vp.IsSetting()) { + } else { + ; + } + return TRUE; } -FX_BOOL event::richChangeEx(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - return TRUE; - if (vp.IsSetting()) - { - } - else - { - ; - } - return TRUE; +FX_BOOL event::richChangeEx(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + return TRUE; + if (vp.IsSetting()) { + } else { + ; + } + return TRUE; } - -FX_BOOL event::richValue(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - return TRUE; - if (vp.IsSetting()) - { - } - else - { - ; - } - return TRUE; +FX_BOOL event::richValue(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + return TRUE; + if (vp.IsSetting()) { + } else { + ; + } + return TRUE; } -FX_BOOL event::selEnd(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - 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::selEnd(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + 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(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - 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::selStart(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + 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(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - 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::shift(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + 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(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - if (!vp.IsGetting())return FALSE; +FX_BOOL event::source(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + if (!vp.IsGetting()) + return FALSE; - CJS_Context* pContext = (CJS_Context*)cc; - ASSERT(pContext != NULL); - CJS_EventHandler* pEvent = pContext->GetEventHandler(); - ASSERT(pEvent != NULL); + CJS_Context* pContext = (CJS_Context*)cc; + ASSERT(pContext != NULL); + CJS_EventHandler* pEvent = pContext->GetEventHandler(); + ASSERT(pEvent != NULL); - vp << pEvent->Source()->GetJSObject(); - return TRUE; + vp << pEvent->Source()->GetJSObject(); + return TRUE; } -FX_BOOL event::target(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - if (!vp.IsGetting())return FALSE; +FX_BOOL event::target(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + if (!vp.IsGetting()) + return FALSE; - CJS_Context* pContext = (CJS_Context*)cc; - ASSERT(pContext != NULL); - CJS_EventHandler* pEvent = pContext->GetEventHandler(); - ASSERT(pEvent != NULL); + CJS_Context* pContext = (CJS_Context*)cc; + ASSERT(pContext != NULL); + CJS_EventHandler* pEvent = pContext->GetEventHandler(); + ASSERT(pEvent != NULL); - vp<Target_Field()->GetJSObject(); - return TRUE; + vp << pEvent->Target_Field()->GetJSObject(); + return TRUE; } -FX_BOOL event::targetName(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - if (!vp.IsGetting())return FALSE; +FX_BOOL event::targetName(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + if (!vp.IsGetting()) + return FALSE; - CJS_Context* pContext = (CJS_Context*)cc; - ASSERT(pContext != NULL); - CJS_EventHandler* pEvent = pContext->GetEventHandler(); - ASSERT(pEvent != NULL); + CJS_Context* pContext = (CJS_Context*)cc; + ASSERT(pContext != NULL); + CJS_EventHandler* pEvent = pContext->GetEventHandler(); + ASSERT(pEvent != NULL); - vp << pEvent->TargetName(); - return TRUE; + vp << pEvent->TargetName(); + return TRUE; } -FX_BOOL event::type(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - if (!vp.IsGetting())return FALSE; +FX_BOOL event::type(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + if (!vp.IsGetting()) + return FALSE; - CJS_Context* pContext = (CJS_Context*)cc; - ASSERT(pContext != NULL); - CJS_EventHandler* pEvent = pContext->GetEventHandler(); - ASSERT(pEvent != NULL); + CJS_Context* pContext = (CJS_Context*)cc; + ASSERT(pContext != NULL); + CJS_EventHandler* pEvent = pContext->GetEventHandler(); + ASSERT(pEvent != NULL); - vp << pEvent->Type(); - return TRUE; + vp << pEvent->Type(); + return TRUE; } -FX_BOOL event::value(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - 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()) - { - vp >> val; - } - else - { - vp << val; - } - return TRUE; +FX_BOOL event::value(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + 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()) { + vp >> val; + } else { + vp << val; + } + return TRUE; } -FX_BOOL event::willCommit(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) -{ - 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; +FX_BOOL event::willCommit(IFXJS_Context* cc, + CJS_PropValue& vp, + CFX_WideString& sError) { + 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 6965c8c884..ee0591b950 100644 --- a/fpdfsdk/src/javascript/global.cpp +++ b/fpdfsdk/src/javascript/global.cpp @@ -39,51 +39,46 @@ struct CHash { }; extern const unsigned int JSCONST_nStringHash = - CHash<'s','t','r','i','n','g'>::value; + CHash<'s', 't', 'r', 'i', 'n', 'g'>::value; extern const unsigned int JSCONST_nNumberHash = - CHash<'n','u','m','b','e','r'>::value; + CHash<'n', 'u', 'm', 'b', 'e', 'r'>::value; extern const unsigned int JSCONST_nBoolHash = - CHash<'b','o','o','l','e','a','n'>::value; -extern const unsigned int JSCONST_nDateHash = - CHash<'d','a','t','e'>::value; + CHash<'b', 'o', 'o', 'l', 'e', 'a', 'n'>::value; +extern const unsigned int JSCONST_nDateHash = CHash<'d', 'a', 't', 'e'>::value; extern const unsigned int JSCONST_nObjectHash = - CHash<'o','b','j','e','c','t'>::value; + CHash<'o', 'b', 'j', 'e', 'c', 't'>::value; extern const unsigned int JSCONST_nFXobjHash = - CHash<'f','x','o','b','j'>::value; -extern const unsigned int JSCONST_nNullHash = - CHash<'n','u','l','l'>::value; + CHash<'f', 'x', 'o', 'b', 'j'>::value; +extern const unsigned int JSCONST_nNullHash = CHash<'n', 'u', 'l', 'l'>::value; extern const unsigned int JSCONST_nUndefHash = - CHash<'u','n','d','e','f','i','n','e','d'>::value; + CHash<'u', 'n', 'd', 'e', 'f', 'i', 'n', 'e', 'd'>::value; #ifdef _DEBUG -class HashVerify -{ -public: +class HashVerify { + public: HashVerify(); } g_hashVerify; -HashVerify::HashVerify() -{ +HashVerify::HashVerify() { ASSERT(JSCONST_nStringHash == - JS_CalcHash(VALUE_NAME_STRING,wcslen(VALUE_NAME_STRING))); + JS_CalcHash(VALUE_NAME_STRING, wcslen(VALUE_NAME_STRING))); ASSERT(JSCONST_nNumberHash == - JS_CalcHash(VALUE_NAME_NUMBER,wcslen(VALUE_NAME_NUMBER))); + JS_CalcHash(VALUE_NAME_NUMBER, wcslen(VALUE_NAME_NUMBER))); ASSERT(JSCONST_nBoolHash == - JS_CalcHash(VALUE_NAME_BOOLEAN,wcslen(VALUE_NAME_BOOLEAN))); + JS_CalcHash(VALUE_NAME_BOOLEAN, wcslen(VALUE_NAME_BOOLEAN))); ASSERT(JSCONST_nDateHash == - JS_CalcHash(VALUE_NAME_DATE,wcslen(VALUE_NAME_DATE))); + JS_CalcHash(VALUE_NAME_DATE, wcslen(VALUE_NAME_DATE))); ASSERT(JSCONST_nObjectHash == - JS_CalcHash(VALUE_NAME_OBJECT,wcslen(VALUE_NAME_OBJECT))); + JS_CalcHash(VALUE_NAME_OBJECT, wcslen(VALUE_NAME_OBJECT))); ASSERT(JSCONST_nFXobjHash == - JS_CalcHash(VALUE_NAME_FXOBJ,wcslen(VALUE_NAME_FXOBJ))); + JS_CalcHash(VALUE_NAME_FXOBJ, wcslen(VALUE_NAME_FXOBJ))); ASSERT(JSCONST_nNullHash == - JS_CalcHash(VALUE_NAME_NULL,wcslen(VALUE_NAME_NULL))); + JS_CalcHash(VALUE_NAME_NULL, wcslen(VALUE_NAME_NULL))); ASSERT(JSCONST_nUndefHash == - JS_CalcHash(VALUE_NAME_UNDEFINED,wcslen(VALUE_NAME_UNDEFINED))); + JS_CalcHash(VALUE_NAME_UNDEFINED, wcslen(VALUE_NAME_UNDEFINED))); } #endif - BEGIN_JS_STATIC_CONST(CJS_Global) END_JS_STATIC_CONST() @@ -91,500 +86,464 @@ BEGIN_JS_STATIC_PROP(CJS_Global) END_JS_STATIC_PROP() BEGIN_JS_STATIC_METHOD(CJS_Global) - JS_STATIC_METHOD_ENTRY(setPersistent) +JS_STATIC_METHOD_ENTRY(setPersistent) 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); +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); + global_alternate* pGlobal = (global_alternate*)GetEmbedObject(); + ASSERT(pGlobal != NULL); - pGlobal->Initial(pContext->GetReaderApp()); + pGlobal->Initial(pContext->GetReaderApp()); - return TRUE; + return TRUE; }; global_alternate::global_alternate(CJS_Object* pJSObject) - : CJS_EmbedObj(pJSObject), - m_pApp(NULL) -{ -} + : CJS_EmbedObj(pJSObject), m_pApp(NULL) {} -global_alternate::~global_alternate(void) -{ - DestroyGlobalPersisitentVariables(); - m_pApp->GetRuntimeFactory()->ReleaseGlobalData(); +global_alternate::~global_alternate(void) { + DestroyGlobalPersisitentVariables(); + m_pApp->GetRuntimeFactory()->ReleaseGlobalData(); } -void global_alternate::Initial(CPDFDoc_Environment* pApp) -{ - m_pApp = pApp; - m_pGlobalData = pApp->GetRuntimeFactory()->NewGlobalData(pApp); - UpdateGlobalPersistentVariables(); +void global_alternate::Initial(CPDFDoc_Environment* pApp) { + m_pApp = pApp; + m_pGlobalData = pApp->GetRuntimeFactory()->NewGlobalData(pApp); + UpdateGlobalPersistentVariables(); } -FX_BOOL global_alternate::QueryProperty(const FX_WCHAR* propname) -{ - return CFX_WideString(propname) != L"setPersistent"; +FX_BOOL global_alternate::QueryProperty(const FX_WCHAR* propname) { + return CFX_WideString(propname) != L"setPersistent"; } -FX_BOOL global_alternate::DelProperty(IFXJS_Context* cc, const FX_WCHAR* propname, CFX_WideString& sError) -{ - js_global_data* pData = NULL; - CFX_ByteString sPropName = CFX_ByteString::FromUnicode(propname); +FX_BOOL global_alternate::DelProperty(IFXJS_Context* cc, + const FX_WCHAR* propname, + CFX_WideString& sError) { + js_global_data* pData = NULL; + CFX_ByteString sPropName = CFX_ByteString::FromUnicode(propname); - if (m_mapGlobal.Lookup(sPropName, (void*&)pData)) - { - pData->bDeleted = TRUE; - return TRUE; - } + if (m_mapGlobal.Lookup(sPropName, (void*&)pData)) { + pData->bDeleted = TRUE; + return TRUE; + } - return FALSE; + return FALSE; } -FX_BOOL global_alternate::DoProperty(IFXJS_Context* cc, const FX_WCHAR* propname, CJS_PropValue& vp, CFX_WideString& 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::Local(), FALSE); - } - case VT_boolean: - { - bool bData; - vp >> bData; - return SetGlobalVariables(sPropName, JS_GLOBALDATA_TYPE_BOOLEAN, 0, bData, "", v8::Local(), FALSE); - } - case VT_string: - { - CFX_ByteString sData; - vp >> sData; - return SetGlobalVariables(sPropName, JS_GLOBALDATA_TYPE_STRING, 0, false, sData, v8::Local(), FALSE); - } - case VT_object: - { - JSObject pData; - vp >> pData; - return SetGlobalVariables(sPropName, JS_GLOBALDATA_TYPE_OBJECT, 0, false, "", pData, FALSE); - } - case VT_null: - { - return SetGlobalVariables(sPropName, JS_GLOBALDATA_TYPE_NULL, 0, false, "", v8::Local(), FALSE); - } - case VT_undefined: - { - DelProperty(cc, propname, sError); - return TRUE; - } - default: - break; - } +FX_BOOL global_alternate::DoProperty(IFXJS_Context* cc, + const FX_WCHAR* propname, + CJS_PropValue& vp, + CFX_WideString& 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::Local(), FALSE); + } + case VT_boolean: { + bool bData; + vp >> bData; + return SetGlobalVariables(sPropName, JS_GLOBALDATA_TYPE_BOOLEAN, 0, + bData, "", v8::Local(), FALSE); + } + case VT_string: { + CFX_ByteString sData; + vp >> sData; + return SetGlobalVariables(sPropName, JS_GLOBALDATA_TYPE_STRING, 0, + false, sData, v8::Local(), FALSE); + } + case VT_object: { + JSObject pData; + vp >> pData; + return SetGlobalVariables(sPropName, JS_GLOBALDATA_TYPE_OBJECT, 0, + false, "", pData, FALSE); + } + case VT_null: { + return SetGlobalVariables(sPropName, JS_GLOBALDATA_TYPE_NULL, 0, false, + "", v8::Local(), FALSE); + } + case VT_undefined: { + DelProperty(cc, propname, sError); + return TRUE; + } + default: + break; } - else - { - void* pVoid = nullptr; - if (!m_mapGlobal.Lookup(CFX_ByteString::FromUnicode(propname), pVoid)) - { - vp.SetNull(); - return TRUE; - } - if (!pVoid) - { - vp.SetNull(); - return TRUE; - } - js_global_data* pData = (js_global_data*)pVoid; - if (pData->bDeleted) - return TRUE; - - switch (pData->nType) - { - case JS_GLOBALDATA_TYPE_NUMBER: - vp << pData->dData; - return TRUE; - case JS_GLOBALDATA_TYPE_BOOLEAN: - vp << pData->bData; - return TRUE; - case JS_GLOBALDATA_TYPE_STRING: - vp << pData->sData; - return TRUE; - case JS_GLOBALDATA_TYPE_OBJECT: - { - v8::Local obj = v8::Local::New(vp.GetIsolate(),pData->pData); - vp << obj; - return TRUE; - } - case JS_GLOBALDATA_TYPE_NULL: - vp.SetNull(); - return TRUE; - default: - break; - } + } else { + void* pVoid = nullptr; + if (!m_mapGlobal.Lookup(CFX_ByteString::FromUnicode(propname), pVoid)) { + vp.SetNull(); + return TRUE; } - return FALSE; -} - -FX_BOOL global_alternate::setPersistent(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - CJS_Context* pContext = static_cast(cc); - if (params.size() != 2) - { - sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); - return FALSE; + if (!pVoid) { + vp.SetNull(); + return TRUE; } + js_global_data* pData = (js_global_data*)pVoid; + if (pData->bDeleted) + return TRUE; - CFX_ByteString sName = params[0].ToCFXByteString(); - - js_global_data* pData = NULL; - if (m_mapGlobal.Lookup(sName, (void*&)pData)) - { - if (pData && !pData->bDeleted) - { - pData->bPersistent = params[1].ToBool(); - return TRUE; - } + switch (pData->nType) { + case JS_GLOBALDATA_TYPE_NUMBER: + vp << pData->dData; + return TRUE; + case JS_GLOBALDATA_TYPE_BOOLEAN: + vp << pData->bData; + return TRUE; + case JS_GLOBALDATA_TYPE_STRING: + vp << pData->sData; + return TRUE; + case JS_GLOBALDATA_TYPE_OBJECT: { + v8::Local obj = + v8::Local::New(vp.GetIsolate(), pData->pData); + vp << obj; + return TRUE; + } + case JS_GLOBALDATA_TYPE_NULL: + vp.SetNull(); + return TRUE; + default: + break; } - - sError = JSGetStringFromID(pContext, IDS_STRING_JSNOGLOBAL); - return FALSE; + } + return FALSE; } -void global_alternate::UpdateGlobalPersistentVariables() -{ - ASSERT(m_pGlobalData != NULL); - - for (int i=0,sz=m_pGlobalData->GetSize(); iGetAt(i); - ASSERT(pData != NULL); - - switch (pData->data.nType) - { - case JS_GLOBALDATA_TYPE_NUMBER: - SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_NUMBER, pData->data.dData, false, "", v8::Local(), pData->bPersistent == 1); - JS_PutObjectNumber(NULL,(JSFXObject)(*m_pJSObject), - pData->data.sKey.UTF8Decode().c_str(), pData->data.dData); - break; - case JS_GLOBALDATA_TYPE_BOOLEAN: - SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_BOOLEAN, 0, (bool)(pData->data.bData == 1), "", v8::Local(), pData->bPersistent == 1); - JS_PutObjectBoolean(NULL,(JSFXObject)(*m_pJSObject), - pData->data.sKey.UTF8Decode().c_str(), (bool)(pData->data.bData == 1)); - break; - case JS_GLOBALDATA_TYPE_STRING: - SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_STRING, 0, false, pData->data.sData, v8::Local(), pData->bPersistent == 1); - JS_PutObjectString(NULL, (JSFXObject)(*m_pJSObject), - pData->data.sKey.UTF8Decode().c_str(), - pData->data.sData.UTF8Decode().c_str()); - break; - case JS_GLOBALDATA_TYPE_OBJECT: - { - IJS_Runtime* pRuntime = JS_GetRuntime((JSFXObject)(*m_pJSObject)); - v8::Local pObj = JS_NewFxDynamicObj(pRuntime, NULL, -1); +FX_BOOL global_alternate::setPersistent(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + CJS_Context* pContext = static_cast(cc); + if (params.size() != 2) { + sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR); + return FALSE; + } - PutObjectProperty(pObj, &pData->data); + CFX_ByteString sName = params[0].ToCFXByteString(); - 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().c_str(), (JSObject)pObj); - } - break; - case JS_GLOBALDATA_TYPE_NULL: - SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_NULL, 0, false, "", v8::Local(), pData->bPersistent == 1); - JS_PutObjectNull(NULL,(JSFXObject)(*m_pJSObject), - pData->data.sKey.UTF8Decode().c_str()); - break; - } + js_global_data* pData = NULL; + if (m_mapGlobal.Lookup(sName, (void*&)pData)) { + if (pData && !pData->bDeleted) { + pData->bPersistent = params[1].ToBool(); + return TRUE; } -} + } -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, (void*&)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::Local obj = v8::Local::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; - } - } - } - } + sError = JSGetStringFromID(pContext, IDS_STRING_JSNOGLOBAL); + return FALSE; } -void global_alternate::ObjectToArray(v8::Local pObj, CJS_GlobalVariableArray& array) -{ - v8::Local context = pObj->CreationContext(); - v8::Isolate* isolate = context->GetIsolate(); - v8::Local pKeyList = JS_GetObjectElementNames(isolate, pObj); - int nObjElements = pKeyList->Length(); +void global_alternate::UpdateGlobalPersistentVariables() { + ASSERT(m_pGlobalData != NULL); - for (int i=0; iGetSize(); i < sz; i++) { + CJS_GlobalData_Element* pData = m_pGlobalData->GetAt(i); + ASSERT(pData != NULL); - v8::Local v = JS_GetObjectElement(isolate, pObj, ws.c_str()); - 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(isolate, 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(isolate, v); - array.Add(pObjElement); - } - break; - case VT_string: - { - CFX_ByteString sValue = CJS_Value(isolate, v, VT_string).ToCFXByteString(); - 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(isolate, 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; - } + switch (pData->data.nType) { + case JS_GLOBALDATA_TYPE_NUMBER: + SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_NUMBER, + pData->data.dData, false, "", + v8::Local(), pData->bPersistent == 1); + JS_PutObjectNumber(NULL, (JSFXObject)(*m_pJSObject), + pData->data.sKey.UTF8Decode().c_str(), + pData->data.dData); + break; + case JS_GLOBALDATA_TYPE_BOOLEAN: + SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_BOOLEAN, 0, + (bool)(pData->data.bData == 1), "", + v8::Local(), pData->bPersistent == 1); + JS_PutObjectBoolean(NULL, (JSFXObject)(*m_pJSObject), + pData->data.sKey.UTF8Decode().c_str(), + (bool)(pData->data.bData == 1)); + break; + case JS_GLOBALDATA_TYPE_STRING: + SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_STRING, 0, + false, pData->data.sData, v8::Local(), + pData->bPersistent == 1); + JS_PutObjectString(NULL, (JSFXObject)(*m_pJSObject), + pData->data.sKey.UTF8Decode().c_str(), + pData->data.sData.UTF8Decode().c_str()); + break; + case JS_GLOBALDATA_TYPE_OBJECT: { + IJS_Runtime* pRuntime = JS_GetRuntime((JSFXObject)(*m_pJSObject)); + v8::Local pObj = JS_NewFxDynamicObj(pRuntime, NULL, -1); + + PutObjectProperty(pObj, &pData->data); + + 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().c_str(), + (JSObject)pObj); + } break; + case JS_GLOBALDATA_TYPE_NULL: + SetGlobalVariables(pData->data.sKey, JS_GLOBALDATA_TYPE_NULL, 0, false, + "", v8::Local(), + pData->bPersistent == 1); + JS_PutObjectNull(NULL, (JSFXObject)(*m_pJSObject), + pData->data.sKey.UTF8Decode().c_str()); + break; } + } } -void global_alternate::PutObjectProperty(v8::Local pObj, CJS_KeyValue* pData) -{ - ASSERT(pData != NULL); - - for (int i=0,sz=pData->objData.Count(); iobjData.GetAt(i); - ASSERT(pObjData != NULL); +void global_alternate::CommitGlobalPersisitentVariables() { + ASSERT(m_pGlobalData != NULL); - switch (pObjData->nType) - { - case JS_GLOBALDATA_TYPE_NUMBER: - JS_PutObjectNumber(NULL,(JSObject)pObj, pObjData->sKey.UTF8Decode().c_str(), pObjData->dData); + FX_POSITION pos = m_mapGlobal.GetStartPosition(); + while (pos) { + CFX_ByteString name; + js_global_data* pData = NULL; + m_mapGlobal.GetNextAssoc(pos, name, (void*&)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: - JS_PutObjectBoolean(NULL,(JSObject)pObj, pObjData->sKey.UTF8Decode().c_str(), (bool)(pObjData->bData == 1)); + case JS_GLOBALDATA_TYPE_BOOLEAN: + m_pGlobalData->SetGlobalVariableBoolean(name, pData->bData); + m_pGlobalData->SetGlobalVariablePersistent(name, + pData->bPersistent); break; - case JS_GLOBALDATA_TYPE_STRING: - JS_PutObjectString(NULL,(JSObject)pObj, pObjData->sKey.UTF8Decode().c_str(), pObjData->sData.UTF8Decode().c_str()); + case JS_GLOBALDATA_TYPE_STRING: + m_pGlobalData->SetGlobalVariableString(name, pData->sData); + m_pGlobalData->SetGlobalVariablePersistent(name, + pData->bPersistent); break; - case JS_GLOBALDATA_TYPE_OBJECT: + case JS_GLOBALDATA_TYPE_OBJECT: + // if (pData->pData) { - IJS_Runtime* pRuntime = JS_GetRuntime((JSFXObject)(*m_pJSObject)); - v8::Local pNewObj = JS_NewFxDynamicObj(pRuntime, NULL, -1); - PutObjectProperty(pNewObj, pObjData); - JS_PutObjectObject(NULL, (JSObject)pObj, pObjData->sKey.UTF8Decode().c_str(), (JSObject)pNewObj); + CJS_GlobalVariableArray array; + v8::Local obj = v8::Local::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: - JS_PutObjectNull(NULL,(JSObject)pObj, pObjData->sKey.UTF8Decode().c_str()); + case JS_GLOBALDATA_TYPE_NULL: + m_pGlobalData->SetGlobalVariableNull(name); + m_pGlobalData->SetGlobalVariablePersistent(name, + pData->bPersistent); 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, (void*&)pData); - delete pData; +void global_alternate::ObjectToArray(v8::Local pObj, + CJS_GlobalVariableArray& array) { + v8::Local context = pObj->CreationContext(); + v8::Isolate* isolate = context->GetIsolate(); + v8::Local pKeyList = JS_GetObjectElementNames(isolate, pObj); + int nObjElements = pKeyList->Length(); + + for (int i = 0; i < nObjElements; i++) { + CFX_WideString ws = + JS_ToString(isolate, JS_GetArrayElement(isolate, pKeyList, i)); + CFX_ByteString sKey = ws.UTF8Encode(); + + v8::Local v = JS_GetObjectElement(isolate, pObj, ws.c_str()); + 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(isolate, 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(isolate, v); + array.Add(pObjElement); + } break; + case VT_string: { + CFX_ByteString sValue = + CJS_Value(isolate, v, VT_string).ToCFXByteString(); + 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(isolate, 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; } - - m_mapGlobal.RemoveAll(); + } } +void global_alternate::PutObjectProperty(v8::Local pObj, + CJS_KeyValue* pData) { + ASSERT(pData != NULL); -FX_BOOL global_alternate::SetGlobalVariables(const FX_CHAR* propname, int nType, - double dData, bool bData, const CFX_ByteString& sData, JSObject pData, bool bDefaultPersistent) -{ - if (propname == NULL) return FALSE; + for (int i = 0, sz = pData->objData.Count(); i < sz; i++) { + CJS_KeyValue* pObjData = pData->objData.GetAt(i); + ASSERT(pObjData != NULL); - js_global_data* pTemp = NULL; - m_mapGlobal.Lookup(propname, (void*&)pTemp); + switch (pObjData->nType) { + case JS_GLOBALDATA_TYPE_NUMBER: + JS_PutObjectNumber(NULL, (JSObject)pObj, + pObjData->sKey.UTF8Decode().c_str(), + pObjData->dData); + break; + case JS_GLOBALDATA_TYPE_BOOLEAN: + JS_PutObjectBoolean(NULL, (JSObject)pObj, + pObjData->sKey.UTF8Decode().c_str(), + (bool)(pObjData->bData == 1)); + break; + case JS_GLOBALDATA_TYPE_STRING: + JS_PutObjectString(NULL, (JSObject)pObj, + pObjData->sKey.UTF8Decode().c_str(), + pObjData->sData.UTF8Decode().c_str()); + break; + case JS_GLOBALDATA_TYPE_OBJECT: { + IJS_Runtime* pRuntime = JS_GetRuntime((JSFXObject)(*m_pJSObject)); + v8::Local pNewObj = JS_NewFxDynamicObj(pRuntime, NULL, -1); + PutObjectProperty(pNewObj, pObjData); + JS_PutObjectObject(NULL, (JSObject)pObj, + pObjData->sKey.UTF8Decode().c_str(), + (JSObject)pNewObj); + } break; + case JS_GLOBALDATA_TYPE_NULL: + JS_PutObjectNull(NULL, (JSObject)pObj, + pObjData->sKey.UTF8Decode().c_str()); + break; + } + } +} - if (pTemp) - { - if (pTemp->bDeleted || pTemp->nType != nType) - { - pTemp->dData = 0; - pTemp->bData = 0; - pTemp->sData = ""; - pTemp->nType = nType; - } +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, (void*&)pData); + delete pData; + } - pTemp->bDeleted = FALSE; + m_mapGlobal.RemoveAll(); +} - 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; - } +FX_BOOL global_alternate::SetGlobalVariables(const FX_CHAR* propname, + int nType, + double dData, + bool bData, + const CFX_ByteString& sData, + JSObject pData, + bool bDefaultPersistent) { + if (propname == NULL) + return FALSE; - return TRUE; - } + js_global_data* pTemp = NULL; + m_mapGlobal.Lookup(propname, (void*&)pTemp); - js_global_data* pNewData = NULL; + if (pTemp) { + if (pTemp->bDeleted || pTemp->nType != nType) { + pTemp->dData = 0; + pTemp->bData = 0; + pTemp->sData = ""; + pTemp->nType = nType; + } - 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; - } + 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: + default: return FALSE; } - m_mapGlobal.SetAt(propname, (void*)pNewData); - 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, (void*)pNewData); + + return TRUE; } -FXJSVALUETYPE GET_VALUE_TYPE(v8::Local p) -{ +FXJSVALUETYPE GET_VALUE_TYPE(v8::Local p) { const unsigned int nHash = JS_CalcHash(JS_GetTypeof(p)); if (nHash == JSCONST_nUndefHash) diff --git a/fpdfsdk/src/javascript/report.cpp b/fpdfsdk/src/javascript/report.cpp index 1478feb1fa..732ae6d20e 100644 --- a/fpdfsdk/src/javascript/report.cpp +++ b/fpdfsdk/src/javascript/report.cpp @@ -20,30 +20,28 @@ BEGIN_JS_STATIC_PROP(CJS_Report) END_JS_STATIC_PROP() BEGIN_JS_STATIC_METHOD(CJS_Report) - JS_STATIC_METHOD_ENTRY(save) - JS_STATIC_METHOD_ENTRY(writeText) +JS_STATIC_METHOD_ENTRY(save) +JS_STATIC_METHOD_ENTRY(writeText) END_JS_STATIC_METHOD() IMPLEMENT_JS_CLASS(CJS_Report, Report) -Report::Report(CJS_Object* pJSObject) : CJS_EmbedObj(pJSObject) -{ +Report::Report(CJS_Object* pJSObject) : CJS_EmbedObj(pJSObject) {} -} - -Report::~Report() -{ - -} +Report::~Report() {} -FX_BOOL Report::writeText(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ +FX_BOOL Report::writeText(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { // Unsafe, not supported. return TRUE; } -FX_BOOL Report::save(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ +FX_BOOL Report::save(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { // Unsafe, not supported. return TRUE; } diff --git a/fpdfsdk/src/javascript/resource.cpp b/fpdfsdk/src/javascript/resource.cpp index 4375da3ff7..5b6bd48703 100644 --- a/fpdfsdk/src/javascript/resource.cpp +++ b/fpdfsdk/src/javascript/resource.cpp @@ -6,61 +6,59 @@ #include "../../include/javascript/resource.h" -CFX_WideString JSGetStringFromID(CJS_Context* pContext, FX_UINT id) -{ - switch (id) - { +CFX_WideString JSGetStringFromID(CJS_Context* pContext, FX_UINT id) { + switch (id) { case IDS_STRING_JSALERT: - return L"Alert"; + return L"Alert"; case IDS_STRING_JSPARAMERROR: - return L"Incorrect number of parameters passed to function."; + return L"Incorrect number of parameters passed to function."; case IDS_STRING_JSAFNUMBER_KEYSTROKE: - return L"The input value is invalid."; + return L"The input value is invalid."; case IDS_STRING_JSPARAM_TOOLONG: - return L"The input value is too long."; + return L"The input value is too long."; case IDS_STRING_JSPARSEDATE: - return L"The input value can't be parsed as a valid date/time (%s)."; + return L"The input value can't be parsed as a valid date/time (%s)."; case IDS_STRING_JSRANGE1: - return L"The input value must be greater than or equal to %s" - L" and less than or equal to %s."; + return L"The input value must be greater than or equal to %s" + L" and less than or equal to %s."; case IDS_STRING_JSRANGE2: - return L"The input value must be greater than or equal to %s."; + return L"The input value must be greater than or equal to %s."; case IDS_STRING_JSRANGE3: - return L"The input value must be less than or equal to %s."; + return L"The input value must be less than or equal to %s."; case IDS_STRING_NOTSUPPORT: - return L"Operation not supported."; + return L"Operation not supported."; case IDS_STRING_JSBUSY: - return L"System is busy."; + return L"System is busy."; case IDS_STRING_JSEVENT: - return L"Duplicate formfield event found."; + return L"Duplicate formfield event found."; case IDS_STRING_RUN: - return L"Script ran successfully."; + return L"Script ran successfully."; case IDS_STRING_JSPRINT1: - return L"The second parameter can't be converted to a Date."; + return L"The second parameter can't be converted to a Date."; case IDS_STRING_JSPRINT2: - return L"The second parameter is an invalid Date!"; + return L"The second parameter is an invalid Date!"; case IDS_STRING_JSNOGLOBAL: - return L"Global value not found."; + return L"Global value not found."; case IDS_STRING_JSREADONLY: - return L"Cannot assign to readonly property."; + return L"Cannot assign to readonly property."; case IDS_STRING_JSTYPEERROR: - return L"Incorrect parameter type."; + return L"Incorrect parameter type."; case IDS_STRING_JSVALUEERROR: - return L"Incorrect parameter value."; + return L"Incorrect parameter value."; default: - return L""; - } + return L""; + } } CFX_WideString JSFormatErrorString(const char* class_name, const char* property_name, const CFX_WideString& details) { - CFX_WideString result = CFX_WideString::FromLocal(class_name); - if (property_name) { - result += L"."; - result += CFX_WideString::FromLocal(property_name); - } - result += L": "; - result += details; - return result; + CFX_WideString result = CFX_WideString::FromLocal(class_name); + if (property_name) { + result += L"."; + result += CFX_WideString::FromLocal(property_name); + } + result += L": "; + result += details; + return result; } diff --git a/fpdfsdk/src/javascript/util.cpp b/fpdfsdk/src/javascript/util.cpp index 4083ed58da..858af0079c 100644 --- a/fpdfsdk/src/javascript/util.cpp +++ b/fpdfsdk/src/javascript/util.cpp @@ -16,19 +16,18 @@ #include "../../include/javascript/JS_EventHandler.h" #include "../../include/javascript/JS_Runtime.h" -#if _FX_OS_ == _FX_ANDROID_ +#if _FX_OS_ == _FX_ANDROID_ #include #endif -static v8::Isolate* GetIsolate(IFXJS_Context* cc) -{ - CJS_Context* pContext = (CJS_Context *)cc; - ASSERT(pContext != NULL); +static v8::Isolate* GetIsolate(IFXJS_Context* cc) { + CJS_Context* pContext = (CJS_Context*)cc; + ASSERT(pContext != NULL); - CJS_Runtime* pRuntime = pContext->GetJSRuntime(); - ASSERT(pRuntime != NULL); + CJS_Runtime* pRuntime = pContext->GetJSRuntime(); + ASSERT(pRuntime != NULL); - return pRuntime->GetIsolate(); + return pRuntime->GetIsolate(); } BEGIN_JS_STATIC_CONST(CJS_Util) @@ -38,350 +37,235 @@ BEGIN_JS_STATIC_PROP(CJS_Util) END_JS_STATIC_PROP() BEGIN_JS_STATIC_METHOD(CJS_Util) - JS_STATIC_METHOD_ENTRY(printd) - JS_STATIC_METHOD_ENTRY(printf) - JS_STATIC_METHOD_ENTRY(printx) - JS_STATIC_METHOD_ENTRY(scand) - JS_STATIC_METHOD_ENTRY(byteToChar) +JS_STATIC_METHOD_ENTRY(printd) +JS_STATIC_METHOD_ENTRY(printf) +JS_STATIC_METHOD_ENTRY(printx) +JS_STATIC_METHOD_ENTRY(scand) +JS_STATIC_METHOD_ENTRY(byteToChar) END_JS_STATIC_METHOD() -IMPLEMENT_JS_CLASS(CJS_Util,util) +IMPLEMENT_JS_CLASS(CJS_Util, util) -util::util(CJS_Object *pJSObject) : CJS_EmbedObj(pJSObject) -{ -} - -util::~util(void) -{ -} +util::util(CJS_Object* pJSObject) : CJS_EmbedObj(pJSObject) {} +util::~util(void) {} -struct stru_TbConvert -{ - const FX_WCHAR* lpszJSMark; - const FX_WCHAR* lpszCppMark; +struct stru_TbConvert { + const FX_WCHAR* lpszJSMark; + const FX_WCHAR* lpszCppMark; }; const stru_TbConvert fcTable[] = { - { L"mmmm", L"%B" }, - { L"mmm", L"%b" }, - { L"mm", L"%m" }, + {L"mmmm", L"%B"}, + {L"mmm", L"%b"}, + {L"mm", L"%m"}, //"m" - { L"dddd", L"%A" }, - { L"ddd", L"%a" }, - { L"dd", L"%d" }, + {L"dddd", L"%A"}, + {L"ddd", L"%a"}, + {L"dd", L"%d"}, //"d", "%w", - { L"yyyy", L"%Y" }, - { L"yy", L"%y" }, - { L"HH", L"%H" }, + {L"yyyy", L"%Y"}, + {L"yy", L"%y"}, + {L"HH", L"%H"}, //"H" - { L"hh", L"%I" }, + {L"hh", L"%I"}, //"h" - { L"MM", L"%M" }, + {L"MM", L"%M"}, //"M" - { L"ss", L"%S" }, + {L"ss", L"%S"}, //"s - { L"TT", L"%p" }, - //"t" + {L"TT", L"%p"}, +//"t" #if defined(_WIN32) - { L"tt", L"%p" }, - { L"h", L"%#I" }, + {L"tt", L"%p"}, + {L"h", L"%#I"}, #else - { L"tt", L"%P" }, - { L"h", L"%l" }, + {L"tt", L"%P"}, + {L"h", L"%l"}, #endif }; -#define UTIL_INT 0 -#define UTIL_DOUBLE 1 -#define UTIL_STRING 2 - -int util::ParstDataType(std::wstring* sFormat) -{ - bool bPercent = FALSE; - for (size_t i = 0; i < sFormat->length(); ++i) - { - wchar_t c = (*sFormat)[i]; - if (c == L'%') - { - bPercent = true; - continue; - } +#define UTIL_INT 0 +#define UTIL_DOUBLE 1 +#define UTIL_STRING 2 + +int util::ParstDataType(std::wstring* sFormat) { + bool bPercent = FALSE; + for (size_t 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; - } - if (c == L'e' || c == L'E' || c == L'f' || c == L'g' || c == L'G') - { - return UTIL_DOUBLE; - } - 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; - } - if (c == L'.' || c == L'+' || c == L'-' || c == L'#' || c == L' ' || CJS_PublicMethods::IsDigit(c)) - { - continue; - } - break; - } + 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; + } + if (c == L'e' || c == L'E' || c == L'f' || c == L'g' || c == L'G') { + return UTIL_DOUBLE; + } + 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; + } + if (c == L'.' || c == L'+' || c == L'-' || c == L'#' || c == L' ' || + CJS_PublicMethods::IsDigit(c)) { + continue; + } + break; } + } - return -1; + return -1; } -FX_BOOL util::printf(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - int iSize = params.size(); - if (iSize < 1) - return FALSE; - std::wstring c_ConvChar(params[0].ToCFXWideString().c_str()); - std::vector 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 ; +FX_BOOL util::printf(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + int iSize = params.size(); + if (iSize < 1) + return FALSE; + std::wstring c_ConvChar(params[0].ToCFXWideString().c_str()); + std::vector 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; } - 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; - } + CFX_WideString strSegment; + if (iIndex >= iSize) { + c_strResult += c_strFormat; + continue; + } - switch (ParstDataType(&c_strFormat)) - { - case UTIL_INT: - strSegment.Format(c_strFormat.c_str(), params[iIndex].ToInt()); - break; - case UTIL_DOUBLE: - strSegment.Format(c_strFormat.c_str(), params[iIndex].ToDouble()); - break; - case UTIL_STRING: - strSegment.Format(c_strFormat.c_str(), params[iIndex].ToCFXWideString().c_str()); - break; - default: - strSegment.Format(L"%S", c_strFormat.c_str()); - break; - } - c_strResult += strSegment.GetBuffer(strSegment.GetLength()+1); + switch (ParstDataType(&c_strFormat)) { + case UTIL_INT: + strSegment.Format(c_strFormat.c_str(), params[iIndex].ToInt()); + break; + case UTIL_DOUBLE: + strSegment.Format(c_strFormat.c_str(), params[iIndex].ToDouble()); + break; + case UTIL_STRING: + strSegment.Format(c_strFormat.c_str(), + params[iIndex].ToCFXWideString().c_str()); + break; + default: + strSegment.Format(L"%S", c_strFormat.c_str()); + break; } + c_strResult += strSegment.GetBuffer(strSegment.GetLength() + 1); + } - c_strResult.erase(c_strResult.begin()); - vRet = c_strResult.c_str(); - return TRUE; + c_strResult.erase(c_strResult.begin()); + vRet = c_strResult.c_str(); + return TRUE; } -FX_BOOL util::printd(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - v8::Isolate* isolate = GetIsolate(cc); +FX_BOOL util::printd(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + v8::Isolate* isolate = GetIsolate(cc); - int iSize = params.size(); - if (iSize < 2) - return FALSE; + int iSize = params.size(); + if (iSize < 2) + return FALSE; - CJS_Value p1(isolate); - p1 = params[0]; + 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; - } + 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); + if (!jsDate.IsValidDate()) { + sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPRINT2); + return FALSE; + } + + if (p1.GetType() == VT_number) { + int nFormat = p1.ToInt(); + CFX_WideString swResult; + + switch (nFormat) { + case 0: + swResult.Format(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(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(L"%04d/%02d/%02d %02d:%02d:%02d", jsDate.GetYear(), + jsDate.GetMonth() + 1, jsDate.GetDay(), + jsDate.GetHours(), jsDate.GetMinutes(), + jsDate.GetSeconds()); + break; + default: return FALSE; } - if (p1.GetType() == VT_number) - { - int nFormat = p1.ToInt(); - CFX_WideString swResult; - - switch (nFormat) - { - case 0: - swResult.Format(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(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(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.c_str(); - return TRUE; - } - if (p1.GetType() == VT_string) - { - std::basic_string cFormat = p1.ToCFXWideString().c_str(); - - bool bXFAPicture = false; - if (iSize > 2) - { - bXFAPicture = params[2].ToBool(); - } - - if (bXFAPicture) - { - return FALSE; //currently, it doesn't support XFAPicture. - } - - int iIndex; - for(iIndex = 0;iIndex12?iHour-12:iHour }, - { L"M", iMin }, - { L"s", iSec }, - }; - - for(iIndex = 0;iIndex 0) - { - if (cFormat[iEnd-1] == L'%') - { - iStart = iEnd+1; - continue; - } - } - cFormat.replace(iEnd, FXSYS_wcslen(cTableAd[iIndex].lpszJSMark), tszValue); - iStart = iEnd; - } - } + vRet = swResult.c_str(); + return TRUE; + } + if (p1.GetType() == VT_string) { + std::basic_string cFormat = p1.ToCFXWideString().c_str(); - CFX_WideString strFormat; - wchar_t buf[64] = {}; - strFormat = wcsftime(buf, 64, cFormat.c_str(), &time); - cFormat = buf; - vRet = cFormat.c_str(); - return TRUE; + bool bXFAPicture = false; + if (iSize > 2) { + bXFAPicture = params[2].ToBool(); } - 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. + if (bXFAPicture) { + return FALSE; // currently, it doesn't support XFAPicture. } int iIndex; - for(iIndex = 0;iIndex12?iHour-12:iHour }, - { L"M", iMin }, - { L"s", iSec }, + stru_TbConvertAd cTableAd[] = { + {L"m", iMonth + 1}, {L"d", iDay}, + {L"H", iHour}, {L"h", iHour > 12 ? iHour - 12 : iHour}, + {L"M", iMin}, {L"s", iSec}, }; - //cFormat = strFormat.GetBuffer(strFormat.GetLength()+1); - for(iIndex = 0;iIndex 0) - { - if (cFormat[iEnd-1] == L'%') - { - iStart = iEnd+1; - continue; - } - } - cFormat.replace(iEnd,FXSYS_wcslen(cTableAd[iIndex].lpszJSMark),tszValue); - iStart = iEnd; + for (iIndex = 0; iIndex < sizeof(cTableAd) / sizeof(stru_TbConvertAd); + iIndex++) { + wchar_t tszValue[10]; + CFX_WideString sValue; + sValue.Format(L"%d", cTableAd[iIndex].iValue); + memcpy(tszValue, (wchar_t*)sValue.GetBuffer(sValue.GetLength() + 1), + (sValue.GetLength() + 1) * sizeof(wchar_t)); + + int iStart = 0; + int iEnd; + while ((iEnd = cFormat.find(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; wchar_t buf[64] = {}; strFormat = wcsftime(buf, 64, cFormat.c_str(), &time); cFormat = buf; - cPurpose = cFormat; + vRet = cFormat.c_str(); + return TRUE; + } + return FALSE; } -FX_BOOL util::printx(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - int iSize = params.size(); - if (iSize<2) - return FALSE; - CFX_WideString sFormat = params[0].ToCFXWideString(); - CFX_WideString sSource = params[1].ToCFXWideString(); - std::string cFormat = CFX_ByteString::FromUnicode(sFormat).c_str(); - std::string cSource = CFX_ByteString::FromUnicode(sSource).c_str(); - std::string cDest; - printx(cFormat,cSource,cDest); - vRet = cDest.c_str(); - return TRUE; +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(fcTable[iIndex].lpszJSMark, iStart)) != -1) { + cFormat.replace(iEnd, FXSYS_wcslen(fcTable[iIndex].lpszJSMark), + 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 = {}; + 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 { + const FX_WCHAR* lpszJSMark; + int iValue; + }; + + stru_TbConvertAd cTableAd[] = { + {L"m", iMonth + 1}, {L"d", iDay}, + {L"H", iHour}, {L"h", iHour > 12 ? iHour - 12 : iHour}, + {L"M", iMin}, {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(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(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; + wchar_t buf[64] = {}; + strFormat = wcsftime(buf, 64, cFormat.c_str(), &time); + cFormat = buf; + cPurpose = cFormat; +} + +FX_BOOL util::printx(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + int iSize = params.size(); + if (iSize < 2) + return FALSE; + CFX_WideString sFormat = params[0].ToCFXWideString(); + CFX_WideString sSource = params[1].ToCFXWideString(); + std::string cFormat = CFX_ByteString::FromUnicode(sFormat).c_str(); + std::string cSource = CFX_ByteString::FromUnicode(sSource).c_str(); + 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= '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; - 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 '=': + } + 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; - default: - //cPurpose.push_back(letter); - cPurpose += letter; + } + 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(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - v8::Isolate* isolate = GetIsolate(cc); - int iSize = params.size(); - if (iSize < 2) - return FALSE; - - CFX_WideString sFormat = params[0].ToCFXWideString(); - CFX_WideString sDate = params[1].ToCFXWideString(); - 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(); - } +FX_BOOL util::scand(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + v8::Isolate* isolate = GetIsolate(cc); + int iSize = params.size(); + if (iSize < 2) + return FALSE; - return TRUE; + CFX_WideString sFormat = params[0].ToCFXWideString(); + CFX_WideString sDate = params[1].ToCFXWideString(); + 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; } -int64_t FX_atoi64(const char *nptr) -{ - int c; /* current char */ - int64_t total; /* current total */ - int sign; /* if '-', then negative, otherwise positive */ +int64_t FX_atoi64(const char* nptr) { + int c; /* current char */ + int64_t total; /* current total */ + int sign; /* if '-', then negative, otherwise positive */ - /* skip whitespace */ - while ( isspace((int)(unsigned char)*nptr) ) - ++nptr; + /* 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 */ + c = (int)(unsigned char)*nptr++; + sign = c; /* save sign indication */ + if (c == '-' || c == '+') + c = (int)(unsigned char)*nptr++; /* skip sign */ - total = 0; + total = 0; - while (isdigit(c)) { - total = 10 * total + (c - '0'); /* accumulate digit */ - c = (int)(unsigned char)*nptr++; /* get next char */ - } + while (isdigit(c)) { + total = 10 * total + (c - '0'); /* accumulate digit */ + c = (int)(unsigned char)*nptr++; /* get next char */ + } - return sign == '-' ? -total : total; + return sign == '-' ? -total : total; } -FX_BOOL util::byteToChar(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value& vRet, CFX_WideString& sError) -{ - int iSize = params.size(); - if (iSize == 0) - return FALSE; - int nByte = params[0].ToInt(); - unsigned char cByte = (unsigned char)nByte; - CFX_WideString csValue; - csValue.Format(L"%c", cByte); - vRet = csValue.c_str(); - return TRUE; +FX_BOOL util::byteToChar(IFXJS_Context* cc, + const CJS_Parameters& params, + CJS_Value& vRet, + CFX_WideString& sError) { + int iSize = params.size(); + if (iSize == 0) + return FALSE; + int nByte = params[0].ToInt(); + unsigned char cByte = (unsigned char)nByte; + CFX_WideString csValue; + csValue.Format(L"%c", cByte); + vRet = csValue.c_str(); + return TRUE; } -- cgit v1.2.3