blob: 00733778937b810fb754e80615acdcf3aafa81a9 [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
Tom Sepez31775852016-03-08 13:25:54 -080014#include "core/include/fpdfapi/cpdf_document.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"
Dan Sinclairdf5a1162016-03-09 16:51:34 -050024#include "public/fpdf_fwlevent.h"
Tom Sepez40e9ff32015-11-30 12:39:54 -080025
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070026class CFFL_IFormFiller;
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;
32class IFX_SystemHandler;
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
Tom Sepez51da0932015-11-25 16:05:49 -080043#ifdef PDF_ENABLE_XFA
Tom Sepezdfbf8e72015-10-14 14:17:26 -070044 void Release() {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070045 if (m_pInfo && m_pInfo->Release)
46 m_pInfo->Release(m_pInfo);
47 delete this;
48 }
Tom Sepez40e9ff32015-11-30 12:39:54 -080049#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -070050
51 void FFI_Invalidate(FPDF_PAGE page,
52 double left,
53 double top,
54 double right,
55 double bottom) {
56 if (m_pInfo && m_pInfo->FFI_Invalidate)
57 m_pInfo->FFI_Invalidate(m_pInfo, page, left, top, right, bottom);
58 }
59
60 void FFI_OutputSelectedRect(FPDF_PAGE page,
61 double left,
62 double top,
63 double right,
64 double bottom) {
65 if (m_pInfo && m_pInfo->FFI_OutputSelectedRect)
66 m_pInfo->FFI_OutputSelectedRect(m_pInfo, page, left, top, right, bottom);
67 }
68
69 void FFI_SetCursor(int nCursorType) {
70 if (m_pInfo && m_pInfo->FFI_SetCursor)
71 m_pInfo->FFI_SetCursor(m_pInfo, nCursorType);
72 }
73
74 int FFI_SetTimer(int uElapse, TimerCallback lpTimerFunc) {
75 if (m_pInfo && m_pInfo->FFI_SetTimer)
76 return m_pInfo->FFI_SetTimer(m_pInfo, uElapse, lpTimerFunc);
77 return -1;
78 }
79
80 void FFI_KillTimer(int nTimerID) {
81 if (m_pInfo && m_pInfo->FFI_KillTimer)
82 m_pInfo->FFI_KillTimer(m_pInfo, nTimerID);
83 }
84
Tom Sepez468e5892015-10-13 15:49:36 -070085 FX_SYSTEMTIME FFI_GetLocalTime() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070086 FX_SYSTEMTIME fxtime;
87 if (m_pInfo && m_pInfo->FFI_GetLocalTime) {
88 FPDF_SYSTEMTIME systime = m_pInfo->FFI_GetLocalTime(m_pInfo);
89 fxtime.wDay = systime.wDay;
90 fxtime.wDayOfWeek = systime.wDayOfWeek;
91 fxtime.wHour = systime.wHour;
92 fxtime.wMilliseconds = systime.wMilliseconds;
93 fxtime.wMinute = systime.wMinute;
94 fxtime.wMonth = systime.wMonth;
95 fxtime.wSecond = systime.wSecond;
96 fxtime.wYear = systime.wYear;
Tom Sepezdcbc02f2015-07-17 09:16:17 -070097 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070098 return fxtime;
99 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700100
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700101 void FFI_OnChange() {
102 if (m_pInfo && m_pInfo->FFI_OnChange)
103 m_pInfo->FFI_OnChange(m_pInfo);
104 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700105
Tom Sepez468e5892015-10-13 15:49:36 -0700106 FX_BOOL FFI_IsSHIFTKeyDown(FX_DWORD nFlag) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700107 return (nFlag & FWL_EVENTFLAG_ShiftKey) != 0;
108 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700109
Tom Sepez468e5892015-10-13 15:49:36 -0700110 FX_BOOL FFI_IsCTRLKeyDown(FX_DWORD nFlag) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700111 return (nFlag & FWL_EVENTFLAG_ControlKey) != 0;
112 }
Tom Sepezc6ab1722015-02-05 15:27:25 -0800113
Tom Sepez468e5892015-10-13 15:49:36 -0700114 FX_BOOL FFI_IsALTKeyDown(FX_DWORD nFlag) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700115 return (nFlag & FWL_EVENTFLAG_AltKey) != 0;
116 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700117
Tom Sepez468e5892015-10-13 15:49:36 -0700118 FX_BOOL FFI_IsINSERTKeyDown(FX_DWORD nFlag) const { return FALSE; }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700119
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700120 FPDF_PAGE FFI_GetPage(FPDF_DOCUMENT document, int nPageIndex) {
121 if (m_pInfo && m_pInfo->FFI_GetPage)
122 return m_pInfo->FFI_GetPage(m_pInfo, document, nPageIndex);
123 return NULL;
124 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700125
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700126 FPDF_PAGE FFI_GetCurrentPage(FPDF_DOCUMENT document) {
127 if (m_pInfo && m_pInfo->FFI_GetCurrentPage)
128 return m_pInfo->FFI_GetCurrentPage(m_pInfo, document);
129 return NULL;
130 }
Tom Sepez0d3b5cc2014-07-30 13:03:52 -0700131
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700132 int FFI_GetRotation(FPDF_PAGE page) {
133 if (m_pInfo && m_pInfo->FFI_GetRotation)
134 return m_pInfo->FFI_GetRotation(m_pInfo, page);
135 return 0;
136 }
Tom Sepez0d3b5cc2014-07-30 13:03:52 -0700137
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700138 void FFI_ExecuteNamedAction(const FX_CHAR* namedAction) {
139 if (m_pInfo && m_pInfo->FFI_ExecuteNamedAction)
140 m_pInfo->FFI_ExecuteNamedAction(m_pInfo, namedAction);
141 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700142
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700143 void FFI_OnSetFieldInputFocus(void* field,
144 FPDF_WIDESTRING focusText,
145 FPDF_DWORD nTextLen,
146 FX_BOOL bFocus) {
147 if (m_pInfo && m_pInfo->FFI_SetTextFieldFocus)
148 m_pInfo->FFI_SetTextFieldFocus(m_pInfo, focusText, nTextLen, bFocus);
149 }
Tom Sepez0d3b5cc2014-07-30 13:03:52 -0700150
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700151 void FFI_DoURIAction(const FX_CHAR* bsURI) {
152 if (m_pInfo && m_pInfo->FFI_DoURIAction)
153 m_pInfo->FFI_DoURIAction(m_pInfo, bsURI);
154 }
Tom Sepez0d3b5cc2014-07-30 13:03:52 -0700155
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700156 void FFI_DoGoToAction(int nPageIndex,
157 int zoomMode,
158 float* fPosArray,
159 int sizeOfArray) {
160 if (m_pInfo && m_pInfo->FFI_DoGoToAction)
161 m_pInfo->FFI_DoGoToAction(m_pInfo, nPageIndex, zoomMode, fPosArray,
162 sizeOfArray);
163 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700164
Tom Sepez51da0932015-11-25 16:05:49 -0800165#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700166 void FFI_DisplayCaret(FPDF_PAGE page,
167 FPDF_BOOL bVisible,
168 double left,
169 double top,
170 double right,
171 double bottom) {
172 if (m_pInfo && m_pInfo->FFI_DisplayCaret)
173 m_pInfo->FFI_DisplayCaret(m_pInfo, page, bVisible, left, top, right,
174 bottom);
175 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700176
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700177 int FFI_GetCurrentPageIndex(FPDF_DOCUMENT document) {
Jun Fang01fe5882015-11-25 11:05:58 +0800178 if (!m_pInfo || !m_pInfo->FFI_GetCurrentPageIndex) {
179 return -1;
180 }
181 return m_pInfo->FFI_GetCurrentPageIndex(m_pInfo, document);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700182 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700183
Jun Fang01fe5882015-11-25 11:05:58 +0800184 void FFI_SetCurrentPage(FPDF_DOCUMENT document, int iCurPage) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700185 if (m_pInfo && m_pInfo->FFI_SetCurrentPage)
186 m_pInfo->FFI_SetCurrentPage(m_pInfo, document, iCurPage);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700187 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700188
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700189 CFX_WideString FFI_GetAppName() const { return CFX_WideString(L"Acrobat"); }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700190
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700191 CFX_WideString FFI_GetPlatform() {
192 if (m_pInfo && m_pInfo->FFI_GetPlatform) {
193 int nRequiredLen = m_pInfo->FFI_GetPlatform(m_pInfo, NULL, 0);
194 if (nRequiredLen <= 0)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700195 return L"";
Bo Xufdc00a72014-10-28 23:03:33 -0700196
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700197 char* pbuff = new char[nRequiredLen];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700198 memset(pbuff, 0, nRequiredLen);
199 int nActualLen = m_pInfo->FFI_GetPlatform(m_pInfo, pbuff, nRequiredLen);
200 if (nActualLen <= 0 || nActualLen > nRequiredLen) {
201 delete[] pbuff;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700202 return L"";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700203 }
204 CFX_ByteString bsRet = CFX_ByteString(pbuff, nActualLen);
205 CFX_WideString wsRet = CFX_WideString::FromUTF16LE(
206 (unsigned short*)bsRet.GetBuffer(bsRet.GetLength()),
207 bsRet.GetLength() / sizeof(unsigned short));
208 delete[] pbuff;
209 return wsRet;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700210 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700211 return L"";
212 }
Bo Xufdc00a72014-10-28 23:03:33 -0700213
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700214 void FFI_GotoURL(FPDF_DOCUMENT document,
215 const CFX_WideStringC& wsURL,
216 FX_BOOL bAppend) {
217 if (m_pInfo && m_pInfo->FFI_GotoURL) {
218 CFX_ByteString bsTo = CFX_WideString(wsURL).UTF16LE_Encode();
219 FPDF_WIDESTRING pTo = (FPDF_WIDESTRING)bsTo.GetBuffer(wsURL.GetLength());
220 m_pInfo->FFI_GotoURL(m_pInfo, document, pTo);
221 bsTo.ReleaseBuffer();
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700222 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700223 }
Bo Xufdc00a72014-10-28 23:03:33 -0700224
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700225 void FFI_GetURL(FPDF_DOCUMENT document, CFX_WideString& wsURL) {
226 wsURL = CFX_WideString();
227 }
228
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700229 void FFI_GetPageViewRect(FPDF_PAGE page, FS_RECTF& dstRect) {
230 if (m_pInfo && m_pInfo->FFI_GetPageViewRect) {
231 double left;
232 double top;
233 double right;
234 double bottom;
235 m_pInfo->FFI_GetPageViewRect(m_pInfo, page, &left, &top, &right, &bottom);
236
237 dstRect.left = static_cast<float>(left);
238 dstRect.top = static_cast<float>(top < bottom ? bottom : top);
239 dstRect.bottom = static_cast<float>(top < bottom ? top : bottom);
240 dstRect.right = static_cast<float>(right);
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700241 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700242 }
Bo Xufdc00a72014-10-28 23:03:33 -0700243
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700244 FX_BOOL FFI_PopupMenu(FPDF_PAGE page,
245 FPDF_WIDGET hWidget,
246 int menuFlag,
247 CFX_PointF ptPopup,
248 const CFX_PointF* pRectExclude) {
249 if (m_pInfo && m_pInfo->FFI_PopupMenu)
250 return m_pInfo->FFI_PopupMenu(m_pInfo, page, hWidget, menuFlag, ptPopup.x,
251 ptPopup.y);
252 return FALSE;
253 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700254
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700255 void FFI_Alert(FPDF_WIDESTRING Msg,
256 FPDF_WIDESTRING Title,
257 int Type,
258 int Icon) {
259 if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_alert)
260 m_pInfo->m_pJsPlatform->app_alert(m_pInfo->m_pJsPlatform, Msg, Title,
261 Type, Icon);
262 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700263
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700264 void FFI_EmailTo(FPDF_FILEHANDLER* fileHandler,
265 FPDF_WIDESTRING pTo,
266 FPDF_WIDESTRING pSubject,
267 FPDF_WIDESTRING pCC,
268 FPDF_WIDESTRING pBcc,
269 FPDF_WIDESTRING pMsg) {
270 if (m_pInfo && m_pInfo->FFI_EmailTo)
271 m_pInfo->FFI_EmailTo(m_pInfo, fileHandler, pTo, pSubject, pCC, pBcc,
272 pMsg);
273 }
274
275 void FFI_UploadTo(FPDF_FILEHANDLER* fileHandler,
276 int fileFlag,
277 FPDF_WIDESTRING uploadTo) {
278 if (m_pInfo && m_pInfo->FFI_UploadTo)
279 m_pInfo->FFI_UploadTo(m_pInfo, fileHandler, fileFlag, uploadTo);
280 }
281
282 FPDF_FILEHANDLER* FFI_OpenFile(int fileType,
283 FPDF_WIDESTRING wsURL,
284 const char* mode) {
285 if (m_pInfo && m_pInfo->FFI_OpenFile)
286 return m_pInfo->FFI_OpenFile(m_pInfo, fileType, wsURL, mode);
287 return NULL;
288 }
289
290 CFX_WideString FFI_GetFilePath(FPDF_FILEHANDLER* pFileHandler) const {
291 return L"";
292 }
293
294 int FFI_GetDocumentCount() const { return 0; }
295 int FFI_GetCurDocument() const { return 0; }
296
297 IFX_FileRead* FFI_DownloadFromURL(const FX_WCHAR* url) {
298 if (m_pInfo && m_pInfo->FFI_DownloadFromURL) {
299 CFX_ByteString bstrURL = CFX_WideString(url).UTF16LE_Encode();
300 FPDF_WIDESTRING wsURL =
301 (FPDF_WIDESTRING)bstrURL.GetBuffer(bstrURL.GetLength());
302
303 FPDF_LPFILEHANDLER fileHandler =
304 m_pInfo->FFI_DownloadFromURL(m_pInfo, wsURL);
305
Lei Zhangdb5256f2015-10-02 10:11:43 -0700306 return new CFPDF_FileStream(fileHandler);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700307 }
308 return NULL;
309 }
310
311 CFX_WideString FFI_PostRequestURL(const FX_WCHAR* wsURL,
312 const FX_WCHAR* wsData,
313 const FX_WCHAR* wsContentType,
314 const FX_WCHAR* wsEncode,
315 const FX_WCHAR* wsHeader) {
316 if (m_pInfo && m_pInfo->FFI_PostRequestURL) {
317 CFX_ByteString bsURL = CFX_WideString(wsURL).UTF16LE_Encode();
318 FPDF_WIDESTRING URL = (FPDF_WIDESTRING)bsURL.GetBuffer(bsURL.GetLength());
319
320 CFX_ByteString bsData = CFX_WideString(wsData).UTF16LE_Encode();
321 FPDF_WIDESTRING data =
322 (FPDF_WIDESTRING)bsData.GetBuffer(bsData.GetLength());
323
324 CFX_ByteString bsContentType =
325 CFX_WideString(wsContentType).UTF16LE_Encode();
326 FPDF_WIDESTRING contentType =
327 (FPDF_WIDESTRING)bsContentType.GetBuffer(bsContentType.GetLength());
328
329 CFX_ByteString bsEncode = CFX_WideString(wsEncode).UTF16LE_Encode();
330 FPDF_WIDESTRING encode =
331 (FPDF_WIDESTRING)bsEncode.GetBuffer(bsEncode.GetLength());
332
333 CFX_ByteString bsHeader = CFX_WideString(wsHeader).UTF16LE_Encode();
334 FPDF_WIDESTRING header =
335 (FPDF_WIDESTRING)bsHeader.GetBuffer(bsHeader.GetLength());
336
337 FPDF_BSTR respone;
338 FPDF_BStr_Init(&respone);
339 m_pInfo->FFI_PostRequestURL(m_pInfo, URL, data, contentType, encode,
340 header, &respone);
341
342 CFX_WideString wsRet = CFX_WideString::FromUTF16LE(
343 (unsigned short*)respone.str, respone.len / sizeof(unsigned short));
344 FPDF_BStr_Clear(&respone);
345
346 return wsRet;
347 }
348 return L"";
349 }
350
351 FPDF_BOOL FFI_PutRequestURL(const FX_WCHAR* wsURL,
352 const FX_WCHAR* wsData,
353 const FX_WCHAR* wsEncode) {
354 if (m_pInfo && m_pInfo->FFI_PutRequestURL) {
355 CFX_ByteString bsURL = CFX_WideString(wsURL).UTF16LE_Encode();
356 FPDF_WIDESTRING URL = (FPDF_WIDESTRING)bsURL.GetBuffer(bsURL.GetLength());
357
358 CFX_ByteString bsData = CFX_WideString(wsData).UTF16LE_Encode();
359 FPDF_WIDESTRING data =
360 (FPDF_WIDESTRING)bsData.GetBuffer(bsData.GetLength());
361
362 CFX_ByteString bsEncode = CFX_WideString(wsEncode).UTF16LE_Encode();
363 FPDF_WIDESTRING encode =
364 (FPDF_WIDESTRING)bsEncode.GetBuffer(bsEncode.GetLength());
365
366 return m_pInfo->FFI_PutRequestURL(m_pInfo, URL, data, encode);
367 }
368 return FALSE;
369 }
370
371 FPDF_BOOL FFI_ShowFileDialog(const FX_WCHAR* wsTitle,
372 const FX_WCHAR* wsFilter,
Tom Sepezab277682016-02-17 10:07:21 -0800373 std::vector<CFX_WideString>& wsPathArr,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700374 FX_BOOL bOpen) {
375 return FALSE;
376 }
377
378 CFX_WideString FFI_GetLanguage() {
379 if (m_pInfo && m_pInfo->FFI_GetLanguage) {
380 int nRequiredLen = m_pInfo->FFI_GetLanguage(m_pInfo, NULL, 0);
381 if (nRequiredLen <= 0)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700382 return L"";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700383
384 char* pbuff = new char[nRequiredLen];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700385 memset(pbuff, 0, nRequiredLen);
386 int nActualLen = m_pInfo->FFI_GetLanguage(m_pInfo, pbuff, nRequiredLen);
387 if (nActualLen <= 0 || nActualLen > nRequiredLen) {
388 delete[] pbuff;
389 return L"";
390 }
391 CFX_ByteString bsRet = CFX_ByteString(pbuff, nActualLen);
392 CFX_WideString wsRet = CFX_WideString::FromUTF16LE(
393 (unsigned short*)bsRet.GetBuffer(bsRet.GetLength()),
394 bsRet.GetLength() / sizeof(unsigned short));
395 delete[] pbuff;
396 return wsRet;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700397 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700398 return L"";
399 }
Lei Zhang84e5a122016-02-19 14:25:10 -0800400
401 void FFI_PageEvent(int iPageIndex, FX_DWORD dwEventType) const {
402 if (m_pInfo && m_pInfo->FFI_PageEvent)
403 m_pInfo->FFI_PageEvent(m_pInfo, iPageIndex, dwEventType);
Jun Fangc30d5bf2016-02-02 18:12:23 -0800404 }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800405#endif // PDF_ENABLE_XFA
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700406
Tom Sepez57028592016-02-01 15:49:11 -0800407 int JS_appAlert(const FX_WCHAR* Msg,
408 const FX_WCHAR* Title,
409 FX_UINT Type,
410 FX_UINT Icon);
411 int JS_appResponse(const FX_WCHAR* Question,
412 const FX_WCHAR* Title,
413 const FX_WCHAR* Default,
414 const FX_WCHAR* cLabel,
415 FPDF_BOOL bPassword,
416 void* response,
417 int length);
418 void JS_appBeep(int nType);
419 CFX_WideString JS_fieldBrowse();
420 CFX_WideString JS_docGetFilePath();
421 void JS_docSubmitForm(void* formData, int length, const FX_WCHAR* URL);
422 void JS_docmailForm(void* mailData,
423 int length,
424 FPDF_BOOL bUI,
425 const FX_WCHAR* To,
426 const FX_WCHAR* Subject,
427 const FX_WCHAR* CC,
428 const FX_WCHAR* BCC,
429 const FX_WCHAR* Msg);
430 void JS_docprint(FPDF_BOOL bUI,
431 int nStart,
432 int nEnd,
433 FPDF_BOOL bSilent,
434 FPDF_BOOL bShrinkToFit,
435 FPDF_BOOL bPrintAsImage,
436 FPDF_BOOL bReverse,
437 FPDF_BOOL bAnnotations);
438 void JS_docgotoPage(int nPageNum);
439
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700440 FX_BOOL IsJSInitiated() const { return m_pInfo && m_pInfo->m_pJsPlatform; }
441 void SetSDKDocument(CPDFSDK_Document* pFXDoc) { m_pSDKDoc = pFXDoc; }
442 CPDFSDK_Document* GetSDKDocument() const { return m_pSDKDoc; }
Tom Sepez50d12ad2015-11-24 09:50:51 -0800443 UnderlyingDocumentType* GetUnderlyingDocument() const {
444 return m_pUnderlyingDoc;
445 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700446 CFX_ByteString GetAppName() const { return ""; }
Oliver Chang24752492015-10-30 16:08:20 -0700447 IFX_SystemHandler* GetSysHandler() const { return m_pSysHandler.get(); }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700448 FPDF_FORMFILLINFO* GetFormFillInfo() const { return m_pInfo; }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700449
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700450 CFFL_IFormFiller* GetIFormFiller(); // Creates if not present.
451 CPDFSDK_AnnotHandlerMgr* GetAnnotHandlerMgr(); // Creates if not present.
Tom Sepezba038bc2015-10-08 12:03:00 -0700452 IJS_Runtime* GetJSRuntime(); // Creates if not present.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700453 CPDFSDK_ActionHandler* GetActionHander(); // Creates if not present.
Tom Sepez2f3dfef2015-03-02 15:35:26 -0800454
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700455 private:
Lei Zhangaa8bf7e2015-12-24 19:13:32 -0800456 std::unique_ptr<CPDFSDK_AnnotHandlerMgr> m_pAnnotHandlerMgr;
457 std::unique_ptr<CPDFSDK_ActionHandler> m_pActionHandler;
458 std::unique_ptr<IJS_Runtime> m_pJSRuntime;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700459 FPDF_FORMFILLINFO* const m_pInfo;
460 CPDFSDK_Document* m_pSDKDoc;
Tom Sepez50d12ad2015-11-24 09:50:51 -0800461 UnderlyingDocumentType* const m_pUnderlyingDoc;
Lei Zhangaa8bf7e2015-12-24 19:13:32 -0800462 std::unique_ptr<CFFL_IFormFiller> m_pIFormFiller;
463 std::unique_ptr<IFX_SystemHandler> m_pSysHandler;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700464};
465
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700466class CPDFSDK_Document {
467 public:
Tom Sepezfe351db2016-01-29 16:26:27 -0800468 static CPDFSDK_Document* FromFPDFFormHandle(FPDF_FORMHANDLE hHandle);
469
Tom Sepez50d12ad2015-11-24 09:50:51 -0800470 CPDFSDK_Document(UnderlyingDocumentType* pDoc, CPDFDoc_Environment* pEnv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700471 ~CPDFSDK_Document();
Tom Sepez2f3dfef2015-03-02 15:35:26 -0800472
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700473 CPDFSDK_InterForm* GetInterForm();
Tom Sepez50d12ad2015-11-24 09:50:51 -0800474
Tom Sepez5259ef32015-11-24 10:21:01 -0800475 // Gets the document object for the next layer down; for master this is
476 // a CPDF_Document, but for XFA it is a CPDFXFA_Document.
Tom Sepez50d12ad2015-11-24 09:50:51 -0800477 UnderlyingDocumentType* GetUnderlyingDocument() const {
Tom Sepez40e9ff32015-11-30 12:39:54 -0800478#ifdef PDF_ENABLE_XFA
Tom Sepez50d12ad2015-11-24 09:50:51 -0800479 return GetXFADocument();
Tom Sepez40e9ff32015-11-30 12:39:54 -0800480#else // PDF_ENABLE_XFA
481 return GetPDFDocument();
482#endif // PDF_ENABLE_XFA
Tom Sepez50d12ad2015-11-24 09:50:51 -0800483 }
Tom Sepez5259ef32015-11-24 10:21:01 -0800484
485 // Gets the CPDF_Document, either directly in master, or from the
486 // CPDFXFA_Document for XFA.
Tom Sepezbf59a072015-10-21 14:07:23 -0700487 CPDF_Document* GetPDFDocument() const {
Tom Sepez40e9ff32015-11-30 12:39:54 -0800488#ifdef PDF_ENABLE_XFA
Tom Sepezbf59a072015-10-21 14:07:23 -0700489 return m_pDoc ? m_pDoc->GetPDFDoc() : nullptr;
Tom Sepez40e9ff32015-11-30 12:39:54 -0800490#else // PDF_ENABLE_XFA
491 return m_pDoc;
492#endif // PDF_ENABLE_XFA
Tom Sepezbf59a072015-10-21 14:07:23 -0700493 }
Tom Sepez5259ef32015-11-24 10:21:01 -0800494
Tom Sepez40e9ff32015-11-30 12:39:54 -0800495#ifdef PDF_ENABLE_XFA
Tom Sepez5259ef32015-11-24 10:21:01 -0800496 // Gets the XFA document directly (XFA-only).
Tom Sepez50d12ad2015-11-24 09:50:51 -0800497 CPDFXFA_Document* GetXFADocument() const { return m_pDoc; }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700498
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700499 int GetPageViewCount() const { return m_pageMap.size(); }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800500#endif // PDF_ENABLE_XFA
501
Tom Sepez540c4362015-11-24 13:33:57 -0800502 CPDFSDK_PageView* GetPageView(UnderlyingPageType* pPage,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700503 FX_BOOL ReNew = TRUE);
504 CPDFSDK_PageView* GetPageView(int nIndex);
505 CPDFSDK_PageView* GetCurrentView();
Tom Sepez540c4362015-11-24 13:33:57 -0800506 void RemovePageView(UnderlyingPageType* pPage);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700507 void UpdateAllViews(CPDFSDK_PageView* pSender, CPDFSDK_Annot* pAnnot);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700508
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700509 CPDFSDK_Annot* GetFocusAnnot();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700510
Tom Sepezba038bc2015-10-08 12:03:00 -0700511 IJS_Runtime* GetJsRuntime();
Tom Sepezc6ab1722015-02-05 15:27:25 -0800512
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700513 FX_BOOL SetFocusAnnot(CPDFSDK_Annot* pAnnot, FX_UINT nFlag = 0);
514 FX_BOOL KillFocusAnnot(FX_UINT nFlag = 0);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700515
Tom Sepez11d93552016-02-09 09:55:54 -0800516 FX_BOOL ExtractPages(const std::vector<FX_WORD>& arrExtraPages,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700517 CPDF_Document* pDstDoc);
518 FX_BOOL InsertPages(int nInsertAt,
519 const CPDF_Document* pSrcDoc,
Tom Sepez11d93552016-02-09 09:55:54 -0800520 const std::vector<FX_WORD>& arrSrcPages);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700521 FX_BOOL ReplacePages(int nPage,
522 const CPDF_Document* pSrcDoc,
Tom Sepez11d93552016-02-09 09:55:54 -0800523 const std::vector<FX_WORD>& arrSrcPages);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700524
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700525 void OnCloseDocument();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700526
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700527 int GetPageCount() { return m_pDoc->GetPageCount(); }
528 FX_BOOL GetPermissions(int nFlag);
529 FX_BOOL GetChangeMark() { return m_bChangeMask; }
530 void SetChangeMark() { m_bChangeMask = TRUE; }
531 void ClearChangeMark() { m_bChangeMask = FALSE; }
532 CFX_WideString GetPath();
Tom Sepez540c4362015-11-24 13:33:57 -0800533 UnderlyingPageType* GetPage(int nIndex);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700534 CPDFDoc_Environment* GetEnv() { return m_pEnv; }
535 void ProcJavascriptFun();
536 FX_BOOL ProcOpenAction();
537 CPDF_OCContext* GetOCContext();
538
539 private:
Tom Sepez540c4362015-11-24 13:33:57 -0800540 std::map<UnderlyingPageType*, CPDFSDK_PageView*> m_pageMap;
Tom Sepez50d12ad2015-11-24 09:50:51 -0800541 UnderlyingDocumentType* m_pDoc;
Lei Zhangaa8bf7e2015-12-24 19:13:32 -0800542 std::unique_ptr<CPDFSDK_InterForm> m_pInterForm;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700543 CPDFSDK_Annot* m_pFocusAnnot;
544 CPDFDoc_Environment* m_pEnv;
Lei Zhangaa8bf7e2015-12-24 19:13:32 -0800545 std::unique_ptr<CPDF_OCContext> m_pOccontent;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700546 FX_BOOL m_bChangeMask;
Oliver Chang972b78d2015-10-30 12:59:29 -0700547 FX_BOOL m_bBeingDestroyed;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700548};
Tom Sepezb9cc7a02016-02-01 13:42:30 -0800549
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700550class CPDFSDK_PageView final {
551 public:
Tom Sepez540c4362015-11-24 13:33:57 -0800552 CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc, UnderlyingPageType* page);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700553 ~CPDFSDK_PageView();
Tom Sepez40e9ff32015-11-30 12:39:54 -0800554
555#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700556 void PageView_OnDraw(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800557 CFX_Matrix* pUser2Device,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700558 CPDF_RenderOptions* pOptions,
Lei Zhangf0e2e1b2015-11-02 13:27:54 -0800559 const FX_RECT& pClip);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800560#else // PDF_ENABLE_XFA
561 void PageView_OnDraw(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800562 CFX_Matrix* pUser2Device,
Tom Sepez40e9ff32015-11-30 12:39:54 -0800563 CPDF_RenderOptions* pOptions);
564#endif // PDF_ENABLE_XFA
565
Lei Zhang1b700c32015-10-30 23:55:35 -0700566 const CPDF_Annot* GetPDFAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700567 CPDFSDK_Annot* GetFXAnnotAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
Lei Zhang1b700c32015-10-30 23:55:35 -0700568 const CPDF_Annot* GetPDFWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700569 CPDFSDK_Annot* GetFXWidgetAtPoint(FX_FLOAT pageX, FX_FLOAT pageY);
570 CPDFSDK_Annot* GetFocusAnnot();
571 void SetFocusAnnot(CPDFSDK_Annot* pSDKAnnot, FX_UINT nFlag = 0) {
572 m_pSDKDoc->SetFocusAnnot(pSDKAnnot, nFlag);
573 }
574 FX_BOOL KillFocusAnnot(FX_UINT nFlag = 0) {
575 return m_pSDKDoc->KillFocusAnnot(nFlag);
576 }
Oliver Chang972b78d2015-10-30 12:59:29 -0700577 void KillFocusAnnotIfNeeded();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700578 FX_BOOL Annot_HasAppearance(CPDF_Annot* pAnnot);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700579
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700580 CPDFSDK_Annot* AddAnnot(CPDF_Dictionary* pDict);
581 CPDFSDK_Annot* AddAnnot(const FX_CHAR* lpSubType, CPDF_Dictionary* pDict);
582 CPDFSDK_Annot* AddAnnot(CPDF_Annot* pPDFAnnot);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800583
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700584 FX_BOOL DeleteAnnot(CPDFSDK_Annot* pAnnot);
Lei Zhang50218532015-10-30 14:03:43 -0700585 size_t CountAnnots() const;
Lei Zhangbf60b292015-10-26 12:14:35 -0700586 CPDFSDK_Annot* GetAnnot(size_t nIndex);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700587 CPDFSDK_Annot* GetAnnotByDict(CPDF_Dictionary* pDict);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800588
589#ifdef PDF_ENABLE_XFA
590 CPDFSDK_Annot* AddAnnot(IXFA_Widget* pPDFAnnot);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700591 CPDFSDK_Annot* GetAnnotByXFAWidget(IXFA_Widget* hWidget);
592 CPDFXFA_Page* GetPDFXFAPage() { return m_page; }
593 CPDF_Page* GetPDFPage();
Tom Sepez40e9ff32015-11-30 12:39:54 -0800594#else
595 CPDF_Page* GetPDFPage() { return m_page; }
596#endif // PDF_ENABLE_XFA
597
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700598 CPDF_Document* GetPDFDocument();
599 CPDFSDK_Document* GetSDKDocument() { return m_pSDKDoc; }
Tom Sepez281a9ea2016-02-26 14:24:28 -0800600 FX_BOOL OnLButtonDown(const CFX_FloatPoint& point, FX_UINT nFlag);
601 FX_BOOL OnLButtonUp(const CFX_FloatPoint& point, FX_UINT nFlag);
Tom Sepez51da0932015-11-25 16:05:49 -0800602#ifdef PDF_ENABLE_XFA
Tom Sepez281a9ea2016-02-26 14:24:28 -0800603 FX_BOOL OnRButtonDown(const CFX_FloatPoint& point, FX_UINT nFlag);
604 FX_BOOL OnRButtonUp(const CFX_FloatPoint& point, FX_UINT nFlag);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800605#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700606 FX_BOOL OnChar(int nChar, FX_UINT nFlag);
607 FX_BOOL OnKeyDown(int nKeyCode, int nFlag);
608 FX_BOOL OnKeyUp(int nKeyCode, int nFlag);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700609
Tom Sepez281a9ea2016-02-26 14:24:28 -0800610 FX_BOOL OnMouseMove(const CFX_FloatPoint& point, int nFlag);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700611 FX_BOOL OnMouseWheel(double deltaX,
612 double deltaY,
Tom Sepez281a9ea2016-02-26 14:24:28 -0800613 const CFX_FloatPoint& point,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700614 int nFlag);
Lei Zhang1b700c32015-10-30 23:55:35 -0700615 bool IsValidAnnot(const CPDF_Annot* p) const;
Tom Sepez60d909e2015-12-10 15:34:55 -0800616 void GetCurrentMatrix(CFX_Matrix& matrix) { matrix = m_curMatrix; }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700617 void UpdateRects(CFX_RectArray& rects);
618 void UpdateView(CPDFSDK_Annot* pAnnot);
Lei Zhangbf60b292015-10-26 12:14:35 -0700619 const std::vector<CPDFSDK_Annot*>& GetAnnotList() const {
620 return m_fxAnnotArray;
621 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700622
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700623 int GetPageIndex();
624 void LoadFXAnnots();
Jun Fang75239542016-01-20 08:04:47 +0800625 void ClearFXAnnots();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700626 void SetValid(FX_BOOL bValid) { m_bValid = bValid; }
627 FX_BOOL IsValid() { return m_bValid; }
628 void SetLock(FX_BOOL bLocked) { m_bLocked = bLocked; }
629 FX_BOOL IsLocked() { return m_bLocked; }
Tom Sepez51da0932015-11-25 16:05:49 -0800630#ifndef PDF_ENABLE_XFA
631 void TakeOverPage() { m_bTakeOverPage = TRUE; }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800632#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700633
634 private:
635 void PageView_OnHighlightFormFields(CFX_RenderDevice* pDevice,
636 CPDFSDK_Widget* pWidget);
Lei Zhangbf60b292015-10-26 12:14:35 -0700637
Tom Sepez60d909e2015-12-10 15:34:55 -0800638 CFX_Matrix m_curMatrix;
Tom Sepez540c4362015-11-24 13:33:57 -0800639 UnderlyingPageType* m_page;
Lei Zhangaa8bf7e2015-12-24 19:13:32 -0800640 std::unique_ptr<CPDF_AnnotList> m_pAnnotList;
Lei Zhangbf60b292015-10-26 12:14:35 -0700641 std::vector<CPDFSDK_Annot*> m_fxAnnotArray;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700642 CPDFSDK_Document* m_pSDKDoc;
Tom Sepez40e9ff32015-11-30 12:39:54 -0800643#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700644 CPDFSDK_Annot* m_CaptureWidget;
Tom Sepez40e9ff32015-11-30 12:39:54 -0800645#else // PDF_ENABLE_XFA
646 CPDFSDK_Widget* m_CaptureWidget;
647 FX_BOOL m_bTakeOverPage;
648#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700649 FX_BOOL m_bEnterWidget;
650 FX_BOOL m_bExitWidget;
651 FX_BOOL m_bOnWidget;
652 FX_BOOL m_bValid;
653 FX_BOOL m_bLocked;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700654};
655
Tom Sepez19922bb2015-05-28 13:23:12 -0700656#endif // FPDFSDK_INCLUDE_FSDK_MGR_H_