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