blob: 69a9929bc3e8e5b6d65e39784e30261a2e3cddfb [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{
233
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700234 delete m_pIFormFiller;
235 m_pIFormFiller = NULL;
Bo Xufdc00a72014-10-28 23:03:33 -0700236
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700237 CPDFXFA_App* pProvider = CPDFXFA_App::GetInstance();
238 if (m_pJSRuntime && pProvider->GetRuntimeFactory())
239 pProvider->GetRuntimeFactory()->DeleteJSRuntime(m_pJSRuntime);
Bo Xufdc00a72014-10-28 23:03:33 -0700240
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700241 if (pProvider->m_pEnvList.GetSize() == 0)
242 {
243 pProvider->ReleaseRuntime();
244 pProvider->InitRuntime(TRUE);
245 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700246
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700247 delete m_pSysHandler;
248 m_pSysHandler = NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700249
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700250 delete m_pAnnotHandlerMgr;
251 m_pAnnotHandlerMgr = NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700252
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700253 delete m_pActionHandler;
254 m_pActionHandler = NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700255}
256
257
258IFXJS_Runtime* CPDFDoc_Environment::GetJSRuntime()
259{
260 if(!IsJSInitiated())
261 return NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700262 if(!m_pJSRuntime)
Tom Sepezbdeeb8a2015-05-27 12:25:00 -0700263 m_pJSRuntime = CPDFXFA_App::GetInstance()->GetRuntimeFactory()->NewJSRuntime(this);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700264 return m_pJSRuntime;
265}
266
267CPDFSDK_AnnotHandlerMgr* CPDFDoc_Environment::GetAnnotHandlerMgr()
268{
269 if(!m_pAnnotHandlerMgr)
270 m_pAnnotHandlerMgr = new CPDFSDK_AnnotHandlerMgr(this);
271 return m_pAnnotHandlerMgr;
272}
273
274CPDFSDK_ActionHandler* CPDFDoc_Environment::GetActionHander()
275{
276 if(!m_pActionHandler)
277 m_pActionHandler = new CPDFSDK_ActionHandler(this);
278 return m_pActionHandler;
279}
280
281int CPDFDoc_Environment::RegAppHandle(FPDF_FORMFILLINFO* pFFinfo)
282{
Lei Zhang60f507b2015-06-13 00:41:00 -0700283 m_pInfo = pFFinfo;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700284 return TRUE;
285}
286
287CPDFSDK_Document* CPDFDoc_Environment::GetCurrentDoc()
288{
289 return m_pSDKDoc;
290}
291
292CFFL_IFormFiller* CPDFDoc_Environment::GetIFormFiller()
293{
294 if(!m_pIFormFiller)
295 m_pIFormFiller = new CFFL_IFormFiller(this);
296 return m_pIFormFiller;
297}
298
299FX_BOOL CPDFDoc_Environment::IsJSInitiated()
300{
301 if(m_pInfo)
302 {
303 if(m_pInfo->m_pJsPlatform)
304 return TRUE;
305 else
306 return FALSE;
307 }
308 return FALSE;
309}
310
Bo Xufdc00a72014-10-28 23:03:33 -0700311CPDFSDK_Document::CPDFSDK_Document(CPDFXFA_Document* pDoc,CPDFDoc_Environment* pEnv):m_pDoc(pDoc),
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700312 m_pInterForm(NULL),m_pEnv(pEnv),m_pOccontent(NULL),m_bChangeMask(FALSE)
313{
314 m_pFocusAnnot = NULL;
315}
316
317CPDFSDK_Document::~CPDFSDK_Document()
318{
Tom Sepez2c286192015-06-18 12:47:11 -0700319 FX_POSITION pos = m_pageMap.GetStartPosition();
320 while(pos)
321 {
322 CPDFXFA_Page* pPage = NULL;
323 CPDFSDK_PageView* pPageView = NULL;
324 m_pageMap.GetNextAssoc(pos, pPage, pPageView);
325 delete pPageView;
326 }
327 m_pageMap.RemoveAll();
328
329 delete m_pInterForm;
330 m_pInterForm = nullptr;
331
332 delete m_pOccontent;
333 m_pOccontent = nullptr;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700334}
335
336void CPDFSDK_Document::InitPageView()
337{
338 int nCount = m_pDoc->GetPageCount();
339 for(int i=0; i<nCount; i++)
340 {
341 // To do
342// CPDF_Dictionary* pDic = m_pDoc->GetPage(i);
343// m_pageMap.SetAt(pDic, pPageView);
344 }
345}
346
Bo Xufdc00a72014-10-28 23:03:33 -0700347void CPDFSDK_Document::AddPageView(CPDFXFA_Page* pPDFXFAPage, CPDFSDK_PageView* pPageView)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700348{
Bo Xufdc00a72014-10-28 23:03:33 -0700349 m_pageMap.SetAt(pPDFXFAPage, pPageView);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700350}
351
Bo Xufdc00a72014-10-28 23:03:33 -0700352CPDFSDK_PageView* CPDFSDK_Document::GetPageView(CPDFXFA_Page* pPDFXFAPage, FX_BOOL ReNew)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700353{
Bo Xufdc00a72014-10-28 23:03:33 -0700354 CPDFSDK_PageView* pPageView = (CPDFSDK_PageView*)m_pageMap.GetValueAt(pPDFXFAPage);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700355 if(pPageView != NULL)
356 return pPageView;
357 if(ReNew)
358 {
Bo Xufdc00a72014-10-28 23:03:33 -0700359 pPageView = new CPDFSDK_PageView(this,pPDFXFAPage);
360 m_pageMap.SetAt(pPDFXFAPage, pPageView);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700361 //Delay to load all the annotations, to avoid endless loop.
362 pPageView->LoadFXAnnots();
363 }
364 return pPageView;
365
366}
367
368CPDFSDK_PageView* CPDFSDK_Document::GetCurrentView()
369{
Lei Zhang60f507b2015-06-13 00:41:00 -0700370 CPDFXFA_Page* pPage = (CPDFXFA_Page *)m_pEnv->FFI_GetCurrentPage(m_pDoc);
371 return pPage ? GetPageView(pPage, TRUE) : nullptr;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700372}
373
374CPDFSDK_PageView* CPDFSDK_Document::GetPageView(int nIndex)
375{
376 CPDFSDK_PageView * pTempPageView = NULL;
Bo Xufdc00a72014-10-28 23:03:33 -0700377 CPDFXFA_Page * pTempPage = (CPDFXFA_Page*)m_pEnv->FFI_GetPage(m_pDoc,nIndex);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700378 if(!pTempPage)
379 return NULL;
380
381 m_pageMap.Lookup(pTempPage, pTempPageView);
Lei Zhang60f507b2015-06-13 00:41:00 -0700382
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700383 ASSERT(pTempPageView != NULL);
Lei Zhang60f507b2015-06-13 00:41:00 -0700384
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700385 return pTempPageView;
386}
387
388void CPDFSDK_Document:: ProcJavascriptFun()
389{
Lei Zhang60f507b2015-06-13 00:41:00 -0700390 CPDFXFA_Document* pPDFDoc = GetDocument();
Bo Xufdc00a72014-10-28 23:03:33 -0700391 CPDF_DocJSActions docJS(pPDFDoc->GetPDFDoc());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700392 int iCount = docJS.CountJSActions();
393 if (iCount < 1) return;
394 for (int i = 0; i < iCount; i ++)
395 {
396 CFX_ByteString csJSName;
397 CPDF_Action jsAction = docJS.GetJSAction(i, csJSName);
398 if(m_pEnv->GetActionHander())
399 m_pEnv->GetActionHander()->DoAction_JavaScript(jsAction,CFX_WideString::FromLocal(csJSName),this);
400 }
Lei Zhang60f507b2015-06-13 00:41:00 -0700401
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700402}
403
404FX_BOOL CPDFSDK_Document::ProcOpenAction()
405{
Tom Sepez7b5bc262015-03-05 16:44:22 -0800406 if(!m_pDoc)
407 return FALSE;
408
409 CPDF_Dictionary* pRoot = m_pDoc->GetPDFDoc()->GetRoot();
410 if (!pRoot)
411 return FALSE;
412
413 CPDF_Object* pOpenAction = pRoot->GetDict("OpenAction");
414 if(!pOpenAction)
415 pOpenAction = pRoot->GetArray("OpenAction");
416
417 if(!pOpenAction)
418 return FALSE;
419
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700420 if(pOpenAction->GetType()==PDFOBJ_ARRAY)
Tom Sepez7b5bc262015-03-05 16:44:22 -0800421 return TRUE;
422
423 if(pOpenAction->GetType()==PDFOBJ_DICTIONARY)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700424 {
Tom Sepez7b5bc262015-03-05 16:44:22 -0800425 CPDF_Dictionary * pDict=(CPDF_Dictionary*)pOpenAction;
426 CPDF_Action action(pDict);
427 if(m_pEnv->GetActionHander())
428 m_pEnv->GetActionHander()->DoAction_DocOpen(action, this);
429 return TRUE;
430 }
431 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700432}
433
434CPDF_OCContext* CPDFSDK_Document::GetOCContext()
435{
436 if(!m_pOccontent)
Bo Xufdc00a72014-10-28 23:03:33 -0700437 m_pOccontent = new CPDF_OCContext(m_pDoc->GetPDFDoc());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700438 return m_pOccontent;
439}
440
Bo Xufdc00a72014-10-28 23:03:33 -0700441void CPDFSDK_Document::ReMovePageView(CPDFXFA_Page* pPDFXFAPage)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700442{
Bo Xufdc00a72014-10-28 23:03:33 -0700443 CPDFSDK_PageView* pPageView = (CPDFSDK_PageView*)m_pageMap.GetValueAt(pPDFXFAPage);
unknown636ad3b2014-10-29 19:37:24 +0800444 if(pPageView && !pPageView->IsLocked())
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700445 {
446 delete pPageView;
Bo Xufdc00a72014-10-28 23:03:33 -0700447 m_pageMap.RemoveKey(pPDFXFAPage);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700448 }
449}
450
Bo Xufdc00a72014-10-28 23:03:33 -0700451CPDFXFA_Page * CPDFSDK_Document::GetPage(int nIndex)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700452{
Bo Xufdc00a72014-10-28 23:03:33 -0700453 CPDFXFA_Page * pTempPage = (CPDFXFA_Page*)m_pEnv->FFI_GetPage(m_pDoc,nIndex);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700454 if(!pTempPage)
455 return NULL;
456 return pTempPage;
457}
458
459CPDFSDK_InterForm* CPDFSDK_Document::GetInterForm()
460{
461 if(!m_pInterForm)
462 m_pInterForm = new CPDFSDK_InterForm(this);
463 return m_pInterForm;
464}
465
466void CPDFSDK_Document::UpdateAllViews(CPDFSDK_PageView* pSender, CPDFSDK_Annot* pAnnot)
467{
Lei Zhang60f507b2015-06-13 00:41:00 -0700468
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700469 FX_POSITION pos = m_pageMap.GetStartPosition();
Bo Xufdc00a72014-10-28 23:03:33 -0700470 CPDFXFA_Page * pPage = NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700471 CPDFSDK_PageView * pPageView = NULL;
472 while(pos)
473 {
474 m_pageMap.GetNextAssoc(pos, pPage, pPageView);
475
476 if(pPageView != pSender)
477 {
478 pPageView->UpdateView(pAnnot);
479 }
480 }
481}
482
483CPDFSDK_Annot* CPDFSDK_Document::GetFocusAnnot()
484{
Lei Zhang60f507b2015-06-13 00:41:00 -0700485 return m_pFocusAnnot;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700486}
487
488FX_BOOL CPDFSDK_Document::SetFocusAnnot(CPDFSDK_Annot* pAnnot,FX_UINT nFlag)
489{
490
491 if(m_pFocusAnnot==pAnnot) return TRUE;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700492
Bo Xufdc00a72014-10-28 23:03:33 -0700493 CPDFSDK_Annot* pLastFocusAnnot = m_pFocusAnnot;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700494
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700495 if(m_pFocusAnnot)
496 {
Lei Zhang60f507b2015-06-13 00:41:00 -0700497 if(!KillFocusAnnot(nFlag) ) return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700498 }
Bo Xufdc00a72014-10-28 23:03:33 -0700499 CPDFSDK_PageView* pPageView = NULL;
500 if (pAnnot)
501 pPageView = pAnnot->GetPageView();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700502 if(pAnnot && pPageView->IsValid())
503 {
504 CPDFSDK_AnnotHandlerMgr *pAnnotHandler=m_pEnv->GetAnnotHandlerMgr();
505
506 if(pAnnotHandler&&!m_pFocusAnnot)
507 {
Bo Xufdc00a72014-10-28 23:03:33 -0700508 if (!pAnnotHandler->Annot_OnChangeFocus(pAnnot,pLastFocusAnnot))
509 return FALSE;
510
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700511 if (!pAnnotHandler->Annot_OnSetFocus(pAnnot,nFlag))
512 return FALSE;
513 if(!m_pFocusAnnot)
514 {
Lei Zhang60f507b2015-06-13 00:41:00 -0700515 m_pFocusAnnot=pAnnot;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700516 return TRUE;
517 }
Lei Zhang60f507b2015-06-13 00:41:00 -0700518 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700519 }
520 return FALSE;
521}
522
523FX_BOOL CPDFSDK_Document::KillFocusAnnot(FX_UINT nFlag)
524{
525 if(m_pFocusAnnot)
526 {
527 CPDFSDK_AnnotHandlerMgr *pAnnotHandler=m_pEnv->GetAnnotHandlerMgr();
528 if(pAnnotHandler)
529 {
530 CPDFSDK_Annot* pFocusAnnot = m_pFocusAnnot;
531 m_pFocusAnnot = NULL;
Bo Xufdc00a72014-10-28 23:03:33 -0700532
533 if (!pAnnotHandler->Annot_OnChangeFocus(NULL, pFocusAnnot))
534 return FALSE;
535
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700536 if(pAnnotHandler->Annot_OnKillFocus(pFocusAnnot, nFlag))
537 {
Lei Zhang60f507b2015-06-13 00:41:00 -0700538
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700539 if(pFocusAnnot->GetType() == FX_BSTRC("Widget"))
540 {
541 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pFocusAnnot;
542 int nFieldType = pWidget->GetFieldType();
543 if(FIELDTYPE_TEXTFIELD == nFieldType || FIELDTYPE_COMBOBOX == nFieldType)
544 m_pEnv->FFI_OnSetFieldInputFocus(NULL, NULL, 0, FALSE);
545 }
546
547 if(!m_pFocusAnnot)
548 return TRUE;
549 }
550 else
551 {
552 m_pFocusAnnot = pFocusAnnot;
553 }
554 }
555 }
556 return FALSE;
557}
558
559FX_BOOL CPDFSDK_Document::DeletePages(int nStart, int nCount)
560{
561 if ( nStart < 0 || nStart >= GetPageCount() || nCount <= 0 )
562 {
563 return FALSE;
564 }
565
Bo Xufdc00a72014-10-28 23:03:33 -0700566 CPDFXFA_Page * pTempPage = NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700567 for ( int i = nCount-1; i >= 0; i-- )
568 {
569 pTempPage = GetPage(nStart+i);
570 if ( pTempPage != NULL )
571 {
572 ReMovePageView(pTempPage);
573 }
574 }
575 return TRUE;
576}
577
578void CPDFSDK_Document::OnCloseDocument()
579{
580 KillFocusAnnot();
581}
582
583FX_BOOL CPDFSDK_Document::GetPermissions(int nFlag)
584{
Bo Xufdc00a72014-10-28 23:03:33 -0700585 FX_DWORD dwPermissions = m_pDoc->GetPDFDoc()->GetUserPermissions();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700586 return dwPermissions&nFlag;
587}
588
589IFXJS_Runtime * CPDFSDK_Document::GetJsRuntime()
590{
591 ASSERT(m_pEnv!=NULL);
592 return m_pEnv->GetJSRuntime();
593}
594
Lei Zhang60f507b2015-06-13 00:41:00 -0700595CFX_WideString CPDFSDK_Document::GetPath()
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700596{
597 ASSERT(m_pEnv != NULL);
598 return m_pEnv->JS_docGetFilePath();
599}
600
601
Bo Xufdc00a72014-10-28 23:03:33 -0700602CPDFSDK_PageView::CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc,CPDFXFA_Page* page):m_page(page),m_pSDKDoc(pSDKDoc)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700603{
604 CPDFSDK_InterForm* pInterForm = pSDKDoc->GetInterForm();
605 if(pInterForm)
606 {
607 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm();
Bo Xufdc00a72014-10-28 23:03:33 -0700608 if (page->GetPDFPage())
609 pPDFInterForm->FixPageFields(page->GetPDFPage());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700610 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700611 m_fxAnnotArray.RemoveAll();
612
613 m_bEnterWidget = FALSE;
614 m_bExitWidget = FALSE;
615 m_bOnWidget = FALSE;
616 m_CaptureWidget = NULL;
617 m_bValid = FALSE;
unknown636ad3b2014-10-29 19:37:24 +0800618 m_bLocked = FALSE;
Bo Xufdc00a72014-10-28 23:03:33 -0700619 m_pAnnotList = NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700620}
621
622CPDFSDK_PageView::~CPDFSDK_PageView()
623{
Lei Zhang60f507b2015-06-13 00:41:00 -0700624 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700625 int nAnnotCount = m_fxAnnotArray.GetSize();
626 for (int i=0; i<nAnnotCount; i++)
627 {
628 CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i);
629 //if there is a focused annot on the page, we should kill the focus first.
630 if(pAnnot == m_pSDKDoc->GetFocusAnnot())
631 KillFocusAnnot();
632 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
633 ASSERT(pAnnotHandlerMgr);
634 pAnnotHandlerMgr->ReleaseAnnot(pAnnot);
635 }
636 m_fxAnnotArray.RemoveAll();
637 if(m_pAnnotList)
638 {
639 delete m_pAnnotList;
640 m_pAnnotList = NULL;
641 }
642}
643
Bo Xufdc00a72014-10-28 23:03:33 -0700644void 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 -0700645{
646 m_curMatrix = *pUser2Device;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700647 // m_pAnnotList->DisplayAnnots(m_page, pDevice, pUser2Device, FALSE, pOptions);
648 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
Bo Xufdc00a72014-10-28 23:03:33 -0700649 CPDFXFA_Page* pPage = GetPDFXFAPage();
650
651 if (pPage == NULL) return;
652
653 if (pPage->GetDocument()->GetDocType() == DOCTYPE_DYNIMIC_XFA) {
654 CFX_Graphics gs;
655 gs.Create(pDevice);
656 if (pClip) {
657 CFX_RectF rectClip;
Bruce Dawson3f49aa32015-01-08 11:47:49 -0800658 rectClip.Set(static_cast<FX_FLOAT>(pClip->left),
659 static_cast<FX_FLOAT>(pClip->top),
660 static_cast<FX_FLOAT>(pClip->Width()),
661 static_cast<FX_FLOAT>(pClip->Height()));
Bo Xufdc00a72014-10-28 23:03:33 -0700662 gs.SetClipRect(rectClip);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700663 }
Bo Xufdc00a72014-10-28 23:03:33 -0700664 IXFA_RenderContext* pRenderContext = XFA_RenderContext_Create();
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700665 if (!pRenderContext)
Bo Xufdc00a72014-10-28 23:03:33 -0700666 return;
667 CXFA_RenderOptions renderOptions;
668 renderOptions.m_bHighlight = TRUE;
669 pRenderContext->StartRender(pPage->GetXFAPageView(), &gs, *pUser2Device, renderOptions);
670 pRenderContext->DoRender();
671 pRenderContext->StopRender();
672 pRenderContext->Release();
673 return;
674 }
675 // for pdf/static xfa.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700676 CPDFSDK_AnnotIterator annotIterator(this, TRUE);
677 CPDFSDK_Annot * pSDKAnnot=NULL;
678 int index=-1;
Bo Xufdc00a72014-10-28 23:03:33 -0700679 pSDKAnnot = annotIterator.Next(index);
680 while(pSDKAnnot)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700681 {
682 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
683 ASSERT(pAnnotHandlerMgr);
684 pAnnotHandlerMgr->Annot_OnDraw(this, pSDKAnnot, pDevice, pUser2Device, 0);
Bo Xufdc00a72014-10-28 23:03:33 -0700685 pSDKAnnot = annotIterator.Next(index);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700686 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700687}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700688CPDF_Annot* CPDFSDK_PageView::GetPDFAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY)
689{
Lei Zhang60f507b2015-06-13 00:41:00 -0700690
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700691 int nCount = m_pAnnotList->Count();
692 for(int i = 0 ; i<nCount; i++)
693 {
694 CPDF_Annot* pAnnot = m_pAnnotList->GetAt(i);
695 CFX_FloatRect annotRect;
696 pAnnot->GetRect(annotRect);
697 if(annotRect.Contains(pageX, pageY))
698 return pAnnot;
699 }
700 return NULL;
701}
702
703CPDF_Annot* CPDFSDK_PageView::GetPDFWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY)
704{
Lei Zhang60f507b2015-06-13 00:41:00 -0700705
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700706 int nCount = m_pAnnotList->Count();
707 for(int i = 0 ; i<nCount; i++)
708 {
709 CPDF_Annot* pAnnot = m_pAnnotList->GetAt(i);
710 if(pAnnot->GetSubType() == "Widget")
711 {
712 CFX_FloatRect annotRect;
713 pAnnot->GetRect(annotRect);
714 if(annotRect.Contains(pageX, pageY))
715 return pAnnot;
716 }
717 }
718 return NULL;
719}
720
721CPDFSDK_Annot* CPDFSDK_PageView::GetFXAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY)
722{
723
724 CPDFSDK_AnnotIterator annotIterator(this, FALSE);
725 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
726 CPDFSDK_AnnotHandlerMgr* pAnnotMgr = pEnv->GetAnnotHandlerMgr();
727 CPDFSDK_Annot* pSDKAnnot = NULL;
728 int index = -1;
Bo Xufdc00a72014-10-28 23:03:33 -0700729 pSDKAnnot = annotIterator.Next(index);
730 while(pSDKAnnot)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700731 {
732 CPDF_Rect rc = pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot);
733 if(rc.Contains(pageX, pageY))
734 return pSDKAnnot;
Bo Xufdc00a72014-10-28 23:03:33 -0700735 pSDKAnnot = annotIterator.Next(index);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700736 }
737
738 return NULL;
739}
740
741CPDFSDK_Annot* CPDFSDK_PageView::GetFXWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY)
742{
743
744 CPDFSDK_AnnotIterator annotIterator(this, FALSE);
745 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
746 CPDFSDK_AnnotHandlerMgr* pAnnotMgr = pEnv->GetAnnotHandlerMgr();
747 CPDFSDK_Annot* pSDKAnnot = NULL;
748 int index = -1;
Bo Xufdc00a72014-10-28 23:03:33 -0700749 pSDKAnnot = annotIterator.Next(index);
750 while(pSDKAnnot)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700751 {
Bo Xufdc00a72014-10-28 23:03:33 -0700752 if(pSDKAnnot->GetType() == "Widget" || pSDKAnnot->GetType() == FSDK_XFAWIDGET_TYPENAME)
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700753 {
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700754 pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot);
755 CPDF_Point point(pageX, pageY);
756 if (pAnnotMgr->Annot_OnHitTest(this, pSDKAnnot, point))
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700757 return pSDKAnnot;
758 }
Bo Xufdc00a72014-10-28 23:03:33 -0700759 pSDKAnnot = annotIterator.Next(index);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700760 }
Lei Zhang60f507b2015-06-13 00:41:00 -0700761
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700762 return NULL;
763}
764
765
766FX_BOOL CPDFSDK_PageView::Annot_HasAppearance(CPDF_Annot* pAnnot)
767{
Lei Zhang64adf192015-06-05 15:50:32 -0700768 CPDF_Dictionary* pAnnotDic = pAnnot->GetAnnotDict();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700769 if(pAnnotDic)
770 return pAnnotDic->KeyExist("AS");
771 return FALSE;
772}
773
774CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CPDF_Annot * pPDFAnnot)
775{
776 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
777 ASSERT(pEnv);
Lei Zhang60f507b2015-06-13 00:41:00 -0700778 CPDFSDK_AnnotHandlerMgr * pAnnotHandler= pEnv->GetAnnotHandlerMgr();
779
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700780 CPDFSDK_Annot* pSDKAnnot =NULL;
Lei Zhang60f507b2015-06-13 00:41:00 -0700781
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700782 if(pAnnotHandler)
783 {
784 pSDKAnnot = pAnnotHandler->NewAnnot(pPDFAnnot, this);
785 }
Lei Zhang60f507b2015-06-13 00:41:00 -0700786 if(!pSDKAnnot)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700787 return NULL;
788
Lei Zhang60f507b2015-06-13 00:41:00 -0700789 m_fxAnnotArray.Add(pSDKAnnot);
790
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700791 if(pAnnotHandler)
Lei Zhang60f507b2015-06-13 00:41:00 -0700792 {
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700793 pAnnotHandler->Annot_OnCreate(pSDKAnnot);
Lei Zhang60f507b2015-06-13 00:41:00 -0700794
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700795 }
796
797 return pSDKAnnot;
798}
799
Tom Sepezeed467d2015-06-02 10:35:27 -0700800CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(IXFA_Widget* pPDFAnnot)
Bo Xufdc00a72014-10-28 23:03:33 -0700801{
802 if (!pPDFAnnot) return NULL;
803
804 CPDFSDK_Annot* pSDKAnnot = GetAnnotByXFAWidget(pPDFAnnot);
805 if (pSDKAnnot)
806 return pSDKAnnot;
807
808 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
809 ASSERT(pEnv);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700810 CPDFSDK_AnnotHandlerMgr * pAnnotHandler= pEnv->GetAnnotHandlerMgr();
Bo Xufdc00a72014-10-28 23:03:33 -0700811
812 pSDKAnnot =NULL;
813
814 if(pAnnotHandler)
815 {
816 pSDKAnnot = pAnnotHandler->NewAnnot(pPDFAnnot, this);
817 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700818 if(!pSDKAnnot)
Bo Xufdc00a72014-10-28 23:03:33 -0700819 return NULL;
820
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700821 m_fxAnnotArray.Add(pSDKAnnot);
Bo Xufdc00a72014-10-28 23:03:33 -0700822
823 return pSDKAnnot;
824}
825
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700826CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CPDF_Dictionary * pDict)
827{
Lei Zhang60f507b2015-06-13 00:41:00 -0700828 return pDict ? AddAnnot(pDict->GetString("Subtype"), pDict) : nullptr;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700829}
830
Tom Sepezd7e5cc72015-06-10 14:33:37 -0700831CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(const FX_CHAR* lpSubType,CPDF_Dictionary * pDict)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700832{
833 return NULL;
834}
835
836FX_BOOL CPDFSDK_PageView::DeleteAnnot(CPDFSDK_Annot* pAnnot)
837{
Bo Xufdc00a72014-10-28 23:03:33 -0700838 if (!pAnnot)
839 return FALSE;
840 CPDFXFA_Page* pPage = pAnnot->GetPDFXFAPage();
841 if (!pPage || (pPage->GetDocument()->GetDocType() != DOCTYPE_STATIC_XFA && pPage->GetDocument()->GetDocType() != DOCTYPE_DYNIMIC_XFA))
842 return FALSE;
843
844 int index = m_fxAnnotArray.Find(pAnnot);
845 m_fxAnnotArray.RemoveAt(index);
846 if (m_CaptureWidget == pAnnot)
847 m_CaptureWidget = NULL;
848
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700849 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700850}
851
852CPDF_Document* CPDFSDK_PageView::GetPDFDocument()
853{
854 if(m_page)
855 {
Bo Xufdc00a72014-10-28 23:03:33 -0700856 return m_page->GetDocument()->GetPDFDoc();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700857 }
858 return NULL;
859}
860
Bo Xufdc00a72014-10-28 23:03:33 -0700861CPDF_Page* CPDFSDK_PageView::GetPDFPage()
862{
863 if (m_page)
864 {
865 return m_page->GetPDFPage();
866 }
867
868 return NULL;
869}
870
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700871int CPDFSDK_PageView::CountAnnots()
872{
Bo Xufdc00a72014-10-28 23:03:33 -0700873 return m_fxAnnotArray.GetSize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700874}
875
876CPDFSDK_Annot* CPDFSDK_PageView::GetAnnot(int nIndex)
877{
878 int nCount = m_fxAnnotArray.GetSize();
879 if ( nIndex < 0 || nIndex >= nCount )
880 {
881 return NULL;
882 }
883
884 return (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(nIndex);
885}
886
887CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByDict(CPDF_Dictionary * pDict)
888{
889 int nCount = m_fxAnnotArray.GetSize();
890 for(int i=0; i<nCount; i++)
891 {
892 CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i);
Lei Zhang64adf192015-06-05 15:50:32 -0700893 if (pDict == pAnnot->GetPDFAnnot()->GetAnnotDict())
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700894 return pAnnot;
895 }
896 return NULL;
897}
Tom Sepezeed467d2015-06-02 10:35:27 -0700898CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByXFAWidget(IXFA_Widget* hWidget)
Bo Xufdc00a72014-10-28 23:03:33 -0700899{
900 if (hWidget == NULL)
901 return NULL;
902 int annotCount = m_fxAnnotArray.GetSize();
903
904 for(int i = 0; i < annotCount; i++)
905 {
906 CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i);
907 if(pAnnot->GetXFAWidget() == hWidget)
908 return pAnnot;
909 }
910 return NULL;
911}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700912
913FX_BOOL CPDFSDK_PageView::OnLButtonDown(const CPDF_Point & point, FX_UINT nFlag)
914{
915 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
916 ASSERT(pEnv);
917 CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y);
918 if(!pFXAnnot)
919 {
920 KillFocusAnnot(nFlag);
921 }
922 else
923 {
924 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
925 ASSERT(pAnnotHandlerMgr);
926
927 FX_BOOL bRet = pAnnotHandlerMgr->Annot_OnLButtonDown(this, pFXAnnot, nFlag,point);
928 if(bRet)
929 {
930 SetFocusAnnot(pFXAnnot);
931 }
932 return bRet;
933 }
934 return FALSE;
935}
936
Bo Xufdc00a72014-10-28 23:03:33 -0700937FX_BOOL CPDFSDK_PageView::OnRButtonDown(const CPDF_Point & point, FX_UINT nFlag)
938{
939 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
940 ASSERT(pEnv);
941 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
942 ASSERT(pAnnotHandlerMgr);
943
944 CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y);
945
946 if (pFXAnnot == NULL)
947 return FALSE;
948
949 FX_BOOL bRet = pAnnotHandlerMgr->Annot_OnRButtonDown(this, pFXAnnot, nFlag,point);
950 if (bRet)
951 {
952 SetFocusAnnot(pFXAnnot);
953 }
954 return TRUE;
955}
956
957FX_BOOL CPDFSDK_PageView::OnRButtonUp(const CPDF_Point & point, FX_UINT nFlag)
958{
959 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
960 ASSERT(pEnv);
961 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
962 ASSERT(pAnnotHandlerMgr);
963
964 CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y);
965
966 if (pFXAnnot == NULL)
967 return FALSE;
968
969 FX_BOOL bRet = pAnnotHandlerMgr->Annot_OnRButtonUp(this, pFXAnnot, nFlag,point);
970 if (bRet)
971 {
972 SetFocusAnnot(pFXAnnot);
973 }
974 return TRUE;
975}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700976
977FX_BOOL CPDFSDK_PageView::OnLButtonUp(const CPDF_Point & point, FX_UINT nFlag)
978{
979 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
980 ASSERT(pEnv);
981 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
982 ASSERT(pAnnotHandlerMgr);
983 CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y);
984 CPDFSDK_Annot* pFocusAnnot = GetFocusAnnot();
985 FX_BOOL bRet = FALSE;
986 if(pFocusAnnot && pFocusAnnot != pFXAnnot)
987 {
988 //Last focus Annot gets a chance to handle the event.
989 bRet = pAnnotHandlerMgr->Annot_OnLButtonUp(this, pFocusAnnot, nFlag,point);
990 }
991 if(pFXAnnot && !bRet)
992 {
993 bRet = pAnnotHandlerMgr->Annot_OnLButtonUp(this, pFXAnnot, nFlag,point);
994 return bRet;
995 }
996 return bRet;
997}
998
999FX_BOOL CPDFSDK_PageView::OnMouseMove(const CPDF_Point & point, int nFlag)
1000{
1001
1002 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1003 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
1004 ASSERT(pAnnotHandlerMgr);
1005 if(CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y))
1006 {
1007 if(m_CaptureWidget && m_CaptureWidget != pFXAnnot)
1008 {
1009 m_bExitWidget = TRUE;
1010 m_bEnterWidget = FALSE;
1011 pAnnotHandlerMgr->Annot_OnMouseExit(this, m_CaptureWidget, nFlag);
1012 }
1013 m_CaptureWidget = (CPDFSDK_Widget*)pFXAnnot;
1014 m_bOnWidget = TRUE;
1015 if(!m_bEnterWidget)
1016 {
1017 m_bEnterWidget = TRUE;
1018 m_bExitWidget = FALSE;
1019 pAnnotHandlerMgr->Annot_OnMouseEnter(this, pFXAnnot,nFlag);
1020 }
1021 pAnnotHandlerMgr->Annot_OnMouseMove(this, pFXAnnot, nFlag, point);
1022 return TRUE;
1023 }
1024 else
1025 {
1026 if(m_bOnWidget)
Lei Zhang60f507b2015-06-13 00:41:00 -07001027 {
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001028 m_bOnWidget = FALSE;
1029 m_bExitWidget = TRUE;
1030 m_bEnterWidget = FALSE;
1031 if(m_CaptureWidget)
1032 {
1033 pAnnotHandlerMgr->Annot_OnMouseExit(this, m_CaptureWidget, nFlag);
1034 m_CaptureWidget = NULL;
1035 }
1036 }
1037 return FALSE;
1038 }
Lei Zhang60f507b2015-06-13 00:41:00 -07001039
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001040 return FALSE;;
1041}
1042
1043FX_BOOL CPDFSDK_PageView::OnMouseWheel(double deltaX, double deltaY,const CPDF_Point& point, int nFlag)
1044{
1045 if(CPDFSDK_Annot* pAnnot = GetFXWidgetAtPoint(point.x, point.y))
1046 {
1047 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1048 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
1049 ASSERT(pAnnotHandlerMgr);
1050 return pAnnotHandlerMgr->Annot_OnMouseWheel(this, pAnnot, nFlag, (int)deltaY, point);
1051 }
1052 return FALSE;
1053
1054}
1055
1056FX_BOOL CPDFSDK_PageView::OnChar(int nChar, FX_UINT nFlag)
1057{
1058 if(CPDFSDK_Annot* pAnnot = GetFocusAnnot())
1059 {
1060 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1061 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
1062 ASSERT(pAnnotHandlerMgr);
1063 return pAnnotHandlerMgr->Annot_OnChar(pAnnot, nChar, nFlag);
1064 }
1065
1066 return FALSE;
1067}
1068
1069FX_BOOL CPDFSDK_PageView::OnKeyDown(int nKeyCode, int nFlag)
1070{
1071 if(CPDFSDK_Annot* pAnnot = GetFocusAnnot())
1072 {
1073 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1074 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
1075 ASSERT(pAnnotHandlerMgr);
1076 return pAnnotHandlerMgr->Annot_OnKeyDown(pAnnot, nKeyCode, nFlag);
1077 }
1078 return FALSE;
1079}
1080
1081FX_BOOL CPDFSDK_PageView::OnKeyUp(int nKeyCode, int nFlag)
1082{
1083// if(CPDFSDK_Annot* pAnnot = GetFocusAnnot())
1084// {
1085// CFFL_IFormFiller* pIFormFiller = g_pFormFillApp->GetIFormFiller();
1086// return pIFormFiller->OnKeyUp(pAnnot, nKeyCode, nFlag);
1087// }
1088 return FALSE;
1089}
1090
1091extern void CheckUnSupportAnnot(CPDF_Document * pDoc, CPDF_Annot* pPDFAnnot);
1092
1093void CPDFSDK_PageView::LoadFXAnnots()
1094{
Bo Xufdc00a72014-10-28 23:03:33 -07001095 ASSERT(m_page != NULL);
1096
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001097 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
Bo Xufdc00a72014-10-28 23:03:33 -07001098 ASSERT(pEnv != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001099
Bo Xufdc00a72014-10-28 23:03:33 -07001100 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
1101 ASSERT(pAnnotHandlerMgr != NULL);
1102
unknown636ad3b2014-10-29 19:37:24 +08001103 SetLock(TRUE);
1104 m_page->AddRef();
Bo Xufdc00a72014-10-28 23:03:33 -07001105 if (m_pSDKDoc->GetDocument()->GetDocType() == DOCTYPE_DYNIMIC_XFA)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001106 {
Bo Xufdc00a72014-10-28 23:03:33 -07001107 IXFA_PageView* pageView = NULL;
1108 pageView = m_page->GetXFAPageView();
1109 ASSERT(pageView != NULL);
1110
Bo Xufdc00a72014-10-28 23:03:33 -07001111 IXFA_WidgetIterator* pWidgetHander = pageView->CreateWidgetIterator(XFA_TRAVERSEWAY_Form, XFA_WIDGETFILTER_Visible|XFA_WIDGETFILTER_Viewable|XFA_WIDGETFILTER_AllType);
1112 if (!pWidgetHander)
unknown636ad3b2014-10-29 19:37:24 +08001113 {
1114 m_page->Release();
1115 SetLock(FALSE);
Bo Xufdc00a72014-10-28 23:03:33 -07001116 return;
unknown636ad3b2014-10-29 19:37:24 +08001117 }
Bo Xufdc00a72014-10-28 23:03:33 -07001118
Tom Sepezeed467d2015-06-02 10:35:27 -07001119 IXFA_Widget* pXFAAnnot = pWidgetHander->MoveToNext();
Bo Xufdc00a72014-10-28 23:03:33 -07001120 while (pXFAAnnot) {
1121 CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pXFAAnnot, this);
1122 if(!pAnnot) {
1123 pXFAAnnot = pWidgetHander->MoveToNext();
1124 continue;
1125 }
1126 m_fxAnnotArray.Add(pAnnot);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07001127
Bo Xufdc00a72014-10-28 23:03:33 -07001128 pAnnotHandlerMgr->Annot_OnLoad(pAnnot);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001129
Bo Xufdc00a72014-10-28 23:03:33 -07001130 pXFAAnnot = pWidgetHander->MoveToNext();
Bo Xufacd0152014-09-24 10:49:52 -07001131
Bo Xufdc00a72014-10-28 23:03:33 -07001132 }
1133
1134 pWidgetHander->Release();
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07001135 }
1136 else
Bo Xufdc00a72014-10-28 23:03:33 -07001137 {
1138 CPDF_Page* pPage = m_page->GetPDFPage();
1139 ASSERT(pPage != NULL);
1140
1141 FX_BOOL enableAPUpdate = CPDF_InterForm::UpdatingAPEnabled();
1142 //Disable the default AP construction.
1143 CPDF_InterForm::EnableUpdateAP(FALSE);
1144 m_pAnnotList = new CPDF_AnnotList(pPage);
1145 CPDF_InterForm::EnableUpdateAP(enableAPUpdate);
1146
1147 int nCount = m_pAnnotList->Count();
1148 for(int i=0; i<nCount; i++)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001149 {
Bo Xufdc00a72014-10-28 23:03:33 -07001150 CPDF_Annot* pPDFAnnot = m_pAnnotList->GetAt(i);
Lei Zhang60f507b2015-06-13 00:41:00 -07001151 CPDF_Document * pDoc = GetPDFDocument();
Bo Xufdc00a72014-10-28 23:03:33 -07001152
1153 CheckUnSupportAnnot(pDoc, pPDFAnnot);
1154
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001155 CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pPDFAnnot, this);
1156 if(!pAnnot)
1157 continue;
1158 m_fxAnnotArray.Add(pAnnot);
1159
1160 pAnnotHandlerMgr->Annot_OnLoad(pAnnot);
1161 }
1162
1163 }
unknown636ad3b2014-10-29 19:37:24 +08001164 m_page->Release();
1165 SetLock(FALSE);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001166}
1167
1168void CPDFSDK_PageView::UpdateRects(CFX_RectArray& rects)
1169{
1170 for(int i=0; i<rects.GetSize(); i++)
1171 {
1172 CPDF_Rect rc = rects.GetAt(i);
1173 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1174 pEnv->FFI_Invalidate(m_page, rc.left, rc.top, rc.right, rc.bottom);
1175 }
1176}
1177
1178void CPDFSDK_PageView::UpdateView(CPDFSDK_Annot* pAnnot)
1179{
Lei Zhang60f507b2015-06-13 00:41:00 -07001180 CPDF_Rect rcWindow = pAnnot->GetRect();
1181 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1182 pEnv->FFI_Invalidate(
1183 m_page, rcWindow.left, rcWindow.top, rcWindow.right, rcWindow.bottom);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001184}
1185
1186int CPDFSDK_PageView::GetPageIndex()
1187{
1188 if(m_page)
1189 {
Bo Xufdc00a72014-10-28 23:03:33 -07001190 CPDF_Dictionary* pDic = m_page->GetPDFPage()->m_pFormDict;
1191 CPDFXFA_Document* pDoc = m_pSDKDoc->GetDocument();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001192 if(pDoc && pDic)
1193 {
Bo Xufdc00a72014-10-28 23:03:33 -07001194 return pDoc->GetPDFDoc()->GetPageIndex(pDic->GetObjNum());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001195 }
1196 }
1197 return -1;
1198}
1199
Tom Sepezd7e5cc72015-06-10 14:33:37 -07001200FX_BOOL CPDFSDK_PageView::IsValidAnnot(void* p)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001201{
1202 if (p == NULL) return FALSE;
1203 int iCount = m_pAnnotList->Count();
1204 for (int i = 0; i < iCount; i++)
1205 {
1206 if (m_pAnnotList->GetAt(i) == p)
1207 return TRUE;
1208 }
1209 return FALSE;
1210}
1211
1212
1213CPDFSDK_Annot* CPDFSDK_PageView::GetFocusAnnot()
1214{
1215 CPDFSDK_Annot* pFocusAnnot = m_pSDKDoc->GetFocusAnnot();
1216 if(!pFocusAnnot)
1217 return NULL;
Lei Zhang60f507b2015-06-13 00:41:00 -07001218
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001219 for(int i=0; i<m_fxAnnotArray.GetSize(); i++)
1220 {
1221 CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i);
1222 if(pAnnot == pFocusAnnot)
1223 return pAnnot;
1224 }
1225 return NULL;
1226}
1227