blob: 924cd444e0b9d077ef8f5ac8bf407270dfaa2b34 [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"
jaepark27362762016-08-11 13:10:39 -070018#include "fpdfsdk/include/cpdfsdk_annot.h"
Dan Sinclairefbc1912016-02-17 16:54:43 -050019#include "fpdfsdk/include/fsdk_actionhandler.h"
Dan Sinclairefbc1912016-02-17 16:54:43 -050020#include "fpdfsdk/include/fsdk_common.h"
21#include "fpdfsdk/include/fsdk_define.h"
Lei Zhangb4e7f302015-11-06 15:52:32 -080022#include "public/fpdf_formfill.h"
Dan Sinclairdf5a1162016-03-09 16:51:34 -050023#include "public/fpdf_fwlevent.h"
Tom Sepez40e9ff32015-11-30 12:39:54 -080024
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070025class CFFL_IFormFiller;
dsinclairb9590102016-04-27 06:38:59 -070026class CFX_SystemHandler;
dsinclaircac704d2016-07-28 12:59:09 -070027class CPDF_AnnotList;
Tom Sepezdcbc02f2015-07-17 09:16:17 -070028class CPDFSDK_ActionHandler;
29class CPDFSDK_Annot;
jaepark98e10192016-08-15 10:51:11 -070030class CPDFSDK_AnnotHandlerMgr;
Tom Sepezdcbc02f2015-07-17 09:16:17 -070031class CPDFSDK_InterForm;
32class CPDFSDK_PageView;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070033class CPDFSDK_Widget;
dsinclair64376be2016-03-31 20:03:24 -070034class IJS_Runtime;
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
Nico Weber9d8ec5a2015-08-04 13:00:21 -070041 void FFI_Invalidate(FPDF_PAGE page,
42 double left,
43 double top,
44 double right,
45 double bottom) {
46 if (m_pInfo && m_pInfo->FFI_Invalidate)
47 m_pInfo->FFI_Invalidate(m_pInfo, page, left, top, right, bottom);
48 }
49
50 void FFI_OutputSelectedRect(FPDF_PAGE page,
51 double left,
52 double top,
53 double right,
54 double bottom) {
55 if (m_pInfo && m_pInfo->FFI_OutputSelectedRect)
56 m_pInfo->FFI_OutputSelectedRect(m_pInfo, page, left, top, right, bottom);
57 }
58
59 void FFI_SetCursor(int nCursorType) {
60 if (m_pInfo && m_pInfo->FFI_SetCursor)
61 m_pInfo->FFI_SetCursor(m_pInfo, nCursorType);
62 }
63
64 int FFI_SetTimer(int uElapse, TimerCallback lpTimerFunc) {
65 if (m_pInfo && m_pInfo->FFI_SetTimer)
66 return m_pInfo->FFI_SetTimer(m_pInfo, uElapse, lpTimerFunc);
67 return -1;
68 }
69
70 void FFI_KillTimer(int nTimerID) {
71 if (m_pInfo && m_pInfo->FFI_KillTimer)
72 m_pInfo->FFI_KillTimer(m_pInfo, nTimerID);
73 }
74
Tom Sepez468e5892015-10-13 15:49:36 -070075 FX_SYSTEMTIME FFI_GetLocalTime() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070076 FX_SYSTEMTIME fxtime;
77 if (m_pInfo && m_pInfo->FFI_GetLocalTime) {
78 FPDF_SYSTEMTIME systime = m_pInfo->FFI_GetLocalTime(m_pInfo);
79 fxtime.wDay = systime.wDay;
80 fxtime.wDayOfWeek = systime.wDayOfWeek;
81 fxtime.wHour = systime.wHour;
82 fxtime.wMilliseconds = systime.wMilliseconds;
83 fxtime.wMinute = systime.wMinute;
84 fxtime.wMonth = systime.wMonth;
85 fxtime.wSecond = systime.wSecond;
86 fxtime.wYear = systime.wYear;
Tom Sepezdcbc02f2015-07-17 09:16:17 -070087 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070088 return fxtime;
89 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070090
Nico Weber9d8ec5a2015-08-04 13:00:21 -070091 void FFI_OnChange() {
92 if (m_pInfo && m_pInfo->FFI_OnChange)
93 m_pInfo->FFI_OnChange(m_pInfo);
94 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070095
tsepezc3255f52016-03-25 14:52:27 -070096 FX_BOOL FFI_IsSHIFTKeyDown(uint32_t nFlag) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070097 return (nFlag & FWL_EVENTFLAG_ShiftKey) != 0;
98 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070099
tsepezc3255f52016-03-25 14:52:27 -0700100 FX_BOOL FFI_IsCTRLKeyDown(uint32_t nFlag) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700101 return (nFlag & FWL_EVENTFLAG_ControlKey) != 0;
102 }
Tom Sepezc6ab1722015-02-05 15:27:25 -0800103
tsepezc3255f52016-03-25 14:52:27 -0700104 FX_BOOL FFI_IsALTKeyDown(uint32_t nFlag) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700105 return (nFlag & FWL_EVENTFLAG_AltKey) != 0;
106 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700107
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700108 FPDF_PAGE FFI_GetPage(FPDF_DOCUMENT document, int nPageIndex) {
109 if (m_pInfo && m_pInfo->FFI_GetPage)
110 return m_pInfo->FFI_GetPage(m_pInfo, document, nPageIndex);
thestig1cd352e2016-06-07 17:53:06 -0700111 return nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700112 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700113
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700114 FPDF_PAGE FFI_GetCurrentPage(FPDF_DOCUMENT document) {
115 if (m_pInfo && m_pInfo->FFI_GetCurrentPage)
116 return m_pInfo->FFI_GetCurrentPage(m_pInfo, document);
thestig1cd352e2016-06-07 17:53:06 -0700117 return nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700118 }
Tom Sepez0d3b5cc2014-07-30 13:03:52 -0700119
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700120 int FFI_GetRotation(FPDF_PAGE page) {
121 if (m_pInfo && m_pInfo->FFI_GetRotation)
122 return m_pInfo->FFI_GetRotation(m_pInfo, page);
123 return 0;
124 }
Tom Sepez0d3b5cc2014-07-30 13:03:52 -0700125
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700126 void FFI_ExecuteNamedAction(const FX_CHAR* namedAction) {
127 if (m_pInfo && m_pInfo->FFI_ExecuteNamedAction)
128 m_pInfo->FFI_ExecuteNamedAction(m_pInfo, namedAction);
129 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700130
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700131 void FFI_OnSetFieldInputFocus(void* field,
132 FPDF_WIDESTRING focusText,
133 FPDF_DWORD nTextLen,
134 FX_BOOL bFocus) {
135 if (m_pInfo && m_pInfo->FFI_SetTextFieldFocus)
136 m_pInfo->FFI_SetTextFieldFocus(m_pInfo, focusText, nTextLen, bFocus);
137 }
Tom Sepez0d3b5cc2014-07-30 13:03:52 -0700138
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700139 void FFI_DoURIAction(const FX_CHAR* bsURI) {
140 if (m_pInfo && m_pInfo->FFI_DoURIAction)
141 m_pInfo->FFI_DoURIAction(m_pInfo, bsURI);
142 }
Tom Sepez0d3b5cc2014-07-30 13:03:52 -0700143
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700144 void FFI_DoGoToAction(int nPageIndex,
145 int zoomMode,
146 float* fPosArray,
147 int sizeOfArray) {
148 if (m_pInfo && m_pInfo->FFI_DoGoToAction)
149 m_pInfo->FFI_DoGoToAction(m_pInfo, nPageIndex, zoomMode, fPosArray,
150 sizeOfArray);
151 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700152
Tom Sepez51da0932015-11-25 16:05:49 -0800153#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700154 void FFI_DisplayCaret(FPDF_PAGE page,
155 FPDF_BOOL bVisible,
156 double left,
157 double top,
158 double right,
159 double bottom) {
160 if (m_pInfo && m_pInfo->FFI_DisplayCaret)
161 m_pInfo->FFI_DisplayCaret(m_pInfo, page, bVisible, left, top, right,
162 bottom);
163 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700164
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700165 int FFI_GetCurrentPageIndex(FPDF_DOCUMENT document) {
Jun Fang01fe5882015-11-25 11:05:58 +0800166 if (!m_pInfo || !m_pInfo->FFI_GetCurrentPageIndex) {
167 return -1;
168 }
169 return m_pInfo->FFI_GetCurrentPageIndex(m_pInfo, document);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700170 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700171
Jun Fang01fe5882015-11-25 11:05:58 +0800172 void FFI_SetCurrentPage(FPDF_DOCUMENT document, int iCurPage) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700173 if (m_pInfo && m_pInfo->FFI_SetCurrentPage)
174 m_pInfo->FFI_SetCurrentPage(m_pInfo, document, iCurPage);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700175 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700176
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700177 CFX_WideString FFI_GetAppName() const { return CFX_WideString(L"Acrobat"); }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700178
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700179 CFX_WideString FFI_GetPlatform() {
180 if (m_pInfo && m_pInfo->FFI_GetPlatform) {
thestig1cd352e2016-06-07 17:53:06 -0700181 int nRequiredLen = m_pInfo->FFI_GetPlatform(m_pInfo, nullptr, 0);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700182 if (nRequiredLen <= 0)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700183 return L"";
Bo Xufdc00a72014-10-28 23:03:33 -0700184
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700185 char* pbuff = new char[nRequiredLen];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700186 memset(pbuff, 0, nRequiredLen);
187 int nActualLen = m_pInfo->FFI_GetPlatform(m_pInfo, pbuff, nRequiredLen);
188 if (nActualLen <= 0 || nActualLen > nRequiredLen) {
189 delete[] pbuff;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700190 return L"";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700191 }
192 CFX_ByteString bsRet = CFX_ByteString(pbuff, nActualLen);
193 CFX_WideString wsRet = CFX_WideString::FromUTF16LE(
194 (unsigned short*)bsRet.GetBuffer(bsRet.GetLength()),
195 bsRet.GetLength() / sizeof(unsigned short));
196 delete[] pbuff;
197 return wsRet;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700198 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700199 return L"";
200 }
Bo Xufdc00a72014-10-28 23:03:33 -0700201
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700202 void FFI_GotoURL(FPDF_DOCUMENT document,
203 const CFX_WideStringC& wsURL,
204 FX_BOOL bAppend) {
205 if (m_pInfo && m_pInfo->FFI_GotoURL) {
206 CFX_ByteString bsTo = CFX_WideString(wsURL).UTF16LE_Encode();
207 FPDF_WIDESTRING pTo = (FPDF_WIDESTRING)bsTo.GetBuffer(wsURL.GetLength());
208 m_pInfo->FFI_GotoURL(m_pInfo, document, pTo);
209 bsTo.ReleaseBuffer();
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700210 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700211 }
Bo Xufdc00a72014-10-28 23:03:33 -0700212
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700213 void FFI_GetURL(FPDF_DOCUMENT document, CFX_WideString& wsURL) {
214 wsURL = CFX_WideString();
215 }
216
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700217 void FFI_GetPageViewRect(FPDF_PAGE page, FS_RECTF& dstRect) {
218 if (m_pInfo && m_pInfo->FFI_GetPageViewRect) {
219 double left;
220 double top;
221 double right;
222 double bottom;
223 m_pInfo->FFI_GetPageViewRect(m_pInfo, page, &left, &top, &right, &bottom);
224
225 dstRect.left = static_cast<float>(left);
226 dstRect.top = static_cast<float>(top < bottom ? bottom : top);
227 dstRect.bottom = static_cast<float>(top < bottom ? top : bottom);
228 dstRect.right = static_cast<float>(right);
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700229 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700230 }
Bo Xufdc00a72014-10-28 23:03:33 -0700231
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700232 FX_BOOL FFI_PopupMenu(FPDF_PAGE page,
233 FPDF_WIDGET hWidget,
234 int menuFlag,
235 CFX_PointF ptPopup,
236 const CFX_PointF* pRectExclude) {
237 if (m_pInfo && m_pInfo->FFI_PopupMenu)
238 return m_pInfo->FFI_PopupMenu(m_pInfo, page, hWidget, menuFlag, ptPopup.x,
239 ptPopup.y);
240 return FALSE;
241 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700242
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700243 void FFI_Alert(FPDF_WIDESTRING Msg,
244 FPDF_WIDESTRING Title,
245 int Type,
246 int Icon) {
247 if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_alert)
248 m_pInfo->m_pJsPlatform->app_alert(m_pInfo->m_pJsPlatform, Msg, Title,
249 Type, Icon);
250 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700251
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700252 void FFI_EmailTo(FPDF_FILEHANDLER* fileHandler,
253 FPDF_WIDESTRING pTo,
254 FPDF_WIDESTRING pSubject,
255 FPDF_WIDESTRING pCC,
256 FPDF_WIDESTRING pBcc,
257 FPDF_WIDESTRING pMsg) {
258 if (m_pInfo && m_pInfo->FFI_EmailTo)
259 m_pInfo->FFI_EmailTo(m_pInfo, fileHandler, pTo, pSubject, pCC, pBcc,
260 pMsg);
261 }
262
263 void FFI_UploadTo(FPDF_FILEHANDLER* fileHandler,
264 int fileFlag,
265 FPDF_WIDESTRING uploadTo) {
266 if (m_pInfo && m_pInfo->FFI_UploadTo)
267 m_pInfo->FFI_UploadTo(m_pInfo, fileHandler, fileFlag, uploadTo);
268 }
269
270 FPDF_FILEHANDLER* FFI_OpenFile(int fileType,
271 FPDF_WIDESTRING wsURL,
272 const char* mode) {
273 if (m_pInfo && m_pInfo->FFI_OpenFile)
274 return m_pInfo->FFI_OpenFile(m_pInfo, fileType, wsURL, mode);
thestig1cd352e2016-06-07 17:53:06 -0700275 return nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700276 }
277
278 CFX_WideString FFI_GetFilePath(FPDF_FILEHANDLER* pFileHandler) const {
279 return L"";
280 }
281
282 int FFI_GetDocumentCount() const { return 0; }
283 int FFI_GetCurDocument() const { return 0; }
284
285 IFX_FileRead* FFI_DownloadFromURL(const FX_WCHAR* url) {
286 if (m_pInfo && m_pInfo->FFI_DownloadFromURL) {
287 CFX_ByteString bstrURL = CFX_WideString(url).UTF16LE_Encode();
288 FPDF_WIDESTRING wsURL =
289 (FPDF_WIDESTRING)bstrURL.GetBuffer(bstrURL.GetLength());
290
291 FPDF_LPFILEHANDLER fileHandler =
292 m_pInfo->FFI_DownloadFromURL(m_pInfo, wsURL);
293
Lei Zhangdb5256f2015-10-02 10:11:43 -0700294 return new CFPDF_FileStream(fileHandler);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700295 }
thestig1cd352e2016-06-07 17:53:06 -0700296 return nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700297 }
298
299 CFX_WideString FFI_PostRequestURL(const FX_WCHAR* wsURL,
300 const FX_WCHAR* wsData,
301 const FX_WCHAR* wsContentType,
302 const FX_WCHAR* wsEncode,
303 const FX_WCHAR* wsHeader) {
304 if (m_pInfo && m_pInfo->FFI_PostRequestURL) {
305 CFX_ByteString bsURL = CFX_WideString(wsURL).UTF16LE_Encode();
306 FPDF_WIDESTRING URL = (FPDF_WIDESTRING)bsURL.GetBuffer(bsURL.GetLength());
307
308 CFX_ByteString bsData = CFX_WideString(wsData).UTF16LE_Encode();
309 FPDF_WIDESTRING data =
310 (FPDF_WIDESTRING)bsData.GetBuffer(bsData.GetLength());
311
312 CFX_ByteString bsContentType =
313 CFX_WideString(wsContentType).UTF16LE_Encode();
314 FPDF_WIDESTRING contentType =
315 (FPDF_WIDESTRING)bsContentType.GetBuffer(bsContentType.GetLength());
316
317 CFX_ByteString bsEncode = CFX_WideString(wsEncode).UTF16LE_Encode();
318 FPDF_WIDESTRING encode =
319 (FPDF_WIDESTRING)bsEncode.GetBuffer(bsEncode.GetLength());
320
321 CFX_ByteString bsHeader = CFX_WideString(wsHeader).UTF16LE_Encode();
322 FPDF_WIDESTRING header =
323 (FPDF_WIDESTRING)bsHeader.GetBuffer(bsHeader.GetLength());
324
thestig77d148d2016-04-06 06:28:31 -0700325 FPDF_BSTR response;
326 FPDF_BStr_Init(&response);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700327 m_pInfo->FFI_PostRequestURL(m_pInfo, URL, data, contentType, encode,
thestig77d148d2016-04-06 06:28:31 -0700328 header, &response);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700329
330 CFX_WideString wsRet = CFX_WideString::FromUTF16LE(
thestig77d148d2016-04-06 06:28:31 -0700331 (unsigned short*)response.str, response.len / sizeof(unsigned short));
332 FPDF_BStr_Clear(&response);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700333
334 return wsRet;
335 }
336 return L"";
337 }
338
339 FPDF_BOOL FFI_PutRequestURL(const FX_WCHAR* wsURL,
340 const FX_WCHAR* wsData,
341 const FX_WCHAR* wsEncode) {
342 if (m_pInfo && m_pInfo->FFI_PutRequestURL) {
343 CFX_ByteString bsURL = CFX_WideString(wsURL).UTF16LE_Encode();
344 FPDF_WIDESTRING URL = (FPDF_WIDESTRING)bsURL.GetBuffer(bsURL.GetLength());
345
346 CFX_ByteString bsData = CFX_WideString(wsData).UTF16LE_Encode();
347 FPDF_WIDESTRING data =
348 (FPDF_WIDESTRING)bsData.GetBuffer(bsData.GetLength());
349
350 CFX_ByteString bsEncode = CFX_WideString(wsEncode).UTF16LE_Encode();
351 FPDF_WIDESTRING encode =
352 (FPDF_WIDESTRING)bsEncode.GetBuffer(bsEncode.GetLength());
353
354 return m_pInfo->FFI_PutRequestURL(m_pInfo, URL, data, encode);
355 }
356 return FALSE;
357 }
358
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700359 CFX_WideString FFI_GetLanguage() {
360 if (m_pInfo && m_pInfo->FFI_GetLanguage) {
thestig1cd352e2016-06-07 17:53:06 -0700361 int nRequiredLen = m_pInfo->FFI_GetLanguage(m_pInfo, nullptr, 0);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700362 if (nRequiredLen <= 0)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700363 return L"";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700364
365 char* pbuff = new char[nRequiredLen];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700366 memset(pbuff, 0, nRequiredLen);
367 int nActualLen = m_pInfo->FFI_GetLanguage(m_pInfo, pbuff, nRequiredLen);
368 if (nActualLen <= 0 || nActualLen > nRequiredLen) {
369 delete[] pbuff;
370 return L"";
371 }
372 CFX_ByteString bsRet = CFX_ByteString(pbuff, nActualLen);
373 CFX_WideString wsRet = CFX_WideString::FromUTF16LE(
374 (unsigned short*)bsRet.GetBuffer(bsRet.GetLength()),
375 bsRet.GetLength() / sizeof(unsigned short));
376 delete[] pbuff;
377 return wsRet;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700378 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700379 return L"";
380 }
Lei Zhang84e5a122016-02-19 14:25:10 -0800381
tsepezc3255f52016-03-25 14:52:27 -0700382 void FFI_PageEvent(int iPageCount, uint32_t dwEventType) const {
Lei Zhang84e5a122016-02-19 14:25:10 -0800383 if (m_pInfo && m_pInfo->FFI_PageEvent)
jinming_wanga1cef702016-03-18 16:35:40 +0800384 m_pInfo->FFI_PageEvent(m_pInfo, iPageCount, dwEventType);
Jun Fangc30d5bf2016-02-02 18:12:23 -0800385 }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800386#endif // PDF_ENABLE_XFA
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700387
Tom Sepez57028592016-02-01 15:49:11 -0800388 int JS_appAlert(const FX_WCHAR* Msg,
389 const FX_WCHAR* Title,
390 FX_UINT Type,
391 FX_UINT Icon);
392 int JS_appResponse(const FX_WCHAR* Question,
393 const FX_WCHAR* Title,
394 const FX_WCHAR* Default,
395 const FX_WCHAR* cLabel,
396 FPDF_BOOL bPassword,
397 void* response,
398 int length);
399 void JS_appBeep(int nType);
400 CFX_WideString JS_fieldBrowse();
401 CFX_WideString JS_docGetFilePath();
402 void JS_docSubmitForm(void* formData, int length, const FX_WCHAR* URL);
403 void JS_docmailForm(void* mailData,
404 int length,
405 FPDF_BOOL bUI,
406 const FX_WCHAR* To,
407 const FX_WCHAR* Subject,
408 const FX_WCHAR* CC,
409 const FX_WCHAR* BCC,
410 const FX_WCHAR* Msg);
411 void JS_docprint(FPDF_BOOL bUI,
412 int nStart,
413 int nEnd,
414 FPDF_BOOL bSilent,
415 FPDF_BOOL bShrinkToFit,
416 FPDF_BOOL bPrintAsImage,
417 FPDF_BOOL bReverse,
418 FPDF_BOOL bAnnotations);
419 void JS_docgotoPage(int nPageNum);
420
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700421 FX_BOOL IsJSInitiated() const { return m_pInfo && m_pInfo->m_pJsPlatform; }
422 void SetSDKDocument(CPDFSDK_Document* pFXDoc) { m_pSDKDoc = pFXDoc; }
423 CPDFSDK_Document* GetSDKDocument() const { return m_pSDKDoc; }
Tom Sepez50d12ad2015-11-24 09:50:51 -0800424 UnderlyingDocumentType* GetUnderlyingDocument() const {
425 return m_pUnderlyingDoc;
426 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700427 CFX_ByteString GetAppName() const { return ""; }
dsinclairb9590102016-04-27 06:38:59 -0700428 CFX_SystemHandler* GetSysHandler() const { return m_pSysHandler.get(); }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700429 FPDF_FORMFILLINFO* GetFormFillInfo() const { return m_pInfo; }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700430
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700431 CFFL_IFormFiller* GetIFormFiller(); // Creates if not present.
432 CPDFSDK_AnnotHandlerMgr* GetAnnotHandlerMgr(); // Creates if not present.
Tom Sepezba038bc2015-10-08 12:03:00 -0700433 IJS_Runtime* GetJSRuntime(); // Creates if not present.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700434 CPDFSDK_ActionHandler* GetActionHander(); // Creates if not present.
Tom Sepez2f3dfef2015-03-02 15:35:26 -0800435
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700436 private:
Lei Zhangaa8bf7e2015-12-24 19:13:32 -0800437 std::unique_ptr<CPDFSDK_AnnotHandlerMgr> m_pAnnotHandlerMgr;
438 std::unique_ptr<CPDFSDK_ActionHandler> m_pActionHandler;
439 std::unique_ptr<IJS_Runtime> m_pJSRuntime;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700440 FPDF_FORMFILLINFO* const m_pInfo;
441 CPDFSDK_Document* m_pSDKDoc;
Tom Sepez50d12ad2015-11-24 09:50:51 -0800442 UnderlyingDocumentType* const m_pUnderlyingDoc;
Lei Zhangaa8bf7e2015-12-24 19:13:32 -0800443 std::unique_ptr<CFFL_IFormFiller> m_pIFormFiller;
dsinclairb9590102016-04-27 06:38:59 -0700444 std::unique_ptr<CFX_SystemHandler> m_pSysHandler;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700445};
446
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700447class CPDFSDK_Document {
448 public:
Tom Sepezfe351db2016-01-29 16:26:27 -0800449 static CPDFSDK_Document* FromFPDFFormHandle(FPDF_FORMHANDLE hHandle);
450
Tom Sepez50d12ad2015-11-24 09:50:51 -0800451 CPDFSDK_Document(UnderlyingDocumentType* pDoc, CPDFDoc_Environment* pEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700452 ~CPDFSDK_Document();
Tom Sepez2f3dfef2015-03-02 15:35:26 -0800453
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700454 CPDFSDK_InterForm* GetInterForm();
Tom Sepez50d12ad2015-11-24 09:50:51 -0800455
Tom Sepez5259ef32015-11-24 10:21:01 -0800456 // Gets the document object for the next layer down; for master this is
457 // a CPDF_Document, but for XFA it is a CPDFXFA_Document.
Tom Sepez50d12ad2015-11-24 09:50:51 -0800458 UnderlyingDocumentType* GetUnderlyingDocument() const {
Tom Sepez40e9ff32015-11-30 12:39:54 -0800459#ifdef PDF_ENABLE_XFA
Tom Sepez50d12ad2015-11-24 09:50:51 -0800460 return GetXFADocument();
Tom Sepez40e9ff32015-11-30 12:39:54 -0800461#else // PDF_ENABLE_XFA
462 return GetPDFDocument();
463#endif // PDF_ENABLE_XFA
Tom Sepez50d12ad2015-11-24 09:50:51 -0800464 }
Tom Sepez5259ef32015-11-24 10:21:01 -0800465
466 // Gets the CPDF_Document, either directly in master, or from the
467 // CPDFXFA_Document for XFA.
Tom Sepezbf59a072015-10-21 14:07:23 -0700468 CPDF_Document* GetPDFDocument() const {
Tom Sepez40e9ff32015-11-30 12:39:54 -0800469#ifdef PDF_ENABLE_XFA
Tom Sepezbf59a072015-10-21 14:07:23 -0700470 return m_pDoc ? m_pDoc->GetPDFDoc() : nullptr;
Tom Sepez40e9ff32015-11-30 12:39:54 -0800471#else // PDF_ENABLE_XFA
472 return m_pDoc;
473#endif // PDF_ENABLE_XFA
Tom Sepezbf59a072015-10-21 14:07:23 -0700474 }
Tom Sepez5259ef32015-11-24 10:21:01 -0800475
Tom Sepez40e9ff32015-11-30 12:39:54 -0800476#ifdef PDF_ENABLE_XFA
Tom Sepez5259ef32015-11-24 10:21:01 -0800477 // Gets the XFA document directly (XFA-only).
Tom Sepez50d12ad2015-11-24 09:50:51 -0800478 CPDFXFA_Document* GetXFADocument() const { return m_pDoc; }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700479
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700480 int GetPageViewCount() const { return m_pageMap.size(); }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800481#endif // PDF_ENABLE_XFA
482
dsinclair461eeaf2016-07-27 07:40:05 -0700483 CPDFSDK_PageView* GetPageView(UnderlyingPageType* pPage, bool ReNew);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700484 CPDFSDK_PageView* GetPageView(int nIndex);
485 CPDFSDK_PageView* GetCurrentView();
Tom Sepez540c4362015-11-24 13:33:57 -0800486 void RemovePageView(UnderlyingPageType* pPage);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700487 void UpdateAllViews(CPDFSDK_PageView* pSender, CPDFSDK_Annot* pAnnot);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700488
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700489 CPDFSDK_Annot* GetFocusAnnot();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700490
Tom Sepezba038bc2015-10-08 12:03:00 -0700491 IJS_Runtime* GetJsRuntime();
Tom Sepezc6ab1722015-02-05 15:27:25 -0800492
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700493 FX_BOOL SetFocusAnnot(CPDFSDK_Annot* pAnnot, FX_UINT nFlag = 0);
494 FX_BOOL KillFocusAnnot(FX_UINT nFlag = 0);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700495
Tom Sepez62a70f92016-03-21 15:00:20 -0700496 FX_BOOL ExtractPages(const std::vector<uint16_t>& arrExtraPages,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700497 CPDF_Document* pDstDoc);
498 FX_BOOL InsertPages(int nInsertAt,
499 const CPDF_Document* pSrcDoc,
Tom Sepez62a70f92016-03-21 15:00:20 -0700500 const std::vector<uint16_t>& arrSrcPages);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700501 FX_BOOL ReplacePages(int nPage,
502 const CPDF_Document* pSrcDoc,
Tom Sepez62a70f92016-03-21 15:00:20 -0700503 const std::vector<uint16_t>& arrSrcPages);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700504
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700505 void OnCloseDocument();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700506
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700507 int GetPageCount() { return m_pDoc->GetPageCount(); }
508 FX_BOOL GetPermissions(int nFlag);
509 FX_BOOL GetChangeMark() { return m_bChangeMask; }
510 void SetChangeMark() { m_bChangeMask = TRUE; }
511 void ClearChangeMark() { m_bChangeMask = FALSE; }
512 CFX_WideString GetPath();
Tom Sepez540c4362015-11-24 13:33:57 -0800513 UnderlyingPageType* GetPage(int nIndex);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700514 CPDFDoc_Environment* GetEnv() { return m_pEnv; }
515 void ProcJavascriptFun();
516 FX_BOOL ProcOpenAction();
517 CPDF_OCContext* GetOCContext();
518
519 private:
Tom Sepez540c4362015-11-24 13:33:57 -0800520 std::map<UnderlyingPageType*, CPDFSDK_PageView*> m_pageMap;
Tom Sepez50d12ad2015-11-24 09:50:51 -0800521 UnderlyingDocumentType* m_pDoc;
Lei Zhangaa8bf7e2015-12-24 19:13:32 -0800522 std::unique_ptr<CPDFSDK_InterForm> m_pInterForm;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700523 CPDFSDK_Annot* m_pFocusAnnot;
524 CPDFDoc_Environment* m_pEnv;
Lei Zhangaa8bf7e2015-12-24 19:13:32 -0800525 std::unique_ptr<CPDF_OCContext> m_pOccontent;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700526 FX_BOOL m_bChangeMask;
Oliver Chang972b78d2015-10-30 12:59:29 -0700527 FX_BOOL m_bBeingDestroyed;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700528};
Tom Sepezb9cc7a02016-02-01 13:42:30 -0800529
tsepez1e2c5572016-05-25 14:58:09 -0700530class CPDFSDK_PageView final : public CPDF_Page::View {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700531 public:
Tom Sepez540c4362015-11-24 13:33:57 -0800532 CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc, UnderlyingPageType* page);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700533 ~CPDFSDK_PageView();
Tom Sepez40e9ff32015-11-30 12:39:54 -0800534
535#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700536 void PageView_OnDraw(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800537 CFX_Matrix* pUser2Device,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700538 CPDF_RenderOptions* pOptions,
Lei Zhangf0e2e1b2015-11-02 13:27:54 -0800539 const FX_RECT& pClip);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800540#else // PDF_ENABLE_XFA
541 void PageView_OnDraw(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800542 CFX_Matrix* pUser2Device,
Tom Sepez40e9ff32015-11-30 12:39:54 -0800543 CPDF_RenderOptions* pOptions);
544#endif // PDF_ENABLE_XFA
545
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();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700558
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700559 CPDFSDK_Annot* AddAnnot(CPDF_Dictionary* pDict);
560 CPDFSDK_Annot* AddAnnot(const FX_CHAR* lpSubType, CPDF_Dictionary* pDict);
561 CPDFSDK_Annot* AddAnnot(CPDF_Annot* pPDFAnnot);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800562
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700563 FX_BOOL DeleteAnnot(CPDFSDK_Annot* pAnnot);
Lei Zhang50218532015-10-30 14:03:43 -0700564 size_t CountAnnots() const;
Lei Zhangbf60b292015-10-26 12:14:35 -0700565 CPDFSDK_Annot* GetAnnot(size_t nIndex);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700566 CPDFSDK_Annot* GetAnnotByDict(CPDF_Dictionary* pDict);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800567
568#ifdef PDF_ENABLE_XFA
dsinclairdf4bc592016-03-31 20:34:43 -0700569 CPDFSDK_Annot* AddAnnot(CXFA_FFWidget* pPDFAnnot);
570 CPDFSDK_Annot* GetAnnotByXFAWidget(CXFA_FFWidget* hWidget);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700571 CPDFXFA_Page* GetPDFXFAPage() { return m_page; }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800572#endif // PDF_ENABLE_XFA
573
jaepark9b57ec92016-08-25 16:20:54 -0700574 CPDF_Page* GetPDFPage() const;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700575 CPDF_Document* GetPDFDocument();
576 CPDFSDK_Document* GetSDKDocument() { return m_pSDKDoc; }
Tom Sepez281a9ea2016-02-26 14:24:28 -0800577 FX_BOOL OnLButtonDown(const CFX_FloatPoint& point, FX_UINT nFlag);
578 FX_BOOL OnLButtonUp(const CFX_FloatPoint& point, FX_UINT nFlag);
Tom Sepez51da0932015-11-25 16:05:49 -0800579#ifdef PDF_ENABLE_XFA
Tom Sepez281a9ea2016-02-26 14:24:28 -0800580 FX_BOOL OnRButtonDown(const CFX_FloatPoint& point, FX_UINT nFlag);
581 FX_BOOL OnRButtonUp(const CFX_FloatPoint& point, FX_UINT nFlag);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800582#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700583 FX_BOOL OnChar(int nChar, FX_UINT nFlag);
584 FX_BOOL OnKeyDown(int nKeyCode, int nFlag);
585 FX_BOOL OnKeyUp(int nKeyCode, int nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700586
Tom Sepez281a9ea2016-02-26 14:24:28 -0800587 FX_BOOL OnMouseMove(const CFX_FloatPoint& point, int nFlag);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700588 FX_BOOL OnMouseWheel(double deltaX,
589 double deltaY,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800590 const CFX_FloatPoint& point,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700591 int nFlag);
Lei Zhang1b700c32015-10-30 23:55:35 -0700592 bool IsValidAnnot(const CPDF_Annot* p) const;
Tom Sepez60d909e2015-12-10 15:34:55 -0800593 void GetCurrentMatrix(CFX_Matrix& matrix) { matrix = m_curMatrix; }
tsepezdf964df2016-04-21 12:09:41 -0700594 void UpdateRects(const std::vector<CFX_FloatRect>& rects);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700595 void UpdateView(CPDFSDK_Annot* pAnnot);
Lei Zhangbf60b292015-10-26 12:14:35 -0700596 const std::vector<CPDFSDK_Annot*>& GetAnnotList() const {
597 return m_fxAnnotArray;
598 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700599
thestigd3be1112016-06-08 06:11:20 -0700600 int GetPageIndex() const;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700601 void LoadFXAnnots();
Jun Fang75239542016-01-20 08:04:47 +0800602 void ClearFXAnnots();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700603 void SetValid(FX_BOOL bValid) { m_bValid = bValid; }
604 FX_BOOL IsValid() { return m_bValid; }
605 void SetLock(FX_BOOL bLocked) { m_bLocked = bLocked; }
606 FX_BOOL IsLocked() { return m_bLocked; }
Tom Sepez51da0932015-11-25 16:05:49 -0800607#ifndef PDF_ENABLE_XFA
608 void TakeOverPage() { m_bTakeOverPage = TRUE; }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800609#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700610
611 private:
thestigd3be1112016-06-08 06:11:20 -0700612 int GetPageIndexForStaticPDF() const;
Lei Zhangbf60b292015-10-26 12:14:35 -0700613
Tom Sepez60d909e2015-12-10 15:34:55 -0800614 CFX_Matrix m_curMatrix;
thestigd3be1112016-06-08 06:11:20 -0700615 UnderlyingPageType* const m_page;
Lei Zhangaa8bf7e2015-12-24 19:13:32 -0800616 std::unique_ptr<CPDF_AnnotList> m_pAnnotList;
Lei Zhangbf60b292015-10-26 12:14:35 -0700617 std::vector<CPDFSDK_Annot*> m_fxAnnotArray;
weili2d5b0202016-08-03 11:06:49 -0700618 CPDFSDK_Document* const m_pSDKDoc;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700619 CPDFSDK_Annot* m_CaptureWidget;
jaepark35512aa2016-08-29 17:15:08 -0700620#ifndef PDF_ENABLE_XFA
Tom Sepez40e9ff32015-11-30 12:39:54 -0800621 FX_BOOL m_bTakeOverPage;
622#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700623 FX_BOOL m_bEnterWidget;
624 FX_BOOL m_bExitWidget;
625 FX_BOOL m_bOnWidget;
626 FX_BOOL m_bValid;
627 FX_BOOL m_bLocked;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700628};
629
Tom Sepez19922bb2015-05-28 13:23:12 -0700630#endif // FPDFSDK_INCLUDE_FSDK_MGR_H_