blob: 5fdf6453065aaac9b1f65addac3c4653e9171c31 [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"
Lei Zhang8241df72015-11-06 14:38:48 -080015#include "fsdk_actionhandler.h"
16#include "fsdk_annothandler.h"
17#include "fsdk_baseannot.h"
18#include "fsdk_baseform.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070019#include "fsdk_common.h"
20#include "fsdk_define.h"
21#include "fx_systemhandler.h"
Lei Zhange5b0bd12015-06-19 17:15:41 -070022#include "javascript/IJavaScript.h"
Lei Zhangb4e7f302015-11-06 15:52:32 -080023#include "public/fpdf_formfill.h"
24#include "public/fpdf_fwlevent.h" // cross platform keycode and events define.
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_PageEvent(FPDF_PAGE page, FPDF_DWORD flag) {}
236
237 void FFI_GetPageViewRect(FPDF_PAGE page, FS_RECTF& dstRect) {
238 if (m_pInfo && m_pInfo->FFI_GetPageViewRect) {
239 double left;
240 double top;
241 double right;
242 double bottom;
243 m_pInfo->FFI_GetPageViewRect(m_pInfo, page, &left, &top, &right, &bottom);
244
245 dstRect.left = static_cast<float>(left);
246 dstRect.top = static_cast<float>(top < bottom ? bottom : top);
247 dstRect.bottom = static_cast<float>(top < bottom ? top : bottom);
248 dstRect.right = static_cast<float>(right);
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700249 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700250 }
Bo Xufdc00a72014-10-28 23:03:33 -0700251
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700252 FX_BOOL FFI_PopupMenu(FPDF_PAGE page,
253 FPDF_WIDGET hWidget,
254 int menuFlag,
255 CFX_PointF ptPopup,
256 const CFX_PointF* pRectExclude) {
257 if (m_pInfo && m_pInfo->FFI_PopupMenu)
258 return m_pInfo->FFI_PopupMenu(m_pInfo, page, hWidget, menuFlag, ptPopup.x,
259 ptPopup.y);
260 return FALSE;
261 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700262
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700263 void FFI_Alert(FPDF_WIDESTRING Msg,
264 FPDF_WIDESTRING Title,
265 int Type,
266 int Icon) {
267 if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_alert)
268 m_pInfo->m_pJsPlatform->app_alert(m_pInfo->m_pJsPlatform, Msg, Title,
269 Type, Icon);
270 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700271
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700272 void FFI_EmailTo(FPDF_FILEHANDLER* fileHandler,
273 FPDF_WIDESTRING pTo,
274 FPDF_WIDESTRING pSubject,
275 FPDF_WIDESTRING pCC,
276 FPDF_WIDESTRING pBcc,
277 FPDF_WIDESTRING pMsg) {
278 if (m_pInfo && m_pInfo->FFI_EmailTo)
279 m_pInfo->FFI_EmailTo(m_pInfo, fileHandler, pTo, pSubject, pCC, pBcc,
280 pMsg);
281 }
282
283 void FFI_UploadTo(FPDF_FILEHANDLER* fileHandler,
284 int fileFlag,
285 FPDF_WIDESTRING uploadTo) {
286 if (m_pInfo && m_pInfo->FFI_UploadTo)
287 m_pInfo->FFI_UploadTo(m_pInfo, fileHandler, fileFlag, uploadTo);
288 }
289
290 FPDF_FILEHANDLER* FFI_OpenFile(int fileType,
291 FPDF_WIDESTRING wsURL,
292 const char* mode) {
293 if (m_pInfo && m_pInfo->FFI_OpenFile)
294 return m_pInfo->FFI_OpenFile(m_pInfo, fileType, wsURL, mode);
295 return NULL;
296 }
297
298 CFX_WideString FFI_GetFilePath(FPDF_FILEHANDLER* pFileHandler) const {
299 return L"";
300 }
301
302 int FFI_GetDocumentCount() const { return 0; }
303 int FFI_GetCurDocument() const { return 0; }
304
305 IFX_FileRead* FFI_DownloadFromURL(const FX_WCHAR* url) {
306 if (m_pInfo && m_pInfo->FFI_DownloadFromURL) {
307 CFX_ByteString bstrURL = CFX_WideString(url).UTF16LE_Encode();
308 FPDF_WIDESTRING wsURL =
309 (FPDF_WIDESTRING)bstrURL.GetBuffer(bstrURL.GetLength());
310
311 FPDF_LPFILEHANDLER fileHandler =
312 m_pInfo->FFI_DownloadFromURL(m_pInfo, wsURL);
313
Lei Zhangdb5256f2015-10-02 10:11:43 -0700314 return new CFPDF_FileStream(fileHandler);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700315 }
316 return NULL;
317 }
318
319 CFX_WideString FFI_PostRequestURL(const FX_WCHAR* wsURL,
320 const FX_WCHAR* wsData,
321 const FX_WCHAR* wsContentType,
322 const FX_WCHAR* wsEncode,
323 const FX_WCHAR* wsHeader) {
324 if (m_pInfo && m_pInfo->FFI_PostRequestURL) {
325 CFX_ByteString bsURL = CFX_WideString(wsURL).UTF16LE_Encode();
326 FPDF_WIDESTRING URL = (FPDF_WIDESTRING)bsURL.GetBuffer(bsURL.GetLength());
327
328 CFX_ByteString bsData = CFX_WideString(wsData).UTF16LE_Encode();
329 FPDF_WIDESTRING data =
330 (FPDF_WIDESTRING)bsData.GetBuffer(bsData.GetLength());
331
332 CFX_ByteString bsContentType =
333 CFX_WideString(wsContentType).UTF16LE_Encode();
334 FPDF_WIDESTRING contentType =
335 (FPDF_WIDESTRING)bsContentType.GetBuffer(bsContentType.GetLength());
336
337 CFX_ByteString bsEncode = CFX_WideString(wsEncode).UTF16LE_Encode();
338 FPDF_WIDESTRING encode =
339 (FPDF_WIDESTRING)bsEncode.GetBuffer(bsEncode.GetLength());
340
341 CFX_ByteString bsHeader = CFX_WideString(wsHeader).UTF16LE_Encode();
342 FPDF_WIDESTRING header =
343 (FPDF_WIDESTRING)bsHeader.GetBuffer(bsHeader.GetLength());
344
345 FPDF_BSTR respone;
346 FPDF_BStr_Init(&respone);
347 m_pInfo->FFI_PostRequestURL(m_pInfo, URL, data, contentType, encode,
348 header, &respone);
349
350 CFX_WideString wsRet = CFX_WideString::FromUTF16LE(
351 (unsigned short*)respone.str, respone.len / sizeof(unsigned short));
352 FPDF_BStr_Clear(&respone);
353
354 return wsRet;
355 }
356 return L"";
357 }
358
359 FPDF_BOOL FFI_PutRequestURL(const FX_WCHAR* wsURL,
360 const FX_WCHAR* wsData,
361 const FX_WCHAR* wsEncode) {
362 if (m_pInfo && m_pInfo->FFI_PutRequestURL) {
363 CFX_ByteString bsURL = CFX_WideString(wsURL).UTF16LE_Encode();
364 FPDF_WIDESTRING URL = (FPDF_WIDESTRING)bsURL.GetBuffer(bsURL.GetLength());
365
366 CFX_ByteString bsData = CFX_WideString(wsData).UTF16LE_Encode();
367 FPDF_WIDESTRING data =
368 (FPDF_WIDESTRING)bsData.GetBuffer(bsData.GetLength());
369
370 CFX_ByteString bsEncode = CFX_WideString(wsEncode).UTF16LE_Encode();
371 FPDF_WIDESTRING encode =
372 (FPDF_WIDESTRING)bsEncode.GetBuffer(bsEncode.GetLength());
373
374 return m_pInfo->FFI_PutRequestURL(m_pInfo, URL, data, encode);
375 }
376 return FALSE;
377 }
378
379 FPDF_BOOL FFI_ShowFileDialog(const FX_WCHAR* wsTitle,
380 const FX_WCHAR* wsFilter,
Tom Sepezab277682016-02-17 10:07:21 -0800381 std::vector<CFX_WideString>& wsPathArr,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700382 FX_BOOL bOpen) {
383 return FALSE;
384 }
385
386 CFX_WideString FFI_GetLanguage() {
387 if (m_pInfo && m_pInfo->FFI_GetLanguage) {
388 int nRequiredLen = m_pInfo->FFI_GetLanguage(m_pInfo, NULL, 0);
389 if (nRequiredLen <= 0)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700390 return L"";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700391
392 char* pbuff = new char[nRequiredLen];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700393 memset(pbuff, 0, nRequiredLen);
394 int nActualLen = m_pInfo->FFI_GetLanguage(m_pInfo, pbuff, nRequiredLen);
395 if (nActualLen <= 0 || nActualLen > nRequiredLen) {
396 delete[] pbuff;
397 return L"";
398 }
399 CFX_ByteString bsRet = CFX_ByteString(pbuff, nActualLen);
400 CFX_WideString wsRet = CFX_WideString::FromUTF16LE(
401 (unsigned short*)bsRet.GetBuffer(bsRet.GetLength()),
402 bsRet.GetLength() / sizeof(unsigned short));
403 delete[] pbuff;
404 return wsRet;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700405 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700406 return L"";
407 }
Jun Fangc30d5bf2016-02-02 18:12:23 -0800408 void FFI_PageEvent(int iPageIndex, int iEventType) const {
409 // Todo: call a call-back function when it's implemented
410 // in applicaiton's side.
411 }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800412#endif // PDF_ENABLE_XFA
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700413
Tom Sepez57028592016-02-01 15:49:11 -0800414 int JS_appAlert(const FX_WCHAR* Msg,
415 const FX_WCHAR* Title,
416 FX_UINT Type,
417 FX_UINT Icon);
418 int JS_appResponse(const FX_WCHAR* Question,
419 const FX_WCHAR* Title,
420 const FX_WCHAR* Default,
421 const FX_WCHAR* cLabel,
422 FPDF_BOOL bPassword,
423 void* response,
424 int length);
425 void JS_appBeep(int nType);
426 CFX_WideString JS_fieldBrowse();
427 CFX_WideString JS_docGetFilePath();
428 void JS_docSubmitForm(void* formData, int length, const FX_WCHAR* URL);
429 void JS_docmailForm(void* mailData,
430 int length,
431 FPDF_BOOL bUI,
432 const FX_WCHAR* To,
433 const FX_WCHAR* Subject,
434 const FX_WCHAR* CC,
435 const FX_WCHAR* BCC,
436 const FX_WCHAR* Msg);
437 void JS_docprint(FPDF_BOOL bUI,
438 int nStart,
439 int nEnd,
440 FPDF_BOOL bSilent,
441 FPDF_BOOL bShrinkToFit,
442 FPDF_BOOL bPrintAsImage,
443 FPDF_BOOL bReverse,
444 FPDF_BOOL bAnnotations);
445 void JS_docgotoPage(int nPageNum);
446
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700447 FX_BOOL IsJSInitiated() const { return m_pInfo && m_pInfo->m_pJsPlatform; }
448 void SetSDKDocument(CPDFSDK_Document* pFXDoc) { m_pSDKDoc = pFXDoc; }
449 CPDFSDK_Document* GetSDKDocument() const { return m_pSDKDoc; }
Tom Sepez50d12ad2015-11-24 09:50:51 -0800450 UnderlyingDocumentType* GetUnderlyingDocument() const {
451 return m_pUnderlyingDoc;
452 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700453 CFX_ByteString GetAppName() const { return ""; }
Oliver Chang24752492015-10-30 16:08:20 -0700454 IFX_SystemHandler* GetSysHandler() const { return m_pSysHandler.get(); }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700455 FPDF_FORMFILLINFO* GetFormFillInfo() const { return m_pInfo; }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700456
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700457 CFFL_IFormFiller* GetIFormFiller(); // Creates if not present.
458 CPDFSDK_AnnotHandlerMgr* GetAnnotHandlerMgr(); // Creates if not present.
Tom Sepezba038bc2015-10-08 12:03:00 -0700459 IJS_Runtime* GetJSRuntime(); // Creates if not present.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700460 CPDFSDK_ActionHandler* GetActionHander(); // Creates if not present.
Tom Sepez2f3dfef2015-03-02 15:35:26 -0800461
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700462 private:
Lei Zhangaa8bf7e2015-12-24 19:13:32 -0800463 std::unique_ptr<CPDFSDK_AnnotHandlerMgr> m_pAnnotHandlerMgr;
464 std::unique_ptr<CPDFSDK_ActionHandler> m_pActionHandler;
465 std::unique_ptr<IJS_Runtime> m_pJSRuntime;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700466 FPDF_FORMFILLINFO* const m_pInfo;
467 CPDFSDK_Document* m_pSDKDoc;
Tom Sepez50d12ad2015-11-24 09:50:51 -0800468 UnderlyingDocumentType* const m_pUnderlyingDoc;
Lei Zhangaa8bf7e2015-12-24 19:13:32 -0800469 std::unique_ptr<CFFL_IFormFiller> m_pIFormFiller;
470 std::unique_ptr<IFX_SystemHandler> m_pSysHandler;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700471};
472
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700473class CPDFSDK_Document {
474 public:
Tom Sepezfe351db2016-01-29 16:26:27 -0800475 static CPDFSDK_Document* FromFPDFFormHandle(FPDF_FORMHANDLE hHandle);
476
Tom Sepez50d12ad2015-11-24 09:50:51 -0800477 CPDFSDK_Document(UnderlyingDocumentType* pDoc, CPDFDoc_Environment* pEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700478 ~CPDFSDK_Document();
Tom Sepez2f3dfef2015-03-02 15:35:26 -0800479
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700480 CPDFSDK_InterForm* GetInterForm();
Tom Sepez50d12ad2015-11-24 09:50:51 -0800481
Tom Sepez5259ef32015-11-24 10:21:01 -0800482 // Gets the document object for the next layer down; for master this is
483 // a CPDF_Document, but for XFA it is a CPDFXFA_Document.
Tom Sepez50d12ad2015-11-24 09:50:51 -0800484 UnderlyingDocumentType* GetUnderlyingDocument() const {
Tom Sepez40e9ff32015-11-30 12:39:54 -0800485#ifdef PDF_ENABLE_XFA
Tom Sepez50d12ad2015-11-24 09:50:51 -0800486 return GetXFADocument();
Tom Sepez40e9ff32015-11-30 12:39:54 -0800487#else // PDF_ENABLE_XFA
488 return GetPDFDocument();
489#endif // PDF_ENABLE_XFA
Tom Sepez50d12ad2015-11-24 09:50:51 -0800490 }
Tom Sepez5259ef32015-11-24 10:21:01 -0800491
492 // Gets the CPDF_Document, either directly in master, or from the
493 // CPDFXFA_Document for XFA.
Tom Sepezbf59a072015-10-21 14:07:23 -0700494 CPDF_Document* GetPDFDocument() const {
Tom Sepez40e9ff32015-11-30 12:39:54 -0800495#ifdef PDF_ENABLE_XFA
Tom Sepezbf59a072015-10-21 14:07:23 -0700496 return m_pDoc ? m_pDoc->GetPDFDoc() : nullptr;
Tom Sepez40e9ff32015-11-30 12:39:54 -0800497#else // PDF_ENABLE_XFA
498 return m_pDoc;
499#endif // PDF_ENABLE_XFA
Tom Sepezbf59a072015-10-21 14:07:23 -0700500 }
Tom Sepez5259ef32015-11-24 10:21:01 -0800501
Tom Sepez40e9ff32015-11-30 12:39:54 -0800502#ifdef PDF_ENABLE_XFA
Tom Sepez5259ef32015-11-24 10:21:01 -0800503 // Gets the XFA document directly (XFA-only).
Tom Sepez50d12ad2015-11-24 09:50:51 -0800504 CPDFXFA_Document* GetXFADocument() const { return m_pDoc; }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700505
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700506 int GetPageViewCount() const { return m_pageMap.size(); }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800507#endif // PDF_ENABLE_XFA
508
Tom Sepez540c4362015-11-24 13:33:57 -0800509 CPDFSDK_PageView* GetPageView(UnderlyingPageType* pPage,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700510 FX_BOOL ReNew = TRUE);
511 CPDFSDK_PageView* GetPageView(int nIndex);
512 CPDFSDK_PageView* GetCurrentView();
Tom Sepez540c4362015-11-24 13:33:57 -0800513 void RemovePageView(UnderlyingPageType* pPage);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700514 void UpdateAllViews(CPDFSDK_PageView* pSender, CPDFSDK_Annot* pAnnot);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700515
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700516 CPDFSDK_Annot* GetFocusAnnot();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700517
Tom Sepezba038bc2015-10-08 12:03:00 -0700518 IJS_Runtime* GetJsRuntime();
Tom Sepezc6ab1722015-02-05 15:27:25 -0800519
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700520 FX_BOOL SetFocusAnnot(CPDFSDK_Annot* pAnnot, FX_UINT nFlag = 0);
521 FX_BOOL KillFocusAnnot(FX_UINT nFlag = 0);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700522
Tom Sepez11d93552016-02-09 09:55:54 -0800523 FX_BOOL ExtractPages(const std::vector<FX_WORD>& arrExtraPages,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700524 CPDF_Document* pDstDoc);
525 FX_BOOL InsertPages(int nInsertAt,
526 const CPDF_Document* pSrcDoc,
Tom Sepez11d93552016-02-09 09:55:54 -0800527 const std::vector<FX_WORD>& arrSrcPages);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700528 FX_BOOL ReplacePages(int nPage,
529 const CPDF_Document* pSrcDoc,
Tom Sepez11d93552016-02-09 09:55:54 -0800530 const std::vector<FX_WORD>& arrSrcPages);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700531
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700532 void OnCloseDocument();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700533
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700534 int GetPageCount() { return m_pDoc->GetPageCount(); }
535 FX_BOOL GetPermissions(int nFlag);
536 FX_BOOL GetChangeMark() { return m_bChangeMask; }
537 void SetChangeMark() { m_bChangeMask = TRUE; }
538 void ClearChangeMark() { m_bChangeMask = FALSE; }
539 CFX_WideString GetPath();
Tom Sepez540c4362015-11-24 13:33:57 -0800540 UnderlyingPageType* GetPage(int nIndex);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700541 CPDFDoc_Environment* GetEnv() { return m_pEnv; }
542 void ProcJavascriptFun();
543 FX_BOOL ProcOpenAction();
544 CPDF_OCContext* GetOCContext();
545
546 private:
Tom Sepez540c4362015-11-24 13:33:57 -0800547 std::map<UnderlyingPageType*, CPDFSDK_PageView*> m_pageMap;
Tom Sepez50d12ad2015-11-24 09:50:51 -0800548 UnderlyingDocumentType* m_pDoc;
Lei Zhangaa8bf7e2015-12-24 19:13:32 -0800549 std::unique_ptr<CPDFSDK_InterForm> m_pInterForm;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700550 CPDFSDK_Annot* m_pFocusAnnot;
551 CPDFDoc_Environment* m_pEnv;
Lei Zhangaa8bf7e2015-12-24 19:13:32 -0800552 std::unique_ptr<CPDF_OCContext> m_pOccontent;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700553 FX_BOOL m_bChangeMask;
Oliver Chang972b78d2015-10-30 12:59:29 -0700554 FX_BOOL m_bBeingDestroyed;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700555};
Tom Sepezb9cc7a02016-02-01 13:42:30 -0800556
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700557class CPDFSDK_PageView final {
558 public:
Tom Sepez540c4362015-11-24 13:33:57 -0800559 CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc, UnderlyingPageType* page);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700560 ~CPDFSDK_PageView();
Tom Sepez40e9ff32015-11-30 12:39:54 -0800561
562#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700563 void PageView_OnDraw(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800564 CFX_Matrix* pUser2Device,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700565 CPDF_RenderOptions* pOptions,
Lei Zhangf0e2e1b2015-11-02 13:27:54 -0800566 const FX_RECT& pClip);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800567#else // PDF_ENABLE_XFA
568 void PageView_OnDraw(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800569 CFX_Matrix* pUser2Device,
Tom Sepez40e9ff32015-11-30 12:39:54 -0800570 CPDF_RenderOptions* pOptions);
571#endif // PDF_ENABLE_XFA
572
Lei Zhang1b700c32015-10-30 23:55:35 -0700573 const CPDF_Annot* GetPDFAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700574 CPDFSDK_Annot* GetFXAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
Lei Zhang1b700c32015-10-30 23:55:35 -0700575 const CPDF_Annot* GetPDFWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700576 CPDFSDK_Annot* GetFXWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
577 CPDFSDK_Annot* GetFocusAnnot();
578 void SetFocusAnnot(CPDFSDK_Annot* pSDKAnnot, FX_UINT nFlag = 0) {
579 m_pSDKDoc->SetFocusAnnot(pSDKAnnot, nFlag);
580 }
581 FX_BOOL KillFocusAnnot(FX_UINT nFlag = 0) {
582 return m_pSDKDoc->KillFocusAnnot(nFlag);
583 }
Oliver Chang972b78d2015-10-30 12:59:29 -0700584 void KillFocusAnnotIfNeeded();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700585 FX_BOOL Annot_HasAppearance(CPDF_Annot* pAnnot);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700586
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700587 CPDFSDK_Annot* AddAnnot(CPDF_Dictionary* pDict);
588 CPDFSDK_Annot* AddAnnot(const FX_CHAR* lpSubType, CPDF_Dictionary* pDict);
589 CPDFSDK_Annot* AddAnnot(CPDF_Annot* pPDFAnnot);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800590
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700591 FX_BOOL DeleteAnnot(CPDFSDK_Annot* pAnnot);
Lei Zhang50218532015-10-30 14:03:43 -0700592 size_t CountAnnots() const;
Lei Zhangbf60b292015-10-26 12:14:35 -0700593 CPDFSDK_Annot* GetAnnot(size_t nIndex);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700594 CPDFSDK_Annot* GetAnnotByDict(CPDF_Dictionary* pDict);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800595
596#ifdef PDF_ENABLE_XFA
597 CPDFSDK_Annot* AddAnnot(IXFA_Widget* pPDFAnnot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700598 CPDFSDK_Annot* GetAnnotByXFAWidget(IXFA_Widget* hWidget);
599 CPDFXFA_Page* GetPDFXFAPage() { return m_page; }
600 CPDF_Page* GetPDFPage();
Tom Sepez40e9ff32015-11-30 12:39:54 -0800601#else
602 CPDF_Page* GetPDFPage() { return m_page; }
603#endif // PDF_ENABLE_XFA
604
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700605 CPDF_Document* GetPDFDocument();
606 CPDFSDK_Document* GetSDKDocument() { return m_pSDKDoc; }
607 FX_BOOL OnLButtonDown(const CPDF_Point& point, FX_UINT nFlag);
608 FX_BOOL OnLButtonUp(const CPDF_Point& point, FX_UINT nFlag);
Tom Sepez51da0932015-11-25 16:05:49 -0800609#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700610 FX_BOOL OnRButtonDown(const CPDF_Point& point, FX_UINT nFlag);
611 FX_BOOL OnRButtonUp(const CPDF_Point& point, FX_UINT nFlag);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800612#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700613 FX_BOOL OnChar(int nChar, FX_UINT nFlag);
614 FX_BOOL OnKeyDown(int nKeyCode, int nFlag);
615 FX_BOOL OnKeyUp(int nKeyCode, int nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700616
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700617 FX_BOOL OnMouseMove(const CPDF_Point& point, int nFlag);
618 FX_BOOL OnMouseWheel(double deltaX,
619 double deltaY,
620 const CPDF_Point& point,
621 int nFlag);
Lei Zhang1b700c32015-10-30 23:55:35 -0700622 bool IsValidAnnot(const CPDF_Annot* p) const;
Tom Sepez60d909e2015-12-10 15:34:55 -0800623 void GetCurrentMatrix(CFX_Matrix& matrix) { matrix = m_curMatrix; }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700624 void UpdateRects(CFX_RectArray& rects);
625 void UpdateView(CPDFSDK_Annot* pAnnot);
Lei Zhangbf60b292015-10-26 12:14:35 -0700626 const std::vector<CPDFSDK_Annot*>& GetAnnotList() const {
627 return m_fxAnnotArray;
628 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700629
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700630 int GetPageIndex();
631 void LoadFXAnnots();
Jun Fang75239542016-01-20 08:04:47 +0800632 void ClearFXAnnots();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700633 void SetValid(FX_BOOL bValid) { m_bValid = bValid; }
634 FX_BOOL IsValid() { return m_bValid; }
635 void SetLock(FX_BOOL bLocked) { m_bLocked = bLocked; }
636 FX_BOOL IsLocked() { return m_bLocked; }
Tom Sepez51da0932015-11-25 16:05:49 -0800637#ifndef PDF_ENABLE_XFA
638 void TakeOverPage() { m_bTakeOverPage = TRUE; }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800639#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700640
641 private:
642 void PageView_OnHighlightFormFields(CFX_RenderDevice* pDevice,
643 CPDFSDK_Widget* pWidget);
Lei Zhangbf60b292015-10-26 12:14:35 -0700644
Tom Sepez60d909e2015-12-10 15:34:55 -0800645 CFX_Matrix m_curMatrix;
Tom Sepez540c4362015-11-24 13:33:57 -0800646 UnderlyingPageType* m_page;
Lei Zhangaa8bf7e2015-12-24 19:13:32 -0800647 std::unique_ptr<CPDF_AnnotList> m_pAnnotList;
Lei Zhangbf60b292015-10-26 12:14:35 -0700648 std::vector<CPDFSDK_Annot*> m_fxAnnotArray;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700649 CPDFSDK_Document* m_pSDKDoc;
Tom Sepez40e9ff32015-11-30 12:39:54 -0800650#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700651 CPDFSDK_Annot* m_CaptureWidget;
Tom Sepez40e9ff32015-11-30 12:39:54 -0800652#else // PDF_ENABLE_XFA
653 CPDFSDK_Widget* m_CaptureWidget;
654 FX_BOOL m_bTakeOverPage;
655#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700656 FX_BOOL m_bEnterWidget;
657 FX_BOOL m_bExitWidget;
658 FX_BOOL m_bOnWidget;
659 FX_BOOL m_bValid;
660 FX_BOOL m_bLocked;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700661};
662
Tom Sepez19922bb2015-05-28 13:23:12 -0700663#endif // FPDFSDK_INCLUDE_FSDK_MGR_H_