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
37 CPDFDoc_Environment(CPDF_Document * pDoc);
38 ~CPDFDoc_Environment();
40 int RegAppHandle(FPDF_FORMFILLINFO* pFFinfo);//{ m_pInfo = pFFinfo; return TRUE;}
42 virtual void Release()
44 if (m_pInfo && m_pInfo->Release)
45 m_pInfo->Release(m_pInfo);
49 virtual void FFI_Invalidate(FPDF_PAGE page, double left, double top, double right, double bottom)
51 if (m_pInfo && m_pInfo->FFI_Invalidate)
53 m_pInfo->FFI_Invalidate(m_pInfo, page, left, top, right, bottom);
56 virtual void FFI_OutputSelectedRect(FPDF_PAGE page, double left, double top, double right, double bottom)
58 if (m_pInfo && m_pInfo->FFI_OutputSelectedRect)
60 m_pInfo->FFI_OutputSelectedRect(m_pInfo, page, left, top, right, bottom);
64 virtual void FFI_SetCursor(int nCursorType)
66 if (m_pInfo && m_pInfo->FFI_SetCursor)
68 m_pInfo->FFI_SetCursor(m_pInfo, nCursorType);
72 virtual int FFI_SetTimer(int uElapse, TimerCallback lpTimerFunc)
74 if (m_pInfo && m_pInfo->FFI_SetTimer)
76 return m_pInfo->FFI_SetTimer(m_pInfo, uElapse, lpTimerFunc);
81 virtual void FFI_KillTimer(int nTimerID)
83 if (m_pInfo && m_pInfo->FFI_KillTimer)
85 m_pInfo->FFI_KillTimer(m_pInfo, nTimerID);
88 FX_SYSTEMTIME FFI_GetLocalTime()
91 if(m_pInfo && m_pInfo->FFI_GetLocalTime)
93 FPDF_SYSTEMTIME systime = m_pInfo->FFI_GetLocalTime(m_pInfo);
94 fxtime.wDay = systime.wDay;
95 fxtime.wDayOfWeek = systime.wDayOfWeek;
96 fxtime.wHour = systime.wHour;
97 fxtime.wMilliseconds = systime.wMilliseconds;
98 fxtime.wMinute = systime.wMinute;
99 fxtime.wMonth = systime.wMonth;
100 fxtime.wSecond = systime.wSecond;
101 fxtime.wYear = systime.wYear;
106 virtual void FFI_OnChange()
108 if(m_pInfo && m_pInfo->FFI_OnChange)
110 m_pInfo->FFI_OnChange(m_pInfo);
114 virtual FX_BOOL FFI_IsSHIFTKeyDown(FX_DWORD nFlag)
117 return (nFlag & FWL_EVENTFLAG_ShiftKey) != 0;
119 virtual FX_BOOL FFI_IsCTRLKeyDown(FX_DWORD nFlag)
122 return (nFlag & FWL_EVENTFLAG_ControlKey) != 0;
124 virtual FX_BOOL FFI_IsALTKeyDown(FX_DWORD nFlag)
127 return (nFlag & FWL_EVENTFLAG_AltKey) != 0;
129 virtual FX_BOOL FFI_IsINSERTKeyDown(FX_DWORD nFlag)
134 virtual int JS_appAlert(FX_LPCWSTR Msg, FX_LPCWSTR Title, FX_UINT Type, FX_UINT Icon)
136 if(m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_alert)
138 CFX_ByteString bsMsg = CFX_WideString(Msg).UTF16LE_Encode();
139 CFX_ByteString bsTitle = CFX_WideString(Title).UTF16LE_Encode();
140 FPDF_WIDESTRING pMsg = (FPDF_WIDESTRING)bsMsg.GetBuffer(bsMsg.GetLength());
141 FPDF_WIDESTRING pTitle = (FPDF_WIDESTRING)bsTitle.GetBuffer(bsTitle.GetLength());
142 int ret = m_pInfo->m_pJsPlatform->app_alert(m_pInfo->m_pJsPlatform, pMsg, pTitle, Type, Icon);
143 bsMsg.ReleaseBuffer();
144 bsTitle.ReleaseBuffer();
150 virtual int JS_appResponse(FX_LPCWSTR Question, FX_LPCWSTR Title, FX_LPCWSTR Default, FX_LPCWSTR cLabel, FPDF_BOOL bPassword, void* response, int length)
152 if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_response)
154 CFX_ByteString bsQuestion = CFX_WideString(Question).UTF16LE_Encode();
155 CFX_ByteString bsTitle = CFX_WideString(Title).UTF16LE_Encode();
156 CFX_ByteString bsDefault = CFX_WideString(Default).UTF16LE_Encode();
157 CFX_ByteString bsLabel = CFX_WideString(cLabel).UTF16LE_Encode();
158 FPDF_WIDESTRING pQuestion = (FPDF_WIDESTRING)bsQuestion.GetBuffer(bsQuestion.GetLength());
159 FPDF_WIDESTRING pTitle = (FPDF_WIDESTRING)bsTitle.GetBuffer(bsTitle.GetLength());
160 FPDF_WIDESTRING pDefault = (FPDF_WIDESTRING)bsDefault.GetBuffer(bsDefault.GetLength());
161 FPDF_WIDESTRING pLabel = (FPDF_WIDESTRING)bsLabel.GetBuffer(bsLabel.GetLength());
162 int ret = m_pInfo->m_pJsPlatform->app_response(m_pInfo->m_pJsPlatform, pQuestion, pTitle,
163 pDefault, pLabel, bPassword, response, length);
164 bsQuestion.ReleaseBuffer();
165 bsTitle.ReleaseBuffer();
166 bsDefault.ReleaseBuffer();
167 bsLabel.ReleaseBuffer();
173 virtual void JS_appBeep(int nType)
175 if(m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_beep)
177 m_pInfo->m_pJsPlatform->app_beep(m_pInfo->m_pJsPlatform, nType);
181 virtual CFX_WideString JS_fieldBrowse()
183 if(m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->Field_browse)
185 int nLen = m_pInfo->m_pJsPlatform->Field_browse(m_pInfo->m_pJsPlatform, NULL, 0);
188 char* pbuff = new char[nLen];
190 memset(pbuff, 0, nLen);
193 nLen = m_pInfo->m_pJsPlatform->Field_browse(m_pInfo->m_pJsPlatform, pbuff, nLen);
194 CFX_ByteString bsRet = CFX_ByteString(pbuff, nLen);
195 CFX_WideString wsRet = CFX_WideString::FromLocal(bsRet);
202 CFX_WideString JS_docGetFilePath()
204 if(m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->Doc_getFilePath)
206 int nLen = m_pInfo->m_pJsPlatform->Doc_getFilePath(m_pInfo->m_pJsPlatform, NULL, 0);
209 char* pbuff = new char[nLen];
211 memset(pbuff, 0, nLen);
214 nLen = m_pInfo->m_pJsPlatform->Doc_getFilePath(m_pInfo->m_pJsPlatform, pbuff, nLen);
215 CFX_ByteString bsRet = CFX_ByteString(pbuff, nLen);
216 CFX_WideString wsRet = CFX_WideString::FromLocal(bsRet);
223 void JS_docSubmitForm(void* formData, int length, FX_LPCWSTR URL)
225 if(m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->Doc_submitForm)
227 CFX_ByteString bsDestination = CFX_WideString(URL).UTF16LE_Encode();
228 FPDF_WIDESTRING pDestination = (FPDF_WIDESTRING)bsDestination.GetBuffer(bsDestination.GetLength());
229 m_pInfo->m_pJsPlatform->Doc_submitForm(m_pInfo->m_pJsPlatform, formData, length, pDestination);
230 bsDestination.ReleaseBuffer();
234 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)
236 if(m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->Doc_mail)
238 CFX_ByteString bsTo = CFX_WideString(To).UTF16LE_Encode();
239 CFX_ByteString bsCC = CFX_WideString(Subject).UTF16LE_Encode();
240 CFX_ByteString bsBcc = CFX_WideString(BCC).UTF16LE_Encode();
241 CFX_ByteString bsSubject = CFX_WideString(Subject).UTF16LE_Encode();
242 CFX_ByteString bsMsg = CFX_WideString(Msg).UTF16LE_Encode();
243 FPDF_WIDESTRING pTo = (FPDF_WIDESTRING)bsTo.GetBuffer(bsTo.GetLength());
244 FPDF_WIDESTRING pCC = (FPDF_WIDESTRING)bsCC.GetBuffer(bsCC.GetLength());
245 FPDF_WIDESTRING pBcc = (FPDF_WIDESTRING)bsBcc.GetBuffer(bsBcc.GetLength());
246 FPDF_WIDESTRING pSubject = (FPDF_WIDESTRING)bsSubject.GetBuffer(bsSubject.GetLength());
247 FPDF_WIDESTRING pMsg = (FPDF_WIDESTRING)bsMsg.GetBuffer(bsMsg.GetLength());
248 m_pInfo->m_pJsPlatform->Doc_mail(m_pInfo->m_pJsPlatform, mailData, length, bUI, pTo, pSubject,
250 bsTo.ReleaseBuffer();
251 bsCC.ReleaseBuffer();
252 bsBcc.ReleaseBuffer();
253 bsSubject.ReleaseBuffer();
254 bsMsg.ReleaseBuffer();
257 CFX_WideString JS_appbrowseForDoc(FPDF_BOOL bSave, FX_LPCWSTR cFilenameInit)
261 // if(m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_browseForDoc)
263 // CFX_ByteString bsFilenameInit = CFX_WideString(cFilenameInit).UTF16LE_Encode();
264 // FPDF_WIDESTRING pFileNameInit = (FPDF_WIDESTRING)bsFilenameInit.GetBuffer(bsFilenameInit.GetLength());
266 // m_pInfo->m_pJsPlatform->app_browseForDoc(m_pInfo->m_pJsPlatform, pFileNameInit);
267 // bsFilenameInit.ReleaseBuffer();
271 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)
273 if(m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->Doc_print)
275 m_pInfo->m_pJsPlatform->Doc_print(m_pInfo->m_pJsPlatform, bUI, nStart, nEnd, bSilent, bShrinkToFit, bPrintAsImage, bReverse, bAnnotations);
278 void JS_docgotoPage(int nPageNum)
280 if(m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->Doc_gotoPage)
282 m_pInfo->m_pJsPlatform->Doc_gotoPage(m_pInfo->m_pJsPlatform, nPageNum);
286 virtual FPDF_PAGE FFI_GetPage(FPDF_DOCUMENT document,int nPageIndex)
288 if(m_pInfo && m_pInfo->FFI_GetPage)
290 return m_pInfo->FFI_GetPage(m_pInfo, document, nPageIndex);
295 virtual FPDF_PAGE FFI_GetCurrentPage(FPDF_DOCUMENT document)
297 if(m_pInfo && m_pInfo->FFI_GetCurrentPage)
299 return m_pInfo->FFI_GetCurrentPage(m_pInfo, document);
304 int FFI_GetRotation(FPDF_PAGE page)
306 if(m_pInfo && m_pInfo->FFI_GetRotation)
308 return m_pInfo->FFI_GetRotation(m_pInfo, page);
312 void FFI_ExecuteNamedAction(FX_LPCSTR namedAction)
314 if(m_pInfo && m_pInfo->FFI_ExecuteNamedAction)
316 m_pInfo->FFI_ExecuteNamedAction(m_pInfo, namedAction);
319 void FFI_OnSetFieldInputFocus(void* field,FPDF_WIDESTRING focusText, FPDF_DWORD nTextLen, FX_BOOL bFocus)
321 if(m_pInfo && m_pInfo->FFI_SetTextFieldFocus)
323 m_pInfo->FFI_SetTextFieldFocus(m_pInfo, focusText, nTextLen, bFocus);
327 void FFI_DoURIAction(FX_LPCSTR bsURI)
329 if(m_pInfo && m_pInfo->FFI_DoURIAction)
331 m_pInfo->FFI_DoURIAction(m_pInfo, bsURI);
335 void FFI_DoGoToAction(int nPageIndex, int zoomMode, float* fPosArray, int sizeOfArray)
337 if(m_pInfo && m_pInfo->FFI_DoGoToAction)
339 m_pInfo->FFI_DoGoToAction(m_pInfo, nPageIndex, zoomMode, fPosArray, sizeOfArray);
344 FX_BOOL IsJSInitiated();
347 void SetCurrentDoc(CPDFSDK_Document* pFXDoc) {m_pSDKDoc = pFXDoc;}
348 CPDFSDK_Document* GetCurrentDoc();
349 CPDF_Document* GetPDFDocument() {return m_pPDFDoc;}
350 // CPDFSDK_Document* GetDocument(int nIndex);
351 // int CountDocuments() {return m_docMap.GetCount();}
353 CPDFSDK_Document* OpenDocument(CFX_WideString &fileName);
354 CPDFSDK_Document* OpenMemPDFDoc(CPDF_Document* pNewDoc, CFX_WideString &fileName);
355 FX_BOOL OpenURL(CFX_WideString &filePath);
358 CFX_ByteString GetAppName() {return "";}
360 CFFL_IFormFiller* GetIFormFiller();
361 IFX_SystemHandler* GetSysHandler() {return m_pSysHandler;}
364 CPDFSDK_AnnotHandlerMgr* GetAnnotHandlerMgr();
365 IFXJS_Runtime* GetJSRuntime();
366 CPDFSDK_ActionHandler* GetActionHander();
368 CPDFSDK_AnnotHandlerMgr* m_pAnnotHandlerMgr;
369 CPDFSDK_ActionHandler* m_pActionHandler;
370 IFXJS_Runtime* m_pJSRuntime;
372 FPDF_FORMFILLINFO* GetFormFillInfo() {return m_pInfo;}
374 FPDF_FORMFILLINFO* m_pInfo;
375 // CFX_MapPtrTemplate<CPDF_Document*, CPDFSDK_Document*> m_docMap;
376 CPDFSDK_Document* m_pSDKDoc;
377 CPDF_Document* m_pPDFDoc;
379 CFFL_IFormFiller* m_pIFormFiller;
380 IFX_SystemHandler* m_pSysHandler;
383 CJS_RuntimeFactory* m_pJSRuntimeFactory;
391 // CFX_App():m_pCurDoc(NULL) {}
392 // void SetAt(CPDF_Document* pPDFDoc, CPDFSDK_Document* pFXDoc);
393 // CPDFSDK_Document* GetAt(CPDF_Document* pPDFDoc);
395 // void SetCurrentDocument(CPDFSDK_Document* pFXDoc) {m_pCurDoc = pFXDoc;}
396 // CPDFSDK_Document* GetCurrentDocument() {return m_pCurDoc;}
398 // CFX_MapPtrTemplate<CPDF_Document*, CPDFSDK_Document*> m_docArray;
399 // CPDFSDK_Document* m_pCurDoc;
401 class CPDFSDK_InterForm;
402 class CPDFSDK_Document
405 CPDFSDK_Document(CPDF_Document* pDoc, CPDFDoc_Environment* pEnv);
408 CPDFSDK_InterForm* GetInterForm() ;
409 CPDF_Document* GetDocument() {return m_pDoc;}
413 void AddPageView(CPDF_Page* pPDFPage, CPDFSDK_PageView* pPageView);
414 CPDFSDK_PageView* GetPageView(CPDF_Page* pPDFPage, FX_BOOL ReNew = TRUE);
415 CPDFSDK_PageView* GetPageView(int nIndex);
416 CPDFSDK_PageView* GetCurrentView();
417 void ReMovePageView(CPDF_Page* pPDFPage);
418 void UpdateAllViews(CPDFSDK_PageView* pSender, CPDFSDK_Annot* pAnnot);
420 CPDFSDK_Annot* GetFocusAnnot();//{return NULL;}
422 IFXJS_Runtime * GetJsRuntime();
424 FX_BOOL SetFocusAnnot(CPDFSDK_Annot* pAnnot, FX_UINT nFlag = 0);//{return FALSE;}
425 FX_BOOL KillFocusAnnot(FX_UINT nFlag = 0);
427 FX_BOOL ExtractPages(const CFX_WordArray &arrExtraPages, CPDF_Document* pDstDoc);
428 FX_BOOL InsertPages(int nInsertAt, const CPDF_Document* pSrcDoc, const CFX_WordArray &arrSrcPages);
429 FX_BOOL DeletePages(int nStart, int nCount);
430 FX_BOOL ReplacePages(int nPage, const CPDF_Document* pSrcDoc, const CFX_WordArray &arrSrcPages);
432 void OnCloseDocument();
434 int GetPageCount() {return m_pDoc->GetPageCount();}
435 FX_BOOL GetPermissions(int nFlag);
436 FX_BOOL GetChangeMark() {return m_bChangeMask;}
437 void SetChangeMark() {m_bChangeMask = TRUE;}
438 void ClearChangeMark() {m_bChangeMask= FALSE;}
439 // FX_BOOL GetChangeMark(){return FALSE;}//IsAnnotModified()||IsFormModified() || IsWidgetModified()|| m_nChangeMark>0 ;}
440 // void ClearChangeMark(){}
441 CFX_WideString GetPath() ;
442 CPDF_Page* GetPage(int nIndex);
443 CPDFDoc_Environment * GetEnv() {return m_pEnv; }
444 void ProcJavascriptFun();
445 FX_BOOL ProcOpenAction();
446 CPDF_OCContext* GetOCContext();
448 //CFX_ArrayTemplate<CPDFSDK_PageView*> m_pageArray;
449 CFX_MapPtrTemplate<CPDF_Page*, CPDFSDK_PageView*> m_pageMap;
450 CPDF_Document* m_pDoc;
452 CPDFSDK_InterForm* m_pInterForm;
453 CPDFSDK_Annot* m_pFocusAnnot;
454 CPDFDoc_Environment * m_pEnv;
455 CPDF_OCContext * m_pOccontent;
456 FX_BOOL m_bChangeMask;
459 class CPDFSDK_PageView
462 CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc,CPDF_Page* page);
465 virtual void PageView_OnDraw(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,CPDF_RenderOptions* pOptions) ;
467 CPDF_Annot* GetPDFAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
468 CPDFSDK_Annot* GetFXAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
469 CPDF_Annot* GetPDFWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
470 CPDFSDK_Annot* GetFXWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
471 CPDFSDK_Annot* GetFocusAnnot() ;
472 void SetFocusAnnot(CPDFSDK_Annot* pSDKAnnot,FX_UINT nFlag = 0) {m_pSDKDoc->SetFocusAnnot(pSDKAnnot, nFlag);}
473 FX_BOOL KillFocusAnnot(FX_UINT nFlag = 0) {return m_pSDKDoc->KillFocusAnnot(nFlag);}
474 FX_BOOL Annot_HasAppearance(CPDF_Annot* pAnnot);
476 CPDFSDK_Annot* AddAnnot(CPDF_Dictionary * pDict);
477 CPDFSDK_Annot* AddAnnot(FX_LPCSTR lpSubType,CPDF_Dictionary * pDict);
478 CPDFSDK_Annot* AddAnnot(CPDF_Annot * pPDFAnnot);
479 FX_BOOL DeleteAnnot(CPDFSDK_Annot* pAnnot);
482 CPDFSDK_Annot* GetAnnot(int nIndex);
483 CPDFSDK_Annot* GetAnnotByDict(CPDF_Dictionary * pDict);
484 CPDF_Page* GetPDFPage(){return m_page;}
485 CPDF_Document* GetPDFDocument();
486 CPDFSDK_Document* GetSDKDocument() {return m_pSDKDoc;}
488 virtual FX_BOOL OnLButtonDown(const CPDF_Point & point, FX_UINT nFlag);
489 virtual FX_BOOL OnLButtonUp(const CPDF_Point & point, FX_UINT nFlag);
490 virtual FX_BOOL OnChar(int nChar, FX_UINT nFlag);
491 virtual FX_BOOL OnKeyDown(int nKeyCode, int nFlag);
492 virtual FX_BOOL OnKeyUp(int nKeyCode, int nFlag);
494 virtual FX_BOOL OnMouseMove(const CPDF_Point & point, int nFlag);
495 virtual FX_BOOL OnMouseWheel(double deltaX, double deltaY,const CPDF_Point& point, int nFlag);
496 virtual FX_BOOL IsValidAnnot(FX_LPVOID p);
498 virtual void GetCurrentMatrix(CPDF_Matrix& matrix) {matrix = m_curMatrix;}
499 virtual void UpdateRects(CFX_RectArray& rects);
500 void UpdateView(CPDFSDK_Annot* pAnnot);
501 CFX_PtrArray* GetAnnotList(){ return &m_fxAnnotArray; }
504 virtual int GetPageIndex();
507 CPDF_Matrix m_curMatrix;
510 void PageView_OnHighlightFormFields(CFX_RenderDevice* pDevice, CPDFSDK_Widget* pWidget);
514 CPDF_AnnotList* m_pAnnotList;
516 //CPDFSDK_Annot* m_pFocusAnnot;
517 CFX_PtrArray m_fxAnnotArray;
519 CPDFSDK_Document* m_pSDKDoc;
521 CPDFSDK_Widget* m_CaptureWidget;
522 FX_BOOL m_bEnterWidget;
523 FX_BOOL m_bExitWidget;
526 void SetValid(FX_BOOL bValid) {m_bValid = bValid;}
527 FX_BOOL IsValid() {return m_bValid;}
534 class CGW_ArrayTemplate : public CFX_ArrayTemplate<TYPE>
537 CGW_ArrayTemplate(){}
538 virtual ~CGW_ArrayTemplate(){}
540 typedef int (*LP_COMPARE)(TYPE p1, TYPE p2);
542 void Sort(LP_COMPARE pCompare, FX_BOOL bAscent = TRUE)
544 int nSize = this->GetSize();
545 QuickSort(0, nSize -1, bAscent, pCompare);
549 void QuickSort(FX_UINT nStartPos, FX_UINT nStopPos, FX_BOOL bAscend, LP_COMPARE pCompare)
551 if (nStartPos >= nStopPos) return;
553 if ((nStopPos - nStartPos) == 1)
555 TYPE Value1 = this->GetAt(nStartPos);
556 TYPE Value2 = this->GetAt(nStopPos);
558 int iGreate = (*pCompare)(Value1, Value2);
559 if ((bAscend && iGreate > 0) || (!bAscend && iGreate < 0))
561 this->SetAt(nStartPos, Value2);
562 this->SetAt(nStopPos, Value1);
567 FX_UINT m = (nStartPos + nStopPos) / 2;
568 FX_UINT i = nStartPos;
570 TYPE Value = this->GetAt(m);
574 TYPE temp = this->GetAt(i);
576 int iGreate = (*pCompare)(temp, Value);
577 if ((bAscend && iGreate > 0) || (!bAscend && iGreate < 0))
579 this->InsertAt(m+1, temp);
589 FX_UINT j = nStopPos;
593 TYPE temp = this->GetAt(j);
595 int iGreate = (*pCompare)(temp, Value);
596 if ((bAscend && iGreate < 0) || (!bAscend && iGreate > 0))
599 this->InsertAt(m, temp);
608 if (nStartPos < m) QuickSort(nStartPos, m, bAscend, pCompare);
609 if (nStopPos > m) QuickSort(m, nStopPos, bAscend, pCompare);
614 #endif //_FPDFSDK_MGR_H