Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / pdfium / fpdfsdk / include / fsdk_mgr.h
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 #ifndef _FPDFSDK_MGR_H
8 #define _FPDFSDK_MGR_H
9
10 #include "fsdk_common.h"
11 #include "fsdk_define.h"
12 #include "fx_systemhandler.h"
13 #include "fsdk_baseannot.h"
14 #include "fsdk_baseform.h"
15 #include "fpdfformfill.h"
16 #include "fsdk_annothandler.h"
17 #include "fsdk_actionhandler.h"
18
19 //cross platform keycode and events define.
20 #include "fpdf_fwlevent.h"
21
22
23 class CPDFSDK_Document;
24 class CPDFSDK_PageView;
25 class CPDFSDK_Annot;
26 class CFFL_IFormFiller;
27 class CPDFSDK_Widget;
28 class IFX_SystemHandler;
29 class CPDFSDK_ActionHandler;
30 class CJS_RuntimeFactory;
31
32 #include "javascript/IJavaScript.h"
33
34 class CPDFDoc_Environment FX_FINAL
35 {
36 public:
37         CPDFDoc_Environment(CPDF_Document * pDoc);
38         ~CPDFDoc_Environment();
39
40         int RegAppHandle(FPDF_FORMFILLINFO* pFFinfo);//{ m_pInfo  = pFFinfo; return TRUE;}
41
42         void FFI_Invalidate(FPDF_PAGE page, double left, double top, double right, double bottom)
43         {
44                 if (m_pInfo && m_pInfo->FFI_Invalidate) 
45                 {
46                         m_pInfo->FFI_Invalidate(m_pInfo, page, left, top, right, bottom);
47                 }
48         }
49         void FFI_OutputSelectedRect(FPDF_PAGE page, double left, double top, double right, double bottom)
50         {
51                 if (m_pInfo && m_pInfo->FFI_OutputSelectedRect) 
52                 {
53                         m_pInfo->FFI_OutputSelectedRect(m_pInfo, page, left, top, right, bottom);
54                 }
55         }
56
57         void FFI_SetCursor(int nCursorType)
58         {
59                 if (m_pInfo && m_pInfo->FFI_SetCursor) 
60                 {
61                         m_pInfo->FFI_SetCursor(m_pInfo, nCursorType);
62                 }
63         }
64
65         int  FFI_SetTimer(int uElapse, TimerCallback lpTimerFunc)
66         {
67                 if (m_pInfo && m_pInfo->FFI_SetTimer) 
68                 {
69                         return m_pInfo->FFI_SetTimer(m_pInfo, uElapse, lpTimerFunc);
70                 }
71                 return -1;
72         }
73                 
74         void FFI_KillTimer(int nTimerID)
75         {
76                 if (m_pInfo && m_pInfo->FFI_KillTimer) 
77                 {
78                         m_pInfo->FFI_KillTimer(m_pInfo, nTimerID);
79                 }
80         }
81         FX_SYSTEMTIME FFI_GetLocalTime()
82         {
83                 FX_SYSTEMTIME fxtime;
84                 if(m_pInfo && m_pInfo->FFI_GetLocalTime)
85                 {
86                         FPDF_SYSTEMTIME systime = m_pInfo->FFI_GetLocalTime(m_pInfo);
87                         fxtime.wDay = systime.wDay;
88                         fxtime.wDayOfWeek = systime.wDayOfWeek;
89                         fxtime.wHour = systime.wHour;
90                         fxtime.wMilliseconds = systime.wMilliseconds;
91                         fxtime.wMinute = systime.wMinute;
92                         fxtime.wMonth = systime.wMonth;
93                         fxtime.wSecond = systime.wSecond;
94                         fxtime.wYear = systime.wYear;
95                 }
96                 return fxtime;
97         }
98
99         void FFI_OnChange()
100         {
101                 if(m_pInfo && m_pInfo->FFI_OnChange)
102                 {
103                         m_pInfo->FFI_OnChange(m_pInfo);
104                 }
105         }
106
107         FX_BOOL FFI_IsSHIFTKeyDown(FX_DWORD nFlag)
108         {
109                 
110                 return (nFlag & FWL_EVENTFLAG_ShiftKey) != 0;
111         }
112         FX_BOOL FFI_IsCTRLKeyDown(FX_DWORD nFlag)
113         {
114
115                 return (nFlag & FWL_EVENTFLAG_ControlKey) != 0;
116         }
117         FX_BOOL FFI_IsALTKeyDown(FX_DWORD nFlag)
118         {
119
120                 return (nFlag & FWL_EVENTFLAG_AltKey) != 0;
121         }
122         FX_BOOL FFI_IsINSERTKeyDown(FX_DWORD nFlag)
123         {
124                 return FALSE;
125         }
126
127         int JS_appAlert(FX_LPCWSTR Msg, FX_LPCWSTR Title, FX_UINT Type, FX_UINT Icon)
128         {
129                 if(m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_alert)
130                 {
131                         CFX_ByteString bsMsg = CFX_WideString(Msg).UTF16LE_Encode();
132                         CFX_ByteString bsTitle = CFX_WideString(Title).UTF16LE_Encode();
133                         FPDF_WIDESTRING pMsg = (FPDF_WIDESTRING)bsMsg.GetBuffer(bsMsg.GetLength());
134                         FPDF_WIDESTRING pTitle = (FPDF_WIDESTRING)bsTitle.GetBuffer(bsTitle.GetLength());
135                         int ret = m_pInfo->m_pJsPlatform->app_alert(m_pInfo->m_pJsPlatform, pMsg, pTitle, Type, Icon);
136                         bsMsg.ReleaseBuffer();
137                         bsTitle.ReleaseBuffer();
138                         return ret;
139                 }
140                 return -1;
141         }
142
143         int JS_appResponse(FX_LPCWSTR Question, FX_LPCWSTR Title, FX_LPCWSTR Default, FX_LPCWSTR cLabel, FPDF_BOOL bPassword, void* response, int length)
144         {
145                 if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_response)
146                 {
147                         CFX_ByteString bsQuestion = CFX_WideString(Question).UTF16LE_Encode();
148                         CFX_ByteString bsTitle = CFX_WideString(Title).UTF16LE_Encode();
149                         CFX_ByteString bsDefault = CFX_WideString(Default).UTF16LE_Encode();
150                         CFX_ByteString bsLabel = CFX_WideString(cLabel).UTF16LE_Encode();
151                         FPDF_WIDESTRING pQuestion = (FPDF_WIDESTRING)bsQuestion.GetBuffer(bsQuestion.GetLength());
152                         FPDF_WIDESTRING pTitle = (FPDF_WIDESTRING)bsTitle.GetBuffer(bsTitle.GetLength());
153                         FPDF_WIDESTRING pDefault = (FPDF_WIDESTRING)bsDefault.GetBuffer(bsDefault.GetLength());
154                         FPDF_WIDESTRING pLabel = (FPDF_WIDESTRING)bsLabel.GetBuffer(bsLabel.GetLength());
155                         int ret = m_pInfo->m_pJsPlatform->app_response(m_pInfo->m_pJsPlatform, pQuestion, pTitle, 
156                                 pDefault, pLabel, bPassword, response, length);
157                         bsQuestion.ReleaseBuffer();
158                         bsTitle.ReleaseBuffer();
159                         bsDefault.ReleaseBuffer();
160                         bsLabel.ReleaseBuffer();
161                         return ret;
162                 }
163                 return -1;
164         }
165
166         void JS_appBeep(int nType)
167         {
168                 if(m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_beep)
169                 {
170                         m_pInfo->m_pJsPlatform->app_beep(m_pInfo->m_pJsPlatform, nType);
171                 }
172         }
173
174         CFX_WideString JS_fieldBrowse()
175         {
176                 if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->Field_browse)
177                 {
178                         int nRequiredLen = m_pInfo->m_pJsPlatform->Field_browse(m_pInfo->m_pJsPlatform, NULL, 0);
179                         if (nRequiredLen <= 0)
180                                 return L"";
181
182                         char* pbuff = new char[nRequiredLen];
183                         if (!pbuff)
184                                 return L"";
185
186                         memset(pbuff, 0, nRequiredLen);
187                         int nActualLen = m_pInfo->m_pJsPlatform->Field_browse(m_pInfo->m_pJsPlatform, pbuff, nRequiredLen);
188                         if (nActualLen <= 0 || nActualLen > nRequiredLen)
189                         {
190                                 delete[] pbuff;
191                                 return L"";
192                         }
193                         CFX_ByteString bsRet = CFX_ByteString(pbuff, nActualLen);
194                         CFX_WideString wsRet = CFX_WideString::FromLocal(bsRet);
195                         delete[] pbuff;
196                         return wsRet;
197                 }
198                 return L"";
199         }
200
201         CFX_WideString JS_docGetFilePath()
202         {
203                 if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->Doc_getFilePath)
204                 {
205                         int nRequiredLen = m_pInfo->m_pJsPlatform->Doc_getFilePath(m_pInfo->m_pJsPlatform, NULL, 0);
206                         if (nRequiredLen <= 0)
207                                 return L"";
208
209                         char* pbuff = new char[nRequiredLen];
210                         if (!pbuff)
211                                 return L"";
212
213                         memset(pbuff, 0, nRequiredLen);
214                         int nActualLen = m_pInfo->m_pJsPlatform->Doc_getFilePath(m_pInfo->m_pJsPlatform, pbuff, nRequiredLen);
215                         if (nActualLen <= 0 || nActualLen > nRequiredLen)
216                         {
217                                 delete[] pbuff;
218                                 return L"";
219                         }
220                         CFX_ByteString bsRet = CFX_ByteString(pbuff, nActualLen);
221                         CFX_WideString wsRet = CFX_WideString::FromLocal(bsRet);
222                         delete[] pbuff;
223                         return wsRet;
224                 }
225                 return L"";
226         }
227
228         void JS_docSubmitForm(void* formData, int length, FX_LPCWSTR URL)
229         {
230                 if(m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->Doc_submitForm)
231                 {
232                         CFX_ByteString bsDestination = CFX_WideString(URL).UTF16LE_Encode();
233                         FPDF_WIDESTRING pDestination = (FPDF_WIDESTRING)bsDestination.GetBuffer(bsDestination.GetLength());
234                         m_pInfo->m_pJsPlatform->Doc_submitForm(m_pInfo->m_pJsPlatform, formData, length, pDestination);
235                         bsDestination.ReleaseBuffer();
236                 }
237         }
238
239         void JS_docmailForm(void* mailData, int length, FPDF_BOOL bUI,FX_LPCWSTR To, FX_LPCWSTR Subject, FX_LPCWSTR CC, FX_LPCWSTR BCC, FX_LPCWSTR Msg)
240         {
241                 if(m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->Doc_mail)
242                 {
243                         CFX_ByteString bsTo = CFX_WideString(To).UTF16LE_Encode();
244                         CFX_ByteString bsCC = CFX_WideString(Subject).UTF16LE_Encode();
245                         CFX_ByteString bsBcc = CFX_WideString(BCC).UTF16LE_Encode();
246                         CFX_ByteString bsSubject = CFX_WideString(Subject).UTF16LE_Encode();
247                         CFX_ByteString bsMsg = CFX_WideString(Msg).UTF16LE_Encode();
248                         FPDF_WIDESTRING pTo = (FPDF_WIDESTRING)bsTo.GetBuffer(bsTo.GetLength());
249                         FPDF_WIDESTRING pCC = (FPDF_WIDESTRING)bsCC.GetBuffer(bsCC.GetLength());
250                         FPDF_WIDESTRING pBcc = (FPDF_WIDESTRING)bsBcc.GetBuffer(bsBcc.GetLength());
251                         FPDF_WIDESTRING pSubject = (FPDF_WIDESTRING)bsSubject.GetBuffer(bsSubject.GetLength());
252                         FPDF_WIDESTRING pMsg = (FPDF_WIDESTRING)bsMsg.GetBuffer(bsMsg.GetLength());
253                         m_pInfo->m_pJsPlatform->Doc_mail(m_pInfo->m_pJsPlatform, mailData, length, bUI, pTo, pSubject,
254                                 pCC, pBcc, pMsg);
255                         bsTo.ReleaseBuffer();
256                         bsCC.ReleaseBuffer();
257                         bsBcc.ReleaseBuffer();
258                         bsSubject.ReleaseBuffer();
259                         bsMsg.ReleaseBuffer();
260                 }
261         }
262         CFX_WideString JS_appbrowseForDoc(FPDF_BOOL bSave, FX_LPCWSTR cFilenameInit)
263         {
264                 //to do....
265                 return L"";
266 //              if(m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_browseForDoc)
267 //              {
268 //                      CFX_ByteString bsFilenameInit = CFX_WideString(cFilenameInit).UTF16LE_Encode();
269 //                      FPDF_WIDESTRING pFileNameInit = (FPDF_WIDESTRING)bsFilenameInit.GetBuffer(bsFilenameInit.GetLength());
270 // 
271 //                      m_pInfo->m_pJsPlatform->app_browseForDoc(m_pInfo->m_pJsPlatform, pFileNameInit);
272 //                      bsFilenameInit.ReleaseBuffer();
273 //              }
274         }
275
276         void JS_docprint(FPDF_BOOL bUI , int nStart, int nEnd, FPDF_BOOL bSilent ,FPDF_BOOL bShrinkToFit,FPDF_BOOL bPrintAsImage ,FPDF_BOOL bReverse ,FPDF_BOOL bAnnotations)
277         {
278                 if(m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->Doc_print)
279                 {
280                         m_pInfo->m_pJsPlatform->Doc_print(m_pInfo->m_pJsPlatform, bUI, nStart, nEnd, bSilent, bShrinkToFit, bPrintAsImage, bReverse, bAnnotations);
281                 }
282         }
283         void JS_docgotoPage(int nPageNum)
284         {
285                 if(m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->Doc_gotoPage)
286                 {
287                         m_pInfo->m_pJsPlatform->Doc_gotoPage(m_pInfo->m_pJsPlatform, nPageNum);
288                 }
289         }
290
291         FPDF_PAGE       FFI_GetPage(FPDF_DOCUMENT document,int nPageIndex)
292         {
293                 if(m_pInfo && m_pInfo->FFI_GetPage)
294                 {
295                         return m_pInfo->FFI_GetPage(m_pInfo, document, nPageIndex);
296                 }
297                 return NULL;
298         }
299
300         FPDF_PAGE FFI_GetCurrentPage(FPDF_DOCUMENT document)
301         {
302                 if(m_pInfo && m_pInfo->FFI_GetCurrentPage)
303                 {
304                         return m_pInfo->FFI_GetCurrentPage(m_pInfo, document);
305                 }
306                 return NULL;
307         }
308
309         int     FFI_GetRotation(FPDF_PAGE page)
310         {
311                 if(m_pInfo && m_pInfo->FFI_GetRotation)
312                 {
313                         return m_pInfo->FFI_GetRotation(m_pInfo, page);
314                 }
315                 return 0;
316         }
317         void    FFI_ExecuteNamedAction(FX_LPCSTR namedAction)
318         {
319                 if(m_pInfo && m_pInfo->FFI_ExecuteNamedAction)
320                 {
321                         m_pInfo->FFI_ExecuteNamedAction(m_pInfo, namedAction);
322                 }
323         }
324         void    FFI_OnSetFieldInputFocus(void* field,FPDF_WIDESTRING focusText, FPDF_DWORD nTextLen, FX_BOOL bFocus)
325         {
326                 if(m_pInfo && m_pInfo->FFI_SetTextFieldFocus)
327                 {
328                         m_pInfo->FFI_SetTextFieldFocus(m_pInfo, focusText, nTextLen, bFocus);
329                 }
330         }
331
332         void    FFI_DoURIAction(FX_LPCSTR bsURI)
333         {
334                 if(m_pInfo && m_pInfo->FFI_DoURIAction)
335                 {
336                         m_pInfo->FFI_DoURIAction(m_pInfo, bsURI);
337                 }
338         }
339
340         void    FFI_DoGoToAction(int nPageIndex, int zoomMode, float* fPosArray, int sizeOfArray)
341         {
342                 if(m_pInfo && m_pInfo->FFI_DoGoToAction)
343                 {
344                         m_pInfo->FFI_DoGoToAction(m_pInfo, nPageIndex, zoomMode, fPosArray, sizeOfArray);
345                 }
346         }
347
348 public:
349         FX_BOOL                         IsJSInitiated();
350
351 public: 
352         void                            SetCurrentDoc(CPDFSDK_Document* pFXDoc) {m_pSDKDoc = pFXDoc;}
353         CPDFSDK_Document*       GetCurrentDoc();
354         CPDF_Document*          GetPDFDocument() {return m_pPDFDoc;}
355 //      CPDFSDK_Document*   GetDocument(int nIndex);
356 //      int                                     CountDocuments() {return m_docMap.GetCount();}
357
358         CPDFSDK_Document*               OpenDocument(CFX_WideString &fileName);
359         CPDFSDK_Document*               OpenMemPDFDoc(CPDF_Document* pNewDoc, CFX_WideString &fileName);
360         FX_BOOL                                 OpenURL(CFX_WideString &filePath);
361         
362
363         CFX_ByteString          GetAppName() {return "";}
364
365         CFFL_IFormFiller*       GetIFormFiller();
366         IFX_SystemHandler*      GetSysHandler() {return m_pSysHandler;}
367
368 public:
369         CPDFSDK_AnnotHandlerMgr* GetAnnotHandlerMgr();
370         IFXJS_Runtime*  GetJSRuntime();
371         CPDFSDK_ActionHandler* GetActionHander();
372 private:
373         CPDFSDK_AnnotHandlerMgr* m_pAnnotHandlerMgr;
374         CPDFSDK_ActionHandler*  m_pActionHandler;
375         IFXJS_Runtime*  m_pJSRuntime;
376 public:
377         FPDF_FORMFILLINFO* GetFormFillInfo() {return m_pInfo;}
378 private:
379         FPDF_FORMFILLINFO*      m_pInfo;
380 //      CFX_MapPtrTemplate<CPDF_Document*, CPDFSDK_Document*> m_docMap;
381         CPDFSDK_Document* m_pSDKDoc;
382         CPDF_Document* m_pPDFDoc;
383
384         CFFL_IFormFiller* m_pIFormFiller;
385         IFX_SystemHandler* m_pSysHandler;
386
387 public:
388         CJS_RuntimeFactory*  m_pJSRuntimeFactory;
389 };
390
391
392
393 // class CFX_App
394 // {
395 // public:
396 //      CFX_App():m_pCurDoc(NULL) {}
397 //      void SetAt(CPDF_Document* pPDFDoc, CPDFSDK_Document* pFXDoc);
398 //      CPDFSDK_Document* GetAt(CPDF_Document* pPDFDoc);
399 // public:
400 //      void SetCurrentDocument(CPDFSDK_Document* pFXDoc) {m_pCurDoc = pFXDoc;}
401 //      CPDFSDK_Document* GetCurrentDocument() {return m_pCurDoc;}
402 // private:
403 //      CFX_MapPtrTemplate<CPDF_Document*, CPDFSDK_Document*> m_docArray;
404 //      CPDFSDK_Document* m_pCurDoc;
405 // };
406 class CPDFSDK_InterForm;
407 class CPDFSDK_Document
408 {
409 public:
410         CPDFSDK_Document(CPDF_Document* pDoc, CPDFDoc_Environment* pEnv);
411         ~CPDFSDK_Document();
412 public:
413         CPDFSDK_InterForm*              GetInterForm() ;
414         CPDF_Document*                  GetDocument() {return m_pDoc;}
415
416 public:
417         void                                    InitPageView();
418         void                                    AddPageView(CPDF_Page* pPDFPage, CPDFSDK_PageView* pPageView);
419         CPDFSDK_PageView*               GetPageView(CPDF_Page* pPDFPage, FX_BOOL ReNew = TRUE);
420         CPDFSDK_PageView*               GetPageView(int nIndex);
421         CPDFSDK_PageView*               GetCurrentView();
422         void                                    ReMovePageView(CPDF_Page* pPDFPage);
423         void                                    UpdateAllViews(CPDFSDK_PageView* pSender, CPDFSDK_Annot* pAnnot);
424
425         CPDFSDK_Annot*                  GetFocusAnnot();//{return NULL;}
426
427         IFXJS_Runtime *                 GetJsRuntime();
428         
429         FX_BOOL                                 SetFocusAnnot(CPDFSDK_Annot* pAnnot, FX_UINT nFlag = 0);//{return FALSE;}
430         FX_BOOL                                 KillFocusAnnot(FX_UINT nFlag = 0);
431
432         FX_BOOL                                 ExtractPages(const CFX_WordArray &arrExtraPages, CPDF_Document* pDstDoc);
433         FX_BOOL                                 InsertPages(int nInsertAt, const CPDF_Document* pSrcDoc, const CFX_WordArray &arrSrcPages);
434         FX_BOOL                                 DeletePages(int nStart, int nCount);
435         FX_BOOL                                 ReplacePages(int nPage, const CPDF_Document* pSrcDoc, const CFX_WordArray &arrSrcPages);
436
437         void                                    OnCloseDocument();
438
439         int                                             GetPageCount() {return m_pDoc->GetPageCount();}
440         FX_BOOL                                 GetPermissions(int nFlag);
441         FX_BOOL                                 GetChangeMark() {return m_bChangeMask;}
442         void                                    SetChangeMark() {m_bChangeMask = TRUE;}
443         void                                    ClearChangeMark() {m_bChangeMask= FALSE;}
444 //      FX_BOOL                                 GetChangeMark(){return FALSE;}//IsAnnotModified()||IsFormModified() || IsWidgetModified()|| m_nChangeMark>0 ;}  
445 //      void                    ClearChangeMark(){}
446         CFX_WideString                  GetPath() ;
447         CPDF_Page*                              GetPage(int nIndex);
448         CPDFDoc_Environment *   GetEnv() {return m_pEnv; }
449         void                                ProcJavascriptFun();
450         FX_BOOL                                 ProcOpenAction();
451         CPDF_OCContext*                 GetOCContext();
452 private:
453         //CFX_ArrayTemplate<CPDFSDK_PageView*> m_pageArray;
454         CFX_MapPtrTemplate<CPDF_Page*, CPDFSDK_PageView*> m_pageMap;
455         CPDF_Document*                  m_pDoc;
456
457         CPDFSDK_InterForm*              m_pInterForm;
458         CPDFSDK_Annot*                  m_pFocusAnnot;
459         CPDFDoc_Environment *   m_pEnv;
460         CPDF_OCContext *                m_pOccontent;
461         FX_BOOL                                 m_bChangeMask;
462 };
463
464 class CPDFSDK_PageView FX_FINAL
465 {
466 public:
467         CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc,CPDF_Page* page);
468         ~CPDFSDK_PageView();
469 public:
470         void PageView_OnDraw(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,CPDF_RenderOptions* pOptions) ;
471 public:
472         CPDF_Annot*                                             GetPDFAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
473         CPDFSDK_Annot*                                  GetFXAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
474         CPDF_Annot*                                             GetPDFWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
475         CPDFSDK_Annot*                                  GetFXWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
476         CPDFSDK_Annot*                                  GetFocusAnnot() ;
477         void                                                    SetFocusAnnot(CPDFSDK_Annot* pSDKAnnot,FX_UINT nFlag = 0) {m_pSDKDoc->SetFocusAnnot(pSDKAnnot, nFlag);}
478         FX_BOOL                                                 KillFocusAnnot(FX_UINT nFlag = 0) {return m_pSDKDoc->KillFocusAnnot(nFlag);}
479         FX_BOOL                                                 Annot_HasAppearance(CPDF_Annot* pAnnot);
480
481         CPDFSDK_Annot*                                  AddAnnot(CPDF_Dictionary * pDict);
482         CPDFSDK_Annot*                                  AddAnnot(FX_LPCSTR lpSubType,CPDF_Dictionary * pDict);
483         CPDFSDK_Annot*                                  AddAnnot(CPDF_Annot * pPDFAnnot);
484         FX_BOOL                                                 DeleteAnnot(CPDFSDK_Annot* pAnnot);                                                     
485         
486         int                                                             CountAnnots();
487         CPDFSDK_Annot*                                  GetAnnot(int nIndex);
488         CPDFSDK_Annot*                              GetAnnotByDict(CPDF_Dictionary * pDict);
489         CPDF_Page*                                              GetPDFPage(){return m_page;}
490         CPDF_Document*                                  GetPDFDocument();
491         CPDFSDK_Document*                               GetSDKDocument() {return m_pSDKDoc;}    
492 public:
493         FX_BOOL                                 OnLButtonDown(const CPDF_Point & point, FX_UINT nFlag);
494         FX_BOOL                                 OnLButtonUp(const CPDF_Point & point, FX_UINT nFlag);
495         FX_BOOL                                 OnChar(int nChar, FX_UINT nFlag);
496         FX_BOOL                                 OnKeyDown(int nKeyCode, int nFlag);
497         FX_BOOL                                 OnKeyUp(int nKeyCode, int nFlag);
498
499         FX_BOOL                                 OnMouseMove(const CPDF_Point & point, int nFlag);
500         FX_BOOL                                 OnMouseWheel(double deltaX, double deltaY,const CPDF_Point& point, int nFlag);
501         FX_BOOL                                 IsValidAnnot(FX_LPVOID p);
502 public:
503         void                                    GetCurrentMatrix(CPDF_Matrix& matrix) {matrix = m_curMatrix;}
504         void                                    UpdateRects(CFX_RectArray& rects);
505         void                                                    UpdateView(CPDFSDK_Annot* pAnnot);
506         CFX_PtrArray*                                   GetAnnotList(){ return &m_fxAnnotArray; }
507
508 public:
509         int                                             GetPageIndex();
510         void                                                    LoadFXAnnots();
511 private:
512         CPDF_Matrix m_curMatrix;
513
514 private:
515         void PageView_OnHighlightFormFields(CFX_RenderDevice* pDevice, CPDFSDK_Widget* pWidget);
516
517 private:
518         CPDF_Page* m_page;
519         CPDF_AnnotList* m_pAnnotList;
520
521         //CPDFSDK_Annot* m_pFocusAnnot;
522         CFX_PtrArray  m_fxAnnotArray;
523
524         CPDFSDK_Document* m_pSDKDoc;
525 private:
526         CPDFSDK_Widget* m_CaptureWidget;
527         FX_BOOL m_bEnterWidget;
528         FX_BOOL m_bExitWidget;
529         FX_BOOL m_bOnWidget;
530 public:
531         void SetValid(FX_BOOL bValid) {m_bValid = bValid;}
532         FX_BOOL IsValid() {return m_bValid;}
533 private:
534         FX_BOOL m_bValid;
535 };
536
537
538 template<class TYPE>
539 class CGW_ArrayTemplate : public CFX_ArrayTemplate<TYPE>
540 {
541 public: 
542         CGW_ArrayTemplate(){}
543         virtual ~CGW_ArrayTemplate(){}
544         
545         typedef int (*LP_COMPARE)(TYPE p1, TYPE p2);
546         
547         void Sort(LP_COMPARE pCompare, FX_BOOL bAscent = TRUE)
548         {
549                 int nSize = this->GetSize();
550                 QuickSort(0, nSize -1, bAscent, pCompare);
551         }
552         
553 private:
554         void QuickSort(FX_UINT nStartPos, FX_UINT nStopPos, FX_BOOL bAscend, LP_COMPARE pCompare)
555         {
556                 if (nStartPos >= nStopPos) return;
557                 
558                 if ((nStopPos - nStartPos) == 1)
559                 {
560                         TYPE Value1 = this->GetAt(nStartPos);
561                         TYPE Value2 = this->GetAt(nStopPos);
562                         
563                         int iGreate = (*pCompare)(Value1, Value2);
564                         if ((bAscend && iGreate > 0) || (!bAscend && iGreate < 0))
565                         {
566                                 this->SetAt(nStartPos, Value2);
567                                 this->SetAt(nStopPos, Value1);
568                         }
569                         return;
570                 }
571                 
572                 FX_UINT m = nStartPos + (nStopPos - nStartPos) / 2;
573                 FX_UINT i = nStartPos;
574                 
575                 TYPE Value = this->GetAt(m);
576                 
577                 while (i < m)
578                 {
579                         TYPE temp = this->GetAt(i);
580                         
581                         int iGreate = (*pCompare)(temp, Value);
582                         if ((bAscend && iGreate > 0) || (!bAscend && iGreate < 0))
583                         {
584                                 this->InsertAt(m+1, temp);
585                                 this->RemoveAt(i);
586                                 m--;
587                         }
588                         else
589                         {
590                                 i++;
591                         }
592                 }
593                 
594                 FX_UINT j = nStopPos;
595                 
596                 while (j > m)
597                 {
598                         TYPE temp = this->GetAt(j);
599                         
600                         int iGreate = (*pCompare)(temp, Value);
601                         if ((bAscend && iGreate < 0) || (!bAscend && iGreate > 0))
602                         {
603                                 this->RemoveAt(j);
604                                 this->InsertAt(m, temp);
605                                 m++;
606                         }
607                         else
608                         {
609                                 j--;
610                         }
611                 }
612                 
613                 if (nStartPos < m) QuickSort(nStartPos, m, bAscend, pCompare);
614                 if (nStopPos > m) QuickSort(m, nStopPos, bAscend, pCompare);
615         }
616 };
617
618
619 #endif //_FPDFSDK_MGR_H
620