9a11927fab735f1dd85b5e248706ed379283fed5
[pdfium.git] / fpdfsdk / src / fsdk_mgr.cpp
1 // Copyright 2014 PDFium Authors. All rights reserved.\r
2 // Use of this source code is governed by a BSD-style license that can be\r
3 // found in the LICENSE file.\r
4  \r
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com\r
6 \r
7 #include "../include/fsdk_define.h"\r
8 #include "../include/fsdk_mgr.h"\r
9 #include "../include/fpdf_ext.h"\r
10 #include "../include/formfiller/FFL_FormFiller.h"\r
11 #include "../include/javascript/IJavaScript.h"\r
12 \r
13 #if _FX_OS_ == _FX_ANDROID_\r
14 #include "time.h"\r
15 #else\r
16 #include <ctime>\r
17 #endif\r
18 \r
19 //extern CPDFDoc_Environment* g_pFormFillApp;\r
20 class CFX_SystemHandler:public IFX_SystemHandler\r
21 {\r
22 public:\r
23         CFX_SystemHandler(CPDFDoc_Environment* pEnv):m_pEnv(pEnv),m_nCharSet(-1) {}\r
24 public:\r
25         virtual void                            InvalidateRect(FX_HWND hWnd, FX_RECT rect) ;\r
26         virtual void                            OutputSelectedRect(void* pFormFiller, CPDF_Rect& rect);\r
27 \r
28         virtual FX_BOOL                         IsSelectionImplemented();\r
29 \r
30         virtual CFX_WideString          GetClipboardText(FX_HWND hWnd){return L"";}\r
31         virtual FX_BOOL                         SetClipboardText(FX_HWND hWnd, CFX_WideString string) {return FALSE;}\r
32         \r
33         virtual void                            ClientToScreen(FX_HWND hWnd, FX_INT32& x, FX_INT32& y) {}\r
34         virtual void                            ScreenToClient(FX_HWND hWnd, FX_INT32& x, FX_INT32& y) {}\r
35 \r
36         /*cursor style\r
37         FXCT_ARROW      \r
38         FXCT_NESW               \r
39         FXCT_NWSE               \r
40         FXCT_VBEAM              \r
41         FXCT_HBEAM              \r
42         FXCT_HAND\r
43         */\r
44         virtual void                            SetCursor(FX_INT32 nCursorType);\r
45 \r
46         virtual FX_HMENU                        CreatePopupMenu() {return NULL;}\r
47         virtual FX_BOOL                         AppendMenuItem(FX_HMENU hMenu, FX_INT32 nIDNewItem, CFX_WideString string) {return FALSE;}\r
48         virtual FX_BOOL                         EnableMenuItem(FX_HMENU hMenu, FX_INT32 nIDItem, FX_BOOL bEnabled) {return FALSE;}\r
49         virtual FX_INT32                        TrackPopupMenu(FX_HMENU hMenu, FX_INT32 x, FX_INT32 y, FX_HWND hParent) {return -1;}\r
50         virtual void                            DestroyMenu(FX_HMENU hMenu) {}\r
51 \r
52         virtual CFX_ByteString          GetNativeTrueTypeFont(FX_INT32 nCharset);\r
53         virtual FX_BOOL                         FindNativeTrueTypeFont(FX_INT32 nCharset, CFX_ByteString sFontFaceName);\r
54         virtual CPDF_Font*                      AddNativeTrueTypeFontToPDF(CPDF_Document* pDoc, CFX_ByteString sFontFaceName, FX_BYTE nCharset);\r
55 \r
56         virtual FX_INT32                        SetTimer(FX_INT32 uElapse, TimerCallback lpTimerFunc) ;\r
57         virtual void                            KillTimer(FX_INT32 nID) ;\r
58 \r
59 \r
60         virtual FX_BOOL                         IsSHIFTKeyDown(FX_DWORD nFlag) {return m_pEnv->FFI_IsSHIFTKeyDown(nFlag);}\r
61         virtual FX_BOOL                         IsCTRLKeyDown(FX_DWORD nFlag) {return m_pEnv->FFI_IsCTRLKeyDown(nFlag);}\r
62         virtual FX_BOOL                         IsALTKeyDown(FX_DWORD nFlag) {return m_pEnv->FFI_IsALTKeyDown(nFlag);}\r
63         virtual FX_BOOL                         IsINSERTKeyDown(FX_DWORD nFlag) {return m_pEnv->FFI_IsINSERTKeyDown(nFlag);}\r
64 \r
65         virtual FX_SYSTEMTIME           GetLocalTime();\r
66 \r
67         virtual FX_INT32                        GetCharSet() {return m_nCharSet;}\r
68         virtual void                            SetCharSet(FX_INT32 nCharSet) {m_nCharSet = nCharSet;}\r
69 private:\r
70         CPDFDoc_Environment* m_pEnv;\r
71         int             m_nCharSet;\r
72 };\r
73 \r
74 void CFX_SystemHandler::SetCursor(FX_INT32 nCursorType)\r
75 {\r
76 \r
77         m_pEnv->FFI_SetCursor(nCursorType);\r
78 }\r
79 \r
80 void CFX_SystemHandler::InvalidateRect(FX_HWND hWnd, FX_RECT rect)\r
81 {\r
82         //g_pFormFillApp->FFI_Invalidate();\r
83         CPDFSDK_Annot* pSDKAnnot = (CPDFSDK_Annot*)hWnd;\r
84         CPDF_Page* pPage = NULL;\r
85         CPDFSDK_PageView* pPageView = NULL;\r
86         pPageView = pSDKAnnot->GetPageView();\r
87         pPage = pSDKAnnot->GetPDFPage();\r
88         if(!pPage || !pPageView)\r
89                 return;\r
90         CPDF_Matrix page2device;\r
91         pPageView->GetCurrentMatrix(page2device);\r
92         CPDF_Matrix device2page;\r
93         device2page.SetReverse(page2device);\r
94         FX_FLOAT left, top, right,bottom;\r
95         device2page.Transform((FX_FLOAT)rect.left, (FX_FLOAT)rect.top, left, top);\r
96         device2page.Transform((FX_FLOAT)rect.right, (FX_FLOAT)rect.bottom, right, bottom);\r
97 //      m_pEnv->FFI_DeviceToPage(pPage, rect.left, rect.top, (double*)&left, (double*)&top);\r
98 //      m_pEnv->FFI_DeviceToPage(pPage, rect.right, rect.bottom, (double*)&right, (double*)&bottom);\r
99         CPDF_Rect rcPDF(left, bottom, right, top);\r
100         rcPDF.Normalize();\r
101 \r
102         m_pEnv->FFI_Invalidate(pPage, rcPDF.left, rcPDF.top, rcPDF.right, rcPDF.bottom);\r
103 }\r
104 void CFX_SystemHandler::OutputSelectedRect(void* pFormFiller, CPDF_Rect& rect)\r
105 {\r
106         CFFL_FormFiller* pFFL = (CFFL_FormFiller*)pFormFiller;\r
107         if(pFFL)\r
108         {\r
109                 CPDF_Point leftbottom = CPDF_Point(rect.left, rect.bottom);\r
110                 CPDF_Point righttop = CPDF_Point(rect.right, rect.top);\r
111                 CPDF_Point ptA = pFFL->PWLtoFFL(leftbottom);\r
112                 CPDF_Point ptB = pFFL->PWLtoFFL(righttop);      \r
113 \r
114 \r
115                 CPDFSDK_Annot* pAnnot  = pFFL->GetSDKAnnot();\r
116                 ASSERT(pAnnot);\r
117                 CPDF_Page* pPage = pAnnot->GetPDFPage();\r
118                 ASSERT(pPage);\r
119                 m_pEnv->FFI_OutputSelectedRect(pPage, ptA.x, ptB.y, ptB.x, ptA.y);\r
120         }\r
121         \r
122 }\r
123 \r
124 FX_BOOL CFX_SystemHandler::IsSelectionImplemented()\r
125 {\r
126         if(m_pEnv)\r
127         {\r
128                 FPDF_FORMFILLINFO* pInfo = m_pEnv->GetFormFillInfo();\r
129                 if(pInfo && pInfo->FFI_OutputSelectedRect)\r
130                         return TRUE;\r
131         }\r
132         return FALSE;\r
133 }\r
134 \r
135 CFX_ByteString CFX_SystemHandler::GetNativeTrueTypeFont(FX_INT32 nCharset)\r
136 {\r
137         return "";\r
138 }\r
139 \r
140 FX_BOOL CFX_SystemHandler::FindNativeTrueTypeFont(FX_INT32 nCharset, CFX_ByteString sFontFaceName) \r
141 {\r
142         CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr();\r
143 //      FXFT_Face nFace = pFontMgr->FindSubstFont(sFontFaceName,TRUE,0,0,0,0,NULL);\r
144 //      FXFT_Face nFace  = pFontMgr->m_pBuiltinMapper->FindSubstFont(sFontFaceName,TRUE,0,0,0,0,NULL);\r
145 \r
146         if(pFontMgr)\r
147         {\r
148                 CFX_FontMapper* pFontMapper = pFontMgr->m_pBuiltinMapper;\r
149                 if(pFontMapper)\r
150                 {       \r
151                         int nSize = pFontMapper->m_InstalledTTFonts.GetSize();\r
152                         if(nSize ==0)\r
153                         {\r
154                                 pFontMapper->LoadInstalledFonts();\r
155                                 nSize = pFontMapper->m_InstalledTTFonts.GetSize();\r
156                         }\r
157                         \r
158                         for(int i=0; i<nSize; i++)\r
159                         {\r
160                                 if(pFontMapper->m_InstalledTTFonts[i].Compare(sFontFaceName))\r
161                                         return TRUE;\r
162                         }\r
163                 }\r
164 \r
165         }\r
166 \r
167         return FALSE;\r
168 //      pFontMgr->m_FaceMap.Lookup(sFontFaceName,pFont);\r
169 //      return (pFont!=NULL);\r
170 }\r
171 \r
172 static int CharSet2CP(int charset)\r
173 {\r
174         if(charset == 128)\r
175                 return 932;\r
176         else if(charset == 134)\r
177                 return 936;\r
178         else if(charset == 129)\r
179                 return 949;\r
180         else if(charset == 136)\r
181                 return 950;\r
182         return 0;\r
183 }\r
184 CPDF_Font* CFX_SystemHandler::AddNativeTrueTypeFontToPDF(CPDF_Document* pDoc, CFX_ByteString sFontFaceName, \r
185                                                                                                                  FX_BYTE nCharset) \r
186 {\r
187         if(pDoc)\r
188         {\r
189                 CFX_Font* pFXFont = new CFX_Font();\r
190                 pFXFont->LoadSubst(sFontFaceName,TRUE,0,0,0,CharSet2CP(nCharset),FALSE);\r
191                 CPDF_Font* pFont = pDoc->AddFont(pFXFont,nCharset,FALSE);\r
192                 delete pFXFont;\r
193                 return pFont;\r
194         }\r
195 \r
196         return NULL;\r
197 }\r
198 \r
199 \r
200 FX_INT32 CFX_SystemHandler::SetTimer(FX_INT32 uElapse, TimerCallback lpTimerFunc)\r
201 {\r
202         return m_pEnv->FFI_SetTimer(uElapse, lpTimerFunc);\r
203 }\r
204 void CFX_SystemHandler::KillTimer(FX_INT32 nID)\r
205 {\r
206         m_pEnv->FFI_KillTimer(nID);\r
207 }\r
208 \r
209 FX_SYSTEMTIME CFX_SystemHandler::GetLocalTime()\r
210 {\r
211         return m_pEnv->FFI_GetLocalTime();\r
212 }\r
213 \r
214 \r
215 CJS_RuntimeFactory* GetJSRuntimeFactory()\r
216 {\r
217         static CJS_RuntimeFactory s_JSRuntimeFactory;\r
218         return &s_JSRuntimeFactory;\r
219 }\r
220 \r
221 CPDFDoc_Environment::CPDFDoc_Environment(CPDF_Document * pDoc):m_pInfo(NULL),m_pIFormFiller(NULL),\r
222                                                                 m_pAnnotHandlerMgr(NULL),m_pActionHandler(NULL),m_pJSRuntime(NULL),\r
223                                                                 m_pSDKDoc(NULL), m_pPDFDoc(pDoc)\r
224 {\r
225 \r
226         m_pSysHandler = NULL;\r
227         m_pSysHandler = new CFX_SystemHandler(this);\r
228 \r
229         \r
230         m_pJSRuntimeFactory = NULL;\r
231         m_pJSRuntimeFactory = GetJSRuntimeFactory();\r
232         m_pJSRuntimeFactory->AddRef();\r
233 }\r
234 \r
235 CPDFDoc_Environment::~CPDFDoc_Environment()\r
236 {\r
237 \r
238         if ( m_pIFormFiller )\r
239         {\r
240                 delete m_pIFormFiller;\r
241                 m_pIFormFiller = NULL;\r
242         }\r
243         if(m_pJSRuntime && m_pJSRuntimeFactory)\r
244                 m_pJSRuntimeFactory->DeleteJSRuntime(m_pJSRuntime);\r
245         m_pJSRuntimeFactory->Release();\r
246 \r
247         if(m_pSysHandler)\r
248         {\r
249                 delete m_pSysHandler;\r
250                 m_pSysHandler = NULL;\r
251         }\r
252 \r
253         if(m_pAnnotHandlerMgr)\r
254         {\r
255                 delete m_pAnnotHandlerMgr;\r
256                 m_pAnnotHandlerMgr = NULL;\r
257         }\r
258         if(m_pActionHandler)\r
259         {\r
260                 delete m_pActionHandler;\r
261                 m_pActionHandler = NULL;\r
262         }\r
263 \r
264 \r
265 }\r
266 \r
267 \r
268 IFXJS_Runtime* CPDFDoc_Environment::GetJSRuntime()\r
269 {\r
270         if(!IsJSInitiated())\r
271                 return NULL;\r
272         assert(m_pJSRuntimeFactory);\r
273         if(!m_pJSRuntime)\r
274                 m_pJSRuntime = m_pJSRuntimeFactory->NewJSRuntime(this);\r
275         return m_pJSRuntime;\r
276 }\r
277 \r
278 CPDFSDK_AnnotHandlerMgr* CPDFDoc_Environment::GetAnnotHandlerMgr()\r
279 {\r
280         if(!m_pAnnotHandlerMgr)\r
281                 m_pAnnotHandlerMgr = new CPDFSDK_AnnotHandlerMgr(this);\r
282         return m_pAnnotHandlerMgr;\r
283 }\r
284 \r
285 CPDFSDK_ActionHandler* CPDFDoc_Environment::GetActionHander()\r
286 {\r
287         if(!m_pActionHandler)\r
288                 m_pActionHandler = new CPDFSDK_ActionHandler(this);\r
289         return m_pActionHandler;\r
290 }\r
291 \r
292 int CPDFDoc_Environment::RegAppHandle(FPDF_FORMFILLINFO* pFFinfo)\r
293 {\r
294         m_pInfo  = pFFinfo; \r
295         return TRUE;\r
296 }\r
297 \r
298 CPDFSDK_Document* CPDFDoc_Environment::GetCurrentDoc()\r
299 {\r
300         return m_pSDKDoc;\r
301 }\r
302 \r
303 CFFL_IFormFiller* CPDFDoc_Environment::GetIFormFiller()\r
304 {\r
305         if(!m_pIFormFiller)\r
306                 m_pIFormFiller = new CFFL_IFormFiller(this);\r
307         return m_pIFormFiller;\r
308 }\r
309 \r
310 FX_BOOL CPDFDoc_Environment::IsJSInitiated()\r
311 {\r
312         if(m_pInfo)\r
313         {\r
314                 if(m_pInfo->m_pJsPlatform)\r
315                         return TRUE;\r
316                 else\r
317                         return FALSE;\r
318         }\r
319         return FALSE;\r
320 }\r
321 \r
322 CPDFSDK_Document::CPDFSDK_Document(CPDF_Document* pDoc,CPDFDoc_Environment* pEnv):m_pDoc(pDoc),\r
323                                                 m_pInterForm(NULL),m_pEnv(pEnv),m_pOccontent(NULL),m_bChangeMask(FALSE)\r
324 {\r
325         m_pFocusAnnot = NULL;\r
326 }\r
327 \r
328 CPDFSDK_Document::~CPDFSDK_Document()\r
329 {\r
330         m_pageMap.RemoveAll();\r
331         if(m_pInterForm)\r
332         {\r
333                 m_pInterForm->Destroy();\r
334                 m_pInterForm = NULL;\r
335         }\r
336         if(m_pOccontent)\r
337         {\r
338                 delete m_pOccontent;\r
339                 m_pOccontent = NULL;\r
340         }\r
341 }\r
342 \r
343 void CPDFSDK_Document::InitPageView()\r
344 {\r
345         int nCount = m_pDoc->GetPageCount();\r
346         for(int i=0; i<nCount; i++)\r
347         {\r
348         // To do\r
349 //              CPDF_Dictionary* pDic = m_pDoc->GetPage(i);\r
350 //              m_pageMap.SetAt(pDic, pPageView);\r
351         }\r
352 }\r
353 \r
354 void CPDFSDK_Document::AddPageView(CPDF_Page* pPDFPage, CPDFSDK_PageView* pPageView)\r
355 {\r
356         m_pageMap.SetAt(pPDFPage, pPageView);\r
357 }\r
358 \r
359 CPDFSDK_PageView* CPDFSDK_Document::GetPageView(CPDF_Page* pPDFPage, FX_BOOL ReNew)\r
360 {\r
361         CPDFSDK_PageView* pPageView = (CPDFSDK_PageView*)m_pageMap.GetValueAt(pPDFPage);\r
362         if(pPageView != NULL)\r
363                 return pPageView;\r
364         if(ReNew)\r
365         {\r
366                 pPageView = new CPDFSDK_PageView(this,pPDFPage);\r
367                 m_pageMap.SetAt(pPDFPage, pPageView);\r
368                 //Delay to load all the annotations, to avoid endless loop.\r
369                 pPageView->LoadFXAnnots();\r
370         }\r
371         return pPageView;\r
372 \r
373 }\r
374 \r
375 CPDFSDK_PageView* CPDFSDK_Document::GetCurrentView()\r
376 {\r
377         CPDF_Page * pPage = (CPDF_Page *)m_pEnv->FFI_GetCurrentPage(m_pDoc);\r
378         if(pPage)\r
379                 return this->GetPageView(pPage, TRUE);\r
380         return NULL;\r
381 }\r
382 \r
383 CPDFSDK_PageView* CPDFSDK_Document::GetPageView(int nIndex)\r
384 {\r
385         CPDFSDK_PageView * pTempPageView = NULL;\r
386         CPDF_Page * pTempPage = (CPDF_Page*)m_pEnv->FFI_GetPage(m_pDoc,nIndex);\r
387         if(!pTempPage)\r
388                 return NULL;\r
389 \r
390         m_pageMap.Lookup(pTempPage, pTempPageView);\r
391         \r
392         ASSERT(pTempPageView != NULL);\r
393         \r
394         return pTempPageView;\r
395 }\r
396 \r
397 void CPDFSDK_Document:: ProcJavascriptFun()\r
398 {\r
399         CPDF_Document* pPDFDoc = this->GetDocument();\r
400         CPDF_DocJSActions docJS(pPDFDoc);\r
401         int iCount = docJS.CountJSActions();\r
402         if (iCount < 1) return;\r
403         for (int i = 0; i < iCount; i ++)\r
404         {\r
405                 CFX_ByteString csJSName;\r
406                 CPDF_Action jsAction = docJS.GetJSAction(i, csJSName);\r
407                 if(m_pEnv->GetActionHander())\r
408                         m_pEnv->GetActionHander()->DoAction_JavaScript(jsAction,CFX_WideString::FromLocal(csJSName),this);\r
409         }\r
410         \r
411 }\r
412 \r
413 FX_BOOL CPDFSDK_Document::ProcOpenAction()\r
414 {\r
415         if(!m_pDoc) return FALSE;\r
416         \r
417         CPDF_Dictionary* pRoot = m_pDoc->GetRoot();     \r
418         if (!pRoot)     return FALSE;\r
419         CPDF_Object* pOpenAction = pRoot->GetDict("OpenAction");//\r
420         if(!pOpenAction) pOpenAction = pRoot->GetArray("OpenAction");//\r
421         if(!pOpenAction) return FALSE;\r
422         \r
423         if(pOpenAction->GetType()==PDFOBJ_ARRAY)\r
424         {       \r
425         }\r
426         else if(pOpenAction->GetType()==PDFOBJ_DICTIONARY)\r
427         {       \r
428                 CPDF_Dictionary * pDict=(CPDF_Dictionary*)pOpenAction;  \r
429                 CPDF_Action Action = pDict;\r
430                 \r
431                 if(m_pEnv->GetActionHander())\r
432                         m_pEnv->GetActionHander()->DoAction_DocOpen(Action,this);               \r
433         }       \r
434         else\r
435         {\r
436                 return FALSE;                   \r
437         }       \r
438         return TRUE;\r
439 }\r
440 \r
441 CPDF_OCContext* CPDFSDK_Document::GetOCContext()\r
442 {\r
443         if(!m_pOccontent)\r
444                 m_pOccontent = new CPDF_OCContext(m_pDoc);\r
445         return m_pOccontent;\r
446 }\r
447 \r
448 void CPDFSDK_Document::ReMovePageView(CPDF_Page* pPDFPage)\r
449 {\r
450         CPDFSDK_PageView* pPageView = (CPDFSDK_PageView*)m_pageMap.GetValueAt(pPDFPage);\r
451         if(pPageView)\r
452         {\r
453                 delete pPageView;\r
454                 m_pageMap.RemoveKey(pPDFPage);\r
455         }\r
456 }\r
457 \r
458 CPDF_Page * CPDFSDK_Document::GetPage(int nIndex)\r
459 {\r
460         CPDF_Page * pTempPage = (CPDF_Page*)m_pEnv->FFI_GetPage(m_pDoc,nIndex);\r
461         if(!pTempPage)\r
462                 return NULL;\r
463         return pTempPage;\r
464 }\r
465 \r
466 CPDFSDK_InterForm* CPDFSDK_Document::GetInterForm()\r
467 {\r
468         if(!m_pInterForm)\r
469                 m_pInterForm = new CPDFSDK_InterForm(this);\r
470         return m_pInterForm;\r
471 }\r
472 \r
473 void CPDFSDK_Document::UpdateAllViews(CPDFSDK_PageView* pSender, CPDFSDK_Annot* pAnnot)\r
474 {\r
475         \r
476         FX_POSITION pos = m_pageMap.GetStartPosition();\r
477         CPDF_Page * pPage = NULL;\r
478         CPDFSDK_PageView * pPageView = NULL;\r
479         while(pos)\r
480         {\r
481                 m_pageMap.GetNextAssoc(pos, pPage, pPageView);\r
482 \r
483                 if(pPageView != pSender)\r
484                 {\r
485                         pPageView->UpdateView(pAnnot);\r
486                 }\r
487         }\r
488 }\r
489 \r
490 CPDFSDK_Annot* CPDFSDK_Document::GetFocusAnnot()\r
491 {\r
492         return this->m_pFocusAnnot;     \r
493 }\r
494 \r
495 FX_BOOL CPDFSDK_Document::SetFocusAnnot(CPDFSDK_Annot* pAnnot,FX_UINT nFlag)\r
496 {\r
497 \r
498         if(m_pFocusAnnot==pAnnot) return TRUE;\r
499         \r
500         if(m_pFocusAnnot)\r
501         {\r
502                 if(!this->KillFocusAnnot(nFlag) ) return FALSE; \r
503         }\r
504         CPDFSDK_PageView* pPageView = pAnnot->GetPageView();\r
505         if(pAnnot && pPageView->IsValid())\r
506         {\r
507                 CPDFSDK_AnnotHandlerMgr *pAnnotHandler=m_pEnv->GetAnnotHandlerMgr();\r
508 \r
509                 if(pAnnotHandler&&!m_pFocusAnnot)\r
510                 {\r
511                         if (!pAnnotHandler->Annot_OnSetFocus(pAnnot,nFlag))\r
512                                 return FALSE;\r
513                         if(!m_pFocusAnnot)\r
514                         {\r
515                                 this->m_pFocusAnnot=pAnnot;\r
516                                 return TRUE;\r
517                         }\r
518                 }                       \r
519         }\r
520         return FALSE;\r
521 }\r
522 \r
523 FX_BOOL CPDFSDK_Document::KillFocusAnnot(FX_UINT nFlag)\r
524 {\r
525         if(m_pFocusAnnot)\r
526         {\r
527                 CPDFSDK_AnnotHandlerMgr *pAnnotHandler=m_pEnv->GetAnnotHandlerMgr();\r
528                 if(pAnnotHandler)\r
529                 {\r
530                         CPDFSDK_Annot* pFocusAnnot = m_pFocusAnnot;\r
531                         m_pFocusAnnot = NULL;\r
532                         if(pAnnotHandler->Annot_OnKillFocus(pFocusAnnot, nFlag))\r
533                         {\r
534                                 \r
535                                 if(pFocusAnnot->GetType() == FX_BSTRC("Widget"))\r
536                                 {\r
537                                         CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pFocusAnnot;\r
538                                         int nFieldType = pWidget->GetFieldType();\r
539                                         if(FIELDTYPE_TEXTFIELD == nFieldType || FIELDTYPE_COMBOBOX == nFieldType)\r
540                                                 m_pEnv->FFI_OnSetFieldInputFocus(NULL, NULL, 0, FALSE);\r
541                                 }\r
542 \r
543                                 if(!m_pFocusAnnot)\r
544                                         return TRUE;\r
545                         }\r
546                         else\r
547                         {\r
548                                 m_pFocusAnnot = pFocusAnnot;\r
549                         }\r
550                 }\r
551         }\r
552         return FALSE;\r
553 }\r
554 \r
555 FX_BOOL CPDFSDK_Document::DeletePages(int nStart, int  nCount)\r
556 {\r
557         if ( nStart < 0 || nStart >= GetPageCount() || nCount <= 0 )\r
558         {\r
559                 return FALSE;\r
560         }\r
561 \r
562         CPDF_Page * pTempPage = NULL;\r
563         for ( int i = nCount-1; i >= 0; i-- )\r
564         {\r
565                 pTempPage = GetPage(nStart+i);\r
566                 if ( pTempPage != NULL )\r
567                 {\r
568                         ReMovePageView(pTempPage);\r
569                 }\r
570         }\r
571         return TRUE;\r
572 }\r
573 \r
574 void CPDFSDK_Document::OnCloseDocument()\r
575 {\r
576         KillFocusAnnot();\r
577 }\r
578 \r
579 FX_BOOL CPDFSDK_Document::GetPermissions(int nFlag)\r
580 {\r
581         FX_DWORD dwPermissions = m_pDoc->GetUserPermissions();\r
582         return dwPermissions&nFlag;\r
583 }\r
584 \r
585 IFXJS_Runtime * CPDFSDK_Document::GetJsRuntime()\r
586 {\r
587         ASSERT(m_pEnv!=NULL);\r
588         return m_pEnv->GetJSRuntime();\r
589 }\r
590 \r
591 CFX_WideString  CPDFSDK_Document::GetPath() \r
592 {\r
593         ASSERT(m_pEnv != NULL);\r
594         return m_pEnv->JS_docGetFilePath();\r
595 }\r
596 \r
597 \r
598 CPDFSDK_PageView::CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc,CPDF_Page* page):m_pSDKDoc(pSDKDoc),m_page(page)\r
599 {\r
600         CPDFSDK_InterForm* pInterForm = pSDKDoc->GetInterForm();\r
601         if(pInterForm)\r
602         {\r
603                 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm();\r
604                 pPDFInterForm->FixPageFields(page);\r
605         }\r
606 \r
607         m_fxAnnotArray.RemoveAll();\r
608 \r
609         m_bEnterWidget = FALSE;\r
610         m_bExitWidget = FALSE;\r
611         m_bOnWidget = FALSE;\r
612         m_CaptureWidget = NULL;\r
613         m_bValid = FALSE;\r
614 }\r
615 \r
616 CPDFSDK_PageView::~CPDFSDK_PageView()\r
617 {\r
618         CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();        \r
619         int nAnnotCount = m_fxAnnotArray.GetSize();\r
620         for (int i=0; i<nAnnotCount; i++)\r
621         {\r
622                 CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i);\r
623                 //if there is a focused annot on the page, we should kill the focus first.\r
624                 if(pAnnot == m_pSDKDoc->GetFocusAnnot())\r
625                         KillFocusAnnot();\r
626                 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();\r
627                 ASSERT(pAnnotHandlerMgr);\r
628                 pAnnotHandlerMgr->ReleaseAnnot(pAnnot);\r
629         }\r
630         m_fxAnnotArray.RemoveAll();\r
631         if(m_pAnnotList)\r
632         {\r
633                 delete m_pAnnotList;\r
634                 m_pAnnotList = NULL;\r
635         }\r
636 }\r
637 \r
638 void CPDFSDK_PageView::PageView_OnDraw(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,CPDF_RenderOptions* pOptions)\r
639 {\r
640         m_curMatrix = *pUser2Device;\r
641         \r
642         //      m_pAnnotList->DisplayAnnots(m_page, pDevice, pUser2Device, FALSE, pOptions);\r
643         CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();\r
644         CPDFSDK_AnnotIterator annotIterator(this, TRUE);\r
645         CPDFSDK_Annot * pSDKAnnot=NULL;\r
646         int index=-1;\r
647         while((pSDKAnnot = annotIterator.Next(index)))\r
648         {\r
649                 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();\r
650                 ASSERT(pAnnotHandlerMgr);\r
651                 pAnnotHandlerMgr->Annot_OnDraw(this, pSDKAnnot, pDevice, pUser2Device, 0);\r
652         }\r
653 \r
654 }\r
655 \r
656 CPDF_Annot* CPDFSDK_PageView::GetPDFAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY)\r
657 {\r
658         \r
659         int nCount = m_pAnnotList->Count();\r
660         for(int i = 0 ; i<nCount; i++)\r
661         {\r
662                 CPDF_Annot* pAnnot = m_pAnnotList->GetAt(i);\r
663                 CFX_FloatRect annotRect;\r
664                 pAnnot->GetRect(annotRect);\r
665                 if(annotRect.Contains(pageX, pageY))\r
666                         return pAnnot;\r
667         }\r
668         return NULL;\r
669 }\r
670 \r
671 CPDF_Annot* CPDFSDK_PageView::GetPDFWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY)\r
672 {\r
673         \r
674         int nCount = m_pAnnotList->Count();\r
675         for(int i = 0 ; i<nCount; i++)\r
676         {\r
677                 CPDF_Annot* pAnnot = m_pAnnotList->GetAt(i);\r
678                 if(pAnnot->GetSubType() == "Widget")\r
679                 {\r
680                         CFX_FloatRect annotRect;\r
681                         pAnnot->GetRect(annotRect);\r
682                         if(annotRect.Contains(pageX, pageY))\r
683                                 return pAnnot;\r
684                 }\r
685         }\r
686         return NULL;\r
687 }\r
688 \r
689 CPDFSDK_Annot* CPDFSDK_PageView::GetFXAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY)\r
690 {\r
691 \r
692         CPDFSDK_AnnotIterator annotIterator(this, FALSE);\r
693         CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();\r
694         CPDFSDK_AnnotHandlerMgr* pAnnotMgr = pEnv->GetAnnotHandlerMgr();\r
695         CPDFSDK_Annot* pSDKAnnot = NULL;\r
696         int index = -1;\r
697         while((pSDKAnnot = annotIterator.Next(index)))\r
698         {\r
699                 CPDF_Rect rc = pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot);\r
700                 if(rc.Contains(pageX, pageY))\r
701                         return pSDKAnnot;\r
702         }\r
703 \r
704         return NULL;\r
705 }\r
706 \r
707 CPDFSDK_Annot* CPDFSDK_PageView::GetFXWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY)\r
708 {\r
709 \r
710         CPDFSDK_AnnotIterator annotIterator(this, FALSE);\r
711         CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();\r
712         CPDFSDK_AnnotHandlerMgr* pAnnotMgr = pEnv->GetAnnotHandlerMgr();\r
713         CPDFSDK_Annot* pSDKAnnot = NULL;\r
714         int index = -1;\r
715         while((pSDKAnnot = annotIterator.Next(index)))\r
716         {\r
717                 if(pSDKAnnot->GetType() == "Widget")\r
718                 {       \r
719                         pAnnotMgr->Annot_OnGetViewBBox(this, pSDKAnnot);\r
720                         CPDF_Point point(pageX, pageY);\r
721                         if (pAnnotMgr->Annot_OnHitTest(this, pSDKAnnot, point))\r
722 //                      if(rc.Contains(pageX, pageY))\r
723                                 return pSDKAnnot;\r
724                 }\r
725         }\r
726         \r
727         return NULL;\r
728 }\r
729 \r
730 \r
731 FX_BOOL CPDFSDK_PageView::Annot_HasAppearance(CPDF_Annot* pAnnot)\r
732 {\r
733         CPDF_Dictionary* pAnnotDic = pAnnot->m_pAnnotDict;\r
734         if(pAnnotDic)\r
735                 return  pAnnotDic->KeyExist("AS");\r
736         return FALSE;\r
737 }\r
738 \r
739 CPDFSDK_Annot*  CPDFSDK_PageView::AddAnnot(CPDF_Annot * pPDFAnnot)\r
740 {\r
741         CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();\r
742         ASSERT(pEnv);\r
743         CPDFSDK_AnnotHandlerMgr * pAnnotHandler= pEnv->GetAnnotHandlerMgr();    \r
744         \r
745         CPDFSDK_Annot* pSDKAnnot =NULL;\r
746         \r
747         if(pAnnotHandler)\r
748         {\r
749                 pSDKAnnot = pAnnotHandler->NewAnnot(pPDFAnnot, this);\r
750         }\r
751         if(!pSDKAnnot)   \r
752                 return NULL;\r
753 \r
754         m_fxAnnotArray.Add(pSDKAnnot);  \r
755                 \r
756         if(pAnnotHandler)\r
757         {                                \r
758                 pAnnotHandler->Annot_OnCreate(pSDKAnnot);\r
759                 \r
760         }\r
761 \r
762          return pSDKAnnot;\r
763 }\r
764 \r
765 CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(CPDF_Dictionary * pDict)\r
766 {\r
767         if(pDict)  \r
768                 return this->AddAnnot(pDict->GetString("Subtype"),pDict);\r
769          return NULL;\r
770 }\r
771 \r
772 CPDFSDK_Annot* CPDFSDK_PageView::AddAnnot(FX_LPCSTR lpSubType,CPDF_Dictionary * pDict)\r
773 {\r
774         return NULL;\r
775 }\r
776 \r
777 FX_BOOL  CPDFSDK_PageView::DeleteAnnot(CPDFSDK_Annot* pAnnot)\r
778 {\r
779         return FALSE;\r
780 }\r
781 \r
782 CPDF_Document* CPDFSDK_PageView::GetPDFDocument()\r
783 {\r
784         if(m_page)\r
785         {\r
786                 return m_page->m_pDocument;\r
787         }\r
788         return NULL;\r
789 }\r
790 \r
791 int     CPDFSDK_PageView::CountAnnots()\r
792 {\r
793         return m_pAnnotList->Count();\r
794 }\r
795 \r
796 CPDFSDK_Annot*  CPDFSDK_PageView::GetAnnot(int nIndex)\r
797 {\r
798         int nCount = m_fxAnnotArray.GetSize();\r
799         if ( nIndex < 0 || nIndex >= nCount )\r
800         {\r
801                 return NULL;\r
802         }\r
803 \r
804         return (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(nIndex);\r
805 }\r
806 \r
807 CPDFSDK_Annot* CPDFSDK_PageView::GetAnnotByDict(CPDF_Dictionary * pDict)\r
808 {\r
809         int nCount = m_fxAnnotArray.GetSize();\r
810         for(int i=0; i<nCount; i++)\r
811         {\r
812                 CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i);\r
813                 if(pDict==pAnnot->GetPDFAnnot()->m_pAnnotDict) \r
814                         return pAnnot;\r
815         }\r
816         return NULL;\r
817 }\r
818 \r
819 FX_BOOL CPDFSDK_PageView::OnLButtonDown(const CPDF_Point & point, FX_UINT nFlag)\r
820 {\r
821         CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();\r
822         ASSERT(pEnv);\r
823         CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y);\r
824         if(!pFXAnnot)\r
825         {\r
826                 KillFocusAnnot(nFlag);\r
827         }\r
828         else\r
829         {\r
830                 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();\r
831                 ASSERT(pAnnotHandlerMgr);\r
832 \r
833                 FX_BOOL bRet = pAnnotHandlerMgr->Annot_OnLButtonDown(this, pFXAnnot, nFlag,point);\r
834                 if(bRet)\r
835                 {\r
836                         SetFocusAnnot(pFXAnnot);\r
837                 }\r
838                 return bRet;\r
839         }\r
840         return FALSE;\r
841 }\r
842 \r
843 \r
844 FX_BOOL CPDFSDK_PageView::OnLButtonUp(const CPDF_Point & point, FX_UINT nFlag)\r
845 {\r
846         CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();\r
847         ASSERT(pEnv);\r
848         CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();\r
849         ASSERT(pAnnotHandlerMgr);\r
850         CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y);\r
851         CPDFSDK_Annot* pFocusAnnot = GetFocusAnnot();\r
852         FX_BOOL bRet  = FALSE;\r
853         if(pFocusAnnot && pFocusAnnot != pFXAnnot)\r
854         {\r
855                 //Last focus Annot gets a chance to handle the event.\r
856                 bRet = pAnnotHandlerMgr->Annot_OnLButtonUp(this, pFocusAnnot, nFlag,point);\r
857         }\r
858         if(pFXAnnot && !bRet)\r
859         {\r
860                 bRet = pAnnotHandlerMgr->Annot_OnLButtonUp(this, pFXAnnot, nFlag,point);\r
861                 return bRet;\r
862         }\r
863         return bRet;\r
864 }\r
865 \r
866 FX_BOOL CPDFSDK_PageView::OnMouseMove(const CPDF_Point & point, int nFlag)\r
867 {\r
868 \r
869         CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();\r
870         CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();\r
871         ASSERT(pAnnotHandlerMgr);\r
872         if(CPDFSDK_Annot* pFXAnnot = GetFXWidgetAtPoint(point.x, point.y))\r
873         {\r
874                 if(m_CaptureWidget && m_CaptureWidget != pFXAnnot)\r
875                 {\r
876                         m_bExitWidget = TRUE;\r
877                         m_bEnterWidget = FALSE;\r
878                         pAnnotHandlerMgr->Annot_OnMouseExit(this, m_CaptureWidget, nFlag);\r
879                 }\r
880                 m_CaptureWidget = (CPDFSDK_Widget*)pFXAnnot;\r
881                 m_bOnWidget = TRUE;\r
882                 if(!m_bEnterWidget)\r
883                 {\r
884                         m_bEnterWidget = TRUE;\r
885                         m_bExitWidget = FALSE;\r
886                         pAnnotHandlerMgr->Annot_OnMouseEnter(this, pFXAnnot,nFlag);\r
887                 }\r
888                 pAnnotHandlerMgr->Annot_OnMouseMove(this, pFXAnnot, nFlag, point);\r
889                 return TRUE;\r
890         }\r
891         else\r
892         {\r
893                 if(m_bOnWidget)\r
894                 {       \r
895                         m_bOnWidget = FALSE;\r
896                         m_bExitWidget = TRUE;\r
897                         m_bEnterWidget = FALSE;\r
898                         if(m_CaptureWidget)\r
899                         {\r
900                                 pAnnotHandlerMgr->Annot_OnMouseExit(this, m_CaptureWidget, nFlag);\r
901                                 m_CaptureWidget = NULL;\r
902                         }\r
903                 }\r
904                 return FALSE;\r
905         }\r
906         \r
907         return FALSE;;\r
908 }\r
909 \r
910 FX_BOOL CPDFSDK_PageView::OnMouseWheel(double deltaX, double deltaY,const CPDF_Point& point, int nFlag)\r
911 {\r
912         if(CPDFSDK_Annot* pAnnot = GetFXWidgetAtPoint(point.x, point.y))\r
913         {\r
914                 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();\r
915                 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();\r
916                 ASSERT(pAnnotHandlerMgr);\r
917                 return pAnnotHandlerMgr->Annot_OnMouseWheel(this, pAnnot, nFlag, (int)deltaY, point);\r
918         }\r
919         return FALSE;\r
920 \r
921 }\r
922 \r
923 FX_BOOL CPDFSDK_PageView::OnChar(int nChar, FX_UINT nFlag)\r
924 {\r
925         if(CPDFSDK_Annot* pAnnot = GetFocusAnnot())\r
926         {\r
927                 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();\r
928                 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();\r
929                 ASSERT(pAnnotHandlerMgr);\r
930                 return pAnnotHandlerMgr->Annot_OnChar(pAnnot, nChar, nFlag);\r
931         }\r
932 \r
933         return FALSE;\r
934 }\r
935 \r
936 FX_BOOL CPDFSDK_PageView::OnKeyDown(int nKeyCode, int nFlag)\r
937 {\r
938         if(CPDFSDK_Annot* pAnnot = GetFocusAnnot())\r
939         {\r
940                 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();\r
941                 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();\r
942                 ASSERT(pAnnotHandlerMgr);\r
943                 return pAnnotHandlerMgr->Annot_OnKeyDown(pAnnot, nKeyCode, nFlag);\r
944         }\r
945         return FALSE;\r
946 }\r
947 \r
948 FX_BOOL CPDFSDK_PageView::OnKeyUp(int nKeyCode, int nFlag)\r
949 {\r
950 //      if(CPDFSDK_Annot* pAnnot = GetFocusAnnot())\r
951 //      {\r
952 //              CFFL_IFormFiller* pIFormFiller = g_pFormFillApp->GetIFormFiller();\r
953 //              return pIFormFiller->OnKeyUp(pAnnot, nKeyCode, nFlag);\r
954 //      }\r
955         return FALSE;\r
956 }\r
957 \r
958 extern void CheckUnSupportAnnot(CPDF_Document * pDoc, CPDF_Annot* pPDFAnnot);\r
959 \r
960 void CPDFSDK_PageView::LoadFXAnnots()\r
961 {\r
962         CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();\r
963 \r
964         FX_BOOL enableAPUpdate = CPDF_InterForm::UpdatingAPEnabled();\r
965         //Disable the default AP construction.\r
966         CPDF_InterForm::EnableUpdateAP(FALSE);\r
967         m_pAnnotList = new CPDF_AnnotList(m_page);\r
968         CPDF_InterForm::EnableUpdateAP(enableAPUpdate);\r
969         int nCount = m_pAnnotList->Count();\r
970         for(int i=0; i<nCount; i++)\r
971         {\r
972                 CPDF_Annot* pPDFAnnot = m_pAnnotList->GetAt(i);\r
973                 CPDF_Document * pDoc = this->GetPDFDocument();\r
974                 \r
975                 CheckUnSupportAnnot(pDoc, pPDFAnnot);\r
976 \r
977                 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr();\r
978                 ASSERT(pAnnotHandlerMgr != NULL);\r
979                 if(pAnnotHandlerMgr)\r
980                 {\r
981                         CPDFSDK_Annot* pAnnot = pAnnotHandlerMgr->NewAnnot(pPDFAnnot, this);\r
982                         if(!pAnnot)\r
983                                 continue;\r
984                         m_fxAnnotArray.Add(pAnnot);\r
985 \r
986                         pAnnotHandlerMgr->Annot_OnLoad(pAnnot);\r
987                 }\r
988 \r
989         }\r
990 }\r
991 \r
992 void    CPDFSDK_PageView::UpdateRects(CFX_RectArray& rects)\r
993 {\r
994         for(int i=0; i<rects.GetSize(); i++)\r
995         {\r
996                 CPDF_Rect rc = rects.GetAt(i);\r
997                 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();\r
998                 pEnv->FFI_Invalidate(m_page, rc.left, rc.top, rc.right, rc.bottom);\r
999         }\r
1000 }\r
1001 \r
1002 void CPDFSDK_PageView::UpdateView(CPDFSDK_Annot* pAnnot)\r
1003 {\r
1004         CPDF_Rect rcWindow;\r
1005 \r
1006         CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv();        \r
1007 //      CPDFSDK_AnnotHandlerMgr* pAnnotHandler = pEnv->GetAnnotHandlerMgr();\r
1008         \r
1009         rcWindow = pAnnot->GetRect();//pAnnotHandler->Annot_OnGetViewBBox(this,pAnnot); \r
1010         pEnv->FFI_Invalidate(m_page, rcWindow.left, rcWindow.top, rcWindow.right, rcWindow.bottom);\r
1011 \r
1012 }\r
1013 \r
1014 int CPDFSDK_PageView::GetPageIndex()\r
1015 {\r
1016         if(m_page)\r
1017         {\r
1018                 CPDF_Dictionary* pDic = m_page->m_pFormDict;\r
1019                 CPDF_Document* pDoc = m_pSDKDoc->GetDocument();\r
1020                 if(pDoc && pDic)\r
1021                 {\r
1022                         return pDoc->GetPageIndex(pDic->GetObjNum());\r
1023                 }\r
1024         }\r
1025         return -1;\r
1026 }\r
1027 \r
1028 FX_BOOL CPDFSDK_PageView::IsValidAnnot(FX_LPVOID p)\r
1029 {\r
1030         if (p == NULL) return FALSE;\r
1031         int iCount = m_pAnnotList->Count();\r
1032         for (int i = 0; i < iCount; i++)\r
1033         {\r
1034                 if (m_pAnnotList->GetAt(i) == p)\r
1035                         return TRUE;\r
1036         }\r
1037         return FALSE;\r
1038 }\r
1039 \r
1040 \r
1041 CPDFSDK_Annot* CPDFSDK_PageView::GetFocusAnnot()\r
1042 {\r
1043         CPDFSDK_Annot* pFocusAnnot = m_pSDKDoc->GetFocusAnnot();\r
1044         if(!pFocusAnnot)\r
1045                 return NULL;\r
1046         \r
1047         for(int i=0; i<m_fxAnnotArray.GetSize(); i++)\r
1048         {\r
1049                 CPDFSDK_Annot* pAnnot = (CPDFSDK_Annot*)m_fxAnnotArray.GetAt(i);\r
1050                 if(pAnnot == pFocusAnnot)\r
1051                         return pAnnot;\r
1052         }\r
1053         return NULL;\r
1054 }\r
1055 \r