Merge XFA to PDFium master at 4dc95e7 on 10/28/2014
[pdfium.git] / fpdfsdk / src / fpdfxfa / fpdfxfa_util.cpp
1 // Copyright 2014 PDFium Authors. All rights reserved.\r
2 // Use of this source code is governed by a BSD-style license that can be\r
3 // found in the LICENSE file.\r
4  \r
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com\r
6 \r
7 #include "../../include/fsdk_define.h"\r
8 #include "../../include/fsdk_mgr.h"\r
9 #include "../../include/fpdfxfa/fpdfxfa_util.h"\r
10 \r
11 FX_BOOL FPDF_HasXFAField(CPDF_Document* pPDFDoc, int& docType)\r
12 {\r
13         if (!pPDFDoc)\r
14                 return FALSE;\r
15 \r
16         CPDF_Dictionary* pRoot = pPDFDoc->GetRoot();\r
17         if (!pRoot)\r
18                 return FALSE;\r
19 \r
20         CPDF_Dictionary* pAcroForm = pRoot->GetDict("AcroForm");\r
21         if (!pAcroForm) \r
22                 return FALSE;\r
23 \r
24         CPDF_Object* pXFA = pAcroForm->GetElement("XFA");\r
25         if (!pXFA) \r
26                 return FALSE;\r
27 \r
28         FX_BOOL bDymasticXFA = FALSE;\r
29         bDymasticXFA = pRoot->GetBoolean("NeedsRendering", FALSE);\r
30 \r
31         if(bDymasticXFA)\r
32                 docType = DOCTYPE_DYNIMIC_XFA;\r
33         else\r
34                 docType = DOCTYPE_STATIC_XFA;\r
35 \r
36         return TRUE;\r
37 }\r
38 \r
39 CFX_PtrArray CXFA_FWLAdapterTimerMgr::ms_timerArray;\r
40 \r
41 FWL_ERR CXFA_FWLAdapterTimerMgr::Start(IFWL_Timer *pTimer, FX_DWORD dwElapse, FWL_HTIMER &hTimer, FX_BOOL bImmediately /* = TRUE */)\r
42 {\r
43         if (m_pEnv)\r
44         {\r
45                 FX_UINT32 uIDEvent = m_pEnv->FFI_SetTimer(dwElapse, TimerProc);\r
46                 CFWL_TimerInfo *pInfo = FX_NEW CFWL_TimerInfo;\r
47                 pInfo->uIDEvent = uIDEvent;\r
48                 pInfo->pTimer = pTimer;\r
49                 ms_timerArray.Add(pInfo);\r
50 \r
51                 hTimer = (FWL_HTIMER)pInfo;\r
52                 return FWL_ERR_Succeeded;\r
53         }\r
54         \r
55         return FWL_ERR_Indefinite;\r
56 }\r
57 \r
58 FWL_ERR CXFA_FWLAdapterTimerMgr::Stop(FWL_HTIMER hTimer)\r
59 {\r
60         if (!hTimer) return FWL_ERR_Indefinite;\r
61 \r
62         if (m_pEnv)\r
63         {\r
64                 CFWL_TimerInfo *pInfo = (CFWL_TimerInfo*)hTimer;\r
65 \r
66                 m_pEnv->FFI_KillTimer(pInfo->uIDEvent);\r
67 \r
68                 FX_INT32 index = ms_timerArray.Find(pInfo);\r
69                 if (index >= 0)\r
70                 {\r
71                         ms_timerArray.RemoveAt(index);\r
72                         delete pInfo;\r
73                 }\r
74                 return FWL_ERR_Succeeded;\r
75         }\r
76 \r
77         return FWL_ERR_Indefinite;\r
78 }\r
79 \r
80 void CXFA_FWLAdapterTimerMgr::TimerProc(FX_INT32 idEvent)\r
81 {\r
82         CFWL_TimerInfo *pInfo = NULL;\r
83         FX_INT32 iCount = CXFA_FWLAdapterTimerMgr::ms_timerArray.GetSize();\r
84         for (FX_INT32 i = 0; i < iCount; i++)\r
85         {\r
86                 CFWL_TimerInfo *pTemp = (CFWL_TimerInfo*)CXFA_FWLAdapterTimerMgr::ms_timerArray.GetAt(i);\r
87                 if (pTemp->uIDEvent == idEvent)\r
88                 {\r
89                         pInfo = pTemp; break;\r
90                 }\r
91         }\r
92         if (pInfo)\r
93         {\r
94                 pInfo->pTimer->Run((FWL_HTIMER)pInfo);\r
95         }\r
96 }\r