blob: 4f457bd86a425dc12a760b7f439d5d4212a01c33 [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.
4
5// 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;}
36
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
41 FXCT_ARROW
42 FXCT_NESW
43 FXCT_NWSE
44 FXCT_VBEAM
45 FXCT_HBEAM
46 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);
116 CPDF_Point ptB = pFFL->PWLtoFFL(righttop);
117
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 }
125
126}
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
Tom Sepezbfa9a822015-06-09 13:24:12 -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)
154 {
155 int nSize = pFontMapper->m_InstalledTTFonts.GetSize();
156 if(nSize ==0)
157 {
158 pFontMapper->LoadInstalledFonts();
159 nSize = pFontMapper->m_InstalledTTFonts.GetSize();
160 }
161
162 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}
188CPDF_Font* CFX_SystemHandler::AddNativeTrueTypeFontToPDF(CPDF_Document* pDoc, CFX_ByteString sFontFaceName,
Tom Sepezbfa9a822015-06-09 13:24:12 -0700189 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{
283 m_pInfo = pFFinfo;
284 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{
unknown636ad3b2014-10-29 19:37:24 +0800319 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 }
Bo Xufdc00a72014-10-28 23:03:33 -0700327 m_pageMap.RemoveAll();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700328 if(m_pInterForm)
329 {
330 m_pInterForm->Destroy();
331 m_pInterForm = NULL;
332 }
333 if(m_pOccontent)
334 {
335 delete m_pOccontent;
336 m_pOccontent = NULL;
337 }
338}
339
340void CPDFSDK_Document::InitPageView()
341{
342 int nCount = m_pDoc->GetPageCount();
343 for(int i=0; i<nCount; i++)
344 {
345 // To do
346// CPDF_Dictionary* pDic = m_pDoc->GetPage(i);
347// m_pageMap.SetAt(pDic, pPageView);
348 }
349}
350
Bo Xufdc00a72014-10-28 23:03:33 -0700351void CPDFSDK_Document::AddPageView(CPDFXFA_Page* pPDFXFAPage, CPDFSDK_PageView* pPageView)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700352{
Bo Xufdc00a72014-10-28 23:03:33 -0700353 m_pageMap.SetAt(pPDFXFAPage, pPageView);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700354}
355
Bo Xufdc00a72014-10-28 23:03:33 -0700356CPDFSDK_PageView* CPDFSDK_Document::GetPageView(CPDFXFA_Page* pPDFXFAPage, FX_BOOL ReNew)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700357{
Bo Xufdc00a72014-10-28 23:03:33 -0700358 CPDFSDK_PageView* pPageView = (CPDFSDK_PageView*)m_pageMap.GetValueAt(pPDFXFAPage);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700359 if(pPageView != NULL)
360 return pPageView;
361 if(ReNew)
362 {
Bo Xufdc00a72014-10-28 23:03:33 -0700363 pPageView = new CPDFSDK_PageView(this,pPDFXFAPage);
364 m_pageMap.SetAt(pPDFXFAPage, pPageView);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700365 //Delay to load all the annotations, to avoid endless loop.
366 pPageView->LoadFXAnnots();
367 }
368 return pPageView;
369
370}
371
372CPDFSDK_PageView* CPDFSDK_Document::GetCurrentView()
373{
Bo Xufdc00a72014-10-28 23:03:33 -0700374 CPDFXFA_Page * pPage = (CPDFXFA_Page *)m_pEnv->FFI_GetCurrentPage(m_pDoc);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700375 if(pPage)
376 return this->GetPageView(pPage, TRUE);
377 return NULL;
378}
379
380CPDFSDK_PageView* CPDFSDK_Document::GetPageView(int nIndex)
381{
382 CPDFSDK_PageView * pTempPageView = NULL;
Bo Xufdc00a72014-10-28 23:03:33 -0700383 CPDFXFA_Page * pTempPage = (CPDFXFA_Page*)m_pEnv->FFI_GetPage(m_pDoc,nIndex);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700384 if(!pTempPage)
385 return NULL;
386
387 m_pageMap.Lookup(pTempPage, pTempPageView);
388
389 ASSERT(pTempPageView != NULL);
390
391 return pTempPageView;
392}
393
394void CPDFSDK_Document:: ProcJavascriptFun()
395{
Bo Xufdc00a72014-10-28 23:03:33 -0700396 CPDFXFA_Document* pPDFDoc = this->GetDocument();
397 CPDF_DocJSActions docJS(pPDFDoc->GetPDFDoc());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700398 int iCount = docJS.CountJSActions();
399 if (iCount < 1) return;
400 for (int i = 0; i < iCount; i ++)
401 {
402 CFX_ByteString csJSName;
403 CPDF_Action jsAction = docJS.GetJSAction(i, csJSName);
404 if(m_pEnv->GetActionHander())
405 m_pEnv->GetActionHander()->DoAction_JavaScript(jsAction,CFX_WideString::FromLocal(csJSName),this);
406 }
407
408}
409
410FX_BOOL CPDFSDK_Document::ProcOpenAction()
411{
Tom Sepez7b5bc262015-03-05 16:44:22 -0800412 if(!m_pDoc)
413 return FALSE;
414
415 CPDF_Dictionary* pRoot = m_pDoc->GetPDFDoc()->GetRoot();
416 if (!pRoot)
417 return FALSE;
418
419 CPDF_Object* pOpenAction = pRoot->GetDict("OpenAction");
420 if(!pOpenAction)
421 pOpenAction = pRoot->GetArray("OpenAction");
422
423 if(!pOpenAction)
424 return FALSE;
425
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700426 if(pOpenAction->GetType()==PDFOBJ_ARRAY)
Tom Sepez7b5bc262015-03-05 16:44:22 -0800427 return TRUE;
428
429 if(pOpenAction->GetType()==PDFOBJ_DICTIONARY)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700430 {
Tom Sepez7b5bc262015-03-05 16:44:22 -0800431 CPDF_Dictionary * pDict=(CPDF_Dictionary*)pOpenAction;
432 CPDF_Action action(pDict);
433 if(m_pEnv->GetActionHander())
434 m_pEnv->GetActionHander()->DoAction_DocOpen(action, this);
435 return TRUE;
436 }
437 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700438}
439
440CPDF_OCContext* CPDFSDK_Document::GetOCContext()
441{
442 if(!m_pOccontent)
Bo Xufdc00a72014-10-28 23:03:33 -0700443 m_pOccontent = new CPDF_OCContext(m_pDoc->GetPDFDoc());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700444 return m_pOccontent;
445}
446
Bo Xufdc00a72014-10-28 23:03:33 -0700447void CPDFSDK_Document::ReMovePageView(CPDFXFA_Page* pPDFXFAPage)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700448{
Bo Xufdc00a72014-10-28 23:03:33 -0700449 CPDFSDK_PageView* pPageView = (CPDFSDK_PageView*)m_pageMap.GetValueAt(pPDFXFAPage);
unknown636ad3b2014-10-29 19:37:24 +0800450 if(pPageView && !pPageView->IsLocked())
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700451 {
452 delete pPageView;
Bo Xufdc00a72014-10-28 23:03:33 -0700453 m_pageMap.RemoveKey(pPDFXFAPage);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700454 }
455}
456
Bo Xufdc00a72014-10-28 23:03:33 -0700457CPDFXFA_Page * CPDFSDK_Document::GetPage(int nIndex)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700458{
Bo Xufdc00a72014-10-28 23:03:33 -0700459 CPDFXFA_Page * pTempPage = (CPDFXFA_Page*)m_pEnv->FFI_GetPage(m_pDoc,nIndex);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700460 if(!pTempPage)
461 return NULL;
462 return pTempPage;
463}
464
465CPDFSDK_InterForm* CPDFSDK_Document::GetInterForm()
466{
467 if(!m_pInterForm)
468 m_pInterForm = new CPDFSDK_InterForm(this);
469 return m_pInterForm;
470}
471
472void CPDFSDK_Document::UpdateAllViews(CPDFSDK_PageView* pSender, CPDFSDK_Annot* pAnnot)
473{
474
475 FX_POSITION pos = m_pageMap.GetStartPosition();
Bo Xufdc00a72014-10-28 23:03:33 -0700476 CPDFXFA_Page * pPage = NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700477 CPDFSDK_PageView * pPageView = NULL;
478 while(pos)
479 {
480 m_pageMap.GetNextAssoc(pos, pPage, pPageView);
481
482 if(pPageView != pSender)
483 {
484 pPageView->UpdateView(pAnnot);
485 }
486 }
487}
488
489CPDFSDK_Annot* CPDFSDK_Document::GetFocusAnnot()
490{
491 return this->m_pFocusAnnot;
492}
493
494FX_BOOL CPDFSDK_Document::SetFocusAnnot(CPDFSDK_Annot* pAnnot,FX_UINT nFlag)
495{
496
497 if(m_pFocusAnnot==pAnnot) return TRUE;
498
Bo Xufdc00a72014-10-28 23:03:33 -0700499 CPDFSDK_Annot* pLastFocusAnnot = m_pFocusAnnot;
500
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700501 if(m_pFocusAnnot)
502 {
503 if(!this->KillFocusAnnot(nFlag) ) return FALSE;
504 }
Bo Xufdc00a72014-10-28 23:03:33 -0700505 CPDFSDK_PageView* pPageView = NULL;
506 if (pAnnot)
507 pPageView = pAnnot->GetPageView();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700508 if(pAnnot && pPageView->IsValid())
509 {
510 CPDFSDK_AnnotHandlerMgr *pAnnotHandler=m_pEnv->GetAnnotHandlerMgr();
511
512 if(pAnnotHandler&&!m_pFocusAnnot)
513 {
Bo Xufdc00a72014-10-28 23:03:33 -0700514 if (!pAnnotHandler->Annot_OnChangeFocus(pAnnot,pLastFocusAnnot))
515 return FALSE;
516
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700517 if (!pAnnotHandler->Annot_OnSetFocus(pAnnot,nFlag))
518 return FALSE;
519 if(!m_pFocusAnnot)
520 {
521 this->m_pFocusAnnot=pAnnot;
522 return TRUE;
523 }
524 }
525 }
526 return FALSE;
527}
528
529FX_BOOL CPDFSDK_Document::KillFocusAnnot(FX_UINT nFlag)
530{
531 if(m_pFocusAnnot)
532 {
533 CPDFSDK_AnnotHandlerMgr *pAnnotHandler=m_pEnv->GetAnnotHandlerMgr();
534 if(pAnnotHandler)
535 {
536 CPDFSDK_Annot* pFocusAnnot = m_pFocusAnnot;
537 m_pFocusAnnot = NULL;
Bo Xufdc00a72014-10-28 23:03:33 -0700538
539 if (!pAnnotHandler->Annot_OnChangeFocus(NULL, pFocusAnnot))
540 return FALSE;
541
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700542 if(pAnnotHandler->Annot_OnKillFocus(pFocusAnnot, nFlag))
543 {
544
545 if(pFocusAnnot->GetType() == FX_BSTRC("Widget"))
546 {
547 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pFocusAnnot;
548 int nFieldType = pWidget->GetFieldType();
549 if(FIELDTYPE_TEXTFIELD == nFieldType || FIELDTYPE_COMBOBOX == nFieldType)
550 m_pEnv->FFI_OnSetFieldInputFocus(NULL, NULL, 0, FALSE);
551 }
552
553 if(!m_pFocusAnnot)
554 return TRUE;
555 }
556 else
557 {
558 m_pFocusAnnot = pFocusAnnot;
559 }
560 }
561 }
562 return FALSE;
563}
564
565FX_BOOL CPDFSDK_Document::DeletePages(int nStart, int nCount)
566{
567 if ( nStart < 0 || nStart >= GetPageCount() || nCount <= 0 )
568 {
569 return FALSE;
570 }
571
Bo Xufdc00a72014-10-28 23:03:33 -0700572 CPDFXFA_Page * pTempPage = NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700573 for ( int i = nCount-1; i >= 0; i-- )
574 {
575 pTempPage = GetPage(nStart+i);
576 if ( pTempPage != NULL )
577 {
578 ReMovePageView(pTempPage);
579 }
580 }
581 return TRUE;
582}
583
584void CPDFSDK_Document::OnCloseDocument()
585{
586 KillFocusAnnot();
587}
588
589FX_BOOL CPDFSDK_Document::GetPermissions(int nFlag)
590{
Bo Xufdc00a72014-10-28 23:03:33 -0700591 FX_DWORD dwPermissions = m_pDoc->GetPDFDoc()->GetUserPermissions();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700592 return dwPermissions&nFlag;
593}
594
595IFXJS_Runtime * CPDFSDK_Document::GetJsRuntime()
596{
597 ASSERT(m_pEnv!=NULL);
598 return m_pEnv->GetJSRuntime();
599}
600
601CFX_WideString CPDFSDK_Document::GetPath()
602{
603 ASSERT(m_pEnv != NULL);
604 return m_pEnv->JS_docGetFilePath();
605}
606
607
Bo Xufdc00a72014-10-28 23:03:33 -0700608CPDFSDK_PageView::CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc,CPDFXFA_Page* page):m_page(page),m_pSDKDoc(pSDKDoc)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700609{
610 CPDFSDK_InterForm* pInterForm = pSDKDoc->GetInterForm();
611 if(pInterForm)
612 {
613 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm();
Bo Xufdc00a72014-10-28 23:03:33 -0700614 if (page->GetPDFPage())
615 pPDFInterForm->FixPageFields(page->GetPDFPage());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700616 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700617 m_fxAnnotArray.RemoveAll();
618
619 m_bEnterWidget = FALSE;
620 m_bExitWidget = FALSE;
621 m_bOnWidget = FALSE;
622 m_CaptureWidget = NULL;
623 m_bValid = FALSE;
unknown636ad3b2014-10-29 19:37:24 +0800624 m_bLocked = FALSE;
Bo Xufdc00a72014-10-28 23:03:33 -0700625 m_pAnnotList = NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700626}
627
628CPDFSDK_PageView::~CPDFSDK_PageView()
629{
630 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
631 int nAnnotCount = m_fxAnnotArray.GetSize();
632 for (int i=0; i<nAnnotCount; i++)
633 {
634 CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i);
635 //if there is a focused annot on the page, we should kill the focus first.
636 if(pAnnot == m_pSDKDoc->GetFocusAnnot())
637 KillFocusAnnot();
638 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
639 ASSERT(pAnnotHandlerMgr);
640 pAnnotHandlerMgr->ReleaseAnnot(pAnnot);
641 }
642 m_fxAnnotArray.RemoveAll();
643 if(m_pAnnotList)
644 {
645 delete m_pAnnotList;
646 m_pAnnotList = NULL;
647 }
648}
649
Bo Xufdc00a72014-10-28 23:03:33 -0700650void 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 -0700651{
652 m_curMatrix = *pUser2Device;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700653 // m_pAnnotList->DisplayAnnots(m_page, pDevice, pUser2Device, FALSE, pOptions);
654 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
Bo Xufdc00a72014-10-28 23:03:33 -0700655 CPDFXFA_Page* pPage = GetPDFXFAPage();
656
657 if (pPage == NULL) return;
658
659 if (pPage->GetDocument()->GetDocType() == DOCTYPE_DYNIMIC_XFA) {
660 CFX_Graphics gs;
661 gs.Create(pDevice);
662 if (pClip) {
663 CFX_RectF rectClip;
Bruce Dawson3f49aa32015-01-08 11:47:49 -0800664 rectClip.Set(static_cast<FX_FLOAT>(pClip->left),
665 static_cast<FX_FLOAT>(pClip->top),
666 static_cast<FX_FLOAT>(pClip->Width()),
667 static_cast<FX_FLOAT>(pClip->Height()));
Bo Xufdc00a72014-10-28 23:03:33 -0700668 gs.SetClipRect(rectClip);
669 }
670 IXFA_RenderContext* pRenderContext = XFA_RenderContext_Create();
671 if (!pRenderContext)
672 return;
673 CXFA_RenderOptions renderOptions;
674 renderOptions.m_bHighlight = TRUE;
675 pRenderContext->StartRender(pPage->GetXFAPageView(), &gs, *pUser2Device, renderOptions);
676 pRenderContext->DoRender();
677 pRenderContext->StopRender();
678 pRenderContext->Release();
679 return;
680 }
681 // for pdf/static xfa.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700682 CPDFSDK_AnnotIterator annotIterator(this, TRUE);
683 CPDFSDK_Annot * pSDKAnnot=NULL;
684 int index=-1;
Bo Xufdc00a72014-10-28 23:03:33 -0700685 pSDKAnnot = annotIterator.Next(index);
686 while(pSDKAnnot)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700687 {
688 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
689 ASSERT(pAnnotHandlerMgr);
690 pAnnotHandlerMgr->Annot_OnDraw(this, pSDKAnnot, pDevice, pUser2Device, 0);
Bo Xufdc00a72014-10-28 23:03:33 -0700691 pSDKAnnot = annotIterator.Next(index);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700692 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700693}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700694CPDF_Annot* CPDFSDK_PageView::GetPDFAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY)
695{
696
697 int nCount = m_pAnnotList->Count();
698 for(int i = 0 ; i<nCount; i++)
699 {
700 CPDF_Annot* pAnnot = m_pAnnotList->GetAt(i);
701 CFX_FloatRect annotRect;
702 pAnnot->GetRect(annotRect);
703 if(annotRect.Contains(pageX, pageY))
704 return pAnnot;
705 }
706 return NULL;
707}
708
709CPDF_Annot* CPDFSDK_PageView::GetPDFWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY)
710{
711
712 int nCount = m_pAnnotList->Count();
713 for(int i = 0 ; i<nCount; i++)
714 {
715 CPDF_Annot* pAnnot = m_pAnnotList->GetAt(i);
716 if(pAnnot->GetSubType() == "Widget")
717 {
718 CFX_FloatRect annotRect;
719 pAnnot->GetRect(annotRect);
720 if(annotRect.Contains(pageX, pageY))
721 return pAnnot;
722 }
723 }
724 return NULL;
725}
726
727CPDFSDK_Annot* CPDFSDK_PageView::GetFXAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY)
728{
729
730 CPDFSDK_AnnotIterator annotIterator(this, FALSE);
731 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
732 CPDFSDK_AnnotHandlerMgr* pAnnotMgr = pEnv->GetAnnotHandlerMgr();
733 CPDFSDK_Annot* pSDKAnnot = NULL;
734 int index = -1;
Bo Xufdc00a72014-10-28 23:03:33 -0700735 pSDKAnnot = annotIterator.Next(index);
736 while(pSDKAnnot)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700737 {
738 CPDF_Rect rc = pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot);
739 if(rc.Contains(pageX, pageY))
740 return pSDKAnnot;
Bo Xufdc00a72014-10-28 23:03:33 -0700741 pSDKAnnot = annotIterator.Next(index);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700742 }
743
744 return NULL;
745}
746
747CPDFSDK_Annot* CPDFSDK_PageView::GetFXWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY)
748{
749
750 CPDFSDK_AnnotIterator annotIterator(this, FALSE);
751 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
752 CPDFSDK_AnnotHandlerMgr* pAnnotMgr = pEnv->GetAnnotHandlerMgr();
753 CPDFSDK_Annot* pSDKAnnot = NULL;
754 int index = -1;
Bo Xufdc00a72014-10-28 23:03:33 -0700755 pSDKAnnot = annotIterator.Next(index);
756 while(pSDKAnnot)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700757 {
Bo Xufdc00a72014-10-28 23:03:33 -0700758 if(pSDKAnnot->GetType() == "Widget" || pSDKAnnot->GetType() == FSDK_XFAWIDGET_TYPENAME)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700759 {
760 pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot);
761 CPDF_Point point(pageX, pageY);
762 if (pAnnotMgr->Annot_OnHitTest(this, pSDKAnnot, point))
763// if(rc.Contains(pageX, pageY))
764 return pSDKAnnot;
765 }
Bo Xufdc00a72014-10-28 23:03:33 -0700766 pSDKAnnot = annotIterator.Next(index);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700767 }
768
769 return NULL;
770}
771
772
773FX_BOOL CPDFSDK_PageView::Annot_HasAppearance(CPDF_Annot* pAnnot)
774{
Lei Zhang64adf192015-06-05 15:50:32 -0700775 CPDF_Dictionary* pAnnotDic = pAnnot->GetAnnotDict();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700776 if(pAnnotDic)
777 return pAnnotDic->KeyExist("AS");
778 return FALSE;
779}
780
781CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CPDF_Annot * pPDFAnnot)
782{
783 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
784 ASSERT(pEnv);
785 CPDFSDK_AnnotHandlerMgr * pAnnotHandler= pEnv->GetAnnotHandlerMgr();
786
787 CPDFSDK_Annot* pSDKAnnot =NULL;
788
789 if(pAnnotHandler)
790 {
791 pSDKAnnot = pAnnotHandler->NewAnnot(pPDFAnnot, this);
792 }
793 if(!pSDKAnnot)
794 return NULL;
795
796 m_fxAnnotArray.Add(pSDKAnnot);
797
798 if(pAnnotHandler)
799 {
800 pAnnotHandler->Annot_OnCreate(pSDKAnnot);
801
802 }
803
804 return pSDKAnnot;
805}
806
Tom Sepezeed467d2015-06-02 10:35:27 -0700807CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(IXFA_Widget* pPDFAnnot)
Bo Xufdc00a72014-10-28 23:03:33 -0700808{
809 if (!pPDFAnnot) return NULL;
810
811 CPDFSDK_Annot* pSDKAnnot = GetAnnotByXFAWidget(pPDFAnnot);
812 if (pSDKAnnot)
813 return pSDKAnnot;
814
815 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
816 ASSERT(pEnv);
817 CPDFSDK_AnnotHandlerMgr * pAnnotHandler= pEnv->GetAnnotHandlerMgr();
818
819 pSDKAnnot =NULL;
820
821 if(pAnnotHandler)
822 {
823 pSDKAnnot = pAnnotHandler->NewAnnot(pPDFAnnot, this);
824 }
825 if(!pSDKAnnot)
826 return NULL;
827
828 m_fxAnnotArray.Add(pSDKAnnot);
829
830 return pSDKAnnot;
831}
832
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700833CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CPDF_Dictionary * pDict)
834{
835 if(pDict)
836 return this->AddAnnot(pDict->GetString("Subtype"),pDict);
837 return NULL;
838}
839
Tom Sepezd7e5cc72015-06-10 14:33:37 -0700840CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(const FX_CHAR* lpSubType,CPDF_Dictionary * pDict)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700841{
842 return NULL;
843}
844
845FX_BOOL CPDFSDK_PageView::DeleteAnnot(CPDFSDK_Annot* pAnnot)
846{
Bo Xufdc00a72014-10-28 23:03:33 -0700847 if (!pAnnot)
848 return FALSE;
849 CPDFXFA_Page* pPage = pAnnot->GetPDFXFAPage();
850 if (!pPage || (pPage->GetDocument()->GetDocType() != DOCTYPE_STATIC_XFA && pPage->GetDocument()->GetDocType() != DOCTYPE_DYNIMIC_XFA))
851 return FALSE;
852
853 int index = m_fxAnnotArray.Find(pAnnot);
854 m_fxAnnotArray.RemoveAt(index);
855 if (m_CaptureWidget == pAnnot)
856 m_CaptureWidget = NULL;
857
858 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700859}
860
861CPDF_Document* CPDFSDK_PageView::GetPDFDocument()
862{
863 if(m_page)
864 {
Bo Xufdc00a72014-10-28 23:03:33 -0700865 return m_page->GetDocument()->GetPDFDoc();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700866 }
867 return NULL;
868}
869
Bo Xufdc00a72014-10-28 23:03:33 -0700870CPDF_Page* CPDFSDK_PageView::GetPDFPage()
871{
872 if (m_page)
873 {
874 return m_page->GetPDFPage();
875 }
876
877 return NULL;
878}
879
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700880int CPDFSDK_PageView::CountAnnots()
881{
Bo Xufdc00a72014-10-28 23:03:33 -0700882 return m_fxAnnotArray.GetSize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700883}
884
885CPDFSDK_Annot* CPDFSDK_PageView::GetAnnot(int nIndex)
886{
887 int nCount = m_fxAnnotArray.GetSize();
888 if ( nIndex < 0 || nIndex >= nCount )
889 {
890 return NULL;
891 }
892
893 return (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(nIndex);
894}
895
896CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByDict(CPDF_Dictionary * pDict)
897{
898 int nCount = m_fxAnnotArray.GetSize();
899 for(int i=0; i<nCount; i++)
900 {
901 CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i);
Lei Zhang64adf192015-06-05 15:50:32 -0700902 if (pDict == pAnnot->GetPDFAnnot()->GetAnnotDict())
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700903 return pAnnot;
904 }
905 return NULL;
906}
Tom Sepezeed467d2015-06-02 10:35:27 -0700907CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByXFAWidget(IXFA_Widget* hWidget)
Bo Xufdc00a72014-10-28 23:03:33 -0700908{
909 if (hWidget == NULL)
910 return NULL;
911 int annotCount = m_fxAnnotArray.GetSize();
912
913 for(int i = 0; i < annotCount; i++)
914 {
915 CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i);
916 if(pAnnot->GetXFAWidget() == hWidget)
917 return pAnnot;
918 }
919 return NULL;
920}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700921
922FX_BOOL CPDFSDK_PageView::OnLButtonDown(const CPDF_Point & point, FX_UINT nFlag)
923{
924 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
925 ASSERT(pEnv);
926 CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y);
927 if(!pFXAnnot)
928 {
929 KillFocusAnnot(nFlag);
930 }
931 else
932 {
933 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
934 ASSERT(pAnnotHandlerMgr);
935
936 FX_BOOL bRet = pAnnotHandlerMgr->Annot_OnLButtonDown(this, pFXAnnot, nFlag,point);
937 if(bRet)
938 {
939 SetFocusAnnot(pFXAnnot);
940 }
941 return bRet;
942 }
943 return FALSE;
944}
945
Bo Xufdc00a72014-10-28 23:03:33 -0700946FX_BOOL CPDFSDK_PageView::OnRButtonDown(const CPDF_Point & point, FX_UINT nFlag)
947{
948 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
949 ASSERT(pEnv);
950 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
951 ASSERT(pAnnotHandlerMgr);
952
953 CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y);
954
955 if (pFXAnnot == NULL)
956 return FALSE;
957
958 FX_BOOL bRet = pAnnotHandlerMgr->Annot_OnRButtonDown(this, pFXAnnot, nFlag,point);
959 if (bRet)
960 {
961 SetFocusAnnot(pFXAnnot);
962 }
963 return TRUE;
964}
965
966FX_BOOL CPDFSDK_PageView::OnRButtonUp(const CPDF_Point & point, FX_UINT nFlag)
967{
968 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
969 ASSERT(pEnv);
970 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
971 ASSERT(pAnnotHandlerMgr);
972
973 CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y);
974
975 if (pFXAnnot == NULL)
976 return FALSE;
977
978 FX_BOOL bRet = pAnnotHandlerMgr->Annot_OnRButtonUp(this, pFXAnnot, nFlag,point);
979 if (bRet)
980 {
981 SetFocusAnnot(pFXAnnot);
982 }
983 return TRUE;
984}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700985
986FX_BOOL CPDFSDK_PageView::OnLButtonUp(const CPDF_Point & point, FX_UINT nFlag)
987{
988 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
989 ASSERT(pEnv);
990 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
991 ASSERT(pAnnotHandlerMgr);
992 CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y);
993 CPDFSDK_Annot* pFocusAnnot = GetFocusAnnot();
994 FX_BOOL bRet = FALSE;
995 if(pFocusAnnot && pFocusAnnot != pFXAnnot)
996 {
997 //Last focus Annot gets a chance to handle the event.
998 bRet = pAnnotHandlerMgr->Annot_OnLButtonUp(this, pFocusAnnot, nFlag,point);
999 }
1000 if(pFXAnnot && !bRet)
1001 {
1002 bRet = pAnnotHandlerMgr->Annot_OnLButtonUp(this, pFXAnnot, nFlag,point);
1003 return bRet;
1004 }
1005 return bRet;
1006}
1007
1008FX_BOOL CPDFSDK_PageView::OnMouseMove(const CPDF_Point & point, int nFlag)
1009{
1010
1011 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1012 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
1013 ASSERT(pAnnotHandlerMgr);
1014 if(CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y))
1015 {
1016 if(m_CaptureWidget && m_CaptureWidget != pFXAnnot)
1017 {
1018 m_bExitWidget = TRUE;
1019 m_bEnterWidget = FALSE;
1020 pAnnotHandlerMgr->Annot_OnMouseExit(this, m_CaptureWidget, nFlag);
1021 }
1022 m_CaptureWidget = (CPDFSDK_Widget*)pFXAnnot;
1023 m_bOnWidget = TRUE;
1024 if(!m_bEnterWidget)
1025 {
1026 m_bEnterWidget = TRUE;
1027 m_bExitWidget = FALSE;
1028 pAnnotHandlerMgr->Annot_OnMouseEnter(this, pFXAnnot,nFlag);
1029 }
1030 pAnnotHandlerMgr->Annot_OnMouseMove(this, pFXAnnot, nFlag, point);
1031 return TRUE;
1032 }
1033 else
1034 {
1035 if(m_bOnWidget)
1036 {
1037 m_bOnWidget = FALSE;
1038 m_bExitWidget = TRUE;
1039 m_bEnterWidget = FALSE;
1040 if(m_CaptureWidget)
1041 {
1042 pAnnotHandlerMgr->Annot_OnMouseExit(this, m_CaptureWidget, nFlag);
1043 m_CaptureWidget = NULL;
1044 }
1045 }
1046 return FALSE;
1047 }
1048
1049 return FALSE;;
1050}
1051
1052FX_BOOL CPDFSDK_PageView::OnMouseWheel(double deltaX, double deltaY,const CPDF_Point& point, int nFlag)
1053{
1054 if(CPDFSDK_Annot* pAnnot = GetFXWidgetAtPoint(point.x, point.y))
1055 {
1056 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1057 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
1058 ASSERT(pAnnotHandlerMgr);
1059 return pAnnotHandlerMgr->Annot_OnMouseWheel(this, pAnnot, nFlag, (int)deltaY, point);
1060 }
1061 return FALSE;
1062
1063}
1064
1065FX_BOOL CPDFSDK_PageView::OnChar(int nChar, FX_UINT nFlag)
1066{
1067 if(CPDFSDK_Annot* pAnnot = GetFocusAnnot())
1068 {
1069 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1070 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
1071 ASSERT(pAnnotHandlerMgr);
1072 return pAnnotHandlerMgr->Annot_OnChar(pAnnot, nChar, nFlag);
1073 }
1074
1075 return FALSE;
1076}
1077
1078FX_BOOL CPDFSDK_PageView::OnKeyDown(int nKeyCode, int nFlag)
1079{
1080 if(CPDFSDK_Annot* pAnnot = GetFocusAnnot())
1081 {
1082 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1083 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
1084 ASSERT(pAnnotHandlerMgr);
1085 return pAnnotHandlerMgr->Annot_OnKeyDown(pAnnot, nKeyCode, nFlag);
1086 }
1087 return FALSE;
1088}
1089
1090FX_BOOL CPDFSDK_PageView::OnKeyUp(int nKeyCode, int nFlag)
1091{
1092// if(CPDFSDK_Annot* pAnnot = GetFocusAnnot())
1093// {
1094// CFFL_IFormFiller* pIFormFiller = g_pFormFillApp->GetIFormFiller();
1095// return pIFormFiller->OnKeyUp(pAnnot, nKeyCode, nFlag);
1096// }
1097 return FALSE;
1098}
1099
1100extern void CheckUnSupportAnnot(CPDF_Document * pDoc, CPDF_Annot* pPDFAnnot);
1101
1102void CPDFSDK_PageView::LoadFXAnnots()
1103{
Bo Xufdc00a72014-10-28 23:03:33 -07001104 ASSERT(m_page != NULL);
1105
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001106 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
Bo Xufdc00a72014-10-28 23:03:33 -07001107 ASSERT(pEnv != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001108
Bo Xufdc00a72014-10-28 23:03:33 -07001109 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
1110 ASSERT(pAnnotHandlerMgr != NULL);
1111
unknown636ad3b2014-10-29 19:37:24 +08001112 SetLock(TRUE);
1113 m_page->AddRef();
Bo Xufdc00a72014-10-28 23:03:33 -07001114 if (m_pSDKDoc->GetDocument()->GetDocType() == DOCTYPE_DYNIMIC_XFA)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001115 {
Bo Xufdc00a72014-10-28 23:03:33 -07001116 IXFA_PageView* pageView = NULL;
1117 pageView = m_page->GetXFAPageView();
1118 ASSERT(pageView != NULL);
1119
Bo Xufdc00a72014-10-28 23:03:33 -07001120 IXFA_WidgetIterator* pWidgetHander = pageView->CreateWidgetIterator(XFA_TRAVERSEWAY_Form, XFA_WIDGETFILTER_Visible|XFA_WIDGETFILTER_Viewable|XFA_WIDGETFILTER_AllType);
1121 if (!pWidgetHander)
unknown636ad3b2014-10-29 19:37:24 +08001122 {
1123 m_page->Release();
1124 SetLock(FALSE);
Bo Xufdc00a72014-10-28 23:03:33 -07001125 return;
unknown636ad3b2014-10-29 19:37:24 +08001126 }
Bo Xufdc00a72014-10-28 23:03:33 -07001127
Tom Sepezeed467d2015-06-02 10:35:27 -07001128 IXFA_Widget* pXFAAnnot = pWidgetHander->MoveToNext();
Bo Xufdc00a72014-10-28 23:03:33 -07001129 while (pXFAAnnot) {
1130 CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pXFAAnnot, this);
1131 if(!pAnnot) {
1132 pXFAAnnot = pWidgetHander->MoveToNext();
1133 continue;
1134 }
1135 m_fxAnnotArray.Add(pAnnot);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001136
Bo Xufdc00a72014-10-28 23:03:33 -07001137 pAnnotHandlerMgr->Annot_OnLoad(pAnnot);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001138
Bo Xufdc00a72014-10-28 23:03:33 -07001139 pXFAAnnot = pWidgetHander->MoveToNext();
Bo Xufacd0152014-09-24 10:49:52 -07001140
Bo Xufdc00a72014-10-28 23:03:33 -07001141 }
1142
1143 pWidgetHander->Release();
1144 }
1145 else
1146 {
1147 CPDF_Page* pPage = m_page->GetPDFPage();
1148 ASSERT(pPage != NULL);
1149
1150 FX_BOOL enableAPUpdate = CPDF_InterForm::UpdatingAPEnabled();
1151 //Disable the default AP construction.
1152 CPDF_InterForm::EnableUpdateAP(FALSE);
1153 m_pAnnotList = new CPDF_AnnotList(pPage);
1154 CPDF_InterForm::EnableUpdateAP(enableAPUpdate);
1155
1156 int nCount = m_pAnnotList->Count();
1157 for(int i=0; i<nCount; i++)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001158 {
Bo Xufdc00a72014-10-28 23:03:33 -07001159 CPDF_Annot* pPDFAnnot = m_pAnnotList->GetAt(i);
1160 CPDF_Document * pDoc = this->GetPDFDocument();
1161
1162 CheckUnSupportAnnot(pDoc, pPDFAnnot);
1163
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001164 CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pPDFAnnot, this);
1165 if(!pAnnot)
1166 continue;
1167 m_fxAnnotArray.Add(pAnnot);
1168
1169 pAnnotHandlerMgr->Annot_OnLoad(pAnnot);
1170 }
1171
1172 }
unknown636ad3b2014-10-29 19:37:24 +08001173 m_page->Release();
1174 SetLock(FALSE);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001175}
1176
1177void CPDFSDK_PageView::UpdateRects(CFX_RectArray& rects)
1178{
1179 for(int i=0; i<rects.GetSize(); i++)
1180 {
1181 CPDF_Rect rc = rects.GetAt(i);
1182 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1183 pEnv->FFI_Invalidate(m_page, rc.left, rc.top, rc.right, rc.bottom);
1184 }
1185}
1186
1187void CPDFSDK_PageView::UpdateView(CPDFSDK_Annot* pAnnot)
1188{
1189 CPDF_Rect rcWindow;
1190
1191 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1192// CPDFSDK_AnnotHandlerMgr* pAnnotHandler = pEnv->GetAnnotHandlerMgr();
1193
1194 rcWindow = pAnnot->GetRect();//pAnnotHandler->Annot_OnGetViewBBox(this,pAnnot);
1195 pEnv->FFI_Invalidate(m_page, rcWindow.left, rcWindow.top, rcWindow.right, rcWindow.bottom);
1196
1197}
1198
1199int CPDFSDK_PageView::GetPageIndex()
1200{
1201 if(m_page)
1202 {
Bo Xufdc00a72014-10-28 23:03:33 -07001203 CPDF_Dictionary* pDic = m_page->GetPDFPage()->m_pFormDict;
1204 CPDFXFA_Document* pDoc = m_pSDKDoc->GetDocument();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001205 if(pDoc && pDic)
1206 {
Bo Xufdc00a72014-10-28 23:03:33 -07001207 return pDoc->GetPDFDoc()->GetPageIndex(pDic->GetObjNum());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001208 }
1209 }
1210 return -1;
1211}
1212
Tom Sepezd7e5cc72015-06-10 14:33:37 -07001213FX_BOOL CPDFSDK_PageView::IsValidAnnot(void* p)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001214{
1215 if (p == NULL) return FALSE;
1216 int iCount = m_pAnnotList->Count();
1217 for (int i = 0; i < iCount; i++)
1218 {
1219 if (m_pAnnotList->GetAt(i) == p)
1220 return TRUE;
1221 }
1222 return FALSE;
1223}
1224
1225
1226CPDFSDK_Annot* CPDFSDK_PageView::GetFocusAnnot()
1227{
1228 CPDFSDK_Annot* pFocusAnnot = m_pSDKDoc->GetFocusAnnot();
1229 if(!pFocusAnnot)
1230 return NULL;
1231
1232 for(int i=0; i<m_fxAnnotArray.GetSize(); i++)
1233 {
1234 CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i);
1235 if(pAnnot == pFocusAnnot)
1236 return pAnnot;
1237 }
1238 return NULL;
1239}
1240