167d0d6fcd282f9103867e76eca1ba9e525948fd
[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     CFX_WideString JS_docGetFilePath();
176
177         void JS_docSubmitForm(void* formData, int length, const FX_WCHAR* URL)
178         {
179                 if(m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->Doc_submitForm)
180                 {
181                         CFX_ByteString bsDestination = CFX_WideString(URL).UTF16LE_Encode();
182                         FPDF_WIDESTRING pDestination = (FPDF_WIDESTRING)bsDestination.GetBuffer(bsDestination.GetLength());
183                         m_pInfo->m_pJsPlatform->Doc_submitForm(m_pInfo->m_pJsPlatform, formData, length, pDestination);
184                         bsDestination.ReleaseBuffer();
185                 }
186         }
187
188         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)
189         {
190                 if(m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->Doc_mail)
191                 {
192                         CFX_ByteString bsTo = CFX_WideString(To).UTF16LE_Encode();
193                         CFX_ByteString bsCC = CFX_WideString(Subject).UTF16LE_Encode();
194                         CFX_ByteString bsBcc = CFX_WideString(BCC).UTF16LE_Encode();
195                         CFX_ByteString bsSubject = CFX_WideString(Subject).UTF16LE_Encode();
196                         CFX_ByteString bsMsg = CFX_WideString(Msg).UTF16LE_Encode();
197                         FPDF_WIDESTRING pTo = (FPDF_WIDESTRING)bsTo.GetBuffer(bsTo.GetLength());
198                         FPDF_WIDESTRING pCC = (FPDF_WIDESTRING)bsCC.GetBuffer(bsCC.GetLength());
199                         FPDF_WIDESTRING pBcc = (FPDF_WIDESTRING)bsBcc.GetBuffer(bsBcc.GetLength());
200                         FPDF_WIDESTRING pSubject = (FPDF_WIDESTRING)bsSubject.GetBuffer(bsSubject.GetLength());
201                         FPDF_WIDESTRING pMsg = (FPDF_WIDESTRING)bsMsg.GetBuffer(bsMsg.GetLength());
202                         m_pInfo->m_pJsPlatform->Doc_mail(m_pInfo->m_pJsPlatform, mailData, length, bUI, pTo, pSubject,
203                                 pCC, pBcc, pMsg);
204                         bsTo.ReleaseBuffer();
205                         bsCC.ReleaseBuffer();
206                         bsBcc.ReleaseBuffer();
207                         bsSubject.ReleaseBuffer();
208                         bsMsg.ReleaseBuffer();
209                 }
210         }
211
212         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)
213         {
214                 if(m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->Doc_print)
215                 {
216                         m_pInfo->m_pJsPlatform->Doc_print(m_pInfo->m_pJsPlatform, bUI, nStart, nEnd, bSilent, bShrinkToFit, bPrintAsImage, bReverse, bAnnotations);
217                 }
218         }
219         void JS_docgotoPage(int nPageNum)
220         {
221                 if(m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->Doc_gotoPage)
222                 {
223                         m_pInfo->m_pJsPlatform->Doc_gotoPage(m_pInfo->m_pJsPlatform, nPageNum);
224                 }
225         }
226
227         FPDF_PAGE       FFI_GetPage(FPDF_DOCUMENT document,int nPageIndex)
228         {
229                 if(m_pInfo && m_pInfo->FFI_GetPage)
230                 {
231                         return m_pInfo->FFI_GetPage(m_pInfo, document, nPageIndex);
232                 }
233                 return NULL;
234         }
235
236         FPDF_PAGE FFI_GetCurrentPage(FPDF_DOCUMENT document)
237         {
238                 if(m_pInfo && m_pInfo->FFI_GetCurrentPage)
239                 {
240                         return m_pInfo->FFI_GetCurrentPage(m_pInfo, document);
241                 }
242                 return NULL;
243         }
244
245         int     FFI_GetRotation(FPDF_PAGE page)
246         {
247                 if(m_pInfo && m_pInfo->FFI_GetRotation)
248                 {
249                         return m_pInfo->FFI_GetRotation(m_pInfo, page);
250                 }
251                 return 0;
252         }
253         void    FFI_ExecuteNamedAction(const FX_CHAR* namedAction)
254         {
255                 if(m_pInfo && m_pInfo->FFI_ExecuteNamedAction)
256                 {
257                         m_pInfo->FFI_ExecuteNamedAction(m_pInfo, namedAction);
258                 }
259         }
260         void    FFI_OnSetFieldInputFocus(void* field,FPDF_WIDESTRING focusText, FPDF_DWORD nTextLen, FX_BOOL bFocus)
261         {
262                 if(m_pInfo && m_pInfo->FFI_SetTextFieldFocus)
263                 {
264                         m_pInfo->FFI_SetTextFieldFocus(m_pInfo, focusText, nTextLen, bFocus);
265                 }
266         }
267
268         void    FFI_DoURIAction(const FX_CHAR* bsURI)
269         {
270                 if(m_pInfo && m_pInfo->FFI_DoURIAction)
271                 {
272                         m_pInfo->FFI_DoURIAction(m_pInfo, bsURI);
273                 }
274         }
275
276         void    FFI_DoGoToAction(int nPageIndex, int zoomMode, float* fPosArray, int sizeOfArray)
277         {
278                 if(m_pInfo && m_pInfo->FFI_DoGoToAction)
279                 {
280                         m_pInfo->FFI_DoGoToAction(m_pInfo, nPageIndex, zoomMode, fPosArray, sizeOfArray);
281                 }
282         }
283
284         FX_BOOL                         IsJSInitiated();
285
286         void                            SetCurrentDoc(CPDFSDK_Document* pFXDoc) {m_pSDKDoc = pFXDoc;}
287         CPDFSDK_Document*       GetCurrentDoc();
288         CPDF_Document*          GetPDFDocument() {return m_pPDFDoc;}
289
290         CFX_ByteString          GetAppName() {return "";}
291
292         CFFL_IFormFiller*       GetIFormFiller();
293         IFX_SystemHandler*      GetSysHandler() {return m_pSysHandler;}
294
295         CPDFSDK_AnnotHandlerMgr* GetAnnotHandlerMgr();
296         IFXJS_Runtime*  GetJSRuntime();
297         CPDFSDK_ActionHandler* GetActionHander();
298         FPDF_FORMFILLINFO* GetFormFillInfo() {return m_pInfo;}
299
300 private:
301         CPDFSDK_AnnotHandlerMgr* m_pAnnotHandlerMgr;
302         CPDFSDK_ActionHandler*  m_pActionHandler;
303         IFXJS_Runtime*  m_pJSRuntime;
304         FPDF_FORMFILLINFO*      m_pInfo;
305         CPDFSDK_Document* m_pSDKDoc;
306         CPDF_Document* m_pPDFDoc;
307
308         CFFL_IFormFiller* m_pIFormFiller;
309         IFX_SystemHandler* m_pSysHandler;
310
311 public:
312         CJS_RuntimeFactory*  m_pJSRuntimeFactory;
313 };
314
315
316
317 class CPDFSDK_InterForm;
318 class CPDFSDK_Document
319 {
320 public:
321         CPDFSDK_Document(CPDF_Document* pDoc, CPDFDoc_Environment* pEnv);
322         ~CPDFSDK_Document();
323
324         CPDFSDK_InterForm*              GetInterForm() ;
325         CPDF_Document*                  GetDocument() {return m_pDoc;}
326
327         CPDFSDK_PageView*               GetPageView(CPDF_Page* pPDFPage, FX_BOOL ReNew = TRUE);
328         CPDFSDK_PageView*               GetPageView(int nIndex);
329         CPDFSDK_PageView*               GetCurrentView();
330         void                                    ReMovePageView(CPDF_Page* pPDFPage);
331         void                                    UpdateAllViews(CPDFSDK_PageView* pSender, CPDFSDK_Annot* pAnnot);
332
333         CPDFSDK_Annot*                  GetFocusAnnot();
334
335         IFXJS_Runtime *                 GetJsRuntime();
336
337         FX_BOOL                                 SetFocusAnnot(CPDFSDK_Annot* pAnnot, FX_UINT nFlag = 0);
338         FX_BOOL                                 KillFocusAnnot(FX_UINT nFlag = 0);
339
340         FX_BOOL                                 ExtractPages(const CFX_WordArray &arrExtraPages, CPDF_Document* pDstDoc);
341         FX_BOOL                                 InsertPages(int nInsertAt, const CPDF_Document* pSrcDoc, const CFX_WordArray &arrSrcPages);
342         FX_BOOL                                 ReplacePages(int nPage, const CPDF_Document* pSrcDoc, const CFX_WordArray &arrSrcPages);
343
344         void                                    OnCloseDocument();
345
346         int                                             GetPageCount() {return m_pDoc->GetPageCount();}
347         FX_BOOL                                 GetPermissions(int nFlag);
348         FX_BOOL                                 GetChangeMark() {return m_bChangeMask;}
349         void                                    SetChangeMark() {m_bChangeMask = TRUE;}
350         void                                    ClearChangeMark() {m_bChangeMask= FALSE;}
351         CFX_WideString                  GetPath() ;
352         CPDF_Page*                              GetPage(int nIndex);
353         CPDFDoc_Environment *   GetEnv() {return m_pEnv; }
354         void                                ProcJavascriptFun();
355         FX_BOOL                                 ProcOpenAction();
356         CPDF_OCContext*                 GetOCContext();
357 private:
358     std::map<CPDF_Page*, CPDFSDK_PageView*> m_pageMap;
359     CPDF_Document* m_pDoc;
360     CPDFSDK_InterForm* m_pInterForm;
361     CPDFSDK_Annot* m_pFocusAnnot;
362     CPDFDoc_Environment* m_pEnv;
363     CPDF_OCContext* m_pOccontent;
364     FX_BOOL m_bChangeMask;
365 };
366 class CPDFSDK_PageView final
367 {
368 public:
369         CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc,CPDF_Page* page);
370         ~CPDFSDK_PageView();
371         void PageView_OnDraw(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,CPDF_RenderOptions* pOptions) ;
372         CPDF_Annot*                                             GetPDFAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
373         CPDFSDK_Annot*                                  GetFXAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
374         CPDF_Annot*                                             GetPDFWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
375         CPDFSDK_Annot*                                  GetFXWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
376         CPDFSDK_Annot*                                  GetFocusAnnot() ;
377         void                                                    SetFocusAnnot(CPDFSDK_Annot* pSDKAnnot,FX_UINT nFlag = 0) {m_pSDKDoc->SetFocusAnnot(pSDKAnnot, nFlag);}
378         FX_BOOL                                                 KillFocusAnnot(FX_UINT nFlag = 0) {return m_pSDKDoc->KillFocusAnnot(nFlag);}
379         FX_BOOL                                                 Annot_HasAppearance(CPDF_Annot* pAnnot);
380
381         CPDFSDK_Annot*                                  AddAnnot(CPDF_Dictionary * pDict);
382         CPDFSDK_Annot*                                  AddAnnot(const FX_CHAR* lpSubType,CPDF_Dictionary * pDict);
383         CPDFSDK_Annot*                                  AddAnnot(CPDF_Annot * pPDFAnnot);
384         FX_BOOL                                         DeleteAnnot(CPDFSDK_Annot* pAnnot);
385         int                                                             CountAnnots();
386         CPDFSDK_Annot*                                  GetAnnot(int nIndex);
387         CPDFSDK_Annot*                              GetAnnotByDict(CPDF_Dictionary * pDict);
388         CPDF_Page*                                              GetPDFPage(){return m_page;}
389         CPDF_Document*                                  GetPDFDocument();
390         CPDFSDK_Document*                               GetSDKDocument() {return m_pSDKDoc;}
391         FX_BOOL                                 OnLButtonDown(const CPDF_Point & point, FX_UINT nFlag);
392         FX_BOOL                                 OnLButtonUp(const CPDF_Point & point, FX_UINT nFlag);
393         FX_BOOL                                 OnChar(int nChar, FX_UINT nFlag);
394         FX_BOOL                                 OnKeyDown(int nKeyCode, int nFlag);
395         FX_BOOL                                 OnKeyUp(int nKeyCode, int nFlag);
396
397         FX_BOOL                                 OnMouseMove(const CPDF_Point & point, int nFlag);
398         FX_BOOL                                 OnMouseWheel(double deltaX, double deltaY,const CPDF_Point& point, int nFlag);
399         FX_BOOL                                 IsValidAnnot(void* p);
400         void                                    GetCurrentMatrix(CPDF_Matrix& matrix) {matrix = m_curMatrix;}
401         void                                    UpdateRects(CFX_RectArray& rects);
402         void                                                    UpdateView(CPDFSDK_Annot* pAnnot);
403         CFX_PtrArray*                                   GetAnnotList(){ return &m_fxAnnotArray; }
404
405         int                                             GetPageIndex();
406         void                                                    LoadFXAnnots();
407
408         void SetValid(FX_BOOL bValid) {m_bValid = bValid;}
409         FX_BOOL IsValid() {return m_bValid;}
410         void SetLock(FX_BOOL bLocked) {m_bLocked= bLocked;}
411         FX_BOOL IsLocked() {return m_bLocked;}
412         void TakeOverPage() {m_bTakeOverPage = TRUE;}
413 private:
414         void PageView_OnHighlightFormFields(CFX_RenderDevice* pDevice, CPDFSDK_Widget* pWidget);
415         CPDF_Matrix m_curMatrix;
416         CPDF_Page* m_page;
417         CPDF_AnnotList* m_pAnnotList;
418         //CPDFSDK_Annot* m_pFocusAnnot;
419         CFX_PtrArray  m_fxAnnotArray;
420         CPDFSDK_Document* m_pSDKDoc;
421         CPDFSDK_Widget* m_CaptureWidget;
422         FX_BOOL m_bEnterWidget;
423         FX_BOOL m_bExitWidget;
424         FX_BOOL m_bOnWidget;
425         FX_BOOL m_bValid;
426         FX_BOOL m_bLocked;
427         FX_BOOL m_bTakeOverPage;
428 };
429
430
431 template<class TYPE>
432 class CGW_ArrayTemplate : public CFX_ArrayTemplate<TYPE>
433 {
434 public:
435         CGW_ArrayTemplate(){}
436         virtual ~CGW_ArrayTemplate(){}
437
438         typedef int (*LP_COMPARE)(TYPE p1, TYPE p2);
439
440         void Sort(LP_COMPARE pCompare, FX_BOOL bAscent = TRUE)
441         {
442                 int nSize = this->GetSize();
443                 QuickSort(0, nSize -1, bAscent, pCompare);
444         }
445
446 private:
447         void QuickSort(FX_UINT nStartPos, FX_UINT nStopPos, FX_BOOL bAscend, LP_COMPARE pCompare)
448         {
449                 if (nStartPos >= nStopPos) return;
450
451                 if ((nStopPos - nStartPos) == 1)
452                 {
453                         TYPE Value1 = this->GetAt(nStartPos);
454                         TYPE Value2 = this->GetAt(nStopPos);
455
456                         int iGreate = (*pCompare)(Value1, Value2);
457                         if ((bAscend && iGreate > 0) || (!bAscend && iGreate < 0))
458                         {
459                                 this->SetAt(nStartPos, Value2);
460                                 this->SetAt(nStopPos, Value1);
461                         }
462                         return;
463                 }
464
465                 FX_UINT m = nStartPos + (nStopPos - nStartPos) / 2;
466                 FX_UINT i = nStartPos;
467
468                 TYPE Value = this->GetAt(m);
469
470                 while (i < m)
471                 {
472                         TYPE temp = this->GetAt(i);
473
474                         int iGreate = (*pCompare)(temp, Value);
475                         if ((bAscend && iGreate > 0) || (!bAscend && iGreate < 0))
476                         {
477                                 this->InsertAt(m+1, temp);
478                                 this->RemoveAt(i);
479                                 m--;
480                         }
481                         else
482                         {
483                                 i++;
484                         }
485                 }
486
487                 FX_UINT j = nStopPos;
488
489                 while (j > m)
490                 {
491                         TYPE temp = this->GetAt(j);
492
493                         int iGreate = (*pCompare)(temp, Value);
494                         if ((bAscend && iGreate < 0) || (!bAscend && iGreate > 0))
495                         {
496                                 this->RemoveAt(j);
497                                 this->InsertAt(m, temp);
498                                 m++;
499                         }
500                         else
501                         {
502                                 j--;
503                         }
504                 }
505
506                 if (nStartPos < m) QuickSort(nStartPos, m, bAscend, pCompare);
507                 if (nStopPos > m) QuickSort(m, nStopPos, bAscend, pCompare);
508         }
509 };
510
511 #endif  // FPDFSDK_INCLUDE_FSDK_MGR_H_