summaryrefslogtreecommitdiff
path: root/fpdfsdk/src/fpdfxfa/fpdfxfa_util.cpp
blob: 9bf1b63c8f0a069b9b75276f3e223378d65ae9f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
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);
	}
}