blob: ca46a069f1aae1c172bacc1b369ee998d7c82ac3 [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
Dan Sinclairaa403d32016-03-15 14:57:22 -040014#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
dsinclairb9590102016-04-27 06:38:59 -070015#include "fpdfsdk/cfx_systemhandler.h"
Dan Sinclairefbc1912016-02-17 16:54:43 -050016#include "fpdfsdk/include/fsdk_actionhandler.h"
17#include "fpdfsdk/include/fsdk_annothandler.h"
18#include "fpdfsdk/include/fsdk_baseannot.h"
19#include "fpdfsdk/include/fsdk_baseform.h"
20#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;
Tom Sepezdcbc02f2015-07-17 09:16:17 -070027class CPDFSDK_ActionHandler;
28class CPDFSDK_Annot;
Tom Sepezdcbc02f2015-07-17 09:16:17 -070029class CPDFSDK_InterForm;
30class CPDFSDK_PageView;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070031class CPDFSDK_Widget;
dsinclair64376be2016-03-31 20:03:24 -070032class IJS_Runtime;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070033
Tom Sepez57028592016-02-01 15:49:11 -080034// NOTE: |bsUTF16LE| must outlive the use of the result. Care must be taken
35// since modifying the result would impact |bsUTF16LE|.
36FPDF_WIDESTRING AsFPDFWideString(CFX_ByteString* bsUTF16LE);
37
Nico Weber9d8ec5a2015-08-04 13:00:21 -070038class CPDFDoc_Environment final {
39 public:
Tom Sepez50d12ad2015-11-24 09:50:51 -080040 CPDFDoc_Environment(UnderlyingDocumentType* pDoc, FPDF_FORMFILLINFO* pFFinfo);
Tom Sepezdfbf8e72015-10-14 14:17:26 -070041 ~CPDFDoc_Environment();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070042
Nico Weber9d8ec5a2015-08-04 13:00:21 -070043 void FFI_Invalidate(FPDF_PAGE page,
44 double left,
45 double top,
46 double right,
47 double bottom) {
48 if (m_pInfo && m_pInfo->FFI_Invalidate)
49 m_pInfo->FFI_Invalidate(m_pInfo, page, left, top, right, bottom);
50 }
51
52 void FFI_OutputSelectedRect(FPDF_PAGE page,
53 double left,
54 double top,
55 double right,
56 double bottom) {
57 if (m_pInfo && m_pInfo->FFI_OutputSelectedRect)
58 m_pInfo->FFI_OutputSelectedRect(m_pInfo, page, left, top, right, bottom);
59 }
60
61 void FFI_SetCursor(int nCursorType) {
62 if (m_pInfo && m_pInfo->FFI_SetCursor)
63 m_pInfo->FFI_SetCursor(m_pInfo, nCursorType);
64 }
65
66 int FFI_SetTimer(int uElapse, TimerCallback lpTimerFunc) {
67 if (m_pInfo && m_pInfo->FFI_SetTimer)
68 return m_pInfo->FFI_SetTimer(m_pInfo, uElapse, lpTimerFunc);
69 return -1;
70 }
71
72 void FFI_KillTimer(int nTimerID) {
73 if (m_pInfo && m_pInfo->FFI_KillTimer)
74 m_pInfo->FFI_KillTimer(m_pInfo, nTimerID);
75 }
76
Tom Sepez468e5892015-10-13 15:49:36 -070077 FX_SYSTEMTIME FFI_GetLocalTime() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070078 FX_SYSTEMTIME fxtime;
79 if (m_pInfo && m_pInfo->FFI_GetLocalTime) {
80 FPDF_SYSTEMTIME systime = m_pInfo->FFI_GetLocalTime(m_pInfo);
81 fxtime.wDay = systime.wDay;
82 fxtime.wDayOfWeek = systime.wDayOfWeek;
83 fxtime.wHour = systime.wHour;
84 fxtime.wMilliseconds = systime.wMilliseconds;
85 fxtime.wMinute = systime.wMinute;
86 fxtime.wMonth = systime.wMonth;
87 fxtime.wSecond = systime.wSecond;
88 fxtime.wYear = systime.wYear;
Tom Sepezdcbc02f2015-07-17 09:16:17 -070089 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070090 return fxtime;
91 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070092
Nico Weber9d8ec5a2015-08-04 13:00:21 -070093 void FFI_OnChange() {
94 if (m_pInfo && m_pInfo->FFI_OnChange)
95 m_pInfo->FFI_OnChange(m_pInfo);
96 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070097
tsepezc3255f52016-03-25 14:52:27 -070098 FX_BOOL FFI_IsSHIFTKeyDown(uint32_t nFlag) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070099 return (nFlag & FWL_EVENTFLAG_ShiftKey) != 0;
100 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700101
tsepezc3255f52016-03-25 14:52:27 -0700102 FX_BOOL FFI_IsCTRLKeyDown(uint32_t nFlag) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700103 return (nFlag & FWL_EVENTFLAG_ControlKey) != 0;
104 }
Tom Sepezc6ab1722015-02-05 15:27:25 -0800105
tsepezc3255f52016-03-25 14:52:27 -0700106 FX_BOOL FFI_IsALTKeyDown(uint32_t nFlag) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700107 return (nFlag & FWL_EVENTFLAG_AltKey) != 0;
108 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700109
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700110 FPDF_PAGE FFI_GetPage(FPDF_DOCUMENT document, int nPageIndex) {
111 if (m_pInfo && m_pInfo->FFI_GetPage)
112 return m_pInfo->FFI_GetPage(m_pInfo, document, nPageIndex);
113 return NULL;
114 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700115
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700116 FPDF_PAGE FFI_GetCurrentPage(FPDF_DOCUMENT document) {
117 if (m_pInfo && m_pInfo->FFI_GetCurrentPage)
118 return m_pInfo->FFI_GetCurrentPage(m_pInfo, document);
119 return NULL;
120 }
Tom Sepez0d3b5cc2014-07-30 13:03:52 -0700121
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700122 int FFI_GetRotation(FPDF_PAGE page) {
123 if (m_pInfo && m_pInfo->FFI_GetRotation)
124 return m_pInfo->FFI_GetRotation(m_pInfo, page);
125 return 0;
126 }
Tom Sepez0d3b5cc2014-07-30 13:03:52 -0700127
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700128 void FFI_ExecuteNamedAction(const FX_CHAR* namedAction) {
129 if (m_pInfo && m_pInfo->FFI_ExecuteNamedAction)
130 m_pInfo->FFI_ExecuteNamedAction(m_pInfo, namedAction);
131 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700132
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700133 void FFI_OnSetFieldInputFocus(void* field,
134 FPDF_WIDESTRING focusText,
135 FPDF_DWORD nTextLen,
136 FX_BOOL bFocus) {
137 if (m_pInfo && m_pInfo->FFI_SetTextFieldFocus)
138 m_pInfo->FFI_SetTextFieldFocus(m_pInfo, focusText, nTextLen, bFocus);
139 }
Tom Sepez0d3b5cc2014-07-30 13:03:52 -0700140
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700141 void FFI_DoURIAction(const FX_CHAR* bsURI) {
142 if (m_pInfo && m_pInfo->FFI_DoURIAction)
143 m_pInfo->FFI_DoURIAction(m_pInfo, bsURI);
144 }
Tom Sepez0d3b5cc2014-07-30 13:03:52 -0700145
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700146 void FFI_DoGoToAction(int nPageIndex,
147 int zoomMode,
148 float* fPosArray,
149 int sizeOfArray) {
150 if (m_pInfo && m_pInfo->FFI_DoGoToAction)
151 m_pInfo->FFI_DoGoToAction(m_pInfo, nPageIndex, zoomMode, fPosArray,
152 sizeOfArray);
153 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700154
Tom Sepez51da0932015-11-25 16:05:49 -0800155#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700156 void FFI_DisplayCaret(FPDF_PAGE page,
157 FPDF_BOOL bVisible,
158 double left,
159 double top,
160 double right,
161 double bottom) {
162 if (m_pInfo && m_pInfo->FFI_DisplayCaret)
163 m_pInfo->FFI_DisplayCaret(m_pInfo, page, bVisible, left, top, right,
164 bottom);
165 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700166
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700167 int FFI_GetCurrentPageIndex(FPDF_DOCUMENT document) {
Jun Fang01fe5882015-11-25 11:05:58 +0800168 if (!m_pInfo || !m_pInfo->FFI_GetCurrentPageIndex) {
169 return -1;
170 }
171 return m_pInfo->FFI_GetCurrentPageIndex(m_pInfo, document);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700172 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700173
Jun Fang01fe5882015-11-25 11:05:58 +0800174 void FFI_SetCurrentPage(FPDF_DOCUMENT document, int iCurPage) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700175 if (m_pInfo && m_pInfo->FFI_SetCurrentPage)
176 m_pInfo->FFI_SetCurrentPage(m_pInfo, document, iCurPage);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700177 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700178
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700179 CFX_WideString FFI_GetAppName() const { return CFX_WideString(L"Acrobat"); }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700180
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700181 CFX_WideString FFI_GetPlatform() {
182 if (m_pInfo && m_pInfo->FFI_GetPlatform) {
183 int nRequiredLen = m_pInfo->FFI_GetPlatform(m_pInfo, NULL, 0);
184 if (nRequiredLen <= 0)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700185 return L"";
Bo Xufdc00a72014-10-28 23:03:33 -0700186
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700187 char* pbuff = new char[nRequiredLen];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700188 memset(pbuff, 0, nRequiredLen);
189 int nActualLen = m_pInfo->FFI_GetPlatform(m_pInfo, pbuff, nRequiredLen);
190 if (nActualLen <= 0 || nActualLen > nRequiredLen) {
191 delete[] pbuff;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700192 return L"";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700193 }
194 CFX_ByteString bsRet = CFX_ByteString(pbuff, nActualLen);
195 CFX_WideString wsRet = CFX_WideString::FromUTF16LE(
196 (unsigned short*)bsRet.GetBuffer(bsRet.GetLength()),
197 bsRet.GetLength() / sizeof(unsigned short));
198 delete[] pbuff;
199 return wsRet;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700200 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700201 return L"";
202 }
Bo Xufdc00a72014-10-28 23:03:33 -0700203
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700204 void FFI_GotoURL(FPDF_DOCUMENT document,
205 const CFX_WideStringC& wsURL,
206 FX_BOOL bAppend) {
207 if (m_pInfo && m_pInfo->FFI_GotoURL) {
208 CFX_ByteString bsTo = CFX_WideString(wsURL).UTF16LE_Encode();
209 FPDF_WIDESTRING pTo = (FPDF_WIDESTRING)bsTo.GetBuffer(wsURL.GetLength());
210 m_pInfo->FFI_GotoURL(m_pInfo, document, pTo);
211 bsTo.ReleaseBuffer();
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700212 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700213 }
Bo Xufdc00a72014-10-28 23:03:33 -0700214
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700215 void FFI_GetURL(FPDF_DOCUMENT document, CFX_WideString& wsURL) {
216 wsURL = CFX_WideString();
217 }
218
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700219 void FFI_GetPageViewRect(FPDF_PAGE page, FS_RECTF& dstRect) {
220 if (m_pInfo && m_pInfo->FFI_GetPageViewRect) {
221 double left;
222 double top;
223 double right;
224 double bottom;
225 m_pInfo->FFI_GetPageViewRect(m_pInfo, page, &left, &top, &right, &bottom);
226
227 dstRect.left = static_cast<float>(left);
228 dstRect.top = static_cast<float>(top < bottom ? bottom : top);
229 dstRect.bottom = static_cast<float>(top < bottom ? top : bottom);
230 dstRect.right = static_cast<float>(right);
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700231 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700232 }
Bo Xufdc00a72014-10-28 23:03:33 -0700233
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700234 FX_BOOL FFI_PopupMenu(FPDF_PAGE page,
235 FPDF_WIDGET hWidget,
236 int menuFlag,
237 CFX_PointF ptPopup,
238 const CFX_PointF* pRectExclude) {
239 if (m_pInfo && m_pInfo->FFI_PopupMenu)
240 return m_pInfo->FFI_PopupMenu(m_pInfo, page, hWidget, menuFlag, ptPopup.x,
241 ptPopup.y);
242 return FALSE;
243 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700244
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700245 void FFI_Alert(FPDF_WIDESTRING Msg,
246 FPDF_WIDESTRING Title,
247 int Type,
248 int Icon) {
249 if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_alert)
250 m_pInfo->m_pJsPlatform->app_alert(m_pInfo->m_pJsPlatform, Msg, Title,
251 Type, Icon);
252 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700253
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700254 void FFI_EmailTo(FPDF_FILEHANDLER* fileHandler,
255 FPDF_WIDESTRING pTo,
256 FPDF_WIDESTRING pSubject,
257 FPDF_WIDESTRING pCC,
258 FPDF_WIDESTRING pBcc,
259 FPDF_WIDESTRING pMsg) {
260 if (m_pInfo && m_pInfo->FFI_EmailTo)
261 m_pInfo->FFI_EmailTo(m_pInfo, fileHandler, pTo, pSubject, pCC, pBcc,
262 pMsg);
263 }
264
265 void FFI_UploadTo(FPDF_FILEHANDLER* fileHandler,
266 int fileFlag,
267 FPDF_WIDESTRING uploadTo) {
268 if (m_pInfo && m_pInfo->FFI_UploadTo)
269 m_pInfo->FFI_UploadTo(m_pInfo, fileHandler, fileFlag, uploadTo);
270 }
271
272 FPDF_FILEHANDLER* FFI_OpenFile(int fileType,
273 FPDF_WIDESTRING wsURL,
274 const char* mode) {
275 if (m_pInfo && m_pInfo->FFI_OpenFile)
276 return m_pInfo->FFI_OpenFile(m_pInfo, fileType, wsURL, mode);
277 return NULL;
278 }
279
280 CFX_WideString FFI_GetFilePath(FPDF_FILEHANDLER* pFileHandler) const {
281 return L"";
282 }
283
284 int FFI_GetDocumentCount() const { return 0; }
285 int FFI_GetCurDocument() const { return 0; }
286
287 IFX_FileRead* FFI_DownloadFromURL(const FX_WCHAR* url) {
288 if (m_pInfo && m_pInfo->FFI_DownloadFromURL) {
289 CFX_ByteString bstrURL = CFX_WideString(url).UTF16LE_Encode();
290 FPDF_WIDESTRING wsURL =
291 (FPDF_WIDESTRING)bstrURL.GetBuffer(bstrURL.GetLength());
292
293 FPDF_LPFILEHANDLER fileHandler =
294 m_pInfo->FFI_DownloadFromURL(m_pInfo, wsURL);
295
Lei Zhangdb5256f2015-10-02 10:11:43 -0700296 return new CFPDF_FileStream(fileHandler);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700297 }
298 return NULL;
299 }
300
301 CFX_WideString FFI_PostRequestURL(const FX_WCHAR* wsURL,
302 const FX_WCHAR* wsData,
303 const FX_WCHAR* wsContentType,
304 const FX_WCHAR* wsEncode,
305 const FX_WCHAR* wsHeader) {
306 if (m_pInfo && m_pInfo->FFI_PostRequestURL) {
307 CFX_ByteString bsURL = CFX_WideString(wsURL).UTF16LE_Encode();
308 FPDF_WIDESTRING URL = (FPDF_WIDESTRING)bsURL.GetBuffer(bsURL.GetLength());
309
310 CFX_ByteString bsData = CFX_WideString(wsData).UTF16LE_Encode();
311 FPDF_WIDESTRING data =
312 (FPDF_WIDESTRING)bsData.GetBuffer(bsData.GetLength());
313
314 CFX_ByteString bsContentType =
315 CFX_WideString(wsContentType).UTF16LE_Encode();
316 FPDF_WIDESTRING contentType =
317 (FPDF_WIDESTRING)bsContentType.GetBuffer(bsContentType.GetLength());
318
319 CFX_ByteString bsEncode = CFX_WideString(wsEncode).UTF16LE_Encode();
320 FPDF_WIDESTRING encode =
321 (FPDF_WIDESTRING)bsEncode.GetBuffer(bsEncode.GetLength());
322
323 CFX_ByteString bsHeader = CFX_WideString(wsHeader).UTF16LE_Encode();
324 FPDF_WIDESTRING header =
325 (FPDF_WIDESTRING)bsHeader.GetBuffer(bsHeader.GetLength());
326
thestig77d148d2016-04-06 06:28:31 -0700327 FPDF_BSTR response;
328 FPDF_BStr_Init(&response);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700329 m_pInfo->FFI_PostRequestURL(m_pInfo, URL, data, contentType, encode,
thestig77d148d2016-04-06 06:28:31 -0700330 header, &response);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700331
332 CFX_WideString wsRet = CFX_WideString::FromUTF16LE(
thestig77d148d2016-04-06 06:28:31 -0700333 (unsigned short*)response.str, response.len / sizeof(unsigned short));
334 FPDF_BStr_Clear(&response);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700335
336 return wsRet;
337 }
338 return L"";
339 }
340
341 FPDF_BOOL FFI_PutRequestURL(const FX_WCHAR* wsURL,
342 const FX_WCHAR* wsData,
343 const FX_WCHAR* wsEncode) {
344 if (m_pInfo && m_pInfo->FFI_PutRequestURL) {
345 CFX_ByteString bsURL = CFX_WideString(wsURL).UTF16LE_Encode();
346 FPDF_WIDESTRING URL = (FPDF_WIDESTRING)bsURL.GetBuffer(bsURL.GetLength());
347
348 CFX_ByteString bsData = CFX_WideString(wsData).UTF16LE_Encode();
349 FPDF_WIDESTRING data =
350 (FPDF_WIDESTRING)bsData.GetBuffer(bsData.GetLength());
351
352 CFX_ByteString bsEncode = CFX_WideString(wsEncode).UTF16LE_Encode();
353 FPDF_WIDESTRING encode =
354 (FPDF_WIDESTRING)bsEncode.GetBuffer(bsEncode.GetLength());
355
356 return m_pInfo->FFI_PutRequestURL(m_pInfo, URL, data, encode);
357 }
358 return FALSE;
359 }
360
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700361 CFX_WideString FFI_GetLanguage() {
362 if (m_pInfo && m_pInfo->FFI_GetLanguage) {
363 int nRequiredLen = m_pInfo->FFI_GetLanguage(m_pInfo, NULL, 0);
364 if (nRequiredLen <= 0)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700365 return L"";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700366
367 char* pbuff = new char[nRequiredLen];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700368 memset(pbuff, 0, nRequiredLen);
369 int nActualLen = m_pInfo->FFI_GetLanguage(m_pInfo, pbuff, nRequiredLen);
370 if (nActualLen <= 0 || nActualLen > nRequiredLen) {
371 delete[] pbuff;
372 return L"";
373 }
374 CFX_ByteString bsRet = CFX_ByteString(pbuff, nActualLen);
375 CFX_WideString wsRet = CFX_WideString::FromUTF16LE(
376 (unsigned short*)bsRet.GetBuffer(bsRet.GetLength()),
377 bsRet.GetLength() / sizeof(unsigned short));
378 delete[] pbuff;
379 return wsRet;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700380 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700381 return L"";
382 }
Lei Zhang84e5a122016-02-19 14:25:10 -0800383
tsepezc3255f52016-03-25 14:52:27 -0700384 void FFI_PageEvent(int iPageCount, uint32_t dwEventType) const {
Lei Zhang84e5a122016-02-19 14:25:10 -0800385 if (m_pInfo && m_pInfo->FFI_PageEvent)
jinming_wanga1cef702016-03-18 16:35:40 +0800386 m_pInfo->FFI_PageEvent(m_pInfo, iPageCount, dwEventType);
Jun Fangc30d5bf2016-02-02 18:12:23 -0800387 }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800388#endif // PDF_ENABLE_XFA
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700389
Tom Sepez57028592016-02-01 15:49:11 -0800390 int JS_appAlert(const FX_WCHAR* Msg,
391 const FX_WCHAR* Title,
392 FX_UINT Type,
393 FX_UINT Icon);
394 int JS_appResponse(const FX_WCHAR* Question,
395 const FX_WCHAR* Title,
396 const FX_WCHAR* Default,
397 const FX_WCHAR* cLabel,
398 FPDF_BOOL bPassword,
399 void* response,
400 int length);
401 void JS_appBeep(int nType);
402 CFX_WideString JS_fieldBrowse();
403 CFX_WideString JS_docGetFilePath();
404 void JS_docSubmitForm(void* formData, int length, const FX_WCHAR* URL);
405 void JS_docmailForm(void* mailData,
406 int length,
407 FPDF_BOOL bUI,
408 const FX_WCHAR* To,
409 const FX_WCHAR* Subject,
410 const FX_WCHAR* CC,
411 const FX_WCHAR* BCC,
412 const FX_WCHAR* Msg);
413 void JS_docprint(FPDF_BOOL bUI,
414 int nStart,
415 int nEnd,
416 FPDF_BOOL bSilent,
417 FPDF_BOOL bShrinkToFit,
418 FPDF_BOOL bPrintAsImage,
419 FPDF_BOOL bReverse,
420 FPDF_BOOL bAnnotations);
421 void JS_docgotoPage(int nPageNum);
422
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700423 FX_BOOL IsJSInitiated() const { return m_pInfo && m_pInfo->m_pJsPlatform; }
424 void SetSDKDocument(CPDFSDK_Document* pFXDoc) { m_pSDKDoc = pFXDoc; }
425 CPDFSDK_Document* GetSDKDocument() const { return m_pSDKDoc; }
Tom Sepez50d12ad2015-11-24 09:50:51 -0800426 UnderlyingDocumentType* GetUnderlyingDocument() const {
427 return m_pUnderlyingDoc;
428 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700429 CFX_ByteString GetAppName() const { return ""; }
dsinclairb9590102016-04-27 06:38:59 -0700430 CFX_SystemHandler* GetSysHandler() const { return m_pSysHandler.get(); }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700431 FPDF_FORMFILLINFO* GetFormFillInfo() const { return m_pInfo; }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700432
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700433 CFFL_IFormFiller* GetIFormFiller(); // Creates if not present.
434 CPDFSDK_AnnotHandlerMgr* GetAnnotHandlerMgr(); // Creates if not present.
Tom Sepezba038bc2015-10-08 12:03:00 -0700435 IJS_Runtime* GetJSRuntime(); // Creates if not present.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700436 CPDFSDK_ActionHandler* GetActionHander(); // Creates if not present.
Tom Sepez2f3dfef2015-03-02 15:35:26 -0800437
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700438 private:
Lei Zhangaa8bf7e2015-12-24 19:13:32 -0800439 std::unique_ptr<CPDFSDK_AnnotHandlerMgr> m_pAnnotHandlerMgr;
440 std::unique_ptr<CPDFSDK_ActionHandler> m_pActionHandler;
441 std::unique_ptr<IJS_Runtime> m_pJSRuntime;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700442 FPDF_FORMFILLINFO* const m_pInfo;
443 CPDFSDK_Document* m_pSDKDoc;
Tom Sepez50d12ad2015-11-24 09:50:51 -0800444 UnderlyingDocumentType* const m_pUnderlyingDoc;
Lei Zhangaa8bf7e2015-12-24 19:13:32 -0800445 std::unique_ptr<CFFL_IFormFiller> m_pIFormFiller;
dsinclairb9590102016-04-27 06:38:59 -0700446 std::unique_ptr<CFX_SystemHandler> m_pSysHandler;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700447};
448
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700449class CPDFSDK_Document {
450 public:
Tom Sepezfe351db2016-01-29 16:26:27 -0800451 static CPDFSDK_Document* FromFPDFFormHandle(FPDF_FORMHANDLE hHandle);
452
Tom Sepez50d12ad2015-11-24 09:50:51 -0800453 CPDFSDK_Document(UnderlyingDocumentType* pDoc, CPDFDoc_Environment* pEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700454 ~CPDFSDK_Document();
Tom Sepez2f3dfef2015-03-02 15:35:26 -0800455
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700456 CPDFSDK_InterForm* GetInterForm();
Tom Sepez50d12ad2015-11-24 09:50:51 -0800457
Tom Sepez5259ef32015-11-24 10:21:01 -0800458 // Gets the document object for the next layer down; for master this is
459 // a CPDF_Document, but for XFA it is a CPDFXFA_Document.
Tom Sepez50d12ad2015-11-24 09:50:51 -0800460 UnderlyingDocumentType* GetUnderlyingDocument() const {
Tom Sepez40e9ff32015-11-30 12:39:54 -0800461#ifdef PDF_ENABLE_XFA
Tom Sepez50d12ad2015-11-24 09:50:51 -0800462 return GetXFADocument();
Tom Sepez40e9ff32015-11-30 12:39:54 -0800463#else // PDF_ENABLE_XFA
464 return GetPDFDocument();
465#endif // PDF_ENABLE_XFA
Tom Sepez50d12ad2015-11-24 09:50:51 -0800466 }
Tom Sepez5259ef32015-11-24 10:21:01 -0800467
468 // Gets the CPDF_Document, either directly in master, or from the
469 // CPDFXFA_Document for XFA.
Tom Sepezbf59a072015-10-21 14:07:23 -0700470 CPDF_Document* GetPDFDocument() const {
Tom Sepez40e9ff32015-11-30 12:39:54 -0800471#ifdef PDF_ENABLE_XFA
Tom Sepezbf59a072015-10-21 14:07:23 -0700472 return m_pDoc ? m_pDoc->GetPDFDoc() : nullptr;
Tom Sepez40e9ff32015-11-30 12:39:54 -0800473#else // PDF_ENABLE_XFA
474 return m_pDoc;
475#endif // PDF_ENABLE_XFA
Tom Sepezbf59a072015-10-21 14:07:23 -0700476 }
Tom Sepez5259ef32015-11-24 10:21:01 -0800477
Tom Sepez40e9ff32015-11-30 12:39:54 -0800478#ifdef PDF_ENABLE_XFA
Tom Sepez5259ef32015-11-24 10:21:01 -0800479 // Gets the XFA document directly (XFA-only).
Tom Sepez50d12ad2015-11-24 09:50:51 -0800480 CPDFXFA_Document* GetXFADocument() const { return m_pDoc; }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700481
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700482 int GetPageViewCount() const { return m_pageMap.size(); }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800483#endif // PDF_ENABLE_XFA
484
Tom Sepez540c4362015-11-24 13:33:57 -0800485 CPDFSDK_PageView* GetPageView(UnderlyingPageType* pPage,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700486 FX_BOOL ReNew = TRUE);
487 CPDFSDK_PageView* GetPageView(int nIndex);
488 CPDFSDK_PageView* GetCurrentView();
Tom Sepez540c4362015-11-24 13:33:57 -0800489 void RemovePageView(UnderlyingPageType* pPage);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700490 void UpdateAllViews(CPDFSDK_PageView* pSender, CPDFSDK_Annot* pAnnot);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700491
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700492 CPDFSDK_Annot* GetFocusAnnot();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700493
Tom Sepezba038bc2015-10-08 12:03:00 -0700494 IJS_Runtime* GetJsRuntime();
Tom Sepezc6ab1722015-02-05 15:27:25 -0800495
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700496 FX_BOOL SetFocusAnnot(CPDFSDK_Annot* pAnnot, FX_UINT nFlag = 0);
497 FX_BOOL KillFocusAnnot(FX_UINT nFlag = 0);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700498
Tom Sepez62a70f92016-03-21 15:00:20 -0700499 FX_BOOL ExtractPages(const std::vector<uint16_t>& arrExtraPages,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700500 CPDF_Document* pDstDoc);
501 FX_BOOL InsertPages(int nInsertAt,
502 const CPDF_Document* pSrcDoc,
Tom Sepez62a70f92016-03-21 15:00:20 -0700503 const std::vector<uint16_t>& arrSrcPages);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700504 FX_BOOL ReplacePages(int nPage,
505 const CPDF_Document* pSrcDoc,
Tom Sepez62a70f92016-03-21 15:00:20 -0700506 const std::vector<uint16_t>& arrSrcPages);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700507
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700508 void OnCloseDocument();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700509
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700510 int GetPageCount() { return m_pDoc->GetPageCount(); }
511 FX_BOOL GetPermissions(int nFlag);
512 FX_BOOL GetChangeMark() { return m_bChangeMask; }
513 void SetChangeMark() { m_bChangeMask = TRUE; }
514 void ClearChangeMark() { m_bChangeMask = FALSE; }
515 CFX_WideString GetPath();
Tom Sepez540c4362015-11-24 13:33:57 -0800516 UnderlyingPageType* GetPage(int nIndex);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700517 CPDFDoc_Environment* GetEnv() { return m_pEnv; }
518 void ProcJavascriptFun();
519 FX_BOOL ProcOpenAction();
520 CPDF_OCContext* GetOCContext();
521
522 private:
Tom Sepez540c4362015-11-24 13:33:57 -0800523 std::map<UnderlyingPageType*, CPDFSDK_PageView*> m_pageMap;
Tom Sepez50d12ad2015-11-24 09:50:51 -0800524 UnderlyingDocumentType* m_pDoc;
Lei Zhangaa8bf7e2015-12-24 19:13:32 -0800525 std::unique_ptr<CPDFSDK_InterForm> m_pInterForm;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700526 CPDFSDK_Annot* m_pFocusAnnot;
527 CPDFDoc_Environment* m_pEnv;
Lei Zhangaa8bf7e2015-12-24 19:13:32 -0800528 std::unique_ptr<CPDF_OCContext> m_pOccontent;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700529 FX_BOOL m_bChangeMask;
Oliver Chang972b78d2015-10-30 12:59:29 -0700530 FX_BOOL m_bBeingDestroyed;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700531};
Tom Sepezb9cc7a02016-02-01 13:42:30 -0800532
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700533class CPDFSDK_PageView final {
534 public:
Tom Sepez540c4362015-11-24 13:33:57 -0800535 CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc, UnderlyingPageType* page);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700536 ~CPDFSDK_PageView();
Tom Sepez40e9ff32015-11-30 12:39:54 -0800537
538#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700539 void PageView_OnDraw(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800540 CFX_Matrix* pUser2Device,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700541 CPDF_RenderOptions* pOptions,
Lei Zhangf0e2e1b2015-11-02 13:27:54 -0800542 const FX_RECT& pClip);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800543#else // PDF_ENABLE_XFA
544 void PageView_OnDraw(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800545 CFX_Matrix* pUser2Device,
Tom Sepez40e9ff32015-11-30 12:39:54 -0800546 CPDF_RenderOptions* pOptions);
547#endif // PDF_ENABLE_XFA
548
Lei Zhang1b700c32015-10-30 23:55:35 -0700549 const CPDF_Annot* GetPDFAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700550 CPDFSDK_Annot* GetFXAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
Lei Zhang1b700c32015-10-30 23:55:35 -0700551 const CPDF_Annot* GetPDFWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700552 CPDFSDK_Annot* GetFXWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
553 CPDFSDK_Annot* GetFocusAnnot();
554 void SetFocusAnnot(CPDFSDK_Annot* pSDKAnnot, FX_UINT nFlag = 0) {
555 m_pSDKDoc->SetFocusAnnot(pSDKAnnot, nFlag);
556 }
557 FX_BOOL KillFocusAnnot(FX_UINT nFlag = 0) {
558 return m_pSDKDoc->KillFocusAnnot(nFlag);
559 }
Oliver Chang972b78d2015-10-30 12:59:29 -0700560 void KillFocusAnnotIfNeeded();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700561 FX_BOOL Annot_HasAppearance(CPDF_Annot* pAnnot);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700562
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700563 CPDFSDK_Annot* AddAnnot(CPDF_Dictionary* pDict);
564 CPDFSDK_Annot* AddAnnot(const FX_CHAR* lpSubType, CPDF_Dictionary* pDict);
565 CPDFSDK_Annot* AddAnnot(CPDF_Annot* pPDFAnnot);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800566
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700567 FX_BOOL DeleteAnnot(CPDFSDK_Annot* pAnnot);
Lei Zhang50218532015-10-30 14:03:43 -0700568 size_t CountAnnots() const;
Lei Zhangbf60b292015-10-26 12:14:35 -0700569 CPDFSDK_Annot* GetAnnot(size_t nIndex);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700570 CPDFSDK_Annot* GetAnnotByDict(CPDF_Dictionary* pDict);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800571
572#ifdef PDF_ENABLE_XFA
dsinclairdf4bc592016-03-31 20:34:43 -0700573 CPDFSDK_Annot* AddAnnot(CXFA_FFWidget* pPDFAnnot);
574 CPDFSDK_Annot* GetAnnotByXFAWidget(CXFA_FFWidget* hWidget);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700575 CPDFXFA_Page* GetPDFXFAPage() { return m_page; }
576 CPDF_Page* GetPDFPage();
Tom Sepez40e9ff32015-11-30 12:39:54 -0800577#else
578 CPDF_Page* GetPDFPage() { return m_page; }
579#endif // PDF_ENABLE_XFA
580
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700581 CPDF_Document* GetPDFDocument();
582 CPDFSDK_Document* GetSDKDocument() { return m_pSDKDoc; }
Tom Sepez281a9ea2016-02-26 14:24:28 -0800583 FX_BOOL OnLButtonDown(const CFX_FloatPoint& point, FX_UINT nFlag);
584 FX_BOOL OnLButtonUp(const CFX_FloatPoint& point, FX_UINT nFlag);
Tom Sepez51da0932015-11-25 16:05:49 -0800585#ifdef PDF_ENABLE_XFA
Tom Sepez281a9ea2016-02-26 14:24:28 -0800586 FX_BOOL OnRButtonDown(const CFX_FloatPoint& point, FX_UINT nFlag);
587 FX_BOOL OnRButtonUp(const CFX_FloatPoint& point, FX_UINT nFlag);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800588#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700589 FX_BOOL OnChar(int nChar, FX_UINT nFlag);
590 FX_BOOL OnKeyDown(int nKeyCode, int nFlag);
591 FX_BOOL OnKeyUp(int nKeyCode, int nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700592
Tom Sepez281a9ea2016-02-26 14:24:28 -0800593 FX_BOOL OnMouseMove(const CFX_FloatPoint& point, int nFlag);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700594 FX_BOOL OnMouseWheel(double deltaX,
595 double deltaY,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800596 const CFX_FloatPoint& point,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700597 int nFlag);
Lei Zhang1b700c32015-10-30 23:55:35 -0700598 bool IsValidAnnot(const CPDF_Annot* p) const;
Tom Sepez60d909e2015-12-10 15:34:55 -0800599 void GetCurrentMatrix(CFX_Matrix& matrix) { matrix = m_curMatrix; }
tsepezdf964df2016-04-21 12:09:41 -0700600 void UpdateRects(const std::vector<CFX_FloatRect>& rects);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700601 void UpdateView(CPDFSDK_Annot* pAnnot);
Lei Zhangbf60b292015-10-26 12:14:35 -0700602 const std::vector<CPDFSDK_Annot*>& GetAnnotList() const {
603 return m_fxAnnotArray;
604 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700605
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700606 int GetPageIndex();
607 void LoadFXAnnots();
Jun Fang75239542016-01-20 08:04:47 +0800608 void ClearFXAnnots();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700609 void SetValid(FX_BOOL bValid) { m_bValid = bValid; }
610 FX_BOOL IsValid() { return m_bValid; }
611 void SetLock(FX_BOOL bLocked) { m_bLocked = bLocked; }
612 FX_BOOL IsLocked() { return m_bLocked; }
Tom Sepez51da0932015-11-25 16:05:49 -0800613#ifndef PDF_ENABLE_XFA
614 void TakeOverPage() { m_bTakeOverPage = TRUE; }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800615#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700616
617 private:
618 void PageView_OnHighlightFormFields(CFX_RenderDevice* pDevice,
619 CPDFSDK_Widget* pWidget);
Lei Zhangbf60b292015-10-26 12:14:35 -0700620
Tom Sepez60d909e2015-12-10 15:34:55 -0800621 CFX_Matrix m_curMatrix;
Tom Sepez540c4362015-11-24 13:33:57 -0800622 UnderlyingPageType* m_page;
Lei Zhangaa8bf7e2015-12-24 19:13:32 -0800623 std::unique_ptr<CPDF_AnnotList> m_pAnnotList;
Lei Zhangbf60b292015-10-26 12:14:35 -0700624 std::vector<CPDFSDK_Annot*> m_fxAnnotArray;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700625 CPDFSDK_Document* m_pSDKDoc;
Tom Sepez40e9ff32015-11-30 12:39:54 -0800626#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700627 CPDFSDK_Annot* m_CaptureWidget;
Tom Sepez40e9ff32015-11-30 12:39:54 -0800628#else // PDF_ENABLE_XFA
629 CPDFSDK_Widget* m_CaptureWidget;
630 FX_BOOL m_bTakeOverPage;
631#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700632 FX_BOOL m_bEnterWidget;
633 FX_BOOL m_bExitWidget;
634 FX_BOOL m_bOnWidget;
635 FX_BOOL m_bValid;
636 FX_BOOL m_bLocked;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700637};
638
Tom Sepez19922bb2015-05-28 13:23:12 -0700639#endif // FPDFSDK_INCLUDE_FSDK_MGR_H_