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