blob: c35d2ff344a373c80f05d7c3f66630c2dbeaccae [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 "fpdfxfa/fpdfxfa_doc.h"
14#include "fpdfxfa/fpdfxfa_page.h"
15#include "fsdk_actionhandler.h"
16#include "fsdk_annothandler.h"
17#include "fsdk_baseannot.h"
18#include "fsdk_baseform.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070019#include "fsdk_common.h"
20#include "fsdk_define.h"
21#include "fx_systemhandler.h"
Lei Zhange5b0bd12015-06-19 17:15:41 -070022#include "javascript/IJavaScript.h"
Lei Zhangb4e7f302015-11-06 15:52:32 -080023#include "public/fpdf_formfill.h"
24#include "public/fpdf_fwlevent.h" // cross platform keycode and events define.
Lei Zhang8241df72015-11-06 14:38:48 -080025#include "third_party/base/nonstd_unique_ptr.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070026
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070027class CFFL_IFormFiller;
Tom Sepezdcbc02f2015-07-17 09:16:17 -070028class CPDFSDK_ActionHandler;
29class CPDFSDK_Annot;
30class CPDFSDK_Document;
31class CPDFSDK_InterForm;
32class CPDFSDK_PageView;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070033class CPDFSDK_Widget;
34class IFX_SystemHandler;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070035
Nico Weber9d8ec5a2015-08-04 13:00:21 -070036class CPDFDoc_Environment final {
37 public:
Tom Sepez50d12ad2015-11-24 09:50:51 -080038 CPDFDoc_Environment(UnderlyingDocumentType* pDoc, FPDF_FORMFILLINFO* pFFinfo);
Tom Sepezdfbf8e72015-10-14 14:17:26 -070039 ~CPDFDoc_Environment();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070040
Tom Sepezdfbf8e72015-10-14 14:17:26 -070041 void Release() {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070042 if (m_pInfo && m_pInfo->Release)
43 m_pInfo->Release(m_pInfo);
44 delete this;
45 }
46
47 void FFI_Invalidate(FPDF_PAGE page,
48 double left,
49 double top,
50 double right,
51 double bottom) {
52 if (m_pInfo && m_pInfo->FFI_Invalidate)
53 m_pInfo->FFI_Invalidate(m_pInfo, page, left, top, right, bottom);
54 }
55
56 void FFI_OutputSelectedRect(FPDF_PAGE page,
57 double left,
58 double top,
59 double right,
60 double bottom) {
61 if (m_pInfo && m_pInfo->FFI_OutputSelectedRect)
62 m_pInfo->FFI_OutputSelectedRect(m_pInfo, page, left, top, right, bottom);
63 }
64
65 void FFI_SetCursor(int nCursorType) {
66 if (m_pInfo && m_pInfo->FFI_SetCursor)
67 m_pInfo->FFI_SetCursor(m_pInfo, nCursorType);
68 }
69
70 int FFI_SetTimer(int uElapse, TimerCallback lpTimerFunc) {
71 if (m_pInfo && m_pInfo->FFI_SetTimer)
72 return m_pInfo->FFI_SetTimer(m_pInfo, uElapse, lpTimerFunc);
73 return -1;
74 }
75
76 void FFI_KillTimer(int nTimerID) {
77 if (m_pInfo && m_pInfo->FFI_KillTimer)
78 m_pInfo->FFI_KillTimer(m_pInfo, nTimerID);
79 }
80
Tom Sepez468e5892015-10-13 15:49:36 -070081 FX_SYSTEMTIME FFI_GetLocalTime() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070082 FX_SYSTEMTIME fxtime;
83 if (m_pInfo && m_pInfo->FFI_GetLocalTime) {
84 FPDF_SYSTEMTIME systime = m_pInfo->FFI_GetLocalTime(m_pInfo);
85 fxtime.wDay = systime.wDay;
86 fxtime.wDayOfWeek = systime.wDayOfWeek;
87 fxtime.wHour = systime.wHour;
88 fxtime.wMilliseconds = systime.wMilliseconds;
89 fxtime.wMinute = systime.wMinute;
90 fxtime.wMonth = systime.wMonth;
91 fxtime.wSecond = systime.wSecond;
92 fxtime.wYear = systime.wYear;
Tom Sepezdcbc02f2015-07-17 09:16:17 -070093 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070094 return fxtime;
95 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070096
Nico Weber9d8ec5a2015-08-04 13:00:21 -070097 void FFI_OnChange() {
98 if (m_pInfo && m_pInfo->FFI_OnChange)
99 m_pInfo->FFI_OnChange(m_pInfo);
100 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700101
Tom Sepez468e5892015-10-13 15:49:36 -0700102 FX_BOOL FFI_IsSHIFTKeyDown(FX_DWORD nFlag) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700103 return (nFlag & FWL_EVENTFLAG_ShiftKey) != 0;
104 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700105
Tom Sepez468e5892015-10-13 15:49:36 -0700106 FX_BOOL FFI_IsCTRLKeyDown(FX_DWORD nFlag) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700107 return (nFlag & FWL_EVENTFLAG_ControlKey) != 0;
108 }
Tom Sepezc6ab1722015-02-05 15:27:25 -0800109
Tom Sepez468e5892015-10-13 15:49:36 -0700110 FX_BOOL FFI_IsALTKeyDown(FX_DWORD nFlag) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700111 return (nFlag & FWL_EVENTFLAG_AltKey) != 0;
112 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700113
Tom Sepez468e5892015-10-13 15:49:36 -0700114 FX_BOOL FFI_IsINSERTKeyDown(FX_DWORD nFlag) const { return FALSE; }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700115
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700116 int JS_appAlert(const FX_WCHAR* Msg,
117 const FX_WCHAR* Title,
118 FX_UINT Type,
119 FX_UINT Icon);
120 int JS_appResponse(const FX_WCHAR* Question,
121 const FX_WCHAR* Title,
122 const FX_WCHAR* Default,
123 const FX_WCHAR* cLabel,
124 FPDF_BOOL bPassword,
125 void* response,
126 int length);
Tom Sepezc6ab1722015-02-05 15:27:25 -0800127
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700128 void JS_appBeep(int nType) {
129 if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_beep)
130 m_pInfo->m_pJsPlatform->app_beep(m_pInfo->m_pJsPlatform, nType);
131 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700132
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700133 CFX_WideString JS_fieldBrowse();
134 CFX_WideString JS_docGetFilePath();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700135
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700136 void JS_docSubmitForm(void* formData, int length, const FX_WCHAR* URL);
137 void JS_docmailForm(void* mailData,
138 int length,
139 FPDF_BOOL bUI,
140 const FX_WCHAR* To,
141 const FX_WCHAR* Subject,
142 const FX_WCHAR* CC,
143 const FX_WCHAR* BCC,
144 const FX_WCHAR* Msg);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700145
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700146 void JS_docprint(FPDF_BOOL bUI,
147 int nStart,
148 int nEnd,
149 FPDF_BOOL bSilent,
150 FPDF_BOOL bShrinkToFit,
151 FPDF_BOOL bPrintAsImage,
152 FPDF_BOOL bReverse,
153 FPDF_BOOL bAnnotations) {
154 if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->Doc_print)
155 m_pInfo->m_pJsPlatform->Doc_print(m_pInfo->m_pJsPlatform, bUI, nStart,
156 nEnd, bSilent, bShrinkToFit,
157 bPrintAsImage, bReverse, bAnnotations);
158 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700159
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700160 void JS_docgotoPage(int nPageNum) {
161 if (m_pInfo && m_pInfo->m_pJsPlatform &&
162 m_pInfo->m_pJsPlatform->Doc_gotoPage)
163 m_pInfo->m_pJsPlatform->Doc_gotoPage(m_pInfo->m_pJsPlatform, nPageNum);
164 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700165
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700166 FPDF_PAGE FFI_GetPage(FPDF_DOCUMENT document, int nPageIndex) {
167 if (m_pInfo && m_pInfo->FFI_GetPage)
168 return m_pInfo->FFI_GetPage(m_pInfo, document, nPageIndex);
169 return NULL;
170 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700171
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700172 FPDF_PAGE FFI_GetCurrentPage(FPDF_DOCUMENT document) {
173 if (m_pInfo && m_pInfo->FFI_GetCurrentPage)
174 return m_pInfo->FFI_GetCurrentPage(m_pInfo, document);
175 return NULL;
176 }
Tom Sepez0d3b5cc2014-07-30 13:03:52 -0700177
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700178 int FFI_GetRotation(FPDF_PAGE page) {
179 if (m_pInfo && m_pInfo->FFI_GetRotation)
180 return m_pInfo->FFI_GetRotation(m_pInfo, page);
181 return 0;
182 }
Tom Sepez0d3b5cc2014-07-30 13:03:52 -0700183
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700184 void FFI_ExecuteNamedAction(const FX_CHAR* namedAction) {
185 if (m_pInfo && m_pInfo->FFI_ExecuteNamedAction)
186 m_pInfo->FFI_ExecuteNamedAction(m_pInfo, namedAction);
187 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700188
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700189 void FFI_OnSetFieldInputFocus(void* field,
190 FPDF_WIDESTRING focusText,
191 FPDF_DWORD nTextLen,
192 FX_BOOL bFocus) {
193 if (m_pInfo && m_pInfo->FFI_SetTextFieldFocus)
194 m_pInfo->FFI_SetTextFieldFocus(m_pInfo, focusText, nTextLen, bFocus);
195 }
Tom Sepez0d3b5cc2014-07-30 13:03:52 -0700196
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700197 void FFI_DoURIAction(const FX_CHAR* bsURI) {
198 if (m_pInfo && m_pInfo->FFI_DoURIAction)
199 m_pInfo->FFI_DoURIAction(m_pInfo, bsURI);
200 }
Tom Sepez0d3b5cc2014-07-30 13:03:52 -0700201
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700202 void FFI_DoGoToAction(int nPageIndex,
203 int zoomMode,
204 float* fPosArray,
205 int sizeOfArray) {
206 if (m_pInfo && m_pInfo->FFI_DoGoToAction)
207 m_pInfo->FFI_DoGoToAction(m_pInfo, nPageIndex, zoomMode, fPosArray,
208 sizeOfArray);
209 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700210
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700211 void FFI_DisplayCaret(FPDF_PAGE page,
212 FPDF_BOOL bVisible,
213 double left,
214 double top,
215 double right,
216 double bottom) {
217 if (m_pInfo && m_pInfo->FFI_DisplayCaret)
218 m_pInfo->FFI_DisplayCaret(m_pInfo, page, bVisible, left, top, right,
219 bottom);
220 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700221
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700222 int FFI_GetCurrentPageIndex(FPDF_DOCUMENT document) {
223 if (m_pInfo && m_pInfo->FFI_GetCurrentPageIndex)
224 m_pInfo->FFI_GetCurrentPageIndex(m_pInfo, document);
225 return -1;
226 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700227
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700228 int FFI_SetCurrentPage(FPDF_DOCUMENT document, int iCurPage) {
229 if (m_pInfo && m_pInfo->FFI_SetCurrentPage)
230 m_pInfo->FFI_SetCurrentPage(m_pInfo, document, iCurPage);
231 return -1;
232 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700233
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700234 CFX_WideString FFI_GetAppName() const { return CFX_WideString(L"Acrobat"); }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700235
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700236 CFX_WideString FFI_GetPlatform() {
237 if (m_pInfo && m_pInfo->FFI_GetPlatform) {
238 int nRequiredLen = m_pInfo->FFI_GetPlatform(m_pInfo, NULL, 0);
239 if (nRequiredLen <= 0)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700240 return L"";
Bo Xufdc00a72014-10-28 23:03:33 -0700241
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700242 char* pbuff = new char[nRequiredLen];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700243 memset(pbuff, 0, nRequiredLen);
244 int nActualLen = m_pInfo->FFI_GetPlatform(m_pInfo, pbuff, nRequiredLen);
245 if (nActualLen <= 0 || nActualLen > nRequiredLen) {
246 delete[] pbuff;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700247 return L"";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700248 }
249 CFX_ByteString bsRet = CFX_ByteString(pbuff, nActualLen);
250 CFX_WideString wsRet = CFX_WideString::FromUTF16LE(
251 (unsigned short*)bsRet.GetBuffer(bsRet.GetLength()),
252 bsRet.GetLength() / sizeof(unsigned short));
253 delete[] pbuff;
254 return wsRet;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700255 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700256 return L"";
257 }
Bo Xufdc00a72014-10-28 23:03:33 -0700258
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700259 void FFI_GotoURL(FPDF_DOCUMENT document,
260 const CFX_WideStringC& wsURL,
261 FX_BOOL bAppend) {
262 if (m_pInfo && m_pInfo->FFI_GotoURL) {
263 CFX_ByteString bsTo = CFX_WideString(wsURL).UTF16LE_Encode();
264 FPDF_WIDESTRING pTo = (FPDF_WIDESTRING)bsTo.GetBuffer(wsURL.GetLength());
265 m_pInfo->FFI_GotoURL(m_pInfo, document, pTo);
266 bsTo.ReleaseBuffer();
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700267 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700268 }
Bo Xufdc00a72014-10-28 23:03:33 -0700269
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700270 void FFI_GetURL(FPDF_DOCUMENT document, CFX_WideString& wsURL) {
271 wsURL = CFX_WideString();
272 }
273
274 void FFI_AddDoRecord(FPDF_DOCUMENT document, FPDF_WIDGET hWidget) {}
275 void FFI_PageEvent(FPDF_PAGE page, FPDF_DWORD flag) {}
276
277 void FFI_GetPageViewRect(FPDF_PAGE page, FS_RECTF& dstRect) {
278 if (m_pInfo && m_pInfo->FFI_GetPageViewRect) {
279 double left;
280 double top;
281 double right;
282 double bottom;
283 m_pInfo->FFI_GetPageViewRect(m_pInfo, page, &left, &top, &right, &bottom);
284
285 dstRect.left = static_cast<float>(left);
286 dstRect.top = static_cast<float>(top < bottom ? bottom : top);
287 dstRect.bottom = static_cast<float>(top < bottom ? top : bottom);
288 dstRect.right = static_cast<float>(right);
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700289 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700290 }
Bo Xufdc00a72014-10-28 23:03:33 -0700291
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700292 FX_BOOL FFI_PopupMenu(FPDF_PAGE page,
293 FPDF_WIDGET hWidget,
294 int menuFlag,
295 CFX_PointF ptPopup,
296 const CFX_PointF* pRectExclude) {
297 if (m_pInfo && m_pInfo->FFI_PopupMenu)
298 return m_pInfo->FFI_PopupMenu(m_pInfo, page, hWidget, menuFlag, ptPopup.x,
299 ptPopup.y);
300 return FALSE;
301 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700302
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700303 void FFI_Alert(FPDF_WIDESTRING Msg,
304 FPDF_WIDESTRING Title,
305 int Type,
306 int Icon) {
307 if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_alert)
308 m_pInfo->m_pJsPlatform->app_alert(m_pInfo->m_pJsPlatform, Msg, Title,
309 Type, Icon);
310 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700311
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700312 void FFI_EmailTo(FPDF_FILEHANDLER* fileHandler,
313 FPDF_WIDESTRING pTo,
314 FPDF_WIDESTRING pSubject,
315 FPDF_WIDESTRING pCC,
316 FPDF_WIDESTRING pBcc,
317 FPDF_WIDESTRING pMsg) {
318 if (m_pInfo && m_pInfo->FFI_EmailTo)
319 m_pInfo->FFI_EmailTo(m_pInfo, fileHandler, pTo, pSubject, pCC, pBcc,
320 pMsg);
321 }
322
323 void FFI_UploadTo(FPDF_FILEHANDLER* fileHandler,
324 int fileFlag,
325 FPDF_WIDESTRING uploadTo) {
326 if (m_pInfo && m_pInfo->FFI_UploadTo)
327 m_pInfo->FFI_UploadTo(m_pInfo, fileHandler, fileFlag, uploadTo);
328 }
329
330 FPDF_FILEHANDLER* FFI_OpenFile(int fileType,
331 FPDF_WIDESTRING wsURL,
332 const char* mode) {
333 if (m_pInfo && m_pInfo->FFI_OpenFile)
334 return m_pInfo->FFI_OpenFile(m_pInfo, fileType, wsURL, mode);
335 return NULL;
336 }
337
338 CFX_WideString FFI_GetFilePath(FPDF_FILEHANDLER* pFileHandler) const {
339 return L"";
340 }
341
342 int FFI_GetDocumentCount() const { return 0; }
343 int FFI_GetCurDocument() const { return 0; }
344
345 IFX_FileRead* FFI_DownloadFromURL(const FX_WCHAR* url) {
346 if (m_pInfo && m_pInfo->FFI_DownloadFromURL) {
347 CFX_ByteString bstrURL = CFX_WideString(url).UTF16LE_Encode();
348 FPDF_WIDESTRING wsURL =
349 (FPDF_WIDESTRING)bstrURL.GetBuffer(bstrURL.GetLength());
350
351 FPDF_LPFILEHANDLER fileHandler =
352 m_pInfo->FFI_DownloadFromURL(m_pInfo, wsURL);
353
Lei Zhangdb5256f2015-10-02 10:11:43 -0700354 return new CFPDF_FileStream(fileHandler);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700355 }
356 return NULL;
357 }
358
359 CFX_WideString FFI_PostRequestURL(const FX_WCHAR* wsURL,
360 const FX_WCHAR* wsData,
361 const FX_WCHAR* wsContentType,
362 const FX_WCHAR* wsEncode,
363 const FX_WCHAR* wsHeader) {
364 if (m_pInfo && m_pInfo->FFI_PostRequestURL) {
365 CFX_ByteString bsURL = CFX_WideString(wsURL).UTF16LE_Encode();
366 FPDF_WIDESTRING URL = (FPDF_WIDESTRING)bsURL.GetBuffer(bsURL.GetLength());
367
368 CFX_ByteString bsData = CFX_WideString(wsData).UTF16LE_Encode();
369 FPDF_WIDESTRING data =
370 (FPDF_WIDESTRING)bsData.GetBuffer(bsData.GetLength());
371
372 CFX_ByteString bsContentType =
373 CFX_WideString(wsContentType).UTF16LE_Encode();
374 FPDF_WIDESTRING contentType =
375 (FPDF_WIDESTRING)bsContentType.GetBuffer(bsContentType.GetLength());
376
377 CFX_ByteString bsEncode = CFX_WideString(wsEncode).UTF16LE_Encode();
378 FPDF_WIDESTRING encode =
379 (FPDF_WIDESTRING)bsEncode.GetBuffer(bsEncode.GetLength());
380
381 CFX_ByteString bsHeader = CFX_WideString(wsHeader).UTF16LE_Encode();
382 FPDF_WIDESTRING header =
383 (FPDF_WIDESTRING)bsHeader.GetBuffer(bsHeader.GetLength());
384
385 FPDF_BSTR respone;
386 FPDF_BStr_Init(&respone);
387 m_pInfo->FFI_PostRequestURL(m_pInfo, URL, data, contentType, encode,
388 header, &respone);
389
390 CFX_WideString wsRet = CFX_WideString::FromUTF16LE(
391 (unsigned short*)respone.str, respone.len / sizeof(unsigned short));
392 FPDF_BStr_Clear(&respone);
393
394 return wsRet;
395 }
396 return L"";
397 }
398
399 FPDF_BOOL FFI_PutRequestURL(const FX_WCHAR* wsURL,
400 const FX_WCHAR* wsData,
401 const FX_WCHAR* wsEncode) {
402 if (m_pInfo && m_pInfo->FFI_PutRequestURL) {
403 CFX_ByteString bsURL = CFX_WideString(wsURL).UTF16LE_Encode();
404 FPDF_WIDESTRING URL = (FPDF_WIDESTRING)bsURL.GetBuffer(bsURL.GetLength());
405
406 CFX_ByteString bsData = CFX_WideString(wsData).UTF16LE_Encode();
407 FPDF_WIDESTRING data =
408 (FPDF_WIDESTRING)bsData.GetBuffer(bsData.GetLength());
409
410 CFX_ByteString bsEncode = CFX_WideString(wsEncode).UTF16LE_Encode();
411 FPDF_WIDESTRING encode =
412 (FPDF_WIDESTRING)bsEncode.GetBuffer(bsEncode.GetLength());
413
414 return m_pInfo->FFI_PutRequestURL(m_pInfo, URL, data, encode);
415 }
416 return FALSE;
417 }
418
419 FPDF_BOOL FFI_ShowFileDialog(const FX_WCHAR* wsTitle,
420 const FX_WCHAR* wsFilter,
421 CFX_WideStringArray& wsPathArr,
422 FX_BOOL bOpen) {
423 return FALSE;
424 }
425
426 CFX_WideString FFI_GetLanguage() {
427 if (m_pInfo && m_pInfo->FFI_GetLanguage) {
428 int nRequiredLen = m_pInfo->FFI_GetLanguage(m_pInfo, NULL, 0);
429 if (nRequiredLen <= 0)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700430 return L"";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700431
432 char* pbuff = new char[nRequiredLen];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700433 memset(pbuff, 0, nRequiredLen);
434 int nActualLen = m_pInfo->FFI_GetLanguage(m_pInfo, pbuff, nRequiredLen);
435 if (nActualLen <= 0 || nActualLen > nRequiredLen) {
436 delete[] pbuff;
437 return L"";
438 }
439 CFX_ByteString bsRet = CFX_ByteString(pbuff, nActualLen);
440 CFX_WideString wsRet = CFX_WideString::FromUTF16LE(
441 (unsigned short*)bsRet.GetBuffer(bsRet.GetLength()),
442 bsRet.GetLength() / sizeof(unsigned short));
443 delete[] pbuff;
444 return wsRet;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700445 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700446 return L"";
447 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700448
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700449 FX_BOOL IsJSInitiated() const { return m_pInfo && m_pInfo->m_pJsPlatform; }
450 void SetSDKDocument(CPDFSDK_Document* pFXDoc) { m_pSDKDoc = pFXDoc; }
451 CPDFSDK_Document* GetSDKDocument() const { return m_pSDKDoc; }
Tom Sepez50d12ad2015-11-24 09:50:51 -0800452 UnderlyingDocumentType* GetUnderlyingDocument() const {
453 return m_pUnderlyingDoc;
454 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700455 CFX_ByteString GetAppName() const { return ""; }
Oliver Chang24752492015-10-30 16:08:20 -0700456 IFX_SystemHandler* GetSysHandler() const { return m_pSysHandler.get(); }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700457 FPDF_FORMFILLINFO* GetFormFillInfo() const { return m_pInfo; }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700458
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700459 CFFL_IFormFiller* GetIFormFiller(); // Creates if not present.
460 CPDFSDK_AnnotHandlerMgr* GetAnnotHandlerMgr(); // Creates if not present.
Tom Sepezba038bc2015-10-08 12:03:00 -0700461 IJS_Runtime* GetJSRuntime(); // Creates if not present.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700462 CPDFSDK_ActionHandler* GetActionHander(); // Creates if not present.
Tom Sepez2f3dfef2015-03-02 15:35:26 -0800463
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700464 private:
Oliver Chang24752492015-10-30 16:08:20 -0700465 nonstd::unique_ptr<CPDFSDK_AnnotHandlerMgr> m_pAnnotHandlerMgr;
466 nonstd::unique_ptr<CPDFSDK_ActionHandler> m_pActionHandler;
Tom Sepezba038bc2015-10-08 12:03:00 -0700467 nonstd::unique_ptr<IJS_Runtime> m_pJSRuntime;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700468 FPDF_FORMFILLINFO* const m_pInfo;
469 CPDFSDK_Document* m_pSDKDoc;
Tom Sepez50d12ad2015-11-24 09:50:51 -0800470 UnderlyingDocumentType* const m_pUnderlyingDoc;
Oliver Chang24752492015-10-30 16:08:20 -0700471 nonstd::unique_ptr<CFFL_IFormFiller> m_pIFormFiller;
472 nonstd::unique_ptr<IFX_SystemHandler> m_pSysHandler;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700473};
474
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700475class CPDFSDK_Document {
476 public:
Tom Sepez50d12ad2015-11-24 09:50:51 -0800477 CPDFSDK_Document(UnderlyingDocumentType* pDoc, CPDFDoc_Environment* pEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700478 ~CPDFSDK_Document();
Tom Sepez2f3dfef2015-03-02 15:35:26 -0800479
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700480 CPDFSDK_InterForm* GetInterForm();
Tom Sepez50d12ad2015-11-24 09:50:51 -0800481
482 UnderlyingDocumentType* GetUnderlyingDocument() const {
483 return GetXFADocument();
484 }
Tom Sepezbf59a072015-10-21 14:07:23 -0700485 CPDF_Document* GetPDFDocument() const {
486 return m_pDoc ? m_pDoc->GetPDFDoc() : nullptr;
487 }
Tom Sepez50d12ad2015-11-24 09:50:51 -0800488 CPDFXFA_Document* GetXFADocument() const { return m_pDoc; }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700489
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700490 int GetPageViewCount() const { return m_pageMap.size(); }
Tom Sepez50d12ad2015-11-24 09:50:51 -0800491 CPDFSDK_PageView* GetPageView(UnderlyingPageType* pPDFXFAPage,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700492 FX_BOOL ReNew = TRUE);
493 CPDFSDK_PageView* GetPageView(int nIndex);
494 CPDFSDK_PageView* GetCurrentView();
Tom Sepez50d12ad2015-11-24 09:50:51 -0800495 void RemovePageView(UnderlyingPageType* pPDFPage);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700496 void UpdateAllViews(CPDFSDK_PageView* pSender, CPDFSDK_Annot* pAnnot);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700497
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700498 CPDFSDK_Annot* GetFocusAnnot();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700499
Tom Sepezba038bc2015-10-08 12:03:00 -0700500 IJS_Runtime* GetJsRuntime();
Tom Sepezc6ab1722015-02-05 15:27:25 -0800501
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700502 FX_BOOL SetFocusAnnot(CPDFSDK_Annot* pAnnot, FX_UINT nFlag = 0);
503 FX_BOOL KillFocusAnnot(FX_UINT nFlag = 0);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700504
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700505 FX_BOOL ExtractPages(const CFX_WordArray& arrExtraPages,
506 CPDF_Document* pDstDoc);
507 FX_BOOL InsertPages(int nInsertAt,
508 const CPDF_Document* pSrcDoc,
509 const CFX_WordArray& arrSrcPages);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700510 FX_BOOL ReplacePages(int nPage,
511 const CPDF_Document* pSrcDoc,
512 const CFX_WordArray& arrSrcPages);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700513
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700514 void OnCloseDocument();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700515
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700516 int GetPageCount() { return m_pDoc->GetPageCount(); }
517 FX_BOOL GetPermissions(int nFlag);
518 FX_BOOL GetChangeMark() { return m_bChangeMask; }
519 void SetChangeMark() { m_bChangeMask = TRUE; }
520 void ClearChangeMark() { m_bChangeMask = FALSE; }
521 CFX_WideString GetPath();
522 CPDFXFA_Page* GetPage(int nIndex);
523 CPDFDoc_Environment* GetEnv() { return m_pEnv; }
524 void ProcJavascriptFun();
525 FX_BOOL ProcOpenAction();
526 CPDF_OCContext* GetOCContext();
527
528 private:
529 std::map<CPDFXFA_Page*, CPDFSDK_PageView*> m_pageMap;
Tom Sepez50d12ad2015-11-24 09:50:51 -0800530 UnderlyingDocumentType* m_pDoc;
Oliver Chang24752492015-10-30 16:08:20 -0700531 nonstd::unique_ptr<CPDFSDK_InterForm> m_pInterForm;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700532 CPDFSDK_Annot* m_pFocusAnnot;
533 CPDFDoc_Environment* m_pEnv;
Oliver Chang24752492015-10-30 16:08:20 -0700534 nonstd::unique_ptr<CPDF_OCContext> m_pOccontent;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700535 FX_BOOL m_bChangeMask;
Oliver Chang972b78d2015-10-30 12:59:29 -0700536 FX_BOOL m_bBeingDestroyed;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700537};
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700538class CPDFSDK_PageView final {
539 public:
540 CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc, CPDFXFA_Page* page);
541 ~CPDFSDK_PageView();
542 void PageView_OnDraw(CFX_RenderDevice* pDevice,
543 CPDF_Matrix* pUser2Device,
544 CPDF_RenderOptions* pOptions,
Lei Zhangf0e2e1b2015-11-02 13:27:54 -0800545 const FX_RECT& pClip);
Lei Zhang1b700c32015-10-30 23:55:35 -0700546 const CPDF_Annot* GetPDFAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700547 CPDFSDK_Annot* GetFXAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
Lei Zhang1b700c32015-10-30 23:55:35 -0700548 const CPDF_Annot* GetPDFWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700549 CPDFSDK_Annot* GetFXWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
550 CPDFSDK_Annot* GetFocusAnnot();
551 void SetFocusAnnot(CPDFSDK_Annot* pSDKAnnot, FX_UINT nFlag = 0) {
552 m_pSDKDoc->SetFocusAnnot(pSDKAnnot, nFlag);
553 }
554 FX_BOOL KillFocusAnnot(FX_UINT nFlag = 0) {
555 return m_pSDKDoc->KillFocusAnnot(nFlag);
556 }
Oliver Chang972b78d2015-10-30 12:59:29 -0700557 void KillFocusAnnotIfNeeded();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700558 FX_BOOL Annot_HasAppearance(CPDF_Annot* pAnnot);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700559
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700560 CPDFSDK_Annot* AddAnnot(CPDF_Dictionary* pDict);
561 CPDFSDK_Annot* AddAnnot(const FX_CHAR* lpSubType, CPDF_Dictionary* pDict);
562 CPDFSDK_Annot* AddAnnot(CPDF_Annot* pPDFAnnot);
563 CPDFSDK_Annot* AddAnnot(IXFA_Widget* pPDFAnnot);
564 FX_BOOL DeleteAnnot(CPDFSDK_Annot* pAnnot);
Lei Zhang50218532015-10-30 14:03:43 -0700565 size_t CountAnnots() const;
Lei Zhangbf60b292015-10-26 12:14:35 -0700566 CPDFSDK_Annot* GetAnnot(size_t nIndex);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700567 CPDFSDK_Annot* GetAnnotByDict(CPDF_Dictionary* pDict);
568 CPDFSDK_Annot* GetAnnotByXFAWidget(IXFA_Widget* hWidget);
569 CPDFXFA_Page* GetPDFXFAPage() { return m_page; }
570 CPDF_Page* GetPDFPage();
571 CPDF_Document* GetPDFDocument();
572 CPDFSDK_Document* GetSDKDocument() { return m_pSDKDoc; }
573 FX_BOOL OnLButtonDown(const CPDF_Point& point, FX_UINT nFlag);
574 FX_BOOL OnLButtonUp(const CPDF_Point& point, FX_UINT nFlag);
575 FX_BOOL OnRButtonDown(const CPDF_Point& point, FX_UINT nFlag);
576 FX_BOOL OnRButtonUp(const CPDF_Point& point, FX_UINT nFlag);
577 FX_BOOL OnChar(int nChar, FX_UINT nFlag);
578 FX_BOOL OnKeyDown(int nKeyCode, int nFlag);
579 FX_BOOL OnKeyUp(int nKeyCode, int nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700580
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700581 FX_BOOL OnMouseMove(const CPDF_Point& point, int nFlag);
582 FX_BOOL OnMouseWheel(double deltaX,
583 double deltaY,
584 const CPDF_Point& point,
585 int nFlag);
Lei Zhang1b700c32015-10-30 23:55:35 -0700586 bool IsValidAnnot(const CPDF_Annot* p) const;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700587 void GetCurrentMatrix(CPDF_Matrix& matrix) { matrix = m_curMatrix; }
588 void UpdateRects(CFX_RectArray& rects);
589 void UpdateView(CPDFSDK_Annot* pAnnot);
Lei Zhangbf60b292015-10-26 12:14:35 -0700590 const std::vector<CPDFSDK_Annot*>& GetAnnotList() const {
591 return m_fxAnnotArray;
592 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700593
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700594 int GetPageIndex();
595 void LoadFXAnnots();
596 void SetValid(FX_BOOL bValid) { m_bValid = bValid; }
597 FX_BOOL IsValid() { return m_bValid; }
598 void SetLock(FX_BOOL bLocked) { m_bLocked = bLocked; }
599 FX_BOOL IsLocked() { return m_bLocked; }
600
601 private:
602 void PageView_OnHighlightFormFields(CFX_RenderDevice* pDevice,
603 CPDFSDK_Widget* pWidget);
Lei Zhangbf60b292015-10-26 12:14:35 -0700604
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700605 CPDF_Matrix m_curMatrix;
606 CPDFXFA_Page* m_page;
Lei Zhangbf60b292015-10-26 12:14:35 -0700607 nonstd::unique_ptr<CPDF_AnnotList> m_pAnnotList;
608 std::vector<CPDFSDK_Annot*> m_fxAnnotArray;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700609 CPDFSDK_Document* m_pSDKDoc;
610 CPDFSDK_Annot* m_CaptureWidget;
611 FX_BOOL m_bEnterWidget;
612 FX_BOOL m_bExitWidget;
613 FX_BOOL m_bOnWidget;
614 FX_BOOL m_bValid;
615 FX_BOOL m_bLocked;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700616};
617
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700618template <class TYPE>
619class CGW_ArrayTemplate : public CFX_ArrayTemplate<TYPE> {
620 public:
621 CGW_ArrayTemplate() {}
Lei Zhang2b1a2d52015-08-14 22:16:22 -0700622 ~CGW_ArrayTemplate() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700623
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700624 typedef int (*LP_COMPARE)(TYPE p1, TYPE p2);
Tom Sepezc6ab1722015-02-05 15:27:25 -0800625
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700626 void Sort(LP_COMPARE pCompare, FX_BOOL bAscent = TRUE) {
627 int nSize = this->GetSize();
628 QuickSort(0, nSize - 1, bAscent, pCompare);
629 }
Tom Sepezc6ab1722015-02-05 15:27:25 -0800630
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700631 private:
632 void QuickSort(FX_UINT nStartPos,
633 FX_UINT nStopPos,
634 FX_BOOL bAscend,
635 LP_COMPARE pCompare) {
636 if (nStartPos >= nStopPos)
637 return;
638
639 if ((nStopPos - nStartPos) == 1) {
640 TYPE Value1 = this->GetAt(nStartPos);
641 TYPE Value2 = this->GetAt(nStopPos);
642
643 int iGreate = (*pCompare)(Value1, Value2);
644 if ((bAscend && iGreate > 0) || (!bAscend && iGreate < 0)) {
645 this->SetAt(nStartPos, Value2);
646 this->SetAt(nStopPos, Value1);
647 }
648 return;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700649 }
Tom Sepezc6ab1722015-02-05 15:27:25 -0800650
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700651 FX_UINT m = nStartPos + (nStopPos - nStartPos) / 2;
652 FX_UINT i = nStartPos;
Tom Sepezc6ab1722015-02-05 15:27:25 -0800653
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700654 TYPE Value = this->GetAt(m);
Tom Sepezc6ab1722015-02-05 15:27:25 -0800655
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700656 while (i < m) {
657 TYPE temp = this->GetAt(i);
Tom Sepezc6ab1722015-02-05 15:27:25 -0800658
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700659 int iGreate = (*pCompare)(temp, Value);
660 if ((bAscend && iGreate > 0) || (!bAscend && iGreate < 0)) {
661 this->InsertAt(m + 1, temp);
662 this->RemoveAt(i);
663 m--;
664 } else {
665 i++;
666 }
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700667 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700668
669 FX_UINT j = nStopPos;
670
671 while (j > m) {
672 TYPE temp = this->GetAt(j);
673
674 int iGreate = (*pCompare)(temp, Value);
675 if ((bAscend && iGreate < 0) || (!bAscend && iGreate > 0)) {
676 this->RemoveAt(j);
677 this->InsertAt(m, temp);
678 m++;
679 } else {
680 j--;
681 }
682 }
683
684 if (nStartPos < m)
685 QuickSort(nStartPos, m, bAscend, pCompare);
686 if (nStopPos > m)
687 QuickSort(m, nStopPos, bAscend, pCompare);
688 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700689};
690
Tom Sepez19922bb2015-05-28 13:23:12 -0700691#endif // FPDFSDK_INCLUDE_FSDK_MGR_H_