Replace some Release() calls with virtual destructors.
[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
329     delete m_pInterForm;
330     m_pInterForm = nullptr;
331
332     delete m_pOccontent;
333     m_pOccontent = nullptr;
334 }
335
336 void CPDFSDK_Document::InitPageView()
337 {
338         int nCount = m_pDoc->GetPageCount();
339         for(int i=0; i<nCount; i++)
340         {
341         // To do
342 //              CPDF_Dictionary* pDic = m_pDoc->GetPage(i);
343 //              m_pageMap.SetAt(pDic, pPageView);
344         }
345 }
346
347 void CPDFSDK_Document::AddPageView(CPDFXFA_Page* pPDFXFAPage, CPDFSDK_PageView* pPageView)
348 {
349         m_pageMap.SetAt(pPDFXFAPage, pPageView);
350 }
351
352 CPDFSDK_PageView* CPDFSDK_Document::GetPageView(CPDFXFA_Page* pPDFXFAPage, FX_BOOL ReNew)
353 {
354         CPDFSDK_PageView* pPageView = (CPDFSDK_PageView*)m_pageMap.GetValueAt(pPDFXFAPage);
355         if(pPageView != NULL)
356                 return pPageView;
357         if(ReNew)
358         {
359                 pPageView = new CPDFSDK_PageView(this,pPDFXFAPage);
360                 m_pageMap.SetAt(pPDFXFAPage, pPageView);
361                 //Delay to load all the annotations, to avoid endless loop.
362                 pPageView->LoadFXAnnots();
363         }
364         return pPageView;
365
366 }
367
368 CPDFSDK_PageView* CPDFSDK_Document::GetCurrentView()
369 {
370     CPDFXFA_Page* pPage = (CPDFXFA_Page *)m_pEnv->FFI_GetCurrentPage(m_pDoc);
371     return pPage ? GetPageView(pPage, TRUE) : nullptr;
372 }
373
374 CPDFSDK_PageView* CPDFSDK_Document::GetPageView(int nIndex)
375 {
376         CPDFSDK_PageView * pTempPageView = NULL;
377         CPDFXFA_Page * pTempPage = (CPDFXFA_Page*)m_pEnv->FFI_GetPage(m_pDoc,nIndex);
378         if(!pTempPage)
379                 return NULL;
380
381         m_pageMap.Lookup(pTempPage, pTempPageView);
382
383         ASSERT(pTempPageView != NULL);
384
385         return pTempPageView;
386 }
387
388 void CPDFSDK_Document:: ProcJavascriptFun()
389 {
390         CPDFXFA_Document* pPDFDoc = GetDocument();
391         CPDF_DocJSActions docJS(pPDFDoc->GetPDFDoc());
392         int iCount = docJS.CountJSActions();
393         if (iCount < 1) return;
394         for (int i = 0; i < iCount; i ++)
395         {
396                 CFX_ByteString csJSName;
397                 CPDF_Action jsAction = docJS.GetJSAction(i, csJSName);
398                 if(m_pEnv->GetActionHander())
399                         m_pEnv->GetActionHander()->DoAction_JavaScript(jsAction,CFX_WideString::FromLocal(csJSName),this);
400         }
401
402 }
403
404 FX_BOOL CPDFSDK_Document::ProcOpenAction()
405 {
406         if(!m_pDoc)
407                 return FALSE;
408
409         CPDF_Dictionary* pRoot = m_pDoc->GetPDFDoc()->GetRoot();
410         if (!pRoot)
411                 return FALSE;
412
413         CPDF_Object* pOpenAction = pRoot->GetDict("OpenAction");
414         if(!pOpenAction)
415                 pOpenAction = pRoot->GetArray("OpenAction");
416
417         if(!pOpenAction)
418                 return FALSE;
419
420         if(pOpenAction->GetType()==PDFOBJ_ARRAY)
421                 return TRUE;
422
423         if(pOpenAction->GetType()==PDFOBJ_DICTIONARY)
424         {
425                 CPDF_Dictionary * pDict=(CPDF_Dictionary*)pOpenAction;
426                 CPDF_Action action(pDict);
427                 if(m_pEnv->GetActionHander())
428                         m_pEnv->GetActionHander()->DoAction_DocOpen(action, this);
429                 return TRUE;
430         }
431         return FALSE;
432 }
433
434 CPDF_OCContext* CPDFSDK_Document::GetOCContext()
435 {
436         if(!m_pOccontent)
437                 m_pOccontent = new CPDF_OCContext(m_pDoc->GetPDFDoc());
438         return m_pOccontent;
439 }
440
441 void CPDFSDK_Document::ReMovePageView(CPDFXFA_Page* pPDFXFAPage)
442 {
443         CPDFSDK_PageView* pPageView = (CPDFSDK_PageView*)m_pageMap.GetValueAt(pPDFXFAPage);
444         if(pPageView && !pPageView->IsLocked())
445         {
446                 delete pPageView;
447                 m_pageMap.RemoveKey(pPDFXFAPage);
448         }
449 }
450
451 CPDFXFA_Page * CPDFSDK_Document::GetPage(int nIndex)
452 {
453         CPDFXFA_Page * pTempPage = (CPDFXFA_Page*)m_pEnv->FFI_GetPage(m_pDoc,nIndex);
454         if(!pTempPage)
455                 return NULL;
456         return pTempPage;
457 }
458
459 CPDFSDK_InterForm* CPDFSDK_Document::GetInterForm()
460 {
461         if(!m_pInterForm)
462                 m_pInterForm = new CPDFSDK_InterForm(this);
463         return m_pInterForm;
464 }
465
466 void CPDFSDK_Document::UpdateAllViews(CPDFSDK_PageView* pSender, CPDFSDK_Annot* pAnnot)
467 {
468
469         FX_POSITION pos = m_pageMap.GetStartPosition();
470         CPDFXFA_Page * pPage = NULL;
471         CPDFSDK_PageView * pPageView = NULL;
472         while(pos)
473         {
474                 m_pageMap.GetNextAssoc(pos, pPage, pPageView);
475
476                 if(pPageView != pSender)
477                 {
478                         pPageView->UpdateView(pAnnot);
479                 }
480         }
481 }
482
483 CPDFSDK_Annot* CPDFSDK_Document::GetFocusAnnot()
484 {
485     return m_pFocusAnnot;
486 }
487
488 FX_BOOL CPDFSDK_Document::SetFocusAnnot(CPDFSDK_Annot* pAnnot,FX_UINT nFlag)
489 {
490
491         if(m_pFocusAnnot==pAnnot) return TRUE;
492
493         CPDFSDK_Annot* pLastFocusAnnot = m_pFocusAnnot;
494
495         if(m_pFocusAnnot)
496         {
497                 if(!KillFocusAnnot(nFlag) ) return FALSE;
498         }
499         CPDFSDK_PageView* pPageView = NULL;
500         if (pAnnot)
501                 pPageView = pAnnot->GetPageView();
502         if(pAnnot && pPageView->IsValid())
503         {
504                 CPDFSDK_AnnotHandlerMgr *pAnnotHandler=m_pEnv->GetAnnotHandlerMgr();
505
506                 if(pAnnotHandler&&!m_pFocusAnnot)
507                 {
508                         if (!pAnnotHandler->Annot_OnChangeFocus(pAnnot,pLastFocusAnnot))
509                                 return FALSE;
510
511                         if (!pAnnotHandler->Annot_OnSetFocus(pAnnot,nFlag))
512                                 return FALSE;
513                         if(!m_pFocusAnnot)
514                         {
515                                 m_pFocusAnnot=pAnnot;
516                                 return TRUE;
517                         }
518                 }
519         }
520         return FALSE;
521 }
522
523 FX_BOOL CPDFSDK_Document::KillFocusAnnot(FX_UINT nFlag)
524 {
525         if(m_pFocusAnnot)
526         {
527                 CPDFSDK_AnnotHandlerMgr *pAnnotHandler=m_pEnv->GetAnnotHandlerMgr();
528                 if(pAnnotHandler)
529                 {
530                         CPDFSDK_Annot* pFocusAnnot = m_pFocusAnnot;
531                         m_pFocusAnnot = NULL;
532
533                         if (!pAnnotHandler->Annot_OnChangeFocus(NULL, pFocusAnnot))
534                                 return FALSE;
535
536                         if(pAnnotHandler->Annot_OnKillFocus(pFocusAnnot, nFlag))
537                         {
538
539                                 if(pFocusAnnot->GetType() == FX_BSTRC("Widget"))
540                                 {
541                                         CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pFocusAnnot;
542                                         int nFieldType = pWidget->GetFieldType();
543                                         if(FIELDTYPE_TEXTFIELD == nFieldType || FIELDTYPE_COMBOBOX == nFieldType)
544                                                 m_pEnv->FFI_OnSetFieldInputFocus(NULL, NULL, 0, FALSE);
545                                 }
546
547                                 if(!m_pFocusAnnot)
548                                         return TRUE;
549                         }
550                         else
551                         {
552                                 m_pFocusAnnot = pFocusAnnot;
553                         }
554                 }
555         }
556         return FALSE;
557 }
558
559 FX_BOOL CPDFSDK_Document::DeletePages(int nStart, int  nCount)
560 {
561         if ( nStart < 0 || nStart >= GetPageCount() || nCount <= 0 )
562         {
563                 return FALSE;
564         }
565
566         CPDFXFA_Page * pTempPage = NULL;
567         for ( int i = nCount-1; i >= 0; i-- )
568         {
569                 pTempPage = GetPage(nStart+i);
570                 if ( pTempPage != NULL )
571                 {
572                         ReMovePageView(pTempPage);
573                 }
574         }
575         return TRUE;
576 }
577
578 void CPDFSDK_Document::OnCloseDocument()
579 {
580         KillFocusAnnot();
581 }
582
583 FX_BOOL CPDFSDK_Document::GetPermissions(int nFlag)
584 {
585         FX_DWORD dwPermissions = m_pDoc->GetPDFDoc()->GetUserPermissions();
586         return dwPermissions&nFlag;
587 }
588
589 IFXJS_Runtime * CPDFSDK_Document::GetJsRuntime()
590 {
591         ASSERT(m_pEnv!=NULL);
592         return m_pEnv->GetJSRuntime();
593 }
594
595 CFX_WideString  CPDFSDK_Document::GetPath()
596 {
597         ASSERT(m_pEnv != NULL);
598         return m_pEnv->JS_docGetFilePath();
599 }
600
601
602 CPDFSDK_PageView::CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc,CPDFXFA_Page* page):m_page(page),m_pSDKDoc(pSDKDoc)
603 {
604         CPDFSDK_InterForm* pInterForm = pSDKDoc->GetInterForm();
605         if(pInterForm)
606         {
607                 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm();
608                 if (page->GetPDFPage())
609                         pPDFInterForm->FixPageFields(page->GetPDFPage());
610         }
611         m_fxAnnotArray.RemoveAll();
612
613         m_bEnterWidget = FALSE;
614         m_bExitWidget = FALSE;
615         m_bOnWidget = FALSE;
616         m_CaptureWidget = NULL;
617         m_bValid = FALSE;
618         m_bLocked = FALSE;
619         m_pAnnotList = NULL;
620 }
621
622 CPDFSDK_PageView::~CPDFSDK_PageView()
623 {
624         CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
625         int nAnnotCount = m_fxAnnotArray.GetSize();
626         for (int i=0; i<nAnnotCount; i++)
627         {
628                 CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i);
629                 //if there is a focused annot on the page, we should kill the focus first.
630                 if(pAnnot == m_pSDKDoc->GetFocusAnnot())
631                         KillFocusAnnot();
632                 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
633                 ASSERT(pAnnotHandlerMgr);
634                 pAnnotHandlerMgr->ReleaseAnnot(pAnnot);
635         }
636         m_fxAnnotArray.RemoveAll();
637         if(m_pAnnotList)
638         {
639                 delete m_pAnnotList;
640                 m_pAnnotList = NULL;
641         }
642 }
643
644 void CPDFSDK_PageView::PageView_OnDraw(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,CPDF_RenderOptions* pOptions, FX_RECT* pClip)
645 {
646         m_curMatrix = *pUser2Device;
647         //      m_pAnnotList->DisplayAnnots(m_page, pDevice, pUser2Device, FALSE, pOptions);
648         CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
649         CPDFXFA_Page* pPage = GetPDFXFAPage();
650
651         if (pPage == NULL) return;
652
653         if (pPage->GetDocument()->GetDocType() == DOCTYPE_DYNIMIC_XFA) {
654                 CFX_Graphics gs;
655                 gs.Create(pDevice);
656                 if (pClip) {
657                         CFX_RectF rectClip;
658                         rectClip.Set(static_cast<FX_FLOAT>(pClip->left),
659                                 static_cast<FX_FLOAT>(pClip->top),
660                                 static_cast<FX_FLOAT>(pClip->Width()),
661                                 static_cast<FX_FLOAT>(pClip->Height()));
662                         gs.SetClipRect(rectClip);
663                 }
664                 IXFA_RenderContext* pRenderContext = XFA_RenderContext_Create();
665                 if (!pRenderContext)
666                         return;
667                 CXFA_RenderOptions renderOptions;
668                 renderOptions.m_bHighlight = TRUE;
669                 pRenderContext->StartRender(pPage->GetXFAPageView(), &gs, *pUser2Device, renderOptions);
670                 pRenderContext->DoRender();
671                 pRenderContext->StopRender();
672                 pRenderContext->Release();
673                 return;
674         }
675         // for pdf/static xfa.
676         CPDFSDK_AnnotIterator annotIterator(this, TRUE);
677         CPDFSDK_Annot * pSDKAnnot=NULL;
678         int index=-1;
679         pSDKAnnot = annotIterator.Next(index);
680         while(pSDKAnnot)
681         {
682                 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
683                 ASSERT(pAnnotHandlerMgr);
684                 pAnnotHandlerMgr->Annot_OnDraw(this, pSDKAnnot, pDevice, pUser2Device, 0);
685                 pSDKAnnot = annotIterator.Next(index);
686         }
687 }
688 CPDF_Annot* CPDFSDK_PageView::GetPDFAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY)
689 {
690
691         int nCount = m_pAnnotList->Count();
692         for(int i = 0 ; i<nCount; i++)
693         {
694                 CPDF_Annot* pAnnot = m_pAnnotList->GetAt(i);
695                 CFX_FloatRect annotRect;
696                 pAnnot->GetRect(annotRect);
697                 if(annotRect.Contains(pageX, pageY))
698                         return pAnnot;
699         }
700         return NULL;
701 }
702
703 CPDF_Annot* CPDFSDK_PageView::GetPDFWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY)
704 {
705
706         int nCount = m_pAnnotList->Count();
707         for(int i = 0 ; i<nCount; i++)
708         {
709                 CPDF_Annot* pAnnot = m_pAnnotList->GetAt(i);
710                 if(pAnnot->GetSubType() == "Widget")
711                 {
712                         CFX_FloatRect annotRect;
713                         pAnnot->GetRect(annotRect);
714                         if(annotRect.Contains(pageX, pageY))
715                                 return pAnnot;
716                 }
717         }
718         return NULL;
719 }
720
721 CPDFSDK_Annot* CPDFSDK_PageView::GetFXAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY)
722 {
723
724         CPDFSDK_AnnotIterator annotIterator(this, FALSE);
725         CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
726         CPDFSDK_AnnotHandlerMgr* pAnnotMgr = pEnv->GetAnnotHandlerMgr();
727         CPDFSDK_Annot* pSDKAnnot = NULL;
728         int index = -1;
729         pSDKAnnot = annotIterator.Next(index);
730         while(pSDKAnnot)
731         {
732                 CPDF_Rect rc = pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot);
733                 if(rc.Contains(pageX, pageY))
734                         return pSDKAnnot;
735                 pSDKAnnot = annotIterator.Next(index);
736         }
737
738         return NULL;
739 }
740
741 CPDFSDK_Annot* CPDFSDK_PageView::GetFXWidgetAtPoint(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;
749         pSDKAnnot = annotIterator.Next(index);
750         while(pSDKAnnot)
751         {
752                 if(pSDKAnnot->GetType() == "Widget" || pSDKAnnot->GetType() == FSDK_XFAWIDGET_TYPENAME)
753                 {
754                         pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot);
755                         CPDF_Point point(pageX, pageY);
756                         if (pAnnotMgr->Annot_OnHitTest(this, pSDKAnnot, point))
757                                 return pSDKAnnot;
758                 }
759                 pSDKAnnot = annotIterator.Next(index);
760         }
761
762         return NULL;
763 }
764
765
766 FX_BOOL CPDFSDK_PageView::Annot_HasAppearance(CPDF_Annot* pAnnot)
767 {
768         CPDF_Dictionary* pAnnotDic = pAnnot->GetAnnotDict();
769         if(pAnnotDic)
770                 return  pAnnotDic->KeyExist("AS");
771         return FALSE;
772 }
773
774 CPDFSDK_Annot*  CPDFSDK_PageView::AddAnnot(CPDF_Annot * pPDFAnnot)
775 {
776         CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
777         ASSERT(pEnv);
778         CPDFSDK_AnnotHandlerMgr * pAnnotHandler= pEnv->GetAnnotHandlerMgr();
779
780         CPDFSDK_Annot* pSDKAnnot =NULL;
781
782         if(pAnnotHandler)
783         {
784                 pSDKAnnot = pAnnotHandler->NewAnnot(pPDFAnnot, this);
785         }
786         if(!pSDKAnnot)
787                 return NULL;
788
789         m_fxAnnotArray.Add(pSDKAnnot);
790
791         if(pAnnotHandler)
792         {
793                 pAnnotHandler->Annot_OnCreate(pSDKAnnot);
794
795         }
796
797          return pSDKAnnot;
798 }
799
800 CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(IXFA_Widget* pPDFAnnot)
801 {
802         if (!pPDFAnnot) return NULL;
803
804         CPDFSDK_Annot* pSDKAnnot = GetAnnotByXFAWidget(pPDFAnnot);
805         if (pSDKAnnot)
806                 return pSDKAnnot;
807
808         CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
809         ASSERT(pEnv);
810         CPDFSDK_AnnotHandlerMgr * pAnnotHandler= pEnv->GetAnnotHandlerMgr();
811
812         pSDKAnnot =NULL;
813
814         if(pAnnotHandler)
815         {
816                 pSDKAnnot = pAnnotHandler->NewAnnot(pPDFAnnot, this);
817         }
818         if(!pSDKAnnot)
819                 return NULL;
820
821         m_fxAnnotArray.Add(pSDKAnnot);
822
823         return pSDKAnnot;
824 }
825
826 CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CPDF_Dictionary * pDict)
827 {
828     return pDict ? AddAnnot(pDict->GetString("Subtype"), pDict) : nullptr;
829 }
830
831 CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(const FX_CHAR* lpSubType,CPDF_Dictionary * pDict)
832 {
833         return NULL;
834 }
835
836 FX_BOOL  CPDFSDK_PageView::DeleteAnnot(CPDFSDK_Annot* pAnnot)
837 {
838         if (!pAnnot)
839                 return FALSE;
840         CPDFXFA_Page* pPage = pAnnot->GetPDFXFAPage();
841         if (!pPage || (pPage->GetDocument()->GetDocType() != DOCTYPE_STATIC_XFA && pPage->GetDocument()->GetDocType() != DOCTYPE_DYNIMIC_XFA))
842                 return FALSE;
843
844         int index = m_fxAnnotArray.Find(pAnnot);
845         m_fxAnnotArray.RemoveAt(index);
846         if (m_CaptureWidget == pAnnot)
847                 m_CaptureWidget = NULL;
848
849         return TRUE;
850 }
851
852 CPDF_Document* CPDFSDK_PageView::GetPDFDocument()
853 {
854         if(m_page)
855         {
856                 return m_page->GetDocument()->GetPDFDoc();
857         }
858         return NULL;
859 }
860
861 CPDF_Page* CPDFSDK_PageView::GetPDFPage()
862 {
863         if (m_page)
864         {
865                 return m_page->GetPDFPage();
866         }
867
868         return NULL;
869 }
870
871 int     CPDFSDK_PageView::CountAnnots()
872 {
873         return m_fxAnnotArray.GetSize();
874 }
875
876 CPDFSDK_Annot*  CPDFSDK_PageView::GetAnnot(int nIndex)
877 {
878         int nCount = m_fxAnnotArray.GetSize();
879         if ( nIndex < 0 || nIndex >= nCount )
880         {
881                 return NULL;
882         }
883
884         return (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(nIndex);
885 }
886
887 CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByDict(CPDF_Dictionary * pDict)
888 {
889         int nCount = m_fxAnnotArray.GetSize();
890         for(int i=0; i<nCount; i++)
891         {
892                 CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i);
893                 if (pDict == pAnnot->GetPDFAnnot()->GetAnnotDict())
894                         return pAnnot;
895         }
896         return NULL;
897 }
898 CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByXFAWidget(IXFA_Widget* hWidget)
899 {
900         if (hWidget == NULL)
901                 return NULL;
902         int annotCount = m_fxAnnotArray.GetSize();
903
904         for(int i = 0; i < annotCount; i++)
905         {
906                 CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i);
907                 if(pAnnot->GetXFAWidget() == hWidget)
908                         return pAnnot;
909         }
910         return NULL;
911 }
912
913 FX_BOOL CPDFSDK_PageView::OnLButtonDown(const CPDF_Point & point, FX_UINT nFlag)
914 {
915         CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
916         ASSERT(pEnv);
917         CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y);
918         if(!pFXAnnot)
919         {
920                 KillFocusAnnot(nFlag);
921         }
922         else
923         {
924                 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
925                 ASSERT(pAnnotHandlerMgr);
926
927                 FX_BOOL bRet = pAnnotHandlerMgr->Annot_OnLButtonDown(this, pFXAnnot, nFlag,point);
928                 if(bRet)
929                 {
930                         SetFocusAnnot(pFXAnnot);
931                 }
932                 return bRet;
933         }
934         return FALSE;
935 }
936
937 FX_BOOL CPDFSDK_PageView::OnRButtonDown(const CPDF_Point & point, FX_UINT nFlag)
938 {
939         CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
940         ASSERT(pEnv);
941         CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
942         ASSERT(pAnnotHandlerMgr);
943
944         CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y);
945
946         if (pFXAnnot == NULL)
947                 return FALSE;
948
949         FX_BOOL bRet = pAnnotHandlerMgr->Annot_OnRButtonDown(this, pFXAnnot, nFlag,point);
950         if (bRet)
951         {
952                 SetFocusAnnot(pFXAnnot);
953         }
954         return TRUE;
955 }
956
957 FX_BOOL CPDFSDK_PageView::OnRButtonUp(const CPDF_Point & point, FX_UINT nFlag)
958 {
959         CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
960         ASSERT(pEnv);
961         CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
962         ASSERT(pAnnotHandlerMgr);
963
964         CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y);
965
966         if (pFXAnnot == NULL)
967                 return FALSE;
968
969         FX_BOOL bRet = pAnnotHandlerMgr->Annot_OnRButtonUp(this, pFXAnnot, nFlag,point);
970         if (bRet)
971         {
972                 SetFocusAnnot(pFXAnnot);
973         }
974         return TRUE;
975 }
976
977 FX_BOOL CPDFSDK_PageView::OnLButtonUp(const CPDF_Point & point, FX_UINT nFlag)
978 {
979         CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
980         ASSERT(pEnv);
981         CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
982         ASSERT(pAnnotHandlerMgr);
983         CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y);
984         CPDFSDK_Annot* pFocusAnnot = GetFocusAnnot();
985         FX_BOOL bRet  = FALSE;
986         if(pFocusAnnot && pFocusAnnot != pFXAnnot)
987         {
988                 //Last focus Annot gets a chance to handle the event.
989                 bRet = pAnnotHandlerMgr->Annot_OnLButtonUp(this, pFocusAnnot, nFlag,point);
990         }
991         if(pFXAnnot && !bRet)
992         {
993                 bRet = pAnnotHandlerMgr->Annot_OnLButtonUp(this, pFXAnnot, nFlag,point);
994                 return bRet;
995         }
996         return bRet;
997 }
998
999 FX_BOOL CPDFSDK_PageView::OnMouseMove(const CPDF_Point & point, int nFlag)
1000 {
1001
1002         CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1003         CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
1004         ASSERT(pAnnotHandlerMgr);
1005         if(CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y))
1006         {
1007                 if(m_CaptureWidget && m_CaptureWidget != pFXAnnot)
1008                 {
1009                         m_bExitWidget = TRUE;
1010                         m_bEnterWidget = FALSE;
1011                         pAnnotHandlerMgr->Annot_OnMouseExit(this, m_CaptureWidget, nFlag);
1012                 }
1013                 m_CaptureWidget = (CPDFSDK_Widget*)pFXAnnot;
1014                 m_bOnWidget = TRUE;
1015                 if(!m_bEnterWidget)
1016                 {
1017                         m_bEnterWidget = TRUE;
1018                         m_bExitWidget = FALSE;
1019                         pAnnotHandlerMgr->Annot_OnMouseEnter(this, pFXAnnot,nFlag);
1020                 }
1021                 pAnnotHandlerMgr->Annot_OnMouseMove(this, pFXAnnot, nFlag, point);
1022                 return TRUE;
1023         }
1024         else
1025         {
1026                 if(m_bOnWidget)
1027                 {
1028                         m_bOnWidget = FALSE;
1029                         m_bExitWidget = TRUE;
1030                         m_bEnterWidget = FALSE;
1031                         if(m_CaptureWidget)
1032                         {
1033                                 pAnnotHandlerMgr->Annot_OnMouseExit(this, m_CaptureWidget, nFlag);
1034                                 m_CaptureWidget = NULL;
1035                         }
1036                 }
1037                 return FALSE;
1038         }
1039
1040         return FALSE;;
1041 }
1042
1043 FX_BOOL CPDFSDK_PageView::OnMouseWheel(double deltaX, double deltaY,const CPDF_Point& point, int nFlag)
1044 {
1045         if(CPDFSDK_Annot* pAnnot = GetFXWidgetAtPoint(point.x, point.y))
1046         {
1047                 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1048                 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
1049                 ASSERT(pAnnotHandlerMgr);
1050                 return pAnnotHandlerMgr->Annot_OnMouseWheel(this, pAnnot, nFlag, (int)deltaY, point);
1051         }
1052         return FALSE;
1053
1054 }
1055
1056 FX_BOOL CPDFSDK_PageView::OnChar(int nChar, FX_UINT nFlag)
1057 {
1058         if(CPDFSDK_Annot* pAnnot = GetFocusAnnot())
1059         {
1060                 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1061                 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
1062                 ASSERT(pAnnotHandlerMgr);
1063                 return pAnnotHandlerMgr->Annot_OnChar(pAnnot, nChar, nFlag);
1064         }
1065
1066         return FALSE;
1067 }
1068
1069 FX_BOOL CPDFSDK_PageView::OnKeyDown(int nKeyCode, int nFlag)
1070 {
1071         if(CPDFSDK_Annot* pAnnot = GetFocusAnnot())
1072         {
1073                 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1074                 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
1075                 ASSERT(pAnnotHandlerMgr);
1076                 return pAnnotHandlerMgr->Annot_OnKeyDown(pAnnot, nKeyCode, nFlag);
1077         }
1078         return FALSE;
1079 }
1080
1081 FX_BOOL CPDFSDK_PageView::OnKeyUp(int nKeyCode, int nFlag)
1082 {
1083 //      if(CPDFSDK_Annot* pAnnot = GetFocusAnnot())
1084 //      {
1085 //              CFFL_IFormFiller* pIFormFiller = g_pFormFillApp->GetIFormFiller();
1086 //              return pIFormFiller->OnKeyUp(pAnnot, nKeyCode, nFlag);
1087 //      }
1088         return FALSE;
1089 }
1090
1091 extern void CheckUnSupportAnnot(CPDF_Document * pDoc, CPDF_Annot* pPDFAnnot);
1092
1093 void CPDFSDK_PageView::LoadFXAnnots()
1094 {
1095         ASSERT(m_page != NULL);
1096
1097         CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1098         ASSERT(pEnv != NULL);
1099
1100         CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();
1101         ASSERT(pAnnotHandlerMgr != NULL);
1102
1103         SetLock(TRUE);
1104         m_page->AddRef();
1105         if (m_pSDKDoc->GetDocument()->GetDocType() == DOCTYPE_DYNIMIC_XFA)
1106         {
1107                 IXFA_PageView* pageView = NULL;
1108                 pageView = m_page->GetXFAPageView();
1109                 ASSERT(pageView != NULL);
1110
1111                 IXFA_WidgetIterator* pWidgetHander = pageView->CreateWidgetIterator(XFA_TRAVERSEWAY_Form, XFA_WIDGETFILTER_Visible|XFA_WIDGETFILTER_Viewable|XFA_WIDGETFILTER_AllType);
1112                 if (!pWidgetHander)
1113                 {
1114                         m_page->Release();
1115                         SetLock(FALSE);
1116                         return;
1117                 }
1118
1119         IXFA_Widget* pXFAAnnot = pWidgetHander->MoveToNext();
1120                 while (pXFAAnnot) {
1121                         CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pXFAAnnot, this);
1122                         if(!pAnnot) {
1123                                 pXFAAnnot = pWidgetHander->MoveToNext();
1124                                 continue;
1125                         }
1126                         m_fxAnnotArray.Add(pAnnot);
1127
1128                         pAnnotHandlerMgr->Annot_OnLoad(pAnnot);
1129
1130                         pXFAAnnot = pWidgetHander->MoveToNext();
1131
1132                 }
1133
1134                 pWidgetHander->Release();
1135         }
1136         else
1137         {
1138                 CPDF_Page* pPage = m_page->GetPDFPage();
1139                 ASSERT(pPage != NULL);
1140
1141                 FX_BOOL enableAPUpdate = CPDF_InterForm::UpdatingAPEnabled();
1142                 //Disable the default AP construction.
1143                 CPDF_InterForm::EnableUpdateAP(FALSE);
1144                 m_pAnnotList = new CPDF_AnnotList(pPage);
1145                 CPDF_InterForm::EnableUpdateAP(enableAPUpdate);
1146
1147                 int nCount = m_pAnnotList->Count();
1148                 for(int i=0; i<nCount; i++)
1149                 {
1150                         CPDF_Annot* pPDFAnnot = m_pAnnotList->GetAt(i);
1151                         CPDF_Document * pDoc = GetPDFDocument();
1152
1153                         CheckUnSupportAnnot(pDoc, pPDFAnnot);
1154
1155                         CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pPDFAnnot, this);
1156                         if(!pAnnot)
1157                                 continue;
1158                         m_fxAnnotArray.Add(pAnnot);
1159
1160                         pAnnotHandlerMgr->Annot_OnLoad(pAnnot);
1161                 }
1162
1163         }
1164         m_page->Release();
1165         SetLock(FALSE);
1166 }
1167
1168 void    CPDFSDK_PageView::UpdateRects(CFX_RectArray& rects)
1169 {
1170         for(int i=0; i<rects.GetSize(); i++)
1171         {
1172                 CPDF_Rect rc = rects.GetAt(i);
1173                 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1174                 pEnv->FFI_Invalidate(m_page, rc.left, rc.top, rc.right, rc.bottom);
1175         }
1176 }
1177
1178 void CPDFSDK_PageView::UpdateView(CPDFSDK_Annot* pAnnot)
1179 {
1180     CPDF_Rect rcWindow = pAnnot->GetRect();
1181     CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();
1182     pEnv->FFI_Invalidate(
1183         m_page, rcWindow.left, rcWindow.top, rcWindow.right, rcWindow.bottom);
1184 }
1185
1186 int CPDFSDK_PageView::GetPageIndex()
1187 {
1188         if(m_page)
1189         {
1190                 CPDF_Dictionary* pDic = m_page->GetPDFPage()->m_pFormDict;
1191                 CPDFXFA_Document* pDoc = m_pSDKDoc->GetDocument();
1192                 if(pDoc && pDic)
1193                 {
1194                         return pDoc->GetPDFDoc()->GetPageIndex(pDic->GetObjNum());
1195                 }
1196         }
1197         return -1;
1198 }
1199
1200 FX_BOOL CPDFSDK_PageView::IsValidAnnot(void* p)
1201 {
1202         if (p == NULL) return FALSE;
1203         int iCount = m_pAnnotList->Count();
1204         for (int i = 0; i < iCount; i++)
1205         {
1206                 if (m_pAnnotList->GetAt(i) == p)
1207                         return TRUE;
1208         }
1209         return FALSE;
1210 }
1211
1212
1213 CPDFSDK_Annot* CPDFSDK_PageView::GetFocusAnnot()
1214 {
1215         CPDFSDK_Annot* pFocusAnnot = m_pSDKDoc->GetFocusAnnot();
1216         if(!pFocusAnnot)
1217                 return NULL;
1218
1219         for(int i=0; i<m_fxAnnotArray.GetSize(); i++)
1220         {
1221                 CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i);
1222                 if(pAnnot == pFocusAnnot)
1223                         return pAnnot;
1224         }
1225         return NULL;
1226 }
1227