OLD | NEW |
1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #ifndef FPDFSDK_INCLUDE_CPDFSDK_ENVIRONMENT_H_ | 7 #ifndef FPDFSDK_INCLUDE_CPDFSDK_ENVIRONMENT_H_ |
8 #define FPDFSDK_INCLUDE_CPDFSDK_ENVIRONMENT_H_ | 8 #define FPDFSDK_INCLUDE_CPDFSDK_ENVIRONMENT_H_ |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 16 matching lines...) Expand all Loading... |
27 | 27 |
28 class CPDFSDK_Environment final { | 28 class CPDFSDK_Environment final { |
29 public: | 29 public: |
30 CPDFSDK_Environment(UnderlyingDocumentType* pDoc, FPDF_FORMFILLINFO* pFFinfo); | 30 CPDFSDK_Environment(UnderlyingDocumentType* pDoc, FPDF_FORMFILLINFO* pFFinfo); |
31 ~CPDFSDK_Environment(); | 31 ~CPDFSDK_Environment(); |
32 | 32 |
33 void Invalidate(FPDF_PAGE page, | 33 void Invalidate(FPDF_PAGE page, |
34 double left, | 34 double left, |
35 double top, | 35 double top, |
36 double right, | 36 double right, |
37 double bottom) { | 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 OutputSelectedRect(FPDF_PAGE page, | 38 void OutputSelectedRect(FPDF_PAGE page, |
43 double left, | 39 double left, |
44 double top, | 40 double top, |
45 double right, | 41 double right, |
46 double bottom) { | 42 double bottom); |
47 if (m_pInfo && m_pInfo->FFI_OutputSelectedRect) | |
48 m_pInfo->FFI_OutputSelectedRect(m_pInfo, page, left, top, right, bottom); | |
49 } | |
50 | 43 |
51 void SetCursor(int nCursorType) { | 44 void SetCursor(int nCursorType); |
52 if (m_pInfo && m_pInfo->FFI_SetCursor) | 45 int SetTimer(int uElapse, TimerCallback lpTimerFunc); |
53 m_pInfo->FFI_SetCursor(m_pInfo, nCursorType); | 46 void KillTimer(int nTimerID); |
54 } | 47 FX_SYSTEMTIME GetLocalTime() const; |
55 | 48 |
56 int SetTimer(int uElapse, TimerCallback lpTimerFunc) { | 49 void OnChange(); |
57 if (m_pInfo && m_pInfo->FFI_SetTimer) | 50 FX_BOOL IsSHIFTKeyDown(uint32_t nFlag) const; |
58 return m_pInfo->FFI_SetTimer(m_pInfo, uElapse, lpTimerFunc); | 51 FX_BOOL IsCTRLKeyDown(uint32_t nFlag) const; |
59 return -1; | 52 FX_BOOL IsALTKeyDown(uint32_t nFlag) const; |
60 } | |
61 | 53 |
62 void KillTimer(int nTimerID) { | 54 FPDF_PAGE GetPage(FPDF_DOCUMENT document, int nPageIndex); |
63 if (m_pInfo && m_pInfo->FFI_KillTimer) | 55 FPDF_PAGE GetCurrentPage(FPDF_DOCUMENT document); |
64 m_pInfo->FFI_KillTimer(m_pInfo, nTimerID); | |
65 } | |
66 | 56 |
67 FX_SYSTEMTIME GetLocalTime() const { | 57 void ExecuteNamedAction(const FX_CHAR* namedAction); |
68 FX_SYSTEMTIME fxtime; | 58 void OnSetFieldInputFocus(FPDF_WIDESTRING focusText, |
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 OnChange() { | |
84 if (m_pInfo && m_pInfo->FFI_OnChange) | |
85 m_pInfo->FFI_OnChange(m_pInfo); | |
86 } | |
87 | |
88 FX_BOOL IsSHIFTKeyDown(uint32_t nFlag) const { | |
89 return (nFlag & FWL_EVENTFLAG_ShiftKey) != 0; | |
90 } | |
91 | |
92 FX_BOOL IsCTRLKeyDown(uint32_t nFlag) const { | |
93 return (nFlag & FWL_EVENTFLAG_ControlKey) != 0; | |
94 } | |
95 | |
96 FX_BOOL IsALTKeyDown(uint32_t nFlag) const { | |
97 return (nFlag & FWL_EVENTFLAG_AltKey) != 0; | |
98 } | |
99 | |
100 FPDF_PAGE 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 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 void ExecuteNamedAction(const FX_CHAR* namedAction) { | |
113 if (m_pInfo && m_pInfo->FFI_ExecuteNamedAction) | |
114 m_pInfo->FFI_ExecuteNamedAction(m_pInfo, namedAction); | |
115 } | |
116 | |
117 void OnSetFieldInputFocus(void* field, | |
118 FPDF_WIDESTRING focusText, | |
119 FPDF_DWORD nTextLen, | 59 FPDF_DWORD nTextLen, |
120 FX_BOOL bFocus) { | 60 FX_BOOL bFocus); |
121 if (m_pInfo && m_pInfo->FFI_SetTextFieldFocus) | 61 void DoURIAction(const FX_CHAR* bsURI); |
122 m_pInfo->FFI_SetTextFieldFocus(m_pInfo, focusText, nTextLen, bFocus); | |
123 } | |
124 | |
125 void DoURIAction(const FX_CHAR* bsURI) { | |
126 if (m_pInfo && m_pInfo->FFI_DoURIAction) | |
127 m_pInfo->FFI_DoURIAction(m_pInfo, bsURI); | |
128 } | |
129 | |
130 void DoGoToAction(int nPageIndex, | 62 void DoGoToAction(int nPageIndex, |
131 int zoomMode, | 63 int zoomMode, |
132 float* fPosArray, | 64 float* fPosArray, |
133 int sizeOfArray) { | 65 int sizeOfArray); |
134 if (m_pInfo && m_pInfo->FFI_DoGoToAction) | |
135 m_pInfo->FFI_DoGoToAction(m_pInfo, nPageIndex, zoomMode, fPosArray, | |
136 sizeOfArray); | |
137 } | |
138 | 66 |
139 #ifdef PDF_ENABLE_XFA | 67 #ifdef PDF_ENABLE_XFA |
140 void DisplayCaret(FPDF_PAGE page, | 68 void DisplayCaret(FPDF_PAGE page, |
141 FPDF_BOOL bVisible, | 69 FPDF_BOOL bVisible, |
142 double left, | 70 double left, |
143 double top, | 71 double top, |
144 double right, | 72 double right, |
145 double bottom) { | 73 double bottom); |
146 if (m_pInfo && m_pInfo->FFI_DisplayCaret) | 74 int GetCurrentPageIndex(FPDF_DOCUMENT document); |
147 m_pInfo->FFI_DisplayCaret(m_pInfo, page, bVisible, left, top, right, | 75 void SetCurrentPage(FPDF_DOCUMENT document, int iCurPage); |
148 bottom); | |
149 } | |
150 | |
151 int GetCurrentPageIndex(FPDF_DOCUMENT document) { | |
152 if (!m_pInfo || !m_pInfo->FFI_GetCurrentPageIndex) | |
153 return -1; | |
154 return m_pInfo->FFI_GetCurrentPageIndex(m_pInfo, document); | |
155 } | |
156 | |
157 void SetCurrentPage(FPDF_DOCUMENT document, int iCurPage) { | |
158 if (m_pInfo && m_pInfo->FFI_SetCurrentPage) | |
159 m_pInfo->FFI_SetCurrentPage(m_pInfo, document, iCurPage); | |
160 } | |
161 | 76 |
162 // TODO(dsinclair): This should probably change to PDFium? | 77 // TODO(dsinclair): This should probably change to PDFium? |
163 CFX_WideString FFI_GetAppName() const { return CFX_WideString(L"Acrobat"); } | 78 CFX_WideString FFI_GetAppName() const { return CFX_WideString(L"Acrobat"); } |
164 | 79 |
165 CFX_WideString GetPlatform() { | 80 CFX_WideString GetPlatform(); |
166 if (!m_pInfo || !m_pInfo->FFI_GetPlatform) | 81 void GotoURL(FPDF_DOCUMENT document, const CFX_WideStringC& wsURL); |
167 return L""; | 82 void GetPageViewRect(FPDF_PAGE page, FS_RECTF& dstRect); |
168 | |
169 int nRequiredLen = m_pInfo->FFI_GetPlatform(m_pInfo, nullptr, 0); | |
170 if (nRequiredLen <= 0) | |
171 return L""; | |
172 | |
173 char* pbuff = new char[nRequiredLen]; | |
174 memset(pbuff, 0, nRequiredLen); | |
175 int nActualLen = m_pInfo->FFI_GetPlatform(m_pInfo, pbuff, nRequiredLen); | |
176 if (nActualLen <= 0 || nActualLen > nRequiredLen) { | |
177 delete[] pbuff; | |
178 return L""; | |
179 } | |
180 CFX_ByteString bsRet = CFX_ByteString(pbuff, nActualLen); | |
181 CFX_WideString wsRet = CFX_WideString::FromUTF16LE( | |
182 (unsigned short*)bsRet.GetBuffer(bsRet.GetLength()), | |
183 bsRet.GetLength() / sizeof(unsigned short)); | |
184 delete[] pbuff; | |
185 return wsRet; | |
186 } | |
187 | |
188 void GotoURL(FPDF_DOCUMENT document, | |
189 const CFX_WideStringC& wsURL, | |
190 FX_BOOL bAppend) { | |
191 if (m_pInfo && m_pInfo->FFI_GotoURL) { | |
192 CFX_ByteString bsTo = CFX_WideString(wsURL).UTF16LE_Encode(); | |
193 FPDF_WIDESTRING pTo = (FPDF_WIDESTRING)bsTo.GetBuffer(wsURL.GetLength()); | |
194 m_pInfo->FFI_GotoURL(m_pInfo, document, pTo); | |
195 bsTo.ReleaseBuffer(); | |
196 } | |
197 } | |
198 | |
199 void GetPageViewRect(FPDF_PAGE page, FS_RECTF& dstRect) { | |
200 if (m_pInfo && m_pInfo->FFI_GetPageViewRect) { | |
201 double left; | |
202 double top; | |
203 double right; | |
204 double bottom; | |
205 m_pInfo->FFI_GetPageViewRect(m_pInfo, page, &left, &top, &right, &bottom); | |
206 | |
207 dstRect.left = static_cast<float>(left); | |
208 dstRect.top = static_cast<float>(top < bottom ? bottom : top); | |
209 dstRect.bottom = static_cast<float>(top < bottom ? top : bottom); | |
210 dstRect.right = static_cast<float>(right); | |
211 } | |
212 } | |
213 | |
214 FX_BOOL PopupMenu(FPDF_PAGE page, | 83 FX_BOOL PopupMenu(FPDF_PAGE page, |
215 FPDF_WIDGET hWidget, | 84 FPDF_WIDGET hWidget, |
216 int menuFlag, | 85 int menuFlag, |
217 CFX_PointF ptPopup, | 86 CFX_PointF pt); |
218 const CFX_PointF* pRectExclude) { | |
219 if (m_pInfo && m_pInfo->FFI_PopupMenu) | |
220 return m_pInfo->FFI_PopupMenu(m_pInfo, page, hWidget, menuFlag, ptPopup.x, | |
221 ptPopup.y); | |
222 return FALSE; | |
223 } | |
224 | 87 |
225 void Alert(FPDF_WIDESTRING Msg, FPDF_WIDESTRING Title, int Type, int Icon) { | 88 void Alert(FPDF_WIDESTRING Msg, FPDF_WIDESTRING Title, int Type, int Icon); |
226 if (m_pInfo && m_pInfo->m_pJsPlatform && m_pInfo->m_pJsPlatform->app_alert) | |
227 m_pInfo->m_pJsPlatform->app_alert(m_pInfo->m_pJsPlatform, Msg, Title, | |
228 Type, Icon); | |
229 } | |
230 | |
231 void EmailTo(FPDF_FILEHANDLER* fileHandler, | 89 void EmailTo(FPDF_FILEHANDLER* fileHandler, |
232 FPDF_WIDESTRING pTo, | 90 FPDF_WIDESTRING pTo, |
233 FPDF_WIDESTRING pSubject, | 91 FPDF_WIDESTRING pSubject, |
234 FPDF_WIDESTRING pCC, | 92 FPDF_WIDESTRING pCC, |
235 FPDF_WIDESTRING pBcc, | 93 FPDF_WIDESTRING pBcc, |
236 FPDF_WIDESTRING pMsg) { | 94 FPDF_WIDESTRING pMsg); |
237 if (m_pInfo && m_pInfo->FFI_EmailTo) | |
238 m_pInfo->FFI_EmailTo(m_pInfo, fileHandler, pTo, pSubject, pCC, pBcc, | |
239 pMsg); | |
240 } | |
241 | |
242 void UploadTo(FPDF_FILEHANDLER* fileHandler, | 95 void UploadTo(FPDF_FILEHANDLER* fileHandler, |
243 int fileFlag, | 96 int fileFlag, |
244 FPDF_WIDESTRING uploadTo) { | 97 FPDF_WIDESTRING uploadTo); |
245 if (m_pInfo && m_pInfo->FFI_UploadTo) | |
246 m_pInfo->FFI_UploadTo(m_pInfo, fileHandler, fileFlag, uploadTo); | |
247 } | |
248 | |
249 FPDF_FILEHANDLER* OpenFile(int fileType, | 98 FPDF_FILEHANDLER* OpenFile(int fileType, |
250 FPDF_WIDESTRING wsURL, | 99 FPDF_WIDESTRING wsURL, |
251 const char* mode) { | 100 const char* mode); |
252 if (m_pInfo && m_pInfo->FFI_OpenFile) | 101 IFX_FileRead* DownloadFromURL(const FX_WCHAR* url); |
253 return m_pInfo->FFI_OpenFile(m_pInfo, fileType, wsURL, mode); | |
254 return nullptr; | |
255 } | |
256 | |
257 IFX_FileRead* DownloadFromURL(const FX_WCHAR* url) { | |
258 if (!m_pInfo || !m_pInfo->FFI_DownloadFromURL) | |
259 return nullptr; | |
260 | |
261 CFX_ByteString bstrURL = CFX_WideString(url).UTF16LE_Encode(); | |
262 FPDF_WIDESTRING wsURL = | |
263 (FPDF_WIDESTRING)bstrURL.GetBuffer(bstrURL.GetLength()); | |
264 | |
265 FPDF_LPFILEHANDLER fileHandler = | |
266 m_pInfo->FFI_DownloadFromURL(m_pInfo, wsURL); | |
267 | |
268 return new CFPDF_FileStream(fileHandler); | |
269 } | |
270 | |
271 CFX_WideString PostRequestURL(const FX_WCHAR* wsURL, | 102 CFX_WideString PostRequestURL(const FX_WCHAR* wsURL, |
272 const FX_WCHAR* wsData, | 103 const FX_WCHAR* wsData, |
273 const FX_WCHAR* wsContentType, | 104 const FX_WCHAR* wsContentType, |
274 const FX_WCHAR* wsEncode, | 105 const FX_WCHAR* wsEncode, |
275 const FX_WCHAR* wsHeader) { | 106 const FX_WCHAR* wsHeader); |
276 if (!m_pInfo || !m_pInfo->FFI_PostRequestURL) | |
277 return L""; | |
278 | |
279 CFX_ByteString bsURL = CFX_WideString(wsURL).UTF16LE_Encode(); | |
280 FPDF_WIDESTRING URL = (FPDF_WIDESTRING)bsURL.GetBuffer(bsURL.GetLength()); | |
281 | |
282 CFX_ByteString bsData = CFX_WideString(wsData).UTF16LE_Encode(); | |
283 FPDF_WIDESTRING data = | |
284 (FPDF_WIDESTRING)bsData.GetBuffer(bsData.GetLength()); | |
285 | |
286 CFX_ByteString bsContentType = | |
287 CFX_WideString(wsContentType).UTF16LE_Encode(); | |
288 FPDF_WIDESTRING contentType = | |
289 (FPDF_WIDESTRING)bsContentType.GetBuffer(bsContentType.GetLength()); | |
290 | |
291 CFX_ByteString bsEncode = CFX_WideString(wsEncode).UTF16LE_Encode(); | |
292 FPDF_WIDESTRING encode = | |
293 (FPDF_WIDESTRING)bsEncode.GetBuffer(bsEncode.GetLength()); | |
294 | |
295 CFX_ByteString bsHeader = CFX_WideString(wsHeader).UTF16LE_Encode(); | |
296 FPDF_WIDESTRING header = | |
297 (FPDF_WIDESTRING)bsHeader.GetBuffer(bsHeader.GetLength()); | |
298 | |
299 FPDF_BSTR response; | |
300 FPDF_BStr_Init(&response); | |
301 m_pInfo->FFI_PostRequestURL(m_pInfo, URL, data, contentType, encode, header, | |
302 &response); | |
303 | |
304 CFX_WideString wsRet = CFX_WideString::FromUTF16LE( | |
305 (unsigned short*)response.str, response.len / sizeof(unsigned short)); | |
306 FPDF_BStr_Clear(&response); | |
307 | |
308 return wsRet; | |
309 } | |
310 | |
311 FPDF_BOOL PutRequestURL(const FX_WCHAR* wsURL, | 107 FPDF_BOOL PutRequestURL(const FX_WCHAR* wsURL, |
312 const FX_WCHAR* wsData, | 108 const FX_WCHAR* wsData, |
313 const FX_WCHAR* wsEncode) { | 109 const FX_WCHAR* wsEncode); |
314 if (!m_pInfo || !m_pInfo->FFI_PutRequestURL) | 110 CFX_WideString GetLanguage(); |
315 return FALSE; | |
316 | 111 |
317 CFX_ByteString bsURL = CFX_WideString(wsURL).UTF16LE_Encode(); | 112 void PageEvent(int iPageCount, uint32_t dwEventType) const; |
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 bsEncode = CFX_WideString(wsEncode).UTF16LE_Encode(); | |
325 FPDF_WIDESTRING encode = | |
326 (FPDF_WIDESTRING)bsEncode.GetBuffer(bsEncode.GetLength()); | |
327 | |
328 return m_pInfo->FFI_PutRequestURL(m_pInfo, URL, data, encode); | |
329 } | |
330 | |
331 CFX_WideString GetLanguage() { | |
332 if (!m_pInfo || !m_pInfo->FFI_GetLanguage) | |
333 return L""; | |
334 | |
335 int nRequiredLen = m_pInfo->FFI_GetLanguage(m_pInfo, nullptr, 0); | |
336 if (nRequiredLen <= 0) | |
337 return L""; | |
338 | |
339 char* pbuff = new char[nRequiredLen]; | |
340 memset(pbuff, 0, nRequiredLen); | |
341 int nActualLen = m_pInfo->FFI_GetLanguage(m_pInfo, pbuff, nRequiredLen); | |
342 if (nActualLen <= 0 || nActualLen > nRequiredLen) { | |
343 delete[] pbuff; | |
344 return L""; | |
345 } | |
346 CFX_ByteString bsRet = CFX_ByteString(pbuff, nActualLen); | |
347 CFX_WideString wsRet = CFX_WideString::FromUTF16LE( | |
348 (unsigned short*)bsRet.GetBuffer(bsRet.GetLength()), | |
349 bsRet.GetLength() / sizeof(unsigned short)); | |
350 delete[] pbuff; | |
351 return wsRet; | |
352 } | |
353 | |
354 void PageEvent(int iPageCount, uint32_t dwEventType) const { | |
355 if (m_pInfo && m_pInfo->FFI_PageEvent) | |
356 m_pInfo->FFI_PageEvent(m_pInfo, iPageCount, dwEventType); | |
357 } | |
358 #endif // PDF_ENABLE_XFA | 113 #endif // PDF_ENABLE_XFA |
359 | 114 |
360 int JS_appAlert(const FX_WCHAR* Msg, | 115 int JS_appAlert(const FX_WCHAR* Msg, |
361 const FX_WCHAR* Title, | 116 const FX_WCHAR* Title, |
362 uint32_t Type, | 117 uint32_t Type, |
363 uint32_t Icon); | 118 uint32_t Icon); |
364 int JS_appResponse(const FX_WCHAR* Question, | 119 int JS_appResponse(const FX_WCHAR* Question, |
365 const FX_WCHAR* Title, | 120 const FX_WCHAR* Title, |
366 const FX_WCHAR* Default, | 121 const FX_WCHAR* Default, |
367 const FX_WCHAR* cLabel, | 122 const FX_WCHAR* cLabel, |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 std::unique_ptr<CPDFSDK_ActionHandler> m_pActionHandler; | 166 std::unique_ptr<CPDFSDK_ActionHandler> m_pActionHandler; |
412 std::unique_ptr<IJS_Runtime> m_pJSRuntime; | 167 std::unique_ptr<IJS_Runtime> m_pJSRuntime; |
413 FPDF_FORMFILLINFO* const m_pInfo; | 168 FPDF_FORMFILLINFO* const m_pInfo; |
414 CPDFSDK_Document* m_pSDKDoc; | 169 CPDFSDK_Document* m_pSDKDoc; |
415 UnderlyingDocumentType* const m_pUnderlyingDoc; | 170 UnderlyingDocumentType* const m_pUnderlyingDoc; |
416 std::unique_ptr<CFFL_InteractiveFormFiller> m_pFormFiller; | 171 std::unique_ptr<CFFL_InteractiveFormFiller> m_pFormFiller; |
417 std::unique_ptr<CFX_SystemHandler> m_pSysHandler; | 172 std::unique_ptr<CFX_SystemHandler> m_pSysHandler; |
418 }; | 173 }; |
419 | 174 |
420 #endif // FPDFSDK_INCLUDE_CPDFSDK_ENVIRONMENT_H_ | 175 #endif // FPDFSDK_INCLUDE_CPDFSDK_ENVIRONMENT_H_ |
OLD | NEW |