3eb3c9dd9b4b3360a6e9982f2f6e7230f2cb53ab
[pdfium.git] / fpdfsdk / src / fsdk_mgr.cpp
1 // 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 "../../public/fpdf_ext.h"
8 #include "../include/fsdk_define.h"
9 #include "../include/fpdfxfa/fpdfxfa_doc.h"
10 #include "../include/fpdfxfa/fpdfxfa_page.h"
11 #include "../include/fpdfxfa/fpdfxfa_util.h"
12 #include "../include/fsdk_mgr.h"
13 #include "../include/formfiller/FFL_FormFiller.h"
14 #include "../include/javascript/IJavaScript.h"
15 #include "../include/fpdfxfa/fpdfxfa_app.h"
16
17 #if _FX_OS_ == _FX_ANDROID_
18 #include "time.h"
19 #else
20 #include <ctime>
21 #endif
22
23 //extern CPDFDoc_Environment* g_pFormFillApp;
24 class CFX_SystemHandler:public IFX_SystemHandler
25 {
26 public:
27         CFX_SystemHandler(CPDFDoc_Environment* pEnv):m_pEnv(pEnv),m_nCharSet(-1) {}
28 public:
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, int32_t& x, int32_t& y) {}
38         virtual void                            ScreenToClient(FX_HWND hWnd, int32_t& x, int32_t& 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(int32_t nCursorType);
49
50         virtual FX_HMENU                        CreatePopupMenu() {return NULL;}
51         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;}
54         virtual void                            DestroyMenu(FX_HMENU hMenu) {}
55
56         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);
59
60         virtual int32_t                 SetTimer(int32_t uElapse, TimerCallback lpTimerFunc) ;
61         virtual void                            KillTimer(int32_t 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 int32_t                 GetCharSet() {return m_nCharSet;}
72         virtual void                            SetCharSet(int32_t nCharSet) {m_nCharSet = nCharSet;}
73 private:
74         CPDFDoc_Environment* m_pEnv;
75         int             m_nCharSet;
76 };
77
78 void CFX_SystemHandler::SetCursor(int32_t nCursorType)
79 {
80
81         m_pEnv->FFI_SetCursor(nCursorType);
82 }
83
84 void CFX_SystemHandler::InvalidateRect(FX_HWND hWnd, FX_RECT rect)
85 {
86         //g_pFormFillApp->FFI_Invalidate();
87         CPDFSDK_Annot* pSDKAnnot = (CPDFSDK_Annot*)hWnd;
88         CPDFXFA_Page* pPage = NULL;
89         CPDFSDK_PageView* pPageView = NULL;
90         pPageView = pSDKAnnot->GetPageView();
91         pPage = pSDKAnnot->GetPDFXFAPage();
92         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 }
108 void 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);
121                 CPDFXFA_Page* pPage = pAnnot->GetPDFXFAPage();
122                 ASSERT(pPage);
123                 m_pEnv->FFI_OutputSelectedRect(pPage, ptA.x, ptB.y, ptB.x, ptA.y);
124         }
125
126 }
127
128 FX_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
139 CFX_ByteString CFX_SystemHandler::GetNativeTrueTypeFont(int32_t nCharset)
140 {
141         return "";
142 }
143
144 FX_BOOL CFX_SystemHandler::FindNativeTrueTypeFont(int32_t 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
176 static 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 }
188 CPDF_Font* CFX_SystemHandler::AddNativeTrueTypeFontToPDF(CPDF_Document* pDoc, CFX_ByteString sFontFaceName,
189                                                                                                                  uint8_t 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
204 int32_t CFX_SystemHandler::SetTimer(int32_t uElapse, TimerCallback lpTimerFunc)
205 {
206         return m_pEnv->FFI_SetTimer(uElapse, lpTimerFunc);
207 }
208 void CFX_SystemHandler::KillTimer(int32_t nID)
209 {
210         m_pEnv->FFI_KillTimer(nID);
211 }
212
213 FX_SYSTEMTIME CFX_SystemHandler::GetLocalTime()
214 {
215         return m_pEnv->FFI_GetLocalTime();
216 }
217
218 CPDFDoc_Environment::CPDFDoc_Environment(CPDFXFA_Document* pDoc) :
219         m_pAnnotHandlerMgr(NULL),
220         m_pActionHandler(NULL),
221         m_pJSRuntime(NULL),
222         m_pInfo(NULL),
223         m_pSDKDoc(NULL),
224         m_pDoc(pDoc),
225         m_pIFormFiller(NULL)
226 {
227         m_pSysHandler = NULL;
228         m_pSysHandler = new CFX_SystemHandler(this);
229 }
230
231 CPDFDoc_Environment::~CPDFDoc_Environment()
232 {
233
234     delete m_pIFormFiller;
235     m_pIFormFiller = NULL;
236
237     CPDFXFA_App* pProvider = CPDFXFA_App::GetInstance();
238     if (m_pJSRuntime && pProvider->GetRuntimeFactory())
239         pProvider->GetRuntimeFactory()->DeleteJSRuntime(m_pJSRuntime);
240
241     if (pProvider->m_pEnvList.GetSize() == 0)
242     {
243         pProvider->ReleaseRuntime();
244         pProvider->InitRuntime(TRUE);
245     }
246
247     delete m_pSysHandler;
248     m_pSysHandler = NULL;
249
250     delete m_pAnnotHandlerMgr;
251     m_pAnnotHandlerMgr = NULL;
252
253     delete m_pActionHandler;
254     m_pActionHandler = NULL;
255 }
256
257
258 IFXJS_Runtime* CPDFDoc_Environment::GetJSRuntime()
259 {
260         if(!IsJSInitiated())
261                 return NULL;
262         if(!m_pJSRuntime)
263                 m_pJSRuntime = CPDFXFA_App::GetInstance()->GetRuntimeFactory()->NewJSRuntime(this);
264         return m_pJSRuntime;
265 }
266
267 CPDFSDK_AnnotHandlerMgr* CPDFDoc_Environment::GetAnnotHandlerMgr()
268 {
269         if(!m_pAnnotHandlerMgr)
270                 m_pAnnotHandlerMgr = new CPDFSDK_AnnotHandlerMgr(this);
271         return m_pAnnotHandlerMgr;
272 }
273
274 CPDFSDK_ActionHandler* CPDFDoc_Environment::GetActionHander()
275 {
276         if(!m_pActionHandler)
277                 m_pActionHandler = new CPDFSDK_ActionHandler(this);
278         return m_pActionHandler;
279 }
280
281 int CPDFDoc_Environment::RegAppHandle(FPDF_FORMFILLINFO* pFFinfo)
282 {
283         m_pInfo  = pFFinfo;
284         return TRUE;
285 }
286
287 CPDFSDK_Document* CPDFDoc_Environment::GetCurrentDoc()
288 {
289         return m_pSDKDoc;
290 }
291
292 CFFL_IFormFiller* CPDFDoc_Environment::GetIFormFiller()
293 {
294         if(!m_pIFormFiller)
295                 m_pIFormFiller = new CFFL_IFormFiller(this);
296         return m_pIFormFiller;
297 }
298
299 FX_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
311 CPDFSDK_Document::CPDFSDK_Document(CPDFXFA_Document* pDoc,CPDFDoc_Environment* pEnv):m_pDoc(pDoc),
312                                                 m_pInterForm(NULL),m_pEnv(pEnv),m_pOccontent(NULL),m_bChangeMask(FALSE)
313 {
314         m_pFocusAnnot = NULL;
315 }
316
317 CPDFSDK_Document::~CPDFSDK_Document()
318 {
319         FX_POSITION pos = m_pageMap.GetStartPosition();
320         while(pos)
321         {
322                 CPDFXFA_Page* pPage = NULL;
323                 CPDFSDK_PageView* pPageView = NULL;
324                 m_pageMap.GetNextAssoc(pos, pPage, pPageView);
325                 delete pPageView;
326         }
327         m_pageMap.RemoveAll();
328         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
340 void 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
351 void CPDFSDK_Document::AddPageView(CPDFXFA_Page* pPDFXFAPage, CPDFSDK_PageView* pPageView)
352 {
353         m_pageMap.SetAt(pPDFXFAPage, pPageView);
354 }
355
356 CPDFSDK_PageView* CPDFSDK_Document::GetPageView(CPDFXFA_Page* pPDFXFAPage, FX_BOOL ReNew)
357 {
358         CPDFSDK_PageView* pPageView = (CPDFSDK_PageView*)m_pageMap.GetValueAt(pPDFXFAPage);
359         if(pPageView != NULL)
360                 return pPageView;
361         if(ReNew)
362         {
363                 pPageView = new CPDFSDK_PageView(this,pPDFXFAPage);
364                 m_pageMap.SetAt(pPDFXFAPage, pPageView);
365                 //Delay to load all the annotations, to avoid endless loop.
366                 pPageView->LoadFXAnnots();
367         }
368         return pPageView;
369
370 }
371
372 CPDFSDK_PageView* CPDFSDK_Document::GetCurrentView()
373 {
374     CPDFXFA_Page* pPage = (CPDFXFA_Page *)m_pEnv->FFI_GetCurrentPage(m_pDoc);
375     return pPage ? GetPageView(pPage, TRUE) : nullptr;
376 }
377
378 CPDFSDK_PageView* CPDFSDK_Document::GetPageView(int nIndex)
379 {
380         CPDFSDK_PageView * pTempPageView = NULL;
381         CPDFXFA_Page * pTempPage = (CPDFXFA_Page*)m_pEnv->FFI_GetPage(m_pDoc,nIndex);
382         if(!pTempPage)
383                 return NULL;
384
385         m_pageMap.Lookup(pTempPage, pTempPageView);
386
387         ASSERT(pTempPageView != NULL);
388
389         return pTempPageView;
390 }
391
392 void CPDFSDK_Document:: ProcJavascriptFun()
393 {
394         CPDFXFA_Document* pPDFDoc = GetDocument();
395         CPDF_DocJSActions docJS(pPDFDoc->GetPDFDoc());
396         int iCount = docJS.CountJSActions();
397         if (iCount < 1) return;
398         for (int i = 0; i < iCount; i ++)
399         {
400                 CFX_ByteString csJSName;
401                 CPDF_Action jsAction = docJS.GetJSAction(i, csJSName);
402                 if(m_pEnv->GetActionHander())
403                         m_pEnv->GetActionHander()->DoAction_JavaScript(jsAction,CFX_WideString::FromLocal(csJSName),this);
404         }
405
406 }
407
408 FX_BOOL CPDFSDK_Document::ProcOpenAction()
409 {
410         if(!m_pDoc)
411                 return FALSE;
412
413         CPDF_Dictionary* pRoot = m_pDoc->GetPDFDoc()->GetRoot();
414         if (!pRoot)
415                 return FALSE;
416
417         CPDF_Object* pOpenAction = pRoot->GetDict("OpenAction");
418         if(!pOpenAction)
419                 pOpenAction = pRoot->GetArray("OpenAction");
420
421         if(!pOpenAction)
422                 return FALSE;
423
424         if(pOpenAction->GetType()==PDFOBJ_ARRAY)
425                 return TRUE;
426
427         if(pOpenAction->GetType()==PDFOBJ_DICTIONARY)
428         {
429                 CPDF_Dictionary * pDict=(CPDF_Dictionary*)pOpenAction;
430                 CPDF_Action action(pDict);
431                 if(m_pEnv->GetActionHander())
432                         m_pEnv->GetActionHander()->DoAction_DocOpen(action, this);
433                 return TRUE;
434         }
435         return FALSE;
436 }
437
438 CPDF_OCContext* CPDFSDK_Document::GetOCContext()
439 {
440         if(!m_pOccontent)
441                 m_pOccontent = new CPDF_OCContext(m_pDoc->GetPDFDoc());
442         return m_pOccontent;
443 }
444
445 void CPDFSDK_Document::ReMovePageView(CPDFXFA_Page* pPDFXFAPage)
446 {
447         CPDFSDK_PageView* pPageView = (CPDFSDK_PageView*)m_pageMap.GetValueAt(pPDFXFAPage);
448         if(pPageView && !pPageView->IsLocked())
449         {
450                 delete pPageView;
451                 m_pageMap.RemoveKey(pPDFXFAPage);
452         }
453 }
454
455 CPDFXFA_Page * CPDFSDK_Document::GetPage(int nIndex)
456 {
457         CPDFXFA_Page * pTempPage = (CPDFXFA_Page*)m_pEnv->FFI_GetPage(m_pDoc,nIndex);
458         if(!pTempPage)
459                 return NULL;
460         return pTempPage;
461 }
462
463 CPDFSDK_InterForm* CPDFSDK_Document::GetInterForm()
464 {
465         if(!m_pInterForm)
466                 m_pInterForm = new CPDFSDK_InterForm(this);
467         return m_pInterForm;
468 }
469
470 void CPDFSDK_Document::UpdateAllViews(CPDFSDK_PageView* pSender, CPDFSDK_Annot* pAnnot)
471 {
472
473         FX_POSITION pos = m_pageMap.GetStartPosition();
474         CPDFXFA_Page * pPage = NULL;
475         CPDFSDK_PageView * pPageView = NULL;
476         while(pos)
477         {
478                 m_pageMap.GetNextAssoc(pos, pPage, pPageView);
479
480                 if(pPageView != pSender)
481                 {
482                         pPageView->UpdateView(pAnnot);
483                 }
484         }
485 }
486
487 CPDFSDK_Annot* CPDFSDK_Document::GetFocusAnnot()
488 {
489     return m_pFocusAnnot;
490 }
491
492 FX_BOOL CPDFSDK_Document::SetFocusAnnot(CPDFSDK_Annot* pAnnot,FX_UINT nFlag)
493 {
494
495         if(m_pFocusAnnot==pAnnot) return TRUE;
496
497         CPDFSDK_Annot* pLastFocusAnnot = m_pFocusAnnot;
498
499         if(m_pFocusAnnot)
500         {
501                 if(!KillFocusAnnot(nFlag) ) return FALSE;
502         }
503         CPDFSDK_PageView* pPageView = NULL;
504         if (pAnnot)
505                 pPageView = pAnnot->GetPageView();
506         if(pAnnot && pPageView->IsValid())
507         {
508                 CPDFSDK_AnnotHandlerMgr *pAnnotHandler=m_pEnv->GetAnnotHandlerMgr();
509
510                 if(pAnnotHandler&&!m_pFocusAnnot)
511                 {
512                         if (!pAnnotHandler->Annot_OnChangeFocus(pAnnot,pLastFocusAnnot))
513                                 return FALSE;
514
515                         if (!pAnnotHandler->Annot_OnSetFocus(pAnnot,nFlag))
516                                 return FALSE;
517                         if(!m_pFocusAnnot)
518                         {
519                                 m_pFocusAnnot=pAnnot;
520                                 return TRUE;
521                         }
522                 }
523         }
524         return FALSE;
525 }
526
527 FX_BOOL CPDFSDK_Document::KillFocusAnnot(FX_UINT nFlag)
528 {
529         if(m_pFocusAnnot)
530         {
531                 CPDFSDK_AnnotHandlerMgr *pAnnotHandler=m_pEnv->GetAnnotHandlerMgr();
532                 if(pAnnotHandler)
533                 {
534                         CPDFSDK_Annot* pFocusAnnot = m_pFocusAnnot;
535                         m_pFocusAnnot = NULL;
536
537                         if (!pAnnotHandler->Annot_OnChangeFocus(NULL, pFocusAnnot))
538                                 return FALSE;
539
540                         if(pAnnotHandler->Annot_OnKillFocus(pFocusAnnot, nFlag))
541                         {
542
543                                 if(pFocusAnnot->GetType() == FX_BSTRC("Widget"))
544                                 {
545                                         CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pFocusAnnot;
546                                         int nFieldType = pWidget->GetFieldType();
547                                         if(FIELDTYPE_TEXTFIELD == nFieldType || FIELDTYPE_COMBOBOX == nFieldType)
548                                                 m_pEnv->FFI_OnSetFieldInputFocus(NULL, NULL, 0, FALSE);
549                                 }
550
551                                 if(!m_pFocusAnnot)
552                                         return TRUE;
553                         }
554                         else
555                         {
556                                 m_pFocusAnnot = pFocusAnnot;
557                         }
558                 }
559         }
560         return FALSE;
561 }
562
563 FX_BOOL CPDFSDK_Document::DeletePages(int nStart, int  nCount)
564 {
565         if ( nStart < 0 || nStart >= GetPageCount() || nCount <= 0 )
566         {
567                 return FALSE;
568         }
569
570         CPDFXFA_Page * pTempPage = NULL;
571         for ( int i = nCount-1; i >= 0; i-- )
572         {
573                 pTempPage = GetPage(nStart+i);
574                 if ( pTempPage != NULL )
575                 {
576                         ReMovePageView(pTempPage);
577                 }
578         }
579         return TRUE;
580 }
581
582 void CPDFSDK_Document::OnCloseDocument()
583 {
584         KillFocusAnnot();
585 }
586
587 FX_BOOL CPDFSDK_Document::GetPermissions(int nFlag)
588 {
589         FX_DWORD dwPermissions = m_pDoc->GetPDFDoc()->GetUserPermissions();
590         return dwPermissions&nFlag;
591 }
592
593 IFXJS_Runtime * CPDFSDK_Document::GetJsRuntime()
594 {
595         ASSERT(m_pEnv!=NULL);
596         return m_pEnv->GetJSRuntime();
597 }
598
599 CFX_WideString  CPDFSDK_Document::GetPath()
600 {
601         ASSERT(m_pEnv != NULL);
602         return m_pEnv->JS_docGetFilePath();
603 }
604
605
606 CPDFSDK_PageView::CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc,CPDFXFA_Page* page):m_page(page),m_pSDKDoc(pSDKDoc)
607 {
608         CPDFSDK_InterForm* pInterForm = pSDKDoc->GetInterForm();
609         if(pInterForm)
610         {
611                 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm();
612                 if (page->GetPDFPage())
613                         pPDFInterForm->FixPageFields(page->GetPDFPage());
614         }
615         m_fxAnnotArray.RemoveAll();
616
617         m_bEnterWidget = FALSE;
618         m_bExitWidget = FALSE;
619         m_bOnWidget = FALSE;
620         m_CaptureWidget = NULL;
621         m_bValid = FALSE;
622         m_bLocked = FALSE;
623         m_pAnnotList = NULL;
624 }
625
626 CPDFSDK_PageView::~CPDFSDK_PageView()
627 {
628         CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
629         int nAnnotCount = m_fxAnnotArray.GetSize();
630         for (int i=0; i<nAnnotCount; i++)
631         {
632                 CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i);
633                 //if there is a focused annot on the page, we should kill the focus first.
634                 if(pAnnot == m_pSDKDoc->GetFocusAnnot())
635                         KillFocusAnnot();
636                 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
637                 ASSERT(pAnnotHandlerMgr);
638                 pAnnotHandlerMgr->ReleaseAnnot(pAnnot);
639         }
640         m_fxAnnotArray.RemoveAll();
641         if(m_pAnnotList)
642         {
643                 delete m_pAnnotList;
644                 m_pAnnotList = NULL;
645         }
646 }
647
648 void CPDFSDK_PageView::PageView_OnDraw(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,CPDF_RenderOptions* pOptions, FX_RECT* pClip)
649 {
650         m_curMatrix = *pUser2Device;
651         //      m_pAnnotList->DisplayAnnots(m_page, pDevice, pUser2Device, FALSE, pOptions);
652         CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
653         CPDFXFA_Page* pPage = GetPDFXFAPage();
654
655         if (pPage == NULL) return;
656
657         if (pPage->GetDocument()->GetDocType() == DOCTYPE_DYNIMIC_XFA) {
658                 CFX_Graphics gs;
659                 gs.Create(pDevice);
660                 if (pClip) {
661                         CFX_RectF rectClip;
662                         rectClip.Set(static_cast<FX_FLOAT>(pClip->left),
663                                 static_cast<FX_FLOAT>(pClip->top),
664                                 static_cast<FX_FLOAT>(pClip->Width()),
665                                 static_cast<FX_FLOAT>(pClip->Height()));
666                         gs.SetClipRect(rectClip);
667                 }
668                 IXFA_RenderContext* pRenderContext = XFA_RenderContext_Create();
669                 if (!pRenderContext)
670                         return;
671                 CXFA_RenderOptions renderOptions;
672                 renderOptions.m_bHighlight = TRUE;
673                 pRenderContext->StartRender(pPage->GetXFAPageView(), &gs, *pUser2Device, renderOptions);
674                 pRenderContext->DoRender();
675                 pRenderContext->StopRender();
676                 pRenderContext->Release();
677                 return;
678         }
679         // for pdf/static xfa.
680         CPDFSDK_AnnotIterator annotIterator(this, TRUE);
681         CPDFSDK_Annot * pSDKAnnot=NULL;
682         int index=-1;
683         pSDKAnnot = annotIterator.Next(index);
684         while(pSDKAnnot)
685         {
686                 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
687                 ASSERT(pAnnotHandlerMgr);
688                 pAnnotHandlerMgr->Annot_OnDraw(this, pSDKAnnot, pDevice, pUser2Device, 0);
689                 pSDKAnnot = annotIterator.Next(index);
690         }
691 }
692 CPDF_Annot* CPDFSDK_PageView::GetPDFAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY)
693 {
694
695         int nCount = m_pAnnotList->Count();
696         for(int i = 0 ; i<nCount; i++)
697         {
698                 CPDF_Annot* pAnnot = m_pAnnotList->GetAt(i);
699                 CFX_FloatRect annotRect;
700                 pAnnot->GetRect(annotRect);
701                 if(annotRect.Contains(pageX, pageY))
702                         return pAnnot;
703         }
704         return NULL;
705 }
706
707 CPDF_Annot* CPDFSDK_PageView::GetPDFWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY)
708 {
709
710         int nCount = m_pAnnotList->Count();
711         for(int i = 0 ; i<nCount; i++)
712         {
713                 CPDF_Annot* pAnnot = m_pAnnotList->GetAt(i);
714                 if(pAnnot->GetSubType() == "Widget")
715                 {
716                         CFX_FloatRect annotRect;
717                         pAnnot->GetRect(annotRect);
718                         if(annotRect.Contains(pageX, pageY))
719                                 return pAnnot;
720                 }
721         }
722         return NULL;
723 }
724
725 CPDFSDK_Annot* CPDFSDK_PageView::GetFXAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY)
726 {
727
728         CPDFSDK_AnnotIterator annotIterator(this, FALSE);
729         CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
730         CPDFSDK_AnnotHandlerMgr* pAnnotMgr = pEnv->GetAnnotHandlerMgr();
731         CPDFSDK_Annot* pSDKAnnot = NULL;
732         int index = -1;
733         pSDKAnnot = annotIterator.Next(index);
734         while(pSDKAnnot)
735         {
736                 CPDF_Rect rc = pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot);
737                 if(rc.Contains(pageX, pageY))
738                         return pSDKAnnot;
739                 pSDKAnnot = annotIterator.Next(index);
740         }
741
742         return NULL;
743 }
744
745 CPDFSDK_Annot* CPDFSDK_PageView::GetFXWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY)
746 {
747
748         CPDFSDK_AnnotIterator annotIterator(this, FALSE);
749         CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
750         CPDFSDK_AnnotHandlerMgr* pAnnotMgr = pEnv->GetAnnotHandlerMgr();
751         CPDFSDK_Annot* pSDKAnnot = NULL;
752         int index = -1;
753         pSDKAnnot = annotIterator.Next(index);
754         while(pSDKAnnot)
755         {
756                 if(pSDKAnnot->GetType() == "Widget" || pSDKAnnot->GetType() == FSDK_XFAWIDGET_TYPENAME)
757                 {
758                         pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot);
759                         CPDF_Point point(pageX, pageY);
760                         if (pAnnotMgr->Annot_OnHitTest(this, pSDKAnnot, point))
761                                 return pSDKAnnot;
762                 }
763                 pSDKAnnot = annotIterator.Next(index);
764         }
765
766         return NULL;
767 }
768
769
770 FX_BOOL CPDFSDK_PageView::Annot_HasAppearance(CPDF_Annot* pAnnot)
771 {
772         CPDF_Dictionary* pAnnotDic = pAnnot->GetAnnotDict();
773         if(pAnnotDic)
774                 return  pAnnotDic->KeyExist("AS");
775         return FALSE;
776 }
777
778 CPDFSDK_Annot*  CPDFSDK_PageView::AddAnnot(CPDF_Annot * pPDFAnnot)
779 {
780         CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
781         ASSERT(pEnv);
782         CPDFSDK_AnnotHandlerMgr * pAnnotHandler= pEnv->GetAnnotHandlerMgr();
783
784         CPDFSDK_Annot* pSDKAnnot =NULL;
785
786         if(pAnnotHandler)
787         {
788                 pSDKAnnot = pAnnotHandler->NewAnnot(pPDFAnnot, this);
789         }
790         if(!pSDKAnnot)
791                 return NULL;
792
793         m_fxAnnotArray.Add(pSDKAnnot);
794
795         if(pAnnotHandler)
796         {
797                 pAnnotHandler->Annot_OnCreate(pSDKAnnot);
798
799         }
800
801          return pSDKAnnot;
802 }
803
804 CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(IXFA_Widget* pPDFAnnot)
805 {
806         if (!pPDFAnnot) return NULL;
807
808         CPDFSDK_Annot* pSDKAnnot = GetAnnotByXFAWidget(pPDFAnnot);
809         if (pSDKAnnot)
810                 return pSDKAnnot;
811
812         CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
813         ASSERT(pEnv);
814         CPDFSDK_AnnotHandlerMgr * pAnnotHandler= pEnv->GetAnnotHandlerMgr();
815
816         pSDKAnnot =NULL;
817
818         if(pAnnotHandler)
819         {
820                 pSDKAnnot = pAnnotHandler->NewAnnot(pPDFAnnot, this);
821         }
822         if(!pSDKAnnot)
823                 return NULL;
824
825         m_fxAnnotArray.Add(pSDKAnnot);
826
827         return pSDKAnnot;
828 }
829
830 CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CPDF_Dictionary * pDict)
831 {
832     return pDict ? AddAnnot(pDict->GetString("Subtype"), pDict) : nullptr;
833 }
834
835 CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(const FX_CHAR* lpSubType,CPDF_Dictionary * pDict)
836 {
837         return NULL;
838 }
839
840 FX_BOOL  CPDFSDK_PageView::DeleteAnnot(CPDFSDK_Annot* pAnnot)
841 {
842         if (!pAnnot)
843                 return FALSE;
844         CPDFXFA_Page* pPage = pAnnot->GetPDFXFAPage();
845         if (!pPage || (pPage->GetDocument()->GetDocType() != DOCTYPE_STATIC_XFA && pPage->GetDocument()->GetDocType() != DOCTYPE_DYNIMIC_XFA))
846                 return FALSE;
847
848         int index = m_fxAnnotArray.Find(pAnnot);
849         m_fxAnnotArray.RemoveAt(index);
850         if (m_CaptureWidget == pAnnot)
851                 m_CaptureWidget = NULL;
852
853         return TRUE;
854 }
855
856 CPDF_Document* CPDFSDK_PageView::GetPDFDocument()
857 {
858         if(m_page)
859         {
860                 return m_page->GetDocument()->GetPDFDoc();
861         }
862         return NULL;
863 }
864
865 CPDF_Page* CPDFSDK_PageView::GetPDFPage()
866 {
867         if (m_page)
868         {
869                 return m_page->GetPDFPage();
870         }
871
872         return NULL;
873 }
874
875 int     CPDFSDK_PageView::CountAnnots()
876 {
877         return m_fxAnnotArray.GetSize();
878 }
879
880 CPDFSDK_Annot*  CPDFSDK_PageView::GetAnnot(int nIndex)
881 {
882         int nCount = m_fxAnnotArray.GetSize();
883         if ( nIndex < 0 || nIndex >= nCount )
884         {
885                 return NULL;
886         }
887
888         return (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(nIndex);
889 }
890
891 CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByDict(CPDF_Dictionary * pDict)
892 {
893         int nCount = m_fxAnnotArray.GetSize();
894         for(int i=0; i<nCount; i++)
895         {
896                 CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i);
897                 if (pDict == pAnnot->GetPDFAnnot()->GetAnnotDict())
898                         return pAnnot;
899         }
900         return NULL;
901 }
902 CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByXFAWidget(IXFA_Widget* hWidget)
903 {
904         if (hWidget == NULL)
905                 return NULL;
906         int annotCount = m_fxAnnotArray.GetSize();
907
908         for(int i = 0; i < annotCount; i++)
909         {
910                 CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i);
911                 if(pAnnot->GetXFAWidget() == hWidget)
912                         return pAnnot;
913         }
914         return NULL;
915 }
916
917 FX_BOOL CPDFSDK_PageView::OnLButtonDown(const CPDF_Point & point, FX_UINT nFlag)
918 {
919         CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
920         ASSERT(pEnv);
921         CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y);
922         if(!pFXAnnot)
923         {
924                 KillFocusAnnot(nFlag);
925         }
926         else
927         {
928                 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
929                 ASSERT(pAnnotHandlerMgr);
930
931                 FX_BOOL bRet = pAnnotHandlerMgr->Annot_OnLButtonDown(this, pFXAnnot, nFlag,point);
932                 if(bRet)
933                 {
934                         SetFocusAnnot(pFXAnnot);
935                 }
936                 return bRet;
937         }
938         return FALSE;
939 }
940
941 FX_BOOL CPDFSDK_PageView::OnRButtonDown(const CPDF_Point & point, FX_UINT nFlag)
942 {
943         CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
944         ASSERT(pEnv);
945         CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
946         ASSERT(pAnnotHandlerMgr);
947
948         CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y);
949
950         if (pFXAnnot == NULL)
951                 return FALSE;
952
953         FX_BOOL bRet = pAnnotHandlerMgr->Annot_OnRButtonDown(this, pFXAnnot, nFlag,point);
954         if (bRet)
955         {
956                 SetFocusAnnot(pFXAnnot);
957         }
958         return TRUE;
959 }
960
961 FX_BOOL CPDFSDK_PageView::OnRButtonUp(const CPDF_Point & point, FX_UINT nFlag)
962 {
963         CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
964         ASSERT(pEnv);
965         CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
966         ASSERT(pAnnotHandlerMgr);
967
968         CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y);
969
970         if (pFXAnnot == NULL)
971                 return FALSE;
972
973         FX_BOOL bRet = pAnnotHandlerMgr->Annot_OnRButtonUp(this, pFXAnnot, nFlag,point);
974         if (bRet)
975         {
976                 SetFocusAnnot(pFXAnnot);
977         }
978         return TRUE;
979 }
980
981 FX_BOOL CPDFSDK_PageView::OnLButtonUp(const CPDF_Point & point, FX_UINT nFlag)
982 {
983         CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
984         ASSERT(pEnv);
985         CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
986         ASSERT(pAnnotHandlerMgr);
987         CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y);
988         CPDFSDK_Annot* pFocusAnnot = GetFocusAnnot();
989         FX_BOOL bRet  = FALSE;
990         if(pFocusAnnot && pFocusAnnot != pFXAnnot)
991         {
992                 //Last focus Annot gets a chance to handle the event.
993                 bRet = pAnnotHandlerMgr->Annot_OnLButtonUp(this, pFocusAnnot, nFlag,point);
994         }
995         if(pFXAnnot && !bRet)
996         {
997                 bRet = pAnnotHandlerMgr->Annot_OnLButtonUp(this, pFXAnnot, nFlag,point);
998                 return bRet;
999         }
1000         return bRet;
1001 }
1002
1003 FX_BOOL CPDFSDK_PageView::OnMouseMove(const CPDF_Point & point, int nFlag)
1004 {
1005
1006         CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1007         CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
1008         ASSERT(pAnnotHandlerMgr);
1009         if(CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y))
1010         {
1011                 if(m_CaptureWidget && m_CaptureWidget != pFXAnnot)
1012                 {
1013                         m_bExitWidget = TRUE;
1014                         m_bEnterWidget = FALSE;
1015                         pAnnotHandlerMgr->Annot_OnMouseExit(this, m_CaptureWidget, nFlag);
1016                 }
1017                 m_CaptureWidget = (CPDFSDK_Widget*)pFXAnnot;
1018                 m_bOnWidget = TRUE;
1019                 if(!m_bEnterWidget)
1020                 {
1021                         m_bEnterWidget = TRUE;
1022                         m_bExitWidget = FALSE;
1023                         pAnnotHandlerMgr->Annot_OnMouseEnter(this, pFXAnnot,nFlag);
1024                 }
1025                 pAnnotHandlerMgr->Annot_OnMouseMove(this, pFXAnnot, nFlag, point);
1026                 return TRUE;
1027         }
1028         else
1029         {
1030                 if(m_bOnWidget)
1031                 {
1032                         m_bOnWidget = FALSE;
1033                         m_bExitWidget = TRUE;
1034                         m_bEnterWidget = FALSE;
1035                         if(m_CaptureWidget)
1036                         {
1037                                 pAnnotHandlerMgr->Annot_OnMouseExit(this, m_CaptureWidget, nFlag);
1038                                 m_CaptureWidget = NULL;
1039                         }
1040                 }
1041                 return FALSE;
1042         }
1043
1044         return FALSE;;
1045 }
1046
1047 FX_BOOL CPDFSDK_PageView::OnMouseWheel(double deltaX, double deltaY,const CPDF_Point& point, int nFlag)
1048 {
1049         if(CPDFSDK_Annot* pAnnot = GetFXWidgetAtPoint(point.x, point.y))
1050         {
1051                 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1052                 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
1053                 ASSERT(pAnnotHandlerMgr);
1054                 return pAnnotHandlerMgr->Annot_OnMouseWheel(this, pAnnot, nFlag, (int)deltaY, point);
1055         }
1056         return FALSE;
1057
1058 }
1059
1060 FX_BOOL CPDFSDK_PageView::OnChar(int nChar, FX_UINT nFlag)
1061 {
1062         if(CPDFSDK_Annot* pAnnot = GetFocusAnnot())
1063         {
1064                 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1065                 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
1066                 ASSERT(pAnnotHandlerMgr);
1067                 return pAnnotHandlerMgr->Annot_OnChar(pAnnot, nChar, nFlag);
1068         }
1069
1070         return FALSE;
1071 }
1072
1073 FX_BOOL CPDFSDK_PageView::OnKeyDown(int nKeyCode, int nFlag)
1074 {
1075         if(CPDFSDK_Annot* pAnnot = GetFocusAnnot())
1076         {
1077                 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1078                 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
1079                 ASSERT(pAnnotHandlerMgr);
1080                 return pAnnotHandlerMgr->Annot_OnKeyDown(pAnnot, nKeyCode, nFlag);
1081         }
1082         return FALSE;
1083 }
1084
1085 FX_BOOL CPDFSDK_PageView::OnKeyUp(int nKeyCode, int nFlag)
1086 {
1087 //      if(CPDFSDK_Annot* pAnnot = GetFocusAnnot())
1088 //      {
1089 //              CFFL_IFormFiller* pIFormFiller = g_pFormFillApp->GetIFormFiller();
1090 //              return pIFormFiller->OnKeyUp(pAnnot, nKeyCode, nFlag);
1091 //      }
1092         return FALSE;
1093 }
1094
1095 extern void CheckUnSupportAnnot(CPDF_Document * pDoc, CPDF_Annot* pPDFAnnot);
1096
1097 void CPDFSDK_PageView::LoadFXAnnots()
1098 {
1099         ASSERT(m_page != NULL);
1100
1101         CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1102         ASSERT(pEnv != NULL);
1103
1104         CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
1105         ASSERT(pAnnotHandlerMgr != NULL);
1106
1107         SetLock(TRUE);
1108         m_page->AddRef();
1109         if (m_pSDKDoc->GetDocument()->GetDocType() == DOCTYPE_DYNIMIC_XFA)
1110         {
1111                 IXFA_PageView* pageView = NULL;
1112                 pageView = m_page->GetXFAPageView();
1113                 ASSERT(pageView != NULL);
1114
1115                 IXFA_WidgetIterator* pWidgetHander = pageView->CreateWidgetIterator(XFA_TRAVERSEWAY_Form, XFA_WIDGETFILTER_Visible|XFA_WIDGETFILTER_Viewable|XFA_WIDGETFILTER_AllType);
1116                 if (!pWidgetHander)
1117                 {
1118                         m_page->Release();
1119                         SetLock(FALSE);
1120                         return;
1121                 }
1122
1123         IXFA_Widget* pXFAAnnot = pWidgetHander->MoveToNext();
1124                 while (pXFAAnnot) {
1125                         CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pXFAAnnot, this);
1126                         if(!pAnnot) {
1127                                 pXFAAnnot = pWidgetHander->MoveToNext();
1128                                 continue;
1129                         }
1130                         m_fxAnnotArray.Add(pAnnot);
1131
1132                         pAnnotHandlerMgr->Annot_OnLoad(pAnnot);
1133
1134                         pXFAAnnot = pWidgetHander->MoveToNext();
1135
1136                 }
1137
1138                 pWidgetHander->Release();
1139         }
1140         else
1141         {
1142                 CPDF_Page* pPage = m_page->GetPDFPage();
1143                 ASSERT(pPage != NULL);
1144
1145                 FX_BOOL enableAPUpdate = CPDF_InterForm::UpdatingAPEnabled();
1146                 //Disable the default AP construction.
1147                 CPDF_InterForm::EnableUpdateAP(FALSE);
1148                 m_pAnnotList = new CPDF_AnnotList(pPage);
1149                 CPDF_InterForm::EnableUpdateAP(enableAPUpdate);
1150
1151                 int nCount = m_pAnnotList->Count();
1152                 for(int i=0; i<nCount; i++)
1153                 {
1154                         CPDF_Annot* pPDFAnnot = m_pAnnotList->GetAt(i);
1155                         CPDF_Document * pDoc = GetPDFDocument();
1156
1157                         CheckUnSupportAnnot(pDoc, pPDFAnnot);
1158
1159                         CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pPDFAnnot, this);
1160                         if(!pAnnot)
1161                                 continue;
1162                         m_fxAnnotArray.Add(pAnnot);
1163
1164                         pAnnotHandlerMgr->Annot_OnLoad(pAnnot);
1165                 }
1166
1167         }
1168         m_page->Release();
1169         SetLock(FALSE);
1170 }
1171
1172 void    CPDFSDK_PageView::UpdateRects(CFX_RectArray& rects)
1173 {
1174         for(int i=0; i<rects.GetSize(); i++)
1175         {
1176                 CPDF_Rect rc = rects.GetAt(i);
1177                 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1178                 pEnv->FFI_Invalidate(m_page, rc.left, rc.top, rc.right, rc.bottom);
1179         }
1180 }
1181
1182 void CPDFSDK_PageView::UpdateView(CPDFSDK_Annot* pAnnot)
1183 {
1184     CPDF_Rect rcWindow = pAnnot->GetRect();
1185     CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1186     pEnv->FFI_Invalidate(
1187         m_page, rcWindow.left, rcWindow.top, rcWindow.right, rcWindow.bottom);
1188 }
1189
1190 int CPDFSDK_PageView::GetPageIndex()
1191 {
1192         if(m_page)
1193         {
1194                 CPDF_Dictionary* pDic = m_page->GetPDFPage()->m_pFormDict;
1195                 CPDFXFA_Document* pDoc = m_pSDKDoc->GetDocument();
1196                 if(pDoc && pDic)
1197                 {
1198                         return pDoc->GetPDFDoc()->GetPageIndex(pDic->GetObjNum());
1199                 }
1200         }
1201         return -1;
1202 }
1203
1204 FX_BOOL CPDFSDK_PageView::IsValidAnnot(void* p)
1205 {
1206         if (p == NULL) return FALSE;
1207         int iCount = m_pAnnotList->Count();
1208         for (int i = 0; i < iCount; i++)
1209         {
1210                 if (m_pAnnotList->GetAt(i) == p)
1211                         return TRUE;
1212         }
1213         return FALSE;
1214 }
1215
1216
1217 CPDFSDK_Annot* CPDFSDK_PageView::GetFocusAnnot()
1218 {
1219         CPDFSDK_Annot* pFocusAnnot = m_pSDKDoc->GetFocusAnnot();
1220         if(!pFocusAnnot)
1221                 return NULL;
1222
1223         for(int i=0; i<m_fxAnnotArray.GetSize(); i++)
1224         {
1225                 CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i);
1226                 if(pAnnot == pFocusAnnot)
1227                         return pAnnot;
1228         }
1229         return NULL;
1230 }
1231