OLD | NEW |
| (Empty) |
1 // Copyright 2016 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. | |
4 | |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | |
6 | |
7 #ifndef FPDFSDK_INCLUDE_CPDFDOC_ENVIRONMENT_H_ | |
8 #define FPDFSDK_INCLUDE_CPDFDOC_ENVIRONMENT_H_ | |
9 | |
10 #include <memory> | |
11 | |
12 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" | |
13 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" | |
14 #include "core/fpdfdoc/include/cpdf_occontext.h" | |
15 #include "core/fxcrt/include/cfx_observable.h" | |
16 #include "fpdfsdk/cfx_systemhandler.h" | |
17 #include "fpdfsdk/include/fsdk_define.h" | |
18 #include "public/fpdf_formfill.h" | |
19 #include "public/fpdf_fwlevent.h" | |
20 | |
21 class CFFL_IFormFiller; | |
22 class CFX_SystemHandler; | |
23 class CPDFSDK_ActionHandler; | |
24 class CPDFSDK_AnnotHandlerMgr; | |
25 class CPDFSDK_Document; | |
26 class IJS_Runtime; | |
27 | |
28 class CPDFDoc_Environment final { | |
29 public: | |
30 CPDFDoc_Environment(UnderlyingDocumentType* pDoc, FPDF_FORMFILLINFO* pFFinfo); | |
31 ~CPDFDoc_Environment(); | |
32 | |
33 void FFI_Invalidate(FPDF_PAGE page, | |
34 double left, | |
35 double top, | |
36 double right, | |
37 double bottom) { | |
38 if (m_pInfo && m_pInfo->FFI_Invalidate) | |
39 m_pInfo->FFI_Invalidate(m_pInfo, page, left, top, right, bottom); | |
40 } | |
41 | |
42 void FFI_OutputSelectedRect(FPDF_PAGE page, | |
43 double left, | |
44 double top, | |
45 double right, | |
46 double bottom) { | |
47 if (m_pInfo && m_pInfo->FFI_OutputSelectedRect) | |
48 m_pInfo->FFI_OutputSelectedRect(m_pInfo, page, left, top, right, bottom); | |
49 } | |
50 | |
51 void FFI_SetCursor(int nCursorType) { | |
52 if (m_pInfo && m_pInfo->FFI_SetCursor) | |
53 m_pInfo->FFI_SetCursor(m_pInfo, nCursorType); | |
54 } | |
55 | |
56 int FFI_SetTimer(int uElapse, TimerCallback lpTimerFunc) { | |
57 if (m_pInfo && m_pInfo->FFI_SetTimer) | |
58 return m_pInfo->FFI_SetTimer(m_pInfo, uElapse, lpTimerFunc); | |
59 return -1; | |
60 } | |
61 | |
62 void FFI_KillTimer(int nTimerID) { | |
63 if (m_pInfo && m_pInfo->FFI_KillTimer) | |
64 m_pInfo->FFI_KillTimer(m_pInfo, nTimerID); | |
65 } | |
66 | |
67 FX_SYSTEMTIME FFI_GetLocalTime() const { | |
68 FX_SYSTEMTIME fxtime; | |
69 if (m_pInfo && m_pInfo->FFI_GetLocalTime) { | |
70 FPDF_SYSTEMTIME systime = m_pInfo->FFI_GetLocalTime(m_pInfo); | |
71 fxtime.wDay = systime.wDay; | |
72 fxtime.wDayOfWeek = systime.wDayOfWeek; | |
73 fxtime.wHour = systime.wHour; | |
74 fxtime.wMilliseconds = systime.wMilliseconds; | |
75 fxtime.wMinute = systime.wMinute; | |
76 fxtime.wMonth = systime.wMonth; | |
77 fxtime.wSecond = systime.wSecond; | |
78 fxtime.wYear = systime.wYear; | |
79 } | |
80 return fxtime; | |
81 } | |
82 | |
83 void FFI_OnChange() { | |
84 if (m_pInfo && m_pInfo->FFI_OnChange) | |
85 m_pInfo->FFI_OnChange(m_pInfo); | |
86 } | |
87 | |
88 FX_BOOL FFI_IsSHIFTKeyDown(uint32_t nFlag) const { | |
89 return (nFlag & FWL_EVENTFLAG_ShiftKey) != 0; | |
90 } | |
91 | |
92 FX_BOOL FFI_IsCTRLKeyDown(uint32_t nFlag) const { | |
93 return (nFlag & FWL_EVENTFLAG_ControlKey) != 0; | |
94 } | |
95 | |
96 FX_BOOL FFI_IsALTKeyDown(uint32_t nFlag) const { | |
97 return (nFlag & FWL_EVENTFLAG_AltKey) != 0; | |
98 } | |
99 | |
100 FPDF_PAGE FFI_GetPage(FPDF_DOCUMENT document, int nPageIndex) { | |
101 if (m_pInfo && m_pInfo->FFI_GetPage) | |
102 return m_pInfo->FFI_GetPage(m_pInfo, document, nPageIndex); | |
103 return nullptr; | |
104 } | |
105 | |
106 FPDF_PAGE FFI_GetCurrentPage(FPDF_DOCUMENT document) { | |
107 if (m_pInfo && m_pInfo->FFI_GetCurrentPage) | |
108 return m_pInfo->FFI_GetCurrentPage(m_pInfo, document); | |
109 return nullptr; | |
110 } | |
111 | |
112 int FFI_GetRotation(FPDF_PAGE page) { | |
113 if (m_pInfo && m_pInfo->FFI_GetRotation) | |
114 return m_pInfo->FFI_GetRotation(m_pInfo, page); | |
115 return 0; | |
116 } | |
117 | |
118 void FFI_ExecuteNamedAction(const FX_CHAR* namedAction) { | |
119 if (m_pInfo && m_pInfo->FFI_ExecuteNamedAction) | |
120 m_pInfo->FFI_ExecuteNamedAction(m_pInfo, namedAction); | |
121 } | |
122 | |
123 void FFI_OnSetFieldInputFocus(void* field, | |
124 FPDF_WIDESTRING focusText, | |
125 FPDF_DWORD nTextLen, | |
126 FX_BOOL bFocus) { | |
127 if (m_pInfo && m_pInfo->FFI_SetTextFieldFocus) | |
128 m_pInfo->FFI_SetTextFieldFocus(m_pInfo, focusText, nTextLen, bFocus); | |
129 } | |
130 | |
131 void FFI_DoURIAction(const FX_CHAR* bsURI) { | |
132 if (m_pInfo && m_pInfo->FFI_DoURIAction) | |
133 m_pInfo->FFI_DoURIAction(m_pInfo, bsURI); | |
134 } | |
135 | |
136 void FFI_DoGoToAction(int nPageIndex, | |
137 int zoomMode, | |
138 float* fPosArray, | |
139 int sizeOfArray) { | |
140 if (m_pInfo && m_pInfo->FFI_DoGoToAction) | |
141 m_pInfo->FFI_DoGoToAction(m_pInfo, nPageIndex, zoomMode, fPosArray, | |
142 sizeOfArray); | |
143 } | |
144 | |
145 #ifdef PDF_ENABLE_XFA | |
146 void FFI_DisplayCaret(FPDF_PAGE page, | |
147 FPDF_BOOL bVisible, | |
148 double left, | |
149 double top, | |
150 double right, | |
151 double bottom) { | |
152 if (m_pInfo && m_pInfo->FFI_DisplayCaret) | |
153 m_pInfo->FFI_DisplayCaret(m_pInfo, page, bVisible, left, top, right, | |
154 bottom); | |
155 } | |
156 | |
157 int FFI_GetCurrentPageIndex(FPDF_DOCUMENT document) { | |
158 if (!m_pInfo || !m_pInfo->FFI_GetCurrentPageIndex) { | |
159 return -1; | |
160 } | |
161 return m_pInfo->FFI_GetCurrentPageIndex(m_pInfo, document); | |
162 } | |
163 | |
164 void FFI_SetCurrentPage(FPDF_DOCUMENT document, int iCurPage) { | |
165 if (m_pInfo && m_pInfo->FFI_SetCurrentPage) | |
166 m_pInfo->FFI_SetCurrentPage(m_pInfo, document, iCurPage); | |
167 } | |
168 | |
169 CFX_WideString FFI_GetAppName() const { return CFX_WideString(L"Acrobat"); } | |
170 | |
171 CFX_WideString FFI_GetPlatform() { | |
172 if (m_pInfo && m_pInfo->FFI_GetPlatform) { | |
173 int nRequiredLen = m_pInfo->FFI_GetPlatform(m_pInfo, nullptr, 0); | |
174 if (nRequiredLen <= 0) | |
175 return L""; | |
176 | |
177 char* pbuff = new char[nRequiredLen]; | |
178 memset(pbuff, 0, nRequiredLen); | |
179 int nActualLen = m_pInfo->FFI_GetPlatform(m_pInfo, pbuff, nRequiredLen); | |
180 if (nActualLen <= 0 || nActualLen > nRequiredLen) { | |
181 delete[] pbuff; | |
182 return L""; | |
183 } | |
184 CFX_ByteString bsRet = CFX_ByteString(pbuff, nActualLen); | |
185 CFX_WideString wsRet = CFX_WideString::FromUTF16LE( | |
186 (unsigned short*)bsRet.GetBuffer(bsRet.GetLength()), | |
187 bsRet.GetLength() / sizeof(unsigned short)); | |
188 delete[] pbuff; | |
189 return wsRet; | |
190 } | |
191 return L""; | |
192 } | |
193 | |
194 void FFI_GotoURL(FPDF_DOCUMENT document, | |
195 const CFX_WideStringC& wsURL, | |
196 FX_BOOL bAppend) { | |
197 if (m_pInfo && m_pInfo->FFI_GotoURL) { | |
198 CFX_ByteString bsTo = CFX_WideString(wsURL).UTF16LE_Encode(); | |
199 FPDF_WIDESTRING pTo = (FPDF_WIDESTRING)bsTo.GetBuffer(wsURL.GetLength()); | |
200 m_pInfo->FFI_GotoURL(m_pInfo, document, pTo); | |
201 bsTo.ReleaseBuffer(); | |
202 } | |
203 } | |
204 | |
205 void FFI_GetPageViewRect(FPDF_PAGE page, FS_RECTF& dstRect) { | |
206 if (m_pInfo && m_pInfo->FFI_GetPageViewRect) { | |
207 double left; | |
208 double top; | |
209 double right; | |
210 double bottom; | |
211 m_pInfo->FFI_GetPageViewRect(m_pInfo, page, &left, &top, &right, &bottom); | |
212 | |
213 dstRect.left = static_cast<float>(left); | |
214 dstRect.top = static_cast<float>(top < bottom ? bottom : top); | |
215 dstRect.bottom = static_cast<float>(top < bottom ? top : bottom); | |
216 dstRect.right = static_cast<float>(right); | |
217 } | |
218 } | |
219 | |
220 FX_BOOL FFI_PopupMenu(FPDF_PAGE page, | |
221 FPDF_WIDGET hWidget, | |
222 int menuFlag, | |
223 CFX_PointF ptPopup, | |
224 const CFX_PointF* pRectExclude) { | |
225 if (m_pInfo && m_pInfo->FFI_PopupMenu) | |
226 return m_pInfo->FFI_PopupMenu(m_pInfo, page, hWidget, menuFlag, ptPopup.x, | |
227 ptPopup.y); | |
228 return FALSE; | |
229 } | |
230 | |
231 void FFI_Alert(FPDF_WIDESTRING Msg, | |
232 FPDF_WIDESTRING Title, | |
233 int Type, | |
234 int Icon) { | |
235 if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_alert) | |
236 m_pInfo->m_pJsPlatform->app_alert(m_pInfo->m_pJsPlatform, Msg, Title, | |
237 Type, Icon); | |
238 } | |
239 | |
240 void FFI_EmailTo(FPDF_FILEHANDLER* fileHandler, | |
241 FPDF_WIDESTRING pTo, | |
242 FPDF_WIDESTRING pSubject, | |
243 FPDF_WIDESTRING pCC, | |
244 FPDF_WIDESTRING pBcc, | |
245 FPDF_WIDESTRING pMsg) { | |
246 if (m_pInfo && m_pInfo->FFI_EmailTo) | |
247 m_pInfo->FFI_EmailTo(m_pInfo, fileHandler, pTo, pSubject, pCC, pBcc, | |
248 pMsg); | |
249 } | |
250 | |
251 void FFI_UploadTo(FPDF_FILEHANDLER* fileHandler, | |
252 int fileFlag, | |
253 FPDF_WIDESTRING uploadTo) { | |
254 if (m_pInfo && m_pInfo->FFI_UploadTo) | |
255 m_pInfo->FFI_UploadTo(m_pInfo, fileHandler, fileFlag, uploadTo); | |
256 } | |
257 | |
258 FPDF_FILEHANDLER* FFI_OpenFile(int fileType, | |
259 FPDF_WIDESTRING wsURL, | |
260 const char* mode) { | |
261 if (m_pInfo && m_pInfo->FFI_OpenFile) | |
262 return m_pInfo->FFI_OpenFile(m_pInfo, fileType, wsURL, mode); | |
263 return nullptr; | |
264 } | |
265 | |
266 CFX_WideString FFI_GetFilePath(FPDF_FILEHANDLER* pFileHandler) const { | |
267 return L""; | |
268 } | |
269 | |
270 int FFI_GetDocumentCount() const { return 0; } | |
271 int FFI_GetCurDocument() const { return 0; } | |
272 | |
273 IFX_FileRead* FFI_DownloadFromURL(const FX_WCHAR* url) { | |
274 if (m_pInfo && m_pInfo->FFI_DownloadFromURL) { | |
275 CFX_ByteString bstrURL = CFX_WideString(url).UTF16LE_Encode(); | |
276 FPDF_WIDESTRING wsURL = | |
277 (FPDF_WIDESTRING)bstrURL.GetBuffer(bstrURL.GetLength()); | |
278 | |
279 FPDF_LPFILEHANDLER fileHandler = | |
280 m_pInfo->FFI_DownloadFromURL(m_pInfo, wsURL); | |
281 | |
282 return new CFPDF_FileStream(fileHandler); | |
283 } | |
284 return nullptr; | |
285 } | |
286 | |
287 CFX_WideString FFI_PostRequestURL(const FX_WCHAR* wsURL, | |
288 const FX_WCHAR* wsData, | |
289 const FX_WCHAR* wsContentType, | |
290 const FX_WCHAR* wsEncode, | |
291 const FX_WCHAR* wsHeader) { | |
292 if (m_pInfo && m_pInfo->FFI_PostRequestURL) { | |
293 CFX_ByteString bsURL = CFX_WideString(wsURL).UTF16LE_Encode(); | |
294 FPDF_WIDESTRING URL = (FPDF_WIDESTRING)bsURL.GetBuffer(bsURL.GetLength()); | |
295 | |
296 CFX_ByteString bsData = CFX_WideString(wsData).UTF16LE_Encode(); | |
297 FPDF_WIDESTRING data = | |
298 (FPDF_WIDESTRING)bsData.GetBuffer(bsData.GetLength()); | |
299 | |
300 CFX_ByteString bsContentType = | |
301 CFX_WideString(wsContentType).UTF16LE_Encode(); | |
302 FPDF_WIDESTRING contentType = | |
303 (FPDF_WIDESTRING)bsContentType.GetBuffer(bsContentType.GetLength()); | |
304 | |
305 CFX_ByteString bsEncode = CFX_WideString(wsEncode).UTF16LE_Encode(); | |
306 FPDF_WIDESTRING encode = | |
307 (FPDF_WIDESTRING)bsEncode.GetBuffer(bsEncode.GetLength()); | |
308 | |
309 CFX_ByteString bsHeader = CFX_WideString(wsHeader).UTF16LE_Encode(); | |
310 FPDF_WIDESTRING header = | |
311 (FPDF_WIDESTRING)bsHeader.GetBuffer(bsHeader.GetLength()); | |
312 | |
313 FPDF_BSTR response; | |
314 FPDF_BStr_Init(&response); | |
315 m_pInfo->FFI_PostRequestURL(m_pInfo, URL, data, contentType, encode, | |
316 header, &response); | |
317 | |
318 CFX_WideString wsRet = CFX_WideString::FromUTF16LE( | |
319 (unsigned short*)response.str, response.len / sizeof(unsigned short)); | |
320 FPDF_BStr_Clear(&response); | |
321 | |
322 return wsRet; | |
323 } | |
324 return L""; | |
325 } | |
326 | |
327 FPDF_BOOL FFI_PutRequestURL(const FX_WCHAR* wsURL, | |
328 const FX_WCHAR* wsData, | |
329 const FX_WCHAR* wsEncode) { | |
330 if (m_pInfo && m_pInfo->FFI_PutRequestURL) { | |
331 CFX_ByteString bsURL = CFX_WideString(wsURL).UTF16LE_Encode(); | |
332 FPDF_WIDESTRING URL = (FPDF_WIDESTRING)bsURL.GetBuffer(bsURL.GetLength()); | |
333 | |
334 CFX_ByteString bsData = CFX_WideString(wsData).UTF16LE_Encode(); | |
335 FPDF_WIDESTRING data = | |
336 (FPDF_WIDESTRING)bsData.GetBuffer(bsData.GetLength()); | |
337 | |
338 CFX_ByteString bsEncode = CFX_WideString(wsEncode).UTF16LE_Encode(); | |
339 FPDF_WIDESTRING encode = | |
340 (FPDF_WIDESTRING)bsEncode.GetBuffer(bsEncode.GetLength()); | |
341 | |
342 return m_pInfo->FFI_PutRequestURL(m_pInfo, URL, data, encode); | |
343 } | |
344 return FALSE; | |
345 } | |
346 | |
347 CFX_WideString FFI_GetLanguage() { | |
348 if (m_pInfo && m_pInfo->FFI_GetLanguage) { | |
349 int nRequiredLen = m_pInfo->FFI_GetLanguage(m_pInfo, nullptr, 0); | |
350 if (nRequiredLen <= 0) | |
351 return L""; | |
352 | |
353 char* pbuff = new char[nRequiredLen]; | |
354 memset(pbuff, 0, nRequiredLen); | |
355 int nActualLen = m_pInfo->FFI_GetLanguage(m_pInfo, pbuff, nRequiredLen); | |
356 if (nActualLen <= 0 || nActualLen > nRequiredLen) { | |
357 delete[] pbuff; | |
358 return L""; | |
359 } | |
360 CFX_ByteString bsRet = CFX_ByteString(pbuff, nActualLen); | |
361 CFX_WideString wsRet = CFX_WideString::FromUTF16LE( | |
362 (unsigned short*)bsRet.GetBuffer(bsRet.GetLength()), | |
363 bsRet.GetLength() / sizeof(unsigned short)); | |
364 delete[] pbuff; | |
365 return wsRet; | |
366 } | |
367 return L""; | |
368 } | |
369 | |
370 void FFI_PageEvent(int iPageCount, uint32_t dwEventType) const { | |
371 if (m_pInfo && m_pInfo->FFI_PageEvent) | |
372 m_pInfo->FFI_PageEvent(m_pInfo, iPageCount, dwEventType); | |
373 } | |
374 #endif // PDF_ENABLE_XFA | |
375 | |
376 int JS_appAlert(const FX_WCHAR* Msg, | |
377 const FX_WCHAR* Title, | |
378 FX_UINT Type, | |
379 FX_UINT Icon); | |
380 int JS_appResponse(const FX_WCHAR* Question, | |
381 const FX_WCHAR* Title, | |
382 const FX_WCHAR* Default, | |
383 const FX_WCHAR* cLabel, | |
384 FPDF_BOOL bPassword, | |
385 void* response, | |
386 int length); | |
387 void JS_appBeep(int nType); | |
388 CFX_WideString JS_fieldBrowse(); | |
389 CFX_WideString JS_docGetFilePath(); | |
390 void JS_docSubmitForm(void* formData, int length, const FX_WCHAR* URL); | |
391 void JS_docmailForm(void* mailData, | |
392 int length, | |
393 FPDF_BOOL bUI, | |
394 const FX_WCHAR* To, | |
395 const FX_WCHAR* Subject, | |
396 const FX_WCHAR* CC, | |
397 const FX_WCHAR* BCC, | |
398 const FX_WCHAR* Msg); | |
399 void JS_docprint(FPDF_BOOL bUI, | |
400 int nStart, | |
401 int nEnd, | |
402 FPDF_BOOL bSilent, | |
403 FPDF_BOOL bShrinkToFit, | |
404 FPDF_BOOL bPrintAsImage, | |
405 FPDF_BOOL bReverse, | |
406 FPDF_BOOL bAnnotations); | |
407 void JS_docgotoPage(int nPageNum); | |
408 | |
409 FX_BOOL IsJSInitiated() const { return m_pInfo && m_pInfo->m_pJsPlatform; } | |
410 void SetSDKDocument(CPDFSDK_Document* pFXDoc) { m_pSDKDoc = pFXDoc; } | |
411 CPDFSDK_Document* GetSDKDocument() const { return m_pSDKDoc; } | |
412 UnderlyingDocumentType* GetUnderlyingDocument() const { | |
413 return m_pUnderlyingDoc; | |
414 } | |
415 CFX_ByteString GetAppName() const { return ""; } | |
416 CFX_SystemHandler* GetSysHandler() const { return m_pSysHandler.get(); } | |
417 FPDF_FORMFILLINFO* GetFormFillInfo() const { return m_pInfo; } | |
418 | |
419 CFFL_IFormFiller* GetIFormFiller(); // Creates if not present. | |
420 CPDFSDK_AnnotHandlerMgr* GetAnnotHandlerMgr(); // Creates if not present. | |
421 IJS_Runtime* GetJSRuntime(); // Creates if not present. | |
422 CPDFSDK_ActionHandler* GetActionHander(); // Creates if not present. | |
423 | |
424 private: | |
425 std::unique_ptr<CPDFSDK_AnnotHandlerMgr> m_pAnnotHandlerMgr; | |
426 std::unique_ptr<CPDFSDK_ActionHandler> m_pActionHandler; | |
427 std::unique_ptr<IJS_Runtime> m_pJSRuntime; | |
428 FPDF_FORMFILLINFO* const m_pInfo; | |
429 CPDFSDK_Document* m_pSDKDoc; | |
430 UnderlyingDocumentType* const m_pUnderlyingDoc; | |
431 std::unique_ptr<CFFL_IFormFiller> m_pIFormFiller; | |
432 std::unique_ptr<CFX_SystemHandler> m_pSysHandler; | |
433 }; | |
434 | |
435 #endif // FPDFSDK_INCLUDE_CPDFDOC_ENVIRONMENT_H_ | |
OLD | NEW |