Kill off JS_ErrorString type.
[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);
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         FX_BOOL                         IsJSInitiated();
336
337         void                            SetCurrentDoc(CPDFSDK_Document* pFXDoc) {m_pSDKDoc = pFXDoc;}
338         CPDFSDK_Document*       GetCurrentDoc();
339         CPDF_Document*          GetPDFDocument() {return m_pPDFDoc;}
340
341         CFX_ByteString          GetAppName() {return "";}
342
343         CFFL_IFormFiller*       GetIFormFiller();
344         IFX_SystemHandler*      GetSysHandler() {return m_pSysHandler;}
345
346         CPDFSDK_AnnotHandlerMgr* GetAnnotHandlerMgr();
347         IFXJS_Runtime*  GetJSRuntime();
348         CPDFSDK_ActionHandler* GetActionHander();
349         FPDF_FORMFILLINFO* GetFormFillInfo() {return m_pInfo;}
350
351 private:
352         CPDFSDK_AnnotHandlerMgr* m_pAnnotHandlerMgr;
353         CPDFSDK_ActionHandler*  m_pActionHandler;
354         IFXJS_Runtime*  m_pJSRuntime;
355         FPDF_FORMFILLINFO*      m_pInfo;
356         CPDFSDK_Document* m_pSDKDoc;
357         CPDF_Document* m_pPDFDoc;
358
359         CFFL_IFormFiller* m_pIFormFiller;
360         IFX_SystemHandler* m_pSysHandler;
361
362 public:
363         CJS_RuntimeFactory*  m_pJSRuntimeFactory;
364 };
365
366
367
368 class CPDFSDK_InterForm;
369 class CPDFSDK_Document
370 {
371 public:
372         CPDFSDK_Document(CPDF_Document* pDoc, CPDFDoc_Environment* pEnv);
373         ~CPDFSDK_Document();
374
375         CPDFSDK_InterForm*              GetInterForm() ;
376         CPDF_Document*                  GetDocument() {return m_pDoc;}
377
378         void                                    InitPageView();
379         void                                    AddPageView(CPDF_Page* pPDFPage, CPDFSDK_PageView* pPageView);
380         CPDFSDK_PageView*               GetPageView(CPDF_Page* pPDFPage, FX_BOOL ReNew = TRUE);
381         CPDFSDK_PageView*               GetPageView(int nIndex);
382         CPDFSDK_PageView*               GetCurrentView();
383         void                                    ReMovePageView(CPDF_Page* pPDFPage);
384         void                                    UpdateAllViews(CPDFSDK_PageView* pSender, CPDFSDK_Annot* pAnnot);
385
386         CPDFSDK_Annot*                  GetFocusAnnot();
387
388         IFXJS_Runtime *                 GetJsRuntime();
389
390         FX_BOOL                                 SetFocusAnnot(CPDFSDK_Annot* pAnnot, FX_UINT nFlag = 0);
391         FX_BOOL                                 KillFocusAnnot(FX_UINT nFlag = 0);
392
393         FX_BOOL                                 ExtractPages(const CFX_WordArray &arrExtraPages, CPDF_Document* pDstDoc);
394         FX_BOOL                                 InsertPages(int nInsertAt, const CPDF_Document* pSrcDoc, const CFX_WordArray &arrSrcPages);
395         FX_BOOL                                 DeletePages(int nStart, int nCount);
396         FX_BOOL                                 ReplacePages(int nPage, const CPDF_Document* pSrcDoc, const CFX_WordArray &arrSrcPages);
397
398         void                                    OnCloseDocument();
399
400         int                                             GetPageCount() {return m_pDoc->GetPageCount();}
401         FX_BOOL                                 GetPermissions(int nFlag);
402         FX_BOOL                                 GetChangeMark() {return m_bChangeMask;}
403         void                                    SetChangeMark() {m_bChangeMask = TRUE;}
404         void                                    ClearChangeMark() {m_bChangeMask= FALSE;}
405         CFX_WideString                  GetPath() ;
406         CPDF_Page*                              GetPage(int nIndex);
407         CPDFDoc_Environment *   GetEnv() {return m_pEnv; }
408         void                                ProcJavascriptFun();
409         FX_BOOL                                 ProcOpenAction();
410         CPDF_OCContext*                 GetOCContext();
411 private:
412         CFX_MapPtrTemplate<CPDF_Page*, CPDFSDK_PageView*> m_pageMap;
413         CPDF_Document*                  m_pDoc;
414         CPDFSDK_InterForm*              m_pInterForm;
415         CPDFSDK_Annot*                  m_pFocusAnnot;
416         CPDFDoc_Environment *   m_pEnv;
417         CPDF_OCContext *                m_pOccontent;
418         FX_BOOL                                 m_bChangeMask;
419 };
420 class CPDFSDK_PageView FX_FINAL
421 {
422 public:
423         CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc,CPDF_Page* page);
424         ~CPDFSDK_PageView();
425         void PageView_OnDraw(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,CPDF_RenderOptions* pOptions) ;
426         CPDF_Annot*                                             GetPDFAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
427         CPDFSDK_Annot*                                  GetFXAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
428         CPDF_Annot*                                             GetPDFWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
429         CPDFSDK_Annot*                                  GetFXWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
430         CPDFSDK_Annot*                                  GetFocusAnnot() ;
431         void                                                    SetFocusAnnot(CPDFSDK_Annot* pSDKAnnot,FX_UINT nFlag = 0) {m_pSDKDoc->SetFocusAnnot(pSDKAnnot, nFlag);}
432         FX_BOOL                                                 KillFocusAnnot(FX_UINT nFlag = 0) {return m_pSDKDoc->KillFocusAnnot(nFlag);}
433         FX_BOOL                                                 Annot_HasAppearance(CPDF_Annot* pAnnot);
434
435         CPDFSDK_Annot*                                  AddAnnot(CPDF_Dictionary * pDict);
436         CPDFSDK_Annot*                                  AddAnnot(FX_LPCSTR lpSubType,CPDF_Dictionary * pDict);
437         CPDFSDK_Annot*                                  AddAnnot(CPDF_Annot * pPDFAnnot);
438         FX_BOOL                                         DeleteAnnot(CPDFSDK_Annot* pAnnot);
439         int                                                             CountAnnots();
440         CPDFSDK_Annot*                                  GetAnnot(int nIndex);
441         CPDFSDK_Annot*                              GetAnnotByDict(CPDF_Dictionary * pDict);
442         CPDF_Page*                                              GetPDFPage(){return m_page;}
443         CPDF_Document*                                  GetPDFDocument();
444         CPDFSDK_Document*                               GetSDKDocument() {return m_pSDKDoc;}
445         FX_BOOL                                 OnLButtonDown(const CPDF_Point & point, FX_UINT nFlag);
446         FX_BOOL                                 OnLButtonUp(const CPDF_Point & point, FX_UINT nFlag);
447         FX_BOOL                                 OnChar(int nChar, FX_UINT nFlag);
448         FX_BOOL                                 OnKeyDown(int nKeyCode, int nFlag);
449         FX_BOOL                                 OnKeyUp(int nKeyCode, int nFlag);
450
451         FX_BOOL                                 OnMouseMove(const CPDF_Point & point, int nFlag);
452         FX_BOOL                                 OnMouseWheel(double deltaX, double deltaY,const CPDF_Point& point, int nFlag);
453         FX_BOOL                                 IsValidAnnot(FX_LPVOID p);
454         void                                    GetCurrentMatrix(CPDF_Matrix& matrix) {matrix = m_curMatrix;}
455         void                                    UpdateRects(CFX_RectArray& rects);
456         void                                                    UpdateView(CPDFSDK_Annot* pAnnot);
457         CFX_PtrArray*                                   GetAnnotList(){ return &m_fxAnnotArray; }
458
459         int                                             GetPageIndex();
460         void                                                    LoadFXAnnots();
461
462         void SetValid(FX_BOOL bValid) {m_bValid = bValid;}
463         FX_BOOL IsValid() {return m_bValid;}
464         void SetLock(FX_BOOL bLocked) {m_bLocked= bLocked;}
465         FX_BOOL IsLocked() {return m_bLocked;}
466         void TakeOverPage() {m_bTakeOverPage = TRUE;}
467 private:
468         void PageView_OnHighlightFormFields(CFX_RenderDevice* pDevice, CPDFSDK_Widget* pWidget);
469         CPDF_Matrix m_curMatrix;
470         CPDF_Page* m_page;
471         CPDF_AnnotList* m_pAnnotList;
472         //CPDFSDK_Annot* m_pFocusAnnot;
473         CFX_PtrArray  m_fxAnnotArray;
474         CPDFSDK_Document* m_pSDKDoc;
475         CPDFSDK_Widget* m_CaptureWidget;
476         FX_BOOL m_bEnterWidget;
477         FX_BOOL m_bExitWidget;
478         FX_BOOL m_bOnWidget;
479         FX_BOOL m_bValid;
480         FX_BOOL m_bLocked;
481         FX_BOOL m_bTakeOverPage;
482 };
483
484
485 template<class TYPE>
486 class CGW_ArrayTemplate : public CFX_ArrayTemplate<TYPE>
487 {
488 public:
489         CGW_ArrayTemplate(){}
490         virtual ~CGW_ArrayTemplate(){}
491
492         typedef int (*LP_COMPARE)(TYPE p1, TYPE p2);
493
494         void Sort(LP_COMPARE pCompare, FX_BOOL bAscent = TRUE)
495         {
496                 int nSize = this->GetSize();
497                 QuickSort(0, nSize -1, bAscent, pCompare);
498         }
499
500 private:
501         void QuickSort(FX_UINT nStartPos, FX_UINT nStopPos, FX_BOOL bAscend, LP_COMPARE pCompare)
502         {
503                 if (nStartPos >= nStopPos) return;
504
505                 if ((nStopPos - nStartPos) == 1)
506                 {
507                         TYPE Value1 = this->GetAt(nStartPos);
508                         TYPE Value2 = this->GetAt(nStopPos);
509
510                         int iGreate = (*pCompare)(Value1, Value2);
511                         if ((bAscend && iGreate > 0) || (!bAscend && iGreate < 0))
512                         {
513                                 this->SetAt(nStartPos, Value2);
514                                 this->SetAt(nStopPos, Value1);
515                         }
516                         return;
517                 }
518
519                 FX_UINT m = nStartPos + (nStopPos - nStartPos) / 2;
520                 FX_UINT i = nStartPos;
521
522                 TYPE Value = this->GetAt(m);
523
524                 while (i < m)
525                 {
526                         TYPE temp = this->GetAt(i);
527
528                         int iGreate = (*pCompare)(temp, Value);
529                         if ((bAscend && iGreate > 0) || (!bAscend && iGreate < 0))
530                         {
531                                 this->InsertAt(m+1, temp);
532                                 this->RemoveAt(i);
533                                 m--;
534                         }
535                         else
536                         {
537                                 i++;
538                         }
539                 }
540
541                 FX_UINT j = nStopPos;
542
543                 while (j > m)
544                 {
545                         TYPE temp = this->GetAt(j);
546
547                         int iGreate = (*pCompare)(temp, Value);
548                         if ((bAscend && iGreate < 0) || (!bAscend && iGreate > 0))
549                         {
550                                 this->RemoveAt(j);
551                                 this->InsertAt(m, temp);
552                                 m++;
553                         }
554                         else
555                         {
556                                 j--;
557                         }
558                 }
559
560                 if (nStartPos < m) QuickSort(nStartPos, m, bAscend, pCompare);
561                 if (nStopPos > m) QuickSort(m, nStopPos, bAscend, pCompare);
562         }
563 };
564
565
566 #endif //_FPDFSDK_MGR_H