summaryrefslogtreecommitdiff
path: root/fpdfsdk/src
diff options
context:
space:
mode:
Diffstat (limited to 'fpdfsdk/src')
-rw-r--r--fpdfsdk/src/formfiller/FFL_ComboBox.cpp13
-rw-r--r--fpdfsdk/src/formfiller/FFL_FormFiller.cpp11
-rw-r--r--fpdfsdk/src/formfiller/FFL_IFormFiller.cpp202
-rw-r--r--fpdfsdk/src/formfiller/FFL_TextField.cpp12
-rw-r--r--fpdfsdk/src/fpdf_dataavail.cpp13
-rw-r--r--fpdfsdk/src/fpdf_ext.cpp3
-rw-r--r--fpdfsdk/src/fpdf_flatten.cpp7
-rw-r--r--fpdfsdk/src/fpdf_progressive.cpp13
-rw-r--r--fpdfsdk/src/fpdf_transformpage.cpp22
-rw-r--r--fpdfsdk/src/fpdfdoc.cpp22
-rw-r--r--fpdfsdk/src/fpdfeditimg.cpp15
-rw-r--r--fpdfsdk/src/fpdfeditpage.cpp44
-rw-r--r--fpdfsdk/src/fpdfformfill.cpp459
-rw-r--r--fpdfsdk/src/fpdfppo.cpp25
-rw-r--r--fpdfsdk/src/fpdfsave.cpp275
-rw-r--r--fpdfsdk/src/fpdftext.cpp10
-rw-r--r--fpdfsdk/src/fpdfview.cpp360
-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
-rw-r--r--fpdfsdk/src/fsdk_actionhandler.cpp5
-rw-r--r--fpdfsdk/src/fsdk_annothandler.cpp494
-rw-r--r--fpdfsdk/src/fsdk_baseannot.cpp130
-rw-r--r--fpdfsdk/src/fsdk_baseform.cpp843
-rw-r--r--fpdfsdk/src/fsdk_mgr.cpp337
-rw-r--r--fpdfsdk/src/javascript/Document.cpp26
-rw-r--r--fpdfsdk/src/javascript/Field.cpp2
-rw-r--r--fpdfsdk/src/javascript/JS_Context.cpp1
-rw-r--r--fpdfsdk/src/javascript/JS_GlobalData.cpp2
-rw-r--r--fpdfsdk/src/javascript/JS_Object.cpp4
-rw-r--r--fpdfsdk/src/javascript/JS_Runtime.cpp74
-rw-r--r--fpdfsdk/src/javascript/app.cpp25
-rw-r--r--fpdfsdk/src/javascript/global.cpp5
-rw-r--r--fpdfsdk/src/jsapi/fxjs_v8.cpp51
-rw-r--r--fpdfsdk/src/pdfwindow/PWL_ComboBox.cpp36
36 files changed, 5565 insertions, 464 deletions
diff --git a/fpdfsdk/src/formfiller/FFL_ComboBox.cpp b/fpdfsdk/src/formfiller/FFL_ComboBox.cpp
index ee6b7bd83a..1c5b49812e 100644
--- a/fpdfsdk/src/formfiller/FFL_ComboBox.cpp
+++ b/fpdfsdk/src/formfiller/FFL_ComboBox.cpp
@@ -348,6 +348,19 @@ void CFFL_ComboBox::OnKeyStroke(FX_BOOL bKeyDown, FX_UINT nFlag)
}
}
+FX_BOOL CFFL_ComboBox::IsFieldFull(CPDFSDK_PageView* pPageView)
+{
+ if (CPWL_ComboBox* pComboBox = (CPWL_ComboBox*)GetPDFWindow(pPageView, FALSE))
+ {
+ if (CPWL_Edit* pEdit = (CPWL_Edit*)*pComboBox)
+ {
+ return pEdit->IsTextFull();
+ }
+ }
+
+ return FALSE;
+}
+
void CFFL_ComboBox::OnSetFocus(CPWL_Wnd* pWnd)
{
ASSERT(m_pApp != NULL);
diff --git a/fpdfsdk/src/formfiller/FFL_FormFiller.cpp b/fpdfsdk/src/formfiller/FFL_FormFiller.cpp
index 530b80ce6f..c9dd6681d2 100644
--- a/fpdfsdk/src/formfiller/FFL_FormFiller.cpp
+++ b/fpdfsdk/src/formfiller/FFL_FormFiller.cpp
@@ -292,7 +292,7 @@ FX_BOOL CFFL_FormFiller::OnSetFocus(CPDFSDK_Annot* pAnnot, FX_UINT nFlag)
{
CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
- CPDF_Page * pPage = pWidget->GetPDFPage();
+ CPDFXFA_Page * pPage = pWidget->GetPDFXFAPage();
CPDFSDK_Document * pDoc = m_pApp->GetCurrentDoc();
CPDFSDK_PageView* pPageView = pDoc->GetPageView(pPage);
ASSERT(pPageView != NULL);
@@ -567,7 +567,7 @@ CPDF_Rect CFFL_FormFiller::GetPDFWindowRect() const
CPDFSDK_PageView* CFFL_FormFiller::GetCurPageView()
{
- CPDF_Page* pPage = m_pAnnot->GetPDFPage();
+ CPDFXFA_Page* pPage = m_pAnnot->GetPDFXFAPage();
CPDFSDK_Document* pSDKDoc = m_pApp->GetCurrentDoc();
if(pSDKDoc)
{
@@ -713,6 +713,11 @@ void CFFL_FormFiller::GetKeyStrokeData(CPDFSDK_PageView* pPageView, FFL_KeyStrok
{
}
+FX_BOOL CFFL_FormFiller::IsFieldFull(CPDFSDK_PageView* pPageView)
+{
+ return FALSE;
+}
+
void CFFL_FormFiller::SetChangeMark()
{
m_pApp->FFI_OnChange();
@@ -803,7 +808,7 @@ void CFFL_FormFiller::DoPaste(CPDFSDK_Document* pDocument)
void CFFL_FormFiller::InvalidateRect(double left, double top, double right, double bottom)
{
- CPDF_Page * pPage = m_pWidget->GetPDFPage();
+ CPDFXFA_Page * pPage = m_pWidget->GetPDFXFAPage();
m_pApp->FFI_Invalidate(pPage, left, top, right, bottom);
}
diff --git a/fpdfsdk/src/formfiller/FFL_IFormFiller.cpp b/fpdfsdk/src/formfiller/FFL_IFormFiller.cpp
index 2b21e13cfc..61cb55f66d 100644
--- a/fpdfsdk/src/formfiller/FFL_IFormFiller.cpp
+++ b/fpdfsdk/src/formfiller/FFL_IFormFiller.cpp
@@ -335,6 +335,9 @@ FX_BOOL CFFL_IFormFiller::OnLButtonUp(CPDFSDK_PageView* pPageView, CPDFSDK_Annot
FX_BOOL bReset = FALSE;
OnButtonUp(pWidget, pPageView, bReset, bExit,nFlags);
if (bExit) return TRUE;
+
+ OnClick(pWidget, pPageView, bReset, bExit, nFlags);
+ if (bExit) return TRUE;
}
return bRet;
}
@@ -830,7 +833,7 @@ void CFFL_IFormFiller::OnSetWindowRect(void* pPrivateData, const CPDF_Rect & rcW
unRect.right = (FX_FLOAT)(unRect.right + 0.5);
unRect.top = (FX_FLOAT)(unRect.top + 0.5);
unRect.bottom = (FX_FLOAT)(unRect.bottom -0.5);
- m_pApp->FFI_Invalidate(pData->pWidget->GetPDFPage(), unRect.left, unRect.top, unRect.right, unRect.bottom);
+ m_pApp->FFI_Invalidate(pData->pWidget->GetPDFXFAPage(), unRect.left, unRect.top, unRect.right, unRect.bottom);
}
}
@@ -1037,6 +1040,190 @@ FX_BOOL CFFL_IFormFiller::GetKeyDown()
// return msg.message == WM_KEYDOWN || msg.message == WM_CHAR;
}
+void CFFL_IFormFiller::OnClick(CPDFSDK_Widget* pWidget, CPDFSDK_PageView* pPageView, FX_BOOL& bReset, FX_BOOL& bExit, FX_UINT nFlag)
+{
+ ASSERT(pWidget != NULL);
+
+ if (!m_bNotifying)
+ {
+ if (pWidget->HasXFAAAction(PDFSDK_XFA_Click))
+ {
+ m_bNotifying = TRUE;
+ int nAge = pWidget->GetAppearanceAge();
+ int nValueAge = pWidget->GetValueAge();
+
+ PDFSDK_FieldAction fa;
+ fa.bModifier = m_pApp->FFI_IsCTRLKeyDown(nFlag);
+ fa.bShift = m_pApp->FFI_IsSHIFTKeyDown(nFlag);
+
+ pWidget->OnXFAAAction(PDFSDK_XFA_Click, fa, pPageView);
+ m_bNotifying = FALSE;
+
+ if (!IsValidAnnot(pPageView, pWidget))
+ {
+ bExit = TRUE;
+ return;
+ }
+
+ if (nAge != pWidget->GetAppearanceAge())
+ {
+ if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, FALSE))
+ {
+ pFormFiller->ResetPDFWindow(pPageView, nValueAge == pWidget->GetValueAge());
+ }
+
+ bReset = TRUE;
+ }
+ }
+ }
+}
+
+void CFFL_IFormFiller::OnFull(CPDFSDK_Widget* pWidget, CPDFSDK_PageView* pPageView, FX_BOOL& bReset, FX_BOOL& bExit, FX_UINT nFlag)
+{
+ ASSERT(pWidget != NULL);
+
+ if (!m_bNotifying)
+ {
+ if (pWidget->HasXFAAAction(PDFSDK_XFA_Full))
+ {
+ m_bNotifying = TRUE;
+ int nAge = pWidget->GetAppearanceAge();
+ int nValueAge = pWidget->GetValueAge();
+
+ PDFSDK_FieldAction fa;
+ fa.bModifier = m_pApp->FFI_IsCTRLKeyDown(nFlag);
+ fa.bShift = m_pApp->FFI_IsSHIFTKeyDown(nFlag);
+
+ pWidget->OnXFAAAction(PDFSDK_XFA_Full, fa, pPageView);
+ m_bNotifying = FALSE;
+
+ if (!IsValidAnnot(pPageView, pWidget))
+ {
+ bExit = TRUE;
+ return;
+ }
+
+ if (nAge != pWidget->GetAppearanceAge())
+ {
+ if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, FALSE))
+ {
+ pFormFiller->ResetPDFWindow(pPageView, nValueAge == pWidget->GetValueAge());
+ }
+
+ bReset = TRUE;
+ }
+ }
+ }
+}
+
+void CFFL_IFormFiller::OnPopupPreOpen(void* pPrivateData, FX_BOOL& bExit, FX_DWORD nFlag)
+{
+ ASSERT(pPrivateData != NULL);
+ CFFL_PrivateData* pData = (CFFL_PrivateData*)pPrivateData;
+ ASSERT(pData->pWidget != NULL);
+
+ FX_BOOL bTempReset = FALSE;
+ FX_BOOL bTempExit = FALSE;
+ this->OnPreOpen(pData->pWidget, pData->pPageView, bTempReset, bTempExit, nFlag);
+
+ if (bTempReset || bTempExit)
+ {
+ bExit = TRUE;
+ }
+}
+
+void CFFL_IFormFiller::OnPopupPostOpen(void* pPrivateData, FX_BOOL& bExit, FX_DWORD nFlag)
+{
+ ASSERT(pPrivateData != NULL);
+ CFFL_PrivateData* pData = (CFFL_PrivateData*)pPrivateData;
+ ASSERT(pData->pWidget != NULL);
+
+ FX_BOOL bTempReset = FALSE;
+ FX_BOOL bTempExit = FALSE;
+ this->OnPostOpen(pData->pWidget, pData->pPageView, bTempReset, bTempExit, nFlag);
+
+ if (bTempReset || bTempExit)
+ {
+ bExit = TRUE;
+ }
+}
+
+void CFFL_IFormFiller::OnPreOpen(CPDFSDK_Widget* pWidget, CPDFSDK_PageView* pPageView, FX_BOOL& bReset, FX_BOOL& bExit, FX_UINT nFlag)
+{
+ ASSERT(pWidget != NULL);
+
+ if (!m_bNotifying)
+ {
+ if (pWidget->HasXFAAAction(PDFSDK_XFA_PreOpen))
+ {
+ m_bNotifying = TRUE;
+ int nAge = pWidget->GetAppearanceAge();
+ int nValueAge = pWidget->GetValueAge();
+
+ PDFSDK_FieldAction fa;
+ fa.bModifier = m_pApp->FFI_IsCTRLKeyDown(nFlag);
+ fa.bShift = m_pApp->FFI_IsSHIFTKeyDown(nFlag);
+
+ pWidget->OnXFAAAction(PDFSDK_XFA_PreOpen, fa, pPageView);
+ m_bNotifying = FALSE;
+
+ if (!IsValidAnnot(pPageView, pWidget))
+ {
+ bExit = TRUE;
+ return;
+ }
+
+ if (nAge != pWidget->GetAppearanceAge())
+ {
+ if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, FALSE))
+ {
+ pFormFiller->ResetPDFWindow(pPageView, nValueAge == pWidget->GetValueAge());
+ }
+
+ bReset = TRUE;
+ }
+ }
+ }
+}
+
+void CFFL_IFormFiller::OnPostOpen(CPDFSDK_Widget* pWidget, CPDFSDK_PageView* pPageView, FX_BOOL& bReset, FX_BOOL& bExit, FX_UINT nFlag)
+{
+ ASSERT(pWidget != NULL);
+
+ if (!m_bNotifying)
+ {
+ if (pWidget->HasXFAAAction(PDFSDK_XFA_PostOpen))
+ {
+ m_bNotifying = TRUE;
+ int nAge = pWidget->GetAppearanceAge();
+ int nValueAge = pWidget->GetValueAge();
+
+ PDFSDK_FieldAction fa;
+ fa.bModifier = m_pApp->FFI_IsCTRLKeyDown(nFlag);
+ fa.bShift = m_pApp->FFI_IsSHIFTKeyDown(nFlag);
+
+ pWidget->OnXFAAAction(PDFSDK_XFA_PostOpen, fa, pPageView);
+ m_bNotifying = FALSE;
+
+ if (!IsValidAnnot(pPageView, pWidget))
+ {
+ bExit = TRUE;
+ return;
+ }
+
+ if (nAge != pWidget->GetAppearanceAge())
+ {
+ if (CFFL_FormFiller* pFormFiller = GetFormFiller(pWidget, FALSE))
+ {
+ pFormFiller->ResetPDFWindow(pPageView, nValueAge == pWidget->GetValueAge());
+ }
+
+ bReset = TRUE;
+ }
+ }
+ }
+}
+
FX_BOOL CFFL_IFormFiller::IsValidAnnot(CPDFSDK_PageView* pPageView, CPDFSDK_Annot* pAnnot)
{
@@ -1109,6 +1296,19 @@ void CFFL_IFormFiller::OnBeforeKeyStroke(FX_BOOL bEditOrList, void* pPrivateData
CFFL_FormFiller* pFormFiller = GetFormFiller(pData->pWidget, FALSE);
ASSERT(pFormFiller != NULL);
+ if (pFormFiller->IsFieldFull(pData->pPageView))
+ {
+ FX_BOOL bFullExit = FALSE;
+ FX_BOOL bFullReset = FALSE;
+ OnFull(pData->pWidget, pData->pPageView, bFullReset, bFullExit, nFlag);
+
+ if (bFullReset || bFullExit)
+ {
+ bExit = TRUE;
+ return;
+ }
+ }
+
if (!m_bNotifying)
{
if (pData->pWidget->GetAAction(CPDF_AAction::KeyStroke))
diff --git a/fpdfsdk/src/formfiller/FFL_TextField.cpp b/fpdfsdk/src/formfiller/FFL_TextField.cpp
index 45c716280c..f9c93914a5 100644
--- a/fpdfsdk/src/formfiller/FFL_TextField.cpp
+++ b/fpdfsdk/src/formfiller/FFL_TextField.cpp
@@ -176,7 +176,7 @@ FX_BOOL CFFL_TextField::OnChar(CPDFSDK_Annot* pAnnot, FX_UINT nChar, FX_UINT nFl
ASSERT(pPageView != NULL);
m_bValid = !m_bValid;
CPDF_Rect rcAnnot = pAnnot->GetRect();
- m_pApp->FFI_Invalidate(pAnnot->GetPDFPage(), rcAnnot.left, rcAnnot.top, rcAnnot.right, rcAnnot.bottom);
+ m_pApp->FFI_Invalidate(pAnnot->GetPDFXFAPage(), rcAnnot.left, rcAnnot.top, rcAnnot.right, rcAnnot.bottom);
if (m_bValid)
{
@@ -348,6 +348,16 @@ CPWL_Wnd* CFFL_TextField::ResetPDFWindow(CPDFSDK_PageView* pPageView, FX_BOOL bR
return pRet;
}
+FX_BOOL CFFL_TextField::IsFieldFull(CPDFSDK_PageView* pPageView)
+{
+ if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, FALSE))
+ {
+ return pWnd->IsTextFull();
+ }
+
+ return FALSE;
+}
+
void CFFL_TextField::OnSetFocus(CPWL_Wnd* pWnd)
{
ASSERT(m_pApp != NULL);
diff --git a/fpdfsdk/src/fpdf_dataavail.cpp b/fpdfsdk/src/fpdf_dataavail.cpp
index b5483f9c39..efd12078a4 100644
--- a/fpdfsdk/src/fpdf_dataavail.cpp
+++ b/fpdfsdk/src/fpdf_dataavail.cpp
@@ -6,6 +6,9 @@
#include "../include/fsdk_define.h"
#include "../include/fpdf_dataavail.h"
+#include "../include/fpdfxfa/fpdfxfa_doc.h"
+#include "../include/fpdfformfill.h"
+#include "../include/fpdfxfa/fpdfxfa_app.h"
extern void ProcessParseError(FX_DWORD err_code);
class CFPDF_FileAvailWrap : public IFX_FileAvail
@@ -133,13 +136,19 @@ DLLEXPORT FPDF_DOCUMENT STDCALL FPDFAvail_GetDocument(FPDF_AVAIL avail, FPDF_BYT
}
((CFPDF_DataAvail*)avail)->m_pDataAvail->SetDocument(pParser->GetDocument());
CheckUnSupportError(pParser->GetDocument(), FPDF_ERR_SUCCESS);
- return pParser->GetDocument();
+ CPDF_Document* pPDFDoc = pParser->GetDocument();
+
+ CPDFXFA_App* pApp = FPDFXFA_GetApp();
+ CPDFXFA_Document* pDocument = FX_NEW CPDFXFA_Document(pPDFDoc, pApp);
+ //pDocument->LoadXFADoc();
+
+ return pDocument;
}
DLLEXPORT int STDCALL FPDFAvail_GetFirstPageNum(FPDF_DOCUMENT doc)
{
if (doc == NULL) return 0;
- CPDF_Document* pDoc = (CPDF_Document*)doc;
+ CPDF_Document* pDoc = ((CPDFXFA_Document*)doc)->GetPDFDoc();
return ((CPDF_Parser*)pDoc->GetParser())->GetFirstPageNo();
}
diff --git a/fpdfsdk/src/fpdf_ext.cpp b/fpdfsdk/src/fpdf_ext.cpp
index 93f6e187da..512a617920 100644
--- a/fpdfsdk/src/fpdf_ext.cpp
+++ b/fpdfsdk/src/fpdf_ext.cpp
@@ -6,6 +6,7 @@
#include "../include/fsdk_define.h"
#include "../include/fpdf_ext.h"
+#include "../include/fpdfxfa/fpdfxfa_doc.h"
#define FPDFSDK_UNSUPPORT_CALL 100
@@ -220,7 +221,7 @@ void CheckUnSupportError(CPDF_Document * pDoc, FX_DWORD err_code)
DLLEXPORT int FPDFDoc_GetPageMode(FPDF_DOCUMENT document)
{
if (!document) return PAGEMODE_UNKNOWN;
- CPDF_Dictionary *pRoot = ((CPDF_Document*)document)->GetRoot();
+ CPDF_Dictionary *pRoot = (((CPDFXFA_Document*)document)->GetPDFDoc())->GetRoot();
if (!pRoot)
return PAGEMODE_UNKNOWN;
CPDF_Object* pName = pRoot->GetElement("PageMode");
diff --git a/fpdfsdk/src/fpdf_flatten.cpp b/fpdfsdk/src/fpdf_flatten.cpp
index 6d3440f556..e07ccc91b7 100644
--- a/fpdfsdk/src/fpdf_flatten.cpp
+++ b/fpdfsdk/src/fpdf_flatten.cpp
@@ -6,6 +6,8 @@
#include "../include/fsdk_define.h"
#include "../include/fpdf_flatten.h"
+#include "../include/fpdfxfa/fpdfxfa_doc.h"
+#include "../include/fpdfxfa/fpdfxfa_page.h"
typedef CFX_ArrayTemplate<CPDF_Dictionary*> CPDF_ObjectArray;
typedef CFX_ArrayTemplate<CPDF_Rect> CPDF_RectArray;
@@ -332,7 +334,10 @@ DLLEXPORT int STDCALL FPDFPage_Flatten( FPDF_PAGE page, int nFlag)
return FLATTEN_FAIL;
}
- CPDF_Page * pPage = (CPDF_Page*)( page );
+ CPDF_Page * pPage = ((CPDFXFA_Page*)( page ))->GetPDFPage();
+ if (!pPage)
+ return FLATTEN_FAIL;
+
CPDF_Document * pDocument = pPage->m_pDocument;
CPDF_Dictionary * pPageDict = pPage->m_pFormDict;
diff --git a/fpdfsdk/src/fpdf_progressive.cpp b/fpdfsdk/src/fpdf_progressive.cpp
index 2490df8c2f..5226770d48 100644
--- a/fpdfsdk/src/fpdf_progressive.cpp
+++ b/fpdfsdk/src/fpdf_progressive.cpp
@@ -8,6 +8,8 @@
#include "../include/fsdk_define.h"
#include "../include/fpdfview.h"
#include "../include/fsdk_rendercontext.h"
+#include "../include/fpdfxfa/fpdfxfa_doc.h"
+#include "../include/fpdfxfa/fpdfxfa_page.h"
extern void (*Func_RenderPage)( CRenderContext*, FPDF_PAGE page, int start_x, int start_y, int size_x, int size_y,
int rotate, int flags,FX_BOOL bNeedToRestore, IFSDK_PAUSE_Adapter * pause );
@@ -28,7 +30,9 @@ DLLEXPORT int STDCALL FPDF_RenderPageBitmap_Start( FPDF_BITMAP bitmap, FPDF_PAGE
if (pause->version !=1)
return FPDF_RENDER_FAILED;
- CPDF_Page* pPage = (CPDF_Page*)page;
+ CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage();
+ if (!pPage)
+ return FPDF_RENDER_FAILED;
// FXMT_CSLOCK_OBJ(&pPage->m_PageLock);
@@ -71,7 +75,9 @@ DLLEXPORT int STDCALL FPDF_RenderPage_Continue(FPDF_PAGE page,IFSDK_PAUSE * paus
if (pause->version !=1)
return FPDF_RENDER_FAILED;
- CPDF_Page* pPage = (CPDF_Page*)page;
+ CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage();
+ if (!pPage)
+ return FPDF_RENDER_FAILED;
// FXMT_CSLOCK_OBJ(&pPage->m_PageLock);
@@ -92,7 +98,8 @@ DLLEXPORT int STDCALL FPDF_RenderPage_Continue(FPDF_PAGE page,IFSDK_PAUSE * paus
DLLEXPORT void STDCALL FPDF_RenderPage_Close(FPDF_PAGE page)
{
if (page == NULL) return;
- CPDF_Page* pPage = (CPDF_Page*)page;
+ CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage();
+ if (!pPage) return;
// FXMT_CSLOCK_OBJ(&pPage->m_PageLock);
diff --git a/fpdfsdk/src/fpdf_transformpage.cpp b/fpdfsdk/src/fpdf_transformpage.cpp
index a666666d55..043c02cc27 100644
--- a/fpdfsdk/src/fpdf_transformpage.cpp
+++ b/fpdfsdk/src/fpdf_transformpage.cpp
@@ -6,12 +6,15 @@
#include "../include/fsdk_define.h"
#include "../include/fpdf_transformpage.h"
+#include "../include/fpdfxfa/fpdfxfa_doc.h"
+#include "../include/fpdfxfa/fpdfxfa_page.h"
DLLEXPORT void STDCALL FPDFPage_SetMediaBox(FPDF_PAGE page, float left, float bottom, float right, float top)
{
if(!page)
return;
- CPDF_Page* pPage = (CPDF_Page*)page;
+ CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage();
+ if (!pPage) return;
CPDF_Dictionary* pPageDict = pPage->m_pFormDict;
CPDF_Array* pMediaBoxArray = FX_NEW CPDF_Array;
pMediaBoxArray->Add(FX_NEW CPDF_Number(left));
@@ -27,7 +30,8 @@ DLLEXPORT void STDCALL FPDFPage_SetCropBox(FPDF_PAGE page, float left, float bot
{
if(!page)
return;
- CPDF_Page* pPage = (CPDF_Page*)page;
+ CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage();
+ if (!pPage) return;
CPDF_Dictionary* pPageDict = pPage->m_pFormDict;
CPDF_Array* pCropBoxArray = FX_NEW CPDF_Array;
pCropBoxArray->Add(FX_NEW CPDF_Number(left));
@@ -44,7 +48,8 @@ DLLEXPORT FX_BOOL STDCALL FPDFPage_GetMediaBox(FPDF_PAGE page, float* left, floa
{
if(!page)
return FALSE;
- CPDF_Page* pPage = (CPDF_Page*)page;
+ CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage();
+ if (!pPage) return FALSE;
CPDF_Dictionary* pPageDict = pPage->m_pFormDict;
CPDF_Array* pArray = pPageDict->GetArray("MediaBox");
if(pArray)
@@ -62,7 +67,8 @@ DLLEXPORT FPDF_BOOL STDCALL FPDFPage_GetCropBox(FPDF_PAGE page, float* left, flo
{
if(!page)
return FALSE;
- CPDF_Page* pPage = (CPDF_Page*)page;
+ CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage();
+ if (!pPage) return FALSE;
CPDF_Dictionary* pPageDict = pPage->m_pFormDict;
CPDF_Array* pArray = pPageDict->GetArray("CropBox");
if(pArray)
@@ -81,6 +87,10 @@ DLLEXPORT FPDF_BOOL STDCALL FPDFPage_TransFormWithClip(FPDF_PAGE page, FS_MATRIX
if(!page)
return FALSE;
+ CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage();
+ if (!pPage)
+ return FALSE;
+
CFX_ByteTextBuf textBuf;
textBuf<<"q ";
CFX_FloatRect rect(clipRect->left, clipRect->bottom, clipRect->right, clipRect->top);
@@ -94,7 +104,6 @@ DLLEXPORT FPDF_BOOL STDCALL FPDFPage_TransFormWithClip(FPDF_PAGE page, FS_MATRIX
textBuf<<bsMatix;
- CPDF_Page* pPage = (CPDF_Page*)page;
CPDF_Dictionary* pPageDic = pPage->m_pFormDict;
CPDF_Object* pContentObj = pPageDic ? pPageDic->GetElement("Contents") : NULL;
if(!pContentObj)
@@ -258,7 +267,8 @@ DLLEXPORT void STDCALL FPDFPage_InsertClipPath(FPDF_PAGE page,FPDF_CLIPPATH clip
{
if(!page)
return;
- CPDF_Page* pPage = (CPDF_Page*)page;
+ CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage();
+ if (!pPage) return;
CPDF_Dictionary* pPageDic = pPage->m_pFormDict;
CPDF_Object* pContentObj = pPageDic ? pPageDic->GetElement("Contents") : NULL;
if(!pContentObj)
diff --git a/fpdfsdk/src/fpdfdoc.cpp b/fpdfsdk/src/fpdfdoc.cpp
index e974ffbcf2..643e398cfd 100644
--- a/fpdfsdk/src/fpdfdoc.cpp
+++ b/fpdfsdk/src/fpdfdoc.cpp
@@ -6,6 +6,8 @@
#include "../include/fsdk_define.h"
#include "../include/fpdfdoc.h"
+#include "../include/fpdfxfa/fpdfxfa_doc.h"
+#include "../include/fpdfxfa/fpdfxfa_page.h"
static int this_module = 0;
@@ -33,7 +35,7 @@ DLLEXPORT FPDF_BOOKMARK STDCALL FPDFBookmark_Find(FPDF_DOCUMENT document, FPDF_W
if (document == NULL) return NULL;
if (title == NULL || title[0] == 0) return NULL;
- CPDF_Document* pDoc = (CPDF_Document*)document;
+ CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc();
CPDF_BookmarkTree tree(pDoc);
FX_STRSIZE len = CFX_WideString::WStringLength(title);
@@ -47,7 +49,7 @@ DLLEXPORT FPDF_DEST STDCALL FPDFBookmark_GetDest(FPDF_DOCUMENT document, FPDF_BO
if (bookmark == NULL) return NULL;
CPDF_Bookmark Bookmark = (CPDF_Dictionary*)bookmark;
- CPDF_Document* pDoc = (CPDF_Document*)document;
+ CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc();
CPDF_Dest dest = Bookmark.GetDest(pDoc);
if (dest != NULL) return dest;
@@ -90,7 +92,7 @@ DLLEXPORT FPDF_DEST STDCALL FPDFAction_GetDest(FPDF_DOCUMENT document, FPDF_ACTI
{
if (document == NULL) return NULL;
if (action == NULL) return NULL;
- CPDF_Document* pDoc = (CPDF_Document*)document;
+ CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc();
CPDF_Action Action = (CPDF_Dictionary*)action;
return Action.GetDest(pDoc);
@@ -101,7 +103,7 @@ DLLEXPORT unsigned long STDCALL FPDFAction_GetURIPath(FPDF_DOCUMENT document, FP
{
if (document == NULL) return 0;
if (action == NULL) return 0;
- CPDF_Document* pDoc = (CPDF_Document*)document;
+ CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc();
CPDF_Action Action = (CPDF_Dictionary*)action;
CFX_ByteString path = Action.GetURI(pDoc);
@@ -115,7 +117,7 @@ DLLEXPORT unsigned long STDCALL FPDFDest_GetPageIndex(FPDF_DOCUMENT document, FP
{
if (document == NULL) return 0;
if (dest == NULL) return 0;
- CPDF_Document* pDoc = (CPDF_Document*)document;
+ CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc();
CPDF_Dest Dest = (CPDF_Array*)dest;
return Dest.GetPageIndex(pDoc);
@@ -129,7 +131,8 @@ static void ReleaseLinkList(FX_LPVOID data)
DLLEXPORT FPDF_LINK STDCALL FPDFLink_GetLinkAtPoint(FPDF_PAGE page, double x, double y)
{
if (page == NULL) return NULL;
- CPDF_Page* pPage = (CPDF_Page*)page;
+ CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage();
+ if (!pPage) return NULL;
// Link list is stored with the document
CPDF_Document* pDoc = pPage->m_pDocument;
@@ -145,7 +148,7 @@ DLLEXPORT FPDF_LINK STDCALL FPDFLink_GetLinkAtPoint(FPDF_PAGE page, double x, do
DLLEXPORT FPDF_DEST STDCALL FPDFLink_GetDest(FPDF_DOCUMENT document, FPDF_LINK link)
{
if (document == NULL) return NULL;
- CPDF_Document* pDoc = (CPDF_Document*)document;
+ CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc();
if (link == NULL) return NULL;
CPDF_Link Link = (CPDF_Dictionary*)link;
@@ -170,7 +173,8 @@ DLLEXPORT FPDF_BOOL STDCALL FPDFLink_Enumerate(FPDF_PAGE page, int* startPos, FP
{
if(!page || !startPos || !linkAnnot)
return FALSE;
- CPDF_Page* pPage = (CPDF_Page*)page;
+ CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage();
+ if (!pPage) return FALSE;
if(!pPage->m_pFormDict) return FALSE;
CPDF_Array* pAnnots = pPage->m_pFormDict->GetArray("Annots");
if(!pAnnots) return FALSE;
@@ -240,7 +244,7 @@ DLLEXPORT unsigned long STDCALL FPDF_GetMetaText(FPDF_DOCUMENT doc, FPDF_BYTESTR
{
if (doc == NULL || tag == NULL) return 0;
- CPDF_Document* pDoc = (CPDF_Document*)doc;
+ CPDF_Document* pDoc = ((CPDFXFA_Document*)doc)->GetPDFDoc();
// Get info dictionary
CPDF_Dictionary* pInfo = pDoc->GetInfo();
if (pInfo == NULL) return 0;
diff --git a/fpdfsdk/src/fpdfeditimg.cpp b/fpdfsdk/src/fpdfeditimg.cpp
index c29d2b74f8..188b5f070d 100644
--- a/fpdfsdk/src/fpdfeditimg.cpp
+++ b/fpdfsdk/src/fpdfeditimg.cpp
@@ -6,6 +6,8 @@
#include "../include/fsdk_define.h"
#include "../include/fpdfedit.h"
+#include "../include/fpdfxfa/fpdfxfa_doc.h"
+#include "../include/fpdfxfa/fpdfxfa_page.h"
DLLEXPORT FPDF_PAGEOBJECT STDCALL FPDFPageObj_NewImgeObj(FPDF_DOCUMENT document)
@@ -13,14 +15,14 @@ DLLEXPORT FPDF_PAGEOBJECT STDCALL FPDFPageObj_NewImgeObj(FPDF_DOCUMENT document)
if (!document)
return NULL;
CPDF_ImageObject* pImageObj = FX_NEW CPDF_ImageObject;
- CPDF_Image* pImg = FX_NEW CPDF_Image((CPDF_Document *)document);
+ CPDF_Image* pImg = FX_NEW CPDF_Image(((CPDFXFA_Document *)document)->GetPDFDoc());
pImageObj->m_pImage = pImg;
return pImageObj;
}
DLLEXPORT FPDF_BOOL STDCALL FPDFImageObj_LoadJpegFile(FPDF_PAGE* pages, int nCount,FPDF_PAGEOBJECT image_object, FPDF_FILEACCESS* fileAccess)
{
- if (!image_object || !fileAccess)
+ if (!image_object || !fileAccess || !pages)
return FALSE;
IFX_FileRead* pFile = FX_NEW CPDF_CustomAccess(fileAccess);
@@ -29,7 +31,9 @@ DLLEXPORT FPDF_BOOL STDCALL FPDFImageObj_LoadJpegFile(FPDF_PAGE* pages, int nCou
pImgObj->m_GeneralState.GetModify();
for (int index=0;index<nCount;index++)
{
- CPDF_Page* pPage = (CPDF_Page*)pages[index];
+ CPDF_Page* pPage = ((CPDFXFA_Page*)pages[index])->GetPDFPage();
+ if (!pPage)
+ continue;
pImgObj->m_pImage->ResetCache(pPage,NULL);
}
pImgObj->m_pImage->SetJpegImage(pFile);
@@ -56,7 +60,7 @@ DLLEXPORT FPDF_BOOL STDCALL FPDFImageObj_SetMatrix (FPDF_PAGEOBJECT image_object
DLLEXPORT FPDF_BOOL STDCALL FPDFImageObj_SetBitmap(FPDF_PAGE* pages,int nCount,FPDF_PAGEOBJECT image_object,FPDF_BITMAP bitmap)
{
- if (!image_object || !bitmap)
+ if (!image_object || !bitmap || !pages)
return FALSE;
CFX_DIBitmap* pBmp = NULL;
pBmp = (CFX_DIBitmap*)bitmap;
@@ -64,7 +68,8 @@ DLLEXPORT FPDF_BOOL STDCALL FPDFImageObj_SetBitmap(FPDF_PAGE* pages,int nCount,F
pImgObj->m_GeneralState.GetModify();
for (int index=0;index<nCount;index++)
{
- CPDF_Page* pPage = (CPDF_Page*)pages[index];
+ CPDF_Page* pPage = ((CPDFXFA_Page*)pages[index])->GetPDFPage();
+ if (!pPage) continue;
pImgObj->m_pImage->ResetCache(pPage,NULL);
}
pImgObj->m_pImage->SetImage(pBmp,FALSE);
diff --git a/fpdfsdk/src/fpdfeditpage.cpp b/fpdfsdk/src/fpdfeditpage.cpp
index 5c43d4d4b2..68dad9dbfe 100644
--- a/fpdfsdk/src/fpdfeditpage.cpp
+++ b/fpdfsdk/src/fpdfeditpage.cpp
@@ -7,6 +7,10 @@
// #include "x:/pdf/fpdfapi5/include/fpdfapi.h"
#include "../include/fsdk_define.h"
#include "../include/fpdfedit.h"
+#include "../include/fpdfformfill.h"
+#include "../include/fpdfxfa/fpdfxfa_doc.h"
+#include "../include/fpdfxfa/fpdfxfa_app.h"
+#include "../include/fpdfxfa/fpdfxfa_page.h"
#if _FX_OS_ == _FX_ANDROID_
@@ -51,12 +55,15 @@ DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_CreateNewDocument()
#endif
}
- return pDoc;
+ CPDFXFA_App* pApp = FPDFXFA_GetApp();
+ CPDFXFA_Document* document = FX_NEW CPDFXFA_Document(pDoc, pApp);
+
+ return document;
}
DLLEXPORT void STDCALL FPDFPage_Delete(FPDF_DOCUMENT document, int page_index)
{
- CPDF_Document* pDoc = (CPDF_Document*)document;
+ CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc();
if (pDoc == NULL)
return;
if (page_index < 0 || page_index >= pDoc->GetPageCount())
@@ -71,7 +78,7 @@ DLLEXPORT FPDF_PAGE STDCALL FPDFPage_New(FPDF_DOCUMENT document, int page_index,
return NULL;
// CPDF_Parser* pParser = (CPDF_Parser*)document;
- CPDF_Document* pDoc = (CPDF_Document*)document;
+ CPDF_Document* pDoc = ((CPDFXFA_Document*)document)->GetPDFDoc();
if(page_index < 0)
page_index = 0;
if(pDoc->GetPageCount()<page_index)
@@ -92,16 +99,19 @@ DLLEXPORT FPDF_PAGE STDCALL FPDFPage_New(FPDF_DOCUMENT document, int page_index,
pPageDict->SetAt("Rotate", FX_NEW CPDF_Number(0));
pPageDict->SetAt("Resources", FX_NEW CPDF_Dictionary);
- CPDF_Page* pPage = FX_NEW CPDF_Page;
- pPage->Load(pDoc,pPageDict);
- pPage->ParseContent();
+// CPDF_Page* pPage = FX_NEW CPDF_Page;
+// pPage->Load(pDoc,pPageDict);
+// pPage->ParseContent();
+
+ CPDFXFA_Page* pPage = FX_NEW CPDFXFA_Page((CPDFXFA_Document*)document, page_index);
+ pPage->LoadPDFPage(pPageDict);
return pPage;
}
DLLEXPORT int STDCALL FPDFPage_GetRotation(FPDF_PAGE page)
{
- CPDF_Page* pPage = (CPDF_Page*)page;
+ CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage();
if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") || !pPage->m_pFormDict->GetElement("Type")->GetDirect()
|| pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare("Page"))
{
@@ -143,7 +153,7 @@ DLLEXPORT int STDCALL FPDFPage_GetRotation(FPDF_PAGE page)
DLLEXPORT void STDCALL FPDFPage_InsertObject(FPDF_PAGE page, FPDF_PAGEOBJECT page_obj)
{
- CPDF_Page* pPage = (CPDF_Page*)page;
+ CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage();
if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") || !pPage->m_pFormDict->GetElement("Type")->GetDirect()
|| pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare("Page"))
{
@@ -198,7 +208,7 @@ DLLEXPORT void STDCALL FPDFPage_InsertObject(FPDF_PAGE page, FPDF_PAGEOBJECT pag
DLLEXPORT int STDCALL FPDFPage_CountObject(FPDF_PAGE page)
{
- CPDF_Page* pPage = (CPDF_Page*)page;
+ CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage();
if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") || !pPage->m_pFormDict->GetElement("Type")->GetDirect()
|| pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare("Page"))
{
@@ -210,7 +220,7 @@ DLLEXPORT int STDCALL FPDFPage_CountObject(FPDF_PAGE page)
DLLEXPORT FPDF_PAGEOBJECT STDCALL FPDFPage_GetObject(FPDF_PAGE page, int index)
{
- CPDF_Page* pPage = (CPDF_Page*)page;
+ CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage();
if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type")
|| pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare("Page"))
{
@@ -223,7 +233,8 @@ DLLEXPORT FPDF_PAGEOBJECT STDCALL FPDFPage_GetObject(FPDF_PAGE page, int index)
DLLEXPORT FPDF_BOOL STDCALL FPDFPage_HasTransparency(FPDF_PAGE page)
{
if(!page) return FALSE;
- CPDF_Page* pPage = (CPDF_Page*)page;
+ CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage();
+ if (!pPage) return FALSE;
return pPage->BackgroundAlphaNeeded();
}
@@ -262,7 +273,7 @@ DLLEXPORT FPDF_BOOL STDCALL FPDFPageObj_HasTransparency(FPDF_PAGEOBJECT pageObje
DLLEXPORT FPDF_BOOL STDCALL FPDFPage_GenerateContent(FPDF_PAGE page)
{
- CPDF_Page* pPage = (CPDF_Page*)page;
+ CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage();
if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") || !pPage->m_pFormDict->GetElement("Type")->GetDirect()
|| pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare("Page"))
{
@@ -289,7 +300,8 @@ DLLEXPORT void STDCALL FPDFPage_TransformAnnots(FPDF_PAGE page,
{
if(page == NULL)
return;
- CPDF_Page* pPage = (CPDF_Page*)page;
+ CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage();
+ if (!pPage) return;
CPDF_AnnotList AnnotList(pPage);
for (int i=0; i<AnnotList.Count();i++)
{
@@ -317,7 +329,11 @@ DLLEXPORT void STDCALL FPDFPage_TransformAnnots(FPDF_PAGE page,
DLLEXPORT void STDCALL FPDFPage_SetRotation(FPDF_PAGE page, int rotate)
{
- CPDF_Page* pPage = (CPDF_Page*)page;
+ if (page == NULL)
+ return;
+ CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage();
+ if (!pPage) return;
+
if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") || !pPage->m_pFormDict->GetElement("Type")->GetDirect()
|| pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare("Page"))
{
diff --git a/fpdfsdk/src/fpdfformfill.cpp b/fpdfsdk/src/fpdfformfill.cpp
index 2de76033fe..38a71fc6d9 100644
--- a/fpdfsdk/src/fpdfformfill.cpp
+++ b/fpdfsdk/src/fpdfformfill.cpp
@@ -7,7 +7,10 @@
#include "../include/fpdfview.h"
#include "../include/fpdfformfill.h"
#include "../include/fsdk_define.h"
+#include "../include/fpdfxfa/fpdfxfa_doc.h"
#include "../include/fsdk_mgr.h"
+#include "../include/fpdfxfa/fpdfxfa_page.h"
+#include "../include/fpdfxfa/fpdfxfa_app.h"
#include "../include/javascript/IJavaScript.h"
@@ -17,60 +20,109 @@ DLLEXPORT int STDCALL FPDPage_HasFormFieldAtPoint(FPDF_FORMHANDLE hHandle, FPDF_
{
if(!page || !hHandle)
return -1;
- CPDF_Page * pPage = (CPDF_Page*) page;
-
- CPDF_InterForm * pInterForm = NULL;
- pInterForm = new CPDF_InterForm(pPage->m_pDocument,FALSE);
- if (!pInterForm)
- return -1;
- CPDF_FormControl* pFormCtrl = pInterForm->GetControlAtPoint(pPage, (FX_FLOAT)page_x, (FX_FLOAT)page_y);
- if(!pFormCtrl)
+ CPDF_Page * pPage = ((CPDFXFA_Page*) page)->GetPDFPage();
+ if (pPage)
{
+ CPDF_InterForm * pInterForm = NULL;
+ pInterForm = new CPDF_InterForm(pPage->m_pDocument,FALSE);
+ if (!pInterForm)
+ return -1;
+ CPDF_FormControl* pFormCtrl = pInterForm->GetControlAtPoint(pPage, (FX_FLOAT)page_x, (FX_FLOAT)page_y);
+ if(!pFormCtrl)
+ {
+ delete pInterForm;
+ return -1;
+ }
+ CPDF_FormField* pFormField = pFormCtrl->GetField();
+ if(!pFormField)
+ {
+ delete pInterForm;
+ return -1;
+ }
+
+ int nType = pFormField->GetFieldType();
delete pInterForm;
- return -1;
+ return nType;
}
- CPDF_FormField* pFormField = pFormCtrl->GetField();
- if(!pFormField)
+
+ IXFA_PageView* pPageView = ((CPDFXFA_Page*)page)->GetXFAPageView();
+ if (pPageView)
{
- delete pInterForm;
- return -1;
+ IXFA_WidgetHandler* pWidgetHandler = NULL;
+ IXFA_DocView* pDocView = pPageView->GetDocView();
+ if (!pDocView)
+ return -1;
+
+ pWidgetHandler = pDocView->GetWidgetHandler();
+ if (!pWidgetHandler)
+ return -1;
+
+ XFA_HWIDGET pXFAAnnot = NULL;
+ IXFA_WidgetIterator* pWidgetIterator = pPageView->CreateWidgetIterator(XFA_TRAVERSEWAY_Form, XFA_WIDGETFILTER_Viewable|XFA_WIDGETFILTER_AllType);
+ if (!pWidgetIterator)
+ return -1;
+ pXFAAnnot = pWidgetIterator->MoveToNext();
+ while (pXFAAnnot) {
+ CFX_RectF rcBBox;
+ pWidgetHandler->GetBBox (pXFAAnnot, rcBBox, 0);
+ CFX_FloatRect rcWidget(rcBBox.left, rcBBox.top, rcBBox.left + rcBBox.width, rcBBox.top+rcBBox.height);
+ rcWidget.left -= 1.0f;
+ rcWidget.right += 1.0f;
+ rcWidget.bottom -= 1.0f;
+ rcWidget.top += 1.0f;
+
+ if (rcWidget.Contains(page_x, page_y)) {
+ pWidgetIterator->Release();
+ return FPDF_FORMFIELD_XFA;
+ }
+ pXFAAnnot = pWidgetIterator->MoveToNext();
+ }
+
+ pWidgetIterator->Release();
}
- int nType = pFormField->GetFieldType();
- delete pInterForm;
- return nType;
+ return -1;
}
DLLEXPORT FPDF_FORMHANDLE STDCALL FPDFDOC_InitFormFillEnviroument(FPDF_DOCUMENT document, FPDF_FORMFILLINFO* formInfo)
{
if(!document || !formInfo || formInfo->version!=1)
return NULL;
- CPDF_Document * pDocument = (CPDF_Document*) document;
+ CPDFXFA_Document * pDocument = (CPDFXFA_Document*) document;
CPDFDoc_Environment * pEnv = NULL;
pEnv = new CPDFDoc_Environment(pDocument);
if (!pEnv)
return NULL;
pEnv->RegAppHandle(formInfo);
- if(pEnv->GetPDFDocument())
+ CPDFXFA_App* pApp = FPDFXFA_GetApp();
+ pApp->AddFormFillEnv(pEnv);
+
+ if(pEnv->GetPDFXFADocument())
{
- CPDFSDK_Document* pSDKDoc = new CPDFSDK_Document(pEnv->GetPDFDocument(), pEnv);
- if(pSDKDoc)
+ //CPDFSDK_Document* pSDKDoc = new CPDFSDK_Document(pEnv->GetPDFXFADocument(), pEnv);
+ CPDFSDK_Document* pSDKDoc = pDocument->GetSDKDocument(pEnv);
+ if(pSDKDoc) {
pEnv->SetCurrentDoc(pSDKDoc);
+ }
}
return pEnv;
}
DLLEXPORT void STDCALL FPDFDOC_ExitFormFillEnviroument(FPDF_FORMHANDLE hHandle)
{
- if(!hHandle)
+ if (!hHandle)
return;
- CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();
- if(pSDKDoc)
- {
- ((CPDFDoc_Environment*)hHandle)->SetCurrentDoc(NULL);
- delete pSDKDoc;
- }
+ //CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();
+ //if(pSDKDoc)
+ //{
+ //((CPDFDoc_Environment*)hHandle)->SetCurrentDoc(NULL);
+ //CPDFXFA_Document* pDoc = ((CPDFDoc_Environment*)hHandle)->GetPDFXFADocument();
+ //if (pDoc)
+ // pDoc->ReleaseSDKDoc();
+ //}
+ CPDFXFA_App* pApp = FPDFXFA_GetApp();
+ pApp->RemoveFormFillEnv((CPDFDoc_Environment*)hHandle);
delete (CPDFDoc_Environment*)hHandle;
hHandle = NULL;
}
@@ -85,7 +137,7 @@ DLLEXPORT FPDF_BOOL STDCALL FORM_OnMouseMove(FPDF_FORMHANDLE hHandle, FPDF_PAGE
CPDFSDK_Document* pFXDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();
if(!pFXDoc)
return FALSE;
- CPDFSDK_PageView* pPageView = pFXDoc->GetPageView((CPDF_Page*)page);
+ CPDFSDK_PageView* pPageView = pFXDoc->GetPageView((CPDFXFA_Page*)page);
if(!pPageView)
return FALSE;
@@ -103,7 +155,7 @@ DLLEXPORT FPDF_BOOL STDCALL FORM_OnLButtonDown(FPDF_FORMHANDLE hHandle, FPDF_PAG
CPDFSDK_Document* pFXDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();
if(!pFXDoc)
return FALSE;
- CPDFSDK_PageView* pPageView = pFXDoc->GetPageView((CPDF_Page*)page);
+ CPDFSDK_PageView* pPageView = pFXDoc->GetPageView((CPDFXFA_Page*)page);
if(!pPageView)
return FALSE;
// double page_x = 0;
@@ -120,7 +172,7 @@ DLLEXPORT FPDF_BOOL STDCALL FORM_OnLButtonUp(FPDF_FORMHANDLE hHandle, FPDF_PAGE
CPDFSDK_Document* pFXDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();
if(!pFXDoc)
return FALSE;
- CPDFSDK_PageView* pPageView = pFXDoc->GetPageView((CPDF_Page*)page);
+ CPDFSDK_PageView* pPageView = pFXDoc->GetPageView((CPDFXFA_Page*)page);
if(!pPageView)
return FALSE;
// double page_x = 0;
@@ -130,6 +182,38 @@ DLLEXPORT FPDF_BOOL STDCALL FORM_OnLButtonUp(FPDF_FORMHANDLE hHandle, FPDF_PAGE
return pPageView->OnLButtonUp(pt, modifier);
}
+DLLEXPORT FPDF_BOOL STDCALL FORM_OnRButtonDown(FPDF_FORMHANDLE hHandle, FPDF_PAGE page, int modifier, double page_x, double page_y)
+{
+ if (!hHandle || !page)
+ return FALSE;
+
+ CPDFSDK_Document* pFXDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();
+ if(!pFXDoc)
+ return FALSE;
+ CPDFSDK_PageView* pPageView = pFXDoc->GetPageView((CPDFXFA_Page*)page);
+ if(!pPageView)
+ return FALSE;
+
+ CPDF_Point pt((FX_FLOAT)page_x, (FX_FLOAT)page_y);
+ return pPageView->OnRButtonDown(pt, modifier);
+}
+
+DLLEXPORT FPDF_BOOL STDCALL FORM_OnRButtonUp(FPDF_FORMHANDLE hHandle, FPDF_PAGE page, int modifier, double page_x, double page_y)
+{
+ if (!hHandle || !page)
+ return FALSE;
+
+ CPDFSDK_Document* pFXDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();
+ if(!pFXDoc)
+ return FALSE;
+ CPDFSDK_PageView* pPageView = pFXDoc->GetPageView((CPDFXFA_Page*)page);
+ if(!pPageView)
+ return FALSE;
+
+ CPDF_Point pt((FX_FLOAT)page_x, (FX_FLOAT)page_y);
+ return pPageView->OnRButtonUp(pt, modifier);
+}
+
DLLEXPORT FPDF_BOOL STDCALL FORM_OnKeyDown(FPDF_FORMHANDLE hHandle, FPDF_PAGE page, int nKeyCode, int modifier)
{
if (!hHandle || !page)
@@ -137,7 +221,7 @@ DLLEXPORT FPDF_BOOL STDCALL FORM_OnKeyDown(FPDF_FORMHANDLE hHandle, FPDF_PAGE pa
CPDFSDK_Document* pFXDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();
if(!pFXDoc)
return FALSE;
- CPDFSDK_PageView* pPageView = pFXDoc->GetPageView((CPDF_Page*)page);
+ CPDFSDK_PageView* pPageView = pFXDoc->GetPageView((CPDFXFA_Page*)page);
if(!pPageView)
return FALSE;
@@ -152,7 +236,7 @@ DLLEXPORT FPDF_BOOL STDCALL FORM_OnKeyUp(FPDF_FORMHANDLE hHandle, FPDF_PAGE page
CPDFSDK_Document* pFXDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();
if(!pFXDoc)
return FALSE;
- CPDFSDK_PageView* pPageView = pFXDoc->GetPageView((CPDF_Page*)page);
+ CPDFSDK_PageView* pPageView = pFXDoc->GetPageView((CPDFXFA_Page*)page);
if(!pPageView)
return FALSE;
@@ -168,7 +252,7 @@ DLLEXPORT FPDF_BOOL STDCALL FORM_OnChar(FPDF_FORMHANDLE hHandle, FPDF_PAGE page,
CPDFSDK_Document* pFXDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();
if(!pFXDoc)
return FALSE;
- CPDFSDK_PageView* pPageView = pFXDoc->GetPageView((CPDF_Page*)page);
+ CPDFSDK_PageView* pPageView = pFXDoc->GetPageView((CPDFXFA_Page*)page);
if(!pPageView)
return FALSE;
return pPageView->OnChar(nChar, modifier);
@@ -191,27 +275,19 @@ DLLEXPORT void STDCALL FPDF_FFLDraw(FPDF_FORMHANDLE hHandle, FPDF_BITMAP bitmap,
{
if (!hHandle || !page)
return ;
- CPDF_Page* pPage = (CPDF_Page*)page;
- CPDF_RenderOptions options;
- if (flags & FPDF_LCD_TEXT)
- options.m_Flags |= RENDER_CLEARTYPE;
- else
- options.m_Flags &= ~RENDER_CLEARTYPE;
-
- //Grayscale output
- if (flags & FPDF_GRAYSCALE)
- {
- options.m_ColorMode = RENDER_COLOR_GRAY;
- options.m_ForeColor = 0;
- options.m_BackColor = 0xffffff;
- }
-
- options.m_AddFlags = flags >> 8;
-
- options.m_pOCContext = FX_NEW CPDF_OCContext(pPage->m_pDocument);
+ CPDFXFA_Page* pPage = (CPDFXFA_Page*)page;
+ CPDFXFA_Document* pDocument = pPage->GetDocument();
+ if (!pDocument)
+ return;
+ CPDF_Document* pPDFDoc = pDocument->GetPDFDoc();
+ if (!pPDFDoc)
+ return;
- //FXMT_CSLOCK_OBJ(&pPage->m_PageLock);
+ CPDFDoc_Environment* pEnv = (CPDFDoc_Environment*)hHandle;
+ CPDFSDK_Document* pFXDoc = pEnv->GetCurrentDoc();
+ if (!pFXDoc)
+ return;
CFX_AffineMatrix matrix;
pPage->GetDisplayMatrix(matrix, start_x, start_y, size_x, size_y, rotate);
@@ -235,31 +311,26 @@ DLLEXPORT void STDCALL FPDF_FFLDraw(FPDF_FORMHANDLE hHandle, FPDF_BITMAP bitmap,
pDevice->SaveState();
pDevice->SetClip_Rect(&clip);
+ CPDF_RenderOptions options;
+ if (flags & FPDF_LCD_TEXT)
+ options.m_Flags |= RENDER_CLEARTYPE;
+ else
+ options.m_Flags &= ~RENDER_CLEARTYPE;
- CPDF_RenderContext* pContext = NULL;
- pContext = FX_NEW CPDF_RenderContext;
- if (!pContext)
+ //Grayscale output
+ if (flags & FPDF_GRAYSCALE)
{
- delete pDevice;
- pDevice = NULL;
- return;
+ options.m_ColorMode = RENDER_COLOR_GRAY;
+ options.m_ForeColor = 0;
+ options.m_BackColor = 0xffffff;
}
+ options.m_AddFlags = flags >> 8;
+ options.m_pOCContext = FX_NEW CPDF_OCContext(pPDFDoc);
-// CPDF_Document* pDoc = pPage->m_pDocument;
- CPDFDoc_Environment* pEnv = (CPDFDoc_Environment*)hHandle;
- CPDFSDK_Document* pFXDoc = pEnv->GetCurrentDoc();
- if(!pFXDoc)
+ if(CPDFSDK_PageView* pPageView = pFXDoc->GetPageView((CPDFXFA_Page*)page))
{
- delete pContext;
- delete pDevice;
- pContext = NULL;
- pDevice = NULL;
- return;
- }
- if(CPDFSDK_PageView* pPageView = pFXDoc->GetPageView(pPage))
- {
- pPageView->PageView_OnDraw(pDevice, &matrix, &options);
+ pPageView->PageView_OnDraw(pDevice, &matrix, &options, &clip);
}
pDevice->RestoreState();
@@ -268,11 +339,6 @@ DLLEXPORT void STDCALL FPDF_FFLDraw(FPDF_FORMHANDLE hHandle, FPDF_BITMAP bitmap,
delete options.m_pOCContext;
options.m_pOCContext = NULL;
}
- if(pContext)
- {
- delete pContext;
- pContext = NULL;
- }
if(pDevice)
{
delete pDevice;
@@ -280,6 +346,235 @@ DLLEXPORT void STDCALL FPDF_FFLDraw(FPDF_FORMHANDLE hHandle, FPDF_BITMAP bitmap,
}
}
+DLLEXPORT void STDCALL FPDF_Widget_Undo(FPDF_DOCUMENT document, FPDF_WIDGET hWidget)
+{
+ if (NULL == hWidget || NULL == document)
+ return;
+
+ CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document;
+
+ if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && pDocument->GetDocType() != XFA_DOCTYPE_Static)
+ return;
+
+ IXFA_MenuHandler* pXFAMenuHander = FPDFXFA_GetApp()->GetXFAApp()->GetMenuHandler();
+
+ if (pXFAMenuHander == NULL)
+ return;
+
+ pXFAMenuHander->Undo((XFA_HWIDGET)hWidget);
+
+}
+DLLEXPORT void STDCALL FPDF_Widget_Redo(FPDF_DOCUMENT document, FPDF_WIDGET hWidget)
+{
+ if (NULL == hWidget || NULL == document)
+ return;
+
+ CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document;
+ if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && pDocument->GetDocType() != XFA_DOCTYPE_Static)
+ return;
+
+ IXFA_MenuHandler* pXFAMenuHander = FPDFXFA_GetApp()->GetXFAApp()->GetMenuHandler();
+
+ if (pXFAMenuHander == NULL)
+ return;
+
+ pXFAMenuHander->Redo((XFA_HWIDGET)hWidget);
+}
+
+DLLEXPORT void STDCALL FPDF_Widget_SelectAll(FPDF_DOCUMENT document, FPDF_WIDGET hWidget)
+{
+ if (NULL == hWidget || NULL == document)
+ return;
+
+ CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document;
+ if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && pDocument->GetDocType() != XFA_DOCTYPE_Static)
+ return;
+
+ IXFA_MenuHandler* pXFAMenuHander = FPDFXFA_GetApp()->GetXFAApp()->GetMenuHandler();
+
+ if (pXFAMenuHander == NULL)
+ return;
+
+ pXFAMenuHander->SelectAll((XFA_HWIDGET)hWidget);
+}
+DLLEXPORT void STDCALL FPDF_Widget_Copy(FPDF_DOCUMENT document, FPDF_WIDGET hWidget, FPDF_WIDESTRING wsText, FPDF_DWORD* size)
+{
+ if (NULL == hWidget || NULL == document)
+ return;
+
+ CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document;
+ if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && pDocument->GetDocType() != XFA_DOCTYPE_Static)
+ return;
+
+ IXFA_MenuHandler* pXFAMenuHander = FPDFXFA_GetApp()->GetXFAApp()->GetMenuHandler();
+
+ if (pXFAMenuHander == NULL)
+ return;
+
+ CFX_WideString wsCpText;
+ pXFAMenuHander->Copy((XFA_HWIDGET)hWidget, wsCpText);
+
+ CFX_ByteString bsCpText = wsCpText.UTF16LE_Encode();
+
+ int len = bsCpText.GetLength()/sizeof(unsigned short);
+
+ if (wsText == NULL) {
+ *size = len;
+ return;
+ }
+
+ int real_size = len < *size ? len : *size;
+ if (real_size > 0)
+ {
+ FXSYS_memcpy((void*)wsText,bsCpText.GetBuffer(real_size*sizeof(unsigned short)),real_size*sizeof(unsigned short));
+ bsCpText.ReleaseBuffer(real_size*sizeof(unsigned short));
+ }
+ *size = real_size;
+}
+DLLEXPORT void STDCALL FPDF_Widget_Cut(FPDF_DOCUMENT document, FPDF_WIDGET hWidget, FPDF_WIDESTRING wsText, FPDF_DWORD* size)
+{
+ if (NULL == hWidget || NULL == document)
+ return;
+
+ CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document;
+ if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && pDocument->GetDocType() != XFA_DOCTYPE_Static)
+ return;
+
+ IXFA_MenuHandler* pXFAMenuHander = FPDFXFA_GetApp()->GetXFAApp()->GetMenuHandler();
+
+ if (pXFAMenuHander == NULL)
+ return;
+
+ CFX_WideString wsCpText;
+ pXFAMenuHander->Cut((XFA_HWIDGET)hWidget, wsCpText);
+
+ CFX_ByteString bsCpText = wsCpText.UTF16LE_Encode();
+
+ int len = bsCpText.GetLength()/sizeof(unsigned short);
+
+ if (wsText == NULL) {
+ *size = len;
+ return;
+ }
+
+ int real_size = len < *size ? len : *size;
+ if (real_size > 0)
+ {
+ FXSYS_memcpy((void*)wsText,bsCpText.GetBuffer(real_size*sizeof(unsigned short)),real_size*sizeof(unsigned short));
+ bsCpText.ReleaseBuffer(real_size*sizeof(unsigned short));
+ }
+ *size = real_size;
+}
+DLLEXPORT void STDCALL FPDF_Widget_Paste(FPDF_DOCUMENT document, FPDF_WIDGET hWidget, FPDF_WIDESTRING wsText, FPDF_DWORD size)
+{
+ if (NULL == hWidget || NULL == document)
+ return;
+
+ CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document;
+ if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && pDocument->GetDocType() != XFA_DOCTYPE_Static)
+ return;
+
+ IXFA_MenuHandler* pXFAMenuHander = FPDFXFA_GetApp()->GetXFAApp()->GetMenuHandler();
+
+ if (pXFAMenuHander == NULL)
+ return;
+
+ CFX_WideString wstr = CFX_WideString::FromUTF16LE(wsText, size);
+
+ pXFAMenuHander->Paste((XFA_HWIDGET)hWidget, wstr);
+
+}
+DLLEXPORT void STDCALL FPDF_Widget_ReplaceSpellCheckWord(FPDF_DOCUMENT document, FPDF_WIDGET hWidget, float x, float y, FPDF_BYTESTRING bsText)
+{
+ if (NULL == hWidget || NULL == document)
+ return;
+
+ CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document;
+ if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && pDocument->GetDocType() != XFA_DOCTYPE_Static)
+ return;
+
+ IXFA_MenuHandler* pXFAMenuHander = FPDFXFA_GetApp()->GetXFAApp()->GetMenuHandler();
+
+ if (pXFAMenuHander == NULL)
+ return;
+
+ CFX_PointF ptPopup;
+ ptPopup.x = x;
+ ptPopup.y = y;
+ CFX_ByteStringC bs(bsText);
+ pXFAMenuHander->ReplaceSpellCheckWord((XFA_HWIDGET)hWidget,ptPopup,bs);
+
+}
+DLLEXPORT void STDCALL FPDF_Widget_GetSpellCheckWords(FPDF_DOCUMENT document, FPDF_WIDGET hWidget, float x, float y, FPDF_STRINGHANDLE* stringHandle)
+{
+ if (NULL == hWidget || NULL == document)
+ return;
+
+ CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document;
+ if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && pDocument->GetDocType() != XFA_DOCTYPE_Static)
+ return;
+
+ IXFA_MenuHandler* pXFAMenuHander = FPDFXFA_GetApp()->GetXFAApp()->GetMenuHandler();
+
+ if (pXFAMenuHander == NULL)
+ return;
+
+ CFX_ByteStringArray* sSuggestWords = FX_NEW CFX_ByteStringArray;
+ CFX_PointF ptPopup;
+ ptPopup.x = x;
+ ptPopup.y = y;
+ pXFAMenuHander->GetSuggestWords((XFA_HWIDGET)hWidget, ptPopup, *sSuggestWords);
+ *stringHandle = (FPDF_STRINGHANDLE)sSuggestWords;
+}
+DLLEXPORT int STDCALL FPDF_StringHandleCounts(FPDF_STRINGHANDLE stringHandle)
+{
+ if (stringHandle == NULL)
+ return -1;
+ CFX_ByteStringArray* sSuggestWords = (CFX_ByteStringArray*)stringHandle;
+ return sSuggestWords->GetSize();
+}
+DLLEXPORT FPDF_BOOL STDCALL FPDF_StringHandleGetStringByIndex(FPDF_STRINGHANDLE stringHandle, int index, FPDF_BYTESTRING bsText, FPDF_DWORD* size)
+{
+ if (stringHandle == NULL || size == NULL)
+ return FALSE;
+ int count = FPDF_StringHandleCounts(stringHandle);
+ if (index < 0|| index >= count)
+ return FALSE;
+
+ CFX_ByteStringArray sSuggestWords = *(CFX_ByteStringArray*)stringHandle;
+ int len = sSuggestWords[index].GetLength();
+
+ if (bsText == NULL) {
+ *size = len;
+ return TRUE;
+ }
+
+ int real_size = len < *size ? len : *size;
+ if (real_size > 0)
+ FXSYS_memcpy((void*)bsText, (FX_LPCSTR)(sSuggestWords[index]), real_size);
+ *size = real_size;
+
+ return TRUE;
+}
+DLLEXPORT void STDCALL FPDF_StringHandleRelease(FPDF_STRINGHANDLE stringHandle)
+{
+ if (stringHandle == NULL)
+ return;
+ CFX_ByteStringArray* sSuggestWords = (CFX_ByteStringArray*)stringHandle;
+ delete sSuggestWords;
+}
+
+DLLEXPORT FPDF_BOOL STDCALL FPDF_StringHandleAddString(FPDF_STRINGHANDLE stringHandle, FPDF_BYTESTRING bsText, FPDF_DWORD size)
+{
+ if (stringHandle == NULL || bsText == NULL || size <= 0)
+ return FALSE;
+
+ CFX_ByteStringArray* stringArr = (CFX_ByteStringArray*)stringHandle;
+ CFX_ByteString bsStr(bsText, size);
+
+ stringArr->Add(bsStr);
+ return TRUE;
+}
DLLEXPORT void STDCALL FPDF_SetFormFieldHighlightColor(FPDF_FORMHANDLE hHandle, int fieldType, unsigned long color)
{
@@ -329,7 +624,7 @@ DLLEXPORT void STDCALL FORM_OnAfterLoadPage(FPDF_PAGE page, FPDF_FORMHANDLE hHan
CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();
if(!pSDKDoc)
return;
- CPDF_Page* pPage = (CPDF_Page*)page;
+ CPDFXFA_Page* pPage = (CPDFXFA_Page*)page;
CPDFSDK_PageView* pPageView = pSDKDoc->GetPageView(pPage, TRUE);
if(pPageView)
{
@@ -342,7 +637,7 @@ DLLEXPORT void STDCALL FORM_OnBeforeClosePage(FPDF_PAGE page, FPDF_FORMHANDLE hH
if(!hHandle || !page)
return;
CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();
- CPDF_Page* pPage = (CPDF_Page*)page;
+ CPDFXFA_Page* pPage = (CPDFXFA_Page*)page;
CPDFSDK_PageView* pPageView = pSDKDoc->GetPageView(pPage, FALSE);
if(pPageView)
{
@@ -380,7 +675,7 @@ DLLEXPORT void STDCALL FORM_DoDocumentAAction(FPDF_FORMHANDLE hHandle, int aaTyp
CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();
if(pSDKDoc)
{
- CPDF_Document* pDoc = pSDKDoc->GetDocument();
+ CPDF_Document* pDoc = pSDKDoc->GetDocument()->GetPDFDoc();
CPDF_Dictionary* pDic = pDoc->GetRoot();
if (!pDic)
return;
@@ -400,7 +695,7 @@ DLLEXPORT void STDCALL FORM_DoPageAAction(FPDF_PAGE page, FPDF_FORMHANDLE hHandl
if(!hHandle || !page)
return;
CPDFSDK_Document* pSDKDoc = ((CPDFDoc_Environment*)hHandle)->GetCurrentDoc();
- CPDF_Page* pPage = (CPDF_Page*)page;
+ CPDFXFA_Page* pPage = (CPDFXFA_Page*)page;
CPDFSDK_PageView* pPageView = pSDKDoc->GetPageView(pPage, FALSE);
if(pPageView)
{
@@ -410,7 +705,9 @@ DLLEXPORT void STDCALL FORM_DoPageAAction(FPDF_PAGE page, FPDF_FORMHANDLE hHandl
CPDFSDK_ActionHandler *pActionHandler = pEnv->GetActionHander();
ASSERT(pActionHandler != NULL);
- CPDF_Dictionary *pPageDict = pPage->m_pFormDict;
+ if (!pPage->GetPDFPage())
+ return;
+ CPDF_Dictionary *pPageDict = pPage->GetPDFPage()->m_pFormDict;
ASSERT(pPageDict != NULL);
CPDF_AAction aa = pPageDict->GetDict(FX_BSTRC("AA"));
diff --git a/fpdfsdk/src/fpdfppo.cpp b/fpdfsdk/src/fpdfppo.cpp
index a5c4275648..ed0c8565c0 100644
--- a/fpdfsdk/src/fpdfppo.cpp
+++ b/fpdfsdk/src/fpdfppo.cpp
@@ -6,6 +6,7 @@
#include "../include/fpdfppo.h"
#include "../include/fsdk_define.h"
+#include "../include/fpdfxfa/fpdfxfa_doc.h"
class CPDF_PageOrganizer
{
@@ -428,8 +429,9 @@ DLLEXPORT FPDF_BOOL STDCALL FPDF_ImportPages(FPDF_DOCUMENT dest_doc,FPDF_DOCUMEN
if(dest_doc == NULL || src_doc == NULL )
return FALSE;
CFX_WordArray pageArray;
- CPDF_Document* pSrcDoc = (CPDF_Document*)src_doc;
- int nCount = pSrcDoc->GetPageCount();
+ CPDFXFA_Document* pSrcDoc = (CPDFXFA_Document*)src_doc;
+ CPDF_Document* pSrcPDFDoc = pSrcDoc->GetPDFDoc();
+ int nCount = pSrcPDFDoc->GetPageCount();
if(pagerange)
{
if(ParserPageRangeString(pagerange,&pageArray,nCount) == FALSE)
@@ -443,12 +445,13 @@ DLLEXPORT FPDF_BOOL STDCALL FPDF_ImportPages(FPDF_DOCUMENT dest_doc,FPDF_DOCUMEN
}
}
- CPDF_Document* pDestDoc = (CPDF_Document*)dest_doc;
+ CPDFXFA_Document* pDestDoc = (CPDFXFA_Document*)dest_doc;
+ CPDF_Document* pDestPDFDoc = pDestDoc->GetPDFDoc();
CPDF_PageOrganizer pageOrg;
- pageOrg.PDFDocInit(pDestDoc,pSrcDoc);
+ pageOrg.PDFDocInit(pDestPDFDoc,pSrcPDFDoc);
- if(pageOrg.ExportPage(pSrcDoc,&pageArray,pDestDoc,index))
+ if(pageOrg.ExportPage(pSrcPDFDoc,&pageArray,pDestPDFDoc,index))
return TRUE;
return FALSE;
}
@@ -457,13 +460,15 @@ DLLEXPORT FPDF_BOOL STDCALL FPDF_CopyViewerPreferences(FPDF_DOCUMENT dest_doc, F
{
if(src_doc == NULL || dest_doc == NULL)
return false;
- CPDF_Document* pSrcDoc = (CPDF_Document*)src_doc;
- CPDF_Dictionary* pSrcDict = pSrcDoc->GetRoot();
- pSrcDict = pSrcDict->GetDict(FX_BSTRC("ViewerPreferences"));;
+ CPDFXFA_Document* pSrcDoc = (CPDFXFA_Document*)src_doc;
+ CPDF_Document* pSrcPDFDoc = pSrcDoc->GetPDFDoc();
+ CPDF_Dictionary* pSrcDict = pSrcPDFDoc->GetRoot();
+ pSrcDict = pSrcDict->GetDict(FX_BSTRC("ViewerPreferences"));
if(!pSrcDict)
return FALSE;
- CPDF_Document* pDstDoc = (CPDF_Document*)dest_doc;
- CPDF_Dictionary* pDstDict = pDstDoc->GetRoot();
+ CPDFXFA_Document* pDstDoc = (CPDFXFA_Document*)dest_doc;
+ CPDF_Document* pDstPDFDoc = pDstDoc->GetPDFDoc();
+ CPDF_Dictionary* pDstDict = pDstPDFDoc->GetRoot();
if(!pDstDict)
return FALSE;
pDstDict->SetAt(FX_BSTRC("ViewerPreferences"), pSrcDict->Clone(TRUE));
diff --git a/fpdfsdk/src/fpdfsave.cpp b/fpdfsdk/src/fpdfsave.cpp
index 45dfbf7214..229e580dec 100644
--- a/fpdfsdk/src/fpdfsave.cpp
+++ b/fpdfsdk/src/fpdfsave.cpp
@@ -7,6 +7,9 @@
#include "../include/fsdk_define.h"
#include "../include/fpdfsave.h"
#include "../include/fpdfedit.h"
+#include "../include/fpdfxfa/fpdfxfa_doc.h"
+#include "../include/fpdfxfa/fpdfxfa_app.h"
+#include "../include/fpdfxfa/fpdfxfa_util.h"
#if _FX_OS_ == _FX_ANDROID_
#include "time.h"
#else
@@ -53,11 +56,258 @@ FX_BOOL CFX_IFileWrite::WriteBlock(const void* pData, size_t size)
return FALSE;
}
-FPDF_BOOL _FPDF_Doc_Save(FPDF_DOCUMENT document,FPDF_FILEWRITE * pFileWrite,FPDF_DWORD flags, FPDF_BOOL bSetVersion,
+#define XFA_DATASETS 0
+#define XFA_FORMS 1
+
+FX_BOOL _SaveXFADocumentData(CPDFXFA_Document* pDocument, CFX_PtrArray& fileList)
+{
+ if (!pDocument)
+ return FALSE;
+ if (pDocument->GetDocType() != DOCTYPE_DYNIMIC_XFA && pDocument->GetDocType() != DOCTYPE_STATIC_XFA)
+ return TRUE;
+ if (!FPDFXFA_GetApp()->GetXFAApp())
+ return TRUE;
+
+ IXFA_DocView* pXFADocView = pDocument->GetXFADocView();
+ if (NULL == pXFADocView)
+ return TRUE;
+ IXFA_DocHandler *pXFADocHandler = FPDFXFA_GetApp()->GetXFAApp()->GetDocHandler();
+
+ CPDF_Document * pPDFDocument = pDocument->GetPDFDoc();
+ if (pDocument == NULL)
+ return FALSE;
+ CPDF_Dictionary* pRoot = pPDFDocument->GetRoot();
+ if (pRoot == NULL)
+ return FALSE;
+ CPDF_Dictionary* pAcroForm = pRoot->GetDict("AcroForm");
+ if (NULL == pAcroForm)
+ return FALSE;
+ CPDF_Object* pXFA = pAcroForm->GetElement("XFA");
+ if (pXFA == NULL)
+ return TRUE;
+ if(pXFA->GetType() != PDFOBJ_ARRAY)
+ return FALSE;
+ CPDF_Array* pArray = pXFA->GetArray();
+ if (NULL == pArray)
+ return FALSE;
+ int size = pArray->GetCount();
+ int iFormIndex = -1;
+ int iDataSetsIndex = -1;
+ int iTemplate = -1;
+ int iLast = size - 2;
+ for (int i = 0; i < size - 1; i++)
+ {
+ CPDF_Object* pPDFObj = pArray->GetElement(i);
+ if (pPDFObj->GetType() != PDFOBJ_STRING)
+ continue;
+ if (pPDFObj->GetString() == "form")
+ iFormIndex = i+1;
+ else if (pPDFObj->GetString() == "datasets")
+ iDataSetsIndex = i+1;
+ else if (pPDFObj->GetString() == FX_BSTRC("template"))
+ iTemplate = i + 1;
+ }
+ IXFA_ChecksumContext* pContext = NULL;
+#define XFA_USECKSUM
+#ifdef XFA_USECKSUM
+ //Checksum
+ pContext = XFA_Checksum_Create();
+ FXSYS_assert(pContext);
+ pContext->StartChecksum();
+
+ //template
+ if (iTemplate > -1)
+ {
+ CPDF_Stream *pTemplateStream = pArray->GetStream(iTemplate);
+ CPDF_StreamAcc streamAcc;
+ streamAcc.LoadAllData(pTemplateStream);
+ FX_LPBYTE pData = (FX_LPBYTE)streamAcc.GetData();
+ FX_DWORD dwSize2 = streamAcc.GetSize();
+ IFX_FileStream *pTemplate = FX_CreateMemoryStream(pData, dwSize2);
+ pContext->UpdateChecksum((IFX_FileRead*)pTemplate);
+ pTemplate->Release();
+ }
+#endif
+ CPDF_Stream* pFormStream = NULL;
+ CPDF_Stream* pDataSetsStream = NULL;
+ if (iFormIndex != -1)
+ {
+ //Get form CPDF_Stream
+ CPDF_Object* pFormPDFObj = pArray->GetElement(iFormIndex);
+ if (pFormPDFObj->GetType() == PDFOBJ_REFERENCE)
+ {
+ CPDF_Reference* pFormRefObj = (CPDF_Reference*)pFormPDFObj;
+ CPDF_Object* pFormDircetObj = pFormPDFObj->GetDirect();
+ if (NULL != pFormDircetObj && pFormDircetObj->GetType() == PDFOBJ_STREAM)
+ {
+ pFormStream = (CPDF_Stream*)pFormDircetObj;
+ }
+ }
+ else if (pFormPDFObj->GetType() == PDFOBJ_STREAM)
+ {
+ pFormStream = (CPDF_Stream*)pFormPDFObj;
+ }
+ }
+
+ if (iDataSetsIndex != -1)
+ {
+ //Get datasets CPDF_Stream
+ CPDF_Object* pDataSetsPDFObj = pArray->GetElement(iDataSetsIndex);
+ if (pDataSetsPDFObj->GetType() == PDFOBJ_REFERENCE)
+ {
+ CPDF_Reference* pDataSetsRefObj = (CPDF_Reference*)pDataSetsPDFObj;
+ CPDF_Object* pDataSetsDircetObj = pDataSetsRefObj->GetDirect();
+ if (NULL != pDataSetsDircetObj && pDataSetsDircetObj->GetType() == PDFOBJ_STREAM)
+ {
+ pDataSetsStream = (CPDF_Stream*)pDataSetsDircetObj;
+ }
+ }
+ else if (pDataSetsPDFObj->GetType() == PDFOBJ_STREAM)
+ {
+ pDataSetsStream = (CPDF_Stream*)pDataSetsPDFObj;
+ }
+ }
+ //end
+ //L"datasets"
+ {
+ IFX_FileStream* pDsfileWrite = FX_CreateMemoryStream();
+ if ( NULL == pDsfileWrite )
+ {
+ pContext->Release();
+ pDsfileWrite->Release();
+ return FALSE;
+ }
+ if (pXFADocHandler->SavePackage(pXFADocView->GetDoc(), CFX_WideStringC(L"datasets"), pDsfileWrite) && pDsfileWrite->GetSize()>0)
+ {
+#ifdef XFA_USECKSUM
+ //Datasets
+ pContext->UpdateChecksum((IFX_FileRead*)pDsfileWrite);
+ pContext->FinishChecksum();
+#endif
+ CPDF_Dictionary* pDataDict = FX_NEW CPDF_Dictionary;
+ if (iDataSetsIndex != -1)
+ {
+ if (pDataSetsStream)
+ pDataSetsStream->InitStream(pDsfileWrite, pDataDict);
+ }
+ else
+ {
+ CPDF_Stream* pData = FX_NEW CPDF_Stream(NULL, 0, NULL);
+ pData->InitStream(pDsfileWrite, pDataDict);
+ FX_DWORD AppStreamobjnum = pPDFDocument->AddIndirectObject(pData);
+ CPDF_Reference* pRef = (CPDF_Reference*)pPDFDocument->GetIndirectObject(AppStreamobjnum);
+ {
+ iLast = pArray->GetCount() -2;
+ pArray->InsertAt(iLast,CPDF_String::Create("datasets"));
+ pArray->InsertAt(iLast+1, pData, pPDFDocument);
+ }
+ }
+ fileList.Add(pDsfileWrite);
+ }
+ }
+
+
+ //L"form"
+ {
+
+ IFX_FileStream* pfileWrite = FX_CreateMemoryStream();
+ if (NULL == pfileWrite)
+ {
+ pContext->Release();
+ return FALSE;
+ }
+ if(pXFADocHandler->SavePackage(pXFADocView->GetDoc(), CFX_WideStringC(L"form"), pfileWrite, pContext) && pfileWrite > 0)
+ {
+ CPDF_Dictionary* pDataDict = FX_NEW CPDF_Dictionary;
+ if (iFormIndex != -1)
+ {
+ if (pFormStream)
+ pFormStream->InitStream(pfileWrite, pDataDict);
+ }
+ else
+ {
+ CPDF_Stream* pData = FX_NEW CPDF_Stream(NULL, 0, NULL);
+ pData->InitStream(pfileWrite, pDataDict);
+ FX_DWORD AppStreamobjnum = pPDFDocument->AddIndirectObject(pData);
+ CPDF_Reference* pRef = (CPDF_Reference*)pPDFDocument->GetIndirectObject(AppStreamobjnum);
+ {
+ iLast = pArray->GetCount() -2;
+ pArray->InsertAt(iLast, CPDF_String::Create("form"));
+ pArray->InsertAt(iLast+1, pData, pPDFDocument);
+ }
+ }
+ fileList.Add(pfileWrite);
+ }
+ }
+ pContext->Release();
+ return TRUE;
+}
+
+
+FX_BOOL _SendPostSaveToXFADoc(CPDFXFA_Document* pDocument)
+{
+ if (!pDocument)
+ return FALSE;
+
+ if (pDocument->GetDocType() != DOCTYPE_DYNIMIC_XFA && pDocument->GetDocType() != DOCTYPE_STATIC_XFA)
+ return TRUE;
+
+ IXFA_DocView* pXFADocView = pDocument->GetXFADocView();
+ if (NULL == pXFADocView)
+ return FALSE;
+ IXFA_WidgetHandler* pWidgetHander = pXFADocView->GetWidgetHandler();
+
+ CXFA_WidgetAcc* pWidgetAcc = NULL;
+ IXFA_WidgetAccIterator* pWidgetAccIterator = pXFADocView->CreateWidgetAccIterator();
+ pWidgetAcc = pWidgetAccIterator->MoveToNext();
+ while(pWidgetAcc)
+ {
+ CXFA_EventParam preParam;
+ preParam.m_eType = XFA_EVENT_PostSave;
+ pWidgetHander->ProcessEvent(pWidgetAcc,&preParam);
+ pWidgetAcc = pWidgetAccIterator->MoveToNext();
+ }
+ pWidgetAccIterator->Release();
+ pXFADocView->UpdateDocView();
+ pDocument->_ClearChangeMark();
+ return TRUE;
+}
+
+
+FX_BOOL _SendPreSaveToXFADoc(CPDFXFA_Document* pDocument, CFX_PtrArray& fileList)
+{
+ if (pDocument->GetDocType() != DOCTYPE_DYNIMIC_XFA && pDocument->GetDocType() != DOCTYPE_STATIC_XFA)
+ return TRUE;
+ IXFA_DocView* pXFADocView = pDocument->GetXFADocView();
+ if (NULL == pXFADocView)
+ return TRUE;
+ IXFA_WidgetHandler* pWidgetHander = pXFADocView->GetWidgetHandler();
+ CXFA_WidgetAcc* pWidgetAcc = NULL;
+ IXFA_WidgetAccIterator* pWidgetAccIterator = pXFADocView->CreateWidgetAccIterator();
+ pWidgetAcc = pWidgetAccIterator->MoveToNext();
+ while(pWidgetAcc)
+ {
+ CXFA_EventParam preParam;
+ preParam.m_eType = XFA_EVENT_PreSave;
+ pWidgetHander->ProcessEvent(pWidgetAcc, &preParam);
+ pWidgetAcc = pWidgetAccIterator->MoveToNext();
+ }
+ pWidgetAccIterator->Release();
+ pXFADocView->UpdateDocView();
+ return _SaveXFADocumentData(pDocument, fileList);
+}
+
+FPDF_BOOL _FPDF_Doc_Save(FPDF_DOCUMENT document, FPDF_FILEWRITE * pFileWrite,FPDF_DWORD flags, FPDF_BOOL bSetVersion,
int fileVerion)
{
- CPDF_Document* pDoc = (CPDF_Document*)document;
- if (!pDoc)
+ CPDFXFA_Document* pDoc = (CPDFXFA_Document*)document;
+
+ CFX_PtrArray fileList;
+
+ _SendPreSaveToXFADoc(pDoc, fileList);
+
+ CPDF_Document* pPDFDoc = pDoc->GetPDFDoc();
+ if (!pPDFDoc)
return 0;
if ( flags < FPDF_INCREMENTAL || flags > FPDF_REMOVE_SECURITY )
@@ -65,10 +315,10 @@ FPDF_BOOL _FPDF_Doc_Save(FPDF_DOCUMENT document,FPDF_FILEWRITE * pFileWrite,FPDF
flags = 0;
}
- CPDF_Creator FileMaker(pDoc);
- if(bSetVersion)
+ CPDF_Creator FileMaker(pPDFDoc);
+ if (bSetVersion)
FileMaker.SetFileVersion(fileVerion);
- if(flags == FPDF_REMOVE_SECURITY)
+ if (flags == FPDF_REMOVE_SECURITY)
{
flags = 0;
FileMaker.RemoveSecurity();
@@ -78,6 +328,17 @@ FPDF_BOOL _FPDF_Doc_Save(FPDF_DOCUMENT document,FPDF_FILEWRITE * pFileWrite,FPDF
pStreamWrite = new CFX_IFileWrite;
pStreamWrite->Init( pFileWrite );
bRet = FileMaker.Create(pStreamWrite, flags);
+
+ _SendPostSaveToXFADoc(pDoc);
+ //pDoc->_ClearChangeMark();
+
+ for (int i = 0; i < fileList.GetSize(); i++)
+ {
+ IFX_FileStream* pFile = (IFX_FileStream*)fileList.GetAt(i);
+ pFile->Release();
+ }
+ fileList.RemoveAll();
+
delete pStreamWrite;
return bRet;
}
@@ -88,9 +349,9 @@ DLLEXPORT FPDF_BOOL STDCALL FPDF_SaveAsCopy( FPDF_DOCUMENT document,FPDF_FILEWRI
return _FPDF_Doc_Save(document, pFileWrite, flags, FALSE , 0);
}
-
DLLEXPORT FPDF_BOOL STDCALL FPDF_SaveWithVersion( FPDF_DOCUMENT document,FPDF_FILEWRITE * pFileWrite,
FPDF_DWORD flags, int fileVersion)
{
return _FPDF_Doc_Save(document, pFileWrite, flags, TRUE , fileVersion);
}
+
diff --git a/fpdfsdk/src/fpdftext.cpp b/fpdfsdk/src/fpdftext.cpp
index 264631b630..002637483d 100644
--- a/fpdfsdk/src/fpdftext.cpp
+++ b/fpdfsdk/src/fpdftext.cpp
@@ -6,6 +6,8 @@
#include "../include/fsdk_define.h"
#include "../include/fpdftext.h"
+#include "../include/fpdfxfa/fpdfxfa_doc.h"
+#include "../include/fpdfxfa/fpdfxfa_page.h"
#ifdef _WIN32
#include <tchar.h>
@@ -18,9 +20,13 @@ DLLEXPORT FPDF_TEXTPAGE STDCALL FPDFText_LoadPage(FPDF_PAGE page)
{
if (!page) return NULL;
IPDF_TextPage* textpage=NULL;
- CPDF_ViewerPreferences viewRef(((CPDF_Page*)page)->m_pDocument);
- textpage=IPDF_TextPage::CreateTextPage((CPDF_Page*)page,viewRef.IsDirectionR2L());
+ CPDFXFA_Page* pPage = (CPDFXFA_Page*)page;
+ if (!pPage->GetPDFPage()) return NULL;
+ CPDFXFA_Document* pDoc = pPage->GetDocument();
+ CPDF_ViewerPreferences viewRef(pDoc->GetPDFDoc());
+ textpage=IPDF_TextPage::CreateTextPage((CPDF_Page*)pPage->GetPDFPage(),viewRef.IsDirectionR2L());
textpage->ParseTextPage();
+
return textpage;
}
DLLEXPORT void STDCALL FPDFText_ClosePage(FPDF_TEXTPAGE text_page)
diff --git a/fpdfsdk/src/fpdfview.cpp b/fpdfsdk/src/fpdfview.cpp
index bd49862e1c..ae8f3ccd91 100644
--- a/fpdfsdk/src/fpdfview.cpp
+++ b/fpdfsdk/src/fpdfview.cpp
@@ -11,11 +11,116 @@
#include "../include/fpdf_progressive.h"
#include "../include/fpdf_ext.h"
#include "../../third_party/numerics/safe_conversions_impl.h"
+#include "../include/fpdfformfill.h"
+#include "../include/fpdfxfa/fpdfxfa_doc.h"
+#include "../include/fpdfxfa/fpdfxfa_app.h"
+#include "../include/fpdfxfa/fpdfxfa_page.h"
+#include "../include/fpdfxfa/fpdfxfa_util.h"
+
+CFPDF_FileStream::CFPDF_FileStream(FPDF_FILEHANDLER* pFS)
+{
+ m_pFS = pFS;
+ m_nCurPos = 0;
+}
+
+IFX_FileStream* CFPDF_FileStream::Retain()
+{
+ return this;
+}
+
+void CFPDF_FileStream::Release()
+{
+ if (m_pFS && m_pFS->Release)
+ m_pFS->Release(m_pFS->clientData);
+ delete this;
+}
+
+FX_FILESIZE CFPDF_FileStream::GetSize()
+{
+ if (m_pFS && m_pFS->GetSize)
+ return (FX_FILESIZE)m_pFS->GetSize(m_pFS->clientData);
+ return 0;
+}
+
+FX_BOOL CFPDF_FileStream::IsEOF()
+{
+ return m_nCurPos >= GetSize();
+}
+
+FX_BOOL CFPDF_FileStream::ReadBlock(void* buffer, FX_FILESIZE offset, size_t size)
+{
+ if (!buffer || !size || !m_pFS->ReadBlock) return FALSE;
+
+ if (m_pFS->ReadBlock(m_pFS->clientData, (FPDF_DWORD)offset, buffer, (FPDF_DWORD)size) == 0)
+ {
+ m_nCurPos = offset + size;
+ return TRUE;
+ }
+ return FALSE;
+}
+
+size_t CFPDF_FileStream::ReadBlock(void* buffer, size_t size)
+{
+ if (!buffer || !size || !m_pFS->ReadBlock) return 0;
+
+ FX_FILESIZE nSize = GetSize();
+ if (m_nCurPos >= nSize) return 0;
+ FX_FILESIZE dwAvail = nSize - m_nCurPos;
+ if (dwAvail < (FX_FILESIZE)size) size = (size_t)dwAvail;
+ if (m_pFS->ReadBlock(m_pFS->clientData, (FPDF_DWORD)m_nCurPos, buffer, (FPDF_DWORD)size) == 0)
+ {
+ m_nCurPos += size;
+ return size;
+ }
+
+ return 0;
+}
+
+FX_BOOL CFPDF_FileStream::WriteBlock(const void* buffer, FX_FILESIZE offset, size_t size)
+{
+ if (!m_pFS || !m_pFS->WriteBlock) return FALSE;
+
+ if(m_pFS->WriteBlock(m_pFS->clientData, (FPDF_DWORD)offset, buffer, (FPDF_DWORD)size) == 0)
+ {
+ m_nCurPos = offset + size;
+ return TRUE;
+ }
+ return FALSE;
+}
+
+FX_BOOL CFPDF_FileStream::Flush()
+{
+ if (!m_pFS || !m_pFS->Flush) return TRUE;
+
+ return m_pFS->Flush(m_pFS->clientData) == 0;
+}
CPDF_CustomAccess::CPDF_CustomAccess(FPDF_FILEACCESS* pFileAccess)
{
- if (pFileAccess)
- m_FileAccess = *pFileAccess;
+ m_FileAccess = *pFileAccess;
+ m_BufferOffset = (FX_DWORD)-1;
+}
+
+FX_BOOL CPDF_CustomAccess::GetByte(FX_DWORD pos, FX_BYTE& ch)
+{
+ if (pos >= m_FileAccess.m_FileLen) return FALSE;
+ if (m_BufferOffset == (FX_DWORD)-1 || pos < m_BufferOffset || pos >= m_BufferOffset + 512) {
+ // Need to read from file access
+ m_BufferOffset = pos;
+ int size = 512;
+ if (pos + 512 > m_FileAccess.m_FileLen)
+ size = m_FileAccess.m_FileLen - pos;
+ if (!m_FileAccess.m_GetBlock(m_FileAccess.m_Param, m_BufferOffset, m_Buffer, size))
+ return FALSE;
+ }
+ ch = m_Buffer[pos - m_BufferOffset];
+ return TRUE;
+}
+
+FX_BOOL CPDF_CustomAccess::GetBlock(FX_DWORD pos, FX_LPBYTE pBuf, FX_DWORD size)
+{
+ if (pos + size > m_FileAccess.m_FileLen) return FALSE;
+ return m_FileAccess.m_GetBlock(m_FileAccess.m_Param, pos, pBuf, size);
}
FX_BOOL CPDF_CustomAccess::ReadBlock(void* buffer, FX_FILESIZE offset, size_t size)
@@ -161,6 +266,9 @@ DLLEXPORT void STDCALL FPDF_InitLibrary(FX_LPVOID hInstance)
#endif
#endif
+ CPDFXFA_App* pAppProvider = FPDFXFA_GetApp();
+ pAppProvider->Initialize();
+
#ifdef _WIN32
// Get module path
TCHAR app_path[MAX_PATH];
@@ -187,6 +295,7 @@ DLLEXPORT void STDCALL FPDF_InitLibrary(FX_LPVOID hInstance)
DLLEXPORT void STDCALL FPDF_DestroyLibrary()
{
+ FPDFXFA_ReleaseApp();
#if _FX_OS_ == _FX_LINUX_EMBEDDED_
if (g_pFontMapper) delete g_pFontMapper;
@@ -254,8 +363,26 @@ DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadDocument(FPDF_STRING file_path, FPDF_BY
ProcessParseError(err_code);
return NULL;
}
- return pParser->GetDocument();
+ CPDF_Document* pPDFDoc = pParser->GetDocument();
+ if (!pPDFDoc)
+ return NULL;
+
+ CPDFXFA_App* pProvider = FPDFXFA_GetApp();
+ CPDFXFA_Document* pDocument = FX_NEW CPDFXFA_Document(pPDFDoc, pProvider);
+ return pDocument;
}
+DLLEXPORT FPDF_BOOL STDCALL FPDF_LoadXFA(FPDF_DOCUMENT document)
+{
+ if (!document||!((CPDFXFA_Document*)document)->GetPDFDoc())
+ return FALSE;
+
+ int iDocType = DOCTYPE_PDF;
+ FX_BOOL hasXFAField = FPDF_HasXFAField(((CPDFXFA_Document*)document)->GetPDFDoc(), iDocType);
+ if (!hasXFAField)
+ return FALSE;
+ return ((CPDFXFA_Document*)document)->LoadXFADoc();
+}
+
extern void CheckUnSupportError(CPDF_Document * pDoc, FX_DWORD err_code);
@@ -297,7 +424,15 @@ DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadMemDocument(const void* data_buf, int s
CPDF_Document * pDoc = NULL;
pDoc = pParser?pParser->GetDocument():NULL;
CheckUnSupportError(pDoc, err_code);
- return pParser->GetDocument();
+ CPDF_Document* pPDFDoc = pParser->GetDocument();
+ if (!pPDFDoc)
+ return NULL;
+
+ CPDFXFA_App* pProvider = FPDFXFA_GetApp();
+ CPDFXFA_Document* pDocument = FX_NEW CPDFXFA_Document(pPDFDoc, pProvider);
+ //pDocument->LoadXFADoc();
+
+ return pDocument;
}
DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadCustomDocument(FPDF_FILEACCESS* pFileAccess, FPDF_BYTESTRING password)
@@ -314,15 +449,26 @@ DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadCustomDocument(FPDF_FILEACCESS* pFileAc
CPDF_Document * pDoc = NULL;
pDoc = pParser?pParser->GetDocument():NULL;
CheckUnSupportError(pDoc, err_code);
- return pParser->GetDocument();
+ CPDF_Document* pPDFDoc = pParser->GetDocument();
+ if (!pPDFDoc)
+ return NULL;
+
+ CPDFXFA_App* pProvider = FPDFXFA_GetApp();
+ CPDFXFA_Document* pDocument = FX_NEW CPDFXFA_Document(pPDFDoc, pProvider);
+ //pDocument->LoadXFADoc();
+
+ return pDocument;
}
DLLEXPORT FPDF_BOOL STDCALL FPDF_GetFileVersion(FPDF_DOCUMENT doc, int* fileVersion)
{
if(!doc||!fileVersion) return FALSE;
*fileVersion = 0;
- CPDF_Document* pDoc = (CPDF_Document*)doc;
- CPDF_Parser* pParser = (CPDF_Parser*)pDoc->GetParser();
+ CPDFXFA_Document* pDoc = (CPDFXFA_Document*)doc;
+ CPDF_Document* pPDFDoc = pDoc->GetPDFDoc();
+ if (!pPDFDoc) return (FX_DWORD)-1;
+ CPDF_Parser* pParser = (CPDF_Parser*)pPDFDoc->GetParser();
+
if(!pParser)
return FALSE;
*fileVersion = pParser->GetFileVersion();
@@ -333,8 +479,10 @@ DLLEXPORT FPDF_BOOL STDCALL FPDF_GetFileVersion(FPDF_DOCUMENT doc, int* fileVers
DLLEXPORT unsigned long STDCALL FPDF_GetDocPermissions(FPDF_DOCUMENT document)
{
if (document == NULL) return 0;
- CPDF_Document*pDoc = (CPDF_Document*)document;
- CPDF_Parser* pParser = (CPDF_Parser*)pDoc->GetParser();
+ CPDFXFA_Document*pDoc = (CPDFXFA_Document*)document;
+ CPDF_Document* pPDFDoc = pDoc->GetPDFDoc();
+ if (!pPDFDoc) return (FX_DWORD)-1;
+ CPDF_Parser* pParser = (CPDF_Parser*)pPDFDoc->GetParser();
CPDF_Dictionary* pDict = pParser->GetEncryptDict();
if (pDict == NULL) return (FX_DWORD)-1;
@@ -355,38 +503,33 @@ DLLEXPORT int STDCALL FPDF_GetSecurityHandlerRevision(FPDF_DOCUMENT document)
DLLEXPORT int STDCALL FPDF_GetPageCount(FPDF_DOCUMENT document)
{
if (document == NULL) return 0;
- return ((CPDF_Document*)document)->GetPageCount();
+ CPDFXFA_Document* pDoc = (CPDFXFA_Document*)document;
+ return pDoc->GetPageCount();
+// return ((CPDF_Document*)document)->GetPageCount();
}
DLLEXPORT FPDF_PAGE STDCALL FPDF_LoadPage(FPDF_DOCUMENT document, int page_index)
{
if (document == NULL) return NULL;
- if (page_index < 0 || page_index >= FPDF_GetPageCount(document)) return NULL;
+ CPDFXFA_Document* pDoc = (CPDFXFA_Document*)document;
+ if (page_index < 0 || page_index >= pDoc->GetPageCount()) return NULL;
// CPDF_Parser* pParser = (CPDF_Parser*)document;
- CPDF_Document* pDoc = (CPDF_Document*)document;
- if (pDoc == NULL) return NULL;
- CPDF_Dictionary* pDict = pDoc->GetPage(page_index);
- if (pDict == NULL) return NULL;
- CPDF_Page* pPage = FX_NEW CPDF_Page;
- pPage->Load(pDoc, pDict);
- pPage->ParseContent();
-
-// CheckUnSupportError(pDoc, 0);
-
- return pPage;
+ return pDoc->GetPage(page_index);
}
DLLEXPORT double STDCALL FPDF_GetPageWidth(FPDF_PAGE page)
{
if (!page)
return 0.0;
- return ((CPDF_Page*)page)->GetPageWidth();
+ return ((CPDFXFA_Page*)page)->GetPageWidth();
+// return ((CPDF_Page*)page)->GetPageWidth();
}
DLLEXPORT double STDCALL FPDF_GetPageHeight(FPDF_PAGE page)
{
if (!page) return 0.0;
- return ((CPDF_Page*)page)->GetPageHeight();
+// return ((CPDF_Page*)page)->GetPageHeight();
+ return ((CPDFXFA_Page*)page)->GetPageHeight();
}
void DropContext(void* data)
@@ -408,7 +551,8 @@ DLLEXPORT void STDCALL FPDF_RenderPage(HDC dc, FPDF_PAGE page, int start_x, int
int rotate, int flags)
{
if (page==NULL) return;
- CPDF_Page* pPage = (CPDF_Page*)page;
+ CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage();
+ if (!pPage) return;
CRenderContext* pContext = FX_NEW CRenderContext;
pPage->SetPrivateData((void*)1, pContext, DropContext);
@@ -562,8 +706,8 @@ DLLEXPORT void STDCALL FPDF_RenderPageBitmap(FPDF_BITMAP bitmap, FPDF_PAGE page,
int size_x, int size_y, int rotate, int flags)
{
if (bitmap == NULL || page == NULL) return;
- CPDF_Page* pPage = (CPDF_Page*)page;
-
+ CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage();
+ if (!pPage) return;
CRenderContext* pContext = FX_NEW CRenderContext;
pPage->SetPrivateData((void*)1, pContext, DropContext);
@@ -592,12 +736,14 @@ DLLEXPORT void STDCALL FPDF_RenderPageBitmap(FPDF_BITMAP bitmap, FPDF_PAGE page,
DLLEXPORT void STDCALL FPDF_ClosePage(FPDF_PAGE page)
{
if (!page) return;
- CPDFSDK_PageView* pPageView = (CPDFSDK_PageView*)(((CPDF_Page*)page))->GetPrivateData((FX_LPVOID)page);
- if (pPageView && pPageView->IsLocked()) {
- pPageView->TakeOverPage();
- return;
- }
- delete (CPDF_Page*)page;
+ CPDFXFA_Page* pPage = (CPDFXFA_Page*)page;
+
+ pPage->Release();
+// CPDFXFA_Document* pDoc = pPage->GetDocument();
+// if (pDoc) {
+// pDoc->RemovePage(pPage);
+// }
+// delete (CPDFXFA_Page*)page;
}
@@ -605,14 +751,16 @@ DLLEXPORT void STDCALL FPDF_CloseDocument(FPDF_DOCUMENT document)
{
if (!document)
return;
- CPDF_Document* pDoc = (CPDF_Document*)document;
- CPDF_Parser* pParser = (CPDF_Parser*)pDoc->GetParser();
- if (pParser == NULL)
- {
- delete pDoc;
- return;
- }
- delete pParser;
+ CPDFXFA_Document* pDoc = (CPDFXFA_Document*)document;
+ delete pDoc;
+
+// CPDF_Parser* pParser = (CPDF_Parser*)pDoc->GetParser();
+// if (pParser == NULL)
+// {
+// delete pDoc;
+// return;
+// }
+// delete pParser;
// delete pDoc;
}
@@ -625,34 +773,17 @@ DLLEXPORT void STDCALL FPDF_DeviceToPage(FPDF_PAGE page, int start_x, int start_
int rotate, int device_x, int device_y, double* page_x, double* page_y)
{
if (page == NULL || page_x == NULL || page_y == NULL) return;
- CPDF_Page* pPage = (CPDF_Page*)page;
+ CPDFXFA_Page* pPage = (CPDFXFA_Page*)page;
- CPDF_Matrix page2device;
- pPage->GetDisplayMatrix(page2device, start_x, start_y, size_x, size_y, rotate);
- CPDF_Matrix device2page;
- device2page.SetReverse(page2device);
-
- FX_FLOAT page_x_f, page_y_f;
- 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);
+ pPage->DeviceToPage(start_x, start_y, size_x, size_y, rotate, device_x, device_y, page_x, page_y);
}
DLLEXPORT void STDCALL FPDF_PageToDevice(FPDF_PAGE page, 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 (page == NULL || device_x == NULL || device_y == NULL) return;
- CPDF_Page* pPage = (CPDF_Page*)page;
-
- CPDF_Matrix page2device;
- pPage->GetDisplayMatrix(page2device, start_x, start_y, size_x, size_y, rotate);
-
- FX_FLOAT device_x_f, device_y_f;
- 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);
+ CPDFXFA_Page* pPage = (CPDFXFA_Page*)page;
+ pPage->PageToDevice(start_x, start_y, size_x, size_y, rotate, page_x, page_y, device_x, device_y);
}
DLLEXPORT FPDF_BITMAP STDCALL FPDFBitmap_Create(int width, int height, int alpha)
@@ -734,7 +865,7 @@ void FPDF_RenderPage_Retail(CRenderContext* pContext, FPDF_PAGE page, int start_
int rotate, int flags,FX_BOOL bNeedToRestore, IFSDK_PAUSE_Adapter * pause )
{
//#ifdef _LICENSED_BUILD_
- CPDF_Page* pPage = (CPDF_Page*)page;
+ CPDF_Page* pPage = ((CPDFXFA_Page*)page)->GetPDFPage();
if (pPage == NULL) return;
if (!pContext->m_pOptions)
@@ -797,26 +928,43 @@ void FPDF_RenderPage_Retail(CRenderContext* pContext, FPDF_PAGE page, int start_
DLLEXPORT int STDCALL FPDF_GetPageSizeByIndex(FPDF_DOCUMENT document, int page_index, double* width, double* height)
{
- CPDF_Document* pDoc = (CPDF_Document*)document;
- if(pDoc == NULL)
+// CPDF_Document* pDoc = (CPDF_Document*)document;
+// if(pDoc == NULL)
+// return FALSE;
+//
+// CPDF_Dictionary* pDict = pDoc->GetPage(page_index);
+// if (pDict == NULL) return FALSE;
+//
+// CPDF_Page page;
+// page.Load(pDoc, pDict);
+// *width = page.GetPageWidth();
+// *height = page.GetPageHeight();
+
+ CPDFXFA_Document* pDoc = (CPDFXFA_Document*)document;
+ if (pDoc == NULL)
return FALSE;
- CPDF_Dictionary* pDict = pDoc->GetPage(page_index);
- if (pDict == NULL) return FALSE;
+ int count = pDoc->GetPageCount();
+ if (page_index < 0 || page_index >= count)
+ return FALSE;
- CPDF_Page page;
- page.Load(pDoc, pDict);
- *width = page.GetPageWidth();
- *height = page.GetPageHeight();
+ CPDFXFA_Page* pPage = pDoc->GetPage(page_index);
+ if (!pPage)
+ return FALSE;
+
+ *width = pPage->GetPageWidth();
+ *height = pPage->GetPageHeight();
return TRUE;
}
DLLEXPORT FPDF_BOOL STDCALL FPDF_VIEWERREF_GetPrintScaling(FPDF_DOCUMENT document)
{
- CPDF_Document* pDoc = (CPDF_Document*)document;
+ CPDFXFA_Document* pDoc = (CPDFXFA_Document*)document;
if (!pDoc) return TRUE;
- CPDF_ViewerPreferences viewRef(pDoc);
+ CPDF_Document* pPDFDoc = pDoc->GetPDFDoc();
+ if (!pPDFDoc) return TRUE;
+ CPDF_ViewerPreferences viewRef(pPDFDoc);
return viewRef.PrintScaling();
}
@@ -858,7 +1006,67 @@ DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDestByName(FPDF_DOCUMENT document,FPDF_
if (name == NULL || name[0] == 0)
return NULL;
- CPDF_Document* pDoc = (CPDF_Document*)document;
- CPDF_NameTree name_tree(pDoc, FX_BSTRC("Dests"));
- return name_tree.LookupNamedDest(pDoc, name);
+ CPDFXFA_Document* pDoc = (CPDFXFA_Document*)document;
+ CPDF_Document* pPDFDoc = pDoc->GetPDFDoc();
+ if (!pPDFDoc)
+ return NULL;
+ CPDF_NameTree name_tree(pPDFDoc, FX_BSTRC("Dests"));
+ return name_tree.LookupNamedDest(pPDFDoc, name);
+}
+
+FPDF_RESULT FPDF_BStr_Init(FPDF_BSTR* str)
+{
+ if (!str)
+ return -1;
+
+ FXSYS_memset32(str, 0, sizeof(FPDF_BSTR));
+ return 0;
+}
+
+FPDF_RESULT FPDF_BStr_Set(FPDF_BSTR* str, FPDF_LPCSTR bstr, int length)
+{
+ if (!str) return -1;
+ if (!bstr || !length)
+ return -1;
+ if (length == -1)
+ length = FXSYS_strlen(bstr);
+
+ if (length == 0)
+ {
+ if (str->str)
+ {
+ FX_Free(str->str);
+ str->str = NULL;
+ }
+ str->len = 0;
+ return 0;
+ }
+
+ if (str->str && str->len < length)
+ str->str = FX_Realloc(char, str->str, length+1);
+ else if (!str->str)
+ str->str = FX_Alloc(char, length+1);
+
+ str->str[length] = 0;
+ if (str->str == NULL)
+ return -1;
+
+ FXSYS_memcpy(str->str, bstr, length);
+ str->len = length;
+
+ return 0;
+}
+
+FPDF_RESULT FPDF_BStr_Clear(FPDF_BSTR* str)
+{
+ if(!str)
+ return -1;
+
+ if (str->str)
+ {
+ FX_Free(str->str);
+ str->str = NULL;
+ }
+ str->len = 0;
+ return 0;
}
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);
+ }
+}
diff --git a/fpdfsdk/src/fsdk_actionhandler.cpp b/fpdfsdk/src/fsdk_actionhandler.cpp
index 518abd21f0..494b5298d3 100644
--- a/fpdfsdk/src/fsdk_actionhandler.cpp
+++ b/fpdfsdk/src/fsdk_actionhandler.cpp
@@ -5,6 +5,7 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#include "../include/fsdk_define.h"
+#include "../include/fpdfxfa/fpdfxfa_doc.h"
#include "../include/fsdk_mgr.h"
#include "../include/fsdk_actionhandler.h"
#include "../include/javascript/IJavaScript.h"
@@ -566,7 +567,7 @@ void CPDFSDK_ActionHandler::DoAction_GoTo(CPDFSDK_Document* pDocument, /*CReader
// ASSERT(pDocView != NULL);
ASSERT(action != NULL);
- CPDF_Document* pPDFDocument = pDocument->GetDocument();
+ CPDF_Document* pPDFDocument = pDocument->GetDocument()->GetPDFDoc();
ASSERT(pPDFDocument != NULL);
CPDFDoc_Environment* pApp = pDocument->GetEnv();
ASSERT(pApp != NULL);
@@ -610,7 +611,7 @@ void CPDFSDK_ActionHandler::DoAction_URI(CPDFSDK_Document* pDocument, const CPDF
CPDFDoc_Environment* pApp = pDocument->GetEnv();
ASSERT(pApp != NULL);
- CFX_ByteString sURI = action.GetURI(pDocument->GetDocument());
+ CFX_ByteString sURI = action.GetURI(pDocument->GetDocument()->GetPDFDoc());
pApp->FFI_DoURIAction(FX_LPCSTR(sURI));
}
diff --git a/fpdfsdk/src/fsdk_annothandler.cpp b/fpdfsdk/src/fsdk_annothandler.cpp
index 9f208d34e2..fff038b809 100644
--- a/fpdfsdk/src/fsdk_annothandler.cpp
+++ b/fpdfsdk/src/fsdk_annothandler.cpp
@@ -5,6 +5,8 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#include "../include/fsdk_define.h"
+#include "../include/fpdfxfa/fpdfxfa_doc.h"
+#include "../include/fpdfxfa/fpdfxfa_util.h"
#include "../include/fsdk_mgr.h"
#include "../include/formfiller/FFL_FormFiller.h"
#include "../include/fsdk_annothandler.h"
@@ -17,6 +19,9 @@ CPDFSDK_AnnotHandlerMgr::CPDFSDK_AnnotHandlerMgr(CPDFDoc_Environment* pApp)
CPDFSDK_BFAnnotHandler* pHandler = new CPDFSDK_BFAnnotHandler(m_pApp);
pHandler->SetFormFiller(m_pApp->GetIFormFiller());
RegisterAnnotHandler(pHandler);
+
+ CPDFSDK_XFAAnnotHandler* pXFAAnnotHandler = new CPDFSDK_XFAAnnotHandler(m_pApp);
+ RegisterAnnotHandler(pXFAAnnotHandler);
}
CPDFSDK_AnnotHandlerMgr::~CPDFSDK_AnnotHandlerMgr()
@@ -66,7 +71,20 @@ CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::NewAnnot(CPDF_Annot * pAnnot, CPDFSDK_Pa
return pAnnotHandler->NewAnnot(pAnnot, pPageView);
}
- return new CPDFSDK_Annot(pAnnot, pPageView);
+ return new CPDFSDK_BAAnnot(pAnnot, pPageView);
+}
+
+CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::NewAnnot(XFA_HWIDGET pAnnot, CPDFSDK_PageView* pPageView)
+{
+ ASSERT(pAnnot != NULL);
+ ASSERT(pPageView != NULL);
+
+ if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(FSDK_XFAWIDGET_TYPENAME))
+ {
+ return pAnnotHandler->NewAnnot(pAnnot, pPageView);
+ }
+
+ return NULL;
}
void CPDFSDK_AnnotHandlerMgr::ReleaseAnnot(CPDFSDK_Annot* pAnnot)
@@ -119,9 +137,11 @@ IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler(CPDFSDK_Annot* pA
ASSERT(pAnnot != NULL);
CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot();
- ASSERT(pPDFAnnot != NULL);
-
- return GetAnnotHandler(pPDFAnnot->GetSubType());
+ if (pPDFAnnot)
+ return GetAnnotHandler(pPDFAnnot->GetSubType());
+ else if (pAnnot->GetXFAWidget())
+ return GetAnnotHandler(FSDK_XFAWIDGET_TYPENAME);
+ return NULL;
}
IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler(const CFX_ByteString& sType) const
@@ -141,7 +161,8 @@ void CPDFSDK_AnnotHandlerMgr::Annot_OnDraw(CPDFSDK_PageView* pPageView, CPDFSDK_
}
else
{
- pAnnot->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL);
+ if (!pAnnot->IsXFAField())
+ ((CPDFSDK_BAAnnot*)pAnnot)->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL);
}
}
@@ -323,6 +344,20 @@ FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnKillFocus(CPDFSDK_Annot* pAnnot, FX_D
return FALSE;
}
+FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnChangeFocus(CPDFSDK_Annot* pSetAnnot,CPDFSDK_Annot* pKillAnnot)
+{
+ FX_BOOL bXFA = (pSetAnnot && pSetAnnot->GetXFAWidget()) ||
+ (pKillAnnot && pKillAnnot->GetXFAWidget());
+
+ if (bXFA)
+ {
+ if (IPDFSDK_AnnotHandler* pXFAAnnotHandler = GetAnnotHandler(FSDK_XFAWIDGET_TYPENAME))
+ return pXFAAnnotHandler->OnXFAChangedFocus(pKillAnnot, pSetAnnot);
+ }
+
+ return TRUE;
+}
+
CPDF_Rect CPDFSDK_AnnotHandlerMgr::Annot_OnGetViewBBox(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot)
{
ASSERT(pAnnot);
@@ -346,13 +381,30 @@ FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnHitTest(CPDFSDK_PageView *pPageView, CP
CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::GetNextAnnot(CPDFSDK_Annot* pSDKAnnot,FX_BOOL bNext)
{
- CBA_AnnotIterator ai(pSDKAnnot->GetPageView(), "Widget", "");
-
- CPDFSDK_Annot* pNext = bNext ?
- ai.GetNextAnnot(pSDKAnnot) :
+ CPDFSDK_PageView* pPageView = pSDKAnnot->GetPageView();
+ CPDFXFA_Page* pPage = pPageView->GetPDFXFAPage();
+ if (pPage == NULL)
+ return NULL;
+ if (pPage->GetPDFPage()) { // for pdf annots.
+ CBA_AnnotIterator ai(pSDKAnnot->GetPageView(), pSDKAnnot->GetType(), "");
+ CPDFSDK_Annot* pNext = bNext ?
+ ai.GetNextAnnot(pSDKAnnot) :
ai.GetPrevAnnot(pSDKAnnot);
-
return pNext;
+ }
+ // for xfa annots
+ IXFA_WidgetIterator* pWidgetIterator = pPage->GetXFAPageView()->CreateWidgetIterator(XFA_TRAVERSEWAY_Tranvalse, XFA_WIDGETFILTER_Visible | XFA_WIDGETFILTER_Viewable | XFA_WIDGETFILTER_Field);
+ if (pWidgetIterator == NULL)
+ return NULL;
+ if (pWidgetIterator->GetCurrentWidget() != pSDKAnnot->GetXFAWidget())
+ pWidgetIterator->SetCurrentWidget(pSDKAnnot->GetXFAWidget());
+ XFA_HWIDGET hNextFocus = NULL;
+ hNextFocus = bNext?pWidgetIterator->MoveToNext():pWidgetIterator->MoveToPrevious();
+ if (hNextFocus == NULL && pSDKAnnot != NULL)
+ hNextFocus = pWidgetIterator->MoveToFirst();
+
+ pWidgetIterator->Release();
+ return pPageView->GetAnnotByXFAWidget(hNextFocus);
}
FX_BOOL CPDFSDK_BFAnnotHandler::CanAnswer(CPDFSDK_Annot* pAnnot)
@@ -414,6 +466,11 @@ CPDFSDK_Annot* CPDFSDK_BFAnnotHandler::NewAnnot(CPDF_Annot* pAnnot, CPDFSDK_Pag
return pWidget;
}
+CPDFSDK_Annot* CPDFSDK_BFAnnotHandler::NewAnnot(XFA_HWIDGET hWidget, CPDFSDK_PageView* pPage)
+{
+ return NULL;
+}
+
void CPDFSDK_BFAnnotHandler::ReleaseAnnot(CPDFSDK_Annot* pAnnot)
{
ASSERT(pAnnot != NULL);
@@ -440,7 +497,7 @@ void CPDFSDK_BFAnnotHandler::OnDraw(CPDFSDK_PageView *pPageView, CPDFSDK_Annot*
if (sSubType == BFFT_SIGNATURE)
{
- pAnnot->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL);
+ ((CPDFSDK_BAAnnot*)pAnnot)->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL);
}
else
{
@@ -660,6 +717,15 @@ void CPDFSDK_BFAnnotHandler::OnLoad(CPDFSDK_Annot* pAnnot)
{
ASSERT(pAnnot != NULL);
+ CPDFSDK_PageView* pPageView = pAnnot->GetPageView();
+ ASSERT(pPageView != NULL);
+
+ CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument();
+ ASSERT(pSDKDoc != NULL);
+
+ CPDFXFA_Document* pDoc = pSDKDoc->GetDocument();
+ ASSERT(pDoc != NULL);
+
CFX_ByteString sSubType = pAnnot->GetSubType();
if (sSubType == BFFT_SIGNATURE)
@@ -685,6 +751,12 @@ void CPDFSDK_BFAnnotHandler::OnLoad(CPDFSDK_Annot* pAnnot)
}
}
+ if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA)
+ {
+ if (!pWidget->IsAppearanceValid() && !pWidget->GetValue().IsEmpty())
+ pWidget->ResetAppearance(FALSE);
+ }
+
if (m_pFormFiller)
m_pFormFiller->OnLoad(pAnnot);
@@ -752,6 +824,406 @@ FX_BOOL CPDFSDK_BFAnnotHandler::HitTest(CPDFSDK_PageView *pPageView, CPDFSDK_Ann
return rect.Contains(point.x, point.y);
}
+//CPDFSDK_XFAAnnotHandler
+
+#define FWL_WGTHITTEST_Unknown 0
+#define FWL_WGTHITTEST_Client 1 //arrow
+#define FWL_WGTHITTEST_Titlebar 11 //caption
+#define FWL_WGTHITTEST_HScrollBar 15
+#define FWL_WGTHITTEST_VScrollBar 16
+#define FWL_WGTHITTEST_Border 17
+#define FWL_WGTHITTEST_Edit 19
+#define FWL_WGTHITTEST_HyperLink 20
+
+CPDFSDK_XFAAnnotHandler::CPDFSDK_XFAAnnotHandler(CPDFDoc_Environment* pApp) :
+ m_pApp(pApp)
+{
+
+}
+
+CPDFSDK_Annot* CPDFSDK_XFAAnnotHandler::NewAnnot(XFA_HWIDGET pAnnot, CPDFSDK_PageView* pPage)
+{
+ ASSERT(pPage != NULL);
+ ASSERT(pAnnot != NULL);
+
+ CPDFSDK_Document* pSDKDoc = m_pApp->GetCurrentDoc();
+ ASSERT(pSDKDoc);
+ CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pSDKDoc->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ CPDFSDK_XFAWidget* pWidget = NULL;
+ pWidget = new CPDFSDK_XFAWidget(pAnnot, pPage, pInterForm);
+ ASSERT(pWidget != NULL);
+ pInterForm->AddXFAMap(pAnnot, pWidget);
+
+ return pWidget;
+}
+
+FX_BOOL CPDFSDK_XFAAnnotHandler::CanAnswer(CPDFSDK_Annot* pAnnot)
+{
+ ASSERT(pAnnot != NULL);
+
+ return pAnnot->GetXFAWidget() != NULL;
+}
+
+void CPDFSDK_XFAAnnotHandler::OnDraw(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device, FX_DWORD dwFlags)
+{
+ ASSERT(pPageView != NULL);
+ ASSERT(pAnnot != NULL);
+
+ CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument();
+ ASSERT(pSDKDoc != NULL);
+
+ IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
+ ASSERT(pWidgetHandler != NULL);
+
+ CFX_Graphics gs;
+ gs.Create(pDevice);
+
+ CFX_Matrix mt;
+ mt = *(CFX_Matrix*)pUser2Device;
+
+ XFA_HWIDGET hWidget = pAnnot->GetXFAWidget();
+ ASSERT(hWidget != NULL);
+
+ FX_BOOL bIsHighlight = FALSE;
+ if (pSDKDoc->GetFocusAnnot() != pAnnot)
+ bIsHighlight = TRUE;
+
+ pWidgetHandler->RenderWidget(pAnnot->GetXFAWidget(), &gs, &mt, bIsHighlight);
+
+ // to do highlight and shadow
+
+}
+
+void CPDFSDK_XFAAnnotHandler::ReleaseAnnot(CPDFSDK_Annot* pAnnot)
+{
+ ASSERT(pAnnot != NULL);
+
+ CPDFSDK_XFAWidget* pWidget = (CPDFSDK_XFAWidget*)pAnnot;
+ CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm();
+ ASSERT(pInterForm != NULL);
+
+ pInterForm->RemoveXFAMap(pWidget->GetXFAWidget());
+
+ delete pWidget;
+}
+
+CPDF_Rect CPDFSDK_XFAAnnotHandler::GetViewBBox(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot)
+{
+ ASSERT(pAnnot != NULL);
+
+ IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
+ ASSERT(pWidgetHandler != NULL);
+
+ XFA_ELEMENT eType = pWidgetHandler->GetDataAcc(pAnnot->GetXFAWidget())->GetUIType();
+ CFX_RectF rcBBox;
+ if (eType == XFA_ELEMENT_Signature)
+ pWidgetHandler->GetBBox (pAnnot->GetXFAWidget(), rcBBox, XFA_WIDGETSTATUS_Visible, TRUE);
+ else
+ pWidgetHandler->GetBBox (pAnnot->GetXFAWidget(), rcBBox, 0);
+
+ CFX_FloatRect rcWidget(rcBBox.left, rcBBox.top, rcBBox.left + rcBBox.width, rcBBox.top+rcBBox.height);
+ rcWidget.left -= 1.0f;
+ rcWidget.right += 1.0f;
+ rcWidget.bottom -= 1.0f;
+ rcWidget.top += 1.0f;
+
+ return rcWidget;
+}
+
+FX_BOOL CPDFSDK_XFAAnnotHandler::HitTest(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, const CPDF_Point& point)
+{
+ if (!pPageView || !pAnnot)
+ return FALSE;
+
+ CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument();
+ if (!pSDKDoc)
+ return FALSE;
+
+ CPDFXFA_Document* pDoc = pSDKDoc->GetDocument();
+ if (!pDoc)
+ return FALSE;
+
+ IXFA_DocView* pDocView = pDoc->GetXFADocView();
+ if (!pDocView)
+ return FALSE;
+
+ IXFA_WidgetHandler* pWidgetHandler = pDocView->GetWidgetHandler();
+ if (!pWidgetHandler)
+ return FALSE;
+
+ FX_DWORD dwHitTest = pWidgetHandler->OnHitTest(pAnnot->GetXFAWidget(), point.x, point.y);
+ return (dwHitTest != FWL_WGTHITTEST_Unknown);
+}
+
+void CPDFSDK_XFAAnnotHandler::OnMouseEnter(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlag)
+{
+ if (!pPageView || !pAnnot)
+ return;
+ IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
+ ASSERT(pWidgetHandler != NULL);
+
+ pWidgetHandler->OnMouseEnter(pAnnot->GetXFAWidget());
+}
+
+void CPDFSDK_XFAAnnotHandler::OnMouseExit(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlag)
+{
+ if (!pPageView || !pAnnot)
+ return;
+
+ IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
+ ASSERT(pWidgetHandler != NULL);
+
+ pWidgetHandler->OnMouseExit(pAnnot->GetXFAWidget());
+}
+
+FX_BOOL CPDFSDK_XFAAnnotHandler::OnLButtonDown(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point)
+{
+ if (!pPageView || !pAnnot)
+ return FALSE;
+
+ IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
+ ASSERT(pWidgetHandler != NULL);
+
+ FX_BOOL bRet = FALSE;
+ bRet = pWidgetHandler->OnLButtonDown(pAnnot->GetXFAWidget(), GetFWLFlags(nFlags), point.x, point.y);
+
+ return bRet;
+}
+
+FX_BOOL CPDFSDK_XFAAnnotHandler::OnLButtonUp(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point)
+{
+ if (!pPageView || !pAnnot)
+ return FALSE;
+
+ IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
+ ASSERT(pWidgetHandler != NULL);
+
+ FX_BOOL bRet = FALSE;
+ bRet = pWidgetHandler->OnLButtonUp(pAnnot->GetXFAWidget(), GetFWLFlags(nFlags), point.x, point.y);
+
+ return bRet;
+}
+
+FX_BOOL CPDFSDK_XFAAnnotHandler::OnLButtonDblClk(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point)
+{
+ if (!pPageView || !pAnnot)
+ return FALSE;
+
+ IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
+ ASSERT(pWidgetHandler != NULL);
+
+ FX_BOOL bRet = FALSE;
+ bRet = pWidgetHandler->OnLButtonDblClk(pAnnot->GetXFAWidget(), GetFWLFlags(nFlags), point.x, point.y);
+
+ return bRet;
+}
+
+FX_BOOL CPDFSDK_XFAAnnotHandler::OnMouseMove(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point)
+{
+ if (!pPageView || !pAnnot)
+ return FALSE;
+
+ IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
+ ASSERT(pWidgetHandler != NULL);
+
+ FX_BOOL bRet = FALSE;
+ bRet = pWidgetHandler->OnMouseMove(pAnnot->GetXFAWidget(), GetFWLFlags(nFlags), point.x, point.y);
+
+ return bRet;
+}
+
+FX_BOOL CPDFSDK_XFAAnnotHandler::OnMouseWheel(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, short zDelta, const CPDF_Point& point)
+{
+ if (!pPageView || !pAnnot)
+ return FALSE;
+
+ IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
+ ASSERT(pWidgetHandler != NULL);
+
+ FX_BOOL bRet = FALSE;
+ bRet = pWidgetHandler->OnMouseWheel(pAnnot->GetXFAWidget(), GetFWLFlags(nFlags), zDelta, point.x, point.y);
+
+ return bRet;
+}
+
+FX_BOOL CPDFSDK_XFAAnnotHandler::OnRButtonDown(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point)
+{
+ if (!pPageView || !pAnnot)
+ return FALSE;
+
+ IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
+ ASSERT(pWidgetHandler != NULL);
+
+ FX_BOOL bRet = FALSE;
+ bRet = pWidgetHandler->OnRButtonDown(pAnnot->GetXFAWidget(), GetFWLFlags(nFlags), point.x, point.y);
+
+ return bRet;
+}
+
+FX_BOOL CPDFSDK_XFAAnnotHandler::OnRButtonUp(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point)
+{
+ if (!pPageView || !pAnnot)
+ return FALSE;
+
+ IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
+ ASSERT(pWidgetHandler != NULL);
+
+ FX_BOOL bRet = FALSE;
+ bRet = pWidgetHandler->OnRButtonUp(pAnnot->GetXFAWidget(), GetFWLFlags(nFlags), point.x, point.y);
+
+ return bRet;
+}
+
+FX_BOOL CPDFSDK_XFAAnnotHandler::OnRButtonDblClk(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point)
+{
+ if (!pPageView || !pAnnot)
+ return FALSE;
+
+ IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
+ ASSERT(pWidgetHandler != NULL);
+
+ FX_BOOL bRet = FALSE;
+ bRet = pWidgetHandler->OnRButtonDblClk(pAnnot->GetXFAWidget(), GetFWLFlags(nFlags), point.x, point.y);
+
+ return bRet;
+}
+
+FX_BOOL CPDFSDK_XFAAnnotHandler::OnChar(CPDFSDK_Annot* pAnnot, FX_DWORD nChar, FX_DWORD nFlags)
+{
+ if (!pAnnot)
+ return FALSE;
+
+ IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
+ ASSERT(pWidgetHandler != NULL);
+
+ FX_BOOL bRet = FALSE;
+ bRet = pWidgetHandler->OnChar(pAnnot->GetXFAWidget(), nChar, GetFWLFlags(nFlags));
+
+ return bRet;
+}
+
+FX_BOOL CPDFSDK_XFAAnnotHandler::OnKeyDown(CPDFSDK_Annot* pAnnot, int nKeyCode, int nFlag)
+{
+ if (!pAnnot)
+ return FALSE;
+
+ IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
+ ASSERT(pWidgetHandler != NULL);
+
+ FX_BOOL bRet = FALSE;
+ bRet = pWidgetHandler->OnKeyDown(pAnnot->GetXFAWidget(), nKeyCode, GetFWLFlags(nFlag));
+
+ return bRet;
+}
+
+FX_BOOL CPDFSDK_XFAAnnotHandler::OnKeyUp(CPDFSDK_Annot* pAnnot, int nKeyCode, int nFlag)
+{
+ if (!pAnnot)
+ return FALSE;
+
+ IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot);
+ ASSERT(pWidgetHandler != NULL);
+
+ FX_BOOL bRet = FALSE;
+ bRet = pWidgetHandler->OnKeyUp(pAnnot->GetXFAWidget(), nKeyCode, GetFWLFlags(nFlag));
+
+ return bRet;
+}
+
+FX_BOOL CPDFSDK_XFAAnnotHandler::OnSetFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFlag)
+{
+ return TRUE;
+}
+
+FX_BOOL CPDFSDK_XFAAnnotHandler::OnKillFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFlag)
+{
+ return TRUE;
+}
+
+FX_BOOL CPDFSDK_XFAAnnotHandler::OnXFAChangedFocus(CPDFSDK_Annot* pOldAnnot, CPDFSDK_Annot* pNewAnnot)
+{
+ IXFA_WidgetHandler* pWidgetHandler = NULL;
+
+ if (pOldAnnot)
+ pWidgetHandler = GetXFAWidgetHandler(pOldAnnot);
+ else if (pNewAnnot)
+ pWidgetHandler = GetXFAWidgetHandler(pNewAnnot);
+
+ if (pWidgetHandler)
+ {
+ FX_BOOL bRet = TRUE; /*pWidgetHandler->OnFocusChange(pNewAnnot ? pNewAnnot->GetXFAWidget() : NULL,
+ pOldAnnot ? pOldAnnot->GetXFAWidget() : NULL); */
+
+ XFA_HWIDGET hWidget = pNewAnnot ? pNewAnnot->GetXFAWidget() : NULL;
+ if (hWidget)
+ {
+ IXFA_PageView* pXFAPageView = pWidgetHandler->GetPageView(hWidget);
+ if (pXFAPageView)
+ {
+ bRet = pXFAPageView->GetDocView()->SetFocus(hWidget);
+ if (pXFAPageView->GetDocView()->GetFocusWidget() == hWidget)
+ bRet = TRUE;
+ }
+ }
+ return bRet;
+ }
+
+ return TRUE;
+}
+
+IXFA_WidgetHandler* CPDFSDK_XFAAnnotHandler::GetXFAWidgetHandler(CPDFSDK_Annot* pAnnot)
+{
+ if (!pAnnot)
+ return NULL;
+
+ CPDFSDK_PageView* pPageView = pAnnot->GetPageView();
+ if (!pPageView)
+ return NULL;
+
+ CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument();
+ if (!pSDKDoc)
+ return NULL;
+
+ CPDFXFA_Document* pDoc = pSDKDoc->GetDocument();
+ if (!pDoc)
+ return NULL;
+
+ IXFA_DocView* pDocView = pDoc->GetXFADocView();
+ if (!pDocView)
+ return NULL;
+
+ return pDocView->GetWidgetHandler();
+}
+
+#define FWL_KEYFLAG_Ctrl (1 << 0)
+#define FWL_KEYFLAG_Alt (1 << 1)
+#define FWL_KEYFLAG_Shift (1 << 2)
+#define FWL_KEYFLAG_LButton (1 << 3)
+#define FWL_KEYFLAG_RButton (1 << 4)
+#define FWL_KEYFLAG_MButton (1 << 5)
+
+FX_DWORD CPDFSDK_XFAAnnotHandler::GetFWLFlags(FX_DWORD dwFlag)
+{
+ FX_DWORD dwFWLFlag = 0;
+
+ if (dwFlag & FWL_EVENTFLAG_ControlKey)
+ dwFWLFlag |= FWL_KEYFLAG_Ctrl;
+ if (dwFlag & FWL_EVENTFLAG_LeftButtonDown)
+ dwFWLFlag |= FWL_KEYFLAG_LButton;
+ if (dwFlag & FWL_EVENTFLAG_MiddleButtonDown)
+ dwFWLFlag |= FWL_KEYFLAG_MButton;
+ if (dwFlag & FWL_EVENTFLAG_RightButtonDown)
+ dwFWLFlag |= FWL_KEYFLAG_RButton;
+ if (dwFlag & FWL_EVENTFLAG_ShiftKey)
+ dwFWLFlag |= FWL_KEYFLAG_Shift;
+ if (dwFlag & FWL_EVENTFLAG_AltKey)
+ dwFWLFlag |= FWL_KEYFLAG_Alt;
+
+ return dwFWLFlag;
+}
+
//CReader_AnnotIteratorEx
CPDFSDK_AnnotIterator::CPDFSDK_AnnotIterator(CPDFSDK_PageView * pPageView,FX_BOOL bReverse,
diff --git a/fpdfsdk/src/fsdk_baseannot.cpp b/fpdfsdk/src/fsdk_baseannot.cpp
index ff054c8b20..90e22d32b2 100644
--- a/fpdfsdk/src/fsdk_baseannot.cpp
+++ b/fpdfsdk/src/fsdk_baseannot.cpp
@@ -5,6 +5,7 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#include "../include/fsdk_define.h"
+#include "../include/fpdfxfa/fpdfxfa_doc.h"
#include "../include/fsdk_mgr.h"
#include "../include/fsdk_baseannot.h"
@@ -500,40 +501,30 @@ CPDFSDK_DateTime& CPDFSDK_DateTime::AddSeconds(int seconds)
//---------------------------------------------------------------------------
// CPDFSDK_Annot
//---------------------------------------------------------------------------
-CPDFSDK_Annot::CPDFSDK_Annot(CPDF_Annot* pAnnot, CPDFSDK_PageView* pPageView) :
-m_pAnnot(pAnnot),
+CPDFSDK_Annot::CPDFSDK_Annot(CPDFSDK_PageView* pPageView) :
m_pPageView(pPageView),
m_bSelected(FALSE),
m_nTabOrder(-1)
{
}
-CPDFSDK_Annot::~CPDFSDK_Annot()
-{
- m_pAnnot = NULL;
- m_pPageView = NULL;
-}
-CPDF_Annot* CPDFSDK_Annot::GetPDFAnnot()
+//CPDFSDK_BAAnnot
+CPDFSDK_BAAnnot::CPDFSDK_BAAnnot(CPDF_Annot* pAnnot, CPDFSDK_PageView* pPageView) :
+ CPDFSDK_Annot(pPageView),
+ m_pAnnot(pAnnot)
{
- return m_pAnnot;
-}
-FX_DWORD CPDFSDK_Annot::GetFlags()
-{
- ASSERT(m_pAnnot != NULL);
-
- return m_pAnnot->GetFlags();
}
-void CPDFSDK_Annot::SetPage(CPDFSDK_PageView* pPageView)
+CPDFSDK_BAAnnot::~CPDFSDK_BAAnnot()
{
- m_pPageView = pPageView;
+ m_pAnnot = NULL;
}
-CPDFSDK_PageView* CPDFSDK_Annot::GetPageView()
+CPDF_Annot* CPDFSDK_BAAnnot::GetPDFAnnot()
{
- return m_pPageView;
+ return m_pAnnot;
}
FX_BOOL CPDFSDK_Annot::IsSelected()
@@ -557,14 +548,14 @@ void CPDFSDK_Annot::SetTabOrder(int iTabOrder)
m_nTabOrder = iTabOrder;
}
-CPDF_Dictionary* CPDFSDK_Annot::GetAnnotDict() const
+CPDF_Dictionary* CPDFSDK_BAAnnot::GetAnnotDict() const
{
ASSERT(m_pAnnot != NULL);
return m_pAnnot->m_pAnnotDict;
}
-void CPDFSDK_Annot::SetRect(const CPDF_Rect& rect)
+void CPDFSDK_BAAnnot::SetRect(const CPDF_Rect& rect)
{
ASSERT(m_pAnnot != NULL);
ASSERT(m_pAnnot->m_pAnnotDict != NULL);
@@ -574,7 +565,7 @@ void CPDFSDK_Annot::SetRect(const CPDF_Rect& rect)
m_pAnnot->m_pAnnotDict->SetAtRect("Rect", rect);
}
-CPDF_Rect CPDFSDK_Annot::GetRect() const
+CPDF_Rect CPDFSDK_BAAnnot::GetRect() const
{
ASSERT(m_pAnnot != NULL);
@@ -584,19 +575,24 @@ CPDF_Rect CPDFSDK_Annot::GetRect() const
return rect;
}
-CFX_ByteString CPDFSDK_Annot::GetType() const
+CFX_ByteString CPDFSDK_BAAnnot::GetType() const
{
ASSERT(m_pAnnot != NULL);
return m_pAnnot->GetSubType();
}
-CFX_ByteString CPDFSDK_Annot::GetSubType() const
+CFX_ByteString CPDFSDK_BAAnnot::GetSubType() const
{
return "";
}
-void CPDFSDK_Annot::DrawAppearance(CFX_RenderDevice* pDevice, const CPDF_Matrix* pUser2Device,
+void CPDFSDK_BAAnnot::ResetAppearance()
+{
+ ASSERT(FALSE);
+}
+
+void CPDFSDK_BAAnnot::DrawAppearance(CFX_RenderDevice* pDevice, const CPDF_Matrix* pUser2Device,
CPDF_Annot::AppearanceMode mode, const CPDF_RenderOptions* pOptions)
{
ASSERT(m_pPageView != NULL);
@@ -605,7 +601,7 @@ void CPDFSDK_Annot::DrawAppearance(CFX_RenderDevice* pDevice, const CPDF_Matrix*
m_pAnnot->DrawAppearance(m_pPageView->GetPDFPage(), pDevice, pUser2Device, mode, pOptions);
}
-FX_BOOL CPDFSDK_Annot::IsAppearanceValid()
+FX_BOOL CPDFSDK_BAAnnot::IsAppearanceValid()
{
ASSERT(m_pAnnot != NULL);
ASSERT(m_pAnnot->m_pAnnotDict != NULL);
@@ -613,7 +609,7 @@ FX_BOOL CPDFSDK_Annot::IsAppearanceValid()
return m_pAnnot->m_pAnnotDict->GetDict("AP") != NULL;
}
-FX_BOOL CPDFSDK_Annot::IsAppearanceValid(CPDF_Annot::AppearanceMode mode)
+FX_BOOL CPDFSDK_BAAnnot::IsAppearanceValid(CPDF_Annot::AppearanceMode mode)
{
ASSERT(m_pAnnot != NULL);
ASSERT(m_pAnnot->m_pAnnotDict != NULL);
@@ -637,20 +633,20 @@ FX_BOOL CPDFSDK_Annot::IsAppearanceValid(CPDF_Annot::AppearanceMode mode)
return TRUE;
}
-void CPDFSDK_Annot::DrawBorder(CFX_RenderDevice* pDevice, const CPDF_Matrix* pUser2Device,
+void CPDFSDK_BAAnnot::DrawBorder(CFX_RenderDevice* pDevice, const CPDF_Matrix* pUser2Device,
const CPDF_RenderOptions* pOptions)
{
ASSERT(m_pAnnot != NULL);
m_pAnnot->DrawBorder(pDevice, pUser2Device, pOptions);
}
-void CPDFSDK_Annot::ClearCachedAP()
+void CPDFSDK_BAAnnot::ClearCachedAP()
{
ASSERT(m_pAnnot != NULL);
m_pAnnot->ClearCachedAP();
}
-void CPDFSDK_Annot::SetContents(const CFX_WideString& sContents)
+void CPDFSDK_BAAnnot::SetContents(const CFX_WideString& sContents)
{
ASSERT(m_pAnnot != NULL);
ASSERT(m_pAnnot->m_pAnnotDict != NULL);
@@ -661,7 +657,7 @@ void CPDFSDK_Annot::SetContents(const CFX_WideString& sContents)
m_pAnnot->m_pAnnotDict->SetAtString("Contents", PDF_EncodeText(sContents));
}
-CFX_WideString CPDFSDK_Annot::GetContents() const
+CFX_WideString CPDFSDK_BAAnnot::GetContents() const
{
ASSERT(m_pAnnot != NULL);
ASSERT(m_pAnnot->m_pAnnotDict != NULL);
@@ -669,7 +665,7 @@ CFX_WideString CPDFSDK_Annot::GetContents() const
return m_pAnnot->m_pAnnotDict->GetUnicodeText("Contents");
}
-void CPDFSDK_Annot::SetAnnotName(const CFX_WideString& sName)
+void CPDFSDK_BAAnnot::SetAnnotName(const CFX_WideString& sName)
{
ASSERT(m_pAnnot != NULL);
ASSERT(m_pAnnot->m_pAnnotDict != NULL);
@@ -680,7 +676,7 @@ void CPDFSDK_Annot::SetAnnotName(const CFX_WideString& sName)
m_pAnnot->m_pAnnotDict->SetAtString("NM", PDF_EncodeText(sName));
}
-CFX_WideString CPDFSDK_Annot::GetAnnotName() const
+CFX_WideString CPDFSDK_BAAnnot::GetAnnotName() const
{
ASSERT(m_pAnnot != NULL);
ASSERT(m_pAnnot->m_pAnnotDict != NULL);
@@ -688,7 +684,7 @@ CFX_WideString CPDFSDK_Annot::GetAnnotName() const
return m_pAnnot->m_pAnnotDict->GetUnicodeText("NM");
}
-void CPDFSDK_Annot::SetModifiedDate(const FX_SYSTEMTIME& st)
+void CPDFSDK_BAAnnot::SetModifiedDate(const FX_SYSTEMTIME& st)
{
ASSERT(m_pAnnot != NULL);
ASSERT(m_pAnnot->m_pAnnotDict != NULL);
@@ -702,7 +698,7 @@ void CPDFSDK_Annot::SetModifiedDate(const FX_SYSTEMTIME& st)
m_pAnnot->m_pAnnotDict->SetAtString("M", str);
}
-FX_SYSTEMTIME CPDFSDK_Annot::GetModifiedDate() const
+FX_SYSTEMTIME CPDFSDK_BAAnnot::GetModifiedDate() const
{
ASSERT(m_pAnnot != NULL);
ASSERT(m_pAnnot->m_pAnnotDict != NULL);
@@ -716,7 +712,7 @@ FX_SYSTEMTIME CPDFSDK_Annot::GetModifiedDate() const
return systime;
}
-void CPDFSDK_Annot::SetFlags(int nFlags)
+void CPDFSDK_BAAnnot::SetFlags(int nFlags)
{
ASSERT(m_pAnnot != NULL);
ASSERT(m_pAnnot->m_pAnnotDict != NULL);
@@ -724,7 +720,7 @@ void CPDFSDK_Annot::SetFlags(int nFlags)
m_pAnnot->m_pAnnotDict->SetAtInteger("F", nFlags);
}
-int CPDFSDK_Annot::GetFlags() const
+int CPDFSDK_BAAnnot::GetFlags() const
{
ASSERT(m_pAnnot != NULL);
ASSERT(m_pAnnot->m_pAnnotDict != NULL);
@@ -732,7 +728,7 @@ int CPDFSDK_Annot::GetFlags() const
return m_pAnnot->m_pAnnotDict->GetInteger("F");
}
-void CPDFSDK_Annot::SetAppState(const CFX_ByteString& str)
+void CPDFSDK_BAAnnot::SetAppState(const CFX_ByteString& str)
{
ASSERT(m_pAnnot != NULL);
ASSERT(m_pAnnot->m_pAnnotDict != NULL);
@@ -743,7 +739,7 @@ void CPDFSDK_Annot::SetAppState(const CFX_ByteString& str)
m_pAnnot->m_pAnnotDict->SetAtString("AS", str);
}
-CFX_ByteString CPDFSDK_Annot::GetAppState() const
+CFX_ByteString CPDFSDK_BAAnnot::GetAppState() const
{
ASSERT(m_pAnnot != NULL);
ASSERT(m_pAnnot->m_pAnnotDict != NULL);
@@ -751,7 +747,7 @@ CFX_ByteString CPDFSDK_Annot::GetAppState() const
return m_pAnnot->m_pAnnotDict->GetString("AS");
}
-void CPDFSDK_Annot::SetStructParent(int key)
+void CPDFSDK_BAAnnot::SetStructParent(int key)
{
ASSERT(m_pAnnot != NULL);
ASSERT(m_pAnnot->m_pAnnotDict != NULL);
@@ -759,7 +755,7 @@ void CPDFSDK_Annot::SetStructParent(int key)
m_pAnnot->m_pAnnotDict->SetAtInteger("StructParent", key);
}
-int CPDFSDK_Annot::GetStructParent() const
+int CPDFSDK_BAAnnot::GetStructParent() const
{
ASSERT(m_pAnnot != NULL);
ASSERT(m_pAnnot->m_pAnnotDict != NULL);
@@ -768,7 +764,7 @@ int CPDFSDK_Annot::GetStructParent() const
}
//border
-void CPDFSDK_Annot::SetBorderWidth(int nWidth)
+void CPDFSDK_BAAnnot::SetBorderWidth(int nWidth)
{
ASSERT(m_pAnnot != NULL);
ASSERT(m_pAnnot->m_pAnnotDict != NULL);
@@ -793,7 +789,7 @@ void CPDFSDK_Annot::SetBorderWidth(int nWidth)
}
}
-int CPDFSDK_Annot::GetBorderWidth() const
+int CPDFSDK_BAAnnot::GetBorderWidth() const
{
ASSERT(m_pAnnot != NULL);
ASSERT(m_pAnnot->m_pAnnotDict != NULL);
@@ -816,7 +812,7 @@ int CPDFSDK_Annot::GetBorderWidth() const
return 1;
}
-void CPDFSDK_Annot::SetBorderStyle(int nStyle)
+void CPDFSDK_BAAnnot::SetBorderStyle(int nStyle)
{
ASSERT(m_pAnnot != NULL);
ASSERT(m_pAnnot->m_pAnnotDict != NULL);
@@ -848,7 +844,7 @@ void CPDFSDK_Annot::SetBorderStyle(int nStyle)
}
}
-int CPDFSDK_Annot::GetBorderStyle() const
+int CPDFSDK_BAAnnot::GetBorderStyle() const
{
ASSERT(m_pAnnot != NULL);
ASSERT(m_pAnnot->m_pAnnotDict != NULL);
@@ -878,7 +874,7 @@ int CPDFSDK_Annot::GetBorderStyle() const
return BBS_SOLID;
}
-void CPDFSDK_Annot::SetBorderDash(const CFX_IntArray& array)
+void CPDFSDK_BAAnnot::SetBorderDash(const CFX_IntArray& array)
{
ASSERT(m_pAnnot != NULL);
ASSERT(m_pAnnot->m_pAnnotDict != NULL);
@@ -899,7 +895,7 @@ void CPDFSDK_Annot::SetBorderDash(const CFX_IntArray& array)
pBSDict->SetAt("D", pArray);
}
-void CPDFSDK_Annot::GetBorderDash(CFX_IntArray& array) const
+void CPDFSDK_BAAnnot::GetBorderDash(CFX_IntArray& array) const
{
ASSERT(m_pAnnot != NULL);
ASSERT(m_pAnnot->m_pAnnotDict != NULL);
@@ -929,7 +925,7 @@ void CPDFSDK_Annot::GetBorderDash(CFX_IntArray& array) const
}
}
-void CPDFSDK_Annot::SetColor(FX_COLORREF color)
+void CPDFSDK_BAAnnot::SetColor(FX_COLORREF color)
{
ASSERT(m_pAnnot != NULL);
ASSERT(m_pAnnot->m_pAnnotDict != NULL);
@@ -941,7 +937,7 @@ void CPDFSDK_Annot::SetColor(FX_COLORREF color)
m_pAnnot->m_pAnnotDict->SetAt("C", pArray);
}
-void CPDFSDK_Annot::RemoveColor()
+void CPDFSDK_BAAnnot::RemoveColor()
{
ASSERT(m_pAnnot != NULL);
ASSERT(m_pAnnot->m_pAnnotDict != NULL);
@@ -949,7 +945,7 @@ void CPDFSDK_Annot::RemoveColor()
m_pAnnot->m_pAnnotDict->RemoveAt("C") ;
}
-FX_BOOL CPDFSDK_Annot::GetColor(FX_COLORREF& color) const
+FX_BOOL CPDFSDK_BAAnnot::GetColor(FX_COLORREF& color) const
{
ASSERT(m_pAnnot != NULL);
ASSERT(m_pAnnot->m_pAnnotDict != NULL);
@@ -996,7 +992,7 @@ FX_BOOL CPDFSDK_Annot::GetColor(FX_COLORREF& color) const
}
-void CPDFSDK_Annot::WriteAppearance(const CFX_ByteString& sAPType, const CPDF_Rect& rcBBox,
+void CPDFSDK_BAAnnot::WriteAppearance(const CFX_ByteString& sAPType, const CPDF_Rect& rcBBox,
const CPDF_Matrix& matrix, const CFX_ByteString& sContents,
const CFX_ByteString& sAPState)
{
@@ -1078,17 +1074,17 @@ FX_FLOAT CPDFSDK_Annot::GetMinHeight() const
return BA_ANNOT_MINHEIGHT;
}
-FX_BOOL CPDFSDK_Annot::CreateFormFiller()
+FX_BOOL CPDFSDK_BAAnnot::CreateFormFiller()
{
return TRUE;
}
-FX_BOOL CPDFSDK_Annot::IsVisible() const
+FX_BOOL CPDFSDK_BAAnnot::IsVisible() const
{
int nFlags = GetFlags();
return !((nFlags & ANNOTFLAG_INVISIBLE) || (nFlags & ANNOTFLAG_HIDDEN) || (nFlags & ANNOTFLAG_NOVIEW));
}
-CPDF_Action CPDFSDK_Annot::GetAction() const
+CPDF_Action CPDFSDK_BAAnnot::GetAction() const
{
ASSERT(m_pAnnot != NULL);
ASSERT(m_pAnnot->m_pAnnotDict != NULL);
@@ -1096,7 +1092,7 @@ CPDF_Action CPDFSDK_Annot::GetAction() const
return m_pAnnot->m_pAnnotDict->GetDict("A");
}
-void CPDFSDK_Annot::SetAction(const CPDF_Action& action)
+void CPDFSDK_BAAnnot::SetAction(const CPDF_Action& action)
{
ASSERT(m_pAnnot != NULL);
ASSERT(m_pAnnot->m_pAnnotDict != NULL);
@@ -1114,7 +1110,7 @@ void CPDFSDK_Annot::SetAction(const CPDF_Action& action)
}
}
-void CPDFSDK_Annot::RemoveAction()
+void CPDFSDK_BAAnnot::RemoveAction()
{
ASSERT(m_pAnnot != NULL);
ASSERT(m_pAnnot->m_pAnnotDict != NULL);
@@ -1122,7 +1118,7 @@ void CPDFSDK_Annot::RemoveAction()
m_pAnnot->m_pAnnotDict->RemoveAt("A");
}
-CPDF_AAction CPDFSDK_Annot::GetAAction() const
+CPDF_AAction CPDFSDK_BAAnnot::GetAAction() const
{
ASSERT(m_pAnnot != NULL);
ASSERT(m_pAnnot->m_pAnnotDict != NULL);
@@ -1130,7 +1126,7 @@ CPDF_AAction CPDFSDK_Annot::GetAAction() const
return m_pAnnot->m_pAnnotDict->GetDict("AA");
}
-void CPDFSDK_Annot::SetAAction(const CPDF_AAction& aa)
+void CPDFSDK_BAAnnot::SetAAction(const CPDF_AAction& aa)
{
ASSERT(m_pAnnot != NULL);
ASSERT(m_pAnnot->m_pAnnotDict != NULL);
@@ -1140,7 +1136,7 @@ void CPDFSDK_Annot::SetAAction(const CPDF_AAction& aa)
m_pAnnot->m_pAnnotDict->SetAt("AA", (CPDF_AAction&)aa);
}
-void CPDFSDK_Annot::RemoveAAction()
+void CPDFSDK_BAAnnot::RemoveAAction()
{
ASSERT(m_pAnnot != NULL);
ASSERT(m_pAnnot->m_pAnnotDict != NULL);
@@ -1148,7 +1144,7 @@ void CPDFSDK_Annot::RemoveAAction()
m_pAnnot->m_pAnnotDict->RemoveAt("AA");
}
-CPDF_Action CPDFSDK_Annot::GetAAction(CPDF_AAction::AActionType eAAT)
+CPDF_Action CPDFSDK_BAAnnot::GetAAction(CPDF_AAction::AActionType eAAT)
{
CPDF_AAction AAction = GetAAction();
@@ -1164,7 +1160,12 @@ CPDF_Action CPDFSDK_Annot::GetAAction(CPDF_AAction::AActionType eAAT)
return NULL;
}
-void CPDFSDK_Annot::Annot_OnDraw(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device, CPDF_RenderOptions* pOptions)
+FX_BOOL CPDFSDK_BAAnnot::IsXFAField()
+{
+ return FALSE;
+}
+
+void CPDFSDK_BAAnnot::Annot_OnDraw(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device, CPDF_RenderOptions* pOptions)
{
m_pAnnot->GetAPForm(m_pPageView->GetPDFPage(), CPDF_Annot::Normal);
@@ -1180,3 +1181,10 @@ CPDF_Page* CPDFSDK_Annot::GetPDFPage()
return NULL;
}
+CPDFXFA_Page* CPDFSDK_Annot::GetPDFXFAPage()
+{
+ if (m_pPageView)
+ return m_pPageView->GetPDFXFAPage();
+ return NULL;
+}
+
diff --git a/fpdfsdk/src/fsdk_baseform.cpp b/fpdfsdk/src/fsdk_baseform.cpp
index aa87dd56bb..c301a8760a 100644
--- a/fpdfsdk/src/fsdk_baseform.cpp
+++ b/fpdfsdk/src/fsdk_baseform.cpp
@@ -5,6 +5,8 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#include "../include/fsdk_define.h"
+#include "../include/fpdfxfa/fpdfxfa_doc.h"
+#include "../include/fpdfxfa/fpdfxfa_util.h"
#include "../include/fsdk_mgr.h"
#include "../include/fsdk_baseannot.h"
#include "../include/fsdk_baseform.h"
@@ -23,10 +25,12 @@
#define IsFloatEqual(fa,fb) IsFloatZero((fa)-(fb))
CPDFSDK_Widget::CPDFSDK_Widget(CPDF_Annot* pAnnot, CPDFSDK_PageView* pPageView, CPDFSDK_InterForm* pInterForm) :
- CPDFSDK_Annot(pAnnot, pPageView),
+ CPDFSDK_BAAnnot(pAnnot, pPageView),
m_pInterForm(pInterForm),
m_nAppAge(0),
- m_nValueAge(0)
+ m_nValueAge(0),
+ m_hMixXFAWidget(NULL),
+ m_pWidgetHandler(NULL)
{
ASSERT(m_pInterForm != NULL);
}
@@ -36,6 +40,527 @@ CPDFSDK_Widget::~CPDFSDK_Widget()
}
+XFA_HWIDGET CPDFSDK_Widget::GetMixXFAWidget()
+{
+ ASSERT(m_pPageView != NULL);
+
+ CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument();
+ ASSERT(pSDKDoc != NULL);
+
+ CPDFXFA_Document* pDoc = pSDKDoc->GetDocument();
+ ASSERT(pDoc != NULL);
+
+ if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA)
+ {
+ if (!m_hMixXFAWidget)
+ {
+ if (IXFA_DocView* pDocView = pDoc->GetXFADocView())
+ {
+ CFX_WideString sName;
+ if (this->GetFieldType() == FIELDTYPE_RADIOBUTTON)
+ {
+ sName = this->GetAnnotName();
+ if (sName.IsEmpty())
+ sName = GetName();
+ }
+ else
+ sName = GetName();
+
+ if (!sName.IsEmpty())
+ m_hMixXFAWidget = pDocView->GetWidgetByName(sName);
+ }
+ }
+ return m_hMixXFAWidget;
+ }
+
+ return NULL;
+}
+
+XFA_HWIDGET CPDFSDK_Widget::GetGroupMixXFAWidget()
+{
+ ASSERT(m_pPageView != NULL);
+
+ CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument();
+ ASSERT(pSDKDoc != NULL);
+
+ CPDFXFA_Document* pDoc = pSDKDoc->GetDocument();
+ ASSERT(pDoc != NULL);
+
+ if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA)
+ {
+ if (IXFA_DocView* pDocView = pDoc->GetXFADocView())
+ {
+ CFX_WideString sName = GetName();
+
+ if (!sName.IsEmpty())
+ return pDocView->GetWidgetByName(sName);
+ }
+ }
+
+ return NULL;
+}
+
+IXFA_WidgetHandler* CPDFSDK_Widget::GetXFAWidgetHandler()
+{
+ ASSERT(m_pPageView != NULL);
+
+ CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument();
+ ASSERT(pSDKDoc != NULL);
+
+ CPDFXFA_Document* pDoc = pSDKDoc->GetDocument();
+ ASSERT(pDoc != NULL);
+
+ if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA)
+ {
+ if (!m_pWidgetHandler)
+ {
+ if (IXFA_DocView* pDocView = pDoc->GetXFADocView())
+ {
+ m_pWidgetHandler = pDocView->GetWidgetHandler();
+ }
+ }
+ return m_pWidgetHandler;
+ }
+
+ return NULL;
+}
+
+static XFA_EVENTTYPE GetXFAEventType(PDFSDK_XFAAActionType eXFAAAT)
+{
+ XFA_EVENTTYPE eEventType = XFA_EVENT_Unknown;
+
+ switch (eXFAAAT)
+ {
+ case PDFSDK_XFA_Click:
+ eEventType = XFA_EVENT_Click;
+ break;
+ case PDFSDK_XFA_Full:
+ eEventType = XFA_EVENT_Full;
+ break;
+ case PDFSDK_XFA_PreOpen:
+ eEventType = XFA_EVENT_PreOpen;
+ break;
+ case PDFSDK_XFA_PostOpen:
+ eEventType = XFA_EVENT_PostOpen;
+ break;
+ }
+
+ return eEventType;
+}
+
+static XFA_EVENTTYPE GetXFAEventType(CPDF_AAction::AActionType eAAT, FX_BOOL bWillCommit)
+{
+ XFA_EVENTTYPE eEventType = XFA_EVENT_Unknown;
+
+ switch (eAAT)
+ {
+ case CPDF_AAction::CursorEnter:
+ eEventType = XFA_EVENT_MouseEnter;
+ break;
+ case CPDF_AAction::CursorExit:
+ eEventType = XFA_EVENT_MouseExit;
+ break;
+ case CPDF_AAction::ButtonDown:
+ eEventType = XFA_EVENT_MouseDown;
+ break;
+ case CPDF_AAction::ButtonUp:
+ eEventType = XFA_EVENT_MouseUp;
+ break;
+ case CPDF_AAction::GetFocus:
+ eEventType = XFA_EVENT_Enter;
+ break;
+ case CPDF_AAction::LoseFocus:
+ eEventType = XFA_EVENT_Exit;
+ break;
+ case CPDF_AAction::PageOpen:
+ break;
+ case CPDF_AAction::PageClose:
+ break;
+ case CPDF_AAction::PageVisible:
+ break;
+ case CPDF_AAction::PageInvisible:
+ break;
+ case CPDF_AAction::KeyStroke:
+ if (!bWillCommit)
+ {
+ eEventType = XFA_EVENT_Change;
+ }
+ break;
+ case CPDF_AAction::Validate:
+ eEventType = XFA_EVENT_Validate;
+ break;
+ case CPDF_AAction::OpenPage:
+ case CPDF_AAction::ClosePage:
+ case CPDF_AAction::Format:
+ case CPDF_AAction::Calculate:
+ case CPDF_AAction::CloseDocument:
+ case CPDF_AAction::SaveDocument:
+ case CPDF_AAction::DocumentSaved:
+ case CPDF_AAction::PrintDocument:
+ case CPDF_AAction::DocumentPrinted:
+ break;
+ }
+
+ return eEventType;
+}
+
+FX_BOOL CPDFSDK_Widget::HasXFAAAction(PDFSDK_XFAAActionType eXFAAAT)
+{
+ if (XFA_HWIDGET hWidget = this->GetMixXFAWidget())
+ {
+ if (IXFA_WidgetHandler* pXFAWidgetHandler = this->GetXFAWidgetHandler())
+ {
+ XFA_EVENTTYPE eEventType = GetXFAEventType(eXFAAAT);
+
+ if ((eEventType == XFA_EVENT_Click ||
+ eEventType == XFA_EVENT_Change) &&
+ GetFieldType() == FIELDTYPE_RADIOBUTTON)
+ {
+ if (XFA_HWIDGET hGroupWidget = GetGroupMixXFAWidget())
+ {
+ CXFA_WidgetAcc* pAcc = pXFAWidgetHandler->GetDataAcc(hGroupWidget);
+ if (pXFAWidgetHandler->HasEvent(pAcc, eEventType))
+ return TRUE;
+ }
+ }
+
+ {
+ CXFA_WidgetAcc* pAcc = pXFAWidgetHandler->GetDataAcc(hWidget);
+ return pXFAWidgetHandler->HasEvent(pAcc, eEventType);
+ }
+ }
+ }
+
+ return FALSE;
+}
+
+FX_BOOL CPDFSDK_Widget::OnXFAAAction(PDFSDK_XFAAActionType eXFAAAT, PDFSDK_FieldAction& data, CPDFSDK_PageView* pPageView)
+{
+ ASSERT(m_pPageView != NULL);
+
+ CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument();
+ ASSERT(pSDKDoc != NULL);
+
+ CPDFXFA_Document* pDoc = pSDKDoc->GetDocument();
+ ASSERT(pDoc != NULL);
+
+ if (XFA_HWIDGET hWidget = this->GetMixXFAWidget())
+ {
+ XFA_EVENTTYPE eEventType = GetXFAEventType(eXFAAAT);
+
+ if (eEventType != XFA_EVENT_Unknown)
+ {
+ if (IXFA_WidgetHandler* pXFAWidgetHandler = this->GetXFAWidgetHandler())
+ {
+ CXFA_EventParam param;
+ param.m_eType = eEventType;
+ param.m_wsChange = data.sChange;
+ param.m_iCommitKey = data.nCommitKey;
+ param.m_bShift = data.bShift;
+ param.m_iSelStart = data.nSelStart;
+ param.m_iSelEnd = data.nSelEnd;
+ param.m_wsFullText = data.sValue;
+ param.m_bKeyDown = data.bKeyDown;
+ param.m_bModifier = data.bModifier;
+ param.m_wsNewText = data.sValue;
+ if (data.nSelEnd > data.nSelStart)
+ param.m_wsNewText.Delete(data.nSelStart, data.nSelEnd - data.nSelStart);
+ for (int i=0; i<data.sChange.GetLength(); i++)
+ param.m_wsNewText.Insert(data.nSelStart, data.sChange[i]);
+ param.m_wsPrevText = data.sValue;
+
+ if ((eEventType == XFA_EVENT_Click ||
+ eEventType == XFA_EVENT_Change) &&
+ GetFieldType() == FIELDTYPE_RADIOBUTTON)
+ {
+ if (XFA_HWIDGET hGroupWidget = GetGroupMixXFAWidget())
+ {
+ CXFA_WidgetAcc* pAcc = pXFAWidgetHandler->GetDataAcc(hGroupWidget);
+ param.m_pTarget = pAcc;
+ pXFAWidgetHandler->ProcessEvent(pAcc, &param);
+ }
+
+ {
+ CXFA_WidgetAcc* pAcc = pXFAWidgetHandler->GetDataAcc(hWidget);
+ param.m_pTarget = pAcc;
+ FX_INT32 nRet = pXFAWidgetHandler->ProcessEvent(pAcc, &param);
+ return nRet == XFA_EVENTERROR_Sucess;
+ }
+ }
+ else
+ {
+ CXFA_WidgetAcc* pAcc = pXFAWidgetHandler->GetDataAcc(hWidget);
+ param.m_pTarget = pAcc;
+ FX_INT32 nRet = pXFAWidgetHandler->ProcessEvent(pAcc, &param);
+ return nRet == XFA_EVENTERROR_Sucess;
+ }
+
+ if (IXFA_DocView* pDocView = pDoc->GetXFADocView())
+ {
+ pDocView->UpdateDocView();
+ }
+ }
+ }
+ }
+
+ return FALSE;
+}
+
+void CPDFSDK_Widget::Synchronize(FX_BOOL bSynchronizeElse)
+{
+ if (XFA_HWIDGET hWidget = this->GetMixXFAWidget())
+ {
+ if (IXFA_WidgetHandler* pXFAWidgetHandler = this->GetXFAWidgetHandler())
+ {
+ CPDF_FormField* pFormField = GetFormField();
+ ASSERT(pFormField != NULL);
+
+ if (CXFA_WidgetAcc* pWidgetAcc = pXFAWidgetHandler->GetDataAcc(hWidget))
+ {
+ switch (GetFieldType())
+ {
+ case FIELDTYPE_CHECKBOX:
+ case FIELDTYPE_RADIOBUTTON:
+ {
+ CPDF_FormControl* pFormCtrl = GetFormControl();
+ ASSERT(pFormCtrl != NULL);
+
+ XFA_CHECKSTATE eCheckState = pFormCtrl->IsChecked() ? XFA_CHECKSTATE_On : XFA_CHECKSTATE_Off;
+ pWidgetAcc->SetCheckState(eCheckState);
+ }
+ break;
+ case FIELDTYPE_TEXTFIELD:
+ pWidgetAcc->SetValue(pFormField->GetValue(), XFA_VALUEPICTURE_Edit);
+ break;
+ case FIELDTYPE_LISTBOX:
+ {
+ pWidgetAcc->ClearAllSelections();
+
+ for (int i=0,sz=pFormField->CountSelectedItems(); i<sz; i++)
+ {
+ int nIndex = pFormField->GetSelectedIndex(i);
+ if (nIndex > -1 && nIndex < pWidgetAcc->CountChoiceListItems())
+ pWidgetAcc->SetItemState(nIndex, TRUE, FALSE);
+ }
+ }
+ break;
+ case FIELDTYPE_COMBOBOX:
+ {
+ pWidgetAcc->ClearAllSelections();
+
+ for (int i=0,sz=pFormField->CountSelectedItems(); i<sz; i++)
+ {
+ int nIndex = pFormField->GetSelectedIndex(i);
+ if (nIndex > -1 && nIndex < pWidgetAcc->CountChoiceListItems())
+ pWidgetAcc->SetItemState(nIndex, TRUE, FALSE);
+ }
+ }
+
+ pWidgetAcc->SetValue(pFormField->GetValue(), XFA_VALUEPICTURE_Edit);
+ break;
+ }
+
+ if (bSynchronizeElse)
+ pWidgetAcc->ProcessValueChanged();
+ }
+ }
+ }
+}
+
+void CPDFSDK_Widget::SynchronizeXFAValue()
+{
+ ASSERT(m_pPageView != NULL);
+
+ CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument();
+ ASSERT(pSDKDoc != NULL);
+
+ CPDFXFA_Document* pDoc = pSDKDoc->GetDocument();
+ ASSERT(pDoc != NULL);
+
+ IXFA_DocView* pXFADocView = pDoc->GetXFADocView();
+ if (!pXFADocView) return;
+
+ if (XFA_HWIDGET hWidget = this->GetMixXFAWidget())
+ {
+ if (IXFA_WidgetHandler* pXFAWidgetHandler = this->GetXFAWidgetHandler())
+ {
+ CPDF_FormField* pFormField = GetFormField();
+ ASSERT(pFormField != NULL);
+
+ CPDF_FormControl* pFormCtrl = GetFormControl();
+ ASSERT(pFormCtrl != NULL);
+
+ CPDFSDK_Widget::SynchronizeXFAValue(pXFADocView, hWidget, pFormField, pFormCtrl);
+ }
+ }
+}
+
+void CPDFSDK_Widget::SynchronizeXFAItems()
+{
+ ASSERT(m_pPageView != NULL);
+
+ CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument();
+ ASSERT(pSDKDoc != NULL);
+
+ CPDFXFA_Document* pDoc = pSDKDoc->GetDocument();
+ ASSERT(pDoc != NULL);
+
+ IXFA_DocView* pXFADocView = pDoc->GetXFADocView();
+ if (!pXFADocView) return;
+
+ if (XFA_HWIDGET hWidget = this->GetMixXFAWidget())
+ {
+ if (IXFA_WidgetHandler* pXFAWidgetHandler = this->GetXFAWidgetHandler())
+ {
+ CPDF_FormField* pFormField = GetFormField();
+ ASSERT(pFormField != NULL);
+
+ SynchronizeXFAItems(pXFADocView, hWidget, pFormField, NULL);
+ }
+ }
+}
+
+void CPDFSDK_Widget::SynchronizeXFAValue(IXFA_DocView* pXFADocView, XFA_HWIDGET hWidget,
+ CPDF_FormField* pFormField, CPDF_FormControl* pFormControl)
+{
+ ASSERT(pXFADocView != NULL);
+ ASSERT(hWidget != NULL);
+
+ if (IXFA_WidgetHandler* pXFAWidgetHandler = pXFADocView->GetWidgetHandler())
+ {
+ ASSERT(pFormField != NULL);
+ ASSERT(pFormControl != NULL);
+
+ switch (pFormField->GetFieldType())
+ {
+ case FIELDTYPE_CHECKBOX:
+ {
+ if (CXFA_WidgetAcc* pWidgetAcc = pXFAWidgetHandler->GetDataAcc(hWidget))
+ {
+ FX_BOOL bChecked = pWidgetAcc->GetCheckState() == XFA_CHECKSTATE_On;
+
+ pFormField->CheckControl(pFormField->GetControlIndex(pFormControl),
+ bChecked, TRUE);
+ }
+ }
+ break;
+ case FIELDTYPE_RADIOBUTTON:
+ {
+ if (CXFA_WidgetAcc* pWidgetAcc = pXFAWidgetHandler->GetDataAcc(hWidget))
+ {
+ FX_BOOL bChecked = pWidgetAcc->GetCheckState() == XFA_CHECKSTATE_On;
+
+ pFormField->CheckControl(pFormField->GetControlIndex(pFormControl),
+ bChecked, TRUE);
+ }
+ }
+ break;
+ case FIELDTYPE_TEXTFIELD:
+ {
+ if (CXFA_WidgetAcc* pWidgetAcc = pXFAWidgetHandler->GetDataAcc(hWidget))
+ {
+ CFX_WideString sValue;
+ pWidgetAcc->GetValue(sValue, XFA_VALUEPICTURE_Display);
+ pFormField->SetValue(sValue, TRUE);
+ }
+ }
+ break;
+ case FIELDTYPE_LISTBOX:
+ {
+ pFormField->ClearSelection(FALSE);
+
+ if (CXFA_WidgetAcc* pWidgetAcc = pXFAWidgetHandler->GetDataAcc(hWidget))
+ {
+ for (int i=0,sz=pWidgetAcc->CountSelectedItems(); i<sz; i++)
+ {
+ int nIndex = pWidgetAcc->GetSelectedItem(i);
+
+ if (nIndex > -1 && nIndex < pFormField->CountOptions())
+ {
+ pFormField->SetItemSelection(nIndex, TRUE, TRUE);
+ }
+ }
+ }
+ }
+ break;
+ case FIELDTYPE_COMBOBOX:
+ {
+ pFormField->ClearSelection(FALSE);
+
+ if (CXFA_WidgetAcc* pWidgetAcc = pXFAWidgetHandler->GetDataAcc(hWidget))
+ {
+ for (int i=0,sz=pWidgetAcc->CountSelectedItems(); i<sz; i++)
+ {
+ int nIndex = pWidgetAcc->GetSelectedItem(i);
+
+ if (nIndex > -1 && nIndex < pFormField->CountOptions())
+ {
+ pFormField->SetItemSelection(nIndex, TRUE, TRUE);
+ }
+ }
+
+ CFX_WideString sValue;
+ pWidgetAcc->GetValue(sValue, XFA_VALUEPICTURE_Display);
+ pFormField->SetValue(sValue, TRUE);
+ }
+ }
+ break;
+ }
+ }
+}
+
+void CPDFSDK_Widget::SynchronizeXFAItems(IXFA_DocView* pXFADocView, XFA_HWIDGET hWidget,
+ CPDF_FormField* pFormField, CPDF_FormControl* pFormControl)
+{
+ ASSERT(pXFADocView != NULL);
+ ASSERT(hWidget != NULL);
+
+ if (IXFA_WidgetHandler* pXFAWidgetHandler = pXFADocView->GetWidgetHandler())
+ {
+ ASSERT(pFormField != NULL);
+
+ switch (pFormField->GetFieldType())
+ {
+ case FIELDTYPE_LISTBOX:
+ {
+ pFormField->ClearSelection(FALSE);
+ pFormField->ClearOptions(TRUE);
+
+ if (CXFA_WidgetAcc* pWidgetAcc = pXFAWidgetHandler->GetDataAcc(hWidget))
+ {
+ for (int i=0,sz=pWidgetAcc->CountChoiceListItems(); i<sz; i++)
+ {
+ CFX_WideString swText;
+ pWidgetAcc->GetChoiceListItem(swText, i);
+
+ pFormField->InsertOption(swText, i, TRUE);
+ }
+ }
+ }
+ break;
+ case FIELDTYPE_COMBOBOX:
+ {
+ pFormField->ClearSelection(FALSE);
+ pFormField->ClearOptions(FALSE);
+
+ if (CXFA_WidgetAcc* pWidgetAcc = pXFAWidgetHandler->GetDataAcc(hWidget))
+ {
+ for (int i=0,sz=pWidgetAcc->CountChoiceListItems(); i<sz; i++)
+ {
+ CFX_WideString swText;
+ pWidgetAcc->GetChoiceListItem(swText, i);
+
+ pFormField->InsertOption(swText, i, FALSE);
+ }
+ }
+
+ pFormField->SetValue(L"", TRUE);
+ }
+ break;
+ }
+ }
+}
+
FX_BOOL CPDFSDK_Widget::IsWidgetAppearanceValid(CPDF_Annot::AppearanceMode mode)
{
ASSERT(m_pAnnot != NULL);
@@ -90,6 +615,23 @@ int CPDFSDK_Widget::GetFieldType() const
return pField->GetFieldType();
}
+FX_BOOL CPDFSDK_Widget::IsAppearanceValid()
+{
+ ASSERT(m_pPageView != NULL);
+
+ CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument();
+ ASSERT(pSDKDoc != NULL);
+
+ CPDFXFA_Document* pDoc = pSDKDoc->GetDocument();
+ ASSERT(pDoc != NULL);
+
+ int nDocType = pDoc->GetDocType();
+ if (nDocType == DOCTYPE_PDF || nDocType == DOCTYPE_STATIC_XFA)
+ return CPDFSDK_BAAnnot::IsAppearanceValid();
+
+ return TRUE;
+}
+
int CPDFSDK_Widget::GetFieldFlags() const
{
CPDF_InterForm* pPDFInterForm = m_pInterForm->GetInterForm();
@@ -160,6 +702,16 @@ int CPDFSDK_Widget::GetRotate() const
return pCtrl->GetRotation() % 360;
}
+CFX_WideString CPDFSDK_Widget::GetName()
+{
+ ASSERT(m_pInterForm != NULL);
+
+ CPDF_FormField* pFormField = GetFormField();
+ ASSERT(pFormField != NULL);
+
+ return pFormField->GetFullName();
+}
+
FX_BOOL CPDFSDK_Widget::GetFillColor(FX_COLORREF& color) const
{
CPDF_FormControl* pFormCtrl = GetFormControl();
@@ -214,16 +766,41 @@ FX_FLOAT CPDFSDK_Widget::GetFontSize() const
return fFontSize;
}
-int CPDFSDK_Widget::GetSelectedIndex(int nIndex) const
+int CPDFSDK_Widget::GetSelectedIndex(int nIndex)
{
+ if (XFA_HWIDGET hWidget = this->GetMixXFAWidget())
+ {
+ if (IXFA_WidgetHandler* pXFAWidgetHandler = this->GetXFAWidgetHandler())
+ {
+ if (CXFA_WidgetAcc* pWidgetAcc = pXFAWidgetHandler->GetDataAcc(hWidget))
+ {
+ if (nIndex < pWidgetAcc->CountSelectedItems())
+ return pWidgetAcc->GetSelectedItem(nIndex);
+ }
+ }
+ }
+
CPDF_FormField* pFormField = GetFormField();
ASSERT(pFormField != NULL);
return pFormField->GetSelectedIndex(nIndex);
}
-CFX_WideString CPDFSDK_Widget::GetValue() const
+CFX_WideString CPDFSDK_Widget::GetValue(FX_BOOL bDisplay)
{
+ if (XFA_HWIDGET hWidget = this->GetMixXFAWidget())
+ {
+ if (IXFA_WidgetHandler* pXFAWidgetHandler = this->GetXFAWidgetHandler())
+ {
+ if (CXFA_WidgetAcc* pWidgetAcc = pXFAWidgetHandler->GetDataAcc(hWidget))
+ {
+ CFX_WideString sValue;
+ pWidgetAcc->GetValue(sValue, bDisplay ? XFA_VALUEPICTURE_Display : XFA_VALUEPICTURE_Edit);
+ return sValue;
+ }
+ }
+ }
+
CPDF_FormField* pFormField = GetFormField();
ASSERT(pFormField != NULL);
@@ -254,8 +831,22 @@ int CPDFSDK_Widget::CountOptions() const
return pFormField->CountOptions();
}
-FX_BOOL CPDFSDK_Widget::IsOptionSelected(int nIndex) const
+FX_BOOL CPDFSDK_Widget::IsOptionSelected(int nIndex)
{
+ if (XFA_HWIDGET hWidget = this->GetMixXFAWidget())
+ {
+ if (IXFA_WidgetHandler* pXFAWidgetHandler = this->GetXFAWidgetHandler())
+ {
+ if (CXFA_WidgetAcc* pWidgetAcc = pXFAWidgetHandler->GetDataAcc(hWidget))
+ {
+ if (nIndex > -1 && nIndex < pWidgetAcc->CountChoiceListItems())
+ return pWidgetAcc->GetItemState(nIndex);
+ else
+ return FALSE;
+ }
+ }
+ }
+
CPDF_FormField* pFormField = GetFormField();
ASSERT(pFormField != NULL);
@@ -270,8 +861,20 @@ int CPDFSDK_Widget::GetTopVisibleIndex() const
return pFormField->GetTopVisibleIndex();
}
-FX_BOOL CPDFSDK_Widget::IsChecked() const
+FX_BOOL CPDFSDK_Widget::IsChecked()
{
+ if (IXFA_WidgetHandler* pXFAWidgetHandler = this->GetXFAWidgetHandler())
+ {
+ if (XFA_HWIDGET hWidget = this->GetMixXFAWidget())
+ {
+ if (CXFA_WidgetAcc* pWidgetAcc = pXFAWidgetHandler->GetDataAcc(hWidget))
+ {
+ FX_BOOL bChecked = pWidgetAcc->GetCheckState() == XFA_CHECKSTATE_On;
+ return bChecked;
+ }
+ }
+ }
+
CPDF_FormControl* pFormCtrl = GetFormControl();
ASSERT(pFormCtrl != NULL);
@@ -303,6 +906,10 @@ void CPDFSDK_Widget::SetCheck(FX_BOOL bChecked, FX_BOOL bNotify)
ASSERT(pFormField != NULL);
pFormField->CheckControl(pFormField->GetControlIndex(pFormCtrl), bChecked, bNotify);
+ if (!IsWidgetAppearanceValid(CPDF_Annot::Normal))
+ ResetAppearance(TRUE);
+ if (!bNotify)
+ Synchronize(TRUE);
}
void CPDFSDK_Widget::SetValue(const CFX_WideString& sValue, FX_BOOL bNotify)
@@ -311,6 +918,9 @@ void CPDFSDK_Widget::SetValue(const CFX_WideString& sValue, FX_BOOL bNotify)
ASSERT(pFormField != NULL);
pFormField->SetValue(sValue, bNotify);
+
+ if (!bNotify)
+ Synchronize(TRUE);
}
void CPDFSDK_Widget::SetDefaultValue(const CFX_WideString& sValue)
@@ -322,6 +932,9 @@ void CPDFSDK_Widget::SetOptionSelection(int index, FX_BOOL bSelected, FX_BOOL bN
ASSERT(pFormField != NULL);
pFormField->SetItemSelection(index, bSelected, bNotify);
+
+ if (!bNotify)
+ Synchronize(TRUE);
}
void CPDFSDK_Widget::ClearSelection(FX_BOOL bNotify)
@@ -330,6 +943,9 @@ void CPDFSDK_Widget::ClearSelection(FX_BOOL bNotify)
ASSERT(pFormField != NULL);
pFormField->ClearSelection(bNotify);
+
+ if (!bNotify)
+ Synchronize(TRUE);
}
void CPDFSDK_Widget::SetTopVisibleIndex(int index)
@@ -351,6 +967,27 @@ FX_BOOL CPDFSDK_Widget::IsAppModified() const
return m_bAppModified;
}
+void CPDFSDK_Widget::ResetAppearance(FX_BOOL bValueChanged)
+{
+ switch (GetFieldType())
+ {
+ case FIELDTYPE_TEXTFIELD:
+ case FIELDTYPE_COMBOBOX:
+ {
+ FX_BOOL bFormated = FALSE;
+ CFX_WideString sValue = this->OnFormat(0, bFormated);
+ if (bFormated)
+ this->ResetAppearance(sValue, TRUE);
+ else
+ this->ResetAppearance(NULL, TRUE);
+ }
+ break;
+ default:
+ this->ResetAppearance(NULL, FALSE);
+ break;
+ }
+}
+
void CPDFSDK_Widget::ResetAppearance(FX_LPCWSTR sValue, FX_BOOL bValueChanged)
{
SetAppModified();
@@ -433,7 +1070,7 @@ void CPDFSDK_Widget::DrawAppearance(CFX_RenderDevice* pDevice, const CPDF_Matrix
}
else
{
- CPDFSDK_Annot::DrawAppearance(pDevice, pUser2Device, mode, pOptions);
+ CPDFSDK_BAAnnot::DrawAppearance(pDevice, pUser2Device, mode, pOptions);
}
}
@@ -1251,6 +1888,13 @@ void CPDFSDK_Widget::ResetAppearance_TextField(FX_LPCWSTR sValue)
FX_BOOL bCharArray = (dwFieldFlags >> 24) & 1;
FX_FLOAT fFontSize = GetFontSize();
+ CFX_WideString sValueTmp;
+ if (!sValue && (NULL != this->GetMixXFAWidget()))
+ {
+ sValueTmp = GetValue(TRUE);
+ sValue = sValueTmp;
+ }
+
if (nMaxLen > 0)
{
if (bCharArray)
@@ -1589,16 +2233,59 @@ void CPDFSDK_Widget::RemoveAppearance(const CFX_ByteString& sAPType)
FX_BOOL CPDFSDK_Widget::OnAAction(CPDF_AAction::AActionType type, PDFSDK_FieldAction& data, CPDFSDK_PageView* pPageView)
{
- CPDF_Action action = GetAAction(type);
+ CPDFSDK_Document* pDocument = pPageView->GetSDKDocument();
+ ASSERT(pDocument != NULL);
- if (action && action.GetType() != CPDF_Action::Unknown)
+ CPDFXFA_Document* pDoc = pDocument->GetDocument();
+ ASSERT(pDoc != NULL);
+
+ CPDFDoc_Environment* pEnv = pDocument->GetEnv();
+ ASSERT(pEnv != NULL);
+
+ if (XFA_HWIDGET hWidget = this->GetMixXFAWidget())
{
- CPDFSDK_Document* pDocument = pPageView->GetSDKDocument();
- ASSERT(pDocument != NULL);
+ XFA_EVENTTYPE eEventType = GetXFAEventType(type, data.bWillCommit);
- CPDFDoc_Environment* pEnv = pDocument->GetEnv();
- ASSERT(pEnv != NULL);
+ if (eEventType != XFA_EVENT_Unknown)
+ {
+ if (IXFA_WidgetHandler* pXFAWidgetHandler = this->GetXFAWidgetHandler())
+ {
+ CXFA_EventParam param;
+ param.m_eType = eEventType;
+ param.m_wsChange = data.sChange;
+ param.m_iCommitKey = data.nCommitKey;
+ param.m_bShift = data.bShift;
+ param.m_iSelStart = data.nSelStart;
+ param.m_iSelEnd = data.nSelEnd;
+ param.m_wsFullText = data.sValue;
+ param.m_bKeyDown = data.bKeyDown;
+ param.m_bModifier = data.bModifier;
+ param.m_wsNewText = data.sValue;
+ if (data.nSelEnd > data.nSelStart)
+ param.m_wsNewText.Delete(data.nSelStart, data.nSelEnd - data.nSelStart);
+ for (int i=data.sChange.GetLength() - 1; i>=0; i--)
+ param.m_wsNewText.Insert(data.nSelStart, data.sChange[i]);
+ param.m_wsPrevText = data.sValue;
+
+ CXFA_WidgetAcc* pAcc = pXFAWidgetHandler->GetDataAcc(hWidget);
+ param.m_pTarget = pAcc;
+ FX_INT32 nRet = pXFAWidgetHandler->ProcessEvent(pAcc, &param);
+
+ if (IXFA_DocView* pDocView = pDoc->GetXFADocView())
+ {
+ pDocView->UpdateDocView();
+ }
+ if (nRet == XFA_EVENTERROR_Sucess)
+ return TRUE;
+ }
+ }
+ }
+
+ CPDF_Action action = GetAAction(type);
+
+ if (action && action.GetType() != CPDF_Action::Unknown)
+ {
CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander();/*(CPDFSDK_ActionHandler*)pApp->GetActionHandler();*/
ASSERT(pActionHandler != NULL);
@@ -1622,7 +2309,7 @@ CPDF_Action CPDFSDK_Widget::GetAAction(CPDF_AAction::AActionType eAAT)
case CPDF_AAction::PageClose:
case CPDF_AAction::PageVisible:
case CPDF_AAction::PageInvisible:
- return CPDFSDK_Annot::GetAAction(eAAT);
+ return CPDFSDK_BAAnnot::GetAAction(eAAT);
case CPDF_AAction::KeyStroke:
case CPDF_AAction::Format:
case CPDF_AAction::Validate:
@@ -1634,7 +2321,7 @@ CPDF_Action CPDFSDK_Widget::GetAAction(CPDF_AAction::AActionType eAAT)
if (CPDF_AAction aa = pField->GetAdditionalAction())
return aa.GetAction(eAAT);
else
- return CPDFSDK_Annot::GetAAction(eAAT);
+ return CPDFSDK_BAAnnot::GetAAction(eAAT);
}
default:
return NULL;
@@ -1681,14 +2368,59 @@ FX_BOOL CPDFSDK_Widget::HitTest(FX_FLOAT pageX, FX_FLOAT pageY)
return FALSE;
}
+//CPDFSDK_XFAWidget
+CPDFSDK_XFAWidget::CPDFSDK_XFAWidget(XFA_HWIDGET pAnnot, CPDFSDK_PageView* pPageView, CPDFSDK_InterForm* pInterForm) :
+ CPDFSDK_Annot(pPageView),
+ m_hXFAWidget(pAnnot),
+ m_pInterForm(pInterForm)
+{
+
+}
+
+FX_BOOL CPDFSDK_XFAWidget::IsXFAField()
+{
+ return TRUE;
+}
+
+CFX_ByteString CPDFSDK_XFAWidget::GetType() const
+{
+ return FSDK_XFAWIDGET_TYPENAME;
+}
+
+CFX_FloatRect CPDFSDK_XFAWidget::GetRect()
+{
+ CPDFSDK_PageView* pPageView = GetPageView();
+ ASSERT(pPageView != NULL);
+
+ CPDFSDK_Document* pDocument = pPageView->GetSDKDocument();
+ ASSERT(pDocument != NULL);
+
+ CPDFXFA_Document* pDoc = pDocument->GetDocument();
+ ASSERT(pDoc != NULL);
+
+ IXFA_DocView* pDocView = pDoc->GetXFADocView();
+ ASSERT(pDocView != NULL);
+
+ IXFA_WidgetHandler* pWidgetHandler = pDocView->GetWidgetHandler();
+ ASSERT(pWidgetHandler != NULL);
+
+ CFX_RectF rcBBox;
+ pWidgetHandler->GetRect(GetXFAWidget(), rcBBox);
+
+ return CFX_FloatRect(rcBBox.left, rcBBox.top, rcBBox.left + rcBBox.width, rcBBox.top+rcBBox.height);
+}
+
+//CPDFSDK_InterForm
CPDFSDK_InterForm::CPDFSDK_InterForm(CPDFSDK_Document* pDocument)
:m_pDocument(pDocument),
m_pInterForm(NULL),
m_bCalculate(TRUE),
+ m_bXfaCalculate(TRUE),
+ m_bXfaValidationsEnabled(TRUE),
m_bBusy(FALSE)
{
ASSERT(m_pDocument != NULL);
- m_pInterForm = new CPDF_InterForm(m_pDocument->GetDocument(), FALSE);
+ m_pInterForm = new CPDF_InterForm(m_pDocument->GetDocument()->GetPDFDoc(), FALSE);
ASSERT(m_pInterForm != NULL);
m_pInterForm->SetFormNotify(this);
@@ -1704,6 +2436,7 @@ CPDFSDK_InterForm::~CPDFSDK_InterForm()
m_pInterForm = NULL;
m_Map.RemoveAll();
+ m_XFAMap.RemoveAll();
}
void CPDFSDK_InterForm::Destroy()
@@ -1730,7 +2463,7 @@ CPDFSDK_Widget* CPDFSDK_InterForm::GetSibling(CPDFSDK_Widget* pWidget, FX_BOOL b
{
ASSERT(pWidget != NULL);
- CBA_AnnotIterator* pIterator = new CBA_AnnotIterator(pWidget->GetPageView(), "Widget", "");
+ CBA_AnnotIterator* pIterator = new CBA_AnnotIterator(pWidget->GetPageView(), "Widget", "");//XfA?
ASSERT(pIterator != NULL);
CPDFSDK_Widget* pRet = NULL;
@@ -1759,7 +2492,7 @@ CPDFSDK_Widget* CPDFSDK_InterForm::GetWidget(CPDF_FormControl* pControl) const
ASSERT(pControlDict != NULL);
ASSERT(m_pDocument != NULL);
- CPDF_Document* pDocument = m_pDocument->GetDocument();
+ CPDF_Document* pDocument = m_pDocument->GetDocument()->GetPDFDoc();
CPDFSDK_PageView* pPage = NULL;
@@ -1852,6 +2585,24 @@ void CPDFSDK_InterForm::RemoveMap(CPDF_FormControl* pControl)
m_Map.RemoveKey(pControl);
}
+void CPDFSDK_InterForm::AddXFAMap(XFA_HWIDGET hWidget, CPDFSDK_XFAWidget* pWidget)
+{
+ m_XFAMap.SetAt(hWidget, pWidget);
+}
+
+void CPDFSDK_InterForm::RemoveXFAMap(XFA_HWIDGET hWidget)
+{
+ m_XFAMap.RemoveKey(hWidget);
+}
+
+CPDFSDK_XFAWidget* CPDFSDK_InterForm::GetXFAWidget(XFA_HWIDGET hWidget)
+{
+ CPDFSDK_XFAWidget* pWidget = NULL;
+ m_XFAMap.Lookup(hWidget, pWidget);
+
+ return pWidget;
+}
+
void CPDFSDK_InterForm::EnableCalculate(FX_BOOL bEnabled)
{
m_bCalculate = bEnabled;
@@ -1862,11 +2613,29 @@ FX_BOOL CPDFSDK_InterForm::IsCalculateEnabled() const
return m_bCalculate;
}
+void CPDFSDK_InterForm::XfaEnableCalculate(FX_BOOL bEnabled)
+{
+ m_bXfaCalculate = bEnabled;
+}
+FX_BOOL CPDFSDK_InterForm::IsXfaCalculateEnabled() const
+{
+ return m_bXfaCalculate;
+}
+
+FX_BOOL CPDFSDK_InterForm::IsXfaValidationsEnabled()
+{
+ return m_bXfaValidationsEnabled;
+}
+void CPDFSDK_InterForm::XfaSetValidationsEnabled(FX_BOOL bEnabled)
+{
+ m_bXfaValidationsEnabled = bEnabled;
+}
+
#ifdef _WIN32
CPDF_Stream* CPDFSDK_InterForm::LoadImageFromFile(const CFX_WideString& sFile)
{
ASSERT(m_pDocument != NULL);
- CPDF_Document* pDocument = m_pDocument->GetDocument();
+ CPDF_Document* pDocument = m_pDocument->GetDocument()->GetPDFDoc();
ASSERT(pDocument != NULL);
CPDF_Stream* pRetStream = NULL;
@@ -2089,7 +2858,7 @@ void CPDFSDK_InterForm::UpdateField(CPDF_FormField* pFormField)
CPDFDoc_Environment * pEnv = m_pDocument->GetEnv();
CFFL_IFormFiller* pIFormFiller = pEnv->GetIFormFiller();
- CPDF_Page * pPage = pWidget->GetPDFPage();
+ CPDFXFA_Page * pPage = pWidget->GetPDFXFAPage();
CPDFSDK_PageView * pPageView = m_pDocument->GetPageView(pPage,FALSE);
FX_RECT rcBBox = pIFormFiller->GetViewBBox(pPageView, pWidget);
@@ -2399,6 +3168,27 @@ FX_BOOL CPDFSDK_InterForm::ExportFieldsToFDFTextBuf(const CFX_PtrArray& fields,F
return bRet;
}
+void CPDFSDK_InterForm::SynchronizeField(CPDF_FormField* pFormField, FX_BOOL bSynchronizeElse)
+{
+ ASSERT(pFormField != NULL);
+
+ int x = 0;
+ if (m_FieldSynchronizeMap.Lookup(pFormField, x))
+ return;
+
+ for (int i=0,sz=pFormField->CountControls(); i<sz; i++)
+ {
+ CPDF_FormControl* pFormCtrl = pFormField->GetControl(i);
+ ASSERT(pFormCtrl != NULL);
+
+ ASSERT(m_pInterForm != NULL);
+ if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl))
+ {
+ pWidget->Synchronize(bSynchronizeElse);
+ }
+ }
+}
+
CFX_WideString CPDFSDK_InterForm::GetTemporaryFileName(const CFX_WideString& sFileExt)
{
CFX_WideString sFileName;
@@ -2621,6 +3411,9 @@ int CPDFSDK_InterForm::AfterValueChange(const CPDF_FormField* pField)
ASSERT(pField != NULL);
CPDF_FormField* pFormField = (CPDF_FormField*)pField;
+
+ SynchronizeField(pFormField, FALSE);
+
int nType = pFormField->GetFieldType();
if (nType == FIELDTYPE_COMBOBOX || nType == FIELDTYPE_TEXTFIELD)
@@ -2724,23 +3517,23 @@ int CPDFSDK_InterForm::AfterFormImportData(const CPDF_InterForm* pForm)
FX_BOOL CPDFSDK_InterForm::IsNeedHighLight(int nFieldType)
{
- if(nFieldType <1 || nFieldType > 6)
+ if(nFieldType <1 || nFieldType > 7)
return FALSE;
return m_bNeedHightlight[nFieldType-1];
}
void CPDFSDK_InterForm::RemoveAllHighLight()
{
- memset((void*)m_bNeedHightlight, 0, 6*sizeof(FX_BOOL));
+ memset((void*)m_bNeedHightlight, 0, 7*sizeof(FX_BOOL));
}
void CPDFSDK_InterForm::SetHighlightColor(FX_COLORREF clr, int nFieldType)
{
- if(nFieldType <0 || nFieldType > 6) return;
+ if(nFieldType <0 || nFieldType > 7) return;
switch(nFieldType)
{
case 0:
{
- for(int i=0; i<6; i++)
+ for(int i=0; i<7; i++)
{
m_aHighlightColor[i] = clr;
m_bNeedHightlight[i] = TRUE;
@@ -2759,7 +3552,7 @@ void CPDFSDK_InterForm::SetHighlightColor(FX_COLORREF clr, int nFieldType)
FX_COLORREF CPDFSDK_InterForm::GetHighlightColor(int nFieldType)
{
- if(nFieldType <0 || nFieldType >6) return FXSYS_RGB(255,255,255);
+ if(nFieldType <0 || nFieldType >7) return FXSYS_RGB(255,255,255);
if(nFieldType == 0)
return m_aHighlightColor[0];
else
diff --git a/fpdfsdk/src/fsdk_mgr.cpp b/fpdfsdk/src/fsdk_mgr.cpp
index efb21a7efc..2340ffa720 100644
--- a/fpdfsdk/src/fsdk_mgr.cpp
+++ b/fpdfsdk/src/fsdk_mgr.cpp
@@ -5,10 +5,14 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#include "../include/fsdk_define.h"
+#include "../include/fpdfxfa/fpdfxfa_doc.h"
+#include "../include/fpdfxfa/fpdfxfa_page.h"
+#include "../include/fpdfxfa/fpdfxfa_util.h"
#include "../include/fsdk_mgr.h"
#include "../include/fpdf_ext.h"
#include "../include/formfiller/FFL_FormFiller.h"
#include "../include/javascript/IJavaScript.h"
+#include "../include/fpdfxfa/fpdfxfa_app.h"
#if _FX_OS_ == _FX_ANDROID_
#include "time.h"
@@ -81,10 +85,10 @@ void CFX_SystemHandler::InvalidateRect(FX_HWND hWnd, FX_RECT rect)
{
//g_pFormFillApp->FFI_Invalidate();
CPDFSDK_Annot* pSDKAnnot = (CPDFSDK_Annot*)hWnd;
- CPDF_Page* pPage = NULL;
+ CPDFXFA_Page* pPage = NULL;
CPDFSDK_PageView* pPageView = NULL;
pPageView = pSDKAnnot->GetPageView();
- pPage = pSDKAnnot->GetPDFPage();
+ pPage = pSDKAnnot->GetPDFXFAPage();
if(!pPage || !pPageView)
return;
CPDF_Matrix page2device;
@@ -114,7 +118,7 @@ void CFX_SystemHandler::OutputSelectedRect(void* pFormFiller, CPDF_Rect& rect)
CPDFSDK_Annot* pAnnot = pFFL->GetSDKAnnot();
ASSERT(pAnnot);
- CPDF_Page* pPage = pAnnot->GetPDFPage();
+ CPDFXFA_Page* pPage = pAnnot->GetPDFXFAPage();
ASSERT(pPage);
m_pEnv->FFI_OutputSelectedRect(pPage, ptA.x, ptB.y, ptB.x, ptA.y);
}
@@ -212,29 +216,22 @@ FX_SYSTEMTIME CFX_SystemHandler::GetLocalTime()
}
-CJS_RuntimeFactory* GetJSRuntimeFactory()
-{
- static CJS_RuntimeFactory s_JSRuntimeFactory;
- return &s_JSRuntimeFactory;
-}
-CPDFDoc_Environment::CPDFDoc_Environment(CPDF_Document* pDoc) :
+CPDFDoc_Environment::CPDFDoc_Environment(CPDFXFA_Document* pDoc) :
m_pAnnotHandlerMgr(NULL),
m_pActionHandler(NULL),
m_pJSRuntime(NULL),
m_pInfo(NULL),
m_pSDKDoc(NULL),
- m_pPDFDoc(pDoc),
+ m_pDoc(pDoc),
m_pIFormFiller(NULL)
{
m_pSysHandler = NULL;
m_pSysHandler = new CFX_SystemHandler(this);
+ //m_pJSRuntimeFactory = pDoc->GetApp()->GetRuntimeFactory();
- m_pJSRuntimeFactory = NULL;
- m_pJSRuntimeFactory = GetJSRuntimeFactory();
- m_pJSRuntimeFactory->AddRef();
}
CPDFDoc_Environment::~CPDFDoc_Environment()
@@ -245,9 +242,15 @@ CPDFDoc_Environment::~CPDFDoc_Environment()
delete m_pIFormFiller;
m_pIFormFiller = NULL;
}
- if(m_pJSRuntime && m_pJSRuntimeFactory)
- m_pJSRuntimeFactory->DeleteJSRuntime(m_pJSRuntime);
- m_pJSRuntimeFactory->Release();
+
+ if (m_pJSRuntime && FPDFXFA_GetApp()->GetRuntimeFactory())
+ FPDFXFA_GetApp()->GetRuntimeFactory()->DeleteJSRuntime(m_pJSRuntime);
+
+ if (FPDFXFA_GetApp()->m_pEnvList.GetSize() == 0)
+ {
+ FPDFXFA_GetApp()->ReleaseRuntime();
+ FPDFXFA_GetApp()->InitRuntime(TRUE);
+ }
if(m_pSysHandler)
{
@@ -274,9 +277,8 @@ IFXJS_Runtime* CPDFDoc_Environment::GetJSRuntime()
{
if(!IsJSInitiated())
return NULL;
- assert(m_pJSRuntimeFactory);
if(!m_pJSRuntime)
- m_pJSRuntime = m_pJSRuntimeFactory->NewJSRuntime(this);
+ m_pJSRuntime = FPDFXFA_GetApp()->GetRuntimeFactory()->NewJSRuntime(this);
return m_pJSRuntime;
}
@@ -324,7 +326,7 @@ FX_BOOL CPDFDoc_Environment::IsJSInitiated()
return FALSE;
}
-CPDFSDK_Document::CPDFSDK_Document(CPDF_Document* pDoc,CPDFDoc_Environment* pEnv):m_pDoc(pDoc),
+CPDFSDK_Document::CPDFSDK_Document(CPDFXFA_Document* pDoc,CPDFDoc_Environment* pEnv):m_pDoc(pDoc),
m_pInterForm(NULL),m_pEnv(pEnv),m_pOccontent(NULL),m_bChangeMask(FALSE)
{
m_pFocusAnnot = NULL;
@@ -332,14 +334,7 @@ CPDFSDK_Document::CPDFSDK_Document(CPDF_Document* pDoc,CPDFDoc_Environment* pEnv
CPDFSDK_Document::~CPDFSDK_Document()
{
- FX_POSITION pos = m_pageMap.GetStartPosition();
- while (pos) {
- CPDF_Page* pPage = NULL;
- CPDFSDK_PageView* pPageView = NULL;
- m_pageMap.GetNextAssoc(pos, pPage, pPageView);
- delete pPageView;
- }
- m_pageMap.RemoveAll();
+ m_pageMap.RemoveAll();
if(m_pInterForm)
{
m_pInterForm->Destroy();
@@ -363,20 +358,20 @@ void CPDFSDK_Document::InitPageView()
}
}
-void CPDFSDK_Document::AddPageView(CPDF_Page* pPDFPage, CPDFSDK_PageView* pPageView)
+void CPDFSDK_Document::AddPageView(CPDFXFA_Page* pPDFXFAPage, CPDFSDK_PageView* pPageView)
{
- m_pageMap.SetAt(pPDFPage, pPageView);
+ m_pageMap.SetAt(pPDFXFAPage, pPageView);
}
-CPDFSDK_PageView* CPDFSDK_Document::GetPageView(CPDF_Page* pPDFPage, FX_BOOL ReNew)
+CPDFSDK_PageView* CPDFSDK_Document::GetPageView(CPDFXFA_Page* pPDFXFAPage, FX_BOOL ReNew)
{
- CPDFSDK_PageView* pPageView = (CPDFSDK_PageView*)m_pageMap.GetValueAt(pPDFPage);
+ CPDFSDK_PageView* pPageView = (CPDFSDK_PageView*)m_pageMap.GetValueAt(pPDFXFAPage);
if(pPageView != NULL)
return pPageView;
if(ReNew)
{
- pPageView = new CPDFSDK_PageView(this,pPDFPage);
- m_pageMap.SetAt(pPDFPage, pPageView);
+ pPageView = new CPDFSDK_PageView(this,pPDFXFAPage);
+ m_pageMap.SetAt(pPDFXFAPage, pPageView);
//Delay to load all the annotations, to avoid endless loop.
pPageView->LoadFXAnnots();
}
@@ -386,7 +381,7 @@ CPDFSDK_PageView* CPDFSDK_Document::GetPageView(CPDF_Page* pPDFPage, FX_BOOL ReN
CPDFSDK_PageView* CPDFSDK_Document::GetCurrentView()
{
- CPDF_Page * pPage = (CPDF_Page *)m_pEnv->FFI_GetCurrentPage(m_pDoc);
+ CPDFXFA_Page * pPage = (CPDFXFA_Page *)m_pEnv->FFI_GetCurrentPage(m_pDoc);
if(pPage)
return this->GetPageView(pPage, TRUE);
return NULL;
@@ -395,7 +390,7 @@ CPDFSDK_PageView* CPDFSDK_Document::GetCurrentView()
CPDFSDK_PageView* CPDFSDK_Document::GetPageView(int nIndex)
{
CPDFSDK_PageView * pTempPageView = NULL;
- CPDF_Page * pTempPage = (CPDF_Page*)m_pEnv->FFI_GetPage(m_pDoc,nIndex);
+ CPDFXFA_Page * pTempPage = (CPDFXFA_Page*)m_pEnv->FFI_GetPage(m_pDoc,nIndex);
if(!pTempPage)
return NULL;
@@ -408,8 +403,8 @@ CPDFSDK_PageView* CPDFSDK_Document::GetPageView(int nIndex)
void CPDFSDK_Document:: ProcJavascriptFun()
{
- CPDF_Document* pPDFDoc = this->GetDocument();
- CPDF_DocJSActions docJS(pPDFDoc);
+ CPDFXFA_Document* pPDFDoc = this->GetDocument();
+ CPDF_DocJSActions docJS(pPDFDoc->GetPDFDoc());
int iCount = docJS.CountJSActions();
if (iCount < 1) return;
for (int i = 0; i < iCount; i ++)
@@ -426,7 +421,7 @@ FX_BOOL CPDFSDK_Document::ProcOpenAction()
{
if(!m_pDoc) return FALSE;
- CPDF_Dictionary* pRoot = m_pDoc->GetRoot();
+ CPDF_Dictionary* pRoot = m_pDoc->GetPDFDoc()->GetRoot();
if (!pRoot) return FALSE;
CPDF_Object* pOpenAction = pRoot->GetDict("OpenAction");//
if(!pOpenAction) pOpenAction = pRoot->GetArray("OpenAction");//
@@ -453,23 +448,23 @@ FX_BOOL CPDFSDK_Document::ProcOpenAction()
CPDF_OCContext* CPDFSDK_Document::GetOCContext()
{
if(!m_pOccontent)
- m_pOccontent = new CPDF_OCContext(m_pDoc);
+ m_pOccontent = new CPDF_OCContext(m_pDoc->GetPDFDoc());
return m_pOccontent;
}
-void CPDFSDK_Document::ReMovePageView(CPDF_Page* pPDFPage)
+void CPDFSDK_Document::ReMovePageView(CPDFXFA_Page* pPDFXFAPage)
{
- CPDFSDK_PageView* pPageView = (CPDFSDK_PageView*)m_pageMap.GetValueAt(pPDFPage);
- if(pPageView && !pPageView->IsLocked())
+ CPDFSDK_PageView* pPageView = (CPDFSDK_PageView*)m_pageMap.GetValueAt(pPDFXFAPage);
+ if(pPageView)
{
delete pPageView;
- m_pageMap.RemoveKey(pPDFPage);
+ m_pageMap.RemoveKey(pPDFXFAPage);
}
}
-CPDF_Page * CPDFSDK_Document::GetPage(int nIndex)
+CPDFXFA_Page * CPDFSDK_Document::GetPage(int nIndex)
{
- CPDF_Page * pTempPage = (CPDF_Page*)m_pEnv->FFI_GetPage(m_pDoc,nIndex);
+ CPDFXFA_Page * pTempPage = (CPDFXFA_Page*)m_pEnv->FFI_GetPage(m_pDoc,nIndex);
if(!pTempPage)
return NULL;
return pTempPage;
@@ -486,7 +481,7 @@ void CPDFSDK_Document::UpdateAllViews(CPDFSDK_PageView* pSender, CPDFSDK_Annot*
{
FX_POSITION pos = m_pageMap.GetStartPosition();
- CPDF_Page * pPage = NULL;
+ CPDFXFA_Page * pPage = NULL;
CPDFSDK_PageView * pPageView = NULL;
while(pos)
{
@@ -509,17 +504,24 @@ FX_BOOL CPDFSDK_Document::SetFocusAnnot(CPDFSDK_Annot* pAnnot,FX_UINT nFlag)
if(m_pFocusAnnot==pAnnot) return TRUE;
+ CPDFSDK_Annot* pLastFocusAnnot = m_pFocusAnnot;
+
if(m_pFocusAnnot)
{
if(!this->KillFocusAnnot(nFlag) ) return FALSE;
}
- CPDFSDK_PageView* pPageView = pAnnot->GetPageView();
+ CPDFSDK_PageView* pPageView = NULL;
+ if (pAnnot)
+ pPageView = pAnnot->GetPageView();
if(pAnnot && pPageView->IsValid())
{
CPDFSDK_AnnotHandlerMgr *pAnnotHandler=m_pEnv->GetAnnotHandlerMgr();
if(pAnnotHandler&&!m_pFocusAnnot)
{
+ if (!pAnnotHandler->Annot_OnChangeFocus(pAnnot,pLastFocusAnnot))
+ return FALSE;
+
if (!pAnnotHandler->Annot_OnSetFocus(pAnnot,nFlag))
return FALSE;
if(!m_pFocusAnnot)
@@ -541,6 +543,10 @@ FX_BOOL CPDFSDK_Document::KillFocusAnnot(FX_UINT nFlag)
{
CPDFSDK_Annot* pFocusAnnot = m_pFocusAnnot;
m_pFocusAnnot = NULL;
+
+ if (!pAnnotHandler->Annot_OnChangeFocus(NULL, pFocusAnnot))
+ return FALSE;
+
if(pAnnotHandler->Annot_OnKillFocus(pFocusAnnot, nFlag))
{
@@ -571,7 +577,7 @@ FX_BOOL CPDFSDK_Document::DeletePages(int nStart, int nCount)
return FALSE;
}
- CPDF_Page * pTempPage = NULL;
+ CPDFXFA_Page * pTempPage = NULL;
for ( int i = nCount-1; i >= 0; i-- )
{
pTempPage = GetPage(nStart+i);
@@ -590,7 +596,7 @@ void CPDFSDK_Document::OnCloseDocument()
FX_BOOL CPDFSDK_Document::GetPermissions(int nFlag)
{
- FX_DWORD dwPermissions = m_pDoc->GetUserPermissions();
+ FX_DWORD dwPermissions = m_pDoc->GetPDFDoc()->GetUserPermissions();
return dwPermissions&nFlag;
}
@@ -607,15 +613,16 @@ CFX_WideString CPDFSDK_Document::GetPath()
}
-CPDFSDK_PageView::CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc,CPDF_Page* page):m_page(page),m_pSDKDoc(pSDKDoc)
+CPDFSDK_PageView::CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc,CPDFXFA_Page* page):m_page(page),m_pSDKDoc(pSDKDoc)
{
CPDFSDK_InterForm* pInterForm = pSDKDoc->GetInterForm();
if(pInterForm)
{
CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm();
- pPDFInterForm->FixPageFields(page);
+ if (page->GetPDFPage())
+ pPDFInterForm->FixPageFields(page->GetPDFPage());
}
- m_page->SetPrivateData((FX_LPVOID)m_page, (FX_LPVOID)this, NULL);
+
m_fxAnnotArray.RemoveAll();
m_bEnterWidget = FALSE;
@@ -623,15 +630,13 @@ CPDFSDK_PageView::CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc,CPDF_Page* page):m_
m_bOnWidget = FALSE;
m_CaptureWidget = NULL;
m_bValid = FALSE;
- m_bLocked = FALSE;
- m_bTakeOverPage = FALSE;
+ m_pAnnotList = NULL;
}
CPDFSDK_PageView::~CPDFSDK_PageView()
{
CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
int nAnnotCount = m_fxAnnotArray.GetSize();
-
for (int i=0; i<nAnnotCount; i++)
{
CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i);
@@ -648,30 +653,49 @@ CPDFSDK_PageView::~CPDFSDK_PageView()
delete m_pAnnotList;
m_pAnnotList = NULL;
}
- m_page->RemovePrivateData((FX_LPVOID)m_page);
- if(m_bTakeOverPage) {
- delete m_page;
- }
}
-void CPDFSDK_PageView::PageView_OnDraw(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,CPDF_RenderOptions* pOptions)
+void CPDFSDK_PageView::PageView_OnDraw(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,CPDF_RenderOptions* pOptions, FX_RECT* pClip)
{
m_curMatrix = *pUser2Device;
-
// m_pAnnotList->DisplayAnnots(m_page, pDevice, pUser2Device, FALSE, pOptions);
CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
+ CPDFXFA_Page* pPage = GetPDFXFAPage();
+
+ if (pPage == NULL) return;
+
+ if (pPage->GetDocument()->GetDocType() == DOCTYPE_DYNIMIC_XFA) {
+ CFX_Graphics gs;
+ gs.Create(pDevice);
+ if (pClip) {
+ CFX_RectF rectClip;
+ rectClip.Set(pClip->left, pClip->top, pClip->Width(), pClip->Height());
+ gs.SetClipRect(rectClip);
+ }
+ IXFA_RenderContext* pRenderContext = XFA_RenderContext_Create();
+ if (!pRenderContext)
+ return;
+ CXFA_RenderOptions renderOptions;
+ renderOptions.m_bHighlight = TRUE;
+ pRenderContext->StartRender(pPage->GetXFAPageView(), &gs, *pUser2Device, renderOptions);
+ pRenderContext->DoRender();
+ pRenderContext->StopRender();
+ pRenderContext->Release();
+ return;
+ }
+ // for pdf/static xfa.
CPDFSDK_AnnotIterator annotIterator(this, TRUE);
CPDFSDK_Annot * pSDKAnnot=NULL;
int index=-1;
- while((pSDKAnnot = annotIterator.Next(index)))
+ pSDKAnnot = annotIterator.Next(index);
+ while(pSDKAnnot)
{
CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
ASSERT(pAnnotHandlerMgr);
pAnnotHandlerMgr->Annot_OnDraw(this, pSDKAnnot, pDevice, pUser2Device, 0);
+ pSDKAnnot = annotIterator.Next(index);
}
-
}
-
CPDF_Annot* CPDFSDK_PageView::GetPDFAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY)
{
@@ -713,11 +737,13 @@ CPDFSDK_Annot* CPDFSDK_PageView::GetFXAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT page
CPDFSDK_AnnotHandlerMgr* pAnnotMgr = pEnv->GetAnnotHandlerMgr();
CPDFSDK_Annot* pSDKAnnot = NULL;
int index = -1;
- while((pSDKAnnot = annotIterator.Next(index)))
+ pSDKAnnot = annotIterator.Next(index);
+ while(pSDKAnnot)
{
CPDF_Rect rc = pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot);
if(rc.Contains(pageX, pageY))
return pSDKAnnot;
+ pSDKAnnot = annotIterator.Next(index);
}
return NULL;
@@ -731,9 +757,10 @@ CPDFSDK_Annot* CPDFSDK_PageView::GetFXWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pag
CPDFSDK_AnnotHandlerMgr* pAnnotMgr = pEnv->GetAnnotHandlerMgr();
CPDFSDK_Annot* pSDKAnnot = NULL;
int index = -1;
- while((pSDKAnnot = annotIterator.Next(index)))
+ pSDKAnnot = annotIterator.Next(index);
+ while(pSDKAnnot)
{
- if(pSDKAnnot->GetType() == "Widget")
+ if(pSDKAnnot->GetType() == "Widget" || pSDKAnnot->GetType() == FSDK_XFAWIDGET_TYPENAME)
{
pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot);
CPDF_Point point(pageX, pageY);
@@ -741,6 +768,7 @@ CPDFSDK_Annot* CPDFSDK_PageView::GetFXWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pag
// if(rc.Contains(pageX, pageY))
return pSDKAnnot;
}
+ pSDKAnnot = annotIterator.Next(index);
}
return NULL;
@@ -781,6 +809,32 @@ CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CPDF_Annot * pPDFAnnot)
return pSDKAnnot;
}
+CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(XFA_HWIDGET pPDFAnnot)
+{
+ if (!pPDFAnnot) return NULL;
+
+ CPDFSDK_Annot* pSDKAnnot = GetAnnotByXFAWidget(pPDFAnnot);
+ if (pSDKAnnot)
+ return pSDKAnnot;
+
+ CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
+ ASSERT(pEnv);
+ CPDFSDK_AnnotHandlerMgr * pAnnotHandler= pEnv->GetAnnotHandlerMgr();
+
+ pSDKAnnot =NULL;
+
+ if(pAnnotHandler)
+ {
+ pSDKAnnot = pAnnotHandler->NewAnnot(pPDFAnnot, this);
+ }
+ if(!pSDKAnnot)
+ return NULL;
+
+ m_fxAnnotArray.Add(pSDKAnnot);
+
+ return pSDKAnnot;
+}
+
CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CPDF_Dictionary * pDict)
{
if(pDict)
@@ -795,21 +849,42 @@ CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(FX_LPCSTR lpSubType,CPDF_Dictionary *
FX_BOOL CPDFSDK_PageView::DeleteAnnot(CPDFSDK_Annot* pAnnot)
{
- return FALSE;
+ if (!pAnnot)
+ return FALSE;
+ CPDFXFA_Page* pPage = pAnnot->GetPDFXFAPage();
+ if (!pPage || (pPage->GetDocument()->GetDocType() != DOCTYPE_STATIC_XFA && pPage->GetDocument()->GetDocType() != DOCTYPE_DYNIMIC_XFA))
+ return FALSE;
+
+ int index = m_fxAnnotArray.Find(pAnnot);
+ m_fxAnnotArray.RemoveAt(index);
+ if (m_CaptureWidget == pAnnot)
+ m_CaptureWidget = NULL;
+
+ return TRUE;
}
CPDF_Document* CPDFSDK_PageView::GetPDFDocument()
{
if(m_page)
{
- return m_page->m_pDocument;
+ return m_page->GetDocument()->GetPDFDoc();
}
return NULL;
}
+CPDF_Page* CPDFSDK_PageView::GetPDFPage()
+{
+ if (m_page)
+ {
+ return m_page->GetPDFPage();
+ }
+
+ return NULL;
+}
+
int CPDFSDK_PageView::CountAnnots()
{
- return m_pAnnotList->Count();
+ return m_fxAnnotArray.GetSize();
}
CPDFSDK_Annot* CPDFSDK_PageView::GetAnnot(int nIndex)
@@ -834,6 +909,20 @@ CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByDict(CPDF_Dictionary * pDict)
}
return NULL;
}
+CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByXFAWidget(XFA_HWIDGET hWidget)
+{
+ if (hWidget == NULL)
+ return NULL;
+ int annotCount = m_fxAnnotArray.GetSize();
+
+ for(int i = 0; i < annotCount; i++)
+ {
+ CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i);
+ if(pAnnot->GetXFAWidget() == hWidget)
+ return pAnnot;
+ }
+ return NULL;
+}
FX_BOOL CPDFSDK_PageView::OnLButtonDown(const CPDF_Point & point, FX_UINT nFlag)
{
@@ -859,6 +948,45 @@ FX_BOOL CPDFSDK_PageView::OnLButtonDown(const CPDF_Point & point, FX_UINT nFlag)
return FALSE;
}
+FX_BOOL CPDFSDK_PageView::OnRButtonDown(const CPDF_Point & point, FX_UINT nFlag)
+{
+ CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
+ ASSERT(pEnv);
+ CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
+ ASSERT(pAnnotHandlerMgr);
+
+ CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y);
+
+ if (pFXAnnot == NULL)
+ return FALSE;
+
+ FX_BOOL bRet = pAnnotHandlerMgr->Annot_OnRButtonDown(this, pFXAnnot, nFlag,point);
+ if (bRet)
+ {
+ SetFocusAnnot(pFXAnnot);
+ }
+ return TRUE;
+}
+
+FX_BOOL CPDFSDK_PageView::OnRButtonUp(const CPDF_Point & point, FX_UINT nFlag)
+{
+ CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
+ ASSERT(pEnv);
+ CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
+ ASSERT(pAnnotHandlerMgr);
+
+ CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y);
+
+ if (pFXAnnot == NULL)
+ return FALSE;
+
+ FX_BOOL bRet = pAnnotHandlerMgr->Annot_OnRButtonUp(this, pFXAnnot, nFlag,point);
+ if (bRet)
+ {
+ SetFocusAnnot(pFXAnnot);
+ }
+ return TRUE;
+}
FX_BOOL CPDFSDK_PageView::OnLButtonUp(const CPDF_Point & point, FX_UINT nFlag)
{
@@ -978,27 +1106,61 @@ extern void CheckUnSupportAnnot(CPDF_Document * pDoc, CPDF_Annot* pPDFAnnot);
void CPDFSDK_PageView::LoadFXAnnots()
{
+ ASSERT(m_page != NULL);
+
CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
+ ASSERT(pEnv != NULL);
- FX_BOOL enableAPUpdate = CPDF_InterForm::UpdatingAPEnabled();
- //Disable the default AP construction.
- CPDF_InterForm::EnableUpdateAP(FALSE);
- m_pAnnotList = new CPDF_AnnotList(m_page);
- CPDF_InterForm::EnableUpdateAP(enableAPUpdate);
- int nCount = m_pAnnotList->Count();
- SetLock(TRUE);
- for(int i=0; i<nCount; i++)
+ CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
+ ASSERT(pAnnotHandlerMgr != NULL);
+
+ if (m_pSDKDoc->GetDocument()->GetDocType() == DOCTYPE_DYNIMIC_XFA)
{
- CPDF_Annot* pPDFAnnot = m_pAnnotList->GetAt(i);
- CPDF_Document * pDoc = this->GetPDFDocument();
+ IXFA_PageView* pageView = NULL;
+ pageView = m_page->GetXFAPageView();
+ ASSERT(pageView != NULL);
+
+ XFA_HWIDGET pXFAAnnot = NULL;
+ IXFA_WidgetIterator* pWidgetHander = pageView->CreateWidgetIterator(XFA_TRAVERSEWAY_Form, XFA_WIDGETFILTER_Visible|XFA_WIDGETFILTER_Viewable|XFA_WIDGETFILTER_AllType);
+ if (!pWidgetHander)
+ return;
+
+ pXFAAnnot = pWidgetHander->MoveToNext();
+ while (pXFAAnnot) {
+ CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pXFAAnnot, this);
+ if(!pAnnot) {
+ pXFAAnnot = pWidgetHander->MoveToNext();
+ continue;
+ }
+ m_fxAnnotArray.Add(pAnnot);
- CheckUnSupportAnnot(pDoc, pPDFAnnot);
+ pAnnotHandlerMgr->Annot_OnLoad(pAnnot);
- CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
- ASSERT(pAnnotHandlerMgr != NULL);
+ pXFAAnnot = pWidgetHander->MoveToNext();
- if(pAnnotHandlerMgr)
+ }
+
+ pWidgetHander->Release();
+ }
+ else
+ {
+ CPDF_Page* pPage = m_page->GetPDFPage();
+ ASSERT(pPage != NULL);
+
+ FX_BOOL enableAPUpdate = CPDF_InterForm::UpdatingAPEnabled();
+ //Disable the default AP construction.
+ CPDF_InterForm::EnableUpdateAP(FALSE);
+ m_pAnnotList = new CPDF_AnnotList(pPage);
+ CPDF_InterForm::EnableUpdateAP(enableAPUpdate);
+
+ int nCount = m_pAnnotList->Count();
+ for(int i=0; i<nCount; i++)
{
+ CPDF_Annot* pPDFAnnot = m_pAnnotList->GetAt(i);
+ CPDF_Document * pDoc = this->GetPDFDocument();
+
+ CheckUnSupportAnnot(pDoc, pPDFAnnot);
+
CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pPDFAnnot, this);
if(!pAnnot)
continue;
@@ -1008,7 +1170,6 @@ void CPDFSDK_PageView::LoadFXAnnots()
}
}
- SetLock(FALSE);
}
void CPDFSDK_PageView::UpdateRects(CFX_RectArray& rects)
@@ -1037,11 +1198,11 @@ int CPDFSDK_PageView::GetPageIndex()
{
if(m_page)
{
- CPDF_Dictionary* pDic = m_page->m_pFormDict;
- CPDF_Document* pDoc = m_pSDKDoc->GetDocument();
+ CPDF_Dictionary* pDic = m_page->GetPDFPage()->m_pFormDict;
+ CPDFXFA_Document* pDoc = m_pSDKDoc->GetDocument();
if(pDoc && pDic)
{
- return pDoc->GetPageIndex(pDic->GetObjNum());
+ return pDoc->GetPDFDoc()->GetPageIndex(pDic->GetObjNum());
}
}
return -1;
diff --git a/fpdfsdk/src/javascript/Document.cpp b/fpdfsdk/src/javascript/Document.cpp
index 229d9770a1..fa3b9de75b 100644
--- a/fpdfsdk/src/javascript/Document.cpp
+++ b/fpdfsdk/src/javascript/Document.cpp
@@ -605,7 +605,7 @@ FX_BOOL Document::mailForm(OBJ_METHOD_PARAMS)
ASSERT(pRuntime != NULL);
pRuntime->BeginBlock();
- pEnv->JS_docmailForm(textBuf.GetBuffer(), textBuf.GetLength(), bUI, (FX_LPCWSTR)cTo, (FX_LPCWSTR)cSubject, (FX_LPCWSTR)cCc, (FX_LPCWSTR)cBcc, (FX_LPCWSTR)cMsg);
+ pEnv->JS_docmailForm(textBuf.GetBuffer(), textBuf.GetLength(), bUI, (FX_LPCWSTR)cTo, (FX_LPCWSTR)cSubject, (FX_LPCWSTR)cCc, (FX_LPCWSTR)cBcc, (FX_LPCWSTR)cMsg);
pRuntime->EndBlock();
return TRUE;
}
@@ -723,7 +723,7 @@ FX_BOOL Document::removeField(OBJ_METHOD_PARAMS)
CFX_RectArray aRefresh;
aRefresh.Add(rcAnnot);
- CPDF_Page* pPage = pWidget->GetPDFPage();
+ CPDFXFA_Page* pPage = pWidget->GetPDFXFAPage();
ASSERT(pPage != NULL);
CPDFSDK_PageView* pPageView = m_pDocument->GetPageView(pPage);
@@ -1009,7 +1009,7 @@ FX_BOOL Document::author(OBJ_PROP_PARAMS)
{
ASSERT(m_pDocument != NULL);
- CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
+ CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetPDFDoc()->GetInfo();
if (!pDictionary)return FALSE;
if (vp.IsGetting())
@@ -1033,7 +1033,7 @@ FX_BOOL Document::info(OBJ_PROP_PARAMS)
{
ASSERT(m_pDocument != NULL);
- CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
+ CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetPDFDoc()->GetInfo();
if (!pDictionary)return FALSE;
CFX_WideString cwAuthor = pDictionary->GetUnicodeText("Author");
@@ -1092,7 +1092,7 @@ FX_BOOL Document::creationDate(OBJ_PROP_PARAMS)
{
ASSERT(m_pDocument != NULL);
- CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
+ CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetPDFDoc()->GetInfo();
if (!pDictionary)return FALSE;
if (vp.IsGetting())
@@ -1117,7 +1117,7 @@ FX_BOOL Document::creator(OBJ_PROP_PARAMS)
{
ASSERT(m_pDocument != NULL);
- CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
+ CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetPDFDoc()->GetInfo();
if (!pDictionary)return FALSE;
if (vp.IsGetting())
@@ -1183,7 +1183,7 @@ FX_BOOL Document::keywords(OBJ_PROP_PARAMS)
{
ASSERT(m_pDocument != NULL);
- CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
+ CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetPDFDoc()->GetInfo();
if (!pDictionary)return FALSE;
if (vp.IsGetting())
@@ -1207,7 +1207,7 @@ FX_BOOL Document::modDate(OBJ_PROP_PARAMS)
{
ASSERT(m_pDocument != NULL);
- CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
+ CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetPDFDoc()->GetInfo();
if (!pDictionary)return FALSE;
if (vp.IsGetting())
@@ -1231,7 +1231,7 @@ FX_BOOL Document::producer(OBJ_PROP_PARAMS)
{
ASSERT(m_pDocument != NULL);
- CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
+ CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetPDFDoc()->GetInfo();
if (!pDictionary)return FALSE;
if (vp.IsGetting())
@@ -1255,7 +1255,7 @@ FX_BOOL Document::subject(OBJ_PROP_PARAMS)
{
ASSERT(m_pDocument != NULL);
- CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
+ CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetPDFDoc()->GetInfo();
if (!pDictionary)return FALSE;
if (vp.IsGetting())
@@ -1282,7 +1282,7 @@ FX_BOOL Document::title(OBJ_PROP_PARAMS)
if (m_pDocument == NULL || m_pDocument->GetDocument() == NULL)
return FALSE;
- CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
+ CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetPDFDoc()->GetInfo();
if (!pDictionary)return FALSE;
if (vp.IsGetting())
@@ -1874,7 +1874,7 @@ FX_BOOL Document::getPageNthWord(OBJ_METHOD_PARAMS)
int nWordNo = params.GetSize() > 1 ? (int)params[1] : 0;
bool bStrip = params.GetSize() > 2 ? (bool)params[2] : true;
- CPDF_Document* pDocument = m_pDocument->GetDocument();
+ CPDF_Document* pDocument = m_pDocument->GetDocument()->GetPDFDoc();
if (!pDocument) return FALSE;
if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount())
@@ -1945,7 +1945,7 @@ FX_BOOL Document::getPageNumWords(OBJ_METHOD_PARAMS)
int nPageNo = params.GetSize() > 0 ? (int)params[0] : 0;
- CPDF_Document* pDocument = m_pDocument->GetDocument();
+ CPDF_Document* pDocument = m_pDocument->GetDocument()->GetPDFDoc();
ASSERT(pDocument != NULL);
if (nPageNo < 0 || nPageNo >= pDocument->GetPageCount())
diff --git a/fpdfsdk/src/javascript/Field.cpp b/fpdfsdk/src/javascript/Field.cpp
index f5f9bf0539..c484cbb1fd 100644
--- a/fpdfsdk/src/javascript/Field.cpp
+++ b/fpdfsdk/src/javascript/Field.cpp
@@ -3820,7 +3820,7 @@ FX_BOOL Field::setFocus(OBJ_METHOD_PARAMS)
{
CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
ASSERT(pEnv);
- CPDF_Page* pPage = (CPDF_Page*)pEnv->FFI_GetCurrentPage(m_pDocument->GetDocument());
+ CPDFXFA_Page* pPage = (CPDFXFA_Page*)pEnv->FFI_GetCurrentPage(m_pDocument->GetDocument());
if(!pPage)
return FALSE;
if (CPDFSDK_PageView* pCurPageView = m_pDocument->GetPageView(pPage))
diff --git a/fpdfsdk/src/javascript/JS_Context.cpp b/fpdfsdk/src/javascript/JS_Context.cpp
index a83e1e057d..31969e4858 100644
--- a/fpdfsdk/src/javascript/JS_Context.cpp
+++ b/fpdfsdk/src/javascript/JS_Context.cpp
@@ -107,6 +107,7 @@ FX_BOOL CJS_Context::DoJob(int nMode, const CFX_WideString& script, CFX_WideStri
FX_BOOL CJS_Context::RunScript(const CFX_WideString& script, CFX_WideString& info)
{
v8::Isolate::Scope isolate_scope(m_pRuntime->GetIsolate());
+ v8::Locker locker(m_pRuntime->GetIsolate());
v8::HandleScope handle_scope(m_pRuntime->GetIsolate());
v8::Local<v8::Context> context = m_pRuntime->NewJSContext();
v8::Context::Scope context_scope(context);
diff --git a/fpdfsdk/src/javascript/JS_GlobalData.cpp b/fpdfsdk/src/javascript/JS_GlobalData.cpp
index 83771dfe57..2207726890 100644
--- a/fpdfsdk/src/javascript/JS_GlobalData.cpp
+++ b/fpdfsdk/src/javascript/JS_GlobalData.cpp
@@ -117,7 +117,7 @@ static const FX_BYTE JS_RC4KEY[] = {0x19,0xa8,0xe8,0x01,0xf6,0xa8,0xb6,0x4d,0x82
0x55,0x8b,0x6e,0x6b,0x19,0xa0,0xf8,0x77,0xd5,0xa3
};
-CJS_GlobalData::CJS_GlobalData(CPDFDoc_Environment* pApp)
+CJS_GlobalData::CJS_GlobalData(CPDFDoc_Environment* pApp) : m_pApp(pApp)
{
// IBaseAnnot* pBaseAnnot = IBaseAnnot::GetBaseAnnot(m_pApp);
// ASSERT(pBaseAnnot != NULL);
diff --git a/fpdfsdk/src/javascript/JS_Object.cpp b/fpdfsdk/src/javascript/JS_Object.cpp
index 3b7774d4d8..09150e796b 100644
--- a/fpdfsdk/src/javascript/JS_Object.cpp
+++ b/fpdfsdk/src/javascript/JS_Object.cpp
@@ -16,7 +16,7 @@ int FXJS_MsgBox(CPDFDoc_Environment* pApp, CPDFSDK_PageView* pPageView, FX_LPCWS
{
int nRet = 0;
- if(pApp)
+ if (pApp)
{
CPDFSDK_Document* pDoc = pApp->GetCurrentDoc();
if(pDoc)
@@ -65,7 +65,7 @@ void CJS_EmbedObj::Alert(CJS_Context* pContext, FX_LPCWSTR swMsg)
CJS_Object::Alert(pContext, swMsg);
}
-CJS_Timer* CJS_EmbedObj::BeginTimer(CPDFDoc_Environment * pApp,FX_UINT nElapse)
+CJS_Timer* CJS_EmbedObj::BeginTimer(CPDFDoc_Environment* pApp, FX_UINT nElapse)
{
CJS_Timer* pTimer = new CJS_Timer(this,pApp);
pTimer->SetJSTimer(nElapse);
diff --git a/fpdfsdk/src/javascript/JS_Runtime.cpp b/fpdfsdk/src/javascript/JS_Runtime.cpp
index d7802b572e..269f23bbd7 100644
--- a/fpdfsdk/src/javascript/JS_Runtime.cpp
+++ b/fpdfsdk/src/javascript/JS_Runtime.cpp
@@ -26,6 +26,12 @@
#include "../../include/javascript/JS_GlobalData.h"
#include "../../include/javascript/global.h"
#include "../../include/javascript/console.h"
+#include "../../include/fpdfxfa/fpdfxfa_app.h"
+#ifndef FOXIT_CHROME_BUILD
+#include "../../../fxjse/value.h"
+#else
+#include "../../../xfa/src/fxjse/src/value.h"
+#endif
#include <libplatform/libplatform.h>
@@ -101,16 +107,26 @@ void CJS_RuntimeFactory::ReleaseGlobalData()
}
/* ------------------------------ CJS_Runtime ------------------------------ */
-
-CJS_Runtime::CJS_Runtime(CPDFDoc_Environment * pApp) :
+extern v8::Persistent<v8::ObjectTemplate>& _getGlobalObjectTemplate(IJS_Runtime* pJSRuntime);
+CJS_Runtime::CJS_Runtime(CPDFDoc_Environment* pApp) :
m_pApp(pApp),
m_pDocument(NULL),
m_bBlocking(FALSE),
m_pFieldEventPath(NULL),
m_bRegistered(FALSE)
{
- m_isolate = v8::Isolate::New();
+ m_isolate = FPDFXFA_GetApp()->GetJSERuntime()?(v8::Isolate*)FPDFXFA_GetApp()->GetJSERuntime():v8::Isolate::New();
//m_isolate->Enter();
+ v8::Isolate* isolate = m_isolate;
+ v8::Isolate::Scope isolate_scope(isolate);
+ v8::Locker locker(isolate);
+ v8::HandleScope handle_scope(isolate);
+ if (FPDFXFA_GetApp()->InitRuntime(FALSE)) {
+ CJS_Context * pContext = (CJS_Context*)NewContext();
+ JS_InitialRuntime(*this, this, pContext, m_context);
+ ReleaseContext(pContext);
+ return;
+ }
InitJSObjects();
@@ -121,12 +137,13 @@ CJS_Runtime::CJS_Runtime(CPDFDoc_Environment * pApp) :
CJS_Runtime::~CJS_Runtime()
{
- for (int i=0, sz=m_ContextArray.GetSize(); i<sz; i++)
+ int size = m_ContextArray.GetSize();
+ for (int i=0;i < size; i++)
delete m_ContextArray.GetAt(i);
m_ContextArray.RemoveAll();
- JS_ReleaseRuntime(*this, m_context);
+ //JS_ReleaseRuntime(*this, m_context);
RemoveEventsInLoop(m_pFieldEventPath);
@@ -136,12 +153,14 @@ CJS_Runtime::~CJS_Runtime()
m_context.Reset();
//m_isolate->Exit();
- m_isolate->Dispose();
+ //m_isolate->Dispose();
+ m_isolate = NULL;
}
FX_BOOL CJS_Runtime::InitJSObjects()
{
v8::Isolate::Scope isolate_scope(GetIsolate());
+ v8::Locker locker(GetIsolate());
v8::HandleScope handle_scope(GetIsolate());
v8::Handle<v8::Context> context = v8::Context::New(GetIsolate());
v8::Context::Scope context_scope(context);
@@ -215,6 +234,7 @@ void CJS_Runtime::SetReaderDocument(CPDFSDK_Document* pReaderDoc)
if (m_pDocument != pReaderDoc)
{
v8::Isolate::Scope isolate_scope(m_isolate);
+ v8::Locker locker(m_isolate);
v8::HandleScope handle_scope(m_isolate);
v8::Local<v8::Context> context =v8::Local<v8::Context>::New(m_isolate, m_context);
v8::Context::Scope context_scope(context);
@@ -476,3 +496,45 @@ void CJS_Runtime::Enter()
{
if(m_isolate) m_isolate->Enter();
}
+FX_BOOL CJS_Runtime::GetHValueByName(FX_BSTR utf8Name, FXJSE_HVALUE hValue)
+{
+ FX_LPCSTR name = utf8Name.GetCStr();
+
+ v8::Locker lock(GetIsolate());
+ v8::Isolate::Scope isolate_scope(GetIsolate());
+ v8::HandleScope handle_scope(GetIsolate());
+ v8::Local<v8::Context> context =
+ v8::Local<v8::Context>::New(GetIsolate(), m_context);
+ v8::Context::Scope context_scope(context);
+
+
+ //v8::Local<v8::Context> tmpCotext = v8::Local<v8::Context>::New(GetIsolate(), m_context);
+ v8::Local<v8::Value> propvalue = context->Global()->Get(v8::String::NewFromUtf8(GetIsolate(), name, v8::String::kNormalString, utf8Name.GetLength()));
+
+ if (propvalue.IsEmpty()) {
+ FXJSE_Value_SetUndefined(hValue);
+ return FALSE;
+ }
+ ((CFXJSE_Value*)hValue)->ForceSetValue(propvalue);
+
+ return TRUE;
+}
+FX_BOOL CJS_Runtime::SetHValueByName(FX_BSTR utf8Name, FXJSE_HVALUE hValue)
+{
+ if (utf8Name.IsEmpty() || hValue == NULL)
+ return FALSE;
+ FX_LPCSTR name = utf8Name.GetCStr();
+ v8::Isolate* pIsolate = GetIsolate();
+ v8::Locker lock(pIsolate);
+ v8::Isolate::Scope isolate_scope(pIsolate);
+ v8::HandleScope handle_scope(pIsolate);
+ v8::Local<v8::Context> context =
+ v8::Local<v8::Context>::New(pIsolate, m_context);
+ v8::Context::Scope context_scope(context);
+
+ //v8::Local<v8::Context> tmpCotext = v8::Local<v8::Context>::New(GetIsolate(), m_context);
+ v8::Local<v8::Value> propvalue = v8::Local<v8::Value>::New(GetIsolate(),((CFXJSE_Value*)hValue)->DirectGetValue());
+ context->Global()->Set(v8::String::NewFromUtf8(pIsolate, name, v8::String::kNormalString, utf8Name.GetLength()), propvalue);
+
+ return TRUE;
+}
diff --git a/fpdfsdk/src/javascript/app.cpp b/fpdfsdk/src/javascript/app.cpp
index 1c4da08ccb..42692382c8 100644
--- a/fpdfsdk/src/javascript/app.cpp
+++ b/fpdfsdk/src/javascript/app.cpp
@@ -68,6 +68,7 @@ CJS_Timer* TimerObj::GetTimer() const
#define JS_STR_PLATFORM L"WIN"
#define JS_STR_LANGUANGE L"ENU"
#define JS_STR_VIEWERVERSION 8
+#define JS_STR_VIEWERVERSION_XFA 11
#define JS_NUM_FORMSVERSION 7
#define JS_FILEPATH_MAXLEN 2000
@@ -152,8 +153,8 @@ FX_BOOL app::activeDocs(OBJ_PROP_PARAMS)
CJS_Array aDocs(pRuntime->GetIsolate());
// int iNumDocs = pApp->CountDocuments();
-// for(int iIndex = 0; iIndex<iNumDocs; iIndex++)
-// {
+// for(int iIndex = 0; iIndex<iNumDocs; iIndex++)
+// {
CPDFSDK_Document* pDoc = pApp->GetCurrentDoc();
if (pDoc)
{
@@ -209,10 +210,10 @@ FX_BOOL app::calculate(OBJ_PROP_PARAMS)
ASSERT(pRuntime != NULL);
CJS_Array aDocs(pRuntime->GetIsolate());
-// int iNumDocs = pApp->CountDocuments();
+// int iNumDocs = pApp->CountDocuments();
//
-// for (int iIndex = 0;iIndex < iNumDocs; iIndex++)
-// {
+// for (int iIndex = 0;iIndex < iNumDocs; iIndex++)
+// {
if (CPDFSDK_Document* pDoc = pApp->GetCurrentDoc())
{
CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDoc->GetInterForm();
@@ -278,7 +279,19 @@ FX_BOOL app::viewerVersion(OBJ_PROP_PARAMS)
{
if (vp.IsGetting())
{
- vp << JS_STR_VIEWERVERSION;
+ CJS_Context* pContext = (CJS_Context *)cc;
+ ASSERT(pContext != NULL);
+
+ CPDFDoc_Environment* pApp = pContext->GetReaderApp();
+ ASSERT(pApp != NULL);
+
+ CPDFSDK_Document* pCurDoc = pContext->GetReaderDocument();
+
+ CPDFXFA_Document* pDoc = pCurDoc->GetDocument();
+ if (pDoc->GetDocType() == 1 || pDoc->GetDocType() == 2)
+ vp << JS_STR_VIEWERVERSION_XFA;
+ else
+ vp << JS_STR_VIEWERVERSION;
return TRUE;
}
diff --git a/fpdfsdk/src/javascript/global.cpp b/fpdfsdk/src/javascript/global.cpp
index 295a8d49af..6bf0861e1a 100644
--- a/fpdfsdk/src/javascript/global.cpp
+++ b/fpdfsdk/src/javascript/global.cpp
@@ -13,6 +13,7 @@
#include "../../include/javascript/global.h"
#include "../../include/javascript/JS_EventHandler.h"
#include "../../include/javascript/JS_Context.h"
+#include "../../include/fpdfxfa/fpdfxfa_app.h"
/* ---------------------------- global ---------------------------- */
@@ -54,7 +55,7 @@ global_alternate::~global_alternate(void)
// CommitGlobalPersisitentVariables();
DestroyGlobalPersisitentVariables();
- CJS_RuntimeFactory* pFactory = m_pApp->m_pJSRuntimeFactory;
+ CJS_RuntimeFactory* pFactory = FPDFXFA_GetApp()->GetRuntimeFactory();
ASSERT(pFactory);
pFactory->ReleaseGlobalData();
@@ -64,7 +65,7 @@ void global_alternate::Initial(CPDFDoc_Environment* pApp)
{
m_pApp = pApp;
- CJS_RuntimeFactory* pFactory = pApp->m_pJSRuntimeFactory;
+ CJS_RuntimeFactory* pFactory = FPDFXFA_GetApp()->GetRuntimeFactory();
ASSERT(pFactory);
m_pGlobalData = pFactory->NewGlobalData(pApp);
UpdateGlobalPersistentVariables();
diff --git a/fpdfsdk/src/jsapi/fxjs_v8.cpp b/fpdfsdk/src/jsapi/fxjs_v8.cpp
index 5eb9873f5c..dcad30edaf 100644
--- a/fpdfsdk/src/jsapi/fxjs_v8.cpp
+++ b/fpdfsdk/src/jsapi/fxjs_v8.cpp
@@ -76,11 +76,11 @@ int JS_DefineObj(IJS_Runtime* pJSRuntime, const wchar_t* sObjName, FXJSOBJTYPE e
v8::Isolate* isolate = (v8::Isolate*)pJSRuntime;
v8::Isolate::Scope isolate_scope(isolate);
v8::HandleScope handle_scope(isolate);
- CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0);
+ CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1);
if(!pArray)
{
pArray = FX_NEW CFX_PtrArray();
- isolate->SetData(0, pArray);
+ isolate->SetData(1, pArray);
}
CJS_ObjDefintion* pObjDef = FX_NEW CJS_ObjDefintion(isolate, sObjName, eObjType, pConstructor, pDestructor, bApplyNew);
pArray->Add(pObjDef);
@@ -96,7 +96,7 @@ int JS_DefineObjMethod(IJS_Runtime* pJSRuntime, int nObjDefnID, const wchar_t* s
CFX_WideString ws = CFX_WideString((FX_LPCWSTR)sMethodName);
CFX_ByteString bsMethodName = ws.UTF8Encode();
- CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0);
+ CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1);
if(!pArray) return 0;
if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return 0;
@@ -116,7 +116,7 @@ int JS_DefineObjProperty(IJS_Runtime* pJSRuntime, int nObjDefnID, const wchar_t*
CFX_WideString ws = CFX_WideString((FX_LPCWSTR)sPropName);
CFX_ByteString bsPropertyName = ws.UTF8Encode();
- CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0);
+ CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1);
if(!pArray) return 0;
if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return 0;
@@ -133,7 +133,7 @@ int JS_DefineObjAllProperties(IJS_Runtime* pJSRuntime, int nObjDefnID, v8::Named
v8::Isolate::Scope isolate_scope(isolate);
v8::HandleScope handle_scope(isolate);
- CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0);
+ CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1);
if(!pArray) return 0;
if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return 0;
@@ -150,7 +150,7 @@ int JS_DefineObjConst(IJS_Runtime* pJSRuntime, int nObjDefnID, const wchar_t* sC
v8::Isolate::Scope isolate_scope(isolate);
v8::HandleScope handle_scope(isolate);
- CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0);
+ CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1);
if(!pArray) return 0;
CFX_WideString ws = CFX_WideString((FX_LPCWSTR)sConstName);
@@ -170,7 +170,7 @@ static v8::Persistent<v8::ObjectTemplate>& _getGlobalObjectTemplate(IJS_Runtime*
v8::Isolate::Scope isolate_scope(isolate);
v8::HandleScope handle_scope(isolate);
- CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0);
+ CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1);
ASSERT(pArray != NULL);
for(int i=0; i<pArray->GetSize(); i++)
{
@@ -234,16 +234,18 @@ void JS_InitialRuntime(IJS_Runtime* pJSRuntime,IFXJS_Runtime* pFXRuntime, IFXJS_
{
v8::Isolate* isolate = (v8::Isolate*)pJSRuntime;
v8::Isolate::Scope isolate_scope(isolate);
+ v8::Locker locker(isolate);
v8::HandleScope handle_scope(isolate);
v8::Persistent<v8::ObjectTemplate>& globalObjTemp = _getGlobalObjectTemplate(pJSRuntime);
v8::Handle<v8::Context> v8Context = v8::Context::New(isolate, NULL, v8::Local<v8::ObjectTemplate>::New(isolate, globalObjTemp));
v8::Context::Scope context_scope(v8Context);
- v8::Handle<v8::External> ptr = v8::External::New(isolate, pFXRuntime);
- v8Context->SetEmbedderData(1, ptr);
+ //v8::Handle<External> ptr = External::New(isolate, pFXRuntime);
+ //v8Context->SetEmbedderData(1, ptr);
+ isolate->SetData(2, pFXRuntime);
- CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0);
+ CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1);
if(!pArray) return;
for(int i=0; i<pArray->GetSize(); i++)
@@ -257,7 +259,8 @@ void JS_InitialRuntime(IJS_Runtime* pJSRuntime,IFXJS_Runtime* pFXRuntime, IFXJS_
if(pObjDef->objType == JS_DYNAMIC)
{
//Document is set as global object, need to construct it first.
- if(ws.Equal(L"Document"))
+ CFX_WideString wsString(L"Document");
+ if(ws.Equal(wsString))
{
CJS_PrivateData* pPrivateData = FX_NEW CJS_PrivateData;
@@ -284,11 +287,10 @@ void JS_ReleaseRuntime(IJS_Runtime* pJSRuntime, v8::Persistent<v8::Context>& v8P
{
v8::Isolate* isolate = (v8::Isolate*)pJSRuntime;
v8::Isolate::Scope isolate_scope(isolate);
+ v8::Locker locker(isolate);
v8::HandleScope handle_scope(isolate);
- v8::Local<v8::Context> context = v8::Local<v8::Context>::New(isolate, v8PersistentContext);
- v8::Context::Scope context_scope(context);
- CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0);
+ CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1);
if(!pArray) return ;
for(int i=0; i<pArray->GetSize(); i++)
@@ -304,14 +306,15 @@ void JS_ReleaseRuntime(IJS_Runtime* pJSRuntime, v8::Persistent<v8::Context>& v8P
delete pObjDef;
}
delete pArray;
- isolate->SetData(0,NULL);
+ isolate->SetData(1,NULL);
+ isolate->SetData(2,NULL);
}
void JS_Initial()
{
-#ifndef FOXIT_CHROME_BUILD
- v8::V8::InitializeICU();
-#endif
+//#ifndef FOXIT_CHROME_BUILD
+// v8::V8::InitializeICU();
+//#endif
}
void JS_Release()
{
@@ -368,7 +371,7 @@ v8::Handle<v8::Object> JS_NewFxDynamicObj(IJS_Runtime* pJSRuntime, IFXJS_Context
return objTempl->NewInstance();
}
- CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0);
+ CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1);
if(!pArray) return v8::Handle<v8::Object>();
@@ -396,7 +399,7 @@ v8::Handle<v8::Object> JS_GetStaticObj(IJS_Runtime* pJSRuntime, int nObjDefnID)
v8::Isolate* isolate = (v8::Isolate*)pJSRuntime;
v8::Isolate::Scope isolate_scope(isolate);
- CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0);
+ CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1);
if(!pArray) return v8::Handle<v8::Object>();
if(nObjDefnID<0 || nObjDefnID>= pArray->GetSize()) return v8::Handle<v8::Object>();
@@ -415,7 +418,7 @@ v8::Handle<v8::Object> JS_GetThisObj(IJS_Runtime * pJSRuntime)
v8::Isolate* isolate = (v8::Isolate*)pJSRuntime;
v8::Isolate::Scope isolate_scope(isolate);
- CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0);
+ CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1);
if(!pArray) return v8::Handle<v8::Object>();
v8::Local<v8::Context> context = isolate->GetCurrentContext();
@@ -445,7 +448,7 @@ int JS_GetObjDefnID(IJS_Runtime * pJSRuntime, const wchar_t* pObjName)
v8::Isolate* isolate = (v8::Isolate*)pJSRuntime;
v8::Isolate::Scope isolate_scope(isolate);
- CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(0);
+ CFX_PtrArray* pArray = (CFX_PtrArray*)isolate->GetData(1);
if(!pArray) return -1;
for(int i=0; i<pArray->GetSize(); i++)
@@ -464,12 +467,12 @@ void JS_Error(v8::Value * pError,const wchar_t * main,const wchar_t * sub)
unsigned JS_CalcHash(const wchar_t* main, unsigned nLen)
{
- return (unsigned)FX_HashCode_String_GetW(main, nLen);
+ return (unsigned)FX_HashCode_String_GetW((FX_LPCWSTR)main, nLen);
}
unsigned JS_CalcHash(const wchar_t* main)
{
- return (unsigned)FX_HashCode_String_GetW(main, FXSYS_wcslen(main));
+ return (unsigned)FX_HashCode_String_GetW((FX_LPCWSTR)main, FXSYS_wcslen(main));
}
const wchar_t* JS_GetTypeof(v8::Handle<v8::Value> pObj)
{
diff --git a/fpdfsdk/src/pdfwindow/PWL_ComboBox.cpp b/fpdfsdk/src/pdfwindow/PWL_ComboBox.cpp
index 01810ffd7a..744118fb9c 100644
--- a/fpdfsdk/src/pdfwindow/PWL_ComboBox.cpp
+++ b/fpdfsdk/src/pdfwindow/PWL_ComboBox.cpp
@@ -502,6 +502,10 @@ void CPWL_ComboBox::SetPopup(FX_BOOL bPopup)
{
if (m_pFillerNotify)
{
+ FX_BOOL bExit = FALSE;
+ m_pFillerNotify->OnPopupPreOpen(GetAttachedData(), bExit, 0);
+ if (bExit) return;
+
FX_INT32 nWhere = 0;
FX_FLOAT fPopupRet = 0.0f;
FX_FLOAT fPopupMin = 0.0f;
@@ -529,6 +533,10 @@ void CPWL_ComboBox::SetPopup(FX_BOOL bPopup)
m_nPopupWhere = nWhere;
Move(rcWindow, TRUE, TRUE);
+
+ bExit = FALSE;
+ m_pFillerNotify->OnPopupPostOpen(GetAttachedData(), bExit, 0);
+ if (bExit) return;
}
}
}
@@ -552,6 +560,15 @@ FX_BOOL CPWL_ComboBox::OnKeyDown(FX_WORD nChar, FX_DWORD nFlag)
if (m_pList->GetCurSel() > 0)
{
FX_BOOL bExit = FALSE;
+
+ if (m_pFillerNotify)
+ {
+ m_pFillerNotify->OnPopupPreOpen(GetAttachedData(), bExit, nFlag);
+ if (bExit) return FALSE;
+ bExit = FALSE;
+ m_pFillerNotify->OnPopupPostOpen(GetAttachedData(), bExit, nFlag);
+ if (bExit) return FALSE;
+ }
if (m_pList->OnKeyDownWithExit(nChar,bExit,nFlag))
{
if (bExit) return FALSE;
@@ -563,6 +580,15 @@ FX_BOOL CPWL_ComboBox::OnKeyDown(FX_WORD nChar, FX_DWORD nFlag)
if (m_pList->GetCurSel() < m_pList->GetCount() - 1)
{
FX_BOOL bExit = FALSE;
+
+ if (m_pFillerNotify)
+ {
+ m_pFillerNotify->OnPopupPreOpen(GetAttachedData(), bExit, nFlag);
+ if (bExit) return FALSE;
+ bExit = FALSE;
+ m_pFillerNotify->OnPopupPostOpen(GetAttachedData(), bExit, nFlag);
+ if (bExit) return FALSE;
+ }
if (m_pList->OnKeyDownWithExit(nChar,bExit,nFlag))
{
if (bExit) return FALSE;
@@ -592,6 +618,16 @@ FX_BOOL CPWL_ComboBox::OnChar(FX_WORD nChar, FX_DWORD nFlag)
}
else
{
+ if (m_pFillerNotify)
+ {
+ bExit = FALSE;
+ m_pFillerNotify->OnPopupPreOpen(GetAttachedData(), bExit, nFlag);
+ if (bExit) return FALSE;
+
+ bExit = FALSE;
+ m_pFillerNotify->OnPopupPostOpen(GetAttachedData(), bExit, nFlag);
+ if (bExit) return FALSE;
+ }
if (m_pList->OnCharWithExit(nChar,bExit,nFlag))
{
return bExit;