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.
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
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"
19 //cross platform keycode and events define.
20 #include "fpdf_fwlevent.h"
23 class CPDFSDK_Document;
24 class CPDFSDK_PageView;
26 class CFFL_IFormFiller;
28 class IFX_SystemHandler;
29 class CPDFSDK_ActionHandler;
30 class CJS_RuntimeFactory;
32 #include "javascript/IJavaScript.h"
34 class CPDFDoc_Environment FX_FINAL
37 CPDFDoc_Environment(CPDF_Document * pDoc);
38 ~CPDFDoc_Environment();
40 int RegAppHandle(FPDF_FORMFILLINFO* pFFinfo);//{ m_pInfo = pFFinfo; return TRUE;}
42 void FFI_Invalidate(FPDF_PAGE page, double left, double top, double right, double bottom)
44 if (m_pInfo && m_pInfo->FFI_Invalidate)
46 m_pInfo->FFI_Invalidate(m_pInfo, page, left, top, right, bottom);
49 void FFI_OutputSelectedRect(FPDF_PAGE page, double left, double top, double right, double bottom)
51 if (m_pInfo && m_pInfo->FFI_OutputSelectedRect)
53 m_pInfo->FFI_OutputSelectedRect(m_pInfo, page, left, top, right, bottom);
57 void FFI_SetCursor(int nCursorType)
59 if (m_pInfo && m_pInfo->FFI_SetCursor)
61 m_pInfo->FFI_SetCursor(m_pInfo, nCursorType);
65 int FFI_SetTimer(int uElapse, TimerCallback lpTimerFunc)
67 if (m_pInfo && m_pInfo->FFI_SetTimer)
69 return m_pInfo->FFI_SetTimer(m_pInfo, uElapse, lpTimerFunc);
74 void FFI_KillTimer(int nTimerID)
76 if (m_pInfo && m_pInfo->FFI_KillTimer)
78 m_pInfo->FFI_KillTimer(m_pInfo, nTimerID);
81 FX_SYSTEMTIME FFI_GetLocalTime()
84 if(m_pInfo && m_pInfo->FFI_GetLocalTime)
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;
101 if(m_pInfo && m_pInfo->FFI_OnChange)
103 m_pInfo->FFI_OnChange(m_pInfo);
107 FX_BOOL FFI_IsSHIFTKeyDown(FX_DWORD nFlag)
110 return (nFlag & FWL_EVENTFLAG_ShiftKey) != 0;
112 FX_BOOL FFI_IsCTRLKeyDown(FX_DWORD nFlag)
115 return (nFlag & FWL_EVENTFLAG_ControlKey) != 0;
117 FX_BOOL FFI_IsALTKeyDown(FX_DWORD nFlag)
120 return (nFlag & FWL_EVENTFLAG_AltKey) != 0;
122 FX_BOOL FFI_IsINSERTKeyDown(FX_DWORD nFlag)
127 int JS_appAlert(FX_LPCWSTR Msg, FX_LPCWSTR Title, FX_UINT Type, FX_UINT Icon)
129 if(m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_alert)
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();
143 int JS_appResponse(FX_LPCWSTR Question, FX_LPCWSTR Title, FX_LPCWSTR Default, FX_LPCWSTR cLabel, FPDF_BOOL bPassword, void* response, int length)
145 if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_response)
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();
166 void JS_appBeep(int nType)
168 if(m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_beep)
170 m_pInfo->m_pJsPlatform->app_beep(m_pInfo->m_pJsPlatform, nType);
174 CFX_WideString JS_fieldBrowse()
176 if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->Field_browse)
178 int nRequiredLen = m_pInfo->m_pJsPlatform->Field_browse(m_pInfo->m_pJsPlatform, NULL, 0);
179 if (nRequiredLen <= 0)
182 char* pbuff = new char[nRequiredLen];
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)
193 CFX_ByteString bsRet = CFX_ByteString(pbuff, nActualLen);
194 CFX_WideString wsRet = CFX_WideString::FromLocal(bsRet);
201 CFX_WideString JS_docGetFilePath()
203 if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->Doc_getFilePath)
205 int nRequiredLen = m_pInfo->m_pJsPlatform->Doc_getFilePath(m_pInfo->m_pJsPlatform, NULL, 0);
206 if (nRequiredLen <= 0)
209 char* pbuff = new char[nRequiredLen];
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)
220 CFX_ByteString bsRet = CFX_ByteString(pbuff, nActualLen);
221 CFX_WideString wsRet = CFX_WideString::FromLocal(bsRet);
228 void JS_docSubmitForm(void* formData, int length, FX_LPCWSTR URL)
230 if(m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->Doc_submitForm)
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();
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)
241 if(m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->Doc_mail)
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,
255 bsTo.ReleaseBuffer();
256 bsCC.ReleaseBuffer();
257 bsBcc.ReleaseBuffer();
258 bsSubject.ReleaseBuffer();
259 bsMsg.ReleaseBuffer();
262 CFX_WideString JS_appbrowseForDoc(FPDF_BOOL bSave, FX_LPCWSTR cFilenameInit)
266 // if(m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_browseForDoc)
268 // CFX_ByteString bsFilenameInit = CFX_WideString(cFilenameInit).UTF16LE_Encode();
269 // FPDF_WIDESTRING pFileNameInit = (FPDF_WIDESTRING)bsFilenameInit.GetBuffer(bsFilenameInit.GetLength());
271 // m_pInfo->m_pJsPlatform->app_browseForDoc(m_pInfo->m_pJsPlatform, pFileNameInit);
272 // bsFilenameInit.ReleaseBuffer();
276 void JS_docprint(FPDF_BOOL bUI , int nStart, int nEnd, FPDF_BOOL bSilent ,FPDF_BOOL bShrinkToFit,FPDF_BOOL bPrintAsImage ,FPDF_BOOL bReverse ,FPDF_BOOL bAnnotations)
278 if(m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->Doc_print)
280 m_pInfo->m_pJsPlatform->Doc_print(m_pInfo->m_pJsPlatform, bUI, nStart, nEnd, bSilent, bShrinkToFit, bPrintAsImage, bReverse, bAnnotations);
283 void JS_docgotoPage(int nPageNum)
285 if(m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->Doc_gotoPage)
287 m_pInfo->m_pJsPlatform->Doc_gotoPage(m_pInfo->m_pJsPlatform, nPageNum);
291 FPDF_PAGE FFI_GetPage(FPDF_DOCUMENT document,int nPageIndex)
293 if(m_pInfo && m_pInfo->FFI_GetPage)
295 return m_pInfo->FFI_GetPage(m_pInfo, document, nPageIndex);
300 FPDF_PAGE FFI_GetCurrentPage(FPDF_DOCUMENT document)
302 if(m_pInfo && m_pInfo->FFI_GetCurrentPage)
304 return m_pInfo->FFI_GetCurrentPage(m_pInfo, document);
309 int FFI_GetRotation(FPDF_PAGE page)
311 if(m_pInfo && m_pInfo->FFI_GetRotation)
313 return m_pInfo->FFI_GetRotation(m_pInfo, page);
317 void FFI_ExecuteNamedAction(FX_LPCSTR namedAction)
319 if(m_pInfo && m_pInfo->FFI_ExecuteNamedAction)
321 m_pInfo->FFI_ExecuteNamedAction(m_pInfo, namedAction);
324 void FFI_OnSetFieldInputFocus(void* field,FPDF_WIDESTRING focusText, FPDF_DWORD nTextLen, FX_BOOL bFocus)
326 if(m_pInfo && m_pInfo->FFI_SetTextFieldFocus)
328 m_pInfo->FFI_SetTextFieldFocus(m_pInfo, focusText, nTextLen, bFocus);
332 void FFI_DoURIAction(FX_LPCSTR bsURI)
334 if(m_pInfo && m_pInfo->FFI_DoURIAction)
336 m_pInfo->FFI_DoURIAction(m_pInfo, bsURI);
340 void FFI_DoGoToAction(int nPageIndex, int zoomMode, float* fPosArray, int sizeOfArray)
342 if(m_pInfo && m_pInfo->FFI_DoGoToAction)
344 m_pInfo->FFI_DoGoToAction(m_pInfo, nPageIndex, zoomMode, fPosArray, sizeOfArray);
349 FX_BOOL IsJSInitiated();
352 void SetCurrentDoc(CPDFSDK_Document* pFXDoc) {m_pSDKDoc = pFXDoc;}
353 CPDFSDK_Document* GetCurrentDoc();
354 CPDF_Document* GetPDFDocument() {return m_pPDFDoc;}
355 // CPDFSDK_Document* GetDocument(int nIndex);
356 // int CountDocuments() {return m_docMap.GetCount();}
358 CPDFSDK_Document* OpenDocument(CFX_WideString &fileName);
359 CPDFSDK_Document* OpenMemPDFDoc(CPDF_Document* pNewDoc, CFX_WideString &fileName);
360 FX_BOOL OpenURL(CFX_WideString &filePath);
363 CFX_ByteString GetAppName() {return "";}
365 CFFL_IFormFiller* GetIFormFiller();
366 IFX_SystemHandler* GetSysHandler() {return m_pSysHandler;}
369 CPDFSDK_AnnotHandlerMgr* GetAnnotHandlerMgr();
370 IFXJS_Runtime* GetJSRuntime();
371 CPDFSDK_ActionHandler* GetActionHander();
373 CPDFSDK_AnnotHandlerMgr* m_pAnnotHandlerMgr;
374 CPDFSDK_ActionHandler* m_pActionHandler;
375 IFXJS_Runtime* m_pJSRuntime;
377 FPDF_FORMFILLINFO* GetFormFillInfo() {return m_pInfo;}
379 FPDF_FORMFILLINFO* m_pInfo;
380 // CFX_MapPtrTemplate<CPDF_Document*, CPDFSDK_Document*> m_docMap;
381 CPDFSDK_Document* m_pSDKDoc;
382 CPDF_Document* m_pPDFDoc;
384 CFFL_IFormFiller* m_pIFormFiller;
385 IFX_SystemHandler* m_pSysHandler;
388 CJS_RuntimeFactory* m_pJSRuntimeFactory;
396 // CFX_App():m_pCurDoc(NULL) {}
397 // void SetAt(CPDF_Document* pPDFDoc, CPDFSDK_Document* pFXDoc);
398 // CPDFSDK_Document* GetAt(CPDF_Document* pPDFDoc);
400 // void SetCurrentDocument(CPDFSDK_Document* pFXDoc) {m_pCurDoc = pFXDoc;}
401 // CPDFSDK_Document* GetCurrentDocument() {return m_pCurDoc;}
403 // CFX_MapPtrTemplate<CPDF_Document*, CPDFSDK_Document*> m_docArray;
404 // CPDFSDK_Document* m_pCurDoc;
406 class CPDFSDK_InterForm;
407 class CPDFSDK_Document
410 CPDFSDK_Document(CPDF_Document* pDoc, CPDFDoc_Environment* pEnv);
413 CPDFSDK_InterForm* GetInterForm() ;
414 CPDF_Document* GetDocument() {return m_pDoc;}
418 void AddPageView(CPDF_Page* pPDFPage, CPDFSDK_PageView* pPageView);
419 CPDFSDK_PageView* GetPageView(CPDF_Page* pPDFPage, FX_BOOL ReNew = TRUE);
420 CPDFSDK_PageView* GetPageView(int nIndex);
421 CPDFSDK_PageView* GetCurrentView();
422 void ReMovePageView(CPDF_Page* pPDFPage);
423 void UpdateAllViews(CPDFSDK_PageView* pSender, CPDFSDK_Annot* pAnnot);
425 CPDFSDK_Annot* GetFocusAnnot();//{return NULL;}
427 IFXJS_Runtime * GetJsRuntime();
429 FX_BOOL SetFocusAnnot(CPDFSDK_Annot* pAnnot, FX_UINT nFlag = 0);//{return FALSE;}
430 FX_BOOL KillFocusAnnot(FX_UINT nFlag = 0);
432 FX_BOOL ExtractPages(const CFX_WordArray &arrExtraPages, CPDF_Document* pDstDoc);
433 FX_BOOL InsertPages(int nInsertAt, const CPDF_Document* pSrcDoc, const CFX_WordArray &arrSrcPages);
434 FX_BOOL DeletePages(int nStart, int nCount);
435 FX_BOOL ReplacePages(int nPage, const CPDF_Document* pSrcDoc, const CFX_WordArray &arrSrcPages);
437 void OnCloseDocument();
439 int GetPageCount() {return m_pDoc->GetPageCount();}
440 FX_BOOL GetPermissions(int nFlag);
441 FX_BOOL GetChangeMark() {return m_bChangeMask;}
442 void SetChangeMark() {m_bChangeMask = TRUE;}
443 void ClearChangeMark() {m_bChangeMask= FALSE;}
444 // FX_BOOL GetChangeMark(){return FALSE;}//IsAnnotModified()||IsFormModified() || IsWidgetModified()|| m_nChangeMark>0 ;}
445 // void ClearChangeMark(){}
446 CFX_WideString GetPath() ;
447 CPDF_Page* GetPage(int nIndex);
448 CPDFDoc_Environment * GetEnv() {return m_pEnv; }
449 void ProcJavascriptFun();
450 FX_BOOL ProcOpenAction();
451 CPDF_OCContext* GetOCContext();
453 //CFX_ArrayTemplate<CPDFSDK_PageView*> m_pageArray;
454 CFX_MapPtrTemplate<CPDF_Page*, CPDFSDK_PageView*> m_pageMap;
455 CPDF_Document* m_pDoc;
457 CPDFSDK_InterForm* m_pInterForm;
458 CPDFSDK_Annot* m_pFocusAnnot;
459 CPDFDoc_Environment * m_pEnv;
460 CPDF_OCContext * m_pOccontent;
461 FX_BOOL m_bChangeMask;
464 class CPDFSDK_PageView FX_FINAL
467 CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc,CPDF_Page* page);
470 void PageView_OnDraw(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,CPDF_RenderOptions* pOptions) ;
472 CPDF_Annot* GetPDFAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
473 CPDFSDK_Annot* GetFXAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
474 CPDF_Annot* GetPDFWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
475 CPDFSDK_Annot* GetFXWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
476 CPDFSDK_Annot* GetFocusAnnot() ;
477 void SetFocusAnnot(CPDFSDK_Annot* pSDKAnnot,FX_UINT nFlag = 0) {m_pSDKDoc->SetFocusAnnot(pSDKAnnot, nFlag);}
478 FX_BOOL KillFocusAnnot(FX_UINT nFlag = 0) {return m_pSDKDoc->KillFocusAnnot(nFlag);}
479 FX_BOOL Annot_HasAppearance(CPDF_Annot* pAnnot);
481 CPDFSDK_Annot* AddAnnot(CPDF_Dictionary * pDict);
482 CPDFSDK_Annot* AddAnnot(FX_LPCSTR lpSubType,CPDF_Dictionary * pDict);
483 CPDFSDK_Annot* AddAnnot(CPDF_Annot * pPDFAnnot);
484 FX_BOOL DeleteAnnot(CPDFSDK_Annot* pAnnot);
487 CPDFSDK_Annot* GetAnnot(int nIndex);
488 CPDFSDK_Annot* GetAnnotByDict(CPDF_Dictionary * pDict);
489 CPDF_Page* GetPDFPage(){return m_page;}
490 CPDF_Document* GetPDFDocument();
491 CPDFSDK_Document* GetSDKDocument() {return m_pSDKDoc;}
493 FX_BOOL OnLButtonDown(const CPDF_Point & point, FX_UINT nFlag);
494 FX_BOOL OnLButtonUp(const CPDF_Point & point, FX_UINT nFlag);
495 FX_BOOL OnChar(int nChar, FX_UINT nFlag);
496 FX_BOOL OnKeyDown(int nKeyCode, int nFlag);
497 FX_BOOL OnKeyUp(int nKeyCode, int nFlag);
499 FX_BOOL OnMouseMove(const CPDF_Point & point, int nFlag);
500 FX_BOOL OnMouseWheel(double deltaX, double deltaY,const CPDF_Point& point, int nFlag);
501 FX_BOOL IsValidAnnot(FX_LPVOID p);
503 void GetCurrentMatrix(CPDF_Matrix& matrix) {matrix = m_curMatrix;}
504 void UpdateRects(CFX_RectArray& rects);
505 void UpdateView(CPDFSDK_Annot* pAnnot);
506 CFX_PtrArray* GetAnnotList(){ return &m_fxAnnotArray; }
512 CPDF_Matrix m_curMatrix;
515 void PageView_OnHighlightFormFields(CFX_RenderDevice* pDevice, CPDFSDK_Widget* pWidget);
519 CPDF_AnnotList* m_pAnnotList;
521 //CPDFSDK_Annot* m_pFocusAnnot;
522 CFX_PtrArray m_fxAnnotArray;
524 CPDFSDK_Document* m_pSDKDoc;
526 CPDFSDK_Widget* m_CaptureWidget;
527 FX_BOOL m_bEnterWidget;
528 FX_BOOL m_bExitWidget;
531 void SetValid(FX_BOOL bValid) {m_bValid = bValid;}
532 FX_BOOL IsValid() {return m_bValid;}
539 class CGW_ArrayTemplate : public CFX_ArrayTemplate<TYPE>
542 CGW_ArrayTemplate(){}
543 virtual ~CGW_ArrayTemplate(){}
545 typedef int (*LP_COMPARE)(TYPE p1, TYPE p2);
547 void Sort(LP_COMPARE pCompare, FX_BOOL bAscent = TRUE)
549 int nSize = this->GetSize();
550 QuickSort(0, nSize -1, bAscent, pCompare);
554 void QuickSort(FX_UINT nStartPos, FX_UINT nStopPos, FX_BOOL bAscend, LP_COMPARE pCompare)
556 if (nStartPos >= nStopPos) return;
558 if ((nStopPos - nStartPos) == 1)
560 TYPE Value1 = this->GetAt(nStartPos);
561 TYPE Value2 = this->GetAt(nStopPos);
563 int iGreate = (*pCompare)(Value1, Value2);
564 if ((bAscend && iGreate > 0) || (!bAscend && iGreate < 0))
566 this->SetAt(nStartPos, Value2);
567 this->SetAt(nStopPos, Value1);
572 FX_UINT m = nStartPos + (nStopPos - nStartPos) / 2;
573 FX_UINT i = nStartPos;
575 TYPE Value = this->GetAt(m);
579 TYPE temp = this->GetAt(i);
581 int iGreate = (*pCompare)(temp, Value);
582 if ((bAscend && iGreate > 0) || (!bAscend && iGreate < 0))
584 this->InsertAt(m+1, temp);
594 FX_UINT j = nStopPos;
598 TYPE temp = this->GetAt(j);
600 int iGreate = (*pCompare)(temp, Value);
601 if ((bAscend && iGreate < 0) || (!bAscend && iGreate > 0))
604 this->InsertAt(m, temp);
613 if (nStartPos < m) QuickSort(nStartPos, m, bAscend, pCompare);
614 if (nStopPos > m) QuickSort(m, nStopPos, bAscend, pCompare);
619 #endif //_FPDFSDK_MGR_H