blob: 4e9aab40bb8171e957fe0e239c59388c59a6392f [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
Lei Zhanga688a042015-11-09 13:57:49 -080014#include "core/include/fpdftext/fpdf_text.h"
Dan Sinclairefbc1912016-02-17 16:54:43 -050015#include "fpdfsdk/include/fsdk_actionhandler.h"
16#include "fpdfsdk/include/fsdk_annothandler.h"
17#include "fpdfsdk/include/fsdk_baseannot.h"
18#include "fpdfsdk/include/fsdk_baseform.h"
19#include "fpdfsdk/include/fsdk_common.h"
20#include "fpdfsdk/include/fsdk_define.h"
21#include "fpdfsdk/include/fx_systemhandler.h"
Lei Zhange5b0bd12015-06-19 17:15:41 -070022#include "javascript/IJavaScript.h"
Lei Zhangb4e7f302015-11-06 15:52:32 -080023#include "public/fpdf_formfill.h"
24#include "public/fpdf_fwlevent.h" // cross platform keycode and events define.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070025
Tom Sepez40e9ff32015-11-30 12:39:54 -080026#ifdef PDF_ENABLE_XFA
Lei Zhang875b9c92016-01-08 13:51:10 -080027#include "fpdfsdk/include/fpdfxfa/fpdfxfa_doc.h"
28#include "fpdfsdk/include/fpdfxfa/fpdfxfa_page.h"
Tom Sepez40e9ff32015-11-30 12:39:54 -080029#endif // PDF_ENABLE_XFA
30
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070031class CFFL_IFormFiller;
Tom Sepezdcbc02f2015-07-17 09:16:17 -070032class CPDFSDK_ActionHandler;
33class CPDFSDK_Annot;
34class CPDFSDK_Document;
35class CPDFSDK_InterForm;
36class CPDFSDK_PageView;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070037class CPDFSDK_Widget;
38class IFX_SystemHandler;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070039
Tom Sepez57028592016-02-01 15:49:11 -080040// NOTE: |bsUTF16LE| must outlive the use of the result. Care must be taken
41// since modifying the result would impact |bsUTF16LE|.
42FPDF_WIDESTRING AsFPDFWideString(CFX_ByteString* bsUTF16LE);
43
Nico Weber9d8ec5a2015-08-04 13:00:21 -070044class CPDFDoc_Environment final {
45 public:
Tom Sepez50d12ad2015-11-24 09:50:51 -080046 CPDFDoc_Environment(UnderlyingDocumentType* pDoc, FPDF_FORMFILLINFO* pFFinfo);
Tom Sepezdfbf8e72015-10-14 14:17:26 -070047 ~CPDFDoc_Environment();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070048
Tom Sepez51da0932015-11-25 16:05:49 -080049#ifdef PDF_ENABLE_XFA
Tom Sepezdfbf8e72015-10-14 14:17:26 -070050 void Release() {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070051 if (m_pInfo && m_pInfo->Release)
52 m_pInfo->Release(m_pInfo);
53 delete this;
54 }
Tom Sepez40e9ff32015-11-30 12:39:54 -080055#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -070056
57 void FFI_Invalidate(FPDF_PAGE page,
58 double left,
59 double top,
60 double right,
61 double bottom) {
62 if (m_pInfo && m_pInfo->FFI_Invalidate)
63 m_pInfo->FFI_Invalidate(m_pInfo, page, left, top, right, bottom);
64 }
65
66 void FFI_OutputSelectedRect(FPDF_PAGE page,
67 double left,
68 double top,
69 double right,
70 double bottom) {
71 if (m_pInfo && m_pInfo->FFI_OutputSelectedRect)
72 m_pInfo->FFI_OutputSelectedRect(m_pInfo, page, left, top, right, bottom);
73 }
74
75 void FFI_SetCursor(int nCursorType) {
76 if (m_pInfo && m_pInfo->FFI_SetCursor)
77 m_pInfo->FFI_SetCursor(m_pInfo, nCursorType);
78 }
79
80 int FFI_SetTimer(int uElapse, TimerCallback lpTimerFunc) {
81 if (m_pInfo && m_pInfo->FFI_SetTimer)
82 return m_pInfo->FFI_SetTimer(m_pInfo, uElapse, lpTimerFunc);
83 return -1;
84 }
85
86 void FFI_KillTimer(int nTimerID) {
87 if (m_pInfo && m_pInfo->FFI_KillTimer)
88 m_pInfo->FFI_KillTimer(m_pInfo, nTimerID);
89 }
90
Tom Sepez468e5892015-10-13 15:49:36 -070091 FX_SYSTEMTIME FFI_GetLocalTime() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070092 FX_SYSTEMTIME fxtime;
93 if (m_pInfo && m_pInfo->FFI_GetLocalTime) {
94 FPDF_SYSTEMTIME systime = m_pInfo->FFI_GetLocalTime(m_pInfo);
95 fxtime.wDay = systime.wDay;
96 fxtime.wDayOfWeek = systime.wDayOfWeek;
97 fxtime.wHour = systime.wHour;
98 fxtime.wMilliseconds = systime.wMilliseconds;
99 fxtime.wMinute = systime.wMinute;
100 fxtime.wMonth = systime.wMonth;
101 fxtime.wSecond = systime.wSecond;
102 fxtime.wYear = systime.wYear;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700103 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700104 return fxtime;
105 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700106
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700107 void FFI_OnChange() {
108 if (m_pInfo && m_pInfo->FFI_OnChange)
109 m_pInfo->FFI_OnChange(m_pInfo);
110 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700111
Tom Sepez468e5892015-10-13 15:49:36 -0700112 FX_BOOL FFI_IsSHIFTKeyDown(FX_DWORD nFlag) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700113 return (nFlag & FWL_EVENTFLAG_ShiftKey) != 0;
114 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700115
Tom Sepez468e5892015-10-13 15:49:36 -0700116 FX_BOOL FFI_IsCTRLKeyDown(FX_DWORD nFlag) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700117 return (nFlag & FWL_EVENTFLAG_ControlKey) != 0;
118 }
Tom Sepezc6ab1722015-02-05 15:27:25 -0800119
Tom Sepez468e5892015-10-13 15:49:36 -0700120 FX_BOOL FFI_IsALTKeyDown(FX_DWORD nFlag) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700121 return (nFlag & FWL_EVENTFLAG_AltKey) != 0;
122 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700123
Tom Sepez468e5892015-10-13 15:49:36 -0700124 FX_BOOL FFI_IsINSERTKeyDown(FX_DWORD nFlag) const { return FALSE; }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700125
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700126 FPDF_PAGE FFI_GetPage(FPDF_DOCUMENT document, int nPageIndex) {
127 if (m_pInfo && m_pInfo->FFI_GetPage)
128 return m_pInfo->FFI_GetPage(m_pInfo, document, nPageIndex);
129 return NULL;
130 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700131
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700132 FPDF_PAGE FFI_GetCurrentPage(FPDF_DOCUMENT document) {
133 if (m_pInfo && m_pInfo->FFI_GetCurrentPage)
134 return m_pInfo->FFI_GetCurrentPage(m_pInfo, document);
135 return NULL;
136 }
Tom Sepez0d3b5cc2014-07-30 13:03:52 -0700137
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700138 int FFI_GetRotation(FPDF_PAGE page) {
139 if (m_pInfo && m_pInfo->FFI_GetRotation)
140 return m_pInfo->FFI_GetRotation(m_pInfo, page);
141 return 0;
142 }
Tom Sepez0d3b5cc2014-07-30 13:03:52 -0700143
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700144 void FFI_ExecuteNamedAction(const FX_CHAR* namedAction) {
145 if (m_pInfo && m_pInfo->FFI_ExecuteNamedAction)
146 m_pInfo->FFI_ExecuteNamedAction(m_pInfo, namedAction);
147 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700148
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700149 void FFI_OnSetFieldInputFocus(void* field,
150 FPDF_WIDESTRING focusText,
151 FPDF_DWORD nTextLen,
152 FX_BOOL bFocus) {
153 if (m_pInfo && m_pInfo->FFI_SetTextFieldFocus)
154 m_pInfo->FFI_SetTextFieldFocus(m_pInfo, focusText, nTextLen, bFocus);
155 }
Tom Sepez0d3b5cc2014-07-30 13:03:52 -0700156
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700157 void FFI_DoURIAction(const FX_CHAR* bsURI) {
158 if (m_pInfo && m_pInfo->FFI_DoURIAction)
159 m_pInfo->FFI_DoURIAction(m_pInfo, bsURI);
160 }
Tom Sepez0d3b5cc2014-07-30 13:03:52 -0700161
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700162 void FFI_DoGoToAction(int nPageIndex,
163 int zoomMode,
164 float* fPosArray,
165 int sizeOfArray) {
166 if (m_pInfo && m_pInfo->FFI_DoGoToAction)
167 m_pInfo->FFI_DoGoToAction(m_pInfo, nPageIndex, zoomMode, fPosArray,
168 sizeOfArray);
169 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700170
Tom Sepez51da0932015-11-25 16:05:49 -0800171#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700172 void FFI_DisplayCaret(FPDF_PAGE page,
173 FPDF_BOOL bVisible,
174 double left,
175 double top,
176 double right,
177 double bottom) {
178 if (m_pInfo && m_pInfo->FFI_DisplayCaret)
179 m_pInfo->FFI_DisplayCaret(m_pInfo, page, bVisible, left, top, right,
180 bottom);
181 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700182
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700183 int FFI_GetCurrentPageIndex(FPDF_DOCUMENT document) {
Jun Fang01fe5882015-11-25 11:05:58 +0800184 if (!m_pInfo || !m_pInfo->FFI_GetCurrentPageIndex) {
185 return -1;
186 }
187 return m_pInfo->FFI_GetCurrentPageIndex(m_pInfo, document);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700188 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700189
Jun Fang01fe5882015-11-25 11:05:58 +0800190 void FFI_SetCurrentPage(FPDF_DOCUMENT document, int iCurPage) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700191 if (m_pInfo && m_pInfo->FFI_SetCurrentPage)
192 m_pInfo->FFI_SetCurrentPage(m_pInfo, document, iCurPage);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700193 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700194
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700195 CFX_WideString FFI_GetAppName() const { return CFX_WideString(L"Acrobat"); }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700196
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700197 CFX_WideString FFI_GetPlatform() {
198 if (m_pInfo && m_pInfo->FFI_GetPlatform) {
199 int nRequiredLen = m_pInfo->FFI_GetPlatform(m_pInfo, NULL, 0);
200 if (nRequiredLen <= 0)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700201 return L"";
Bo Xufdc00a72014-10-28 23:03:33 -0700202
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700203 char* pbuff = new char[nRequiredLen];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700204 memset(pbuff, 0, nRequiredLen);
205 int nActualLen = m_pInfo->FFI_GetPlatform(m_pInfo, pbuff, nRequiredLen);
206 if (nActualLen <= 0 || nActualLen > nRequiredLen) {
207 delete[] pbuff;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700208 return L"";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700209 }
210 CFX_ByteString bsRet = CFX_ByteString(pbuff, nActualLen);
211 CFX_WideString wsRet = CFX_WideString::FromUTF16LE(
212 (unsigned short*)bsRet.GetBuffer(bsRet.GetLength()),
213 bsRet.GetLength() / sizeof(unsigned short));
214 delete[] pbuff;
215 return wsRet;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700216 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700217 return L"";
218 }
Bo Xufdc00a72014-10-28 23:03:33 -0700219
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700220 void FFI_GotoURL(FPDF_DOCUMENT document,
221 const CFX_WideStringC& wsURL,
222 FX_BOOL bAppend) {
223 if (m_pInfo && m_pInfo->FFI_GotoURL) {
224 CFX_ByteString bsTo = CFX_WideString(wsURL).UTF16LE_Encode();
225 FPDF_WIDESTRING pTo = (FPDF_WIDESTRING)bsTo.GetBuffer(wsURL.GetLength());
226 m_pInfo->FFI_GotoURL(m_pInfo, document, pTo);
227 bsTo.ReleaseBuffer();
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700228 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700229 }
Bo Xufdc00a72014-10-28 23:03:33 -0700230
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700231 void FFI_GetURL(FPDF_DOCUMENT document, CFX_WideString& wsURL) {
232 wsURL = CFX_WideString();
233 }
234
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700235 void FFI_GetPageViewRect(FPDF_PAGE page, FS_RECTF& dstRect) {
236 if (m_pInfo && m_pInfo->FFI_GetPageViewRect) {
237 double left;
238 double top;
239 double right;
240 double bottom;
241 m_pInfo->FFI_GetPageViewRect(m_pInfo, page, &left, &top, &right, &bottom);
242
243 dstRect.left = static_cast<float>(left);
244 dstRect.top = static_cast<float>(top < bottom ? bottom : top);
245 dstRect.bottom = static_cast<float>(top < bottom ? top : bottom);
246 dstRect.right = static_cast<float>(right);
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700247 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700248 }
Bo Xufdc00a72014-10-28 23:03:33 -0700249
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700250 FX_BOOL FFI_PopupMenu(FPDF_PAGE page,
251 FPDF_WIDGET hWidget,
252 int menuFlag,
253 CFX_PointF ptPopup,
254 const CFX_PointF* pRectExclude) {
255 if (m_pInfo && m_pInfo->FFI_PopupMenu)
256 return m_pInfo->FFI_PopupMenu(m_pInfo, page, hWidget, menuFlag, ptPopup.x,
257 ptPopup.y);
258 return FALSE;
259 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700260
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700261 void FFI_Alert(FPDF_WIDESTRING Msg,
262 FPDF_WIDESTRING Title,
263 int Type,
264 int Icon) {
265 if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_alert)
266 m_pInfo->m_pJsPlatform->app_alert(m_pInfo->m_pJsPlatform, Msg, Title,
267 Type, Icon);
268 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700269
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700270 void FFI_EmailTo(FPDF_FILEHANDLER* fileHandler,
271 FPDF_WIDESTRING pTo,
272 FPDF_WIDESTRING pSubject,
273 FPDF_WIDESTRING pCC,
274 FPDF_WIDESTRING pBcc,
275 FPDF_WIDESTRING pMsg) {
276 if (m_pInfo && m_pInfo->FFI_EmailTo)
277 m_pInfo->FFI_EmailTo(m_pInfo, fileHandler, pTo, pSubject, pCC, pBcc,
278 pMsg);
279 }
280
281 void FFI_UploadTo(FPDF_FILEHANDLER* fileHandler,
282 int fileFlag,
283 FPDF_WIDESTRING uploadTo) {
284 if (m_pInfo && m_pInfo->FFI_UploadTo)
285 m_pInfo->FFI_UploadTo(m_pInfo, fileHandler, fileFlag, uploadTo);
286 }
287
288 FPDF_FILEHANDLER* FFI_OpenFile(int fileType,
289 FPDF_WIDESTRING wsURL,
290 const char* mode) {
291 if (m_pInfo && m_pInfo->FFI_OpenFile)
292 return m_pInfo->FFI_OpenFile(m_pInfo, fileType, wsURL, mode);
293 return NULL;
294 }
295
296 CFX_WideString FFI_GetFilePath(FPDF_FILEHANDLER* pFileHandler) const {
297 return L"";
298 }
299
300 int FFI_GetDocumentCount() const { return 0; }
301 int FFI_GetCurDocument() const { return 0; }
302
303 IFX_FileRead* FFI_DownloadFromURL(const FX_WCHAR* url) {
304 if (m_pInfo && m_pInfo->FFI_DownloadFromURL) {
305 CFX_ByteString bstrURL = CFX_WideString(url).UTF16LE_Encode();
306 FPDF_WIDESTRING wsURL =
307 (FPDF_WIDESTRING)bstrURL.GetBuffer(bstrURL.GetLength());
308
309 FPDF_LPFILEHANDLER fileHandler =
310 m_pInfo->FFI_DownloadFromURL(m_pInfo, wsURL);
311
Lei Zhangdb5256f2015-10-02 10:11:43 -0700312 return new CFPDF_FileStream(fileHandler);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700313 }
314 return NULL;
315 }
316
317 CFX_WideString FFI_PostRequestURL(const FX_WCHAR* wsURL,
318 const FX_WCHAR* wsData,
319 const FX_WCHAR* wsContentType,
320 const FX_WCHAR* wsEncode,
321 const FX_WCHAR* wsHeader) {
322 if (m_pInfo && m_pInfo->FFI_PostRequestURL) {
323 CFX_ByteString bsURL = CFX_WideString(wsURL).UTF16LE_Encode();
324 FPDF_WIDESTRING URL = (FPDF_WIDESTRING)bsURL.GetBuffer(bsURL.GetLength());
325
326 CFX_ByteString bsData = CFX_WideString(wsData).UTF16LE_Encode();
327 FPDF_WIDESTRING data =
328 (FPDF_WIDESTRING)bsData.GetBuffer(bsData.GetLength());
329
330 CFX_ByteString bsContentType =
331 CFX_WideString(wsContentType).UTF16LE_Encode();
332 FPDF_WIDESTRING contentType =
333 (FPDF_WIDESTRING)bsContentType.GetBuffer(bsContentType.GetLength());
334
335 CFX_ByteString bsEncode = CFX_WideString(wsEncode).UTF16LE_Encode();
336 FPDF_WIDESTRING encode =
337 (FPDF_WIDESTRING)bsEncode.GetBuffer(bsEncode.GetLength());
338
339 CFX_ByteString bsHeader = CFX_WideString(wsHeader).UTF16LE_Encode();
340 FPDF_WIDESTRING header =
341 (FPDF_WIDESTRING)bsHeader.GetBuffer(bsHeader.GetLength());
342
343 FPDF_BSTR respone;
344 FPDF_BStr_Init(&respone);
345 m_pInfo->FFI_PostRequestURL(m_pInfo, URL, data, contentType, encode,
346 header, &respone);
347
348 CFX_WideString wsRet = CFX_WideString::FromUTF16LE(
349 (unsigned short*)respone.str, respone.len / sizeof(unsigned short));
350 FPDF_BStr_Clear(&respone);
351
352 return wsRet;
353 }
354 return L"";
355 }
356
357 FPDF_BOOL FFI_PutRequestURL(const FX_WCHAR* wsURL,
358 const FX_WCHAR* wsData,
359 const FX_WCHAR* wsEncode) {
360 if (m_pInfo && m_pInfo->FFI_PutRequestURL) {
361 CFX_ByteString bsURL = CFX_WideString(wsURL).UTF16LE_Encode();
362 FPDF_WIDESTRING URL = (FPDF_WIDESTRING)bsURL.GetBuffer(bsURL.GetLength());
363
364 CFX_ByteString bsData = CFX_WideString(wsData).UTF16LE_Encode();
365 FPDF_WIDESTRING data =
366 (FPDF_WIDESTRING)bsData.GetBuffer(bsData.GetLength());
367
368 CFX_ByteString bsEncode = CFX_WideString(wsEncode).UTF16LE_Encode();
369 FPDF_WIDESTRING encode =
370 (FPDF_WIDESTRING)bsEncode.GetBuffer(bsEncode.GetLength());
371
372 return m_pInfo->FFI_PutRequestURL(m_pInfo, URL, data, encode);
373 }
374 return FALSE;
375 }
376
377 FPDF_BOOL FFI_ShowFileDialog(const FX_WCHAR* wsTitle,
378 const FX_WCHAR* wsFilter,
Tom Sepezab277682016-02-17 10:07:21 -0800379 std::vector<CFX_WideString>& wsPathArr,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700380 FX_BOOL bOpen) {
381 return FALSE;
382 }
383
384 CFX_WideString FFI_GetLanguage() {
385 if (m_pInfo && m_pInfo->FFI_GetLanguage) {
386 int nRequiredLen = m_pInfo->FFI_GetLanguage(m_pInfo, NULL, 0);
387 if (nRequiredLen <= 0)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700388 return L"";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700389
390 char* pbuff = new char[nRequiredLen];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700391 memset(pbuff, 0, nRequiredLen);
392 int nActualLen = m_pInfo->FFI_GetLanguage(m_pInfo, pbuff, nRequiredLen);
393 if (nActualLen <= 0 || nActualLen > nRequiredLen) {
394 delete[] pbuff;
395 return L"";
396 }
397 CFX_ByteString bsRet = CFX_ByteString(pbuff, nActualLen);
398 CFX_WideString wsRet = CFX_WideString::FromUTF16LE(
399 (unsigned short*)bsRet.GetBuffer(bsRet.GetLength()),
400 bsRet.GetLength() / sizeof(unsigned short));
401 delete[] pbuff;
402 return wsRet;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700403 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700404 return L"";
405 }
Lei Zhang84e5a122016-02-19 14:25:10 -0800406
407 void FFI_PageEvent(int iPageIndex, FX_DWORD dwEventType) const {
408 if (m_pInfo && m_pInfo->FFI_PageEvent)
409 m_pInfo->FFI_PageEvent(m_pInfo, iPageIndex, dwEventType);
Jun Fangc30d5bf2016-02-02 18:12:23 -0800410 }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800411#endif // PDF_ENABLE_XFA
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700412
Tom Sepez57028592016-02-01 15:49:11 -0800413 int JS_appAlert(const FX_WCHAR* Msg,
414 const FX_WCHAR* Title,
415 FX_UINT Type,
416 FX_UINT Icon);
417 int JS_appResponse(const FX_WCHAR* Question,
418 const FX_WCHAR* Title,
419 const FX_WCHAR* Default,
420 const FX_WCHAR* cLabel,
421 FPDF_BOOL bPassword,
422 void* response,
423 int length);
424 void JS_appBeep(int nType);
425 CFX_WideString JS_fieldBrowse();
426 CFX_WideString JS_docGetFilePath();
427 void JS_docSubmitForm(void* formData, int length, const FX_WCHAR* URL);
428 void JS_docmailForm(void* mailData,
429 int length,
430 FPDF_BOOL bUI,
431 const FX_WCHAR* To,
432 const FX_WCHAR* Subject,
433 const FX_WCHAR* CC,
434 const FX_WCHAR* BCC,
435 const FX_WCHAR* Msg);
436 void JS_docprint(FPDF_BOOL bUI,
437 int nStart,
438 int nEnd,
439 FPDF_BOOL bSilent,
440 FPDF_BOOL bShrinkToFit,
441 FPDF_BOOL bPrintAsImage,
442 FPDF_BOOL bReverse,
443 FPDF_BOOL bAnnotations);
444 void JS_docgotoPage(int nPageNum);
445
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700446 FX_BOOL IsJSInitiated() const { return m_pInfo && m_pInfo->m_pJsPlatform; }
447 void SetSDKDocument(CPDFSDK_Document* pFXDoc) { m_pSDKDoc = pFXDoc; }
448 CPDFSDK_Document* GetSDKDocument() const { return m_pSDKDoc; }
Tom Sepez50d12ad2015-11-24 09:50:51 -0800449 UnderlyingDocumentType* GetUnderlyingDocument() const {
450 return m_pUnderlyingDoc;
451 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700452 CFX_ByteString GetAppName() const { return ""; }
Oliver Chang24752492015-10-30 16:08:20 -0700453 IFX_SystemHandler* GetSysHandler() const { return m_pSysHandler.get(); }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700454 FPDF_FORMFILLINFO* GetFormFillInfo() const { return m_pInfo; }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700455
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700456 CFFL_IFormFiller* GetIFormFiller(); // Creates if not present.
457 CPDFSDK_AnnotHandlerMgr* GetAnnotHandlerMgr(); // Creates if not present.
Tom Sepezba038bc2015-10-08 12:03:00 -0700458 IJS_Runtime* GetJSRuntime(); // Creates if not present.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700459 CPDFSDK_ActionHandler* GetActionHander(); // Creates if not present.
Tom Sepez2f3dfef2015-03-02 15:35:26 -0800460
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700461 private:
Lei Zhangaa8bf7e2015-12-24 19:13:32 -0800462 std::unique_ptr<CPDFSDK_AnnotHandlerMgr> m_pAnnotHandlerMgr;
463 std::unique_ptr<CPDFSDK_ActionHandler> m_pActionHandler;
464 std::unique_ptr<IJS_Runtime> m_pJSRuntime;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700465 FPDF_FORMFILLINFO* const m_pInfo;
466 CPDFSDK_Document* m_pSDKDoc;
Tom Sepez50d12ad2015-11-24 09:50:51 -0800467 UnderlyingDocumentType* const m_pUnderlyingDoc;
Lei Zhangaa8bf7e2015-12-24 19:13:32 -0800468 std::unique_ptr<CFFL_IFormFiller> m_pIFormFiller;
469 std::unique_ptr<IFX_SystemHandler> m_pSysHandler;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700470};
471
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700472class CPDFSDK_Document {
473 public:
Tom Sepezfe351db2016-01-29 16:26:27 -0800474 static CPDFSDK_Document* FromFPDFFormHandle(FPDF_FORMHANDLE hHandle);
475
Tom Sepez50d12ad2015-11-24 09:50:51 -0800476 CPDFSDK_Document(UnderlyingDocumentType* pDoc, CPDFDoc_Environment* pEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700477 ~CPDFSDK_Document();
Tom Sepez2f3dfef2015-03-02 15:35:26 -0800478
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700479 CPDFSDK_InterForm* GetInterForm();
Tom Sepez50d12ad2015-11-24 09:50:51 -0800480
Tom Sepez5259ef32015-11-24 10:21:01 -0800481 // Gets the document object for the next layer down; for master this is
482 // a CPDF_Document, but for XFA it is a CPDFXFA_Document.
Tom Sepez50d12ad2015-11-24 09:50:51 -0800483 UnderlyingDocumentType* GetUnderlyingDocument() const {
Tom Sepez40e9ff32015-11-30 12:39:54 -0800484#ifdef PDF_ENABLE_XFA
Tom Sepez50d12ad2015-11-24 09:50:51 -0800485 return GetXFADocument();
Tom Sepez40e9ff32015-11-30 12:39:54 -0800486#else // PDF_ENABLE_XFA
487 return GetPDFDocument();
488#endif // PDF_ENABLE_XFA
Tom Sepez50d12ad2015-11-24 09:50:51 -0800489 }
Tom Sepez5259ef32015-11-24 10:21:01 -0800490
491 // Gets the CPDF_Document, either directly in master, or from the
492 // CPDFXFA_Document for XFA.
Tom Sepezbf59a072015-10-21 14:07:23 -0700493 CPDF_Document* GetPDFDocument() const {
Tom Sepez40e9ff32015-11-30 12:39:54 -0800494#ifdef PDF_ENABLE_XFA
Tom Sepezbf59a072015-10-21 14:07:23 -0700495 return m_pDoc ? m_pDoc->GetPDFDoc() : nullptr;
Tom Sepez40e9ff32015-11-30 12:39:54 -0800496#else // PDF_ENABLE_XFA
497 return m_pDoc;
498#endif // PDF_ENABLE_XFA
Tom Sepezbf59a072015-10-21 14:07:23 -0700499 }
Tom Sepez5259ef32015-11-24 10:21:01 -0800500
Tom Sepez40e9ff32015-11-30 12:39:54 -0800501#ifdef PDF_ENABLE_XFA
Tom Sepez5259ef32015-11-24 10:21:01 -0800502 // Gets the XFA document directly (XFA-only).
Tom Sepez50d12ad2015-11-24 09:50:51 -0800503 CPDFXFA_Document* GetXFADocument() const { return m_pDoc; }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700504
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700505 int GetPageViewCount() const { return m_pageMap.size(); }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800506#endif // PDF_ENABLE_XFA
507
Tom Sepez540c4362015-11-24 13:33:57 -0800508 CPDFSDK_PageView* GetPageView(UnderlyingPageType* pPage,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700509 FX_BOOL ReNew = TRUE);
510 CPDFSDK_PageView* GetPageView(int nIndex);
511 CPDFSDK_PageView* GetCurrentView();
Tom Sepez540c4362015-11-24 13:33:57 -0800512 void RemovePageView(UnderlyingPageType* pPage);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700513 void UpdateAllViews(CPDFSDK_PageView* pSender, CPDFSDK_Annot* pAnnot);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700514
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700515 CPDFSDK_Annot* GetFocusAnnot();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700516
Tom Sepezba038bc2015-10-08 12:03:00 -0700517 IJS_Runtime* GetJsRuntime();
Tom Sepezc6ab1722015-02-05 15:27:25 -0800518
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700519 FX_BOOL SetFocusAnnot(CPDFSDK_Annot* pAnnot, FX_UINT nFlag = 0);
520 FX_BOOL KillFocusAnnot(FX_UINT nFlag = 0);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700521
Tom Sepez11d93552016-02-09 09:55:54 -0800522 FX_BOOL ExtractPages(const std::vector<FX_WORD>& arrExtraPages,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700523 CPDF_Document* pDstDoc);
524 FX_BOOL InsertPages(int nInsertAt,
525 const CPDF_Document* pSrcDoc,
Tom Sepez11d93552016-02-09 09:55:54 -0800526 const std::vector<FX_WORD>& arrSrcPages);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700527 FX_BOOL ReplacePages(int nPage,
528 const CPDF_Document* pSrcDoc,
Tom Sepez11d93552016-02-09 09:55:54 -0800529 const std::vector<FX_WORD>& arrSrcPages);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700530
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700531 void OnCloseDocument();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700532
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700533 int GetPageCount() { return m_pDoc->GetPageCount(); }
534 FX_BOOL GetPermissions(int nFlag);
535 FX_BOOL GetChangeMark() { return m_bChangeMask; }
536 void SetChangeMark() { m_bChangeMask = TRUE; }
537 void ClearChangeMark() { m_bChangeMask = FALSE; }
538 CFX_WideString GetPath();
Tom Sepez540c4362015-11-24 13:33:57 -0800539 UnderlyingPageType* GetPage(int nIndex);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700540 CPDFDoc_Environment* GetEnv() { return m_pEnv; }
541 void ProcJavascriptFun();
542 FX_BOOL ProcOpenAction();
543 CPDF_OCContext* GetOCContext();
544
545 private:
Tom Sepez540c4362015-11-24 13:33:57 -0800546 std::map<UnderlyingPageType*, CPDFSDK_PageView*> m_pageMap;
Tom Sepez50d12ad2015-11-24 09:50:51 -0800547 UnderlyingDocumentType* m_pDoc;
Lei Zhangaa8bf7e2015-12-24 19:13:32 -0800548 std::unique_ptr<CPDFSDK_InterForm> m_pInterForm;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700549 CPDFSDK_Annot* m_pFocusAnnot;
550 CPDFDoc_Environment* m_pEnv;
Lei Zhangaa8bf7e2015-12-24 19:13:32 -0800551 std::unique_ptr<CPDF_OCContext> m_pOccontent;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700552 FX_BOOL m_bChangeMask;
Oliver Chang972b78d2015-10-30 12:59:29 -0700553 FX_BOOL m_bBeingDestroyed;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700554};
Tom Sepezb9cc7a02016-02-01 13:42:30 -0800555
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700556class CPDFSDK_PageView final {
557 public:
Tom Sepez540c4362015-11-24 13:33:57 -0800558 CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc, UnderlyingPageType* page);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700559 ~CPDFSDK_PageView();
Tom Sepez40e9ff32015-11-30 12:39:54 -0800560
561#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700562 void PageView_OnDraw(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800563 CFX_Matrix* pUser2Device,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700564 CPDF_RenderOptions* pOptions,
Lei Zhangf0e2e1b2015-11-02 13:27:54 -0800565 const FX_RECT& pClip);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800566#else // PDF_ENABLE_XFA
567 void PageView_OnDraw(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800568 CFX_Matrix* pUser2Device,
Tom Sepez40e9ff32015-11-30 12:39:54 -0800569 CPDF_RenderOptions* pOptions);
570#endif // PDF_ENABLE_XFA
571
Lei Zhang1b700c32015-10-30 23:55:35 -0700572 const CPDF_Annot* GetPDFAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700573 CPDFSDK_Annot* GetFXAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
Lei Zhang1b700c32015-10-30 23:55:35 -0700574 const CPDF_Annot* GetPDFWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700575 CPDFSDK_Annot* GetFXWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
576 CPDFSDK_Annot* GetFocusAnnot();
577 void SetFocusAnnot(CPDFSDK_Annot* pSDKAnnot, FX_UINT nFlag = 0) {
578 m_pSDKDoc->SetFocusAnnot(pSDKAnnot, nFlag);
579 }
580 FX_BOOL KillFocusAnnot(FX_UINT nFlag = 0) {
581 return m_pSDKDoc->KillFocusAnnot(nFlag);
582 }
Oliver Chang972b78d2015-10-30 12:59:29 -0700583 void KillFocusAnnotIfNeeded();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700584 FX_BOOL Annot_HasAppearance(CPDF_Annot* pAnnot);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700585
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700586 CPDFSDK_Annot* AddAnnot(CPDF_Dictionary* pDict);
587 CPDFSDK_Annot* AddAnnot(const FX_CHAR* lpSubType, CPDF_Dictionary* pDict);
588 CPDFSDK_Annot* AddAnnot(CPDF_Annot* pPDFAnnot);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800589
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700590 FX_BOOL DeleteAnnot(CPDFSDK_Annot* pAnnot);
Lei Zhang50218532015-10-30 14:03:43 -0700591 size_t CountAnnots() const;
Lei Zhangbf60b292015-10-26 12:14:35 -0700592 CPDFSDK_Annot* GetAnnot(size_t nIndex);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700593 CPDFSDK_Annot* GetAnnotByDict(CPDF_Dictionary* pDict);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800594
595#ifdef PDF_ENABLE_XFA
596 CPDFSDK_Annot* AddAnnot(IXFA_Widget* pPDFAnnot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700597 CPDFSDK_Annot* GetAnnotByXFAWidget(IXFA_Widget* hWidget);
598 CPDFXFA_Page* GetPDFXFAPage() { return m_page; }
599 CPDF_Page* GetPDFPage();
Tom Sepez40e9ff32015-11-30 12:39:54 -0800600#else
601 CPDF_Page* GetPDFPage() { return m_page; }
602#endif // PDF_ENABLE_XFA
603
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700604 CPDF_Document* GetPDFDocument();
605 CPDFSDK_Document* GetSDKDocument() { return m_pSDKDoc; }
Tom Sepez281a9ea2016-02-26 14:24:28 -0800606 FX_BOOL OnLButtonDown(const CFX_FloatPoint& point, FX_UINT nFlag);
607 FX_BOOL OnLButtonUp(const CFX_FloatPoint& point, FX_UINT nFlag);
Tom Sepez51da0932015-11-25 16:05:49 -0800608#ifdef PDF_ENABLE_XFA
Tom Sepez281a9ea2016-02-26 14:24:28 -0800609 FX_BOOL OnRButtonDown(const CFX_FloatPoint& point, FX_UINT nFlag);
610 FX_BOOL OnRButtonUp(const CFX_FloatPoint& point, FX_UINT nFlag);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800611#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700612 FX_BOOL OnChar(int nChar, FX_UINT nFlag);
613 FX_BOOL OnKeyDown(int nKeyCode, int nFlag);
614 FX_BOOL OnKeyUp(int nKeyCode, int nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700615
Tom Sepez281a9ea2016-02-26 14:24:28 -0800616 FX_BOOL OnMouseMove(const CFX_FloatPoint& point, int nFlag);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700617 FX_BOOL OnMouseWheel(double deltaX,
618 double deltaY,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800619 const CFX_FloatPoint& point,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700620 int nFlag);
Lei Zhang1b700c32015-10-30 23:55:35 -0700621 bool IsValidAnnot(const CPDF_Annot* p) const;
Tom Sepez60d909e2015-12-10 15:34:55 -0800622 void GetCurrentMatrix(CFX_Matrix& matrix) { matrix = m_curMatrix; }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700623 void UpdateRects(CFX_RectArray& rects);
624 void UpdateView(CPDFSDK_Annot* pAnnot);
Lei Zhangbf60b292015-10-26 12:14:35 -0700625 const std::vector<CPDFSDK_Annot*>& GetAnnotList() const {
626 return m_fxAnnotArray;
627 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700628
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700629 int GetPageIndex();
630 void LoadFXAnnots();
Jun Fang75239542016-01-20 08:04:47 +0800631 void ClearFXAnnots();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700632 void SetValid(FX_BOOL bValid) { m_bValid = bValid; }
633 FX_BOOL IsValid() { return m_bValid; }
634 void SetLock(FX_BOOL bLocked) { m_bLocked = bLocked; }
635 FX_BOOL IsLocked() { return m_bLocked; }
Tom Sepez51da0932015-11-25 16:05:49 -0800636#ifndef PDF_ENABLE_XFA
637 void TakeOverPage() { m_bTakeOverPage = TRUE; }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800638#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700639
640 private:
641 void PageView_OnHighlightFormFields(CFX_RenderDevice* pDevice,
642 CPDFSDK_Widget* pWidget);
Lei Zhangbf60b292015-10-26 12:14:35 -0700643
Tom Sepez60d909e2015-12-10 15:34:55 -0800644 CFX_Matrix m_curMatrix;
Tom Sepez540c4362015-11-24 13:33:57 -0800645 UnderlyingPageType* m_page;
Lei Zhangaa8bf7e2015-12-24 19:13:32 -0800646 std::unique_ptr<CPDF_AnnotList> m_pAnnotList;
Lei Zhangbf60b292015-10-26 12:14:35 -0700647 std::vector<CPDFSDK_Annot*> m_fxAnnotArray;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700648 CPDFSDK_Document* m_pSDKDoc;
Tom Sepez40e9ff32015-11-30 12:39:54 -0800649#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700650 CPDFSDK_Annot* m_CaptureWidget;
Tom Sepez40e9ff32015-11-30 12:39:54 -0800651#else // PDF_ENABLE_XFA
652 CPDFSDK_Widget* m_CaptureWidget;
653 FX_BOOL m_bTakeOverPage;
654#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700655 FX_BOOL m_bEnterWidget;
656 FX_BOOL m_bExitWidget;
657 FX_BOOL m_bOnWidget;
658 FX_BOOL m_bValid;
659 FX_BOOL m_bLocked;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700660};
661
Tom Sepez19922bb2015-05-28 13:23:12 -0700662#endif // FPDFSDK_INCLUDE_FSDK_MGR_H_