blob: 2df44c7ca1d8516acc4b316c7f5ac5422eaaa81f [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>
Lei Zhang606346f2015-06-19 18:11:07 -070012
Lei Zhanga688a042015-11-09 13:57:49 -080013#include "core/include/fpdftext/fpdf_text.h"
Lei Zhang8241df72015-11-06 14:38:48 -080014#include "fsdk_actionhandler.h"
15#include "fsdk_annothandler.h"
16#include "fsdk_baseannot.h"
17#include "fsdk_baseform.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070018#include "fsdk_common.h"
19#include "fsdk_define.h"
20#include "fx_systemhandler.h"
Lei Zhange5b0bd12015-06-19 17:15:41 -070021#include "javascript/IJavaScript.h"
Lei Zhangb4e7f302015-11-06 15:52:32 -080022#include "public/fpdf_formfill.h"
23#include "public/fpdf_fwlevent.h" // cross platform keycode and events define.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070024
Tom Sepez40e9ff32015-11-30 12:39:54 -080025#ifdef PDF_ENABLE_XFA
Lei Zhang875b9c92016-01-08 13:51:10 -080026#include "fpdfsdk/include/fpdfxfa/fpdfxfa_doc.h"
27#include "fpdfsdk/include/fpdfxfa/fpdfxfa_page.h"
Tom Sepez40e9ff32015-11-30 12:39:54 -080028#endif // PDF_ENABLE_XFA
29
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070030class CFFL_IFormFiller;
Tom Sepezdcbc02f2015-07-17 09:16:17 -070031class CPDFSDK_ActionHandler;
32class CPDFSDK_Annot;
33class CPDFSDK_Document;
34class CPDFSDK_InterForm;
35class CPDFSDK_PageView;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070036class CPDFSDK_Widget;
37class IFX_SystemHandler;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070038
Tom Sepez57028592016-02-01 15:49:11 -080039// NOTE: |bsUTF16LE| must outlive the use of the result. Care must be taken
40// since modifying the result would impact |bsUTF16LE|.
41FPDF_WIDESTRING AsFPDFWideString(CFX_ByteString* bsUTF16LE);
42
Nico Weber9d8ec5a2015-08-04 13:00:21 -070043class CPDFDoc_Environment final {
44 public:
Tom Sepez50d12ad2015-11-24 09:50:51 -080045 CPDFDoc_Environment(UnderlyingDocumentType* pDoc, FPDF_FORMFILLINFO* pFFinfo);
Tom Sepezdfbf8e72015-10-14 14:17:26 -070046 ~CPDFDoc_Environment();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070047
Tom Sepez51da0932015-11-25 16:05:49 -080048#ifdef PDF_ENABLE_XFA
Tom Sepezdfbf8e72015-10-14 14:17:26 -070049 void Release() {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070050 if (m_pInfo && m_pInfo->Release)
51 m_pInfo->Release(m_pInfo);
52 delete this;
53 }
Tom Sepez40e9ff32015-11-30 12:39:54 -080054#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -070055
56 void FFI_Invalidate(FPDF_PAGE page,
57 double left,
58 double top,
59 double right,
60 double bottom) {
61 if (m_pInfo && m_pInfo->FFI_Invalidate)
62 m_pInfo->FFI_Invalidate(m_pInfo, page, left, top, right, bottom);
63 }
64
65 void FFI_OutputSelectedRect(FPDF_PAGE page,
66 double left,
67 double top,
68 double right,
69 double bottom) {
70 if (m_pInfo && m_pInfo->FFI_OutputSelectedRect)
71 m_pInfo->FFI_OutputSelectedRect(m_pInfo, page, left, top, right, bottom);
72 }
73
74 void FFI_SetCursor(int nCursorType) {
75 if (m_pInfo && m_pInfo->FFI_SetCursor)
76 m_pInfo->FFI_SetCursor(m_pInfo, nCursorType);
77 }
78
79 int FFI_SetTimer(int uElapse, TimerCallback lpTimerFunc) {
80 if (m_pInfo && m_pInfo->FFI_SetTimer)
81 return m_pInfo->FFI_SetTimer(m_pInfo, uElapse, lpTimerFunc);
82 return -1;
83 }
84
85 void FFI_KillTimer(int nTimerID) {
86 if (m_pInfo && m_pInfo->FFI_KillTimer)
87 m_pInfo->FFI_KillTimer(m_pInfo, nTimerID);
88 }
89
Tom Sepez468e5892015-10-13 15:49:36 -070090 FX_SYSTEMTIME FFI_GetLocalTime() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070091 FX_SYSTEMTIME fxtime;
92 if (m_pInfo && m_pInfo->FFI_GetLocalTime) {
93 FPDF_SYSTEMTIME systime = m_pInfo->FFI_GetLocalTime(m_pInfo);
94 fxtime.wDay = systime.wDay;
95 fxtime.wDayOfWeek = systime.wDayOfWeek;
96 fxtime.wHour = systime.wHour;
97 fxtime.wMilliseconds = systime.wMilliseconds;
98 fxtime.wMinute = systime.wMinute;
99 fxtime.wMonth = systime.wMonth;
100 fxtime.wSecond = systime.wSecond;
101 fxtime.wYear = systime.wYear;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700102 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700103 return fxtime;
104 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700105
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700106 void FFI_OnChange() {
107 if (m_pInfo && m_pInfo->FFI_OnChange)
108 m_pInfo->FFI_OnChange(m_pInfo);
109 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700110
Tom Sepez468e5892015-10-13 15:49:36 -0700111 FX_BOOL FFI_IsSHIFTKeyDown(FX_DWORD nFlag) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700112 return (nFlag & FWL_EVENTFLAG_ShiftKey) != 0;
113 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700114
Tom Sepez468e5892015-10-13 15:49:36 -0700115 FX_BOOL FFI_IsCTRLKeyDown(FX_DWORD nFlag) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700116 return (nFlag & FWL_EVENTFLAG_ControlKey) != 0;
117 }
Tom Sepezc6ab1722015-02-05 15:27:25 -0800118
Tom Sepez468e5892015-10-13 15:49:36 -0700119 FX_BOOL FFI_IsALTKeyDown(FX_DWORD nFlag) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700120 return (nFlag & FWL_EVENTFLAG_AltKey) != 0;
121 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700122
Tom Sepez468e5892015-10-13 15:49:36 -0700123 FX_BOOL FFI_IsINSERTKeyDown(FX_DWORD nFlag) const { return FALSE; }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700124
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700125 FPDF_PAGE FFI_GetPage(FPDF_DOCUMENT document, int nPageIndex) {
126 if (m_pInfo && m_pInfo->FFI_GetPage)
127 return m_pInfo->FFI_GetPage(m_pInfo, document, nPageIndex);
128 return NULL;
129 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700130
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700131 FPDF_PAGE FFI_GetCurrentPage(FPDF_DOCUMENT document) {
132 if (m_pInfo && m_pInfo->FFI_GetCurrentPage)
133 return m_pInfo->FFI_GetCurrentPage(m_pInfo, document);
134 return NULL;
135 }
Tom Sepez0d3b5cc2014-07-30 13:03:52 -0700136
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700137 int FFI_GetRotation(FPDF_PAGE page) {
138 if (m_pInfo && m_pInfo->FFI_GetRotation)
139 return m_pInfo->FFI_GetRotation(m_pInfo, page);
140 return 0;
141 }
Tom Sepez0d3b5cc2014-07-30 13:03:52 -0700142
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700143 void FFI_ExecuteNamedAction(const FX_CHAR* namedAction) {
144 if (m_pInfo && m_pInfo->FFI_ExecuteNamedAction)
145 m_pInfo->FFI_ExecuteNamedAction(m_pInfo, namedAction);
146 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700147
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700148 void FFI_OnSetFieldInputFocus(void* field,
149 FPDF_WIDESTRING focusText,
150 FPDF_DWORD nTextLen,
151 FX_BOOL bFocus) {
152 if (m_pInfo && m_pInfo->FFI_SetTextFieldFocus)
153 m_pInfo->FFI_SetTextFieldFocus(m_pInfo, focusText, nTextLen, bFocus);
154 }
Tom Sepez0d3b5cc2014-07-30 13:03:52 -0700155
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700156 void FFI_DoURIAction(const FX_CHAR* bsURI) {
157 if (m_pInfo && m_pInfo->FFI_DoURIAction)
158 m_pInfo->FFI_DoURIAction(m_pInfo, bsURI);
159 }
Tom Sepez0d3b5cc2014-07-30 13:03:52 -0700160
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700161 void FFI_DoGoToAction(int nPageIndex,
162 int zoomMode,
163 float* fPosArray,
164 int sizeOfArray) {
165 if (m_pInfo && m_pInfo->FFI_DoGoToAction)
166 m_pInfo->FFI_DoGoToAction(m_pInfo, nPageIndex, zoomMode, fPosArray,
167 sizeOfArray);
168 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700169
Tom Sepez51da0932015-11-25 16:05:49 -0800170#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700171 void FFI_DisplayCaret(FPDF_PAGE page,
172 FPDF_BOOL bVisible,
173 double left,
174 double top,
175 double right,
176 double bottom) {
177 if (m_pInfo && m_pInfo->FFI_DisplayCaret)
178 m_pInfo->FFI_DisplayCaret(m_pInfo, page, bVisible, left, top, right,
179 bottom);
180 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700181
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700182 int FFI_GetCurrentPageIndex(FPDF_DOCUMENT document) {
Jun Fang01fe5882015-11-25 11:05:58 +0800183 if (!m_pInfo || !m_pInfo->FFI_GetCurrentPageIndex) {
184 return -1;
185 }
186 return m_pInfo->FFI_GetCurrentPageIndex(m_pInfo, document);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700187 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700188
Jun Fang01fe5882015-11-25 11:05:58 +0800189 void FFI_SetCurrentPage(FPDF_DOCUMENT document, int iCurPage) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700190 if (m_pInfo && m_pInfo->FFI_SetCurrentPage)
191 m_pInfo->FFI_SetCurrentPage(m_pInfo, document, iCurPage);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700192 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700193
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700194 CFX_WideString FFI_GetAppName() const { return CFX_WideString(L"Acrobat"); }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700195
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700196 CFX_WideString FFI_GetPlatform() {
197 if (m_pInfo && m_pInfo->FFI_GetPlatform) {
198 int nRequiredLen = m_pInfo->FFI_GetPlatform(m_pInfo, NULL, 0);
199 if (nRequiredLen <= 0)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700200 return L"";
Bo Xufdc00a72014-10-28 23:03:33 -0700201
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700202 char* pbuff = new char[nRequiredLen];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700203 memset(pbuff, 0, nRequiredLen);
204 int nActualLen = m_pInfo->FFI_GetPlatform(m_pInfo, pbuff, nRequiredLen);
205 if (nActualLen <= 0 || nActualLen > nRequiredLen) {
206 delete[] pbuff;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700207 return L"";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700208 }
209 CFX_ByteString bsRet = CFX_ByteString(pbuff, nActualLen);
210 CFX_WideString wsRet = CFX_WideString::FromUTF16LE(
211 (unsigned short*)bsRet.GetBuffer(bsRet.GetLength()),
212 bsRet.GetLength() / sizeof(unsigned short));
213 delete[] pbuff;
214 return wsRet;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700215 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700216 return L"";
217 }
Bo Xufdc00a72014-10-28 23:03:33 -0700218
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700219 void FFI_GotoURL(FPDF_DOCUMENT document,
220 const CFX_WideStringC& wsURL,
221 FX_BOOL bAppend) {
222 if (m_pInfo && m_pInfo->FFI_GotoURL) {
223 CFX_ByteString bsTo = CFX_WideString(wsURL).UTF16LE_Encode();
224 FPDF_WIDESTRING pTo = (FPDF_WIDESTRING)bsTo.GetBuffer(wsURL.GetLength());
225 m_pInfo->FFI_GotoURL(m_pInfo, document, pTo);
226 bsTo.ReleaseBuffer();
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700227 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700228 }
Bo Xufdc00a72014-10-28 23:03:33 -0700229
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700230 void FFI_GetURL(FPDF_DOCUMENT document, CFX_WideString& wsURL) {
231 wsURL = CFX_WideString();
232 }
233
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700234 void FFI_PageEvent(FPDF_PAGE page, FPDF_DWORD flag) {}
235
236 void FFI_GetPageViewRect(FPDF_PAGE page, FS_RECTF& dstRect) {
237 if (m_pInfo && m_pInfo->FFI_GetPageViewRect) {
238 double left;
239 double top;
240 double right;
241 double bottom;
242 m_pInfo->FFI_GetPageViewRect(m_pInfo, page, &left, &top, &right, &bottom);
243
244 dstRect.left = static_cast<float>(left);
245 dstRect.top = static_cast<float>(top < bottom ? bottom : top);
246 dstRect.bottom = static_cast<float>(top < bottom ? top : bottom);
247 dstRect.right = static_cast<float>(right);
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700248 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700249 }
Bo Xufdc00a72014-10-28 23:03:33 -0700250
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700251 FX_BOOL FFI_PopupMenu(FPDF_PAGE page,
252 FPDF_WIDGET hWidget,
253 int menuFlag,
254 CFX_PointF ptPopup,
255 const CFX_PointF* pRectExclude) {
256 if (m_pInfo && m_pInfo->FFI_PopupMenu)
257 return m_pInfo->FFI_PopupMenu(m_pInfo, page, hWidget, menuFlag, ptPopup.x,
258 ptPopup.y);
259 return FALSE;
260 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700261
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700262 void FFI_Alert(FPDF_WIDESTRING Msg,
263 FPDF_WIDESTRING Title,
264 int Type,
265 int Icon) {
266 if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_alert)
267 m_pInfo->m_pJsPlatform->app_alert(m_pInfo->m_pJsPlatform, Msg, Title,
268 Type, Icon);
269 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700270
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700271 void FFI_EmailTo(FPDF_FILEHANDLER* fileHandler,
272 FPDF_WIDESTRING pTo,
273 FPDF_WIDESTRING pSubject,
274 FPDF_WIDESTRING pCC,
275 FPDF_WIDESTRING pBcc,
276 FPDF_WIDESTRING pMsg) {
277 if (m_pInfo && m_pInfo->FFI_EmailTo)
278 m_pInfo->FFI_EmailTo(m_pInfo, fileHandler, pTo, pSubject, pCC, pBcc,
279 pMsg);
280 }
281
282 void FFI_UploadTo(FPDF_FILEHANDLER* fileHandler,
283 int fileFlag,
284 FPDF_WIDESTRING uploadTo) {
285 if (m_pInfo && m_pInfo->FFI_UploadTo)
286 m_pInfo->FFI_UploadTo(m_pInfo, fileHandler, fileFlag, uploadTo);
287 }
288
289 FPDF_FILEHANDLER* FFI_OpenFile(int fileType,
290 FPDF_WIDESTRING wsURL,
291 const char* mode) {
292 if (m_pInfo && m_pInfo->FFI_OpenFile)
293 return m_pInfo->FFI_OpenFile(m_pInfo, fileType, wsURL, mode);
294 return NULL;
295 }
296
297 CFX_WideString FFI_GetFilePath(FPDF_FILEHANDLER* pFileHandler) const {
298 return L"";
299 }
300
301 int FFI_GetDocumentCount() const { return 0; }
302 int FFI_GetCurDocument() const { return 0; }
303
304 IFX_FileRead* FFI_DownloadFromURL(const FX_WCHAR* url) {
305 if (m_pInfo && m_pInfo->FFI_DownloadFromURL) {
306 CFX_ByteString bstrURL = CFX_WideString(url).UTF16LE_Encode();
307 FPDF_WIDESTRING wsURL =
308 (FPDF_WIDESTRING)bstrURL.GetBuffer(bstrURL.GetLength());
309
310 FPDF_LPFILEHANDLER fileHandler =
311 m_pInfo->FFI_DownloadFromURL(m_pInfo, wsURL);
312
Lei Zhangdb5256f2015-10-02 10:11:43 -0700313 return new CFPDF_FileStream(fileHandler);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700314 }
315 return NULL;
316 }
317
318 CFX_WideString FFI_PostRequestURL(const FX_WCHAR* wsURL,
319 const FX_WCHAR* wsData,
320 const FX_WCHAR* wsContentType,
321 const FX_WCHAR* wsEncode,
322 const FX_WCHAR* wsHeader) {
323 if (m_pInfo && m_pInfo->FFI_PostRequestURL) {
324 CFX_ByteString bsURL = CFX_WideString(wsURL).UTF16LE_Encode();
325 FPDF_WIDESTRING URL = (FPDF_WIDESTRING)bsURL.GetBuffer(bsURL.GetLength());
326
327 CFX_ByteString bsData = CFX_WideString(wsData).UTF16LE_Encode();
328 FPDF_WIDESTRING data =
329 (FPDF_WIDESTRING)bsData.GetBuffer(bsData.GetLength());
330
331 CFX_ByteString bsContentType =
332 CFX_WideString(wsContentType).UTF16LE_Encode();
333 FPDF_WIDESTRING contentType =
334 (FPDF_WIDESTRING)bsContentType.GetBuffer(bsContentType.GetLength());
335
336 CFX_ByteString bsEncode = CFX_WideString(wsEncode).UTF16LE_Encode();
337 FPDF_WIDESTRING encode =
338 (FPDF_WIDESTRING)bsEncode.GetBuffer(bsEncode.GetLength());
339
340 CFX_ByteString bsHeader = CFX_WideString(wsHeader).UTF16LE_Encode();
341 FPDF_WIDESTRING header =
342 (FPDF_WIDESTRING)bsHeader.GetBuffer(bsHeader.GetLength());
343
344 FPDF_BSTR respone;
345 FPDF_BStr_Init(&respone);
346 m_pInfo->FFI_PostRequestURL(m_pInfo, URL, data, contentType, encode,
347 header, &respone);
348
349 CFX_WideString wsRet = CFX_WideString::FromUTF16LE(
350 (unsigned short*)respone.str, respone.len / sizeof(unsigned short));
351 FPDF_BStr_Clear(&respone);
352
353 return wsRet;
354 }
355 return L"";
356 }
357
358 FPDF_BOOL FFI_PutRequestURL(const FX_WCHAR* wsURL,
359 const FX_WCHAR* wsData,
360 const FX_WCHAR* wsEncode) {
361 if (m_pInfo && m_pInfo->FFI_PutRequestURL) {
362 CFX_ByteString bsURL = CFX_WideString(wsURL).UTF16LE_Encode();
363 FPDF_WIDESTRING URL = (FPDF_WIDESTRING)bsURL.GetBuffer(bsURL.GetLength());
364
365 CFX_ByteString bsData = CFX_WideString(wsData).UTF16LE_Encode();
366 FPDF_WIDESTRING data =
367 (FPDF_WIDESTRING)bsData.GetBuffer(bsData.GetLength());
368
369 CFX_ByteString bsEncode = CFX_WideString(wsEncode).UTF16LE_Encode();
370 FPDF_WIDESTRING encode =
371 (FPDF_WIDESTRING)bsEncode.GetBuffer(bsEncode.GetLength());
372
373 return m_pInfo->FFI_PutRequestURL(m_pInfo, URL, data, encode);
374 }
375 return FALSE;
376 }
377
378 FPDF_BOOL FFI_ShowFileDialog(const FX_WCHAR* wsTitle,
379 const FX_WCHAR* wsFilter,
380 CFX_WideStringArray& wsPathArr,
381 FX_BOOL bOpen) {
382 return FALSE;
383 }
384
385 CFX_WideString FFI_GetLanguage() {
386 if (m_pInfo && m_pInfo->FFI_GetLanguage) {
387 int nRequiredLen = m_pInfo->FFI_GetLanguage(m_pInfo, NULL, 0);
388 if (nRequiredLen <= 0)
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700389 return L"";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700390
391 char* pbuff = new char[nRequiredLen];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700392 memset(pbuff, 0, nRequiredLen);
393 int nActualLen = m_pInfo->FFI_GetLanguage(m_pInfo, pbuff, nRequiredLen);
394 if (nActualLen <= 0 || nActualLen > nRequiredLen) {
395 delete[] pbuff;
396 return L"";
397 }
398 CFX_ByteString bsRet = CFX_ByteString(pbuff, nActualLen);
399 CFX_WideString wsRet = CFX_WideString::FromUTF16LE(
400 (unsigned short*)bsRet.GetBuffer(bsRet.GetLength()),
401 bsRet.GetLength() / sizeof(unsigned short));
402 delete[] pbuff;
403 return wsRet;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700404 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700405 return L"";
406 }
Jun Fangc30d5bf2016-02-02 18:12:23 -0800407 void FFI_PageEvent(int iPageIndex, int iEventType) const {
408 // Todo: call a call-back function when it's implemented
409 // in applicaiton's side.
410 }
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
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700522 FX_BOOL ExtractPages(const CFX_WordArray& arrExtraPages,
523 CPDF_Document* pDstDoc);
524 FX_BOOL InsertPages(int nInsertAt,
525 const CPDF_Document* pSrcDoc,
526 const CFX_WordArray& arrSrcPages);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700527 FX_BOOL ReplacePages(int nPage,
528 const CPDF_Document* pSrcDoc,
529 const CFX_WordArray& 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; }
606 FX_BOOL OnLButtonDown(const CPDF_Point& point, FX_UINT nFlag);
607 FX_BOOL OnLButtonUp(const CPDF_Point& point, FX_UINT nFlag);
Tom Sepez51da0932015-11-25 16:05:49 -0800608#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700609 FX_BOOL OnRButtonDown(const CPDF_Point& point, FX_UINT nFlag);
610 FX_BOOL OnRButtonUp(const CPDF_Point& 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
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700616 FX_BOOL OnMouseMove(const CPDF_Point& point, int nFlag);
617 FX_BOOL OnMouseWheel(double deltaX,
618 double deltaY,
619 const CPDF_Point& point,
620 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_