summaryrefslogtreecommitdiff
path: root/fpdfsdk/src/fpdfxfa
diff options
context:
space:
mode:
Diffstat (limited to 'fpdfsdk/src/fpdfxfa')
-rw-r--r--fpdfsdk/src/fpdfxfa/fpdfxfa_app.cpp640
-rw-r--r--fpdfsdk/src/fpdfxfa/fpdfxfa_doc.cpp1476
-rw-r--r--fpdfsdk/src/fpdfxfa/fpdfxfa_page.cpp276
-rw-r--r--fpdfsdk/src/fpdfxfa/fpdfxfa_util.cpp96
4 files changed, 2488 insertions, 0 deletions
diff --git a/fpdfsdk/src/fpdfxfa/fpdfxfa_app.cpp b/fpdfsdk/src/fpdfxfa/fpdfxfa_app.cpp
new file mode 100644
index 0000000000..7abd2741a0
--- /dev/null
+++ b/fpdfsdk/src/fpdfxfa/fpdfxfa_app.cpp
@@ -0,0 +1,640 @@
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/fsdk_define.h"
+#include "../../include/fpdfformfill.h"
+#include "../../include/fsdk_mgr.h"
+#include "../../include/fpdfxfa/fpdfxfa_doc.h"
+#include "../../include/fpdfxfa/fpdfxfa_util.h"
+#include "../../include/jsapi/fxjs_v8.h"
+#include "../../include/javascript/IJavaScript.h"
+#include "../../include/fpdfxfa/fpdfxfa_app.h"
+CPDFXFA_App* CPDFXFA_App::m_pApp = NULL;
+
+CPDFXFA_App* FPDFXFA_GetApp()
+{
+ if (!CPDFXFA_App::m_pApp)
+ CPDFXFA_App::m_pApp = FX_NEW CPDFXFA_App();
+
+ return CPDFXFA_App::m_pApp;
+}
+
+void FPDFXFA_ReleaseApp()
+{
+ if (CPDFXFA_App::m_pApp)
+ delete CPDFXFA_App::m_pApp;
+ CPDFXFA_App::m_pApp = NULL;
+}
+
+CJS_RuntimeFactory* g_GetJSRuntimeFactory()
+{
+ static CJS_RuntimeFactory g_JSRuntimeFactory;
+ return &g_JSRuntimeFactory;
+}
+
+CPDFXFA_App::CPDFXFA_App() :
+ m_pXFAApp(NULL),
+ m_pFontMgr(NULL),
+ m_hJSERuntime(NULL),
+ //m_pJSRuntime(NULL),
+ //m_pEnv(NULL),
+ m_csAppType(JS_STR_VIEWERTYPE_STANDARD)
+{
+ m_pJSRuntimeFactory = NULL;
+ m_pJSRuntimeFactory = g_GetJSRuntimeFactory();
+ m_pJSRuntimeFactory->AddRef();
+ m_pEnvList.RemoveAll();
+ m_bInitRuntime = FALSE;
+}
+//IFXJS_Runtime* CPDFXFA_App::GetJSRuntime()
+//{
+// FXSYS_assert(m_pJSRuntimeFactory);
+// if(!m_pJSRuntime)
+// m_pJSRuntime = m_pJSRuntimeFactory->NewJSRuntime(this);
+// return m_pJSRuntime;
+//}
+
+CPDFXFA_App::~CPDFXFA_App()
+{
+ if (m_pFontMgr)
+ {
+ m_pFontMgr->Release();
+ m_pFontMgr = NULL;
+ }
+
+ if (m_pXFAApp)
+ {
+ m_pXFAApp->Release();
+ m_pXFAApp = NULL;
+ }
+
+ //if (m_pJSRuntime && m_pJSRuntimeFactory)
+ // m_pJSRuntimeFactory->DeleteJSRuntime(m_pJSRuntime);
+ m_pJSRuntimeFactory->Release();
+
+
+ if (m_hJSERuntime)
+ {
+ FXJSE_Runtime_Release(m_hJSERuntime);
+ m_hJSERuntime = NULL;
+ }
+
+ FXJSE_Finalize();
+
+ BC_Library_Destory();
+}
+
+FX_BOOL CPDFXFA_App::Initialize()
+{
+ BC_Library_Init();
+
+ FXJSE_Initialize();
+ m_hJSERuntime = FXJSE_Runtime_Create();
+
+ if (!m_hJSERuntime)
+ return FALSE;
+
+ //m_pJSRuntime = m_pJSRuntimeFactory->NewJSRuntime(this);
+
+ m_pXFAApp = IXFA_App::Create(this);
+ if (!m_pXFAApp)
+ return FALSE;
+
+ m_pFontMgr = XFA_GetDefaultFontMgr();
+ if (!m_pFontMgr)
+ return FALSE;
+
+ m_pXFAApp->SetDefaultFontMgr(m_pFontMgr);
+
+ return TRUE;
+}
+
+FX_BOOL CPDFXFA_App::AddFormFillEnv(CPDFDoc_Environment* pEnv)
+{
+ if (!pEnv) return FALSE;
+
+ m_pEnvList.Add(pEnv);
+ return TRUE;
+}
+
+FX_BOOL CPDFXFA_App::RemoveFormFillEnv(CPDFDoc_Environment* pEnv)
+{
+ if (!pEnv) return FALSE;
+
+ int nFind = m_pEnvList.Find(pEnv);
+ if (nFind != -1) {
+ m_pEnvList.RemoveAt(nFind);
+ return TRUE;
+ }
+
+ return FALSE;
+}
+void CPDFXFA_App::ReleaseRuntime()
+{
+ v8::Persistent<v8::Context> context;
+ JS_ReleaseRuntime((IJS_Runtime*)m_hJSERuntime, context);
+}
+
+void CPDFXFA_App::GetAppType(CFX_WideString &wsAppType)
+{
+ wsAppType = m_csAppType;
+}
+
+void CPDFXFA_App::GetAppName(CFX_WideString& wsName)
+{
+ CPDFDoc_Environment* pEnv = m_pEnvList.GetAt(0);
+ if (pEnv)
+ {
+ wsName = pEnv->FFI_GetAppName();
+ }
+}
+
+void CPDFXFA_App::SetAppType(FX_WSTR wsAppType)
+{
+ m_csAppType = wsAppType;
+}
+
+void CPDFXFA_App::GetLanguage(CFX_WideString &wsLanguage)
+{
+ CPDFDoc_Environment* pEnv = m_pEnvList.GetAt(0);
+ if (pEnv)
+ {
+ wsLanguage = pEnv->FFI_GetLanguage();
+ }
+}
+
+void CPDFXFA_App::GetPlatform(CFX_WideString &wsPlatform)
+{
+ CPDFDoc_Environment* pEnv = m_pEnvList.GetAt(0);
+ if (pEnv)
+ {
+ wsPlatform = pEnv->FFI_GetPlatform();
+ }
+}
+
+void CPDFXFA_App::GetVariation(CFX_WideString &wsVariation)
+{
+ wsVariation = JS_STR_VIEWERVARIATION;
+}
+
+void CPDFXFA_App::GetVersion(CFX_WideString &wsVersion)
+{
+ wsVersion = JS_STR_VIEWERVERSION_XFA;
+}
+
+void CPDFXFA_App::Beep(FX_DWORD dwType)
+{
+ CPDFDoc_Environment* pEnv = m_pEnvList.GetAt(0);
+ if (pEnv)
+ {
+ pEnv->JS_appBeep(dwType);
+ }
+}
+
+FX_INT32 CPDFXFA_App::MsgBox(FX_WSTR wsMessage, FX_WSTR wsTitle, FX_DWORD dwIconType, FX_DWORD dwButtonType)
+{
+ CPDFDoc_Environment* pEnv = m_pEnvList.GetAt(0);
+ if (!pEnv)
+ return -1;
+
+ FX_DWORD iconType = 0;
+ int iButtonType = 0;
+ switch (dwIconType)
+ {
+ case XFA_MBICON_Error:
+ iconType |= 0;
+ break;
+ case XFA_MBICON_Warning:
+ iconType |= 1;
+ break;
+ case XFA_MBICON_Question:
+ iconType |= 2;
+ break;
+ case XFA_MBICON_Status:
+ iconType |= 3;
+ break;
+ }
+ switch (dwButtonType)
+ {
+ case XFA_MB_OK:
+ iButtonType |= 0;
+ break;
+ case XFA_MB_OKCancel:
+ iButtonType |= 1;
+ break;
+ case XFA_MB_YesNo:
+ iButtonType |= 2;
+ break;
+ case XFA_MB_YesNoCancel:
+ iButtonType |= 3;
+ break;
+ }
+ FX_INT32 iRet = pEnv->JS_appAlert(wsMessage.GetPtr(), wsTitle.GetPtr(), iButtonType, iconType);
+ switch (iRet)
+ {
+ case 1:
+ return XFA_IDOK;
+ case 2:
+ return XFA_IDCancel;
+ case 3:
+ return XFA_IDNo;
+ case 4:
+ return XFA_IDYes;
+ }
+ return XFA_IDYes;
+}
+
+void CPDFXFA_App::Response(CFX_WideString &wsAnswer, FX_WSTR wsQuestion, FX_WSTR wsTitle, FX_WSTR wsDefaultAnswer, FX_BOOL bMark)
+{
+ CPDFDoc_Environment* pEnv = m_pEnvList.GetAt(0);
+ if (pEnv)
+ {
+ int nLength = 2048;
+ char* pBuff = new char[nLength];
+ nLength = pEnv->JS_appResponse(wsQuestion.GetPtr(), wsTitle.GetPtr(), wsDefaultAnswer.GetPtr(), NULL, bMark, pBuff, nLength);
+ if(nLength > 0)
+ {
+ nLength = nLength>2046?2046:nLength;
+ pBuff[nLength] = 0;
+ pBuff[nLength+1] = 0;
+ wsAnswer = CFX_WideString::FromUTF16LE((unsigned short*)pBuff, nLength);
+ }
+ delete[] pBuff;
+ }
+}
+
+FX_INT32 CPDFXFA_App::GetCurDocumentInBatch()
+{
+ CPDFDoc_Environment* pEnv = m_pEnvList.GetAt(0);
+ if (pEnv)
+ {
+ return pEnv->FFI_GetCurDocument();
+ }
+ return 0;
+}
+
+FX_INT32 CPDFXFA_App::GetDocumentCountInBatch()
+{
+ CPDFDoc_Environment* pEnv = m_pEnvList.GetAt(0);
+ if (pEnv)
+ {
+ return pEnv->FFI_GetDocumentCount();
+ }
+
+ return 0;
+}
+
+IFX_FileRead* CPDFXFA_App::DownloadURL(FX_WSTR wsURL)
+{
+ CPDFDoc_Environment* pEnv = m_pEnvList.GetAt(0);
+ if (pEnv)
+ {
+ return pEnv->FFI_DownloadFromURL(wsURL.GetPtr());
+ }
+ return NULL;
+}
+
+FX_BOOL CPDFXFA_App::PostRequestURL(FX_WSTR wsURL, FX_WSTR wsData, FX_WSTR wsContentType,
+ FX_WSTR wsEncode, FX_WSTR wsHeader, CFX_WideString &wsResponse)
+{
+ CPDFDoc_Environment* pEnv = m_pEnvList.GetAt(0);
+ if (pEnv)
+ {
+ wsResponse = pEnv->FFI_PostRequestURL(wsURL.GetPtr(), wsData.GetPtr(), wsContentType.GetPtr(), wsEncode.GetPtr(), wsHeader.GetPtr());
+ return TRUE;
+ }
+ return FALSE;
+}
+
+FX_BOOL CPDFXFA_App::PutRequestURL(FX_WSTR wsURL, FX_WSTR wsData, FX_WSTR wsEncode)
+{
+ CPDFDoc_Environment* pEnv = m_pEnvList.GetAt(0);
+ if (pEnv)
+ {
+ return pEnv->FFI_PutRequestURL(wsURL.GetPtr(), wsData.GetPtr(), wsEncode.GetPtr());
+ }
+ return FALSE;
+}
+
+void CPDFXFA_App::LoadString(FX_INT32 iStringID, CFX_WideString &wsString)
+{
+ switch (iStringID)
+ {
+ case XFA_IDS_ValidateFailed:
+ wsString = L"%s validate failed";
+ return;
+ case XFA_IDS_CalcOverride:
+ wsString = L"Calculate Override";
+ return;
+ case XFA_IDS_ModifyField:
+ wsString = L"Are you sure you want to modify this field?";
+ return;
+ case XFA_IDS_NotModifyField:
+ wsString = L"You are not allowed to modify this field.";
+ return;
+ case XFA_IDS_AppName:
+ wsString = L"Foxit";
+ return;
+ case XFA_IDS_ImageFilter:
+ wsString = L"Image Files(*.bmp;*.jpg;*.png;*.gif;*.tif)|*.bmp;*.jpg;*.png;*.gif;*.tif|All Files(*.*)|*.*||";
+ return;
+ case XFA_IDS_UNKNOW_CATCHED:
+ wsString = L"unknown error is catched!";
+ return;
+ case XFA_IDS_Unable_TO_SET:
+ wsString = L"Unable to set ";
+ return;
+ case XFA_IDS_VALUE_EXCALMATORY:
+ wsString = L" value!";
+ return;
+ case XFA_IDS_INVALID_ENUM_VALUE:
+ wsString = L"Invalid enumerated value: ";
+ return;
+ case XFA_IDS_UNSUPPORT_METHOD:
+ wsString = L"unsupport %s method.";
+ return;
+ case XFA_IDS_UNSUPPORT_PROP:
+ wsString = L"unsupport %s property.";
+ return;
+ case XFA_IDS_INVAlID_PROP_SET:
+ wsString = L"Invalid property set operation;";
+ return;
+ case XFA_IDS_NOT_DEFAUL_VALUE:
+ wsString = L" doesn't have a default property";
+ return;
+ case XFA_IDS_UNABLE_SET_LANGUAGE:
+ wsString = L"Unable to set language value!";
+ return;
+ case XFA_IDS_UNABLE_SET_NUMPAGES:
+ wsString = L"Unable to set numPages value!";
+ return;
+ case XFA_IDS_UNABLE_SET_PLATFORM:
+ wsString = L"Unable to set platform value!";
+ return;
+ case XFA_IDS_UNABLE_SET_VALIDATIONENABLE:
+ wsString = L"Unable to set validationsEnabled value!";
+ return;
+ case XFA_IDS_UNABLE_SET_VARIATION:
+ wsString = L"Unable to set variation value!";
+ return;
+ case XFA_IDS_UNABLE_SET_VERSION:
+ wsString = L"Unable to set version value!";
+ return;
+ case XFA_IDS_UNABLE_SET_READY:
+ wsString = L"Unable to set ready value!";
+ return;
+ case XFA_IDS_NUMBER_OF_OCCUR:
+ wsString = L"The element [%s] has violated its allowable number of occurrences";
+ return;
+ case XFA_IDS_UNABLE_SET_CLASS_NAME:
+ wsString = L"Unable to set className value!";
+ return;
+ case XFA_IDS_UNABLE_SET_LENGTH_VALUE:
+ wsString = L"Unable to set length value!";
+ return;
+ case XFA_IDS_UNSUPPORT_CHAR:
+ wsString = L"unsupported char '%c'";
+ return;
+ case XFA_IDS_BAD_SUFFIX:
+ wsString = L"bad suffix on number";
+ return;
+ case XFA_IDS_EXPECTED_IDENT:
+ wsString = L"expected identifier instead of '%s'";
+ return;
+ case XFA_IDS_EXPECTED_STRING:
+ wsString = L"expected '%s' instead of '%s'";
+ return;
+ case XFA_IDS_INVALIDATE_CHAR:
+ wsString = L"invalidate char '%c'";
+ return;
+ case XFA_IDS_REDEFINITION:
+ wsString = L"'%s' redefinition ";
+ return;
+ case XFA_IDS_INVALIDATE_TOKEN:
+ wsString = L"invalidate token '%s'";
+ return;
+ case XFA_IDS_INVALIDATE_EXPRESSION:
+ wsString = L"invalidate expression '%s'";
+ return;
+ case XFA_IDS_UNDEFINE_IDENTIFIER:
+ wsString = L"undefined identifier '%s'";
+ return;
+ case XFA_IDS_INVALIDATE_LEFTVALUE:
+ wsString = L"invalidate left-value '%s'";
+ return;
+ case XFA_IDS_COMPILER_ERROR:
+ wsString = L"compiler error";
+ return;
+ case XFA_IDS_CANNOT_MODIFY_VALUE:
+ wsString = L"can't modify the '%s' value";
+ return;
+ case XFA_IDS_ERROR_PARAMETERS:
+ wsString = L"function '%s' has not %d parameters";
+ return;
+ case XFA_IDS_EXPECT_ENDIF:
+ wsString = L"expected 'endif' instead of '%s'";
+ return;
+ case XFA_IDS_UNEXPECTED_EXPRESSION:
+ wsString = L"unexpected expression '%s'";
+ return;
+ case XFA_IDS_CONDITION_IS_NULL:
+ wsString = L"condition is null";
+ return;
+ case XFA_IDS_ILLEGALBREAK:
+ wsString = L"illegal break";
+ return;
+ case XFA_IDS_ILLEGALCONTINUE:
+ wsString = L"illegal continue";
+ return;
+ case XFA_IDS_EXPECTED_OPERATOR:
+ wsString = L"expected operator '%s' instead of '%s'";
+ return;
+ case XFA_IDS_DIVIDE_ZERO:
+ wsString = L"divide by zero";
+ return;
+ case XFA_IDS_CANNOT_COVERT_OBJECT:
+ wsString = L"%s.%s can not covert to object";
+ return;
+ case XFA_IDS_NOT_FOUND_CONTAINER:
+ wsString = L"can not found container '%s'";
+ return;
+ case XFA_IDS_NOT_FOUND_PROPERTY:
+ wsString = L"can not found property '%s'";
+ return;
+ case XFA_IDS_NOT_FOUND_METHOD:
+ wsString = L"can not found method '%s'";
+ return;
+ case XFA_IDS_NOT_FOUND_CONST:
+ wsString = L"can not found const '%s'";
+ return;
+ case XFA_IDS_NOT_ASSIGN_OBJECT:
+ wsString = L"can not direct assign value to object";
+ return;
+ case XFA_IDS_IVALIDATE_INSTRUCTION:
+ wsString = L"invalidate instruction";
+ return;
+ case XFA_IDS_EXPECT_NUMBER:
+ wsString = L"expected number instead of '%s'";
+ return;
+ case XFA_IDS_VALIDATE_OUT_ARRAY:
+ wsString = L"validate access index '%s' out of array";
+ return;
+ case XFA_IDS_CANNOT_ASSIGN_IDENT:
+ wsString = L"can not assign to %s";
+ return;
+ case XFA_IDS_NOT_FOUNT_FUNCTION:
+ wsString = L"can not found '%s' function";
+ return;
+ case XFA_IDS_NOT_ARRAY:
+ wsString = L"'%s' doesn't an array";
+ return;
+ case XFA_IDS_OUT_ARRAY:
+ wsString = L"out of range of '%s' array";
+ return;
+ case XFA_IDS_NOT_SUPPORT_CALC:
+ wsString = L"'%s' operator can not support array calculate";
+ return;
+ case XFA_IDS_ARGUMENT_NOT_ARRAY:
+ wsString = L"'%s' function's %d argument can not be array";
+ return;
+ case XFA_IDS_ARGUMENT_EXPECT_CONTAINER:
+ wsString = L"'%s' argument expected a container";
+ return;
+ case XFA_IDS_ACCESS_PROPERTY_IN_NOT_OBJECT:
+ wsString = L"an attempt was made to reference property '%s' of a non-object in SOM expression %s";
+ return;
+ case XFA_IDS_FUNCTION_IS_BUILDIN:
+ wsString = L"function '%s' is buildin";
+ return;
+ case XFA_IDS_ERROR_MSG:
+ wsString = L"%s : %s";
+ return;
+ case XFA_IDS_INDEX_OUT_OF_BOUNDS:
+ wsString = L"Index value is out of bounds";
+ return;
+ case XFA_IDS_INCORRECT_NUMBER_OF_METHOD:
+ wsString = L"Incorrect number of parameters calling method '%s'";
+ return;
+ case XFA_IDS_ARGUMENT_MISMATCH:
+ wsString = L"Argument mismatch in property or function argument";
+ return;
+ case XFA_IDS_INVALID_ENUMERATE:
+ wsString = L"Invalid enumerated value: %s";
+ return;
+ case XFA_IDS_INVALID_APPEND:
+ wsString = L"Invalid append operation: %s cannot have a child element of %s";
+ return;
+ case XFA_IDS_SOM_EXPECTED_LIST:
+ wsString = L"SOM expression returned list when single result was expected";
+ return;
+ case XFA_IDS_NOT_HAVE_PROPERTY:
+ wsString = L"'%s' doesn't have property '%s'";
+ return;
+ case XFA_IDS_INVALID_NODE_TYPE:
+ wsString = L"Invalid node type : '%s'";
+ return;
+ case XFA_IDS_VIOLATE_BOUNDARY:
+ wsString = L"The element [%s] has violated its allowable number of occurrences";
+ return;
+ case XFA_IDS_SERVER_DENY:
+ wsString = L"Server does not permit";
+ return;
+ /*case XFA_IDS_StringWeekDay_Sun:
+ wsString = L"?¨¹¨¨?";
+ return;
+ case XFA_IDS_StringWeekDay_Mon:
+ wsString = L"?¨¹¨°?";
+ return;
+ case XFA_IDS_StringWeekDay_Tue:
+ wsString = L"?¨¹?t";
+ return;
+ case XFA_IDS_StringWeekDay_Wed:
+ wsString = L"?¨¹¨¨y";
+ return;
+ case XFA_IDS_StringWeekDay_Thu:
+ wsString = L"?¨¹??";
+ return;
+ case XFA_IDS_StringWeekDay_Fri:
+ wsString = L"?¨¹??";
+ return;
+ case XFA_IDS_StringWeekDay_Sat:
+ wsString = L"?¨¹¨¢¨´";
+ return;
+ case XFA_IDS_StringMonth_Jan:
+ wsString = L"1??";
+ return;
+ case XFA_IDS_StringMonth_Feb:
+ wsString = L"2??";
+ return;
+ case XFA_IDS_StringMonth_March:
+ wsString = L"3??";
+ return;
+ case XFA_IDS_StringMonth_April:
+ wsString = L"4??";
+ return;
+ case XFA_IDS_StringMonth_May:
+ wsString = L"5??";
+ return;
+ case XFA_IDS_StringMonth_June:
+ wsString = L"6??";
+ return;
+ case XFA_IDS_StringMonth_July:
+ wsString = L"7??";
+ return;
+ case XFA_IDS_StringMonth_Aug:
+ wsString = L"8??";
+ return;
+ case XFA_IDS_StringMonth_Sept:
+ wsString = L"9??";
+ return;
+ case XFA_IDS_StringMonth_Oct:
+ wsString = L"10??";
+ return;
+ case XFA_IDS_StringMonth_Nov:
+ wsString = L"11??";
+ return;
+ case XFA_IDS_StringMonth_Dec:
+ wsString = L"12??";
+ return;
+ case XFA_IDS_String_Today:
+ wsString = L"??¨¬¨¬";
+ return;*/
+ case XFA_IDS_ValidateLimit:
+ wsString = FX_WSTRC(L"Message limit exceeded. Remaining %d validation errors not reported.");
+ return;
+ case XFA_IDS_ValidateNullWarning:
+ wsString = FX_WSTRC(L"%s cannot be left blank. To ignore validations for %s, click Ignore.");
+ return;
+ case XFA_IDS_ValidateNullError:
+ wsString = FX_WSTRC(L"%s cannot be left blank.");
+ return;
+ case XFA_IDS_ValidateWarning:
+ wsString = FX_WSTRC(L"The value you entered for %s is invalid. To ignore validations for %s, click Ignore.");
+ return;
+ case XFA_IDS_ValidateError:
+ wsString = FX_WSTRC(L"The value you entered for %s is invalid.");
+ return;
+ }
+
+}
+
+FX_BOOL CPDFXFA_App::ShowFileDialog(FX_WSTR wsTitle, FX_WSTR wsFilter, CFX_WideStringArray &wsPathArr, FX_BOOL bOpen)
+{
+ //if (m_pEnv)
+ //{
+ // return m_pEnv->FFI_ShowFileDialog(wsTitle.GetPtr(), wsFilter.GetPtr(), wsPathArr, bOpen);
+ //}
+ return FALSE;
+}
+
+IFWL_AdapterTimerMgr* CPDFXFA_App::GetTimerMgr()
+{
+ CXFA_FWLAdapterTimerMgr* pAdapter = NULL;
+ CPDFDoc_Environment* pEnv = m_pEnvList.GetAt(0);
+ if (pEnv)
+ pAdapter = FX_NEW CXFA_FWLAdapterTimerMgr(pEnv);
+ return pAdapter;
+}
diff --git a/fpdfsdk/src/fpdfxfa/fpdfxfa_doc.cpp b/fpdfsdk/src/fpdfxfa/fpdfxfa_doc.cpp
new file mode 100644
index 0000000000..b416da0abc
--- /dev/null
+++ b/fpdfsdk/src/fpdfxfa/fpdfxfa_doc.cpp
@@ -0,0 +1,1476 @@
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/fsdk_define.h"
+#include "../../include/fpdfxfa/fpdfxfa_doc.h"
+#include "../../include/fpdfformfill.h"
+#include "../../include/fsdk_mgr.h"
+#include "../../include/fpdfxfa/fpdfxfa_app.h"
+#include "../../include/fpdfxfa/fpdfxfa_util.h"
+#include "../../include/fpdfxfa/fpdfxfa_page.h"
+#include "../../include/javascript/IJavaScript.h"
+
+
+
+#define IDS_XFA_StringMonth_April "April"
+#define IDS_XFA_StringMonth_May "May"
+#define IDS_XFA_StringMonth_June "June"
+#define IDS_XFA_StringMonth_July "July"
+#define IDS_XFA_StringMonth_Aug "August"
+#define IDS_XFA_StringMonth_Sept "September"
+#define IDS_XFA_StringMonth_Oct "October"
+#define IDS_XFA_StringMonth_Nov "November"
+#define IDS_XFA_StringMonth_Dec "December"
+#define IDS_XFA_String_Today "Today"
+#define IDS_XFA_ValidateLimit "Message limit exceeded. Remaining %d validation errors not reported."
+#define IDS_XFA_Validate_Input "At least one required field was empty. Please fill in the required fields\r\n(highlighted) before continuing."
+
+// submit
+#define FXFA_CONFIG 0x00000001
+#define FXFA_TEMPLATE 0x00000010
+#define FXFA_LOCALESET 0x00000100
+#define FXFA_DATASETS 0x00001000
+#define FXFA_XMPMETA 0x00010000
+#define FXFA_XFDF 0x00100000
+#define FXFA_FORM 0x01000000
+#define FXFA_PDF 0x10000000
+
+#ifndef _WIN32
+extern void SetLastError(int err);
+
+extern int GetLastError();
+#endif
+
+CPDFXFA_Document::CPDFXFA_Document(CPDF_Document* pPDFDoc, CPDFXFA_App* pProvider) :
+ m_pPDFDoc(pPDFDoc),
+ m_pApp(pProvider),
+ m_pXFADoc(NULL),
+ m_pXFADocView(NULL),
+ m_iDocType(DOCTYPE_PDF),
+ m_pJSContext(NULL),
+ m_pSDKDoc(NULL)
+{
+ m_XFAPageList.RemoveAll();
+}
+
+CPDFXFA_Document::~CPDFXFA_Document()
+{
+ if (m_pPDFDoc)
+ {
+ CPDF_Parser* pParser = (CPDF_Parser*)m_pPDFDoc->GetParser();
+ if (pParser == NULL)
+ {
+ delete m_pPDFDoc;
+ }else
+ {
+ delete pParser;
+ }
+ m_pPDFDoc = NULL;
+ }
+ if (m_pXFADoc)
+ {
+ IXFA_App* pApp = m_pApp->GetXFAApp();
+ if (pApp)
+ {
+ IXFA_DocHandler* pDocHandler = pApp->GetDocHandler();
+ if (pDocHandler)
+ {
+ pDocHandler->CloseDoc(m_pXFADoc);
+ pDocHandler->ReleaseDoc(m_pXFADoc);
+ m_pXFADoc = NULL;
+ }
+ }
+ }
+
+ if (m_pJSContext)
+ {
+ if (m_pSDKDoc && m_pSDKDoc->GetEnv())
+ {
+ m_pSDKDoc->GetEnv()->GetJSRuntime()->ReleaseContext(m_pJSContext);
+ m_pJSContext = NULL;
+ }
+ }
+
+
+ if (m_pSDKDoc)
+ delete m_pSDKDoc;
+ m_pSDKDoc = NULL;
+}
+
+FX_BOOL CPDFXFA_Document::LoadXFADoc()
+{
+ if (!m_pPDFDoc)
+ return FALSE;
+
+ m_XFAPageList.RemoveAll();
+
+ int iDocType = DOCTYPE_PDF;
+ FX_BOOL hasXFAField = FPDF_HasXFAField(m_pPDFDoc, iDocType);
+
+ if (hasXFAField)
+ {
+ IXFA_App* pApp = m_pApp->GetXFAApp();
+ if (pApp)
+ {
+ m_pXFADoc = pApp->CreateDoc(this, m_pPDFDoc);
+ if (!m_pXFADoc)
+ {
+ SetLastError(FPDF_ERR_XFALOAD);
+ return FALSE;
+ }
+
+ IXFA_DocHandler* pDocHandler = pApp->GetDocHandler();
+ if (pDocHandler)
+ {
+ int iStatus = pDocHandler->StartLoad(m_pXFADoc);
+ iStatus = pDocHandler->DoLoad(m_pXFADoc, NULL);
+ if (iStatus != 100)
+ {
+ pDocHandler->CloseDoc(m_pXFADoc);
+ pDocHandler->ReleaseDoc(m_pXFADoc);
+ m_pXFADoc = NULL;
+
+ SetLastError(FPDF_ERR_XFALOAD);
+ return FALSE;
+ }
+ pDocHandler->StopLoad(m_pXFADoc);
+ pDocHandler->SetJSERuntime(m_pXFADoc, m_pApp->GetJSERuntime());
+
+ if (pDocHandler->GetDocType(m_pXFADoc) == XFA_DOCTYPE_Dynamic)
+ m_iDocType = DOCTYPE_DYNIMIC_XFA;
+ else
+ m_iDocType = DOCTYPE_STATIC_XFA;
+
+ m_pXFADocView = pDocHandler->CreateDocView(m_pXFADoc, XFA_DOCVIEW_View);
+ FXSYS_assert(m_pXFADocView);
+
+ if (m_pXFADocView->StartLayout() < 0)
+ {
+ pDocHandler->CloseDoc(m_pXFADoc);
+ pDocHandler->ReleaseDoc(m_pXFADoc);
+ m_pXFADoc = NULL;
+
+ SetLastError(FPDF_ERR_XFALAYOUT);
+ return FALSE;
+ }
+ else
+ {
+ m_pXFADocView->DoLayout(NULL);
+ m_pXFADocView->StopLayout();
+
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+ }
+
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+int CPDFXFA_Document::GetPageCount()
+{
+ if (!m_pPDFDoc && !m_pXFADoc)
+ return 0;
+
+ switch (m_iDocType)
+ {
+ case DOCTYPE_PDF:
+ case DOCTYPE_STATIC_XFA:
+ if (m_pPDFDoc)
+ return m_pPDFDoc->GetPageCount();
+ case DOCTYPE_DYNIMIC_XFA:
+ if (m_pXFADoc)
+ return m_pXFADocView->CountPageViews();
+ default:
+ return 0;
+ }
+
+ return 0;
+}
+
+CPDFXFA_Page* CPDFXFA_Document::GetPage(int page_index)
+{
+ if (!m_pPDFDoc && !m_pXFADoc)
+ return NULL;
+
+ CPDFXFA_Page* pPage = NULL;
+ if (m_XFAPageList.GetSize())
+ {
+ pPage = m_XFAPageList.GetAt(page_index);
+ if (pPage)
+ pPage->AddRef();
+ }
+ else
+ {
+ m_XFAPageList.SetSize(GetPageCount());
+ }
+
+ if (!pPage)
+ {
+ pPage = FX_NEW CPDFXFA_Page(this, page_index);
+ FX_BOOL bRet = pPage->LoadPage();
+ if (!bRet) {
+ delete pPage;
+ return NULL;
+ }
+
+ m_XFAPageList.SetAt(page_index, pPage);
+ }
+
+ return pPage;
+}
+
+CPDFXFA_Page* CPDFXFA_Document::GetPage(IXFA_PageView* pPage)
+{
+ if (!pPage)
+ return NULL;
+
+ if (!m_pXFADoc)
+ return NULL;
+
+ if (m_iDocType != DOCTYPE_DYNIMIC_XFA)
+ return NULL;
+
+ int nSize = m_XFAPageList.GetSize();
+ for (int i=0; i<nSize; i++)
+ {
+ CPDFXFA_Page* pTempPage = m_XFAPageList.GetAt(i);
+ if (!pTempPage) continue;
+ if (pTempPage->GetXFAPageView() && pTempPage->GetXFAPageView() == pPage)
+ return pTempPage;
+ }
+
+ return NULL;
+}
+
+void CPDFXFA_Document::RemovePage(CPDFXFA_Page* page)
+{
+ m_XFAPageList.SetAt(page->GetPageIndex(), NULL);
+}
+
+CPDFSDK_Document* CPDFXFA_Document::GetSDKDocument(CPDFDoc_Environment* pFormFillEnv)
+{
+ if (!pFormFillEnv)
+ return m_pSDKDoc;
+
+ if (m_pSDKDoc)
+ return m_pSDKDoc;
+
+ m_pSDKDoc = new CPDFSDK_Document(this, pFormFillEnv);
+ if (!m_pSDKDoc)
+ return NULL;
+
+ return m_pSDKDoc;
+}
+
+void CPDFXFA_Document::ReleaseSDKDoc()
+{
+ if (m_pSDKDoc)
+ delete m_pSDKDoc;
+
+ m_pSDKDoc = NULL;
+}
+
+void CPDFXFA_Document::FXRect2PDFRect(const CFX_RectF& fxRectF, CPDF_Rect& pdfRect)
+{
+ pdfRect.left = fxRectF.left;
+ pdfRect.top = fxRectF.bottom();
+ pdfRect.right = fxRectF.right();
+ pdfRect.bottom = fxRectF.top;
+}
+
+//////////////////////////////////////////////////////////////////////////
+void CPDFXFA_Document::SetChangeMark(XFA_HDOC hDoc)
+{
+ if (hDoc == m_pXFADoc && m_pSDKDoc)
+ {
+ m_pSDKDoc->SetChangeMark();
+ }
+}
+
+FX_BOOL CPDFXFA_Document::GetChangeMark(XFA_HDOC hDoc)
+{
+ if (hDoc == m_pXFADoc && m_pSDKDoc)
+ return m_pSDKDoc->GetChangeMark();
+ return FALSE;
+}
+
+void CPDFXFA_Document::InvalidateRect(IXFA_PageView* pPageView, const CFX_RectF& rt, FX_DWORD dwFlags /* = 0 */)
+{
+ if (!m_pXFADoc || !m_pSDKDoc)
+ return;
+
+ if (m_iDocType != DOCTYPE_DYNIMIC_XFA)
+ return;
+
+ CPDF_Rect rcPage;
+ FXRect2PDFRect(rt, rcPage);
+
+ CPDFXFA_Page* pPage = GetPage(pPageView);
+
+ if (pPage == NULL)
+ return;
+
+ CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
+ if (!pEnv)
+ return;
+
+ pEnv->FFI_Invalidate((FPDF_PAGE)pPage, rcPage.left, rcPage.bottom, rcPage.right, rcPage.top);
+}
+
+void CPDFXFA_Document::InvalidateRect(XFA_HWIDGET hWidget, FX_DWORD dwFlags /* = 0 */)
+{
+ if (!hWidget)
+ return;
+
+ if (!m_pXFADoc || !m_pSDKDoc || !m_pXFADocView)
+ return;
+
+ if (m_iDocType != DOCTYPE_DYNIMIC_XFA)
+ return;
+
+ IXFA_WidgetHandler* pWidgetHandler = m_pXFADocView->GetWidgetHandler();
+ if (!pWidgetHandler)
+ return;
+
+ IXFA_PageView* pPageView = pWidgetHandler->GetPageView(hWidget);
+ if (!pPageView)
+ return;
+
+ CFX_RectF rect;
+ pWidgetHandler->GetRect(hWidget, rect);
+ InvalidateRect(pPageView, rect, dwFlags);
+}
+
+void CPDFXFA_Document::DisplayCaret(XFA_HWIDGET hWidget, FX_BOOL bVisible, const CFX_RectF* pRtAnchor)
+{
+ if (!hWidget || pRtAnchor == NULL)
+ return;
+
+ if (!m_pXFADoc || !m_pSDKDoc || !m_pXFADocView)
+ return;
+
+ if (m_iDocType != DOCTYPE_DYNIMIC_XFA)
+ return;
+
+ IXFA_WidgetHandler* pWidgetHandler = m_pXFADocView->GetWidgetHandler();
+ if (!pWidgetHandler)
+ return;
+
+ IXFA_PageView* pPageView = pWidgetHandler->GetPageView(hWidget);
+ if (!pPageView)
+ return;
+
+ CPDFXFA_Page* pPage = GetPage(pPageView);
+
+ if (pPage == NULL)
+ return;
+
+ CPDF_Rect rcCaret;
+ FXRect2PDFRect(*pRtAnchor, rcCaret);
+
+ CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
+ if (!pEnv)
+ return;
+
+ pEnv->FFI_DisplayCaret((FPDF_PAGE)pPage, bVisible, rcCaret.left, rcCaret.top, rcCaret.right, rcCaret.bottom);
+
+}
+
+FX_BOOL CPDFXFA_Document::GetPopupPos(XFA_HWIDGET hWidget, FX_FLOAT fMinPopup, FX_FLOAT fMaxPopup, const CFX_RectF &rtAnchor, CFX_RectF &rtPopup)
+{
+ if (NULL == hWidget)
+ {
+ return FALSE;
+ }
+ IXFA_PageView* pXFAPageView = m_pXFADocView->GetWidgetHandler()->GetPageView(hWidget);
+ if (NULL == pXFAPageView)
+ {
+ return FALSE;
+ }
+ CPDFXFA_Page* pPage = GetPage(pXFAPageView);
+ if (pPage == NULL)
+ return FALSE;
+
+ CXFA_WidgetAcc* pWidgetAcc = m_pXFADocView->GetWidgetHandler()->GetDataAcc(hWidget);
+
+ int nRotate = pWidgetAcc->GetRotate();
+
+ CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
+ if (pEnv == NULL)
+ return FALSE;
+ FS_RECTF pageViewRect;
+ pEnv->FFI_GetPageViewRect(pPage, pageViewRect);
+
+ CPDF_Rect rcAnchor;
+
+ rcAnchor.left = rtAnchor.left;
+ rcAnchor.top = rtAnchor.bottom();
+ rcAnchor.right = rtAnchor.right();
+ rcAnchor.bottom = rtAnchor.top;
+
+ int t1,t2,t;
+ FX_DWORD dwPos; FX_FLOAT fPoupHeight;
+ switch(nRotate)
+ {
+
+ case 90:
+ {
+ t1 = (int)(pageViewRect.right - rcAnchor.right);
+ t2 = (int)(rcAnchor.left - pageViewRect.left);
+ if (rcAnchor.bottom < pageViewRect.bottom)
+ {
+ rtPopup.left += rcAnchor.bottom - pageViewRect.bottom;
+ }
+
+ break;
+ }
+
+ case 180:
+ {
+ t2 = (int)(pageViewRect.top - rcAnchor.top);
+ t1 = (int)(rcAnchor.bottom - pageViewRect.bottom);
+ if (rcAnchor.left < pageViewRect.left)
+ {
+ rtPopup.left += rcAnchor.left - pageViewRect.left;
+ }
+ break;
+ }
+ case 270:
+ {
+ t1 = (int)(rcAnchor.left - pageViewRect.left);
+ t2 = (int)(pageViewRect.right - rcAnchor.right);
+
+ if (rcAnchor.top > pageViewRect.top)
+ {
+ rtPopup.left -= rcAnchor.top - pageViewRect.top;
+ }
+ break;
+ }
+ case 0:
+ default:
+ {
+ t1 = (int)(pageViewRect.top - rcAnchor.top);
+ t2 = (int)(rcAnchor.bottom - pageViewRect.bottom);
+ if (rcAnchor.right > pageViewRect.right)
+ {
+ rtPopup.left -= rcAnchor.right - pageViewRect.right;
+ }
+ break;
+ }
+
+ }
+
+ if (t1 <= 0 && t2 <= 0)
+ {
+ return FALSE;
+ }
+ if (t1 <= 0)
+ {
+ t = t2;
+ dwPos = 1;
+ }
+ else if(t2 <= 0)
+ {
+ t = t1;
+ dwPos = 0;
+ }
+ else if (t1 > t2 )
+ {
+ t = t1;
+ dwPos = 0;
+ }
+ else
+ {
+ t = t2;
+ dwPos = 1;
+ }
+ if (t<fMinPopup)
+ {
+ fPoupHeight = fMinPopup;
+ }
+ else if (t > fMaxPopup)
+ {
+ fPoupHeight = fMaxPopup;
+ }
+ else
+ {
+ fPoupHeight = (FX_FLOAT)t;
+ }
+
+ switch(nRotate)
+ {
+
+ case 0:
+ case 180:
+ {
+ if (dwPos == 0)
+ {
+ rtPopup.top = rtAnchor.height;
+ rtPopup.height = fPoupHeight;
+ }
+ else
+ {
+ rtPopup.top = - fPoupHeight;
+ rtPopup.height = fPoupHeight;
+ }
+ break;
+ }
+ case 90:
+ case 270:
+ {
+ if (dwPos == 0)
+ {
+ rtPopup.top = rtAnchor.width;
+ rtPopup.height = fPoupHeight;
+ }
+ else
+ {
+ rtPopup.top = - fPoupHeight;
+ rtPopup.height = fPoupHeight;
+ }
+ break;
+ }
+ default:
+ break;
+ }
+
+ return TRUE;
+}
+
+FX_BOOL CPDFXFA_Document::PopupMenu(XFA_HWIDGET hWidget, CFX_PointF ptPopup, const CFX_RectF* pRectExclude)
+{
+ if (NULL == hWidget)
+ {
+ return FALSE;
+ }
+ IXFA_PageView* pXFAPageView = m_pXFADocView->GetWidgetHandler()->GetPageView(hWidget);
+ if (pXFAPageView == NULL)
+ return FALSE;
+ CPDFXFA_Page* pPage = GetPage(pXFAPageView);
+
+ if (pPage == NULL)
+ return FALSE;
+
+ int menuFlag = 0;
+
+ IXFA_MenuHandler* pXFAMenuHander = m_pApp->GetXFAApp()->GetMenuHandler();
+ if (pXFAMenuHander->CanUndo(hWidget))
+ menuFlag |= FXFA_MEMU_UNDO;
+ if (pXFAMenuHander->CanRedo(hWidget))
+ menuFlag |= FXFA_MEMU_REDO;
+ if (pXFAMenuHander->CanPaste(hWidget))
+ menuFlag |= FXFA_MEMU_PASTE;
+ if (pXFAMenuHander->CanCopy(hWidget))
+ menuFlag |= FXFA_MEMU_COPY;
+ if (pXFAMenuHander->CanCut(hWidget))
+ menuFlag |= FXFA_MEMU_CUT;
+ if (pXFAMenuHander->CanSelectAll(hWidget))
+ menuFlag |= FXFA_MEMU_SELECTALL;
+
+
+ CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
+ if (pEnv == NULL)
+ return FALSE;
+
+ return pEnv->FFI_PopupMenu(pPage, hWidget, menuFlag, ptPopup, NULL);
+}
+
+void CPDFXFA_Document::PageViewEvent(IXFA_PageView* pPageView, FX_DWORD dwFlags)
+{
+ if (m_iDocType != DOCTYPE_DYNIMIC_XFA)
+ return;
+
+ CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
+ if (pEnv == NULL)
+ return;
+
+ CPDFXFA_Page* pPage = GetPage(pPageView);
+ if (pPage == NULL)
+ return;
+
+ if (dwFlags == FXFA_PAGEVIEWEVENT_POSTADDED)
+ {
+ //pEnv->FFI_PageEvent(pPage, FXFA_PAGEVIEWEVENT_POSTADDED);
+ }
+ else if (dwFlags == FXFA_PAGEVIEWEVENT_POSTREMOVED)
+ {
+ //pEnv->FFI_PageEvent(pPage, FXFA_PAGEVIEWEVENT_POSTREMOVED);
+ //RemovePage(pPage);
+ //delete pPage;
+ }
+}
+
+void CPDFXFA_Document::WidgetEvent(XFA_HWIDGET hWidget, CXFA_WidgetAcc* pWidgetData, FX_DWORD dwEvent, FX_LPVOID pParam, FX_LPVOID pAdditional)
+{
+ if (m_iDocType != DOCTYPE_DYNIMIC_XFA || NULL == hWidget)
+ return;
+
+ int pageViewCount = m_pSDKDoc->GetPageViewCount();
+
+ CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
+ if (pEnv == NULL)
+ return;
+
+ if (NULL == hWidget) return;
+
+ IXFA_PageView* pPageView = m_pXFADocView->GetWidgetHandler()->GetPageView(hWidget);
+
+ if (pPageView == NULL)
+ return;
+ CPDFXFA_Page* pXFAPage = GetPage(pPageView);
+ if (pXFAPage == NULL)
+ return;
+
+ CPDFSDK_PageView* pSdkPageView = m_pSDKDoc->GetPageView(pXFAPage);
+
+ CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
+
+
+ if (dwEvent == XFA_WIDGETEVENT_PostAdded)
+ {
+// CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(hWidget, pSdkPageView);
+// pAnnotHandlerMgr->Annot_OnLoad(pAnnot);
+
+ //pEnv->FFI_WidgetEvent(hWidget, XFA_WIDGETEVENT_PostAdded);
+// IXFA_PageView* pOldPageView = (IXFA_PageView*)pAdditional;
+// if (pOldPageView)
+// {
+// CPDFXFA_Page* pDestPage = m_pSDKDoc->GetPageView((IXFA_PageView*)pOldPageView);
+// ASSERT(pDestPage);
+// CPDFSDK_Annot* pAnnot = pDestPage->GetAnnotByXFAWidget(hWidget);
+// if (pAnnot)
+// {
+// if (m_pSDKDoc->GetFocusAnnot() == pAnnot)
+// {
+// m_pSDKDoc->SetFocusAnnot(NULL);
+// }
+// pDestPage->DeleteAnnot(pAnnot);
+// }
+// }
+ pSdkPageView->AddAnnot(hWidget);
+
+ }
+ else if (dwEvent == XFA_WIDGETEVENT_PreRemoved)
+ {
+ CPDFSDK_Annot* pAnnot = pSdkPageView->GetAnnotByXFAWidget(hWidget);
+ if (pAnnot) {
+ pSdkPageView->DeleteAnnot(pAnnot);
+ //pEnv->FFI_WidgetEvent(hWidget, XFA_WIDGETEVENT_PreRemoved);
+ }
+ }
+}
+
+FX_INT32 CPDFXFA_Document::CountPages(XFA_HDOC hDoc)
+{
+ if (hDoc == m_pXFADoc && m_pSDKDoc)
+ {
+ return GetPageCount();
+ }
+ return 0;
+}
+FX_INT32 CPDFXFA_Document::GetCurrentPage(XFA_HDOC hDoc)
+{
+ if (hDoc != m_pXFADoc || !m_pSDKDoc)
+ return -1;
+ if (m_iDocType != DOCTYPE_DYNIMIC_XFA)
+ return -1;
+
+
+ CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
+ if (pEnv == NULL)
+ return -1;
+
+ return pEnv->FFI_GetCurrentPageIndex(this);
+}
+void CPDFXFA_Document::SetCurrentPage(XFA_HDOC hDoc, FX_INT32 iCurPage)
+{
+ if (hDoc != m_pXFADoc || !m_pSDKDoc)
+ return;
+ if (m_iDocType != DOCTYPE_DYNIMIC_XFA)
+ return;
+
+ CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
+ if (pEnv == NULL)
+ return;
+
+ pEnv->FFI_SetCurrentPage(this, iCurPage);
+}
+FX_BOOL CPDFXFA_Document::IsCalculationsEnabled(XFA_HDOC hDoc)
+{
+ if (hDoc != m_pXFADoc || !m_pSDKDoc)
+ return FALSE;
+ if (m_pSDKDoc->GetInterForm())
+ return m_pSDKDoc->GetInterForm()->IsXfaCalculateEnabled();
+
+ return FALSE;
+
+}
+void CPDFXFA_Document::SetCalculationsEnabled(XFA_HDOC hDoc, FX_BOOL bEnabled)
+{
+ if (hDoc != m_pXFADoc || !m_pSDKDoc)
+ return;
+ if (m_pSDKDoc->GetInterForm())
+ m_pSDKDoc->GetInterForm()->XfaEnableCalculate(bEnabled);
+}
+
+void CPDFXFA_Document::GetTitle(XFA_HDOC hDoc, CFX_WideString &wsTitle)
+{
+ if (hDoc != m_pXFADoc)
+ return;
+ if (m_pPDFDoc == NULL)
+ return;
+ CPDF_Dictionary* pInfoDict = m_pPDFDoc->GetInfo();
+
+ if (pInfoDict == NULL)
+ return;
+
+ CFX_ByteString csTitle = pInfoDict->GetString("Title");
+ wsTitle = wsTitle.FromLocal(csTitle.GetBuffer(csTitle.GetLength()));
+ csTitle.ReleaseBuffer(csTitle.GetLength());
+}
+void CPDFXFA_Document::SetTitle(XFA_HDOC hDoc, FX_WSTR wsTitle)
+{
+ if (hDoc != m_pXFADoc)
+ return;
+ if (m_pPDFDoc == NULL)
+ return;
+ CPDF_Dictionary* pInfoDict = m_pPDFDoc->GetInfo();
+
+ if (pInfoDict == NULL)
+ return;
+ pInfoDict->SetAt("Title", FX_NEW CPDF_String(wsTitle));
+}
+void CPDFXFA_Document::ExportData(XFA_HDOC hDoc, FX_WSTR wsFilePath, FX_BOOL bXDP)
+{
+ if (hDoc != m_pXFADoc)
+ return;
+ if (m_iDocType != DOCTYPE_DYNIMIC_XFA && m_iDocType != DOCTYPE_STATIC_XFA)
+ return;
+ CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
+ if (pEnv == NULL)
+ return;
+ int fileType = bXDP?FXFA_SAVEAS_XDP:FXFA_SAVEAS_XML;
+ CFX_ByteString bs = CFX_WideString(wsFilePath).UTF16LE_Encode();
+
+ if (wsFilePath.IsEmpty()) {
+ if (!pEnv->GetFormFillInfo() || pEnv->GetFormFillInfo()->m_pJsPlatform == NULL)
+ return;
+ CFX_WideString filepath = pEnv->JS_fieldBrowse();
+ bs = filepath.UTF16LE_Encode();
+ }
+ int len = bs.GetLength()/sizeof(unsigned short);
+ FPDF_FILEHANDLER* pFileHandler = pEnv->FFI_OpenFile(bXDP?FXFA_SAVEAS_XDP:FXFA_SAVEAS_XML, (FPDF_WIDESTRING)bs.GetBuffer(len*sizeof(unsigned short)), "wb");
+ bs.ReleaseBuffer(len*sizeof(unsigned short));
+
+ if (pFileHandler == NULL)
+ return;
+
+ CFPDF_FileStream fileWrite(pFileHandler);
+
+ IXFA_DocHandler *pXFADocHander = m_pApp->GetXFAApp()->GetDocHandler();
+ CFX_ByteString content;
+ if (fileType == FXFA_SAVEAS_XML)
+ {
+ content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n";
+ fileWrite.WriteBlock((FX_LPCSTR)content, fileWrite.GetSize(), content.GetLength());
+ CFX_WideStringC data(L"data");
+ if( pXFADocHander->SavePackage(m_pXFADocView->GetDoc(),data, &fileWrite))
+ {
+ NULL;
+ }
+ }
+ /*else if (fileType == FXFA_FILE_STATIC_XDP)
+ {
+ content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n";
+ fileWrite.WriteBlock((FX_LPCSTR)content, fileWrite.GetSize(), content.GetLength());
+ CFX_WideStringC data(L"data");
+ if( pXFADocHander->SavePackage(m_pXFADocView->GetDoc(), data, &fileWrite))
+ {
+ NULL;
+ }
+ CFX_WideString wPath = pEnv->FFI_GetFilePath(pFileHandler);
+// CFX_WideString wPath;
+// wPath.FromUTF16LE(filePath);
+ CFX_ByteString bPath = wPath.UTF8Encode();
+ CFX_ByteString szFormat = "\n<pdf href=\"%s\" xmlns=\"http://ns.adobe.com/xdp/pdf/\"/>";
+ content.Format(szFormat,(char*)(FX_LPCSTR)bPath);
+ fileWrite.WriteBlock((FX_LPCSTR)content,fileWrite.GetSize(), content.GetLength());
+ }
+ */
+ else if (fileType == FXFA_SAVEAS_XDP)
+ {
+ if (m_pPDFDoc == NULL)
+ return;
+ CPDF_Dictionary* pRoot = m_pPDFDoc->GetRoot();
+ if (pRoot == NULL)
+ return;
+ CPDF_Dictionary* pAcroForm = pRoot->GetDict("AcroForm");
+ if (NULL == pAcroForm)
+ return;
+ CPDF_Object* pXFA = pAcroForm->GetElement("XFA");
+ if (pXFA == NULL)
+ return;
+ if (pXFA->GetType() != PDFOBJ_ARRAY)
+ return;
+ CPDF_Array* pArray = pXFA->GetArray();
+ if (NULL == pArray)
+ return;
+ int size = pArray->GetCount();
+ int iFormIndex = -1;
+ int iDataSetsIndex = -1;
+ for (int i=1; i<size;i+=2)
+ {
+ CPDF_Object* pPDFObj = pArray->GetElement(i);
+ CPDF_Object* pPrePDFObj = pArray->GetElement(i-1);
+ if(pPrePDFObj->GetType() != PDFOBJ_STRING)
+ continue;
+ if (pPDFObj->GetType() != PDFOBJ_REFERENCE)
+ continue;
+ CPDF_Object* pDirectObj = pPDFObj->GetDirect();
+ if(pDirectObj->GetType() != PDFOBJ_STREAM)
+ continue;
+ if (pPrePDFObj->GetString()=="form")
+ {
+ CFX_WideStringC form(L"form");
+ pXFADocHander->SavePackage(m_pXFADocView->GetDoc(), form, &fileWrite);
+ }
+ else if (pPrePDFObj->GetString()=="datasets")
+ {
+ CFX_WideStringC datasets(L"datasets");
+ pXFADocHander->SavePackage(m_pXFADocView->GetDoc(), datasets, &fileWrite);
+ }
+ else
+ {
+ if (i == size-1)
+ {
+ //CFX_WideString wPath = pEnv->FFI_GetFilePath(pFileHandler);
+ CFX_WideString wPath = CFX_WideString::FromUTF16LE((unsigned short*)(FX_LPCSTR)bs, bs.GetLength()/sizeof(unsigned short));
+ CFX_ByteString bPath = wPath.UTF8Encode();
+ CFX_ByteString szFormat = "\n<pdf href=\"%s\" xmlns=\"http://ns.adobe.com/xdp/pdf/\"/>";
+ content.Format(szFormat,(char*)(FX_LPCSTR)bPath);
+ fileWrite.WriteBlock((FX_LPCSTR)content,fileWrite.GetSize(), content.GetLength());
+ }
+
+ CPDF_Stream* pStream = (CPDF_Stream*)pDirectObj;
+ CPDF_StreamAcc* pAcc = FX_NEW CPDF_StreamAcc;
+ pAcc->LoadAllData(pStream);
+ fileWrite.WriteBlock(pAcc->GetData(), fileWrite.GetSize(), pAcc->GetSize());
+ delete pAcc;
+ }
+ }
+ }
+ FX_BOOL bError= fileWrite.Flush();
+}
+void CPDFXFA_Document::ImportData(XFA_HDOC hDoc, FX_WSTR wsFilePath)
+{
+ //TODO...
+}
+
+void CPDFXFA_Document::GotoURL(XFA_HDOC hDoc, FX_WSTR bsURL, FX_BOOL bAppend)
+{
+ if (hDoc != m_pXFADoc)
+ return;
+
+ if (m_iDocType != DOCTYPE_DYNIMIC_XFA)
+ return;
+
+ CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
+ if (pEnv == NULL)
+ return;
+
+ CFX_WideStringC str(bsURL.GetPtr());
+
+ pEnv->FFI_GotoURL(this, str, bAppend);
+
+}
+
+FX_BOOL CPDFXFA_Document::IsValidationsEnabled(XFA_HDOC hDoc)
+{
+ if (hDoc != m_pXFADoc || !m_pSDKDoc)
+ return FALSE;
+ if (m_pSDKDoc->GetInterForm())
+ return m_pSDKDoc->GetInterForm()->IsXfaValidationsEnabled();
+
+ return TRUE;
+}
+void CPDFXFA_Document::SetValidationsEnabled(XFA_HDOC hDoc, FX_BOOL bEnabled)
+{
+ if (hDoc != m_pXFADoc || !m_pSDKDoc)
+ return;
+ if (m_pSDKDoc->GetInterForm())
+ m_pSDKDoc->GetInterForm()->XfaSetValidationsEnabled(bEnabled);
+}
+void CPDFXFA_Document::SetFocusWidget(XFA_HDOC hDoc, XFA_HWIDGET hWidget)
+{
+ if (hDoc != m_pXFADoc)
+ return;
+
+ if (NULL == hWidget) {
+ m_pSDKDoc->SetFocusAnnot(NULL);
+ return;
+ }
+
+ int pageViewCount = m_pSDKDoc->GetPageViewCount();
+ for (int i = 0; i < pageViewCount; i++)
+ {
+ CPDFSDK_PageView* pPageView = m_pSDKDoc->GetPageView(i);
+ if (pPageView == NULL)
+ continue;
+ CPDFSDK_Annot* pAnnot = pPageView->GetAnnotByXFAWidget(hWidget);
+ if (pAnnot) {
+ m_pSDKDoc->SetFocusAnnot(pAnnot);
+ break;
+ }
+ }
+}
+void CPDFXFA_Document::Print(XFA_HDOC hDoc, FX_INT32 nStartPage, FX_INT32 nEndPage, FX_DWORD dwOptions)
+{
+ if (hDoc != m_pXFADoc)
+ return;
+
+ CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
+ if (pEnv == NULL)
+ return;
+
+ if (!pEnv->GetFormFillInfo() || pEnv->GetFormFillInfo()->m_pJsPlatform == NULL)
+ return;
+ if (pEnv->GetFormFillInfo()->m_pJsPlatform->Doc_print == NULL)
+ return;
+ pEnv->GetFormFillInfo()->m_pJsPlatform->Doc_print(pEnv->GetFormFillInfo()->m_pJsPlatform,dwOptions&XFA_PRINTOPT_ShowDialog,
+ nStartPage,nEndPage,dwOptions&XFA_PRINTOPT_CanCancel,dwOptions&XFA_PRINTOPT_ShrinkPage,dwOptions&XFA_PRINTOPT_AsImage,
+ dwOptions&XFA_PRINTOPT_ReverseOrder,dwOptions&XFA_PRINTOPT_PrintAnnot);
+}
+
+void CPDFXFA_Document::GetURL(XFA_HDOC hDoc, CFX_WideString &wsDocURL)
+{
+ if (hDoc != m_pXFADoc)
+ return;
+
+ CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
+ if (pEnv == NULL)
+ return;
+
+ pEnv->FFI_GetURL(this, wsDocURL);
+}
+
+FX_ARGB CPDFXFA_Document::GetHighlightColor(XFA_HDOC hDoc)
+{
+ if (hDoc != m_pXFADoc)
+ return 0;
+ if (m_pSDKDoc)
+ {
+ if(CPDFSDK_InterForm* pInterForm = m_pSDKDoc->GetInterForm())
+ {
+ FX_COLORREF color = pInterForm->GetHighlightColor(FPDF_FORMFIELD_XFA);
+ FX_BYTE alpha = pInterForm->GetHighlightAlpha();
+ FX_ARGB argb = ArgbEncode((int)alpha, color);
+ return argb;
+ }
+ }
+ return 0;
+}
+
+void CPDFXFA_Document::AddDoRecord(XFA_HWIDGET hWidget)
+{
+ CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
+ if (pEnv == NULL)
+ return;
+ return;
+ //pEnv->FFI_AddDoRecord(this, hWidget);
+}
+
+FX_BOOL CPDFXFA_Document::_NotifySubmit(FX_BOOL bPrevOrPost)
+{
+ if (bPrevOrPost)
+ return _OnBeforeNotifySumbit();
+ else
+ _OnAfterNotifySumbit();
+ return TRUE;
+}
+
+FX_BOOL CPDFXFA_Document::_OnBeforeNotifySumbit()
+{
+ if (m_iDocType != DOCTYPE_DYNIMIC_XFA && m_iDocType != DOCTYPE_STATIC_XFA)
+ return TRUE;
+ if (m_pXFADocView == NULL)
+ return TRUE;
+ IXFA_WidgetHandler* pWidgetHandler = m_pXFADocView->GetWidgetHandler();
+ if (pWidgetHandler == NULL)
+ return TRUE;
+ IXFA_WidgetAccIterator* pWidgetAccIterator = m_pXFADocView->CreateWidgetAccIterator();
+ if (pWidgetAccIterator)
+ {
+ CXFA_EventParam Param;
+ Param.m_eType = XFA_EVENT_PreSubmit;
+ CXFA_WidgetAcc* pWidgetAcc = pWidgetAccIterator->MoveToNext();
+ while (pWidgetAcc)
+ {
+ pWidgetHandler->ProcessEvent(pWidgetAcc, &Param);
+ pWidgetAcc = pWidgetAccIterator->MoveToNext();
+ }
+ pWidgetAccIterator->Release();
+ }
+ pWidgetAccIterator = m_pXFADocView->CreateWidgetAccIterator();
+ if (pWidgetAccIterator)
+ {
+ CXFA_WidgetAcc* pWidgetAcc = pWidgetAccIterator->MoveToNext();
+ pWidgetAcc = pWidgetAccIterator->MoveToNext();
+ while (pWidgetAcc)
+ {
+ int fRet = pWidgetAcc->ProcessValidate(-1);
+ if (fRet == XFA_EVENTERROR_Error)
+ {
+ CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
+ if (pEnv == NULL)
+ return FALSE;
+ CFX_WideString ws;
+ ws.FromLocal(IDS_XFA_Validate_Input);
+ CFX_ByteString bs = ws.UTF16LE_Encode();
+ int len = bs.GetLength()/sizeof(unsigned short);
+ pEnv->FFI_Alert((FPDF_WIDESTRING)bs.GetBuffer(len*sizeof(unsigned short)), (FPDF_WIDESTRING)L"", 0, 1);
+ bs.ReleaseBuffer(len*sizeof(unsigned short));
+ pWidgetAccIterator->Release();
+ return FALSE;
+ }
+ pWidgetAcc = pWidgetAccIterator->MoveToNext();
+ }
+ pWidgetAccIterator->Release();
+ m_pXFADocView->UpdateDocView();
+ }
+
+ return TRUE;
+
+}
+void CPDFXFA_Document::_OnAfterNotifySumbit()
+{
+ if (m_iDocType != DOCTYPE_DYNIMIC_XFA && m_iDocType != DOCTYPE_STATIC_XFA)
+ return;
+ if (m_pXFADocView == NULL)
+ return;
+ IXFA_WidgetHandler* pWidgetHandler = m_pXFADocView->GetWidgetHandler();
+ if (pWidgetHandler == NULL)
+ return;
+ IXFA_WidgetAccIterator* pWidgetAccIterator = m_pXFADocView->CreateWidgetAccIterator();
+ if (pWidgetAccIterator == NULL)
+ return;
+ CXFA_EventParam Param;
+ Param.m_eType = XFA_EVENT_PostSubmit;
+
+ CXFA_WidgetAcc* pWidgetAcc = pWidgetAccIterator->MoveToNext();
+ while (pWidgetAcc)
+ {
+ pWidgetHandler->ProcessEvent(pWidgetAcc, &Param);
+ pWidgetAcc = pWidgetAccIterator->MoveToNext();
+ }
+ pWidgetAccIterator->Release();
+ m_pXFADocView->UpdateDocView();
+}
+
+FX_BOOL CPDFXFA_Document::SubmitData(XFA_HDOC hDoc, CXFA_Submit submit)
+{
+ if (!_NotifySubmit(TRUE))
+ return FALSE;
+ if (NULL == m_pXFADocView)
+ return FALSE;
+ m_pXFADocView->UpdateDocView();
+
+ FX_BOOL ret = _SubmitData(hDoc, submit);
+ _NotifySubmit(FALSE);
+ return ret;
+}
+
+IFX_FileRead* CPDFXFA_Document::OpenLinkedFile(XFA_HDOC hDoc, const CFX_WideString& wsLink)
+{
+ CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
+ if (pEnv == NULL)
+ return FALSE;
+ CFX_ByteString bs = wsLink.UTF16LE_Encode();
+ int len = bs.GetLength()/sizeof(unsigned short);
+ FPDF_FILEHANDLER* pFileHandler = pEnv->FFI_OpenFile(0, (FPDF_WIDESTRING)bs.GetBuffer(len*sizeof(unsigned short)), "rb");
+ bs.ReleaseBuffer(len*sizeof(unsigned short));
+
+ if (pFileHandler == NULL)
+ return NULL;
+ CFPDF_FileStream* pFileRead = FX_NEW CFPDF_FileStream(pFileHandler);
+ return pFileRead;
+}
+FX_BOOL CPDFXFA_Document::_ExportSubmitFile(FPDF_FILEHANDLER* pFileHandler, int fileType, FPDF_DWORD encodeType, FPDF_DWORD flag)
+{
+ if (NULL == m_pXFADocView)
+ return FALSE;
+ IXFA_DocHandler* pDocHandler = m_pApp->GetXFAApp()->GetDocHandler();
+ CFX_ByteString content;
+
+ CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
+ if (pEnv == NULL)
+ return FALSE;
+
+ CFPDF_FileStream fileStream(pFileHandler);
+
+ if (fileType == FXFA_SAVEAS_XML)
+ {
+ CFX_WideString ws;
+ ws.FromLocal("data");
+ CFX_ByteString content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n";
+ fileStream.WriteBlock((FX_LPCSTR)content,0,content.GetLength());
+ pDocHandler->SavePackage(m_pXFADoc, ws, &fileStream);
+ }
+ else if (fileType == FXFA_SAVEAS_XDP)
+ {
+ if (flag == 0)
+ flag = FXFA_CONFIG|FXFA_TEMPLATE|FXFA_LOCALESET|FXFA_DATASETS|FXFA_XMPMETA|FXFA_XFDF|FXFA_FORM;
+ if (m_pPDFDoc == NULL)
+ {
+ fileStream.Flush();
+ return FALSE;
+ }
+ CPDF_Dictionary* pRoot = m_pPDFDoc->GetRoot();
+ if (pRoot == NULL)
+ {
+ fileStream.Flush();
+ return FALSE;
+ }
+ CPDF_Dictionary* pAcroForm = pRoot->GetDict("AcroForm");
+ if (NULL == pAcroForm)
+ {
+ fileStream.Flush();
+ return FALSE;
+ }
+ CPDF_Object* pXFA = pAcroForm->GetElement("XFA");
+ if (pXFA == NULL)
+ {
+ fileStream.Flush();
+ return FALSE;
+ }
+ if (pXFA->GetType() != PDFOBJ_ARRAY)
+ {
+ fileStream.Flush();
+ return FALSE;
+ }
+ CPDF_Array* pArray = pXFA->GetArray();
+ if (NULL == pArray)
+ {
+ fileStream.Flush();
+ return FALSE;
+ }
+ int size = pArray->GetCount();
+ int iFormIndex = -1;
+ int iDataSetsIndex = -1;
+ for (int i=1; i<size;i+=2)
+ {
+ CPDF_Object* pPDFObj = pArray->GetElement(i);
+ CPDF_Object* pPrePDFObj = pArray->GetElement(i-1);
+ if(pPrePDFObj->GetType() != PDFOBJ_STRING)
+ continue;
+ if (pPDFObj->GetType() != PDFOBJ_REFERENCE)
+ continue;
+ CPDF_Object* pDirectObj = pPDFObj->GetDirect();
+ if (pDirectObj->GetType() != PDFOBJ_STREAM)
+ continue;
+ if (pPrePDFObj->GetString()=="config" && !(flag & FXFA_CONFIG))
+ continue;
+ if (pPrePDFObj->GetString()=="template" && !(flag & FXFA_TEMPLATE))
+ continue;
+ if (pPrePDFObj->GetString()=="localeSet" && !(flag & FXFA_LOCALESET))
+ continue;
+ if (pPrePDFObj->GetString()=="datasets" && !(flag & FXFA_DATASETS))
+ continue;
+ if (pPrePDFObj->GetString()=="xmpmeta" && !(flag & FXFA_XMPMETA))
+ continue;
+ if (pPrePDFObj->GetString()=="xfdf" && !(flag & FXFA_XFDF))
+ continue;
+ if (pPrePDFObj->GetString()=="form" && !(flag & FXFA_FORM))
+ continue;
+ if (pPrePDFObj->GetString()=="form")
+ {
+ CFX_WideString ws;
+ ws.FromLocal("form");
+ pDocHandler->SavePackage(m_pXFADoc, ws, &fileStream);
+ }
+ else if (pPrePDFObj->GetString()=="datasets")
+ {
+ CFX_WideString ws;
+ ws.FromLocal("datasets");
+ pDocHandler->SavePackage(m_pXFADoc, ws, &fileStream);
+ }
+ else
+ {
+ //PDF,creator.
+ //TODO:
+ }
+ }
+ }
+ return TRUE;
+}
+
+void CPDFXFA_Document::_ClearChangeMark()
+{
+ if (m_pSDKDoc)
+ m_pSDKDoc->ClearChangeMark();
+}
+
+void CPDFXFA_Document::_ToXFAContentFlags(CFX_WideString csSrcContent, FPDF_DWORD& flag)
+{
+ if (csSrcContent.Find(L" config ", 0) != -1)
+ flag |= FXFA_CONFIG;
+ if (csSrcContent.Find(L" template ", 0) != -1)
+ flag |= FXFA_TEMPLATE;
+ if (csSrcContent.Find(L" localeSet ", 0) != -1)
+ flag |= FXFA_LOCALESET;
+ if (csSrcContent.Find(L" datasets ", 0) != -1)
+ flag |= FXFA_DATASETS;
+ if (csSrcContent.Find(L" xmpmeta ", 0) != -1)
+ flag |= FXFA_XMPMETA;
+ if (csSrcContent.Find(L" xfdf ", 0) != -1)
+ flag |= FXFA_XFDF;
+ if (csSrcContent.Find(L" form ", 0) != -1)
+ flag |= FXFA_FORM;
+ if (flag == 0)
+ flag = FXFA_CONFIG|FXFA_TEMPLATE|FXFA_LOCALESET|FXFA_DATASETS|FXFA_XMPMETA|FXFA_XFDF|FXFA_FORM;
+}
+FX_BOOL CPDFXFA_Document::_MailToInfo(CFX_WideString& csURL, CFX_WideString& csToAddress, CFX_WideString& csCCAddress, CFX_WideString& csBCCAddress, CFX_WideString& csSubject, CFX_WideString& csMsg)
+{
+ CFX_WideString srcURL = csURL;
+ srcURL.TrimLeft();
+ if (0 != srcURL.Left(7).CompareNoCase(L"mailto:"))
+ return FALSE;
+ int pos = srcURL.Find(L'?',0);
+ CFX_WideString tmp;
+ if (pos == -1) {
+ pos = srcURL.Find(L'@',0);
+ if (pos == -1)
+ return FALSE;
+ else
+ {
+ tmp = srcURL.Right(csURL.GetLength()-7);
+ tmp.TrimLeft();
+ tmp.TrimRight();
+ }
+ } else {
+ tmp = srcURL.Left(pos);
+ tmp = tmp.Right(tmp.GetLength()-7);
+ tmp.TrimLeft();
+ tmp.TrimRight();
+ }
+
+ csToAddress = tmp;
+
+ srcURL = srcURL.Right(srcURL.GetLength()-(pos+1));
+ while ( !srcURL.IsEmpty() )
+ {
+ srcURL.TrimLeft();
+ srcURL.TrimRight();
+ pos = srcURL.Find(L'&',0);
+ if (pos == -1)
+ tmp = srcURL;
+ else
+ tmp = srcURL.Left(pos);
+
+ tmp.TrimLeft();
+ tmp.TrimRight();
+ if (tmp.GetLength() >= 3 && 0 == tmp.Left(3).CompareNoCase(L"cc=") )
+ {
+ tmp = tmp.Right(tmp.GetLength()-3);
+ if (!csCCAddress.IsEmpty())
+ csCCAddress += L';';
+ csCCAddress += tmp;
+
+ }
+ else if (tmp.GetLength() >= 4 && 0 == tmp.Left(4).CompareNoCase(L"bcc="))
+ {
+ tmp = tmp.Right(tmp.GetLength() - 4);
+ if (!csBCCAddress.IsEmpty())
+ csBCCAddress += L';';
+ csBCCAddress += tmp;
+ }
+ else if (tmp.GetLength() >= 8 && 0 ==tmp.Left(8).CompareNoCase(L"subject=") )
+ {
+ tmp=tmp.Right(tmp.GetLength()-8);
+ csSubject += tmp;
+ }
+ else if(tmp.GetLength() >= 5 && 0 ==tmp.Left(5).CompareNoCase(L"body=") )
+ {
+ tmp=tmp.Right(tmp.GetLength() - 5);
+ csMsg += tmp;
+ }
+ if (pos == -1)
+ srcURL = L"";
+ else
+ srcURL = srcURL.Right(csURL.GetLength()-(pos+1));
+ }
+ csToAddress.Replace((FX_LPCWSTR)L",", (FX_LPCWSTR)L";");
+ csCCAddress.Replace((FX_LPCWSTR)L",", (FX_LPCWSTR)L";");
+ csBCCAddress.Replace((FX_LPCWSTR)L",", (FX_LPCWSTR)L";");
+ return TRUE;
+}
+
+FX_BOOL CPDFXFA_Document::_SubmitData(XFA_HDOC hDoc, CXFA_Submit submit)
+{
+ CFX_WideStringC csURLC;
+ submit.GetSubmitTarget(csURLC);
+ CFX_WideString csURL = csURLC;
+ CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
+ if (pEnv == NULL)
+ return FALSE;
+ if (csURL.IsEmpty()){
+ CFX_WideString ws;
+ ws.FromLocal("Submit cancelled.");
+ CFX_ByteString bs = ws.UTF16LE_Encode();
+ int len = bs.GetLength()/sizeof(unsigned short);
+ pEnv->FFI_Alert((FPDF_WIDESTRING)bs.GetBuffer(len*sizeof(unsigned short)), (FPDF_WIDESTRING)L"", 0, 4);
+ bs.ReleaseBuffer(len*sizeof(unsigned short));
+ return FALSE;
+ }
+
+ FPDF_BOOL bRet = TRUE;
+ FPDF_FILEHANDLER* pFileHandler = NULL;
+ int fileFlag = -1;
+
+ if (submit.GetSubmitFormat() == XFA_ATTRIBUTEENUM_Xdp)
+ {
+ CFX_WideStringC csContentC;
+ submit.GetSubmitXDPContent(csContentC);
+ CFX_WideString csContent;
+ csContent = csContentC.GetPtr();
+ csContent.TrimLeft();
+ csContent.TrimRight();
+ CFX_WideString space;
+ space.FromLocal(" ");
+ csContent = space + csContent + space;
+ FPDF_DWORD flag = 0;
+ if (submit.IsSubmitEmbedPDF())
+ flag |= FXFA_PDF;
+ _ToXFAContentFlags(csContent, flag);
+ pFileHandler = pEnv->FFI_OpenFile(FXFA_SAVEAS_XDP, NULL, "wb");
+ fileFlag = FXFA_SAVEAS_XDP;
+ _ExportSubmitFile(pFileHandler, FXFA_SAVEAS_XDP, 0, flag);
+ }
+ else if (submit.GetSubmitFormat() == XFA_ATTRIBUTEENUM_Xml )
+ {
+ pFileHandler = pEnv->FFI_OpenFile(FXFA_SAVEAS_XML, NULL, "wb");
+ fileFlag = FXFA_SAVEAS_XML;
+ _ExportSubmitFile(pFileHandler, FXFA_SAVEAS_XML, 0);
+ }
+ else if (submit.GetSubmitFormat() == XFA_ATTRIBUTEENUM_Pdf )
+ {
+ //csfilename = csDocName;
+ }
+ else if (submit.GetSubmitFormat() == XFA_ATTRIBUTEENUM_Formdata )
+ {
+ return FALSE;
+ }
+ else if (submit.GetSubmitFormat() == XFA_ATTRIBUTEENUM_Urlencoded )
+ {
+ pFileHandler = pEnv->FFI_OpenFile(FXFA_SAVEAS_XML, NULL, "wb");
+ fileFlag = FXFA_SAVEAS_XML;
+ _ExportSubmitFile(pFileHandler, FXFA_SAVEAS_XML, 0);
+ }
+ else if (submit.GetSubmitFormat() == XFA_ATTRIBUTEENUM_Xfd )
+ {
+ return FALSE;
+ }
+ else
+ {
+ return FALSE;
+ }
+ if (pFileHandler == NULL)
+ return FALSE;
+ if (0 == csURL.Left(7).CompareNoCase(L"mailto:"))
+ {
+ CFX_WideString csToAddress;
+ CFX_WideString csCCAddress;
+ CFX_WideString csBCCAddress;
+ CFX_WideString csSubject;
+ CFX_WideString csMsg;
+
+ bRet = _MailToInfo(csURL, csToAddress, csCCAddress, csBCCAddress, csSubject, csMsg);
+ if (FALSE == bRet)
+ return FALSE;
+
+ CFX_ByteString bsTo = CFX_WideString(csToAddress).UTF16LE_Encode();
+ CFX_ByteString bsCC = CFX_WideString(csCCAddress).UTF16LE_Encode();
+ CFX_ByteString bsBcc = CFX_WideString(csBCCAddress).UTF16LE_Encode();
+ CFX_ByteString bsSubject = CFX_WideString(csSubject).UTF16LE_Encode();
+ CFX_ByteString bsMsg = CFX_WideString(csMsg).UTF16LE_Encode();
+
+ FPDF_WIDESTRING pTo = (FPDF_WIDESTRING)bsTo.GetBuffer(bsTo.GetLength());
+ FPDF_WIDESTRING pCC = (FPDF_WIDESTRING)bsCC.GetBuffer(bsCC.GetLength());
+ FPDF_WIDESTRING pBcc = (FPDF_WIDESTRING)bsBcc.GetBuffer(bsBcc.GetLength());
+ FPDF_WIDESTRING pSubject = (FPDF_WIDESTRING)bsSubject.GetBuffer(bsSubject.GetLength());
+ FPDF_WIDESTRING pMsg = (FPDF_WIDESTRING)bsMsg.GetBuffer(bsMsg.GetLength());
+
+ pEnv->FFI_EmailTo(pFileHandler, pTo, pSubject, pCC, pBcc, pMsg);
+ bsTo.ReleaseBuffer();
+ bsCC.ReleaseBuffer();
+ bsBcc.ReleaseBuffer();
+ bsSubject.ReleaseBuffer();
+ bsMsg.ReleaseBuffer();
+ }
+ else
+ {
+ //http¡¢ftp
+ CFX_WideString ws;
+ CFX_ByteString bs = csURL.UTF16LE_Encode();
+ int len = bs.GetLength()/sizeof(unsigned short);
+ pEnv->FFI_UploadTo(pFileHandler, fileFlag, (FPDF_WIDESTRING)bs.GetBuffer(len*sizeof(unsigned short)));
+ bs.ReleaseBuffer(len*sizeof(unsigned short));
+ }
+
+ return bRet;
+}
+
+FX_BOOL CPDFXFA_Document::SetGlobalProperty(XFA_HDOC hDoc, FX_BSTR szPropName, FXJSE_HVALUE hValue)
+{
+ if (hDoc != m_pXFADoc)
+ return FALSE;
+
+ if (m_pSDKDoc && m_pSDKDoc->GetEnv()->GetJSRuntime())
+ return m_pSDKDoc->GetEnv()->GetJSRuntime()->SetHValueByName(szPropName, hValue);
+ return FALSE;
+}
+FX_BOOL CPDFXFA_Document::GetPDFScriptObject(XFA_HDOC hDoc, FX_BSTR utf8Name, FXJSE_HVALUE hValue)
+{
+ if (hDoc != m_pXFADoc)
+ return FALSE;
+
+ if (!m_pSDKDoc || !m_pSDKDoc->GetEnv()->GetJSRuntime())
+ return FALSE;
+
+ if (!m_pJSContext)
+ {
+ m_pSDKDoc->GetEnv()->GetJSRuntime()->SetReaderDocument(m_pSDKDoc);
+ m_pJSContext =m_pSDKDoc->GetEnv()->GetJSRuntime()->NewContext();
+ }
+
+ return _GetHValueByName(utf8Name, hValue, m_pSDKDoc->GetEnv()->GetJSRuntime());
+
+}
+FX_BOOL CPDFXFA_Document::GetGlobalProperty(XFA_HDOC hDoc, FX_BSTR szPropName, FXJSE_HVALUE hValue)
+{
+ if (hDoc != m_pXFADoc)
+ return FALSE;
+ if (!m_pSDKDoc || !m_pSDKDoc->GetEnv()->GetJSRuntime())
+ return FALSE;
+
+ if (!m_pJSContext)
+ {
+ m_pSDKDoc->GetEnv()->GetJSRuntime()->SetReaderDocument(m_pSDKDoc);
+ m_pJSContext = m_pSDKDoc->GetEnv()->GetJSRuntime()->NewContext();
+ }
+
+ return _GetHValueByName(szPropName, hValue, m_pSDKDoc->GetEnv()->GetJSRuntime());
+
+}
+FX_BOOL CPDFXFA_Document::_GetHValueByName(FX_BSTR utf8Name, FXJSE_HVALUE hValue, IFXJS_Runtime* runTime)
+{
+ return runTime->GetHValueByName(utf8Name, hValue);
+}
+
diff --git a/fpdfsdk/src/fpdfxfa/fpdfxfa_page.cpp b/fpdfsdk/src/fpdfxfa/fpdfxfa_page.cpp
new file mode 100644
index 0000000000..cf05d4ced7
--- /dev/null
+++ b/fpdfsdk/src/fpdfxfa/fpdfxfa_page.cpp
@@ -0,0 +1,276 @@
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/fsdk_define.h"
+#include "../../include/fsdk_mgr.h"
+#include "../../include/fpdfxfa/fpdfxfa_util.h"
+#include "../../include/fpdfxfa/fpdfxfa_doc.h"
+#include "../../include/fpdfxfa/fpdfxfa_page.h"
+
+CPDFXFA_Page::CPDFXFA_Page(CPDFXFA_Document* pDoc, int page_index) :
+ m_pPDFPage(NULL),
+ m_pXFAPageView(NULL),
+ m_iPageIndex(page_index),
+ m_pDocument(pDoc),
+ m_iRef(1)
+{
+
+}
+
+CPDFXFA_Page::~CPDFXFA_Page()
+{
+ if (m_pPDFPage)
+ delete m_pPDFPage;
+ m_pPDFPage = NULL;
+ m_pXFAPageView = NULL;
+}
+
+void CPDFXFA_Page::Release()
+{
+ m_iRef--;
+ if (m_iRef > 0)
+ return;
+
+ if (m_pDocument)
+ m_pDocument->RemovePage(this);
+
+ delete this;
+}
+
+FX_BOOL CPDFXFA_Page::LoadPDFPage()
+{
+ if (!m_pDocument) return FALSE;
+ CPDF_Document* pPDFDoc = m_pDocument->GetPDFDoc();
+ if (pPDFDoc)
+ {
+ CPDF_Dictionary* pDict = pPDFDoc->GetPage(m_iPageIndex);
+ if (pDict == NULL) return FALSE;
+ if (m_pPDFPage) {
+ if (m_pPDFPage->m_pFormDict == pDict)
+ return TRUE;
+
+ delete m_pPDFPage;
+ m_pPDFPage = NULL;
+ }
+
+ m_pPDFPage = FX_NEW CPDF_Page;
+ m_pPDFPage->Load(pPDFDoc, pDict);
+ m_pPDFPage->ParseContent();
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+FX_BOOL CPDFXFA_Page::LoadXFAPageView()
+{
+ if (!m_pDocument)
+ return FALSE;
+ XFA_HDOC pXFADoc = m_pDocument->GetXFADoc();
+ if (pXFADoc)
+ {
+ IXFA_DocView* pXFADocView = m_pDocument->GetXFADocView();
+ if (!pXFADocView)
+ return FALSE;
+
+ IXFA_PageView* pPageView = pXFADocView->GetPageView(m_iPageIndex);
+ if (!pPageView)
+ return FALSE;
+
+ if (m_pXFAPageView)
+ if (m_pXFAPageView == pPageView)
+ return TRUE;
+
+ m_pXFAPageView = pPageView;
+ int iStatus = m_pXFAPageView->LoadPageView(NULL);
+
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+FX_BOOL CPDFXFA_Page::LoadPage()
+{
+ if (!m_pDocument || m_iPageIndex < 0)
+ return FALSE;
+
+ int iDocType = m_pDocument->GetDocType();
+ CPDF_Document* pPDFDoc = m_pDocument->GetPDFDoc();
+ XFA_HDOC pXFADoc = m_pDocument->GetXFADoc();
+
+ switch (iDocType)
+ {
+ case DOCTYPE_PDF:
+ case DOCTYPE_STATIC_XFA:
+ {
+ return LoadPDFPage();
+ }
+ case DOCTYPE_DYNIMIC_XFA:
+ {
+ return LoadXFAPageView();
+ }
+ default:
+ return FALSE;
+ }
+
+ return FALSE;
+}
+
+FX_BOOL CPDFXFA_Page::LoadPDFPage(CPDF_Dictionary* pageDict)
+{
+ if (!m_pDocument || m_iPageIndex < 0 || !pageDict)
+ return FALSE;
+
+ if (m_pPDFPage)
+ delete m_pPDFPage;
+
+ m_pPDFPage = FX_NEW CPDF_Page();
+ m_pPDFPage->Load(m_pDocument->GetPDFDoc(), pageDict);
+ m_pPDFPage->ParseContent();
+
+ return TRUE;
+}
+
+FX_FLOAT CPDFXFA_Page::GetPageWidth()
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (!m_pPDFPage && !m_pXFAPageView)
+ return 0.0f;
+
+ int nDocType = m_pDocument->GetDocType();
+ switch (nDocType)
+ {
+ case DOCTYPE_DYNIMIC_XFA:
+ {
+ if (m_pXFAPageView)
+ {
+ CFX_RectF rect;
+ m_pXFAPageView->GetPageViewRect(rect);
+ return rect.width;
+ }
+ }
+ break;
+ case DOCTYPE_STATIC_XFA:
+ case DOCTYPE_PDF:
+ {
+ if (m_pPDFPage)
+ return m_pPDFPage->GetPageWidth();
+ }
+ break;
+ default:
+ return 0.0f;
+ }
+
+ return 0.0f;
+}
+
+FX_FLOAT CPDFXFA_Page::GetPageHeight()
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (!m_pPDFPage && !m_pXFAPageView)
+ return 0.0f;
+
+ int nDocType = m_pDocument->GetDocType();
+ switch (nDocType)
+ {
+ case DOCTYPE_PDF:
+ case DOCTYPE_STATIC_XFA:
+ {
+ if (m_pPDFPage)
+ return m_pPDFPage->GetPageHeight();
+ }
+ break;
+ case DOCTYPE_DYNIMIC_XFA:
+ {
+ if (m_pXFAPageView)
+ {
+ CFX_RectF rect;
+ m_pXFAPageView->GetPageViewRect(rect);
+ return rect.height;
+ }
+ }
+ break;
+ default:
+ return 0.0f;
+ }
+
+ return 0.0f;
+}
+
+void CPDFXFA_Page::DeviceToPage(int start_x, int start_y, int size_x, int size_y, int rotate, int device_x, int device_y, double* page_x, double* page_y)
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (!m_pPDFPage && !m_pXFAPageView)
+ return;
+
+ CPDF_Matrix page2device;
+ CPDF_Matrix device2page;
+ FX_FLOAT page_x_f, page_y_f;
+
+ GetDisplayMatrix(page2device, start_x, start_y, size_x, size_y, rotate);
+
+ device2page.SetReverse(page2device);
+ device2page.Transform((FX_FLOAT)(device_x), (FX_FLOAT)(device_y), page_x_f, page_y_f);
+
+ *page_x = (page_x_f);
+ *page_y = (page_y_f);
+}
+
+void CPDFXFA_Page::PageToDevice(int start_x, int start_y, int size_x, int size_y, int rotate, double page_x, double page_y, int* device_x, int* device_y)
+{
+ if (!m_pPDFPage && !m_pXFAPageView)
+ return;
+
+ CPDF_Matrix page2device;
+ FX_FLOAT device_x_f, device_y_f;
+
+ GetDisplayMatrix(page2device, start_x, start_y, size_x, size_y, rotate);
+
+ page2device.Transform(((FX_FLOAT)page_x), ((FX_FLOAT)page_y), device_x_f, device_y_f);
+
+ *device_x = FXSYS_round(device_x_f);
+ *device_y = FXSYS_round(device_y_f);
+}
+
+void CPDFXFA_Page::GetDisplayMatrix(CFX_AffineMatrix& matrix, int xPos, int yPos,
+ int xSize, int ySize, int iRotate) const
+{
+ ASSERT(m_pDocument != NULL);
+
+ if (!m_pPDFPage && !m_pXFAPageView)
+ return;
+
+ int nDocType = m_pDocument->GetDocType();
+ switch (nDocType)
+ {
+ case DOCTYPE_DYNIMIC_XFA:
+ {
+ if (m_pXFAPageView)
+ {
+ CFX_Rect rect;
+ rect.Set(xPos, yPos, xSize, ySize);
+ m_pXFAPageView->GetDisplayMatrix(matrix, rect, iRotate);
+ }
+ }
+ break;
+ case DOCTYPE_PDF:
+ case DOCTYPE_STATIC_XFA:
+ {
+ if (m_pPDFPage)
+ {
+ m_pPDFPage->GetDisplayMatrix(matrix, xPos, yPos, xSize, ySize, iRotate);
+ }
+ }
+ break;
+ default:
+ return;
+ }
+
+}
diff --git a/fpdfsdk/src/fpdfxfa/fpdfxfa_util.cpp b/fpdfsdk/src/fpdfxfa/fpdfxfa_util.cpp
new file mode 100644
index 0000000000..9bf1b63c8f
--- /dev/null
+++ b/fpdfsdk/src/fpdfxfa/fpdfxfa_util.cpp
@@ -0,0 +1,96 @@
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "../../include/fsdk_define.h"
+#include "../../include/fsdk_mgr.h"
+#include "../../include/fpdfxfa/fpdfxfa_util.h"
+
+FX_BOOL FPDF_HasXFAField(CPDF_Document* pPDFDoc, int& docType)
+{
+ if (!pPDFDoc)
+ return FALSE;
+
+ CPDF_Dictionary* pRoot = pPDFDoc->GetRoot();
+ if (!pRoot)
+ return FALSE;
+
+ CPDF_Dictionary* pAcroForm = pRoot->GetDict("AcroForm");
+ if (!pAcroForm)
+ return FALSE;
+
+ CPDF_Object* pXFA = pAcroForm->GetElement("XFA");
+ if (!pXFA)
+ return FALSE;
+
+ FX_BOOL bDymasticXFA = FALSE;
+ bDymasticXFA = pRoot->GetBoolean("NeedsRendering", FALSE);
+
+ if(bDymasticXFA)
+ docType = DOCTYPE_DYNIMIC_XFA;
+ else
+ docType = DOCTYPE_STATIC_XFA;
+
+ return TRUE;
+}
+
+CFX_PtrArray CXFA_FWLAdapterTimerMgr::ms_timerArray;
+
+FWL_ERR CXFA_FWLAdapterTimerMgr::Start(IFWL_Timer *pTimer, FX_DWORD dwElapse, FWL_HTIMER &hTimer, FX_BOOL bImmediately /* = TRUE */)
+{
+ if (m_pEnv)
+ {
+ FX_UINT32 uIDEvent = m_pEnv->FFI_SetTimer(dwElapse, TimerProc);
+ CFWL_TimerInfo *pInfo = FX_NEW CFWL_TimerInfo;
+ pInfo->uIDEvent = uIDEvent;
+ pInfo->pTimer = pTimer;
+ ms_timerArray.Add(pInfo);
+
+ hTimer = (FWL_HTIMER)pInfo;
+ return FWL_ERR_Succeeded;
+ }
+
+ return FWL_ERR_Indefinite;
+}
+
+FWL_ERR CXFA_FWLAdapterTimerMgr::Stop(FWL_HTIMER hTimer)
+{
+ if (!hTimer) return FWL_ERR_Indefinite;
+
+ if (m_pEnv)
+ {
+ CFWL_TimerInfo *pInfo = (CFWL_TimerInfo*)hTimer;
+
+ m_pEnv->FFI_KillTimer(pInfo->uIDEvent);
+
+ FX_INT32 index = ms_timerArray.Find(pInfo);
+ if (index >= 0)
+ {
+ ms_timerArray.RemoveAt(index);
+ delete pInfo;
+ }
+ return FWL_ERR_Succeeded;
+ }
+
+ return FWL_ERR_Indefinite;
+}
+
+void CXFA_FWLAdapterTimerMgr::TimerProc(FX_INT32 idEvent)
+{
+ CFWL_TimerInfo *pInfo = NULL;
+ FX_INT32 iCount = CXFA_FWLAdapterTimerMgr::ms_timerArray.GetSize();
+ for (FX_INT32 i = 0; i < iCount; i++)
+ {
+ CFWL_TimerInfo *pTemp = (CFWL_TimerInfo*)CXFA_FWLAdapterTimerMgr::ms_timerArray.GetAt(i);
+ if (pTemp->uIDEvent == idEvent)
+ {
+ pInfo = pTemp; break;
+ }
+ }
+ if (pInfo)
+ {
+ pInfo->pTimer->Run((FWL_HTIMER)pInfo);
+ }
+}