blob: b87c982cc16a3aee9c5bcf984eb5c349bea5b2d8 [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>
Lei Zhangaa8bf7e2015-12-24 19:13:32 -080011#include <memory>
Tom Sepez11d93552016-02-09 09:55:54 -080012#include <vector>
Lei Zhang606346f2015-06-19 18:11:07 -070013
tsepez1e2c5572016-05-25 14:58:09 -070014#include "core/fpdfapi/fpdf_page/include/cpdf_page.h"
Dan Sinclairaa403d32016-03-15 14:57:22 -040015#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
dsinclaircac704d2016-07-28 12:59:09 -070016#include "core/fpdfdoc/include/cpdf_occontext.h"
dsinclairb9590102016-04-27 06:38:59 -070017#include "fpdfsdk/cfx_systemhandler.h"
Dan Sinclairefbc1912016-02-17 16:54:43 -050018#include "fpdfsdk/include/fsdk_actionhandler.h"
19#include "fpdfsdk/include/fsdk_annothandler.h"
20#include "fpdfsdk/include/fsdk_baseannot.h"
21#include "fpdfsdk/include/fsdk_baseform.h"
22#include "fpdfsdk/include/fsdk_common.h"
23#include "fpdfsdk/include/fsdk_define.h"
Lei Zhangb4e7f302015-11-06 15:52:32 -080024#include "public/fpdf_formfill.h"
Dan Sinclairdf5a1162016-03-09 16:51:34 -050025#include "public/fpdf_fwlevent.h"
Tom Sepez40e9ff32015-11-30 12:39:54 -080026
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070027class CFFL_IFormFiller;
dsinclairb9590102016-04-27 06:38:59 -070028class CFX_SystemHandler;
dsinclaircac704d2016-07-28 12:59:09 -070029class CPDF_AnnotList;
Tom Sepezdcbc02f2015-07-17 09:16:17 -070030class CPDFSDK_ActionHandler;
31class CPDFSDK_Annot;
Tom Sepezdcbc02f2015-07-17 09:16:17 -070032class CPDFSDK_InterForm;
33class CPDFSDK_PageView;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070034class CPDFSDK_Widget;
dsinclair64376be2016-03-31 20:03:24 -070035class IJS_Runtime;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070036
Nico Weber9d8ec5a2015-08-04 13:00:21 -070037class CPDFDoc_Environment final {
38 public:
Tom Sepez50d12ad2015-11-24 09:50:51 -080039 CPDFDoc_Environment(UnderlyingDocumentType* pDoc, FPDF_FORMFILLINFO* pFFinfo);
Tom Sepezdfbf8e72015-10-14 14:17:26 -070040 ~CPDFDoc_Environment();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070041
Nico Weber9d8ec5a2015-08-04 13:00:21 -070042 void FFI_Invalidate(FPDF_PAGE page,
43 double left,
44 double top,
45 double right,
46 double bottom) {
47 if (m_pInfo && m_pInfo->FFI_Invalidate)
48 m_pInfo->FFI_Invalidate(m_pInfo, page, left, top, right, bottom);
49 }
50
51 void FFI_OutputSelectedRect(FPDF_PAGE page,
52 double left,
53 double top,
54 double right,
55 double bottom) {
56 if (m_pInfo && m_pInfo->FFI_OutputSelectedRect)
57 m_pInfo->FFI_OutputSelectedRect(m_pInfo, page, left, top, right, bottom);
58 }
59
60 void FFI_SetCursor(int nCursorType) {
61 if (m_pInfo && m_pInfo->FFI_SetCursor)
62 m_pInfo->FFI_SetCursor(m_pInfo, nCursorType);
63 }
64
65 int FFI_SetTimer(int uElapse, TimerCallback lpTimerFunc) {
66 if (m_pInfo && m_pInfo->FFI_SetTimer)
67 return m_pInfo->FFI_SetTimer(m_pInfo, uElapse, lpTimerFunc);
68 return -1;
69 }
70
71 void FFI_KillTimer(int nTimerID) {
72 if (m_pInfo && m_pInfo->FFI_KillTimer)
73 m_pInfo->FFI_KillTimer(m_pInfo, nTimerID);
74 }
75
Tom Sepez468e5892015-10-13 15:49:36 -070076 FX_SYSTEMTIME FFI_GetLocalTime() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070077 FX_SYSTEMTIME fxtime;
78 if (m_pInfo && m_pInfo->FFI_GetLocalTime) {
79 FPDF_SYSTEMTIME systime = m_pInfo->FFI_GetLocalTime(m_pInfo);
80 fxtime.wDay = systime.wDay;
81 fxtime.wDayOfWeek = systime.wDayOfWeek;
82 fxtime.wHour = systime.wHour;
83 fxtime.wMilliseconds = systime.wMilliseconds;
84 fxtime.wMinute = systime.wMinute;
85 fxtime.wMonth = systime.wMonth;
86 fxtime.wSecond = systime.wSecond;
87 fxtime.wYear = systime.wYear;
Tom Sepezdcbc02f2015-07-17 09:16:17 -070088 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070089 return fxtime;
90 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070091
Nico Weber9d8ec5a2015-08-04 13:00:21 -070092 void FFI_OnChange() {
93 if (m_pInfo && m_pInfo->FFI_OnChange)
94 m_pInfo->FFI_OnChange(m_pInfo);
95 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070096
tsepezc3255f52016-03-25 14:52:27 -070097 FX_BOOL FFI_IsSHIFTKeyDown(uint32_t nFlag) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070098 return (nFlag & FWL_EVENTFLAG_ShiftKey) != 0;
99 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700100
tsepezc3255f52016-03-25 14:52:27 -0700101 FX_BOOL FFI_IsCTRLKeyDown(uint32_t nFlag) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700102 return (nFlag & FWL_EVENTFLAG_ControlKey) != 0;
103 }
Tom Sepezc6ab1722015-02-05 15:27:25 -0800104
tsepezc3255f52016-03-25 14:52:27 -0700105 FX_BOOL FFI_IsALTKeyDown(uint32_t nFlag) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700106 return (nFlag & FWL_EVENTFLAG_AltKey) != 0;
107 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700108
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700109 FPDF_PAGE FFI_GetPage(FPDF_DOCUMENT document, int nPageIndex) {
110 if (m_pInfo && m_pInfo->FFI_GetPage)
111 return m_pInfo->FFI_GetPage(m_pInfo, document, nPageIndex);
thestig1cd352e2016-06-07 17:53:06 -0700112 return nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700113 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700114
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700115 FPDF_PAGE FFI_GetCurrentPage(FPDF_DOCUMENT document) {
116 if (m_pInfo && m_pInfo->FFI_GetCurrentPage)
117 return m_pInfo->FFI_GetCurrentPage(m_pInfo, document);
thestig1cd352e2016-06-07 17:53:06 -0700118 return nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700119 }
Tom Sepez0d3b5cc2014-07-30 13:03:52 -0700120
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700121 int FFI_GetRotation(FPDF_PAGE page) {
122 if (m_pInfo && m_pInfo->FFI_GetRotation)
123 return m_pInfo->FFI_GetRotation(m_pInfo, page);
124 return 0;
125 }
Tom Sepez0d3b5cc2014-07-30 13:03:52 -0700126
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700127 void FFI_ExecuteNamedAction(const FX_CHAR* namedAction) {
128 if (m_pInfo && m_pInfo->FFI_ExecuteNamedAction)
129 m_pInfo->FFI_ExecuteNamedAction(m_pInfo, namedAction);
130 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700131
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700132 void FFI_OnSetFieldInputFocus(void* field,
133 FPDF_WIDESTRING focusText,
134 FPDF_DWORD nTextLen,
135 FX_BOOL bFocus) {
136 if (m_pInfo && m_pInfo->FFI_SetTextFieldFocus)
137 m_pInfo->FFI_SetTextFieldFocus(m_pInfo, focusText, nTextLen, bFocus);
138 }
Tom Sepez0d3b5cc2014-07-30 13:03:52 -0700139
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700140 void FFI_DoURIAction(const FX_CHAR* bsURI) {
141 if (m_pInfo && m_pInfo->FFI_DoURIAction)
142 m_pInfo->FFI_DoURIAction(m_pInfo, bsURI);
143 }
Tom Sepez0d3b5cc2014-07-30 13:03:52 -0700144
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700145 void FFI_DoGoToAction(int nPageIndex,
146 int zoomMode,
147 float* fPosArray,
148 int sizeOfArray) {
149 if (m_pInfo && m_pInfo->FFI_DoGoToAction)
150 m_pInfo->FFI_DoGoToAction(m_pInfo, nPageIndex, zoomMode, fPosArray,
151 sizeOfArray);
152 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700153
Tom Sepez51da0932015-11-25 16:05:49 -0800154#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700155 void FFI_DisplayCaret(FPDF_PAGE page,
156 FPDF_BOOL bVisible,
157 double left,
158 double top,
159 double right,
160 double bottom) {
161 if (m_pInfo && m_pInfo->FFI_DisplayCaret)
162 m_pInfo->FFI_DisplayCaret(m_pInfo, page, bVisible, left, top, right,
163 bottom);
164 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700165
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700166 int FFI_GetCurrentPageIndex(FPDF_DOCUMENT document) {
Jun Fang01fe5882015-11-25 11:05:58 +0800167 if (!m_pInfo || !m_pInfo->FFI_GetCurrentPageIndex) {
168 return -1;
169 }
170 return m_pInfo->FFI_GetCurrentPageIndex(m_pInfo, document);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700171 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700172
Jun Fang01fe5882015-11-25 11:05:58 +0800173 void FFI_SetCurrentPage(FPDF_DOCUMENT document, int iCurPage) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700174 if (m_pInfo && m_pInfo->FFI_SetCurrentPage)
175 m_pInfo->FFI_SetCurrentPage(m_pInfo, document, iCurPage);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700176 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700177
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700178 CFX_WideString FFI_GetAppName() const { return CFX_WideString(L"Acrobat"); }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700179
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700180 CFX_WideString FFI_GetPlatform() {
181 if (m_pInfo && m_pInfo->FFI_GetPlatform) {
thestig1cd352e2016-06-07 17:53:06 -0700182 int nRequiredLen = m_pInfo->FFI_GetPlatform(m_pInfo, nullptr, 0);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700183 if (nRequiredLen <= 0)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700184 return L"";
Bo Xufdc00a72014-10-28 23:03:33 -0700185
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700186 char* pbuff = new char[nRequiredLen];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700187 memset(pbuff, 0, nRequiredLen);
188 int nActualLen = m_pInfo->FFI_GetPlatform(m_pInfo, pbuff, nRequiredLen);
189 if (nActualLen <= 0 || nActualLen > nRequiredLen) {
190 delete[] pbuff;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700191 return L"";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700192 }
193 CFX_ByteString bsRet = CFX_ByteString(pbuff, nActualLen);
194 CFX_WideString wsRet = CFX_WideString::FromUTF16LE(
195 (unsigned short*)bsRet.GetBuffer(bsRet.GetLength()),
196 bsRet.GetLength() / sizeof(unsigned short));
197 delete[] pbuff;
198 return wsRet;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700199 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700200 return L"";
201 }
Bo Xufdc00a72014-10-28 23:03:33 -0700202
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700203 void FFI_GotoURL(FPDF_DOCUMENT document,
204 const CFX_WideStringC& wsURL,
205 FX_BOOL bAppend) {
206 if (m_pInfo && m_pInfo->FFI_GotoURL) {
207 CFX_ByteString bsTo = CFX_WideString(wsURL).UTF16LE_Encode();
208 FPDF_WIDESTRING pTo = (FPDF_WIDESTRING)bsTo.GetBuffer(wsURL.GetLength());
209 m_pInfo->FFI_GotoURL(m_pInfo, document, pTo);
210 bsTo.ReleaseBuffer();
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700211 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700212 }
Bo Xufdc00a72014-10-28 23:03:33 -0700213
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700214 void FFI_GetURL(FPDF_DOCUMENT document, CFX_WideString& wsURL) {
215 wsURL = CFX_WideString();
216 }
217
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700218 void FFI_GetPageViewRect(FPDF_PAGE page, FS_RECTF& dstRect) {
219 if (m_pInfo && m_pInfo->FFI_GetPageViewRect) {
220 double left;
221 double top;
222 double right;
223 double bottom;
224 m_pInfo->FFI_GetPageViewRect(m_pInfo, page, &left, &top, &right, &bottom);
225
226 dstRect.left = static_cast<float>(left);
227 dstRect.top = static_cast<float>(top < bottom ? bottom : top);
228 dstRect.bottom = static_cast<float>(top < bottom ? top : bottom);
229 dstRect.right = static_cast<float>(right);
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700230 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700231 }
Bo Xufdc00a72014-10-28 23:03:33 -0700232
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700233 FX_BOOL FFI_PopupMenu(FPDF_PAGE page,
234 FPDF_WIDGET hWidget,
235 int menuFlag,
236 CFX_PointF ptPopup,
237 const CFX_PointF* pRectExclude) {
238 if (m_pInfo && m_pInfo->FFI_PopupMenu)
239 return m_pInfo->FFI_PopupMenu(m_pInfo, page, hWidget, menuFlag, ptPopup.x,
240 ptPopup.y);
241 return FALSE;
242 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700243
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700244 void FFI_Alert(FPDF_WIDESTRING Msg,
245 FPDF_WIDESTRING Title,
246 int Type,
247 int Icon) {
248 if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_alert)
249 m_pInfo->m_pJsPlatform->app_alert(m_pInfo->m_pJsPlatform, Msg, Title,
250 Type, Icon);
251 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700252
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700253 void FFI_EmailTo(FPDF_FILEHANDLER* fileHandler,
254 FPDF_WIDESTRING pTo,
255 FPDF_WIDESTRING pSubject,
256 FPDF_WIDESTRING pCC,
257 FPDF_WIDESTRING pBcc,
258 FPDF_WIDESTRING pMsg) {
259 if (m_pInfo && m_pInfo->FFI_EmailTo)
260 m_pInfo->FFI_EmailTo(m_pInfo, fileHandler, pTo, pSubject, pCC, pBcc,
261 pMsg);
262 }
263
264 void FFI_UploadTo(FPDF_FILEHANDLER* fileHandler,
265 int fileFlag,
266 FPDF_WIDESTRING uploadTo) {
267 if (m_pInfo && m_pInfo->FFI_UploadTo)
268 m_pInfo->FFI_UploadTo(m_pInfo, fileHandler, fileFlag, uploadTo);
269 }
270
271 FPDF_FILEHANDLER* FFI_OpenFile(int fileType,
272 FPDF_WIDESTRING wsURL,
273 const char* mode) {
274 if (m_pInfo && m_pInfo->FFI_OpenFile)
275 return m_pInfo->FFI_OpenFile(m_pInfo, fileType, wsURL, mode);
thestig1cd352e2016-06-07 17:53:06 -0700276 return nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700277 }
278
279 CFX_WideString FFI_GetFilePath(FPDF_FILEHANDLER* pFileHandler) const {
280 return L"";
281 }
282
283 int FFI_GetDocumentCount() const { return 0; }
284 int FFI_GetCurDocument() const { return 0; }
285
286 IFX_FileRead* FFI_DownloadFromURL(const FX_WCHAR* url) {
287 if (m_pInfo && m_pInfo->FFI_DownloadFromURL) {
288 CFX_ByteString bstrURL = CFX_WideString(url).UTF16LE_Encode();
289 FPDF_WIDESTRING wsURL =
290 (FPDF_WIDESTRING)bstrURL.GetBuffer(bstrURL.GetLength());
291
292 FPDF_LPFILEHANDLER fileHandler =
293 m_pInfo->FFI_DownloadFromURL(m_pInfo, wsURL);
294
Lei Zhangdb5256f2015-10-02 10:11:43 -0700295 return new CFPDF_FileStream(fileHandler);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700296 }
thestig1cd352e2016-06-07 17:53:06 -0700297 return nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700298 }
299
300 CFX_WideString FFI_PostRequestURL(const FX_WCHAR* wsURL,
301 const FX_WCHAR* wsData,
302 const FX_WCHAR* wsContentType,
303 const FX_WCHAR* wsEncode,
304 const FX_WCHAR* wsHeader) {
305 if (m_pInfo && m_pInfo->FFI_PostRequestURL) {
306 CFX_ByteString bsURL = CFX_WideString(wsURL).UTF16LE_Encode();
307 FPDF_WIDESTRING URL = (FPDF_WIDESTRING)bsURL.GetBuffer(bsURL.GetLength());
308
309 CFX_ByteString bsData = CFX_WideString(wsData).UTF16LE_Encode();
310 FPDF_WIDESTRING data =
311 (FPDF_WIDESTRING)bsData.GetBuffer(bsData.GetLength());
312
313 CFX_ByteString bsContentType =
314 CFX_WideString(wsContentType).UTF16LE_Encode();
315 FPDF_WIDESTRING contentType =
316 (FPDF_WIDESTRING)bsContentType.GetBuffer(bsContentType.GetLength());
317
318 CFX_ByteString bsEncode = CFX_WideString(wsEncode).UTF16LE_Encode();
319 FPDF_WIDESTRING encode =
320 (FPDF_WIDESTRING)bsEncode.GetBuffer(bsEncode.GetLength());
321
322 CFX_ByteString bsHeader = CFX_WideString(wsHeader).UTF16LE_Encode();
323 FPDF_WIDESTRING header =
324 (FPDF_WIDESTRING)bsHeader.GetBuffer(bsHeader.GetLength());
325
thestig77d148d2016-04-06 06:28:31 -0700326 FPDF_BSTR response;
327 FPDF_BStr_Init(&response);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700328 m_pInfo->FFI_PostRequestURL(m_pInfo, URL, data, contentType, encode,
thestig77d148d2016-04-06 06:28:31 -0700329 header, &response);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700330
331 CFX_WideString wsRet = CFX_WideString::FromUTF16LE(
thestig77d148d2016-04-06 06:28:31 -0700332 (unsigned short*)response.str, response.len / sizeof(unsigned short));
333 FPDF_BStr_Clear(&response);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700334
335 return wsRet;
336 }
337 return L"";
338 }
339
340 FPDF_BOOL FFI_PutRequestURL(const FX_WCHAR* wsURL,
341 const FX_WCHAR* wsData,
342 const FX_WCHAR* wsEncode) {
343 if (m_pInfo && m_pInfo->FFI_PutRequestURL) {
344 CFX_ByteString bsURL = CFX_WideString(wsURL).UTF16LE_Encode();
345 FPDF_WIDESTRING URL = (FPDF_WIDESTRING)bsURL.GetBuffer(bsURL.GetLength());
346
347 CFX_ByteString bsData = CFX_WideString(wsData).UTF16LE_Encode();
348 FPDF_WIDESTRING data =
349 (FPDF_WIDESTRING)bsData.GetBuffer(bsData.GetLength());
350
351 CFX_ByteString bsEncode = CFX_WideString(wsEncode).UTF16LE_Encode();
352 FPDF_WIDESTRING encode =
353 (FPDF_WIDESTRING)bsEncode.GetBuffer(bsEncode.GetLength());
354
355 return m_pInfo->FFI_PutRequestURL(m_pInfo, URL, data, encode);
356 }
357 return FALSE;
358 }
359
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700360 CFX_WideString FFI_GetLanguage() {
361 if (m_pInfo && m_pInfo->FFI_GetLanguage) {
thestig1cd352e2016-06-07 17:53:06 -0700362 int nRequiredLen = m_pInfo->FFI_GetLanguage(m_pInfo, nullptr, 0);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700363 if (nRequiredLen <= 0)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700364 return L"";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700365
366 char* pbuff = new char[nRequiredLen];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700367 memset(pbuff, 0, nRequiredLen);
368 int nActualLen = m_pInfo->FFI_GetLanguage(m_pInfo, pbuff, nRequiredLen);
369 if (nActualLen <= 0 || nActualLen > nRequiredLen) {
370 delete[] pbuff;
371 return L"";
372 }
373 CFX_ByteString bsRet = CFX_ByteString(pbuff, nActualLen);
374 CFX_WideString wsRet = CFX_WideString::FromUTF16LE(
375 (unsigned short*)bsRet.GetBuffer(bsRet.GetLength()),
376 bsRet.GetLength() / sizeof(unsigned short));
377 delete[] pbuff;
378 return wsRet;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700379 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700380 return L"";
381 }
Lei Zhang84e5a122016-02-19 14:25:10 -0800382
tsepezc3255f52016-03-25 14:52:27 -0700383 void FFI_PageEvent(int iPageCount, uint32_t dwEventType) const {
Lei Zhang84e5a122016-02-19 14:25:10 -0800384 if (m_pInfo && m_pInfo->FFI_PageEvent)
jinming_wanga1cef702016-03-18 16:35:40 +0800385 m_pInfo->FFI_PageEvent(m_pInfo, iPageCount, dwEventType);
Jun Fangc30d5bf2016-02-02 18:12:23 -0800386 }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800387#endif // PDF_ENABLE_XFA
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700388
Tom Sepez57028592016-02-01 15:49:11 -0800389 int JS_appAlert(const FX_WCHAR* Msg,
390 const FX_WCHAR* Title,
391 FX_UINT Type,
392 FX_UINT Icon);
393 int JS_appResponse(const FX_WCHAR* Question,
394 const FX_WCHAR* Title,
395 const FX_WCHAR* Default,
396 const FX_WCHAR* cLabel,
397 FPDF_BOOL bPassword,
398 void* response,
399 int length);
400 void JS_appBeep(int nType);
401 CFX_WideString JS_fieldBrowse();
402 CFX_WideString JS_docGetFilePath();
403 void JS_docSubmitForm(void* formData, int length, const FX_WCHAR* URL);
404 void JS_docmailForm(void* mailData,
405 int length,
406 FPDF_BOOL bUI,
407 const FX_WCHAR* To,
408 const FX_WCHAR* Subject,
409 const FX_WCHAR* CC,
410 const FX_WCHAR* BCC,
411 const FX_WCHAR* Msg);
412 void JS_docprint(FPDF_BOOL bUI,
413 int nStart,
414 int nEnd,
415 FPDF_BOOL bSilent,
416 FPDF_BOOL bShrinkToFit,
417 FPDF_BOOL bPrintAsImage,
418 FPDF_BOOL bReverse,
419 FPDF_BOOL bAnnotations);
420 void JS_docgotoPage(int nPageNum);
421
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700422 FX_BOOL IsJSInitiated() const { return m_pInfo && m_pInfo->m_pJsPlatform; }
423 void SetSDKDocument(CPDFSDK_Document* pFXDoc) { m_pSDKDoc = pFXDoc; }
424 CPDFSDK_Document* GetSDKDocument() const { return m_pSDKDoc; }
Tom Sepez50d12ad2015-11-24 09:50:51 -0800425 UnderlyingDocumentType* GetUnderlyingDocument() const {
426 return m_pUnderlyingDoc;
427 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700428 CFX_ByteString GetAppName() const { return ""; }
dsinclairb9590102016-04-27 06:38:59 -0700429 CFX_SystemHandler* GetSysHandler() const { return m_pSysHandler.get(); }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700430 FPDF_FORMFILLINFO* GetFormFillInfo() const { return m_pInfo; }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700431
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700432 CFFL_IFormFiller* GetIFormFiller(); // Creates if not present.
433 CPDFSDK_AnnotHandlerMgr* GetAnnotHandlerMgr(); // Creates if not present.
Tom Sepezba038bc2015-10-08 12:03:00 -0700434 IJS_Runtime* GetJSRuntime(); // Creates if not present.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700435 CPDFSDK_ActionHandler* GetActionHander(); // Creates if not present.
Tom Sepez2f3dfef2015-03-02 15:35:26 -0800436
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700437 private:
Lei Zhangaa8bf7e2015-12-24 19:13:32 -0800438 std::unique_ptr<CPDFSDK_AnnotHandlerMgr> m_pAnnotHandlerMgr;
439 std::unique_ptr<CPDFSDK_ActionHandler> m_pActionHandler;
440 std::unique_ptr<IJS_Runtime> m_pJSRuntime;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700441 FPDF_FORMFILLINFO* const m_pInfo;
442 CPDFSDK_Document* m_pSDKDoc;
Tom Sepez50d12ad2015-11-24 09:50:51 -0800443 UnderlyingDocumentType* const m_pUnderlyingDoc;
Lei Zhangaa8bf7e2015-12-24 19:13:32 -0800444 std::unique_ptr<CFFL_IFormFiller> m_pIFormFiller;
dsinclairb9590102016-04-27 06:38:59 -0700445 std::unique_ptr<CFX_SystemHandler> m_pSysHandler;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700446};
447
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700448class CPDFSDK_Document {
449 public:
Tom Sepezfe351db2016-01-29 16:26:27 -0800450 static CPDFSDK_Document* FromFPDFFormHandle(FPDF_FORMHANDLE hHandle);
451
Tom Sepez50d12ad2015-11-24 09:50:51 -0800452 CPDFSDK_Document(UnderlyingDocumentType* pDoc, CPDFDoc_Environment* pEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700453 ~CPDFSDK_Document();
Tom Sepez2f3dfef2015-03-02 15:35:26 -0800454
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700455 CPDFSDK_InterForm* GetInterForm();
Tom Sepez50d12ad2015-11-24 09:50:51 -0800456
Tom Sepez5259ef32015-11-24 10:21:01 -0800457 // Gets the document object for the next layer down; for master this is
458 // a CPDF_Document, but for XFA it is a CPDFXFA_Document.
Tom Sepez50d12ad2015-11-24 09:50:51 -0800459 UnderlyingDocumentType* GetUnderlyingDocument() const {
Tom Sepez40e9ff32015-11-30 12:39:54 -0800460#ifdef PDF_ENABLE_XFA
Tom Sepez50d12ad2015-11-24 09:50:51 -0800461 return GetXFADocument();
Tom Sepez40e9ff32015-11-30 12:39:54 -0800462#else // PDF_ENABLE_XFA
463 return GetPDFDocument();
464#endif // PDF_ENABLE_XFA
Tom Sepez50d12ad2015-11-24 09:50:51 -0800465 }
Tom Sepez5259ef32015-11-24 10:21:01 -0800466
467 // Gets the CPDF_Document, either directly in master, or from the
468 // CPDFXFA_Document for XFA.
Tom Sepezbf59a072015-10-21 14:07:23 -0700469 CPDF_Document* GetPDFDocument() const {
Tom Sepez40e9ff32015-11-30 12:39:54 -0800470#ifdef PDF_ENABLE_XFA
Tom Sepezbf59a072015-10-21 14:07:23 -0700471 return m_pDoc ? m_pDoc->GetPDFDoc() : nullptr;
Tom Sepez40e9ff32015-11-30 12:39:54 -0800472#else // PDF_ENABLE_XFA
473 return m_pDoc;
474#endif // PDF_ENABLE_XFA
Tom Sepezbf59a072015-10-21 14:07:23 -0700475 }
Tom Sepez5259ef32015-11-24 10:21:01 -0800476
Tom Sepez40e9ff32015-11-30 12:39:54 -0800477#ifdef PDF_ENABLE_XFA
Tom Sepez5259ef32015-11-24 10:21:01 -0800478 // Gets the XFA document directly (XFA-only).
Tom Sepez50d12ad2015-11-24 09:50:51 -0800479 CPDFXFA_Document* GetXFADocument() const { return m_pDoc; }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700480
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700481 int GetPageViewCount() const { return m_pageMap.size(); }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800482#endif // PDF_ENABLE_XFA
483
dsinclair461eeaf2016-07-27 07:40:05 -0700484 CPDFSDK_PageView* GetPageView(UnderlyingPageType* pPage, bool ReNew);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700485 CPDFSDK_PageView* GetPageView(int nIndex);
486 CPDFSDK_PageView* GetCurrentView();
Tom Sepez540c4362015-11-24 13:33:57 -0800487 void RemovePageView(UnderlyingPageType* pPage);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700488 void UpdateAllViews(CPDFSDK_PageView* pSender, CPDFSDK_Annot* pAnnot);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700489
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700490 CPDFSDK_Annot* GetFocusAnnot();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700491
Tom Sepezba038bc2015-10-08 12:03:00 -0700492 IJS_Runtime* GetJsRuntime();
Tom Sepezc6ab1722015-02-05 15:27:25 -0800493
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700494 FX_BOOL SetFocusAnnot(CPDFSDK_Annot* pAnnot, FX_UINT nFlag = 0);
495 FX_BOOL KillFocusAnnot(FX_UINT nFlag = 0);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700496
Tom Sepez62a70f92016-03-21 15:00:20 -0700497 FX_BOOL ExtractPages(const std::vector<uint16_t>& arrExtraPages,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700498 CPDF_Document* pDstDoc);
499 FX_BOOL InsertPages(int nInsertAt,
500 const CPDF_Document* pSrcDoc,
Tom Sepez62a70f92016-03-21 15:00:20 -0700501 const std::vector<uint16_t>& arrSrcPages);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700502 FX_BOOL ReplacePages(int nPage,
503 const CPDF_Document* pSrcDoc,
Tom Sepez62a70f92016-03-21 15:00:20 -0700504 const std::vector<uint16_t>& arrSrcPages);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700505
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700506 void OnCloseDocument();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700507
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700508 int GetPageCount() { return m_pDoc->GetPageCount(); }
509 FX_BOOL GetPermissions(int nFlag);
510 FX_BOOL GetChangeMark() { return m_bChangeMask; }
511 void SetChangeMark() { m_bChangeMask = TRUE; }
512 void ClearChangeMark() { m_bChangeMask = FALSE; }
513 CFX_WideString GetPath();
Tom Sepez540c4362015-11-24 13:33:57 -0800514 UnderlyingPageType* GetPage(int nIndex);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700515 CPDFDoc_Environment* GetEnv() { return m_pEnv; }
516 void ProcJavascriptFun();
517 FX_BOOL ProcOpenAction();
518 CPDF_OCContext* GetOCContext();
519
520 private:
Tom Sepez540c4362015-11-24 13:33:57 -0800521 std::map<UnderlyingPageType*, CPDFSDK_PageView*> m_pageMap;
Tom Sepez50d12ad2015-11-24 09:50:51 -0800522 UnderlyingDocumentType* m_pDoc;
Lei Zhangaa8bf7e2015-12-24 19:13:32 -0800523 std::unique_ptr<CPDFSDK_InterForm> m_pInterForm;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700524 CPDFSDK_Annot* m_pFocusAnnot;
525 CPDFDoc_Environment* m_pEnv;
Lei Zhangaa8bf7e2015-12-24 19:13:32 -0800526 std::unique_ptr<CPDF_OCContext> m_pOccontent;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700527 FX_BOOL m_bChangeMask;
Oliver Chang972b78d2015-10-30 12:59:29 -0700528 FX_BOOL m_bBeingDestroyed;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700529};
Tom Sepezb9cc7a02016-02-01 13:42:30 -0800530
tsepez1e2c5572016-05-25 14:58:09 -0700531class CPDFSDK_PageView final : public CPDF_Page::View {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700532 public:
Tom Sepez540c4362015-11-24 13:33:57 -0800533 CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc, UnderlyingPageType* page);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700534 ~CPDFSDK_PageView();
Tom Sepez40e9ff32015-11-30 12:39:54 -0800535
536#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700537 void PageView_OnDraw(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800538 CFX_Matrix* pUser2Device,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700539 CPDF_RenderOptions* pOptions,
Lei Zhangf0e2e1b2015-11-02 13:27:54 -0800540 const FX_RECT& pClip);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800541#else // PDF_ENABLE_XFA
542 void PageView_OnDraw(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800543 CFX_Matrix* pUser2Device,
Tom Sepez40e9ff32015-11-30 12:39:54 -0800544 CPDF_RenderOptions* pOptions);
545#endif // PDF_ENABLE_XFA
546
Lei Zhang1b700c32015-10-30 23:55:35 -0700547 const CPDF_Annot* GetPDFAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700548 CPDFSDK_Annot* GetFXAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
Lei Zhang1b700c32015-10-30 23:55:35 -0700549 const CPDF_Annot* GetPDFWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700550 CPDFSDK_Annot* GetFXWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
551 CPDFSDK_Annot* GetFocusAnnot();
552 void SetFocusAnnot(CPDFSDK_Annot* pSDKAnnot, FX_UINT nFlag = 0) {
553 m_pSDKDoc->SetFocusAnnot(pSDKAnnot, nFlag);
554 }
555 FX_BOOL KillFocusAnnot(FX_UINT nFlag = 0) {
556 return m_pSDKDoc->KillFocusAnnot(nFlag);
557 }
Oliver Chang972b78d2015-10-30 12:59:29 -0700558 void KillFocusAnnotIfNeeded();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700559 FX_BOOL Annot_HasAppearance(CPDF_Annot* pAnnot);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700560
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700561 CPDFSDK_Annot* AddAnnot(CPDF_Dictionary* pDict);
562 CPDFSDK_Annot* AddAnnot(const FX_CHAR* lpSubType, CPDF_Dictionary* pDict);
563 CPDFSDK_Annot* AddAnnot(CPDF_Annot* pPDFAnnot);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800564
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700565 FX_BOOL DeleteAnnot(CPDFSDK_Annot* pAnnot);
Lei Zhang50218532015-10-30 14:03:43 -0700566 size_t CountAnnots() const;
Lei Zhangbf60b292015-10-26 12:14:35 -0700567 CPDFSDK_Annot* GetAnnot(size_t nIndex);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700568 CPDFSDK_Annot* GetAnnotByDict(CPDF_Dictionary* pDict);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800569
570#ifdef PDF_ENABLE_XFA
dsinclairdf4bc592016-03-31 20:34:43 -0700571 CPDFSDK_Annot* AddAnnot(CXFA_FFWidget* pPDFAnnot);
572 CPDFSDK_Annot* GetAnnotByXFAWidget(CXFA_FFWidget* hWidget);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700573 CPDFXFA_Page* GetPDFXFAPage() { return m_page; }
574 CPDF_Page* GetPDFPage();
Tom Sepez40e9ff32015-11-30 12:39:54 -0800575#else
576 CPDF_Page* GetPDFPage() { return m_page; }
577#endif // PDF_ENABLE_XFA
578
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700579 CPDF_Document* GetPDFDocument();
580 CPDFSDK_Document* GetSDKDocument() { return m_pSDKDoc; }
Tom Sepez281a9ea2016-02-26 14:24:28 -0800581 FX_BOOL OnLButtonDown(const CFX_FloatPoint& point, FX_UINT nFlag);
582 FX_BOOL OnLButtonUp(const CFX_FloatPoint& point, FX_UINT nFlag);
Tom Sepez51da0932015-11-25 16:05:49 -0800583#ifdef PDF_ENABLE_XFA
Tom Sepez281a9ea2016-02-26 14:24:28 -0800584 FX_BOOL OnRButtonDown(const CFX_FloatPoint& point, FX_UINT nFlag);
585 FX_BOOL OnRButtonUp(const CFX_FloatPoint& point, FX_UINT nFlag);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800586#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700587 FX_BOOL OnChar(int nChar, FX_UINT nFlag);
588 FX_BOOL OnKeyDown(int nKeyCode, int nFlag);
589 FX_BOOL OnKeyUp(int nKeyCode, int nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700590
Tom Sepez281a9ea2016-02-26 14:24:28 -0800591 FX_BOOL OnMouseMove(const CFX_FloatPoint& point, int nFlag);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700592 FX_BOOL OnMouseWheel(double deltaX,
593 double deltaY,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800594 const CFX_FloatPoint& point,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700595 int nFlag);
Lei Zhang1b700c32015-10-30 23:55:35 -0700596 bool IsValidAnnot(const CPDF_Annot* p) const;
Tom Sepez60d909e2015-12-10 15:34:55 -0800597 void GetCurrentMatrix(CFX_Matrix& matrix) { matrix = m_curMatrix; }
tsepezdf964df2016-04-21 12:09:41 -0700598 void UpdateRects(const std::vector<CFX_FloatRect>& rects);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700599 void UpdateView(CPDFSDK_Annot* pAnnot);
Lei Zhangbf60b292015-10-26 12:14:35 -0700600 const std::vector<CPDFSDK_Annot*>& GetAnnotList() const {
601 return m_fxAnnotArray;
602 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700603
thestigd3be1112016-06-08 06:11:20 -0700604 int GetPageIndex() const;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700605 void LoadFXAnnots();
Jun Fang75239542016-01-20 08:04:47 +0800606 void ClearFXAnnots();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700607 void SetValid(FX_BOOL bValid) { m_bValid = bValid; }
608 FX_BOOL IsValid() { return m_bValid; }
609 void SetLock(FX_BOOL bLocked) { m_bLocked = bLocked; }
610 FX_BOOL IsLocked() { return m_bLocked; }
Tom Sepez51da0932015-11-25 16:05:49 -0800611#ifndef PDF_ENABLE_XFA
612 void TakeOverPage() { m_bTakeOverPage = TRUE; }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800613#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700614
615 private:
thestigd3be1112016-06-08 06:11:20 -0700616 int GetPageIndexForStaticPDF() const;
Lei Zhangbf60b292015-10-26 12:14:35 -0700617
Tom Sepez60d909e2015-12-10 15:34:55 -0800618 CFX_Matrix m_curMatrix;
thestigd3be1112016-06-08 06:11:20 -0700619 UnderlyingPageType* const m_page;
Lei Zhangaa8bf7e2015-12-24 19:13:32 -0800620 std::unique_ptr<CPDF_AnnotList> m_pAnnotList;
Lei Zhangbf60b292015-10-26 12:14:35 -0700621 std::vector<CPDFSDK_Annot*> m_fxAnnotArray;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700622 CPDFSDK_Document* m_pSDKDoc;
Tom Sepez40e9ff32015-11-30 12:39:54 -0800623#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700624 CPDFSDK_Annot* m_CaptureWidget;
Tom Sepez40e9ff32015-11-30 12:39:54 -0800625#else // PDF_ENABLE_XFA
626 CPDFSDK_Widget* m_CaptureWidget;
627 FX_BOOL m_bTakeOverPage;
628#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700629 FX_BOOL m_bEnterWidget;
630 FX_BOOL m_bExitWidget;
631 FX_BOOL m_bOnWidget;
632 FX_BOOL m_bValid;
633 FX_BOOL m_bLocked;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700634};
635
Tom Sepez19922bb2015-05-28 13:23:12 -0700636#endif // FPDFSDK_INCLUDE_FSDK_MGR_H_