Merge to master: Kill off some dodgy JS callbacks
[pdfium.git] / 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
263         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)
264         {
265                 if(m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->Doc_print)
266                 {
267                         m_pInfo->m_pJsPlatform->Doc_print(m_pInfo->m_pJsPlatform, bUI, nStart, nEnd, bSilent, bShrinkToFit, bPrintAsImage, bReverse, bAnnotations);
268                 }
269         }
270         void JS_docgotoPage(int nPageNum)
271         {
272                 if(m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->Doc_gotoPage)
273                 {
274                         m_pInfo->m_pJsPlatform->Doc_gotoPage(m_pInfo->m_pJsPlatform, nPageNum);
275                 }
276         }
277
278         FPDF_PAGE       FFI_GetPage(FPDF_DOCUMENT document,int nPageIndex)
279         {
280                 if(m_pInfo && m_pInfo->FFI_GetPage)
281                 {
282                         return m_pInfo->FFI_GetPage(m_pInfo, document, nPageIndex);
283                 }
284                 return NULL;
285         }
286
287         FPDF_PAGE FFI_GetCurrentPage(FPDF_DOCUMENT document)
288         {
289                 if(m_pInfo && m_pInfo->FFI_GetCurrentPage)
290                 {
291                         return m_pInfo->FFI_GetCurrentPage(m_pInfo, document);
292                 }
293                 return NULL;
294         }
295
296         int     FFI_GetRotation(FPDF_PAGE page)
297         {
298                 if(m_pInfo && m_pInfo->FFI_GetRotation)
299                 {
300                         return m_pInfo->FFI_GetRotation(m_pInfo, page);
301                 }
302                 return 0;
303         }
304         void    FFI_ExecuteNamedAction(FX_LPCSTR namedAction)
305         {
306                 if(m_pInfo && m_pInfo->FFI_ExecuteNamedAction)
307                 {
308                         m_pInfo->FFI_ExecuteNamedAction(m_pInfo, namedAction);
309                 }
310         }
311         void    FFI_OnSetFieldInputFocus(void* field,FPDF_WIDESTRING focusText, FPDF_DWORD nTextLen, FX_BOOL bFocus)
312         {
313                 if(m_pInfo && m_pInfo->FFI_SetTextFieldFocus)
314                 {
315                         m_pInfo->FFI_SetTextFieldFocus(m_pInfo, focusText, nTextLen, bFocus);
316                 }
317         }
318
319         void    FFI_DoURIAction(FX_LPCSTR bsURI)
320         {
321                 if(m_pInfo && m_pInfo->FFI_DoURIAction)
322                 {
323                         m_pInfo->FFI_DoURIAction(m_pInfo, bsURI);
324                 }
325         }
326
327         void    FFI_DoGoToAction(int nPageIndex, int zoomMode, float* fPosArray, int sizeOfArray)
328         {
329                 if(m_pInfo && m_pInfo->FFI_DoGoToAction)
330                 {
331                         m_pInfo->FFI_DoGoToAction(m_pInfo, nPageIndex, zoomMode, fPosArray, sizeOfArray);
332                 }
333         }
334
335 public:
336         FX_BOOL                         IsJSInitiated();
337
338 public:
339         void                            SetCurrentDoc(CPDFSDK_Document* pFXDoc) {m_pSDKDoc = pFXDoc;}
340         CPDFSDK_Document*       GetCurrentDoc();
341         CPDF_Document*          GetPDFDocument() {return m_pPDFDoc;}
342 //      CPDFSDK_Document*   GetDocument(int nIndex);
343 //      int                                     CountDocuments() {return m_docMap.GetCount();}
344
345         CPDFSDK_Document*               OpenDocument(CFX_WideString &fileName){return NULL;}
346         CPDFSDK_Document*               OpenMemPDFDoc(CPDF_Document* pNewDoc, CFX_WideString &fileName){return NULL;}
347
348
349         CFX_ByteString          GetAppName() {return "";}
350
351         CFFL_IFormFiller*       GetIFormFiller();
352         IFX_SystemHandler*      GetSysHandler() {return m_pSysHandler;}
353
354 public:
355         CPDFSDK_AnnotHandlerMgr* GetAnnotHandlerMgr();
356         IFXJS_Runtime*  GetJSRuntime();
357         CPDFSDK_ActionHandler* GetActionHander();
358 private:
359         CPDFSDK_AnnotHandlerMgr* m_pAnnotHandlerMgr;
360         CPDFSDK_ActionHandler*  m_pActionHandler;
361         IFXJS_Runtime*  m_pJSRuntime;
362 public:
363         FPDF_FORMFILLINFO* GetFormFillInfo() {return m_pInfo;}
364 private:
365         FPDF_FORMFILLINFO*      m_pInfo;
366 //      CFX_MapPtrTemplate<CPDF_Document*, CPDFSDK_Document*> m_docMap;
367         CPDFSDK_Document* m_pSDKDoc;
368         CPDF_Document* m_pPDFDoc;
369
370         CFFL_IFormFiller* m_pIFormFiller;
371         IFX_SystemHandler* m_pSysHandler;
372
373 public:
374         CJS_RuntimeFactory*  m_pJSRuntimeFactory;
375 };
376
377
378
379 // class CFX_App
380 // {
381 // public:
382 //      CFX_App():m_pCurDoc(NULL) {}
383 //      void SetAt(CPDF_Document* pPDFDoc, CPDFSDK_Document* pFXDoc);
384 //      CPDFSDK_Document* GetAt(CPDF_Document* pPDFDoc);
385 // public:
386 //      void SetCurrentDocument(CPDFSDK_Document* pFXDoc) {m_pCurDoc = pFXDoc;}
387 //      CPDFSDK_Document* GetCurrentDocument() {return m_pCurDoc;}
388 // private:
389 //      CFX_MapPtrTemplate<CPDF_Document*, CPDFSDK_Document*> m_docArray;
390 //      CPDFSDK_Document* m_pCurDoc;
391 // };
392 class CPDFSDK_InterForm;
393 class CPDFSDK_Document
394 {
395 public:
396         CPDFSDK_Document(CPDF_Document* pDoc, CPDFDoc_Environment* pEnv);
397         ~CPDFSDK_Document();
398 public:
399         CPDFSDK_InterForm*              GetInterForm() ;
400         CPDF_Document*                  GetDocument() {return m_pDoc;}
401
402 public:
403         void                                    InitPageView();
404         void                                    AddPageView(CPDF_Page* pPDFPage, CPDFSDK_PageView* pPageView);
405         CPDFSDK_PageView*               GetPageView(CPDF_Page* pPDFPage, FX_BOOL ReNew = TRUE);
406         CPDFSDK_PageView*               GetPageView(int nIndex);
407         CPDFSDK_PageView*               GetCurrentView();
408         void                                    ReMovePageView(CPDF_Page* pPDFPage);
409         void                                    UpdateAllViews(CPDFSDK_PageView* pSender, CPDFSDK_Annot* pAnnot);
410
411         CPDFSDK_Annot*                  GetFocusAnnot();//{return NULL;}
412
413         IFXJS_Runtime *                 GetJsRuntime();
414
415         FX_BOOL                                 SetFocusAnnot(CPDFSDK_Annot* pAnnot, FX_UINT nFlag = 0);//{return FALSE;}
416         FX_BOOL                                 KillFocusAnnot(FX_UINT nFlag = 0);
417
418         FX_BOOL                                 ExtractPages(const CFX_WordArray &arrExtraPages, CPDF_Document* pDstDoc);
419         FX_BOOL                                 InsertPages(int nInsertAt, const CPDF_Document* pSrcDoc, const CFX_WordArray &arrSrcPages);
420         FX_BOOL                                 DeletePages(int nStart, int nCount);
421         FX_BOOL                                 ReplacePages(int nPage, const CPDF_Document* pSrcDoc, const CFX_WordArray &arrSrcPages);
422
423         void                                    OnCloseDocument();
424
425         int                                             GetPageCount() {return m_pDoc->GetPageCount();}
426         FX_BOOL                                 GetPermissions(int nFlag);
427         FX_BOOL                                 GetChangeMark() {return m_bChangeMask;}
428         void                                    SetChangeMark() {m_bChangeMask = TRUE;}
429         void                                    ClearChangeMark() {m_bChangeMask= FALSE;}
430 //      FX_BOOL                                 GetChangeMark(){return FALSE;}//IsAnnotModified()||IsFormModified() || IsWidgetModified()|| m_nChangeMark>0 ;}
431 //      void                    ClearChangeMark(){}
432         CFX_WideString                  GetPath() ;
433         CPDF_Page*                              GetPage(int nIndex);
434         CPDFDoc_Environment *   GetEnv() {return m_pEnv; }
435         void                                ProcJavascriptFun();
436         FX_BOOL                                 ProcOpenAction();
437         CPDF_OCContext*                 GetOCContext();
438 private:
439         //CFX_ArrayTemplate<CPDFSDK_PageView*> m_pageArray;
440         CFX_MapPtrTemplate<CPDF_Page*, CPDFSDK_PageView*> m_pageMap;
441         CPDF_Document*                  m_pDoc;
442
443         CPDFSDK_InterForm*              m_pInterForm;
444         CPDFSDK_Annot*                  m_pFocusAnnot;
445         CPDFDoc_Environment *   m_pEnv;
446         CPDF_OCContext *                m_pOccontent;
447         FX_BOOL                                 m_bChangeMask;
448 };
449 class CPDFSDK_PageView FX_FINAL
450 {
451 public:
452         CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc,CPDF_Page* page);
453         ~CPDFSDK_PageView();
454         void PageView_OnDraw(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,CPDF_RenderOptions* pOptions) ;
455         CPDF_Annot*                                             GetPDFAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
456         CPDFSDK_Annot*                                  GetFXAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
457         CPDF_Annot*                                             GetPDFWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
458         CPDFSDK_Annot*                                  GetFXWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
459         CPDFSDK_Annot*                                  GetFocusAnnot() ;
460         void                                                    SetFocusAnnot(CPDFSDK_Annot* pSDKAnnot,FX_UINT nFlag = 0) {m_pSDKDoc->SetFocusAnnot(pSDKAnnot, nFlag);}
461         FX_BOOL                                                 KillFocusAnnot(FX_UINT nFlag = 0) {return m_pSDKDoc->KillFocusAnnot(nFlag);}
462         FX_BOOL                                                 Annot_HasAppearance(CPDF_Annot* pAnnot);
463
464         CPDFSDK_Annot*                                  AddAnnot(CPDF_Dictionary * pDict);
465         CPDFSDK_Annot*                                  AddAnnot(FX_LPCSTR lpSubType,CPDF_Dictionary * pDict);
466         CPDFSDK_Annot*                                  AddAnnot(CPDF_Annot * pPDFAnnot);
467         FX_BOOL                                         DeleteAnnot(CPDFSDK_Annot* pAnnot);
468         int                                                             CountAnnots();
469         CPDFSDK_Annot*                                  GetAnnot(int nIndex);
470         CPDFSDK_Annot*                              GetAnnotByDict(CPDF_Dictionary * pDict);
471         CPDF_Page*                                              GetPDFPage(){return m_page;}
472         CPDF_Document*                                  GetPDFDocument();
473         CPDFSDK_Document*                               GetSDKDocument() {return m_pSDKDoc;}
474         FX_BOOL                                 OnLButtonDown(const CPDF_Point & point, FX_UINT nFlag);
475         FX_BOOL                                 OnLButtonUp(const CPDF_Point & point, FX_UINT nFlag);
476         FX_BOOL                                 OnChar(int nChar, FX_UINT nFlag);
477         FX_BOOL                                 OnKeyDown(int nKeyCode, int nFlag);
478         FX_BOOL                                 OnKeyUp(int nKeyCode, int nFlag);
479
480         FX_BOOL                                 OnMouseMove(const CPDF_Point & point, int nFlag);
481         FX_BOOL                                 OnMouseWheel(double deltaX, double deltaY,const CPDF_Point& point, int nFlag);
482         FX_BOOL                                 IsValidAnnot(FX_LPVOID p);
483         void                                    GetCurrentMatrix(CPDF_Matrix& matrix) {matrix = m_curMatrix;}
484         void                                    UpdateRects(CFX_RectArray& rects);
485         void                                                    UpdateView(CPDFSDK_Annot* pAnnot);
486         CFX_PtrArray*                                   GetAnnotList(){ return &m_fxAnnotArray; }
487
488         int                                             GetPageIndex();
489         void                                                    LoadFXAnnots();
490
491         void SetValid(FX_BOOL bValid) {m_bValid = bValid;}
492         FX_BOOL IsValid() {return m_bValid;}
493         void SetLock(FX_BOOL bLocked) {m_bLocked= bLocked;}
494         FX_BOOL IsLocked() {return m_bLocked;}
495         void TakeOverPage() {m_bTakeOverPage = TRUE;}
496 private:
497         void PageView_OnHighlightFormFields(CFX_RenderDevice* pDevice, CPDFSDK_Widget* pWidget);
498         CPDF_Matrix m_curMatrix;
499         CPDF_Page* m_page;
500         CPDF_AnnotList* m_pAnnotList;
501         //CPDFSDK_Annot* m_pFocusAnnot;
502         CFX_PtrArray  m_fxAnnotArray;
503         CPDFSDK_Document* m_pSDKDoc;
504         CPDFSDK_Widget* m_CaptureWidget;
505         FX_BOOL m_bEnterWidget;
506         FX_BOOL m_bExitWidget;
507         FX_BOOL m_bOnWidget;
508         FX_BOOL m_bValid;
509         FX_BOOL m_bLocked;
510         FX_BOOL m_bTakeOverPage;
511 };
512
513
514 template<class TYPE>
515 class CGW_ArrayTemplate : public CFX_ArrayTemplate<TYPE>
516 {
517 public:
518         CGW_ArrayTemplate(){}
519         virtual ~CGW_ArrayTemplate(){}
520
521         typedef int (*LP_COMPARE)(TYPE p1, TYPE p2);
522
523         void Sort(LP_COMPARE pCompare, FX_BOOL bAscent = TRUE)
524         {
525                 int nSize = this->GetSize();
526                 QuickSort(0, nSize -1, bAscent, pCompare);
527         }
528
529 private:
530         void QuickSort(FX_UINT nStartPos, FX_UINT nStopPos, FX_BOOL bAscend, LP_COMPARE pCompare)
531         {
532                 if (nStartPos >= nStopPos) return;
533
534                 if ((nStopPos - nStartPos) == 1)
535                 {
536                         TYPE Value1 = this->GetAt(nStartPos);
537                         TYPE Value2 = this->GetAt(nStopPos);
538
539                         int iGreate = (*pCompare)(Value1, Value2);
540                         if ((bAscend && iGreate > 0) || (!bAscend && iGreate < 0))
541                         {
542                                 this->SetAt(nStartPos, Value2);
543                                 this->SetAt(nStopPos, Value1);
544                         }
545                         return;
546                 }
547
548                 FX_UINT m = nStartPos + (nStopPos - nStartPos) / 2;
549                 FX_UINT i = nStartPos;
550
551                 TYPE Value = this->GetAt(m);
552
553                 while (i < m)
554                 {
555                         TYPE temp = this->GetAt(i);
556
557                         int iGreate = (*pCompare)(temp, Value);
558                         if ((bAscend && iGreate > 0) || (!bAscend && iGreate < 0))
559                         {
560                                 this->InsertAt(m+1, temp);
561                                 this->RemoveAt(i);
562                                 m--;
563                         }
564                         else
565                         {
566                                 i++;
567                         }
568                 }
569
570                 FX_UINT j = nStopPos;
571
572                 while (j > m)
573                 {
574                         TYPE temp = this->GetAt(j);
575
576                         int iGreate = (*pCompare)(temp, Value);
577                         if ((bAscend && iGreate < 0) || (!bAscend && iGreate > 0))
578                         {
579                                 this->RemoveAt(j);
580                                 this->InsertAt(m, temp);
581                                 m++;
582                         }
583                         else
584                         {
585                                 j--;
586                         }
587                 }
588
589                 if (nStartPos < m) QuickSort(nStartPos, m, bAscend, pCompare);
590                 if (nStopPos > m) QuickSort(m, nStopPos, bAscend, pCompare);
591         }
592 };
593
594
595 #endif //_FPDFSDK_MGR_H