blob: c4cee6f4d82e808ab6b38863eb7a42ac84911d14 [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
7#include "../include/fsdk_define.h"
Bo Xufdc00a72014-10-28 23:03:33 -07008#include "../include/fpdfxfa/fpdfxfa_doc.h"
9#include "../include/fpdfxfa/fpdfxfa_page.h"
10#include "../include/fpdfxfa/fpdfxfa_util.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070011#include "../include/fsdk_mgr.h"
12#include "../include/fpdf_ext.h"
13#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
37 virtual void ClientToScreen(FX_HWND hWnd, FX_INT32& x, FX_INT32& y) {}
38 virtual void ScreenToClient(FX_HWND hWnd, FX_INT32& x, FX_INT32& y) {}
39
40 /*cursor style
41 FXCT_ARROW
42 FXCT_NESW
43 FXCT_NWSE
44 FXCT_VBEAM
45 FXCT_HBEAM
46 FXCT_HAND
47 */
48 virtual void SetCursor(FX_INT32 nCursorType);
49
50 virtual FX_HMENU CreatePopupMenu() {return NULL;}
51 virtual FX_BOOL AppendMenuItem(FX_HMENU hMenu, FX_INT32 nIDNewItem, CFX_WideString string) {return FALSE;}
52 virtual FX_BOOL EnableMenuItem(FX_HMENU hMenu, FX_INT32 nIDItem, FX_BOOL bEnabled) {return FALSE;}
53 virtual FX_INT32 TrackPopupMenu(FX_HMENU hMenu, FX_INT32 x, FX_INT32 y, FX_HWND hParent) {return -1;}
54 virtual void DestroyMenu(FX_HMENU hMenu) {}
55
56 virtual CFX_ByteString GetNativeTrueTypeFont(FX_INT32 nCharset);
57 virtual FX_BOOL FindNativeTrueTypeFont(FX_INT32 nCharset, CFX_ByteString sFontFaceName);
58 virtual CPDF_Font* AddNativeTrueTypeFontToPDF(CPDF_Document* pDoc, CFX_ByteString sFontFaceName, FX_BYTE nCharset);
59
60 virtual FX_INT32 SetTimer(FX_INT32 uElapse, TimerCallback lpTimerFunc) ;
61 virtual void KillTimer(FX_INT32 nID) ;
62
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
71 virtual FX_INT32 GetCharSet() {return m_nCharSet;}
72 virtual void SetCharSet(FX_INT32 nCharSet) {m_nCharSet = nCharSet;}
73private:
74 CPDFDoc_Environment* m_pEnv;
75 int m_nCharSet;
76};
77
78void CFX_SystemHandler::SetCursor(FX_INT32 nCursorType)
79{
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
139CFX_ByteString CFX_SystemHandler::GetNativeTrueTypeFont(FX_INT32 nCharset)
140{
141 return "";
142}
143
144FX_BOOL CFX_SystemHandler::FindNativeTrueTypeFont(FX_INT32 nCharset, CFX_ByteString sFontFaceName)
145{
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,
189 FX_BYTE nCharset)
190{
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
204FX_INT32 CFX_SystemHandler::SetTimer(FX_INT32 uElapse, TimerCallback lpTimerFunc)
205{
206 return m_pEnv->FFI_SetTimer(uElapse, lpTimerFunc);
207}
208void CFX_SystemHandler::KillTimer(FX_INT32 nID)
209{
210 m_pEnv->FFI_KillTimer(nID);
211}
212
213FX_SYSTEMTIME CFX_SystemHandler::GetLocalTime()
214{
215 return m_pEnv->FFI_GetLocalTime();
216}
217
218
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700219
Bo Xufdc00a72014-10-28 23:03:33 -0700220CPDFDoc_Environment::CPDFDoc_Environment(CPDFXFA_Document* pDoc) :
Nico Weber09363c82014-07-31 10:07:04 -0700221 m_pAnnotHandlerMgr(NULL),
222 m_pActionHandler(NULL),
223 m_pJSRuntime(NULL),
224 m_pInfo(NULL),
225 m_pSDKDoc(NULL),
Bo Xufdc00a72014-10-28 23:03:33 -0700226 m_pDoc(pDoc),
Nico Weber09363c82014-07-31 10:07:04 -0700227 m_pIFormFiller(NULL)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700228{
229
230 m_pSysHandler = NULL;
231 m_pSysHandler = new CFX_SystemHandler(this);
232
Bo Xufdc00a72014-10-28 23:03:33 -0700233 //m_pJSRuntimeFactory = pDoc->GetApp()->GetRuntimeFactory();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700234
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700235}
236
237CPDFDoc_Environment::~CPDFDoc_Environment()
238{
239
240 if ( m_pIFormFiller )
241 {
242 delete m_pIFormFiller;
243 m_pIFormFiller = NULL;
244 }
Bo Xufdc00a72014-10-28 23:03:33 -0700245
246 if (m_pJSRuntime && FPDFXFA_GetApp()->GetRuntimeFactory())
247 FPDFXFA_GetApp()->GetRuntimeFactory()->DeleteJSRuntime(m_pJSRuntime);
248
249 if (FPDFXFA_GetApp()->m_pEnvList.GetSize() == 0)
250 {
251 FPDFXFA_GetApp()->ReleaseRuntime();
252 FPDFXFA_GetApp()->InitRuntime(TRUE);
253 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700254
255 if(m_pSysHandler)
256 {
257 delete m_pSysHandler;
258 m_pSysHandler = NULL;
259 }
260
261 if(m_pAnnotHandlerMgr)
262 {
263 delete m_pAnnotHandlerMgr;
264 m_pAnnotHandlerMgr = NULL;
265 }
266 if(m_pActionHandler)
267 {
268 delete m_pActionHandler;
269 m_pActionHandler = NULL;
270 }
271
272
273}
274
275
276IFXJS_Runtime* CPDFDoc_Environment::GetJSRuntime()
277{
278 if(!IsJSInitiated())
279 return NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700280 if(!m_pJSRuntime)
Bo Xufdc00a72014-10-28 23:03:33 -0700281 m_pJSRuntime = FPDFXFA_GetApp()->GetRuntimeFactory()->NewJSRuntime(this);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700282 return m_pJSRuntime;
283}
284
285CPDFSDK_AnnotHandlerMgr* CPDFDoc_Environment::GetAnnotHandlerMgr()
286{
287 if(!m_pAnnotHandlerMgr)
288 m_pAnnotHandlerMgr = new CPDFSDK_AnnotHandlerMgr(this);
289 return m_pAnnotHandlerMgr;
290}
291
292CPDFSDK_ActionHandler* CPDFDoc_Environment::GetActionHander()
293{
294 if(!m_pActionHandler)
295 m_pActionHandler = new CPDFSDK_ActionHandler(this);
296 return m_pActionHandler;
297}
298
299int CPDFDoc_Environment::RegAppHandle(FPDF_FORMFILLINFO* pFFinfo)
300{
301 m_pInfo = pFFinfo;
302 return TRUE;
303}
304
305CPDFSDK_Document* CPDFDoc_Environment::GetCurrentDoc()
306{
307 return m_pSDKDoc;
308}
309
310CFFL_IFormFiller* CPDFDoc_Environment::GetIFormFiller()
311{
312 if(!m_pIFormFiller)
313 m_pIFormFiller = new CFFL_IFormFiller(this);
314 return m_pIFormFiller;
315}
316
317FX_BOOL CPDFDoc_Environment::IsJSInitiated()
318{
319 if(m_pInfo)
320 {
321 if(m_pInfo->m_pJsPlatform)
322 return TRUE;
323 else
324 return FALSE;
325 }
326 return FALSE;
327}
328
Bo Xufdc00a72014-10-28 23:03:33 -0700329CPDFSDK_Document::CPDFSDK_Document(CPDFXFA_Document* pDoc,CPDFDoc_Environment* pEnv):m_pDoc(pDoc),
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700330 m_pInterForm(NULL),m_pEnv(pEnv),m_pOccontent(NULL),m_bChangeMask(FALSE)
331{
332 m_pFocusAnnot = NULL;
333}
334
335CPDFSDK_Document::~CPDFSDK_Document()
336{
unknown636ad3b2014-10-29 19:37:24 +0800337 FX_POSITION pos = m_pageMap.GetStartPosition();
338 while(pos)
339 {
340 CPDFXFA_Page* pPage = NULL;
341 CPDFSDK_PageView* pPageView = NULL;
342 m_pageMap.GetNextAssoc(pos, pPage, pPageView);
343 delete pPageView;
344 }
Bo Xufdc00a72014-10-28 23:03:33 -0700345 m_pageMap.RemoveAll();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700346 if(m_pInterForm)
347 {
348 m_pInterForm->Destroy();
349 m_pInterForm = NULL;
350 }
351 if(m_pOccontent)
352 {
353 delete m_pOccontent;
354 m_pOccontent = NULL;
355 }
356}
357
358void CPDFSDK_Document::InitPageView()
359{
360 int nCount = m_pDoc->GetPageCount();
361 for(int i=0; i<nCount; i++)
362 {
363 // To do
364// CPDF_Dictionary* pDic = m_pDoc->GetPage(i);
365// m_pageMap.SetAt(pDic, pPageView);
366 }
367}
368
Bo Xufdc00a72014-10-28 23:03:33 -0700369void CPDFSDK_Document::AddPageView(CPDFXFA_Page* pPDFXFAPage, CPDFSDK_PageView* pPageView)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700370{
Bo Xufdc00a72014-10-28 23:03:33 -0700371 m_pageMap.SetAt(pPDFXFAPage, pPageView);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700372}
373
Bo Xufdc00a72014-10-28 23:03:33 -0700374CPDFSDK_PageView* CPDFSDK_Document::GetPageView(CPDFXFA_Page* pPDFXFAPage, FX_BOOL ReNew)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700375{
Bo Xufdc00a72014-10-28 23:03:33 -0700376 CPDFSDK_PageView* pPageView = (CPDFSDK_PageView*)m_pageMap.GetValueAt(pPDFXFAPage);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700377 if(pPageView != NULL)
378 return pPageView;
379 if(ReNew)
380 {
Bo Xufdc00a72014-10-28 23:03:33 -0700381 pPageView = new CPDFSDK_PageView(this,pPDFXFAPage);
382 m_pageMap.SetAt(pPDFXFAPage, pPageView);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700383 //Delay to load all the annotations, to avoid endless loop.
384 pPageView->LoadFXAnnots();
385 }
386 return pPageView;
387
388}
389
390CPDFSDK_PageView* CPDFSDK_Document::GetCurrentView()
391{
Bo Xufdc00a72014-10-28 23:03:33 -0700392 CPDFXFA_Page * pPage = (CPDFXFA_Page *)m_pEnv->FFI_GetCurrentPage(m_pDoc);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700393 if(pPage)
394 return this->GetPageView(pPage, TRUE);
395 return NULL;
396}
397
398CPDFSDK_PageView* CPDFSDK_Document::GetPageView(int nIndex)
399{
400 CPDFSDK_PageView * pTempPageView = NULL;
Bo Xufdc00a72014-10-28 23:03:33 -0700401 CPDFXFA_Page * pTempPage = (CPDFXFA_Page*)m_pEnv->FFI_GetPage(m_pDoc,nIndex);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700402 if(!pTempPage)
403 return NULL;
404
405 m_pageMap.Lookup(pTempPage, pTempPageView);
406
407 ASSERT(pTempPageView != NULL);
408
409 return pTempPageView;
410}
411
412void CPDFSDK_Document:: ProcJavascriptFun()
413{
Bo Xufdc00a72014-10-28 23:03:33 -0700414 CPDFXFA_Document* pPDFDoc = this->GetDocument();
415 CPDF_DocJSActions docJS(pPDFDoc->GetPDFDoc());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700416 int iCount = docJS.CountJSActions();
417 if (iCount < 1) return;
418 for (int i = 0; i < iCount; i ++)
419 {
420 CFX_ByteString csJSName;
421 CPDF_Action jsAction = docJS.GetJSAction(i, csJSName);
422 if(m_pEnv->GetActionHander())
423 m_pEnv->GetActionHander()->DoAction_JavaScript(jsAction,CFX_WideString::FromLocal(csJSName),this);
424 }
425
426}
427
428FX_BOOL CPDFSDK_Document::ProcOpenAction()
429{
430 if(!m_pDoc) return FALSE;
431
Bo Xufdc00a72014-10-28 23:03:33 -0700432 CPDF_Dictionary* pRoot = m_pDoc->GetPDFDoc()->GetRoot();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700433 if (!pRoot) return FALSE;
434 CPDF_Object* pOpenAction = pRoot->GetDict("OpenAction");//
435 if(!pOpenAction) pOpenAction = pRoot->GetArray("OpenAction");//
436 if(!pOpenAction) return FALSE;
437
438 if(pOpenAction->GetType()==PDFOBJ_ARRAY)
439 {
440 }
441 else if(pOpenAction->GetType()==PDFOBJ_DICTIONARY)
442 {
443 CPDF_Dictionary * pDict=(CPDF_Dictionary*)pOpenAction;
444 CPDF_Action Action = pDict;
445
446 if(m_pEnv->GetActionHander())
447 m_pEnv->GetActionHander()->DoAction_DocOpen(Action,this);
448 }
449 else
450 {
451 return FALSE;
452 }
453 return TRUE;
454}
455
456CPDF_OCContext* CPDFSDK_Document::GetOCContext()
457{
458 if(!m_pOccontent)
Bo Xufdc00a72014-10-28 23:03:33 -0700459 m_pOccontent = new CPDF_OCContext(m_pDoc->GetPDFDoc());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700460 return m_pOccontent;
461}
462
Bo Xufdc00a72014-10-28 23:03:33 -0700463void CPDFSDK_Document::ReMovePageView(CPDFXFA_Page* pPDFXFAPage)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700464{
Bo Xufdc00a72014-10-28 23:03:33 -0700465 CPDFSDK_PageView* pPageView = (CPDFSDK_PageView*)m_pageMap.GetValueAt(pPDFXFAPage);
unknown636ad3b2014-10-29 19:37:24 +0800466 if(pPageView && !pPageView->IsLocked())
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700467 {
468 delete pPageView;
Bo Xufdc00a72014-10-28 23:03:33 -0700469 m_pageMap.RemoveKey(pPDFXFAPage);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700470 }
471}
472
Bo Xufdc00a72014-10-28 23:03:33 -0700473CPDFXFA_Page * CPDFSDK_Document::GetPage(int nIndex)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700474{
Bo Xufdc00a72014-10-28 23:03:33 -0700475 CPDFXFA_Page * pTempPage = (CPDFXFA_Page*)m_pEnv->FFI_GetPage(m_pDoc,nIndex);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700476 if(!pTempPage)
477 return NULL;
478 return pTempPage;
479}
480
481CPDFSDK_InterForm* CPDFSDK_Document::GetInterForm()
482{
483 if(!m_pInterForm)
484 m_pInterForm = new CPDFSDK_InterForm(this);
485 return m_pInterForm;
486}
487
488void CPDFSDK_Document::UpdateAllViews(CPDFSDK_PageView* pSender, CPDFSDK_Annot* pAnnot)
489{
490
491 FX_POSITION pos = m_pageMap.GetStartPosition();
Bo Xufdc00a72014-10-28 23:03:33 -0700492 CPDFXFA_Page * pPage = NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700493 CPDFSDK_PageView * pPageView = NULL;
494 while(pos)
495 {
496 m_pageMap.GetNextAssoc(pos, pPage, pPageView);
497
498 if(pPageView != pSender)
499 {
500 pPageView->UpdateView(pAnnot);
501 }
502 }
503}
504
505CPDFSDK_Annot* CPDFSDK_Document::GetFocusAnnot()
506{
507 return this->m_pFocusAnnot;
508}
509
510FX_BOOL CPDFSDK_Document::SetFocusAnnot(CPDFSDK_Annot* pAnnot,FX_UINT nFlag)
511{
512
513 if(m_pFocusAnnot==pAnnot) return TRUE;
514
Bo Xufdc00a72014-10-28 23:03:33 -0700515 CPDFSDK_Annot* pLastFocusAnnot = m_pFocusAnnot;
516
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700517 if(m_pFocusAnnot)
518 {
519 if(!this->KillFocusAnnot(nFlag) ) return FALSE;
520 }
Bo Xufdc00a72014-10-28 23:03:33 -0700521 CPDFSDK_PageView* pPageView = NULL;
522 if (pAnnot)
523 pPageView = pAnnot->GetPageView();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700524 if(pAnnot && pPageView->IsValid())
525 {
526 CPDFSDK_AnnotHandlerMgr *pAnnotHandler=m_pEnv->GetAnnotHandlerMgr();
527
528 if(pAnnotHandler&&!m_pFocusAnnot)
529 {
Bo Xufdc00a72014-10-28 23:03:33 -0700530 if (!pAnnotHandler->Annot_OnChangeFocus(pAnnot,pLastFocusAnnot))
531 return FALSE;
532
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700533 if (!pAnnotHandler->Annot_OnSetFocus(pAnnot,nFlag))
534 return FALSE;
535 if(!m_pFocusAnnot)
536 {
537 this->m_pFocusAnnot=pAnnot;
538 return TRUE;
539 }
540 }
541 }
542 return FALSE;
543}
544
545FX_BOOL CPDFSDK_Document::KillFocusAnnot(FX_UINT nFlag)
546{
547 if(m_pFocusAnnot)
548 {
549 CPDFSDK_AnnotHandlerMgr *pAnnotHandler=m_pEnv->GetAnnotHandlerMgr();
550 if(pAnnotHandler)
551 {
552 CPDFSDK_Annot* pFocusAnnot = m_pFocusAnnot;
553 m_pFocusAnnot = NULL;
Bo Xufdc00a72014-10-28 23:03:33 -0700554
555 if (!pAnnotHandler->Annot_OnChangeFocus(NULL, pFocusAnnot))
556 return FALSE;
557
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700558 if(pAnnotHandler->Annot_OnKillFocus(pFocusAnnot, nFlag))
559 {
560
561 if(pFocusAnnot->GetType() == FX_BSTRC("Widget"))
562 {
563 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pFocusAnnot;
564 int nFieldType = pWidget->GetFieldType();
565 if(FIELDTYPE_TEXTFIELD == nFieldType || FIELDTYPE_COMBOBOX == nFieldType)
566 m_pEnv->FFI_OnSetFieldInputFocus(NULL, NULL, 0, FALSE);
567 }
568
569 if(!m_pFocusAnnot)
570 return TRUE;
571 }
572 else
573 {
574 m_pFocusAnnot = pFocusAnnot;
575 }
576 }
577 }
578 return FALSE;
579}
580
581FX_BOOL CPDFSDK_Document::DeletePages(int nStart, int nCount)
582{
583 if ( nStart < 0 || nStart >= GetPageCount() || nCount <= 0 )
584 {
585 return FALSE;
586 }
587
Bo Xufdc00a72014-10-28 23:03:33 -0700588 CPDFXFA_Page * pTempPage = NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700589 for ( int i = nCount-1; i >= 0; i-- )
590 {
591 pTempPage = GetPage(nStart+i);
592 if ( pTempPage != NULL )
593 {
594 ReMovePageView(pTempPage);
595 }
596 }
597 return TRUE;
598}
599
600void CPDFSDK_Document::OnCloseDocument()
601{
602 KillFocusAnnot();
603}
604
605FX_BOOL CPDFSDK_Document::GetPermissions(int nFlag)
606{
Bo Xufdc00a72014-10-28 23:03:33 -0700607 FX_DWORD dwPermissions = m_pDoc->GetPDFDoc()->GetUserPermissions();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700608 return dwPermissions&nFlag;
609}
610
611IFXJS_Runtime * CPDFSDK_Document::GetJsRuntime()
612{
613 ASSERT(m_pEnv!=NULL);
614 return m_pEnv->GetJSRuntime();
615}
616
617CFX_WideString CPDFSDK_Document::GetPath()
618{
619 ASSERT(m_pEnv != NULL);
620 return m_pEnv->JS_docGetFilePath();
621}
622
623
Bo Xufdc00a72014-10-28 23:03:33 -0700624CPDFSDK_PageView::CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc,CPDFXFA_Page* page):m_page(page),m_pSDKDoc(pSDKDoc)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700625{
626 CPDFSDK_InterForm* pInterForm = pSDKDoc->GetInterForm();
627 if(pInterForm)
628 {
629 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm();
Bo Xufdc00a72014-10-28 23:03:33 -0700630 if (page->GetPDFPage())
631 pPDFInterForm->FixPageFields(page->GetPDFPage());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700632 }
Bo Xufdc00a72014-10-28 23:03:33 -0700633
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700634 m_fxAnnotArray.RemoveAll();
635
636 m_bEnterWidget = FALSE;
637 m_bExitWidget = FALSE;
638 m_bOnWidget = FALSE;
639 m_CaptureWidget = NULL;
640 m_bValid = FALSE;
unknown636ad3b2014-10-29 19:37:24 +0800641 m_bLocked = FALSE;
Bo Xufdc00a72014-10-28 23:03:33 -0700642 m_pAnnotList = NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700643}
644
645CPDFSDK_PageView::~CPDFSDK_PageView()
646{
647 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
648 int nAnnotCount = m_fxAnnotArray.GetSize();
649 for (int i=0; i<nAnnotCount; i++)
650 {
651 CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i);
652 //if there is a focused annot on the page, we should kill the focus first.
653 if(pAnnot == m_pSDKDoc->GetFocusAnnot())
654 KillFocusAnnot();
655 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
656 ASSERT(pAnnotHandlerMgr);
657 pAnnotHandlerMgr->ReleaseAnnot(pAnnot);
658 }
659 m_fxAnnotArray.RemoveAll();
660 if(m_pAnnotList)
661 {
662 delete m_pAnnotList;
663 m_pAnnotList = NULL;
664 }
665}
666
Bo Xufdc00a72014-10-28 23:03:33 -0700667void 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 -0700668{
669 m_curMatrix = *pUser2Device;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700670 // m_pAnnotList->DisplayAnnots(m_page, pDevice, pUser2Device, FALSE, pOptions);
671 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
Bo Xufdc00a72014-10-28 23:03:33 -0700672 CPDFXFA_Page* pPage = GetPDFXFAPage();
673
674 if (pPage == NULL) return;
675
676 if (pPage->GetDocument()->GetDocType() == DOCTYPE_DYNIMIC_XFA) {
677 CFX_Graphics gs;
678 gs.Create(pDevice);
679 if (pClip) {
680 CFX_RectF rectClip;
681 rectClip.Set(pClip->left, pClip->top, pClip->Width(), pClip->Height());
682 gs.SetClipRect(rectClip);
683 }
684 IXFA_RenderContext* pRenderContext = XFA_RenderContext_Create();
685 if (!pRenderContext)
686 return;
687 CXFA_RenderOptions renderOptions;
688 renderOptions.m_bHighlight = TRUE;
689 pRenderContext->StartRender(pPage->GetXFAPageView(), &gs, *pUser2Device, renderOptions);
690 pRenderContext->DoRender();
691 pRenderContext->StopRender();
692 pRenderContext->Release();
693 return;
694 }
695 // for pdf/static xfa.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700696 CPDFSDK_AnnotIterator annotIterator(this, TRUE);
697 CPDFSDK_Annot * pSDKAnnot=NULL;
698 int index=-1;
Bo Xufdc00a72014-10-28 23:03:33 -0700699 pSDKAnnot = annotIterator.Next(index);
700 while(pSDKAnnot)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700701 {
702 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
703 ASSERT(pAnnotHandlerMgr);
704 pAnnotHandlerMgr->Annot_OnDraw(this, pSDKAnnot, pDevice, pUser2Device, 0);
Bo Xufdc00a72014-10-28 23:03:33 -0700705 pSDKAnnot = annotIterator.Next(index);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700706 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700707}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700708CPDF_Annot* CPDFSDK_PageView::GetPDFAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY)
709{
710
711 int nCount = m_pAnnotList->Count();
712 for(int i = 0 ; i<nCount; i++)
713 {
714 CPDF_Annot* pAnnot = m_pAnnotList->GetAt(i);
715 CFX_FloatRect annotRect;
716 pAnnot->GetRect(annotRect);
717 if(annotRect.Contains(pageX, pageY))
718 return pAnnot;
719 }
720 return NULL;
721}
722
723CPDF_Annot* CPDFSDK_PageView::GetPDFWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY)
724{
725
726 int nCount = m_pAnnotList->Count();
727 for(int i = 0 ; i<nCount; i++)
728 {
729 CPDF_Annot* pAnnot = m_pAnnotList->GetAt(i);
730 if(pAnnot->GetSubType() == "Widget")
731 {
732 CFX_FloatRect annotRect;
733 pAnnot->GetRect(annotRect);
734 if(annotRect.Contains(pageX, pageY))
735 return pAnnot;
736 }
737 }
738 return NULL;
739}
740
741CPDFSDK_Annot* CPDFSDK_PageView::GetFXAnnotAtPoint(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 {
752 CPDF_Rect rc = pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot);
753 if(rc.Contains(pageX, pageY))
754 return pSDKAnnot;
Bo Xufdc00a72014-10-28 23:03:33 -0700755 pSDKAnnot = annotIterator.Next(index);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700756 }
757
758 return NULL;
759}
760
761CPDFSDK_Annot* CPDFSDK_PageView::GetFXWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY)
762{
763
764 CPDFSDK_AnnotIterator annotIterator(this, FALSE);
765 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
766 CPDFSDK_AnnotHandlerMgr* pAnnotMgr = pEnv->GetAnnotHandlerMgr();
767 CPDFSDK_Annot* pSDKAnnot = NULL;
768 int index = -1;
Bo Xufdc00a72014-10-28 23:03:33 -0700769 pSDKAnnot = annotIterator.Next(index);
770 while(pSDKAnnot)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700771 {
Bo Xufdc00a72014-10-28 23:03:33 -0700772 if(pSDKAnnot->GetType() == "Widget" || pSDKAnnot->GetType() == FSDK_XFAWIDGET_TYPENAME)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700773 {
774 pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot);
775 CPDF_Point point(pageX, pageY);
776 if (pAnnotMgr->Annot_OnHitTest(this, pSDKAnnot, point))
777// if(rc.Contains(pageX, pageY))
778 return pSDKAnnot;
779 }
Bo Xufdc00a72014-10-28 23:03:33 -0700780 pSDKAnnot = annotIterator.Next(index);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700781 }
782
783 return NULL;
784}
785
786
787FX_BOOL CPDFSDK_PageView::Annot_HasAppearance(CPDF_Annot* pAnnot)
788{
789 CPDF_Dictionary* pAnnotDic = pAnnot->m_pAnnotDict;
790 if(pAnnotDic)
791 return pAnnotDic->KeyExist("AS");
792 return FALSE;
793}
794
795CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CPDF_Annot * pPDFAnnot)
796{
797 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
798 ASSERT(pEnv);
799 CPDFSDK_AnnotHandlerMgr * pAnnotHandler= pEnv->GetAnnotHandlerMgr();
800
801 CPDFSDK_Annot* pSDKAnnot =NULL;
802
803 if(pAnnotHandler)
804 {
805 pSDKAnnot = pAnnotHandler->NewAnnot(pPDFAnnot, this);
806 }
807 if(!pSDKAnnot)
808 return NULL;
809
810 m_fxAnnotArray.Add(pSDKAnnot);
811
812 if(pAnnotHandler)
813 {
814 pAnnotHandler->Annot_OnCreate(pSDKAnnot);
815
816 }
817
818 return pSDKAnnot;
819}
820
Bo Xufdc00a72014-10-28 23:03:33 -0700821CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(XFA_HWIDGET pPDFAnnot)
822{
823 if (!pPDFAnnot) return NULL;
824
825 CPDFSDK_Annot* pSDKAnnot = GetAnnotByXFAWidget(pPDFAnnot);
826 if (pSDKAnnot)
827 return pSDKAnnot;
828
829 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
830 ASSERT(pEnv);
831 CPDFSDK_AnnotHandlerMgr * pAnnotHandler= pEnv->GetAnnotHandlerMgr();
832
833 pSDKAnnot =NULL;
834
835 if(pAnnotHandler)
836 {
837 pSDKAnnot = pAnnotHandler->NewAnnot(pPDFAnnot, this);
838 }
839 if(!pSDKAnnot)
840 return NULL;
841
842 m_fxAnnotArray.Add(pSDKAnnot);
843
844 return pSDKAnnot;
845}
846
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700847CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CPDF_Dictionary * pDict)
848{
849 if(pDict)
850 return this->AddAnnot(pDict->GetString("Subtype"),pDict);
851 return NULL;
852}
853
854CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(FX_LPCSTR lpSubType,CPDF_Dictionary * pDict)
855{
856 return NULL;
857}
858
859FX_BOOL CPDFSDK_PageView::DeleteAnnot(CPDFSDK_Annot* pAnnot)
860{
Bo Xufdc00a72014-10-28 23:03:33 -0700861 if (!pAnnot)
862 return FALSE;
863 CPDFXFA_Page* pPage = pAnnot->GetPDFXFAPage();
864 if (!pPage || (pPage->GetDocument()->GetDocType() != DOCTYPE_STATIC_XFA && pPage->GetDocument()->GetDocType() != DOCTYPE_DYNIMIC_XFA))
865 return FALSE;
866
867 int index = m_fxAnnotArray.Find(pAnnot);
868 m_fxAnnotArray.RemoveAt(index);
869 if (m_CaptureWidget == pAnnot)
870 m_CaptureWidget = NULL;
871
872 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700873}
874
875CPDF_Document* CPDFSDK_PageView::GetPDFDocument()
876{
877 if(m_page)
878 {
Bo Xufdc00a72014-10-28 23:03:33 -0700879 return m_page->GetDocument()->GetPDFDoc();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700880 }
881 return NULL;
882}
883
Bo Xufdc00a72014-10-28 23:03:33 -0700884CPDF_Page* CPDFSDK_PageView::GetPDFPage()
885{
886 if (m_page)
887 {
888 return m_page->GetPDFPage();
889 }
890
891 return NULL;
892}
893
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700894int CPDFSDK_PageView::CountAnnots()
895{
Bo Xufdc00a72014-10-28 23:03:33 -0700896 return m_fxAnnotArray.GetSize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700897}
898
899CPDFSDK_Annot* CPDFSDK_PageView::GetAnnot(int nIndex)
900{
901 int nCount = m_fxAnnotArray.GetSize();
902 if ( nIndex < 0 || nIndex >= nCount )
903 {
904 return NULL;
905 }
906
907 return (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(nIndex);
908}
909
910CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByDict(CPDF_Dictionary * pDict)
911{
912 int nCount = m_fxAnnotArray.GetSize();
913 for(int i=0; i<nCount; i++)
914 {
915 CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i);
916 if(pDict==pAnnot->GetPDFAnnot()->m_pAnnotDict)
917 return pAnnot;
918 }
919 return NULL;
920}
Bo Xufdc00a72014-10-28 23:03:33 -0700921CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByXFAWidget(XFA_HWIDGET hWidget)
922{
923 if (hWidget == NULL)
924 return NULL;
925 int annotCount = m_fxAnnotArray.GetSize();
926
927 for(int i = 0; i < annotCount; i++)
928 {
929 CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i);
930 if(pAnnot->GetXFAWidget() == hWidget)
931 return pAnnot;
932 }
933 return NULL;
934}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700935
936FX_BOOL CPDFSDK_PageView::OnLButtonDown(const CPDF_Point & point, FX_UINT nFlag)
937{
938 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
939 ASSERT(pEnv);
940 CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y);
941 if(!pFXAnnot)
942 {
943 KillFocusAnnot(nFlag);
944 }
945 else
946 {
947 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
948 ASSERT(pAnnotHandlerMgr);
949
950 FX_BOOL bRet = pAnnotHandlerMgr->Annot_OnLButtonDown(this, pFXAnnot, nFlag,point);
951 if(bRet)
952 {
953 SetFocusAnnot(pFXAnnot);
954 }
955 return bRet;
956 }
957 return FALSE;
958}
959
Bo Xufdc00a72014-10-28 23:03:33 -0700960FX_BOOL CPDFSDK_PageView::OnRButtonDown(const CPDF_Point & point, FX_UINT nFlag)
961{
962 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
963 ASSERT(pEnv);
964 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
965 ASSERT(pAnnotHandlerMgr);
966
967 CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y);
968
969 if (pFXAnnot == NULL)
970 return FALSE;
971
972 FX_BOOL bRet = pAnnotHandlerMgr->Annot_OnRButtonDown(this, pFXAnnot, nFlag,point);
973 if (bRet)
974 {
975 SetFocusAnnot(pFXAnnot);
976 }
977 return TRUE;
978}
979
980FX_BOOL CPDFSDK_PageView::OnRButtonUp(const CPDF_Point & point, FX_UINT nFlag)
981{
982 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
983 ASSERT(pEnv);
984 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
985 ASSERT(pAnnotHandlerMgr);
986
987 CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y);
988
989 if (pFXAnnot == NULL)
990 return FALSE;
991
992 FX_BOOL bRet = pAnnotHandlerMgr->Annot_OnRButtonUp(this, pFXAnnot, nFlag,point);
993 if (bRet)
994 {
995 SetFocusAnnot(pFXAnnot);
996 }
997 return TRUE;
998}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700999
1000FX_BOOL CPDFSDK_PageView::OnLButtonUp(const CPDF_Point & point, FX_UINT nFlag)
1001{
1002 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1003 ASSERT(pEnv);
1004 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
1005 ASSERT(pAnnotHandlerMgr);
1006 CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y);
1007 CPDFSDK_Annot* pFocusAnnot = GetFocusAnnot();
1008 FX_BOOL bRet = FALSE;
1009 if(pFocusAnnot && pFocusAnnot != pFXAnnot)
1010 {
1011 //Last focus Annot gets a chance to handle the event.
1012 bRet = pAnnotHandlerMgr->Annot_OnLButtonUp(this, pFocusAnnot, nFlag,point);
1013 }
1014 if(pFXAnnot && !bRet)
1015 {
1016 bRet = pAnnotHandlerMgr->Annot_OnLButtonUp(this, pFXAnnot, nFlag,point);
1017 return bRet;
1018 }
1019 return bRet;
1020}
1021
1022FX_BOOL CPDFSDK_PageView::OnMouseMove(const CPDF_Point & point, int nFlag)
1023{
1024
1025 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1026 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
1027 ASSERT(pAnnotHandlerMgr);
1028 if(CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y))
1029 {
1030 if(m_CaptureWidget && m_CaptureWidget != pFXAnnot)
1031 {
1032 m_bExitWidget = TRUE;
1033 m_bEnterWidget = FALSE;
1034 pAnnotHandlerMgr->Annot_OnMouseExit(this, m_CaptureWidget, nFlag);
1035 }
1036 m_CaptureWidget = (CPDFSDK_Widget*)pFXAnnot;
1037 m_bOnWidget = TRUE;
1038 if(!m_bEnterWidget)
1039 {
1040 m_bEnterWidget = TRUE;
1041 m_bExitWidget = FALSE;
1042 pAnnotHandlerMgr->Annot_OnMouseEnter(this, pFXAnnot,nFlag);
1043 }
1044 pAnnotHandlerMgr->Annot_OnMouseMove(this, pFXAnnot, nFlag, point);
1045 return TRUE;
1046 }
1047 else
1048 {
1049 if(m_bOnWidget)
1050 {
1051 m_bOnWidget = FALSE;
1052 m_bExitWidget = TRUE;
1053 m_bEnterWidget = FALSE;
1054 if(m_CaptureWidget)
1055 {
1056 pAnnotHandlerMgr->Annot_OnMouseExit(this, m_CaptureWidget, nFlag);
1057 m_CaptureWidget = NULL;
1058 }
1059 }
1060 return FALSE;
1061 }
1062
1063 return FALSE;;
1064}
1065
1066FX_BOOL CPDFSDK_PageView::OnMouseWheel(double deltaX, double deltaY,const CPDF_Point& point, int nFlag)
1067{
1068 if(CPDFSDK_Annot* pAnnot = GetFXWidgetAtPoint(point.x, point.y))
1069 {
1070 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1071 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
1072 ASSERT(pAnnotHandlerMgr);
1073 return pAnnotHandlerMgr->Annot_OnMouseWheel(this, pAnnot, nFlag, (int)deltaY, point);
1074 }
1075 return FALSE;
1076
1077}
1078
1079FX_BOOL CPDFSDK_PageView::OnChar(int nChar, FX_UINT nFlag)
1080{
1081 if(CPDFSDK_Annot* pAnnot = GetFocusAnnot())
1082 {
1083 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1084 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
1085 ASSERT(pAnnotHandlerMgr);
1086 return pAnnotHandlerMgr->Annot_OnChar(pAnnot, nChar, nFlag);
1087 }
1088
1089 return FALSE;
1090}
1091
1092FX_BOOL CPDFSDK_PageView::OnKeyDown(int nKeyCode, int nFlag)
1093{
1094 if(CPDFSDK_Annot* pAnnot = GetFocusAnnot())
1095 {
1096 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1097 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
1098 ASSERT(pAnnotHandlerMgr);
1099 return pAnnotHandlerMgr->Annot_OnKeyDown(pAnnot, nKeyCode, nFlag);
1100 }
1101 return FALSE;
1102}
1103
1104FX_BOOL CPDFSDK_PageView::OnKeyUp(int nKeyCode, int nFlag)
1105{
1106// if(CPDFSDK_Annot* pAnnot = GetFocusAnnot())
1107// {
1108// CFFL_IFormFiller* pIFormFiller = g_pFormFillApp->GetIFormFiller();
1109// return pIFormFiller->OnKeyUp(pAnnot, nKeyCode, nFlag);
1110// }
1111 return FALSE;
1112}
1113
1114extern void CheckUnSupportAnnot(CPDF_Document * pDoc, CPDF_Annot* pPDFAnnot);
1115
1116void CPDFSDK_PageView::LoadFXAnnots()
1117{
Bo Xufdc00a72014-10-28 23:03:33 -07001118 ASSERT(m_page != NULL);
1119
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001120 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
Bo Xufdc00a72014-10-28 23:03:33 -07001121 ASSERT(pEnv != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001122
Bo Xufdc00a72014-10-28 23:03:33 -07001123 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
1124 ASSERT(pAnnotHandlerMgr != NULL);
1125
unknown636ad3b2014-10-29 19:37:24 +08001126 SetLock(TRUE);
1127 m_page->AddRef();
Bo Xufdc00a72014-10-28 23:03:33 -07001128 if (m_pSDKDoc->GetDocument()->GetDocType() == DOCTYPE_DYNIMIC_XFA)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001129 {
Bo Xufdc00a72014-10-28 23:03:33 -07001130 IXFA_PageView* pageView = NULL;
1131 pageView = m_page->GetXFAPageView();
1132 ASSERT(pageView != NULL);
1133
1134 XFA_HWIDGET pXFAAnnot = NULL;
1135 IXFA_WidgetIterator* pWidgetHander = pageView->CreateWidgetIterator(XFA_TRAVERSEWAY_Form, XFA_WIDGETFILTER_Visible|XFA_WIDGETFILTER_Viewable|XFA_WIDGETFILTER_AllType);
1136 if (!pWidgetHander)
unknown636ad3b2014-10-29 19:37:24 +08001137 {
1138 m_page->Release();
1139 SetLock(FALSE);
Bo Xufdc00a72014-10-28 23:03:33 -07001140 return;
unknown636ad3b2014-10-29 19:37:24 +08001141 }
Bo Xufdc00a72014-10-28 23:03:33 -07001142
1143 pXFAAnnot = pWidgetHander->MoveToNext();
1144 while (pXFAAnnot) {
1145 CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pXFAAnnot, this);
1146 if(!pAnnot) {
1147 pXFAAnnot = pWidgetHander->MoveToNext();
1148 continue;
1149 }
1150 m_fxAnnotArray.Add(pAnnot);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001151
Bo Xufdc00a72014-10-28 23:03:33 -07001152 pAnnotHandlerMgr->Annot_OnLoad(pAnnot);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001153
Bo Xufdc00a72014-10-28 23:03:33 -07001154 pXFAAnnot = pWidgetHander->MoveToNext();
Bo Xufacd0152014-09-24 10:49:52 -07001155
Bo Xufdc00a72014-10-28 23:03:33 -07001156 }
1157
1158 pWidgetHander->Release();
1159 }
1160 else
1161 {
1162 CPDF_Page* pPage = m_page->GetPDFPage();
1163 ASSERT(pPage != NULL);
1164
1165 FX_BOOL enableAPUpdate = CPDF_InterForm::UpdatingAPEnabled();
1166 //Disable the default AP construction.
1167 CPDF_InterForm::EnableUpdateAP(FALSE);
1168 m_pAnnotList = new CPDF_AnnotList(pPage);
1169 CPDF_InterForm::EnableUpdateAP(enableAPUpdate);
1170
1171 int nCount = m_pAnnotList->Count();
1172 for(int i=0; i<nCount; i++)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001173 {
Bo Xufdc00a72014-10-28 23:03:33 -07001174 CPDF_Annot* pPDFAnnot = m_pAnnotList->GetAt(i);
1175 CPDF_Document * pDoc = this->GetPDFDocument();
1176
1177 CheckUnSupportAnnot(pDoc, pPDFAnnot);
1178
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001179 CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pPDFAnnot, this);
1180 if(!pAnnot)
1181 continue;
1182 m_fxAnnotArray.Add(pAnnot);
1183
1184 pAnnotHandlerMgr->Annot_OnLoad(pAnnot);
1185 }
1186
1187 }
unknown636ad3b2014-10-29 19:37:24 +08001188 m_page->Release();
1189 SetLock(FALSE);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001190}
1191
1192void CPDFSDK_PageView::UpdateRects(CFX_RectArray& rects)
1193{
1194 for(int i=0; i<rects.GetSize(); i++)
1195 {
1196 CPDF_Rect rc = rects.GetAt(i);
1197 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1198 pEnv->FFI_Invalidate(m_page, rc.left, rc.top, rc.right, rc.bottom);
1199 }
1200}
1201
1202void CPDFSDK_PageView::UpdateView(CPDFSDK_Annot* pAnnot)
1203{
1204 CPDF_Rect rcWindow;
1205
1206 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1207// CPDFSDK_AnnotHandlerMgr* pAnnotHandler = pEnv->GetAnnotHandlerMgr();
1208
1209 rcWindow = pAnnot->GetRect();//pAnnotHandler->Annot_OnGetViewBBox(this,pAnnot);
1210 pEnv->FFI_Invalidate(m_page, rcWindow.left, rcWindow.top, rcWindow.right, rcWindow.bottom);
1211
1212}
1213
1214int CPDFSDK_PageView::GetPageIndex()
1215{
1216 if(m_page)
1217 {
Bo Xufdc00a72014-10-28 23:03:33 -07001218 CPDF_Dictionary* pDic = m_page->GetPDFPage()->m_pFormDict;
1219 CPDFXFA_Document* pDoc = m_pSDKDoc->GetDocument();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001220 if(pDoc && pDic)
1221 {
Bo Xufdc00a72014-10-28 23:03:33 -07001222 return pDoc->GetPDFDoc()->GetPageIndex(pDic->GetObjNum());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001223 }
1224 }
1225 return -1;
1226}
1227
1228FX_BOOL CPDFSDK_PageView::IsValidAnnot(FX_LPVOID p)
1229{
1230 if (p == NULL) return FALSE;
1231 int iCount = m_pAnnotList->Count();
1232 for (int i = 0; i < iCount; i++)
1233 {
1234 if (m_pAnnotList->GetAt(i) == p)
1235 return TRUE;
1236 }
1237 return FALSE;
1238}
1239
1240
1241CPDFSDK_Annot* CPDFSDK_PageView::GetFocusAnnot()
1242{
1243 CPDFSDK_Annot* pFocusAnnot = m_pSDKDoc->GetFocusAnnot();
1244 if(!pFocusAnnot)
1245 return NULL;
1246
1247 for(int i=0; i<m_fxAnnotArray.GetSize(); i++)
1248 {
1249 CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i);
1250 if(pAnnot == pFocusAnnot)
1251 return pAnnot;
1252 }
1253 return NULL;
1254}
1255