blob: 0f71e6eaa0553f200e405aa2e80e8b5127d11ed8 [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{
Tom Sepez2c286192015-06-18 12:47:11 -0700318 FX_POSITION pos = m_pageMap.GetStartPosition();
319 while(pos)
320 {
321 CPDFXFA_Page* pPage = NULL;
322 CPDFSDK_PageView* pPageView = NULL;
323 m_pageMap.GetNextAssoc(pos, pPage, pPageView);
324 delete pPageView;
325 }
326 m_pageMap.RemoveAll();
327
328 delete m_pInterForm;
329 m_pInterForm = nullptr;
330
331 delete m_pOccontent;
332 m_pOccontent = nullptr;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700333}
334
335void CPDFSDK_Document::InitPageView()
336{
337 int nCount = m_pDoc->GetPageCount();
338 for(int i=0; i<nCount; i++)
339 {
340 // To do
341// CPDF_Dictionary* pDic = m_pDoc->GetPage(i);
342// m_pageMap.SetAt(pDic, pPageView);
343 }
344}
345
Bo Xufdc00a72014-10-28 23:03:33 -0700346void CPDFSDK_Document::AddPageView(CPDFXFA_Page* pPDFXFAPage, CPDFSDK_PageView* pPageView)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700347{
Bo Xufdc00a72014-10-28 23:03:33 -0700348 m_pageMap.SetAt(pPDFXFAPage, pPageView);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700349}
350
Bo Xufdc00a72014-10-28 23:03:33 -0700351CPDFSDK_PageView* CPDFSDK_Document::GetPageView(CPDFXFA_Page* pPDFXFAPage, FX_BOOL ReNew)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700352{
Bo Xufdc00a72014-10-28 23:03:33 -0700353 CPDFSDK_PageView* pPageView = (CPDFSDK_PageView*)m_pageMap.GetValueAt(pPDFXFAPage);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700354 if(pPageView != NULL)
355 return pPageView;
356 if(ReNew)
357 {
Bo Xufdc00a72014-10-28 23:03:33 -0700358 pPageView = new CPDFSDK_PageView(this,pPDFXFAPage);
359 m_pageMap.SetAt(pPDFXFAPage, pPageView);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700360 //Delay to load all the annotations, to avoid endless loop.
361 pPageView->LoadFXAnnots();
362 }
363 return pPageView;
364
365}
366
367CPDFSDK_PageView* CPDFSDK_Document::GetCurrentView()
368{
Lei Zhang60f507b2015-06-13 00:41:00 -0700369 CPDFXFA_Page* pPage = (CPDFXFA_Page *)m_pEnv->FFI_GetCurrentPage(m_pDoc);
370 return pPage ? GetPageView(pPage, TRUE) : nullptr;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700371}
372
373CPDFSDK_PageView* CPDFSDK_Document::GetPageView(int nIndex)
374{
375 CPDFSDK_PageView * pTempPageView = NULL;
Bo Xufdc00a72014-10-28 23:03:33 -0700376 CPDFXFA_Page * pTempPage = (CPDFXFA_Page*)m_pEnv->FFI_GetPage(m_pDoc,nIndex);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700377 if(!pTempPage)
378 return NULL;
379
380 m_pageMap.Lookup(pTempPage, pTempPageView);
Lei Zhang60f507b2015-06-13 00:41:00 -0700381
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700382 ASSERT(pTempPageView != NULL);
Lei Zhang60f507b2015-06-13 00:41:00 -0700383
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700384 return pTempPageView;
385}
386
387void CPDFSDK_Document:: ProcJavascriptFun()
388{
Lei Zhang60f507b2015-06-13 00:41:00 -0700389 CPDFXFA_Document* pPDFDoc = GetDocument();
Bo Xufdc00a72014-10-28 23:03:33 -0700390 CPDF_DocJSActions docJS(pPDFDoc->GetPDFDoc());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700391 int iCount = docJS.CountJSActions();
392 if (iCount < 1) return;
393 for (int i = 0; i < iCount; i ++)
394 {
395 CFX_ByteString csJSName;
396 CPDF_Action jsAction = docJS.GetJSAction(i, csJSName);
397 if(m_pEnv->GetActionHander())
398 m_pEnv->GetActionHander()->DoAction_JavaScript(jsAction,CFX_WideString::FromLocal(csJSName),this);
399 }
Lei Zhang60f507b2015-06-13 00:41:00 -0700400
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700401}
402
403FX_BOOL CPDFSDK_Document::ProcOpenAction()
404{
Tom Sepez7b5bc262015-03-05 16:44:22 -0800405 if(!m_pDoc)
406 return FALSE;
407
408 CPDF_Dictionary* pRoot = m_pDoc->GetPDFDoc()->GetRoot();
409 if (!pRoot)
410 return FALSE;
411
412 CPDF_Object* pOpenAction = pRoot->GetDict("OpenAction");
413 if(!pOpenAction)
414 pOpenAction = pRoot->GetArray("OpenAction");
415
416 if(!pOpenAction)
417 return FALSE;
418
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700419 if(pOpenAction->GetType()==PDFOBJ_ARRAY)
Tom Sepez7b5bc262015-03-05 16:44:22 -0800420 return TRUE;
421
422 if(pOpenAction->GetType()==PDFOBJ_DICTIONARY)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700423 {
Tom Sepez7b5bc262015-03-05 16:44:22 -0800424 CPDF_Dictionary * pDict=(CPDF_Dictionary*)pOpenAction;
425 CPDF_Action action(pDict);
426 if(m_pEnv->GetActionHander())
427 m_pEnv->GetActionHander()->DoAction_DocOpen(action, this);
428 return TRUE;
429 }
430 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700431}
432
433CPDF_OCContext* CPDFSDK_Document::GetOCContext()
434{
435 if(!m_pOccontent)
Bo Xufdc00a72014-10-28 23:03:33 -0700436 m_pOccontent = new CPDF_OCContext(m_pDoc->GetPDFDoc());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700437 return m_pOccontent;
438}
439
Bo Xufdc00a72014-10-28 23:03:33 -0700440void CPDFSDK_Document::ReMovePageView(CPDFXFA_Page* pPDFXFAPage)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700441{
Bo Xufdc00a72014-10-28 23:03:33 -0700442 CPDFSDK_PageView* pPageView = (CPDFSDK_PageView*)m_pageMap.GetValueAt(pPDFXFAPage);
unknown636ad3b2014-10-29 19:37:24 +0800443 if(pPageView && !pPageView->IsLocked())
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700444 {
445 delete pPageView;
Bo Xufdc00a72014-10-28 23:03:33 -0700446 m_pageMap.RemoveKey(pPDFXFAPage);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700447 }
448}
449
Bo Xufdc00a72014-10-28 23:03:33 -0700450CPDFXFA_Page * CPDFSDK_Document::GetPage(int nIndex)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700451{
Bo Xufdc00a72014-10-28 23:03:33 -0700452 CPDFXFA_Page * pTempPage = (CPDFXFA_Page*)m_pEnv->FFI_GetPage(m_pDoc,nIndex);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700453 if(!pTempPage)
454 return NULL;
455 return pTempPage;
456}
457
458CPDFSDK_InterForm* CPDFSDK_Document::GetInterForm()
459{
460 if(!m_pInterForm)
461 m_pInterForm = new CPDFSDK_InterForm(this);
462 return m_pInterForm;
463}
464
465void CPDFSDK_Document::UpdateAllViews(CPDFSDK_PageView* pSender, CPDFSDK_Annot* pAnnot)
466{
Lei Zhang60f507b2015-06-13 00:41:00 -0700467
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700468 FX_POSITION pos = m_pageMap.GetStartPosition();
Bo Xufdc00a72014-10-28 23:03:33 -0700469 CPDFXFA_Page * pPage = NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700470 CPDFSDK_PageView * pPageView = NULL;
471 while(pos)
472 {
473 m_pageMap.GetNextAssoc(pos, pPage, pPageView);
474
475 if(pPageView != pSender)
476 {
477 pPageView->UpdateView(pAnnot);
478 }
479 }
480}
481
482CPDFSDK_Annot* CPDFSDK_Document::GetFocusAnnot()
483{
Lei Zhang60f507b2015-06-13 00:41:00 -0700484 return m_pFocusAnnot;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700485}
486
487FX_BOOL CPDFSDK_Document::SetFocusAnnot(CPDFSDK_Annot* pAnnot,FX_UINT nFlag)
488{
489
490 if(m_pFocusAnnot==pAnnot) return TRUE;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700491
Bo Xufdc00a72014-10-28 23:03:33 -0700492 CPDFSDK_Annot* pLastFocusAnnot = m_pFocusAnnot;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700493
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700494 if(m_pFocusAnnot)
495 {
Lei Zhang60f507b2015-06-13 00:41:00 -0700496 if(!KillFocusAnnot(nFlag) ) return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700497 }
Bo Xufdc00a72014-10-28 23:03:33 -0700498 CPDFSDK_PageView* pPageView = NULL;
499 if (pAnnot)
500 pPageView = pAnnot->GetPageView();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700501 if(pAnnot && pPageView->IsValid())
502 {
503 CPDFSDK_AnnotHandlerMgr *pAnnotHandler=m_pEnv->GetAnnotHandlerMgr();
504
505 if(pAnnotHandler&&!m_pFocusAnnot)
506 {
Bo Xufdc00a72014-10-28 23:03:33 -0700507 if (!pAnnotHandler->Annot_OnChangeFocus(pAnnot,pLastFocusAnnot))
508 return FALSE;
509
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700510 if (!pAnnotHandler->Annot_OnSetFocus(pAnnot,nFlag))
511 return FALSE;
512 if(!m_pFocusAnnot)
513 {
Lei Zhang60f507b2015-06-13 00:41:00 -0700514 m_pFocusAnnot=pAnnot;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700515 return TRUE;
516 }
Lei Zhang60f507b2015-06-13 00:41:00 -0700517 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700518 }
519 return FALSE;
520}
521
522FX_BOOL CPDFSDK_Document::KillFocusAnnot(FX_UINT nFlag)
523{
524 if(m_pFocusAnnot)
525 {
526 CPDFSDK_AnnotHandlerMgr *pAnnotHandler=m_pEnv->GetAnnotHandlerMgr();
527 if(pAnnotHandler)
528 {
529 CPDFSDK_Annot* pFocusAnnot = m_pFocusAnnot;
530 m_pFocusAnnot = NULL;
Bo Xufdc00a72014-10-28 23:03:33 -0700531
532 if (!pAnnotHandler->Annot_OnChangeFocus(NULL, pFocusAnnot))
533 return FALSE;
534
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700535 if(pAnnotHandler->Annot_OnKillFocus(pFocusAnnot, nFlag))
536 {
Lei Zhang60f507b2015-06-13 00:41:00 -0700537
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700538 if(pFocusAnnot->GetType() == FX_BSTRC("Widget"))
539 {
540 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pFocusAnnot;
541 int nFieldType = pWidget->GetFieldType();
542 if(FIELDTYPE_TEXTFIELD == nFieldType || FIELDTYPE_COMBOBOX == nFieldType)
543 m_pEnv->FFI_OnSetFieldInputFocus(NULL, NULL, 0, FALSE);
544 }
545
546 if(!m_pFocusAnnot)
547 return TRUE;
548 }
549 else
550 {
551 m_pFocusAnnot = pFocusAnnot;
552 }
553 }
554 }
555 return FALSE;
556}
557
558FX_BOOL CPDFSDK_Document::DeletePages(int nStart, int nCount)
559{
560 if ( nStart < 0 || nStart >= GetPageCount() || nCount <= 0 )
561 {
562 return FALSE;
563 }
564
Bo Xufdc00a72014-10-28 23:03:33 -0700565 CPDFXFA_Page * pTempPage = NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700566 for ( int i = nCount-1; i >= 0; i-- )
567 {
568 pTempPage = GetPage(nStart+i);
569 if ( pTempPage != NULL )
570 {
571 ReMovePageView(pTempPage);
572 }
573 }
574 return TRUE;
575}
576
577void CPDFSDK_Document::OnCloseDocument()
578{
579 KillFocusAnnot();
580}
581
582FX_BOOL CPDFSDK_Document::GetPermissions(int nFlag)
583{
Bo Xufdc00a72014-10-28 23:03:33 -0700584 FX_DWORD dwPermissions = m_pDoc->GetPDFDoc()->GetUserPermissions();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700585 return dwPermissions&nFlag;
586}
587
588IFXJS_Runtime * CPDFSDK_Document::GetJsRuntime()
589{
590 ASSERT(m_pEnv!=NULL);
591 return m_pEnv->GetJSRuntime();
592}
593
Lei Zhang60f507b2015-06-13 00:41:00 -0700594CFX_WideString CPDFSDK_Document::GetPath()
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700595{
596 ASSERT(m_pEnv != NULL);
597 return m_pEnv->JS_docGetFilePath();
598}
599
600
Bo Xufdc00a72014-10-28 23:03:33 -0700601CPDFSDK_PageView::CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc,CPDFXFA_Page* page):m_page(page),m_pSDKDoc(pSDKDoc)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700602{
603 CPDFSDK_InterForm* pInterForm = pSDKDoc->GetInterForm();
604 if(pInterForm)
605 {
606 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm();
Bo Xufdc00a72014-10-28 23:03:33 -0700607 if (page->GetPDFPage())
608 pPDFInterForm->FixPageFields(page->GetPDFPage());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700609 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700610 m_fxAnnotArray.RemoveAll();
611
612 m_bEnterWidget = FALSE;
613 m_bExitWidget = FALSE;
614 m_bOnWidget = FALSE;
615 m_CaptureWidget = NULL;
616 m_bValid = FALSE;
unknown636ad3b2014-10-29 19:37:24 +0800617 m_bLocked = FALSE;
Bo Xufdc00a72014-10-28 23:03:33 -0700618 m_pAnnotList = NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700619}
620
621CPDFSDK_PageView::~CPDFSDK_PageView()
622{
Lei Zhang60f507b2015-06-13 00:41:00 -0700623 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700624 int nAnnotCount = m_fxAnnotArray.GetSize();
625 for (int i=0; i<nAnnotCount; i++)
626 {
627 CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i);
628 //if there is a focused annot on the page, we should kill the focus first.
629 if(pAnnot == m_pSDKDoc->GetFocusAnnot())
630 KillFocusAnnot();
631 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
632 ASSERT(pAnnotHandlerMgr);
633 pAnnotHandlerMgr->ReleaseAnnot(pAnnot);
634 }
635 m_fxAnnotArray.RemoveAll();
Lei Zhang6d8b1c22015-06-19 17:26:17 -0700636
637 delete m_pAnnotList;
638 m_pAnnotList = NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700639}
640
Bo Xufdc00a72014-10-28 23:03:33 -0700641void 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 -0700642{
643 m_curMatrix = *pUser2Device;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700644 // m_pAnnotList->DisplayAnnots(m_page, pDevice, pUser2Device, FALSE, pOptions);
645 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
Bo Xufdc00a72014-10-28 23:03:33 -0700646 CPDFXFA_Page* pPage = GetPDFXFAPage();
647
648 if (pPage == NULL) return;
649
650 if (pPage->GetDocument()->GetDocType() == DOCTYPE_DYNIMIC_XFA) {
651 CFX_Graphics gs;
652 gs.Create(pDevice);
653 if (pClip) {
654 CFX_RectF rectClip;
Bruce Dawson3f49aa32015-01-08 11:47:49 -0800655 rectClip.Set(static_cast<FX_FLOAT>(pClip->left),
656 static_cast<FX_FLOAT>(pClip->top),
657 static_cast<FX_FLOAT>(pClip->Width()),
658 static_cast<FX_FLOAT>(pClip->Height()));
Bo Xufdc00a72014-10-28 23:03:33 -0700659 gs.SetClipRect(rectClip);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700660 }
Bo Xufdc00a72014-10-28 23:03:33 -0700661 IXFA_RenderContext* pRenderContext = XFA_RenderContext_Create();
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700662 if (!pRenderContext)
Bo Xufdc00a72014-10-28 23:03:33 -0700663 return;
664 CXFA_RenderOptions renderOptions;
665 renderOptions.m_bHighlight = TRUE;
666 pRenderContext->StartRender(pPage->GetXFAPageView(), &gs, *pUser2Device, renderOptions);
667 pRenderContext->DoRender();
668 pRenderContext->StopRender();
669 pRenderContext->Release();
670 return;
671 }
672 // for pdf/static xfa.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700673 CPDFSDK_AnnotIterator annotIterator(this, TRUE);
674 CPDFSDK_Annot * pSDKAnnot=NULL;
675 int index=-1;
Bo Xufdc00a72014-10-28 23:03:33 -0700676 pSDKAnnot = annotIterator.Next(index);
677 while(pSDKAnnot)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700678 {
679 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
680 ASSERT(pAnnotHandlerMgr);
681 pAnnotHandlerMgr->Annot_OnDraw(this, pSDKAnnot, pDevice, pUser2Device, 0);
Bo Xufdc00a72014-10-28 23:03:33 -0700682 pSDKAnnot = annotIterator.Next(index);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700683 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700684}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700685CPDF_Annot* CPDFSDK_PageView::GetPDFAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY)
686{
Lei Zhang60f507b2015-06-13 00:41:00 -0700687
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700688 int nCount = m_pAnnotList->Count();
689 for(int i = 0 ; i<nCount; i++)
690 {
691 CPDF_Annot* pAnnot = m_pAnnotList->GetAt(i);
692 CFX_FloatRect annotRect;
693 pAnnot->GetRect(annotRect);
694 if(annotRect.Contains(pageX, pageY))
695 return pAnnot;
696 }
697 return NULL;
698}
699
700CPDF_Annot* CPDFSDK_PageView::GetPDFWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY)
701{
Lei Zhang60f507b2015-06-13 00:41:00 -0700702
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700703 int nCount = m_pAnnotList->Count();
704 for(int i = 0 ; i<nCount; i++)
705 {
706 CPDF_Annot* pAnnot = m_pAnnotList->GetAt(i);
707 if(pAnnot->GetSubType() == "Widget")
708 {
709 CFX_FloatRect annotRect;
710 pAnnot->GetRect(annotRect);
711 if(annotRect.Contains(pageX, pageY))
712 return pAnnot;
713 }
714 }
715 return NULL;
716}
717
718CPDFSDK_Annot* CPDFSDK_PageView::GetFXAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY)
719{
720
721 CPDFSDK_AnnotIterator annotIterator(this, FALSE);
722 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
723 CPDFSDK_AnnotHandlerMgr* pAnnotMgr = pEnv->GetAnnotHandlerMgr();
724 CPDFSDK_Annot* pSDKAnnot = NULL;
725 int index = -1;
Bo Xufdc00a72014-10-28 23:03:33 -0700726 pSDKAnnot = annotIterator.Next(index);
727 while(pSDKAnnot)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700728 {
729 CPDF_Rect rc = pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot);
730 if(rc.Contains(pageX, pageY))
731 return pSDKAnnot;
Bo Xufdc00a72014-10-28 23:03:33 -0700732 pSDKAnnot = annotIterator.Next(index);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700733 }
734
735 return NULL;
736}
737
738CPDFSDK_Annot* CPDFSDK_PageView::GetFXWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY)
739{
740
741 CPDFSDK_AnnotIterator annotIterator(this, FALSE);
742 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
743 CPDFSDK_AnnotHandlerMgr* pAnnotMgr = pEnv->GetAnnotHandlerMgr();
744 CPDFSDK_Annot* pSDKAnnot = NULL;
745 int index = -1;
Bo Xufdc00a72014-10-28 23:03:33 -0700746 pSDKAnnot = annotIterator.Next(index);
747 while(pSDKAnnot)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700748 {
Bo Xufdc00a72014-10-28 23:03:33 -0700749 if(pSDKAnnot->GetType() == "Widget" || pSDKAnnot->GetType() == FSDK_XFAWIDGET_TYPENAME)
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700750 {
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700751 pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot);
752 CPDF_Point point(pageX, pageY);
753 if (pAnnotMgr->Annot_OnHitTest(this, pSDKAnnot, point))
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700754 return pSDKAnnot;
755 }
Bo Xufdc00a72014-10-28 23:03:33 -0700756 pSDKAnnot = annotIterator.Next(index);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700757 }
Lei Zhang60f507b2015-06-13 00:41:00 -0700758
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700759 return NULL;
760}
761
762
763FX_BOOL CPDFSDK_PageView::Annot_HasAppearance(CPDF_Annot* pAnnot)
764{
Lei Zhang64adf192015-06-05 15:50:32 -0700765 CPDF_Dictionary* pAnnotDic = pAnnot->GetAnnotDict();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700766 if(pAnnotDic)
767 return pAnnotDic->KeyExist("AS");
768 return FALSE;
769}
770
771CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CPDF_Annot * pPDFAnnot)
772{
773 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
774 ASSERT(pEnv);
Lei Zhang60f507b2015-06-13 00:41:00 -0700775 CPDFSDK_AnnotHandlerMgr * pAnnotHandler= pEnv->GetAnnotHandlerMgr();
776
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700777 CPDFSDK_Annot* pSDKAnnot =NULL;
Lei Zhang60f507b2015-06-13 00:41:00 -0700778
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700779 if(pAnnotHandler)
780 {
781 pSDKAnnot = pAnnotHandler->NewAnnot(pPDFAnnot, this);
782 }
Lei Zhang60f507b2015-06-13 00:41:00 -0700783 if(!pSDKAnnot)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700784 return NULL;
785
Lei Zhang60f507b2015-06-13 00:41:00 -0700786 m_fxAnnotArray.Add(pSDKAnnot);
787
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700788 if(pAnnotHandler)
Lei Zhang60f507b2015-06-13 00:41:00 -0700789 {
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700790 pAnnotHandler->Annot_OnCreate(pSDKAnnot);
Lei Zhang60f507b2015-06-13 00:41:00 -0700791
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700792 }
793
794 return pSDKAnnot;
795}
796
Tom Sepezeed467d2015-06-02 10:35:27 -0700797CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(IXFA_Widget* pPDFAnnot)
Bo Xufdc00a72014-10-28 23:03:33 -0700798{
799 if (!pPDFAnnot) return NULL;
800
801 CPDFSDK_Annot* pSDKAnnot = GetAnnotByXFAWidget(pPDFAnnot);
802 if (pSDKAnnot)
803 return pSDKAnnot;
804
805 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
806 ASSERT(pEnv);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700807 CPDFSDK_AnnotHandlerMgr * pAnnotHandler= pEnv->GetAnnotHandlerMgr();
Bo Xufdc00a72014-10-28 23:03:33 -0700808
809 pSDKAnnot =NULL;
810
811 if(pAnnotHandler)
812 {
813 pSDKAnnot = pAnnotHandler->NewAnnot(pPDFAnnot, this);
814 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700815 if(!pSDKAnnot)
Bo Xufdc00a72014-10-28 23:03:33 -0700816 return NULL;
817
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700818 m_fxAnnotArray.Add(pSDKAnnot);
Bo Xufdc00a72014-10-28 23:03:33 -0700819
820 return pSDKAnnot;
821}
822
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700823CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CPDF_Dictionary * pDict)
824{
Lei Zhang60f507b2015-06-13 00:41:00 -0700825 return pDict ? AddAnnot(pDict->GetString("Subtype"), pDict) : nullptr;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700826}
827
Tom Sepezd7e5cc72015-06-10 14:33:37 -0700828CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(const FX_CHAR* lpSubType,CPDF_Dictionary * pDict)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700829{
830 return NULL;
831}
832
833FX_BOOL CPDFSDK_PageView::DeleteAnnot(CPDFSDK_Annot* pAnnot)
834{
Bo Xufdc00a72014-10-28 23:03:33 -0700835 if (!pAnnot)
836 return FALSE;
837 CPDFXFA_Page* pPage = pAnnot->GetPDFXFAPage();
838 if (!pPage || (pPage->GetDocument()->GetDocType() != DOCTYPE_STATIC_XFA && pPage->GetDocument()->GetDocType() != DOCTYPE_DYNIMIC_XFA))
839 return FALSE;
840
841 int index = m_fxAnnotArray.Find(pAnnot);
842 m_fxAnnotArray.RemoveAt(index);
843 if (m_CaptureWidget == pAnnot)
844 m_CaptureWidget = NULL;
845
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700846 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700847}
848
849CPDF_Document* CPDFSDK_PageView::GetPDFDocument()
850{
851 if(m_page)
852 {
Bo Xufdc00a72014-10-28 23:03:33 -0700853 return m_page->GetDocument()->GetPDFDoc();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700854 }
855 return NULL;
856}
857
Bo Xufdc00a72014-10-28 23:03:33 -0700858CPDF_Page* CPDFSDK_PageView::GetPDFPage()
859{
860 if (m_page)
861 {
862 return m_page->GetPDFPage();
863 }
864
865 return NULL;
866}
867
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700868int CPDFSDK_PageView::CountAnnots()
869{
Bo Xufdc00a72014-10-28 23:03:33 -0700870 return m_fxAnnotArray.GetSize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700871}
872
873CPDFSDK_Annot* CPDFSDK_PageView::GetAnnot(int nIndex)
874{
875 int nCount = m_fxAnnotArray.GetSize();
876 if ( nIndex < 0 || nIndex >= nCount )
877 {
878 return NULL;
879 }
880
881 return (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(nIndex);
882}
883
884CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByDict(CPDF_Dictionary * pDict)
885{
886 int nCount = m_fxAnnotArray.GetSize();
887 for(int i=0; i<nCount; i++)
888 {
889 CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i);
Lei Zhang64adf192015-06-05 15:50:32 -0700890 if (pDict == pAnnot->GetPDFAnnot()->GetAnnotDict())
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700891 return pAnnot;
892 }
893 return NULL;
894}
Tom Sepezeed467d2015-06-02 10:35:27 -0700895CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByXFAWidget(IXFA_Widget* hWidget)
Bo Xufdc00a72014-10-28 23:03:33 -0700896{
897 if (hWidget == NULL)
898 return NULL;
899 int annotCount = m_fxAnnotArray.GetSize();
900
901 for(int i = 0; i < annotCount; i++)
902 {
903 CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i);
904 if(pAnnot->GetXFAWidget() == hWidget)
905 return pAnnot;
906 }
907 return NULL;
908}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700909
910FX_BOOL CPDFSDK_PageView::OnLButtonDown(const CPDF_Point & point, FX_UINT nFlag)
911{
912 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
913 ASSERT(pEnv);
914 CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y);
915 if(!pFXAnnot)
916 {
917 KillFocusAnnot(nFlag);
918 }
919 else
920 {
921 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
922 ASSERT(pAnnotHandlerMgr);
923
924 FX_BOOL bRet = pAnnotHandlerMgr->Annot_OnLButtonDown(this, pFXAnnot, nFlag,point);
925 if(bRet)
926 {
927 SetFocusAnnot(pFXAnnot);
928 }
929 return bRet;
930 }
931 return FALSE;
932}
933
Bo Xufdc00a72014-10-28 23:03:33 -0700934FX_BOOL CPDFSDK_PageView::OnRButtonDown(const CPDF_Point & point, FX_UINT nFlag)
935{
936 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
937 ASSERT(pEnv);
938 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
939 ASSERT(pAnnotHandlerMgr);
940
941 CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y);
942
943 if (pFXAnnot == NULL)
944 return FALSE;
945
946 FX_BOOL bRet = pAnnotHandlerMgr->Annot_OnRButtonDown(this, pFXAnnot, nFlag,point);
947 if (bRet)
948 {
949 SetFocusAnnot(pFXAnnot);
950 }
951 return TRUE;
952}
953
954FX_BOOL CPDFSDK_PageView::OnRButtonUp(const CPDF_Point & point, FX_UINT nFlag)
955{
956 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
957 ASSERT(pEnv);
958 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
959 ASSERT(pAnnotHandlerMgr);
960
961 CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y);
962
963 if (pFXAnnot == NULL)
964 return FALSE;
965
966 FX_BOOL bRet = pAnnotHandlerMgr->Annot_OnRButtonUp(this, pFXAnnot, nFlag,point);
967 if (bRet)
968 {
969 SetFocusAnnot(pFXAnnot);
970 }
971 return TRUE;
972}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700973
974FX_BOOL CPDFSDK_PageView::OnLButtonUp(const CPDF_Point & point, FX_UINT nFlag)
975{
976 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
977 ASSERT(pEnv);
978 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
979 ASSERT(pAnnotHandlerMgr);
980 CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y);
981 CPDFSDK_Annot* pFocusAnnot = GetFocusAnnot();
982 FX_BOOL bRet = FALSE;
983 if(pFocusAnnot && pFocusAnnot != pFXAnnot)
984 {
985 //Last focus Annot gets a chance to handle the event.
986 bRet = pAnnotHandlerMgr->Annot_OnLButtonUp(this, pFocusAnnot, nFlag,point);
987 }
988 if(pFXAnnot && !bRet)
989 {
990 bRet = pAnnotHandlerMgr->Annot_OnLButtonUp(this, pFXAnnot, nFlag,point);
991 return bRet;
992 }
993 return bRet;
994}
995
996FX_BOOL CPDFSDK_PageView::OnMouseMove(const CPDF_Point & point, int nFlag)
997{
998
999 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1000 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
1001 ASSERT(pAnnotHandlerMgr);
1002 if(CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y))
1003 {
1004 if(m_CaptureWidget && m_CaptureWidget != pFXAnnot)
1005 {
1006 m_bExitWidget = TRUE;
1007 m_bEnterWidget = FALSE;
1008 pAnnotHandlerMgr->Annot_OnMouseExit(this, m_CaptureWidget, nFlag);
1009 }
1010 m_CaptureWidget = (CPDFSDK_Widget*)pFXAnnot;
1011 m_bOnWidget = TRUE;
1012 if(!m_bEnterWidget)
1013 {
1014 m_bEnterWidget = TRUE;
1015 m_bExitWidget = FALSE;
1016 pAnnotHandlerMgr->Annot_OnMouseEnter(this, pFXAnnot,nFlag);
1017 }
1018 pAnnotHandlerMgr->Annot_OnMouseMove(this, pFXAnnot, nFlag, point);
1019 return TRUE;
1020 }
1021 else
1022 {
1023 if(m_bOnWidget)
Lei Zhang60f507b2015-06-13 00:41:00 -07001024 {
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001025 m_bOnWidget = FALSE;
1026 m_bExitWidget = TRUE;
1027 m_bEnterWidget = FALSE;
1028 if(m_CaptureWidget)
1029 {
1030 pAnnotHandlerMgr->Annot_OnMouseExit(this, m_CaptureWidget, nFlag);
1031 m_CaptureWidget = NULL;
1032 }
1033 }
1034 return FALSE;
1035 }
Lei Zhang60f507b2015-06-13 00:41:00 -07001036
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001037 return FALSE;;
1038}
1039
1040FX_BOOL CPDFSDK_PageView::OnMouseWheel(double deltaX, double deltaY,const CPDF_Point& point, int nFlag)
1041{
1042 if(CPDFSDK_Annot* pAnnot = GetFXWidgetAtPoint(point.x, point.y))
1043 {
1044 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1045 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
1046 ASSERT(pAnnotHandlerMgr);
1047 return pAnnotHandlerMgr->Annot_OnMouseWheel(this, pAnnot, nFlag, (int)deltaY, point);
1048 }
1049 return FALSE;
1050
1051}
1052
1053FX_BOOL CPDFSDK_PageView::OnChar(int nChar, FX_UINT nFlag)
1054{
1055 if(CPDFSDK_Annot* pAnnot = GetFocusAnnot())
1056 {
1057 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1058 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
1059 ASSERT(pAnnotHandlerMgr);
1060 return pAnnotHandlerMgr->Annot_OnChar(pAnnot, nChar, nFlag);
1061 }
1062
1063 return FALSE;
1064}
1065
1066FX_BOOL CPDFSDK_PageView::OnKeyDown(int nKeyCode, int nFlag)
1067{
1068 if(CPDFSDK_Annot* pAnnot = GetFocusAnnot())
1069 {
1070 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1071 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
1072 ASSERT(pAnnotHandlerMgr);
1073 return pAnnotHandlerMgr->Annot_OnKeyDown(pAnnot, nKeyCode, nFlag);
1074 }
1075 return FALSE;
1076}
1077
1078FX_BOOL CPDFSDK_PageView::OnKeyUp(int nKeyCode, int nFlag)
1079{
1080// if(CPDFSDK_Annot* pAnnot = GetFocusAnnot())
1081// {
1082// CFFL_IFormFiller* pIFormFiller = g_pFormFillApp->GetIFormFiller();
1083// return pIFormFiller->OnKeyUp(pAnnot, nKeyCode, nFlag);
1084// }
1085 return FALSE;
1086}
1087
1088extern void CheckUnSupportAnnot(CPDF_Document * pDoc, CPDF_Annot* pPDFAnnot);
1089
1090void CPDFSDK_PageView::LoadFXAnnots()
1091{
Bo Xufdc00a72014-10-28 23:03:33 -07001092 ASSERT(m_page != NULL);
1093
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001094 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
Bo Xufdc00a72014-10-28 23:03:33 -07001095 ASSERT(pEnv != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001096
Bo Xufdc00a72014-10-28 23:03:33 -07001097 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
1098 ASSERT(pAnnotHandlerMgr != NULL);
1099
unknown636ad3b2014-10-29 19:37:24 +08001100 SetLock(TRUE);
1101 m_page->AddRef();
Bo Xufdc00a72014-10-28 23:03:33 -07001102 if (m_pSDKDoc->GetDocument()->GetDocType() == DOCTYPE_DYNIMIC_XFA)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001103 {
Bo Xufdc00a72014-10-28 23:03:33 -07001104 IXFA_PageView* pageView = NULL;
1105 pageView = m_page->GetXFAPageView();
1106 ASSERT(pageView != NULL);
1107
Bo Xufdc00a72014-10-28 23:03:33 -07001108 IXFA_WidgetIterator* pWidgetHander = pageView->CreateWidgetIterator(XFA_TRAVERSEWAY_Form, XFA_WIDGETFILTER_Visible|XFA_WIDGETFILTER_Viewable|XFA_WIDGETFILTER_AllType);
1109 if (!pWidgetHander)
unknown636ad3b2014-10-29 19:37:24 +08001110 {
1111 m_page->Release();
1112 SetLock(FALSE);
Bo Xufdc00a72014-10-28 23:03:33 -07001113 return;
unknown636ad3b2014-10-29 19:37:24 +08001114 }
Bo Xufdc00a72014-10-28 23:03:33 -07001115
Tom Sepezeed467d2015-06-02 10:35:27 -07001116 IXFA_Widget* pXFAAnnot = pWidgetHander->MoveToNext();
Bo Xufdc00a72014-10-28 23:03:33 -07001117 while (pXFAAnnot) {
1118 CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pXFAAnnot, this);
1119 if(!pAnnot) {
1120 pXFAAnnot = pWidgetHander->MoveToNext();
1121 continue;
1122 }
1123 m_fxAnnotArray.Add(pAnnot);
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07001124
Bo Xufdc00a72014-10-28 23:03:33 -07001125 pAnnotHandlerMgr->Annot_OnLoad(pAnnot);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001126
Bo Xufdc00a72014-10-28 23:03:33 -07001127 pXFAAnnot = pWidgetHander->MoveToNext();
Bo Xufacd0152014-09-24 10:49:52 -07001128
Bo Xufdc00a72014-10-28 23:03:33 -07001129 }
1130
1131 pWidgetHander->Release();
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07001132 }
1133 else
Bo Xufdc00a72014-10-28 23:03:33 -07001134 {
1135 CPDF_Page* pPage = m_page->GetPDFPage();
1136 ASSERT(pPage != NULL);
1137
1138 FX_BOOL enableAPUpdate = CPDF_InterForm::UpdatingAPEnabled();
1139 //Disable the default AP construction.
1140 CPDF_InterForm::EnableUpdateAP(FALSE);
1141 m_pAnnotList = new CPDF_AnnotList(pPage);
1142 CPDF_InterForm::EnableUpdateAP(enableAPUpdate);
1143
1144 int nCount = m_pAnnotList->Count();
1145 for(int i=0; i<nCount; i++)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001146 {
Bo Xufdc00a72014-10-28 23:03:33 -07001147 CPDF_Annot* pPDFAnnot = m_pAnnotList->GetAt(i);
Lei Zhang60f507b2015-06-13 00:41:00 -07001148 CPDF_Document * pDoc = GetPDFDocument();
Bo Xufdc00a72014-10-28 23:03:33 -07001149
1150 CheckUnSupportAnnot(pDoc, pPDFAnnot);
1151
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001152 CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pPDFAnnot, this);
1153 if(!pAnnot)
1154 continue;
1155 m_fxAnnotArray.Add(pAnnot);
1156
1157 pAnnotHandlerMgr->Annot_OnLoad(pAnnot);
1158 }
1159
1160 }
unknown636ad3b2014-10-29 19:37:24 +08001161 m_page->Release();
1162 SetLock(FALSE);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001163}
1164
1165void CPDFSDK_PageView::UpdateRects(CFX_RectArray& rects)
1166{
1167 for(int i=0; i<rects.GetSize(); i++)
1168 {
1169 CPDF_Rect rc = rects.GetAt(i);
1170 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1171 pEnv->FFI_Invalidate(m_page, rc.left, rc.top, rc.right, rc.bottom);
1172 }
1173}
1174
1175void CPDFSDK_PageView::UpdateView(CPDFSDK_Annot* pAnnot)
1176{
Lei Zhang60f507b2015-06-13 00:41:00 -07001177 CPDF_Rect rcWindow = pAnnot->GetRect();
1178 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1179 pEnv->FFI_Invalidate(
1180 m_page, rcWindow.left, rcWindow.top, rcWindow.right, rcWindow.bottom);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001181}
1182
1183int CPDFSDK_PageView::GetPageIndex()
1184{
1185 if(m_page)
1186 {
Bo Xufdc00a72014-10-28 23:03:33 -07001187 CPDF_Dictionary* pDic = m_page->GetPDFPage()->m_pFormDict;
1188 CPDFXFA_Document* pDoc = m_pSDKDoc->GetDocument();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001189 if(pDoc && pDic)
1190 {
Bo Xufdc00a72014-10-28 23:03:33 -07001191 return pDoc->GetPDFDoc()->GetPageIndex(pDic->GetObjNum());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001192 }
1193 }
1194 return -1;
1195}
1196
Tom Sepezd7e5cc72015-06-10 14:33:37 -07001197FX_BOOL CPDFSDK_PageView::IsValidAnnot(void* p)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001198{
1199 if (p == NULL) return FALSE;
1200 int iCount = m_pAnnotList->Count();
1201 for (int i = 0; i < iCount; i++)
1202 {
1203 if (m_pAnnotList->GetAt(i) == p)
1204 return TRUE;
1205 }
1206 return FALSE;
1207}
1208
1209
1210CPDFSDK_Annot* CPDFSDK_PageView::GetFocusAnnot()
1211{
1212 CPDFSDK_Annot* pFocusAnnot = m_pSDKDoc->GetFocusAnnot();
1213 if(!pFocusAnnot)
1214 return NULL;
Lei Zhang60f507b2015-06-13 00:41:00 -07001215
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001216 for(int i=0; i<m_fxAnnotArray.GetSize(); i++)
1217 {
1218 CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i);
1219 if(pAnnot == pFocusAnnot)
1220 return pAnnot;
1221 }
1222 return NULL;
1223}
1224