Replace XFA_HDOC with IXFA_Doc*
[pdfium.git] / fpdfsdk / src / fpdfxfa / fpdfxfa_doc.cpp
index b416da0..9ef8d53 100644 (file)
@@ -4,28 +4,15 @@
  \r
 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com\r
 \r
+#include "../../../public/fpdf_formfill.h"\r
 #include "../../include/fsdk_define.h"\r
 #include "../../include/fpdfxfa/fpdfxfa_doc.h"\r
-#include "../../include/fpdfformfill.h"\r
 #include "../../include/fsdk_mgr.h"\r
 #include "../../include/fpdfxfa/fpdfxfa_app.h"\r
 #include "../../include/fpdfxfa/fpdfxfa_util.h"\r
 #include "../../include/fpdfxfa/fpdfxfa_page.h"\r
 #include "../../include/javascript/IJavaScript.h"\r
 \r
-\r
-\r
-#define IDS_XFA_StringMonth_April "April"\r
-#define IDS_XFA_StringMonth_May "May"\r
-#define IDS_XFA_StringMonth_June "June"\r
-#define IDS_XFA_StringMonth_July "July"\r
-#define IDS_XFA_StringMonth_Aug "August"\r
-#define IDS_XFA_StringMonth_Sept "September"\r
-#define IDS_XFA_StringMonth_Oct "October"\r
-#define IDS_XFA_StringMonth_Nov "November"\r
-#define IDS_XFA_StringMonth_Dec "December"\r
-#define IDS_XFA_String_Today    "Today"\r
-#define IDS_XFA_ValidateLimit   "Message limit exceeded. Remaining %d validation errors not reported."\r
 #define IDS_XFA_Validate_Input  "At least one required field was empty. Please fill in the required fields\r\n(highlighted) before continuing."\r
 \r
 // submit\r
@@ -78,9 +65,7 @@ CPDFXFA_Document::~CPDFXFA_Document()
                        IXFA_DocHandler* pDocHandler = pApp->GetDocHandler();\r
                        if (pDocHandler)\r
                        {\r
-                               pDocHandler->CloseDoc(m_pXFADoc);\r
-                               pDocHandler->ReleaseDoc(m_pXFADoc);\r
-                               m_pXFADoc = NULL;\r
+                               CloseXFADoc(pDocHandler);\r
                        }       \r
                }\r
        }\r
@@ -107,70 +92,50 @@ FX_BOOL CPDFXFA_Document::LoadXFADoc()
 \r
        m_XFAPageList.RemoveAll();\r
 \r
-       int iDocType = DOCTYPE_PDF;\r
-       FX_BOOL hasXFAField = FPDF_HasXFAField(m_pPDFDoc, iDocType);\r
+       IXFA_App* pApp = m_pApp->GetXFAApp();\r
+       if (!pApp)\r
+               return FALSE;\r
 \r
-       if (hasXFAField)\r
+       m_pXFADoc = pApp->CreateDoc(this, m_pPDFDoc);\r
+       if (!m_pXFADoc)\r
        {\r
-               IXFA_App* pApp = m_pApp->GetXFAApp();\r
-               if (pApp)\r
-               {\r
-                       m_pXFADoc = pApp->CreateDoc(this, m_pPDFDoc);\r
-                       if (!m_pXFADoc)\r
-                       {\r
-                               SetLastError(FPDF_ERR_XFALOAD);\r
-                               return FALSE;\r
-                       }\r
-\r
-                       IXFA_DocHandler* pDocHandler = pApp->GetDocHandler();\r
-                       if (pDocHandler)\r
-                       {\r
-                               int iStatus = pDocHandler->StartLoad(m_pXFADoc);\r
-                               iStatus = pDocHandler->DoLoad(m_pXFADoc, NULL);\r
-                               if (iStatus != 100) \r
-                               {\r
-                                       pDocHandler->CloseDoc(m_pXFADoc);\r
-                                       pDocHandler->ReleaseDoc(m_pXFADoc);\r
-                                       m_pXFADoc = NULL;\r
-\r
-                                       SetLastError(FPDF_ERR_XFALOAD);\r
-                                       return FALSE;\r
-                               }\r
-                               pDocHandler->StopLoad(m_pXFADoc);\r
-                               pDocHandler->SetJSERuntime(m_pXFADoc, m_pApp->GetJSERuntime());\r
-\r
-                               if (pDocHandler->GetDocType(m_pXFADoc) == XFA_DOCTYPE_Dynamic)\r
-                                       m_iDocType = DOCTYPE_DYNIMIC_XFA;\r
-                               else\r
-                                       m_iDocType = DOCTYPE_STATIC_XFA;\r
-\r
-                               m_pXFADocView = pDocHandler->CreateDocView(m_pXFADoc, XFA_DOCVIEW_View);\r
-                               FXSYS_assert(m_pXFADocView);\r
-\r
-                               if (m_pXFADocView->StartLayout() < 0) \r
-                               {\r
-                                       pDocHandler->CloseDoc(m_pXFADoc);\r
-                                       pDocHandler->ReleaseDoc(m_pXFADoc);\r
-                                       m_pXFADoc = NULL;\r
+               SetLastError(FPDF_ERR_XFALOAD);\r
+               return FALSE;\r
+       }\r
 \r
-                                       SetLastError(FPDF_ERR_XFALAYOUT);\r
-                                       return FALSE;\r
-                               }\r
-                               else\r
-                               {\r
-                                       m_pXFADocView->DoLayout(NULL);\r
-                                       m_pXFADocView->StopLayout();\r
+       IXFA_DocHandler* pDocHandler = pApp->GetDocHandler();\r
+       if (!pDocHandler)\r
+       {\r
+               SetLastError(FPDF_ERR_XFALOAD);\r
+               return FALSE;\r
+       }\r
 \r
-                                       return TRUE;\r
-                               }                               \r
-                       }\r
+       pDocHandler->StartLoad(m_pXFADoc);\r
+       int iStatus = pDocHandler->DoLoad(m_pXFADoc, NULL);\r
+       if (iStatus != XFA_PARSESTATUS_Done) \r
+       {\r
+               CloseXFADoc(pDocHandler);\r
+               SetLastError(FPDF_ERR_XFALOAD);\r
+               return FALSE;\r
+       }\r
+       pDocHandler->StopLoad(m_pXFADoc);\r
+       pDocHandler->SetJSERuntime(m_pXFADoc, m_pApp->GetJSERuntime());\r
 \r
-                       return FALSE;\r
-               }\r
+       if (pDocHandler->GetDocType(m_pXFADoc) == XFA_DOCTYPE_Dynamic)\r
+               m_iDocType = DOCTYPE_DYNIMIC_XFA;\r
+       else\r
+               m_iDocType = DOCTYPE_STATIC_XFA;\r
 \r
+       m_pXFADocView = pDocHandler->CreateDocView(m_pXFADoc, XFA_DOCVIEW_View);\r
+       if (m_pXFADocView->StartLayout() < 0)\r
+       {\r
+               CloseXFADoc(pDocHandler);\r
+               SetLastError(FPDF_ERR_XFALAYOUT);\r
                return FALSE;\r
        }\r
-       \r
+\r
+       m_pXFADocView->DoLayout(NULL);\r
+       m_pXFADocView->StopLayout();\r
        return TRUE;\r
 }\r
 \r
@@ -287,7 +252,7 @@ void CPDFXFA_Document::FXRect2PDFRect(const CFX_RectF& fxRectF, CPDF_Rect& pdfRe
 }\r
 \r
 //////////////////////////////////////////////////////////////////////////\r
-void CPDFXFA_Document::SetChangeMark(XFA_HDOC hDoc)\r
+void CPDFXFA_Document::SetChangeMark(IXFA_Doc* hDoc)\r
 {\r
        if (hDoc == m_pXFADoc && m_pSDKDoc)\r
        {\r
@@ -295,7 +260,7 @@ void CPDFXFA_Document::SetChangeMark(XFA_HDOC hDoc)
        }\r
 }\r
 \r
-FX_BOOL CPDFXFA_Document::GetChangeMark(XFA_HDOC hDoc)\r
+FX_BOOL CPDFXFA_Document::GetChangeMark(IXFA_Doc* hDoc)\r
 {\r
        if (hDoc == m_pXFADoc && m_pSDKDoc)\r
                return m_pSDKDoc->GetChangeMark();\r
@@ -668,7 +633,7 @@ void CPDFXFA_Document::WidgetEvent(XFA_HWIDGET hWidget, CXFA_WidgetAcc* pWidgetD
        }\r
 }\r
 \r
-FX_INT32 CPDFXFA_Document::CountPages(XFA_HDOC hDoc)\r
+FX_INT32 CPDFXFA_Document::CountPages(IXFA_Doc* hDoc)\r
 {\r
        if (hDoc == m_pXFADoc && m_pSDKDoc)\r
        {\r
@@ -676,7 +641,7 @@ FX_INT32 CPDFXFA_Document::CountPages(XFA_HDOC hDoc)
        }\r
        return 0;\r
 }\r
-FX_INT32 CPDFXFA_Document::GetCurrentPage(XFA_HDOC hDoc)\r
+FX_INT32 CPDFXFA_Document::GetCurrentPage(IXFA_Doc* hDoc)\r
 {\r
        if (hDoc != m_pXFADoc || !m_pSDKDoc)\r
                return -1;\r
@@ -690,7 +655,7 @@ FX_INT32 CPDFXFA_Document::GetCurrentPage(XFA_HDOC hDoc)
 \r
        return pEnv->FFI_GetCurrentPageIndex(this);\r
 }\r
-void CPDFXFA_Document::SetCurrentPage(XFA_HDOC hDoc, FX_INT32 iCurPage)\r
+void CPDFXFA_Document::SetCurrentPage(IXFA_Doc* hDoc, FX_INT32 iCurPage)\r
 {\r
        if (hDoc != m_pXFADoc || !m_pSDKDoc)\r
                return;\r
@@ -703,7 +668,7 @@ void CPDFXFA_Document::SetCurrentPage(XFA_HDOC hDoc, FX_INT32 iCurPage)
 \r
        pEnv->FFI_SetCurrentPage(this, iCurPage);\r
 }\r
-FX_BOOL        CPDFXFA_Document::IsCalculationsEnabled(XFA_HDOC hDoc)\r
+FX_BOOL        CPDFXFA_Document::IsCalculationsEnabled(IXFA_Doc* hDoc)\r
 {\r
        if (hDoc != m_pXFADoc || !m_pSDKDoc)\r
                return FALSE;\r
@@ -713,7 +678,7 @@ FX_BOOL     CPDFXFA_Document::IsCalculationsEnabled(XFA_HDOC hDoc)
        return FALSE;\r
 \r
 }\r
-void CPDFXFA_Document::SetCalculationsEnabled(XFA_HDOC hDoc, FX_BOOL bEnabled)\r
+void CPDFXFA_Document::SetCalculationsEnabled(IXFA_Doc* hDoc, FX_BOOL bEnabled)\r
 {\r
        if (hDoc != m_pXFADoc || !m_pSDKDoc)\r
                return;\r
@@ -721,7 +686,7 @@ void CPDFXFA_Document::SetCalculationsEnabled(XFA_HDOC hDoc, FX_BOOL bEnabled)
                m_pSDKDoc->GetInterForm()->XfaEnableCalculate(bEnabled);\r
 }\r
 \r
-void CPDFXFA_Document::GetTitle(XFA_HDOC hDoc, CFX_WideString &wsTitle)\r
+void CPDFXFA_Document::GetTitle(IXFA_Doc* hDoc, CFX_WideString &wsTitle)\r
 {\r
        if (hDoc != m_pXFADoc)\r
                return;\r
@@ -736,7 +701,7 @@ void CPDFXFA_Document::GetTitle(XFA_HDOC hDoc, CFX_WideString &wsTitle)
     wsTitle = wsTitle.FromLocal(csTitle.GetBuffer(csTitle.GetLength()));\r
        csTitle.ReleaseBuffer(csTitle.GetLength());\r
 }\r
-void CPDFXFA_Document::SetTitle(XFA_HDOC hDoc, FX_WSTR wsTitle)\r
+void CPDFXFA_Document::SetTitle(IXFA_Doc* hDoc, FX_WSTR wsTitle)\r
 {\r
        if (hDoc != m_pXFADoc)\r
                return;\r
@@ -748,7 +713,7 @@ void CPDFXFA_Document::SetTitle(XFA_HDOC hDoc, FX_WSTR wsTitle)
                return;\r
        pInfoDict->SetAt("Title", FX_NEW CPDF_String(wsTitle));\r
 }\r
-void CPDFXFA_Document::ExportData(XFA_HDOC hDoc, FX_WSTR wsFilePath, FX_BOOL bXDP)\r
+void CPDFXFA_Document::ExportData(IXFA_Doc* hDoc, FX_WSTR wsFilePath, FX_BOOL bXDP)\r
 {\r
        if (hDoc != m_pXFADoc)\r
                return;\r
@@ -869,12 +834,12 @@ void CPDFXFA_Document::ExportData(XFA_HDOC hDoc, FX_WSTR wsFilePath, FX_BOOL bXD
        }\r
        FX_BOOL bError= fileWrite.Flush();\r
 }\r
-void CPDFXFA_Document::ImportData(XFA_HDOC hDoc, FX_WSTR wsFilePath)\r
+void CPDFXFA_Document::ImportData(IXFA_Doc* hDoc, FX_WSTR wsFilePath)\r
 {\r
        //TODO...\r
 }\r
 \r
-void CPDFXFA_Document::GotoURL(XFA_HDOC hDoc, FX_WSTR bsURL, FX_BOOL bAppend)\r
+void CPDFXFA_Document::GotoURL(IXFA_Doc* hDoc, FX_WSTR bsURL, FX_BOOL bAppend)\r
 {\r
        if (hDoc != m_pXFADoc)\r
                return;\r
@@ -892,7 +857,7 @@ void CPDFXFA_Document::GotoURL(XFA_HDOC hDoc, FX_WSTR bsURL, FX_BOOL bAppend)
 \r
 }\r
 \r
-FX_BOOL        CPDFXFA_Document::IsValidationsEnabled(XFA_HDOC hDoc)\r
+FX_BOOL        CPDFXFA_Document::IsValidationsEnabled(IXFA_Doc* hDoc)\r
 {\r
        if (hDoc != m_pXFADoc || !m_pSDKDoc)\r
                return FALSE;\r
@@ -901,14 +866,14 @@ FX_BOOL   CPDFXFA_Document::IsValidationsEnabled(XFA_HDOC hDoc)
 \r
        return TRUE;\r
 }\r
-void CPDFXFA_Document::SetValidationsEnabled(XFA_HDOC hDoc, FX_BOOL bEnabled)\r
+void CPDFXFA_Document::SetValidationsEnabled(IXFA_Doc* hDoc, FX_BOOL bEnabled)\r
 {\r
        if (hDoc != m_pXFADoc || !m_pSDKDoc)\r
                return;\r
        if (m_pSDKDoc->GetInterForm())\r
                m_pSDKDoc->GetInterForm()->XfaSetValidationsEnabled(bEnabled);\r
 }\r
-void  CPDFXFA_Document::SetFocusWidget(XFA_HDOC hDoc, XFA_HWIDGET hWidget)\r
+void  CPDFXFA_Document::SetFocusWidget(IXFA_Doc* hDoc, XFA_HWIDGET hWidget)\r
 {\r
        if (hDoc != m_pXFADoc)\r
                return;\r
@@ -931,7 +896,7 @@ void  CPDFXFA_Document::SetFocusWidget(XFA_HDOC hDoc, XFA_HWIDGET hWidget)
                }\r
        }\r
 }\r
-void CPDFXFA_Document::Print(XFA_HDOC hDoc, FX_INT32 nStartPage, FX_INT32 nEndPage, FX_DWORD dwOptions)\r
+void CPDFXFA_Document::Print(IXFA_Doc* hDoc, FX_INT32 nStartPage, FX_INT32 nEndPage, FX_DWORD dwOptions)\r
 {\r
        if (hDoc != m_pXFADoc)\r
                return;\r
@@ -949,7 +914,7 @@ void CPDFXFA_Document::Print(XFA_HDOC hDoc, FX_INT32 nStartPage, FX_INT32 nEndPa
                dwOptions&XFA_PRINTOPT_ReverseOrder,dwOptions&XFA_PRINTOPT_PrintAnnot);\r
 }\r
 \r
-void CPDFXFA_Document::GetURL(XFA_HDOC hDoc, CFX_WideString &wsDocURL)\r
+void CPDFXFA_Document::GetURL(IXFA_Doc* hDoc, CFX_WideString &wsDocURL)\r
 {\r
        if (hDoc != m_pXFADoc)\r
                return;\r
@@ -961,7 +926,7 @@ void CPDFXFA_Document::GetURL(XFA_HDOC hDoc, CFX_WideString &wsDocURL)
        pEnv->FFI_GetURL(this, wsDocURL);\r
 }\r
 \r
-FX_ARGB        CPDFXFA_Document::GetHighlightColor(XFA_HDOC hDoc)\r
+FX_ARGB        CPDFXFA_Document::GetHighlightColor(IXFA_Doc* hDoc)\r
 {\r
        if (hDoc != m_pXFADoc)\r
                return 0;\r
@@ -1074,7 +1039,7 @@ void CPDFXFA_Document::_OnAfterNotifySumbit()
        m_pXFADocView->UpdateDocView();\r
 }\r
 \r
-FX_BOOL CPDFXFA_Document::SubmitData(XFA_HDOC hDoc, CXFA_Submit submit)\r
+FX_BOOL CPDFXFA_Document::SubmitData(IXFA_Doc* hDoc, CXFA_Submit submit)\r
 {\r
        if (!_NotifySubmit(TRUE))\r
                return FALSE;\r
@@ -1087,7 +1052,7 @@ FX_BOOL CPDFXFA_Document::SubmitData(XFA_HDOC hDoc, CXFA_Submit submit)
        return ret;\r
 }\r
 \r
-IFX_FileRead* CPDFXFA_Document::OpenLinkedFile(XFA_HDOC hDoc, const CFX_WideString& wsLink)\r
+IFX_FileRead* CPDFXFA_Document::OpenLinkedFile(IXFA_Doc* hDoc, const CFX_WideString& wsLink)\r
 {\r
        CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();\r
        if (pEnv == NULL)\r
@@ -1306,13 +1271,13 @@ FX_BOOL CPDFXFA_Document::_MailToInfo(CFX_WideString& csURL, CFX_WideString& csT
                else\r
                        srcURL = srcURL.Right(csURL.GetLength()-(pos+1));\r
        }\r
-       csToAddress.Replace((FX_LPCWSTR)L",", (FX_LPCWSTR)L";");\r
-       csCCAddress.Replace((FX_LPCWSTR)L",", (FX_LPCWSTR)L";");\r
-       csBCCAddress.Replace((FX_LPCWSTR)L",", (FX_LPCWSTR)L";");\r
+       csToAddress.Replace(L",", L";");\r
+       csCCAddress.Replace(L",", L";");\r
+       csBCCAddress.Replace(L",", L";");\r
        return TRUE;\r
 }\r
 \r
-FX_BOOL CPDFXFA_Document::_SubmitData(XFA_HDOC hDoc, CXFA_Submit submit)\r
+FX_BOOL CPDFXFA_Document::_SubmitData(IXFA_Doc* hDoc, CXFA_Submit submit)\r
 {\r
        CFX_WideStringC csURLC;\r
        submit.GetSubmitTarget(csURLC);\r
@@ -1427,7 +1392,7 @@ FX_BOOL CPDFXFA_Document::_SubmitData(XFA_HDOC hDoc, CXFA_Submit submit)
        return bRet;\r
 }\r
 \r
-FX_BOOL        CPDFXFA_Document::SetGlobalProperty(XFA_HDOC hDoc, FX_BSTR szPropName, FXJSE_HVALUE hValue)\r
+FX_BOOL        CPDFXFA_Document::SetGlobalProperty(IXFA_Doc* hDoc, FX_BSTR szPropName, FXJSE_HVALUE hValue)\r
 {\r
        if (hDoc != m_pXFADoc)\r
                return FALSE;\r
@@ -1436,7 +1401,7 @@ FX_BOOL   CPDFXFA_Document::SetGlobalProperty(XFA_HDOC hDoc, FX_BSTR szPropName, F
                return m_pSDKDoc->GetEnv()->GetJSRuntime()->SetHValueByName(szPropName, hValue);\r
        return FALSE;\r
 }\r
-FX_BOOL        CPDFXFA_Document::GetPDFScriptObject(XFA_HDOC hDoc, FX_BSTR utf8Name, FXJSE_HVALUE hValue)\r
+FX_BOOL        CPDFXFA_Document::GetPDFScriptObject(IXFA_Doc* hDoc, FX_BSTR utf8Name, FXJSE_HVALUE hValue)\r
 {\r
        if (hDoc != m_pXFADoc)\r
                return FALSE;\r
@@ -1453,7 +1418,7 @@ FX_BOOL   CPDFXFA_Document::GetPDFScriptObject(XFA_HDOC hDoc, FX_BSTR utf8Name, FX
        return _GetHValueByName(utf8Name, hValue, m_pSDKDoc->GetEnv()->GetJSRuntime());\r
 \r
 }\r
-FX_BOOL CPDFXFA_Document::GetGlobalProperty(XFA_HDOC hDoc, FX_BSTR szPropName, FXJSE_HVALUE hValue)\r
+FX_BOOL CPDFXFA_Document::GetGlobalProperty(IXFA_Doc* hDoc, FX_BSTR szPropName, FXJSE_HVALUE hValue)\r
 {\r
        if (hDoc != m_pXFADoc)\r
                return FALSE;\r