blob: 7b071a9b5582d2ce2e4ccb9c0a4d8e426989c3fe [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{
Tom Sepez7b5bc262015-03-05 16:44:22 -0800430 if(!m_pDoc)
431 return FALSE;
432
433 CPDF_Dictionary* pRoot = m_pDoc->GetPDFDoc()->GetRoot();
434 if (!pRoot)
435 return FALSE;
436
437 CPDF_Object* pOpenAction = pRoot->GetDict("OpenAction");
438 if(!pOpenAction)
439 pOpenAction = pRoot->GetArray("OpenAction");
440
441 if(!pOpenAction)
442 return FALSE;
443
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700444 if(pOpenAction->GetType()==PDFOBJ_ARRAY)
Tom Sepez7b5bc262015-03-05 16:44:22 -0800445 return TRUE;
446
447 if(pOpenAction->GetType()==PDFOBJ_DICTIONARY)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700448 {
Tom Sepez7b5bc262015-03-05 16:44:22 -0800449 CPDF_Dictionary * pDict=(CPDF_Dictionary*)pOpenAction;
450 CPDF_Action action(pDict);
451 if(m_pEnv->GetActionHander())
452 m_pEnv->GetActionHander()->DoAction_DocOpen(action, this);
453 return TRUE;
454 }
455 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700456}
457
458CPDF_OCContext* CPDFSDK_Document::GetOCContext()
459{
460 if(!m_pOccontent)
Bo Xufdc00a72014-10-28 23:03:33 -0700461 m_pOccontent = new CPDF_OCContext(m_pDoc->GetPDFDoc());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700462 return m_pOccontent;
463}
464
Bo Xufdc00a72014-10-28 23:03:33 -0700465void CPDFSDK_Document::ReMovePageView(CPDFXFA_Page* pPDFXFAPage)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700466{
Bo Xufdc00a72014-10-28 23:03:33 -0700467 CPDFSDK_PageView* pPageView = (CPDFSDK_PageView*)m_pageMap.GetValueAt(pPDFXFAPage);
unknown636ad3b2014-10-29 19:37:24 +0800468 if(pPageView && !pPageView->IsLocked())
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700469 {
470 delete pPageView;
Bo Xufdc00a72014-10-28 23:03:33 -0700471 m_pageMap.RemoveKey(pPDFXFAPage);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700472 }
473}
474
Bo Xufdc00a72014-10-28 23:03:33 -0700475CPDFXFA_Page * CPDFSDK_Document::GetPage(int nIndex)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700476{
Bo Xufdc00a72014-10-28 23:03:33 -0700477 CPDFXFA_Page * pTempPage = (CPDFXFA_Page*)m_pEnv->FFI_GetPage(m_pDoc,nIndex);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700478 if(!pTempPage)
479 return NULL;
480 return pTempPage;
481}
482
483CPDFSDK_InterForm* CPDFSDK_Document::GetInterForm()
484{
485 if(!m_pInterForm)
486 m_pInterForm = new CPDFSDK_InterForm(this);
487 return m_pInterForm;
488}
489
490void CPDFSDK_Document::UpdateAllViews(CPDFSDK_PageView* pSender, CPDFSDK_Annot* pAnnot)
491{
492
493 FX_POSITION pos = m_pageMap.GetStartPosition();
Bo Xufdc00a72014-10-28 23:03:33 -0700494 CPDFXFA_Page * pPage = NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700495 CPDFSDK_PageView * pPageView = NULL;
496 while(pos)
497 {
498 m_pageMap.GetNextAssoc(pos, pPage, pPageView);
499
500 if(pPageView != pSender)
501 {
502 pPageView->UpdateView(pAnnot);
503 }
504 }
505}
506
507CPDFSDK_Annot* CPDFSDK_Document::GetFocusAnnot()
508{
509 return this->m_pFocusAnnot;
510}
511
512FX_BOOL CPDFSDK_Document::SetFocusAnnot(CPDFSDK_Annot* pAnnot,FX_UINT nFlag)
513{
514
515 if(m_pFocusAnnot==pAnnot) return TRUE;
516
Bo Xufdc00a72014-10-28 23:03:33 -0700517 CPDFSDK_Annot* pLastFocusAnnot = m_pFocusAnnot;
518
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700519 if(m_pFocusAnnot)
520 {
521 if(!this->KillFocusAnnot(nFlag) ) return FALSE;
522 }
Bo Xufdc00a72014-10-28 23:03:33 -0700523 CPDFSDK_PageView* pPageView = NULL;
524 if (pAnnot)
525 pPageView = pAnnot->GetPageView();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700526 if(pAnnot && pPageView->IsValid())
527 {
528 CPDFSDK_AnnotHandlerMgr *pAnnotHandler=m_pEnv->GetAnnotHandlerMgr();
529
530 if(pAnnotHandler&&!m_pFocusAnnot)
531 {
Bo Xufdc00a72014-10-28 23:03:33 -0700532 if (!pAnnotHandler->Annot_OnChangeFocus(pAnnot,pLastFocusAnnot))
533 return FALSE;
534
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700535 if (!pAnnotHandler->Annot_OnSetFocus(pAnnot,nFlag))
536 return FALSE;
537 if(!m_pFocusAnnot)
538 {
539 this->m_pFocusAnnot=pAnnot;
540 return TRUE;
541 }
542 }
543 }
544 return FALSE;
545}
546
547FX_BOOL CPDFSDK_Document::KillFocusAnnot(FX_UINT nFlag)
548{
549 if(m_pFocusAnnot)
550 {
551 CPDFSDK_AnnotHandlerMgr *pAnnotHandler=m_pEnv->GetAnnotHandlerMgr();
552 if(pAnnotHandler)
553 {
554 CPDFSDK_Annot* pFocusAnnot = m_pFocusAnnot;
555 m_pFocusAnnot = NULL;
Bo Xufdc00a72014-10-28 23:03:33 -0700556
557 if (!pAnnotHandler->Annot_OnChangeFocus(NULL, pFocusAnnot))
558 return FALSE;
559
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700560 if(pAnnotHandler->Annot_OnKillFocus(pFocusAnnot, nFlag))
561 {
562
563 if(pFocusAnnot->GetType() == FX_BSTRC("Widget"))
564 {
565 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pFocusAnnot;
566 int nFieldType = pWidget->GetFieldType();
567 if(FIELDTYPE_TEXTFIELD == nFieldType || FIELDTYPE_COMBOBOX == nFieldType)
568 m_pEnv->FFI_OnSetFieldInputFocus(NULL, NULL, 0, FALSE);
569 }
570
571 if(!m_pFocusAnnot)
572 return TRUE;
573 }
574 else
575 {
576 m_pFocusAnnot = pFocusAnnot;
577 }
578 }
579 }
580 return FALSE;
581}
582
583FX_BOOL CPDFSDK_Document::DeletePages(int nStart, int nCount)
584{
585 if ( nStart < 0 || nStart >= GetPageCount() || nCount <= 0 )
586 {
587 return FALSE;
588 }
589
Bo Xufdc00a72014-10-28 23:03:33 -0700590 CPDFXFA_Page * pTempPage = NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700591 for ( int i = nCount-1; i >= 0; i-- )
592 {
593 pTempPage = GetPage(nStart+i);
594 if ( pTempPage != NULL )
595 {
596 ReMovePageView(pTempPage);
597 }
598 }
599 return TRUE;
600}
601
602void CPDFSDK_Document::OnCloseDocument()
603{
604 KillFocusAnnot();
605}
606
607FX_BOOL CPDFSDK_Document::GetPermissions(int nFlag)
608{
Bo Xufdc00a72014-10-28 23:03:33 -0700609 FX_DWORD dwPermissions = m_pDoc->GetPDFDoc()->GetUserPermissions();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700610 return dwPermissions&nFlag;
611}
612
613IFXJS_Runtime * CPDFSDK_Document::GetJsRuntime()
614{
615 ASSERT(m_pEnv!=NULL);
616 return m_pEnv->GetJSRuntime();
617}
618
619CFX_WideString CPDFSDK_Document::GetPath()
620{
621 ASSERT(m_pEnv != NULL);
622 return m_pEnv->JS_docGetFilePath();
623}
624
625
Bo Xufdc00a72014-10-28 23:03:33 -0700626CPDFSDK_PageView::CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc,CPDFXFA_Page* page):m_page(page),m_pSDKDoc(pSDKDoc)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700627{
628 CPDFSDK_InterForm* pInterForm = pSDKDoc->GetInterForm();
629 if(pInterForm)
630 {
631 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm();
Bo Xufdc00a72014-10-28 23:03:33 -0700632 if (page->GetPDFPage())
633 pPDFInterForm->FixPageFields(page->GetPDFPage());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700634 }
Bo Xufdc00a72014-10-28 23:03:33 -0700635
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700636 m_fxAnnotArray.RemoveAll();
637
638 m_bEnterWidget = FALSE;
639 m_bExitWidget = FALSE;
640 m_bOnWidget = FALSE;
641 m_CaptureWidget = NULL;
642 m_bValid = FALSE;
unknown636ad3b2014-10-29 19:37:24 +0800643 m_bLocked = FALSE;
Bo Xufdc00a72014-10-28 23:03:33 -0700644 m_pAnnotList = NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700645}
646
647CPDFSDK_PageView::~CPDFSDK_PageView()
648{
649 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
650 int nAnnotCount = m_fxAnnotArray.GetSize();
651 for (int i=0; i<nAnnotCount; i++)
652 {
653 CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i);
654 //if there is a focused annot on the page, we should kill the focus first.
655 if(pAnnot == m_pSDKDoc->GetFocusAnnot())
656 KillFocusAnnot();
657 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
658 ASSERT(pAnnotHandlerMgr);
659 pAnnotHandlerMgr->ReleaseAnnot(pAnnot);
660 }
661 m_fxAnnotArray.RemoveAll();
662 if(m_pAnnotList)
663 {
664 delete m_pAnnotList;
665 m_pAnnotList = NULL;
666 }
667}
668
Bo Xufdc00a72014-10-28 23:03:33 -0700669void 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 -0700670{
671 m_curMatrix = *pUser2Device;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700672 // m_pAnnotList->DisplayAnnots(m_page, pDevice, pUser2Device, FALSE, pOptions);
673 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
Bo Xufdc00a72014-10-28 23:03:33 -0700674 CPDFXFA_Page* pPage = GetPDFXFAPage();
675
676 if (pPage == NULL) return;
677
678 if (pPage->GetDocument()->GetDocType() == DOCTYPE_DYNIMIC_XFA) {
679 CFX_Graphics gs;
680 gs.Create(pDevice);
681 if (pClip) {
682 CFX_RectF rectClip;
Bruce Dawson3f49aa32015-01-08 11:47:49 -0800683 rectClip.Set(static_cast<FX_FLOAT>(pClip->left),
684 static_cast<FX_FLOAT>(pClip->top),
685 static_cast<FX_FLOAT>(pClip->Width()),
686 static_cast<FX_FLOAT>(pClip->Height()));
Bo Xufdc00a72014-10-28 23:03:33 -0700687 gs.SetClipRect(rectClip);
688 }
689 IXFA_RenderContext* pRenderContext = XFA_RenderContext_Create();
690 if (!pRenderContext)
691 return;
692 CXFA_RenderOptions renderOptions;
693 renderOptions.m_bHighlight = TRUE;
694 pRenderContext->StartRender(pPage->GetXFAPageView(), &gs, *pUser2Device, renderOptions);
695 pRenderContext->DoRender();
696 pRenderContext->StopRender();
697 pRenderContext->Release();
698 return;
699 }
700 // for pdf/static xfa.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700701 CPDFSDK_AnnotIterator annotIterator(this, TRUE);
702 CPDFSDK_Annot * pSDKAnnot=NULL;
703 int index=-1;
Bo Xufdc00a72014-10-28 23:03:33 -0700704 pSDKAnnot = annotIterator.Next(index);
705 while(pSDKAnnot)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700706 {
707 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
708 ASSERT(pAnnotHandlerMgr);
709 pAnnotHandlerMgr->Annot_OnDraw(this, pSDKAnnot, pDevice, pUser2Device, 0);
Bo Xufdc00a72014-10-28 23:03:33 -0700710 pSDKAnnot = annotIterator.Next(index);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700711 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700712}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700713CPDF_Annot* CPDFSDK_PageView::GetPDFAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY)
714{
715
716 int nCount = m_pAnnotList->Count();
717 for(int i = 0 ; i<nCount; i++)
718 {
719 CPDF_Annot* pAnnot = m_pAnnotList->GetAt(i);
720 CFX_FloatRect annotRect;
721 pAnnot->GetRect(annotRect);
722 if(annotRect.Contains(pageX, pageY))
723 return pAnnot;
724 }
725 return NULL;
726}
727
728CPDF_Annot* CPDFSDK_PageView::GetPDFWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY)
729{
730
731 int nCount = m_pAnnotList->Count();
732 for(int i = 0 ; i<nCount; i++)
733 {
734 CPDF_Annot* pAnnot = m_pAnnotList->GetAt(i);
735 if(pAnnot->GetSubType() == "Widget")
736 {
737 CFX_FloatRect annotRect;
738 pAnnot->GetRect(annotRect);
739 if(annotRect.Contains(pageX, pageY))
740 return pAnnot;
741 }
742 }
743 return NULL;
744}
745
746CPDFSDK_Annot* CPDFSDK_PageView::GetFXAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY)
747{
748
749 CPDFSDK_AnnotIterator annotIterator(this, FALSE);
750 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
751 CPDFSDK_AnnotHandlerMgr* pAnnotMgr = pEnv->GetAnnotHandlerMgr();
752 CPDFSDK_Annot* pSDKAnnot = NULL;
753 int index = -1;
Bo Xufdc00a72014-10-28 23:03:33 -0700754 pSDKAnnot = annotIterator.Next(index);
755 while(pSDKAnnot)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700756 {
757 CPDF_Rect rc = pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot);
758 if(rc.Contains(pageX, pageY))
759 return pSDKAnnot;
Bo Xufdc00a72014-10-28 23:03:33 -0700760 pSDKAnnot = annotIterator.Next(index);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700761 }
762
763 return NULL;
764}
765
766CPDFSDK_Annot* CPDFSDK_PageView::GetFXWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY)
767{
768
769 CPDFSDK_AnnotIterator annotIterator(this, FALSE);
770 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
771 CPDFSDK_AnnotHandlerMgr* pAnnotMgr = pEnv->GetAnnotHandlerMgr();
772 CPDFSDK_Annot* pSDKAnnot = NULL;
773 int index = -1;
Bo Xufdc00a72014-10-28 23:03:33 -0700774 pSDKAnnot = annotIterator.Next(index);
775 while(pSDKAnnot)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700776 {
Bo Xufdc00a72014-10-28 23:03:33 -0700777 if(pSDKAnnot->GetType() == "Widget" || pSDKAnnot->GetType() == FSDK_XFAWIDGET_TYPENAME)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700778 {
779 pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot);
780 CPDF_Point point(pageX, pageY);
781 if (pAnnotMgr->Annot_OnHitTest(this, pSDKAnnot, point))
782// if(rc.Contains(pageX, pageY))
783 return pSDKAnnot;
784 }
Bo Xufdc00a72014-10-28 23:03:33 -0700785 pSDKAnnot = annotIterator.Next(index);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700786 }
787
788 return NULL;
789}
790
791
792FX_BOOL CPDFSDK_PageView::Annot_HasAppearance(CPDF_Annot* pAnnot)
793{
794 CPDF_Dictionary* pAnnotDic = pAnnot->m_pAnnotDict;
795 if(pAnnotDic)
796 return pAnnotDic->KeyExist("AS");
797 return FALSE;
798}
799
800CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CPDF_Annot * pPDFAnnot)
801{
802 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
803 ASSERT(pEnv);
804 CPDFSDK_AnnotHandlerMgr * pAnnotHandler= pEnv->GetAnnotHandlerMgr();
805
806 CPDFSDK_Annot* pSDKAnnot =NULL;
807
808 if(pAnnotHandler)
809 {
810 pSDKAnnot = pAnnotHandler->NewAnnot(pPDFAnnot, this);
811 }
812 if(!pSDKAnnot)
813 return NULL;
814
815 m_fxAnnotArray.Add(pSDKAnnot);
816
817 if(pAnnotHandler)
818 {
819 pAnnotHandler->Annot_OnCreate(pSDKAnnot);
820
821 }
822
823 return pSDKAnnot;
824}
825
Bo Xufdc00a72014-10-28 23:03:33 -0700826CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(XFA_HWIDGET pPDFAnnot)
827{
828 if (!pPDFAnnot) return NULL;
829
830 CPDFSDK_Annot* pSDKAnnot = GetAnnotByXFAWidget(pPDFAnnot);
831 if (pSDKAnnot)
832 return pSDKAnnot;
833
834 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
835 ASSERT(pEnv);
836 CPDFSDK_AnnotHandlerMgr * pAnnotHandler= pEnv->GetAnnotHandlerMgr();
837
838 pSDKAnnot =NULL;
839
840 if(pAnnotHandler)
841 {
842 pSDKAnnot = pAnnotHandler->NewAnnot(pPDFAnnot, this);
843 }
844 if(!pSDKAnnot)
845 return NULL;
846
847 m_fxAnnotArray.Add(pSDKAnnot);
848
849 return pSDKAnnot;
850}
851
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700852CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CPDF_Dictionary * pDict)
853{
854 if(pDict)
855 return this->AddAnnot(pDict->GetString("Subtype"),pDict);
856 return NULL;
857}
858
859CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(FX_LPCSTR lpSubType,CPDF_Dictionary * pDict)
860{
861 return NULL;
862}
863
864FX_BOOL CPDFSDK_PageView::DeleteAnnot(CPDFSDK_Annot* pAnnot)
865{
Bo Xufdc00a72014-10-28 23:03:33 -0700866 if (!pAnnot)
867 return FALSE;
868 CPDFXFA_Page* pPage = pAnnot->GetPDFXFAPage();
869 if (!pPage || (pPage->GetDocument()->GetDocType() != DOCTYPE_STATIC_XFA && pPage->GetDocument()->GetDocType() != DOCTYPE_DYNIMIC_XFA))
870 return FALSE;
871
872 int index = m_fxAnnotArray.Find(pAnnot);
873 m_fxAnnotArray.RemoveAt(index);
874 if (m_CaptureWidget == pAnnot)
875 m_CaptureWidget = NULL;
876
877 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700878}
879
880CPDF_Document* CPDFSDK_PageView::GetPDFDocument()
881{
882 if(m_page)
883 {
Bo Xufdc00a72014-10-28 23:03:33 -0700884 return m_page->GetDocument()->GetPDFDoc();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700885 }
886 return NULL;
887}
888
Bo Xufdc00a72014-10-28 23:03:33 -0700889CPDF_Page* CPDFSDK_PageView::GetPDFPage()
890{
891 if (m_page)
892 {
893 return m_page->GetPDFPage();
894 }
895
896 return NULL;
897}
898
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700899int CPDFSDK_PageView::CountAnnots()
900{
Bo Xufdc00a72014-10-28 23:03:33 -0700901 return m_fxAnnotArray.GetSize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700902}
903
904CPDFSDK_Annot* CPDFSDK_PageView::GetAnnot(int nIndex)
905{
906 int nCount = m_fxAnnotArray.GetSize();
907 if ( nIndex < 0 || nIndex >= nCount )
908 {
909 return NULL;
910 }
911
912 return (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(nIndex);
913}
914
915CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByDict(CPDF_Dictionary * pDict)
916{
917 int nCount = m_fxAnnotArray.GetSize();
918 for(int i=0; i<nCount; i++)
919 {
920 CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i);
921 if(pDict==pAnnot->GetPDFAnnot()->m_pAnnotDict)
922 return pAnnot;
923 }
924 return NULL;
925}
Bo Xufdc00a72014-10-28 23:03:33 -0700926CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByXFAWidget(XFA_HWIDGET hWidget)
927{
928 if (hWidget == NULL)
929 return NULL;
930 int annotCount = m_fxAnnotArray.GetSize();
931
932 for(int i = 0; i < annotCount; i++)
933 {
934 CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i);
935 if(pAnnot->GetXFAWidget() == hWidget)
936 return pAnnot;
937 }
938 return NULL;
939}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700940
941FX_BOOL CPDFSDK_PageView::OnLButtonDown(const CPDF_Point & point, FX_UINT nFlag)
942{
943 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
944 ASSERT(pEnv);
945 CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y);
946 if(!pFXAnnot)
947 {
948 KillFocusAnnot(nFlag);
949 }
950 else
951 {
952 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
953 ASSERT(pAnnotHandlerMgr);
954
955 FX_BOOL bRet = pAnnotHandlerMgr->Annot_OnLButtonDown(this, pFXAnnot, nFlag,point);
956 if(bRet)
957 {
958 SetFocusAnnot(pFXAnnot);
959 }
960 return bRet;
961 }
962 return FALSE;
963}
964
Bo Xufdc00a72014-10-28 23:03:33 -0700965FX_BOOL CPDFSDK_PageView::OnRButtonDown(const CPDF_Point & point, FX_UINT nFlag)
966{
967 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
968 ASSERT(pEnv);
969 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
970 ASSERT(pAnnotHandlerMgr);
971
972 CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y);
973
974 if (pFXAnnot == NULL)
975 return FALSE;
976
977 FX_BOOL bRet = pAnnotHandlerMgr->Annot_OnRButtonDown(this, pFXAnnot, nFlag,point);
978 if (bRet)
979 {
980 SetFocusAnnot(pFXAnnot);
981 }
982 return TRUE;
983}
984
985FX_BOOL CPDFSDK_PageView::OnRButtonUp(const CPDF_Point & point, FX_UINT nFlag)
986{
987 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
988 ASSERT(pEnv);
989 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
990 ASSERT(pAnnotHandlerMgr);
991
992 CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y);
993
994 if (pFXAnnot == NULL)
995 return FALSE;
996
997 FX_BOOL bRet = pAnnotHandlerMgr->Annot_OnRButtonUp(this, pFXAnnot, nFlag,point);
998 if (bRet)
999 {
1000 SetFocusAnnot(pFXAnnot);
1001 }
1002 return TRUE;
1003}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001004
1005FX_BOOL CPDFSDK_PageView::OnLButtonUp(const CPDF_Point & point, FX_UINT nFlag)
1006{
1007 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1008 ASSERT(pEnv);
1009 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
1010 ASSERT(pAnnotHandlerMgr);
1011 CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y);
1012 CPDFSDK_Annot* pFocusAnnot = GetFocusAnnot();
1013 FX_BOOL bRet = FALSE;
1014 if(pFocusAnnot && pFocusAnnot != pFXAnnot)
1015 {
1016 //Last focus Annot gets a chance to handle the event.
1017 bRet = pAnnotHandlerMgr->Annot_OnLButtonUp(this, pFocusAnnot, nFlag,point);
1018 }
1019 if(pFXAnnot && !bRet)
1020 {
1021 bRet = pAnnotHandlerMgr->Annot_OnLButtonUp(this, pFXAnnot, nFlag,point);
1022 return bRet;
1023 }
1024 return bRet;
1025}
1026
1027FX_BOOL CPDFSDK_PageView::OnMouseMove(const CPDF_Point & point, int nFlag)
1028{
1029
1030 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1031 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
1032 ASSERT(pAnnotHandlerMgr);
1033 if(CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y))
1034 {
1035 if(m_CaptureWidget && m_CaptureWidget != pFXAnnot)
1036 {
1037 m_bExitWidget = TRUE;
1038 m_bEnterWidget = FALSE;
1039 pAnnotHandlerMgr->Annot_OnMouseExit(this, m_CaptureWidget, nFlag);
1040 }
1041 m_CaptureWidget = (CPDFSDK_Widget*)pFXAnnot;
1042 m_bOnWidget = TRUE;
1043 if(!m_bEnterWidget)
1044 {
1045 m_bEnterWidget = TRUE;
1046 m_bExitWidget = FALSE;
1047 pAnnotHandlerMgr->Annot_OnMouseEnter(this, pFXAnnot,nFlag);
1048 }
1049 pAnnotHandlerMgr->Annot_OnMouseMove(this, pFXAnnot, nFlag, point);
1050 return TRUE;
1051 }
1052 else
1053 {
1054 if(m_bOnWidget)
1055 {
1056 m_bOnWidget = FALSE;
1057 m_bExitWidget = TRUE;
1058 m_bEnterWidget = FALSE;
1059 if(m_CaptureWidget)
1060 {
1061 pAnnotHandlerMgr->Annot_OnMouseExit(this, m_CaptureWidget, nFlag);
1062 m_CaptureWidget = NULL;
1063 }
1064 }
1065 return FALSE;
1066 }
1067
1068 return FALSE;;
1069}
1070
1071FX_BOOL CPDFSDK_PageView::OnMouseWheel(double deltaX, double deltaY,const CPDF_Point& point, int nFlag)
1072{
1073 if(CPDFSDK_Annot* pAnnot = GetFXWidgetAtPoint(point.x, point.y))
1074 {
1075 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1076 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
1077 ASSERT(pAnnotHandlerMgr);
1078 return pAnnotHandlerMgr->Annot_OnMouseWheel(this, pAnnot, nFlag, (int)deltaY, point);
1079 }
1080 return FALSE;
1081
1082}
1083
1084FX_BOOL CPDFSDK_PageView::OnChar(int nChar, FX_UINT nFlag)
1085{
1086 if(CPDFSDK_Annot* pAnnot = GetFocusAnnot())
1087 {
1088 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1089 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
1090 ASSERT(pAnnotHandlerMgr);
1091 return pAnnotHandlerMgr->Annot_OnChar(pAnnot, nChar, nFlag);
1092 }
1093
1094 return FALSE;
1095}
1096
1097FX_BOOL CPDFSDK_PageView::OnKeyDown(int nKeyCode, int nFlag)
1098{
1099 if(CPDFSDK_Annot* pAnnot = GetFocusAnnot())
1100 {
1101 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1102 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
1103 ASSERT(pAnnotHandlerMgr);
1104 return pAnnotHandlerMgr->Annot_OnKeyDown(pAnnot, nKeyCode, nFlag);
1105 }
1106 return FALSE;
1107}
1108
1109FX_BOOL CPDFSDK_PageView::OnKeyUp(int nKeyCode, int nFlag)
1110{
1111// if(CPDFSDK_Annot* pAnnot = GetFocusAnnot())
1112// {
1113// CFFL_IFormFiller* pIFormFiller = g_pFormFillApp->GetIFormFiller();
1114// return pIFormFiller->OnKeyUp(pAnnot, nKeyCode, nFlag);
1115// }
1116 return FALSE;
1117}
1118
1119extern void CheckUnSupportAnnot(CPDF_Document * pDoc, CPDF_Annot* pPDFAnnot);
1120
1121void CPDFSDK_PageView::LoadFXAnnots()
1122{
Bo Xufdc00a72014-10-28 23:03:33 -07001123 ASSERT(m_page != NULL);
1124
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001125 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
Bo Xufdc00a72014-10-28 23:03:33 -07001126 ASSERT(pEnv != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001127
Bo Xufdc00a72014-10-28 23:03:33 -07001128 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
1129 ASSERT(pAnnotHandlerMgr != NULL);
1130
unknown636ad3b2014-10-29 19:37:24 +08001131 SetLock(TRUE);
1132 m_page->AddRef();
Bo Xufdc00a72014-10-28 23:03:33 -07001133 if (m_pSDKDoc->GetDocument()->GetDocType() == DOCTYPE_DYNIMIC_XFA)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001134 {
Bo Xufdc00a72014-10-28 23:03:33 -07001135 IXFA_PageView* pageView = NULL;
1136 pageView = m_page->GetXFAPageView();
1137 ASSERT(pageView != NULL);
1138
1139 XFA_HWIDGET pXFAAnnot = NULL;
1140 IXFA_WidgetIterator* pWidgetHander = pageView->CreateWidgetIterator(XFA_TRAVERSEWAY_Form, XFA_WIDGETFILTER_Visible|XFA_WIDGETFILTER_Viewable|XFA_WIDGETFILTER_AllType);
1141 if (!pWidgetHander)
unknown636ad3b2014-10-29 19:37:24 +08001142 {
1143 m_page->Release();
1144 SetLock(FALSE);
Bo Xufdc00a72014-10-28 23:03:33 -07001145 return;
unknown636ad3b2014-10-29 19:37:24 +08001146 }
Bo Xufdc00a72014-10-28 23:03:33 -07001147
1148 pXFAAnnot = pWidgetHander->MoveToNext();
1149 while (pXFAAnnot) {
1150 CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pXFAAnnot, this);
1151 if(!pAnnot) {
1152 pXFAAnnot = pWidgetHander->MoveToNext();
1153 continue;
1154 }
1155 m_fxAnnotArray.Add(pAnnot);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001156
Bo Xufdc00a72014-10-28 23:03:33 -07001157 pAnnotHandlerMgr->Annot_OnLoad(pAnnot);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001158
Bo Xufdc00a72014-10-28 23:03:33 -07001159 pXFAAnnot = pWidgetHander->MoveToNext();
Bo Xufacd0152014-09-24 10:49:52 -07001160
Bo Xufdc00a72014-10-28 23:03:33 -07001161 }
1162
1163 pWidgetHander->Release();
1164 }
1165 else
1166 {
1167 CPDF_Page* pPage = m_page->GetPDFPage();
1168 ASSERT(pPage != NULL);
1169
1170 FX_BOOL enableAPUpdate = CPDF_InterForm::UpdatingAPEnabled();
1171 //Disable the default AP construction.
1172 CPDF_InterForm::EnableUpdateAP(FALSE);
1173 m_pAnnotList = new CPDF_AnnotList(pPage);
1174 CPDF_InterForm::EnableUpdateAP(enableAPUpdate);
1175
1176 int nCount = m_pAnnotList->Count();
1177 for(int i=0; i<nCount; i++)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001178 {
Bo Xufdc00a72014-10-28 23:03:33 -07001179 CPDF_Annot* pPDFAnnot = m_pAnnotList->GetAt(i);
1180 CPDF_Document * pDoc = this->GetPDFDocument();
1181
1182 CheckUnSupportAnnot(pDoc, pPDFAnnot);
1183
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001184 CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pPDFAnnot, this);
1185 if(!pAnnot)
1186 continue;
1187 m_fxAnnotArray.Add(pAnnot);
1188
1189 pAnnotHandlerMgr->Annot_OnLoad(pAnnot);
1190 }
1191
1192 }
unknown636ad3b2014-10-29 19:37:24 +08001193 m_page->Release();
1194 SetLock(FALSE);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001195}
1196
1197void CPDFSDK_PageView::UpdateRects(CFX_RectArray& rects)
1198{
1199 for(int i=0; i<rects.GetSize(); i++)
1200 {
1201 CPDF_Rect rc = rects.GetAt(i);
1202 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1203 pEnv->FFI_Invalidate(m_page, rc.left, rc.top, rc.right, rc.bottom);
1204 }
1205}
1206
1207void CPDFSDK_PageView::UpdateView(CPDFSDK_Annot* pAnnot)
1208{
1209 CPDF_Rect rcWindow;
1210
1211 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1212// CPDFSDK_AnnotHandlerMgr* pAnnotHandler = pEnv->GetAnnotHandlerMgr();
1213
1214 rcWindow = pAnnot->GetRect();//pAnnotHandler->Annot_OnGetViewBBox(this,pAnnot);
1215 pEnv->FFI_Invalidate(m_page, rcWindow.left, rcWindow.top, rcWindow.right, rcWindow.bottom);
1216
1217}
1218
1219int CPDFSDK_PageView::GetPageIndex()
1220{
1221 if(m_page)
1222 {
Bo Xufdc00a72014-10-28 23:03:33 -07001223 CPDF_Dictionary* pDic = m_page->GetPDFPage()->m_pFormDict;
1224 CPDFXFA_Document* pDoc = m_pSDKDoc->GetDocument();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001225 if(pDoc && pDic)
1226 {
Bo Xufdc00a72014-10-28 23:03:33 -07001227 return pDoc->GetPDFDoc()->GetPageIndex(pDic->GetObjNum());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001228 }
1229 }
1230 return -1;
1231}
1232
1233FX_BOOL CPDFSDK_PageView::IsValidAnnot(FX_LPVOID p)
1234{
1235 if (p == NULL) return FALSE;
1236 int iCount = m_pAnnotList->Count();
1237 for (int i = 0; i < iCount; i++)
1238 {
1239 if (m_pAnnotList->GetAt(i) == p)
1240 return TRUE;
1241 }
1242 return FALSE;
1243}
1244
1245
1246CPDFSDK_Annot* CPDFSDK_PageView::GetFocusAnnot()
1247{
1248 CPDFSDK_Annot* pFocusAnnot = m_pSDKDoc->GetFocusAnnot();
1249 if(!pFocusAnnot)
1250 return NULL;
1251
1252 for(int i=0; i<m_fxAnnotArray.GetSize(); i++)
1253 {
1254 CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i);
1255 if(pAnnot == pFocusAnnot)
1256 return pAnnot;
1257 }
1258 return NULL;
1259}
1260