blob: 1169d79a22bb98ff3b1da112fb6fe2555e86cf0a [file] [log] [blame]
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001// Copyright 2014 PDFium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Lei Zhang60f507b2015-06-13 00:41:00 -07004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
Tom Sepez1ed8a212015-05-11 15:25:39 -07007#include "../../public/fpdf_ext.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07008#include "../include/fsdk_define.h"
Bo Xufdc00a72014-10-28 23:03:33 -07009#include "../include/fpdfxfa/fpdfxfa_doc.h"
10#include "../include/fpdfxfa/fpdfxfa_page.h"
11#include "../include/fpdfxfa/fpdfxfa_util.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070012#include "../include/fsdk_mgr.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070013#include "../include/formfiller/FFL_FormFiller.h"
14#include "../include/javascript/IJavaScript.h"
Bo Xufdc00a72014-10-28 23:03:33 -070015#include "../include/fpdfxfa/fpdfxfa_app.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070016
17#if _FX_OS_ == _FX_ANDROID_
18#include "time.h"
19#else
20#include <ctime>
21#endif
22
23//extern CPDFDoc_Environment* g_pFormFillApp;
24class CFX_SystemHandler:public IFX_SystemHandler
25{
26public:
27 CFX_SystemHandler(CPDFDoc_Environment* pEnv):m_pEnv(pEnv),m_nCharSet(-1) {}
28public:
29 virtual void InvalidateRect(FX_HWND hWnd, FX_RECT rect) ;
30 virtual void OutputSelectedRect(void* pFormFiller, CPDF_Rect& rect);
31
32 virtual FX_BOOL IsSelectionImplemented();
33
34 virtual CFX_WideString GetClipboardText(FX_HWND hWnd){return L"";}
35 virtual FX_BOOL SetClipboardText(FX_HWND hWnd, CFX_WideString string) {return FALSE;}
Lei Zhang60f507b2015-06-13 00:41:00 -070036
Tom Sepezbfa9a822015-06-09 13:24:12 -070037 virtual void ClientToScreen(FX_HWND hWnd, int32_t& x, int32_t& y) {}
38 virtual void ScreenToClient(FX_HWND hWnd, int32_t& x, int32_t& y) {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070039
40 /*cursor style
Lei Zhang60f507b2015-06-13 00:41:00 -070041 FXCT_ARROW
42 FXCT_NESW
43 FXCT_NWSE
44 FXCT_VBEAM
45 FXCT_HBEAM
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070046 FXCT_HAND
47 */
Tom Sepezbfa9a822015-06-09 13:24:12 -070048 virtual void SetCursor(int32_t nCursorType);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070049
50 virtual FX_HMENU CreatePopupMenu() {return NULL;}
Tom Sepezbfa9a822015-06-09 13:24:12 -070051 virtual FX_BOOL AppendMenuItem(FX_HMENU hMenu, int32_t nIDNewItem, CFX_WideString string) {return FALSE;}
52 virtual FX_BOOL EnableMenuItem(FX_HMENU hMenu, int32_t nIDItem, FX_BOOL bEnabled) {return FALSE;}
53 virtual int32_t TrackPopupMenu(FX_HMENU hMenu, int32_t x, int32_t y, FX_HWND hParent) {return -1;}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070054 virtual void DestroyMenu(FX_HMENU hMenu) {}
55
Tom Sepezbfa9a822015-06-09 13:24:12 -070056 virtual CFX_ByteString GetNativeTrueTypeFont(int32_t nCharset);
57 virtual FX_BOOL FindNativeTrueTypeFont(int32_t nCharset, CFX_ByteString sFontFaceName);
58 virtual CPDF_Font* AddNativeTrueTypeFontToPDF(CPDF_Document* pDoc, CFX_ByteString sFontFaceName, uint8_t nCharset);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070059
Tom Sepezbfa9a822015-06-09 13:24:12 -070060 virtual int32_t SetTimer(int32_t uElapse, TimerCallback lpTimerFunc) ;
61 virtual void KillTimer(int32_t nID) ;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070062
63
64 virtual FX_BOOL IsSHIFTKeyDown(FX_DWORD nFlag) {return m_pEnv->FFI_IsSHIFTKeyDown(nFlag);}
65 virtual FX_BOOL IsCTRLKeyDown(FX_DWORD nFlag) {return m_pEnv->FFI_IsCTRLKeyDown(nFlag);}
66 virtual FX_BOOL IsALTKeyDown(FX_DWORD nFlag) {return m_pEnv->FFI_IsALTKeyDown(nFlag);}
67 virtual FX_BOOL IsINSERTKeyDown(FX_DWORD nFlag) {return m_pEnv->FFI_IsINSERTKeyDown(nFlag);}
68
69 virtual FX_SYSTEMTIME GetLocalTime();
70
Tom Sepezbfa9a822015-06-09 13:24:12 -070071 virtual int32_t GetCharSet() {return m_nCharSet;}
72 virtual void SetCharSet(int32_t nCharSet) {m_nCharSet = nCharSet;}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070073private:
74 CPDFDoc_Environment* m_pEnv;
75 int m_nCharSet;
76};
77
Tom Sepezbfa9a822015-06-09 13:24:12 -070078void CFX_SystemHandler::SetCursor(int32_t nCursorType)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070079{
80
81 m_pEnv->FFI_SetCursor(nCursorType);
82}
83
84void CFX_SystemHandler::InvalidateRect(FX_HWND hWnd, FX_RECT rect)
85{
86 //g_pFormFillApp->FFI_Invalidate();
87 CPDFSDK_Annot* pSDKAnnot = (CPDFSDK_Annot*)hWnd;
Bo Xufdc00a72014-10-28 23:03:33 -070088 CPDFXFA_Page* pPage = NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070089 CPDFSDK_PageView* pPageView = NULL;
90 pPageView = pSDKAnnot->GetPageView();
Bo Xufdc00a72014-10-28 23:03:33 -070091 pPage = pSDKAnnot->GetPDFXFAPage();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070092 if(!pPage || !pPageView)
93 return;
94 CPDF_Matrix page2device;
95 pPageView->GetCurrentMatrix(page2device);
96 CPDF_Matrix device2page;
97 device2page.SetReverse(page2device);
98 FX_FLOAT left, top, right,bottom;
99 device2page.Transform((FX_FLOAT)rect.left, (FX_FLOAT)rect.top, left, top);
100 device2page.Transform((FX_FLOAT)rect.right, (FX_FLOAT)rect.bottom, right, bottom);
101// m_pEnv->FFI_DeviceToPage(pPage, rect.left, rect.top, (double*)&left, (double*)&top);
102// m_pEnv->FFI_DeviceToPage(pPage, rect.right, rect.bottom, (double*)&right, (double*)&bottom);
103 CPDF_Rect rcPDF(left, bottom, right, top);
104 rcPDF.Normalize();
105
106 m_pEnv->FFI_Invalidate(pPage, rcPDF.left, rcPDF.top, rcPDF.right, rcPDF.bottom);
107}
108void CFX_SystemHandler::OutputSelectedRect(void* pFormFiller, CPDF_Rect& rect)
109{
110 CFFL_FormFiller* pFFL = (CFFL_FormFiller*)pFormFiller;
111 if(pFFL)
112 {
113 CPDF_Point leftbottom = CPDF_Point(rect.left, rect.bottom);
114 CPDF_Point righttop = CPDF_Point(rect.right, rect.top);
115 CPDF_Point ptA = pFFL->PWLtoFFL(leftbottom);
Lei Zhang60f507b2015-06-13 00:41:00 -0700116 CPDF_Point ptB = pFFL->PWLtoFFL(righttop);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700117
118
119 CPDFSDK_Annot* pAnnot = pFFL->GetSDKAnnot();
120 ASSERT(pAnnot);
Bo Xufdc00a72014-10-28 23:03:33 -0700121 CPDFXFA_Page* pPage = pAnnot->GetPDFXFAPage();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700122 ASSERT(pPage);
123 m_pEnv->FFI_OutputSelectedRect(pPage, ptA.x, ptB.y, ptB.x, ptA.y);
124 }
Lei Zhang60f507b2015-06-13 00:41:00 -0700125
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700126}
127
128FX_BOOL CFX_SystemHandler::IsSelectionImplemented()
129{
130 if(m_pEnv)
131 {
132 FPDF_FORMFILLINFO* pInfo = m_pEnv->GetFormFillInfo();
133 if(pInfo && pInfo->FFI_OutputSelectedRect)
134 return TRUE;
135 }
136 return FALSE;
137}
138
Tom Sepezbfa9a822015-06-09 13:24:12 -0700139CFX_ByteString CFX_SystemHandler::GetNativeTrueTypeFont(int32_t nCharset)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700140{
141 return "";
142}
143
Lei Zhang60f507b2015-06-13 00:41:00 -0700144FX_BOOL CFX_SystemHandler::FindNativeTrueTypeFont(int32_t nCharset, CFX_ByteString sFontFaceName)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700145{
146 CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr();
147// FXFT_Face nFace = pFontMgr->FindSubstFont(sFontFaceName,TRUE,0,0,0,0,NULL);
148// FXFT_Face nFace = pFontMgr->m_pBuiltinMapper->FindSubstFont(sFontFaceName,TRUE,0,0,0,0,NULL);
149
150 if(pFontMgr)
151 {
152 CFX_FontMapper* pFontMapper = pFontMgr->m_pBuiltinMapper;
153 if(pFontMapper)
Lei Zhang60f507b2015-06-13 00:41:00 -0700154 {
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700155 int nSize = pFontMapper->m_InstalledTTFonts.GetSize();
156 if(nSize ==0)
157 {
158 pFontMapper->LoadInstalledFonts();
159 nSize = pFontMapper->m_InstalledTTFonts.GetSize();
160 }
Lei Zhang60f507b2015-06-13 00:41:00 -0700161
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700162 for(int i=0; i<nSize; i++)
163 {
164 if(pFontMapper->m_InstalledTTFonts[i].Compare(sFontFaceName))
165 return TRUE;
166 }
167 }
168
169 }
170
171 return FALSE;
172// pFontMgr->m_FaceMap.Lookup(sFontFaceName,pFont);
173// return (pFont!=NULL);
174}
175
176static int CharSet2CP(int charset)
177{
178 if(charset == 128)
179 return 932;
180 else if(charset == 134)
181 return 936;
182 else if(charset == 129)
183 return 949;
184 else if(charset == 136)
185 return 950;
186 return 0;
187}
Lei Zhang60f507b2015-06-13 00:41:00 -0700188CPDF_Font* CFX_SystemHandler::AddNativeTrueTypeFontToPDF(CPDF_Document* pDoc, CFX_ByteString sFontFaceName,
189 uint8_t nCharset)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700190{
191 if(pDoc)
192 {
193 CFX_Font* pFXFont = new CFX_Font();
194 pFXFont->LoadSubst(sFontFaceName,TRUE,0,0,0,CharSet2CP(nCharset),FALSE);
195 CPDF_Font* pFont = pDoc->AddFont(pFXFont,nCharset,FALSE);
196 delete pFXFont;
197 return pFont;
198 }
199
200 return NULL;
201}
202
203
Tom Sepezbfa9a822015-06-09 13:24:12 -0700204int32_t CFX_SystemHandler::SetTimer(int32_t uElapse, TimerCallback lpTimerFunc)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700205{
206 return m_pEnv->FFI_SetTimer(uElapse, lpTimerFunc);
207}
Tom Sepezbfa9a822015-06-09 13:24:12 -0700208void CFX_SystemHandler::KillTimer(int32_t nID)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700209{
210 m_pEnv->FFI_KillTimer(nID);
211}
212
213FX_SYSTEMTIME CFX_SystemHandler::GetLocalTime()
214{
215 return m_pEnv->FFI_GetLocalTime();
216}
217
Bo Xufdc00a72014-10-28 23:03:33 -0700218CPDFDoc_Environment::CPDFDoc_Environment(CPDFXFA_Document* pDoc) :
Nico Weber09363c82014-07-31 10:07:04 -0700219 m_pAnnotHandlerMgr(NULL),
220 m_pActionHandler(NULL),
221 m_pJSRuntime(NULL),
222 m_pInfo(NULL),
223 m_pSDKDoc(NULL),
Bo Xufdc00a72014-10-28 23:03:33 -0700224 m_pDoc(pDoc),
Nico Weber09363c82014-07-31 10:07:04 -0700225 m_pIFormFiller(NULL)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700226{
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700227 m_pSysHandler = NULL;
228 m_pSysHandler = new CFX_SystemHandler(this);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700229}
230
231CPDFDoc_Environment::~CPDFDoc_Environment()
232{
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700233 delete m_pIFormFiller;
234 m_pIFormFiller = NULL;
Bo Xufdc00a72014-10-28 23:03:33 -0700235
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700236 CPDFXFA_App* pProvider = CPDFXFA_App::GetInstance();
237 if (m_pJSRuntime && pProvider->GetRuntimeFactory())
238 pProvider->GetRuntimeFactory()->DeleteJSRuntime(m_pJSRuntime);
Bo Xufdc00a72014-10-28 23:03:33 -0700239
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700240 if (pProvider->m_pEnvList.GetSize() == 0)
241 {
242 pProvider->ReleaseRuntime();
243 pProvider->InitRuntime(TRUE);
244 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700245
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700246 delete m_pSysHandler;
247 m_pSysHandler = NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700248
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700249 delete m_pAnnotHandlerMgr;
250 m_pAnnotHandlerMgr = NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700251
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700252 delete m_pActionHandler;
253 m_pActionHandler = NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700254}
255
256
257IFXJS_Runtime* CPDFDoc_Environment::GetJSRuntime()
258{
259 if(!IsJSInitiated())
260 return NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700261 if(!m_pJSRuntime)
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700262 m_pJSRuntime = CPDFXFA_App::GetInstance()->GetRuntimeFactory()->NewJSRuntime(this);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700263 return m_pJSRuntime;
264}
265
266CPDFSDK_AnnotHandlerMgr* CPDFDoc_Environment::GetAnnotHandlerMgr()
267{
268 if(!m_pAnnotHandlerMgr)
269 m_pAnnotHandlerMgr = new CPDFSDK_AnnotHandlerMgr(this);
270 return m_pAnnotHandlerMgr;
271}
272
273CPDFSDK_ActionHandler* CPDFDoc_Environment::GetActionHander()
274{
275 if(!m_pActionHandler)
276 m_pActionHandler = new CPDFSDK_ActionHandler(this);
277 return m_pActionHandler;
278}
279
280int CPDFDoc_Environment::RegAppHandle(FPDF_FORMFILLINFO* pFFinfo)
281{
Lei Zhang60f507b2015-06-13 00:41:00 -0700282 m_pInfo = pFFinfo;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700283 return TRUE;
284}
285
286CPDFSDK_Document* CPDFDoc_Environment::GetCurrentDoc()
287{
288 return m_pSDKDoc;
289}
290
291CFFL_IFormFiller* CPDFDoc_Environment::GetIFormFiller()
292{
293 if(!m_pIFormFiller)
294 m_pIFormFiller = new CFFL_IFormFiller(this);
295 return m_pIFormFiller;
296}
297
298FX_BOOL CPDFDoc_Environment::IsJSInitiated()
299{
300 if(m_pInfo)
301 {
302 if(m_pInfo->m_pJsPlatform)
303 return TRUE;
304 else
305 return FALSE;
306 }
307 return FALSE;
308}
309
Bo Xufdc00a72014-10-28 23:03:33 -0700310CPDFSDK_Document::CPDFSDK_Document(CPDFXFA_Document* pDoc,CPDFDoc_Environment* pEnv):m_pDoc(pDoc),
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700311 m_pInterForm(NULL),m_pEnv(pEnv),m_pOccontent(NULL),m_bChangeMask(FALSE)
312{
313 m_pFocusAnnot = NULL;
314}
315
316CPDFSDK_Document::~CPDFSDK_Document()
317{
Lei Zhang606346f2015-06-19 18:11:07 -0700318 for (auto& it : m_pageMap)
319 delete it.second;
320 m_pageMap.clear();
Tom Sepez2c286192015-06-18 12:47:11 -0700321
322 delete m_pInterForm;
323 m_pInterForm = nullptr;
324
325 delete m_pOccontent;
326 m_pOccontent = nullptr;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700327}
328
Bo Xufdc00a72014-10-28 23:03:33 -0700329CPDFSDK_PageView* CPDFSDK_Document::GetPageView(CPDFXFA_Page* pPDFXFAPage, FX_BOOL ReNew)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700330{
Lei Zhang606346f2015-06-19 18:11:07 -0700331 auto it = m_pageMap.find(pPDFXFAPage);
332 if (it != m_pageMap.end())
333 return it->second;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700334
Lei Zhang606346f2015-06-19 18:11:07 -0700335 if (!ReNew)
336 return nullptr;
337
338 CPDFSDK_PageView* pPageView = new CPDFSDK_PageView(this, pPDFXFAPage);
339 m_pageMap[pPDFXFAPage] = pPageView;
340 // Delay to load all the annotations, to avoid endless loop.
341 pPageView->LoadFXAnnots();
342 return pPageView;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700343}
344
345CPDFSDK_PageView* CPDFSDK_Document::GetCurrentView()
346{
Lei Zhang60f507b2015-06-13 00:41:00 -0700347 CPDFXFA_Page* pPage = (CPDFXFA_Page *)m_pEnv->FFI_GetCurrentPage(m_pDoc);
348 return pPage ? GetPageView(pPage, TRUE) : nullptr;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700349}
350
351CPDFSDK_PageView* CPDFSDK_Document::GetPageView(int nIndex)
352{
Lei Zhang606346f2015-06-19 18:11:07 -0700353 CPDFXFA_Page* pTempPage =
354 (CPDFXFA_Page*)m_pEnv->FFI_GetPage(m_pDoc, nIndex);
355 if (!pTempPage)
356 return nullptr;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700357
Lei Zhang606346f2015-06-19 18:11:07 -0700358 auto it = m_pageMap.find(pTempPage);
359 return it->second;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700360}
361
362void CPDFSDK_Document:: ProcJavascriptFun()
363{
Lei Zhang60f507b2015-06-13 00:41:00 -0700364 CPDFXFA_Document* pPDFDoc = GetDocument();
Bo Xufdc00a72014-10-28 23:03:33 -0700365 CPDF_DocJSActions docJS(pPDFDoc->GetPDFDoc());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700366 int iCount = docJS.CountJSActions();
367 if (iCount < 1) return;
368 for (int i = 0; i < iCount; i ++)
369 {
370 CFX_ByteString csJSName;
371 CPDF_Action jsAction = docJS.GetJSAction(i, csJSName);
372 if(m_pEnv->GetActionHander())
373 m_pEnv->GetActionHander()->DoAction_JavaScript(jsAction,CFX_WideString::FromLocal(csJSName),this);
374 }
Lei Zhang60f507b2015-06-13 00:41:00 -0700375
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700376}
377
378FX_BOOL CPDFSDK_Document::ProcOpenAction()
379{
Tom Sepez7b5bc262015-03-05 16:44:22 -0800380 if(!m_pDoc)
381 return FALSE;
382
383 CPDF_Dictionary* pRoot = m_pDoc->GetPDFDoc()->GetRoot();
384 if (!pRoot)
385 return FALSE;
386
387 CPDF_Object* pOpenAction = pRoot->GetDict("OpenAction");
388 if(!pOpenAction)
389 pOpenAction = pRoot->GetArray("OpenAction");
390
391 if(!pOpenAction)
392 return FALSE;
393
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700394 if(pOpenAction->GetType()==PDFOBJ_ARRAY)
Tom Sepez7b5bc262015-03-05 16:44:22 -0800395 return TRUE;
396
397 if(pOpenAction->GetType()==PDFOBJ_DICTIONARY)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700398 {
Tom Sepez7b5bc262015-03-05 16:44:22 -0800399 CPDF_Dictionary * pDict=(CPDF_Dictionary*)pOpenAction;
400 CPDF_Action action(pDict);
401 if(m_pEnv->GetActionHander())
402 m_pEnv->GetActionHander()->DoAction_DocOpen(action, this);
403 return TRUE;
404 }
405 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700406}
407
408CPDF_OCContext* CPDFSDK_Document::GetOCContext()
409{
410 if(!m_pOccontent)
Bo Xufdc00a72014-10-28 23:03:33 -0700411 m_pOccontent = new CPDF_OCContext(m_pDoc->GetPDFDoc());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700412 return m_pOccontent;
413}
414
Bo Xufdc00a72014-10-28 23:03:33 -0700415void CPDFSDK_Document::ReMovePageView(CPDFXFA_Page* pPDFXFAPage)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700416{
Lei Zhang606346f2015-06-19 18:11:07 -0700417 auto it = m_pageMap.find(pPDFXFAPage);
418 if (it == m_pageMap.end())
419 return;
420
421 CPDFSDK_PageView* pPageView = it->second;
422 if (pPageView->IsLocked())
423 return;
424
425 delete pPageView;
426 m_pageMap.erase(it);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700427}
428
Bo Xufdc00a72014-10-28 23:03:33 -0700429CPDFXFA_Page * CPDFSDK_Document::GetPage(int nIndex)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700430{
Bo Xufdc00a72014-10-28 23:03:33 -0700431 CPDFXFA_Page * pTempPage = (CPDFXFA_Page*)m_pEnv->FFI_GetPage(m_pDoc,nIndex);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700432 if(!pTempPage)
433 return NULL;
434 return pTempPage;
435}
436
437CPDFSDK_InterForm* CPDFSDK_Document::GetInterForm()
438{
439 if(!m_pInterForm)
440 m_pInterForm = new CPDFSDK_InterForm(this);
441 return m_pInterForm;
442}
443
444void CPDFSDK_Document::UpdateAllViews(CPDFSDK_PageView* pSender, CPDFSDK_Annot* pAnnot)
445{
Lei Zhang606346f2015-06-19 18:11:07 -0700446 for (const auto& it : m_pageMap) {
447 CPDFSDK_PageView* pPageView = it.second;
448 if (pPageView != pSender) {
449 pPageView->UpdateView(pAnnot);
450 }
451 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700452}
453
454CPDFSDK_Annot* CPDFSDK_Document::GetFocusAnnot()
455{
Lei Zhang60f507b2015-06-13 00:41:00 -0700456 return m_pFocusAnnot;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700457}
458
459FX_BOOL CPDFSDK_Document::SetFocusAnnot(CPDFSDK_Annot* pAnnot,FX_UINT nFlag)
460{
461
462 if(m_pFocusAnnot==pAnnot) return TRUE;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700463
Bo Xufdc00a72014-10-28 23:03:33 -0700464 CPDFSDK_Annot* pLastFocusAnnot = m_pFocusAnnot;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700465
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700466 if(m_pFocusAnnot)
467 {
Lei Zhang60f507b2015-06-13 00:41:00 -0700468 if(!KillFocusAnnot(nFlag) ) return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700469 }
Bo Xufdc00a72014-10-28 23:03:33 -0700470 CPDFSDK_PageView* pPageView = NULL;
471 if (pAnnot)
472 pPageView = pAnnot->GetPageView();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700473 if(pAnnot && pPageView->IsValid())
474 {
475 CPDFSDK_AnnotHandlerMgr *pAnnotHandler=m_pEnv->GetAnnotHandlerMgr();
476
477 if(pAnnotHandler&&!m_pFocusAnnot)
478 {
Bo Xufdc00a72014-10-28 23:03:33 -0700479 if (!pAnnotHandler->Annot_OnChangeFocus(pAnnot,pLastFocusAnnot))
480 return FALSE;
481
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700482 if (!pAnnotHandler->Annot_OnSetFocus(pAnnot,nFlag))
483 return FALSE;
484 if(!m_pFocusAnnot)
485 {
Lei Zhang60f507b2015-06-13 00:41:00 -0700486 m_pFocusAnnot=pAnnot;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700487 return TRUE;
488 }
Lei Zhang60f507b2015-06-13 00:41:00 -0700489 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700490 }
491 return FALSE;
492}
493
494FX_BOOL CPDFSDK_Document::KillFocusAnnot(FX_UINT nFlag)
495{
496 if(m_pFocusAnnot)
497 {
498 CPDFSDK_AnnotHandlerMgr *pAnnotHandler=m_pEnv->GetAnnotHandlerMgr();
499 if(pAnnotHandler)
500 {
501 CPDFSDK_Annot* pFocusAnnot = m_pFocusAnnot;
502 m_pFocusAnnot = NULL;
Bo Xufdc00a72014-10-28 23:03:33 -0700503
504 if (!pAnnotHandler->Annot_OnChangeFocus(NULL, pFocusAnnot))
505 return FALSE;
506
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700507 if(pAnnotHandler->Annot_OnKillFocus(pFocusAnnot, nFlag))
508 {
Lei Zhang60f507b2015-06-13 00:41:00 -0700509
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700510 if(pFocusAnnot->GetType() == FX_BSTRC("Widget"))
511 {
512 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pFocusAnnot;
513 int nFieldType = pWidget->GetFieldType();
514 if(FIELDTYPE_TEXTFIELD == nFieldType || FIELDTYPE_COMBOBOX == nFieldType)
515 m_pEnv->FFI_OnSetFieldInputFocus(NULL, NULL, 0, FALSE);
516 }
517
518 if(!m_pFocusAnnot)
519 return TRUE;
520 }
521 else
522 {
523 m_pFocusAnnot = pFocusAnnot;
524 }
525 }
526 }
527 return FALSE;
528}
529
530FX_BOOL CPDFSDK_Document::DeletePages(int nStart, int nCount)
531{
532 if ( nStart < 0 || nStart >= GetPageCount() || nCount <= 0 )
533 {
534 return FALSE;
535 }
536
Bo Xufdc00a72014-10-28 23:03:33 -0700537 CPDFXFA_Page * pTempPage = NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700538 for ( int i = nCount-1; i >= 0; i-- )
539 {
540 pTempPage = GetPage(nStart+i);
541 if ( pTempPage != NULL )
542 {
543 ReMovePageView(pTempPage);
544 }
545 }
546 return TRUE;
547}
548
549void CPDFSDK_Document::OnCloseDocument()
550{
551 KillFocusAnnot();
552}
553
554FX_BOOL CPDFSDK_Document::GetPermissions(int nFlag)
555{
Bo Xufdc00a72014-10-28 23:03:33 -0700556 FX_DWORD dwPermissions = m_pDoc->GetPDFDoc()->GetUserPermissions();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700557 return dwPermissions&nFlag;
558}
559
560IFXJS_Runtime * CPDFSDK_Document::GetJsRuntime()
561{
562 ASSERT(m_pEnv!=NULL);
563 return m_pEnv->GetJSRuntime();
564}
565
Lei Zhang60f507b2015-06-13 00:41:00 -0700566CFX_WideString CPDFSDK_Document::GetPath()
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700567{
568 ASSERT(m_pEnv != NULL);
569 return m_pEnv->JS_docGetFilePath();
570}
571
572
Bo Xufdc00a72014-10-28 23:03:33 -0700573CPDFSDK_PageView::CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc,CPDFXFA_Page* page):m_page(page),m_pSDKDoc(pSDKDoc)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700574{
575 CPDFSDK_InterForm* pInterForm = pSDKDoc->GetInterForm();
576 if(pInterForm)
577 {
578 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm();
Bo Xufdc00a72014-10-28 23:03:33 -0700579 if (page->GetPDFPage())
580 pPDFInterForm->FixPageFields(page->GetPDFPage());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700581 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700582 m_fxAnnotArray.RemoveAll();
583
584 m_bEnterWidget = FALSE;
585 m_bExitWidget = FALSE;
586 m_bOnWidget = FALSE;
587 m_CaptureWidget = NULL;
588 m_bValid = FALSE;
unknown636ad3b2014-10-29 19:37:24 +0800589 m_bLocked = FALSE;
Bo Xufdc00a72014-10-28 23:03:33 -0700590 m_pAnnotList = NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700591}
592
593CPDFSDK_PageView::~CPDFSDK_PageView()
594{
Lei Zhang60f507b2015-06-13 00:41:00 -0700595 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700596 int nAnnotCount = m_fxAnnotArray.GetSize();
597 for (int i=0; i<nAnnotCount; i++)
598 {
599 CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i);
600 //if there is a focused annot on the page, we should kill the focus first.
601 if(pAnnot == m_pSDKDoc->GetFocusAnnot())
602 KillFocusAnnot();
603 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
604 ASSERT(pAnnotHandlerMgr);
605 pAnnotHandlerMgr->ReleaseAnnot(pAnnot);
606 }
607 m_fxAnnotArray.RemoveAll();
Lei Zhang6d8b1c22015-06-19 17:26:17 -0700608
609 delete m_pAnnotList;
610 m_pAnnotList = NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700611}
612
Bo Xufdc00a72014-10-28 23:03:33 -0700613void CPDFSDK_PageView::PageView_OnDraw(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,CPDF_RenderOptions* pOptions, FX_RECT* pClip)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700614{
615 m_curMatrix = *pUser2Device;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700616 // m_pAnnotList->DisplayAnnots(m_page, pDevice, pUser2Device, FALSE, pOptions);
617 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
Bo Xufdc00a72014-10-28 23:03:33 -0700618 CPDFXFA_Page* pPage = GetPDFXFAPage();
619
620 if (pPage == NULL) return;
621
622 if (pPage->GetDocument()->GetDocType() == DOCTYPE_DYNIMIC_XFA) {
623 CFX_Graphics gs;
624 gs.Create(pDevice);
625 if (pClip) {
626 CFX_RectF rectClip;
Bruce Dawson3f49aa32015-01-08 11:47:49 -0800627 rectClip.Set(static_cast<FX_FLOAT>(pClip->left),
628 static_cast<FX_FLOAT>(pClip->top),
629 static_cast<FX_FLOAT>(pClip->Width()),
630 static_cast<FX_FLOAT>(pClip->Height()));
Bo Xufdc00a72014-10-28 23:03:33 -0700631 gs.SetClipRect(rectClip);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700632 }
Bo Xufdc00a72014-10-28 23:03:33 -0700633 IXFA_RenderContext* pRenderContext = XFA_RenderContext_Create();
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700634 if (!pRenderContext)
Bo Xufdc00a72014-10-28 23:03:33 -0700635 return;
636 CXFA_RenderOptions renderOptions;
637 renderOptions.m_bHighlight = TRUE;
638 pRenderContext->StartRender(pPage->GetXFAPageView(), &gs, *pUser2Device, renderOptions);
639 pRenderContext->DoRender();
640 pRenderContext->StopRender();
641 pRenderContext->Release();
642 return;
643 }
644 // for pdf/static xfa.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700645 CPDFSDK_AnnotIterator annotIterator(this, TRUE);
646 CPDFSDK_Annot * pSDKAnnot=NULL;
647 int index=-1;
Bo Xufdc00a72014-10-28 23:03:33 -0700648 pSDKAnnot = annotIterator.Next(index);
649 while(pSDKAnnot)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700650 {
651 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
652 ASSERT(pAnnotHandlerMgr);
653 pAnnotHandlerMgr->Annot_OnDraw(this, pSDKAnnot, pDevice, pUser2Device, 0);
Bo Xufdc00a72014-10-28 23:03:33 -0700654 pSDKAnnot = annotIterator.Next(index);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700655 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700656}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700657CPDF_Annot* CPDFSDK_PageView::GetPDFAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY)
658{
Lei Zhang60f507b2015-06-13 00:41:00 -0700659
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700660 int nCount = m_pAnnotList->Count();
661 for(int i = 0 ; i<nCount; i++)
662 {
663 CPDF_Annot* pAnnot = m_pAnnotList->GetAt(i);
664 CFX_FloatRect annotRect;
665 pAnnot->GetRect(annotRect);
666 if(annotRect.Contains(pageX, pageY))
667 return pAnnot;
668 }
669 return NULL;
670}
671
672CPDF_Annot* CPDFSDK_PageView::GetPDFWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY)
673{
Lei Zhang60f507b2015-06-13 00:41:00 -0700674
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700675 int nCount = m_pAnnotList->Count();
676 for(int i = 0 ; i<nCount; i++)
677 {
678 CPDF_Annot* pAnnot = m_pAnnotList->GetAt(i);
679 if(pAnnot->GetSubType() == "Widget")
680 {
681 CFX_FloatRect annotRect;
682 pAnnot->GetRect(annotRect);
683 if(annotRect.Contains(pageX, pageY))
684 return pAnnot;
685 }
686 }
687 return NULL;
688}
689
690CPDFSDK_Annot* CPDFSDK_PageView::GetFXAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY)
691{
692
693 CPDFSDK_AnnotIterator annotIterator(this, FALSE);
694 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
695 CPDFSDK_AnnotHandlerMgr* pAnnotMgr = pEnv->GetAnnotHandlerMgr();
696 CPDFSDK_Annot* pSDKAnnot = NULL;
697 int index = -1;
Bo Xufdc00a72014-10-28 23:03:33 -0700698 pSDKAnnot = annotIterator.Next(index);
699 while(pSDKAnnot)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700700 {
701 CPDF_Rect rc = pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot);
702 if(rc.Contains(pageX, pageY))
703 return pSDKAnnot;
Bo Xufdc00a72014-10-28 23:03:33 -0700704 pSDKAnnot = annotIterator.Next(index);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700705 }
706
707 return NULL;
708}
709
710CPDFSDK_Annot* CPDFSDK_PageView::GetFXWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY)
711{
712
713 CPDFSDK_AnnotIterator annotIterator(this, FALSE);
714 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
715 CPDFSDK_AnnotHandlerMgr* pAnnotMgr = pEnv->GetAnnotHandlerMgr();
716 CPDFSDK_Annot* pSDKAnnot = NULL;
717 int index = -1;
Bo Xufdc00a72014-10-28 23:03:33 -0700718 pSDKAnnot = annotIterator.Next(index);
719 while(pSDKAnnot)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700720 {
Bo Xufdc00a72014-10-28 23:03:33 -0700721 if(pSDKAnnot->GetType() == "Widget" || pSDKAnnot->GetType() == FSDK_XFAWIDGET_TYPENAME)
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700722 {
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700723 pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot);
724 CPDF_Point point(pageX, pageY);
725 if (pAnnotMgr->Annot_OnHitTest(this, pSDKAnnot, point))
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700726 return pSDKAnnot;
727 }
Bo Xufdc00a72014-10-28 23:03:33 -0700728 pSDKAnnot = annotIterator.Next(index);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700729 }
Lei Zhang60f507b2015-06-13 00:41:00 -0700730
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700731 return NULL;
732}
733
734
735FX_BOOL CPDFSDK_PageView::Annot_HasAppearance(CPDF_Annot* pAnnot)
736{
Lei Zhang64adf192015-06-05 15:50:32 -0700737 CPDF_Dictionary* pAnnotDic = pAnnot->GetAnnotDict();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700738 if(pAnnotDic)
739 return pAnnotDic->KeyExist("AS");
740 return FALSE;
741}
742
743CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CPDF_Annot * pPDFAnnot)
744{
745 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
746 ASSERT(pEnv);
Lei Zhang60f507b2015-06-13 00:41:00 -0700747 CPDFSDK_AnnotHandlerMgr * pAnnotHandler= pEnv->GetAnnotHandlerMgr();
748
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700749 CPDFSDK_Annot* pSDKAnnot =NULL;
Lei Zhang60f507b2015-06-13 00:41:00 -0700750
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700751 if(pAnnotHandler)
752 {
753 pSDKAnnot = pAnnotHandler->NewAnnot(pPDFAnnot, this);
754 }
Lei Zhang60f507b2015-06-13 00:41:00 -0700755 if(!pSDKAnnot)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700756 return NULL;
757
Lei Zhang60f507b2015-06-13 00:41:00 -0700758 m_fxAnnotArray.Add(pSDKAnnot);
759
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700760 if(pAnnotHandler)
Lei Zhang60f507b2015-06-13 00:41:00 -0700761 {
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700762 pAnnotHandler->Annot_OnCreate(pSDKAnnot);
Lei Zhang60f507b2015-06-13 00:41:00 -0700763
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700764 }
765
766 return pSDKAnnot;
767}
768
Tom Sepezeed467d2015-06-02 10:35:27 -0700769CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(IXFA_Widget* pPDFAnnot)
Bo Xufdc00a72014-10-28 23:03:33 -0700770{
771 if (!pPDFAnnot) return NULL;
772
773 CPDFSDK_Annot* pSDKAnnot = GetAnnotByXFAWidget(pPDFAnnot);
774 if (pSDKAnnot)
775 return pSDKAnnot;
776
777 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
778 ASSERT(pEnv);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700779 CPDFSDK_AnnotHandlerMgr * pAnnotHandler= pEnv->GetAnnotHandlerMgr();
Bo Xufdc00a72014-10-28 23:03:33 -0700780
781 pSDKAnnot =NULL;
782
783 if(pAnnotHandler)
784 {
785 pSDKAnnot = pAnnotHandler->NewAnnot(pPDFAnnot, this);
786 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700787 if(!pSDKAnnot)
Bo Xufdc00a72014-10-28 23:03:33 -0700788 return NULL;
789
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700790 m_fxAnnotArray.Add(pSDKAnnot);
Bo Xufdc00a72014-10-28 23:03:33 -0700791
792 return pSDKAnnot;
793}
794
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700795CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CPDF_Dictionary * pDict)
796{
Lei Zhang60f507b2015-06-13 00:41:00 -0700797 return pDict ? AddAnnot(pDict->GetString("Subtype"), pDict) : nullptr;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700798}
799
Tom Sepezd7e5cc72015-06-10 14:33:37 -0700800CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(const FX_CHAR* lpSubType,CPDF_Dictionary * pDict)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700801{
802 return NULL;
803}
804
805FX_BOOL CPDFSDK_PageView::DeleteAnnot(CPDFSDK_Annot* pAnnot)
806{
Bo Xufdc00a72014-10-28 23:03:33 -0700807 if (!pAnnot)
808 return FALSE;
809 CPDFXFA_Page* pPage = pAnnot->GetPDFXFAPage();
810 if (!pPage || (pPage->GetDocument()->GetDocType() != DOCTYPE_STATIC_XFA && pPage->GetDocument()->GetDocType() != DOCTYPE_DYNIMIC_XFA))
811 return FALSE;
812
813 int index = m_fxAnnotArray.Find(pAnnot);
814 m_fxAnnotArray.RemoveAt(index);
815 if (m_CaptureWidget == pAnnot)
816 m_CaptureWidget = NULL;
817
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700818 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700819}
820
821CPDF_Document* CPDFSDK_PageView::GetPDFDocument()
822{
823 if(m_page)
824 {
Bo Xufdc00a72014-10-28 23:03:33 -0700825 return m_page->GetDocument()->GetPDFDoc();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700826 }
827 return NULL;
828}
829
Bo Xufdc00a72014-10-28 23:03:33 -0700830CPDF_Page* CPDFSDK_PageView::GetPDFPage()
831{
832 if (m_page)
833 {
834 return m_page->GetPDFPage();
835 }
836
837 return NULL;
838}
839
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700840int CPDFSDK_PageView::CountAnnots()
841{
Bo Xufdc00a72014-10-28 23:03:33 -0700842 return m_fxAnnotArray.GetSize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700843}
844
845CPDFSDK_Annot* CPDFSDK_PageView::GetAnnot(int nIndex)
846{
847 int nCount = m_fxAnnotArray.GetSize();
848 if ( nIndex < 0 || nIndex >= nCount )
849 {
850 return NULL;
851 }
852
853 return (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(nIndex);
854}
855
856CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByDict(CPDF_Dictionary * pDict)
857{
858 int nCount = m_fxAnnotArray.GetSize();
859 for(int i=0; i<nCount; i++)
860 {
861 CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i);
Lei Zhang64adf192015-06-05 15:50:32 -0700862 if (pDict == pAnnot->GetPDFAnnot()->GetAnnotDict())
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700863 return pAnnot;
864 }
865 return NULL;
866}
Tom Sepezeed467d2015-06-02 10:35:27 -0700867CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByXFAWidget(IXFA_Widget* hWidget)
Bo Xufdc00a72014-10-28 23:03:33 -0700868{
869 if (hWidget == NULL)
870 return NULL;
871 int annotCount = m_fxAnnotArray.GetSize();
872
873 for(int i = 0; i < annotCount; i++)
874 {
875 CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i);
876 if(pAnnot->GetXFAWidget() == hWidget)
877 return pAnnot;
878 }
879 return NULL;
880}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700881
882FX_BOOL CPDFSDK_PageView::OnLButtonDown(const CPDF_Point & point, FX_UINT nFlag)
883{
884 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
885 ASSERT(pEnv);
886 CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y);
887 if(!pFXAnnot)
888 {
889 KillFocusAnnot(nFlag);
890 }
891 else
892 {
893 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
894 ASSERT(pAnnotHandlerMgr);
895
896 FX_BOOL bRet = pAnnotHandlerMgr->Annot_OnLButtonDown(this, pFXAnnot, nFlag,point);
897 if(bRet)
898 {
899 SetFocusAnnot(pFXAnnot);
900 }
901 return bRet;
902 }
903 return FALSE;
904}
905
Bo Xufdc00a72014-10-28 23:03:33 -0700906FX_BOOL CPDFSDK_PageView::OnRButtonDown(const CPDF_Point & point, FX_UINT nFlag)
907{
908 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
909 ASSERT(pEnv);
910 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
911 ASSERT(pAnnotHandlerMgr);
912
913 CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y);
914
915 if (pFXAnnot == NULL)
916 return FALSE;
917
918 FX_BOOL bRet = pAnnotHandlerMgr->Annot_OnRButtonDown(this, pFXAnnot, nFlag,point);
919 if (bRet)
920 {
921 SetFocusAnnot(pFXAnnot);
922 }
923 return TRUE;
924}
925
926FX_BOOL CPDFSDK_PageView::OnRButtonUp(const CPDF_Point & point, FX_UINT nFlag)
927{
928 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
929 ASSERT(pEnv);
930 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
931 ASSERT(pAnnotHandlerMgr);
932
933 CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y);
934
935 if (pFXAnnot == NULL)
936 return FALSE;
937
938 FX_BOOL bRet = pAnnotHandlerMgr->Annot_OnRButtonUp(this, pFXAnnot, nFlag,point);
939 if (bRet)
940 {
941 SetFocusAnnot(pFXAnnot);
942 }
943 return TRUE;
944}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700945
946FX_BOOL CPDFSDK_PageView::OnLButtonUp(const CPDF_Point & point, FX_UINT nFlag)
947{
948 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
949 ASSERT(pEnv);
950 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
951 ASSERT(pAnnotHandlerMgr);
952 CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y);
953 CPDFSDK_Annot* pFocusAnnot = GetFocusAnnot();
954 FX_BOOL bRet = FALSE;
955 if(pFocusAnnot && pFocusAnnot != pFXAnnot)
956 {
957 //Last focus Annot gets a chance to handle the event.
958 bRet = pAnnotHandlerMgr->Annot_OnLButtonUp(this, pFocusAnnot, nFlag,point);
959 }
960 if(pFXAnnot && !bRet)
961 {
962 bRet = pAnnotHandlerMgr->Annot_OnLButtonUp(this, pFXAnnot, nFlag,point);
963 return bRet;
964 }
965 return bRet;
966}
967
968FX_BOOL CPDFSDK_PageView::OnMouseMove(const CPDF_Point & point, int nFlag)
969{
970
971 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
972 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
973 ASSERT(pAnnotHandlerMgr);
974 if(CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y))
975 {
976 if(m_CaptureWidget && m_CaptureWidget != pFXAnnot)
977 {
978 m_bExitWidget = TRUE;
979 m_bEnterWidget = FALSE;
980 pAnnotHandlerMgr->Annot_OnMouseExit(this, m_CaptureWidget, nFlag);
981 }
982 m_CaptureWidget = (CPDFSDK_Widget*)pFXAnnot;
983 m_bOnWidget = TRUE;
984 if(!m_bEnterWidget)
985 {
986 m_bEnterWidget = TRUE;
987 m_bExitWidget = FALSE;
988 pAnnotHandlerMgr->Annot_OnMouseEnter(this, pFXAnnot,nFlag);
989 }
990 pAnnotHandlerMgr->Annot_OnMouseMove(this, pFXAnnot, nFlag, point);
991 return TRUE;
992 }
993 else
994 {
995 if(m_bOnWidget)
Lei Zhang60f507b2015-06-13 00:41:00 -0700996 {
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700997 m_bOnWidget = FALSE;
998 m_bExitWidget = TRUE;
999 m_bEnterWidget = FALSE;
1000 if(m_CaptureWidget)
1001 {
1002 pAnnotHandlerMgr->Annot_OnMouseExit(this, m_CaptureWidget, nFlag);
1003 m_CaptureWidget = NULL;
1004 }
1005 }
1006 return FALSE;
1007 }
Lei Zhang60f507b2015-06-13 00:41:00 -07001008
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001009 return FALSE;;
1010}
1011
1012FX_BOOL CPDFSDK_PageView::OnMouseWheel(double deltaX, double deltaY,const CPDF_Point& point, int nFlag)
1013{
1014 if(CPDFSDK_Annot* pAnnot = GetFXWidgetAtPoint(point.x, point.y))
1015 {
1016 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1017 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
1018 ASSERT(pAnnotHandlerMgr);
1019 return pAnnotHandlerMgr->Annot_OnMouseWheel(this, pAnnot, nFlag, (int)deltaY, point);
1020 }
1021 return FALSE;
1022
1023}
1024
1025FX_BOOL CPDFSDK_PageView::OnChar(int nChar, FX_UINT nFlag)
1026{
1027 if(CPDFSDK_Annot* pAnnot = GetFocusAnnot())
1028 {
1029 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1030 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
1031 ASSERT(pAnnotHandlerMgr);
1032 return pAnnotHandlerMgr->Annot_OnChar(pAnnot, nChar, nFlag);
1033 }
1034
1035 return FALSE;
1036}
1037
1038FX_BOOL CPDFSDK_PageView::OnKeyDown(int nKeyCode, int nFlag)
1039{
1040 if(CPDFSDK_Annot* pAnnot = GetFocusAnnot())
1041 {
1042 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1043 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
1044 ASSERT(pAnnotHandlerMgr);
1045 return pAnnotHandlerMgr->Annot_OnKeyDown(pAnnot, nKeyCode, nFlag);
1046 }
1047 return FALSE;
1048}
1049
1050FX_BOOL CPDFSDK_PageView::OnKeyUp(int nKeyCode, int nFlag)
1051{
1052// if(CPDFSDK_Annot* pAnnot = GetFocusAnnot())
1053// {
1054// CFFL_IFormFiller* pIFormFiller = g_pFormFillApp->GetIFormFiller();
1055// return pIFormFiller->OnKeyUp(pAnnot, nKeyCode, nFlag);
1056// }
1057 return FALSE;
1058}
1059
1060extern void CheckUnSupportAnnot(CPDF_Document * pDoc, CPDF_Annot* pPDFAnnot);
1061
1062void CPDFSDK_PageView::LoadFXAnnots()
1063{
Bo Xufdc00a72014-10-28 23:03:33 -07001064 ASSERT(m_page != NULL);
1065
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001066 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
Bo Xufdc00a72014-10-28 23:03:33 -07001067 ASSERT(pEnv != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001068
Bo Xufdc00a72014-10-28 23:03:33 -07001069 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
1070 ASSERT(pAnnotHandlerMgr != NULL);
1071
unknown636ad3b2014-10-29 19:37:24 +08001072 SetLock(TRUE);
1073 m_page->AddRef();
Bo Xufdc00a72014-10-28 23:03:33 -07001074 if (m_pSDKDoc->GetDocument()->GetDocType() == DOCTYPE_DYNIMIC_XFA)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001075 {
Bo Xufdc00a72014-10-28 23:03:33 -07001076 IXFA_PageView* pageView = NULL;
1077 pageView = m_page->GetXFAPageView();
1078 ASSERT(pageView != NULL);
1079
Bo Xufdc00a72014-10-28 23:03:33 -07001080 IXFA_WidgetIterator* pWidgetHander = pageView->CreateWidgetIterator(XFA_TRAVERSEWAY_Form, XFA_WIDGETFILTER_Visible|XFA_WIDGETFILTER_Viewable|XFA_WIDGETFILTER_AllType);
1081 if (!pWidgetHander)
unknown636ad3b2014-10-29 19:37:24 +08001082 {
1083 m_page->Release();
1084 SetLock(FALSE);
Bo Xufdc00a72014-10-28 23:03:33 -07001085 return;
unknown636ad3b2014-10-29 19:37:24 +08001086 }
Bo Xufdc00a72014-10-28 23:03:33 -07001087
Tom Sepezeed467d2015-06-02 10:35:27 -07001088 IXFA_Widget* pXFAAnnot = pWidgetHander->MoveToNext();
Bo Xufdc00a72014-10-28 23:03:33 -07001089 while (pXFAAnnot) {
1090 CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pXFAAnnot, this);
1091 if(!pAnnot) {
1092 pXFAAnnot = pWidgetHander->MoveToNext();
1093 continue;
1094 }
1095 m_fxAnnotArray.Add(pAnnot);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07001096
Bo Xufdc00a72014-10-28 23:03:33 -07001097 pAnnotHandlerMgr->Annot_OnLoad(pAnnot);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001098
Bo Xufdc00a72014-10-28 23:03:33 -07001099 pXFAAnnot = pWidgetHander->MoveToNext();
Bo Xufacd0152014-09-24 10:49:52 -07001100
Bo Xufdc00a72014-10-28 23:03:33 -07001101 }
1102
1103 pWidgetHander->Release();
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07001104 }
1105 else
Bo Xufdc00a72014-10-28 23:03:33 -07001106 {
1107 CPDF_Page* pPage = m_page->GetPDFPage();
1108 ASSERT(pPage != NULL);
1109
1110 FX_BOOL enableAPUpdate = CPDF_InterForm::UpdatingAPEnabled();
1111 //Disable the default AP construction.
1112 CPDF_InterForm::EnableUpdateAP(FALSE);
1113 m_pAnnotList = new CPDF_AnnotList(pPage);
1114 CPDF_InterForm::EnableUpdateAP(enableAPUpdate);
1115
1116 int nCount = m_pAnnotList->Count();
1117 for(int i=0; i<nCount; i++)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001118 {
Bo Xufdc00a72014-10-28 23:03:33 -07001119 CPDF_Annot* pPDFAnnot = m_pAnnotList->GetAt(i);
Lei Zhang60f507b2015-06-13 00:41:00 -07001120 CPDF_Document * pDoc = GetPDFDocument();
Bo Xufdc00a72014-10-28 23:03:33 -07001121
1122 CheckUnSupportAnnot(pDoc, pPDFAnnot);
1123
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001124 CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pPDFAnnot, this);
1125 if(!pAnnot)
1126 continue;
1127 m_fxAnnotArray.Add(pAnnot);
1128
1129 pAnnotHandlerMgr->Annot_OnLoad(pAnnot);
1130 }
1131
1132 }
unknown636ad3b2014-10-29 19:37:24 +08001133 m_page->Release();
1134 SetLock(FALSE);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001135}
1136
1137void CPDFSDK_PageView::UpdateRects(CFX_RectArray& rects)
1138{
1139 for(int i=0; i<rects.GetSize(); i++)
1140 {
1141 CPDF_Rect rc = rects.GetAt(i);
1142 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1143 pEnv->FFI_Invalidate(m_page, rc.left, rc.top, rc.right, rc.bottom);
1144 }
1145}
1146
1147void CPDFSDK_PageView::UpdateView(CPDFSDK_Annot* pAnnot)
1148{
Lei Zhang60f507b2015-06-13 00:41:00 -07001149 CPDF_Rect rcWindow = pAnnot->GetRect();
1150 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1151 pEnv->FFI_Invalidate(
1152 m_page, rcWindow.left, rcWindow.top, rcWindow.right, rcWindow.bottom);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001153}
1154
1155int CPDFSDK_PageView::GetPageIndex()
1156{
1157 if(m_page)
1158 {
Bo Xufdc00a72014-10-28 23:03:33 -07001159 CPDF_Dictionary* pDic = m_page->GetPDFPage()->m_pFormDict;
1160 CPDFXFA_Document* pDoc = m_pSDKDoc->GetDocument();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001161 if(pDoc && pDic)
1162 {
Bo Xufdc00a72014-10-28 23:03:33 -07001163 return pDoc->GetPDFDoc()->GetPageIndex(pDic->GetObjNum());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001164 }
1165 }
1166 return -1;
1167}
1168
Tom Sepezd7e5cc72015-06-10 14:33:37 -07001169FX_BOOL CPDFSDK_PageView::IsValidAnnot(void* p)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001170{
1171 if (p == NULL) return FALSE;
1172 int iCount = m_pAnnotList->Count();
1173 for (int i = 0; i < iCount; i++)
1174 {
1175 if (m_pAnnotList->GetAt(i) == p)
1176 return TRUE;
1177 }
1178 return FALSE;
1179}
1180
1181
1182CPDFSDK_Annot* CPDFSDK_PageView::GetFocusAnnot()
1183{
1184 CPDFSDK_Annot* pFocusAnnot = m_pSDKDoc->GetFocusAnnot();
1185 if(!pFocusAnnot)
1186 return NULL;
Lei Zhang60f507b2015-06-13 00:41:00 -07001187
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001188 for(int i=0; i<m_fxAnnotArray.GetSize(); i++)
1189 {
1190 CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i);
1191 if(pAnnot == pFocusAnnot)
1192 return pAnnot;
1193 }
1194 return NULL;
1195}
1196