blob: 385cfdbbff7267d89c63d41d7e64fb678a696564 [file] [log] [blame]
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001// 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.
Tom Sepezc6ab1722015-02-05 15:27:25 -08004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
Tom Sepez19922bb2015-05-28 13:23:12 -07007#ifndef FPDFSDK_INCLUDE_FSDK_MGR_H_
8#define FPDFSDK_INCLUDE_FSDK_MGR_H_
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07009
Lei Zhang606346f2015-06-19 18:11:07 -070010#include <map>
11
Lei Zhanga688a042015-11-09 13:57:49 -080012#include "core/include/fpdftext/fpdf_text.h"
Lei Zhang8241df72015-11-06 14:38:48 -080013#include "fsdk_actionhandler.h"
14#include "fsdk_annothandler.h"
15#include "fsdk_baseannot.h"
16#include "fsdk_baseform.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070017#include "fsdk_common.h"
18#include "fsdk_define.h"
19#include "fx_systemhandler.h"
Lei Zhange5b0bd12015-06-19 17:15:41 -070020#include "javascript/IJavaScript.h"
Lei Zhangb4e7f302015-11-06 15:52:32 -080021#include "public/fpdf_formfill.h"
22#include "public/fpdf_fwlevent.h" // cross platform keycode and events define.
Lei Zhang8241df72015-11-06 14:38:48 -080023#include "third_party/base/nonstd_unique_ptr.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070024
Tom Sepez40e9ff32015-11-30 12:39:54 -080025#ifdef PDF_ENABLE_XFA
26#include "fpdfxfa/fpdfxfa_doc.h"
27#include "fpdfxfa/fpdfxfa_page.h"
28#endif // PDF_ENABLE_XFA
29
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070030class CFFL_IFormFiller;
Tom Sepezdcbc02f2015-07-17 09:16:17 -070031class CPDFSDK_ActionHandler;
32class CPDFSDK_Annot;
33class CPDFSDK_Document;
34class CPDFSDK_InterForm;
35class CPDFSDK_PageView;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070036class CPDFSDK_Widget;
37class IFX_SystemHandler;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070038
Nico Weber9d8ec5a2015-08-04 13:00:21 -070039class CPDFDoc_Environment final {
40 public:
Tom Sepez50d12ad2015-11-24 09:50:51 -080041 CPDFDoc_Environment(UnderlyingDocumentType* pDoc, FPDF_FORMFILLINFO* pFFinfo);
Tom Sepezdfbf8e72015-10-14 14:17:26 -070042 ~CPDFDoc_Environment();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070043
Tom Sepez51da0932015-11-25 16:05:49 -080044#ifdef PDF_ENABLE_XFA
Tom Sepezdfbf8e72015-10-14 14:17:26 -070045 void Release() {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070046 if (m_pInfo && m_pInfo->Release)
47 m_pInfo->Release(m_pInfo);
48 delete this;
49 }
Tom Sepez40e9ff32015-11-30 12:39:54 -080050#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -070051
52 void FFI_Invalidate(FPDF_PAGE page,
53 double left,
54 double top,
55 double right,
56 double bottom) {
57 if (m_pInfo && m_pInfo->FFI_Invalidate)
58 m_pInfo->FFI_Invalidate(m_pInfo, page, left, top, right, bottom);
59 }
60
61 void FFI_OutputSelectedRect(FPDF_PAGE page,
62 double left,
63 double top,
64 double right,
65 double bottom) {
66 if (m_pInfo && m_pInfo->FFI_OutputSelectedRect)
67 m_pInfo->FFI_OutputSelectedRect(m_pInfo, page, left, top, right, bottom);
68 }
69
70 void FFI_SetCursor(int nCursorType) {
71 if (m_pInfo && m_pInfo->FFI_SetCursor)
72 m_pInfo->FFI_SetCursor(m_pInfo, nCursorType);
73 }
74
75 int FFI_SetTimer(int uElapse, TimerCallback lpTimerFunc) {
76 if (m_pInfo && m_pInfo->FFI_SetTimer)
77 return m_pInfo->FFI_SetTimer(m_pInfo, uElapse, lpTimerFunc);
78 return -1;
79 }
80
81 void FFI_KillTimer(int nTimerID) {
82 if (m_pInfo && m_pInfo->FFI_KillTimer)
83 m_pInfo->FFI_KillTimer(m_pInfo, nTimerID);
84 }
85
Tom Sepez468e5892015-10-13 15:49:36 -070086 FX_SYSTEMTIME FFI_GetLocalTime() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070087 FX_SYSTEMTIME fxtime;
88 if (m_pInfo && m_pInfo->FFI_GetLocalTime) {
89 FPDF_SYSTEMTIME systime = m_pInfo->FFI_GetLocalTime(m_pInfo);
90 fxtime.wDay = systime.wDay;
91 fxtime.wDayOfWeek = systime.wDayOfWeek;
92 fxtime.wHour = systime.wHour;
93 fxtime.wMilliseconds = systime.wMilliseconds;
94 fxtime.wMinute = systime.wMinute;
95 fxtime.wMonth = systime.wMonth;
96 fxtime.wSecond = systime.wSecond;
97 fxtime.wYear = systime.wYear;
Tom Sepezdcbc02f2015-07-17 09:16:17 -070098 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070099 return fxtime;
100 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700101
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700102 void FFI_OnChange() {
103 if (m_pInfo && m_pInfo->FFI_OnChange)
104 m_pInfo->FFI_OnChange(m_pInfo);
105 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700106
Tom Sepez468e5892015-10-13 15:49:36 -0700107 FX_BOOL FFI_IsSHIFTKeyDown(FX_DWORD nFlag) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700108 return (nFlag & FWL_EVENTFLAG_ShiftKey) != 0;
109 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700110
Tom Sepez468e5892015-10-13 15:49:36 -0700111 FX_BOOL FFI_IsCTRLKeyDown(FX_DWORD nFlag) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700112 return (nFlag & FWL_EVENTFLAG_ControlKey) != 0;
113 }
Tom Sepezc6ab1722015-02-05 15:27:25 -0800114
Tom Sepez468e5892015-10-13 15:49:36 -0700115 FX_BOOL FFI_IsALTKeyDown(FX_DWORD nFlag) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700116 return (nFlag & FWL_EVENTFLAG_AltKey) != 0;
117 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700118
Tom Sepez468e5892015-10-13 15:49:36 -0700119 FX_BOOL FFI_IsINSERTKeyDown(FX_DWORD nFlag) const { return FALSE; }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700120
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700121 int JS_appAlert(const FX_WCHAR* Msg,
122 const FX_WCHAR* Title,
123 FX_UINT Type,
124 FX_UINT Icon);
125 int JS_appResponse(const FX_WCHAR* Question,
126 const FX_WCHAR* Title,
127 const FX_WCHAR* Default,
128 const FX_WCHAR* cLabel,
129 FPDF_BOOL bPassword,
130 void* response,
131 int length);
Tom Sepezc6ab1722015-02-05 15:27:25 -0800132
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700133 void JS_appBeep(int nType) {
134 if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_beep)
135 m_pInfo->m_pJsPlatform->app_beep(m_pInfo->m_pJsPlatform, nType);
136 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700137
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700138 CFX_WideString JS_fieldBrowse();
139 CFX_WideString JS_docGetFilePath();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700140
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700141 void JS_docSubmitForm(void* formData, int length, const FX_WCHAR* URL);
142 void JS_docmailForm(void* mailData,
143 int length,
144 FPDF_BOOL bUI,
145 const FX_WCHAR* To,
146 const FX_WCHAR* Subject,
147 const FX_WCHAR* CC,
148 const FX_WCHAR* BCC,
149 const FX_WCHAR* Msg);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700150
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700151 void JS_docprint(FPDF_BOOL bUI,
152 int nStart,
153 int nEnd,
154 FPDF_BOOL bSilent,
155 FPDF_BOOL bShrinkToFit,
156 FPDF_BOOL bPrintAsImage,
157 FPDF_BOOL bReverse,
158 FPDF_BOOL bAnnotations) {
159 if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->Doc_print)
160 m_pInfo->m_pJsPlatform->Doc_print(m_pInfo->m_pJsPlatform, bUI, nStart,
161 nEnd, bSilent, bShrinkToFit,
162 bPrintAsImage, bReverse, bAnnotations);
163 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700164
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700165 void JS_docgotoPage(int nPageNum) {
166 if (m_pInfo && m_pInfo->m_pJsPlatform &&
167 m_pInfo->m_pJsPlatform->Doc_gotoPage)
168 m_pInfo->m_pJsPlatform->Doc_gotoPage(m_pInfo->m_pJsPlatform, nPageNum);
169 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700170
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700171 FPDF_PAGE FFI_GetPage(FPDF_DOCUMENT document, int nPageIndex) {
172 if (m_pInfo && m_pInfo->FFI_GetPage)
173 return m_pInfo->FFI_GetPage(m_pInfo, document, nPageIndex);
174 return NULL;
175 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700176
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700177 FPDF_PAGE FFI_GetCurrentPage(FPDF_DOCUMENT document) {
178 if (m_pInfo && m_pInfo->FFI_GetCurrentPage)
179 return m_pInfo->FFI_GetCurrentPage(m_pInfo, document);
180 return NULL;
181 }
Tom Sepez0d3b5cc2014-07-30 13:03:52 -0700182
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700183 int FFI_GetRotation(FPDF_PAGE page) {
184 if (m_pInfo && m_pInfo->FFI_GetRotation)
185 return m_pInfo->FFI_GetRotation(m_pInfo, page);
186 return 0;
187 }
Tom Sepez0d3b5cc2014-07-30 13:03:52 -0700188
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700189 void FFI_ExecuteNamedAction(const FX_CHAR* namedAction) {
190 if (m_pInfo && m_pInfo->FFI_ExecuteNamedAction)
191 m_pInfo->FFI_ExecuteNamedAction(m_pInfo, namedAction);
192 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700193
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700194 void FFI_OnSetFieldInputFocus(void* field,
195 FPDF_WIDESTRING focusText,
196 FPDF_DWORD nTextLen,
197 FX_BOOL bFocus) {
198 if (m_pInfo && m_pInfo->FFI_SetTextFieldFocus)
199 m_pInfo->FFI_SetTextFieldFocus(m_pInfo, focusText, nTextLen, bFocus);
200 }
Tom Sepez0d3b5cc2014-07-30 13:03:52 -0700201
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700202 void FFI_DoURIAction(const FX_CHAR* bsURI) {
203 if (m_pInfo && m_pInfo->FFI_DoURIAction)
204 m_pInfo->FFI_DoURIAction(m_pInfo, bsURI);
205 }
Tom Sepez0d3b5cc2014-07-30 13:03:52 -0700206
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700207 void FFI_DoGoToAction(int nPageIndex,
208 int zoomMode,
209 float* fPosArray,
210 int sizeOfArray) {
211 if (m_pInfo && m_pInfo->FFI_DoGoToAction)
212 m_pInfo->FFI_DoGoToAction(m_pInfo, nPageIndex, zoomMode, fPosArray,
213 sizeOfArray);
214 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700215
Tom Sepez51da0932015-11-25 16:05:49 -0800216#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700217 void FFI_DisplayCaret(FPDF_PAGE page,
218 FPDF_BOOL bVisible,
219 double left,
220 double top,
221 double right,
222 double bottom) {
223 if (m_pInfo && m_pInfo->FFI_DisplayCaret)
224 m_pInfo->FFI_DisplayCaret(m_pInfo, page, bVisible, left, top, right,
225 bottom);
226 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700227
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700228 int FFI_GetCurrentPageIndex(FPDF_DOCUMENT document) {
Jun Fang01fe5882015-11-25 11:05:58 +0800229 if (!m_pInfo || !m_pInfo->FFI_GetCurrentPageIndex) {
230 return -1;
231 }
232 return m_pInfo->FFI_GetCurrentPageIndex(m_pInfo, document);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700233 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700234
Jun Fang01fe5882015-11-25 11:05:58 +0800235 void FFI_SetCurrentPage(FPDF_DOCUMENT document, int iCurPage) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700236 if (m_pInfo && m_pInfo->FFI_SetCurrentPage)
237 m_pInfo->FFI_SetCurrentPage(m_pInfo, document, iCurPage);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700238 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700239
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700240 CFX_WideString FFI_GetAppName() const { return CFX_WideString(L"Acrobat"); }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700241
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700242 CFX_WideString FFI_GetPlatform() {
243 if (m_pInfo && m_pInfo->FFI_GetPlatform) {
244 int nRequiredLen = m_pInfo->FFI_GetPlatform(m_pInfo, NULL, 0);
245 if (nRequiredLen <= 0)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700246 return L"";
Bo Xufdc00a72014-10-28 23:03:33 -0700247
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700248 char* pbuff = new char[nRequiredLen];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700249 memset(pbuff, 0, nRequiredLen);
250 int nActualLen = m_pInfo->FFI_GetPlatform(m_pInfo, pbuff, nRequiredLen);
251 if (nActualLen <= 0 || nActualLen > nRequiredLen) {
252 delete[] pbuff;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700253 return L"";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700254 }
255 CFX_ByteString bsRet = CFX_ByteString(pbuff, nActualLen);
256 CFX_WideString wsRet = CFX_WideString::FromUTF16LE(
257 (unsigned short*)bsRet.GetBuffer(bsRet.GetLength()),
258 bsRet.GetLength() / sizeof(unsigned short));
259 delete[] pbuff;
260 return wsRet;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700261 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700262 return L"";
263 }
Bo Xufdc00a72014-10-28 23:03:33 -0700264
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700265 void FFI_GotoURL(FPDF_DOCUMENT document,
266 const CFX_WideStringC& wsURL,
267 FX_BOOL bAppend) {
268 if (m_pInfo && m_pInfo->FFI_GotoURL) {
269 CFX_ByteString bsTo = CFX_WideString(wsURL).UTF16LE_Encode();
270 FPDF_WIDESTRING pTo = (FPDF_WIDESTRING)bsTo.GetBuffer(wsURL.GetLength());
271 m_pInfo->FFI_GotoURL(m_pInfo, document, pTo);
272 bsTo.ReleaseBuffer();
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700273 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700274 }
Bo Xufdc00a72014-10-28 23:03:33 -0700275
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700276 void FFI_GetURL(FPDF_DOCUMENT document, CFX_WideString& wsURL) {
277 wsURL = CFX_WideString();
278 }
279
280 void FFI_AddDoRecord(FPDF_DOCUMENT document, FPDF_WIDGET hWidget) {}
281 void FFI_PageEvent(FPDF_PAGE page, FPDF_DWORD flag) {}
282
283 void FFI_GetPageViewRect(FPDF_PAGE page, FS_RECTF& dstRect) {
284 if (m_pInfo && m_pInfo->FFI_GetPageViewRect) {
285 double left;
286 double top;
287 double right;
288 double bottom;
289 m_pInfo->FFI_GetPageViewRect(m_pInfo, page, &left, &top, &right, &bottom);
290
291 dstRect.left = static_cast<float>(left);
292 dstRect.top = static_cast<float>(top < bottom ? bottom : top);
293 dstRect.bottom = static_cast<float>(top < bottom ? top : bottom);
294 dstRect.right = static_cast<float>(right);
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700295 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700296 }
Bo Xufdc00a72014-10-28 23:03:33 -0700297
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700298 FX_BOOL FFI_PopupMenu(FPDF_PAGE page,
299 FPDF_WIDGET hWidget,
300 int menuFlag,
301 CFX_PointF ptPopup,
302 const CFX_PointF* pRectExclude) {
303 if (m_pInfo && m_pInfo->FFI_PopupMenu)
304 return m_pInfo->FFI_PopupMenu(m_pInfo, page, hWidget, menuFlag, ptPopup.x,
305 ptPopup.y);
306 return FALSE;
307 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700308
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700309 void FFI_Alert(FPDF_WIDESTRING Msg,
310 FPDF_WIDESTRING Title,
311 int Type,
312 int Icon) {
313 if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_alert)
314 m_pInfo->m_pJsPlatform->app_alert(m_pInfo->m_pJsPlatform, Msg, Title,
315 Type, Icon);
316 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700317
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700318 void FFI_EmailTo(FPDF_FILEHANDLER* fileHandler,
319 FPDF_WIDESTRING pTo,
320 FPDF_WIDESTRING pSubject,
321 FPDF_WIDESTRING pCC,
322 FPDF_WIDESTRING pBcc,
323 FPDF_WIDESTRING pMsg) {
324 if (m_pInfo && m_pInfo->FFI_EmailTo)
325 m_pInfo->FFI_EmailTo(m_pInfo, fileHandler, pTo, pSubject, pCC, pBcc,
326 pMsg);
327 }
328
329 void FFI_UploadTo(FPDF_FILEHANDLER* fileHandler,
330 int fileFlag,
331 FPDF_WIDESTRING uploadTo) {
332 if (m_pInfo && m_pInfo->FFI_UploadTo)
333 m_pInfo->FFI_UploadTo(m_pInfo, fileHandler, fileFlag, uploadTo);
334 }
335
336 FPDF_FILEHANDLER* FFI_OpenFile(int fileType,
337 FPDF_WIDESTRING wsURL,
338 const char* mode) {
339 if (m_pInfo && m_pInfo->FFI_OpenFile)
340 return m_pInfo->FFI_OpenFile(m_pInfo, fileType, wsURL, mode);
341 return NULL;
342 }
343
344 CFX_WideString FFI_GetFilePath(FPDF_FILEHANDLER* pFileHandler) const {
345 return L"";
346 }
347
348 int FFI_GetDocumentCount() const { return 0; }
349 int FFI_GetCurDocument() const { return 0; }
350
351 IFX_FileRead* FFI_DownloadFromURL(const FX_WCHAR* url) {
352 if (m_pInfo && m_pInfo->FFI_DownloadFromURL) {
353 CFX_ByteString bstrURL = CFX_WideString(url).UTF16LE_Encode();
354 FPDF_WIDESTRING wsURL =
355 (FPDF_WIDESTRING)bstrURL.GetBuffer(bstrURL.GetLength());
356
357 FPDF_LPFILEHANDLER fileHandler =
358 m_pInfo->FFI_DownloadFromURL(m_pInfo, wsURL);
359
Lei Zhangdb5256f2015-10-02 10:11:43 -0700360 return new CFPDF_FileStream(fileHandler);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700361 }
362 return NULL;
363 }
364
365 CFX_WideString FFI_PostRequestURL(const FX_WCHAR* wsURL,
366 const FX_WCHAR* wsData,
367 const FX_WCHAR* wsContentType,
368 const FX_WCHAR* wsEncode,
369 const FX_WCHAR* wsHeader) {
370 if (m_pInfo && m_pInfo->FFI_PostRequestURL) {
371 CFX_ByteString bsURL = CFX_WideString(wsURL).UTF16LE_Encode();
372 FPDF_WIDESTRING URL = (FPDF_WIDESTRING)bsURL.GetBuffer(bsURL.GetLength());
373
374 CFX_ByteString bsData = CFX_WideString(wsData).UTF16LE_Encode();
375 FPDF_WIDESTRING data =
376 (FPDF_WIDESTRING)bsData.GetBuffer(bsData.GetLength());
377
378 CFX_ByteString bsContentType =
379 CFX_WideString(wsContentType).UTF16LE_Encode();
380 FPDF_WIDESTRING contentType =
381 (FPDF_WIDESTRING)bsContentType.GetBuffer(bsContentType.GetLength());
382
383 CFX_ByteString bsEncode = CFX_WideString(wsEncode).UTF16LE_Encode();
384 FPDF_WIDESTRING encode =
385 (FPDF_WIDESTRING)bsEncode.GetBuffer(bsEncode.GetLength());
386
387 CFX_ByteString bsHeader = CFX_WideString(wsHeader).UTF16LE_Encode();
388 FPDF_WIDESTRING header =
389 (FPDF_WIDESTRING)bsHeader.GetBuffer(bsHeader.GetLength());
390
391 FPDF_BSTR respone;
392 FPDF_BStr_Init(&respone);
393 m_pInfo->FFI_PostRequestURL(m_pInfo, URL, data, contentType, encode,
394 header, &respone);
395
396 CFX_WideString wsRet = CFX_WideString::FromUTF16LE(
397 (unsigned short*)respone.str, respone.len / sizeof(unsigned short));
398 FPDF_BStr_Clear(&respone);
399
400 return wsRet;
401 }
402 return L"";
403 }
404
405 FPDF_BOOL FFI_PutRequestURL(const FX_WCHAR* wsURL,
406 const FX_WCHAR* wsData,
407 const FX_WCHAR* wsEncode) {
408 if (m_pInfo && m_pInfo->FFI_PutRequestURL) {
409 CFX_ByteString bsURL = CFX_WideString(wsURL).UTF16LE_Encode();
410 FPDF_WIDESTRING URL = (FPDF_WIDESTRING)bsURL.GetBuffer(bsURL.GetLength());
411
412 CFX_ByteString bsData = CFX_WideString(wsData).UTF16LE_Encode();
413 FPDF_WIDESTRING data =
414 (FPDF_WIDESTRING)bsData.GetBuffer(bsData.GetLength());
415
416 CFX_ByteString bsEncode = CFX_WideString(wsEncode).UTF16LE_Encode();
417 FPDF_WIDESTRING encode =
418 (FPDF_WIDESTRING)bsEncode.GetBuffer(bsEncode.GetLength());
419
420 return m_pInfo->FFI_PutRequestURL(m_pInfo, URL, data, encode);
421 }
422 return FALSE;
423 }
424
425 FPDF_BOOL FFI_ShowFileDialog(const FX_WCHAR* wsTitle,
426 const FX_WCHAR* wsFilter,
427 CFX_WideStringArray& wsPathArr,
428 FX_BOOL bOpen) {
429 return FALSE;
430 }
431
432 CFX_WideString FFI_GetLanguage() {
433 if (m_pInfo && m_pInfo->FFI_GetLanguage) {
434 int nRequiredLen = m_pInfo->FFI_GetLanguage(m_pInfo, NULL, 0);
435 if (nRequiredLen <= 0)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700436 return L"";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700437
438 char* pbuff = new char[nRequiredLen];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700439 memset(pbuff, 0, nRequiredLen);
440 int nActualLen = m_pInfo->FFI_GetLanguage(m_pInfo, pbuff, nRequiredLen);
441 if (nActualLen <= 0 || nActualLen > nRequiredLen) {
442 delete[] pbuff;
443 return L"";
444 }
445 CFX_ByteString bsRet = CFX_ByteString(pbuff, nActualLen);
446 CFX_WideString wsRet = CFX_WideString::FromUTF16LE(
447 (unsigned short*)bsRet.GetBuffer(bsRet.GetLength()),
448 bsRet.GetLength() / sizeof(unsigned short));
449 delete[] pbuff;
450 return wsRet;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700451 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700452 return L"";
453 }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800454#endif // PDF_ENABLE_XFA
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700455
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700456 FX_BOOL IsJSInitiated() const { return m_pInfo && m_pInfo->m_pJsPlatform; }
457 void SetSDKDocument(CPDFSDK_Document* pFXDoc) { m_pSDKDoc = pFXDoc; }
458 CPDFSDK_Document* GetSDKDocument() const { return m_pSDKDoc; }
Tom Sepez50d12ad2015-11-24 09:50:51 -0800459 UnderlyingDocumentType* GetUnderlyingDocument() const {
460 return m_pUnderlyingDoc;
461 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700462 CFX_ByteString GetAppName() const { return ""; }
Oliver Chang24752492015-10-30 16:08:20 -0700463 IFX_SystemHandler* GetSysHandler() const { return m_pSysHandler.get(); }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700464 FPDF_FORMFILLINFO* GetFormFillInfo() const { return m_pInfo; }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700465
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700466 CFFL_IFormFiller* GetIFormFiller(); // Creates if not present.
467 CPDFSDK_AnnotHandlerMgr* GetAnnotHandlerMgr(); // Creates if not present.
Tom Sepezba038bc2015-10-08 12:03:00 -0700468 IJS_Runtime* GetJSRuntime(); // Creates if not present.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700469 CPDFSDK_ActionHandler* GetActionHander(); // Creates if not present.
Tom Sepez2f3dfef2015-03-02 15:35:26 -0800470
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700471 private:
Oliver Chang24752492015-10-30 16:08:20 -0700472 nonstd::unique_ptr<CPDFSDK_AnnotHandlerMgr> m_pAnnotHandlerMgr;
473 nonstd::unique_ptr<CPDFSDK_ActionHandler> m_pActionHandler;
Tom Sepezba038bc2015-10-08 12:03:00 -0700474 nonstd::unique_ptr<IJS_Runtime> m_pJSRuntime;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700475 FPDF_FORMFILLINFO* const m_pInfo;
476 CPDFSDK_Document* m_pSDKDoc;
Tom Sepez50d12ad2015-11-24 09:50:51 -0800477 UnderlyingDocumentType* const m_pUnderlyingDoc;
Oliver Chang24752492015-10-30 16:08:20 -0700478 nonstd::unique_ptr<CFFL_IFormFiller> m_pIFormFiller;
479 nonstd::unique_ptr<IFX_SystemHandler> m_pSysHandler;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700480};
481
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700482class CPDFSDK_Document {
483 public:
Tom Sepez50d12ad2015-11-24 09:50:51 -0800484 CPDFSDK_Document(UnderlyingDocumentType* pDoc, CPDFDoc_Environment* pEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700485 ~CPDFSDK_Document();
Tom Sepez2f3dfef2015-03-02 15:35:26 -0800486
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700487 CPDFSDK_InterForm* GetInterForm();
Tom Sepez50d12ad2015-11-24 09:50:51 -0800488
Tom Sepez5259ef32015-11-24 10:21:01 -0800489 // Gets the document object for the next layer down; for master this is
490 // a CPDF_Document, but for XFA it is a CPDFXFA_Document.
Tom Sepez50d12ad2015-11-24 09:50:51 -0800491 UnderlyingDocumentType* GetUnderlyingDocument() const {
Tom Sepez40e9ff32015-11-30 12:39:54 -0800492#ifdef PDF_ENABLE_XFA
Tom Sepez50d12ad2015-11-24 09:50:51 -0800493 return GetXFADocument();
Tom Sepez40e9ff32015-11-30 12:39:54 -0800494#else // PDF_ENABLE_XFA
495 return GetPDFDocument();
496#endif // PDF_ENABLE_XFA
Tom Sepez50d12ad2015-11-24 09:50:51 -0800497 }
Tom Sepez5259ef32015-11-24 10:21:01 -0800498
499 // Gets the CPDF_Document, either directly in master, or from the
500 // CPDFXFA_Document for XFA.
Tom Sepezbf59a072015-10-21 14:07:23 -0700501 CPDF_Document* GetPDFDocument() const {
Tom Sepez40e9ff32015-11-30 12:39:54 -0800502#ifdef PDF_ENABLE_XFA
Tom Sepezbf59a072015-10-21 14:07:23 -0700503 return m_pDoc ? m_pDoc->GetPDFDoc() : nullptr;
Tom Sepez40e9ff32015-11-30 12:39:54 -0800504#else // PDF_ENABLE_XFA
505 return m_pDoc;
506#endif // PDF_ENABLE_XFA
Tom Sepezbf59a072015-10-21 14:07:23 -0700507 }
Tom Sepez5259ef32015-11-24 10:21:01 -0800508
Tom Sepez40e9ff32015-11-30 12:39:54 -0800509#ifdef PDF_ENABLE_XFA
Tom Sepez5259ef32015-11-24 10:21:01 -0800510 // Gets the XFA document directly (XFA-only).
Tom Sepez50d12ad2015-11-24 09:50:51 -0800511 CPDFXFA_Document* GetXFADocument() const { return m_pDoc; }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700512
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700513 int GetPageViewCount() const { return m_pageMap.size(); }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800514#endif // PDF_ENABLE_XFA
515
Tom Sepez540c4362015-11-24 13:33:57 -0800516 CPDFSDK_PageView* GetPageView(UnderlyingPageType* pPage,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700517 FX_BOOL ReNew = TRUE);
518 CPDFSDK_PageView* GetPageView(int nIndex);
519 CPDFSDK_PageView* GetCurrentView();
Tom Sepez540c4362015-11-24 13:33:57 -0800520 void RemovePageView(UnderlyingPageType* pPage);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700521 void UpdateAllViews(CPDFSDK_PageView* pSender, CPDFSDK_Annot* pAnnot);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700522
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700523 CPDFSDK_Annot* GetFocusAnnot();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700524
Tom Sepezba038bc2015-10-08 12:03:00 -0700525 IJS_Runtime* GetJsRuntime();
Tom Sepezc6ab1722015-02-05 15:27:25 -0800526
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700527 FX_BOOL SetFocusAnnot(CPDFSDK_Annot* pAnnot, FX_UINT nFlag = 0);
528 FX_BOOL KillFocusAnnot(FX_UINT nFlag = 0);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700529
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700530 FX_BOOL ExtractPages(const CFX_WordArray& arrExtraPages,
531 CPDF_Document* pDstDoc);
532 FX_BOOL InsertPages(int nInsertAt,
533 const CPDF_Document* pSrcDoc,
534 const CFX_WordArray& arrSrcPages);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700535 FX_BOOL ReplacePages(int nPage,
536 const CPDF_Document* pSrcDoc,
537 const CFX_WordArray& arrSrcPages);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700538
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700539 void OnCloseDocument();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700540
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700541 int GetPageCount() { return m_pDoc->GetPageCount(); }
542 FX_BOOL GetPermissions(int nFlag);
543 FX_BOOL GetChangeMark() { return m_bChangeMask; }
544 void SetChangeMark() { m_bChangeMask = TRUE; }
545 void ClearChangeMark() { m_bChangeMask = FALSE; }
546 CFX_WideString GetPath();
Tom Sepez540c4362015-11-24 13:33:57 -0800547 UnderlyingPageType* GetPage(int nIndex);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700548 CPDFDoc_Environment* GetEnv() { return m_pEnv; }
549 void ProcJavascriptFun();
550 FX_BOOL ProcOpenAction();
551 CPDF_OCContext* GetOCContext();
552
553 private:
Tom Sepez540c4362015-11-24 13:33:57 -0800554 std::map<UnderlyingPageType*, CPDFSDK_PageView*> m_pageMap;
Tom Sepez50d12ad2015-11-24 09:50:51 -0800555 UnderlyingDocumentType* m_pDoc;
Oliver Chang24752492015-10-30 16:08:20 -0700556 nonstd::unique_ptr<CPDFSDK_InterForm> m_pInterForm;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700557 CPDFSDK_Annot* m_pFocusAnnot;
558 CPDFDoc_Environment* m_pEnv;
Oliver Chang24752492015-10-30 16:08:20 -0700559 nonstd::unique_ptr<CPDF_OCContext> m_pOccontent;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700560 FX_BOOL m_bChangeMask;
Oliver Chang972b78d2015-10-30 12:59:29 -0700561 FX_BOOL m_bBeingDestroyed;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700562};
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700563class CPDFSDK_PageView final {
564 public:
Tom Sepez540c4362015-11-24 13:33:57 -0800565 CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc, UnderlyingPageType* page);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700566 ~CPDFSDK_PageView();
Tom Sepez40e9ff32015-11-30 12:39:54 -0800567
568#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700569 void PageView_OnDraw(CFX_RenderDevice* pDevice,
570 CPDF_Matrix* pUser2Device,
571 CPDF_RenderOptions* pOptions,
Lei Zhangf0e2e1b2015-11-02 13:27:54 -0800572 const FX_RECT& pClip);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800573#else // PDF_ENABLE_XFA
574 void PageView_OnDraw(CFX_RenderDevice* pDevice,
575 CPDF_Matrix* pUser2Device,
576 CPDF_RenderOptions* pOptions);
577#endif // PDF_ENABLE_XFA
578
Lei Zhang1b700c32015-10-30 23:55:35 -0700579 const CPDF_Annot* GetPDFAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700580 CPDFSDK_Annot* GetFXAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
Lei Zhang1b700c32015-10-30 23:55:35 -0700581 const CPDF_Annot* GetPDFWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700582 CPDFSDK_Annot* GetFXWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
583 CPDFSDK_Annot* GetFocusAnnot();
584 void SetFocusAnnot(CPDFSDK_Annot* pSDKAnnot, FX_UINT nFlag = 0) {
585 m_pSDKDoc->SetFocusAnnot(pSDKAnnot, nFlag);
586 }
587 FX_BOOL KillFocusAnnot(FX_UINT nFlag = 0) {
588 return m_pSDKDoc->KillFocusAnnot(nFlag);
589 }
Oliver Chang972b78d2015-10-30 12:59:29 -0700590 void KillFocusAnnotIfNeeded();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700591 FX_BOOL Annot_HasAppearance(CPDF_Annot* pAnnot);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700592
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700593 CPDFSDK_Annot* AddAnnot(CPDF_Dictionary* pDict);
594 CPDFSDK_Annot* AddAnnot(const FX_CHAR* lpSubType, CPDF_Dictionary* pDict);
595 CPDFSDK_Annot* AddAnnot(CPDF_Annot* pPDFAnnot);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800596
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700597 FX_BOOL DeleteAnnot(CPDFSDK_Annot* pAnnot);
Lei Zhang50218532015-10-30 14:03:43 -0700598 size_t CountAnnots() const;
Lei Zhangbf60b292015-10-26 12:14:35 -0700599 CPDFSDK_Annot* GetAnnot(size_t nIndex);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700600 CPDFSDK_Annot* GetAnnotByDict(CPDF_Dictionary* pDict);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800601
602#ifdef PDF_ENABLE_XFA
603 CPDFSDK_Annot* AddAnnot(IXFA_Widget* pPDFAnnot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700604 CPDFSDK_Annot* GetAnnotByXFAWidget(IXFA_Widget* hWidget);
605 CPDFXFA_Page* GetPDFXFAPage() { return m_page; }
606 CPDF_Page* GetPDFPage();
Tom Sepez40e9ff32015-11-30 12:39:54 -0800607#else
608 CPDF_Page* GetPDFPage() { return m_page; }
609#endif // PDF_ENABLE_XFA
610
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700611 CPDF_Document* GetPDFDocument();
612 CPDFSDK_Document* GetSDKDocument() { return m_pSDKDoc; }
613 FX_BOOL OnLButtonDown(const CPDF_Point& point, FX_UINT nFlag);
614 FX_BOOL OnLButtonUp(const CPDF_Point& point, FX_UINT nFlag);
Tom Sepez51da0932015-11-25 16:05:49 -0800615#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700616 FX_BOOL OnRButtonDown(const CPDF_Point& point, FX_UINT nFlag);
617 FX_BOOL OnRButtonUp(const CPDF_Point& point, FX_UINT nFlag);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800618#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700619 FX_BOOL OnChar(int nChar, FX_UINT nFlag);
620 FX_BOOL OnKeyDown(int nKeyCode, int nFlag);
621 FX_BOOL OnKeyUp(int nKeyCode, int nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700622
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700623 FX_BOOL OnMouseMove(const CPDF_Point& point, int nFlag);
624 FX_BOOL OnMouseWheel(double deltaX,
625 double deltaY,
626 const CPDF_Point& point,
627 int nFlag);
Lei Zhang1b700c32015-10-30 23:55:35 -0700628 bool IsValidAnnot(const CPDF_Annot* p) const;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700629 void GetCurrentMatrix(CPDF_Matrix& matrix) { matrix = m_curMatrix; }
630 void UpdateRects(CFX_RectArray& rects);
631 void UpdateView(CPDFSDK_Annot* pAnnot);
Lei Zhangbf60b292015-10-26 12:14:35 -0700632 const std::vector<CPDFSDK_Annot*>& GetAnnotList() const {
633 return m_fxAnnotArray;
634 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700635
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700636 int GetPageIndex();
637 void LoadFXAnnots();
638 void SetValid(FX_BOOL bValid) { m_bValid = bValid; }
639 FX_BOOL IsValid() { return m_bValid; }
640 void SetLock(FX_BOOL bLocked) { m_bLocked = bLocked; }
641 FX_BOOL IsLocked() { return m_bLocked; }
Tom Sepez51da0932015-11-25 16:05:49 -0800642#ifndef PDF_ENABLE_XFA
643 void TakeOverPage() { m_bTakeOverPage = TRUE; }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800644#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700645
646 private:
647 void PageView_OnHighlightFormFields(CFX_RenderDevice* pDevice,
648 CPDFSDK_Widget* pWidget);
Lei Zhangbf60b292015-10-26 12:14:35 -0700649
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700650 CPDF_Matrix m_curMatrix;
Tom Sepez540c4362015-11-24 13:33:57 -0800651 UnderlyingPageType* m_page;
Lei Zhangbf60b292015-10-26 12:14:35 -0700652 nonstd::unique_ptr<CPDF_AnnotList> m_pAnnotList;
653 std::vector<CPDFSDK_Annot*> m_fxAnnotArray;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700654 CPDFSDK_Document* m_pSDKDoc;
Tom Sepez40e9ff32015-11-30 12:39:54 -0800655#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700656 CPDFSDK_Annot* m_CaptureWidget;
Tom Sepez40e9ff32015-11-30 12:39:54 -0800657#else // PDF_ENABLE_XFA
658 CPDFSDK_Widget* m_CaptureWidget;
659 FX_BOOL m_bTakeOverPage;
660#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700661 FX_BOOL m_bEnterWidget;
662 FX_BOOL m_bExitWidget;
663 FX_BOOL m_bOnWidget;
664 FX_BOOL m_bValid;
665 FX_BOOL m_bLocked;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700666};
667
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700668template <class TYPE>
669class CGW_ArrayTemplate : public CFX_ArrayTemplate<TYPE> {
670 public:
671 CGW_ArrayTemplate() {}
Lei Zhang2b1a2d52015-08-14 22:16:22 -0700672 ~CGW_ArrayTemplate() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700673
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700674 typedef int (*LP_COMPARE)(TYPE p1, TYPE p2);
Tom Sepezc6ab1722015-02-05 15:27:25 -0800675
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700676 void Sort(LP_COMPARE pCompare, FX_BOOL bAscent = TRUE) {
677 int nSize = this->GetSize();
678 QuickSort(0, nSize - 1, bAscent, pCompare);
679 }
Tom Sepezc6ab1722015-02-05 15:27:25 -0800680
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700681 private:
682 void QuickSort(FX_UINT nStartPos,
683 FX_UINT nStopPos,
684 FX_BOOL bAscend,
685 LP_COMPARE pCompare) {
686 if (nStartPos >= nStopPos)
687 return;
688
689 if ((nStopPos - nStartPos) == 1) {
690 TYPE Value1 = this->GetAt(nStartPos);
691 TYPE Value2 = this->GetAt(nStopPos);
692
693 int iGreate = (*pCompare)(Value1, Value2);
694 if ((bAscend && iGreate > 0) || (!bAscend && iGreate < 0)) {
695 this->SetAt(nStartPos, Value2);
696 this->SetAt(nStopPos, Value1);
697 }
698 return;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700699 }
Tom Sepezc6ab1722015-02-05 15:27:25 -0800700
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700701 FX_UINT m = nStartPos + (nStopPos - nStartPos) / 2;
702 FX_UINT i = nStartPos;
Tom Sepezc6ab1722015-02-05 15:27:25 -0800703
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700704 TYPE Value = this->GetAt(m);
Tom Sepezc6ab1722015-02-05 15:27:25 -0800705
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700706 while (i < m) {
707 TYPE temp = this->GetAt(i);
Tom Sepezc6ab1722015-02-05 15:27:25 -0800708
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700709 int iGreate = (*pCompare)(temp, Value);
710 if ((bAscend && iGreate > 0) || (!bAscend && iGreate < 0)) {
711 this->InsertAt(m + 1, temp);
712 this->RemoveAt(i);
713 m--;
714 } else {
715 i++;
716 }
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700717 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700718
719 FX_UINT j = nStopPos;
720
721 while (j > m) {
722 TYPE temp = this->GetAt(j);
723
724 int iGreate = (*pCompare)(temp, Value);
725 if ((bAscend && iGreate < 0) || (!bAscend && iGreate > 0)) {
726 this->RemoveAt(j);
727 this->InsertAt(m, temp);
728 m++;
729 } else {
730 j--;
731 }
732 }
733
734 if (nStartPos < m)
735 QuickSort(nStartPos, m, bAscend, pCompare);
736 if (nStopPos > m)
737 QuickSort(m, nStopPos, bAscend, pCompare);
738 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700739};
740
Tom Sepez19922bb2015-05-28 13:23:12 -0700741#endif // FPDFSDK_INCLUDE_FSDK_MGR_H_